diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index bf03cf3f9b3..4d905700af4 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,6 @@ +2003-09-12 Hoda Amer + - Added lots of test cases to CompleteParseASTExpressionTest + 2003-09-12 John Camelon Created QuickParseASTTests::testBug42985(). Moved LokiFailures::testBug40419() to QuickParseASTTests. 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 8cd2754799e..ba100a48039 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 @@ -15,6 +15,8 @@ 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.IASTFieldReference; import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTFunctionReference; import org.eclipse.cdt.core.parser.ast.IASTReference; @@ -33,68 +35,8 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ { super(a); } - // IASTExpression.Kind.PRIMARY_INTEGER_LITERAL - public void testExpressionResultValueWithSimpleTypes1() throws Exception - { - Iterator i = parse ("int f(int, int); \n int f(int); \n int x = f(1, 2+3);").getDeclarations(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - Iterator references = callback.getReferences().iterator(); - IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); - assertEquals( fr1.getReferencedElement(), f1 ); - - } - // IASTExpression.Kind.PRIMARY_CHAR_LITERAL - public void testExpressionResultValueWithSimpleTypes2() throws Exception - { - Iterator i = parse ("int f(char, int); \n int f(char); \n int x = f('c');").getDeclarations(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - Iterator references = callback.getReferences().iterator(); - IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); - assertEquals( fr1.getReferencedElement(), f2 ); - - } - // IASTExpression.Kind.PRIMARY_FLOAT_LITERAL - public void testExpressionResultValueWithSimpleTypes3() throws Exception - { - Iterator i = parse ("int f(char); \n int f(float); \n int x = f(1.13);").getDeclarations(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - Iterator references = callback.getReferences().iterator(); - IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); - assertEquals( fr1.getReferencedElement(), f2 ); - - } - // IASTExpression.Kind.PRIMARY_STRING_LITERAL - public void testExpressionResultValueWithSimpleTypes4() throws Exception - { - Iterator i = parse ("int f(char); \n int f(char*); \n int x = f(\"str\");").getDeclarations(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - Iterator references = callback.getReferences().iterator(); - IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); - assertEquals( fr1.getReferencedElement(), f2 ); - - } - // IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL - public void testExpressionResultValueWithSimpleTypes5() throws Exception - { - Iterator i = parse ("int f(bool); \n int f(float); \n int x = f(true);").getDeclarations(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - Iterator references = callback.getReferences().iterator(); - IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); - assertEquals( fr1.getReferencedElement(), f1 ); - - } - // IASTExpression.Kind.PRIMARY_EMPTY - public void testExpressionResultValueWithSimpleTypes6() throws Exception + // Kind PRIMARY_EMPTY : void + public void testPrimaryEmpty() throws Exception { Iterator i = parse ("int f(char); \n int f(void); \n int x = f();").getDeclarations(); IASTFunction f1 = (IASTFunction) i.next(); @@ -105,8 +47,81 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertEquals( fr1.getReferencedElement(), f2 ); } - // IASTExpression.Kind.ID_EXPRESSION - public void testExpressionResultValueWithReferenceTypes() throws Exception + // Kind PRIMARY_INTEGER_LITERAL : int + public void testPrimaryIntegerLiteral() throws Exception + { + Iterator i = parse ("int f(int, int); \n int f(int); \n int x = f(1, 2+3);").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f1 ); + + } + // Kind PRIMARY_CHAR_LITERAL : char + public void testPrimaryCharLiteral() throws Exception + { + Iterator i = parse ("int f(char, int); \n int f(char); \n int x = f('c');").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f2 ); + + } + // Kind PRIMARY_FLOAT_LITERAL : float + public void testPrimaryFloatLiteral() throws Exception + { + Iterator i = parse ("int f(char); \n int f(float); \n int x = f(1.13);").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f2 ); + + } + // Kind PRIMARY_STRING_LITERAL : char* + public void testPrimaryStringLiteral() throws Exception + { + Iterator i = parse ("int f(char); \n int f(char*); \n int x = f(\"str\");").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f2 ); + + } + // Kind PRIMARY_BOOLEAN_LITERAL : bool + public void testPrimaryBooleanLiteral() throws Exception + { + Iterator i = parse ("int f(bool); \n int f(float); \n int x = f(true);").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f1 ); + + } + // Kind PRIMARY_THIS + + // Kind PRIMARY_BRACKETED_EXPRESSION : LHS + public void testPrimaryBracketedExpression() throws Exception + { + Iterator i = parse ("int f(int, int); \n int f(int); \n int x = f(1, (2+3));").getDeclarations(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( fr1.getReferencedElement(), f1 ); + } + // Kind ID_EXPRESSION : type of the ID + public void testIdExpression() throws Exception { Iterator i = parse ("class A{}a; \n int f(A a); \n int f(void); \n int x = f(a);").getDeclarations(); IASTVariable a = (IASTVariable) i.next(); @@ -120,8 +135,228 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertEquals( ar1.getReferencedElement(), a ); assertEquals( fr1.getReferencedElement(), f1 ); } - // IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION - public void testExpressionResultValueWithReferenceTypesAndPointers1() throws Exception + // Kind ID_EXPRESSION ( refers to a pointer ) : pointer to type of ID + public void testIdExpressionToPointer() throws Exception + { + Iterator i = parse ("class A {}; \n A * pa; \n int f(A *ia){} \n int f(void); \n int x = f(pa);").getDeclarations(); + IASTClassSpecifier cl = (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(); + Iterator references = callback.getReferences().iterator(); + IASTClassReference clr1 = (IASTClassReference) references.next(); + IASTClassReference clr2 = (IASTClassReference) references.next(); + IASTVariableReference ar1 = (IASTVariableReference) references.next(); + IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); + assertEquals( clr1.getReferencedElement(), cl ); + assertEquals( ar1.getReferencedElement(), a ); + assertEquals( fr1.getReferencedElement(), f1 ); + } + // Kind POSTFIX_SUBSCRIPT + + // Kind POSTFIX_FUNCTIONCALL : return type of called function + public void testPostfixFunctioncallBug42822() throws Exception + { + Iterator i = parse( "int foo( float b ); int bar( int a, int b ); int test( void ) { int x = bar( foo( 3.0 ), foo( 5.0 ) ) ; }").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction bar = (IASTFunction)i.next(); + IASTFunction test = (IASTFunction)i.next(); + assertFalse( i.hasNext() ); + Iterator references = callback.getReferences().iterator(); + //THIS SHOULD BE 3, 2 references of foo(), one reference of bar() + assertEquals( callback.getReferences().size(), 3 ); + } + // Kind POSTFIX_SIMPLETYPE_* : simple type + public void testPostfixSimpletypesBug42823() throws Exception + { + StringBuffer buffer = new StringBuffer(); + buffer.append( "void foo( int anInt, short aShort, double aDouble, float aFloat, char aChar, wchar_t aWchar, signed aSigned, unsigned anUnsigned, bool aBool, long aLong );"); + buffer.append( "void test( void ) { int someInt = foo( int(3), short(4), double(3.0), float(4.0), char( 'a'), wchar_t( 'a' ), signed( 2 ), unsigned( 3 ), bool( false ), long( 3L ) ); }"); + Iterator i = parse( buffer.toString() ).getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction test = (IASTFunction)i.next(); + assertFalse( i.hasNext() ); + Iterator references = callback.getReferences().iterator(); + //should be 1 + assertEquals( callback.getReferences().size(), 1 ); + } + // Kind POSTFIX_TYPENAME_IDENTIFIER + + // Kind POSTFIX_TYPENAME_TEMPLATEID + + // Kind POSTFIX_DOT_IDEXPRESSION : type of member in the scope of the container + public void testPostfixDotExpression() throws Exception{ + Iterator i = parse( "class A {int m;}; \n A a; \n int foo(char); int foo( int ); \n int x = foo( a.m );").getDeclarations(); + IASTClassSpecifier cl = (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(); + Iterator members = getDeclarations(cl); + IASTField m = (IASTField)members.next(); + Iterator references = callback.getReferences().iterator(); + IASTClassReference clr= (IASTClassReference)references.next(); + assertEquals(clr.getReferencedElement(), cl); + IASTVariableReference ar = (IASTVariableReference)references.next(); + assertEquals(ar.getReferencedElement(), a); + IASTFieldReference mr = (IASTFieldReference) references.next(); + assertEquals(mr.getReferencedElement(), m); + IASTFunctionReference fr = (IASTFunctionReference) references.next(); + assertEquals(fr.getReferencedElement(), f2); + } + // Kind POSTFIX_ARROW_IDEXPRESSION : type of member in the scope of the container + public void testPostfixArrowExpression() throws Exception{ + Iterator i = parse( "class A {int m;}; \n A * a; \n int foo(char); int foo( int ); \n int x = foo( a->m );").getDeclarations(); + IASTClassSpecifier cl = (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(); + Iterator members = getDeclarations(cl); + IASTField m = (IASTField)members.next(); + Iterator references = callback.getReferences().iterator(); + IASTClassReference clr= (IASTClassReference)references.next(); + assertEquals(clr.getReferencedElement(), cl); + IASTVariableReference ar = (IASTVariableReference)references.next(); + assertEquals(ar.getReferencedElement(), a); + IASTFieldReference mr = (IASTFieldReference) references.next(); + assertEquals(mr.getReferencedElement(), m); + IASTFunctionReference fr = (IASTFunctionReference) references.next(); + assertEquals(fr.getReferencedElement(), f2); + } + // Kind POSTFIX_DOT_TEMPL_IDEXPRESS + // Kind POSTFIX_ARROW_TEMPL_IDEXP + // Kind POSTFIX_DOT_DESTRUCTOR + // Kind POSTFIX_ARROW_DESTRUCTOR + + // Kind POSTFIX_INCREMENT : LHS + public void testPostfixIncrement() throws Exception + { + Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( x++ ); } ").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTFunction test = (IASTFunction)i.next(); + Iterator subDecls = getDeclarations( test ); + IASTVariable x = (IASTVariable)subDecls.next(); + IASTVariable y = (IASTVariable)subDecls.next(); + assertFalse( subDecls.hasNext() ); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), x ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); // should be foo2 + assertFalse( references.hasNext() ); + } + // Kind POSTFIX_DECREMENT : LHS + public void testPostfixDecrement() throws Exception + { + Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( x-- ); } ").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTFunction test = (IASTFunction)i.next(); + Iterator subDecls = getDeclarations( test ); + IASTVariable x = (IASTVariable)subDecls.next(); + IASTVariable y = (IASTVariable)subDecls.next(); + assertFalse( subDecls.hasNext() ); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), x ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); // should be foo2 + assertFalse( references.hasNext() ); + } + + // 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); + } +*/ + // Kind POSTFIX_REINTERPRET_CAST + // Kind POSTFIX_STATIC_CAST + // Kind POSTFIX_CONST_CAST + + // 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(); + IASTFunction f1 = (IASTFunction) i.next(); + IASTFunction f2 = (IASTFunction) i.next(); + IASTVariable x = (IASTVariable) i.next(); + Iterator references = callback.getReferences().iterator(); + IASTFunctionReference fr = (IASTFunctionReference) references.next(); + assertEquals(fr.getReferencedElement(), f2); + + } + // 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(); + IASTClassSpecifier cl = (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(); + Iterator references = callback.getReferences().iterator(); + IASTClassReference clr= (IASTClassReference)references.next(); + assertEquals(clr.getReferencedElement(), cl); + IASTClassReference clr2= (IASTClassReference)references.next(); + assertEquals(clr2.getReferencedElement(), cl); + IASTVariableReference ar = (IASTVariableReference)references.next(); + assertEquals(ar.getReferencedElement(), a); + IASTFunctionReference fr = (IASTFunctionReference) references.next(); + assertEquals(fr.getReferencedElement(), f1); + + } + // Kind UNARY_INCREMENT : LHS + public void testUnaryIncrement() throws Exception + { + Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( ++x ); } ").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTFunction test = (IASTFunction)i.next(); + Iterator subDecls = getDeclarations( test ); + IASTVariable x = (IASTVariable)subDecls.next(); + IASTVariable y = (IASTVariable)subDecls.next(); + assertFalse( subDecls.hasNext() ); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), x ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); // should be foo2 + assertFalse( references.hasNext() ); + } + // Kind UNARY_DECREMENT : LHS + public void testUnaryDecrement() throws Exception + { + Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( --x ); } ").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTFunction test = (IASTFunction)i.next(); + Iterator subDecls = getDeclarations( test ); + IASTVariable x = (IASTVariable)subDecls.next(); + IASTVariable y = (IASTVariable)subDecls.next(); + assertFalse( subDecls.hasNext() ); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), x ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); // should be foo2 + assertFalse( references.hasNext() ); + } + // Kind UNARY_STAR_CASTEXPRESSION : LHS + t_pointer + public void testUnaryStarCastExpression() throws Exception { Iterator i = parse ("class A {}; \n A * pa; \n int f(A ia){} \n int f(void); \n int x = f(*pa);").getDeclarations(); IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); @@ -139,26 +374,8 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertEquals( fr1.getReferencedElement(), f1 ); } - // IASTExpression.Kind.ID_EXPRESSION ( refers to a pointer ) - public void testExpressionResultValueWithReferenceTypesAndPointers2() throws Exception - { - Iterator i = parse ("class A {}; \n A * pa; \n int f(A *ia){} \n int f(void); \n int x = f(pa);").getDeclarations(); - IASTClassSpecifier cl = (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(); - Iterator references = callback.getReferences().iterator(); - IASTClassReference clr1 = (IASTClassReference) references.next(); - IASTClassReference clr2 = (IASTClassReference) references.next(); - IASTVariableReference ar1 = (IASTVariableReference) references.next(); - IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); - assertEquals( clr1.getReferencedElement(), cl ); - assertEquals( ar1.getReferencedElement(), a ); - assertEquals( fr1.getReferencedElement(), f1 ); - } - // IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION - public void testExpressionResultValueWithReferenceTypesAndPointers3() throws Exception + // Kind UNARY_AMPSND_CASTEXPRESSION : LHS + t_reference + public void testUnaryAmpersandCastExpression() throws Exception { Iterator i = parse ("class A {}; \n A * pa; \n int f(A ** ia){} \n int f(void); \n int x = f(&pa);").getDeclarations(); IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); @@ -175,51 +392,543 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ assertEquals( ar1.getReferencedElement(), a ); assertEquals( fr1.getReferencedElement(), f1 ); } - // IASTExpression.Kind.POSTFIX_FUNCTIONCALL - public void testBug42822() throws Exception - { - Iterator i = parse( "int foo( float b ); int bar( int a, int b ); int test( void ) { int x = bar( foo( 3.0 ), foo( 5.0 ) ) ; }").getDeclarations(); - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction bar = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - Iterator references = callback.getReferences().iterator(); - //THIS SHOULD BE 3, 2 references of foo(), one reference of bar() - assertEquals( callback.getReferences().size(), 3 ); - } - - // IASTExpression.Kind.POSTFIX_SIMPLETYPE_* - public void testBug42823() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "void foo( int anInt, short aShort, double aDouble, float aFloat, char aChar, wchar_t aWchar, signed aSigned, unsigned anUnsigned, bool aBool, long aLong );"); - buffer.append( "void test( void ) { int someInt = foo( int(3), short(4), double(3.0), float(4.0), char( 'a'), wchar_t( 'a' ), signed( 2 ), unsigned( 3 ), bool( false ), long( 3L ) ); }"); - Iterator i = parse( buffer.toString() ).getDeclarations(); - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - Iterator references = callback.getReferences().iterator(); - //should be 1 - assertEquals( callback.getReferences().size(), 1 ); - } - - // IASTExpression.Kind.POSTFIX_INCREMENT - public void testBug42822B() throws Exception - { - Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( x++ ); } ").getDeclarations(); + // Kind UNARY_PLUS_CASTEXPRESSION : LHS + public void testUnaryPlusCastExpression() throws Exception { + Iterator i = parse( "void foo(); int foo( int ); int x = foo( +5 );").getDeclarations(); IASTFunction foo = (IASTFunction)i.next(); IASTFunction foo2 = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - Iterator subDecls = getDeclarations( test ); - IASTVariable x = (IASTVariable)subDecls.next(); - IASTVariable y = (IASTVariable)subDecls.next(); - assertFalse( subDecls.hasNext() ); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 1 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind UNARY_MINUS_CASTEXPRESSION : LHS + public void testUnaryMinusCastExpression() throws Exception { + Iterator i = parse( "void foo(); int foo( int ); int x = foo( -5 );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 1 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind UNARY_NOT_CASTEXPRESSION : LHS + public void testUnaryNotCastExpression() throws Exception { + Iterator i = parse( "void foo(); int foo( bool ); bool b=true; int x = foo( !b );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind UNARY_TILDE_CASTEXPRESSION : LHS + public void testTildeNotCastExpression() throws Exception { + Iterator i = parse( "void foo(); int foo( int ); int x = 5; int y = foo( ~x );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable x = (IASTVariable)i.next(); + IASTVariable y = (IASTVariable)i.next(); assertFalse( i.hasNext() ); assertEquals( callback.getReferences().size(), 2 ); Iterator references =callback.getReferences().iterator(); assertEquals( ((IASTReference)references.next()).getReferencedElement(), x ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); // should be foo2 + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind UNARY_SIZEOF_UNARYEXPRESSION : unsigned int + public void testUnarySizeofUnaryExpression() throws Exception { + Iterator i = parse( "void foo(); int foo( int ); int x = 5; int y = foo( sizeof(5) );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable x = (IASTVariable)i.next(); + IASTVariable y = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 1 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind UNARY_SIZEOF_TYPEID : unsigned int + public void testUnarySizeofTypeId() throws Exception { + Iterator i = parse( "void foo(); int foo( int ); int x = 5; int y = foo( sizeof(x) );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable x = (IASTVariable)i.next(); + IASTVariable y = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), x ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); assertFalse( references.hasNext() ); } + // 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() ); + //assertEquals( callback.getReferences().size(), 3 ); + Iterator references =callback.getReferences().iterator(); + IASTClassReference clr1 = (IASTClassReference) references.next(); + IASTClassReference clr2 = (IASTClassReference) references.next(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } +*/ + // Kind DELETE_CASTEXPRESSION + // Kind DELETE_VECTORCASTEXPRESSION + // Kind CASTEXPRESSION + // Kind PM_DOTSTAR + // Kind PM_ARROWSTAR + + // 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(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 3 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind MULTIPLICATIVE_DIVIDE : usual arithmetic conversions + public void testMultiplicativeDivide() throws Exception { + Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b / a );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + 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 MULTIPLICATIVE_MODULUS : usual arithmetic conversions + public void testMultiplicativeModulus() throws Exception { + Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b % a );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + 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_PLUS : usual arithmetic conversions + public void testAdditivePlus() throws Exception { + Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b + a );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + 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 { + Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b - a );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + 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 SHIFT_LEFT : LHS + public void testShiftLeft() throws Exception { + Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a << 5 );").getDeclarations(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + + // 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(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + + // 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(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind RELATIONAL_GREATERTHAN : bool + public void testRelationalGreaterThan() throws Exception { + Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b > 3 );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind RELATIONAL_LESSTHANEQUALTO : bool + public void testRelationalLessThanOrEqual() throws Exception { + Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b <= 3 );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind RELATIONAL_GREATERTHANEQUALTO : bool + public void testRelationalGreaterThanOrEqual() throws Exception { + Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b >= 3 );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind EQUALITY_EQUALS : bool + public void testEqualityEquals() throws Exception { + Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b == 3 );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind EQUALITY_NOTEQUALS : bool + public void testEqualityNotEquals() throws Exception { + Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b != 3 );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind ANDEXPRESSION : usual arithmetic conversions + public void testAndExpression() throws Exception { + Iterator i = parse( "int foo(); int foo( int ); int a = 3; int b= 5; int x = foo( a & b );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 3 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind EXCLUSIVEOREXPRESSION : usual arithmetic conversions + public void testExclusiveOrExpression() throws Exception { + Iterator i = parse( "int foo(); int foo( int ); int a = 3; int b= 5; int x = foo( a ^ b );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 3 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind INCLUSIVEOREXPRESSION : : usual arithmetic conversions + public void testInclusiveOrExpression() throws Exception { + Iterator i = parse( "int foo(); int foo( int ); int a = 3; int b= 5; int x = foo( a | b );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 3 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind LOGICALANDEXPRESSION : bool + public void testLogicalAndExpression() throws Exception { + Iterator i = parse( "int foo(); int foo( bool ); bool a = true; bool b= false; int x = foo( a && b );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 3 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind LOGICALOREXPRESSION : bool + public void testLogicalOrExpression() throws Exception { + Iterator i = parse( "int foo(); int foo( bool ); bool a = true; bool b= false; int x = foo( a || b );").getDeclarations(); + IASTFunction foo = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable b = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 3 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); + assertFalse( references.hasNext() ); + } + // Kind CONDITIONALEXPRESSION + + // Kind THROWEXPRESSION + + // Kind ASSIGNMENTEXPRESSION_NORMAL : LHS + public void testAssignmentExpressionNormal() throws Exception { + Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a = 5 );").getDeclarations(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + + // 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(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + // Kind ASSIGNMENTEXPRESSION_MINUS : LHS + public void testAssignmentExpressionMinus() throws Exception { + Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a -= 5 );").getDeclarations(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + // Kind ASSIGNMENTEXPRESSION_MULT : LHS + public void testAssignmentExpressionMulti() throws Exception { + Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a *= 5 );").getDeclarations(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + // Kind ASSIGNMENTEXPRESSION_DIV : LHS + public void testAssignmentExpressionDiv() throws Exception { + Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a /= 5 );").getDeclarations(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + // Kind ASSIGNMENTEXPRESSION_MOD : LHS + public void testAssignmentExpressionMod() throws Exception { + Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a %= 5 );").getDeclarations(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + // Kind ASSIGNMENTEXPRESSION_LSHIFT : LHS + public void testAssignmentExpressionLShift() throws Exception { + Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a >>= 5 );").getDeclarations(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + // Kind ASSIGNMENTEXPRESSION_RSHIFT : LHS + public void testAssignmentExpressionRShift() throws Exception { + Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a <<= 5 );").getDeclarations(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + // Kind ASSIGNMENTEXPRESSION_AND : LHS + public void testAssignmentExpressionAnd() throws Exception { + Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a &= 5 );").getDeclarations(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + // Kind ASSIGNMENTEXPRESSION_OR : LHS + public void testAssignmentExpressionOr() throws Exception { + Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a |= 5 );").getDeclarations(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + // Kind ASSIGNMENTEXPRESSION_XOR : LHS + public void testAssignmentExpressionXOr() throws Exception { + Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a ^= 5 );").getDeclarations(); + IASTFunction foo1 = (IASTFunction)i.next(); + IASTFunction foo2 = (IASTFunction)i.next(); + IASTVariable a = (IASTVariable)i.next(); + IASTVariable x = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + Iterator references =callback.getReferences().iterator(); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); + assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 ); + assertFalse( references.hasNext() ); + } + // Kind EXPRESSIONLIST : list of LHS, RHS + // Already tested with each test trying to find a reference to function. } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 81ff90c66c1..e033d2dd20f 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,8 @@ +2003-09-12 Hoda Amer + In completeParseASTFactory.getExpressionResultType() + - Added the handling of some more expression types. + See CompleteParseASTExpressionTest for details. + 2003-09-12 John Camelon Fixed Bug 42985 : Search: Qualified function call is treated as a declaration Fixed Bug 40419 : parser fails on heavily templated expressions diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java index 5d52a7fbf68..59aa93c4e61 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java @@ -95,8 +95,7 @@ public interface IASTExpression extends ISourceElementCallbackDelegate public static final Kind INCLUSIVEOREXPRESSION = new Kind( 68 ); public static final Kind LOGICALANDEXPRESSION = new Kind( 69 ); public static final Kind LOGICALOREXPRESSION = new Kind( 70 ); - public static final Kind CONDITIONALEXPRESSION_SIMPLE = new Kind( 71 ); - public static final Kind CONDITIONALEXPRESSION_HARD = new Kind( 72 ); + public static final Kind CONDITIONALEXPRESSION = new Kind( 71 ); public static final Kind THROWEXPRESSION = new Kind( 72 ); public static final Kind ASSIGNMENTEXPRESSION_NORMAL = new Kind( 73 ); public static final Kind ASSIGNMENTEXPRESSION_PLUS = new Kind( 74 ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index 42a352404f3..e3f3c45979d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -2893,7 +2893,7 @@ public class Parser implements IParser // if the condition not taken, try assignment operators if (conditionalExpression != null && conditionalExpression.getExpressionKind() - == IASTExpression.Kind.CONDITIONALEXPRESSION_HARD) + == IASTExpression.Kind.CONDITIONALEXPRESSION) return conditionalExpression; switch (LT(1)) { case IToken.tASSIGN : @@ -3031,7 +3031,7 @@ public class Parser implements IParser { return astFactory.createExpression( scope, - IASTExpression.Kind.CONDITIONALEXPRESSION_HARD, + IASTExpression.Kind.CONDITIONALEXPRESSION, firstExpression, secondExpression, thirdExpression, 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 7e824eb6caa..ffaacd02b8c 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 @@ -767,6 +767,15 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto if( typeId != null ){ symbol = lookupQualifiedName( startingScope, typeId, references, false ); } + // "a.m" or "a->m : lookup m in the scope of the declaration of a + if ((kind == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION) + || (kind == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION)){ + TypeInfo lhsInfo = (TypeInfo) ((ASTExpression)lhs).getResultType().iterator().next(); + ISymbol containingScope = (ISymbol) lhsInfo.getTypeSymbol().getTypeSymbol(); + if(containingScope != null){ + symbol = lookupQualifiedName((IContainerSymbol)containingScope, ((ASTExpression)rhs).getTypeId() , references, false); + } + } if (kind == IASTExpression.Kind.POSTFIX_FUNCTIONCALL){ ITokenDuple functionId = ((ASTExpression)lhs).getTypeId(); @@ -781,7 +790,72 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto return expression; } - + /* + * Apply the usual arithmetic conversions to find out the result of an expression + * that has a lhs and a rhs as indicated in the specs (section 5.Expressions, page 64) + */ + protected TypeInfo usualArithmeticConversions(TypeInfo lhs, TypeInfo rhs){ + TypeInfo info = new TypeInfo(); + if( + ( lhs.checkBit(TypeInfo.isLong) && lhs.getType() == TypeInfo.t_double) + || ( rhs.checkBit(TypeInfo.isLong) && rhs.getType() == TypeInfo.t_double) + ){ + info.setType(TypeInfo.t_double); + info.setBit(true, TypeInfo.isLong); + return info; + } + else if( + ( lhs.getType() == TypeInfo.t_double ) + || ( rhs.getType() == TypeInfo.t_double ) + ){ + info.setType(TypeInfo.t_double); + return info; + } + else if ( + ( lhs.getType() == TypeInfo.t_float ) + || ( rhs.getType() == TypeInfo.t_float ) + ){ + info.setType(TypeInfo.t_float); + return info; + } else { + // perform intergral promotions (Specs section 4.5) + info.setType(TypeInfo.t_int); + } + + if( + ( lhs.checkBit(TypeInfo.isUnsigned) && lhs.checkBit(TypeInfo.isLong)) + || ( rhs.checkBit(TypeInfo.isUnsigned) && rhs.checkBit(TypeInfo.isLong)) + ){ + info.setBit(true, TypeInfo.isUnsigned); + info.setBit(true, TypeInfo.isLong); + return info; + } + else if( + ( lhs.checkBit(TypeInfo.isUnsigned) && rhs.checkBit(TypeInfo.isLong) ) + || ( rhs.checkBit(TypeInfo.isUnsigned) && lhs.checkBit(TypeInfo.isLong) ) + ){ + info.setBit(true, TypeInfo.isUnsigned); + info.setBit(true, TypeInfo.isLong); + return info; + } + else if ( + ( lhs.checkBit(TypeInfo.isLong)) + || ( rhs.checkBit(TypeInfo.isLong)) + ){ + info.setBit(true, TypeInfo.isLong); + return info; + } + else if ( + ( lhs.checkBit(TypeInfo.isUnsigned) ) + || ( rhs.checkBit(TypeInfo.isUnsigned) ) + ){ + info.setBit(true, TypeInfo.isUnsigned); + return info; + } else { + // it should be both = int + return info; + } + } protected List getExpressionResultType(IASTExpression expression, ISymbol symbol){ List result = new ArrayList(); TypeInfo info = new TypeInfo(); @@ -794,25 +868,22 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto return result; } // types that resolve to int - // the relational kinds are 0 and !0 if ((expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_INTEGER_LITERAL) || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT) - || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHAN) - || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO) - || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHAN) - || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO) - || (expression.getExpressionKind() == IASTExpression.Kind.EQUALITY_EQUALS) - || (expression.getExpressionKind() == IASTExpression.Kind.EQUALITY_NOTEQUALS) - || (expression.getExpressionKind() == IASTExpression.Kind.ANDEXPRESSION) - || (expression.getExpressionKind() == IASTExpression.Kind.EXCLUSIVEOREXPRESSION) - || (expression.getExpressionKind() == IASTExpression.Kind.INCLUSIVEOREXPRESSION) - || (expression.getExpressionKind() == IASTExpression.Kind.LOGICALANDEXPRESSION) - || (expression.getExpressionKind() == IASTExpression.Kind.LOGICALOREXPRESSION) ){ info.setType(TypeInfo.t_int); result.add(info); return result; } + // size of is always unsigned int + if ((expression.getExpressionKind() == IASTExpression.Kind.UNARY_SIZEOF_TYPEID) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_SIZEOF_UNARYEXPRESSION) + ){ + info.setType(TypeInfo.t_int); + info.setBit(true, TypeInfo.isUnsigned); + result.add(info); + return result; + } // types that resolve to char if( (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_CHAR_LITERAL) || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR)){ @@ -849,6 +920,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto // types that resolve to bool if( (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL) || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHAN) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHAN) + || (expression.getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO) + || (expression.getExpressionKind() == IASTExpression.Kind.EQUALITY_EQUALS) + || (expression.getExpressionKind() == IASTExpression.Kind.EQUALITY_NOTEQUALS) + || (expression.getExpressionKind() == IASTExpression.Kind.LOGICALANDEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.LOGICALOREXPRESSION) ) { info.setType(TypeInfo.t_bool); @@ -885,7 +964,9 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } // types that resolve to t_type, symbol already looked up in type id - if (expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION){ + if( (expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_TYPEID_TYPEID) + ){ info.setType(TypeInfo.t_type); if(symbol != null) info.setTypeSymbol(symbol); @@ -914,16 +995,64 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto result.add(info); return result; } - // types that resolve to LHS types - if ((expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_INCREMENT) - || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DECREMENT) - || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_INCREMENT) - || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_DECREMENT) - || (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY) + // the dot and the arrow resolves to the type of the member + if ((expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION) + ){ + if(symbol != null){ + info = new TypeInfo(symbol.getTypeInfo()); + result.add(info); + return result; + } + } + // new +/* if((expression.getExpressionKind() == IASTExpression.Kind.NEW_NEWTYPEID) + || (expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID) + ){ + if(symbol != null){ + info.setType(symbol.getType()); + info.setTypeSymbol(symbol); + result.add(info); + return result; + } + } +*/ // types that use the usual arithmetic conversions + if((expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY) || (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_DIVIDE) || (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MODULUS) || (expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_PLUS) || (expression.getExpressionKind() == IASTExpression.Kind.ADDITIVE_MINUS) + || (expression.getExpressionKind() == IASTExpression.Kind.ANDEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.EXCLUSIVEOREXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.INCLUSIVEOREXPRESSION) + ){ + ASTExpression left = (ASTExpression)expression.getLHSExpression(); + ASTExpression right = (ASTExpression)expression.getRHSExpression(); + if((left != null ) && (right != null)){ + TypeInfo leftType =(TypeInfo)left.getResultType().iterator().next(); + while( (leftType.getType() == TypeInfo.t_type) && (leftType.getTypeSymbol() != null)){ + leftType = leftType.getTypeSymbol().getTypeInfo(); + } + TypeInfo rightType =(TypeInfo)right.getResultType().iterator().next(); + while( (rightType.getType() == TypeInfo.t_type) && (rightType.getTypeSymbol() != null)){ + rightType = rightType.getTypeSymbol().getTypeInfo(); + } + info = usualArithmeticConversions(leftType, rightType); + result.add(info); + return result; + } + } + // types that resolve to LHS types + if ((expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_INCREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_DECREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_TYPEID_EXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_INCREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_DECREMENT) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION) + || (expression.getExpressionKind() == IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION) || (expression.getExpressionKind() == IASTExpression.Kind.SHIFT_LEFT) || (expression.getExpressionKind() == IASTExpression.Kind.SHIFT_RIGHT) || (expression.getExpressionKind() == IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL) @@ -945,6 +1074,20 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto return result; } } + // 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(symbol != null){ + info = new TypeInfo(symbol.getTypeInfo()); + info.setTypeSymbol(symbol); + 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){