1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00
Fixed Bug 43084 : need to restructure TypeId to allow dynamic_cast<> type expression references.
	Fixed Bug 39504 : sizeof-expressions are not handled properly

TESTS
	Replaced ASTFailedTests::testBug39504A() with CompleteParseASTTest::testBug39504(). 
	Moved testPostfixTypeIdExpression2() && testPostfixTypeIdTypeId2() to CompleteParseASTExpressionTest. 
	Restructured expression reference tests so that the order of arrival will not cause JUnit failures.
This commit is contained in:
John Camelon 2003-09-23 22:58:34 +00:00
parent 66859771be
commit 02c194aaf4
26 changed files with 1445 additions and 695 deletions

View file

@ -1,3 +1,8 @@
2003-09-23 John Camelon
Replaced ASTFailedTests::testBug39504A() with CompleteParseASTTest::testBug39504().
Moved testPostfixTypeIdExpression2() && testPostfixTypeIdTypeId2() to CompleteParseASTExpressionTest.
Restructured expression reference tests so that the order of arrival will not cause JUnit failures.
2003-09-23 Hoda Amer 2003-09-23 Hoda Amer
Added CompleteParseASTTest.testBug43373() Added CompleteParseASTTest.testBug43373()
Added QuickParseASTTests.testBug43371() Added QuickParseASTTests.testBug43371()

View file

@ -37,10 +37,7 @@ public class ASTFailedTests extends BaseASTTest
{ {
assertCodeFailsParse("FUNCTION_MACRO( 1, a )\n int i;"); assertCodeFailsParse("FUNCTION_MACRO( 1, a )\n int i;");
} }
public void testBug39504A() throws Exception
{
assertCodeFailsParse("int y = sizeof(x[0]);");
}
public void testBug39525() throws Exception public void testBug39525() throws Exception
{ {

View file

@ -41,62 +41,6 @@ public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest
super(name); super(name);
} }
// public void testPostfixSubscriptA_Bug43238() throws Exception
// {
// Iterator i = parse ("int pa[10][5] ; \n int f(int ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
// IASTVariable pa = (IASTVariable) i.next();
// IASTFunction f1 = (IASTFunction) i.next();
// IASTFunction f2 = (IASTFunction) i.next();
// IASTVariable x = (IASTVariable) i.next();
// Iterator references = callback.getReferences().iterator();
// assertEquals( callback.getReferences().size(), 1 ); // should be = 2
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
// //assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
// }
// public void testPostfixSubscriptB_Bug43238() throws Exception
// {
// Iterator i = parse ("int* pa[10][5] ; \n int f(int* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
// IASTVariable pa = (IASTVariable) i.next();
// IASTFunction f1 = (IASTFunction) i.next();
// IASTFunction f2 = (IASTFunction) i.next();
// IASTVariable x = (IASTVariable) i.next();
// Iterator references = callback.getReferences().iterator();
// assertEquals( callback.getReferences().size(), 1 ); // should be = 2
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
// //assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
// }
// public void testPostfixSubscriptWithReferences_Bug43238() throws Exception
// {
// Iterator i = parse ("class A{}; \n A *pa[10][5] ; \n int f(A* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations();
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
// IASTVariable pa = (IASTVariable) i.next();
// IASTFunction f1 = (IASTFunction) i.next();
// IASTFunction f2 = (IASTFunction) i.next();
// IASTVariable x = (IASTVariable) i.next();
// Iterator references = callback.getReferences().iterator();
// assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
// assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
// }
// public void testConditionalExpression_Bug43159() throws Exception {
// Iterator i = parse( "int foo(bool); int foo(int); int a = 10, b = 4, c = 2; int x = foo( a > 5 ? b : c );").getDeclarations();
// 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() );
// assertEquals( callback.getReferences().size(), 3 ); // should be 4
// Iterator references =callback.getReferences().iterator();
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
// assertEquals( ((IASTReference)references.next()).getReferencedElement(), c );
// //assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
// assertFalse( references.hasNext() );
// }
public void testConditionalExpressionWithReferencesB_Bug43106() throws Exception { 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(); 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 cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
@ -108,18 +52,10 @@ public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest
IASTVariable c = (IASTVariable)i.next(); IASTVariable c = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 7 ); // should be 8 assertAllReferences( 7 /* should be 8 */,
Iterator references =callback.getReferences().iterator(); createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c), new Task( b ), new Task( a )/*, new Task( foo2) */));
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), clb );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), c );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
//assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
public void testPMDotStarPointerToMemberFunction_Bug43242() throws Exception public void testPMDotStarPointerToMemberFunction_Bug43242() throws Exception
{ {
Iterator i = parse ("class A { int m(int); }; \n A a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a.*pm)(5));").getDeclarations(); Iterator i = parse ("class A { int m(int); }; \n A a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a.*pm)(5));").getDeclarations();
@ -131,14 +67,10 @@ public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator();
assertEquals( callback.getReferences().size(), 5 ); // should be 6 assertAllReferences( 5 /* should be 8 */,
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl ); createTaskList( new Task( cl, 2 /* should be 3 */ ), new Task( method ), new Task( a ), new Task( pm ) /* should be ,new Task( f2 ) */
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl ); ));
assertEquals( ((IASTReference) references.next()).getReferencedElement(), method );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), pm );
// assertEquals( ((IASTReference) references.next()).getReferencedElement(), f2 );
} }
public void testPMArrowStarPointerToMemberFunction_Bug43242() throws Exception public void testPMArrowStarPointerToMemberFunction_Bug43242() throws Exception
{ {
@ -151,14 +83,10 @@ public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator();
assertEquals( callback.getReferences().size(), 5 ); // should be 6 assertAllReferences( 5 /* should be more */,
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl ); createTaskList( new Task( cl, 2 ), new Task( method ), new Task( a /*, 2 */), new Task( pm )/* ,new Task( f2 )*/));
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), method );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), pm );
// assertEquals( ((IASTReference) references.next()).getReferencedElement(), f2 );
} }
public void testUnaryStarCastexpressionPointerToFunction_Bug43241() throws Exception public void testUnaryStarCastexpressionPointerToFunction_Bug43241() throws Exception
{ {
@ -168,11 +96,9 @@ public class FailedCompleteParseASTExpressionTest extends CompleteParseBaseTest
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 2 /* should be 3 */,
assertEquals( callback.getReferences().size(), 2 ); // should be 3 createTaskList( new Task( m ), new Task( pm ) /* ,new Task( f2 )*/));
assertEquals( ((IASTReference) references.next()).getReferencedElement(), m );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), pm );
// assertEquals( ((IASTReference) references.next()).getReferencedElement(), f2 );
} }
} }

View file

@ -16,13 +16,10 @@ import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTClassReference; import org.eclipse.cdt.core.parser.ast.IASTClassReference;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTField; 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.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTFunctionReference;
import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTReference; import org.eclipse.cdt.core.parser.ast.IASTReference;
import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTVariableReference;
/** /**
* @author hamer * @author hamer
@ -43,10 +40,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences(1, createTaskList( new Task( f2 ) ));
IASTFunctionReference fr1 = (IASTFunctionReference) references.next();
assertEquals( fr1.getReferencedElement(), f2 );
} }
// Kind PRIMARY_INTEGER_LITERAL : int // Kind PRIMARY_INTEGER_LITERAL : int
public void testPrimaryIntegerLiteral() throws Exception public void testPrimaryIntegerLiteral() throws Exception
@ -55,9 +49,10 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 1, createTaskList( new Task( f1 )));
IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); // Iterator references = callback.getReferences().iterator();
assertEquals( fr1.getReferencedElement(), f1 ); // IASTFunctionReference fr1 = (IASTFunctionReference) references.next();
// assertEquals( fr1.getReferencedElement(), f1 );
} }
// Kind PRIMARY_CHAR_LITERAL : char // Kind PRIMARY_CHAR_LITERAL : char
@ -67,10 +62,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 1, createTaskList( new Task( f2 )));
IASTFunctionReference fr1 = (IASTFunctionReference) references.next();
assertEquals( fr1.getReferencedElement(), f2 );
} }
// Kind PRIMARY_FLOAT_LITERAL : float // Kind PRIMARY_FLOAT_LITERAL : float
public void testPrimaryFloatLiteral() throws Exception public void testPrimaryFloatLiteral() throws Exception
@ -79,10 +71,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 1, createTaskList( new Task( f2 )));
IASTFunctionReference fr1 = (IASTFunctionReference) references.next();
assertEquals( fr1.getReferencedElement(), f2 );
} }
// Kind PRIMARY_STRING_LITERAL : char* // Kind PRIMARY_STRING_LITERAL : char*
public void testPrimaryStringLiteral() throws Exception public void testPrimaryStringLiteral() throws Exception
@ -91,10 +80,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 1, createTaskList( new Task( f2 )));
IASTFunctionReference fr1 = (IASTFunctionReference) references.next();
assertEquals( fr1.getReferencedElement(), f2 );
} }
// Kind PRIMARY_BOOLEAN_LITERAL : bool // Kind PRIMARY_BOOLEAN_LITERAL : bool
public void testPrimaryBooleanLiteral() throws Exception public void testPrimaryBooleanLiteral() throws Exception
@ -103,10 +89,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 1, createTaskList( new Task( f1 )));
IASTFunctionReference fr1 = (IASTFunctionReference) references.next();
assertEquals( fr1.getReferencedElement(), f1 );
} }
// Kind PRIMARY_THIS : type of inner most enclosing structure scope // Kind PRIMARY_THIS : type of inner most enclosing structure scope
public void testPrimaryThis() throws Exception public void testPrimaryThis() throws Exception
@ -119,11 +102,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTMethod m = (IASTMethod) i.next(); IASTMethod m = (IASTMethod) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 4, createTaskList( new Task( cl, 3 ), new Task( f2 )));
assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
assertEquals( ((IASTFunctionReference) references.next()).getReferencedElement(), f2 );
} }
// Kind PRIMARY_BRACKETED_EXPRESSION : LHS // Kind PRIMARY_BRACKETED_EXPRESSION : LHS
public void testPrimaryBracketedExpression() throws Exception public void testPrimaryBracketedExpression() throws Exception
@ -132,24 +111,20 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 1, createTaskList( new Task( f1 )));
IASTFunctionReference fr1 = (IASTFunctionReference) references.next(); }
assertEquals( fr1.getReferencedElement(), f1 );
}
// Kind ID_EXPRESSION : type of the ID // Kind ID_EXPRESSION : type of the ID
public void testIdExpression() throws Exception 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(); 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(); IASTVariable a = (IASTVariable) i.next();
IASTClassSpecifier cl = (IASTClassSpecifier)a.getAbstractDeclaration().getTypeSpecifier();
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator();
IASTClassReference clr1 = (IASTClassReference) references.next(); assertAllReferences( 3, createTaskList( new Task( cl ), new Task( f1 ),new Task( a ) ) );
IASTVariableReference ar1 = (IASTVariableReference) references.next();
IASTFunctionReference fr1 = (IASTFunctionReference) references.next();
assertEquals( ar1.getReferencedElement(), a );
assertEquals( fr1.getReferencedElement(), f1 );
} }
// Kind ID_EXPRESSION ( refers to a pointer ) : pointer to type of ID // Kind ID_EXPRESSION ( refers to a pointer ) : pointer to type of ID
public void testIdExpressionToPointer() throws Exception public void testIdExpressionToPointer() throws Exception
@ -160,14 +135,8 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 4, createTaskList( new Task( cl, 2 ), new Task( f1 ), new Task( a ) ) );
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_SUBSCRIPT
public void testPostfixSubscript() throws Exception public void testPostfixSubscript() throws Exception
@ -176,11 +145,8 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable pa = (IASTVariable) i.next(); IASTVariable pa = (IASTVariable) i.next();
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) );
assertEquals( callback.getReferences().size(), 2 );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
} }
public void testPostfixSubscriptA() throws Exception public void testPostfixSubscriptA() throws Exception
@ -190,10 +156,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) );
assertEquals( callback.getReferences().size(), 2 ); // should be = 2
assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
} }
public void testPostfixSubscriptB() throws Exception public void testPostfixSubscriptB() throws Exception
@ -203,10 +166,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) );
assertEquals( callback.getReferences().size(), 2 ); // should be = 2
assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
} }
public void testPostfixSubscriptWithReferences() throws Exception public void testPostfixSubscriptWithReferences() throws Exception
@ -217,11 +177,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 4, createTaskList( new Task( cl, 2 ), new Task( pa ), new Task( f1 )));
assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
assertEquals( ((IASTClassReference) references.next()).getReferencedElement(), cl );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), pa );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), f1 );
} }
// Kind POSTFIX_FUNCTIONCALL : return type of called function // Kind POSTFIX_FUNCTIONCALL : return type of called function
@ -230,11 +186,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
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(); 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 foo = (IASTFunction)i.next();
IASTFunction bar = (IASTFunction)i.next(); IASTFunction bar = (IASTFunction)i.next();
IASTFunction test = (IASTFunction)i.next(); i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
Iterator references = callback.getReferences().iterator(); assertAllReferences( 3, createTaskList( new Task( bar ), new Task( foo, 2 )));
//THIS SHOULD BE 3, 2 references of foo(), one reference of bar()
assertEquals( callback.getReferences().size(), 3 );
} }
// Kind POSTFIX_SIMPLETYPE_* : simple type // Kind POSTFIX_SIMPLETYPE_* : simple type
public void testPostfixSimpletypesBug42823() throws Exception public void testPostfixSimpletypesBug42823() throws Exception
@ -246,10 +200,9 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction foo = (IASTFunction)i.next(); IASTFunction foo = (IASTFunction)i.next();
IASTFunction test = (IASTFunction)i.next(); IASTFunction test = (IASTFunction)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
Iterator references = callback.getReferences().iterator(); assertAllReferences( 1, createTaskList( new Task( foo )));
//should be 1
assertEquals( callback.getReferences().size(), 1 );
} }
// Kind POSTFIX_TYPENAME_IDENTIFIER // Kind POSTFIX_TYPENAME_IDENTIFIER
// public void testPostfixTypenameIdentifier() throws Exception{ // public void testPostfixTypenameIdentifier() throws Exception{
// Iterator i = parse( "class A {}; \n int foo(); int foo( A a ); \n int x = foo( typename A(); );").getDeclarations(); // Iterator i = parse( "class A {}; \n int foo(); int foo( A a ); \n int x = foo( typename A(); );").getDeclarations();
@ -282,15 +235,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator members = getDeclarations(cl); Iterator members = getDeclarations(cl);
IASTField m = (IASTField)members.next(); IASTField m = (IASTField)members.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 4, createTaskList( new Task(cl), new Task(a), new Task(m), new Task(f2) ));
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 // Kind POSTFIX_ARROW_IDEXPRESSION : type of member in the scope of the container
public void testPostfixArrowExpression() throws Exception{ public void testPostfixArrowExpression() throws Exception{
@ -302,15 +247,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator members = getDeclarations(cl); Iterator members = getDeclarations(cl);
IASTField m = (IASTField)members.next(); IASTField m = (IASTField)members.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 4, createTaskList( new Task(cl), new Task(a), new Task(m), new Task(f2) ));
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_DOT_TEMPL_IDEXPRESS
// Kind POSTFIX_ARROW_TEMPL_IDEXP // Kind POSTFIX_ARROW_TEMPL_IDEXP
@ -329,11 +266,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable y = (IASTVariable)subDecls.next(); IASTVariable y = (IASTVariable)subDecls.next();
assertFalse( subDecls.hasNext() ); assertFalse( subDecls.hasNext() );
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2)));
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 // Kind POSTFIX_DECREMENT : LHS
public void testPostfixDecrement() throws Exception public void testPostfixDecrement() throws Exception
@ -347,11 +280,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable y = (IASTVariable)subDecls.next(); IASTVariable y = (IASTVariable)subDecls.next();
assertFalse( subDecls.hasNext() ); assertFalse( subDecls.hasNext() );
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2)));
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 // Kind POSTFIX_DYNAMIC_CAST
@ -382,30 +311,45 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 1, createTaskList( new Task( f2 )));
IASTFunctionReference fr = (IASTFunctionReference) references.next();
assertEquals(fr.getReferencedElement(), f2);
} }
// Kind POSTFIX_TYPEID_TYPEID : type of the ID
public void testPostfixTypeIdTypeId() throws Exception{ // 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(); 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(); IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
IASTVariable a = (IASTVariable) i.next(); IASTVariable a = (IASTVariable) i.next();
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 4, createTaskList( new Task(cl, 2),new Task(a),new Task(f1)));
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 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();
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();
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();
assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1)));
}
// Kind UNARY_INCREMENT : LHS // Kind UNARY_INCREMENT : LHS
public void testUnaryIncrement() throws Exception public void testUnaryIncrement() throws Exception
{ {
@ -418,11 +362,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable y = (IASTVariable)subDecls.next(); IASTVariable y = (IASTVariable)subDecls.next();
assertFalse( subDecls.hasNext() ); assertFalse( subDecls.hasNext() );
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task(foo2), new Task(x) ));
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 // Kind UNARY_DECREMENT : LHS
public void testUnaryDecrement() throws Exception public void testUnaryDecrement() throws Exception
@ -436,11 +376,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable y = (IASTVariable)subDecls.next(); IASTVariable y = (IASTVariable)subDecls.next();
assertFalse( subDecls.hasNext() ); assertFalse( subDecls.hasNext() );
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task(foo2), new Task(x) ));
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 // Kind UNARY_STAR_CASTEXPRESSION : LHS + t_pointer
public void testUnaryStarCastExpression() throws Exception public void testUnaryStarCastExpression() throws Exception
@ -451,15 +387,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 4, createTaskList( new Task(cl, 2 ), new Task( a ), new Task(f1) ));
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 UNARY_AMPSND_CASTEXPRESSION : LHS + t_reference // Kind UNARY_AMPSND_CASTEXPRESSION : LHS + t_reference
public void testUnaryAmpersandCastExpression() throws Exception public void testUnaryAmpersandCastExpression() throws Exception
@ -470,14 +398,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 4, createTaskList( new Task(cl, 2 ), new Task( a ), new Task(f1) ));
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 UNARY_PLUS_CASTEXPRESSION : LHS // Kind UNARY_PLUS_CASTEXPRESSION : LHS
public void testUnaryPlusCastExpression() throws Exception { public void testUnaryPlusCastExpression() throws Exception {
@ -486,10 +407,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction foo2 = (IASTFunction)i.next(); IASTFunction foo2 = (IASTFunction)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 1 ); assertAllReferences( 1, createTaskList( new Task( foo2 )));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
// Kind UNARY_MINUS_CASTEXPRESSION : LHS // Kind UNARY_MINUS_CASTEXPRESSION : LHS
public void testUnaryMinusCastExpression() throws Exception { public void testUnaryMinusCastExpression() throws Exception {
@ -498,10 +416,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction foo2 = (IASTFunction)i.next(); IASTFunction foo2 = (IASTFunction)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 1 ); assertAllReferences( 1, createTaskList( new Task( foo2 )));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
// Kind UNARY_NOT_CASTEXPRESSION : LHS // Kind UNARY_NOT_CASTEXPRESSION : LHS
public void testUnaryNotCastExpression() throws Exception { public void testUnaryNotCastExpression() throws Exception {
@ -511,11 +426,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task( b ), new Task( foo2 )));
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 // Kind UNARY_TILDE_CASTEXPRESSION : LHS
public void testTildeNotCastExpression() throws Exception { public void testTildeNotCastExpression() throws Exception {
@ -525,11 +436,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
IASTVariable y = (IASTVariable)i.next(); IASTVariable y = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2 )));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), x );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
// Kind UNARY_SIZEOF_UNARYEXPRESSION : unsigned int // Kind UNARY_SIZEOF_UNARYEXPRESSION : unsigned int
public void testUnarySizeofUnaryExpression() throws Exception { public void testUnarySizeofUnaryExpression() throws Exception {
@ -539,10 +446,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
IASTVariable y = (IASTVariable)i.next(); IASTVariable y = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 1 ); assertAllReferences( 1, createTaskList( new Task( foo2 )));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
// Kind UNARY_SIZEOF_TYPEID : unsigned int // Kind UNARY_SIZEOF_TYPEID : unsigned int
public void testUnarySizeofTypeId() throws Exception { public void testUnarySizeofTypeId() throws Exception {
@ -552,29 +456,20 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
IASTVariable y = (IASTVariable)i.next(); IASTVariable y = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2 )));
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_NEWTYPEID
// Kind NEW_TYPEID // // Kind NEW_TYPEID
// There are so many ways to call new, only this case is handeled. // // There are so many ways to call new, only this case is handeled.
// public void testNewTypeId() throws Exception { // public void testNewTypeId() throws Exception {
// Iterator i = parse( "class A{}; void foo(); int foo( A a ); int x = foo( new A() );").getDeclarations(); // Iterator i = parse( "class A{}; void foo(); int foo( A * a ); int x = foo( new A() );").getDeclarations();
// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); // IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
// IASTFunction foo = (IASTFunction)i.next(); // IASTFunction foo = (IASTFunction)i.next();
// IASTFunction foo2 = (IASTFunction)i.next(); // IASTFunction foo2 = (IASTFunction)i.next();
// IASTVariable x = (IASTVariable)i.next(); // IASTVariable x = (IASTVariable)i.next();
// assertFalse( i.hasNext() ); // assertFalse( i.hasNext() );
// //assertEquals( callback.getReferences().size(), 3 ); // assertAllReferences( 3, createTaskList( new Task( cl, 2), new Task( foo2 )));
// 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_CASTEXPRESSION
@ -590,12 +485,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 4, createTaskList( new Task( cl ), new Task( a), new Task( pm ), new Task(f2)));
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), pm );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), f2 );
} }
// Kind PM_ARROWSTAR // Kind PM_ARROWSTAR
@ -608,12 +498,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTFunction f1 = (IASTFunction) i.next(); IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next(); IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next(); IASTVariable x = (IASTVariable) i.next();
Iterator references = callback.getReferences().iterator(); assertAllReferences( 4, createTaskList( new Task( cl ), new Task( a), new Task( pm), new Task( f2)));
assertEquals( ((IASTReference) references.next()).getReferencedElement(), cl );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), pm );
assertEquals( ((IASTReference) references.next()).getReferencedElement(), f2 );
} }
// Kind MULTIPLICATIVE_MULTIPLY : usual arithmetic conversions // Kind MULTIPLICATIVE_MULTIPLY : usual arithmetic conversions
@ -626,11 +511,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 3 ); assertEquals( callback.getReferences().size(), 3 );
Iterator references =callback.getReferences().iterator(); assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) );
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 // Kind MULTIPLICATIVE_DIVIDE : usual arithmetic conversions
public void testMultiplicativeDivide() throws Exception { public void testMultiplicativeDivide() throws Exception {
@ -641,12 +522,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 3 ); assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) );
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 // Kind MULTIPLICATIVE_MODULUS : usual arithmetic conversions
public void testMultiplicativeModulus() throws Exception { public void testMultiplicativeModulus() throws Exception {
@ -657,12 +533,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 3 ); assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) );
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 // Kind ADDITIVE_PLUS : usual arithmetic conversions
public void testAdditivePlus() throws Exception { public void testAdditivePlus() throws Exception {
@ -673,12 +544,13 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 3 ); assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) );
Iterator references =callback.getReferences().iterator(); // assertEquals( callback.getReferences().size(), 3 );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b ); // Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a ); // assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 ); // assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertFalse( references.hasNext() ); // assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
// assertFalse( references.hasNext() );
} }
// Kind ADDITIVE_MINUS : usual arithmetic conversions // Kind ADDITIVE_MINUS : usual arithmetic conversions
public void testAdditiveMinus() throws Exception { public void testAdditiveMinus() throws Exception {
@ -689,12 +561,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 3 ); assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) );
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 // Kind SHIFT_LEFT : LHS
public void testShiftLeft() throws Exception { public void testShiftLeft() throws Exception {
@ -704,11 +571,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) );
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind SHIFT_RIGHT : LHS // Kind SHIFT_RIGHT : LHS
@ -719,11 +582,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) );
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind RELATIONAL_LESSTHAN : bool // Kind RELATIONAL_LESSTHAN : bool
@ -734,11 +593,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) );
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
// Kind RELATIONAL_GREATERTHAN : bool // Kind RELATIONAL_GREATERTHAN : bool
public void testRelationalGreaterThan() throws Exception { public void testRelationalGreaterThan() throws Exception {
@ -748,11 +603,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) );
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
// Kind RELATIONAL_LESSTHANEQUALTO : bool // Kind RELATIONAL_LESSTHANEQUALTO : bool
public void testRelationalLessThanOrEqual() throws Exception { public void testRelationalLessThanOrEqual() throws Exception {
@ -762,11 +613,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) );
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
// Kind RELATIONAL_GREATERTHANEQUALTO : bool // Kind RELATIONAL_GREATERTHANEQUALTO : bool
public void testRelationalGreaterThanOrEqual() throws Exception { public void testRelationalGreaterThanOrEqual() throws Exception {
@ -776,11 +623,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) );
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
// Kind EQUALITY_EQUALS : bool // Kind EQUALITY_EQUALS : bool
public void testEqualityEquals() throws Exception { public void testEqualityEquals() throws Exception {
@ -790,11 +633,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) );
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
// Kind EQUALITY_NOTEQUALS : bool // Kind EQUALITY_NOTEQUALS : bool
public void testEqualityNotEquals() throws Exception { public void testEqualityNotEquals() throws Exception {
@ -804,11 +643,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) );
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 // Kind ANDEXPRESSION : usual arithmetic conversions
public void testAndExpression() throws Exception { public void testAndExpression() throws Exception {
@ -819,12 +654,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 3 ); assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) );
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 // Kind EXCLUSIVEOREXPRESSION : usual arithmetic conversions
public void testExclusiveOrExpression() throws Exception { public void testExclusiveOrExpression() throws Exception {
@ -835,12 +665,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 3 ); assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) );
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 // Kind INCLUSIVEOREXPRESSION : : usual arithmetic conversions
public void testInclusiveOrExpression() throws Exception { public void testInclusiveOrExpression() throws Exception {
@ -851,12 +676,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 3 ); assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) );
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 // Kind LOGICALANDEXPRESSION : bool
public void testLogicalAndExpression() throws Exception { public void testLogicalAndExpression() throws Exception {
@ -867,12 +687,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 3 ); assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) );
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 // Kind LOGICALOREXPRESSION : bool
public void testLogicalOrExpression() throws Exception { public void testLogicalOrExpression() throws Exception {
@ -883,12 +698,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable b = (IASTVariable)i.next(); IASTVariable b = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 3 ); assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) );
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 : conditional Expression Conversions // Kind CONDITIONALEXPRESSION : conditional Expression Conversions
public void testConditionalExpression() throws Exception { public void testConditionalExpression() throws Exception {
@ -900,13 +710,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable c = (IASTVariable)i.next(); IASTVariable c = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 4 ); assertAllReferences( 4, createTaskList( new Task( a ), new Task(b), new Task( c ), new Task( foo2 ) ) );
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), c );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
// Kind CONDITIONALEXPRESSION with references : conditional Expression Conversions // Kind CONDITIONALEXPRESSION with references : conditional Expression Conversions
public void testConditionalExpressionWithReferencesA() throws Exception { public void testConditionalExpressionWithReferencesA() throws Exception {
@ -920,17 +724,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable c = (IASTVariable)i.next(); IASTVariable c = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 8 ); assertAllReferences(8, createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c ), new Task( b ), new Task( a ), new Task( foo2 )) );
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), cla );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), clb );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), c );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), b );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo2 );
assertFalse( references.hasNext() );
} }
// Kind THROWEXPRESSION // Kind THROWEXPRESSION
@ -943,11 +737,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind ASSIGNMENTEXPRESSION_PLUS : LHS // Kind ASSIGNMENTEXPRESSION_PLUS : LHS
@ -958,11 +748,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind ASSIGNMENTEXPRESSION_MINUS : LHS // Kind ASSIGNMENTEXPRESSION_MINUS : LHS
public void testAssignmentExpressionMinus() throws Exception { public void testAssignmentExpressionMinus() throws Exception {
@ -972,11 +758,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind ASSIGNMENTEXPRESSION_MULT : LHS // Kind ASSIGNMENTEXPRESSION_MULT : LHS
public void testAssignmentExpressionMulti() throws Exception { public void testAssignmentExpressionMulti() throws Exception {
@ -986,11 +768,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind ASSIGNMENTEXPRESSION_DIV : LHS // Kind ASSIGNMENTEXPRESSION_DIV : LHS
public void testAssignmentExpressionDiv() throws Exception { public void testAssignmentExpressionDiv() throws Exception {
@ -1000,11 +778,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind ASSIGNMENTEXPRESSION_MOD : LHS // Kind ASSIGNMENTEXPRESSION_MOD : LHS
public void testAssignmentExpressionMod() throws Exception { public void testAssignmentExpressionMod() throws Exception {
@ -1014,11 +788,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind ASSIGNMENTEXPRESSION_LSHIFT : LHS // Kind ASSIGNMENTEXPRESSION_LSHIFT : LHS
public void testAssignmentExpressionLShift() throws Exception { public void testAssignmentExpressionLShift() throws Exception {
@ -1028,11 +798,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind ASSIGNMENTEXPRESSION_RSHIFT : LHS // Kind ASSIGNMENTEXPRESSION_RSHIFT : LHS
public void testAssignmentExpressionRShift() throws Exception { public void testAssignmentExpressionRShift() throws Exception {
@ -1042,11 +808,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind ASSIGNMENTEXPRESSION_AND : LHS // Kind ASSIGNMENTEXPRESSION_AND : LHS
public void testAssignmentExpressionAnd() throws Exception { public void testAssignmentExpressionAnd() throws Exception {
@ -1056,11 +818,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind ASSIGNMENTEXPRESSION_OR : LHS // Kind ASSIGNMENTEXPRESSION_OR : LHS
public void testAssignmentExpressionOr() throws Exception { public void testAssignmentExpressionOr() throws Exception {
@ -1070,11 +828,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
Iterator references =callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), a );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), foo1 );
assertFalse( references.hasNext() );
} }
// Kind ASSIGNMENTEXPRESSION_XOR : LHS // Kind ASSIGNMENTEXPRESSION_XOR : LHS
public void testAssignmentExpressionXOr() throws Exception { public void testAssignmentExpressionXOr() throws Exception {
@ -1084,11 +838,7 @@ public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{
IASTVariable a = (IASTVariable)i.next(); IASTVariable a = (IASTVariable)i.next();
IASTVariable x = (IASTVariable)i.next(); IASTVariable x = (IASTVariable)i.next();
assertFalse( i.hasNext() ); assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 ); assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) ));
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 // Kind EXPRESSIONLIST : list of LHS, RHS
// Already tested with each test trying to find a reference to function. // Already tested with each test trying to find a reference to function.

View file

@ -499,11 +499,11 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
IASTVariable variablep = (IASTVariable)declarations.next(); IASTVariable variablep = (IASTVariable)declarations.next();
assertEquals( callback.getReferences().size(), 5 ); assertEquals( callback.getReferences().size(), 5 );
Iterator references = callback.getReferences().iterator(); Iterator references = callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableP );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableB );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableC );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableD );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableA ); assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableA );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableP );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableB );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableC );
assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableD );
} }
public void testBug41520() throws Exception public void testBug41520() throws Exception
@ -796,5 +796,14 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
} }
} }
public void testBug39504() throws Exception
{
Iterator i = parse( "const int w = 2; int x[ 5 ]; int y = sizeof (x[w]);" ).getDeclarations();
IASTVariable varW = (IASTVariable)i.next();
IASTVariable varX = (IASTVariable)i.next();
IASTVariable vary = (IASTVariable)i.next();
assertFalse( i.hasNext() );
assertEquals( callback.getReferences().size(), 2 );
}
} }

View file

@ -12,15 +12,18 @@ package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader; import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.Stack; import java.util.Stack;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ParserFactory; import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
@ -48,6 +51,7 @@ import org.eclipse.cdt.core.parser.ast.IASTMethodReference;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference; import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference;
import org.eclipse.cdt.core.parser.ast.IASTParameterReference; import org.eclipse.cdt.core.parser.ast.IASTParameterReference;
import org.eclipse.cdt.core.parser.ast.IASTReference;
import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
@ -170,6 +174,17 @@ public class CompleteParseBaseTest extends TestCase
private Stack inclusions = new Stack(); private Stack inclusions = new Stack();
private Scope compilationUnit; private Scope compilationUnit;
public FullParseCallback()
{
// System.out.println( "NEW");
// System.out.println();
}
public void finalize()
{
// System.out.println( );
}
public IASTScope getCompilationUnit() public IASTScope getCompilationUnit()
{ {
return compilationUnit; return compilationUnit;
@ -504,7 +519,7 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void acceptClassReference(IASTClassReference reference) public void acceptClassReference(IASTClassReference reference)
{ {
references.add( reference ); processReference( reference );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -512,7 +527,7 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void acceptTypedefReference(IASTTypedefReference reference) public void acceptTypedefReference(IASTTypedefReference reference)
{ {
references.add( reference ); processReference( reference );
} }
@ -521,7 +536,7 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void acceptNamespaceReference(IASTNamespaceReference reference) public void acceptNamespaceReference(IASTNamespaceReference reference)
{ {
references.add( reference ); processReference( reference );
} }
@ -530,7 +545,7 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void acceptEnumerationReference(IASTEnumerationReference reference) public void acceptEnumerationReference(IASTEnumerationReference reference)
{ {
references.add( reference ); processReference( reference );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -538,8 +553,7 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void acceptVariableReference(IASTVariableReference reference) public void acceptVariableReference(IASTVariableReference reference)
{ {
references.add( reference ); processReference( reference );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -547,8 +561,13 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void acceptFunctionReference(IASTFunctionReference reference) public void acceptFunctionReference(IASTFunctionReference reference)
{ {
references.add( reference ); processReference(reference);
}
protected void processReference(IASTReference reference)
{
references.add( reference );
// System.out.println( "Callback received Reference to " + reference.getName() + " @ offset " + reference.getOffset() );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -556,7 +575,7 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void acceptFieldReference(IASTFieldReference reference) public void acceptFieldReference(IASTFieldReference reference)
{ {
references.add( reference ); processReference( reference );
} }
@ -565,7 +584,7 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void acceptMethodReference(IASTMethodReference reference) public void acceptMethodReference(IASTMethodReference reference)
{ {
references.add( reference ); processReference( reference );
} }
@ -617,7 +636,7 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void acceptEnumeratorReference(IASTEnumeratorReference reference) public void acceptEnumeratorReference(IASTEnumeratorReference reference)
{ {
references.add( reference ); processReference( reference );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -625,7 +644,7 @@ public class CompleteParseBaseTest extends TestCase
*/ */
public void acceptParameterReference(IASTParameterReference reference) public void acceptParameterReference(IASTParameterReference reference)
{ {
references.add( reference ); processReference( reference );
} }
} }
@ -656,4 +675,140 @@ public class CompleteParseBaseTest extends TestCase
if( ! parser.parse() ) throw new ParserException( "FAILURE"); if( ! parser.parse() ) throw new ParserException( "FAILURE");
return callback.getCompilationUnit(); return callback.getCompilationUnit();
} }
protected void assertReferences(
ISourceElementCallbackDelegate element,
int expectedDistinctReferenceCount,
boolean allowDuplicates )
{
Set matches = new HashSet();
Iterator allReferences = callback.getReferences().iterator();
while( allReferences.hasNext() )
{
IASTReference r = (IASTReference)allReferences.next();
if( r.getReferencedElement() == element )
if( ! matches.add( r ) && ! allowDuplicates )
fail( "Duplicate reference found for ISourceElementCallbackDelegate: " + element + " @ offset " + r.getOffset() );
}
assertEquals( expectedDistinctReferenceCount, matches.size() );
}
protected static class Task
{
private final boolean unique;
private final int count;
private final ISourceElementCallbackDelegate element;
public Task( ISourceElementCallbackDelegate element, int referenceCount, boolean distinct )
{
this.element = element;
this.count = referenceCount;
this.unique = distinct;
}
public Task( ISourceElementCallbackDelegate element, int referenceCount )
{
this( element, referenceCount, true );
}
public Task( ISourceElementCallbackDelegate element )
{
this( element, 1, false );
}
/**
* @return
*/
public int getCount()
{
return count;
}
/**
* @return
*/
public ISourceElementCallbackDelegate getElement()
{
return element;
}
/**
* @return
*/
public boolean isUnique()
{
return unique;
}
}
protected void assertReferenceTask( Task task )
{
assertReferences( task.getElement(), task.getCount(), task.isUnique() );
}
protected void assertAllReferences( int count, List tasks )
{
assertEquals( callback.getReferences().size(), count );
if( tasks == null ) return;
Iterator i = tasks.iterator();
while( i.hasNext() )
{
assertReferenceTask( (Task)i.next() );
}
}
protected List createTaskList( Task t1 )
{
List result = new ArrayList();
result.add( t1 );
return result;
}
protected List createTaskList( Task t1, Task t2 )
{
List result = createTaskList(t1);
result.add( t2 );
return result;
}
protected List createTaskList( Task t1, Task t2, Task t3 )
{
List result = createTaskList(t1, t2);
result.add( t3 );
return result;
}
protected List createTaskList( Task t1, Task t2, Task t3, Task t4 )
{
List result = createTaskList(t1, t2, t3);
result.add( t4 );
return result;
}
protected List createTaskList( Task t1, Task t2, Task t3, Task t4, Task t5 )
{
List result = createTaskList(t1, t2, t3, t4);
result.add( t5 );
return result;
}
/**
* @param task
* @param task2
* @param task3
* @param task4
* @param task5
* @param task6
* @return
*/
protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6)
{
List result = createTaskList( task, task2, task3, task4, task5 );
result.add( task6 );
return result;
}
} }

View file

@ -1431,7 +1431,7 @@ public class QuickParseASTTests extends BaseASTTest
assertFalse( enumerators.hasNext() ); assertFalse( enumerators.hasNext() );
assertEquals( enumerator.getName(), "isPointer"); assertEquals( enumerator.getName(), "isPointer");
assertEquals( enumerator.getInitialValue().getExpressionKind(), IASTExpression.Kind.ID_EXPRESSION ); assertEquals( enumerator.getInitialValue().getExpressionKind(), IASTExpression.Kind.ID_EXPRESSION );
assertEquals( enumerator.getInitialValue().getTypeIdString(), "PointerTraits<T>::result"); assertEquals( enumerator.getInitialValue().getIdExpression(), "PointerTraits<T>::result");
} }
public void testBug36690() throws Exception { public void testBug36690() throws Exception {
@ -1814,7 +1814,9 @@ public class QuickParseASTTests extends BaseASTTest
public void testBug39556() throws Exception public void testBug39556() throws Exception
{ {
parse("int *restrict ip_fn (void);", true, true, ParserLanguage.C).getDeclarations().next(); parse("int *restrict ip_fn (void);", true, true, ParserLanguage.C).getDeclarations().next();
}
}
/** /**
* Test code: struct Example { Example(); Example(int); ~Example();}; * Test code: struct Example { Example(); Example(int); ~Example();};
* Purpose: tests a declaration in a class scope. * Purpose: tests a declaration in a class scope.
@ -1842,4 +1844,5 @@ public class QuickParseASTTests extends BaseASTTest
assertTrue(m2.getVisiblity() == ASTAccessVisibility.PUBLIC); assertTrue(m2.getVisiblity() == ASTAccessVisibility.PUBLIC);
assertTrue(m3.getVisiblity() == ASTAccessVisibility.PUBLIC); assertTrue(m3.getVisiblity() == ASTAccessVisibility.PUBLIC);
} }
} }

View file

@ -1,3 +1,7 @@
2003-09-23 John Camelon
Fixed Bug 43084 : need to restructure TypeId to allow dynamic_cast<> type expression references.
Fixed Bug 39504 : sizeof-expressions are not handled properly
2003-09-23 Hoda Amer 2003-09-23 Hoda Amer
Solution to bug#43373: No reference to static member in definition Solution to bug#43373: No reference to static member in definition
Solution to bug#43371: constructor incorrectly marked private Solution to bug#43371: constructor incorrectly marked private

View file

@ -121,7 +121,7 @@ public interface IASTExpression extends ISourceElementCallbackDelegate
} }
public interface IASTNewExpressionDescriptor public interface IASTNewExpressionDescriptor extends ISourceElementCallbackDelegate
{ {
public Iterator getNewPlacementExpressions(); public Iterator getNewPlacementExpressions();
public Iterator getNewTypeIdExpressions(); public Iterator getNewTypeIdExpressions();
@ -135,9 +135,11 @@ public interface IASTExpression extends ISourceElementCallbackDelegate
public IASTExpression getRHSExpression(); public IASTExpression getRHSExpression();
public IASTExpression getThirdExpression(); public IASTExpression getThirdExpression();
public String getLiteralString(); public String getLiteralString();
public String getTypeIdString(); public String getIdExpression();
public IASTTypeId getTypeId();
public IASTNewExpressionDescriptor getNewExpressionDescriptor(); public IASTNewExpressionDescriptor getNewExpressionDescriptor();
public int evaluateExpression() throws ExpressionEvaluationException; public int evaluateExpression() throws ExpressionEvaluationException;
public void reconcileReferences() throws ASTNotImplementedException;
} }

View file

@ -102,8 +102,8 @@ public interface IASTFactory
IASTExpression lhs, IASTExpression lhs,
IASTExpression rhs, IASTExpression rhs,
IASTExpression thirdExpression, IASTExpression thirdExpression,
ITokenDuple typeId, IASTTypeId typeId,
String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException; ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException;
public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List newPlacementExpressions,List newTypeIdExpressions,List newInitializerExpressions); public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List newPlacementExpressions,List newTypeIdExpressions,List newInitializerExpressions);
public IASTInitializerClause createInitializerClause( public IASTInitializerClause createInitializerClause(
IASTInitializerClause.Kind kind, IASTInitializerClause.Kind kind,
@ -200,5 +200,9 @@ public interface IASTFactory
* @return * @return
*/ */
public IASTCodeScope createNewCodeBlock(IASTScope scope); public IASTCodeScope createNewCodeBlock(IASTScope scope);
public IASTTypeId createTypeId( IASTScope scope, IASTSimpleTypeSpecifier.Type kind, boolean isConst, boolean isVolatile, boolean isShort,
boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods ) throws ASTSemanticException;
} }

View file

@ -0,0 +1,40 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.core.parser.ast;
import java.util.Iterator;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
/**
* @author jcamelon
*
*/
public interface IASTTypeId extends ISourceElementCallbackDelegate
{
public IASTSimpleTypeSpecifier.Type getKind();
public String getTypeOrClassName();
public Iterator getPointerOperators();
public Iterator getArrayModifiers();
public boolean isConst();
public boolean isVolatile();
public boolean isLong();
public boolean isShort();
public boolean isSigned();
public boolean isUnsigned();
public boolean isTypename();
public String getFullSignature() throws ASTNotImplementedException;
public ISymbol getTypeSymbol() throws ASTNotImplementedException;
}

View file

@ -348,7 +348,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
{ {
Declarator d = declarator.getOwnedDeclarator(); Declarator d = declarator.getOwnedDeclarator();
Iterator i = d.getPtrOps().iterator(); Iterator i = d.getPointerOperators().iterator();
if( !i.hasNext() ) if( !i.hasNext() )
{ {
boolean isWithinClass = scope instanceof IASTClassSpecifier; boolean isWithinClass = scope instanceof IASTClassSpecifier;
@ -375,7 +375,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
List convertedParms = createParameterList( declarator.getParameters() ); List convertedParms = createParameterList( declarator.getParameters() );
IASTAbstractDeclaration abs = astFactory.createAbstractDeclaration( IASTAbstractDeclaration abs = astFactory.createAbstractDeclaration(
constt, volatil, getTypeSpecifier(), declarator.getPtrOps(), declarator.getArrayModifiers(), constt, volatil, getTypeSpecifier(), declarator.getPointerOperators(), declarator.getArrayModifiers(),
convertedParms, (ASTPointerOperator)i.next() ); convertedParms, (ASTPointerOperator)i.next() );
String name = ( d.getPointerOperatorNameDuple() != null ) ? d.getPointerOperatorNameDuple().toString() + d.getName() : d.getName(); String name = ( d.getPointerOperatorNameDuple() != null ) ? d.getPointerOperatorNameDuple().toString() + d.getName() : d.getName();
if( typedef ) if( typedef )
@ -407,7 +407,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
constt, constt,
volatil, volatil,
getTypeSpecifier(), getTypeSpecifier(),
declarator.getPtrOps(), declarator.getArrayModifiers(), null, null), startingOffset, declarator.getNameStartOffset()); declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), startingOffset, declarator.getNameStartOffset());
} }
/** /**
* @param declarator * @param declarator
@ -425,7 +425,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
constt, constt,
volatil, volatil,
getTypeSpecifier(), getTypeSpecifier(),
declarator.getPtrOps(), declarator.getArrayModifiers(), null, null), declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null),
declarator.getExceptionSpecification(), declarator.getExceptionSpecification(),
inline, inline,
friend, friend,
@ -455,7 +455,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
constt, constt,
volatil, volatil,
getTypeSpecifier(), getTypeSpecifier(),
declarator.getPtrOps(), declarator.getArrayModifiers(), null, null), declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null),
declarator.getExceptionSpecification(), declarator.getExceptionSpecification(),
inline, inline,
friend, friend,
@ -486,7 +486,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
constt, constt,
volatil, volatil,
getTypeSpecifier(), getTypeSpecifier(),
declarator.getPtrOps(), declarator.getArrayModifiers(), null, null), declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null),
mutable, mutable,
extern, extern,
register, register,
@ -511,7 +511,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
wrapper.isConst(), wrapper.isConst(),
wrapper.isVolatile(), wrapper.isVolatile(),
wrapper.getTypeSpecifier(), wrapper.getTypeSpecifier(),
declarator.getPtrOps(), declarator.getPointerOperators(),
declarator.getArrayModifiers(), declarator.getArrayModifiers(),
null, null, declarator.getName() == null null, null, declarator.getName() == null
? "" ? ""
@ -536,7 +536,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
constt, constt,
volatil, volatil,
getTypeSpecifier(), getTypeSpecifier(),
declarator.getPtrOps(), declarator.getArrayModifiers(), null, null), declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null),
mutable, mutable,
extern, extern,
register, register,

View file

@ -27,7 +27,7 @@ import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
* @author jcamelon * @author jcamelon
* *
*/ */
public class Declarator implements IParameterCollection, IDeclaratorOwner public class Declarator implements IParameterCollection, IDeclaratorOwner, IDeclarator
{ {
private ITokenDuple pointerOperatorNameDuple; private ITokenDuple pointerOperatorNameDuple;
private ITokenDuple namedDuple; private ITokenDuple namedDuple;
@ -116,12 +116,12 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner
/** /**
* @return * @return
*/ */
public List getPtrOps() public List getPointerOperators()
{ {
return Collections.unmodifiableList( ptrOps ); return Collections.unmodifiableList( ptrOps );
} }
public void addPtrOp( ASTPointerOperator ptrOp ) public void addPointerOperator( ASTPointerOperator ptrOp )
{ {
ptrOps.add( ptrOp ); ptrOps.add( ptrOp );
} }
@ -362,7 +362,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner
public DeclarationWrapper getDeclarationWrapper() public DeclarationWrapper getDeclarationWrapper()
{ {
Declarator d = this; Declarator d = this;
while( d.getOwner() instanceof Declarator ) while( d.getOwner() instanceof IDeclarator )
d = (Declarator)d.getOwner(); d = (Declarator)d.getOwner();
return (DeclarationWrapper)d.getOwner(); return (DeclarationWrapper)d.getOwner();
} }

View file

@ -0,0 +1,44 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser;
import java.util.List;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.IASTArrayModifier;
/**
* @author jcamelon
*
*/
public interface IDeclarator
{
/**
* @return
*/
public abstract List getPointerOperators();
public abstract void addPointerOperator(ASTPointerOperator ptrOp);
/**
* @param arrayMod
*/
public abstract void addArrayModifier(IASTArrayModifier arrayMod);
/**
* @return
*/
public abstract List getArrayModifiers();
/**
* @param nameDuple
*/
public void setPointerOperatorName(ITokenDuple nameDuple);
public ITokenDuple getPointerOperatorNameDuple();
}

View file

@ -52,6 +52,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
@ -521,7 +522,7 @@ public class Parser implements IParser
: IASTTemplateParameter.ParamKind.TYPENAME; : IASTTemplateParameter.ParamKind.TYPENAME;
IToken id = null; IToken id = null;
ITokenDuple typeId = null; IASTTypeId typeId = null;
try try
{ {
if (LT(1) == IToken.tIDENTIFIER) // optional identifier if (LT(1) == IToken.tIDENTIFIER) // optional identifier
@ -531,7 +532,7 @@ public class Parser implements IParser
if (LT(1) == IToken.tASSIGN) // optional = type-id if (LT(1) == IToken.tASSIGN) // optional = type-id
{ {
consume(IToken.tASSIGN); consume(IToken.tASSIGN);
typeId = typeId(); // type-id typeId = typeId(scope, false); // type-id
} }
} }
@ -544,7 +545,7 @@ public class Parser implements IParser
astFactory.createTemplateParameter( astFactory.createTemplateParameter(
kind, kind,
( id == null )? "" : id.getImage(), ( id == null )? "" : id.getImage(),
(typeId == null) ? null : typeId.toString(), (typeId == null) ? null : typeId.getTypeOrClassName(),
null, null,
null)); null));
@ -558,7 +559,7 @@ public class Parser implements IParser
consume(IToken.tGT); consume(IToken.tGT);
consume(IToken.t_class); consume(IToken.t_class);
IToken optionalId = null; IToken optionalId = null;
ITokenDuple optionalTypeId = null; IASTTypeId optionalTypeId = null;
if (LT(1) == IToken.tIDENTIFIER) // optional identifier if (LT(1) == IToken.tIDENTIFIER) // optional identifier
{ {
optionalId = identifier(); optionalId = identifier();
@ -566,7 +567,7 @@ public class Parser implements IParser
if (LT(1) == IToken.tASSIGN) // optional = type-id if (LT(1) == IToken.tASSIGN) // optional = type-id
{ {
consume(IToken.tASSIGN); consume(IToken.tASSIGN);
optionalTypeId = typeId(); optionalTypeId = typeId(scope, false);
} }
} }
@ -601,7 +602,7 @@ public class Parser implements IParser
wrapper.isConst(), wrapper.isConst(),
wrapper.isVolatile(), wrapper.isVolatile(),
wrapper.getTypeSpecifier(), wrapper.getTypeSpecifier(),
declarator.getPtrOps(), declarator.getPointerOperators(),
declarator.getArrayModifiers(), declarator.getArrayModifiers(),
null, null, declarator.getName() == null null, null, declarator.getName() == null
? "" ? ""
@ -1732,7 +1733,7 @@ public class Parser implements IParser
* @throws Backtrack * @throws Backtrack
*/ */
protected IToken cvQualifier( protected IToken cvQualifier(
Declarator declarator) IDeclarator declarator)
throws Backtrack throws Backtrack
{ {
IToken result = null; IToken result = null;
@ -1740,17 +1741,17 @@ public class Parser implements IParser
{ {
case IToken.t_const : case IToken.t_const :
result = consume( IToken.t_const ); result = consume( IToken.t_const );
if( declarator != null ) declarator.addPtrOp(ASTPointerOperator.CONST_POINTER); declarator.addPointerOperator(ASTPointerOperator.CONST_POINTER);
break; break;
case IToken.t_volatile : case IToken.t_volatile :
result = consume( IToken.t_volatile ); result = consume( IToken.t_volatile );
if( declarator != null ) declarator.addPtrOp(ASTPointerOperator.VOLATILE_POINTER); declarator.addPointerOperator(ASTPointerOperator.VOLATILE_POINTER);
break; break;
case IToken.t_restrict : case IToken.t_restrict :
if( language == ParserLanguage.C ) if( language == ParserLanguage.C )
{ {
result = consume( IToken.t_restrict ); result = consume( IToken.t_restrict );
if( declarator != null ) declarator.addPtrOp(ASTPointerOperator.RESTRICT_POINTER); declarator.addPointerOperator(ASTPointerOperator.RESTRICT_POINTER);
break; break;
} }
else else
@ -1882,7 +1883,7 @@ public class Parser implements IParser
{ {
d = new Declarator(owner); d = new Declarator(owner);
consumePointerOperators(d, false); consumePointerOperators(d);
if (LT(1) == IToken.tLPAREN) if (LT(1) == IToken.tLPAREN)
{ {
@ -2014,7 +2015,7 @@ public class Parser implements IParser
consume(); // throw consume(); // throw
consume(IToken.tLPAREN); // ( consume(IToken.tLPAREN); // (
boolean done = false; boolean done = false;
ITokenDuple duple = null; IASTTypeId duple = null;
while (!done) while (!done)
{ {
switch (LT(1)) switch (LT(1))
@ -2030,7 +2031,7 @@ public class Parser implements IParser
String image = LA(1).getImage(); String image = LA(1).getImage();
try try
{ {
duple = typeId(); duple = typeId(scope, false);
exceptionSpecIds.add(duple); exceptionSpecIds.add(duple);
} }
catch (Backtrack e) catch (Backtrack e)
@ -2120,21 +2121,7 @@ public class Parser implements IParser
} }
break; break;
case IToken.tLBRACKET : case IToken.tLBRACKET :
while (LT(1) == IToken.tLBRACKET) consumeArrayModifiers(d, sdw.getScope());
{
consume(); // eat the '['
IASTExpression exp = null;
if (LT(1) != IToken.tRBRACKET)
{
exp = constantExpression(sdw.getScope());
}
consume(IToken.tRBRACKET);
IASTArrayModifier arrayMod =
astFactory.createArrayModifier(exp);
d.addArrayModifier(arrayMod);
}
continue; continue;
case IToken.tCOLON : case IToken.tCOLON :
consume(IToken.tCOLON); consume(IToken.tCOLON);
@ -2151,10 +2138,30 @@ public class Parser implements IParser
} }
while (true); while (true);
if (d.getOwner() instanceof Declarator) if (d.getOwner() instanceof IDeclarator)
((Declarator)d.getOwner()).setOwnedDeclarator(d); ((Declarator)d.getOwner()).setOwnedDeclarator(d);
return d; return d;
} }
protected void consumeArrayModifiers( IDeclarator d, IASTScope scope )
throws EndOfFile, Backtrack
{
while (LT(1) == IToken.tLBRACKET)
{
consume( IToken.tLBRACKET ); // eat the '['
IASTExpression exp = null;
if (LT(1) != IToken.tRBRACKET)
{
exp = constantExpression(scope);
}
consume(IToken.tRBRACKET);
IASTArrayModifier arrayMod =
astFactory.createArrayModifier(exp);
d.addArrayModifier(arrayMod);
}
}
protected void operatorId( protected void operatorId(
Declarator d, Declarator d,
IToken originalToken) IToken originalToken)
@ -2195,21 +2202,8 @@ public class Parser implements IParser
else else
{ {
// must be a conversion function // must be a conversion function
toSend = typeId().getLastToken(); typeId(d.getDeclarationWrapper().getScope(), false );
toSend = lastToken;
try
{
// this ptrOp doesn't belong to the declarator,
// it's just a part of the name
IToken temp = consumePointerOperators(d, true);
if( temp != null )
toSend = temp;
}
catch (Backtrack b)
{
}
// In case we'll need better error recovery
// while( LT(1) != Token.tLPAREN ) { toSend = consume(); }
} }
ITokenDuple duple = ITokenDuple duple =
new TokenDuple( new TokenDuple(
@ -2229,7 +2223,7 @@ public class Parser implements IParser
* @param owner Declarator that this pointer operator corresponds to. * @param owner Declarator that this pointer operator corresponds to.
* @throws Backtrack request a backtrack * @throws Backtrack request a backtrack
*/ */
protected IToken consumePointerOperators(Declarator d, boolean consumeOnlyOne) throws Backtrack protected IToken consumePointerOperators(IDeclarator d) throws Backtrack
{ {
IToken result = null; IToken result = null;
for( ; ; ) for( ; ; )
@ -2237,9 +2231,9 @@ public class Parser implements IParser
if (LT(1) == IToken.tAMPER) if (LT(1) == IToken.tAMPER)
{ {
result = consume( IToken.tAMPER ); result = consume( IToken.tAMPER );
if( d != null ) d.addPtrOp(ASTPointerOperator.REFERENCE); d.addPointerOperator(ASTPointerOperator.REFERENCE);
/*if( consumeOnlyOne ) */return result; return result;
/* continue; */
} }
IToken mark = mark(); IToken mark = mark();
@ -2260,7 +2254,7 @@ public class Parser implements IParser
{ {
result = consume(Token.tSTAR); // tokenType = "*" result = consume(Token.tSTAR); // tokenType = "*"
if( d != null ) d.setPointerOperatorName(nameDuple); d.setPointerOperatorName(nameDuple);
IToken successful = null; IToken successful = null;
for (;;) for (;;)
@ -2273,9 +2267,8 @@ public class Parser implements IParser
if( successful == null ) if( successful == null )
{ {
if( d != null ) d.addPtrOp( ASTPointerOperator.POINTER ); d.addPointerOperator( ASTPointerOperator.POINTER );
} }
if( consumeOnlyOne ) return result;
continue; continue;
} }
backup(mark); backup(mark);
@ -2871,7 +2864,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -2972,7 +2965,7 @@ public class Parser implements IParser
assignmentExpression, assignmentExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3005,7 +2998,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3037,7 +3030,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
thirdExpression, thirdExpression,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3071,7 +3064,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3103,7 +3096,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3136,7 +3129,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3169,7 +3162,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3201,7 +3194,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3241,7 +3234,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3317,7 +3310,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3360,7 +3353,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3402,7 +3395,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3455,7 +3448,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3496,7 +3489,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3521,13 +3514,11 @@ public class Parser implements IParser
{ {
IToken mark = mark(); IToken mark = mark();
consume(); consume();
ITokenDuple duple = null; IASTTypeId typeId = null;
// If this isn't a type name, then we shouldn't be here // If this isn't a type name, then we shouldn't be here
try try
{ {
if (LT(1) == IToken.t_const) typeId = typeId(scope, false);
consume();
duple = typeId();
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
IASTExpression castExpression = castExpression(scope); IASTExpression castExpression = castExpression(scope);
try try
@ -3538,8 +3529,8 @@ public class Parser implements IParser
castExpression, castExpression,
null, null,
null, null,
duple, typeId,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3558,56 +3549,119 @@ public class Parser implements IParser
/** /**
* @throws Backtrack * @throws Backtrack
*/ */
protected ITokenDuple typeId( ) throws Backtrack protected IASTTypeId typeId(IASTScope scope, boolean forNewExpression ) throws Backtrack
{ {
IToken begin = LA(1); IToken mark = mark();
IToken end = null; ITokenDuple name = null;
try boolean isConst = false, isVolatile = false;
{ boolean isSigned = false, isUnsigned = false;
ITokenDuple d = name(); boolean isShort = false, isLong = false;
IToken checkForPtrs = consumePointerOperators(null, false); boolean isTypename = false;
if( checkForPtrs == null ) return d;
return new TokenDuple( d.getFirstToken(), checkForPtrs ); IASTSimpleTypeSpecifier.Type kind = null;
} do
catch (Backtrack b) {
{ try
{
name = name();
kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
break;
}
catch (Backtrack b)
{
// do nothing
}
simpleMods : for (;;) simpleMods : for (;;)
{ {
switch (LT(1)) switch (LT(1))
{ {
case IToken.t_signed : case IToken.t_signed :
consume();
isSigned = true;
break;
case IToken.t_unsigned : case IToken.t_unsigned :
consume();
isUnsigned = true;
break;
case IToken.t_short : case IToken.t_short :
consume();
isShort = true;
break;
case IToken.t_long : case IToken.t_long :
consume();
isLong = true;
break;
case IToken.t_const : case IToken.t_const :
consume();
isConst = true;
break;
case IToken.t_volatile : case IToken.t_volatile :
end = consume(); consume();
isVolatile = true;
break; break;
case IToken.tAMPER :
case IToken.tSTAR :
case IToken.tIDENTIFIER : case IToken.tIDENTIFIER :
if (end == null) name = name();
throw backtrack; kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
end = consume(); break simpleMods;
break;
case IToken.t_int : case IToken.t_int :
kind = IASTSimpleTypeSpecifier.Type.INT;
consume();
break simpleMods;
case IToken.t_char : case IToken.t_char :
kind = IASTSimpleTypeSpecifier.Type.CHAR;
consume();
break simpleMods;
case IToken.t_bool : case IToken.t_bool :
kind = IASTSimpleTypeSpecifier.Type.BOOL;
consume();
break simpleMods;
case IToken.t_double : case IToken.t_double :
kind = IASTSimpleTypeSpecifier.Type.DOUBLE;
consume();
break simpleMods;
case IToken.t_float : case IToken.t_float :
kind = IASTSimpleTypeSpecifier.Type.FLOAT;
consume();
break simpleMods;
case IToken.t_wchar_t : case IToken.t_wchar_t :
kind = IASTSimpleTypeSpecifier.Type.WCHAR_T;
consume();
break simpleMods;
case IToken.t_void : case IToken.t_void :
end = consume(); kind = IASTSimpleTypeSpecifier.Type.VOID;
consume();
break simpleMods;
default : default :
break simpleMods; break simpleMods;
} }
} }
if (end != null)
{ if( kind != null ) break;
IToken end2 = consumePointerOperators(null, false);
return new TokenDuple(begin, end2 == null ? end : end2); if( isShort || isLong || isUnsigned || isSigned )
} {
else if ( kind = IASTSimpleTypeSpecifier.Type.INT;
break;
}
if (
LT(1) == IToken.t_typename LT(1) == IToken.t_typename
|| LT(1) == IToken.t_struct || LT(1) == IToken.t_struct
|| LT(1) == IToken.t_class || LT(1) == IToken.t_class
@ -3615,12 +3669,42 @@ public class Parser implements IParser
|| LT(1) == IToken.t_union) || LT(1) == IToken.t_union)
{ {
consume(); consume();
ITokenDuple d = name(); try
IToken end2 = consumePointerOperators(null, false); {
return new TokenDuple(begin, ( (end2 == null) ? d.getLastToken() : end2 ) ); name = name();
kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
} catch( Backtrack b )
{
backup( mark );
throw backtrack;
}
} }
else
throw backtrack; } while( false );
if( kind == null )
throw backtrack;
TypeId id = new TypeId();
IToken last = mark();
consumePointerOperators( id );
if( lastToken == null ) lastToken = last;
if( ! forNewExpression )
{
last = mark();
consumeArrayModifiers( id, scope );
if( lastToken == null ) lastToken = last;
}
try
{
return astFactory.createTypeId( scope, kind, isConst, isVolatile, isShort, isLong, isSigned, isUnsigned, isTypename, name, id.getPointerOperators(), id.getArrayModifiers());
}
catch (ASTSemanticException e)
{
backup( mark );
throw backtrack;
} }
} }
/** /**
@ -3656,7 +3740,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3692,7 +3776,7 @@ public class Parser implements IParser
boolean placementParseFailure = true; boolean placementParseFailure = true;
IToken beforeSecondParen = null; IToken beforeSecondParen = null;
IToken backtrackMarker = null; IToken backtrackMarker = null;
ITokenDuple typeId = null; IASTTypeId typeId = null;
ArrayList newPlacementExpressions = new ArrayList(); ArrayList newPlacementExpressions = new ArrayList();
ArrayList newTypeIdExpressions = new ArrayList(); ArrayList newTypeIdExpressions = new ArrayList();
ArrayList newInitializerExpressions = new ArrayList(); ArrayList newInitializerExpressions = new ArrayList();
@ -3724,7 +3808,7 @@ public class Parser implements IParser
// CASE: new (typeid-not-looking-as-placement) ... // CASE: new (typeid-not-looking-as-placement) ...
// the first expression in () is not a placement // the first expression in () is not a placement
// - then it has to be typeId // - then it has to be typeId
typeId = typeId(); typeId = typeId(scope, true );
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
} }
else else
@ -3748,7 +3832,7 @@ public class Parser implements IParser
try try
{ {
backtrackMarker = mark(); backtrackMarker = mark();
typeId = typeId(); typeId = typeId(scope, true);
} }
catch (Backtrack e) catch (Backtrack e)
{ {
@ -3767,7 +3851,7 @@ public class Parser implements IParser
// The problem is, the first expression might as well be a typeid // The problem is, the first expression might as well be a typeid
try try
{ {
typeId = typeId(); typeId = typeId(scope, true);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
if (LT(1) == IToken.tLPAREN if (LT(1) == IToken.tLPAREN
|| LT(1) == IToken.tLBRACKET) || LT(1) == IToken.tLBRACKET)
@ -3788,8 +3872,8 @@ public class Parser implements IParser
{ {
return astFactory.createExpression( return astFactory.createExpression(
scope, IASTExpression.Kind.NEW_TYPEID, scope, IASTExpression.Kind.NEW_TYPEID,
null, null, null, typeId, "", null, null, null, typeId, null,
astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions)); "", astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions));
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3812,7 +3896,7 @@ public class Parser implements IParser
// CASE: new typeid ... // CASE: new typeid ...
// new parameters do not start with '(' // new parameters do not start with '('
// i.e it has to be a plain typeId // i.e it has to be a plain typeId
typeId = typeId(); typeId = typeId(scope, true);
} }
while (LT(1) == IToken.tLBRACKET) while (LT(1) == IToken.tLBRACKET)
{ {
@ -3833,8 +3917,8 @@ public class Parser implements IParser
{ {
return astFactory.createExpression( return astFactory.createExpression(
scope, IASTExpression.Kind.NEW_TYPEID, scope, IASTExpression.Kind.NEW_TYPEID,
null, null, null, typeId, "", null, null, null, typeId, null,
astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions)); "", astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions));
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3856,7 +3940,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3908,14 +3992,14 @@ public class Parser implements IParser
case IToken.t_sizeof : case IToken.t_sizeof :
consume(IToken.t_sizeof); consume(IToken.t_sizeof);
IToken mark = LA(1); IToken mark = LA(1);
ITokenDuple d = null; IASTTypeId d = null;
IASTExpression unaryExpression = null; IASTExpression unaryExpression = null;
if (LT(1) == IToken.tLPAREN) if (LT(1) == IToken.tLPAREN)
{ {
try try
{ {
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
d = typeId(); d = typeId(scope, false);
consume(IToken.tRPAREN); consume(IToken.tRPAREN);
} }
catch (Backtrack bt) catch (Backtrack bt)
@ -3938,7 +4022,7 @@ public class Parser implements IParser
null, null,
null, null,
d, d,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -3955,7 +4039,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e1) catch (ASTSemanticException e1)
{ {
@ -4072,10 +4156,10 @@ public class Parser implements IParser
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
boolean isTypeId = true; boolean isTypeId = true;
IASTExpression lhs = null; IASTExpression lhs = null;
ITokenDuple typeId = null; IASTTypeId typeId = null;
try try
{ {
typeId = typeId(); typeId = typeId(scope, false);
} }
catch (Backtrack b) catch (Backtrack b)
{ {
@ -4095,7 +4179,7 @@ public class Parser implements IParser
null, null,
null, null,
typeId, typeId,
"", null); null, "", null);
} }
catch (ASTSemanticException e6) catch (ASTSemanticException e6)
{ {
@ -4126,7 +4210,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e2) catch (ASTSemanticException e2)
{ {
@ -4149,7 +4233,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e3) catch (ASTSemanticException e3)
{ {
@ -4169,7 +4253,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e1) catch (ASTSemanticException e1)
{ {
@ -4189,7 +4273,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e4) catch (ASTSemanticException e4)
{ {
@ -4218,7 +4302,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e5) catch (ASTSemanticException e5)
{ {
@ -4247,7 +4331,7 @@ public class Parser implements IParser
secondExpression, secondExpression,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -4266,7 +4350,7 @@ public class Parser implements IParser
{ {
consume(); consume();
consume(IToken.tLT); consume(IToken.tLT);
ITokenDuple duple = typeId(); IASTTypeId duple = typeId(scope, false);
consume(IToken.tGT); consume(IToken.tGT);
consume(IToken.tLPAREN); consume(IToken.tLPAREN);
IASTExpression lhs = expression(scope); IASTExpression lhs = expression(scope);
@ -4280,7 +4364,7 @@ public class Parser implements IParser
null, null,
null, null,
duple, duple,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -4305,7 +4389,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {
@ -4335,7 +4419,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
t.getImage(), null); null, t.getImage(), null);
} }
catch (ASTSemanticException e1) catch (ASTSemanticException e1)
{ {
@ -4353,7 +4437,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
t.getImage(), null); null, t.getImage(), null);
} }
catch (ASTSemanticException e2) catch (ASTSemanticException e2)
{ {
@ -4365,7 +4449,7 @@ public class Parser implements IParser
t = consume(); t = consume();
try try
{ {
return astFactory.createExpression( scope, IASTExpression.Kind.PRIMARY_STRING_LITERAL, null, null, null, null, t.getImage(), null ); return astFactory.createExpression( scope, IASTExpression.Kind.PRIMARY_STRING_LITERAL, null, null, null, null, null, t.getImage(), null );
} }
catch (ASTSemanticException e5) catch (ASTSemanticException e5)
{ {
@ -4385,7 +4469,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
t.getImage(), null); null, t.getImage(), null);
} }
catch (ASTSemanticException e3) catch (ASTSemanticException e3)
{ {
@ -4406,7 +4490,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
t.getImage(), null); null, t.getImage(), null);
} }
catch (ASTSemanticException e4) catch (ASTSemanticException e4)
{ {
@ -4425,7 +4509,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e7) catch (ASTSemanticException e7)
{ {
@ -4445,7 +4529,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e6) catch (ASTSemanticException e6)
{ {
@ -4454,7 +4538,7 @@ public class Parser implements IParser
} }
case IToken.tIDENTIFIER : case IToken.tIDENTIFIER :
case IToken.tCOLONCOLON : case IToken.tCOLONCOLON :
ITokenDuple duple = name(); ITokenDuple duple = name();
//TODO should be an ID Expression really //TODO should be an ID Expression really
try try
{ {
@ -4464,8 +4548,8 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
duple, null,
"", null); duple, "", null);
} }
catch (ASTSemanticException e8) catch (ASTSemanticException e8)
{ {
@ -4482,7 +4566,7 @@ public class Parser implements IParser
null, null,
null, null,
null, null,
"", null); null, "", null);
} }
catch (ASTSemanticException e) catch (ASTSemanticException e)
{ {

View file

@ -0,0 +1,79 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.IASTArrayModifier;
/**
* @author jcamelon
*
*/
public class TypeId implements IDeclarator
{
private ITokenDuple name;
private List arrayModifiers = new ArrayList();
private List pointerOperators = new ArrayList();
/**
*
*/
public TypeId()
{
super();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#getPointerOperators()
*/
public List getPointerOperators()
{
return pointerOperators;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#addPointerOperator(org.eclipse.cdt.core.parser.ast.ASTPointerOperator)
*/
public void addPointerOperator(ASTPointerOperator ptrOp)
{
pointerOperators.add( ptrOp );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#addArrayModifier(org.eclipse.cdt.core.parser.ast.IASTArrayModifier)
*/
public void addArrayModifier(IASTArrayModifier arrayMod)
{
arrayModifiers.add( arrayMod );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#getArrayModifiers()
*/
public List getArrayModifiers()
{
return arrayModifiers;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#setPointerOperatorName(org.eclipse.cdt.core.parser.ITokenDuple)
*/
public void setPointerOperatorName(ITokenDuple nameDuple)
{
name = nameDuple;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IDeclarator#getPointerOperatorNameDuple()
*/
public ITokenDuple getPointerOperatorNameDuple()
{
return name;
}
}

View file

@ -11,12 +11,16 @@
package org.eclipse.cdt.internal.core.parser.ast.complete; package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.ExpressionEvaluationException; import org.eclipse.cdt.core.parser.ast.ExpressionEvaluationException;
import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTReference;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
/** /**
* @author jcamelon * @author jcamelon
@ -28,8 +32,9 @@ public class ASTExpression implements IASTExpression
private final IASTExpression lhs; private final IASTExpression lhs;
private final IASTExpression rhs; private final IASTExpression rhs;
private final IASTExpression thirdExpression; private final IASTExpression thirdExpression;
private final String literal; private final String literal, idExpression;
private final ITokenDuple typeId; private ITokenDuple idExpressionDuple;
private final IASTTypeId typeId;
private final IASTNewExpressionDescriptor newDescriptor; private final IASTNewExpressionDescriptor newDescriptor;
private final List references; private final List references;
private List resultType; private List resultType;
@ -37,7 +42,7 @@ public class ASTExpression implements IASTExpression
* *
*/ */
public ASTExpression( Kind kind, IASTExpression lhs, IASTExpression rhs, public ASTExpression( Kind kind, IASTExpression lhs, IASTExpression rhs,
IASTExpression thirdExpression, ITokenDuple typeId, String literal, IASTNewExpressionDescriptor newDescriptor, List references ) IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor, List references )
{ {
this.kind = kind; this.kind = kind;
this.lhs = lhs; this.lhs = lhs;
@ -48,6 +53,8 @@ public class ASTExpression implements IASTExpression
this.newDescriptor = newDescriptor; this.newDescriptor = newDescriptor;
this.references = references; this.references = references;
resultType = new ArrayList(); resultType = new ArrayList();
this.idExpressionDuple = idExpression;
this.idExpression = idExpressionDuple == null ? "" : idExpressionDuple.toString();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getExpressionKind() * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getExpressionKind()
@ -87,16 +94,17 @@ public class ASTExpression implements IASTExpression
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId() * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/ */
public String getTypeIdString() public IASTTypeId getTypeId()
{ {
return typeId == null ? "" : typeId.toString(); return typeId;
} }
/* /*
* returns the type id token * returns the type id token
*/ */
public ITokenDuple getTypeId() public ITokenDuple getTypeIdTokenDuple()
{ {
return typeId; if( typeId == null ) return null;
return ((ASTTypeId)typeId).getTokenDuple();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor() * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor()
@ -122,12 +130,33 @@ public class ASTExpression implements IASTExpression
*/ */
public void acceptElement(ISourceElementRequestor requestor) public void acceptElement(ISourceElementRequestor requestor)
{ {
try
{
reconcileReferences();
}
catch (ASTNotImplementedException e)
{
// will not get thrown
}
if( ! references.isEmpty() ) if( ! references.isEmpty() )
{ new ASTReferenceStore( references ).processReferences(requestor);
ASTReferenceStore store = new ASTReferenceStore( references );
store.processReferences(requestor); if( typeId != null )
} typeId.acceptElement(requestor);
if( lhs != null )
lhs.acceptElement(requestor);
if( rhs!= null )
rhs.acceptElement(requestor);
if( thirdExpression != null )
thirdExpression.acceptElement(requestor);
if( newDescriptor != null )
newDescriptor.acceptElement(requestor);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/ */
@ -154,5 +183,48 @@ public class ASTExpression implements IASTExpression
public void setResultType(List i) { public void setResultType(List i) {
resultType = i; resultType = i;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getIdExpression()
*/
public String getIdExpression()
{
return idExpression;
}
/**
* @return
*/
public ITokenDuple getIdExpressionTokenDuple()
{
return idExpressionDuple;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences()
*/
public void reconcileReferences() throws ASTNotImplementedException
{
if( lhs != null )
lhs.reconcileReferences();
if( rhs != null )
rhs.reconcileReferences();
if( thirdExpression != null )
thirdExpression.reconcileReferences();
reconcileSubExpression((ASTExpression)lhs);
reconcileSubExpression((ASTExpression)rhs);
reconcileSubExpression((ASTExpression)thirdExpression);
}
protected void reconcileSubExpression(ASTExpression subExpression)
{
if( subExpression != null && subExpression.getReferences() != null )
{
Iterator subExp = subExpression.getReferences().iterator();
while( subExp.hasNext() )
{
IASTReference aReference = (IASTReference)subExp.next();
if( aReference != null && references.contains( aReference ) )
subExp.remove();
}
}
}
} }

View file

@ -13,6 +13,8 @@ package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
/** /**
@ -47,4 +49,42 @@ public class ASTNewDescriptor implements IASTNewExpressionDescriptor {
return newInitializerExpressions.iterator(); return newInitializerExpressions.iterator();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void acceptElement(ISourceElementRequestor requestor)
{
accept( requestor, getNewPlacementExpressions() );
accept( requestor, getNewTypeIdExpressions() );
accept( requestor, getNewInitializerExpressions() );
}
/**
* @param requestor
* @param iterator
*/
protected void accept(ISourceElementRequestor requestor, Iterator iterator)
{
while( iterator.hasNext() )
((IASTExpression)iterator.next()).acceptElement(requestor);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void enterScope(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void exitScope(ISourceElementRequestor requestor)
{
}
} }

View file

@ -43,4 +43,17 @@ public abstract class ASTReference implements IASTReference
{ {
return name; return name;
} }
public boolean equals(Object obj)
{
if( obj == null )
return false;
if( ! (obj instanceof IASTReference ) )
return false;
if( ((IASTReference)obj).getName().equals( getName() ) &&
((IASTReference)obj).getOffset() == getOffset() )
return true;
return false;
}
} }

View file

@ -0,0 +1,229 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTArrayModifier;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
/**
* @author jcamelon
*
*/
public class ASTTypeId implements IASTTypeId
{
private final boolean isTypename;
private final boolean isUnsigned;
private final boolean isSigned;
private final boolean isShort;
private final boolean isLong;
private final boolean isVolatile;
private final boolean isConst;
private final String signature;
private ITokenDuple tokenDuple;
private final List arrayModifiers;
private final String typeName;
private final List pointerOps;
private final Type kind;
private List references = new ArrayList();
private ISymbol symbol;
/**
*
*/
public ASTTypeId( Type kind, ITokenDuple duple, List pointerOps, List arrayMods, String signature,
boolean isConst, boolean isVolatile, boolean isUnsigned, boolean isSigned, boolean isShort, boolean isLong, boolean isTypeName )
{
typeName = ( duple == null ) ? "" : duple.toString() ;
this.tokenDuple = duple;
this.kind = kind;
this.pointerOps = pointerOps;
this.arrayModifiers = arrayMods;
this.signature = signature;
this.isConst = isConst;
this.isVolatile = isVolatile;
this.isUnsigned = isUnsigned;
this.isSigned = isSigned;
this.isShort = isShort;
this.isLong = isLong;
this.isTypename = isTypeName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getKind()
*/
public Type getKind()
{
return kind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getType()
*/
public String getTypeOrClassName()
{
return typeName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getPointerOperators()
*/
public Iterator getPointerOperators()
{
return pointerOps.iterator();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getArrayModifiers()
*/
public Iterator getArrayModifiers()
{
return arrayModifiers.iterator();
}
public List getReferences()
{
return references;
}
public void finalize()
{
references.clear();
references = null;
tokenDuple = null;
}
public ITokenDuple getTokenDuple()
{
return tokenDuple;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getFullSignature()
*/
public String getFullSignature()
{
return signature;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#createTypeSymbol(org.eclipse.cdt.core.parser.ast.IASTFactory)
*/
public ISymbol getTypeSymbol() throws ASTNotImplementedException
{
return symbol;
}
public void setTypeSymbol( ISymbol symbol )
{
this.symbol = symbol;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isConst()
*/
public boolean isConst()
{
return isConst;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isVolatile()
*/
public boolean isVolatile()
{
return isVolatile;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isLong()
*/
public boolean isLong()
{
return isLong;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isShort()
*/
public boolean isShort()
{
return isShort;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isSigned()
*/
public boolean isSigned()
{
return isSigned;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isUnsigned()
*/
public boolean isUnsigned()
{
return isUnsigned;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isTypename()
*/
public boolean isTypename()
{
return isTypename;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void acceptElement(ISourceElementRequestor requestor)
{
if( references != null && ! references.isEmpty() )
{
ASTReferenceStore store = new ASTReferenceStore( references );
store.processReferences(requestor);
}
Iterator arrayMods = getArrayModifiers();
while( arrayMods.hasNext() )
{
((IASTArrayModifier)arrayMods.next()).acceptElement(requestor);
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void enterScope(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void exitScope(ISourceElementRequestor requestor)
{
}
/**
* @param list
*/
public void addReferences(List list)
{
references.addAll( list );
}
}

View file

@ -21,12 +21,12 @@ import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.ASTClassKind; import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.ASTSemanticException; import org.eclipse.cdt.core.parser.ast.ASTSemanticException;
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTArrayModifier;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope; import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
@ -53,6 +53,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
@ -101,6 +102,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
* Overrides an existing reference if it has the same name and offset * Overrides an existing reference if it has the same name and offset
*/ */
protected void addReference(List references, IASTReference reference){ protected void addReference(List references, IASTReference reference){
if( references == null ) return;
Iterator i = references.iterator(); Iterator i = references.iterator();
while (i.hasNext()){ while (i.hasNext()){
IASTReference ref = (IASTReference)i.next(); IASTReference ref = (IASTReference)i.next();
@ -758,40 +760,22 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
IASTExpression lhs, IASTExpression lhs,
IASTExpression rhs, IASTExpression rhs,
IASTExpression thirdExpression, IASTExpression thirdExpression,
ITokenDuple typeId, IASTTypeId typeId,
String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException
{ {
List references = new ArrayList(); List references = new ArrayList();
getExpressionReferences(lhs, references);
getExpressionReferences(rhs, references);
getExpressionReferences(thirdExpression,references);
// add newDescriptor's references & add to references
// if there is a newDescriptor, check related expressions
if(newDescriptor != null){
Iterator i = newDescriptor.getNewPlacementExpressions();
while (i.hasNext()){
getExpressionReferences((IASTExpression)i.next(), references);
}
i = newDescriptor.getNewTypeIdExpressions();
while (i.hasNext()){
getExpressionReferences((IASTExpression)i.next(), references);
}
i = newDescriptor.getNewInitializerExpressions();
while (i.hasNext()){
getExpressionReferences((IASTExpression)i.next(), references);
}
}
//look up id & add to references //look up id & add to references
IContainerSymbol startingScope = scopeToSymbol( scope ); IContainerSymbol startingScope = scopeToSymbol( scope );
//look up typeId & add to references //look up typeId & add to references
ISymbol symbol = null; ISymbol symbol = null;
if( typeId != null ){
symbol = lookupQualifiedName( startingScope, typeId, references, false ); if( idExpression != null )
} symbol = lookupQualifiedName( startingScope, idExpression, references, false );
// "a.m" or "a->m : lookup m in the scope of the declaration of a // "a.m" or "a->m : lookup m in the scope of the declaration of a
if((kind == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION) if((kind == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION)
|| (kind == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION) || (kind == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION)
@ -803,7 +787,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
TypeInfo lhsInfo = (TypeInfo) ((ASTExpression)lhs).getResultType().iterator().next(); TypeInfo lhsInfo = (TypeInfo) ((ASTExpression)lhs).getResultType().iterator().next();
ISymbol containingScope = (ISymbol) lhsInfo.getTypeSymbol().getTypeSymbol(); ISymbol containingScope = (ISymbol) lhsInfo.getTypeSymbol().getTypeSymbol();
if(containingScope != null){ if(containingScope != null){
symbol = lookupQualifiedName((IContainerSymbol)containingScope, ((ASTExpression)rhs).getTypeId() , references, false); symbol = lookupQualifiedName((IContainerSymbol)containingScope, ((ASTExpression)rhs).getIdExpressionTokenDuple(), references, false);
} }
} }
@ -819,13 +803,13 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
if (kind == IASTExpression.Kind.POSTFIX_FUNCTIONCALL){ if (kind == IASTExpression.Kind.POSTFIX_FUNCTIONCALL){
ITokenDuple functionId = ((ASTExpression)lhs).getTypeId(); ITokenDuple functionId = ((ASTExpression)lhs).getIdExpressionTokenDuple();
List parameters = ((ASTExpression)rhs).getResultType(); List parameters = ((ASTExpression)rhs).getResultType();
symbol = lookupQualifiedName(startingScope, functionId, TypeInfo.t_function, parameters, references, false); symbol = lookupQualifiedName(startingScope, functionId, TypeInfo.t_function, parameters, references, false);
} }
ASTExpression expression = new ASTExpression( kind, lhs, rhs, thirdExpression, ASTExpression expression = new ASTExpression( kind, lhs, rhs, thirdExpression,
typeId, literal, newDescriptor, references); typeId, idExpression, literal, newDescriptor, references);
expression.setResultType (getExpressionResultType(expression, symbol)); expression.setResultType (getExpressionResultType(expression, symbol));
@ -1048,9 +1032,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
// types that resolve to t_type, symbol already looked up in type id // 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); info.setType(TypeInfo.t_type);
info.setTypeSymbol(symbol); info.setTypeSymbol(symbol);
result.add(info); result.add(info);
@ -1067,6 +1050,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
result.add(info); result.add(info);
return result; return result;
} }
// a star implies a pointer operation of type pointer // a star implies a pointer operation of type pointer
if (expression.getExpressionKind() == IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION){ if (expression.getExpressionKind() == IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION){
List lhsResult = ((ASTExpression)expression.getLHSExpression()).getResultType(); List lhsResult = ((ASTExpression)expression.getLHSExpression()).getResultType();
@ -1141,17 +1125,23 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
} }
// new // new
/* if((expression.getExpressionKind() == IASTExpression.Kind.NEW_NEWTYPEID) if( expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID )
|| (expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID) {
){
if(symbol != null){ if(symbol != null){
info.setType(symbol.getType()); try
info.setTypeSymbol(symbol); {
info = expression.getTypeId().getTypeSymbol().getTypeInfo();
}
catch (ASTNotImplementedException e)
{
// will never happen
}
info.addOperatorExpression( TypeInfo.OperatorExpression.indirection);
result.add(info); result.add(info);
return result; return result;
} }
} }
*/ // types that use the usual arithmetic conversions // types that use the usual arithmetic conversions
if((expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY) if((expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY)
|| (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_DIVIDE) || (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_DIVIDE)
|| (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MODULUS) || (expression.getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MODULUS)
@ -1243,6 +1233,22 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
result.add(info); result.add(info);
return result; return result;
} }
if( expression.getExpressionKind() == IASTExpression.Kind.POSTFIX_TYPEID_TYPEID )
{
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; return result;
} }
@ -1273,10 +1279,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
Iterator iter =typeIds.iterator(); Iterator iter =typeIds.iterator();
while( iter.hasNext() ) while( iter.hasNext() )
{ {
ITokenDuple duple = (ITokenDuple)iter.next(); IASTTypeId duple = (IASTTypeId)iter.next();
if( duple != null ) if( duple != null )
{ {
lookupQualifiedName( scopeToSymbol( scope ), duple, references, false ); lookupQualifiedName( scopeToSymbol( scope ), ((ASTTypeId)duple).getTokenDuple(), references, false );
newTypeIds.add( duple.toString() ); newTypeIds.add( duple.toString() );
} }
} }
@ -1429,7 +1435,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
} }
String functionName = oneToken; String functionName = oneToken;
String parentName = name.substring(0, name.lastIndexOf(DOUBLE_COLON)); // String parentName = name.substring(0, name.lastIndexOf(DOUBLE_COLON));
int numOfTokens = 1; int numOfTokens = 1;
int offset = nameOffset; int offset = nameOffset;
@ -1688,7 +1694,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
while( arrayModsIterator.hasNext() ) while( arrayModsIterator.hasNext() )
{ {
IASTArrayModifier astArrayModifier = (IASTArrayModifier)arrayModsIterator.next(); arrayModsIterator.next();
symbol.addPtrOperator( new TypeInfo.PtrOp( TypeInfo.PtrOp.t_array )); symbol.addPtrOperator( new TypeInfo.PtrOp( TypeInfo.PtrOp.t_array ));
} }
} }
@ -2366,4 +2372,70 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
{ {
return new ASTParameterDeclaration( null, isConst, isVolatile, typeSpecifier, pointerOperators, arrayModifiers, parameters, pointerOp, parameterName, initializerClause, startingOffset, endingOffset, nameOffset ); return new ASTParameterDeclaration( null, isConst, isVolatile, typeSpecifier, pointerOperators, arrayModifiers, parameters, pointerOp, parameterName, initializerClause, startingOffset, endingOffset, nameOffset );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypeId(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type, org.eclipse.cdt.core.parser.ITokenDuple, java.util.List, java.util.List)
*/
public IASTTypeId createTypeId(IASTScope scope, Type kind, boolean isConst, boolean isVolatile, boolean isShort,
boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods) throws ASTSemanticException
{
ASTTypeId result =
new ASTTypeId( kind, name, pointerOps, arrayMods, "", //TODO
isConst, isVolatile, isUnsigned, isSigned, isShort, isLong, isTypename );
result.setTypeSymbol( createSymbolForTypeId( scope, result ) );
return result;
}
/**
* @param id
* @return
*/
public static TypeInfo.eType getTypeKind(IASTTypeId id)
{
IASTSimpleTypeSpecifier.Type type = id.getKind();
if( type == IASTSimpleTypeSpecifier.Type.BOOL )
return TypeInfo.t_bool;
else if( type == IASTSimpleTypeSpecifier.Type.CHAR )
return TypeInfo.t_char;
else if( type == IASTSimpleTypeSpecifier.Type.DOUBLE )
return TypeInfo.t_double;
else if( type == IASTSimpleTypeSpecifier.Type.FLOAT )
return TypeInfo.t_float;
else if( type == IASTSimpleTypeSpecifier.Type.INT )
return TypeInfo.t_int;
else if( type == IASTSimpleTypeSpecifier.Type.VOID )
return TypeInfo.t_void;
else if( id.isShort() || id.isLong() || id.isUnsigned() || id.isSigned() )
return TypeInfo.t_int;
else
return TypeInfo.t_type;
}
protected ISymbol createSymbolForTypeId( IASTScope scope, IASTTypeId id ) throws ASTSemanticException
{
if( id == null ) return null;
ASTTypeId typeId = (ASTTypeId)id;
ISymbol result = pst.newSymbol( "", CompleteParseASTFactory.getTypeKind(id));
result.getTypeInfo().setBit( id.isConst(), TypeInfo.isConst );
result.getTypeInfo().setBit( id.isVolatile(), TypeInfo.isVolatile );
result.getTypeInfo().setBit( id.isShort(), TypeInfo.isShort);
result.getTypeInfo().setBit( id.isLong(), TypeInfo.isLong);
result.getTypeInfo().setBit( id.isUnsigned(), TypeInfo.isUnsigned);
List refs = new ArrayList();
if( result.getType() == TypeInfo.t_type )
{
ISymbol typeSymbol = lookupQualifiedName( scopeToSymbol(scope), typeId.getTokenDuple(), refs, true );
if( typeSymbol.getType() == TypeInfo.t_type )
throw new ASTSemanticException();
result.setTypeSymbol( typeSymbol );
typeId.addReferences( refs );
}
setPointerOperators( result, id.getPointerOperators(), id.getArrayModifiers() );
return result;
}
} }

View file

@ -15,8 +15,8 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
/** /**
* @author jcamelon * @author jcamelon
@ -33,7 +33,7 @@ public class ASTExceptionSpecification implements IASTExceptionSpecification
Iterator i = typeIds.iterator(); Iterator i = typeIds.iterator();
this.typeIds = new ArrayList(); this.typeIds = new ArrayList();
while( i.hasNext() ) while( i.hasNext() )
this.typeIds.add( ((ITokenDuple)i.next()).toString() ); this.typeIds.add( ((IASTTypeId)i.next()).getTypeOrClassName());
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -7,8 +7,10 @@
package org.eclipse.cdt.internal.core.parser.ast.quick; package org.eclipse.cdt.internal.core.parser.ast.quick;
import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.ExpressionEvaluationException; import org.eclipse.cdt.core.parser.ast.ExpressionEvaluationException;
import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
@ -22,7 +24,8 @@ public class ASTExpression implements IASTExpression {
private final Kind kind; private final Kind kind;
private final IASTExpression lhs, rhs, third; private final IASTExpression lhs, rhs, third;
private final String typeId, literal; private final IASTTypeId typeId;
private final String literal, idExpression;
private final IASTNewExpressionDescriptor newDescriptor; private final IASTNewExpressionDescriptor newDescriptor;
/** /**
@ -33,7 +36,7 @@ public class ASTExpression implements IASTExpression {
* @param typeId * @param typeId
* @param literal * @param literal
*/ */
public ASTExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression third, String typeId, String literal, IASTNewExpressionDescriptor newDescriptor) { public ASTExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression third, IASTTypeId typeId, String idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) {
this.kind = kind; this.kind = kind;
this.lhs =lhs; this.lhs =lhs;
this.rhs = rhs; this.rhs = rhs;
@ -41,6 +44,7 @@ public class ASTExpression implements IASTExpression {
this.typeId = typeId; this.typeId = typeId;
this.literal = literal; this.literal = literal;
this.newDescriptor = newDescriptor; this.newDescriptor = newDescriptor;
this.idExpression = idExpression;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -74,7 +78,7 @@ public class ASTExpression implements IASTExpression {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId() * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId()
*/ */
public String getTypeIdString() { public IASTTypeId getTypeId() {
return typeId; return typeId;
} }
@ -176,6 +180,22 @@ public class ASTExpression implements IASTExpression {
{ {
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#getIdExpression()
*/
public String getIdExpression()
{
return idExpression;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences()
*/
public void reconcileReferences() throws ASTNotImplementedException
{
throw new ASTNotImplementedException();
}
} }

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.quick;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
/** /**
@ -44,4 +45,25 @@ public class ASTNewDescriptor implements IASTNewExpressionDescriptor {
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void acceptElement(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void enterScope(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void exitScope(ISourceElementRequestor requestor)
{
}
} }

View file

@ -0,0 +1,169 @@
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.ast.quick;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
/**
* @author jcamelon
*
*/
public class ASTTypeId implements IASTTypeId
{
private final boolean isVolatile;
private final boolean isUnsigned;
private final boolean isTypeName;
private final boolean isSigned;
private final boolean isShort;
private final boolean isLong;
private final boolean isConst;
private final Type kind;
private final String name;
private final List pointerOps;
private final List arrayMods;
/**
* @param kind
* @param string
* @param pointerOps
* @param arrayMods
*/
public ASTTypeId(Type kind, String string, List pointerOps, List arrayMods, boolean isConst, boolean isVolatile,
boolean isUnsigned, boolean isSigned, boolean isShort, boolean isLong, boolean isTypeName)
{
this.kind = kind;
this.name = string;
this.pointerOps = pointerOps;
this.arrayMods = arrayMods;
this.isVolatile =isVolatile;
this.isUnsigned =isUnsigned;
this.isTypeName =isTypeName;
this.isSigned =isSigned;
this.isShort =isShort;
this.isLong =isLong;
this.isConst =isConst;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getKind()
*/
public Type getKind()
{
return kind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getType()
*/
public String getTypeOrClassName()
{
return name;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getPointerOperators()
*/
public Iterator getPointerOperators()
{
return pointerOps.iterator();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getArrayModifiers()
*/
public Iterator getArrayModifiers()
{
return arrayMods.iterator();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getFullSignature()
*/
public String getFullSignature() throws ASTNotImplementedException
{
throw new ASTNotImplementedException();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#createTypeSymbol(org.eclipse.cdt.core.parser.ast.IASTFactory)
*/
public ISymbol getTypeSymbol() throws ASTNotImplementedException
{
throw new ASTNotImplementedException();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isConst()
*/
public boolean isConst()
{
return isConst;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isVolatile()
*/
public boolean isVolatile()
{
return isVolatile;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isLong()
*/
public boolean isLong()
{
return isLong;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isShort()
*/
public boolean isShort()
{
return isShort;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isSigned()
*/
public boolean isSigned()
{
return isSigned;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isUnsigned()
*/
public boolean isUnsigned()
{
return isUnsigned;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isTypename()
*/
public boolean isTypename()
{
return isTypeName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void acceptElement(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void enterScope(ISourceElementRequestor requestor)
{
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
*/
public void exitScope(ISourceElementRequestor requestor)
{
}
}

View file

@ -46,6 +46,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
import org.eclipse.cdt.core.parser.ast.IASTTypeId;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
@ -150,8 +151,8 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.ExpressionKind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.ExpressionKind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String)
*/ */
public IASTExpression createExpression(IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, ITokenDuple typeId, String literal, IASTNewExpressionDescriptor newDescriptor) { public IASTExpression createExpression(IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) {
return new ASTExpression( kind, lhs, rhs, thirdExpression, typeId == null ? "" : typeId.toString(), literal, newDescriptor ); return new ASTExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -296,4 +297,14 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
{ {
return new ASTParameterDeclaration( isConst, isVolatile, typeSpecifier, pointerOperators, arrayModifiers, parameters, pointerOp, parameterName, initializerClause, startingOffset, endingOffset, nameOffset ); return new ASTParameterDeclaration( isConst, isVolatile, typeSpecifier, pointerOperators, arrayModifiers, parameters, pointerOp, parameterName, initializerClause, startingOffset, endingOffset, nameOffset );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypeId(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type, org.eclipse.cdt.core.parser.ITokenDuple, java.util.List, java.util.List)
*/
public IASTTypeId createTypeId(IASTScope scope, Type kind, boolean isConst, boolean isVolatile, boolean isShort,
boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods)
{
return new ASTTypeId( kind, name == null ? "" : name.toString(), pointerOps, arrayMods, isConst,
isVolatile, isUnsigned, isSigned, isShort, isLong, isTypename );
}
} }