From b74edd50a199190d44897d46ccaf21eca6a1920d Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 10 Apr 2008 16:14:43 +0000 Subject: [PATCH] Correct parsing of typeof-expressions, bug 226492. --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 9 +++++++++ .../dom/parser/AbstractGNUSourceCodeParser.java | 14 +++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 2cbcdb50f4f..ed4dc63f18a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -4478,6 +4478,15 @@ public class AST2Tests extends AST2BaseTest { // void test(int count) { // __typeof__(count) a= 1; // int ret0 = ((__typeof__(count)) 1); + // } + public void testTypeofUnaryExpression_Bug226492() throws Exception { + final String code = getAboveComment(); + parseAndCheckBindings(code, ParserLanguage.C, true); + parseAndCheckBindings(code, ParserLanguage.CPP, true); + } + + // void test(int count) { + // typeof(count==1) a= 1; // } public void testTypeofExpression_Bug226492() throws Exception { final String code = getAboveComment(); 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 3b6669f02ac..84e7aca8f76 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 @@ -850,15 +850,15 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { BacktrackException { int offset = consume().getOffset(); // t_typeof IASTTypeId d = null; - IASTExpression unaryExpression = null; + IASTExpression expression = null; int lastOffset = 0; - // prefer unary expressions over type-expressions + // prefer expressions over type-ids if (LT(1) == IToken.tLPAREN && LT(2) != IToken.tLBRACE) { consume(); final IToken m = mark(); try { - unaryExpression= unaryExpression(); + expression= expression(); } catch (BacktrackException e) { backup(m); @@ -868,14 +868,14 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { } lastOffset = consume(IToken.tRPAREN).getEndOffset(); } else { - unaryExpression = unaryExpression(); - lastOffset = calculateEndOffset(unaryExpression); + expression = unaryExpression(); + lastOffset = calculateEndOffset(expression); } if (d != null) return buildTypeIdExpression(IGNUASTTypeIdExpression.op_typeof, d, offset, lastOffset); - if (unaryExpression != null) - return buildUnaryExpression(IGNUASTUnaryExpression.op_typeof, unaryExpression, offset, lastOffset); + if (expression != null) + return buildUnaryExpression(IGNUASTUnaryExpression.op_typeof, expression, offset, lastOffset); return null; }