From 646f923f972a3038055034cdc43deeaaa5deac66 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Wed, 23 Feb 2005 19:49:24 +0000 Subject: [PATCH] Fixed Bug 86323 [Lengths] IASTSimpleDeclaration for the for-init-statement includes ';' in length --- .../core/parser/tests/ast2/DOMLocationTests.java | 15 +++++++++++++-- .../core/dom/parser/c/GNUCSourceParser.java | 4 +++- .../core/dom/parser/cpp/GNUCPPSourceParser.java | 11 +++++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java index 3cd7f8ee44a..821c09e1446 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; +import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter; @@ -219,9 +220,9 @@ public class DOMLocationTests extends AST2BaseTest { String code = "enum hue { red, blue, green };"; //$NON-NLS-1$ IASTTranslationUnit tu = parse(code, ParserLanguage.CPP); IASTSimpleDeclaration d = (IASTSimpleDeclaration) tu.getDeclarations()[0]; - IASTEnumerationSpecifier enum = (IASTEnumerationSpecifier) d + IASTEnumerationSpecifier enumeration = (IASTEnumerationSpecifier) d .getDeclSpecifier(); - IASTEnumerationSpecifier.IASTEnumerator enumerator = enum + IASTEnumerationSpecifier.IASTEnumerator enumerator = enumeration .getEnumerators()[0]; assertSoleLocation(enumerator, code.indexOf("red"), "red".length()); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -448,4 +449,14 @@ public class DOMLocationTests extends AST2BaseTest { IASTDeclarator d = sd.getDeclarators()[0]; assertSoleLocation( d, code.indexOf("*p = (int []){2, 4}"), "*p = (int []){2, 4}".length() ); //$NON-NLS-1$//$NON-NLS-2$ } + + public void testBug86323() throws Exception { + String code = "void f() { int i=0; for (; i<10; i++) { } }"; + for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP + : null) { + IASTTranslationUnit tu = parse(code, p); + IASTForStatement for_stmt = (IASTForStatement) ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody()).getStatements()[1]; + assertNull( for_stmt.getInitDeclaration() ); + } + } } \ No newline at end of file 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 078ea78729d..6e9f671dda1 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 @@ -2180,7 +2180,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { EndOfFileException { IToken mark = mark(); try { - IASTExpression e = expression(); + IASTExpression e = null; + if( LT(1) != IToken.tSEMI ) + e = expression(); consume(IToken.tSEMI); // TODO is this a problem? Should we wrap this in an expression // statement? 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 7af64d65215..1a65a99717f 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 @@ -4305,10 +4305,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { EndOfFileException { IToken mark = mark(); try { - IASTExpression e = expression(); - consume(IToken.tSEMI); - return e; - + IASTExpression e = null; + if( LT(1) != IToken.tSEMI ) + e = expression(); + consume(IToken.tSEMI); + // TODO is this a problem? Should we wrap this in an expression + // statement? + return e; } catch (BacktrackException bt) { backup(mark); try {