diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java
index f9071bfa96d..3fea21ef45e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java
@@ -30,7 +30,8 @@ public abstract class CPPASTAmbiguity extends CPPASTNode {
protected static class CPPASTNameCollector extends CPPASTVisitor {
private IASTName[] names = new IASTName[2];
private int namesPos=-1;
- {
+
+ public CPPASTNameCollector() {
shouldVisitNames = true;
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml b/lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml
index 96f11442b79..6801241a2d6 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml
@@ -79,6 +79,15 @@
+
+
+
+
+
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPGrammar.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPGrammar.g
index ee7622c560e..fc704e74057 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPGrammar.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPGrammar.g
@@ -233,7 +233,7 @@ $Headers
int kind = super.getKind(i);
// There used to be a special token kind for zero used to parser pure virtual function declarations.
- // But it turned out to be easier to just parse them as an init_declarator and programaticaly check
+ // But it turned out to be easier to just parse them as an init_ declarator and programaticaly check
// for pure virtual, see consumeMemberDeclaratorWithInitializer().
//if(kind == CPPParsersym.TK_integer && "0".equals(getTokenText(i))) { //$NON-NLS-1$
@@ -435,8 +435,9 @@ template_opt
/. $Build consumeEmpty(); $EndBuild ./
+-- the ::=? is necessary for example 8.2.1 in the C++ spec to parse correctly
dcolon_opt
- ::= '::'
+ ::=? '::'
/. $Build consumePlaceHolder(); $EndBuild ./
| $empty
/. $Build consumeEmpty(); $EndBuild ./
@@ -942,12 +943,12 @@ declaration_seq_opt
simple_declaration
::= declaration_specifiers_opt init_declarator_list_opt ';'
- /. $Build consumeDeclarationSimple(true); $EndBuild ./
+ /. $Build consumeDeclarationSimple(true, true); $EndBuild ./
simple_declaration_with_declspec
::= declaration_specifiers init_declarator_list_opt ';'
- /. $Build consumeDeclarationSimple(true); $EndBuild ./
+ /. $Build consumeDeclarationSimple(true, false); $EndBuild ./
-- declaration specifier nodes not created here, they are created by sub-rules
@@ -1238,8 +1239,8 @@ linkage_specification
init_declarator_list
- ::= init_declarator
- | init_declarator_list ',' init_declarator
+ ::= init_declarator_complete
+ | init_declarator_list ',' init_declarator_complete
init_declarator_list_opt
@@ -1247,6 +1248,11 @@ init_declarator_list_opt
| $empty
+init_declarator_complete
+ ::= init_declarator
+ /. $Build consumeInitDeclaratorComplete(); $EndBuild ./
+
+
init_declarator
::= declarator
| declarator initializer
@@ -1332,9 +1338,10 @@ cv_qualifier
declarator_id_name
- ::= qualified_or_unqualified_name
- | dcolon_opt nested_name_specifier_opt type_name
+ ::= qualified_or_unqualified_name
+ | dcolon_opt nested_name_specifier_opt type_name
/. $Build consumeQualifiedId(false); $EndBuild ./
+
type_id
@@ -1520,9 +1527,9 @@ visibility_label
member_declaration
::= declaration_specifiers_opt member_declarator_list ';'
- /. $Build consumeDeclarationSimple(true); $EndBuild ./
+ /. $Build consumeDeclarationSimple(true, true); $EndBuild ./
| declaration_specifiers_opt ';'
- /. $Build consumeDeclarationSimple(false); $EndBuild ./
+ /. $Build consumeDeclarationSimple(false, false); $EndBuild ./
| function_definition ';'
| function_definition
| dcolon_opt nested_name_specifier template_opt unqualified_id_name ';'
@@ -1785,11 +1792,11 @@ handler
-- open a scope just so that we can reuse consumeDeclarationSimple()
exception_declaration
::= type_specifier_seq declarator
- /. $Build consumeDeclarationSimple(true); $EndBuild ./
+ /. $Build consumeDeclarationSimple(true, false); $EndBuild ./
| type_specifier_seq abstract_declarator -- TODO might need to be abstract_declarator_without_function, might be too lenient, what exactly can you catch?
- /. $Build consumeDeclarationSimple(true); $EndBuild ./
+ /. $Build consumeDeclarationSimple(true, false); $EndBuild ./
| type_specifier_seq
- /. $Build consumeDeclarationSimple(false); $EndBuild ./
+ /. $Build consumeDeclarationSimple(false, false); $EndBuild ./
-- puts type ids on the stack
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoFunctionDeclaratorParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoFunctionDeclaratorParser.g
new file mode 100644
index 00000000000..5ca750de1fe
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoFunctionDeclaratorParser.g
@@ -0,0 +1,43 @@
+-----------------------------------------------------------------------------------
+-- Copyright (c) 2006, 2008 IBM Corporation and others.
+-- All rights reserved. This program and the accompanying materials
+-- are made available under the terms of the Eclipse Public License v1.0
+-- which accompanies this distribution, and is available at
+-- http://www.eclipse.org/legal/epl-v10.html
+--
+-- Contributors:
+-- IBM Corporation - initial API and implementation
+-----------------------------------------------------------------------------------
+
+%options la=2
+%options package=org.eclipse.cdt.internal.core.dom.lrparser.cpp
+%options template=btParserTemplateD.g
+
+$Import
+ CPPGrammar.g
+$DropRules
+
+ direct_declarator
+ ::= function_direct_declarator
+
+ init_declarator_complete
+ ::= init_declarator
+
+$End
+
+$Start
+ no_function_declarator_start
+$End
+
+$Rules
+
+ no_function_declarator_start
+ ::= init_declarator_complete
+ | ERROR_TOKEN
+ /. $Build consumeDeclarationProblem(); $EndBuild ./
+
+ -- redeclare this rule with no semantic action, prevents recursion
+ init_declarator_complete
+ ::= init_declarator
+
+$End
\ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/BuildASTParserAction.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/BuildASTParserAction.java
index 3bb5cfbf7d4..63f31fd21a1 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/BuildASTParserAction.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/BuildASTParserAction.java
@@ -70,6 +70,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
import org.eclipse.cdt.core.dom.lrparser.IParser;
import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
import org.eclipse.cdt.core.parser.util.DebugUtil;
+import org.eclipse.cdt.internal.core.dom.lrparser.c99.C99Parsersym;
import org.eclipse.cdt.internal.core.dom.lrparser.cpp.CPPParsersym;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@@ -92,7 +93,7 @@ public abstract class BuildASTParserAction {
* @see BuildASTParserAction#consumePlaceHolder()
* @see BuildASTParserAction#consumeEmpty()
*/
- protected static final Object PLACE_HOLDER = Boolean.TRUE;
+ protected static final Object PLACE_HOLDER = Boolean.TRUE; // any object will do
// turn debug tracing on and off
@@ -311,6 +312,9 @@ public abstract class BuildASTParserAction {
return true;
}
+
+
+
/*************************************************************************************************************
* Start of actions.
************************************************************************************************************/
@@ -403,6 +407,7 @@ public abstract class BuildASTParserAction {
tu.accept(EMPTY_VISITOR);
}
+
/**
* When applied to the AST causes ambiguity nodes to be resolved.
*/
@@ -453,8 +458,10 @@ public abstract class BuildASTParserAction {
result = declarationStatement;
else if(isImplicitInt(decl))
result = expressionStatement;
- else
+ else {
result = nodeFactory.newAmbiguousStatement(declarationStatement, expressionStatement);
+ setOffsetAndLength(result);
+ }
astStack.push(result);
@@ -532,7 +539,11 @@ public abstract class BuildASTParserAction {
public void consumeExpressionID() {
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
- IASTName name = createName(parser.getRightIToken());
+ System.out.println("Right Token: " + parser.getRightIToken());
+ System.out.println("Left Token: " + parser.getLeftIToken());
+ System.out.println("All Tokens: " + parser.getRuleTokens());
+ //IASTName name = createName(parser.getRightIToken());
+ IASTName name = createName(parser.getLeftIToken());
IASTIdExpression expr = nodeFactory.newIdExpression(name);
setOffsetAndLength(expr);
astStack.push(expr);
@@ -628,8 +639,11 @@ public abstract class BuildASTParserAction {
if(alternateExpr == null || alternateExpr instanceof IASTProblemExpression)
astStack.push(expr);
- else
- astStack.push(nodeFactory.newAmbiguousExpression(expr, (IASTExpression)alternateExpr));
+ else {
+ IASTNode ambiguityNode = nodeFactory.newAmbiguousExpression(expr, (IASTExpression)alternateExpr);
+ setOffsetAndLength(ambiguityNode);
+ astStack.push(ambiguityNode);
+ }
if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -669,19 +683,13 @@ public abstract class BuildASTParserAction {
if(alternateExpr == null || alternateExpr instanceof IASTProblemExpression)
astStack.push(expr);
- else
- astStack.push(nodeFactory.newAmbiguousExpression(expr, (IASTExpression)alternateExpr));
+ else {
+ IASTNode ambiguityNode = nodeFactory.newAmbiguousExpression(expr, (IASTExpression)alternateExpr);
+ setOffsetAndLength(ambiguityNode);
+ astStack.push(ambiguityNode);
+ }
if(TRACE_AST_STACK) System.out.println(astStack);
-
-// if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-//
-// IASTTypeId typeId = (IASTTypeId) astStack.pop();
-// IASTTypeIdExpression expr = nodeFactory.newTypeIdExpression(operator, typeId);
-// setOffsetAndLength(expr);
-// astStack.push(expr);
-//
-// if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -1035,15 +1043,14 @@ public abstract class BuildASTParserAction {
/**
* parameter_declaration ::= declaration_specifiers
*/
- public void consumeParameterDeclarationWithoutDeclarator(/*IBinding binding*/) {
+ public void consumeParameterDeclarationWithoutDeclarator() {
if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
// offsets need to be calculated differently in this case
- final int endOffset = parser.getRightIToken().getEndOffset() + 1;
+ final int endOffset = parser.getRightIToken().getEndOffset();
IASTName name = nodeFactory.newName();
setOffsetAndLength(name, endOffset, 0);
- //name.setBinding(binding);
// it appears that a declarator is always required in the AST here
IASTDeclarator declarator = nodeFactory.newDeclarator(name);
@@ -1078,31 +1085,31 @@ public abstract class BuildASTParserAction {
*
* TODO Make both grammars the same here.
*/
- public void consumeDeclarationSimple(boolean hasDeclaratorList) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- List