mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 03:53:21 +02:00
Fixed Bug 86323 [Lengths] IASTSimpleDeclaration for the for-init-statement includes ';' in length
This commit is contained in:
parent
a0f0ff7593
commit
646f923f97
3 changed files with 23 additions and 7 deletions
|
@ -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.IASTEnumerationSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
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.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
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$
|
String code = "enum hue { red, blue, green };"; //$NON-NLS-1$
|
||||||
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
|
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
|
||||||
IASTSimpleDeclaration d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
IASTSimpleDeclaration d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||||
IASTEnumerationSpecifier enum = (IASTEnumerationSpecifier) d
|
IASTEnumerationSpecifier enumeration = (IASTEnumerationSpecifier) d
|
||||||
.getDeclSpecifier();
|
.getDeclSpecifier();
|
||||||
IASTEnumerationSpecifier.IASTEnumerator enumerator = enum
|
IASTEnumerationSpecifier.IASTEnumerator enumerator = enumeration
|
||||||
.getEnumerators()[0];
|
.getEnumerators()[0];
|
||||||
assertSoleLocation(enumerator, code.indexOf("red"), "red".length()); //$NON-NLS-1$ //$NON-NLS-2$
|
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];
|
IASTDeclarator d = sd.getDeclarators()[0];
|
||||||
assertSoleLocation( d, code.indexOf("*p = (int []){2, 4}"), "*p = (int []){2, 4}".length() ); //$NON-NLS-1$//$NON-NLS-2$
|
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() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -2180,7 +2180,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
EndOfFileException {
|
EndOfFileException {
|
||||||
IToken mark = mark();
|
IToken mark = mark();
|
||||||
try {
|
try {
|
||||||
IASTExpression e = expression();
|
IASTExpression e = null;
|
||||||
|
if( LT(1) != IToken.tSEMI )
|
||||||
|
e = expression();
|
||||||
consume(IToken.tSEMI);
|
consume(IToken.tSEMI);
|
||||||
// TODO is this a problem? Should we wrap this in an expression
|
// TODO is this a problem? Should we wrap this in an expression
|
||||||
// statement?
|
// statement?
|
||||||
|
|
|
@ -4305,10 +4305,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
EndOfFileException {
|
EndOfFileException {
|
||||||
IToken mark = mark();
|
IToken mark = mark();
|
||||||
try {
|
try {
|
||||||
IASTExpression e = expression();
|
IASTExpression e = null;
|
||||||
consume(IToken.tSEMI);
|
if( LT(1) != IToken.tSEMI )
|
||||||
return e;
|
e = expression();
|
||||||
|
consume(IToken.tSEMI);
|
||||||
|
// TODO is this a problem? Should we wrap this in an expression
|
||||||
|
// statement?
|
||||||
|
return e;
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
backup(mark);
|
backup(mark);
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Reference in a new issue