From b65a7925063149e53018b01929cd2d01841ff891 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 27 Apr 2009 08:32:31 +0000 Subject: [PATCH] Fixes a loop in the c-parser, bug 273759. --- .../parser/tests/ast2/FaultToleranceTests.java | 18 ++++++++++++++++++ .../parser/AbstractGNUSourceCodeParser.java | 7 +++++-- .../core/dom/parser/c/GNUCSourceParser.java | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java index 2359ec1742e..ae064f03212 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/FaultToleranceTests.java @@ -242,4 +242,22 @@ public class FaultToleranceTests extends AST2BaseTest { IASTSimpleDeclaration s= getDeclaration(ct, 2); assertEquals("int i;", s.getRawSignature()); } + + + // #define XX() . + // int c; + // XX( + // ); + // int d; + public void testErrorRecovery_273759() throws Exception { + IASTTranslationUnit tu= parse(getAboveComment(), ParserLanguage.C, false, false); + IASTSimpleDeclaration s= getDeclaration(tu, 0); + IASTProblemDeclaration p= getDeclaration(tu, 1); + s= getDeclaration(tu, 2); + + tu= parse(getAboveComment(), ParserLanguage.CPP, false, false); + s= getDeclaration(tu, 0); + p= getDeclaration(tu, 1); + s= getDeclaration(tu, 2); + } } 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 e71d02e799e..236462c657a 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 @@ -1539,8 +1539,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { // a node was detected by assuming additional tokens (e.g. missing semicolon) IASTNode n= bt.getNodeBeforeProblem(); if (n instanceof IASTDeclaration) { - declarationMark= null; - return new IASTDeclaration[] {(IASTDeclaration) n, buildProblemDeclaration(origProblem)}; + IToken la1= LAcatchEOF(1); + if (la1 == null || la1.getOffset() > offset) { + declarationMark= null; + return new IASTDeclaration[] {(IASTDeclaration) n, buildProblemDeclaration(origProblem)}; + } } if (declarationMark != null && isActiveCode()) { 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 06d2bc7927a..d1e38fe719c 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 @@ -389,7 +389,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { endOffset= figureEndOffset(declSpec, declarators); break; default: - if (declOption != DeclarationOptions.LOCAL) { + if (declOption != DeclarationOptions.LOCAL && endOffset != firstOffset) { insertSemi= true; if (markBeforDtor != null && !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) { backup(markBeforDtor);