[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Applied [HEAD] Expression x-reference w/callbacks
|
CORE
Added Expression x-reference support into Parser.
TESTS
Added testSimpleExpression(), testParameterExpressions() &&
testNestedNamespaceExpression() to CompleteParseASTTest.java.
JohnC
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.58
diff -u -r1.58 ChangeLog
--- ChangeLog 13 Aug 2003 17:45:21 -0000 1.58
+++ ChangeLog 13 Aug 2003 21:49:51 -0000
@@ -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.
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java,v
retrieving revision 1.11
diff -u -r1.11 CompleteParseASTTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java 12 Aug 2003 20:40:11 -0000 1.11
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java 13 Aug 2003 21:49:52 -0000
@@ -193,6 +193,7 @@
public void exitFunctionBody(IASTFunction function)
{
popScope();
+ getCurrentScope().addDeclaration(function);
}
/* (non-Javadoc)
@@ -291,6 +292,7 @@
public void exitMethodBody(IASTMethod method)
{
popScope();
+ getCurrentScope().addDeclaration(method);
}
/* (non-Javadoc)
@@ -536,7 +538,7 @@
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 @@
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 );
+ }
}
Index: parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java,v
retrieving revision 1.6
diff -u -r1.6 ExprEvalTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java 18 Jul 2003 16:39:12 -0000 1.6
+++ parser/org/eclipse/cdt/core/parser/tests/ExprEvalTest.java 13 Aug 2003 21:49:52 -0000
@@ -27,7 +27,7 @@
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());
}
Index: parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java,v
retrieving revision 1.11
diff -u -r1.11 QuickParseASTTests.java
--- parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java 12 Aug 2003 18:19:55 -0000 1.11
+++ parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java 13 Aug 2003 21:49:52 -0000
@@ -1429,7 +1429,7 @@
assertFalse( enumerators.hasNext() );
assertEquals( enumerator.getName(), "isPointer");
assertEquals( enumerator.getInitialValue().getExpressionKind(), IASTExpression.Kind.ID_EXPRESSION );
- assertEquals( enumerator.getInitialValue().getLiteralString(), "PointerTraits<T>::result");
+ assertEquals( enumerator.getInitialValue().getTypeId(), "PointerTraits<T>::result");
}
public void testBug36690() throws Exception {
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.98
diff -u -r1.98 ChangeLog
--- parser/ChangeLog 12 Aug 2003 20:40:04 -0000 1.98
+++ parser/ChangeLog 13 Aug 2003 21:48:33 -0000
@@ -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.
Index: parser/org/eclipse/cdt/core/parser/IParser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java,v
retrieving revision 1.7
diff -u -r1.7 IParser.java
--- parser/org/eclipse/cdt/core/parser/IParser.java 18 Jul 2003 16:39:22 -0000 1.7
+++ parser/org/eclipse/cdt/core/parser/IParser.java 13 Aug 2003 21:48:33 -0000
@@ -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 @@
* @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++?
Index: parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java,v
retrieving revision 1.3
diff -u -r1.3 IASTExpression.java
--- parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java 28 Jun 2003 22:39:33 -0000 1.3
+++ parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java 13 Aug 2003 21:48:33 -0000
@@ -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
{
Index: parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java,v
retrieving revision 1.20
diff -u -r1.20 IASTFactory.java
--- parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java 12 Aug 2003 18:19:38 -0000 1.20
+++ parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java 13 Aug 2003 21:48:33 -0000
@@ -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 @@
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,
Index: parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java,v
retrieving revision 1.2
diff -u -r1.2 IASTInitializerClause.java
--- parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java 9 Jul 2003 00:47:42 -0000 1.2
+++ parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java 13 Aug 2003 21:48:33 -0000
@@ -13,11 +13,12 @@
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
{
Index: parser/org/eclipse/cdt/internal/core/parser/Parser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java,v
retrieving revision 1.89
diff -u -r1.89 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java 12 Aug 2003 20:40:04 -0000 1.89
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java 13 Aug 2003 21:48:35 -0000
@@ -968,7 +968,7 @@
consume(IToken.tLPAREN);
IASTExpression expressionList = null;
- expressionList = expression();
+ expressionList = expression(d.getDeclarationWrapper().getScope());
consume(IToken.tRPAREN);
@@ -1001,7 +1001,7 @@
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 @@
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 @@
/**
*
*/
- protected IASTInitializerClause initializerClause()
+ protected IASTInitializerClause initializerClause(IASTScope scope)
throws Backtrack
{
if (LT(1) == IToken.tLBRACE)
@@ -1748,7 +1748,7 @@
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 @@
IToken marked = mark();
IASTExpression assignmentExpression =
- assignmentExpression();
+ assignmentExpression(scope);
return astFactory.createInitializerClause(
IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION,
@@ -1876,6 +1876,7 @@
{
// parameterDeclarationClause
d.setIsFunction(true);
+ // TODO need to create a temporary scope object here
consume();
boolean seenParameter = false;
parameterDeclarationLoop : for (;;)
@@ -2031,7 +2032,7 @@
IASTExpression exp = null;
if (LT(1) != IToken.tRBRACKET)
{
- exp = constantExpression();
+ exp = constantExpression(sdw.getScope());
}
consume(IToken.tRBRACKET);
IASTArrayModifier arrayMod =
@@ -2043,7 +2044,7 @@
case IToken.tCOLON :
consume(IToken.tCOLON);
IASTExpression exp = null;
- exp = constantExpression();
+ exp = constantExpression(scope);
d.setBitFieldExpression(exp);
default :
break;
@@ -2237,7 +2238,7 @@
if (LT(1) == IToken.tASSIGN)
{
consume(IToken.tASSIGN);
- initialValue = constantExpression();
+ initialValue = constantExpression(sdw.getScope());
}
if (LT(1) == IToken.tRBRACE)
@@ -2509,21 +2510,21 @@
*
* @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 @@
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 @@
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 @@
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 @@
if (LT(1) != IToken.tSEMI)
{
//TODO get rid of NULL
- expression();
+ expression(scope);
}
consume(IToken.tSEMI);
return;
@@ -2621,7 +2622,7 @@
{
consume();
consume();
- statement();
+ statement(null);
return;
}
// expressionStatement
@@ -2629,7 +2630,7 @@
// Since it only happens when we are in a statement
try
{
- expression();
+ expression(scope);
consume(IToken.tSEMI);
return;
}
@@ -2661,38 +2662,46 @@
{
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 @@
* @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 @@
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 @@
* @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 @@
* @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 @@
* @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 @@
* @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 @@
* @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 @@
* @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 @@
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 @@
* @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 @@
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 @@
.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 @@
* @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 @@
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 @@
* @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 @@
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 @@
* @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 @@
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 @@
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 @@
* @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 @@
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 @@
* : 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 @@
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 @@
* @param expression
* @throws Backtrack
*/
- protected IASTExpression deleteExpression()
+ protected IASTExpression deleteExpression( IASTScope scope )
throws Backtrack
{
if (LT(1) == IToken.tCOLONCOLON)
@@ -3336,18 +3466,26 @@
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 @@
* 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 @@
// 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 @@
{
// array new
consume();
- assignmentExpression();
+ assignmentExpression(scope);
consume(IToken.tRBRACKET);
}
// newinitializer
@@ -3494,66 +3632,74 @@
{
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 @@
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 @@
// 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
// 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;
+ }
}
}
/**
Index: parser/org/eclipse/cdt/internal/core/parser/Scanner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java,v
retrieving revision 1.45
diff -u -r1.45 Scanner.java
--- parser/org/eclipse/cdt/internal/core/parser/Scanner.java 28 Jul 2003 15:40:36 -0000 1.45
+++ parser/org/eclipse/cdt/internal/core/parser/Scanner.java 13 Aug 2003 21:48:36 -0000
@@ -1786,7 +1786,7 @@
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 )
Index: parser/org/eclipse/cdt/internal/core/parser/ast/ASTInitializerClause.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/ast/ASTInitializerClause.java
diff -N parser/org/eclipse/cdt/internal/core/parser/ast/ASTInitializerClause.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/parser/ast/ASTInitializerClause.java 13 Aug 2003 21:48:36 -0000
@@ -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)
+ {
+ }
+
+}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java,v
retrieving revision 1.7
diff -u -r1.7 BaseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java 12 Aug 2003 18:19:38 -0000 1.7
+++ parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java 13 Aug 2003 21:48:36 -0000
@@ -14,6 +14,7 @@
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;
@@ -57,6 +58,11 @@
public IASTParameterDeclaration createParameterDeclaration(boolean isConst, boolean isVolatile, IASTTypeSpecifier typeSpecifier, List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOp, String parameterName, IASTInitializerClause initializerClause)
{
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 );
}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java
diff -N parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java 13 Aug 2003 21:48:37 -0000
@@ -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)
+ {
+ }
+
+}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java,v
retrieving revision 1.1
diff -u -r1.1 ASTField.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java 22 Jul 2003 22:02:20 -0000 1.1
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java 13 Aug 2003 21:48:37 -0000
@@ -55,5 +55,8 @@
{
requestor.acceptField(this);
referenceDelegate.processReferences(requestor);
+ if( getInitializerClause() != null )
+ getInitializerClause().acceptElement(requestor);
+
}
}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java,v
retrieving revision 1.2
diff -u -r1.2 ASTFunction.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java 25 Jul 2003 00:35:40 -0000 1.2
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java 13 Aug 2003 21:48:37 -0000
@@ -17,6 +17,7 @@
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 @@
{
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 @@
{
requestor.enterFunctionBody( this );
references.processReferences(requestor);
+ processParameterInitializers(requestor);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java,v
retrieving revision 1.2
diff -u -r1.2 ASTMethod.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java 25 Jul 2003 00:35:40 -0000 1.2
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java 13 Aug 2003 21:48:37 -0000
@@ -123,6 +123,7 @@
{
requestor.acceptMethodDeclaration(this);
references.processReferences(requestor);
+ processParameterInitializers(requestor);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor)
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java,v
retrieving revision 1.1
diff -u -r1.1 ASTVariable.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java 22 Jul 2003 22:02:20 -0000 1.1
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java 13 Aug 2003 21:48:37 -0000
@@ -160,6 +160,8 @@
{
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)
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java,v
retrieving revision 1.13
diff -u -r1.13 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 12 Aug 2003 20:40:04 -0000 1.13
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 13 Aug 2003 21:48:37 -0000
@@ -87,67 +87,79 @@
}
- 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
- {
- if( t == name.getLastToken() )
- result = ((IContainerSymbol)result).qualifiedLookup( t.getImage() );
+ {
+ result = startingScope.lookup( firstSymbol.getImage());
+ if( result != null )
+ references.add( createReference( result, firstSymbol.getImage(), firstSymbol.getOffset() ));
else
- result = ((IContainerSymbol)result).lookupNestedNameSpecifier( t.getImage() );
- references.add( createReference( result, t.getImage(), t.getOffset() ));
+ 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 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 @@
{
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 @@
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 @@
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 @@
* @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 @@
// 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 @@
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();
}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpression.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpression.java,v
retrieving revision 1.1
diff -u -r1.1 ASTExpression.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpression.java 28 Jun 2003 22:39:33 -0000 1.1
+++ parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpression.java 13 Aug 2003 21:48:37 -0000
@@ -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;
@@ -161,6 +162,27 @@
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)
+ {
+ }
Index: parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerClause.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerClause.java
diff -N parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerClause.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerClause.java 9 Jul 2003 00:47:42 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -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;
- }
-
-}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java,v
retrieving revision 1.21
diff -u -r1.21 QuickParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java 12 Aug 2003 20:40:04 -0000 1.21
+++ parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java 13 Aug 2003 21:48:38 -0000
@@ -12,6 +12,7 @@
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 @@
/* (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 @@
}
/* (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)