Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Kucera2008-03-24 16:16:14 +0000
committerMike Kucera2008-03-24 16:16:14 +0000
commit8d37ffe0608d00f84191d229b9d4030e641f347f (patch)
tree3abe2d43963dde54205ec94a9d07b7b6211f11d3 /lrparser/org.eclipse.cdt.core.lrparser/grammar
parente1bf40252e94c577e8bcea1c650130567de17bf6 (diff)
downloadorg.eclipse.cdt-8d37ffe0608d00f84191d229b9d4030e641f347f.tar.gz
org.eclipse.cdt-8d37ffe0608d00f84191d229b9d4030e641f347f.tar.xz
org.eclipse.cdt-8d37ffe0608d00f84191d229b9d4030e641f347f.zip
attempt at fixing function declarator/constructor initializer ambiguity, needs more testing
Diffstat (limited to 'lrparser/org.eclipse.cdt.core.lrparser/grammar')
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml9
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPGrammar.g33
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoFunctionDeclaratorParser.g43
3 files changed, 72 insertions, 13 deletions
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 @@
<antcall target="generate_cpp">
<param name="grammar_name" value="CPPSizeofExpressionParser"/>
</antcall>
+ <!-- Generate parser for disambiguating declarators
+ <antcall target="generate_cpp">
+ <param name="grammar_name" value="CPPNoConstructorInitializerParser"/>
+ </antcall>
+ -->
+ <!-- Generate parser for disambiguating declarators -->
+ <antcall target="generate_cpp">
+ <param name="grammar_name" value="CPPNoFunctionDeclaratorParser"/>
+ </antcall>
</target>
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 <openscope-ast> init_declarator_list_opt ';'
- /. $Build consumeDeclarationSimple(true); $EndBuild ./
+ /. $Build consumeDeclarationSimple(true, true); $EndBuild ./
simple_declaration_with_declspec
::= declaration_specifiers <openscope-ast> 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 <openscope-ast> 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 <openscope-ast> declarator
- /. $Build consumeDeclarationSimple(true); $EndBuild ./
+ /. $Build consumeDeclarationSimple(true, false); $EndBuild ./
| type_specifier_seq <openscope-ast> 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

Back to the top