diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index b49226c4e68..a0d0a3fcb25 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,8 @@ +2003-09-24 Hoda Amer + Added testNewTypeId(), testCastExpression(), testPostfixDynamicCast(), + testPostfixReinterpretCast(), testPostfixStaticCast(), and testPostfixConstCast() + to CompleteParseASTExpressionTest. + 2003-09-24 Sean Evoy Changed the implementor of IScannerInfo to answer only absolute paths when asked for includes paths. As a result, the managed builder test had to be updated to expect paths diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java index b7cfd308de0..7a85c76e9cb 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java @@ -13,12 +13,10 @@ package org.eclipse.cdt.core.parser.tests; import java.util.Iterator; import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassReference; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTField; import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTReference; import org.eclipse.cdt.core.parser.ast.IASTVariable; /** @@ -268,29 +266,48 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2))); } - // Kind POSTFIX_DYNAMIC_CAST -// public void testPostfixDynamicCast() throws Exception{ -// Iterator i = parse( "class A {}; class B : public A{}; \n B * b; \n int foo(); int foo( A* ); \n int x = foo( dynamic_cast(b) );").getDeclarations(); -// IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); -// IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); -// IASTVariable b = (IASTVariable) i.next(); -// IASTFunction f1 = (IASTFunction) i.next(); -// IASTFunction f2 = (IASTFunction) i.next(); -// IASTVariable x = (IASTVariable) i.next(); -// Iterator references = callback.getReferences().iterator(); -// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), cla); -// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), clb); -// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), cla); -// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), b); -// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), cla); -// assertEquals(((IASTClassReference)references.next()).getReferencedElement(), f2); -// } - + public void testPostfixDynamicCast() throws Exception{ + Iterator i = parse( "class A {}; class B : public A{}; \n A *a; \n int foo(); int foo( B* ); \n int x = foo( dynamic_cast(a) );").getDeclarations(); + IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTVariable a = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + assertFalse( i.hasNext() ); + assertAllReferences( 6, createTaskList( new Task( cla, 2 ), new Task( clb, 2), new Task(a), new Task(f2))); + } // Kind POSTFIX_REINTERPRET_CAST + public void testPostfixReinterpretCast() throws Exception{ + Iterator i = parse( "int *a; \n int foo(); int foo( double* ); \n int x = foo( reinterpret_cast(a) );").getDeclarations(); + IASTVariable a = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + assertFalse( i.hasNext() ); + assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); + } // Kind POSTFIX_STATIC_CAST + public void testPostfixStaticCast() throws Exception{ + Iterator i = parse( "int a; \n int foo(); int foo( char ); \n int x = foo( static_cast(a) );").getDeclarations(); + IASTVariable a = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + assertFalse( i.hasNext() ); + assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); + } // Kind POSTFIX_CONST_CAST - + public void testPostfixConstCast() throws Exception{ + Iterator i = parse( "const int a; \n int foo(); int foo( int * ); \n int x = foo( const_cast(&a) );").getDeclarations(); + IASTVariable a = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + assertFalse( i.hasNext() ); + assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); + } // Kind POSTFIX_TYPEID_EXPRESSION : LHS public void testPostfixTypeIdExpression() throws Exception{ Iterator i = parse( "int foo(char); int foo( int ); \n int x = foo( typeid(5) );").getDeclarations(); @@ -299,7 +316,6 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 1, createTaskList( new Task( f2 ))); } - // Kind POSTFIX_TYPEID_EXPRESSION : type of the ID public void testPostfixTypeIdExpression2() throws Exception{ Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(a) );").getDeclarations(); @@ -310,8 +326,6 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 4, createTaskList( new Task(cl, 2),new Task(a),new Task(f1))); } - - // Kind POSTFIX_TYPEID_TYPEID : type of the ID public void testPostfixTypeIdTypeId() throws Exception{ Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(A) );").getDeclarations(); @@ -321,8 +335,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1))); - } - + } // Kind POSTFIX_TYPEID_TYPEID : type of the ID public void testPostfixTypeIdTypeId2() throws Exception{ Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(const A) );").getDeclarations(); @@ -332,10 +345,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTFunction f2 = (IASTFunction) i.next(); IASTVariable x = (IASTVariable) i.next(); assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1))); - } - - - + } // Kind UNARY_INCREMENT : LHS public void testUnaryIncrement() throws Exception { @@ -444,20 +454,40 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2 ))); } + // Kind NEW_NEWTYPEID + // Kind NEW_TYPEID + public void testNewTypeId() throws Exception { + Iterator i = parse( "class A{}; void foo(); int foo( A * a ); int x = foo( new A() );").getDeclarations(); + IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertAllReferences( 3, createTaskList( new Task( cl, 2), new Task( foo2 ))); + } + + // Kind DELETE_CASTEXPRESSION + // Kind DELETE_VECTORCASTEXPRESSION + + // Kind CASTEXPRESSION + public void testCastExpression() throws Exception{ + Iterator i = parse( "class A {}; class B : public A{}; \n B *b; \n int foo(); int foo( A* ); \n int x = foo( (A*)b );").getDeclarations(); + IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTVariable b = (IASTVariable) i.next(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + assertFalse( i.hasNext() ); + assertAllReferences( 6, createTaskList( new Task( cla, 3 ), new Task( clb, 1), new Task(b), new Task(f2))); + } + + // Kind PM_DOTSTAR + // failed -// // Kind NEW_NEWTYPEID -// // Kind NEW_TYPEID -// // There are so many ways to call new, only this case is handeled. -// public void testNewTypeId() throws Exception { -// Iterator i = parse( "class A{}; void foo(); int foo( A * a ); int x = foo( new A() );").getDeclarations(); -// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); -// IASTFunction foo = (IASTFunction)i.next(); -// IASTFunction foo2 = (IASTFunction)i.next(); -// IASTVariable x = (IASTVariable)i.next(); -// assertFalse( i.hasNext() ); -// assertAllReferences( 3, createTaskList( new Task( cl, 2), new Task( foo2 ))); -// } - + // Kind PM_ARROWSTAR + // failed + // Kind MULTIPLICATIVE_MULTIPLY : usual arithmetic conversions public void testMultiplicativeMultiply() throws Exception { Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( a * b );").getDeclarations(); @@ -502,12 +532,6 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); -// assertEquals( callback.getReferences().size(), 3 ); -// Iterator references =callback.getReferences().iterator(); -// assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); -// assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); -// assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); -// assertFalse( references.hasNext() ); } // Kind ADDITIVE_MINUS : usual arithmetic conversions public void testAdditiveMinus() throws Exception { @@ -529,8 +553,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ IASTVariable x = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) ); - } - + } // Kind SHIFT_RIGHT : LHS public void testShiftRight() throws Exception { Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a >> 5 );").getDeclarations(); @@ -541,7 +564,6 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertFalse( i.hasNext() ); assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) ); } - // Kind RELATIONAL_LESSTHAN : bool public void testRelationalLessThan() throws Exception { Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b < 3 );").getDeclarations(); @@ -683,7 +705,20 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertFalse( i.hasNext() ); assertAllReferences(8, createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c ), new Task( b ), new Task( a ), new Task( foo2 )) ); } - + public void testConditionalExpressionWithReferencesB_Bug43106() throws Exception { + Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A&); A a ; B b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations(); + IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable c = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertAllReferences( 8, + createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c), new Task( b ), new Task( a ), new Task( foo2) )); + } // Kind THROWEXPRESSION // Kind ASSIGNMENTEXPRESSION_NORMAL : LHS @@ -696,7 +731,6 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertFalse( i.hasNext() ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); } - // Kind ASSIGNMENTEXPRESSION_PLUS : LHS public void testAssignmentExpressionPlus() throws Exception { Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a += 5 );").getDeclarations(); @@ -800,19 +834,6 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ // Kind EXPRESSIONLIST : list of LHS, RHS // Already tested with each test trying to find a reference to function. - public void testConditionalExpressionWithReferencesB_Bug43106() throws Exception { - Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A&); A a ; B b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations(); - IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable c = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 8, - createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c), new Task( b ), new Task( a ), new Task( foo2) )); - } + } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index c46e51cf79c..b1d732792cc 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,8 @@ +2003-09-24 Hoda Amer + Partial solution to bug#42453: Expression result types not computed + Added the handling of the NEW_TYPEID, CASTEXPRESSION, POSTFIX_DYNAMIC_CAST, + POSTFIX_REINTERPRET_CAST, POSTFIX_STATIC_CAST, and POSTFIX_CONST_CAST + 2003-09-25 John Camelon Partial fix for Bug 43221 : POSTFIX_TYPENAME_IDENTIFIER not implemented diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index b6fe9718065..33fd405b5d2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -764,9 +764,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException { List references = new ArrayList(); - - - + //look up id & add to references IContainerSymbol startingScope = scopeToSymbol( scope ); @@ -1030,8 +1028,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto result.add(info); return result; } - - // types that resolve to t_type, symbol already looked up in type id + // Id expressions resolve to t_type, symbol already looked up if( expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION ) { info.setType(TypeInfo.t_type); @@ -1125,21 +1122,20 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } } // new - if( expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID ) + if( ( expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID ) + || ( expression.getExpressionKind() == IASTExpression.Kind.NEW_NEWTYPEID ) ) { - if(symbol != null){ - try - { - info = expression.getTypeId().getTypeSymbol().getTypeInfo(); - } - catch (ASTNotImplementedException e) - { - // will never happen - } - info.addOperatorExpression( TypeInfo.OperatorExpression.indirection); - result.add(info); - return result; - } + try + { + info = expression.getTypeId().getTypeSymbol().getTypeInfo(); + info.addPtrOperator( new TypeInfo.PtrOp(TypeInfo.PtrOp.t_pointer)); + } + catch (ASTNotImplementedException e) + { + // will never happen + } + result.add(info); + return result; } // types that use the usual arithmetic conversions if((expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY) @@ -1194,19 +1190,19 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } } // the cast changes the types to the type looked up in typeId = symbol - if((expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DYNAMIC_CAST) - || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_REINTERPRET_CAST) - || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_STATIC_CAST) - || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_CONST_CAST) + if(( expression.getExpressionKind() == IASTExpression.Kind.CASTEXPRESSION ) + || ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DYNAMIC_CAST ) + || ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_STATIC_CAST ) + || ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_REINTERPRET_CAST ) + || ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_CONST_CAST ) ){ - if(symbol != null){ - info = new TypeInfo(symbol.getTypeInfo()); - info.setTypeSymbol(symbol); - result.add(info); - return result; + try{ + info = new TypeInfo(expression.getTypeId().getTypeSymbol().getTypeInfo()); + }catch (Exception e){ } - } - + result.add(info); + return result; + } // a list collects all types of left and right hand sides if(expression.getExpressionKind() == IASTExpression.Kind.EXPRESSIONLIST){ if(expression.getLHSExpression() != null){ @@ -1248,7 +1244,23 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto result.add(info); return result; } - + +// if ( ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_TYPENAME_IDENTIFIER ) +// || ( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_TYPENAME_TEMPLATEID ) ) +// { +// IASTTypeId typeId = expression.getTypeId(); +// try +// { +// info = typeId.getTypeSymbol().getTypeInfo(); +// } +// catch (ASTNotImplementedException e) +// { +// // will not ever happen from within CompleteParseASTFactory +// } +// result.add(info); +// return result; +// } + return result; }