diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index c00bfb04500..e0bc910b1af 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,7 @@ +2003-08-13 John Camelon + Added testSimpleExpression(), testParameterExpressions() && + testNestedNamespaceExpression() to CompleteParseASTTest.java. + 2003-08-13 Sean Evoy Renamed the 'AllBuildTest' class to 'ManagedBuildTest' and updated the integration suite class. diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java index f08cd76c40b..0e57fb8aad1 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java @@ -193,6 +193,7 @@ public class CompleteParseASTTest extends TestCase public void exitFunctionBody(IASTFunction function) { popScope(); + getCurrentScope().addDeclaration(function); } /* (non-Javadoc) @@ -291,6 +292,7 @@ public class CompleteParseASTTest extends TestCase public void exitMethodBody(IASTMethod method) { popScope(); + getCurrentScope().addDeclaration(method); } /* (non-Javadoc) @@ -536,7 +538,7 @@ public class CompleteParseASTTest extends TestCase ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(), ParserMode.COMPLETE_PARSE, callback ), callback, ParserMode.COMPLETE_PARSE ); - parser.parse(); + if( ! parser.parse() ) throw new ParserException( "FAILURE"); return callback.getCompilationUnit(); } @@ -901,5 +903,30 @@ public class CompleteParseASTTest extends TestCase IASTFunction f2 = (IASTFunction)i.next(); assertFalse( i.hasNext() ); } - + + public void testSimpleExpression() throws Exception + { + Iterator i = parse( "int x; int y = x;").getDeclarations(); + IASTVariable varX = (IASTVariable)i.next(); + IASTVariable varY = (IASTVariable)i.next(); + assertEquals( callback.getReferences().size(), 1 ); + } + + public void testParameterExpressions() throws Exception + { + Iterator i = parse( "int x = 5; void foo( int sub = x ) { }").getDeclarations(); + IASTVariable varX = (IASTVariable)i.next(); + IASTFunction funFoo = (IASTFunction)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 1 ); + } + + public void testNestedNamespaceExpression() throws Exception + { + Iterator i = parse( "namespace A { int x = 666; } int y = A::x;").getDeclarations(); + IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)i.next(); + IASTVariable variableY = (IASTVariable)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java index 28346274eee..9807a895789 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java @@ -27,7 +27,7 @@ public class ExprEvalTest extends TestCase { final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor(); IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), null, new ScannerInfo(), null, nullCallback ), nullCallback, ParserMode.QUICK_PARSE); - IASTExpression expression = parser.expression(); + IASTExpression expression = parser.expression(null); assertEquals(expectedValue, expression.evaluateExpression()); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java index 6452dc10961..7bfa0e7e345 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java @@ -1429,7 +1429,7 @@ public class QuickParseASTTests extends BaseASTTest assertFalse( enumerators.hasNext() ); assertEquals( enumerator.getName(), "isPointer"); assertEquals( enumerator.getInitialValue().getExpressionKind(), IASTExpression.Kind.ID_EXPRESSION ); - assertEquals( enumerator.getInitialValue().getLiteralString(), "PointerTraits::result"); + assertEquals( enumerator.getInitialValue().getTypeId(), "PointerTraits::result"); } public void testBug36690() throws Exception { diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 7f6daf09af7..3d9e688006d 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,6 @@ +2003-08-13 John Camelon + Added Expression x-reference support into Parser. + 2003-08-12 John Camelon Added X-Ref/Elaborated type support w/element requestor callbacks. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java index 8d08ce939fe..1998f85ec8f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.core.parser; import org.eclipse.cdt.core.parser.ast.IASTExpression; +import org.eclipse.cdt.core.parser.ast.IASTScope; @@ -40,7 +41,7 @@ public interface IParser { * @throws Backtrack thrown if the Scanner/Stream provided does not yield a valid * expression */ - public IASTExpression expression() throws Backtrack; + public IASTExpression expression(IASTScope scope) throws Backtrack; /** * Is the parser configured for ANSI C or ANSI C++? diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java index d50ae2d3ab9..da88299dd6e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java @@ -11,12 +11,13 @@ package org.eclipse.cdt.core.parser.ast; import org.eclipse.cdt.core.parser.Enum; +import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; /** * @author jcamelon * */ -public interface IASTExpression +public interface IASTExpression extends ISourceElementCallbackDelegate { public class Kind extends Enum { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java index 11fad9d0021..7ce96cc20f0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.core.parser.ast; import java.util.List; +import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; @@ -88,14 +89,14 @@ public interface IASTFactory int startingOffset, int endingOffset, IASTExpression initialValue)throws ASTSemanticException; public IASTExpression createExpression( + IASTScope scope, IASTExpression.Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, - String id, - String typeId, - String literal, - IASTNewExpressionDescriptor newDescriptor); + IToken id, + ITokenDuple typeId, + String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException; public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(); public IASTInitializerClause createInitializerClause( IASTInitializerClause.Kind kind, diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java index 227324b241e..b6c00dba867 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java @@ -13,11 +13,12 @@ package org.eclipse.cdt.core.parser.ast; import java.util.Iterator; import org.eclipse.cdt.core.parser.Enum; +import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; /** * @author jcamelon */ -public interface IASTInitializerClause { +public interface IASTInitializerClause extends ISourceElementCallbackDelegate{ public class Kind extends Enum { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index faba2b5a609..088433b4f80 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -968,7 +968,7 @@ public class Parser implements IParser consume(IToken.tLPAREN); IASTExpression expressionList = null; - expressionList = expression(); + expressionList = expression(d.getDeclarationWrapper().getScope()); consume(IToken.tRPAREN); @@ -1001,7 +1001,7 @@ public class Parser implements IParser IToken current = LA(1); DeclarationWrapper sdw = - new DeclarationWrapper(null, current.getOffset(), null); + new DeclarationWrapper(scope, current.getOffset(), null); declSpecifierSeq(true, false, sdw); try { @@ -1712,14 +1712,14 @@ public class Parser implements IParser if (LT(1) == IToken.tASSIGN) { consume(IToken.tASSIGN); - d.setInitializerClause(initializerClause()); + d.setInitializerClause(initializerClause(sdw.getScope())); } else if (LT(1) == IToken.tLPAREN) { // initializer in constructor consume(IToken.tLPAREN); // EAT IT! IASTExpression astExpression = null; - astExpression = expression(); + astExpression = expression(sdw.getScope()); consume(IToken.tRPAREN); d.setConstructorExpression(astExpression); } @@ -1729,7 +1729,7 @@ public class Parser implements IParser /** * */ - protected IASTInitializerClause initializerClause() + protected IASTInitializerClause initializerClause(IASTScope scope) throws Backtrack { if (LT(1) == IToken.tLBRACE) @@ -1748,7 +1748,7 @@ public class Parser implements IParser List initializerClauses = new ArrayList(); for (;;) { - IASTInitializerClause clause = initializerClause(); + IASTInitializerClause clause = initializerClause(scope); initializerClauses.add(clause); if (LT(1) == IToken.tRBRACE) break; @@ -1767,7 +1767,7 @@ public class Parser implements IParser IToken marked = mark(); IASTExpression assignmentExpression = - assignmentExpression(); + assignmentExpression(scope); return astFactory.createInitializerClause( IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION, @@ -1876,6 +1876,7 @@ public class Parser implements IParser { // parameterDeclarationClause d.setIsFunction(true); + // TODO need to create a temporary scope object here consume(); boolean seenParameter = false; parameterDeclarationLoop : for (;;) @@ -2031,7 +2032,7 @@ public class Parser implements IParser IASTExpression exp = null; if (LT(1) != IToken.tRBRACKET) { - exp = constantExpression(); + exp = constantExpression(sdw.getScope()); } consume(IToken.tRBRACKET); IASTArrayModifier arrayMod = @@ -2043,7 +2044,7 @@ public class Parser implements IParser case IToken.tCOLON : consume(IToken.tCOLON); IASTExpression exp = null; - exp = constantExpression(); + exp = constantExpression(scope); d.setBitFieldExpression(exp); default : break; @@ -2237,7 +2238,7 @@ public class Parser implements IParser if (LT(1) == IToken.tASSIGN) { consume(IToken.tASSIGN); - initialValue = constantExpression(); + initialValue = constantExpression(sdw.getScope()); } if (LT(1) == IToken.tRBRACE) @@ -2509,21 +2510,21 @@ public class Parser implements IParser * * @throws Backtrack request a backtrack */ - protected void statement() throws Backtrack + protected void statement(IASTScope scope) throws Backtrack { switch (LT(1)) { case IToken.t_case : consume(); - constantExpression(); + constantExpression(scope); consume(IToken.tCOLON); - statement(); + statement(null); return; case IToken.t_default : consume(); consume(IToken.tCOLON); - statement(); + statement(null); return; case IToken.tLBRACE : compoundStatement(); @@ -2533,11 +2534,11 @@ public class Parser implements IParser consume(IToken.tLPAREN); condition(); consume(IToken.tRPAREN); - statement(); + statement(null); if (LT(1) == IToken.t_else) { consume(); - statement(); + statement(null); } return; case IToken.t_switch : @@ -2545,18 +2546,18 @@ public class Parser implements IParser consume(IToken.tLPAREN); condition(); consume(IToken.tRPAREN); - statement(); + statement(null); return; case IToken.t_while : consume(); consume(IToken.tLPAREN); condition(); consume(IToken.tRPAREN); - statement(); + statement(null); return; case IToken.t_do : consume(); - statement(); + statement(null); consume(IToken.t_while); consume(IToken.tLPAREN); condition(); @@ -2572,10 +2573,10 @@ public class Parser implements IParser if (LT(1) != IToken.tRPAREN) { //TODO get rid of NULL - expression(); + expression(scope); } consume(IToken.tRPAREN); - statement(); + statement(null); return; case IToken.t_break : consume(); @@ -2590,7 +2591,7 @@ public class Parser implements IParser if (LT(1) != IToken.tSEMI) { //TODO get rid of NULL - expression(); + expression(scope); } consume(IToken.tSEMI); return; @@ -2621,7 +2622,7 @@ public class Parser implements IParser { consume(); consume(); - statement(); + statement(null); return; } // expressionStatement @@ -2629,7 +2630,7 @@ public class Parser implements IParser // Since it only happens when we are in a statement try { - expression(); + expression(scope); consume(IToken.tSEMI); return; } @@ -2661,38 +2662,46 @@ public class Parser implements IParser { consume(IToken.tLBRACE); while (LT(1) != IToken.tRBRACE) - statement(); + statement(null); consume(); } /** * @param expression * @throws Backtrack */ - protected IASTExpression constantExpression() + protected IASTExpression constantExpression( IASTScope scope ) throws Backtrack { - return conditionalExpression(); + return conditionalExpression(scope); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParser#expression(java.lang.Object) */ - public IASTExpression expression() throws Backtrack + public IASTExpression expression(IASTScope scope) throws Backtrack { - IASTExpression assignmentExpression = assignmentExpression(); + IASTExpression assignmentExpression = assignmentExpression(scope); while (LT(1) == IToken.tCOMMA) { IToken t = consume(); - IASTExpression secondExpression = assignmentExpression(); - assignmentExpression = - astFactory.createExpression( - IASTExpression.Kind.EXPRESSIONLIST, - assignmentExpression, - secondExpression, - null, - "", - "", - "", - null); + IASTExpression secondExpression = assignmentExpression(scope); + try + { + assignmentExpression = + astFactory.createExpression( + scope, + IASTExpression.Kind.EXPRESSIONLIST, + assignmentExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } return assignmentExpression; } @@ -2700,15 +2709,15 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression assignmentExpression() + protected IASTExpression assignmentExpression( IASTScope scope ) throws Backtrack { if (LT(1) == IToken.t_throw) { - return throwExpression(); + return throwExpression(scope); } IASTExpression conditionalExpression = - conditionalExpression(); + conditionalExpression(scope); // if the condition not taken, try assignment operators if (conditionalExpression != null && conditionalExpression.getExpressionKind() @@ -2717,108 +2726,133 @@ public class Parser implements IParser switch (LT(1)) { case IToken.tASSIGN : - return assignmentOperatorExpression( + return assignmentOperatorExpression( scope, IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL); case IToken.tSTARASSIGN : - return assignmentOperatorExpression( + return assignmentOperatorExpression(scope, IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT); case IToken.tDIVASSIGN : - return assignmentOperatorExpression( + return assignmentOperatorExpression(scope, IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV); case IToken.tMODASSIGN : - return assignmentOperatorExpression( + return assignmentOperatorExpression(scope, IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD); case IToken.tPLUSASSIGN : - return assignmentOperatorExpression( + return assignmentOperatorExpression(scope, IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS); case IToken.tMINUSASSIGN : - return assignmentOperatorExpression( + return assignmentOperatorExpression(scope, IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS); case IToken.tSHIFTRASSIGN : - return assignmentOperatorExpression( + return assignmentOperatorExpression(scope, IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT); case IToken.tSHIFTLASSIGN : - return assignmentOperatorExpression( + return assignmentOperatorExpression(scope, IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT); case IToken.tAMPERASSIGN : - return assignmentOperatorExpression( + return assignmentOperatorExpression(scope, IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND); case IToken.tXORASSIGN : - return assignmentOperatorExpression( + return assignmentOperatorExpression(scope, IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR); case IToken.tBITORASSIGN : - return assignmentOperatorExpression( + return assignmentOperatorExpression(scope, IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR); } return conditionalExpression; } protected IASTExpression assignmentOperatorExpression( + IASTScope scope, IASTExpression.Kind kind) throws EndOfFile, Backtrack { IToken t = consume(); - IASTExpression assignmentExpression = assignmentExpression(); + IASTExpression assignmentExpression = assignmentExpression(scope); - return astFactory.createExpression( - kind, - assignmentExpression, - null, - null, - "", - "", - "", - null); + try + { + return astFactory.createExpression( + scope, + kind, + assignmentExpression, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } /** * @param expression * @throws Backtrack */ - protected IASTExpression throwExpression() + protected IASTExpression throwExpression( IASTScope scope ) throws Backtrack { consume(IToken.t_throw); IASTExpression throwExpression = null; try { - throwExpression = expression(); + throwExpression = expression(scope); } catch (Backtrack b) { } - return astFactory.createExpression( - IASTExpression.Kind.THROWEXPRESSION, - throwExpression, - null, - null, - "", - "", - "", - null); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.THROWEXPRESSION, + throwExpression, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } /** * @param expression * @return * @throws Backtrack */ - protected IASTExpression conditionalExpression() + protected IASTExpression conditionalExpression( IASTScope scope ) throws Backtrack { - IASTExpression firstExpression = logicalOrExpression(); + IASTExpression firstExpression = logicalOrExpression(scope); if (LT(1) == IToken.tQUESTION) { consume(); - IASTExpression secondExpression = expression(); + IASTExpression secondExpression = expression(scope); consume(IToken.tCOLON); - IASTExpression thirdExpression = assignmentExpression(); - return astFactory.createExpression( - IASTExpression.Kind.CONDITIONALEXPRESSION_HARD, - firstExpression, - secondExpression, - thirdExpression, - "", - "", - "", - null); + IASTExpression thirdExpression = assignmentExpression(scope); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.CONDITIONALEXPRESSION_HARD, + firstExpression, + secondExpression, + thirdExpression, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } else return firstExpression; @@ -2827,25 +2861,33 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression logicalOrExpression() + protected IASTExpression logicalOrExpression(IASTScope scope) throws Backtrack { - IASTExpression firstExpression = logicalAndExpression(); + IASTExpression firstExpression = logicalAndExpression(scope); while (LT(1) == IToken.tOR) { IToken t = consume(); - IASTExpression secondExpression = logicalAndExpression(); + IASTExpression secondExpression = logicalAndExpression(scope); - firstExpression = - astFactory.createExpression( - IASTExpression.Kind.LOGICALOREXPRESSION, - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + IASTExpression.Kind.LOGICALOREXPRESSION, + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } return firstExpression; } @@ -2853,24 +2895,32 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression logicalAndExpression() + protected IASTExpression logicalAndExpression( IASTScope scope ) throws Backtrack { - IASTExpression firstExpression = inclusiveOrExpression(); + IASTExpression firstExpression = inclusiveOrExpression( scope ); while (LT(1) == IToken.tAND) { IToken t = consume(); - IASTExpression secondExpression = inclusiveOrExpression(); - firstExpression = - astFactory.createExpression( - IASTExpression.Kind.LOGICALANDEXPRESSION, - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + IASTExpression secondExpression = inclusiveOrExpression( scope ); + try + { + firstExpression = + astFactory.createExpression( + scope, + IASTExpression.Kind.LOGICALANDEXPRESSION, + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } return firstExpression; } @@ -2878,25 +2928,33 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression inclusiveOrExpression() + protected IASTExpression inclusiveOrExpression( IASTScope scope ) throws Backtrack { - IASTExpression firstExpression = exclusiveOrExpression(); + IASTExpression firstExpression = exclusiveOrExpression(scope); while (LT(1) == IToken.tBITOR) { IToken t = consume(); - IASTExpression secondExpression = exclusiveOrExpression(); + IASTExpression secondExpression = exclusiveOrExpression(scope); - firstExpression = - astFactory.createExpression( - IASTExpression.Kind.INCLUSIVEOREXPRESSION, - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + IASTExpression.Kind.INCLUSIVEOREXPRESSION, + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } return firstExpression; } @@ -2904,25 +2962,33 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression exclusiveOrExpression() + protected IASTExpression exclusiveOrExpression( IASTScope scope ) throws Backtrack { - IASTExpression firstExpression = andExpression(); + IASTExpression firstExpression = andExpression( scope ); while (LT(1) == IToken.tXOR) { IToken t = consume(); - IASTExpression secondExpression = andExpression(); + IASTExpression secondExpression = andExpression( scope ); - firstExpression = - astFactory.createExpression( - IASTExpression.Kind.EXCLUSIVEOREXPRESSION, - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + IASTExpression.Kind.EXCLUSIVEOREXPRESSION, + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } return firstExpression; } @@ -2930,24 +2996,32 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression andExpression() throws Backtrack + protected IASTExpression andExpression(IASTScope scope) throws Backtrack { - IASTExpression firstExpression = equalityExpression(); + IASTExpression firstExpression = equalityExpression(scope); while (LT(1) == IToken.tAMPER) { IToken t = consume(); - IASTExpression secondExpression = equalityExpression(); + IASTExpression secondExpression = equalityExpression(scope); - firstExpression = - astFactory.createExpression( - IASTExpression.Kind.ANDEXPRESSION, - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + IASTExpression.Kind.ANDEXPRESSION, + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } return firstExpression; } @@ -2955,10 +3029,10 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression equalityExpression() + protected IASTExpression equalityExpression( IASTScope scope ) throws Backtrack { - IASTExpression firstExpression = relationalExpression(); + IASTExpression firstExpression = relationalExpression(scope); for (;;) { switch (LT(1)) @@ -2967,20 +3041,28 @@ public class Parser implements IParser case IToken.tNOTEQUAL : IToken t = consume(); IASTExpression secondExpression = - relationalExpression(); + relationalExpression(scope); - firstExpression = - astFactory.createExpression( - (t.getType() == IToken.tEQUAL) - ? IASTExpression.Kind.EQUALITY_EQUALS - : IASTExpression.Kind.EQUALITY_NOTEQUALS, - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + (t.getType() == IToken.tEQUAL) + ? IASTExpression.Kind.EQUALITY_EQUALS + : IASTExpression.Kind.EQUALITY_NOTEQUALS, + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } break; default : return firstExpression; @@ -2991,10 +3073,10 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression relationalExpression() + protected IASTExpression relationalExpression(IASTScope scope) throws Backtrack { - IASTExpression firstExpression = shiftExpression(); + IASTExpression firstExpression = shiftExpression(scope); for (;;) { switch (LT(1)) @@ -3007,7 +3089,7 @@ public class Parser implements IParser IToken t = consume(); IToken next = LA(1); IASTExpression secondExpression = - shiftExpression(); + shiftExpression(scope); if (next == LA(1)) { // we did not consume anything @@ -3040,16 +3122,24 @@ public class Parser implements IParser .RELATIONAL_GREATERTHANEQUALTO; break; } - firstExpression = - astFactory.createExpression( - kind, - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + kind, + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } break; default : @@ -3061,10 +3151,10 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression shiftExpression() + protected IASTExpression shiftExpression(IASTScope scope) throws Backtrack { - IASTExpression firstExpression = additiveExpression(); + IASTExpression firstExpression = additiveExpression(scope); for (;;) { switch (LT(1)) @@ -3073,19 +3163,27 @@ public class Parser implements IParser case IToken.tSHIFTR : IToken t = consume(); IASTExpression secondExpression = - additiveExpression(); - firstExpression = - astFactory.createExpression( - ((t.getType() == IToken.tSHIFTL) - ? IASTExpression.Kind.SHIFT_LEFT - : IASTExpression.Kind.SHIFT_RIGHT), - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + additiveExpression(scope); + try + { + firstExpression = + astFactory.createExpression( + scope, + ((t.getType() == IToken.tSHIFTL) + ? IASTExpression.Kind.SHIFT_LEFT + : IASTExpression.Kind.SHIFT_RIGHT), + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } break; default : return firstExpression; @@ -3096,10 +3194,10 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression additiveExpression() + protected IASTExpression additiveExpression( IASTScope scope ) throws Backtrack { - IASTExpression firstExpression = multiplicativeExpression(); + IASTExpression firstExpression = multiplicativeExpression( scope ); for (;;) { switch (LT(1)) @@ -3108,19 +3206,27 @@ public class Parser implements IParser case IToken.tMINUS : IToken t = consume(); IASTExpression secondExpression = - multiplicativeExpression(); - firstExpression = - astFactory.createExpression( - ((t.getType() == IToken.tPLUS) - ? IASTExpression.Kind.ADDITIVE_PLUS - : IASTExpression.Kind.ADDITIVE_MINUS), - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + multiplicativeExpression(scope); + try + { + firstExpression = + astFactory.createExpression( + scope, + ((t.getType() == IToken.tPLUS) + ? IASTExpression.Kind.ADDITIVE_PLUS + : IASTExpression.Kind.ADDITIVE_MINUS), + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } break; default : return firstExpression; @@ -3131,10 +3237,10 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression multiplicativeExpression() + protected IASTExpression multiplicativeExpression( IASTScope scope ) throws Backtrack { - IASTExpression firstExpression = pmExpression(); + IASTExpression firstExpression = pmExpression(scope); for (;;) { switch (LT(1)) @@ -3143,7 +3249,7 @@ public class Parser implements IParser case IToken.tDIV : case IToken.tMOD : IToken t = consume(); - IASTExpression secondExpression = pmExpression(); + IASTExpression secondExpression = pmExpression(scope); IASTExpression.Kind kind = null; switch (t.getType()) { @@ -3157,16 +3263,24 @@ public class Parser implements IParser kind = IASTExpression.Kind.MULTIPLICATIVE_MODULUS; break; } - firstExpression = - astFactory.createExpression( - kind, - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + kind, + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } break; default : return firstExpression; @@ -3177,9 +3291,9 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression pmExpression() throws Backtrack + protected IASTExpression pmExpression( IASTScope scope ) throws Backtrack { - IASTExpression firstExpression = castExpression(); + IASTExpression firstExpression = castExpression(scope); for (;;) { switch (LT(1)) @@ -3188,19 +3302,27 @@ public class Parser implements IParser case IToken.tARROWSTAR : IToken t = consume(); IASTExpression secondExpression = - castExpression(); - firstExpression = - astFactory.createExpression( - ((t.getType() == IToken.tDOTSTAR) - ? IASTExpression.Kind.PM_DOTSTAR - : IASTExpression.Kind.PM_ARROWSTAR), - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + castExpression(scope); + try + { + firstExpression = + astFactory.createExpression( + scope, + ((t.getType() == IToken.tDOTSTAR) + ? IASTExpression.Kind.PM_DOTSTAR + : IASTExpression.Kind.PM_ARROWSTAR), + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } break; default : return firstExpression; @@ -3212,7 +3334,7 @@ public class Parser implements IParser * : unaryExpression * | "(" typeId ")" castExpression */ - protected IASTExpression castExpression() throws Backtrack + protected IASTExpression castExpression( IASTScope scope ) throws Backtrack { // TO DO: we need proper symbol checkint to ensure type name if (LT(1) == IToken.tLPAREN) @@ -3233,23 +3355,31 @@ public class Parser implements IParser consume(); } consume(IToken.tRPAREN); - IASTExpression castExpression = castExpression(); - return astFactory.createExpression( - IASTExpression.Kind.CASTEXPRESSION, - castExpression, - null, - null, - null, - duple.toString(), - "", - null); + IASTExpression castExpression = castExpression(scope); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.CASTEXPRESSION, + castExpression, + null, + null, + null, + duple, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } catch (Backtrack b) { backup(mark); } } - return unaryExpression(); + return unaryExpression(scope); } /** * @throws Backtrack @@ -3319,7 +3449,7 @@ public class Parser implements IParser * @param expression * @throws Backtrack */ - protected IASTExpression deleteExpression() + protected IASTExpression deleteExpression( IASTScope scope ) throws Backtrack { if (LT(1) == IToken.tCOLONCOLON) @@ -3336,18 +3466,26 @@ public class Parser implements IParser consume(IToken.tRBRACKET); vectored = true; } - IASTExpression castExpression = castExpression(); - return astFactory.createExpression( - (vectored - ? IASTExpression.Kind.DELETE_VECTORCASTEXPRESSION - : IASTExpression.Kind.DELETE_CASTEXPRESSION), - castExpression, - null, - null, - "", - "", - "", - null); + IASTExpression castExpression = castExpression(scope); + try + { + return astFactory.createExpression( + scope, + (vectored + ? IASTExpression.Kind.DELETE_VECTORCASTEXPRESSION + : IASTExpression.Kind.DELETE_CASTEXPRESSION), + castExpression, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } /** * Pazse a new-expression. @@ -3365,7 +3503,7 @@ public class Parser implements IParser * directnewdeclarator [ constantexpression ] * newinitializer: ( expressionlist? ) */ - protected IASTExpression newExpression() throws Backtrack + protected IASTExpression newExpression( IASTScope scope ) throws Backtrack { if (LT(1) == IToken.tCOLONCOLON) { @@ -3385,7 +3523,7 @@ public class Parser implements IParser // Try to consume placement list // Note: since expressionList and expression are the same... backtrackMarker = mark(); - expression(); + expression(scope); consume(IToken.tRPAREN); placementParseFailure = false; if (LT(1) == IToken.tLPAREN) @@ -3486,7 +3624,7 @@ public class Parser implements IParser { // array new consume(); - assignmentExpression(); + assignmentExpression(scope); consume(IToken.tRBRACKET); } // newinitializer @@ -3494,66 +3632,74 @@ public class Parser implements IParser { consume(IToken.tLPAREN); if (LT(1) != IToken.tRPAREN) - expression(); + expression(scope); consume(IToken.tRPAREN); } return null; //TODO fix this } - protected IASTExpression unaryOperatorCastExpression( + protected IASTExpression unaryOperatorCastExpression( IASTScope scope, IASTExpression.Kind kind, IToken consumed) throws Backtrack { - IASTExpression castExpression = castExpression(); - return astFactory.createExpression( - kind, - castExpression, - null, - null, - "", - "", - "", - null); + IASTExpression castExpression = castExpression(scope); + try + { + return astFactory.createExpression( + scope, + kind, + castExpression, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } /** * @param expression * @throws Backtrack */ - protected IASTExpression unaryExpression() + protected IASTExpression unaryExpression( IASTScope scope ) throws Backtrack { switch (LT(1)) { case IToken.tSTAR : - return unaryOperatorCastExpression( + return unaryOperatorCastExpression(scope, IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION, consume()); case IToken.tAMPER : - return unaryOperatorCastExpression( + return unaryOperatorCastExpression(scope, IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION, consume()); case IToken.tPLUS : - return unaryOperatorCastExpression( + return unaryOperatorCastExpression(scope, IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION, consume()); case IToken.tMINUS : - return unaryOperatorCastExpression( + return unaryOperatorCastExpression(scope, IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION, consume()); case IToken.tNOT : - return unaryOperatorCastExpression( + return unaryOperatorCastExpression(scope, IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION, consume()); case IToken.tCOMPL : - return unaryOperatorCastExpression( + return unaryOperatorCastExpression(scope, IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION, consume()); case IToken.tINCR : - return unaryOperatorCastExpression( + return unaryOperatorCastExpression(scope, IASTExpression.Kind.UNARY_INCREMENT, consume()); case IToken.tDECR : - return unaryOperatorCastExpression( + return unaryOperatorCastExpression(scope, IASTExpression.Kind.UNARY_DECREMENT, consume()); case IToken.t_sizeof : @@ -3572,58 +3718,74 @@ public class Parser implements IParser catch (Backtrack bt) { backup(mark); - unaryExpression = unaryExpression(); + unaryExpression = unaryExpression(scope); } } else { - unaryExpression = unaryExpression(); + unaryExpression = unaryExpression(scope); } if (d != null & unaryExpression == null) - return astFactory.createExpression( - IASTExpression.Kind.UNARY_SIZEOF_TYPEID, - null, - null, - null, - "", - d.toString(), - "", - null); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.UNARY_SIZEOF_TYPEID, + null, + null, + null, + null, + d, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } else if (unaryExpression != null && d == null) - return astFactory.createExpression( - IASTExpression.Kind.UNARY_SIZEOF_UNARYEXPRESSION, - unaryExpression, - null, - null, - "", - "", - "", - null); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.UNARY_SIZEOF_UNARYEXPRESSION, + unaryExpression, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e1) + { + failParse(); + throw backtrack; + } else throw backtrack; case IToken.t_new : - return newExpression(); + return newExpression(scope); case IToken.t_delete : - return deleteExpression(); + return deleteExpression(scope); case IToken.tCOLONCOLON : switch (LT(2)) { case IToken.t_new : - return newExpression(); + return newExpression(scope); case IToken.t_delete : - return deleteExpression(); + return deleteExpression(scope); default : - return postfixExpression(); + return postfixExpression(scope); } default : - return postfixExpression(); + return postfixExpression(scope); } } /** * @param expression * @throws Backtrack */ - protected IASTExpression postfixExpression() + protected IASTExpression postfixExpression( IASTScope scope ) throws Backtrack { IASTExpression firstExpression = null; @@ -3636,72 +3798,72 @@ public class Parser implements IParser // simple-type-specifier ( assignment-expression , .. ) case IToken.t_char : firstExpression = - simpleTypeConstructorExpression( + simpleTypeConstructorExpression(scope, IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR); break; case IToken.t_wchar_t : firstExpression = - simpleTypeConstructorExpression( + simpleTypeConstructorExpression(scope, IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART); break; case IToken.t_bool : firstExpression = - simpleTypeConstructorExpression( + simpleTypeConstructorExpression(scope, IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL); break; case IToken.t_short : firstExpression = - simpleTypeConstructorExpression( + simpleTypeConstructorExpression(scope, IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT); break; case IToken.t_int : firstExpression = - simpleTypeConstructorExpression( + simpleTypeConstructorExpression(scope, IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT); break; case IToken.t_long : firstExpression = - simpleTypeConstructorExpression( + simpleTypeConstructorExpression(scope, IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG); break; case IToken.t_signed : firstExpression = - simpleTypeConstructorExpression( + simpleTypeConstructorExpression(scope, IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED); break; case IToken.t_unsigned : firstExpression = - simpleTypeConstructorExpression( + simpleTypeConstructorExpression(scope, IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED); break; case IToken.t_float : firstExpression = - simpleTypeConstructorExpression( + simpleTypeConstructorExpression(scope, IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT); break; case IToken.t_double : firstExpression = - simpleTypeConstructorExpression( + simpleTypeConstructorExpression( scope, IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE); break; case IToken.t_dynamic_cast : firstExpression = - specialCastExpression( + specialCastExpression(scope, IASTExpression.Kind.POSTFIX_DYNAMIC_CAST); break; case IToken.t_static_cast : firstExpression = - specialCastExpression( + specialCastExpression(scope, IASTExpression.Kind.POSTFIX_STATIC_CAST); break; case IToken.t_reinterpret_cast : firstExpression = - specialCastExpression( + specialCastExpression(scope, IASTExpression.Kind.POSTFIX_REINTERPRET_CAST); break; case IToken.t_const_cast : firstExpression = - specialCastExpression( + specialCastExpression(scope, IASTExpression.Kind.POSTFIX_CONST_CAST); break; case IToken.t_typeid : @@ -3717,24 +3879,32 @@ public class Parser implements IParser catch (Backtrack b) { isTypeId = false; - lhs = expression(); + lhs = expression(scope); } consume(IToken.tRPAREN); - firstExpression = - astFactory.createExpression( - (isTypeId - ? IASTExpression.Kind.POSTFIX_TYPEID_TYPEID - : IASTExpression.Kind.POSTFIX_TYPEID_EXPRESSION), - lhs, - null, - null, - "", - (isTypeId ? typeId.toString() : ""), - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + (isTypeId + ? IASTExpression.Kind.POSTFIX_TYPEID_TYPEID + : IASTExpression.Kind.POSTFIX_TYPEID_EXPRESSION), + lhs, + null, + null, + null, + typeId, + "", null); + } + catch (ASTSemanticException e6) + { + failParse(); + throw backtrack; + } break; default : - firstExpression = primaryExpression(); + firstExpression = primaryExpression(scope); } IASTExpression secondExpression = null; for (;;) @@ -3744,60 +3914,92 @@ public class Parser implements IParser case IToken.tLBRACKET : // array access consume(); - secondExpression = expression(); + secondExpression = expression(scope); consume(IToken.tRBRACKET); - firstExpression = - astFactory.createExpression( - IASTExpression.Kind.POSTFIX_SUBSCRIPT, - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + IASTExpression.Kind.POSTFIX_SUBSCRIPT, + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e2) + { + failParse(); + throw backtrack; + } break; case IToken.tLPAREN : // function call consume(); - secondExpression = expression(); + secondExpression = expression(scope); consume(IToken.tRPAREN); - firstExpression = - astFactory.createExpression( - IASTExpression.Kind.POSTFIX_FUNCTIONCALL, - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + IASTExpression.Kind.POSTFIX_FUNCTIONCALL, + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e3) + { + failParse(); + throw backtrack; + } break; case IToken.tINCR : consume(); - firstExpression = - astFactory.createExpression( - IASTExpression.Kind.POSTFIX_INCREMENT, - firstExpression, - null, - null, - "", - "", - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + IASTExpression.Kind.POSTFIX_INCREMENT, + firstExpression, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e1) + { + failParse(); + throw backtrack; + } break; case IToken.tDECR : consume(); - firstExpression = - astFactory.createExpression( - IASTExpression.Kind.POSTFIX_DECREMENT, - firstExpression, - null, - null, - "", - "", - "", - null); + try + { + firstExpression = + astFactory.createExpression( + scope, + IASTExpression.Kind.POSTFIX_DECREMENT, + firstExpression, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e4) + { + failParse(); + throw backtrack; + } break; case IToken.tDOT : // member access @@ -3807,19 +4009,27 @@ public class Parser implements IParser consume(IToken.t_template); isTemplate = true; } - secondExpression = primaryExpression(); - firstExpression = - astFactory.createExpression( - (isTemplate - ? IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS - : IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION), - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + secondExpression = primaryExpression(scope); + try + { + firstExpression = + astFactory.createExpression( + scope, + (isTemplate + ? IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS + : IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION), + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e5) + { + failParse(); + throw backtrack; + } break; case IToken.tARROW : // member access @@ -3829,26 +4039,34 @@ public class Parser implements IParser consume(IToken.t_template); isTemplate = true; } - secondExpression = primaryExpression(); - firstExpression = - astFactory.createExpression( - (isTemplate - ? IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP - : IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION), - firstExpression, - secondExpression, - null, - "", - "", - "", - null); + secondExpression = primaryExpression(scope); + try + { + firstExpression = + astFactory.createExpression( + scope, + (isTemplate + ? IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP + : IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION), + firstExpression, + secondExpression, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } break; default : return firstExpression; } } } - protected IASTExpression specialCastExpression( + protected IASTExpression specialCastExpression( IASTScope scope, IASTExpression.Kind kind) throws EndOfFile, Backtrack { @@ -3857,48 +4075,57 @@ public class Parser implements IParser ITokenDuple duple = typeId(); consume(IToken.tGT); consume(IToken.tLPAREN); - IASTExpression lhs = expression(); + IASTExpression lhs = expression(scope); consume(IToken.tRPAREN); - return astFactory.createExpression( - kind, - lhs, - null, - null, - "", - "", - "", - null); + try + { + return astFactory.createExpression( + scope, + kind, + lhs, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } - protected IASTExpression simpleTypeConstructorExpression( + protected IASTExpression simpleTypeConstructorExpression( IASTScope scope, Kind type) throws EndOfFile, Backtrack { consume(); consume(IToken.tLPAREN); - IASTExpression inside = expression(); - // while (true) - // { - // assignmentExpression(expression); - // if (LT(1) == IToken.tRPAREN) - // break; - // consume(IToken.tCOMMA); - // } + IASTExpression inside = expression(scope); consume(IToken.tRPAREN); - return astFactory.createExpression( - type, - inside, - null, - null, - "", - "", - "", - null); + try + { + return astFactory.createExpression( + scope, + type, + inside, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } /** * @param expression * @throws Backtrack */ - protected IASTExpression primaryExpression() + protected IASTExpression primaryExpression( IASTScope scope ) throws Backtrack { IToken t = null; @@ -3907,104 +4134,176 @@ public class Parser implements IParser // TO DO: we need more literals... case IToken.tINTEGER : t = consume(); - return astFactory.createExpression( - IASTExpression.Kind.PRIMARY_INTEGER_LITERAL, - null, - null, - null, - "", - "", - t.getImage(), - null); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.PRIMARY_INTEGER_LITERAL, + null, + null, + null, + null, + null, + t.getImage(), null); + } + catch (ASTSemanticException e1) + { + failParse(); + throw backtrack; + } case IToken.tFLOATINGPT : t = consume(); - return astFactory.createExpression( - IASTExpression.Kind.PRIMARY_FLOAT_LITERAL, - null, - null, - null, - "", - "", - t.getImage(), - null); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.PRIMARY_FLOAT_LITERAL, + null, + null, + null, + null, + null, + t.getImage(), null); + } + catch (ASTSemanticException e2) + { + failParse(); + throw backtrack; + } case IToken.tSTRING : case IToken.tLSTRING : t = consume(); - return astFactory.createExpression( IASTExpression.Kind.PRIMARY_STRING_LITERAL, null, null, null, "", "", t.getImage(), null ); + try + { + return astFactory.createExpression( scope, IASTExpression.Kind.PRIMARY_STRING_LITERAL, null, null, null, null, null, t.getImage(), null ); + } + catch (ASTSemanticException e5) + { + failParse(); + throw backtrack; + } case IToken.t_false : case IToken.t_true : t = consume(); - return astFactory.createExpression( - IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL, - null, - null, - null, - "", - "", - t.getImage(), - null); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL, + null, + null, + null, + null, + null, + t.getImage(), null); + } + catch (ASTSemanticException e3) + { + failParse(); + throw backtrack; + } case IToken.tCHAR : case IToken.tLCHAR : t = consume(); - return astFactory.createExpression( - IASTExpression.Kind.PRIMARY_CHAR_LITERAL, - null, - null, - null, - "", - "", - t.getImage(), - null); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.PRIMARY_CHAR_LITERAL, + null, + null, + null, + null, + null, + t.getImage(), null); + } + catch (ASTSemanticException e4) + { + failParse(); + throw backtrack; + } case IToken.t_this : consume(IToken.t_this); - return astFactory.createExpression( - IASTExpression.Kind.PRIMARY_THIS, - null, - null, - null, - "", - "", - "", - null); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.PRIMARY_THIS, + null, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e7) + { + failParse(); + throw backtrack; + } case IToken.tLPAREN : consume(); - IASTExpression lhs = expression(); + IASTExpression lhs = expression(scope); consume(IToken.tRPAREN); - return astFactory.createExpression( - IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION, - lhs, - null, - null, - "", - "", - "", - null); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION, + lhs, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e6) + { + failParse(); + throw backtrack; + } case IToken.tIDENTIFIER : ITokenDuple duple = name(); //TODO should be an ID Expression really - return astFactory.createExpression( - IASTExpression.Kind.ID_EXPRESSION, - null, - null, - null, - "", - "", - duple.toString(), - null); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.ID_EXPRESSION, + null, + null, + null, + null, + duple, + "", null); + } + catch (ASTSemanticException e8) + { + failParse(); + throw backtrack; + } default : - return astFactory.createExpression( - IASTExpression.Kind.PRIMARY_EMPTY, - null, - null, - null, - "", - "", - "", - null); + try + { + return astFactory.createExpression( + scope, + IASTExpression.Kind.PRIMARY_EMPTY, + null, + null, + null, + null, + null, + "", null); + } + catch (ASTSemanticException e) + { + failParse(); + throw backtrack; + } } } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java index c2999cec0c7..7380edb27b5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java @@ -1786,7 +1786,7 @@ public class Scanner implements IScanner { IParser parser = ParserFactory.createParser(trial, nullCallback, ParserMode.QUICK_PARSE ); try { - IASTExpression exp = parser.expression(); + IASTExpression exp = parser.expression(null); if( exp.evaluateExpression() == 0 ) return false; } catch( Backtrack b ) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInitializerClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInitializerClause.java new file mode 100644 index 00000000000..171c18f0131 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInitializerClause.java @@ -0,0 +1,121 @@ +/********************************************************************** + * 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; + +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + +import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ast.IASTExpression; +import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; + +/** + * @author jcamelon + */ +public class ASTInitializerClause implements IASTInitializerClause { + + private final IASTInitializerClause.Kind kind; + private final IASTExpression assignmentExpression; + private final List initializerClauses; + /** + * @param kind + * @param assignmentExpression + * @param initializerClauses + */ + public ASTInitializerClause(Kind kind, IASTExpression assignmentExpression, List initializerClauses) { + this.kind = kind; + this.assignmentExpression = assignmentExpression; + this.initializerClauses = initializerClauses; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getKind() + */ + public Kind getKind() { + return kind; + } + + public static class EmptyIterator implements Iterator + { + + /* (non-Javadoc) + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() + { + return false; + } + + /* (non-Javadoc) + * @see java.util.Iterator#next() + */ + public Object next() + { + throw new NoSuchElementException(); + } + + /* (non-Javadoc) + * @see java.util.Iterator#remove() + */ + public void remove() + { + throw new UnsupportedOperationException(); + } + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializerList() + */ + public Iterator getInitializers() { + if( initializerClauses == null ) + return new EmptyIterator(); + return initializerClauses.iterator(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression() + */ + public IASTExpression getAssigmentExpression() { + return assignmentExpression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void acceptElement(ISourceElementRequestor requestor) + { + Iterator i = getInitializers(); + while( i.hasNext() ) + { + IASTInitializerClause initializerClause = (IASTInitializerClause)i.next(); + initializerClause.acceptElement(requestor); + } + if( assignmentExpression != null ) + assignmentExpression.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) + { + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java index d754df9813e..763e430f79b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java @@ -14,6 +14,7 @@ import java.util.List; import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTInclusion; import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; import org.eclipse.cdt.core.parser.ast.IASTMacro; @@ -59,5 +60,10 @@ public class BaseASTFactory { return new ASTParameterDeclaration( isConst, isVolatile, typeSpecifier, pointerOperators, arrayModifiers, parameters, pointerOp, parameterName, initializerClause ); } + public IASTInitializerClause createInitializerClause(IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, List initializerClauses) + { + return new ASTInitializerClause( kind, assignmentExpression, initializerClauses ); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java new file mode 100644 index 00000000000..3c34a8278ab --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java @@ -0,0 +1,139 @@ +/********************************************************************** + * 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.List; + +import org.eclipse.cdt.core.parser.ISourceElementRequestor; +import org.eclipse.cdt.core.parser.ast.ExpressionEvaluationException; +import org.eclipse.cdt.core.parser.ast.IASTExpression; + +/** + * @author jcamelon + * + */ +public class ASTExpression implements IASTExpression +{ + private final Kind kind; + private final IASTExpression lhs; + private final IASTExpression rhs; + private final IASTExpression thirdExpression; + private final String literal; + private final String typeId; + private final String id; + private final IASTNewExpressionDescriptor newDescriptor; + private final List references; + /** + * + */ + public ASTExpression( Kind kind, IASTExpression lhs, IASTExpression rhs, + IASTExpression thirdExpression, String literal, String typeId, String id, IASTNewExpressionDescriptor newDescriptor, List references ) + { + this.kind = kind; + this.lhs = lhs; + this.rhs = rhs; + this.thirdExpression = thirdExpression; + this.literal = literal; + this.typeId = typeId; + this.id = id; + this.newDescriptor = newDescriptor; + this.references = references; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getExpressionKind() + */ + public Kind getExpressionKind() + { + return kind; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLHSExpression() + */ + public IASTExpression getLHSExpression() + { + return lhs; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getRHSExpression() + */ + public IASTExpression getRHSExpression() + { + return rhs; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getThirdExpression() + */ + public IASTExpression getThirdExpression() + { + return thirdExpression; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLiteralString() + */ + public String getLiteralString() + { + return literal; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId() + */ + public String getTypeId() + { + return typeId; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getId() + */ + public String getId() + { + return id; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor() + */ + public IASTNewExpressionDescriptor getNewExpressionDescriptor() + { + return newDescriptor; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression() + */ + public int evaluateExpression() throws ExpressionEvaluationException + { + throw new ExpressionEvaluationException(); + } + + public List getReferences() + { + return references; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) + */ + public void acceptElement(ISourceElementRequestor requestor) + { + ASTReferenceStore store = new ASTReferenceStore( references ); + store.processReferences(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) + { + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java index 69d3ce305dd..4f67974eaed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java @@ -55,5 +55,8 @@ public class ASTField extends ASTVariable implements IASTField { requestor.acceptField(this); referenceDelegate.processReferences(requestor); + if( getInitializerClause() != null ) + getInitializerClause().acceptElement(requestor); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java index 589535ed6ed..2efd4057155 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; import org.eclipse.cdt.core.parser.ast.IASTFunction; +import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.parser.ast.IASTTemplate; import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets; @@ -191,7 +192,23 @@ public class ASTFunction extends ASTScope implements IASTFunction { requestor.acceptFunctionDeclaration(this); references.processReferences(requestor); + processParameterInitializers(requestor); } + /** + * @param requestor + */ + protected void processParameterInitializers(ISourceElementRequestor requestor) + { + Iterator i = parameters.iterator(); + while( i.hasNext() ) + { + IASTParameterDeclaration parm = (IASTParameterDeclaration)i.next(); + if( parm.getDefaultValue() != null ) + parm.getDefaultValue().acceptElement(requestor); + } + } + + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) */ @@ -199,6 +216,7 @@ public class ASTFunction extends ASTScope implements IASTFunction { requestor.enterFunctionBody( this ); references.processReferences(requestor); + processParameterInitializers(requestor); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java index 7cd8683f0d6..27034967282 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java @@ -123,6 +123,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod { requestor.acceptMethodDeclaration(this); references.processReferences(requestor); + processParameterInitializers(requestor); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java index a3327752248..7db440ab3d7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java @@ -160,6 +160,8 @@ public class ASTVariable extends ASTSymbol implements IASTVariable { requestor.acceptVariable(this); referenceDelegate.processReferences(requestor); + if( initializerClause != null ) + initializerClause.acceptElement(requestor); } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index d57fdab14ee..95b878ab478 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -87,67 +87,79 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } - protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, ITokenDuple name, List references ) throws ASTSemanticException + protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, ITokenDuple name, List references, boolean throwOnError ) throws ASTSemanticException { ISymbol result = null; - IToken firstSymbol = null; - switch( name.length() ) - { - case 0: - throw new ASTSemanticException(); - case 1: - firstSymbol = name.getFirstToken(); - try - { - result = startingScope.lookup( firstSymbol.getImage()); - if( result != null ) - references.add( createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() )); - else - throw new ASTSemanticException(); - } - catch (ParserSymbolTableException e) - { - throw new ASTSemanticException(); - } - break; - case 2: - firstSymbol = name.getFirstToken(); - if( firstSymbol.getType() != IToken.tCOLONCOLON ) - throw new ASTSemanticException(); - try - { - result = pst.getCompilationUnit().lookup( name.getLastToken().getImage() ); - references.add( createReference( result, name.getLastToken().getImage(), name.getLastToken().getOffset() )); - } - catch( ParserSymbolTableException e) - { - throw new ASTSemanticException(); - } - break; - default: - Iterator iter = name.iterator(); - firstSymbol = name.getFirstToken(); - result = startingScope; - if( firstSymbol.getType() == IToken.tCOLONCOLON ) - result = pst.getCompilationUnit(); - while( iter.hasNext() ) - { - IToken t = (IToken)iter.next(); - if( t.getType() == IToken.tCOLONCOLON ) continue; + IToken firstSymbol = null; + try + { + if( name == null ) throw new ASTSemanticException(); + + switch( name.length() ) + { + case 0: + if( throwOnError ) + throw new ASTSemanticException(); + case 1: + firstSymbol = name.getFirstToken(); + try + { + result = startingScope.lookup( firstSymbol.getImage()); + if( result != null ) + references.add( createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() )); + else + throw new ASTSemanticException(); + } + catch (ParserSymbolTableException e) + { + throw new ASTSemanticException(); + } + break; + case 2: + firstSymbol = name.getFirstToken(); + if( firstSymbol.getType() != IToken.tCOLONCOLON ) + throw new ASTSemanticException(); try { - if( t == name.getLastToken() ) - result = ((IContainerSymbol)result).qualifiedLookup( t.getImage() ); - else - result = ((IContainerSymbol)result).lookupNestedNameSpecifier( t.getImage() ); - references.add( createReference( result, t.getImage(), t.getOffset() )); + result = pst.getCompilationUnit().lookup( name.getLastToken().getImage() ); + references.add( createReference( result, name.getLastToken().getImage(), name.getLastToken().getOffset() )); } - catch( ParserSymbolTableException pste ) + catch( ParserSymbolTableException e) { - throw new ASTSemanticException(); + throw new ASTSemanticException(); } - } - + break; + default: + Iterator iter = name.iterator(); + firstSymbol = name.getFirstToken(); + result = startingScope; + if( firstSymbol.getType() == IToken.tCOLONCOLON ) + result = pst.getCompilationUnit(); + while( iter.hasNext() ) + { + IToken t = (IToken)iter.next(); + if( t.getType() == IToken.tCOLONCOLON ) continue; + try + { + if( t == name.getLastToken() ) + result = ((IContainerSymbol)result).qualifiedLookup( t.getImage() ); + else + result = ((IContainerSymbol)result).lookupNestedNameSpecifier( t.getImage() ); + references.add( createReference( result, t.getImage(), t.getOffset() )); + } + catch( ParserSymbolTableException pste ) + { + throw new ASTSemanticException(); + } + } + + } + } + catch( ASTSemanticException se ) + { + if( throwOnError ) + throw se; + return null; } return result; } @@ -165,7 +177,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto { List references = new ArrayList(); ISymbol symbol = lookupQualifiedName( - scopeToSymbol( scope), duple, references ); + scopeToSymbol( scope), duple, references, true ); try { ((ASTScope)scope).getContainerSymbol().addUsingDirective( (IContainerSymbol)symbol ); @@ -212,7 +224,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto int endingOffset) throws ASTSemanticException { List references = new ArrayList(); - ISymbol symbol = lookupQualifiedName( scopeToSymbol(scope), name, references ); + ISymbol symbol = lookupQualifiedName( scopeToSymbol(scope), name, references, true ); try { @@ -376,7 +388,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto ITokenDuple containerSymbolName = name.getSubrange( 0, name.length() - 3 ); // -1 for index, -2 for last hop of qualified name currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol, - containerSymbolName, references); + containerSymbolName, references, true); if( currentScopeSymbol == null ) throw new ASTSemanticException(); } @@ -610,17 +622,58 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String, org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor) */ public IASTExpression createExpression( + IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, - String id, - String typeId, - String literal, - IASTNewExpressionDescriptor newDescriptor) + IToken id, + ITokenDuple typeId, + String literal, IASTNewExpressionDescriptor newDescriptor) throws ASTSemanticException { - // TODO FIX THIS - return null; + List references = new ArrayList(); + + getExpressionReferences(lhs, references); + getExpressionReferences(rhs, references); + getExpressionReferences(thirdExpression,references); + + //look up id & add to references + IContainerSymbol startingScope = scopeToSymbol( scope ); + + if( id != null ) + { + try + { + ISymbol s = startingScope.lookup( id.getImage() ); + if( s != null ) + references.add( createReference( s, id.getImage(), id.getOffset() )); + else + throw new ASTSemanticException(); + } + catch (ParserSymbolTableException e) + { + throw new ASTSemanticException(); + } + } + + //look up typeId & add to references + if( typeId != null ) + lookupQualifiedName( startingScope, typeId, references, false ); + + //TODO add newDescriptor's references & add to references + return new ASTExpression( kind, lhs, rhs, thirdExpression, + id == null ? "" : id.getImage(), + typeId == null ? "" : typeId.toString(), + literal, newDescriptor, references); + } + + + protected void getExpressionReferences(IASTExpression expression, List references) + { + if( expression != null ) + { + references.addAll( ((ASTExpression)expression).getReferences() ); + } } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor() @@ -630,17 +683,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto // TODO FIX THIS return null; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createInitializerClause(org.eclipse.cdt.core.parser.ast.IASTInitializerClause.Kind, org.eclipse.cdt.core.parser.ast.IASTExpression, java.util.List) - */ - public IASTInitializerClause createInitializerClause( - org.eclipse.cdt.core.parser.ast.IASTInitializerClause.Kind kind, - IASTExpression assignmentExpression, - List initializerClauses) - { - // TODO Auto-generated method stub - return null; - } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExceptionSpecification(java.util.List) */ @@ -1263,7 +1306,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto ITokenDuple containerSymbolName = name.getSubrange( 0, name.length() - 3 ); // -1 for index, -2 for last hop of qualified name currentScopeSymbol = (IContainerSymbol)lookupQualifiedName( currentScopeSymbol, - containerSymbolName, references); + containerSymbolName, references, true); if( currentScopeSymbol == null ) throw new ASTSemanticException(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpression.java index 490f29f273f..f7acb1b3b27 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpression.java @@ -6,6 +6,7 @@ */ package org.eclipse.cdt.internal.core.parser.ast.quick; +import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.ast.ExpressionEvaluationException; import org.eclipse.cdt.core.parser.ast.IASTExpression; @@ -162,6 +163,27 @@ public class ASTExpression implements IASTExpression { throw new ExpressionEvaluationException(); } + /* (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) + { + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerClause.java deleted file mode 100644 index 8659d39926d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerClause.java +++ /dev/null @@ -1,59 +0,0 @@ -/********************************************************************** - * 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.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; - -/** - * @author jcamelon - */ -public class ASTInitializerClause implements IASTInitializerClause { - - private final IASTInitializerClause.Kind kind; - private final IASTExpression assignmentExpression; - private final List initializerClauses; - /** - * @param kind - * @param assignmentExpression - * @param initializerClauses - */ - public ASTInitializerClause(Kind kind, IASTExpression assignmentExpression, List initializerClauses) { - this.kind = kind; - this.assignmentExpression = assignmentExpression; - this.initializerClauses = initializerClauses; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getKind() - */ - public Kind getKind() { - return kind; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializerList() - */ - public Iterator getInitializers() { - return initializerClauses.iterator(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression() - */ - public IASTExpression getAssigmentExpression() { - return assignmentExpression; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java index 9bdac7e0d28..c5f9c321fbb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.ast.quick; import java.util.List; +import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTClassKind; @@ -148,8 +149,8 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory /* (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) */ - public IASTExpression createExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, String id, String typeId, String literal, IASTNewExpressionDescriptor newDescriptor) { - return new ASTExpression( kind, lhs, rhs, thirdExpression, id, typeId, literal, newDescriptor ); + public IASTExpression createExpression(IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IToken id, ITokenDuple typeId, String literal, IASTNewExpressionDescriptor newDescriptor) { + return new ASTExpression( kind, lhs, rhs, thirdExpression, id == null ? "" : id.getImage(), typeId == null ? "" : typeId.toString(), literal, newDescriptor ); } /* (non-Javadoc) @@ -160,13 +161,6 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createIASTInitializerClause() - */ - public IASTInitializerClause createInitializerClause(IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, List initializerClauses) { - return new ASTInitializerClause( kind, assignmentExpression, initializerClauses ); - } - - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExceptionSpecification(java.util.List) */ public IASTExceptionSpecification createExceptionSpecification(List typeIds)