Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2005-04-17 21:53:39 -0400
committerDoug Schaefer2005-04-17 21:53:39 -0400
commit9d949fe555cff8da4344ef7f23ed8a49e824fa34 (patch)
tree0c694bfc57261721ee641b03211138815960a3a2
parent80830d7267980cb9bb84d665bf6f91e344ef1a57 (diff)
downloadorg.eclipse.cdt-9d949fe555cff8da4344ef7f23ed8a49e824fa34.tar.gz
org.eclipse.cdt-9d949fe555cff8da4344ef7f23ed8a49e824fa34.tar.xz
org.eclipse.cdt-9d949fe555cff8da4344ef7f23ed8a49e824fa34.zip
Content assist support in for statement.
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java51
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java10
3 files changed, 58 insertions, 13 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
index ccd2835e1c..df35ee099f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
@@ -1703,19 +1703,46 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
consume(IToken.tLPAREN);
IASTNode init = forInitStatement();
IASTExpression for_condition = null;
- if (LT(1) != IToken.tSEMI)
+ switch (LT(1)) {
+ case IToken.tSEMI:
+ case IToken.tEOC:
+ break;
+ default:
for_condition = condition();
- consume(IToken.tSEMI);
+ }
+ switch (LT(1)) {
+ case IToken.tSEMI:
+ consume(IToken.tSEMI);
+ break;
+ case IToken.tEOC:
+ break;
+ default:
+ throw backtrack;
+ }
IASTExpression iterationExpression = null;
- if (LT(1) != IToken.tRPAREN) {
+ switch (LT(1)) {
+ case IToken.tRPAREN:
+ case IToken.tEOC:
+ break;
+ default:
iterationExpression = expression();
-
- }
- consume(IToken.tRPAREN);
- IASTStatement for_body = statement();
+ }
+ switch (LT(1)) {
+ case IToken.tRPAREN:
+ consume(IToken.tRPAREN);
+ break;
+ case IToken.tEOC:
+ break;
+ default:
+ throw backtrack;
+ }
IASTForStatement for_statement = createForStatement();
- ((ASTNode) for_statement).setOffsetAndLength(startOffset,
+ IASTStatement for_body = null;
+ if (LT(1) != IToken.tEOC) {
+ for_body = statement();
+ ((ASTNode) for_statement).setOffsetAndLength(startOffset,
calculateEndOffset(for_body) - startOffset);
+ }
if (init instanceof IASTDeclaration) {
for_statement.setInit((IASTDeclaration) init);
@@ -1738,9 +1765,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
iterationExpression.setParent(for_statement);
iterationExpression.setPropertyInParent(IASTForStatement.ITERATION);
}
- for_statement.setBody(for_body);
- for_body.setParent(for_statement);
- for_body.setPropertyInParent(IASTForStatement.BODY);
+ if (for_body != null) {
+ for_statement.setBody(for_body);
+ for_body.setParent(for_statement);
+ for_body.setPropertyInParent(IASTForStatement.BODY);
+ }
return for_statement;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
index 121b2762d7..ac5048e09b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
@@ -2215,7 +2215,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
IASTExpression e = null;
if( LT(1) != IToken.tSEMI )
e = expression();
- consume(IToken.tSEMI);
+ switch (LT(1)) {
+ case IToken.tSEMI:
+ consume(IToken.tSEMI);
+ break;
+ case IToken.tEOC:
+ break;
+ default:
+ throw backtrack;
+ }
// TODO is this a problem? Should we wrap this in an expression
// statement?
return e;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index 56b414cabd..c812b344b2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -4420,7 +4420,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IASTExpression e = null;
if (LT(1) != IToken.tSEMI)
e = expression();
- consume(IToken.tSEMI);
+ switch (LT(1)) {
+ case IToken.tSEMI:
+ consume(IToken.tSEMI);
+ break;
+ case IToken.tEOC:
+ break;
+ default:
+ throw backtrack;
+ }
return e;
} catch (BacktrackException bt) {
backup(mark);

Back to the top