diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog
index 07d25c87ddb..1eefdfd0ed4 100644
--- a/core/org.eclipse.cdt.core.tests/ChangeLog
+++ b/core/org.eclipse.cdt.core.tests/ChangeLog
@@ -1,3 +1,6 @@
+2004-02-11 John Camelon
+ Updated tests to accommodate for new Parser class hierarchy and factories.
+
2004-02-10 Andrew Niefer
Added new File: ParserSymbolTableTemplateTests.java (contains 30 new tests)
Added new File: FailingTemplateTests.java (contains 5 test stubs for failing cases)
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 6693466c27a..5695ffa599e 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
@@ -6,14 +6,14 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.NullLogService;
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
-import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
+import org.eclipse.cdt.internal.core.parser.IExpressionParser;
+import org.eclipse.cdt.internal.core.parser.InternalParserFactory;
public class ExprEvalTest extends TestCase {
@@ -28,7 +28,7 @@ public class ExprEvalTest extends TestCase {
public void runTest(String code, int expectedValue) throws Exception {
final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor();
- IParser parser = ParserFactory.createParser(ParserFactory.createScanner( new StringReader( code ), getClass().getName(), new ScannerInfo(), null, ParserLanguage.CPP, nullCallback, new NullLogService() ), nullCallback, ParserMode.QUICK_PARSE, ParserLanguage.CPP, null );
+ IExpressionParser parser = InternalParserFactory.createExpressionParser(ParserFactory.createScanner( new StringReader( code ), getClass().getName(), new ScannerInfo(), null, ParserLanguage.CPP, nullCallback, new NullLogService() ), ParserLanguage.CPP, null );
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/SelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java
index de820958d18..28f8d6a10fd 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java
@@ -53,7 +53,7 @@ public class SelectionParseTest extends CompleteParseBaseTest {
}
- public void testBaseCase_Variable() throws Exception
+ public void testBaseCase_VariableReference() throws Exception
{
String code = "int x; x=3;";
int offset1 = code.indexOf( "x=" );
@@ -63,9 +63,9 @@ public class SelectionParseTest extends CompleteParseBaseTest {
assertEquals( ((IASTVariable)node).getName(), "x" );
}
- public void testBaseCase_Function() throws Exception
+ public void testBaseCase_FunctionReference() throws Exception
{
- String code = "int x(); x( );";
+ String code = "int x(){x( );}";
int offset1 = code.indexOf( "x( " );
int offset2 = code.indexOf( "( )");
IASTNode node = parse( code, offset1, offset2 );
@@ -75,11 +75,31 @@ public class SelectionParseTest extends CompleteParseBaseTest {
public void testBaseCase_Error() throws Exception
{
- String code = "int x(); y( );";
+ String code = "int x() { y( ) }";
int offset1 = code.indexOf( "y( " );
int offset2 = code.indexOf( "( )");
assertNull( parse( code, offset1, offset2 ));
}
+// public void testBaseCase_FunctionDeclaration() throws Exception
+// {
+// String code = "int x(); x( );";
+// int offset1 = code.indexOf( "x()" );
+// int offset2 = code.indexOf( "()");
+// IASTNode node = parse( code, offset1, offset2 );
+// assertTrue( node instanceof IASTFunction );
+// assertEquals( ((IASTFunction)node).getName(), "x" );
+// }
+//
+// public void testBaseCase_VariableDeclaration() throws Exception
+// {
+// String code = "int x = 3;";
+// int offset1 = code.indexOf( "x" );
+// int offset2 = code.indexOf( " =");
+// IASTNode node = parse( code, offset1, offset2 );
+// assertTrue( node instanceof IASTVariable );
+// assertEquals( ((IASTVariable)node).getName(), "x" );
+// }
+
}
diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog-parser b/core/org.eclipse.cdt.core/parser/ChangeLog-parser
index a800c7612ec..330d1e5b732 100644
--- a/core/org.eclipse.cdt.core/parser/ChangeLog-parser
+++ b/core/org.eclipse.cdt.core/parser/ChangeLog-parser
@@ -1,3 +1,7 @@
+2004-02-11 John Camelon
+ Restructured Parser implementation to allow for better support of Selection Search.
+ Restructured Parser implementation to allow for separation between parsing expressions (Scanner) and complete C/C++ source.
+
2004-02-10 John Camelon
Workaround for Bug 51502 - Parser spins on particular file (Scalability)
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 a8a9b9b3dd3..e01ea5339db 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,9 +11,7 @@
package org.eclipse.cdt.core.parser;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
-import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTNode;
-import org.eclipse.cdt.core.parser.ast.IASTScope;
@@ -23,7 +21,7 @@ import org.eclipse.cdt.core.parser.ast.IASTScope;
*
* @author jcamelon
*/
-public interface IParser {
+public interface IParser {
/**
@@ -47,18 +45,6 @@ public interface IParser {
*/
public IASTNode parse( int startingOffset, int endingOffset ) throws ParseError;
-
- /**
- * Request a parse from a pre-configured parser to parse an expression.
- *
- * @param expression Optional parameter representing an expression object that
- * your particular IParserCallback instance would appreciate
- *
- * @throws BacktrackException thrown if the Scanner/Stream provided does not yield a valid
- * expression
- */
- public IASTExpression expression(IASTScope scope) throws BacktrackException, EndOfFileException;
-
/**
* If an error was encountered, give us the offset of the token that caused the error.
*
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java
index c679807730c..094b2f00155 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java
@@ -24,6 +24,7 @@ import org.eclipse.cdt.internal.core.parser.SelectionParser;
import org.eclipse.cdt.internal.core.parser.StructuralParseCallback;
import org.eclipse.cdt.internal.core.parser.StructuralParser;
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
+import org.eclipse.cdt.internal.core.parser.ast.expression.ExpressionParseASTFactory;
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
import org.eclipse.cdt.internal.core.parser.scanner.LineOffsetReconciler;
import org.eclipse.cdt.internal.core.parser.scanner.Preprocessor;
@@ -41,7 +42,9 @@ public class ParserFactory {
public static IASTFactory createASTFactory( ParserMode mode, ParserLanguage language )
{
if( mode == ParserMode.QUICK_PARSE )
- return new QuickParseASTFactory( extensionFactory.createASTExtensionFactory( ParserMode.QUICK_PARSE ) );
+ return new QuickParseASTFactory( extensionFactory.createASTExtensionFactory( ParserMode.QUICK_PARSE ) );
+ else if( mode == ParserMode.EXPRESSION_PARSE )
+ return new ExpressionParseASTFactory( extensionFactory.createASTExtensionFactory( ParserMode.EXPRESSION_PARSE ) );
else
return new CompleteParseASTFactory( language, mode, extensionFactory.createASTExtensionFactory( ParserMode.COMPLETE_PARSE ) );
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java
index 3401d02306d..a59771daefb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserMode.java
@@ -16,14 +16,16 @@ package org.eclipse.cdt.core.parser;
*/
public class ParserMode extends Enum {
- // follow inclusions, parse function/method bodies
- public static final ParserMode COMPLETE_PARSE = new ParserMode( 1 );
-
- // follow inclusions, do not parse function/method bodies
- public static final ParserMode STRUCTURAL_PARSE = new ParserMode( 2 );
+ public static final ParserMode EXPRESSION_PARSE = new ParserMode( 0 );
// do not follow inclusions, do not parse function/method bodies
- public static final ParserMode QUICK_PARSE = new ParserMode( 3 );
+ public static final ParserMode QUICK_PARSE = new ParserMode( 1 );
+
+ //follow inclusions, do not parse function/method bodies
+ public static final ParserMode STRUCTURAL_PARSE = new ParserMode( 2 );
+
+ // follow inclusions, parse function/method bodies
+ public static final ParserMode COMPLETE_PARSE = new ParserMode( 3 );
// follow inclusions, parse function/method bodies, stop at particular offset
// provide optimized lookup capability for querying symbols
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompleteParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompleteParser.java
index 20f20a1fc5b..18228db8a59 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompleteParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompleteParser.java
@@ -37,8 +37,6 @@ public class CompleteParser extends Parser {
*/
public CompleteParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log) {
super(scanner, callback, language, log);
- astFactory = ParserFactory.createASTFactory( ParserMode.COMPLETE_PARSE, language);
- scanner.setASTFactory(astFactory);
}
protected void handleFunctionBody(IASTScope scope) throws BacktrackException, EndOfFileException
@@ -67,4 +65,12 @@ public class CompleteParser extends Parser {
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setupASTFactory(org.eclipse.cdt.core.parser.IScanner, org.eclipse.cdt.core.parser.ParserLanguage)
+ */
+ protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
+ astFactory = ParserFactory.createASTFactory( ParserMode.COMPLETE_PARSE, language);
+ scanner.setASTFactory(astFactory);
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompletionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompletionParser.java
index 7ec4f6893b9..3112240905b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompletionParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/CompletionParser.java
@@ -29,27 +29,17 @@ import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
-import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.internal.core.parser.ast.ASTCompletionNode;
-import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
-import org.eclipse.cdt.internal.core.parser.token.Token;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key;
/**
* @author jcamelon
*/
-public class CompletionParser extends CompleteParser implements IParser {
+public class CompletionParser extends ContextualParser implements IParser {
- protected CompletionKind kind;
- protected IASTNode context;
- protected IToken finalToken;
- private Set keywordSet;
- protected IASTScope scope;
-
-
/**
* @param scanner
* @param callback
@@ -58,8 +48,6 @@ public class CompletionParser extends CompleteParser implements IParser {
*/
public CompletionParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log) {
super(scanner, callback, language, log);
- astFactory = ParserFactory.createASTFactory( ParserMode.COMPLETION_PARSE, language);
- scanner.setASTFactory(astFactory);
}
/* (non-Javadoc)
@@ -98,38 +86,6 @@ public class CompletionParser extends CompleteParser implements IParser {
return keywordSet;
}
- /**
- * @return
- */
- protected String getCompletionPrefix() {
- return ( finalToken == null ? "" : finalToken.getImage() );
- }
-
- /**
- * @return
- */
- protected IASTNode getCompletionContext() {
- return context;
- }
-
- /**
- * @return
- */
- protected IASTCompletionNode.CompletionKind getCompletionKind() {
- return kind;
- }
-
- protected void setCompletionContext( IASTNode node )
- {
- this.context = node;
- }
-
- protected void setCompletionKind( IASTCompletionNode.CompletionKind kind )
- {
- this.kind = kind;
- }
-
-
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.Parser#handleOffsetLimitException()
*/
@@ -149,91 +105,12 @@ public class CompletionParser extends CompleteParser implements IParser {
throw exception;
}
- /**
- * @param compilationUnit
- * @param kind2
- * @param set
- * @param object
- * @param string
- */
- protected void setCompletionValues(CompletionKind kind, Set keywordSet, String prefix ) {
- setCompletionScope(compilationUnit);
- this.keywordSet = keywordSet;
- setCompletionKind(kind);
- setCompletionContext(null);
- setCompletionToken( new Token( IToken.tIDENTIFIER, prefix ) );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.parser.Parser#setCompletionKeywords(java.lang.String[])
- */
- protected void setCompletionKeywords(KeywordSets.Key key) {
- this.keywordSet = KeywordSets.getKeywords( key, language );
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.parser.Parser#setCompletionToken(org.eclipse.cdt.core.parser.IToken)
- */
- protected void setCompletionToken(IToken token) {
- finalToken = token;
- }
-
protected IToken getCompletionToken()
{
return finalToken;
}
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.parser.Parser#setCompletionContextForExpression(org.eclipse.cdt.core.parser.ast.IASTExpression, boolean)
- */
- protected IASTNode getCompletionContextForExpression(
- IASTExpression firstExpression,
- boolean isTemplate) {
- return astFactory.getCompletionContext( (isTemplate
- ? IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS
- : IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION),
- firstExpression ) ;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.parser.Parser#setCompletionValues(org.eclipse.cdt.core.parser.ast.IASTNode, org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind, org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key, java.lang.String)
- */
- protected void setCompletionValues(
- IASTScope scope,
- CompletionKind kind,
- Key key,
- IASTNode node, String prefix) throws EndOfFileException {
- setCompletionToken( new Token( IToken.tIDENTIFIER, prefix ) );
- setCompletionValues(scope, kind, key, node );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.parser.Parser#setCompletionValues(org.eclipse.cdt.core.parser.ast.IASTNode, org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind, org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key)
- */
- protected void setCompletionValues(
- IASTScope scope,
- CompletionKind kind,
- Key key ) throws EndOfFileException {
- setCompletionValues(scope, kind, key, null );
- }
-
- protected void setCompletionValues(
- IASTScope scope,
- CompletionKind kind,
- Key key,
- IASTNode node ) throws EndOfFileException
- {
- setCompletionScope(scope);
- setCompletionKeywords(key);
- setCompletionKind(kind);
- setCompletionContext(node);
- checkEndOfFile();
- }
-
-
-
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.Parser#getCompletionKindForDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope)
*/
@@ -250,18 +127,6 @@ public class CompletionParser extends CompleteParser implements IParser {
return kind;
}
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.parser.Parser#setCompletionValues(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind, org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key, org.eclipse.cdt.core.parser.ast.IASTExpression, boolean)
- */
- protected void setCompletionValues(
- IASTScope scope,
- CompletionKind kind,
- Key key,
- IASTExpression firstExpression,
- boolean isTemplate) throws EndOfFileException {
- setCompletionValues(scope,kind,key, getCompletionContextForExpression(firstExpression,isTemplate) );
- }
-
protected void catchHandlerSequence(IASTScope scope)
throws EndOfFileException, BacktrackException {
if( LT(1) != IToken.t_catch )
@@ -269,36 +134,34 @@ public class CompletionParser extends CompleteParser implements IParser {
while (LT(1) == IToken.t_catch)
{
consume(IToken.t_catch);
- setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY);
+ setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,Key.EMPTY );
consume(IToken.tLPAREN);
- setCompletionValues(scope,CompletionKind.EXCEPTION_REFERENCE,Key.DECL_SPECIFIER_SEQUENCE );
+ setCompletionValues(scope,CompletionKind.EXCEPTION_REFERENCE,Key.DECL_SPECIFIER_SEQUENCE);
if( LT(1) == IToken.tELLIPSIS )
consume( IToken.tELLIPSIS );
else
- declaration(scope, null, CompletionKind.EXCEPTION_REFERENCE); // was exceptionDeclaration
+ simpleDeclarationStrategyUnion( scope, null, CompletionKind.EXCEPTION_REFERENCE); // was exceptionDeclaration
consume(IToken.tRPAREN);
catchBlockCompoundStatement(scope);
}
}
- /**
- * @return
- */
- protected IASTScope getCompletionScope() {
- return scope;
- }
-
public IASTNode parse(int startingOffset, int endingOffset) {
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
}
- protected void setCompletionScope(IASTScope scope) {
- this.scope = scope;
- }
-
public boolean parse() {
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setupASTFactory(org.eclipse.cdt.core.parser.IScanner, org.eclipse.cdt.core.parser.ParserLanguage)
+ */
+ protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
+ astFactory = ParserFactory.createASTFactory( ParserMode.COMPLETION_PARSE, language);
+ scanner.setASTFactory(astFactory);
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextualParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextualParser.java
new file mode 100644
index 00000000000..221edbe645c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextualParser.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2000 - 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser;
+
+import java.util.Set;
+
+import org.eclipse.cdt.core.parser.EndOfFileException;
+import org.eclipse.cdt.core.parser.IParserLogService;
+import org.eclipse.cdt.core.parser.IScanner;
+import org.eclipse.cdt.core.parser.ISourceElementRequestor;
+import org.eclipse.cdt.core.parser.IToken;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.parser.ast.IASTExpression;
+import org.eclipse.cdt.core.parser.ast.IASTNode;
+import org.eclipse.cdt.core.parser.ast.IASTScope;
+import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
+import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
+import org.eclipse.cdt.internal.core.parser.token.Token;
+import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key;
+
+/**
+ * @author jcamelon
+ */
+public class ContextualParser extends CompleteParser {
+
+ /**
+ * @param scanner
+ * @param callback
+ * @param language
+ * @param log
+ */
+ public ContextualParser(
+ IScanner scanner,
+ ISourceElementRequestor callback,
+ ParserLanguage language,
+ IParserLogService log) {
+ super(scanner, callback, language, log);
+ }
+
+ protected IASTScope scope;
+
+ /**
+ * @return
+ */
+ protected IASTScope getCompletionScope() {
+ return scope;
+ }
+
+ protected CompletionKind kind;
+
+ /**
+ * @return
+ */
+ protected IASTCompletionNode.CompletionKind getCompletionKind() {
+ return kind;
+ }
+
+ protected IASTNode context;
+ protected IToken finalToken;
+ protected Set keywordSet;
+
+ /**
+ * @return
+ */
+ protected String getCompletionPrefix() {
+ return ( finalToken == null ? "" : finalToken.getImage() );
+ }
+
+ /**
+ * @return
+ */
+ protected IASTNode getCompletionContext() {
+ return context;
+ }
+
+ protected void setCompletionContext(IASTNode node) {
+ this.context = node;
+ }
+
+ protected void setCompletionKind(IASTCompletionNode.CompletionKind kind) {
+ this.kind = kind;
+ }
+
+ /**
+ * @param compilationUnit
+ * @param kind2
+ * @param set
+ * @param object
+ * @param string
+ */
+ protected void setCompletionValues(CompletionKind kind, Set keywordSet, String prefix) {
+ setCompletionScope(compilationUnit);
+ this.keywordSet = keywordSet;
+ setCompletionKind(kind);
+ setCompletionContext(null);
+ setCompletionToken( new Token( IToken.tIDENTIFIER, prefix ) );
+ }
+
+ protected void setCompletionKeywords(KeywordSets.Key key) {
+ this.keywordSet = KeywordSets.getKeywords( key, language );
+ }
+
+ protected void setCompletionToken(IToken token) {
+ finalToken = token;
+ }
+
+ protected IASTNode getCompletionContextForExpression(IASTExpression firstExpression, boolean isTemplate) {
+ return astFactory.getCompletionContext( (isTemplate
+ ? IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS
+ : IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION),
+ firstExpression ) ;
+ }
+
+ protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTNode node, String prefix) throws EndOfFileException {
+ setCompletionToken( new Token( IToken.tIDENTIFIER, prefix ) );
+ setCompletionValues(scope, kind, key, node );
+ }
+
+ protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key) throws EndOfFileException {
+ setCompletionValues(scope, kind, key, null );
+ }
+
+ protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTNode node) throws EndOfFileException {
+ setCompletionScope(scope);
+ setCompletionKeywords(key);
+ setCompletionKind(kind);
+ setCompletionContext(node);
+ checkEndOfFile();
+ }
+
+ protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTExpression firstExpression, boolean isTemplate) throws EndOfFileException {
+ setCompletionValues(scope,kind,key, getCompletionContextForExpression(firstExpression,isTemplate) );
+ }
+
+ protected void setCompletionScope(IASTScope scope) {
+ this.scope = scope;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java
new file mode 100644
index 00000000000..c667633363a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionParser.java
@@ -0,0 +1,2510 @@
+/*******************************************************************************
+ * Copyright (c) 2000 - 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser;
+
+import java.util.ArrayList;
+import java.util.Stack;
+
+import org.eclipse.cdt.core.parser.BacktrackException;
+import org.eclipse.cdt.core.parser.EndOfFileException;
+import org.eclipse.cdt.core.parser.IParserLogService;
+import org.eclipse.cdt.core.parser.IScanner;
+import org.eclipse.cdt.core.parser.IToken;
+import org.eclipse.cdt.core.parser.ITokenDuple;
+import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.ParserMode;
+import org.eclipse.cdt.core.parser.ScannerException;
+import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
+import org.eclipse.cdt.core.parser.ast.ASTSemanticException;
+import org.eclipse.cdt.core.parser.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.parser.ast.IASTExpression;
+import org.eclipse.cdt.core.parser.ast.IASTFactory;
+import org.eclipse.cdt.core.parser.ast.IASTNode;
+import org.eclipse.cdt.core.parser.ast.IASTScope;
+import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTTypeId;
+import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
+import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
+import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
+import org.eclipse.cdt.internal.core.parser.token.Token;
+import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
+import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key;
+
+/**
+ * @author jcamelon
+ */
+public class ExpressionParser implements IExpressionParser {
+
+ protected final IParserLogService log;
+ private static int FIRST_ERROR_OFFSET_UNSET = -1;
+ protected int firstErrorOffset = FIRST_ERROR_OFFSET_UNSET;
+ protected boolean parsePassed = true;
+ protected ParserLanguage language = ParserLanguage.CPP;
+ protected IASTFactory astFactory = null;
+
+ /**
+ * @param scanner2
+ * @param callback
+ * @param language2
+ * @param log2
+ */
+ public ExpressionParser(IScanner scanner, ParserLanguage language, IParserLogService log) {
+ this.scanner = scanner;
+ this.language = language;
+ this.log = log;
+ setupASTFactory(scanner, language);
+ }
+
+ /**
+ * @param scanner
+ * @param language
+ */
+ protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
+ astFactory = ParserFactory.createASTFactory( ParserMode.EXPRESSION_PARSE, language);
+ scanner.setASTFactory(astFactory);
+ }
+
+ /**
+ * This is the single entry point for setting parsePassed to
+ * false, and also making note what token offset we failed upon.
+ *
+ * @throws EndOfFileException
+ */
+ protected void failParse() {
+ try
+ {
+ if (firstErrorOffset == FIRST_ERROR_OFFSET_UNSET )
+ firstErrorOffset = LA(1).getOffset();
+ } catch( EndOfFileException eof )
+ {
+ // do nothing
+ }
+ finally
+ {
+ parsePassed = false;
+ }
+ }
+
+ /**
+ * Consumes template parameters.
+ *
+ * @param previousLast Previous "last" token (returned if nothing was consumed)
+ * @return Last consumed token, or previousLast
if nothing was consumed
+ * @throws BacktrackException request a backtrack
+ */
+ protected IToken consumeTemplateParameters(IToken previousLast) throws EndOfFileException, BacktrackException {
+ IToken last = previousLast;
+ if (LT(1) == IToken.tLT)
+ {
+ last = consume(IToken.tLT);
+ // until we get all the names sorted out
+ Stack scopes = new Stack();
+ scopes.push(new Integer(IToken.tLT));
+
+ while (!scopes.empty())
+ {
+ int top;
+ last = consume();
+
+ switch (last.getType()) {
+ case IToken.tGT :
+ if (((Integer)scopes.peek()).intValue() == IToken.tLT) {
+ scopes.pop();
+ }
+ break;
+ case IToken.tRBRACKET :
+ do {
+ top = ((Integer)scopes.pop()).intValue();
+ } while (!scopes.empty() && (top == IToken.tGT || top == IToken.tLT));
+ if (top != IToken.tLBRACKET) throw backtrack;
+
+ break;
+ case IToken.tRPAREN :
+ do {
+ top = ((Integer)scopes.pop()).intValue();
+ } while (!scopes.empty() && (top == IToken.tGT || top == IToken.tLT));
+ if (top != IToken.tLPAREN) throw backtrack;
+
+ break;
+ case IToken.tLT :
+ case IToken.tLBRACKET:
+ case IToken.tLPAREN:
+ scopes.push(new Integer(last.getType()));
+ break;
+ }
+ }
+ }
+ return last;
+ }
+
+ /**
+ * Parse a template-id, according to the ANSI C++ spec.
+ *
+ * template-id: template-name < template-argument-list opt >
+ * template-name : identifier
+ *
+ * @return the last token that we consumed in a successful parse
+ *
+ * @throws BacktrackException request a backtrack
+ */
+ protected IToken templateId(IASTScope scope) throws EndOfFileException, BacktrackException {
+ ITokenDuple duple = name(scope);
+ IToken last = consumeTemplateParameters(duple.getLastToken());
+ return last;
+ }
+
+ /**
+ * Parse a name.
+ *
+ * name
+ * : ("::")? name2 ("::" name2)*
+ *
+ * name2
+ * : IDENTIFER
+ *
+ * @throws BacktrackException request a backtrack
+ */
+ protected TokenDuple name(IASTScope scope) throws BacktrackException, EndOfFileException {
+ IToken first = LA(1);
+ IToken last = null;
+ IToken mark = mark();
+
+ try
+ {
+ if (LT(1) == IToken.tCOLONCOLON)
+ last = consume( IToken.tCOLONCOLON );
+ // TODO - whacky way to deal with destructors, please revisit
+ if (LT(1) == IToken.tCOMPL)
+ consume();
+ switch (LT(1))
+ {
+ case IToken.tIDENTIFIER :
+ last = consume(IToken.tIDENTIFIER);
+ IToken secondMark = null;
+ if( queryLookaheadCapability() )
+ secondMark = mark();
+ else
+ return new TokenDuple(last, last);
+
+ try
+ {
+ last = consumeTemplateParameters(last);
+ } catch( BacktrackException bt )
+ {
+ backup( secondMark );
+ }
+ break;
+ default :
+ backup(mark);
+ throw backtrack;
+ }
+ while (LT(1) == IToken.tCOLONCOLON)
+ {
+ last = consume();
+ if (LT(1) == IToken.t_template)
+ consume();
+ if (LT(1) == IToken.tCOMPL)
+ consume();
+ switch (LT(1))
+ {
+ case IToken.t_operator :
+ backup(mark);
+ throw backtrack;
+ case IToken.tIDENTIFIER :
+ last = consume();
+ last = consumeTemplateParameters(last);
+ }
+ }
+
+ return new TokenDuple(first, last);
+ } catch( OffsetLimitReachedException olre )
+ {
+ backup(mark);
+ throw backtrack;
+ }
+ }
+
+ /**
+ * Parse a const-volatile qualifier.
+ *
+ * cvQualifier
+ * : "const" | "volatile"
+ *
+ * TODO: fix this
+ * @param ptrOp Pointer Operator that const-volatile applies to.
+ * @return Returns the same object sent in.
+ * @throws BacktrackException
+ */
+ protected IToken cvQualifier(IDeclarator declarator) throws EndOfFileException, BacktrackException {
+ IToken result = null;
+ switch (LT(1))
+ {
+ case IToken.t_const :
+ result = consume( IToken.t_const );
+ declarator.addPointerOperator(ASTPointerOperator.CONST_POINTER);
+ break;
+ case IToken.t_volatile :
+ result = consume( IToken.t_volatile );
+ declarator.addPointerOperator(ASTPointerOperator.VOLATILE_POINTER);
+ break;
+ case IToken.t_restrict :
+ if( language == ParserLanguage.C )
+ {
+ result = consume( IToken.t_restrict );
+ declarator.addPointerOperator(ASTPointerOperator.RESTRICT_POINTER);
+ break;
+ }
+ else
+ throw backtrack;
+ default :
+
+ }
+ return result;
+ }
+
+ protected void consumeArrayModifiers(IDeclarator d, IASTScope scope) throws EndOfFileException, BacktrackException {
+ while (LT(1) == IToken.tLBRACKET)
+ {
+ consume( IToken.tLBRACKET ); // eat the '['
+
+ IASTExpression exp = null;
+ if (LT(1) != IToken.tRBRACKET)
+ {
+ exp = constantExpression(scope);
+ }
+ consume(IToken.tRBRACKET);
+ IASTArrayModifier arrayMod;
+ try
+ {
+ arrayMod = astFactory.createArrayModifier(exp);
+ }
+ catch (Exception e)
+ {
+ throw backtrack;
+ }
+ d.addArrayModifier(arrayMod);
+ }
+ }
+
+ protected void operatorId(Declarator d, IToken originalToken) throws BacktrackException, EndOfFileException {
+ // we know this is an operator
+ IToken operatorToken = consume(IToken.t_operator);
+ IToken toSend = null;
+ if (LA(1).isOperator()
+ || LT(1) == IToken.tLPAREN
+ || LT(1) == IToken.tLBRACKET)
+ {
+ if ((LT(1) == IToken.t_new || LT(1) == IToken.t_delete)
+ && LT(2) == IToken.tLBRACKET
+ && LT(3) == IToken.tRBRACKET)
+ {
+ consume();
+ consume(IToken.tLBRACKET);
+ toSend = consume(IToken.tRBRACKET);
+ // vector new and delete operators
+ }
+ else if (LT(1) == IToken.tLPAREN && LT(2) == IToken.tRPAREN)
+ {
+ // operator ()
+ consume(IToken.tLPAREN);
+ toSend = consume(IToken.tRPAREN);
+ }
+ else if (LT(1) == IToken.tLBRACKET && LT(2) == IToken.tRBRACKET)
+ {
+ consume(IToken.tLBRACKET);
+ toSend = consume(IToken.tRBRACKET);
+ }
+ else if (LA(1).isOperator())
+ toSend = consume();
+ else
+ throw backtrack;
+ }
+ else
+ {
+ // must be a conversion function
+ typeId(d.getDeclarationWrapper().getScope(), true );
+ toSend = lastToken;
+ }
+ ITokenDuple duple =
+ new TokenDuple(
+ originalToken == null ? operatorToken : originalToken,
+ toSend);
+
+ d.setName(duple);
+ }
+
+ /**
+ * Parse a Pointer Operator.
+ *
+ * ptrOperator
+ * : "*" (cvQualifier)*
+ * | "&"
+ * | ::? nestedNameSpecifier "*" (cvQualifier)*
+ *
+ * @param owner Declarator that this pointer operator corresponds to.
+ * @throws BacktrackException request a backtrack
+ */
+ protected IToken consumePointerOperators(IDeclarator d) throws EndOfFileException, BacktrackException {
+ IToken result = null;
+ for( ; ; )
+ {
+ if (LT(1) == IToken.tAMPER)
+ {
+ result = consume( IToken.tAMPER );
+ d.addPointerOperator(ASTPointerOperator.REFERENCE);
+ return result;
+
+ }
+ IToken mark = mark();
+
+ ITokenDuple nameDuple = null;
+ if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON)
+ {
+ try
+ {
+ nameDuple = name(d.getScope());
+ }
+ catch( BacktrackException bt )
+ {
+ backup( mark );
+ return null;
+ }
+ }
+ if ( LT(1) == IToken.tSTAR)
+ {
+ result = consume(IToken.tSTAR); // tokenType = "*"
+
+ d.setPointerOperatorName(nameDuple);
+
+ IToken successful = null;
+ for (;;)
+ {
+ IToken newSuccess = cvQualifier(d);
+ if( newSuccess != null ) successful = newSuccess;
+ else break;
+
+ }
+
+ if( successful == null )
+ {
+ d.addPointerOperator( ASTPointerOperator.POINTER );
+ }
+ continue;
+ }
+ backup(mark);
+ return result;
+ }
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression constantExpression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ return conditionalExpression(scope);
+ }
+
+ public IASTExpression expression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ IASTExpression assignmentExpression = assignmentExpression(scope);
+ while (LT(1) == IToken.tCOMMA)
+ {
+ consume();
+ IASTExpression secondExpression = assignmentExpression(scope);
+ try
+ {
+ assignmentExpression =
+ astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.EXPRESSIONLIST,
+ assignmentExpression,
+ secondExpression,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+ return assignmentExpression;
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression assignmentExpression(IASTScope scope) throws EndOfFileException, BacktrackException {
+ if (LT(1) == IToken.t_throw) {
+ return throwExpression(scope);
+ }
+ IASTExpression conditionalExpression = conditionalExpression(scope);
+ // if the condition not taken, try assignment operators
+ if (conditionalExpression != null
+ && conditionalExpression.getExpressionKind()
+ == IASTExpression.Kind.CONDITIONALEXPRESSION)
+ return conditionalExpression;
+ switch (LT(1)) {
+ case IToken.tASSIGN :
+ return assignmentOperatorExpression(
+ scope,
+ IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL,
+ conditionalExpression);
+ case IToken.tSTARASSIGN :
+ return assignmentOperatorExpression(
+ scope,
+ IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT,
+ conditionalExpression);
+ case IToken.tDIVASSIGN :
+ return assignmentOperatorExpression(
+ scope,
+ IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV,
+ conditionalExpression);
+ case IToken.tMODASSIGN :
+ return assignmentOperatorExpression(
+ scope,
+ IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD,
+ conditionalExpression);
+ case IToken.tPLUSASSIGN :
+ return assignmentOperatorExpression(
+ scope,
+ IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS,
+ conditionalExpression);
+ case IToken.tMINUSASSIGN :
+ return assignmentOperatorExpression(
+ scope,
+ IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS,
+ conditionalExpression);
+ case IToken.tSHIFTRASSIGN :
+ return assignmentOperatorExpression(
+ scope,
+ IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT,
+ conditionalExpression);
+ case IToken.tSHIFTLASSIGN :
+ return assignmentOperatorExpression(
+ scope,
+ IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT,
+ conditionalExpression);
+ case IToken.tAMPERASSIGN :
+ return assignmentOperatorExpression(
+ scope,
+ IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND,
+ conditionalExpression);
+ case IToken.tXORASSIGN :
+ return assignmentOperatorExpression(
+ scope,
+ IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR,
+ conditionalExpression);
+ case IToken.tBITORASSIGN :
+ return assignmentOperatorExpression(
+ scope,
+ IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR,
+ conditionalExpression);
+ }
+ return conditionalExpression;
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression throwExpression(IASTScope scope) throws EndOfFileException, BacktrackException {
+ consume(IToken.t_throw);
+ IASTExpression throwExpression = null;
+ try
+ {
+ throwExpression = expression(scope);
+ }
+ catch (BacktrackException b)
+ {
+ }
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.THROWEXPRESSION,
+ throwExpression,
+ null,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+
+ /**
+ * @param expression
+ * @return
+ * @throws BacktrackException
+ */
+ protected IASTExpression conditionalExpression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ IASTExpression firstExpression = logicalOrExpression(scope);
+ if (LT(1) == IToken.tQUESTION)
+ {
+ consume();
+ IASTExpression secondExpression = expression(scope);
+ consume(IToken.tCOLON);
+ IASTExpression thirdExpression = assignmentExpression(scope);
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.CONDITIONALEXPRESSION,
+ firstExpression,
+ secondExpression,
+ thirdExpression,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+ else
+ return firstExpression;
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression logicalOrExpression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ IASTExpression firstExpression = logicalAndExpression(scope);
+ while (LT(1) == IToken.tOR)
+ {
+ consume();
+ IASTExpression secondExpression = logicalAndExpression(scope);
+
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.LOGICALOREXPRESSION,
+ firstExpression,
+ secondExpression,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+ return firstExpression;
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression logicalAndExpression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ IASTExpression firstExpression = inclusiveOrExpression( scope );
+ while (LT(1) == IToken.tAND)
+ {
+ consume();
+ IASTExpression secondExpression = inclusiveOrExpression( scope );
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.LOGICALANDEXPRESSION,
+ firstExpression,
+ secondExpression,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+ return firstExpression;
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression inclusiveOrExpression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ IASTExpression firstExpression = exclusiveOrExpression(scope);
+ while (LT(1) == IToken.tBITOR)
+ {
+ consume();
+ IASTExpression secondExpression = exclusiveOrExpression(scope);
+
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.INCLUSIVEOREXPRESSION,
+ firstExpression,
+ secondExpression,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+ return firstExpression;
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression exclusiveOrExpression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ IASTExpression firstExpression = andExpression( scope );
+ while (LT(1) == IToken.tXOR)
+ {
+ consume();
+
+ IASTExpression secondExpression = andExpression( scope );
+
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.EXCLUSIVEOREXPRESSION,
+ firstExpression,
+ secondExpression,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+ return firstExpression;
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression andExpression(IASTScope scope) throws EndOfFileException, BacktrackException {
+ IASTExpression firstExpression = equalityExpression(scope);
+ while (LT(1) == IToken.tAMPER)
+ {
+ consume();
+ IASTExpression secondExpression = equalityExpression(scope);
+
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.ANDEXPRESSION,
+ firstExpression,
+ secondExpression,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+ return firstExpression;
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression equalityExpression(IASTScope scope) throws EndOfFileException, BacktrackException {
+ IASTExpression firstExpression = relationalExpression(scope);
+ for (;;)
+ {
+ switch (LT(1))
+ {
+ case IToken.tEQUAL :
+ case IToken.tNOTEQUAL :
+ IToken t = consume();
+ IASTExpression secondExpression =
+ relationalExpression(scope);
+
+ 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)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ default :
+ return firstExpression;
+ }
+ }
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression relationalExpression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ IASTExpression firstExpression = shiftExpression(scope);
+ for (;;)
+ {
+ switch (LT(1))
+ {
+ case IToken.tGT :
+ case IToken.tLT :
+ case IToken.tLTEQUAL :
+ case IToken.tGTEQUAL :
+ IToken mark = mark();
+ IToken t = consume();
+ IToken next = LA(1);
+ IASTExpression secondExpression =
+ shiftExpression(scope);
+ if (next == LA(1))
+ {
+ // we did not consume anything
+ // this is most likely an error
+ backup(mark);
+ return firstExpression;
+ }
+ else
+ {
+ IASTExpression.Kind kind = null;
+ switch (t.getType())
+ {
+ case IToken.tGT :
+ kind =
+ IASTExpression.Kind.RELATIONAL_GREATERTHAN;
+ break;
+ case IToken.tLT :
+ kind = IASTExpression.Kind.RELATIONAL_LESSTHAN;
+ break;
+ case IToken.tLTEQUAL :
+ kind =
+ IASTExpression
+ .Kind
+ .RELATIONAL_LESSTHANEQUALTO;
+ break;
+ case IToken.tGTEQUAL :
+ kind =
+ IASTExpression
+ .Kind
+ .RELATIONAL_GREATERTHANEQUALTO;
+ break;
+ }
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ kind,
+ firstExpression,
+ secondExpression,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+ break;
+ default :
+ return firstExpression;
+ }
+ }
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression shiftExpression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ IASTExpression firstExpression = additiveExpression(scope);
+ for (;;)
+ {
+ switch (LT(1))
+ {
+ case IToken.tSHIFTL :
+ case IToken.tSHIFTR :
+ IToken t = consume();
+ IASTExpression secondExpression =
+ 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)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ default :
+ return firstExpression;
+ }
+ }
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression additiveExpression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ IASTExpression firstExpression = multiplicativeExpression( scope );
+ for (;;)
+ {
+ switch (LT(1))
+ {
+ case IToken.tPLUS :
+ case IToken.tMINUS :
+ IToken t = consume();
+ IASTExpression secondExpression =
+ 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)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ default :
+ return firstExpression;
+ }
+ }
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression multiplicativeExpression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ IASTExpression firstExpression = pmExpression(scope);
+ for (;;)
+ {
+ switch (LT(1))
+ {
+ case IToken.tSTAR :
+ case IToken.tDIV :
+ case IToken.tMOD :
+ IToken t = consume();
+ IASTExpression secondExpression = pmExpression(scope);
+ IASTExpression.Kind kind = null;
+ switch (t.getType())
+ {
+ case IToken.tSTAR :
+ kind = IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY;
+ break;
+ case IToken.tDIV :
+ kind = IASTExpression.Kind.MULTIPLICATIVE_DIVIDE;
+ break;
+ case IToken.tMOD :
+ kind = IASTExpression.Kind.MULTIPLICATIVE_MODULUS;
+ break;
+ }
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ kind,
+ firstExpression,
+ secondExpression,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ default :
+ return firstExpression;
+ }
+ }
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression pmExpression(IASTScope scope) throws EndOfFileException, BacktrackException {
+ IASTExpression firstExpression = castExpression(scope);
+ for (;;)
+ {
+ switch (LT(1))
+ {
+ case IToken.tDOTSTAR :
+ case IToken.tARROWSTAR :
+ IToken t = consume();
+ IASTExpression secondExpression =
+ 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)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ default :
+ return firstExpression;
+ }
+ }
+ }
+
+ /**
+ * castExpression
+ * : unaryExpression
+ * | "(" typeId ")" castExpression
+ */
+ protected IASTExpression castExpression(IASTScope scope) throws EndOfFileException, BacktrackException {
+ // TO DO: we need proper symbol checkint to ensure type name
+ if (LT(1) == IToken.tLPAREN)
+ {
+ IToken mark = mark();
+ consume();
+ IASTTypeId typeId = null;
+ // If this isn't a type name, then we shouldn't be here
+ try
+ {
+ typeId = typeId(scope, false);
+ consume(IToken.tRPAREN);
+ IASTExpression castExpression = castExpression(scope);
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.CASTEXPRESSION,
+ castExpression,
+ null,
+ null,
+ typeId,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+ catch (BacktrackException b)
+ {
+ backup(mark);
+ }
+ }
+ return unaryExpression(scope);
+
+ }
+
+ /**
+ * @throws BacktrackException
+ */
+ protected IASTTypeId typeId(IASTScope scope, boolean skipArrayModifiers) throws EndOfFileException, BacktrackException {
+ IToken mark = mark();
+ ITokenDuple name = null;
+ boolean isConst = false, isVolatile = false;
+ boolean isSigned = false, isUnsigned = false;
+ boolean isShort = false, isLong = false;
+ boolean isTypename = false;
+
+ IASTSimpleTypeSpecifier.Type kind = null;
+ do
+ {
+ try
+ {
+ name = name(scope);
+ kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
+ break;
+ }
+ catch (BacktrackException b)
+ {
+ // do nothing
+ }
+
+ boolean encounteredType = false;
+ simpleMods : for (;;)
+ {
+ switch (LT(1))
+ {
+ case IToken.t_signed :
+ consume();
+ isSigned = true;
+ break;
+
+ case IToken.t_unsigned :
+ consume();
+ isUnsigned = true;
+ break;
+
+ case IToken.t_short :
+ consume();
+ isShort = true;
+ break;
+
+ case IToken.t_long :
+ consume();
+ isLong = true;
+ break;
+
+ case IToken.t_const :
+ consume();
+ isConst = true;
+ break;
+
+ case IToken.t_volatile :
+ consume();
+ isVolatile = true;
+ break;
+
+ case IToken.tIDENTIFIER :
+ if( encounteredType ) break simpleMods;
+ encounteredType = true;
+ name = name(scope);
+ kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
+ break;
+
+ case IToken.t_int :
+ if( encounteredType ) break simpleMods;
+ encounteredType = true;
+ kind = IASTSimpleTypeSpecifier.Type.INT;
+ consume();
+ break;
+
+ case IToken.t_char :
+ if( encounteredType ) break simpleMods;
+ encounteredType = true;
+ kind = IASTSimpleTypeSpecifier.Type.CHAR;
+ consume();
+ break;
+
+ case IToken.t_bool :
+ if( encounteredType ) break simpleMods;
+ encounteredType = true;
+ kind = IASTSimpleTypeSpecifier.Type.BOOL;
+ consume();
+ break;
+
+ case IToken.t_double :
+ if( encounteredType ) break simpleMods;
+ encounteredType = true;
+ kind = IASTSimpleTypeSpecifier.Type.DOUBLE;
+ consume();
+ break;
+
+ case IToken.t_float :
+ if( encounteredType ) break simpleMods;
+ encounteredType = true;
+ kind = IASTSimpleTypeSpecifier.Type.FLOAT;
+ consume();
+ break;
+
+ case IToken.t_wchar_t :
+ if( encounteredType ) break simpleMods;
+ encounteredType = true;
+ kind = IASTSimpleTypeSpecifier.Type.WCHAR_T;
+ consume();
+ break;
+
+
+ case IToken.t_void :
+ if( encounteredType ) break simpleMods;
+ encounteredType = true;
+ kind = IASTSimpleTypeSpecifier.Type.VOID;
+ consume();
+ break;
+
+ case IToken.t__Bool :
+ if( encounteredType ) break simpleMods;
+ encounteredType = true;
+ kind = IASTSimpleTypeSpecifier.Type._BOOL;
+ consume();
+ break;
+
+ default :
+ break simpleMods;
+ }
+ }
+
+ if( kind != null ) break;
+
+ if( isShort || isLong || isUnsigned || isSigned )
+ {
+ kind = IASTSimpleTypeSpecifier.Type.INT;
+ break;
+ }
+
+ if (
+ LT(1) == IToken.t_typename
+ || LT(1) == IToken.t_struct
+ || LT(1) == IToken.t_class
+ || LT(1) == IToken.t_enum
+ || LT(1) == IToken.t_union)
+ {
+ consume();
+ try
+ {
+ name = name(scope);
+ kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
+ } catch( BacktrackException b )
+ {
+ backup( mark );
+ throw backtrack;
+ }
+ }
+
+ } while( false );
+
+ if( kind == null )
+ throw backtrack;
+
+ TypeId id = new TypeId(scope);
+ IToken last = lastToken;
+
+ lastToken = consumeTemplateParameters( last );
+ if( lastToken == null ) lastToken = last;
+
+ consumePointerOperators( id );
+ if( lastToken == null ) lastToken = last;
+
+ if( ! skipArrayModifiers )
+ {
+ last = lastToken;
+ consumeArrayModifiers( id, scope );
+ if( lastToken == null ) lastToken = last;
+ }
+
+ try
+ {
+ return astFactory.createTypeId( scope, kind, isConst, isVolatile, isShort, isLong, isSigned, isUnsigned, isTypename, name, id.getPointerOperators(), id.getArrayModifiers());
+ }
+ catch (ASTSemanticException e)
+ {
+ backup( mark );
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression deleteExpression(IASTScope scope) throws EndOfFileException, BacktrackException {
+ if (LT(1) == IToken.tCOLONCOLON)
+ {
+ // global scope
+ consume();
+ }
+ consume(IToken.t_delete);
+ boolean vectored = false;
+ if (LT(1) == IToken.tLBRACKET)
+ {
+ // array delete
+ consume();
+ consume(IToken.tRBRACKET);
+ vectored = true;
+ }
+ 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)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+
+ /**
+ * Pazse a new-expression.
+ *
+ * @param expression
+ * @throws BacktrackException
+ *
+ *
+ * newexpression: ::? new newplacement? newtypeid newinitializer?
+ * ::? new newplacement? ( typeid ) newinitializer?
+ * newplacement: ( expressionlist )
+ * newtypeid: typespecifierseq newdeclarator?
+ * newdeclarator: ptroperator newdeclarator? | directnewdeclarator
+ * directnewdeclarator: [ expression ]
+ * directnewdeclarator [ constantexpression ]
+ * newinitializer: ( expressionlist? )
+ */
+ protected IASTExpression newExpression(IASTScope scope) throws BacktrackException, EndOfFileException {
+ setCompletionValues(scope, CompletionKind.NEW_TYPE_REFERENCE, Key.EMPTY);
+ if (LT(1) == IToken.tCOLONCOLON)
+ {
+ // global scope
+ consume();
+ }
+ consume(IToken.t_new);
+ boolean typeIdInParen = false;
+ boolean placementParseFailure = true;
+ IToken beforeSecondParen = null;
+ IToken backtrackMarker = null;
+ IASTTypeId typeId = null;
+ ArrayList newPlacementExpressions = new ArrayList();
+ ArrayList newTypeIdExpressions = new ArrayList();
+ ArrayList newInitializerExpressions = new ArrayList();
+
+ if (LT(1) == IToken.tLPAREN)
+ {
+ consume(IToken.tLPAREN);
+ try
+ {
+ // Try to consume placement list
+ // Note: since expressionList and expression are the same...
+ backtrackMarker = mark();
+ newPlacementExpressions.add(expression(scope));
+ consume(IToken.tRPAREN);
+ placementParseFailure = false;
+ if (LT(1) == IToken.tLPAREN)
+ {
+ beforeSecondParen = mark();
+ consume(IToken.tLPAREN);
+ typeIdInParen = true;
+ }
+ }
+ catch (BacktrackException e)
+ {
+ backup(backtrackMarker);
+ }
+ if (placementParseFailure)
+ {
+ // CASE: new (typeid-not-looking-as-placement) ...
+ // the first expression in () is not a placement
+ // - then it has to be typeId
+ typeId = typeId(scope, true );
+ consume(IToken.tRPAREN);
+ }
+ else
+ {
+ if (!typeIdInParen)
+ {
+ if (LT(1) == IToken.tLBRACKET)
+ {
+ // CASE: new (typeid-looking-as-placement) [expr]...
+ // the first expression in () has been parsed as a placement;
+ // however, we assume that it was in fact typeId, and this
+ // new statement creates an array.
+ // Do nothing, fallback to array/initializer processing
+ }
+ else
+ {
+ // CASE: new (placement) typeid ...
+ // the first expression in () is parsed as a placement,
+ // and the next expression doesn't start with '(' or '['
+ // - then it has to be typeId
+ try
+ {
+ backtrackMarker = mark();
+ typeId = typeId(scope, true);
+ }
+ catch (BacktrackException e)
+ {
+ // Hmmm, so it wasn't typeId after all... Then it is
+ // CASE: new (typeid-looking-as-placement)
+ backup(backtrackMarker);
+ // TODO fix this
+ return null;
+ }
+ }
+ }
+ else
+ {
+ // Tricky cases: first expression in () is parsed as a placement,
+ // and the next expression starts with '('.
+ // The problem is, the first expression might as well be a typeid
+ try
+ {
+ typeId = typeId(scope, true);
+ consume(IToken.tRPAREN);
+ if (LT(1) == IToken.tLPAREN
+ || LT(1) == IToken.tLBRACKET)
+ {
+ // CASE: new (placement)(typeid)(initializer)
+ // CASE: new (placement)(typeid)[] ...
+ // Great, so far all our assumptions have been correct
+ // Do nothing, fallback to array/initializer processing
+ }
+ else
+ {
+ // CASE: new (placement)(typeid)
+ // CASE: new (typeid-looking-as-placement)(initializer-looking-as-typeid)
+ // Worst-case scenario - this cannot be resolved w/o more semantic information.
+ // Luckily, we don't need to know what was that - we only know that
+ // new-expression ends here.
+ try
+ {
+ setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, Key.EMPTY);
+ return astFactory.createExpression(
+ scope, IASTExpression.Kind.NEW_TYPEID,
+ null, null, null, typeId, null,
+ "", astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions));
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+ }
+ catch (BacktrackException e)
+ {
+ // CASE: new (typeid-looking-as-placement)(initializer-not-looking-as-typeid)
+ // Fallback to initializer processing
+ backup(beforeSecondParen);
+ }
+ }
+ }
+ }
+ else
+ {
+ // CASE: new typeid ...
+ // new parameters do not start with '('
+ // i.e it has to be a plain typeId
+ typeId = typeId(scope, true);
+ }
+ while (LT(1) == IToken.tLBRACKET)
+ {
+ // array new
+ consume();
+ newTypeIdExpressions.add(assignmentExpression(scope));
+ consume(IToken.tRBRACKET);
+ }
+ // newinitializer
+ if (LT(1) == IToken.tLPAREN)
+ {
+ consume(IToken.tLPAREN);
+ if (LT(1) != IToken.tRPAREN)
+ newInitializerExpressions.add(expression(scope));
+ consume(IToken.tRPAREN);
+ }
+ setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, Key.EMPTY);
+ try
+ {
+ return astFactory.createExpression(
+ scope, IASTExpression.Kind.NEW_TYPEID,
+ null, null, null, typeId, null,
+ "", astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions));
+ }
+ catch (ASTSemanticException e)
+ {
+ return null;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression unaryExpression(IASTScope scope) throws EndOfFileException, BacktrackException {
+ switch (LT(1))
+ {
+ case IToken.tSTAR :
+ consume();
+ return unaryOperatorCastExpression(scope,
+ IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION);
+ case IToken.tAMPER :
+ consume();
+ return unaryOperatorCastExpression(scope,
+ IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION);
+ case IToken.tPLUS :
+ consume();
+ return unaryOperatorCastExpression(scope,
+ IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION);
+ case IToken.tMINUS :
+ consume();
+ return unaryOperatorCastExpression(scope,
+ IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION);
+ case IToken.tNOT :
+ consume();
+ return unaryOperatorCastExpression(scope,
+ IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION);
+ case IToken.tCOMPL :
+ consume();
+ return unaryOperatorCastExpression(scope,
+ IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION);
+ case IToken.tINCR :
+ consume();
+ return unaryOperatorCastExpression(scope,
+ IASTExpression.Kind.UNARY_INCREMENT);
+ case IToken.tDECR :
+ consume();
+ return unaryOperatorCastExpression(scope,
+ IASTExpression.Kind.UNARY_DECREMENT);
+ case IToken.t_sizeof :
+ consume(IToken.t_sizeof);
+ IToken mark = LA(1);
+ IASTTypeId d = null;
+ IASTExpression unaryExpression = null;
+ if (LT(1) == IToken.tLPAREN)
+ {
+ try
+ {
+ consume(IToken.tLPAREN);
+ d = typeId(scope, false);
+ consume(IToken.tRPAREN);
+ }
+ catch (BacktrackException bt)
+ {
+ backup(mark);
+ unaryExpression = unaryExpression(scope);
+ }
+ }
+ else
+ {
+ unaryExpression = unaryExpression(scope);
+ }
+ if (d != null & unaryExpression == null)
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.UNARY_SIZEOF_TYPEID,
+ null,
+ null,
+ null,
+ d,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ else if (unaryExpression != null && d == null)
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.UNARY_SIZEOF_UNARYEXPRESSION,
+ unaryExpression,
+ null,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e1)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ else
+ throw backtrack;
+ case IToken.t_new :
+ return newExpression(scope);
+ case IToken.t_delete :
+ return deleteExpression(scope);
+ case IToken.tCOLONCOLON :
+ switch (LT(2))
+ {
+ case IToken.t_new :
+ return newExpression(scope);
+ case IToken.t_delete :
+ return deleteExpression(scope);
+ default :
+ return postfixExpression(scope);
+ }
+ default :
+ return postfixExpression(scope);
+ }
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression postfixExpression(IASTScope scope) throws EndOfFileException, BacktrackException {
+ IASTExpression firstExpression = null;
+ boolean isTemplate = false;
+ checkEndOfFile();
+ switch (LT(1))
+ {
+ case IToken.t_typename :
+ consume(IToken.t_typename);
+ ITokenDuple nestedName = name(scope);
+ boolean templateTokenConsumed = false;
+ if( LT(1) == IToken.t_template )
+ {
+ consume( IToken.t_template );
+ templateTokenConsumed = true;
+ }
+ IToken current = mark();
+ ITokenDuple templateId = null;
+ try
+ {
+ templateId = new TokenDuple( current, templateId(scope) );
+ }
+ catch( BacktrackException bt )
+ {
+ if( templateTokenConsumed )
+ throw bt;
+ backup( current );
+ }
+ consume( IToken.tLPAREN );
+ IASTExpression expressionList = expression( scope );
+ consume( IToken.tRPAREN );
+ try {
+ firstExpression =
+ astFactory.createExpression( scope,
+ (( templateId != null )? IASTExpression.Kind.POSTFIX_TYPENAME_TEMPLATEID : IASTExpression.Kind.POSTFIX_TYPENAME_IDENTIFIER ),
+ expressionList,
+ null,
+ null,
+ null,
+ nestedName,
+ "",
+ null );
+ } catch (ASTSemanticException ase ) {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ // simple-type-specifier ( assignment-expression , .. )
+ case IToken.t_char :
+ firstExpression =
+ simpleTypeConstructorExpression(scope,
+ IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR);
+ break;
+ case IToken.t_wchar_t :
+ firstExpression =
+ simpleTypeConstructorExpression(scope,
+ IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART);
+ break;
+ case IToken.t_bool :
+ firstExpression =
+ simpleTypeConstructorExpression(scope,
+ IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL);
+ break;
+ case IToken.t_short :
+ firstExpression =
+ simpleTypeConstructorExpression(scope,
+ IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT);
+ break;
+ case IToken.t_int :
+ firstExpression =
+ simpleTypeConstructorExpression(scope,
+ IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT);
+ break;
+ case IToken.t_long :
+ firstExpression =
+ simpleTypeConstructorExpression(scope,
+ IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG);
+ break;
+ case IToken.t_signed :
+ firstExpression =
+ simpleTypeConstructorExpression(scope,
+ IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED);
+ break;
+ case IToken.t_unsigned :
+ firstExpression =
+ simpleTypeConstructorExpression(scope,
+ IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED);
+ break;
+ case IToken.t_float :
+ firstExpression =
+ simpleTypeConstructorExpression(scope,
+ IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT);
+ break;
+ case IToken.t_double :
+ firstExpression =
+ simpleTypeConstructorExpression( scope,
+ IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE);
+ break;
+ case IToken.t_dynamic_cast :
+ firstExpression =
+ specialCastExpression(scope,
+ IASTExpression.Kind.POSTFIX_DYNAMIC_CAST);
+ break;
+ case IToken.t_static_cast :
+ firstExpression =
+ specialCastExpression(scope,
+ IASTExpression.Kind.POSTFIX_STATIC_CAST);
+ break;
+ case IToken.t_reinterpret_cast :
+ firstExpression =
+ specialCastExpression(scope,
+ IASTExpression.Kind.POSTFIX_REINTERPRET_CAST);
+ break;
+ case IToken.t_const_cast :
+ firstExpression =
+ specialCastExpression(scope,
+ IASTExpression.Kind.POSTFIX_CONST_CAST);
+ break;
+ case IToken.t_typeid :
+ consume();
+ consume(IToken.tLPAREN);
+ boolean isTypeId = true;
+ IASTExpression lhs = null;
+ IASTTypeId typeId = null;
+ try
+ {
+ typeId = typeId(scope, false);
+ }
+ catch (BacktrackException b)
+ {
+ isTypeId = false;
+ lhs = expression(scope);
+ }
+ consume(IToken.tRPAREN);
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ (isTypeId
+ ? IASTExpression.Kind.POSTFIX_TYPEID_TYPEID
+ : IASTExpression.Kind.POSTFIX_TYPEID_EXPRESSION),
+ lhs,
+ null,
+ null,
+ typeId,
+ null, "", null);
+ }
+ catch (ASTSemanticException e6)
+ {
+ failParse();
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ default :
+ firstExpression = primaryExpression(scope);
+ }
+ IASTExpression secondExpression = null;
+ for (;;)
+ {
+ switch (LT(1))
+ {
+ case IToken.tLBRACKET :
+ // array access
+ consume();
+ secondExpression = expression(scope);
+ consume(IToken.tRBRACKET);
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.POSTFIX_SUBSCRIPT,
+ firstExpression,
+ secondExpression,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e2)
+ {
+ failParse();
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ case IToken.tLPAREN :
+ // function call
+ consume(IToken.tLPAREN);
+ secondExpression = expression(scope);
+ consume(IToken.tRPAREN);
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.POSTFIX_FUNCTIONCALL,
+ firstExpression,
+ secondExpression,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e3)
+ {
+ failParse();
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ case IToken.tINCR :
+ consume();
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.POSTFIX_INCREMENT,
+ firstExpression,
+ null,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e1)
+ {
+ failParse();
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ case IToken.tDECR :
+ consume();
+ try
+ {
+ firstExpression =
+ astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.POSTFIX_DECREMENT,
+ firstExpression,
+ null,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e4)
+ {
+ failParse();
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ case IToken.tDOT :
+ // member access
+ consume(IToken.tDOT);
+
+ if( queryLookaheadCapability() )
+ if (LT(1) == IToken.t_template)
+ {
+ consume(IToken.t_template);
+ isTemplate = true;
+ }
+
+ setCompletionValues(scope, CompletionKind.MEMBER_REFERENCE, KeywordSets.Key.EMPTY, firstExpression, isTemplate );
+
+ secondExpression = primaryExpression(scope);
+ checkEndOfFile();
+
+ setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, KeywordSets.Key.EMPTY );
+
+ 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;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ case IToken.tARROW :
+ // member access
+ consume(IToken.tARROW);
+
+ if( queryLookaheadCapability() )
+ if (LT(1) == IToken.t_template)
+ {
+ consume(IToken.t_template);
+ isTemplate = true;
+ }
+
+ setCompletionValues(scope, CompletionKind.MEMBER_REFERENCE, KeywordSets.Key.EMPTY, firstExpression, isTemplate );
+
+ secondExpression = primaryExpression(scope);
+ checkEndOfFile();
+
+ setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, KeywordSets.Key.EMPTY );
+ 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;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ break;
+ default :
+ return firstExpression;
+ }
+ }
+ }
+
+ /**
+ * @return
+ * @throws EndOfFileException
+ */
+ protected boolean queryLookaheadCapability(int count) throws EndOfFileException {
+ //make sure we can look ahead one before doing this
+ boolean result = true;
+ try
+ {
+ LA(count);
+ }
+ catch( EndOfFileException olre )
+ {
+ result = false;
+ }
+ return result;
+ }
+
+ protected boolean queryLookaheadCapability() throws EndOfFileException {
+ return queryLookaheadCapability(1);
+ }
+
+ protected void checkEndOfFile() throws EndOfFileException {
+ LA(1);
+ }
+
+ protected IASTExpression simpleTypeConstructorExpression(IASTScope scope, Kind type) throws EndOfFileException, BacktrackException {
+ consume();
+ consume(IToken.tLPAREN);
+ IASTExpression inside = expression(scope);
+ consume(IToken.tRPAREN);
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ type,
+ inside,
+ null,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ failParse();
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+
+ /**
+ * @param expression
+ * @throws BacktrackException
+ */
+ protected IASTExpression primaryExpression(IASTScope scope) throws EndOfFileException, BacktrackException {
+ IToken t = null;
+ switch (LT(1))
+ {
+ // TO DO: we need more literals...
+ case IToken.tINTEGER :
+ t = consume();
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.PRIMARY_INTEGER_LITERAL,
+ null,
+ null,
+ null,
+ null,
+ null, t.getImage(), null);
+ }
+ catch (ASTSemanticException e1)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ case IToken.tFLOATINGPT :
+ t = consume();
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.PRIMARY_FLOAT_LITERAL,
+ null,
+ null,
+ null,
+ null,
+ null, t.getImage(), null);
+ }
+ catch (ASTSemanticException e2)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ case IToken.tSTRING :
+ case IToken.tLSTRING :
+ t = consume();
+ try
+ {
+ return astFactory.createExpression( scope, IASTExpression.Kind.PRIMARY_STRING_LITERAL, null, null, null, null, null, t.getImage(), null );
+ }
+ catch (ASTSemanticException e5)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+
+ case IToken.t_false :
+ case IToken.t_true :
+ t = consume();
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL,
+ null,
+ null,
+ null,
+ null,
+ null, t.getImage(), null);
+ }
+ catch (ASTSemanticException e3)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+
+ case IToken.tCHAR :
+ case IToken.tLCHAR :
+
+ t = consume();
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.PRIMARY_CHAR_LITERAL,
+ null,
+ null,
+ null,
+ null,
+ null, t.getImage(), null);
+ }
+ catch (ASTSemanticException e4)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+
+ case IToken.t_this :
+ consume(IToken.t_this);
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.PRIMARY_THIS,
+ null,
+ null,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e7)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ case IToken.tLPAREN :
+ consume();
+ IASTExpression lhs = expression(scope);
+ consume(IToken.tRPAREN);
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION,
+ lhs,
+ null,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e6)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ case IToken.tIDENTIFIER :
+ case IToken.tCOLONCOLON :
+ case IToken.t_operator :
+ ITokenDuple duple = null;
+
+ IToken mark = mark();
+ try
+ {
+ duple = name(scope);
+ }
+ catch( BacktrackException bt )
+ {
+ Declarator d = new Declarator( new DeclarationWrapper(scope, mark.getOffset(), mark.getLineNumber(), null) );
+
+ if (LT(1) == IToken.tCOLONCOLON || LT(1) == IToken.tIDENTIFIER)
+ {
+ IToken start = consume();
+ IToken end = null;
+ if (start.getType() == IToken.tIDENTIFIER)
+ end = consumeTemplateParameters(end);
+ while (LT(1) == IToken.tCOLONCOLON || LT(1) == IToken.tIDENTIFIER)
+ {
+ end = consume();
+ if (end.getType() == IToken.tIDENTIFIER)
+ end = consumeTemplateParameters(end);
+ }
+ if (LT(1) == IToken.t_operator)
+ operatorId(d, start);
+ else
+ {
+ backup(mark);
+ throw backtrack;
+ }
+ }
+ else if( LT(1) == IToken.t_operator )
+ operatorId( d, null);
+
+ duple = d.getNameDuple();
+ }
+ catch(OffsetLimitReachedException olre )
+ {
+ backup(mark);
+ throw backtrack;
+ }
+
+ checkEndOfFile();
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.ID_EXPRESSION,
+ null,
+ null,
+ null,
+ null,
+ duple, "", null);
+ }
+ catch (ASTSemanticException e8)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ default :
+ IASTExpression empty = null;
+ try {
+ empty = astFactory.createExpression(
+ scope,
+ IASTExpression.Kind.PRIMARY_EMPTY,
+ null,
+ null,
+ null,
+ null,
+ null, "", null);
+ } catch (ASTSemanticException e9) {
+ // TODO Auto-generated catch block
+ e9.printStackTrace();
+
+ }
+ return empty;
+ }
+
+ }
+
+ protected static BacktrackException backtrack = new BacktrackException();
+ protected IScanner scanner;
+ protected IToken currToken;
+ protected IToken lastToken;
+ private boolean limitReached = false;
+
+ /**
+ * Fetches a token from the scanner.
+ *
+ * @return the next token from the scanner
+ * @throws EndOfFileException thrown when the scanner.nextToken() yields no tokens
+ */
+ protected IToken fetchToken() throws EndOfFileException {
+ if(limitReached) throw new EndOfFileException();
+
+ try
+ {
+ IToken value = scanner.nextToken();
+ handleNewToken( value );
+ return value;
+ }
+ catch( OffsetLimitReachedException olre )
+ {
+ limitReached = true;
+ handleOffsetLimitException(olre);
+ return null;
+ }
+ catch (ScannerException e)
+ {
+ log.traceLog( "ScannerException thrown : " + e.getProblem().getMessage() );
+ log.errorLog( "Scanner Exception: " + e.getProblem().getMessage()); //$NON-NLS-1$h
+ failParse();
+ return fetchToken();
+ }
+ }
+
+ /**
+ * @param value
+ */
+ protected void handleNewToken(IToken value) {
+ }
+
+ protected void handleOffsetLimitException(OffsetLimitReachedException exception) throws EndOfFileException {
+ // unexpected, throw EOF instead (equivalent)
+ throw new EndOfFileException();
+ }
+
+ /**
+ * Look Ahead in the token list to see what is coming.
+ *
+ * @param i How far ahead do you wish to peek?
+ * @return the token you wish to observe
+ * @throws EndOfFileException if looking ahead encounters EOF, throw EndOfFile
+ */
+ protected IToken LA(int i) throws EndOfFileException {
+ if (i < 1) // can't go backwards
+ return null;
+ if (currToken == null)
+ currToken = fetchToken();
+ IToken retToken = currToken;
+ for (; i > 1; --i)
+ {
+ retToken = retToken.getNext();
+ if (retToken == null)
+ retToken = fetchToken();
+ }
+ return retToken;
+ }
+
+ /**
+ * Look ahead in the token list and return the token type.
+ *
+ * @param i How far ahead do you wish to peek?
+ * @return The type of that token
+ * @throws EndOfFileException if looking ahead encounters EOF, throw EndOfFile
+ */
+ protected int LT(int i) throws EndOfFileException {
+ return LA(i).getType();
+ }
+
+ /**
+ * Consume the next token available, regardless of the type.
+ *
+ * @return The token that was consumed and removed from our buffer.
+ * @throws EndOfFileException If there is no token to consume.
+ */
+ protected IToken consume() throws EndOfFileException {
+ if (currToken == null)
+ currToken = fetchToken();
+ if (currToken != null)
+ lastToken = currToken;
+ currToken = currToken.getNext();
+ return lastToken;
+ }
+
+ /**
+ * Consume the next token available only if the type is as specified.
+ *
+ * @param type The type of token that you are expecting.
+ * @return the token that was consumed and removed from our buffer.
+ * @throws BacktrackException If LT(1) != type
+ */
+ protected IToken consume(int type) throws EndOfFileException, BacktrackException {
+ if (LT(1) == type)
+ return consume();
+ else
+ throw backtrack;
+ }
+
+ /**
+ * Mark our place in the buffer so that we could return to it should we have to.
+ *
+ * @return The current token.
+ * @throws EndOfFileException If there are no more tokens.
+ */
+ protected IToken mark() throws EndOfFileException {
+ if (currToken == null)
+ currToken = fetchToken();
+ return currToken;
+ }
+
+ /**
+ * Rollback to a previous point, reseting the queue of tokens.
+ *
+ * @param mark The point that we wish to restore to.
+ *
+ */
+ protected void backup(IToken mark) {
+ currToken = (Token)mark;
+ lastToken = null; // this is not entirely right ...
+ }
+
+ protected IASTExpression assignmentOperatorExpression(IASTScope scope, IASTExpression.Kind kind, IASTExpression lhs) throws EndOfFileException, BacktrackException {
+ consume();
+ IASTExpression assignmentExpression = assignmentExpression(scope);
+
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ kind,
+ lhs,
+ assignmentExpression,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+
+ protected void setCompletionValues(IASTScope scope, IASTCompletionNode.CompletionKind kind, KeywordSets.Key key) throws EndOfFileException {
+ }
+
+ protected void setCompletionValues(IASTScope scope, IASTCompletionNode.CompletionKind kind, KeywordSets.Key key, IASTNode node, String prefix) throws EndOfFileException {
+ }
+
+ protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTExpression firstExpression, boolean isTemplate) throws EndOfFileException {
+ }
+
+ protected IASTExpression unaryOperatorCastExpression(IASTScope scope, IASTExpression.Kind kind) throws EndOfFileException, BacktrackException {
+ IASTExpression castExpression = castExpression(scope);
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ kind,
+ castExpression,
+ null,
+ null,
+ null,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+
+ protected IASTExpression specialCastExpression(IASTScope scope, IASTExpression.Kind kind) throws EndOfFileException, BacktrackException {
+ consume();
+ consume(IToken.tLT);
+ IASTTypeId duple = typeId(scope, false);
+ consume(IToken.tGT);
+ consume(IToken.tLPAREN);
+ IASTExpression lhs = expression(scope);
+ consume(IToken.tRPAREN);
+ try
+ {
+ return astFactory.createExpression(
+ scope,
+ kind,
+ lhs,
+ null,
+ null,
+ duple,
+ null, "", null);
+ }
+ catch (ASTSemanticException e)
+ {
+ throw backtrack;
+ } catch (Exception e)
+ {
+ throw backtrack;
+ }
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IExpressionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IExpressionParser.java
new file mode 100644
index 00000000000..54e49fc5145
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IExpressionParser.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2000 - 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser;
+
+import org.eclipse.cdt.core.parser.BacktrackException;
+import org.eclipse.cdt.core.parser.EndOfFileException;
+import org.eclipse.cdt.core.parser.ast.IASTExpression;
+import org.eclipse.cdt.core.parser.ast.IASTScope;
+
+/**
+ * @author jcamelon
+ */
+public interface IExpressionParser {
+
+ /**
+ * Request a parse from a pre-configured parser to parse an expression.
+ *
+ * @param expression Optional parameter representing an expression object that
+ * your particular IParserCallback instance would appreciate
+ *
+ * @throws BacktrackException thrown if the Scanner/Stream provided does not yield a valid
+ * expression
+ */
+ public IASTExpression expression(IASTScope scope) throws BacktrackException, EndOfFileException;
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserFactory.java
new file mode 100644
index 00000000000..83b4ba6cebb
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/InternalParserFactory.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2000 - 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser;
+
+import org.eclipse.cdt.core.parser.IParserLogService;
+import org.eclipse.cdt.core.parser.IScanner;
+import org.eclipse.cdt.core.parser.ParserFactory;
+import org.eclipse.cdt.core.parser.ParserFactoryError;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+
+/**
+ * @author jcamelon
+ */
+public class InternalParserFactory extends ParserFactory {
+
+ public static IExpressionParser createExpressionParser( IScanner scanner, ParserLanguage language, IParserLogService log ) throws ParserFactoryError
+ {
+ if( scanner == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_SCANNER );
+ if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE );
+ IParserLogService logService = ( log == null ) ? createDefaultLogService() : log;
+ return new ExpressionParser( scanner, language, logService );
+ }
+
+}
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 a341095b45c..062d9fe94d1 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
@@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.core.parser;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.Stack;
import org.eclipse.cdt.core.parser.BacktrackException;
import org.eclipse.cdt.core.parser.EndOfFileException;
@@ -23,14 +22,12 @@ import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple;
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
+import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserLanguage;
-import org.eclipse.cdt.core.parser.ScannerException;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
-import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.ASTSemanticException;
import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
-import org.eclipse.cdt.core.parser.ast.IASTArrayModifier;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
@@ -40,7 +37,6 @@ import org.eclipse.cdt.core.parser.ast.IASTDesignator;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTExpression;
-import org.eclipse.cdt.core.parser.ast.IASTFactory;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
@@ -59,9 +55,7 @@ import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
-import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
-import org.eclipse.cdt.internal.core.parser.token.Token;
import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key;
@@ -73,42 +67,13 @@ import org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key;
*
* @author jcamelon
*/
-public abstract class Parser implements IParser
+public abstract class Parser extends ExpressionParser implements IParser
{
- protected final IParserLogService log;
- private static final List EMPTY_LIST = new ArrayList();
- private static int FIRST_ERROR_OFFSET_UNSET = -1;
- // sentinel initial value for offsets
- protected int firstErrorOffset = FIRST_ERROR_OFFSET_UNSET;
- // offset where the first parse error occurred
-
- // are we doing the high-level parse, or an in depth parse?
- protected boolean parsePassed = true; // did the parse pass?
- protected ParserLanguage language = ParserLanguage.CPP; // C or CPP
+ private static final List EMPTY_LIST = new ArrayList();
protected ISourceElementRequestor requestor = null;
- // new callback mechanism
- protected IASTFactory astFactory = null; // ast factory
- /**
- * This is the single entry point for setting parsePassed to
- * false, and also making note what token offset we failed upon.
- *
- * @throws EndOfFileException
- */
- protected void failParse()
- {
- try
- {
- if (firstErrorOffset == FIRST_ERROR_OFFSET_UNSET )
- firstErrorOffset = LA(1).getOffset();
- } catch( EndOfFileException eof )
- {
- // do nothing
- }
- finally
- {
- parsePassed = false;
- }
- }
+
+
+
/**
* This is the standard cosntructor that we expect the Parser to be instantiated
* with.
@@ -123,11 +88,8 @@ public abstract class Parser implements IParser
ParserLanguage language,
IParserLogService log )
{
- this.scanner = scanner;
- this.requestor = callback;
- this.language = language;
- this.log = log;
-
+ super( scanner, language, log );
+ requestor = callback;
}
// counter that keeps track of the number of times Parser.parse() is called
@@ -768,9 +730,10 @@ public abstract class Parser implements IParser
return;
}
default :
- simpleDeclarationStrategyUnion(scope, ownerTemplate, overideKind);
+ simpleDeclarationStrategyUnion(scope, ownerTemplate, overideKind );
}
- setCompletionValues(scope, kind, Key.DECLARATION );
+ setCompletionValues(scope, kind, Key.DECLARATION );
+ checkEndOfFile();
}
/**
@@ -896,7 +859,7 @@ public abstract class Parser implements IParser
if (checkToken == LA(1))
errorHandling();
}
- setCompletionValues(scope, CompletionKind.NO_SUCH_KIND,Key.EMPTY);
+ setCompletionValues(scope, CompletionKind.NO_SUCH_KIND,Key.EMPTY );
// consume the }
IToken last = consume(IToken.tRBRACE);
@@ -1709,59 +1672,6 @@ public abstract class Parser implements IParser
if( isForewardDecl )
((IASTElaboratedTypeSpecifier)elaboratedTypeSpec).acceptElement( requestor );
}
- /**
- * Consumes template parameters.
- *
- * @param previousLast Previous "last" token (returned if nothing was consumed)
- * @return Last consumed token, or previousLast
if nothing was consumed
- * @throws BacktrackException request a backtrack
- */
- protected IToken consumeTemplateParameters(IToken previousLast)
- throws EndOfFileException, BacktrackException
- {
- IToken last = previousLast;
- if (LT(1) == IToken.tLT)
- {
- last = consume(IToken.tLT);
- // until we get all the names sorted out
- Stack scopes = new Stack();
- scopes.push(new Integer(IToken.tLT));
-
- while (!scopes.empty())
- {
- int top;
- last = consume();
-
- switch (last.getType()) {
- case IToken.tGT :
- if (((Integer)scopes.peek()).intValue() == IToken.tLT) {
- scopes.pop();
- }
- break;
- case IToken.tRBRACKET :
- do {
- top = ((Integer)scopes.pop()).intValue();
- } while (!scopes.empty() && (top == IToken.tGT || top == IToken.tLT));
- if (top != IToken.tLBRACKET) throw backtrack;
-
- break;
- case IToken.tRPAREN :
- do {
- top = ((Integer)scopes.pop()).intValue();
- } while (!scopes.empty() && (top == IToken.tGT || top == IToken.tLT));
- if (top != IToken.tLPAREN) throw backtrack;
-
- break;
- case IToken.tLT :
- case IToken.tLBRACKET:
- case IToken.tLPAREN:
- scopes.push(new Integer(last.getType()));
- break;
- }
- }
- }
- return last;
- }
/**
* Parse an identifier.
*
@@ -1790,133 +1700,6 @@ public abstract class Parser implements IParser
return new TokenDuple(duple.getFirstToken(), last);
}
- /**
- * Parse a template-id, according to the ANSI C++ spec.
- *
- * template-id: template-name < template-argument-list opt >
- * template-name : identifier
- *
- * @return the last token that we consumed in a successful parse
- *
- * @throws BacktrackException request a backtrack
- */
- protected IToken templateId(IASTScope scope) throws EndOfFileException, BacktrackException
- {
- ITokenDuple duple = name(scope);
- IToken last = consumeTemplateParameters(duple.getLastToken());
- return last;
- }
- /**
- * Parse a name.
- *
- * name
- * : ("::")? name2 ("::" name2)*
- *
- * name2
- * : IDENTIFER
- *
- * @throws BacktrackException request a backtrack
- */
- protected TokenDuple name(IASTScope scope) throws BacktrackException, EndOfFileException
- {
- IToken first = LA(1);
- IToken last = null;
- IToken mark = mark();
-
- try
- {
- if (LT(1) == IToken.tCOLONCOLON)
- last = consume( IToken.tCOLONCOLON );
- // TODO - whacky way to deal with destructors, please revisit
- if (LT(1) == IToken.tCOMPL)
- consume();
- switch (LT(1))
- {
- case IToken.tIDENTIFIER :
- last = consume(IToken.tIDENTIFIER);
- IToken secondMark = null;
- if( queryLookaheadCapability() )
- secondMark = mark();
- else
- return new TokenDuple(last, last);
-
- try
- {
- last = consumeTemplateParameters(last);
- } catch( BacktrackException bt )
- {
- backup( secondMark );
- }
- break;
- default :
- backup(mark);
- throw backtrack;
- }
- while (LT(1) == IToken.tCOLONCOLON)
- {
- last = consume();
- if (LT(1) == IToken.t_template)
- consume();
- if (LT(1) == IToken.tCOMPL)
- consume();
- switch (LT(1))
- {
- case IToken.t_operator :
- backup(mark);
- throw backtrack;
- case IToken.tIDENTIFIER :
- last = consume();
- last = consumeTemplateParameters(last);
- }
- }
-
- return new TokenDuple(first, last);
- } catch( OffsetLimitReachedException olre )
- {
- backup(mark);
- throw backtrack;
- }
- }
- /**
- * Parse a const-volatile qualifier.
- *
- * cvQualifier
- * : "const" | "volatile"
- *
- * TODO: fix this
- * @param ptrOp Pointer Operator that const-volatile applies to.
- * @return Returns the same object sent in.
- * @throws BacktrackException
- */
- protected IToken cvQualifier(
- IDeclarator declarator)
- throws EndOfFileException, BacktrackException
- {
- IToken result = null;
- switch (LT(1))
- {
- case IToken.t_const :
- result = consume( IToken.t_const );
- declarator.addPointerOperator(ASTPointerOperator.CONST_POINTER);
- break;
- case IToken.t_volatile :
- result = consume( IToken.t_volatile );
- declarator.addPointerOperator(ASTPointerOperator.VOLATILE_POINTER);
- break;
- case IToken.t_restrict :
- if( language == ParserLanguage.C )
- {
- result = consume( IToken.t_restrict );
- declarator.addPointerOperator(ASTPointerOperator.RESTRICT_POINTER);
- break;
- }
- else
- throw backtrack;
- default :
-
- }
- return result;
- }
/**
* Parses the initDeclarator construct of the ANSI C++ spec.
*
@@ -2441,145 +2224,6 @@ public abstract class Parser implements IParser
}
}
}
- protected void consumeArrayModifiers( IDeclarator d, IASTScope scope )
- throws EndOfFileException, BacktrackException
- {
- while (LT(1) == IToken.tLBRACKET)
- {
- consume( IToken.tLBRACKET ); // eat the '['
-
- IASTExpression exp = null;
- if (LT(1) != IToken.tRBRACKET)
- {
- exp = constantExpression(scope);
- }
- consume(IToken.tRBRACKET);
- IASTArrayModifier arrayMod;
- try
- {
- arrayMod = astFactory.createArrayModifier(exp);
- }
- catch (Exception e)
- {
- throw backtrack;
- }
- d.addArrayModifier(arrayMod);
- }
- }
-
- protected void operatorId(
- Declarator d,
- IToken originalToken)
- throws BacktrackException, EndOfFileException
- {
- // we know this is an operator
- IToken operatorToken = consume(IToken.t_operator);
- IToken toSend = null;
- if (LA(1).isOperator()
- || LT(1) == IToken.tLPAREN
- || LT(1) == IToken.tLBRACKET)
- {
- if ((LT(1) == IToken.t_new || LT(1) == IToken.t_delete)
- && LT(2) == IToken.tLBRACKET
- && LT(3) == IToken.tRBRACKET)
- {
- consume();
- consume(IToken.tLBRACKET);
- toSend = consume(IToken.tRBRACKET);
- // vector new and delete operators
- }
- else if (LT(1) == IToken.tLPAREN && LT(2) == IToken.tRPAREN)
- {
- // operator ()
- consume(IToken.tLPAREN);
- toSend = consume(IToken.tRPAREN);
- }
- else if (LT(1) == IToken.tLBRACKET && LT(2) == IToken.tRBRACKET)
- {
- consume(IToken.tLBRACKET);
- toSend = consume(IToken.tRBRACKET);
- }
- else if (LA(1).isOperator())
- toSend = consume();
- else
- throw backtrack;
- }
- else
- {
- // must be a conversion function
- typeId(d.getDeclarationWrapper().getScope(), true );
- toSend = lastToken;
- }
- ITokenDuple duple =
- new TokenDuple(
- originalToken == null ? operatorToken : originalToken,
- toSend);
-
- d.setName(duple);
- }
- /**
- * Parse a Pointer Operator.
- *
- * ptrOperator
- * : "*" (cvQualifier)*
- * | "&"
- * | ::? nestedNameSpecifier "*" (cvQualifier)*
- *
- * @param owner Declarator that this pointer operator corresponds to.
- * @throws BacktrackException request a backtrack
- */
- protected IToken consumePointerOperators(IDeclarator d) throws EndOfFileException, BacktrackException
- {
- IToken result = null;
- for( ; ; )
- {
- if (LT(1) == IToken.tAMPER)
- {
- result = consume( IToken.tAMPER );
- d.addPointerOperator(ASTPointerOperator.REFERENCE);
- return result;
-
- }
- IToken mark = mark();
-
- ITokenDuple nameDuple = null;
- if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON)
- {
- try
- {
- nameDuple = name(d.getScope());
- }
- catch( BacktrackException bt )
- {
- backup( mark );
- return null;
- }
- }
- if ( LT(1) == IToken.tSTAR)
- {
- result = consume(IToken.tSTAR); // tokenType = "*"
-
- d.setPointerOperatorName(nameDuple);
-
- IToken successful = null;
- for (;;)
- {
- IToken newSuccess = cvQualifier(d);
- if( newSuccess != null ) successful = newSuccess;
- else break;
-
- }
-
- if( successful == null )
- {
- d.addPointerOperator( ASTPointerOperator.POINTER );
- }
- continue;
- }
- backup(mark);
- return result;
- }
- }
/**
* Parse an enumeration specifier, as according to the ANSI specs in C & C++.
*
@@ -3237,2007 +2881,7 @@ public abstract class Parser implements IParser
if( createNewScope )
newScope.exitScope( requestor );
}
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression constantExpression( IASTScope scope )
- throws BacktrackException, EndOfFileException
- {
- return conditionalExpression(scope);
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.parser.IParser#expression(java.lang.Object)
- */
- public IASTExpression expression(IASTScope scope) throws BacktrackException, EndOfFileException
- {
- IASTExpression assignmentExpression = assignmentExpression(scope);
- while (LT(1) == IToken.tCOMMA)
- {
- consume();
- IASTExpression secondExpression = assignmentExpression(scope);
- try
- {
- assignmentExpression =
- astFactory.createExpression(
- scope,
- IASTExpression.Kind.EXPRESSIONLIST,
- assignmentExpression,
- secondExpression,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- return assignmentExpression;
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression assignmentExpression(IASTScope scope)
- throws EndOfFileException, BacktrackException {
- if (LT(1) == IToken.t_throw) {
- return throwExpression(scope);
- }
- IASTExpression conditionalExpression = conditionalExpression(scope);
- // if the condition not taken, try assignment operators
- if (conditionalExpression != null
- && conditionalExpression.getExpressionKind()
- == IASTExpression.Kind.CONDITIONALEXPRESSION)
- return conditionalExpression;
- switch (LT(1)) {
- case IToken.tASSIGN :
- return assignmentOperatorExpression(
- scope,
- IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL,
- conditionalExpression);
- case IToken.tSTARASSIGN :
- return assignmentOperatorExpression(
- scope,
- IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT,
- conditionalExpression);
- case IToken.tDIVASSIGN :
- return assignmentOperatorExpression(
- scope,
- IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV,
- conditionalExpression);
- case IToken.tMODASSIGN :
- return assignmentOperatorExpression(
- scope,
- IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD,
- conditionalExpression);
- case IToken.tPLUSASSIGN :
- return assignmentOperatorExpression(
- scope,
- IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS,
- conditionalExpression);
- case IToken.tMINUSASSIGN :
- return assignmentOperatorExpression(
- scope,
- IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS,
- conditionalExpression);
- case IToken.tSHIFTRASSIGN :
- return assignmentOperatorExpression(
- scope,
- IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT,
- conditionalExpression);
- case IToken.tSHIFTLASSIGN :
- return assignmentOperatorExpression(
- scope,
- IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT,
- conditionalExpression);
- case IToken.tAMPERASSIGN :
- return assignmentOperatorExpression(
- scope,
- IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND,
- conditionalExpression);
- case IToken.tXORASSIGN :
- return assignmentOperatorExpression(
- scope,
- IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR,
- conditionalExpression);
- case IToken.tBITORASSIGN :
- return assignmentOperatorExpression(
- scope,
- IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR,
- conditionalExpression);
- }
- return conditionalExpression;
- }
- protected IASTExpression assignmentOperatorExpression(
- IASTScope scope,
- IASTExpression.Kind kind, IASTExpression lhs )
- throws EndOfFileException, BacktrackException
- {
- consume();
- IASTExpression assignmentExpression = assignmentExpression(scope);
-
- try
- {
- return astFactory.createExpression(
- scope,
- kind,
- lhs,
- assignmentExpression,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression throwExpression( IASTScope scope )
- throws EndOfFileException, BacktrackException
- {
- consume(IToken.t_throw);
- IASTExpression throwExpression = null;
- try
- {
- throwExpression = expression(scope);
- }
- catch (BacktrackException b)
- {
- }
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.THROWEXPRESSION,
- throwExpression,
- null,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- /**
- * @param expression
- * @return
- * @throws BacktrackException
- */
- protected IASTExpression conditionalExpression( IASTScope scope )
- throws BacktrackException, EndOfFileException
- {
- IASTExpression firstExpression = logicalOrExpression(scope);
- if (LT(1) == IToken.tQUESTION)
- {
- consume();
- IASTExpression secondExpression = expression(scope);
- consume(IToken.tCOLON);
- IASTExpression thirdExpression = assignmentExpression(scope);
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.CONDITIONALEXPRESSION,
- firstExpression,
- secondExpression,
- thirdExpression,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- else
- return firstExpression;
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression logicalOrExpression(IASTScope scope)
- throws BacktrackException, EndOfFileException
- {
- IASTExpression firstExpression = logicalAndExpression(scope);
- while (LT(1) == IToken.tOR)
- {
- consume();
- IASTExpression secondExpression = logicalAndExpression(scope);
-
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- IASTExpression.Kind.LOGICALOREXPRESSION,
- firstExpression,
- secondExpression,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- return firstExpression;
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression logicalAndExpression( IASTScope scope )
- throws BacktrackException, EndOfFileException
- {
- IASTExpression firstExpression = inclusiveOrExpression( scope );
- while (LT(1) == IToken.tAND)
- {
- consume();
- IASTExpression secondExpression = inclusiveOrExpression( scope );
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- IASTExpression.Kind.LOGICALANDEXPRESSION,
- firstExpression,
- secondExpression,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- return firstExpression;
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression inclusiveOrExpression( IASTScope scope )
- throws BacktrackException, EndOfFileException
- {
- IASTExpression firstExpression = exclusiveOrExpression(scope);
- while (LT(1) == IToken.tBITOR)
- {
- consume();
- IASTExpression secondExpression = exclusiveOrExpression(scope);
-
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- IASTExpression.Kind.INCLUSIVEOREXPRESSION,
- firstExpression,
- secondExpression,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- return firstExpression;
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression exclusiveOrExpression( IASTScope scope )
- throws BacktrackException, EndOfFileException
- {
- IASTExpression firstExpression = andExpression( scope );
- while (LT(1) == IToken.tXOR)
- {
- consume();
-
- IASTExpression secondExpression = andExpression( scope );
-
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- IASTExpression.Kind.EXCLUSIVEOREXPRESSION,
- firstExpression,
- secondExpression,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- return firstExpression;
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression andExpression(IASTScope scope) throws EndOfFileException, BacktrackException
- {
- IASTExpression firstExpression = equalityExpression(scope);
- while (LT(1) == IToken.tAMPER)
- {
- consume();
- IASTExpression secondExpression = equalityExpression(scope);
-
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- IASTExpression.Kind.ANDEXPRESSION,
- firstExpression,
- secondExpression,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- return firstExpression;
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression equalityExpression( IASTScope scope )
- throws EndOfFileException, BacktrackException
- {
- IASTExpression firstExpression = relationalExpression(scope);
- for (;;)
- {
- switch (LT(1))
- {
- case IToken.tEQUAL :
- case IToken.tNOTEQUAL :
- IToken t = consume();
- IASTExpression secondExpression =
- relationalExpression(scope);
-
- 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)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- default :
- return firstExpression;
- }
- }
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression relationalExpression(IASTScope scope)
- throws BacktrackException, EndOfFileException
- {
- IASTExpression firstExpression = shiftExpression(scope);
- for (;;)
- {
- switch (LT(1))
- {
- case IToken.tGT :
- case IToken.tLT :
- case IToken.tLTEQUAL :
- case IToken.tGTEQUAL :
- IToken mark = mark();
- IToken t = consume();
- IToken next = LA(1);
- IASTExpression secondExpression =
- shiftExpression(scope);
- if (next == LA(1))
- {
- // we did not consume anything
- // this is most likely an error
- backup(mark);
- return firstExpression;
- }
- else
- {
- IASTExpression.Kind kind = null;
- switch (t.getType())
- {
- case IToken.tGT :
- kind =
- IASTExpression.Kind.RELATIONAL_GREATERTHAN;
- break;
- case IToken.tLT :
- kind = IASTExpression.Kind.RELATIONAL_LESSTHAN;
- break;
- case IToken.tLTEQUAL :
- kind =
- IASTExpression
- .Kind
- .RELATIONAL_LESSTHANEQUALTO;
- break;
- case IToken.tGTEQUAL :
- kind =
- IASTExpression
- .Kind
- .RELATIONAL_GREATERTHANEQUALTO;
- break;
- }
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- kind,
- firstExpression,
- secondExpression,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- break;
- default :
- return firstExpression;
- }
- }
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression shiftExpression(IASTScope scope)
- throws BacktrackException, EndOfFileException
- {
- IASTExpression firstExpression = additiveExpression(scope);
- for (;;)
- {
- switch (LT(1))
- {
- case IToken.tSHIFTL :
- case IToken.tSHIFTR :
- IToken t = consume();
- IASTExpression secondExpression =
- 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)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- default :
- return firstExpression;
- }
- }
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression additiveExpression( IASTScope scope )
- throws BacktrackException, EndOfFileException
- {
- IASTExpression firstExpression = multiplicativeExpression( scope );
- for (;;)
- {
- switch (LT(1))
- {
- case IToken.tPLUS :
- case IToken.tMINUS :
- IToken t = consume();
- IASTExpression secondExpression =
- 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)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- default :
- return firstExpression;
- }
- }
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression multiplicativeExpression( IASTScope scope )
- throws BacktrackException, EndOfFileException
- {
- IASTExpression firstExpression = pmExpression(scope);
- for (;;)
- {
- switch (LT(1))
- {
- case IToken.tSTAR :
- case IToken.tDIV :
- case IToken.tMOD :
- IToken t = consume();
- IASTExpression secondExpression = pmExpression(scope);
- IASTExpression.Kind kind = null;
- switch (t.getType())
- {
- case IToken.tSTAR :
- kind = IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY;
- break;
- case IToken.tDIV :
- kind = IASTExpression.Kind.MULTIPLICATIVE_DIVIDE;
- break;
- case IToken.tMOD :
- kind = IASTExpression.Kind.MULTIPLICATIVE_MODULUS;
- break;
- }
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- kind,
- firstExpression,
- secondExpression,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- default :
- return firstExpression;
- }
- }
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression pmExpression( IASTScope scope ) throws EndOfFileException, BacktrackException
- {
- IASTExpression firstExpression = castExpression(scope);
- for (;;)
- {
- switch (LT(1))
- {
- case IToken.tDOTSTAR :
- case IToken.tARROWSTAR :
- IToken t = consume();
- IASTExpression secondExpression =
- 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)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- default :
- return firstExpression;
- }
- }
- }
- /**
- * castExpression
- * : unaryExpression
- * | "(" typeId ")" castExpression
- */
- protected IASTExpression castExpression( IASTScope scope ) throws EndOfFileException, BacktrackException
- {
- // TO DO: we need proper symbol checkint to ensure type name
- if (LT(1) == IToken.tLPAREN)
- {
- IToken mark = mark();
- consume();
- IASTTypeId typeId = null;
- // If this isn't a type name, then we shouldn't be here
- try
- {
- typeId = typeId(scope, false);
- consume(IToken.tRPAREN);
- IASTExpression castExpression = castExpression(scope);
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.CASTEXPRESSION,
- castExpression,
- null,
- null,
- typeId,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- catch (BacktrackException b)
- {
- backup(mark);
- }
- }
- return unaryExpression(scope);
-
- }
- /**
- * @throws BacktrackException
- */
- protected IASTTypeId typeId(IASTScope scope, boolean skipArrayModifiers ) throws EndOfFileException, BacktrackException
- {
- IToken mark = mark();
- ITokenDuple name = null;
- boolean isConst = false, isVolatile = false;
- boolean isSigned = false, isUnsigned = false;
- boolean isShort = false, isLong = false;
- boolean isTypename = false;
-
- IASTSimpleTypeSpecifier.Type kind = null;
- do
- {
- try
- {
- name = name(scope);
- kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
- break;
- }
- catch (BacktrackException b)
- {
- // do nothing
- }
-
- boolean encounteredType = false;
- simpleMods : for (;;)
- {
- switch (LT(1))
- {
- case IToken.t_signed :
- consume();
- isSigned = true;
- break;
-
- case IToken.t_unsigned :
- consume();
- isUnsigned = true;
- break;
-
- case IToken.t_short :
- consume();
- isShort = true;
- break;
-
- case IToken.t_long :
- consume();
- isLong = true;
- break;
-
- case IToken.t_const :
- consume();
- isConst = true;
- break;
-
- case IToken.t_volatile :
- consume();
- isVolatile = true;
- break;
-
- case IToken.tIDENTIFIER :
- if( encounteredType ) break simpleMods;
- encounteredType = true;
- name = name(scope);
- kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
- break;
-
- case IToken.t_int :
- if( encounteredType ) break simpleMods;
- encounteredType = true;
- kind = IASTSimpleTypeSpecifier.Type.INT;
- consume();
- break;
-
- case IToken.t_char :
- if( encounteredType ) break simpleMods;
- encounteredType = true;
- kind = IASTSimpleTypeSpecifier.Type.CHAR;
- consume();
- break;
-
- case IToken.t_bool :
- if( encounteredType ) break simpleMods;
- encounteredType = true;
- kind = IASTSimpleTypeSpecifier.Type.BOOL;
- consume();
- break;
-
- case IToken.t_double :
- if( encounteredType ) break simpleMods;
- encounteredType = true;
- kind = IASTSimpleTypeSpecifier.Type.DOUBLE;
- consume();
- break;
-
- case IToken.t_float :
- if( encounteredType ) break simpleMods;
- encounteredType = true;
- kind = IASTSimpleTypeSpecifier.Type.FLOAT;
- consume();
- break;
-
- case IToken.t_wchar_t :
- if( encounteredType ) break simpleMods;
- encounteredType = true;
- kind = IASTSimpleTypeSpecifier.Type.WCHAR_T;
- consume();
- break;
-
-
- case IToken.t_void :
- if( encounteredType ) break simpleMods;
- encounteredType = true;
- kind = IASTSimpleTypeSpecifier.Type.VOID;
- consume();
- break;
-
- case IToken.t__Bool :
- if( encounteredType ) break simpleMods;
- encounteredType = true;
- kind = IASTSimpleTypeSpecifier.Type._BOOL;
- consume();
- break;
-
- default :
- break simpleMods;
- }
- }
-
- if( kind != null ) break;
-
- if( isShort || isLong || isUnsigned || isSigned )
- {
- kind = IASTSimpleTypeSpecifier.Type.INT;
- break;
- }
-
- if (
- LT(1) == IToken.t_typename
- || LT(1) == IToken.t_struct
- || LT(1) == IToken.t_class
- || LT(1) == IToken.t_enum
- || LT(1) == IToken.t_union)
- {
- consume();
- try
- {
- name = name(scope);
- kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME;
- } catch( BacktrackException b )
- {
- backup( mark );
- throw backtrack;
- }
- }
-
- } while( false );
-
- if( kind == null )
- throw backtrack;
-
- TypeId id = new TypeId(scope);
- IToken last = lastToken;
-
- lastToken = consumeTemplateParameters( last );
- if( lastToken == null ) lastToken = last;
-
- consumePointerOperators( id );
- if( lastToken == null ) lastToken = last;
-
- if( ! skipArrayModifiers )
- {
- last = lastToken;
- consumeArrayModifiers( id, scope );
- if( lastToken == null ) lastToken = last;
- }
-
- try
- {
- return astFactory.createTypeId( scope, kind, isConst, isVolatile, isShort, isLong, isSigned, isUnsigned, isTypename, name, id.getPointerOperators(), id.getArrayModifiers());
- }
- catch (ASTSemanticException e)
- {
- backup( mark );
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression deleteExpression( IASTScope scope )
- throws EndOfFileException, BacktrackException
- {
- if (LT(1) == IToken.tCOLONCOLON)
- {
- // global scope
- consume();
- }
- consume(IToken.t_delete);
- boolean vectored = false;
- if (LT(1) == IToken.tLBRACKET)
- {
- // array delete
- consume();
- consume(IToken.tRBRACKET);
- vectored = true;
- }
- 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)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- /**
- * Pazse a new-expression.
- *
- * @param expression
- * @throws BacktrackException
- *
- *
- * newexpression: ::? new newplacement? newtypeid newinitializer?
- * ::? new newplacement? ( typeid ) newinitializer?
- * newplacement: ( expressionlist )
- * newtypeid: typespecifierseq newdeclarator?
- * newdeclarator: ptroperator newdeclarator? | directnewdeclarator
- * directnewdeclarator: [ expression ]
- * directnewdeclarator [ constantexpression ]
- * newinitializer: ( expressionlist? )
- */
- protected IASTExpression newExpression( IASTScope scope ) throws BacktrackException, EndOfFileException
- {
- setCompletionValues(scope, CompletionKind.NEW_TYPE_REFERENCE, Key.EMPTY);
- if (LT(1) == IToken.tCOLONCOLON)
- {
- // global scope
- consume();
- }
- consume(IToken.t_new);
- boolean typeIdInParen = false;
- boolean placementParseFailure = true;
- IToken beforeSecondParen = null;
- IToken backtrackMarker = null;
- IASTTypeId typeId = null;
- ArrayList newPlacementExpressions = new ArrayList();
- ArrayList newTypeIdExpressions = new ArrayList();
- ArrayList newInitializerExpressions = new ArrayList();
-
- if (LT(1) == IToken.tLPAREN)
- {
- consume(IToken.tLPAREN);
- try
- {
- // Try to consume placement list
- // Note: since expressionList and expression are the same...
- backtrackMarker = mark();
- newPlacementExpressions.add(expression(scope));
- consume(IToken.tRPAREN);
- placementParseFailure = false;
- if (LT(1) == IToken.tLPAREN)
- {
- beforeSecondParen = mark();
- consume(IToken.tLPAREN);
- typeIdInParen = true;
- }
- }
- catch (BacktrackException e)
- {
- backup(backtrackMarker);
- }
- if (placementParseFailure)
- {
- // CASE: new (typeid-not-looking-as-placement) ...
- // the first expression in () is not a placement
- // - then it has to be typeId
- typeId = typeId(scope, true );
- consume(IToken.tRPAREN);
- }
- else
- {
- if (!typeIdInParen)
- {
- if (LT(1) == IToken.tLBRACKET)
- {
- // CASE: new (typeid-looking-as-placement) [expr]...
- // the first expression in () has been parsed as a placement;
- // however, we assume that it was in fact typeId, and this
- // new statement creates an array.
- // Do nothing, fallback to array/initializer processing
- }
- else
- {
- // CASE: new (placement) typeid ...
- // the first expression in () is parsed as a placement,
- // and the next expression doesn't start with '(' or '['
- // - then it has to be typeId
- try
- {
- backtrackMarker = mark();
- typeId = typeId(scope, true);
- }
- catch (BacktrackException e)
- {
- // Hmmm, so it wasn't typeId after all... Then it is
- // CASE: new (typeid-looking-as-placement)
- backup(backtrackMarker);
- // TODO fix this
- return null;
- }
- }
- }
- else
- {
- // Tricky cases: first expression in () is parsed as a placement,
- // and the next expression starts with '('.
- // The problem is, the first expression might as well be a typeid
- try
- {
- typeId = typeId(scope, true);
- consume(IToken.tRPAREN);
- if (LT(1) == IToken.tLPAREN
- || LT(1) == IToken.tLBRACKET)
- {
- // CASE: new (placement)(typeid)(initializer)
- // CASE: new (placement)(typeid)[] ...
- // Great, so far all our assumptions have been correct
- // Do nothing, fallback to array/initializer processing
- }
- else
- {
- // CASE: new (placement)(typeid)
- // CASE: new (typeid-looking-as-placement)(initializer-looking-as-typeid)
- // Worst-case scenario - this cannot be resolved w/o more semantic information.
- // Luckily, we don't need to know what was that - we only know that
- // new-expression ends here.
- try
- {
- setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, Key.EMPTY);
- return astFactory.createExpression(
- scope, IASTExpression.Kind.NEW_TYPEID,
- null, null, null, typeId, null,
- "", astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions));
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- }
- catch (BacktrackException e)
- {
- // CASE: new (typeid-looking-as-placement)(initializer-not-looking-as-typeid)
- // Fallback to initializer processing
- backup(beforeSecondParen);
- }
- }
- }
- }
- else
- {
- // CASE: new typeid ...
- // new parameters do not start with '('
- // i.e it has to be a plain typeId
- typeId = typeId(scope, true);
- }
- while (LT(1) == IToken.tLBRACKET)
- {
- // array new
- consume();
- newTypeIdExpressions.add(assignmentExpression(scope));
- consume(IToken.tRBRACKET);
- }
- // newinitializer
- if (LT(1) == IToken.tLPAREN)
- {
- consume(IToken.tLPAREN);
- if (LT(1) != IToken.tRPAREN)
- newInitializerExpressions.add(expression(scope));
- consume(IToken.tRPAREN);
- }
- setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, Key.EMPTY);
- try
- {
- return astFactory.createExpression(
- scope, IASTExpression.Kind.NEW_TYPEID,
- null, null, null, typeId, null,
- "", astFactory.createNewDescriptor(newPlacementExpressions, newTypeIdExpressions, newInitializerExpressions));
- }
- catch (ASTSemanticException e)
- {
- return null;
- } catch (Exception e)
- {
- throw backtrack;
- }
-
- }
- protected IASTExpression unaryOperatorCastExpression( IASTScope scope,
- IASTExpression.Kind kind)
- throws EndOfFileException, BacktrackException
- {
- IASTExpression castExpression = castExpression(scope);
- try
- {
- return astFactory.createExpression(
- scope,
- kind,
- castExpression,
- null,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression unaryExpression( IASTScope scope )
- throws EndOfFileException, BacktrackException
- {
- switch (LT(1))
- {
- case IToken.tSTAR :
- consume();
- return unaryOperatorCastExpression(scope,
- IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION);
- case IToken.tAMPER :
- consume();
- return unaryOperatorCastExpression(scope,
- IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION);
- case IToken.tPLUS :
- consume();
- return unaryOperatorCastExpression(scope,
- IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION);
- case IToken.tMINUS :
- consume();
- return unaryOperatorCastExpression(scope,
- IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION);
- case IToken.tNOT :
- consume();
- return unaryOperatorCastExpression(scope,
- IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION);
- case IToken.tCOMPL :
- consume();
- return unaryOperatorCastExpression(scope,
- IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION);
- case IToken.tINCR :
- consume();
- return unaryOperatorCastExpression(scope,
- IASTExpression.Kind.UNARY_INCREMENT);
- case IToken.tDECR :
- consume();
- return unaryOperatorCastExpression(scope,
- IASTExpression.Kind.UNARY_DECREMENT);
- case IToken.t_sizeof :
- consume(IToken.t_sizeof);
- IToken mark = LA(1);
- IASTTypeId d = null;
- IASTExpression unaryExpression = null;
- if (LT(1) == IToken.tLPAREN)
- {
- try
- {
- consume(IToken.tLPAREN);
- d = typeId(scope, false);
- consume(IToken.tRPAREN);
- }
- catch (BacktrackException bt)
- {
- backup(mark);
- unaryExpression = unaryExpression(scope);
- }
- }
- else
- {
- unaryExpression = unaryExpression(scope);
- }
- if (d != null & unaryExpression == null)
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.UNARY_SIZEOF_TYPEID,
- null,
- null,
- null,
- d,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- else if (unaryExpression != null && d == null)
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.UNARY_SIZEOF_UNARYEXPRESSION,
- unaryExpression,
- null,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e1)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- else
- throw backtrack;
- case IToken.t_new :
- return newExpression(scope);
- case IToken.t_delete :
- return deleteExpression(scope);
- case IToken.tCOLONCOLON :
- switch (LT(2))
- {
- case IToken.t_new :
- return newExpression(scope);
- case IToken.t_delete :
- return deleteExpression(scope);
- default :
- return postfixExpression(scope);
- }
- default :
- return postfixExpression(scope);
- }
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression postfixExpression( IASTScope scope )
- throws EndOfFileException, BacktrackException
- {
- IASTExpression firstExpression = null;
- boolean isTemplate = false;
- checkEndOfFile();
- switch (LT(1))
- {
- case IToken.t_typename :
- consume(IToken.t_typename);
- ITokenDuple nestedName = name(scope);
- boolean templateTokenConsumed = false;
- if( LT(1) == IToken.t_template )
- {
- consume( IToken.t_template );
- templateTokenConsumed = true;
- }
- IToken current = mark();
- ITokenDuple templateId = null;
- try
- {
- templateId = new TokenDuple( current, templateId(scope) );
- }
- catch( BacktrackException bt )
- {
- if( templateTokenConsumed )
- throw bt;
- backup( current );
- }
- consume( IToken.tLPAREN );
- IASTExpression expressionList = expression( scope );
- consume( IToken.tRPAREN );
- try {
- firstExpression =
- astFactory.createExpression( scope,
- (( templateId != null )? IASTExpression.Kind.POSTFIX_TYPENAME_TEMPLATEID : IASTExpression.Kind.POSTFIX_TYPENAME_IDENTIFIER ),
- expressionList,
- null,
- null,
- null,
- nestedName,
- "",
- null );
- } catch (ASTSemanticException ase ) {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- // simple-type-specifier ( assignment-expression , .. )
- case IToken.t_char :
- firstExpression =
- simpleTypeConstructorExpression(scope,
- IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR);
- break;
- case IToken.t_wchar_t :
- firstExpression =
- simpleTypeConstructorExpression(scope,
- IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART);
- break;
- case IToken.t_bool :
- firstExpression =
- simpleTypeConstructorExpression(scope,
- IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL);
- break;
- case IToken.t_short :
- firstExpression =
- simpleTypeConstructorExpression(scope,
- IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT);
- break;
- case IToken.t_int :
- firstExpression =
- simpleTypeConstructorExpression(scope,
- IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT);
- break;
- case IToken.t_long :
- firstExpression =
- simpleTypeConstructorExpression(scope,
- IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG);
- break;
- case IToken.t_signed :
- firstExpression =
- simpleTypeConstructorExpression(scope,
- IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED);
- break;
- case IToken.t_unsigned :
- firstExpression =
- simpleTypeConstructorExpression(scope,
- IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED);
- break;
- case IToken.t_float :
- firstExpression =
- simpleTypeConstructorExpression(scope,
- IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT);
- break;
- case IToken.t_double :
- firstExpression =
- simpleTypeConstructorExpression( scope,
- IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE);
- break;
- case IToken.t_dynamic_cast :
- firstExpression =
- specialCastExpression(scope,
- IASTExpression.Kind.POSTFIX_DYNAMIC_CAST);
- break;
- case IToken.t_static_cast :
- firstExpression =
- specialCastExpression(scope,
- IASTExpression.Kind.POSTFIX_STATIC_CAST);
- break;
- case IToken.t_reinterpret_cast :
- firstExpression =
- specialCastExpression(scope,
- IASTExpression.Kind.POSTFIX_REINTERPRET_CAST);
- break;
- case IToken.t_const_cast :
- firstExpression =
- specialCastExpression(scope,
- IASTExpression.Kind.POSTFIX_CONST_CAST);
- break;
- case IToken.t_typeid :
- consume();
- consume(IToken.tLPAREN);
- boolean isTypeId = true;
- IASTExpression lhs = null;
- IASTTypeId typeId = null;
- try
- {
- typeId = typeId(scope, false);
- }
- catch (BacktrackException b)
- {
- isTypeId = false;
- lhs = expression(scope);
- }
- consume(IToken.tRPAREN);
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- (isTypeId
- ? IASTExpression.Kind.POSTFIX_TYPEID_TYPEID
- : IASTExpression.Kind.POSTFIX_TYPEID_EXPRESSION),
- lhs,
- null,
- null,
- typeId,
- null, "", null);
- }
- catch (ASTSemanticException e6)
- {
- failParse();
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- default :
- firstExpression = primaryExpression(scope);
- }
- IASTExpression secondExpression = null;
- for (;;)
- {
- switch (LT(1))
- {
- case IToken.tLBRACKET :
- // array access
- consume();
- secondExpression = expression(scope);
- consume(IToken.tRBRACKET);
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- IASTExpression.Kind.POSTFIX_SUBSCRIPT,
- firstExpression,
- secondExpression,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e2)
- {
- failParse();
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- case IToken.tLPAREN :
- // function call
- consume(IToken.tLPAREN);
- secondExpression = expression(scope);
- consume(IToken.tRPAREN);
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- IASTExpression.Kind.POSTFIX_FUNCTIONCALL,
- firstExpression,
- secondExpression,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e3)
- {
- failParse();
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- case IToken.tINCR :
- consume();
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- IASTExpression.Kind.POSTFIX_INCREMENT,
- firstExpression,
- null,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e1)
- {
- failParse();
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- case IToken.tDECR :
- consume();
- try
- {
- firstExpression =
- astFactory.createExpression(
- scope,
- IASTExpression.Kind.POSTFIX_DECREMENT,
- firstExpression,
- null,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e4)
- {
- failParse();
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- case IToken.tDOT :
- // member access
- consume(IToken.tDOT);
-
- if( queryLookaheadCapability() )
- if (LT(1) == IToken.t_template)
- {
- consume(IToken.t_template);
- isTemplate = true;
- }
-
- setCompletionValues(scope, CompletionKind.MEMBER_REFERENCE, KeywordSets.Key.EMPTY, firstExpression, isTemplate );
-
- secondExpression = primaryExpression(scope);
- checkEndOfFile();
-
- setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, KeywordSets.Key.EMPTY );
-
- 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;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- case IToken.tARROW :
- // member access
- consume(IToken.tARROW);
-
- if( queryLookaheadCapability() )
- if (LT(1) == IToken.t_template)
- {
- consume(IToken.t_template);
- isTemplate = true;
- }
-
- setCompletionValues(scope, CompletionKind.MEMBER_REFERENCE, KeywordSets.Key.EMPTY, firstExpression, isTemplate );
-
- secondExpression = primaryExpression(scope);
- checkEndOfFile();
-
- setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, KeywordSets.Key.EMPTY );
- 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;
- } catch (Exception e)
- {
- throw backtrack;
- }
- break;
- default :
- return firstExpression;
- }
- }
- }
-
- /**
- * @param scope
- * @param kind
- * @param key
- * @param firstExpression
- * @param isTemplate
- */
- protected void setCompletionValues(IASTScope scope, CompletionKind kind, Key key, IASTExpression firstExpression, boolean isTemplate) throws EndOfFileException {
- }
-
- /**
- * @return
- * @throws EndOfFileException
- */
- protected boolean queryLookaheadCapability( int count ) throws EndOfFileException {
- //make sure we can look ahead one before doing this
- boolean result = true;
- try
- {
- LA(count);
- }
- catch( EndOfFileException olre )
- {
- result = false;
- }
- return result;
- }
-
- protected boolean queryLookaheadCapability() throws EndOfFileException {
- return queryLookaheadCapability(1);
- }
-
- protected void checkEndOfFile() throws EndOfFileException
- {
- LA(1);
- }
-
-
- protected IASTExpression specialCastExpression( IASTScope scope,
- IASTExpression.Kind kind)
- throws EndOfFileException, BacktrackException
- {
- consume();
- consume(IToken.tLT);
- IASTTypeId duple = typeId(scope, false);
- consume(IToken.tGT);
- consume(IToken.tLPAREN);
- IASTExpression lhs = expression(scope);
- consume(IToken.tRPAREN);
- try
- {
- return astFactory.createExpression(
- scope,
- kind,
- lhs,
- null,
- null,
- duple,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- protected IASTExpression simpleTypeConstructorExpression( IASTScope scope,
- Kind type)
- throws EndOfFileException, BacktrackException
- {
- consume();
- consume(IToken.tLPAREN);
- IASTExpression inside = expression(scope);
- consume(IToken.tRPAREN);
- try
- {
- return astFactory.createExpression(
- scope,
- type,
- inside,
- null,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e)
- {
- failParse();
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- }
- /**
- * @param expression
- * @throws BacktrackException
- */
- protected IASTExpression primaryExpression( IASTScope scope )
- throws EndOfFileException, BacktrackException
- {
- IToken t = null;
- switch (LT(1))
- {
- // TO DO: we need more literals...
- case IToken.tINTEGER :
- t = consume();
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.PRIMARY_INTEGER_LITERAL,
- null,
- null,
- null,
- null,
- null, t.getImage(), null);
- }
- catch (ASTSemanticException e1)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- case IToken.tFLOATINGPT :
- t = consume();
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.PRIMARY_FLOAT_LITERAL,
- null,
- null,
- null,
- null,
- null, t.getImage(), null);
- }
- catch (ASTSemanticException e2)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- case IToken.tSTRING :
- case IToken.tLSTRING :
- t = consume();
- try
- {
- return astFactory.createExpression( scope, IASTExpression.Kind.PRIMARY_STRING_LITERAL, null, null, null, null, null, t.getImage(), null );
- }
- catch (ASTSemanticException e5)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
-
- case IToken.t_false :
- case IToken.t_true :
- t = consume();
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL,
- null,
- null,
- null,
- null,
- null, t.getImage(), null);
- }
- catch (ASTSemanticException e3)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
-
- case IToken.tCHAR :
- case IToken.tLCHAR :
-
- t = consume();
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.PRIMARY_CHAR_LITERAL,
- null,
- null,
- null,
- null,
- null, t.getImage(), null);
- }
- catch (ASTSemanticException e4)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
-
- case IToken.t_this :
- consume(IToken.t_this);
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.PRIMARY_THIS,
- null,
- null,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e7)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- case IToken.tLPAREN :
- consume();
- IASTExpression lhs = expression(scope);
- consume(IToken.tRPAREN);
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION,
- lhs,
- null,
- null,
- null,
- null, "", null);
- }
- catch (ASTSemanticException e6)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- case IToken.tIDENTIFIER :
- case IToken.tCOLONCOLON :
- case IToken.t_operator :
- ITokenDuple duple = null;
-
- IToken mark = mark();
- try
- {
- duple = name(scope);
- }
- catch( BacktrackException bt )
- {
- Declarator d = new Declarator( new DeclarationWrapper(scope, mark.getOffset(), mark.getLineNumber(), null) );
-
- if (LT(1) == IToken.tCOLONCOLON || LT(1) == IToken.tIDENTIFIER)
- {
- IToken start = consume();
- IToken end = null;
- if (start.getType() == IToken.tIDENTIFIER)
- end = consumeTemplateParameters(end);
- while (LT(1) == IToken.tCOLONCOLON || LT(1) == IToken.tIDENTIFIER)
- {
- end = consume();
- if (end.getType() == IToken.tIDENTIFIER)
- end = consumeTemplateParameters(end);
- }
- if (LT(1) == IToken.t_operator)
- operatorId(d, start);
- else
- {
- backup(mark);
- throw backtrack;
- }
- }
- else if( LT(1) == IToken.t_operator )
- operatorId( d, null);
-
- duple = d.getNameDuple();
- }
- catch(OffsetLimitReachedException olre )
- {
- backup(mark);
- throw backtrack;
- }
-
- checkEndOfFile();
- try
- {
- return astFactory.createExpression(
- scope,
- IASTExpression.Kind.ID_EXPRESSION,
- null,
- null,
- null,
- null,
- duple, "", null);
- }
- catch (ASTSemanticException e8)
- {
- throw backtrack;
- } catch (Exception e)
- {
- throw backtrack;
- }
- default :
- IASTExpression empty = null;
- try {
- empty = astFactory.createExpression(
- scope,
- IASTExpression.Kind.PRIMARY_EMPTY,
- null,
- null,
- null,
- null,
- null, "", null);
- } catch (ASTSemanticException e9) {
- // TODO Auto-generated catch block
- e9.printStackTrace();
-
- }
- return empty;
- }
-
- }
/**
* @throws Exception
*/
@@ -5284,142 +2928,8 @@ public abstract class Parser implements IParser
}
}
- // the static instance we always use
- protected static BacktrackException backtrack = new BacktrackException();
-
- // Token management
- protected IScanner scanner;
- protected IToken currToken, // current token we plan to consume next
- lastToken; // last token we consumed
- private boolean limitReached = false;
- protected IASTCompilationUnit compilationUnit;
+ protected IASTCompilationUnit compilationUnit;
- /**
- * Fetches a token from the scanner.
- *
- * @return the next token from the scanner
- * @throws EndOfFileException thrown when the scanner.nextToken() yields no tokens
- */
- protected IToken fetchToken() throws EndOfFileException
- {
- if(limitReached) throw new EndOfFileException();
-
- try
- {
- IToken value = scanner.nextToken();
- handleNewToken( value );
- return value;
- }
- catch( OffsetLimitReachedException olre )
- {
- limitReached = true;
- handleOffsetLimitException(olre);
- return null;
- }
- catch (ScannerException e)
- {
- log.traceLog( "ScannerException thrown : " + e.getProblem().getMessage() );
- log.errorLog( "Scanner Exception: " + e.getProblem().getMessage()); //$NON-NLS-1$h
- failParse();
- return fetchToken();
- }
- }
-
- /**
- * @param value
- */
- protected void handleNewToken(IToken value) throws EndOfFileException {
- }
-
- protected void handleOffsetLimitException(OffsetLimitReachedException exception) throws EndOfFileException {
- // unexpected, throw EOF instead (equivalent)
- throw new EndOfFileException();
- }
- /**
- * Look Ahead in the token list to see what is coming.
- *
- * @param i How far ahead do you wish to peek?
- * @return the token you wish to observe
- * @throws EndOfFileException if looking ahead encounters EOF, throw EndOfFile
- */
- protected IToken LA(int i) throws EndOfFileException
- {
- if (i < 1) // can't go backwards
- return null;
- if (currToken == null)
- currToken = fetchToken();
- IToken retToken = currToken;
- for (; i > 1; --i)
- {
- retToken = retToken.getNext();
- if (retToken == null)
- retToken = fetchToken();
- }
- return retToken;
- }
- /**
- * Look ahead in the token list and return the token type.
- *
- * @param i How far ahead do you wish to peek?
- * @return The type of that token
- * @throws EndOfFileException if looking ahead encounters EOF, throw EndOfFile
- */
- protected int LT(int i) throws EndOfFileException
- {
- return LA(i).getType();
- }
- /**
- * Consume the next token available, regardless of the type.
- *
- * @return The token that was consumed and removed from our buffer.
- * @throws EndOfFileException If there is no token to consume.
- */
- protected IToken consume() throws EndOfFileException
- {
- if (currToken == null)
- currToken = fetchToken();
- if (currToken != null)
- lastToken = currToken;
- currToken = currToken.getNext();
- return lastToken;
- }
- /**
- * Consume the next token available only if the type is as specified.
- *
- * @param type The type of token that you are expecting.
- * @return the token that was consumed and removed from our buffer.
- * @throws BacktrackException If LT(1) != type
- */
- protected IToken consume(int type) throws EndOfFileException, BacktrackException
- {
- if (LT(1) == type)
- return consume();
- else
- throw backtrack;
- }
- /**
- * Mark our place in the buffer so that we could return to it should we have to.
- *
- * @return The current token.
- * @throws EndOfFileException If there are no more tokens.
- */
- protected IToken mark() throws EndOfFileException
- {
- if (currToken == null)
- currToken = fetchToken();
- return currToken;
- }
- /**
- * Rollback to a previous point, reseting the queue of tokens.
- *
- * @param mark The point that we wish to restore to.
- *
- */
- protected void backup(IToken mark)
- {
- currToken = (Token)mark;
- lastToken = null; // this is not entirely right ...
- }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParser#getLanguage()
*/
@@ -5442,14 +2952,6 @@ public abstract class Parser implements IParser
return firstErrorOffset;
}
- protected void setCompletionValues( IASTScope scope, IASTCompletionNode.CompletionKind kind, KeywordSets.Key key )throws EndOfFileException
- {
- }
-
- protected void setCompletionValues( IASTScope scope, IASTCompletionNode.CompletionKind kind, KeywordSets.Key key, IASTNode node, String prefix )throws EndOfFileException
- {
- }
-
protected void setCompletionToken( IToken token )
{
}
@@ -5458,4 +2960,28 @@ public abstract class Parser implements IParser
{
return null;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
+ */
+ public IASTNode parse(int startingOffset, int endingOffset)
+ throws ParseError {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.parser.IParser#parse(int)
+ */
+ public IASTCompletionNode parse(int offset) throws ParseError {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setupASTFactory(org.eclipse.cdt.core.parser.IScanner, org.eclipse.cdt.core.parser.ParserLanguage)
+ */
+ protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserExtensionFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserExtensionFactory.java
index 7c2ea9701ab..20e463fda30 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserExtensionFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserExtensionFactory.java
@@ -51,7 +51,7 @@ public class ParserExtensionFactory implements IParserExtensionFactory {
public IASTExtensionFactory createASTExtensionFactory(ParserMode mode) throws ParserFactoryError {
if( dialect == ExtensionDialect.GCC )
{
- if( mode == ParserMode.QUICK_PARSE )
+ if( mode == ParserMode.QUICK_PARSE || mode == ParserMode.EXPRESSION_PARSE )
return new QuickParseASTExtensionFactory();
return new CompleteParseASTExtensionFactory();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParser.java
index caa390aa8d7..d78269e1eca 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParser.java
@@ -38,8 +38,6 @@ public class QuickParser extends Parser {
*/
public QuickParser(IScanner scanner, ISourceElementRequestor callback, ParserLanguage language, IParserLogService log) {
super(scanner, callback, language, log);
- astFactory = ParserFactory.createASTFactory( ParserMode.QUICK_PARSE, language);
- scanner.setASTFactory(astFactory);
}
protected void handleFunctionBody(IASTScope scope) throws BacktrackException, EndOfFileException
@@ -65,5 +63,15 @@ public class QuickParser extends Parser {
public IASTNode parse(int startingOffset, int endingOffset) throws ParseError {
throw new ParseError( ParseErrorKind.METHOD_NOT_IMPLEMENTED );
}
-
+
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setupASTFactory(org.eclipse.cdt.core.parser.IScanner, org.eclipse.cdt.core.parser.ParserLanguage)
+ */
+ protected void setupASTFactory(IScanner scanner, ParserLanguage language) {
+ astFactory = ParserFactory.createASTFactory( ParserMode.QUICK_PARSE, language);
+ scanner.setASTFactory(astFactory);
+ }
+
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java
index 0d3427a8b9a..9fc6f809c67 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/SelectionParser.java
@@ -26,7 +26,7 @@ import org.eclipse.cdt.internal.core.parser.token.TokenDuple;
/**
* @author jcamelon
*/
-public class SelectionParser extends CompletionParser {
+public class SelectionParser extends ContextualParser {
private OffsetDuple offsetRange;
private IToken firstTokenOfDuple = null, lastTokenOfDuple = null;
@@ -34,16 +34,13 @@ public class SelectionParser extends CompletionParser {
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.Parser#handleNewToken(org.eclipse.cdt.core.parser.IToken)
*/
- protected void handleNewToken(IToken value) throws EndOfFileException {
+ protected void handleNewToken(IToken value) {
if( value != null )
{
if( value.getOffset() == offsetRange.getFloorOffset() )
firstTokenOfDuple = value;
if( value.getEndOffset() == offsetRange.getCeilingOffset() )
- {
lastTokenOfDuple = value;
- throw new EndOfFileException();
- }
}
}
@@ -63,7 +60,7 @@ public class SelectionParser extends CompletionParser {
* @see org.eclipse.cdt.core.parser.IParser#parse(int, int)
*/
public IASTNode parse(int startingOffset, int endingOffset) {
- scanner.setOffsetBoundary(endingOffset);
+// scanner.setOffsetBoundary(endingOffset);
offsetRange = new OffsetDuple( startingOffset, endingOffset );
translationUnit();
return reconcileTokenDuple();
@@ -88,5 +85,15 @@ public class SelectionParser extends CompletionParser {
*/
public IASTCompletionNode parse(int offset) {
throw new ParseError( ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED );
- }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.parser.Parser#checkEndOfFile()
+ */
+ protected void checkEndOfFile() throws EndOfFileException {
+ if( lastToken != null && lastToken.getEndOffset() >= offsetRange.getCeilingOffset() )
+ throw new EndOfFileException();
+ }
+
}
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/expression/ASTExpression.java
similarity index 99%
rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpression.java
rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ASTExpression.java
index f98072e15fa..e4b46b7b669 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/expression/ASTExpression.java
@@ -4,7 +4,7 @@
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
-package org.eclipse.cdt.internal.core.parser.ast.quick;
+package org.eclipse.cdt.internal.core.parser.ast.expression;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionParseASTFactory.java
new file mode 100644
index 00000000000..e822078aa3b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/expression/ExpressionParseASTFactory.java
@@ -0,0 +1,917 @@
+/*******************************************************************************
+ * Copyright (c) 2000 - 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser.ast.expression;
+
+import java.util.List;
+
+import org.eclipse.cdt.core.parser.IMacroDescriptor;
+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;
+import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException;
+import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
+import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
+import org.eclipse.cdt.core.parser.ast.ASTSemanticException;
+import org.eclipse.cdt.core.parser.ast.IASTASMDefinition;
+import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTCodeScope;
+import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
+import org.eclipse.cdt.core.parser.ast.IASTConstructorMemberInitializer;
+import org.eclipse.cdt.core.parser.ast.IASTDesignator;
+import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification;
+import org.eclipse.cdt.core.parser.ast.IASTExpression;
+import org.eclipse.cdt.core.parser.ast.IASTFactory;
+import org.eclipse.cdt.core.parser.ast.IASTField;
+import org.eclipse.cdt.core.parser.ast.IASTFunction;
+import org.eclipse.cdt.core.parser.ast.IASTInclusion;
+import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
+import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification;
+import org.eclipse.cdt.core.parser.ast.IASTMacro;
+import org.eclipse.cdt.core.parser.ast.IASTMethod;
+import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias;
+import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
+import org.eclipse.cdt.core.parser.ast.IASTNode;
+import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTScope;
+import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTTemplate;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
+import org.eclipse.cdt.core.parser.ast.IASTTypeId;
+import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
+import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration;
+import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
+import org.eclipse.cdt.core.parser.ast.IASTVariable;
+import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType;
+import org.eclipse.cdt.core.parser.ast.IASTDesignator.DesignatorKind;
+import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor;
+import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind;
+import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
+import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind;
+import org.eclipse.cdt.core.parser.ast.extension.IASTExpressionExtension;
+import org.eclipse.cdt.core.parser.ast.extension.IASTExtensionFactory;
+
+/**
+ * @author jcamelon
+ */
+public class ExpressionParseASTFactory implements IASTFactory {
+
+ private final IASTExtensionFactory extensionFactory;
+
+ /**
+ * @param factory
+ */
+ public ExpressionParseASTFactory(IASTExtensionFactory factory) {
+ this.extensionFactory = factory;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createMacro(java.lang.String,
+ * int, int, int, int, int, int, int,
+ * org.eclipse.cdt.core.parser.IMacroDescriptor)
+ */
+ public IASTMacro createMacro(
+ String name,
+ int startingOffset,
+ int startingLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine,
+ int endingOffset,
+ int endingLine,
+ IMacroDescriptor info) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createInclusion(java.lang.String,
+ * java.lang.String, boolean, int, int, int, int, int, int, int)
+ */
+ public IASTInclusion createInclusion(
+ String name,
+ String fileName,
+ boolean local,
+ int startingOffset,
+ int startingLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine,
+ int endingOffset,
+ int endingLine) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createUsingDirective(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ITokenDuple, int, int, int, int)
+ */
+ public IASTUsingDirective createUsingDirective(
+ IASTScope scope,
+ ITokenDuple duple,
+ int startingOffset,
+ int startingLine,
+ int endingOffset,
+ int endingLine)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * boolean, org.eclipse.cdt.core.parser.ITokenDuple, int, int, int,
+ * int)
+ */
+ public IASTUsingDeclaration createUsingDeclaration(
+ IASTScope scope,
+ boolean isTypeName,
+ ITokenDuple name,
+ int startingOffset,
+ int startingLine,
+ int endingOffset,
+ int endingLine)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createASMDefinition(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * java.lang.String, int, int, int, int)
+ */
+ public IASTASMDefinition createASMDefinition(
+ IASTScope scope,
+ String assembly,
+ int startingOffset,
+ int startingLine,
+ int endingOffset,
+ int endingLine) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * java.lang.String, int, int, int, int, int)
+ */
+ public IASTNamespaceDefinition createNamespaceDefinition(
+ IASTScope scope,
+ String identifier,
+ int startingOffset,
+ int startingLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLineNumber)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNamespaceAlias(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * java.lang.String, org.eclipse.cdt.core.parser.ITokenDuple, int,
+ * int, int, int, int, int, int)
+ */
+ public IASTNamespaceAlias createNamespaceAlias(
+ IASTScope scope,
+ String identifier,
+ ITokenDuple alias,
+ int startingOffset,
+ int startingLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine,
+ int endOffset,
+ int endingLine)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createCompilationUnit()
+ */
+ public IASTCompilationUnit createCompilationUnit() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * java.lang.String, int, int)
+ */
+ public IASTLinkageSpecification createLinkageSpecification(
+ IASTScope scope,
+ String spec,
+ int startingOffset,
+ int startingLine) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ITokenDuple,
+ * org.eclipse.cdt.core.parser.ast.ASTClassKind,
+ * org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType,
+ * org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, int, int, int,
+ * int, int)
+ */
+ public IASTClassSpecifier createClassSpecifier(
+ IASTScope scope,
+ ITokenDuple name,
+ ASTClassKind kind,
+ ClassNameType type,
+ ASTAccessVisibility access,
+ int startingOffset,
+ int startingLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#addBaseSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier,
+ * boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility,
+ * org.eclipse.cdt.core.parser.ITokenDuple)
+ */
+ public void addBaseSpecifier(
+ IASTClassSpecifier astClassSpec,
+ boolean isVirtual,
+ ASTAccessVisibility visibility,
+ ITokenDuple parentClassName)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createElaboratedTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ast.ASTClassKind,
+ * org.eclipse.cdt.core.parser.ITokenDuple, int, int, int, int,
+ * boolean, boolean)
+ */
+ public IASTElaboratedTypeSpecifier createElaboratedTypeSpecifier(
+ IASTScope scope,
+ ASTClassKind elaboratedClassKind,
+ ITokenDuple typeName,
+ int startingOffset,
+ int startingLine,
+ int endOffset,
+ int endingLine,
+ boolean isForewardDecl,
+ boolean isFriend)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * java.lang.String, int, int, int, int, int)
+ */
+ public IASTEnumerationSpecifier createEnumerationSpecifier(
+ IASTScope scope,
+ String name,
+ int startingOffset,
+ int startingLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#addEnumerator(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier,
+ * java.lang.String, int, int, int, int, int, int, int,
+ * org.eclipse.cdt.core.parser.ast.IASTExpression)
+ */
+ public void addEnumerator(
+ IASTEnumerationSpecifier enumeration,
+ String string,
+ int startingOffset,
+ int startingLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine,
+ int endingOffset,
+ int endLine,
+ IASTExpression initialValue)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * 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,
+ * org.eclipse.cdt.core.parser.ast.IASTTypeId,
+ * org.eclipse.cdt.core.parser.ITokenDuple, java.lang.String,
+ * org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor)
+ */
+ public IASTExpression createExpression(
+ IASTScope scope,
+ Kind kind,
+ IASTExpression lhs,
+ IASTExpression rhs,
+ IASTExpression thirdExpression,
+ IASTTypeId typeId,
+ ITokenDuple idExpression,
+ String literal,
+ IASTNewExpressionDescriptor newDescriptor)
+ throws ASTSemanticException {
+ try {
+ return new ASTExpression(
+ kind,
+ lhs,
+ rhs,
+ thirdExpression,
+ typeId,
+ idExpression == null ? "" : idExpression.toString(),
+ literal,
+ newDescriptor,
+ extensionFactory.createExpressionExtension());
+ } catch (ASTNotImplementedException e) {
+ return new ASTExpression(
+ kind,
+ lhs,
+ rhs,
+ thirdExpression,
+ typeId,
+ idExpression == null ? "" : idExpression.toString(),
+ literal,
+ newDescriptor,
+ new IASTExpressionExtension() {
+
+ public void setExpression(IASTExpression expression) {
+ }
+
+ public int evaluateExpression()
+ throws ASTExpressionEvaluationException {
+ throw new ASTExpressionEvaluationException();
+ }
+ });
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor(java.util.List,
+ * java.util.List, java.util.List)
+ */
+ public IASTNewExpressionDescriptor createNewDescriptor(
+ List newPlacementExpressions,
+ List newTypeIdExpressions,
+ List newInitializerExpressions) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createInitializerClause(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ast.IASTInitializerClause.Kind,
+ * org.eclipse.cdt.core.parser.ast.IASTExpression, java.util.List,
+ * java.util.List)
+ */
+ public IASTInitializerClause createInitializerClause(
+ IASTScope scope,
+ org.eclipse.cdt.core.parser.ast.IASTInitializerClause.Kind kind,
+ IASTExpression assignmentExpression,
+ List initializerClauses,
+ List designators) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExceptionSpecification(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * java.util.List)
+ */
+ public IASTExceptionSpecification createExceptionSpecification(
+ IASTScope scope,
+ List typeIds)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createArrayModifier(org.eclipse.cdt.core.parser.ast.IASTExpression)
+ */
+ public IASTArrayModifier createArrayModifier(IASTExpression exp) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createConstructorMemberInitializer(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ITokenDuple,
+ * org.eclipse.cdt.core.parser.ast.IASTExpression)
+ */
+ public IASTConstructorMemberInitializer createConstructorMemberInitializer(
+ IASTScope scope,
+ ITokenDuple duple,
+ IASTExpression expressionList)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type,
+ * org.eclipse.cdt.core.parser.ITokenDuple, boolean, boolean, boolean,
+ * boolean, boolean, boolean, boolean)
+ */
+ public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(
+ IASTScope scope,
+ Type kind,
+ ITokenDuple typeName,
+ boolean isShort,
+ boolean isLong,
+ boolean isSigned,
+ boolean isUnsigned,
+ boolean isTypename,
+ boolean isComplex,
+ boolean isImaginary)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createFunction(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ITokenDuple, java.util.List,
+ * org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration,
+ * org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification,
+ * boolean, boolean, boolean, int, int, int, int, int,
+ * org.eclipse.cdt.core.parser.ast.IASTTemplate, boolean, boolean,
+ * boolean, boolean, boolean, java.util.List, boolean, boolean,
+ * boolean)
+ */
+ public IASTFunction createFunction(
+ IASTScope scope,
+ ITokenDuple name,
+ List parameters,
+ IASTAbstractDeclaration returnType,
+ IASTExceptionSpecification exception,
+ boolean isInline,
+ boolean isFriend,
+ boolean isStatic,
+ int startOffset,
+ int startLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine,
+ IASTTemplate ownerTemplate,
+ boolean isConst,
+ boolean isVolatile,
+ boolean isVirtual,
+ boolean isExplicit,
+ boolean isPureVirtual,
+ List constructorChain,
+ boolean isDefinition,
+ boolean hasFunctionTryBlock,
+ boolean hasVariableArguments)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createAbstractDeclaration(boolean,
+ * boolean, org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier,
+ * java.util.List, java.util.List, java.util.List,
+ * org.eclipse.cdt.core.parser.ast.ASTPointerOperator)
+ */
+ public IASTAbstractDeclaration createAbstractDeclaration(
+ boolean isConst,
+ boolean isVolatile,
+ IASTTypeSpecifier typeSpecifier,
+ List pointerOperators,
+ List arrayModifiers,
+ List parameters,
+ ASTPointerOperator pointerOperator) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createMethod(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ITokenDuple, java.util.List,
+ * org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration,
+ * org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification,
+ * boolean, boolean, boolean, int, int, int, int, int,
+ * org.eclipse.cdt.core.parser.ast.IASTTemplate, boolean, boolean,
+ * boolean, boolean, boolean,
+ * org.eclipse.cdt.core.parser.ast.ASTAccessVisibility,
+ * java.util.List, boolean, boolean, boolean)
+ */
+ public IASTMethod createMethod(
+ IASTScope scope,
+ ITokenDuple name,
+ List parameters,
+ IASTAbstractDeclaration returnType,
+ IASTExceptionSpecification exception,
+ boolean isInline,
+ boolean isFriend,
+ boolean isStatic,
+ int startOffset,
+ int startLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine,
+ IASTTemplate ownerTemplate,
+ boolean isConst,
+ boolean isVolatile,
+ boolean isVirtual,
+ boolean isExplicit,
+ boolean isPureVirtual,
+ ASTAccessVisibility visibility,
+ List constructorChain,
+ boolean isDefinition,
+ boolean hasFunctionTryBlock,
+ boolean hasVariableArguments)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createVariable(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * java.lang.String, boolean,
+ * org.eclipse.cdt.core.parser.ast.IASTInitializerClause,
+ * org.eclipse.cdt.core.parser.ast.IASTExpression,
+ * org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, boolean,
+ * boolean, boolean, boolean, int, int, int, int, int,
+ * org.eclipse.cdt.core.parser.ast.IASTExpression)
+ */
+ public IASTVariable createVariable(
+ IASTScope scope,
+ String name,
+ boolean isAuto,
+ IASTInitializerClause initializerClause,
+ IASTExpression bitfieldExpression,
+ IASTAbstractDeclaration abstractDeclaration,
+ boolean isMutable,
+ boolean isExtern,
+ boolean isRegister,
+ boolean isStatic,
+ int startingOffset,
+ int startingLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine,
+ IASTExpression constructorExpression)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createField(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * java.lang.String, boolean,
+ * org.eclipse.cdt.core.parser.ast.IASTInitializerClause,
+ * org.eclipse.cdt.core.parser.ast.IASTExpression,
+ * org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, boolean,
+ * boolean, boolean, boolean, int, int, int, int, int,
+ * org.eclipse.cdt.core.parser.ast.IASTExpression,
+ * org.eclipse.cdt.core.parser.ast.ASTAccessVisibility)
+ */
+ public IASTField createField(
+ IASTScope scope,
+ String name,
+ boolean isAuto,
+ IASTInitializerClause initializerClause,
+ IASTExpression bitfieldExpression,
+ IASTAbstractDeclaration abstractDeclaration,
+ boolean isMutable,
+ boolean isExtern,
+ boolean isRegister,
+ boolean isStatic,
+ int startingOffset,
+ int startingLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine,
+ IASTExpression constructorExpression,
+ ASTAccessVisibility visibility)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createDesignator(org.eclipse.cdt.core.parser.ast.IASTDesignator.DesignatorKind,
+ * org.eclipse.cdt.core.parser.ast.IASTExpression,
+ * org.eclipse.cdt.core.parser.IToken)
+ */
+ public IASTDesignator createDesignator(
+ DesignatorKind kind,
+ IASTExpression constantExpression,
+ IToken fieldIdentifier) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createParameterDeclaration(boolean,
+ * boolean, org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier,
+ * java.util.List, java.util.List, java.util.List,
+ * org.eclipse.cdt.core.parser.ast.ASTPointerOperator,
+ * java.lang.String,
+ * org.eclipse.cdt.core.parser.ast.IASTInitializerClause, int, int,
+ * int, int, int, int, int)
+ */
+ public IASTParameterDeclaration createParameterDeclaration(
+ boolean isConst,
+ boolean isVolatile,
+ IASTTypeSpecifier getTypeSpecifier,
+ List pointerOperators,
+ List arrayModifiers,
+ List parameters,
+ ASTPointerOperator pointerOp,
+ String parameterName,
+ IASTInitializerClause initializerClause,
+ int startingOffset,
+ int startingLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine,
+ int endingOffset,
+ int endingLine) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * java.util.List, boolean, int, int)
+ */
+ public IASTTemplateDeclaration createTemplateDeclaration(
+ IASTScope scope,
+ List templateParameters,
+ boolean exported,
+ int startingOffset,
+ int startingLine) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateParameter(org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind,
+ * java.lang.String, java.lang.String,
+ * org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration,
+ * java.util.List)
+ */
+ public IASTTemplateParameter createTemplateParameter(
+ ParamKind kind,
+ String identifier,
+ String defaultValue,
+ IASTParameterDeclaration parameter,
+ List parms) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateInstantiation(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * int, int)
+ */
+ public IASTTemplateInstantiation createTemplateInstantiation(
+ IASTScope scope,
+ int startingOffset,
+ int startingLine) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * int, int)
+ */
+ public IASTTemplateSpecialization createTemplateSpecialization(
+ IASTScope scope,
+ int startingOffset,
+ int startingLine) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypedef(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * java.lang.String,
+ * org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, int, int,
+ * int, int, int)
+ */
+ public IASTTypedefDeclaration createTypedef(
+ IASTScope scope,
+ String name,
+ IASTAbstractDeclaration mapping,
+ int startingOffset,
+ int startingLine,
+ int nameOffset,
+ int nameEndOffset,
+ int nameLine)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier,
+ * org.eclipse.cdt.core.parser.ast.IASTTemplate, int, int, int, int)
+ */
+ public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration(
+ IASTScope scope,
+ IASTTypeSpecifier typeSpecifier,
+ IASTTemplate template,
+ int startingOffset,
+ int startingLine,
+ int endingOffset,
+ int endingLine) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#queryIsTypeName(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ITokenDuple)
+ */
+ public boolean queryIsTypeName(
+ IASTScope scope,
+ ITokenDuple nameInQuestion) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewCodeBlock(org.eclipse.cdt.core.parser.ast.IASTScope)
+ */
+ public IASTCodeScope createNewCodeBlock(IASTScope scope) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypeId(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type,
+ * boolean, boolean, boolean, boolean, boolean, boolean, boolean,
+ * org.eclipse.cdt.core.parser.ITokenDuple, java.util.List,
+ * java.util.List)
+ */
+ public IASTTypeId createTypeId(
+ IASTScope scope,
+ Type kind,
+ boolean isConst,
+ boolean isVolatile,
+ boolean isShort,
+ boolean isLong,
+ boolean isSigned,
+ boolean isUnsigned,
+ boolean isTypename,
+ ITokenDuple name,
+ List pointerOps,
+ List arrayMods)
+ throws ASTSemanticException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#signalEndOfClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier)
+ */
+ public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#getCompletionContext(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind,
+ * org.eclipse.cdt.core.parser.ast.IASTExpression)
+ */
+ public IASTNode getCompletionContext(
+ Kind kind,
+ IASTExpression expression) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.core.parser.ast.IASTFactory#lookupSymbolInContext(org.eclipse.cdt.core.parser.ast.IASTScope,
+ * org.eclipse.cdt.core.parser.ITokenDuple)
+ */
+ public IASTNode lookupSymbolInContext(IASTScope scope, ITokenDuple duple)
+ throws ASTNotImplementedException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
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 6ad4e77f11c..fd3ab9af9c0 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
@@ -61,6 +61,7 @@ import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type;
import org.eclipse.cdt.core.parser.ast.extension.IASTExpressionExtension;
import org.eclipse.cdt.core.parser.ast.extension.IASTExtensionFactory;
import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
+import org.eclipse.cdt.internal.core.parser.ast.expression.ASTExpression;
/**
@@ -69,6 +70,7 @@ import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory;
*/
public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory {
+ private static final boolean CREATE_EXCESS_CONSTRUCTS = true;
private final IASTExtensionFactory extensionFactory;
public QuickParseASTFactory( IASTExtensionFactory extensionFactory )
@@ -159,25 +161,31 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.ExpressionKind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, java.lang.String, java.lang.String)
*/
public IASTExpression createExpression(IASTScope scope, Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, String literal, IASTNewExpressionDescriptor newDescriptor) {
- try {
- return new ASTExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor, extensionFactory.createExpressionExtension() );
- } catch (ASTNotImplementedException e) {
- return new ASTExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor, new IASTExpressionExtension() {
-
- public void setExpression(IASTExpression expression) {
- }
-
- public int evaluateExpression() throws ASTExpressionEvaluationException {
- throw new ASTExpressionEvaluationException();
- } } );
+ if( CREATE_EXCESS_CONSTRUCTS )
+ {
+ try {
+ return new ASTExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor, extensionFactory.createExpressionExtension() );
+ } catch (ASTNotImplementedException e) {
+ return new ASTExpression( kind, lhs, rhs, thirdExpression, typeId, idExpression == null ? "" : idExpression.toString(), literal, newDescriptor, new IASTExpressionExtension() {
+
+ public void setExpression(IASTExpression expression) {
+ }
+
+ public int evaluateExpression() throws ASTExpressionEvaluationException {
+ throw new ASTExpressionEvaluationException();
+ } } );
+ }
}
+ return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor()
*/
public IASTNewExpressionDescriptor createNewDescriptor(List newPlacementEpressions, List newTypeIdExpressions, List newInitializerExpressions) {
- return new ASTNewDescriptor();
+ if( CREATE_EXCESS_CONSTRUCTS )
+ return new ASTNewDescriptor();
+ return null;
}
/* (non-Javadoc)
@@ -193,7 +201,8 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
*/
public IASTConstructorMemberInitializer createConstructorMemberInitializer(IASTScope scope, ITokenDuple duple, IASTExpression expressionList )
{
- return new ASTConstructorMemberInitializer( duple.toString(), expressionList );
+// return new ASTConstructorMemberInitializer( duple.toString(), expressionList );
+ return null;
}
/* (non-Javadoc)
@@ -233,8 +242,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
*/
public IASTField createField(IASTScope scope, String name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression, ASTAccessVisibility visibility)
{
- final ASTField field = new ASTField(scope, name, isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern, isRegister, isStatic, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, constructorExpression, visibility);
- return field;
+ return new ASTField(scope, name, isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern, isRegister, isStatic, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, constructorExpression, visibility);
}
/* (non-Javadoc)
@@ -336,7 +344,9 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
public IASTInitializerClause createInitializerClause(IASTScope scope, IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, List initializerClauses, List designators)
{
- return new ASTInitializerClause( kind, assignmentExpression, initializerClauses, designators );
+ if( CREATE_EXCESS_CONSTRUCTS )
+ return new ASTInitializerClause( kind, assignmentExpression, initializerClauses, designators );
+ return null;
}
/* (non-Javadoc)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java
index baac4349837..04a50f86e72 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java
@@ -498,7 +498,7 @@ public final class TemplateEngine {
List pPtrs = p.getPtrOperators();
if( pPtrs.size() != 0 ){
- PtrOp op = (PtrOp) pPtrs.iterator().next();;
+ PtrOp op = (PtrOp) pPtrs.iterator().next();
if( op.getType() == PtrOp.t_memberPointer ){
TypeInfo info = new TypeInfo( TypeInfo.t_type, 0, aFunction.getContainingSymbol() );
if( !deduceTemplateArgument( map, op.getMemberOf(), info ) ){
@@ -657,7 +657,6 @@ public final class TemplateEngine {
Iterator pIter = pList.iterator();
Iterator aIter = arguments.iterator();
- ISymbol aSymbol = null;
while( pIter.hasNext() ){
if( !deduceTemplateArgument( map, (ISymbol) pIter.next(), (TypeInfo) aIter.next() ) ){
return null;
@@ -887,7 +886,7 @@ public final class TemplateEngine {
* @throws ParserSymbolTableException
*/
static protected ITemplateSymbol selectTemplateOrSpecialization( ITemplateSymbol template, List parameters, List arguments ) throws ParserSymbolTableException {
- if( template != null && template instanceof ITemplateSymbol ){
+ if( template != null ){
//primary definition or specialization?
boolean forPrimary = true;
@@ -908,7 +907,7 @@ public final class TemplateEngine {
}
}
- ITemplateSymbol primary = (ITemplateSymbol) template;
+ ITemplateSymbol primary = template;
if( forPrimary ){
//make sure parameters match up with found template
@@ -1085,7 +1084,7 @@ public final class TemplateEngine {
ISpecializedSymbol spec = (ISpecializedSymbol) symbol;
instance = spec.deferredInstance( spec.getArgumentList() );
} else {
- ITemplateSymbol template = (ITemplateSymbol) symbol;
+ ITemplateSymbol template = symbol;
Iterator iter = template.getParameterList().iterator();
List args = new LinkedList();
while( iter.hasNext() ){
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateFactory.java
index 50b33f8510d..e1ab2ae1d74 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateFactory.java
@@ -97,7 +97,7 @@ public class TemplateFactory implements ITemplateFactory {
}
ITemplateSymbol template = (ITemplateSymbol) getTemplatesList().get( getTemplatesList().size() - 1 );
- IContainerSymbol container = (IContainerSymbol) template.getTemplatedSymbol();
+ IContainerSymbol container = template.getTemplatedSymbol();
if( container.isForwardDeclaration() && container.getTypeSymbol() == symbol ){
template.addSymbol( symbol );
@@ -113,7 +113,7 @@ public class TemplateFactory implements ITemplateFactory {
Set keys = getPrimaryTemplate().getContainedSymbols().keySet();
IContainerSymbol symbol = (IContainerSymbol) getPrimaryTemplate().getContainedSymbols().get( keys.iterator().next() );
- return (ISymbol) symbol.lookupMemberForDefinition( name );
+ return symbol.lookupMemberForDefinition( name );
}
/* (non-Javadoc)
@@ -123,7 +123,7 @@ public class TemplateFactory implements ITemplateFactory {
Set keys = getPrimaryTemplate().getContainedSymbols().keySet();
IContainerSymbol symbol = (IContainerSymbol) getPrimaryTemplate().getContainedSymbols().get( keys.iterator().next() );
- return (IParameterizedSymbol) symbol.lookupMethodForDefinition( name, params );
+ return symbol.lookupMethodForDefinition( name, params );
}
/* (non-Javadoc)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java
index a5a02a27d2b..e1cbfe4ecf6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Scanner.java
@@ -31,7 +31,6 @@ import org.eclipse.cdt.core.parser.BacktrackException;
import org.eclipse.cdt.core.parser.Directives;
import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IMacroDescriptor;
-import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.core.parser.IScanner;
@@ -55,6 +54,8 @@ import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTFactory;
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
+import org.eclipse.cdt.internal.core.parser.*;
+import org.eclipse.cdt.internal.core.parser.InternalParserFactory;
import org.eclipse.cdt.internal.core.parser.ast.ASTCompletionNode;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.parser.token.Token;
@@ -2255,12 +2256,12 @@ public class Scanner implements IScanner {
{
if( expression.trim().equals( "0" ) )
return false;
+
return true;
}
else
{
- final NullSourceElementRequestor nullCallback = new NullSourceElementRequestor();
- IParser parser = null;
+ IExpressionParser parser = null;
StringBuffer expressionBuffer = new StringBuffer( expression );
expressionBuffer.append( ';');
try
@@ -2270,8 +2271,8 @@ public class Scanner implements IScanner {
new StringReader(expressionBuffer.toString()),
EXPRESSION,
new ScannerInfo( scannerData.getDefinitions(), scannerData.getOriginalConfig().getIncludePaths()),
- ParserMode.QUICK_PARSE, scannerData.getLanguage(), nullCallback, nullLogService );
- parser = ParserFactory.createParser(trial, nullCallback, ParserMode.QUICK_PARSE, scannerData.getLanguage(), nullLogService);
+ ParserMode.QUICK_PARSE, scannerData.getLanguage(), new NullSourceElementRequestor(), nullLogService );
+ parser = InternalParserFactory.createExpressionParser(trial, scannerData.getLanguage(), nullLogService);
} catch( ParserFactoryError pfe )
{
handleInternalError();