Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Kucera2009-10-21 13:18:01 -0400
committerMike Kucera2009-10-21 13:18:01 -0400
commit7b97f230cca8963374abaeae61dcf9a8cb85747f (patch)
tree43dffb9fe977aa85dfb4df793e04915f3b945ae1
parentd204001ae3aa40d38defe0a4d9c26c500348cc30 (diff)
downloadorg.eclipse.cdt-7b97f230cca8963374abaeae61dcf9a8cb85747f.tar.gz
org.eclipse.cdt-7b97f230cca8963374abaeae61dcf9a8cb85747f.tar.xz
org.eclipse.cdt-7b97f230cca8963374abaeae61dcf9a8cb85747f.zip
Bug 292782 - backport enhancements to LR parser into 5.0 branch
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/.classpath7
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/.project28
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/.settings/org.eclipse.jdt.core.prefs65
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/.settings/org.eclipse.jdt.ui.prefs3
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/META-INF/MANIFEST.MF15
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/about.html24
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/build.properties17
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/plugin.properties15
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecTest.java88
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPTests.java137
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecTests.java102
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCommentTests.java78
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompleteParser2Tests.java151
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionBasicTest.java102
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionParseTest.java415
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationInclusionTests.java72
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationMacroTests.java65
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationTests.java91
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMPreprocessorInformationTest.java47
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDigraphTrigraphTests.java186
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCCompleteParseExtensionsTest.java51
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCTests.java51
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRImageLocationTests.java54
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRKnRTests.java84
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRNodeSelectorTest.java62
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRParserTestSuite.java55
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRQuickParser2Tests.java181
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSelectionParseTest.java96
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSemanticsTests.java53
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTaskParserTest.java52
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTemplateTests.java51
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTests.java168
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRUtilOldTests.java56
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRUtilTests.java55
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java215
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/.classpath1
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF8
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/build.properties15
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml104
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99ExpressionParser.g8
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Grammar.g214
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99NoCastExpressionParser.g12
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Parser.g4
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99SizeofExpressionParser.g16
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/common.g147
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPExpressionParser.g8
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPGrammar.g378
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoCastExpressionParser.g8
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoFunctionDeclaratorParser.g8
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPParser.g2
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPSizeofExpressionParser.g14
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPTemplateTypeParameterParser.g14
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCGrammar.g112
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCParser.g26
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCSizeofExpressionParser.g43
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/generate.xml64
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/gnu/GNUExtensions.g205
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPGrammar.g130
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPParser.g26
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPSizeofExpressionParser.g46
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/template/LRParserTemplate.g (renamed from lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/lpgextensions/FixedBtParserTemplateD.g)152
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/grammar/template/LRSecondaryParserTemplate.g66
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/C99ResolveParserAction.java1558
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/C99TypedefTrackerParserAction.java355
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/DeclSpec.java168
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/DeclaratorFrame.java142
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ArrayType.java124
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99BasicType.java133
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99CompositeTypeScope.java38
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumeration.java107
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java67
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Field.java48
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java153
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionScope.java41
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionType.java61
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Label.java62
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Parameter.java34
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99PointerType.java100
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ProblemBinding.java32
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99QualifierType.java104
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Scope.java118
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Structure.java147
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Typedef.java101
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java112
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/IC99Binding.java19
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/IC99Scope.java31
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/ITypeable.java17
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/C99SymbolTable.java110
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/CImperativeSymbolTable.java157
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/CNamespace.java29
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/FunctionalMap.java295
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/SymbolTableTests.java219
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/TypedefSymbolTable.java72
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/plugin.properties16
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/plugin.xml25
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java164
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CLanguageKeywords.java2
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CPreprocessorAdapter.java24
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParser.java23
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ISecondaryParser.java37
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ITokenCollector.java33
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserPlugin.java93
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserProperties.java43
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ScannerExtensionConfiguration.java43
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ASTCompletionNode.java32
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/AbstractParserAction.java229
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/BuildASTParserAction.java729
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/INodeFactory.java (renamed from lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/IASTNodeFactory.java)83
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ISecondaryParserFactory.java48
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenStream.java (renamed from lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParserActionTokenProvider.java)6
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ParserUtil.java112
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99BuildASTParserAction.java251
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99SecondaryParserFactory.java43
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/CNodeFactory.java (renamed from lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99ASTNodeFactory.java)145
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/IC99ASTNodeFactory.java61
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/ICNodeFactory.java73
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java804
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPNodeFactory.java (renamed from lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPASTNodeFactory.java)277
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPSecondaryParserFactory.java56
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/ICPPASTNodeFactory.java147
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/ICPPNodeFactory.java225
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/ICPPSecondaryParserFactory.java33
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/gnu/GCCBuildASTParserAction.java88
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/gnu/GCCSecondaryParserFactory.java43
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/gnu/GNUBuildASTParserAction.java98
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/gnu/GPPBuildASTParserAction.java197
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/gnu/GPPSecondaryParserFactory.java57
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/c99/C99Language.java62
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/c99/DOMToC99TokenMap.java18
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/cpp/DOMToISOCPPTokenMap.java18
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/cpp/ISOCPPLanguage.java65
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/DOMToGCCTokenMap.java161
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/DOMToGPPTokenMap.java194
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GCCLanguage.java70
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GPPLanguage.java70
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99ExpressionParser.java757
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99ExpressionParserprs.java1375
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99ExpressionParsersym.java110
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99NoCastExpressionParser.java753
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99NoCastExpressionParserprs.java1354
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99NoCastExpressionParsersym.java104
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parser.java768
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parserprs.java1920
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parsersym.java154
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99SizeofExpressionParser.java753
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99SizeofExpressionParserprs.java1361
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99SizeofExpressionParsersym.java112
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPExpressionParser.java2111
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPExpressionParserprs.java4001
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPExpressionParsersym.java286
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoCastExpressionParser.java2104
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoCastExpressionParserprs.java4046
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoCastExpressionParsersym.java286
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoFunctionDeclaratorParser.java2104
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoFunctionDeclaratorParserprs.java3957
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoFunctionDeclaratorParsersym.java288
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParser.java2117
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParserprs.java4046
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParsersym.java282
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPRules.java10
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPSizeofExpressionParser.java2097
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPSizeofExpressionParserprs.java3971
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPSizeofExpressionParsersym.java286
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPTemplateTypeParameterParser.java2113
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPTemplateTypeParameterParserprs.java3964
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPTemplateTypeParameterParsersym.java294
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCParser.java1381
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCParserprs.java1916
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCParsersym.java224
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCSizeofExpressionParser.java1392
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCSizeofExpressionParserprs.java1805
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCSizeofExpressionParsersym.java224
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPParser.java2043
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPParserprs.java3430
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPParsersym.java286
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPSizeofExpressionParser.java2048
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPSizeofExpressionParserprs.java3366
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPSizeofExpressionParsersym.java286
178 files changed, 49103 insertions, 31757 deletions
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/.classpath b/lrparser/org.eclipse.cdt.core.lrparser.tests/.classpath
new file mode 100644
index 0000000000..64c5e31b7a
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/.project b/lrparser/org.eclipse.cdt.core.lrparser.tests/.project
new file mode 100644
index 0000000000..2a6eb655e2
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>~org.eclipse.cdt.core.lrparser.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/.settings/org.eclipse.jdt.core.prefs b/lrparser/org.eclipse.cdt.core.lrparser.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..2a8aa999e3
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,65 @@
+#Fri Apr 25 15:22:29 EDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=error
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/.settings/org.eclipse.jdt.ui.prefs b/lrparser/org.eclipse.cdt.core.lrparser.tests/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000000..95087c66c9
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,3 @@
+#Fri Oct 05 11:17:36 EDT 2007
+eclipse.preferences.version=1
+internal.default.compliance=default
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/META-INF/MANIFEST.MF b/lrparser/org.eclipse.cdt.core.lrparser.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..afe29df131
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name.0
+Bundle-SymbolicName: org.eclipse.cdt.core.lrparser.tests
+Bundle-Version: 5.1.0.qualifier
+Require-Bundle: org.eclipse.core.runtime,
+ org.junit,
+ org.eclipse.cdt.core.tests,
+ org.eclipse.cdt.core,
+ org.eclipse.core.resources,
+ org.eclipse.cdt.core.lrparser;bundle-version="4.0.1"
+Export-Package: org.eclipse.cdt.core.lrparser.tests
+Bundle-Vendor: %Bundle-Vendor.0
+Bundle-Localization: plugin
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/about.html b/lrparser/org.eclipse.cdt.core.lrparser.tests/about.html
new file mode 100644
index 0000000000..9b669c2fd0
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/about.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
+
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>February 8, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body></html> \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/build.properties b/lrparser/org.eclipse.cdt.core.lrparser.tests/build.properties
new file mode 100644
index 0000000000..417826ea2a
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/build.properties
@@ -0,0 +1,17 @@
+###############################################################################
+# Copyright (c) 2007, 2009 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
+###############################################################################
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ plugin.properties
+src.includes = about.html
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/plugin.properties b/lrparser/org.eclipse.cdt.core.lrparser.tests/plugin.properties
new file mode 100644
index 0000000000..3d52fe6fe9
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/plugin.properties
@@ -0,0 +1,15 @@
+###############################################################################
+# Copyright (c) 2007, 2009 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
+###############################################################################
+# properties file for org.eclipse.cdt.core.parser.c99.tests
+Bundle-Vendor.0 = Eclipse CDT
+Bundle-Name.0 = C99 Parser Tests Plug-in
+
+upcSourceName=UPC Source File \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecTest.java
new file mode 100644
index 0000000000..cf63addaa6
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecTest.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPSpecTest;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRCPPSpecTest extends AST2CPPSpecTest {
+
+ public static TestSuite suite() {
+ return suite(LRCPPSpecTest.class);
+ }
+
+ public LRCPPSpecTest() { }
+ public LRCPPSpecTest(String name) { super(name); }
+
+
+ @Override
+ protected void parseCandCPP( String code, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
+ parse(code, ParserLanguage.C, checkBindings, expectedProblemBindings);
+ parse(code, ParserLanguage.CPP, checkBindings, expectedProblemBindings);
+ }
+
+ @Override
+ protected IASTTranslationUnit parseWithErrors(String code, ParserLanguage lang) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckBindings(false);
+ options.setCheckPreprocessorProblems(false);
+ options.setCheckSyntaxProblems(false);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckBindings(checkBindings);
+ options.setExpectedProblemBindings(expectedProblemBindings);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setSkipTrivialInitializers(skipTrivialInitializers);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang, String[] problems) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setProblems(problems);
+ return ParseHelper.parse(code, language, options);
+ }
+
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPTests.java
new file mode 100644
index 0000000000..e5bec7fb1a
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPTests.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRCPPTests extends AST2CPPTests {
+
+
+ public static TestSuite suite() {
+ return suite(LRCPPTests.class);
+ }
+
+ public LRCPPTests() {
+
+ }
+
+ public LRCPPTests(String name) {
+ super(name);
+ }
+
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setSkipTrivialInitializers(skipTrivialInitializers);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+ @Override
+ public void testBug98704() throws Exception {
+ // this one gets stuck in infinite loop
+
+ }
+
+// @Override
+// public void testBug87424() throws Exception { // gcc extension
+// try {
+// super.testBug87424();
+// fail();
+// } catch(AssertionFailedError _) {
+// }
+// }
+//
+//
+// @Override
+// public void testBug95757() throws Exception { // gcc extension
+// try {
+// super.testBug95757();
+// fail();
+// } catch(AssertionFailedError _) {
+// }
+// }
+//
+// @Override
+// public void testBug108202() throws Exception { // gcc attributes not supported
+// try {
+// super.testBug108202();
+// fail();
+// } catch(AssertionFailedError _) {
+// }
+// }
+//
+//
+// @Override
+// public void testBug195701() throws Exception { // gcc attributes not supported
+// try {
+// super.testBug195701();
+// fail();
+// } catch(AssertionFailedError _) {
+// }
+// }
+//
+// @Override
+// public void testBug179712() throws Exception { // gcc attributes not supported
+// try {
+// super.testBug179712();
+// fail();
+// } catch(AssertionFailedError _) {
+// }
+// }
+//
+// @Override
+// public void testBug240567() throws Exception { // gcc
+// try {
+// super.testBug240567();
+// fail();
+// } catch(AssertionFailedError _) {
+// }
+// }
+//
+// @Override
+// public void testLiteralsViaOverloads_225534() throws Exception { // gcc, I think
+// try {
+// super.testLiteralsViaOverloads_225534();
+// fail();
+// } catch(AssertionFailedError _) {
+// }
+// }
+
+
+ @Override
+ public void testNestedTemplateIDAmbiguity_259501() throws Exception {
+ // this test hangs, not sure I'll ever fix it
+ }
+
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecTests.java
new file mode 100644
index 0000000000..5cb7b86b62
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecTests.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2CSpecTest;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings({"restriction", "nls"})
+public class LRCSpecTests extends AST2CSpecTest {
+
+ public static TestSuite suite() {
+ return suite(LRCSpecTests.class);
+ }
+
+ public LRCSpecTests() { }
+ public LRCSpecTests(String name) { super(name); }
+
+
+ @Override
+ protected void parseCandCPP( String code, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
+ parse(code, ParserLanguage.C, checkBindings, expectedProblemBindings);
+ parse(code, ParserLanguage.CPP, checkBindings, expectedProblemBindings);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(true);
+ options.setCheckPreprocessorProblems(true);
+ options.setCheckBindings(checkBindings);
+ options.setExpectedProblemBindings(expectedProblemBindings);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang, String[] problems) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setProblems(problems);
+ options.setCheckSyntaxProblems(true);
+ options.setCheckPreprocessorProblems(true);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+ @Override // example code needs to be nested in a function body
+ public void test5_1_2_3s15() throws Exception {
+ String code =
+ "//#include <stdio.h>\n" +
+ "int foo() { \n" +
+ "int sum;\n" +
+ "char *p;\n" +
+ "sum = sum * 10 - '0' + (*p++ = getchar());\n" +
+ "sum = (((sum * 10) - '0') + ((*(p++)) = (getchar())));\n" +
+ "} \n";
+
+ parseCandCPP(code, false, 0);
+ }
+
+
+
+// @Override
+// public void test6_7_2_1s17() throws Exception { // what the heck is offsetof
+// try {
+// super.test6_7_2_1s17();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+
+
+ public void testBug276360() throws Exception {
+ String code =
+ "int foo(int*[]) {} ";
+
+ parseCandCPP(code, false, 0);
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCommentTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCommentTests.java
new file mode 100644
index 0000000000..b9566ea3e8
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCommentTests.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.CommentTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRCommentTests extends CommentTests {
+
+ public static TestSuite suite() {
+ return suite(LRCommentTests.class);
+ }
+
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ return ParseHelper.parse(code, language, expectNoProblems);
+ }
+
+
+ @Override
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang,
+ boolean useGNUExtensions, boolean expectNoProblems,
+ boolean skipTrivialInitializers) throws ParserException {
+
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setSkipTrivialInitializers(skipTrivialInitializers);
+ return ParseHelper.commentParse(code, language);
+ }
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+ @SuppressWarnings("nls")
+ public void testBug191266() throws Exception {
+ String code =
+ "#define MACRO 1000000000000 \n" +
+ "int x = MACRO; \n" +
+ "//comment\n";
+
+ IASTTranslationUnit tu = parse(code, ParserLanguage.C, false, false, true);
+
+ IASTComment[] comments = tu.getComments();
+ assertEquals(1, comments.length);
+
+ IASTFileLocation location = comments[0].getFileLocation();
+ assertEquals(code.indexOf("//"), location.getNodeOffset());
+ assertEquals("//comment".length(), location.getNodeLength());
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompleteParser2Tests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompleteParser2Tests.java
new file mode 100644
index 0000000000..e7059e9f85
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompleteParser2Tests.java
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.CompleteParser2Tests;
+
+public class LRCompleteParser2Tests extends CompleteParser2Tests {
+
+ public static TestSuite suite() {
+ return suite(LRCompleteParser2Tests.class);
+ }
+
+ public LRCompleteParser2Tests() {
+ }
+
+ public LRCompleteParser2Tests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse(String code, boolean expectedToPass,
+ ParserLanguage lang, boolean gcc) throws Exception {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ return ParseHelper.parse(code, language, expectedToPass);
+ }
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+ // Tests that are failing at this point
+
+// @Override
+// public void testBug39676_tough() { // is this C99?
+// try {
+// super.testBug39676_tough();
+// } catch(AssertionFailedError _) {
+// return;
+// } catch(Exception _) {
+// return;
+// }
+// fail();
+// }
+
+// public void testPredefinedSymbol_bug70928_infinite_loop_test1() throws Exception { // gcc extension
+// try {
+// super.testPredefinedSymbol_bug70928_infinite_loop_test1();
+// fail();
+// } catch(AssertionError _) { }
+// }
+//
+// public void testPredefinedSymbol_bug70928_infinite_loop_test2() throws Exception { // gcc extension
+// try {
+// super.testPredefinedSymbol_bug70928_infinite_loop_test2();
+// fail();
+// } catch(AssertionError _) { }
+// }
+
+
+// @Override
+// public void testBug102376() throws Exception { // gcc extension
+// try {
+// super.testBug102376();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+
+// @Override
+// public void test158192_declspec_in_declarator() throws Exception {
+// try {
+// super.test158192_declspec_in_declarator();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+// @Override
+// public void test158192_declspec_on_class() throws Exception {
+// try {
+// super.test158192_declspec_on_class();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+// @Override
+// public void test158192_declspec_on_variable() throws Exception {
+// try {
+// super.test158192_declspec_on_variable();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+// @Override
+// public void testPredefinedSymbol_bug70928() throws Exception {
+// try {
+// super.testPredefinedSymbol_bug70928();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+
+ @Override
+ public void testBug64010() throws Exception { // 10000 else-ifs, busts LPG's stack
+ try {
+ //super.testBug64010();
+ //fail();
+ } catch(AssertionFailedError _) { }
+ }
+
+//
+// @Override
+// public void testGNUASMExtension() throws Exception {
+// try {
+// super.testGNUASMExtension();
+// fail();
+// } catch(AssertionFailedError _) {
+// } catch(AssertionError _) {
+// }
+// }
+//
+// @Override
+// public void testBug39551B() throws Exception {
+// try {
+// super.testBug39551B();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+//
+//
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionBasicTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionBasicTest.java
new file mode 100644
index 0000000000..07c3a841b4
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionBasicTest.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IFunction;
+import org.eclipse.cdt.core.dom.ast.ITypedef;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.prefix.BasicCompletionTest;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings({"restriction", "nls"})
+public class LRCompletionBasicTest extends BasicCompletionTest {
+
+ public static TestSuite suite() {
+ return new TestSuite(LRCompletionBasicTest.class);
+ }
+
+ public LRCompletionBasicTest() { }
+
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTCompletionNode getCompletionNode(String code,
+ ParserLanguage lang, boolean useGNUExtensions)
+ throws ParserException {
+
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ return ParseHelper.getCompletionNode(code, language);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+ @Override
+ public void testFunction() throws Exception {
+ String code =
+ "void func(int x) { }" +
+ "void func2() { fu";
+
+ // C++
+ IASTCompletionNode node = getGPPCompletionNode(code);
+ IBinding[] bindings = LRCompletionParseTest.getBindings(node.getNames());
+
+ assertEquals(2, bindings.length);
+ assertEquals("func", ((IFunction)bindings[0]).getName());
+ assertEquals("func2", ((IFunction)bindings[1]).getName());
+
+ // C
+ node = getGCCCompletionNode(code);
+ bindings = LRCompletionParseTest.getBindings(node.getNames());
+
+ assertEquals(2, bindings.length);
+ assertEquals("func", ((IFunction)bindings[0]).getName());
+ assertEquals("func2", ((IFunction)bindings[1]).getName());
+ }
+
+
+ @Override
+ public void testTypedef() throws Exception {
+ String code =
+ "typedef int blah;" +
+ "bl";
+
+ // C++
+ IASTCompletionNode node = getGPPCompletionNode(code);
+ IBinding[] bindings = LRCompletionParseTest.getBindings(node.getNames());
+
+ assertEquals(1, bindings.length);
+ assertEquals("blah", ((ITypedef)bindings[0]).getName());
+
+ // C
+ node = getGCCCompletionNode(code);
+ bindings = LRCompletionParseTest.getBindings(node.getNames());
+
+ assertEquals(1, bindings.length);
+ assertEquals("blah", ((ITypedef)bindings[0]).getName());
+ }
+
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionParseTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionParseTest.java
new file mode 100644
index 0000000000..373d3c2a21
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionParseTest.java
@@ -0,0 +1,415 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IEnumerator;
+import org.eclipse.cdt.core.dom.ast.IField;
+import org.eclipse.cdt.core.dom.ast.ITypedef;
+import org.eclipse.cdt.core.dom.ast.IVariable;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+
+
+/**
+ * Reuse the completion parse tests from the old parser for now.
+ */
+@SuppressWarnings("nls")
+public class LRCompletionParseTest extends TestCase {
+
+ public static TestSuite suite() {
+ return new TestSuite(LRCompletionParseTest.class);
+ }
+
+
+ public LRCompletionParseTest() { }
+ public LRCompletionParseTest(String name) { super(name); }
+
+
+ protected IASTCompletionNode parse(String code, int offset) throws Exception {
+ return ParseHelper.getCompletionNode(code, getCLanguage(), offset);
+ }
+
+
+ private static final Comparator<IBinding> BINDING_COMPARATOR = new Comparator<IBinding>() {
+ public int compare(IBinding b1, IBinding b2) {
+ return b1.getName().compareTo(b2.getName());
+ }
+ };
+
+
+ public static IBinding[] getBindings(IASTName[] names) {
+ List<IBinding> bindings = new ArrayList<IBinding>();
+
+ for(IASTName name : names) {
+ if(name.getTranslationUnit() == null)
+ continue;
+
+ for(IBinding binding : name.getCompletionContext().findBindings(name, true))
+ bindings.add(binding);
+ }
+
+ Collections.sort(bindings, BINDING_COMPARATOR);
+ return bindings.toArray(new IBinding[bindings.size()]);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+
+ // First steal tests from CompletionParseTest
+
+
+ public void testCompletionStructField() throws Exception {
+ String code =
+ "int aVar; " +
+ "struct D{ " +
+ " int aField1; " +
+ " int aField2; " +
+ "}; " +
+ "void foo(){" +
+ " struct D d; " +
+ " d.a " +
+ "}\n";
+
+ int index = code.indexOf( "d.a" );
+
+ IASTCompletionNode node = parse( code, index + 3 );
+ assertNotNull( node );
+
+ String prefix = node.getPrefix();
+ assertNotNull( prefix );
+ assertEquals( prefix, "a" );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(2, bindings.length);
+ assertEquals("aField1", ((IField)bindings[0]).getName());
+ assertEquals("aField2", ((IField)bindings[1]).getName());
+ }
+
+ public void testCompletionStructFieldPointer() throws Exception {
+ String code =
+ "struct Cube { " +
+ " int nLen; " +
+ " int nWidth; " +
+ " int nHeight; " +
+ "}; " +
+ "int volume( struct Cube * pCube ) { " +
+ " pCube->SP ";
+
+ IASTCompletionNode node = parse( code, code.indexOf("SP"));
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(3, bindings.length);
+ assertEquals("nHeight", ((IField)bindings[0]).getName());
+ assertEquals("nLen", ((IField)bindings[1]).getName());
+ assertEquals("nWidth", ((IField)bindings[2]).getName());
+ }
+
+
+ public void testCompletionParametersAsLocalVariables() throws Exception{
+ String code =
+ "int foo( int aParameter ){" +
+ " int aLocal;" +
+ " if( aLocal != 0 ){" +
+ " int aBlockLocal;" +
+ " a \n";
+
+ int index = code.indexOf( " a " );
+
+ IASTCompletionNode node = parse( code, index + 2 );
+ assertNotNull( node );
+
+ assertEquals("a", node.getPrefix()); //$NON-NLS-1$
+
+ IASTName[] names = node.getNames();
+ assertEquals(2, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(3, bindings.length);
+ assertEquals("aBlockLocal", ((IVariable)bindings[0]).getName());
+ assertEquals("aLocal", ((IVariable)bindings[1]).getName());
+ assertEquals("aParameter", ((IVariable)bindings[2]).getName());
+ }
+
+
+ public void testCompletionTypedef() throws Exception {
+ String code =
+ "typedef int Int; " +
+ "InSP";
+
+ int index = code.indexOf( "SP" );
+
+ IASTCompletionNode node = parse( code, index );
+ assertNotNull(node);
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ assertEquals("In", node.getPrefix());
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(1, bindings.length);
+ assertEquals("Int", ((ITypedef)bindings[0]).getName());
+ }
+
+ public void testCompletion() throws Exception {
+ String code =
+ "#define GL_T 0x2001\n" +
+ "#define GL_TRUE 0x1\n" +
+ "typedef unsigned char GLboolean;\n" +
+ "static GLboolean should_rotate = GL_T";
+
+ int index = code.indexOf("= GL_T");
+
+ IASTCompletionNode node = parse( code, index + 6);
+ assertNotNull(node);
+
+ assertEquals("GL_T", node.getPrefix()); //$NON-NLS-1$
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+ }
+
+ public void testCompletionInTypeDef() throws Exception {
+ String code =
+ "struct A { int name; }; \n" +
+ "typedef struct A * PA; \n" +
+ "int main() { \n" +
+ " PA a; \n" +
+ " a->SP \n" +
+ "} \n";
+
+ int index = code.indexOf("SP"); //$NON-NLS-1$
+
+ IASTCompletionNode node = parse( code, index );
+ assertNotNull( node );
+
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(1, bindings.length);
+ assertEquals("name", ((IField)bindings[0]).getName());
+ }
+
+
+ public void _testCompletionFunctionCall() throws Exception {
+ String code =
+ "struct A { \n" +
+ " int f2; \n" +
+ " int f4; \n" +
+ "}; \n" +
+ "const A * foo(){} \n" +
+ "void main( ) \n" +
+ "{ \n" +
+ " foo()->SP \n";
+
+ int index = code.indexOf( "SP" );
+
+ IASTCompletionNode node = parse( code, index );
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(2, bindings.length);
+ assertEquals("f2", ((IField)bindings[0]).getName());
+ assertEquals("f4", ((IField)bindings[1]).getName());
+ }
+
+
+ public void _testCompletionSizeof() throws Exception {
+ String code =
+ "int f() {\n" +
+ "short blah;\n" +
+ "int x = sizeof(bl";
+
+ int index = code.indexOf( "of(bl" );
+
+ IASTCompletionNode node = parse( code, index + 5);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(1, bindings.length);
+ assertEquals("blah", ((IVariable)bindings[0]).getName());
+ }
+
+
+ public void testCompletionForLoop() throws Exception {
+ String code =
+ "int f() {\n" +
+ " int biSizeImage = 5;\n" +
+ "for (int i = 0; i < bi ";
+
+ int index = code.indexOf("< bi");
+
+ IASTCompletionNode node = parse( code, index + 4);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(1, bindings.length);
+ assertEquals("biSizeImage", ((IVariable)bindings[0]).getName());
+ }
+
+
+
+ public void testCompletionStructPointer() throws Exception {
+ String code =
+ " struct Temp { char * total; };" +
+ " int f(struct Temp * t) {" +
+ " t->t[5] = t->";
+
+ int index = code.indexOf("= t->");
+
+ IASTCompletionNode node = parse( code, index + 5);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(1, bindings.length);
+ assertEquals("total", ((IVariable)bindings[0]).getName());
+ }
+
+
+ public void testCompletionEnum() throws Exception {
+ String code =
+ "typedef int DWORD;\n" +
+ "typedef char BYTE;\n" +
+ "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n" +
+ "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n" +
+ "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n" +
+ "enum e {\n" +
+ "blah1 = 5,\n" +
+ "blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n" +
+ "blah3\n" +
+ "};\n" +
+ "e mye = bl\n";
+
+ int index = code.indexOf("= bl");
+
+ IASTCompletionNode node = parse( code, index + 4);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(3, bindings.length);
+ assertEquals("blah1", ((IEnumerator)bindings[0]).getName());
+ assertEquals("blah2", ((IEnumerator)bindings[1]).getName());
+ assertEquals("blah3", ((IEnumerator)bindings[2]).getName());
+ }
+
+
+ public void testCompletionStructArray() throws Exception {
+ String code =
+ "struct packet { int a; int b; };\n" +
+ "struct packet buffer[5];\n" +
+ "int main(int argc, char **argv) {\n" +
+ " buffer[2].";
+
+ int index = code.indexOf("[2].");
+
+ IASTCompletionNode node = parse( code, index + 4);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(2, bindings.length);
+ assertEquals("a", ((IField)bindings[0]).getName());
+ assertEquals("b", ((IField)bindings[1]).getName());
+ }
+
+
+ public void testCompletionPreprocessorDirective() throws Exception {
+ IASTCompletionNode node = parse("#", 1);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ //assertEquals("#", node.getPrefix());
+ }
+
+ public void testCompletionPreprocessorMacro() throws Exception {
+ String code =
+ "#define AMACRO 99 \n" +
+ "int main() { \n" +
+ " int AVAR; \n" +
+ " int x = A \n";
+
+ int index = code.indexOf("= A");
+
+ IASTCompletionNode node = parse( code, index + 3);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+ assertEquals("A", node.getPrefix());
+ }
+
+
+ public void testCompletionInsidePreprocessorDirective() throws Exception {
+ String code =
+ "#define MAC1 99 \n" +
+ "#define MAC2 99 \n" +
+ "#ifdef MA";
+
+ int index = code.length();
+
+ IASTCompletionNode node = parse( code, index );
+ assertNotNull( node );
+
+ assertEquals("MA", node.getPrefix());
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationInclusionTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationInclusionTests.java
new file mode 100644
index 0000000000..9ce5a54359
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationInclusionTests.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.CodeReader;
+import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.core.parser.ParserUtil;
+import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationInclusionTests;
+import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
+import org.eclipse.core.resources.IFile;
+
+@SuppressWarnings("restriction")
+public class LRDOMLocationInclusionTests extends DOMLocationInclusionTests {
+
+ public static TestSuite suite() {
+ return new TestSuite(LRDOMLocationInclusionTests.class);
+ }
+
+ public LRDOMLocationInclusionTests() {
+ }
+
+ public LRDOMLocationInclusionTests(String name, Class<Object> className) {
+ super(name, className);
+ }
+
+ public LRDOMLocationInclusionTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse(IFile code, IScannerInfo s)throws Exception {
+ // TODO: total freakin hack! the test suite needs to be refactored
+ ILanguage lang = code.getName().endsWith("cc") ? getCPPLanguage() : getCLanguage(); //$NON-NLS-1$
+
+ CodeReader codeReader = new CodeReader(code.getLocation().toOSString());
+ IASTTranslationUnit tu = lang.getASTTranslationUnit(codeReader, s, SavedCodeReaderFactory.getInstance(), null, ILanguage.OPTION_ADD_COMMENTS, ParserUtil.getParserLogService());
+
+ return tu;
+ }
+
+ @Override
+ protected IASTTranslationUnit parse(IFile code) throws Exception {
+
+ return parse(code, new ExtendedScannerInfo());
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationMacroTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationMacroTests.java
new file mode 100644
index 0000000000..ad7e88b7b6
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationMacroTests.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationMacroTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRDOMLocationMacroTests extends DOMLocationMacroTests {
+
+ public static TestSuite suite() {
+ return suite(LRDOMLocationMacroTests.class);
+ }
+
+ public LRDOMLocationMacroTests() {}
+ public LRDOMLocationMacroTests(String name) { super(name); }
+
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options().setCheckSyntaxProblems(expectNoProblems).setCheckPreprocessorProblems(expectNoProblems);
+ return ParseHelper.parse(code, language, options);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+ /**
+ * Tests GCC specific stuff, not applicable at this point
+ */
+
+// @Override
+// public void testStdioBug() throws ParserException {
+// try {
+// super.testStdioBug();
+// fail();
+// }
+// catch(Throwable e) { }
+// }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationTests.java
new file mode 100644
index 0000000000..13badf509c
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMLocationTests.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRDOMLocationTests extends DOMLocationTests {
+
+ public static TestSuite suite() {
+ return suite(LRDOMLocationTests.class);
+ }
+
+ public LRDOMLocationTests() { }
+ public LRDOMLocationTests(String name) { super(name); }
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options().setCheckSyntaxProblems(expectNoProblems).setCheckPreprocessorProblems(expectNoProblems);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+
+ // this one fails because the C99 parser does error recovery differently
+ @Override
+ public void test162180_1() throws Exception {
+ try {
+ super.test162180_1();
+ fail();
+ }
+ catch(AssertionFailedError e) {}
+
+ }
+//
+// @Override
+// public void test162180_3() throws Exception {
+// try {
+// super.test162180_3();
+// fail();
+// }
+// catch(AssertionFailedError e) {}
+// }
+//
+// @Override
+// public void testBug86698_2() throws Exception { // I don't think C++ supports nested functions
+// try {
+// super.testBug86698_2();
+// fail();
+// }
+// catch(AssertionFailedError e) {}
+// }
+//
+//
+// @Override
+// public void testBug120607() throws Exception { // #assert and #unassert are gcc extensions
+// try {
+// super.testBug120607();
+// fail();
+// }
+// catch(AssertionFailedError e) {}
+// }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMPreprocessorInformationTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMPreprocessorInformationTest.java
new file mode 100644
index 0000000000..412f16d768
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMPreprocessorInformationTest.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.DOMPreprocessorInformationTest;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRDOMPreprocessorInformationTest extends DOMPreprocessorInformationTest {
+
+ public static TestSuite suite() {
+ return suite(LRDOMPreprocessorInformationTest.class);
+ }
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options().setCheckSyntaxProblems(expectNoProblems).setCheckPreprocessorProblems(expectNoProblems);
+ return ParseHelper.parse(code, language, options);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDigraphTrigraphTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDigraphTrigraphTests.java
new file mode 100644
index 0000000000..cbd38557c7
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDigraphTrigraphTests.java
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
+import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
+import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
+import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+
+
+/**
+ * TODO these tests can be moved into the core
+ */
+@SuppressWarnings("nls")
+public class LRDigraphTrigraphTests extends TestCase {
+
+ public static TestSuite suite() {
+ return new TestSuite(LRDigraphTrigraphTests.class);
+ }
+
+
+ public LRDigraphTrigraphTests() { }
+ public LRDigraphTrigraphTests(String name) { super(name); }
+
+
+ protected IASTTranslationUnit parse(String code) {
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(true);
+ options.setCheckPreprocessorProblems(true);
+ return ParseHelper.parse(code, getCLanguage(), options);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+
+ public void testTrigraphSequences() {
+ String code =
+ "??=define SIZE ??/ \n" + // trigraph used as backslash to ignore newline
+ "99 \n" +
+ "int main(void)??< \n" +
+ " int arr??(SIZE??); \n" +
+ " arr??(4??) = '0' - (??-0 ??' 1 ??! 2); \n" +
+ " printf(\"%c??/n\", arr??(4??)); \n" +
+ "??> \n";
+
+ IASTTranslationUnit tu = parse(code);
+ assertNotNull(tu);
+
+ IASTPreprocessorStatement[] defines = tu.getAllPreprocessorStatements();
+ assertEquals(1, defines.length);
+ IASTPreprocessorMacroDefinition macro = (IASTPreprocessorMacroDefinition)defines[0];
+ assertEquals("SIZE", macro.getName().toString());
+ //assertEquals("99", macro.getExpansion());
+
+ IASTFunctionDefinition main = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTCompoundStatement body = (IASTCompoundStatement) main.getBody();
+ IASTStatement[] statements = body.getStatements();
+ assertEquals(3, statements.length);
+
+ // int arr??(SIZE??);
+ IASTSimpleDeclaration arr = (IASTSimpleDeclaration)((IASTDeclarationStatement)statements[0]).getDeclaration();
+ IASTArrayDeclarator arr_decl = (IASTArrayDeclarator)arr.getDeclarators()[0];
+ IASTArrayModifier modifier = arr_decl.getArrayModifiers()[0];
+ IASTLiteralExpression lit = (IASTLiteralExpression)modifier.getConstantExpression();
+ assertEquals(IASTLiteralExpression.lk_integer_constant, lit.getKind());
+
+ // arr??(4??) = '0' - (??-0 ??' 1 ??! 2);
+ IASTBinaryExpression expr = (IASTBinaryExpression)((IASTExpressionStatement)statements[1]).getExpression();
+ assertEquals(IASTBinaryExpression.op_assign, expr.getOperator());
+ IASTArraySubscriptExpression arr_op = (IASTArraySubscriptExpression)expr.getOperand1();
+ assertEquals("4", ((IASTLiteralExpression)arr_op.getSubscriptExpression()).toString());
+ IASTBinaryExpression cond = (IASTBinaryExpression)((IASTUnaryExpression)((IASTBinaryExpression)expr.getOperand2()).getOperand2()).getOperand();
+ assertEquals(IASTBinaryExpression.op_binaryOr, cond.getOperator());
+ IASTBinaryExpression cond2 = (IASTBinaryExpression)cond.getOperand1();
+ assertEquals(IASTBinaryExpression.op_binaryXor, cond2.getOperator());
+ IASTUnaryExpression not = (IASTUnaryExpression)cond2.getOperand1();
+ assertEquals(IASTUnaryExpression.op_tilde, not.getOperator());
+
+ // printf(\"%c??/n\", arr??(4??));
+ IASTFunctionCallExpression expr2 = (IASTFunctionCallExpression)((IASTExpressionStatement)statements[2]).getExpression();
+ IASTExpressionList params = (IASTExpressionList) expr2.getParameterExpression();
+ IASTArraySubscriptExpression arr_op2 = (IASTArraySubscriptExpression)params.getExpressions()[1];
+ assertEquals("4", ((IASTLiteralExpression)arr_op2.getSubscriptExpression()).toString());
+ }
+
+
+ public void testTrigraphEscapeSequences() {
+ // a ??/ trigraph should act just like a backslash in a string literal
+ String code =
+ "int main(void)??< \n" +
+ " char str[] = \"??/\"??/n\"; \n" +
+ " char c = '??/u0000'; \n" +
+ "??> \n";
+
+ parse(code); // will throw an exception if there are parse errors
+ }
+
+
+ public void testDigraphSequences() {
+ String code =
+ "%:define join(a, b) a %:%: b \n" +
+ "int main() <% \n" +
+ " int arr<:5:>; \n" +
+ "%> \n";
+
+ IASTTranslationUnit tu = parse(code); // will throw an exception if there are parse errors
+
+ IASTFunctionDefinition main = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTCompoundStatement body = (IASTCompoundStatement) main.getBody();
+ IASTStatement[] statements = body.getStatements();
+ assertEquals(1, statements.length);
+
+ IASTSimpleDeclaration arr = (IASTSimpleDeclaration)((IASTDeclarationStatement)statements[0]).getDeclaration();
+ IASTArrayDeclarator arr_decl = (IASTArrayDeclarator)arr.getDeclarators()[0];
+ IASTArrayModifier modifier = arr_decl.getArrayModifiers()[0];
+ IASTLiteralExpression lit = (IASTLiteralExpression)modifier.getConstantExpression();
+ assertEquals("5", lit.toString());
+
+ }
+
+
+
+ public void testTrigraphAndDigraphSequecesInPreprocessorDirectives() {
+ String code =
+ "%:define join1(a, b) a %:%: b \n" +
+ "%:define str1(a) %: a \n" +
+ "??=define join2(a, b) a ??=??= b \n" +
+ "??=define str2(a) ??= a \n" +
+ "int main() <% \n" +
+ " int join1(x, y) = str1(its all good); \n" +
+ " int join2(a, b) = str2(its still good); \n" +
+ "%> \n";
+
+ IASTTranslationUnit tu = parse(code); // will throw an exception if there are parse errors
+
+ IASTFunctionDefinition main = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTCompoundStatement body = (IASTCompoundStatement) main.getBody();
+ IASTStatement[] statements = body.getStatements();
+ assertEquals(2, statements.length);
+
+ IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration)((IASTDeclarationStatement)statements[0]).getDeclaration();
+ IASTDeclarator declarator1 = decl1.getDeclarators()[0];
+ assertEquals("xy", declarator1.getName().toString());
+ IASTLiteralExpression expr1 = (IASTLiteralExpression)((IASTInitializerExpression)declarator1.getInitializer()).getExpression();
+ assertEquals(IASTLiteralExpression.lk_string_literal, expr1.getKind());
+ assertEquals("\"its all good\"", expr1.toString());
+
+ IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration)((IASTDeclarationStatement)statements[1]).getDeclaration();
+ IASTDeclarator declarator2 = decl2.getDeclarators()[0];
+ assertEquals("ab", declarator2.getName().toString());
+ IASTLiteralExpression expr2 = (IASTLiteralExpression)((IASTInitializerExpression)declarator2.getInitializer()).getExpression();
+ assertEquals(IASTLiteralExpression.lk_string_literal, expr2.getKind());
+ assertEquals("\"its still good\"", expr2.toString());
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCCompleteParseExtensionsTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCCompleteParseExtensionsTest.java
new file mode 100644
index 0000000000..eeea2f59f5
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCCompleteParseExtensionsTest.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.GCCCompleteParseExtensionsTest;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRGCCCompleteParseExtensionsTest extends GCCCompleteParseExtensionsTest {
+
+ public static TestSuite suite() {
+ return suite(LRGCCCompleteParseExtensionsTest.class);
+ }
+
+ public LRGCCCompleteParseExtensionsTest() {}
+ public LRGCCCompleteParseExtensionsTest(String name) { super(name); }
+
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options().setCheckSyntaxProblems(expectNoProblems).setCheckPreprocessorProblems(expectNoProblems);
+ return ParseHelper.parse(code, language, options);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCTests.java
new file mode 100644
index 0000000000..712db6dcb9
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCTests.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.GCCTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRGCCTests extends GCCTests {
+
+ public static TestSuite suite() {
+ return suite(LRGCCTests.class);
+ }
+
+ public LRGCCTests() {}
+ public LRGCCTests(String name) { super(name); }
+
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options().setCheckSyntaxProblems(expectNoProblems).setCheckPreprocessorProblems(expectNoProblems);
+ return ParseHelper.parse(code, language, options);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRImageLocationTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRImageLocationTests.java
new file mode 100644
index 0000000000..21997f6b77
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRImageLocationTests.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.ImageLocationTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRImageLocationTests extends ImageLocationTests {
+
+ public static TestSuite suite() {
+ return suite(LRImageLocationTests.class);
+ }
+
+ public LRImageLocationTests() { }
+ public LRImageLocationTests(String name) { super(name); }
+
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions,
+ boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setSkipTrivialInitializers(skipTrivialInitializers);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRKnRTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRKnRTests.java
new file mode 100644
index 0000000000..3a1c690315
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRKnRTests.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2KnRTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+/**
+ * @author Mike Kucera
+ */
+@SuppressWarnings("restriction")
+public class LRKnRTests extends AST2KnRTests {
+
+ public static TestSuite suite() {
+ return suite(LRKnRTests.class);
+ }
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ return ParseHelper.parse(code, language, expectNoProblems);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+ // LPG handles syntax errors differently than the DOM parser
+ // these tests look for syntax errors in specific places and they fail
+
+ @Override
+ public void testKRCProblem3() throws Exception {
+ try {
+ super.testKRCProblem3();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+ @Override
+ public void testKRCProblem4() throws Exception {
+ try {
+ super.testKRCProblem4();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+ @Override
+ public void testKRCProblem5() throws Exception {
+ try {
+ super.testKRCProblem5();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+ @Override
+ public void testKRCProblem2() throws Exception {
+ try {
+ super.testKRCProblem2();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRNodeSelectorTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRNodeSelectorTest.java
new file mode 100644
index 0000000000..4c8a8b8bdc
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRNodeSelectorTest.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import java.io.IOException;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.ASTNodeSelectorTest;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRNodeSelectorTest extends ASTNodeSelectorTest {
+
+ public static TestSuite suite() {
+ return suite(LRNodeSelectorTest.class);
+ }
+
+ public LRNodeSelectorTest() {}
+ public LRNodeSelectorTest(String name) { super(name); }
+
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems, boolean skipTrivialInitializer) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setSkipTrivialInitializers(skipTrivialInitializer);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ @Override
+ protected void createTranslationUnit() throws IOException {
+ fCode= getContents(1)[0].toString();
+ fTu = ParseHelper.parse(fCode, getCPPLanguage(), false);
+ fSelector= fTu.getNodeSelector(null);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRParserTestSuite.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRParserTestSuite.java
new file mode 100644
index 0000000000..7c380a91c4
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRParserTestSuite.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class LRParserTestSuite extends TestSuite {
+
+
+ public static Test suite() {
+ return new TestSuite() {{
+
+ addTest(LRCommentTests.suite());
+ addTest(LRCompleteParser2Tests.suite());
+ addTest(LRCompletionBasicTest.suite());
+ addTest(LRCompletionParseTest.suite());
+ addTest(LRCPPSpecTest.suite());
+ addTest(LRCPPTests.suite());
+ addTest(LRCSpecTests.suite()); // a couple of failures
+ addTest(LRDigraphTrigraphTests.suite());
+ addTest(LRDOMLocationInclusionTests.suite());
+ addTest(LRDOMLocationMacroTests.suite());
+ addTest(LRDOMLocationTests.suite());
+ addTest(LRDOMPreprocessorInformationTest.suite());
+ addTest(LRGCCTests.suite());
+ addTest(LRGCCCompleteParseExtensionsTest.suite());
+ addTest(LRImageLocationTests.suite());
+ addTest(LRKnRTests.suite()); // mostly fail due to ambiguities
+ addTest(LRNodeSelectorTest.suite());
+ addTestSuite(LRQuickParser2Tests.class);
+ addTest(LRSelectionParseTest.suite()); // this one still has a lot of failing tests though
+ addTest(LRSemanticsTests.suite());
+ addTest(LRTaskParserTest.suite());
+ addTest(LRTemplateTests.suite());
+ addTest(LRTests.suite()); // has some tests that do fail
+ addTest(LRUtilOldTests.suite());
+ addTest(LRUtilTests.suite());
+ //addTest(LRCPPImplicitNameTests.suite());
+ //addTest(LRInactiveCodeTests.suite());
+
+ }};
+ }
+}
+
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRQuickParser2Tests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRQuickParser2Tests.java
new file mode 100644
index 0000000000..d0b7dc7082
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRQuickParser2Tests.java
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.QuickParser2Tests;
+
+public class LRQuickParser2Tests extends QuickParser2Tests {
+
+ public LRQuickParser2Tests() {}
+ public LRQuickParser2Tests(String name) { super(name); }
+
+
+ @Override
+ protected void parse(String code, boolean expectedToPass,
+ ParserLanguage lang, @SuppressWarnings("unused") boolean gcc) throws Exception {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ // don't check preprocessor problems for this test suite (causes tons of failures)
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectedToPass);
+ options.setCheckPreprocessorProblems(false);
+ ParseHelper.parse(code, language, options);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+ @Override
+ public void testBug36532() {
+ // ParseHelper does not throw ParserException
+ // just ignore this test
+ }
+
+// @Override
+// public void testBug39695() throws Exception { // no support for __alignof__
+// try {
+// super.testBug39695();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+// @Override
+// public void testBug39684() throws Exception { // typeof is gcc extension
+// try {
+// super.testBug39684();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+// @Override
+// public void testBug39698A() throws Exception { // gcc extension
+// try {
+// super.testBug39698A();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+// @Override
+// public void testBug39698B() throws Exception { // gcc extension
+// try {
+// super.testBug39698B();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+// @Override
+// public void testBug39704B() throws Exception { // gcc extension
+// try {
+// super.testBug39704B();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+// @Override
+// public void testBug39704C() throws Exception { // gcc extension
+// try {
+// super.testBug39704C();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+// @Override
+// public void testBug39677() throws Exception { // gcc extension
+// try {
+// super.testBug39677();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+//
+// @Override
+// public void testBug57652() throws Exception { // gcc extension
+// try {
+// super.testBug57652();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+//
+// @Override
+// public void testBug39701A() throws Exception { // gcc extension
+// try {
+// super.testBug39701A();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+// @Override
+// public void testBug39701B() throws Exception { // gcc extension
+// try {
+// super.testBug39701B();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+// @Override
+// public void testBug39701C() throws Exception { // gcc extension
+// try {
+// super.testBug39701C();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+//
+// @Override
+// public void testBug40007() throws Exception { // gcc extension
+// try {
+// super.testBug40007();
+// fail();
+// } catch(AssertionFailedError _) {
+// } catch(AssertionError _) {
+// }
+//
+// }
+//
+// @Override
+// public void testBug39703() throws Exception { // gcc extension
+// try {
+// super.testBug39703();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+//
+// @Override
+// public void testBug39554() throws Exception { // gcc extension
+// try {
+// super.testBug39554();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+//
+//
+// @Override
+// public void testBug39686() throws Exception { // gcc extension
+// try {
+// super.testBug39686();
+// fail();
+// } catch(AssertionFailedError _) { }
+// }
+
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSelectionParseTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSelectionParseTest.java
new file mode 100644
index 0000000000..f6b3d5662d
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSelectionParseTest.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ICodeReaderFactory;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.CodeReader;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.ScannerInfo;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2SelectionParseTest;
+import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+import org.eclipse.core.resources.IFile;
+
+@SuppressWarnings("restriction")
+public class LRSelectionParseTest extends AST2SelectionParseTest {
+
+ public static TestSuite suite() {
+ return new TestSuite(LRSelectionParseTest.class);
+ }
+
+ public LRSelectionParseTest() {}
+ public LRSelectionParseTest(String name) { super(name); }
+
+ @Override
+ protected IASTNode parse(String code, ParserLanguage lang, int offset, int length) throws ParserException {
+ return parse(code, lang, false, false, offset, length);
+ }
+
+ @Override
+ protected IASTNode parse(IFile file, ParserLanguage lang, int offset, int length) throws ParserException {
+ IASTTranslationUnit tu = parse(file, lang, false, false);
+ return tu.selectNodeForLocation(tu.getFilePath(), offset, length);
+ }
+
+ @Override
+ protected IASTNode parse(String code, ParserLanguage lang, int offset, int length, boolean expectedToPass) throws ParserException {
+ return parse(code, lang, false, expectedToPass, offset, length);
+ }
+
+ @Override
+ protected IASTNode parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, int offset, int length) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setCheckSyntaxProblems(expectNoProblems);
+ IASTTranslationUnit tu = ParseHelper.parse(code, language, options);
+ return tu.selectNodeForLocation(tu.getFilePath(), offset, length);
+ }
+
+ protected IASTTranslationUnit parse( IFile file, ParserLanguage lang, IScannerInfo scanInfo, boolean useGNUExtensions, boolean expectNoProblems ) {
+
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+
+ String fileName = file.getLocation().toOSString();
+ ICodeReaderFactory fileCreator = SavedCodeReaderFactory.getInstance();
+ CodeReader reader = fileCreator.createCodeReaderForTranslationUnit(fileName);
+
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckBindings(true);
+
+ return ParseHelper.parse(reader, language, scanInfo, fileCreator, options);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse( IFile file, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems )
+ throws ParserException {
+ return parse(file, lang, new ScannerInfo(), useGNUExtensions, expectNoProblems);
+ }
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSemanticsTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSemanticsTests.java
new file mode 100644
index 0000000000..d88581caa0
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSemanticsTests.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.SemanticsTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRSemanticsTests extends SemanticsTests {
+
+ public static TestSuite suite() {
+ return suite(LRSemanticsTests.class);
+ }
+
+ public LRSemanticsTests() { }
+ public LRSemanticsTests(String name) { super(name); }
+
+
+ @SuppressWarnings("unused")
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions,
+ boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setSkipTrivialInitializers(skipTrivialInitializers);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTaskParserTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTaskParserTest.java
new file mode 100644
index 0000000000..b3e67ec916
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTaskParserTest.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.TaskParserTest;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRTaskParserTest extends TaskParserTest {
+
+ public static TestSuite suite() {
+ return new TestSuite(LRTaskParserTest.class);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ return parse(code, lang, useGNUExtensions, expectNoProblems, false);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setSkipTrivialInitializers(skipTrivialInitializers);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTemplateTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTemplateTests.java
new file mode 100644
index 0000000000..ffeab5cc29
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTemplateTests.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2TemplateTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRTemplateTests extends AST2TemplateTests {
+
+
+ public static TestSuite suite() {
+ return suite(LRTemplateTests.class);
+ }
+
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setSkipTrivialInitializers(skipTrivialInitializers);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTests.java
new file mode 100644
index 0000000000..6cc16d5444
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTests.java
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2Tests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+
+/**
+ *
+ * @author Mike Kucera
+ *
+ */
+@SuppressWarnings({ "nls", "restriction" })
+public class LRTests extends AST2Tests {
+
+ public static TestSuite suite() {
+ return suite(LRTests.class);
+ }
+
+ public LRTests(String name) {
+ super(name);
+ }
+
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ return parse(code, lang, useGNUExtensions, expectNoProblems, false);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, boolean skipTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setSkipTrivialInitializers(skipTrivialInitializers);
+ return ParseHelper.parse(code, language, options);
+ }
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+ public void testMultipleHashHash() throws Exception {
+ String code = "#define TWICE(a) int a##tera; int a##ther; \n TWICE(pan)";
+ parseAndCheckBindings(code, ParserLanguage.C);
+ }
+
+
+ public void testBug191279() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append(" /**/ \n");
+ sb.append("# define YO 99 /**/ \n");
+ sb.append("# undef YO /**/ ");
+ sb.append(" /* $ */ ");
+ String code = sb.toString();
+ parseAndCheckBindings(code, ParserLanguage.C);
+ }
+
+
+ public void testBug191324() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append("int x$y = 99; \n");
+ sb.append("int $q = 100; \n"); // can use $ as first character in identifier
+ sb.append("#ifndef SS$_INVFILFOROP \n");
+ sb.append("int z; \n");
+ sb.append("#endif \n");
+ String code = sb.toString();
+ parseAndCheckBindings(code, ParserLanguage.C);
+ }
+
+
+ public void testBug192009_implicitInt() throws Exception {
+ String code = "main() { int x; }";
+ IASTTranslationUnit tu = parse(code, ParserLanguage.C, false, true);
+
+ IASTDeclaration[] declarations = tu.getDeclarations();
+ assertEquals(1, declarations.length);
+
+ IASTFunctionDefinition main = (IASTFunctionDefinition) declarations[0];
+ ICASTSimpleDeclSpecifier declSpec = (ICASTSimpleDeclSpecifier) main.getDeclSpecifier();
+ assertEquals(0, declSpec.getType());
+
+
+ assertEquals("main", main.getDeclarator().getName().toString());
+ }
+
+
+
+ /* I don't care about C98
+ */
+ @Override
+ public void testBug196468_emptyArrayInitializer() { }
+ public void _testBug196468_emptyArrayInitializer() throws Exception {
+ super.testBug196468_emptyArrayInitializer();
+ }
+
+
+ // CHANGED
+// /* LPG holds on to all the tokens as you parse, so I don't think
+// * it would be easy to fix this bug.
+// */
+// @Override
+// public void testScalabilityOfLargeTrivialInitializer_Bug253690() { }
+// public void _testScalabilityOfLargeTrivialInitializer_Bug253690() throws Exception {
+//
+// super.testScalabilityOfLargeTrivialInitializer_Bug253690();
+// }
+
+
+ /* All of the identifiers in the code resolve correctly.
+ * The problem is that some of the expressions parse wrong but
+ * thats not actually a big deal. Fixing this bug will be
+ * difficult so defer it to the future.
+ */
+ @Override
+ public void testBinaryVsCastAmbiguities_Bug237057() { }
+ public void _testBinaryVsCastAmbiguities_Bug237057() throws Exception {
+ super.testBinaryVsCastAmbiguities_Bug237057();
+ }
+
+
+ /* All of the identifiers in the code resolve correctly.
+ * The problem is that some of the expressions parse wrong but
+ * thats not actually a big deal. Fixing this bug will be
+ * difficult so defer it to the future.
+ */
+ @Override
+ public void testCastVsFunctionCallAmbiguities_Bug237057() { }
+ public void _testCastVsFunctionCallAmbiguities_Bug237057() throws Exception {
+ super.testCastVsFunctionCallAmbiguities_Bug237057();
+ }
+
+
+ /* The LR parser generates the AST for switch statements
+ * differently than the DOM parser.
+ */
+ @Override
+ public void testCaseRange_Bug211882() { }
+ public void _testCaseRange_Bug211882() throws Exception {
+ super.testCaseRange_Bug211882();
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRUtilOldTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRUtilOldTests.java
new file mode 100644
index 0000000000..85debdd48b
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRUtilOldTests.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2UtilOldTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRUtilOldTests extends AST2UtilOldTests {
+
+ public static TestSuite suite() {
+ return suite(LRUtilOldTests.class);
+ }
+
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ return ParseHelper.parse(code, language, expectNoProblems);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+
+
+ @Override
+ public void testCastExpression() throws Exception { // A not typedefed
+ try {
+ super.testCastExpression();
+ fail();
+ } catch(AssertionFailedError _) {}
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRUtilTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRUtilTests.java
new file mode 100644
index 0000000000..98b0326454
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRUtilTests.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2UtilTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+@SuppressWarnings("restriction")
+public class LRUtilTests extends AST2UtilTests {
+
+ public static TestSuite suite() {
+ return suite(LRUtilTests.class);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang ) throws ParserException {
+ return parse(code, lang, false, true );
+ }
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions ) throws ParserException {
+ return parse( code, lang, useGNUExtensions, true );
+ }
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ return ParseHelper.parse(code, language, expectNoProblems);
+ }
+
+
+ protected ILanguage getCLanguage() {
+ return GCCLanguage.getDefault();
+ }
+
+ protected ILanguage getCPPLanguage() {
+ return GPPLanguage.getDefault();
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java
new file mode 100644
index 0000000000..8fec58190c
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java
@@ -0,0 +1,215 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.lrparser.tests;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.AssertionFailedError;
+
+import org.eclipse.cdt.core.dom.ICodeReaderFactory;
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IProblemBinding;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.CodeReader;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.core.parser.ParserUtil;
+import org.eclipse.cdt.core.parser.ScannerInfo;
+import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Utility methods for parsing test code using the C99 LPG parser.
+ *
+ * @author Mike Kucera
+ */
+@SuppressWarnings({"restriction", "nls"})
+public class ParseHelper {
+
+ static int testsRun = 0;
+
+
+
+ static protected class NameResolver extends ASTVisitor {
+ {
+ shouldVisitNames = true;
+ }
+
+ public List<IASTName> nameList = new ArrayList<IASTName>();
+ public List<String> problemBindings = new ArrayList<String>();
+ public int numNullBindings = 0;
+
+
+ @Override
+ public int visit(IASTName name) {
+ nameList.add(name);
+ IBinding binding = name.resolveBinding();
+ if (binding instanceof IProblemBinding)
+ problemBindings.add(name.toString());
+ if (binding == null)
+ numNullBindings++;
+ return PROCESS_CONTINUE;
+ }
+
+ public IASTName getName(int idx) {
+ if(idx < 0 || idx >= nameList.size())
+ return null;
+ return nameList.get(idx);
+ }
+
+ public int size() {
+ return nameList.size();
+ }
+ }
+
+
+
+ public static class Options {
+
+ boolean checkSyntaxProblems = true;
+ boolean checkPreprocessorProblems = true;
+ boolean checkBindings = false;
+
+ int expectedProblemBindings;
+ String[] problems;
+ boolean skipTrivialInitializers;
+
+ public Options setCheckSyntaxProblems(boolean checkSyntaxProblems) {
+ this.checkSyntaxProblems = checkSyntaxProblems;
+ return this;
+ }
+ public Options setCheckBindings(boolean checkBindings) {
+ this.checkBindings = checkBindings;
+ return this;
+ }
+ public Options setCheckPreprocessorProblems(boolean checkPreprocessorProblems) {
+ this.checkPreprocessorProblems = checkPreprocessorProblems;
+ return this;
+ }
+ public Options setExpectedProblemBindings(int expectedProblemBindings) {
+ this.expectedProblemBindings = expectedProblemBindings;
+ return this;
+ }
+ public Options setProblems(String[] problems) {
+ this.problems = problems;
+ setExpectedProblemBindings(problems.length);
+ setCheckBindings(true);
+ return this;
+ }
+ public Options setSkipTrivialInitializers(boolean skipTrivialInitializers) {
+ this.skipTrivialInitializers = skipTrivialInitializers;
+ return this;
+ }
+
+ }
+
+
+ public static IASTTranslationUnit parse(String code, ILanguage lang, boolean expectNoProblems) {
+ Options options = new Options().setCheckSyntaxProblems(expectNoProblems).setCheckPreprocessorProblems(expectNoProblems);
+ return parse(code.toCharArray(), lang, options);
+ }
+
+ public static IASTTranslationUnit parse(String code, ILanguage lang, Options options) {
+ return parse(code.toCharArray(), lang, options);
+ }
+
+
+ public static IASTTranslationUnit parse(char[] code, ILanguage lang, Options options) {
+ CodeReader codeReader = new CodeReader(code);
+ return parse(codeReader, lang, new ScannerInfo(), null, options);
+ }
+
+
+ /**
+ * TODO thats WAY too many parameters, need to use a parameter object, need to refactor the
+ * DOM parser test suite so that its a lot cleaner.
+ */
+ public static IASTTranslationUnit parse(CodeReader codeReader, ILanguage language, IScannerInfo scanInfo,
+ ICodeReaderFactory fileCreator, Options options) {
+ testsRun++;
+
+ IASTTranslationUnit tu;
+ try {
+ int languageOptions = 0;
+// if(options.skipTrivialInitializers)
+// languageOptions |= ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS;
+
+ tu = language.getASTTranslationUnit(codeReader, scanInfo, fileCreator, null, languageOptions, ParserUtil.getParserLogService());
+ } catch (CoreException e) {
+ throw new AssertionFailedError(e.toString());
+ }
+
+ // should parse correctly first before we look at the bindings
+ if(options.checkSyntaxProblems) {
+
+ // this should work for C++ also, CVisitor.getProblems() and CPPVisitor.getProblems() are exactly the same code!
+ if (CVisitor.getProblems(tu).length != 0) {
+ throw new AssertionFailedError(" CVisitor has AST Problems " );
+ }
+ }
+
+ if(options.checkPreprocessorProblems) {
+ if (tu.getPreprocessorProblems().length != 0) {
+ throw new AssertionFailedError(language.getName() + " TranslationUnit has Preprocessor Problems " );
+ }
+ }
+
+ // resolve all bindings
+ if (options.checkBindings) {
+ NameResolver res = new NameResolver();
+ tu.accept( res );
+ if(res.problemBindings.size() != options.expectedProblemBindings)
+ throw new AssertionFailedError("Expected " + options.expectedProblemBindings + " problem(s), encountered " + res.problemBindings.size());
+
+ if(options.problems != null) {
+ for(int i = 0; i < options.problems.length; i++) {
+ String expected = options.problems[i];
+ String actual = res.problemBindings.get(i);
+ if(!expected.equals(actual))
+ throw new AssertionFailedError(String.format("Problem binding not equal, expected: %s, got: %s", expected, actual));
+ }
+ }
+ }
+
+ return tu;
+ }
+
+
+ public static IASTTranslationUnit commentParse(String code, ILanguage language) {
+ CodeReader codeReader = new CodeReader(code.toCharArray());
+ IASTTranslationUnit tu;
+ try {
+ tu = language.getASTTranslationUnit(codeReader, new ScannerInfo(), null, null, ILanguage.OPTION_ADD_COMMENTS, ParserUtil.getParserLogService());
+ } catch (CoreException e) {
+ throw new AssertionFailedError(e.toString());
+ }
+ return tu;
+ }
+
+ public static IASTCompletionNode getCompletionNode(String code, ILanguage lang) {
+ return getCompletionNode(code, lang, code.length());
+ }
+
+
+ public static IASTCompletionNode getCompletionNode(String code, ILanguage language, int offset) {
+ CodeReader reader = new CodeReader(code.toCharArray());
+ try {
+ return language.getCompletionNode(reader, new ScannerInfo(), null, null, ParserUtil.getParserLogService(), offset);
+ } catch (CoreException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/.classpath b/lrparser/org.eclipse.cdt.core.lrparser/.classpath
index d207cd2c39..64c5e31b7a 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/.classpath
+++ b/lrparser/org.eclipse.cdt.core.lrparser/.classpath
@@ -3,6 +3,5 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="old"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF b/lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF
index 59fd47944f..5f6adddfee 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF
+++ b/lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF
@@ -11,10 +11,16 @@ Require-Bundle: org.eclipse.cdt.core,
Export-Package: org.eclipse.cdt.core.dom.lrparser,
org.eclipse.cdt.core.dom.lrparser.action,
org.eclipse.cdt.core.dom.lrparser.action.c99,
+ org.eclipse.cdt.core.dom.lrparser.action.cpp,
+ org.eclipse.cdt.core.dom.lrparser.action.gnu,
org.eclipse.cdt.core.dom.lrparser.c99,
org.eclipse.cdt.core.dom.lrparser.cpp,
+ org.eclipse.cdt.core.dom.lrparser.gnu,
org.eclipse.cdt.core.dom.lrparser.lpgextensions,
- org.eclipse.cdt.internal.core.dom.lrparser.c99;x-internal:=true
+ org.eclipse.cdt.internal.core.dom.lrparser.c99;x-internal:=true,
+ org.eclipse.cdt.internal.core.dom.lrparser.cpp,
+ org.eclipse.cdt.internal.core.dom.lrparser.gcc,
+ org.eclipse.cdt.internal.core.dom.lrparser.gpp
Bundle-Localization: plugin
Bundle-Vendor: %Bundle-Vendor.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/build.properties b/lrparser/org.eclipse.cdt.core.lrparser/build.properties
index 71b26d6c8f..b1a19e8d27 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/build.properties
+++ b/lrparser/org.eclipse.cdt.core.lrparser/build.properties
@@ -1,11 +1,11 @@
###############################################################################
-# Copyright (c) 2007 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:
+# Copyright (c) 2007, 2009 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
###############################################################################
source.. = src/
@@ -19,3 +19,4 @@ bin.includes = META-INF/,\
about.ini,\
about.mappings,\
about.properties
+src.includes = about.html
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml b/lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml
index 7ce515c2c7..2dfb0d5191 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/build.xml
@@ -1,5 +1,5 @@
<!--
- Copyright (c) 2006, 2008 IBM Corporation and others.
+ Copyright (c) 2006, 2009 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
@@ -9,38 +9,28 @@
IBM Corporation - initial API and implementation
-->
-<project name="CDT Extensible LR Parser Framework" default="both" basedir=".">
+<project name="CDT Extensible LR Parser Framework" basedir=".">
<description>Generates LPG parsers from grammar files</description>
-
- <fail unless="lpg_exe">
- Property $${lpg_exe} not set.
- This property must be set to the full path to the LPG generator executable.
- </fail>
-
- <fail unless="lpg_template">
- Property $${lpg_template} not set.
- This property must be set to the full path to the LPG templates folder.
- </fail>
-
+ <import file="generate.xml"/>
+
<property name="c99_location" value="../src/org/eclipse/cdt/internal/core/dom/lrparser/c99"/>
+ <property name="gcc_location" value="../src/org/eclipse/cdt/internal/core/dom/lrparser/gcc"/>
<property name="cpp_location" value="../src/org/eclipse/cdt/internal/core/dom/lrparser/cpp"/>
-
+ <property name="gpp_location" value="../src/org/eclipse/cdt/internal/core/dom/lrparser/gpp"/>
+
+ <target name="all" depends="c99, gcc, cpp, gpp"/>
<target name="clean_l_files">
<delete>
<fileset dir="${c99_location}" includes="**/*.l"/>
+ <fileset dir="${gcc_location}" includes="**/*.l"/>
<fileset dir="${cpp_location}" includes="**/*.l"/>
+ <fileset dir="${gpp_location}" includes="**/*.l"/>
</delete>
</target>
- <target name="both" depends="cpp, c99">
- <description>Generates the C99 and C++ parsers</description>
- <echo message="Done"/>
- </target>
-
-
<target name="c99">
<description>Generate the C99 parser</description>
<!-- Generate main parser -->
@@ -61,7 +51,36 @@
</antcall>
</target>
+ <target name="generate_c99">
+ <antcall target="generate">
+ <param name="grammar_dir" value="c99"/>
+ <param name="output_dir" value="${c99_location}"/>
+ <param name="grammar_name" value="${grammar_name}"/>
+ </antcall>
+ </target>
+
+
+ <target name="gcc">
+ <description>Generate the GCC parser</description>
+ <!-- Generate main parser -->
+ <antcall target="generate_gcc">
+ <param name="grammar_name" value="GCCParser"/>
+ </antcall>
+ <antcall target="generate_gcc">
+ <param name="grammar_name" value="GCCSizeofExpressionParser"/>
+ </antcall>
+ </target>
+
+ <target name="generate_gcc">
+ <antcall target="generate">
+ <param name="grammar_dir" value="gcc"/>
+ <param name="output_dir" value="${gcc_location}"/>
+ <param name="grammar_name" value="${grammar_name}"/>
+ </antcall>
+ </target>
+
+
<target name="cpp">
<description>Generate the C++ parser</description>
<antcall target="generate_cpp">
@@ -89,42 +108,37 @@
</antcall>
</target>
-
- <target name="generate_c99">
+ <target name="generate_cpp">
<antcall target="generate">
- <param name="grammar_dir" value="c99"/>
- <param name="output_dir" value="${c99_location}"/>
+ <param name="grammar_dir" value="cpp"/>
+ <param name="output_dir" value="${cpp_location}"/>
<param name="grammar_name" value="${grammar_name}"/>
</antcall>
</target>
- <target name="generate_cpp">
+ <target name="gpp">
+ <description>Generate the GCC parser</description>
+ <!-- Generate main parser -->
+ <antcall target="generate_gpp">
+ <param name="grammar_name" value="GPPParser"/>
+ </antcall>
+ <antcall target="generate_gpp">
+ <param name="grammar_name" value="GPPSizeofExpressionParser"/>
+ </antcall>
+ </target>
+
+
+ <target name="generate_gpp">
<antcall target="generate">
- <param name="grammar_dir" value="cpp"/>
- <param name="output_dir" value="${cpp_location}"/>
+ <param name="grammar_dir" value="gpp"/>
+ <param name="output_dir" value="${gpp_location}"/>
<param name="grammar_name" value="${grammar_name}"/>
</antcall>
</target>
-
- <target name="generate">
- <property name="grammar_file" value="${grammar_dir}/${grammar_name}.g"/>
- <echo message="lpg_exe=${lpg_exe}"/>
- <echo message="lpg_template=${lpg_template}"/>
- <echo message="grammar_file=${grammar_file}.g"/>
- <echo message="output_dir=${output_dir}"/>
- <exec executable="${lpg_exe}">
- <arg value="${grammar_file}"/>
- <env key="LPG_TEMPLATE" path="${lpg_template}"/>
- </exec>
-
- <move overwrite="true" toDir="${output_dir}">
- <fileset dir=".">
- <include name="${grammar_name}*.*"/>
- </fileset>
- </move>
- </target>
+
+
</project> \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99ExpressionParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99ExpressionParser.g
index 80919514f3..4e999b0da8 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99ExpressionParser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99ExpressionParser.g
@@ -11,7 +11,7 @@
%options la=2
%options package=org.eclipse.cdt.internal.core.dom.lrparser.c99
-%options template=FixedBtParserTemplateD.g
+%options template=LRSecondaryParserTemplate.g
-- All we need to do is import the main parser and redefine the start symbol.
@@ -20,6 +20,10 @@ $Import
C99Grammar.g
$End
+$Define
+ $ast_class /. IASTExpression ./
+$End
+
$Start
expression_parser_start
$End
@@ -29,6 +33,6 @@ $Rules
expression_parser_start
::= expression
| ERROR_TOKEN
- /. $Build consumeExpressionProblem(); $EndBuild ./
+ /. $Build consumeEmpty(); $EndBuild ./
$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Grammar.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Grammar.g
index f591416686..0fd203cd02 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Grammar.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Grammar.g
@@ -1,5 +1,5 @@
-----------------------------------------------------------------------------------
--- Copyright (c) 2006, 2008 IBM Corporation and others.
+-- Copyright (c) 2006, 2009 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
@@ -9,16 +9,6 @@
-- IBM Corporation - initial API and implementation
-----------------------------------------------------------------------------------
--- TODO "complete" rules can be removed
-
--- TODO when the architecture has solidified try to move common
--- stuff between C99 and C++ into one file.
-
-$Include
-common.g
-$End
-
-
$Terminals
-- Keywords
@@ -34,10 +24,8 @@ $Terminals
integer floating charconst stringlit
-- identifiers
- -- Special token that represents identifiers that have been declared as typedefs (lexer feedback hack)
identifier
- --TypedefName
-- Special tokens used in content assist
@@ -104,8 +92,9 @@ $End
$Globals
/.
- import org.eclipse.cdt.core.dom.lrparser.action.c99.C99ASTNodeFactory;
+ import org.eclipse.cdt.core.dom.lrparser.action.c99.CNodeFactory;
import org.eclipse.cdt.core.dom.lrparser.action.c99.C99BuildASTParserAction;
+ import org.eclipse.cdt.core.dom.lrparser.action.c99.C99SecondaryParserFactory;
./
$End
@@ -113,7 +102,8 @@ $End
$Define
$build_action_class /. C99BuildASTParserAction ./
- $node_factory_create_expression /. C99ASTNodeFactory.DEFAULT_INSTANCE ./
+ $node_factory_create_expression /. CNodeFactory.getDefault() ./
+ $parser_factory_create_expression /. C99SecondaryParserFactory.getDefault() ./
$End
@@ -121,7 +111,7 @@ $End
$Rules
-------------------------------------------------------------------------------------------
--- AST and Symbol Table Scoping
+-- AST scopes
-------------------------------------------------------------------------------------------
@@ -129,7 +119,11 @@ $Rules
::= $empty
/. $Build openASTScope(); $EndBuild ./
-
+<empty>
+ ::= $empty
+ /. $Build consumeEmpty(); $EndBuild ./
+
+
-------------------------------------------------------------------------------------------
-- Content assist
-------------------------------------------------------------------------------------------
@@ -157,6 +151,10 @@ $Rules
-- Expressions
-------------------------------------------------------------------------------------------
+identifier_token
+ ::= 'identifier'
+ | 'Completion'
+
literal
::= 'integer'
@@ -177,9 +175,8 @@ primary_expression
/. $Build consumeExpressionBracketed(); $EndBuild ./
-primary_expression_id -- Typedefname not allowed as a variable name.
- ::= 'identifier'
- | 'Completion'
+primary_expression_id
+ ::= identifier_token
postfix_expression
@@ -196,7 +193,7 @@ postfix_expression
/. $Build consumeExpressionUnaryOperator(IASTUnaryExpression.op_postFixIncr); $EndBuild ./
| postfix_expression '--'
/. $Build consumeExpressionUnaryOperator(IASTUnaryExpression.op_postFixDecr); $EndBuild ./
- | '(' type_name ')' '{' <openscope-ast> initializer_list comma_opt '}'
+ | '(' type_id ')' initializer_list
/. $Build consumeExpressionTypeIdInitializer(); $EndBuild ./
@@ -205,9 +202,7 @@ comma_opt
member_name
- ::= 'identifier'
- -- | 'TypedefName'
- | 'Completion'
+ ::= identifier_token
unary_expression
@@ -230,13 +225,13 @@ unary_expression
/. $Build consumeExpressionUnaryOperator(IASTUnaryExpression.op_not); $EndBuild ./
| 'sizeof' unary_expression
/. $Build consumeExpressionUnaryOperator(IASTUnaryExpression.op_sizeof); $EndBuild ./
- | 'sizeof' '(' type_name ')'
+ | 'sizeof' '(' type_id ')'
/. $Build consumeExpressionTypeId(IASTTypeIdExpression.op_sizeof); $EndBuild ./
cast_expression
::= unary_expression
- | '(' type_name ')' cast_expression
+ | '(' type_id ')' cast_expression
/. $Build consumeExpressionCast(IASTCastExpression.op_cast); $EndBuild ./
@@ -286,40 +281,40 @@ equality_expression
/. $Build consumeExpressionBinaryOperator(IASTBinaryExpression.op_notequals); $EndBuild ./
-AND_expression
+and_expression
::= equality_expression
- | AND_expression '&' equality_expression
+ | and_expression '&' equality_expression
/. $Build consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryAnd); $EndBuild ./
-exclusive_OR_expression
- ::= AND_expression
- | exclusive_OR_expression '^' AND_expression
+exclusive_or_expression
+ ::= and_expression
+ | exclusive_or_expression '^' and_expression
/. $Build consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryXor); $EndBuild ./
-inclusive_OR_expression
- ::= exclusive_OR_expression
- | inclusive_OR_expression '|' exclusive_OR_expression
+inclusive_or_expression
+ ::= exclusive_or_expression
+ | inclusive_or_expression '|' exclusive_or_expression
/. $Build consumeExpressionBinaryOperator(IASTBinaryExpression.op_binaryOr); $EndBuild ./
-logical_AND_expression
- ::= inclusive_OR_expression
- | logical_AND_expression '&&' inclusive_OR_expression
+logical_and_expression
+ ::= inclusive_or_expression
+ | logical_and_expression '&&' inclusive_or_expression
/. $Build consumeExpressionBinaryOperator(IASTBinaryExpression.op_logicalAnd); $EndBuild ./
-logical_OR_expression
- ::= logical_AND_expression
- | logical_OR_expression '||' logical_AND_expression
+logical_or_expression
+ ::= logical_and_expression
+ | logical_or_expression '||' logical_and_expression
/. $Build consumeExpressionBinaryOperator(IASTBinaryExpression.op_logicalOr); $EndBuild ./
conditional_expression
- ::= logical_OR_expression
- | logical_OR_expression '?' expression ':' conditional_expression
- /. $Build consumeExpressionConditional(); $EndBuild ./
+ ::= logical_or_expression
+ | logical_or_expression '?' expression ':' assignment_expression
+ /. $Build consumeExpressionConditional(); $EndBuild ./
assignment_expression
@@ -395,11 +390,11 @@ statement
labeled_statement
- ::= identifier_or_typedefname ':' statement
+ ::= identifier_token ':' statement
/. $Build consumeStatementLabeled(); $EndBuild ./
- | 'case' constant_expression ':'
+ | 'case' constant_expression ':' statement
/. $Build consumeStatementCase(); $EndBuild ./
- | 'default' ':'
+ | 'default' ':' statement
/. $Build consumeStatementDefault(); $EndBuild ./
@@ -455,7 +450,7 @@ iteration_statement
jump_statement
- ::= 'goto' identifier_or_typedefname ';'
+ ::= 'goto' identifier_token ';'
/. $Build consumeStatementGoto(); $EndBuild ./
| 'continue' ';'
/. $Build consumeStatementContinue(); $EndBuild ./
@@ -531,8 +526,8 @@ enum_declaration_specifiers
typdef_name_declaration_specifiers
- ::= typedef_name_in_declspec
- | no_type_declaration_specifiers typedef_name_in_declspec
+ ::= type_name_specifier
+ | no_type_declaration_specifiers type_name_specifier
| typdef_name_declaration_specifiers no_type_declaration_specifier
@@ -553,7 +548,7 @@ complete_declarator
storage_class_specifier
::= storage_class_specifier_token
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
storage_class_specifier_token
@@ -566,7 +561,7 @@ storage_class_specifier_token
simple_type_specifier
::= simple_type_specifier_token
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
simple_type_specifier_token
::= 'void'
@@ -583,41 +578,41 @@ simple_type_specifier_token
| '_Imaginary'
-typedef_name_in_declspec
- ::= 'Completion'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
- | 'identifier'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
- -- | 'TypedefName' -- remove identifier if this is uncommented
+type_name_specifier
+ ::= identifier_token
+ /. $Build consumeToken(); $EndBuild ./
-
-identifier_or_typedefname
- ::= 'identifier'
- | 'Completion'
- -- | 'TypedefName'
-
struct_or_union_specifier
- ::= 'struct' '{' <openscope-ast> struct_declaration_list_opt '}'
- /. $Build consumeTypeSpecifierComposite(false, IASTCompositeTypeSpecifier.k_struct); $EndBuild ./
- | 'union' '{' <openscope-ast> struct_declaration_list_opt '}'
- /. $Build consumeTypeSpecifierComposite(false, IASTCompositeTypeSpecifier.k_union); $EndBuild ./
- | 'struct' identifier_or_typedefname '{' <openscope-ast> struct_declaration_list_opt '}'
- /. $Build consumeTypeSpecifierComposite(true, IASTCompositeTypeSpecifier.k_struct); $EndBuild ./
- | 'union' identifier_or_typedefname '{' <openscope-ast> struct_declaration_list_opt '}'
- /. $Build consumeTypeSpecifierComposite(true, IASTCompositeTypeSpecifier.k_union); $EndBuild ./
-
+ ::= struct_or_union struct_or_union_specifier_hook '{' <openscope-ast> struct_declaration_list_opt '}'
+ /. $Build consumeTypeSpecifierComposite(false); $EndBuild ./
+ | struct_or_union struct_or_union_specifier_hook identifier_token struct_or_union_specifier_suffix_hook '{' <openscope-ast> struct_declaration_list_opt '}'
+ /. $Build consumeTypeSpecifierComposite(true); $EndBuild ./
+struct_or_union_specifier_hook
+ ::= $empty
+
+struct_or_union_specifier_suffix_hook
+ ::= $empty
+
+struct_or_union
+ ::= 'struct'
+ | 'union'
+
+
elaborated_specifier
- ::= 'struct' identifier_or_typedefname
+ ::= 'struct' elaborated_specifier_hook identifier_token
/. $Build consumeTypeSpecifierElaborated(IASTCompositeTypeSpecifier.k_struct); $EndBuild ./
- | 'union' identifier_or_typedefname
+ | 'union' elaborated_specifier_hook identifier_token
/. $Build consumeTypeSpecifierElaborated(IASTCompositeTypeSpecifier.k_union); $EndBuild ./
- | 'enum' identifier_or_typedefname
+ | 'enum' elaborated_specifier_hook identifier_token
/. $Build consumeTypeSpecifierElaborated(IASTElaboratedTypeSpecifier.k_enum); $EndBuild ./
-
+elaborated_specifier_hook
+ ::= $empty
+
+
struct_declaration_list_opt
::= struct_declaration_list
| $empty
@@ -659,12 +654,15 @@ struct_declarator
enum_specifier
- ::= 'enum' '{' <openscope-ast> enumerator_list_opt comma_opt '}'
+ ::= 'enum' enum_specifier_hook '{' <openscope-ast> enumerator_list_opt comma_opt '}'
/. $Build consumeTypeSpecifierEnumeration(false); $EndBuild ./
- | 'enum' identifier_or_typedefname '{' <openscope-ast> enumerator_list_opt comma_opt '}'
+ | 'enum' enum_specifier_hook identifier_token '{' <openscope-ast> enumerator_list_opt comma_opt '}'
/. $Build consumeTypeSpecifierEnumeration(true); $EndBuild ./
-
+enum_specifier_hook
+ ::= $empty
+
+
enumerator_list_opt
::= enumerator_list
| $empty
@@ -676,15 +674,15 @@ enumerator_list
enumerator
- ::= identifier_or_typedefname
+ ::= identifier_token
/. $Build consumeEnumerator(false); $EndBuild ./
- | identifier_or_typedefname '=' constant_expression
+ | identifier_token '=' constant_expression
/. $Build consumeEnumerator(true); $EndBuild ./
type_qualifier
::= type_qualifier_token
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
type_qualifier_token
@@ -695,7 +693,7 @@ type_qualifier_token
function_specifier
::= 'inline'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
declarator
@@ -798,15 +796,18 @@ array_modifier_type_qualifiers
pointer_seq
- ::= '*'
+ ::= pointer_hook '*' pointer_hook
/. $Build consumePointer(); $EndBuild ./
- | pointer_seq '*'
+ | pointer_seq pointer_hook '*' pointer_hook
/. $Build consumePointer(); $EndBuild ./
- | '*' <openscope-ast> type_qualifier_list
+ | pointer_hook '*' pointer_hook <openscope-ast> type_qualifier_list
/. $Build consumePointerTypeQualifierList(); $EndBuild ./
- | pointer_seq '*' <openscope-ast> type_qualifier_list
+ | pointer_seq pointer_hook '*' pointer_hook <openscope-ast> type_qualifier_list
/. $Build consumePointerTypeQualifierList(); $EndBuild ./
+pointer_hook
+ ::= $empty
+
type_qualifier_list
::= type_qualifier
@@ -841,7 +842,7 @@ complete_parameter_declarator
-- only used in expressions, eg) sizeof, casts etc...
-type_name
+type_id
::= specifier_qualifier_list
/. $Build consumeTypeId(false); $EndBuild ./
| specifier_qualifier_list abstract_declarator
@@ -853,7 +854,7 @@ abstract_declarator -- a declarator that does not include an identifier
| <openscope-ast> pointer_seq
/. $Build consumeDeclaratorWithPointer(false); $EndBuild ./
| <openscope-ast> pointer_seq direct_abstract_declarator
- /. $Build consumeDeclaratorWithPointer(false); $EndBuild ./
+ /. $Build consumeDeclaratorWithPointer(true); $EndBuild ./
direct_abstract_declarator
@@ -890,15 +891,30 @@ function_direct_abstract_declarator
initializer
::= assignment_expression
/. $Build consumeInitializer(); $EndBuild ./
- | '{' <openscope-ast> initializer_list comma_opt '}'
+ | initializer_list
+
+
+initializer_list
+ ::= start_initializer_list '{' <openscope-ast> initializer_seq comma_opt '}' end_initializer_list
+ /. $Build consumeInitializerList(); $EndBuild ./
+ | '{' <openscope-ast> '}'
/. $Build consumeInitializerList(); $EndBuild ./
-initializer_list
+start_initializer_list
+ ::= $empty
+ /. $Build initializerListStart(); $EndBuild ./
+
+end_initializer_list
+ ::= $empty
+ /. $Build initializerListEnd(); $EndBuild ./
+
+
+initializer_seq
::= initializer
| designated_initializer
- | initializer_list ',' initializer
- | initializer_list ',' designated_initializer
+ | initializer_seq ',' initializer
+ | initializer_seq ',' designated_initializer
designated_initializer
@@ -918,13 +934,13 @@ designator_list
designator_base
::= '[' constant_expression ']'
/. $Build consumeDesignatorArray(); $EndBuild ./
- | '.' identifier_or_typedefname
+ | '.' identifier_token
/. $Build consumeDesignatorField(); $EndBuild ./
designator
::= '[' constant_expression ']'
/. $Build consumeDesignatorArray(); $EndBuild ./
- | '.' identifier_or_typedefname
+ | '.' identifier_token
/. $Build consumeDesignatorField(); $EndBuild ./
@@ -963,15 +979,17 @@ declaration_list
-- to avoid a shift/reduce error with the rule for declaration.
-- The symbol table scoped is opened in the rule for function_direct_declarator
function_definition
- ::= declaration_specifiers <openscope-ast> function_declarator function_body
- /. $Build consumeFunctionDefinition(true); $EndBuild ./
+ ::= normal_function_definition
-- this rule is here as a special case (its not C99 spec) just to support implicit int in function definitions
| <openscope-ast> function_declarator function_body
/. $Build consumeFunctionDefinition(false); $EndBuild ./
| declaration_specifiers <openscope-ast> knr_function_declarator <openscope-ast> declaration_list compound_statement
/. $Build consumeFunctionDefinitionKnR(); $EndBuild ./
-
+normal_function_definition
+ ::= declaration_specifiers <openscope-ast> function_declarator function_body
+ /. $Build consumeFunctionDefinition(true); $EndBuild ./
+
-- same syntax as compound_statement but a symbol table scope isn't opened
function_body
::= '{' '}'
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99NoCastExpressionParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99NoCastExpressionParser.g
index 3d63ced995..229155762b 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99NoCastExpressionParser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99NoCastExpressionParser.g
@@ -1,5 +1,5 @@
-----------------------------------------------------------------------------------
--- Copyright (c) 2006, 2008 IBM Corporation and others.
+-- Copyright (c) 2006, 2009 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
@@ -11,17 +11,21 @@
%options la=2
%options package=org.eclipse.cdt.internal.core.dom.lrparser.c99
-%options template=FixedBtParserTemplateD.g
+%options template=LRSecondaryParserTemplate.g
$Import
C99Grammar.g
$DropRules
cast_expression
- ::= '(' type_name ')' cast_expression
+ ::= '(' type_id ')' cast_expression
$End
+$Define
+ $ast_class /. IASTExpression ./
+$End
+
$Start
no_cast_start
$End
@@ -31,6 +35,6 @@ $Rules
no_cast_start
::= expression
| ERROR_TOKEN
- /. $Build consumeExpressionProblem(); $EndBuild ./
+ /. $Build consumeEmpty(); $EndBuild ./
$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Parser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Parser.g
index f89f4493f3..505d9ed0b9 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Parser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99Parser.g
@@ -11,10 +11,10 @@
%options la=2
%options package=org.eclipse.cdt.internal.core.dom.lrparser.c99
-%options template=FixedBtParserTemplateD.g
+%options template=LRParserTemplate.g
-- This file is needed because LPG won't allow redefinition of the
--- start symbol, so C99Grammar.g cannot define a start symbol.
+-- start symbol, so C99Grammar.g cannot define the start symbol.
$Import
C99Grammar.g
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99SizeofExpressionParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99SizeofExpressionParser.g
index a4f28e80ca..d9e515c576 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99SizeofExpressionParser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/C99SizeofExpressionParser.g
@@ -1,5 +1,5 @@
-----------------------------------------------------------------------------------
--- Copyright (c) 2006, 2008 IBM Corporation and others.
+-- Copyright (c) 2006, 2009 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
@@ -11,7 +11,7 @@
%options la=2
%options package=org.eclipse.cdt.internal.core.dom.lrparser.c99
-%options template=FixedBtParserTemplateD.g
+%options template=LRSecondaryParserTemplate.g
$Import
@@ -19,19 +19,23 @@ $Import
$DropRules
unary_expression
- ::= 'sizeof' '(' type_name ')'
+ ::= 'sizeof' '(' type_id ')'
$End
+$Define
+ $ast_class /. IASTExpression ./
+$End
+
$Start
- no_sizeof_type_name_start
+ no_sizeof_type_id_start
$End
$Rules
- no_sizeof_type_name_start
+ no_sizeof_type_id_start
::= expression
| ERROR_TOKEN
- /. $Build consumeExpressionProblem(); $EndBuild ./
+ /. $Build consumeEmpty(); $EndBuild ./
$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/common.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/common.g
deleted file mode 100644
index 3cd0fe8bd9..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/c99/common.g
+++ /dev/null
@@ -1,147 +0,0 @@
------------------------------------------------------------------------------------
--- 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
------------------------------------------------------------------------------------
-
-
-$Notice
--- Copied into all files generated by LPG
-/./*******************************************************************************
- * 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
- *********************************************************************************/
-
- // This file was generated by LPG
-./
-$End
-
-
-$Define
- -- These macros allow the template and header code to be customized by an extending parser.
- $ast_class /.Object./
- $data_class /. Object ./ -- allow anything to be passed between actions
-
- $extra_interfaces /. ./
- $additional_interfaces /. , IParserActionTokenProvider, IParser $extra_interfaces ./
-
- $build_action_class /. ./
- $resolve_action_class /. ./
- $node_factory_create_expression /. ./
-
- $lexer_class /. ./
- $action_class /. ./
-
- $Build /. $BeginAction action. ./
- $EndBuild /. $EndAction ./
-$End
-
-
-
-$Globals
-/.
- import java.util.*;
- import org.eclipse.cdt.core.dom.ast.*;
- import org.eclipse.cdt.core.dom.lrparser.IParser;
- import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
- import org.eclipse.cdt.core.dom.lrparser.lpgextensions.FixedBacktrackingParser;
-./
-$End
-
-$Headers
-/.
- private $build_action_class action;
-
- public $action_type() { // constructor
- }
-
- private void initActions(IASTTranslationUnit tu) {
- action = new $build_action_class($node_factory_create_expression, this, tu);
- }
-
-
- public void addToken(IToken token) {
- token.setKind(mapKind(token.getKind())); // TODO does mapKind need to be called?
- super.addToken(token);
- }
-
-
- public IASTCompletionNode parse(IASTTranslationUnit tu) {
- // this has to be done, or... kaboom!
- setStreamLength(getSize());
- initActions(tu);
-
- final int errorRepairCount = -1; // -1 means full error handling
- parser(null, errorRepairCount); // do the actual parse
- super.resetTokenStream(); // allow tokens to be garbage collected
-
- // the completion node may be null
- IASTCompletionNode compNode = action.getASTCompletionNode();
-
- //action = null;
- //parserAction = null;
- return compNode;
- }
-
- // uncomment this method to use with backtracking parser
- public List getRuleTokens() {
- return Collections.unmodifiableList(getTokens().subList(getLeftSpan(), getRightSpan() + 1));
- }
-
-
- public IASTNode getSecondaryParseResult() {
- return action.getSecondaryParseResult();
- }
-
- public String[] getOrderedTerminalSymbols() {
- return $sym_type.orderedTerminalSymbols;
- }
-
- public String getName() {
- return "$action_type"; //$NON-NLS-1$
- }
-
-./
-$End
-
-$Globals
-/.
- import org.eclipse.cdt.core.dom.lrparser.action.ITokenMap;
- import org.eclipse.cdt.core.dom.lrparser.action.TokenMap;
-./
-$End
-
-$Headers
-/.
-
- private ITokenMap tokenMap = null;
-
- public void setTokens(List<IToken> tokens) {
- resetTokenStream();
- addToken(new Token(null, 0, 0, 0)); // dummy token
- for(IToken token : tokens) {
- token.setKind(tokenMap.mapKind(token.getKind()));
- addToken(token);
- }
- addToken(new Token(null, 0, 0, $sym_type.TK_EOF_TOKEN));
- }
-
- public $action_type(String[] mapFrom) { // constructor
- tokenMap = new TokenMap($sym_type.orderedTerminalSymbols, mapFrom);
- }
-
-
-./
-$End
-
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPExpressionParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPExpressionParser.g
index 3af8f68ce6..ef93dac3d5 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPExpressionParser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPExpressionParser.g
@@ -11,7 +11,7 @@
%options la=2
%options package=org.eclipse.cdt.internal.core.dom.lrparser.cpp
-%options template=FixedBtParserTemplateD.g
+%options template=LRSecondaryParserTemplate.g
-- All we need to do is import the main parser and redefine the start symbol.
@@ -19,6 +19,10 @@ $Import
CPPGrammar.g
$End
+$Define
+ $ast_class /. IASTExpression ./
+$End
+
$Start
expression_parser_start
$End
@@ -28,6 +32,6 @@ $Rules
expression_parser_start
::= expression
| ERROR_TOKEN
- /. $Build consumeExpressionProblem(); $EndBuild ./
+ /. $Build consumeEmpty(); $EndBuild ./
$End \ No newline at end of file
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 e00df4ffae..23898a1d40 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPGrammar.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPGrammar.g
@@ -1,5 +1,5 @@
----------------------------------------------------------------------------------
--- Copyright (c) 2006, 2008 IBM Corporation and others.
+-- Copyright (c) 2006, 2009 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
@@ -9,24 +9,6 @@
-- IBM Corporation - initial API and implementation
----------------------------------------------------------------------------------
-$Notice
--- Copied into all files generated by LPG
-/./*******************************************************************************
- * 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
- *********************************************************************************/
-
- // This file was generated by LPG
-./
-$End
-
-
$Terminals
@@ -118,172 +100,35 @@ $End
$Globals
/.
- import java.util.*;
-
- import org.eclipse.cdt.core.dom.ast.*;
- import org.eclipse.cdt.core.dom.ast.cpp.*;
- import org.eclipse.cdt.core.dom.lrparser.action.cpp.CPPASTNodeFactory;
+ import org.eclipse.cdt.core.dom.ast.cpp.*;
+ import org.eclipse.cdt.core.dom.lrparser.action.cpp.CPPNodeFactory;
import org.eclipse.cdt.core.dom.lrparser.action.cpp.CPPBuildASTParserAction;
- import org.eclipse.cdt.core.dom.lrparser.IParser;
- import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
- import org.eclipse.cdt.core.dom.lrparser.lpgextensions.FixedBacktrackingParser;
+ import org.eclipse.cdt.core.dom.lrparser.action.cpp.CPPSecondaryParserFactory;
./
$End
--- TODO move as much code and macros as possible into a common file
$Define
- -- These macros allow the template and header code to be customized by an extending parser.
- $ast_class /.Object./
- $additional_interfaces /. , IParserActionTokenProvider, IParser ./
-
$build_action_class /. CPPBuildASTParserAction ./
- $resolve_action_class /. C99TypedefTrackerParserAction ./
- $node_factory_create_expression /. CPPASTNodeFactory.DEFAULT_INSTANCE ./
-
- $action_class /. CPPParserAction ./
- $data_class /. Object ./ -- allow anything to be passed between actions
-
- $UndoResolver /.$Undo action.resolver.undo(); $EndUndo./
-
- $Resolve /. $BeginTrial $resolve.
- ./
- $EndResolve /. $EndTrial
- $UndoResolver
- ./ -- undo actions are automatically generated for binding resolution actions
-
- $Builder /. $BeginFinal $builder.
- ./
- $EndBuilder /. $EndFinal ./
-
- $Build /. $Action $Builder ./
- $EndBuild /. $EndBuilder $EndAction ./
-
- $resolve /. action.resolver./
- $builder /. action.builder./
-
- -- comment out when using trial/undo
- $Action /. $BeginAction ./
- $BeginFinal /. ./
- $EndFinal /. ./
-
-$End
-
-
-$Headers
-/.
- private $action_class action;
-
- // uncomment to use with backtracking parser
- public $action_type() { // constructor
- }
-
- private void initActions(IASTTranslationUnit tu) {
- // binding resolution actions need access to IASTName nodes, temporary
- action = new $action_class();
- //action.resolver = new $resolve_action_class(this);
- action.builder = new $build_action_class($node_factory_create_expression, this, tu);
- //action.builder.setTokenMap(CPPParsersym.orderedTerminalSymbols);
-
- // comment this line to use with backtracking parser
- //setParserAction(action);
- }
-
-
- public void addToken(IToken token) {
- token.setKind(mapKind(token.getKind()));
- super.addToken(token);
- }
-
-
- public IASTCompletionNode parse(IASTTranslationUnit tu) {
- // this has to be done, or... kaboom!
- setStreamLength(getSize());
- initActions(tu);
-
- final int errorRepairCount = -1; // _1 means full error handling
- parser(null, errorRepairCount); // do the actual parse
- super.resetTokenStream(); // allow tokens to be garbage collected
-
- // the completion node may be null
- IASTCompletionNode compNode = action.builder.getASTCompletionNode();
-
- //action = null; // causes getSecondaryParseResult() to fail
-
- // Comment this line to use with backtracking parser
- //parserAction = null;
-
- return compNode;
- }
-
-
- // uncomment this method to use with backtracking parser
- public List getRuleTokens() {
- return Collections.unmodifiableList(getTokens().subList(getLeftSpan(), getRightSpan() + 1));
- }
-
- public IASTNode getSecondaryParseResult() {
- return action.builder.getSecondaryParseResult();
- }
-
- public String[] getOrderedTerminalSymbols() {
- return $sym_type.orderedTerminalSymbols;
- }
-
- public String getName() {
- return "$action_type"; //$NON-NLS-1$
- }
-
-./
-$End
-
--- TODO this has to be moved into a common file
-
-$Globals
-/.
- import org.eclipse.cdt.core.dom.lrparser.action.ITokenMap;
- import org.eclipse.cdt.core.dom.lrparser.action.TokenMap;
-./
-$End
-
-$Headers
-/.
-
- private ITokenMap tokenMap = null;
-
- public void setTokens(List<IToken> tokens) {
- resetTokenStream();
- addToken(new Token(null, 0, 0, 0)); // dummy token
- for(IToken token : tokens) {
- token.setKind(tokenMap.mapKind(token.getKind()));
- addToken(token);
- }
- addToken(new Token(null, 0, 0, $sym_type.TK_EOF_TOKEN));
- }
-
- public $action_type(String[] mapFrom) { // constructor
- tokenMap = new TokenMap($sym_type.orderedTerminalSymbols, mapFrom);
- }
-
-
-./
+ $node_factory_create_expression /. CPPNodeFactory.getDefault() ./
+ $parser_factory_create_expression /. CPPSecondaryParserFactory.getDefault() ./
$End
$Rules
------------------------------------------------------------------------------------------
--- AST and Symbol Table Scoping
+-- AST scoping
------------------------------------------------------------------------------------------
<openscope-ast>
::= $empty
- /.$Action $Builder openASTScope(); $EndBuilder $EndAction./
+ /. $Build openASTScope(); $EndBuild ./
<empty>
::= $empty
- /.$Action $Builder consumeEmpty(); $EndBuilder $EndAction./
+ /. $Build consumeEmpty(); $EndBuild ./
------------------------------------------------------------------------------------------
-- Content assist
@@ -319,21 +164,8 @@ $Rules
-- caught at the top level.
translation_unit
- ::= external_declaration_list
- /. $Build consumeTranslationUnit(); $EndBuild ./
- | $empty
+ ::= declaration_seq_opt
/. $Build consumeTranslationUnit(); $EndBuild ./
-
-
-external_declaration_list
- ::= external_declaration
- | external_declaration_list external_declaration
-
-
-external_declaration
- ::= declaration
- | ERROR_TOKEN
- /. $Build consumeDeclarationProblem(); $EndBuild ./
------------------------------------------------------------------------------------------
@@ -348,8 +180,6 @@ identifier_token
literal
::= 'integer'
/. $Build consumeExpressionLiteral(ICPPASTLiteralExpression.lk_integer_constant); $EndBuild ./
- | '0'
- /. $Build consumeExpressionLiteral(ICPPASTLiteralExpression.lk_integer_constant); $EndBuild ./
| 'floating'
/. $Build consumeExpressionLiteral(ICPPASTLiteralExpression.lk_float_constant); $EndBuild ./
| 'charconst'
@@ -420,12 +250,15 @@ dcolon_opt
qualified_id_name
::= dcolon_opt nested_name_specifier template_opt unqualified_id_name
/. $Build consumeQualifiedId(true); $EndBuild ./
- | '::' identifier_name
- /. $Build consumeGlobalQualifiedId(); $EndBuild ./
- | '::' operator_function_id_name
- /. $Build consumeGlobalQualifiedId(); $EndBuild ./
- | '::' template_id_name
+ | '::' unqualified_id_name
/. $Build consumeGlobalQualifiedId(); $EndBuild ./
+
+ --| '::' identifier_name
+ -- /. $Build consumeGlobalQualifiedId(); $EndBuild ./
+ --| '::' operator_function_id_name
+ -- /. $Build consumeGlobalQualifiedId(); $EndBuild ./
+ --| '::' template_id_name
+ -- /. $Build consumeGlobalQualifiedId(); $EndBuild ./
@@ -606,6 +439,7 @@ new_array_expressions_opt
new_initializer
::= '(' expression_list_opt ')' -- even if the parens are there we get null in the AST
+ /. $Build consumeNewInitializer(); $EndBuild ./
new_initializer_opt
@@ -809,11 +643,11 @@ statement
labeled_statement
- ::= identifier ':' statement
+ ::= 'identifier' ':' statement
/. $Build consumeStatementLabeled(); $EndBuild ./
- | case constant_expression ':'
+ | 'case' constant_expression ':' statement
/. $Build consumeStatementCase(); $EndBuild ./
- | default ':'
+ | 'default' ':' statement
/. $Build consumeStatementDefault(); $EndBuild ./
@@ -909,6 +743,8 @@ declaration
| explicit_specialization
| linkage_specification
| namespace_definition
+ | ERROR_TOKEN
+ /. $Build consumeDeclarationProblem(); $EndBuild ./
block_declaration
@@ -957,9 +793,9 @@ declaration_specifiers
declaration_specifiers_opt
- ::=? $empty -- this option must come first for constructors to parse correctly
+ ::= declaration_specifiers
+ | $empty
/. $Build consumeEmpty(); $EndBuild ./
- | declaration_specifiers
@@ -969,9 +805,9 @@ no_type_declaration_specifier
| function_specifier
| cv_qualifier
| 'friend'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
| 'typedef'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
no_type_declaration_specifiers
@@ -1028,24 +864,24 @@ type_name_declaration_specifiers
storage_class_specifier
::= 'auto'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
| 'register'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
| 'static'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
| 'extern'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
| 'mutable'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
function_specifier
::= 'inline'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
| 'virtual'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
| 'explicit'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
-- We have no way to disambiguate token types
@@ -1071,28 +907,21 @@ function_specifier
simple_type_specifier
+ ::= simple_type_specifier_token
+ /. $Build consumeToken(); $EndBuild ./
+
+simple_type_specifier_token
::= 'char'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
| 'wchar_t'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
| 'bool'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
| 'short'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
| 'int'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
| 'long'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
| 'signed'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
| 'unsigned'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
| 'float'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
| 'double'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
| 'void'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
-- last two rules moved here from simple_type_specifier
@@ -1118,26 +947,36 @@ type_name_specifier -- all identifiers of some kind
-- used for forward declaration and incomplete types
elaborated_type_specifier
- ::= class_keyword dcolon_opt nested_name_specifier_opt identifier_name
+ ::= class_keyword elaborated_specifier_hook dcolon_opt nested_name_specifier_opt identifier_name
/. $Build consumeTypeSpecifierElaborated(false); $EndBuild ./
- | class_keyword dcolon_opt nested_name_specifier_opt template_opt template_id_name
+ | class_keyword elaborated_specifier_hook dcolon_opt nested_name_specifier_opt template_opt template_id_name
/. $Build consumeTypeSpecifierElaborated(true); $EndBuild ./
- | 'enum' dcolon_opt nested_name_specifier_opt identifier_name
+ | 'enum' elaborated_specifier_hook dcolon_opt nested_name_specifier_opt identifier_name
/. $Build consumeTypeSpecifierElaborated(false); $EndBuild ./
+elaborated_specifier_hook
+ ::= $empty
+
+
-- there is currently no way to disambiguate identifier tokens
--enum_name
-- ::= identifier_token
+comma_opt
+ ::= ',' | $empty
+
+
enum_specifier
- ::= 'enum' '{' <openscope-ast> enumerator_list_opt '}'
+ ::= 'enum' enum_specifier_hook '{' <openscope-ast> enumerator_list_opt comma_opt '}'
/. $Build consumeTypeSpecifierEnumeration(false); $EndBuild ./
- | 'enum' identifier_token '{' <openscope-ast> enumerator_list_opt '}'
+ | 'enum' enum_specifier_hook identifier_token '{' <openscope-ast> enumerator_list_opt comma_opt '}'
/. $Build consumeTypeSpecifierEnumeration(true); $EndBuild ./
-
+enum_specifier_hook
+ ::= $empty
+
enumerator_list
::= enumerator_definition
| enumerator_list ',' enumerator_definition
@@ -1159,23 +998,18 @@ namespace_name
::= identifier_name
-namespace_definition
- ::= named_namespace_definition
- | unnamed_namespace_definition
-
-
-- In the spec grammar this is broken down into original_namespace_definition and extension_namespace_definition.
-- But since we are not tracking identifiers it becomes the same thing, so its simplified here.
-named_namespace_definition
- ::= 'namespace' namespace_name '{' <openscope-ast> declaration_seq_opt '}'
+namespace_definition
+ ::= 'namespace' namespace_name namespace_definition_hook '{' <openscope-ast> declaration_seq_opt '}'
/. $Build consumeNamespaceDefinition(true); $EndBuild ./
-
-
-unnamed_namespace_definition
- ::= 'namespace' '{' <openscope-ast> declaration_seq_opt '}'
+ | 'namespace' namespace_definition_hook '{' <openscope-ast> declaration_seq_opt '}'
/. $Build consumeNamespaceDefinition(false); $EndBuild ./
-
+namespace_definition_hook
+ ::= $empty
+
+
namespace_alias_definition
::= 'namespace' identifier_token '=' dcolon_opt nested_name_specifier_opt namespace_name ';'
/. $Build consumeNamespaceAliasDefinition(); $EndBuild ./
@@ -1187,6 +1021,7 @@ namespace_alias_definition
-- | 'using' '::' unqualified_id_name ';'
+-- TODO why not just check if the second token is 'typename'?
using_declaration
::= 'using' typename_opt dcolon_opt nested_name_specifier_opt unqualified_id_name ';'
/. $Build consumeUsingDeclaration(); $EndBuild ./
@@ -1232,10 +1067,12 @@ init_declarator_complete
init_declarator
- ::= declarator
- | declarator initializer
+ ::= complete_declarator
+ | complete_declarator initializer
/. $Build consumeDeclaratorWithInitializer(true); $EndBuild ./
+complete_declarator
+ ::= declarator
declarator
::= direct_declarator
@@ -1281,14 +1118,16 @@ array_modifier
ptr_operator
- ::= '*' <openscope-ast> cv_qualifier_seq_opt
+ ::= pointer_hook '*' pointer_hook <openscope-ast> cv_qualifier_seq_opt
/. $Build consumePointer(); $EndBuild ./
- | '&'
+ | pointer_hook '&' pointer_hook
/. $Build consumeReferenceOperator(); $EndBuild ./
- | dcolon_opt nested_name_specifier '*' <openscope-ast> cv_qualifier_seq_opt
+ | dcolon_opt nested_name_specifier pointer_hook '*' pointer_hook <openscope-ast> cv_qualifier_seq_opt
/. $Build consumePointerToMember(); $EndBuild ./
-
+pointer_hook
+ ::= $empty
+
ptr_operator_seq
::= ptr_operator
| ptr_operator_seq ptr_operator
@@ -1310,20 +1149,20 @@ cv_qualifier_seq_opt
cv_qualifier
::= 'const'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
| 'volatile'
- /. $Build consumeDeclSpecToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
---declarator_id_name
--- ::= qualified_or_unqualified_name
--- | dcolon_opt nested_name_specifier_opt type_name
--- /. $Build consumeQualifiedId(false); $EndBuild ./
-
declarator_id_name
- ::= unqualified_id_name
- | <empty> nested_name_specifier template_opt unqualified_id_name
- /. $Build consumeQualifiedId(true); $EndBuild ./
+ ::= qualified_or_unqualified_name
+ | dcolon_opt nested_name_specifier_opt type_name
+ /. $Build consumeQualifiedId(false); $EndBuild ./
+
+--declarator_id_name
+-- ::= unqualified_id_name
+-- | <empty> nested_name_specifier template_opt unqualified_id_name
+-- /. $Build consumeQualifiedId(true); $EndBuild ./
type_id
@@ -1451,17 +1290,29 @@ initializer
initializer_clause
::= assignment_expression
/. $Build consumeInitializer(); $EndBuild ./
- | '{' <openscope-ast> initializer_list ',' '}'
+ | initializer_list
+
+
+initializer_list
+ ::= start_initializer_list '{' <openscope-ast> initializer_seq ',' '}' end_initializer_list
/. $Build consumeInitializerList(); $EndBuild ./
- | '{' <openscope-ast> initializer_list '}'
+ | start_initializer_list '{' <openscope-ast> initializer_seq '}' end_initializer_list
/. $Build consumeInitializerList(); $EndBuild ./
| '{' <openscope-ast> '}'
/. $Build consumeInitializerList(); $EndBuild ./
-initializer_list
+start_initializer_list
+ ::= $empty
+ /. $Build initializerListStart(); $EndBuild ./
+
+end_initializer_list
+ ::= $empty
+ /. $Build initializerListEnd(); $EndBuild ./
+
+initializer_seq
::= initializer_clause
- | initializer_list ',' initializer_clause
+ | initializer_seq ',' initializer_clause
@@ -1481,15 +1332,20 @@ class_specifier
class_head
- ::= class_keyword identifier_name_opt <openscope-ast> base_clause_opt
+ ::= class_keyword composite_specifier_hook identifier_name_opt class_name_suffix_hook <openscope-ast> base_clause_opt
/. $Build consumeClassHead(false); $EndBuild ./
- | class_keyword template_id_name <openscope-ast> base_clause_opt
+ | class_keyword composite_specifier_hook template_id_name class_name_suffix_hook <openscope-ast> base_clause_opt
/. $Build consumeClassHead(false); $EndBuild ./
- | class_keyword nested_name_specifier identifier_name <openscope-ast> base_clause_opt
+ | class_keyword composite_specifier_hook nested_name_specifier identifier_name class_name_suffix_hook <openscope-ast> base_clause_opt
/. $Build consumeClassHead(true); $EndBuild ./
- | class_keyword nested_name_specifier template_id_name <openscope-ast> base_clause_opt
+ | class_keyword composite_specifier_hook nested_name_specifier template_id_name class_name_suffix_hook <openscope-ast> base_clause_opt
/. $Build consumeClassHead(true); $EndBuild ./
+composite_specifier_hook
+ ::= $empty
+
+class_name_suffix_hook
+ ::= $empty
identifier_name_opt
::= identifier_name
@@ -1538,9 +1394,12 @@ member_declaration_list_opt
member_declarator_list
- ::= member_declarator
- | member_declarator_list ',' member_declarator
+ ::= member_declarator_complete
+ | member_declarator_list ',' member_declarator_complete
+
+member_declarator_complete
+ ::= member_declarator
member_declarator
::= declarator
@@ -1592,11 +1451,11 @@ base_specifier
access_specifier_keyword
::= 'private'
- /. $Build consumeAccessKeywordToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
| 'protected'
- /. $Build consumeAccessKeywordToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
| 'public'
- /. $Build consumeAccessKeywordToken(); $EndBuild ./
+ /. $Build consumeToken(); $EndBuild ./
access_specifier_keyword_opt
@@ -1739,11 +1598,11 @@ template_argument_list_opt
template_argument
::= assignment_expression
+ /. $Build consumeTemplateArgumentExpression(); $EndBuild ./
| type_id
/. $Build consumeTemplateArgumentTypeId(); $EndBuild ./
--| qualified_or_unqualified_name -- accessible through assignment_expression
-
explicit_instantiation
::= 'template' declaration
/. $Build consumeTemplateExplicitInstantiation(); $EndBuild ./
@@ -1788,6 +1647,7 @@ exception_declaration
exception_specification
::= 'throw' '(' type_id_list ')'
| 'throw' '(' ')'
+ /. $Build consumePlaceHolder(); $EndBuild ./
exception_specification_opt
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoCastExpressionParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoCastExpressionParser.g
index 7340ce79e0..f5438e7751 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoCastExpressionParser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoCastExpressionParser.g
@@ -11,7 +11,7 @@
%options la=2
%options package=org.eclipse.cdt.internal.core.dom.lrparser.cpp
-%options template=FixedBtParserTemplateD.g
+%options template=LRSecondaryParserTemplate.g
$Import
CPPGrammar.g
@@ -22,6 +22,10 @@ $DropRules
$End
+$Define
+ $ast_class /. IASTExpression ./
+$End
+
$Start
no_cast_start
$End
@@ -31,6 +35,6 @@ $Rules
no_cast_start
::= expression
| ERROR_TOKEN
- /. $Build consumeExpressionProblem(); $EndBuild ./
+ /. $Build consumeEmpty(); $EndBuild ./
$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoFunctionDeclaratorParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoFunctionDeclaratorParser.g
index bdbaf96e24..ad093c6355 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoFunctionDeclaratorParser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPNoFunctionDeclaratorParser.g
@@ -11,7 +11,7 @@
%options la=2
%options package=org.eclipse.cdt.internal.core.dom.lrparser.cpp
-%options template=FixedBtParserTemplateD.g
+%options template=LRSecondaryParserTemplate.g
$Import
CPPGrammar.g
@@ -25,6 +25,10 @@ $DropRules
$End
+$Define
+ $ast_class /. IASTDeclarator ./
+$End
+
$Start
no_function_declarator_start
$End
@@ -34,7 +38,7 @@ $Rules
no_function_declarator_start
::= init_declarator_complete
| ERROR_TOKEN
- /. $Build consumeDeclarationProblem(); $EndBuild ./
+ /. $Build consumeEmpty(); $EndBuild ./
-- redeclare this rule with no semantic action, prevents recursion
init_declarator_complete
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPParser.g
index 47e91f6a41..9d9fb78abe 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPParser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPParser.g
@@ -11,7 +11,7 @@
%options la=2
%options package=org.eclipse.cdt.internal.core.dom.lrparser.cpp
-%options template=FixedBtParserTemplateD.g
+%options template=LRParserTemplate.g
-- This file is needed because LPG won't allow redefinition of the
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPSizeofExpressionParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPSizeofExpressionParser.g
index a98badc4ff..44f875fcea 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPSizeofExpressionParser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPSizeofExpressionParser.g
@@ -1,5 +1,5 @@
-----------------------------------------------------------------------------------
--- Copyright (c) 2006, 2008 IBM Corporation and others.
+-- Copyright (c) 2006, 2009 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
@@ -11,7 +11,7 @@
%options la=2
%options package=org.eclipse.cdt.internal.core.dom.lrparser.cpp
-%options template=FixedBtParserTemplateD.g
+%options template=LRSecondaryParserTemplate.g
$Import
@@ -26,15 +26,19 @@ $DropRules
$End
+$Define
+ $ast_class /. IASTExpression ./
+$End
+
$Start
- no_sizeof_type_name_start
+ no_sizeof_type_id_start
$End
$Rules
- no_sizeof_type_name_start
+ no_sizeof_type_id_start
::= expression
| ERROR_TOKEN
- /. $Build consumeExpressionProblem(); $EndBuild ./
+ /. $Build consumeEmpty(); $EndBuild ./
$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPTemplateTypeParameterParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPTemplateTypeParameterParser.g
index 6095b8b464..86f452af64 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPTemplateTypeParameterParser.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/cpp/CPPTemplateTypeParameterParser.g
@@ -11,7 +11,7 @@
%options la=2
%options package=org.eclipse.cdt.internal.core.dom.lrparser.cpp
-%options template=FixedBtParserTemplateD.g
+%options template=LRSecondaryParserTemplate.g
-- This parser is a bit of a hack.
@@ -33,6 +33,16 @@ $Import
CPPGrammar.g
$End
+$Globals
+/.
+ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
+./
+$End
+
+$Define
+ $ast_class /. ICPPASTTemplateParameter ./
+$End
+
$Start
type_parameter_start
$End
@@ -42,6 +52,6 @@ $Rules
type_parameter_start
::= type_parameter
| ERROR_TOKEN
- /. $Build consumeDeclarationProblem(); $EndBuild ./
+ /. $Build consumeEmpty(); $EndBuild ./
$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCGrammar.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCGrammar.g
new file mode 100644
index 0000000000..be071f5308
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCGrammar.g
@@ -0,0 +1,112 @@
+-----------------------------------------------------------------------------------
+-- Copyright (c) 2009 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
+-----------------------------------------------------------------------------------
+
+
+-- For this to work the environment variable LPG_INCLUDE must be set up
+-- to point at the directory where the C99Parser.g file is located.
+$Import
+ ../c99/C99Grammar.g
+$End
+
+$Import
+ ../gnu/GNUExtensions.g
+$End
+
+
+-- Tokens used by GCC but not part of the C99 spec
+$Terminals
+
+ asm
+
+$End
+
+
+$Globals
+/.
+ import org.eclipse.cdt.core.dom.lrparser.action.gnu.GCCBuildASTParserAction;
+ import org.eclipse.cdt.core.dom.lrparser.action.gnu.GCCSecondaryParserFactory;
+./
+$End
+
+$Define
+
+ $build_action_class /. GCCBuildASTParserAction ./
+ $parser_factory_create_expression /. GCCSecondaryParserFactory.getDefault() ./
+
+$End
+
+
+$Rules
+
+
+declaration
+ ::= extended_asm_declaration
+
+
+no_type_declaration_specifier
+ ::= attribute_or_decl_specifier
+
+complete_declarator
+ ::= attribute_or_decl_specifier_seq declarator
+ | declarator attribute_or_decl_specifier_seq
+ | attribute_or_decl_specifier_seq declarator attribute_or_decl_specifier_seq
+
+complete_struct_declarator
+ ::= attribute_or_decl_specifier_seq struct_declarator
+ | struct_declarator attribute_or_decl_specifier_seq
+ | attribute_or_decl_specifier_seq struct_declarator attribute_or_decl_specifier_seq
+
+enum_specifier_hook
+ ::= attribute_or_decl_specifier_seq
+
+struct_or_union_specifier_hook
+ ::= attribute_or_decl_specifier_seq
+
+struct_or_union_specifier_suffix_hook
+ ::= attribute_or_decl_specifier_seq
+
+pointer_hook
+ ::= attribute_or_decl_specifier_seq
+
+elaborated_specifier_hook
+ ::= attribute_or_decl_specifier_seq
+
+
+
+
+
+-- GCC extensions to designated initializers
+
+designator_base
+ ::= field_name_designator
+ | array_range_designator
+
+field_name_designator
+ ::= identifier_token ':'
+ /. $Build consumeDesignatorFieldGCC(); $EndBuild ./
+
+array_range_designator
+ ::= '[' constant_expression '...' constant_expression ']'
+ /. $Build consumeDesignatorArrayRange(); $EndBuild ./
+
+designated_initializer
+ ::= <openscope-ast> field_name_designator initializer
+ /. $Build consumeInitializerDesignated(); $EndBuild ./
+
+
+
+-- Nested functions
+
+block_item
+ ::= normal_function_definition
+ /. $Build consumeStatementDeclaration(); $EndBuild ./
+
+$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCParser.g
new file mode 100644
index 0000000000..ac9b15cff2
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCParser.g
@@ -0,0 +1,26 @@
+-----------------------------------------------------------------------------------
+-- Copyright (c) 2008, 2009 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.gcc
+%options template=LRParserTemplate.g
+
+
+-- This file is needed because LPG won't allow redefinition of the
+-- start symbol, so C99Grammar.g cannot define a start symbol.
+
+$Import
+ GCCGrammar.g
+$End
+
+$Start
+ translation_unit
+$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCSizeofExpressionParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCSizeofExpressionParser.g
new file mode 100644
index 0000000000..389a215e6c
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gcc/GCCSizeofExpressionParser.g
@@ -0,0 +1,43 @@
+-----------------------------------------------------------------------------------
+-- Copyright (c) 2009 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.gcc
+%options template=LRSecondaryParserTemplate.g
+
+
+$Import
+ GCCGrammar.g
+$DropRules
+
+ unary_expression
+ ::= 'sizeof' '(' type_id ')'
+ | '__alignof__' '(' type_id ')'
+ | 'typeof' '(' type_id ')'
+
+$End
+
+$Define
+ $ast_class /. IASTExpression ./
+$End
+
+$Start
+ no_sizeof_type_name_start
+$End
+
+$Rules
+
+ no_sizeof_type_name_start
+ ::= expression
+ | ERROR_TOKEN
+ /. $Build consumeEmpty(); $EndBuild ./
+
+$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/generate.xml b/lrparser/org.eclipse.cdt.core.lrparser/grammar/generate.xml
new file mode 100644
index 0000000000..6241db9594
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/generate.xml
@@ -0,0 +1,64 @@
+<!--
+ Copyright (c) 2009 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
+-->
+
+<project name="CDT Extensible LR Parser Framework" basedir=".">
+
+ <!--
+ Common tasks that can be used to generate a parser using LPG and the
+ LR parser framework.
+
+ There are two ANT properties that must be defined:
+ 1) lpg_exe - This property must be set to the full path to the LPG generator executable (lpg.exe).
+ 2) lpg_template - This property must be set to the full path to the folder that contains the LRParserTemplate.g file.
+
+ Additionally if the $Import or $Include directives are being used in a grammar
+ file then the LPG_INCLUDE environment variable must be set to the directory
+ of the files being included.
+ -->
+
+ <fail unless="lpg_exe">
+ Property $${lpg_exe} not set.
+ This property must be set to the full path to the LPG generator executable.
+ </fail>
+
+ <fail unless="lpg_template">
+ Property $${lpg_template} not set.
+ This property must be set to the full path to the LPG templates folder.
+ </fail>
+
+
+ <!--
+ Parameters:
+ ${grammar_dir} - directory that contains the grammar files
+ ${grammar_name} - the name of the main grammar file to run LPG on (not including the .g extension)
+ ${output_dir} - name of directory where generated files should go
+ -->
+ <target name="generate">
+ <property name="grammar_file" value="${grammar_dir}/${grammar_name}.g"/>
+ <echo message="lpg_exe=${lpg_exe}"/>
+ <echo message="lpg_template=${lpg_template}"/>
+ <echo message="grammar_file=${grammar_file}.g"/>
+ <echo message="output_dir=${output_dir}"/>
+
+ <exec executable="${lpg_exe}">
+ <arg value="${grammar_file}"/>
+ <env key="LPG_TEMPLATE" path="${lpg_template}"/>
+ </exec>
+
+ <move overwrite="true" toDir="${output_dir}">
+ <fileset dir=".">
+ <include name="${grammar_name}*.*"/>
+ </fileset>
+ </move>
+ </target>
+
+
+</project> \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/gnu/GNUExtensions.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gnu/GNUExtensions.g
new file mode 100644
index 0000000000..9fb2dbafe5
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gnu/GNUExtensions.g
@@ -0,0 +1,205 @@
+-----------------------------------------------------------------------------------
+-- Copyright (c) 2008, 2009 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
+-----------------------------------------------------------------------------------
+
+
+-- These are additional rules that allow for parsing of GNU extensions.
+-- This file is intended to be mixed-in with C99Parser.g or GPPParser.g
+
+
+$Terminals
+ -- additional GCC only tokens as defined in IGCCToken
+
+ typeof
+ __alignof__
+ __attribute__
+ __declspec
+ MAX
+ MIN
+
+ MAX ::= '>?'
+ MIN ::= '<?'
+
+$End
+
+
+$Headers
+/.
+ private $gnu_action_class gnuAction;
+./
+$End
+
+
+$Globals
+/.
+ import org.eclipse.cdt.core.dom.lrparser.action.gnu.GNUBuildASTParserAction;
+./
+$End
+
+
+$Define
+
+ $gnu_action_class /. GNUBuildASTParserAction ./ -- overridable
+
+ $action_initializations /.
+
+ gnuAction = new $gnu_action_class (this, astStack, $node_factory_create_expression);
+ gnuAction.setParserProperties(properties);
+ ./
+
+$End
+
+$Rules
+
+------------------------------------------------------------------------------------
+-- Support for __attribute__ and __declspec
+------------------------------------------------------------------------------------
+
+attribute_or_decl_specifier
+ ::= attribute_specifier
+ | decl_specifier
+ | asm_label
+
+attribute_or_decl_specifier_seq
+ ::= attribute_or_decl_specifier
+ | attribute_or_decl_specifier_seq attribute_or_decl_specifier
+
+
+
+attribute_specifier
+ ::= '__attribute__' '(' '(' attribute_list ')' ')'
+ | '__attribute__' '(' ')'
+
+attribute_list
+ ::= attribute
+ | attribute_list ',' attribute
+
+attribute
+ ::= word
+ | word '(' attribute_parameter_list ')'
+ | $empty
+
+word
+ ::= 'identifier'
+ | 'const'
+
+attribute_parameter_list
+ ::= attribute_parameter
+ | attribute_parameter_list ',' attribute_parameter
+
+attribute_parameter
+ ::= assignment_expression
+ /. $Build consumeIgnore(); $EndBuild ./
+ | $empty
+
+
+
+decl_specifier
+ ::= '__declspec' '(' extended_decl_modifier_seq ')'
+ | '__declspec' '(' ')'
+
+extended_decl_modifier_seq
+ ::= extended_decl_modifier
+ | extended_decl_modifier_seq extended_decl_modifier
+
+extended_decl_modifier
+ ::= 'identifier'
+ | 'identifier' '(' ')'
+ | 'identifier' '(' 'identifier' ')'
+ | 'identifier' '(' 'stringlit' ')'
+
+
+------------------------------------------------------------------------------------
+-- Other stuff
+------------------------------------------------------------------------------------
+
+asm_label
+ ::= 'asm' '(' 'stringlit' ')'
+
+
+extended_asm_declaration
+ ::= 'asm' volatile_opt '(' extended_asm_param_seq ')' ';'
+ /. $BeginAction gnuAction.consumeDeclarationASM(); $EndAction ./
+
+volatile_opt ::= 'volatile' | $empty
+
+extended_asm_param_seq
+ ::= extended_asm_param_with_operand
+ | extended_asm_param_seq ':' extended_asm_param_with_operand
+
+extended_asm_param_with_operand
+ ::= extended_asm_param
+ | extended_asm_param ',' extended_asm_param
+ | $empty
+
+extended_asm_param
+ ::= 'stringlit'
+ | 'stringlit' '(' 'identifier' ')'
+ | 'stringlit' '(' '*' 'identifier' ')'
+
+
+
+unary_expression
+ ::= '__alignof__' unary_expression
+ /. $Build consumeExpressionUnaryOperator(IASTUnaryExpression.op_alignOf); $EndBuild ./
+ | '__alignof__' '(' type_id ')'
+ /. $Build consumeExpressionTypeId(IASTTypeIdExpression.op_alignof); $EndBuild ./
+ | 'typeof' unary_expression
+ /. $Build consumeExpressionUnaryOperator(IASTUnaryExpression.op_typeof); $EndBuild ./
+ | 'typeof' '(' type_id ')'
+ /. $Build consumeExpressionTypeId(IASTTypeIdExpression.op_typeof); $EndBuild ./
+
+
+relational_expression
+ ::= relational_expression '>?' shift_expression
+ /. $Build consumeExpressionBinaryOperator(IASTBinaryExpression.op_max); $EndBuild ./
+ | relational_expression '<?' shift_expression
+ /. $Build consumeExpressionBinaryOperator(IASTBinaryExpression.op_min); $EndBuild ./
+
+
+conditional_expression
+ ::= logical_or_expression '?' <empty> ':' assignment_expression
+ /. $Build consumeExpressionConditional(); $EndBuild ./
+
+
+primary_expression
+ ::= '(' compound_statement ')'
+ /. $BeginAction gnuAction.consumeCompoundStatementExpression(); $EndAction ./
+
+
+labeled_statement
+ ::= 'case' case_range_expression ':' statement
+ /. $Build consumeStatementCase(); $EndBuild ./
+
+
+case_range_expression
+ ::= constant_expression '...' constant_expression
+ /. $Build consumeExpressionBinaryOperator(IASTBinaryExpression.op_assign); $EndBuild ./
+
+
+typeof_declaration_specifiers
+ ::= typeof_type_specifier
+ | no_type_declaration_specifiers typeof_type_specifier
+ | typeof_declaration_specifiers no_type_declaration_specifier
+
+
+typeof_type_specifier
+ ::= 'typeof' unary_expression
+ /. $Build consumeExpressionUnaryOperator(IASTUnaryExpression.op_typeof); $EndBuild ./
+ | 'typeof' '(' type_id ')'
+ /. $Build consumeExpressionTypeId(IASTTypeIdExpression.op_typeof); $EndBuild ./
+
+
+declaration_specifiers
+ ::= <openscope-ast> typeof_declaration_specifiers
+ /. $Build consumeDeclarationSpecifiersTypeof(); $EndBuild ./
+
+$End
+
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPGrammar.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPGrammar.g
new file mode 100644
index 0000000000..05b2767aea
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPGrammar.g
@@ -0,0 +1,130 @@
+-----------------------------------------------------------------------------------
+-- Copyright (c) 2009 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.gpp
+%options template=FixedBtParserTemplateD.g
+
+
+$Terminals
+
+ -- GCC allows these keywords to be used in C++
+
+ _Complex
+ _Imaginary
+ restrict
+
+$End
+
+
+-- For this to work the environment variable LPG_INCLUDE must be set up
+-- to point at the directory where the CPPParser.g file is located.
+$Import
+ ../cpp/CPPGrammar.g
+
+$DropRules
+
+-- will be replaced by extended asm syntax
+asm_definition
+ ::= 'asm' '(' 'stringlit' ')' ';'
+
+$End
+
+
+$Import
+ ../gnu/GNUExtensions.g
+$End
+
+$Globals
+/.
+ import org.eclipse.cdt.core.dom.lrparser.action.gnu.GPPBuildASTParserAction;
+ import org.eclipse.cdt.core.dom.lrparser.action.gnu.GPPSecondaryParserFactory;
+ import org.eclipse.cdt.core.dom.ast.gnu.cpp.*;
+./
+$End
+
+$Define
+
+ $build_action_class /. GPPBuildASTParserAction ./
+ $parser_factory_create_expression /. GPPSecondaryParserFactory.getDefault() ./
+
+$End
+
+$Rules
+
+
+asm_definition
+ ::= extended_asm_declaration
+
+
+no_type_declaration_specifier
+ ::= attribute_or_decl_specifier
+
+complete_declarator
+ ::= attribute_or_decl_specifier_seq declarator
+ | declarator attribute_or_decl_specifier_seq
+ | attribute_or_decl_specifier_seq declarator attribute_or_decl_specifier_seq
+
+member_declarator_complete
+ ::= attribute_or_decl_specifier_seq member_declarator_complete
+ | member_declarator_complete attribute_or_decl_specifier_seq
+ | attribute_or_decl_specifier_seq member_declarator_complete attribute_or_decl_specifier_seq
+
+enum_specifier_hook
+ ::= attribute_or_decl_specifier_seq
+
+composite_specifier_hook
+ ::= attribute_or_decl_specifier_seq
+
+class_name_suffix_hook
+ ::= attribute_or_decl_specifier_seq
+
+pointer_hook
+ ::= attribute_or_decl_specifier_seq
+
+declarator
+ ::= <openscope-ast> ptr_operator_seq attribute_or_decl_specifier_seq direct_declarator
+ /. $Build consumeDeclaratorWithPointer(true); $EndBuild ./
+
+elaborated_specifier_hook
+ ::= attribute_or_decl_specifier_seq
+
+namespace_definition_hook
+ ::= attribute_or_decl_specifier_seq
+
+
+simple_type_specifier
+ ::= '_Complex'
+ /. $Build consumeToken(); $EndBuild ./
+ | '_Imaginary'
+ /. $Build consumeToken(); $EndBuild ./
+
+cv_qualifier
+ ::= 'restrict'
+ /. $Build consumeToken(); $EndBuild ./
+
+
+explicit_instantiation
+ ::= 'extern' 'template' declaration
+ /. $Build consumeTemplateExplicitInstantiationGCC(IGPPASTExplicitTemplateInstantiation.ti_extern); $EndBuild ./
+ | 'static' 'template' declaration
+ /. $Build consumeTemplateExplicitInstantiationGCC(IGPPASTExplicitTemplateInstantiation.ti_static); $EndBuild ./
+ | 'inline' 'template' declaration
+ /. $Build consumeTemplateExplicitInstantiationGCC(IGPPASTExplicitTemplateInstantiation.ti_inline); $EndBuild ./
+
+
+-- CHANGED CDT 5 does not support this
+--postfix_expression
+-- ::= '(' type_id ')' initializer_list
+-- /. $Build consumeExpressionTypeIdInitializer(); $EndBuild ./
+
+
+$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPParser.g
new file mode 100644
index 0000000000..4ee7b043a0
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPParser.g
@@ -0,0 +1,26 @@
+----------------------------------------------------------------------------------
+-- Copyright (c) 2008, 2009 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.gpp
+%options template=LRParserTemplate.g
+
+
+-- This file is needed because LPG won't allow redefinition of the
+-- start symbol, so CPPGrammar.g cannot define a start symbol.
+
+$Import
+ GPPGrammar.g
+$End
+
+$Start
+ translation_unit
+$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPSizeofExpressionParser.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPSizeofExpressionParser.g
new file mode 100644
index 0000000000..e8a8833d66
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/gpp/GPPSizeofExpressionParser.g
@@ -0,0 +1,46 @@
+-----------------------------------------------------------------------------------
+-- Copyright (c) 2009 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.gpp
+%options template=LRSecondaryParserTemplate.g
+
+
+$Import
+ GPPGrammar.g
+$DropRules
+
+ unary_expression
+ ::= 'sizeof' '(' type_id ')'
+ | '__alignof__' '(' type_id ')'
+ | 'typeof' '(' type_id ')'
+
+ postfix_expression
+ ::= 'typeid' '(' type_id ')'
+
+$End
+
+$Define
+ $ast_class /. IASTExpression ./
+$End
+
+$Start
+ no_sizeof_type_id_start
+$End
+
+$Rules
+
+ no_sizeof_type_id_start
+ ::= expression
+ | ERROR_TOKEN
+ /. $Build consumeEmpty(); $EndBuild ./
+
+$End \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/lpgextensions/FixedBtParserTemplateD.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/template/LRParserTemplate.g
index fc1ef55420..9c7070f74b 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/lpgextensions/FixedBtParserTemplateD.g
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/template/LRParserTemplate.g
@@ -1,5 +1,5 @@
----------------------------------------------------------------------------------
--- Copyright (c) 2006, 2008 IBM Corporation and others.
+-- Copyright (c) 2006, 2009 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
@@ -9,6 +9,13 @@
-- IBM Corporation - initial API and implementation
----------------------------------------------------------------------------------
+
+-- This template is a modified version of BtParserTemplateD.g. for use with the LR parsers.
+-- This template contains a fix for an LPG bug:
+-- http://sourceforge.net/tracker/index.php?func=detail&aid=1732851&group_id=155963&atid=797879
+
+
+
--
-- In a parser using this template, the following macro may be redefined:
--
@@ -134,7 +141,9 @@ $End
$Headers
/.
- public class $action_type extends PrsStream implements RuleAction$additional_interfaces
+ public class $action_type extends PrsStream implements RuleAction, ITokenStream,
+ ITokenCollector, IParser<$ast_class>
+ $additional_interfaces
{
private static ParseTable prs = new $prs_type();
private FixedBacktrackingParser btParser;
@@ -225,22 +234,22 @@ $Headers
super.reportError((firsttok > lasttok ? ParseErrorCodes.INSERTION_CODE : ParseErrorCodes.SUBSTITUTION_CODE), location, msg);
}
- public $ast_class parser()
+ public void parser()
{
- return parser(null, 0);
+ parser(null, 0);
}
- public $ast_class parser(Monitor monitor)
+ public void parser(Monitor monitor)
{
- return parser(monitor, 0);
+ parser(monitor, 0);
}
- public $ast_class parser(int error_repair_count)
+ public void parser(int error_repair_count)
{
- return parser(null, error_repair_count);
+ parser(null, error_repair_count);
}
- public $ast_class parser(Monitor monitor, int error_repair_count)
+ public void parser(Monitor monitor, int error_repair_count)
{
try
{
@@ -258,7 +267,7 @@ $Headers
try
{
- return ($ast_class) btParser.parse(error_repair_count);
+ btParser.parse(error_repair_count);
}
catch (BadParseException e)
{
@@ -266,8 +275,6 @@ $Headers
DiagnoseParser diagnoseParser = new DiagnoseParser(this, prs);
diagnoseParser.diagnose(e.error_token);
}
-
- return null;
}
./
@@ -285,6 +292,121 @@ $Trailers
./
$End
---
--- E N D O F T E M P L A T E
---
+
+$Notice
+-- Copied into all files generated by LPG
+/./*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *********************************************************************************/
+
+ // This file was generated by LPG
+./
+$End
+
+
+$Define
+ -- These macros allow the template and header code to be customized by an extending parser.
+
+ $ast_class /. IASTTranslationUnit ./ -- override in secondary parsers
+
+ $extra_interfaces /. ./ -- can override this macro to provide additional interfaces
+ $additional_interfaces /. $extra_interfaces ./
+
+ $build_action_class /. ./ -- name of the class that has the AST building callbacks
+ $node_factory_create_expression /. ./ -- expression that will create the INodeFactory
+ $parser_factory_create_expression /. ./ -- expression that will create the ISecondaryParserFactory
+
+ $action_initializations /. ./
+
+ $Build /. $BeginAction action. ./ -- special action just for calling methods on the builder
+ $EndBuild /. $EndAction ./
+$End
+
+
+$Globals
+/.
+ import java.util.*;
+ import org.eclipse.cdt.core.dom.ast.*;
+ import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
+ import org.eclipse.cdt.core.dom.lrparser.IParser;
+ import org.eclipse.cdt.core.dom.lrparser.ITokenCollector;
+ import org.eclipse.cdt.core.dom.lrparser.CPreprocessorAdapter;
+ import org.eclipse.cdt.core.dom.lrparser.action.ITokenStream;
+ import org.eclipse.cdt.core.dom.lrparser.lpgextensions.FixedBacktrackingParser;
+ import org.eclipse.cdt.core.dom.lrparser.action.ScopedStack;
+ import org.eclipse.cdt.core.parser.IScanner;
+ import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
+ import org.eclipse.cdt.core.index.IIndex;
+./
+$End
+
+$Headers
+/.
+ private $build_action_class action;
+ private IASTCompletionNode compNode;
+
+
+ public $action_type(IScanner scanner, IDOMTokenMap tokenMap, IBuiltinBindingsProvider builtinBindingsProvider, IIndex index, Map<String,String> properties) {
+ initActions(properties);
+ action.initializeTranslationUnit(scanner, builtinBindingsProvider, index);
+ CPreprocessorAdapter.runCPreprocessor(scanner, this, tokenMap);
+ }
+
+ private void initActions(Map<String,String> properties) {
+ ScopedStack<Object> astStack = new ScopedStack<Object>();
+
+ action = new $build_action_class(this, astStack, $node_factory_create_expression, $parser_factory_create_expression);
+ action.setParserProperties(properties);
+
+ $action_initializations
+ }
+
+
+ public void addToken(IToken token) {
+ token.setKind(mapKind(token.getKind())); // TODO does mapKind need to be called?
+ super.addToken(token);
+ }
+
+
+ public $ast_class parse() {
+ // this has to be done, or... kaboom!
+ setStreamLength(getSize());
+
+ final int errorRepairCount = -1; // -1 means full error handling
+ parser(null, errorRepairCount); // do the actual parse
+ super.resetTokenStream(); // allow tokens to be garbage collected
+
+ compNode = action.getASTCompletionNode(); // the completion node may be null
+ return ($ast_class) action.getParseResult();
+ }
+
+
+ public IASTCompletionNode getCompletionNode() {
+ return compNode;
+ }
+
+ // uncomment this method to use with backtracking parser
+ public List<IToken> getRuleTokens() {
+ return getTokens().subList(getLeftSpan(), getRightSpan() + 1);
+ }
+
+ public String[] getOrderedTerminalSymbols() {
+ return $sym_type.orderedTerminalSymbols;
+ }
+
+ @SuppressWarnings("nls")
+ public String getName() {
+ return "$action_type";
+ }
+
+./
+$End
+
+
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/grammar/template/LRSecondaryParserTemplate.g b/lrparser/org.eclipse.cdt.core.lrparser/grammar/template/LRSecondaryParserTemplate.g
new file mode 100644
index 0000000000..50c66497a5
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/grammar/template/LRSecondaryParserTemplate.g
@@ -0,0 +1,66 @@
+----------------------------------------------------------------------------------
+-- Copyright (c) 2006, 2009 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 programming_language=java,margin=4,backtrack
+%Options table,error_maps,scopes
+%options prefix=TK_,
+%options action=("*.java", "/.", "./")
+%options ParseTable=lpg.lpgjavaruntime.ParseTable
+
+
+-- additional code needed by secondary parsers
+
+-- path is relative to the grammar file that uses the template
+$Include
+../template/LRParserTemplate.g
+$End
+
+
+
+
+$Define
+
+ $additional_interfaces /. , ISecondaryParser<$ast_class> $extra_interfaces ./
+
+$End
+
+$Globals
+/.
+ import org.eclipse.cdt.core.dom.lrparser.action.ITokenMap;
+ import org.eclipse.cdt.core.dom.lrparser.action.TokenMap;
+ import org.eclipse.cdt.core.dom.lrparser.ISecondaryParser;
+./
+$End
+
+$Headers
+/.
+
+ private ITokenMap tokenMap = null;
+
+ public void setTokens(List<IToken> tokens) {
+ resetTokenStream();
+ addToken(new Token(null, 0, 0, 0)); // dummy token
+ for(IToken token : tokens) {
+ token.setKind(tokenMap.mapKind(token.getKind()));
+ addToken(token);
+ }
+ addToken(new Token(null, 0, 0, $sym_type.TK_EOF_TOKEN));
+ }
+
+ public $action_type(ITokenStream stream, Map<String,String> properties) { // constructor for creating secondary parser
+ initActions(properties);
+ tokenMap = new TokenMap($sym_type.orderedTerminalSymbols, stream.getOrderedTerminalSymbols());
+ }
+
+./
+$End
+
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/C99ResolveParserAction.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/C99ResolveParserAction.java
deleted file mode 100644
index 6953ff43da..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/C99ResolveParserAction.java
+++ /dev/null
@@ -1,1558 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.action.deprecated;
-
-import static org.eclipse.cdt.core.parser.util.CollectionUtils.reverseIterable;
-import static org.eclipse.cdt.internal.core.dom.lrparser.symboltable.CNamespace.*;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import lpg.lpgjavaruntime.IToken;
-
-import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
-import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
-import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
-import org.eclipse.cdt.core.dom.ast.IArrayType;
-import org.eclipse.cdt.core.dom.ast.IBasicType;
-import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.ICompositeType;
-import org.eclipse.cdt.core.dom.ast.IField;
-import org.eclipse.cdt.core.dom.ast.IFunctionType;
-import org.eclipse.cdt.core.dom.ast.IParameter;
-import org.eclipse.cdt.core.dom.ast.IPointerType;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.ITypedef;
-import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
-import org.eclipse.cdt.core.dom.lrparser.action.ScopedStack;
-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.c99.bindings.C99ArrayType;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99BasicType;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Enumeration;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Enumerator;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Field;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Function;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99FunctionScope;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99FunctionType;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Label;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Parameter;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99PointerType;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99ProblemBinding;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Scope;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Structure;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Typedef;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Variable;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Binding;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Scope;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.ITypeable;
-import org.eclipse.cdt.internal.core.dom.lrparser.symboltable.C99SymbolTable;
-import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
-/**
- * This class was an attempt at doing full binding resolution during the parse
- * as opposed to doing it after the parse as is normally done with the DOM parser.
- *
- *
- * TODO: token mapping so that this will work with UPC
- * TODO: what about function definitions, don't they count as declarations?
- *
- * Try to resolve bindings without using the ASTStack, that way I can resolve bindings
- * without generating an AST. In the future I can remove this as a subclass of C99ParserAction.
- *
- * TODO: if I'm calculating scopes then those scopes need to be linked to AST nodes
- *
- * TODO: some language constructs are not handled yet: typeIds (casts), field designators
- *
- * @author Mike Kucera
- *
- * @deprecated Binding resolution is too hard, replacing with simpler C99TypedefTrackerParserAction
- */
-@SuppressWarnings("restriction")
-@Deprecated public class C99ResolveParserAction {
-
- private static final boolean DEBUG = true;
- private static final String NO_IDENT = ""; //$NON-NLS-1$
-
-
- // provides limited access to the token stream
- private final IParserActionTokenProvider parser;
-
- // The symbolTable currently in use
- private C99SymbolTable symbolTable = C99SymbolTable.EMPTY_TABLE;
-
- // A stack that keeps track of scopes in the symbol table, used to "close" scopes and to undo the opening of scopes
- private final LinkedList<C99SymbolTable> symbolTableScopeStack = new LinkedList<C99SymbolTable>();
-
- // A stack that keeps track of scopes that are set on bindings
- private final LinkedList<IC99Scope> bindingScopeStack = new LinkedList<IC99Scope>();
-
- // keeps track of nested declarations
- private final LinkedList<DeclaratorFrame> declarationStack = new LinkedList<DeclaratorFrame>();
-
- // keeps track of expression types
- private final ScopedStack<IType> exprTypeStack = new ScopedStack<IType>();
-
-
-
-
-
- private TypeQualifiers typeQualifiers; // TODO: can this go in the declaration stack?
-
- private static class TypeQualifiers {
- boolean isConst, isRestrict, isVolatile;
- }
-
-
- // "For every action there is an equal and opposite reaction." - Newton's third law
- private final LinkedList<IUndoAction> undoStack = new LinkedList<IUndoAction>();
-
-
- private interface IUndoAction {
- void undo();
- }
-
- public void undo() {
- undoStack.removeLast().undo();
- }
-
- public void undo(int steps) {
- for(int i = 0; i < steps; i++) {
- undo();
- }
- }
-
- public IC99Scope getCurrentScope() {
- return bindingScopeStack.getLast();
- }
-
-
- public C99ResolveParserAction(IParserActionTokenProvider parser) {
- this.parser = parser;
- bindingScopeStack.add(new C99Scope()); // the global scope
- System.out.println();
- }
-
-
- private static IType rawType(IType type) {
- while(type instanceof ITypedef) {
- type = ((C99Typedef)type).getType();
- }
- return type;
- }
-
- /**
- * Lexer feedback hack, used by the parser to identify typedefname tokens.
- */
- public boolean isTypedef(String ident) {
- boolean result = symbolTable.lookup(IDENTIFIER, ident) instanceof ITypedef;
- return result;
- }
-
-
- /**
- * Methods used by tests, package local access.
- */
- C99SymbolTable getSymbolTable() {
- return symbolTable;
- }
-
- int undoStackSize() {
- return undoStack.size();
- }
-
- LinkedList<DeclaratorFrame> getDeclarationStack() {
- return declarationStack;
- }
-
-
- /**
- * Called from the grammar file in places where a scope is created.
- *
- * Scopes are created by compound statements, however special care
- * must also be taken with for loops because they may contain
- * declarations.
- *
- * TODO: scope object now need to be handled explicitly
- */
- public void openSymbolScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- symbolTableScopeStack.add(symbolTable);
- bindingScopeStack.add(new C99Scope());
-
- undoStack.add(new IUndoAction() {
- public void undo() {
-
- bindingScopeStack.removeLast();
- symbolTable = symbolTableScopeStack.removeLast();
- }
- });
- }
-
-
- public IC99Scope closeSymbolScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final C99SymbolTable undoTable = symbolTable;
- symbolTable = symbolTableScopeStack.removeLast(); // close the scope
-
- final IC99Scope undoScope = bindingScopeStack.removeLast();
- if(!bindingScopeStack.isEmpty())
- undoScope.setParent(bindingScopeStack.getLast());
-
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- undoScope.setParent(null);
- bindingScopeStack.add(undoScope);
-
- symbolTableScopeStack.add(symbolTable);
- symbolTable = undoTable;
- }
- });
-
- return undoScope;
- }
-
-
- // TODO, this needs an undo action
- public void openPointerScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
- frame.openPointerModifierScope();
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- frame.closePointerModifierScope();
- }
- });
- }
-
-
- /**
- * Called from the grammar before a declaration is about to be reduced.
- */
- public void openDeclarationScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declarationStack.add(new DeclaratorFrame());
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declarationStack.removeLast();
- }
- });
- }
-
-
- public void closeDeclarationScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame undoFrame = declarationStack.removeLast();
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declarationStack.add(undoFrame);
- }
- });
- }
-
-
- public void consumeFunctionDefinition() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
-// final IC99Scope undoScope = bindingScope;
-//
-// C99FunctionScope functionScope = new C99FunctionScope();
-// functionScope.setBodyScope(undoScope);
-// undoScope.setParent(functionScope);
-// bindingScope = bindingScopeStack.removeLast();
-// functionScope.setParent(bindingScope);
-
-
- final IC99Scope undoScope = bindingScopeStack.removeLast();
-
- C99FunctionScope functionScope = new C99FunctionScope();
- functionScope.setBodyScope(undoScope);
- undoScope.setParent(functionScope);
- functionScope.setParent(bindingScopeStack.getLast());
-
-
- final DeclaratorFrame frame = declarationStack.removeLast();
-
- // the function binding needs to be available outside of the function's scope
- String functionName = frame.getDeclaratorName().toString();
- C99Function functionBinding = (C99Function) symbolTable.lookup(IDENTIFIER, functionName);
- functionBinding.setFunctionScope(functionScope);
-
- final C99SymbolTable undoTable = symbolTable;
- final C99SymbolTable outerTable = symbolTableScopeStack.removeLast();
- symbolTable = outerTable.insert(IDENTIFIER, functionName, functionBinding);
-
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- symbolTableScopeStack.add(outerTable);
- symbolTable = undoTable;
- declarationStack.add(frame);
- bindingScopeStack.add(undoScope);
- }
- });
- }
-
-
- public void consumeAbstractDeclaratorFunctionDeclarator() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
- frame.setFunctionDeclarator(true);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- frame.setFunctionDeclarator(false);
- }
- });
- }
-
-
- public void consumeDirectDeclaratorFunctionDeclarator() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
- frame.setFunctionDeclarator(true);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- frame.setFunctionDeclarator(false);
- }
- });
- }
-
-
- public void consumeDeclSpecToken() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- IToken token = parser.getRightIToken();
- final int kind = token.getKind();
-
- // creates a DeclSpec if there isn't one already
- DeclaratorFrame frame = declarationStack.getLast();
- final DeclSpec declSpec = frame.getDeclSpec();
- declSpec.add(kind);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declSpec.remove(kind);
- }
- });
- }
-
-
- /**
- * A labeled statement is creates an implicit declaration of the label identifier.
- *
- * TODO: a label has function scope, meaning the same label cannot be declared twice
- * in a function regardless of block scope.
- * TODO: labels can be implicitly declared, that is a goto can exist above the label
- */
- public IBinding consumeStatementLabeled() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- IToken token = parser.getLeftIToken();
- String ident = token.toString();
-
- IC99Binding labelBinding = new C99Label(ident);
- // TODO: strictly speaking the same label cannot be declared twice,
- // but we aren't checking that here
- final C99SymbolTable oldTable = symbolTable;
- symbolTable = symbolTable.insert(GOTO_LABEL, ident, labelBinding);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- symbolTable = oldTable;
- }
- });
-
- return labelBinding;
- }
-
-
- public IBinding consumeStatementGoto() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- List<IToken> ruleTokens = parser.getRuleTokens();
- assert ruleTokens.size() == 3 : "a goto statement must always consist of 3 tokens"; //$NON-NLS-1$
- String ident = ruleTokens.get(1).toString();
-
- final C99SymbolTable oldTable = symbolTable;
-
- IC99Binding labelBinding = symbolTable.lookup(GOTO_LABEL, ident);
- if(labelBinding == null) {
- labelBinding = new C99Label(ident);
- symbolTable = symbolTable.insert(GOTO_LABEL, ident, labelBinding);
- }
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- symbolTable = oldTable;
- }
- });
-
-
- return labelBinding;
- }
-
-
- public IBinding consumeDeclarationSpecifiersTypedefName() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- // find the typedef token
- String typedefName = null;
- for(IToken token : parser.getRuleTokens()) {
- // the token kind will still be TK_identifier, but there can only be one
- if(token.getKind() == C99Parsersym.TK_identifier) {
- typedefName = token.toString();
- break;
- }
- }
- assert typedefName != null : "a typedef token must have been parsed for this action to fire"; //$NON-NLS-1$
-
- // we know that the binding is a typedef because the lexer feedback hack worked and got us here
- ITypedef binding = (ITypedef) symbolTable.lookup(IDENTIFIER, typedefName);
- // TODO: do I need to clone the typedef in case it is further modified like with const?
- DeclaratorFrame frame = declarationStack.getLast();
- final DeclSpec declSpec = frame.getDeclSpec();
- declSpec.setType(binding);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- declSpec.setType(null);
- }
- });
-
- return binding;
- }
-
-
-
- public void consumeDirectDeclaratorIdentifier() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
- DebugUtil.printMethodTrace();
- frame.setDeclaratorName(parser.getRightIToken());
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- DebugUtil.printMethodTrace();
- frame.setDeclaratorName(null);
- }
- });
- }
-
-
-
- // TODO need to be careful, this is called in a lot of places in the grammar
- public void consumeDeclaratorWithPointer() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
- final LinkedList<C99PointerType> scope = frame.closePointerModifierScope();
- final int scopeSize = scope.size();
-
- for(C99PointerType pt : reverseIterable(scope)) {
- frame.addTypeModifier(pt);
- }
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- for(int i = 0; i < scopeSize; i++) {
- frame.removeLastTypeModifier();
- }
- frame.openPointerModifierScope(scope);
- }
- });
- }
-
-
-
- public void consumeDirectDeclaratorBracketed() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- // Used to tell the difference between function prototype declarations and function pointer declarations
- final DeclaratorFrame frame = declarationStack.getLast();
- frame.setDeclaratorBracketed(true);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- frame.setDeclaratorBracketed(false);
- }
- });
- }
-
-
- public IBinding consumeDeclaratorComplete() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
-
- IToken token = frame.getDeclaratorName();
- IType type = frame.getDeclaratorType();
- DeclSpec declSpec = frame.getDeclSpec();
- boolean isFunction = frame.isFunctionDeclarator();
- List<IBinding> nestedDeclarators = frame.getNestedDeclarations();
-
- if(isFunction)
- type = createFunctionType(type, nestedDeclarators);
-
- String ident = (token == null) ? null : token.toString();
-
- // compute the binding
- IC99Binding binding;
- if(declSpec.isTypedef())
- binding = createTypedefBinding(ident, type);
- else if(isFunction && !frame.isDeclaratorBracketed())
- binding = createFunctionBinding(ident, (IFunctionType)type, declSpec, nestedDeclarators);
- else
- binding = createVariableBinding(ident, type, declSpec);
-
- binding.setScope(bindingScopeStack.getLast());
-
- // insert into symbol table
- final C99SymbolTable oldTable = symbolTable;
- if(ident != null)
- symbolTable = symbolTable.insert(IDENTIFIER, ident, binding);
-
- declarationStack.removeLast();
- declarationStack.add(new DeclaratorFrame(frame.getDeclSpec())); // reset the declarator
- exprTypeStack.push(type);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- exprTypeStack.pop();
- declarationStack.removeLast();
- declarationStack.add(frame);
- symbolTable = oldTable;
- }
- });
-
- return binding;
- }
-
- /**
- * Just gets rid of the type that was on the type stack.
- */
- public void consumeInitDeclarator() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final IType type = exprTypeStack.pop();
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- exprTypeStack.push(type);
- }
- });
- }
-
-
- public IBinding consumeFunctionDefinitionHeader() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- DeclaratorFrame frame = declarationStack.getLast();
- DeclSpec declSpec = frame.getDeclSpec();
- String functionName = frame.getDeclaratorName().toString();
-
- final C99SymbolTable oldTable = symbolTable;
-
- // there may have been a function prototype, hence there may already be a binding for the function
- IC99Binding binding = symbolTable.lookup(IDENTIFIER, functionName);
- if(binding == null) {
- IType type = frame.getDeclaratorType();
- List<IBinding> nestedDeclarators = frame.getNestedDeclarations();
-
- IFunctionType functionType = createFunctionType(type, nestedDeclarators);
- binding = createFunctionBinding(functionName, functionType, declSpec, nestedDeclarators);
-
- // a scope has already been opened for the function body, use the outer scope
- IC99Scope topScope = bindingScopeStack.removeLast();
- binding.setScope(bindingScopeStack.getLast());
- bindingScopeStack.add(topScope);
-
- symbolTable = symbolTable.insert(IDENTIFIER, functionName, binding);
- }
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- symbolTable = oldTable;
- }
- });
-
- return binding;
- }
-
-
- public IBinding consumeDeclaratorCompleteParameter() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.removeLast();
- IToken token = frame.getDeclaratorName();
- IType type = frame.getDeclaratorType();
- DeclSpec declSpec = frame.getDeclSpec();
- boolean isFunction = frame.isFunctionDeclarator();
-
- // its a function pointer
- if(isFunction)
- type = createFunctionType(type, frame.getNestedDeclarations());
-
- String ident = (token == null) ? NO_IDENT : token.toString();
-
- IC99Binding parameterBinding = createParameterBinding(ident, type, declSpec);
- parameterBinding.setScope(bindingScopeStack.getLast());
-
- // check to see if there is already a parameter binding
- String functionName = declarationStack.getLast().getDeclaratorName().toString();
- C99Function function = (C99Function) symbolTable.lookup(IDENTIFIER, functionName);
-
- if(function != null) {
- // there is already a function binding for this function, that means there
- // is a function prototype and there is already a binding for this parameter
- int position = declarationStack.getLast().getNestedDeclarations().size();
- IParameter[] parameters = function.getParameters();
- if(parameters != null && position < parameters.length) {
- parameterBinding = (IC99Binding)parameters[position];
- }
- }
-
- // even if the binding is reused it still might be under a different name
- final C99SymbolTable oldTable = symbolTable;
- if(ident != null) {
- symbolTable = symbolTable.insert(IDENTIFIER, ident, parameterBinding);
- }
-
- declarationStack.getLast().addNestedDeclaration(parameterBinding);
-
- // parameter declarations can only have one declarator, so don't reset
- //declarationStack.add(new DeclaratorFrame()); // reset
-
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- //declarationStack.removeLast();
- declarationStack.getLast().removeLastNestedDeclaration();
- declarationStack.add(frame);
- symbolTable = oldTable;
- }
- });
-
- return parameterBinding;
- }
-
-
- /**
- * This is a special case for the rule:
- * parameter_declaration ::= declaration_specifiers
- *
- * In this case there is no declarator at all
- *
- * TODO: creating bindings that have no identifier seems really dumb,
- * why does it need to be done? Why not just have a null binding or
- * for that matter don't even have a name node
- *
- */
- public IBinding consumeParameterDeclarationWithoutDeclarator() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.removeLast();
- DeclSpec declSpec = frame.getDeclSpec();
- C99Parameter param = createParameterBinding(null, declSpec.getType(), declSpec);
- declarationStack.getLast().addNestedDeclaration(param);
-
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- declarationStack.getLast().removeLastNestedDeclaration();
- declarationStack.add(frame);
- }
- });
-
- return param;
- }
-
-
- public IBinding consumeDeclaratorCompleteField() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
- IToken token = frame.getDeclaratorName();
- IType type = frame.getDeclaratorType();
-
- // its a function pointer
- if(frame.isFunctionDeclarator())
- type = createFunctionType(type, frame.getNestedDeclarations());
-
- IBinding binding = createFieldBinding(token.toString(), type, frame.getDeclSpec());
-
- declarationStack.removeLast();
- declarationStack.getLast().addNestedDeclaration(binding);
- declarationStack.add(new DeclaratorFrame(frame.getDeclSpec())); // reset the declarator
- exprTypeStack.push(type);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- declarationStack.removeLast();
- declarationStack.getLast().removeLastNestedDeclaration();
- declarationStack.add(frame);
- }
- });
-
- return binding;
- }
-
-
- /**
- * An abstract declarator used as part of an expression, eg) a cast.
- * Only need the type.
- *
- * TODO: this isn't enough, I need a binding for the abstract declarator
- * what I really need is a consumeDeclaratorCompleteTypeId similar to above
- */
- public void consumeTypeId() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.removeLast();
- IType type = frame.getDeclaratorType();
- if(frame.isFunctionDeclarator()) // its a function pointer
- type = createFunctionType(type, frame.getNestedDeclarations());
-
- exprTypeStack.push(type);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- declarationStack.add(frame);
- }
- });
- }
-
-
- public void consumeDirectDeclaratorArrayModifier() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
- frame.addTypeModifier(new C99ArrayType());
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- frame.removeLastTypeModifier();
- }
- });
- }
-
-
- public void consumeAbstractDeclaratorArrayModifier() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
- frame.addTypeModifier(new C99ArrayType());
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- frame.removeLastTypeModifier();
- }
- });
- }
-
-
- public void consumeDirectDeclaratorModifiedArrayModifier(boolean isStatic, boolean isVarSized, boolean hasTypeQualifierList) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- C99ArrayType arrayType = new C99ArrayType();
- arrayType.setStatic(isStatic);
- arrayType.setVariableLength(isVarSized);
-
- if(hasTypeQualifierList) {
- arrayType.setConst(typeQualifiers.isConst);
- arrayType.setRestrict(typeQualifiers.isRestrict);
- arrayType.setVolatile(typeQualifiers.isVolatile);
- }
-
- final DeclaratorFrame frame = declarationStack.getLast();
- frame.addTypeModifier(arrayType);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- frame.removeLastTypeModifier();
- }
- });
- }
-
-
-
- public void consumePointer() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
- frame.addPointerModifier(new C99PointerType());
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- frame.removeLastPointerModifier();
- }
- });
- }
-
-
- public void consumePointerTypeQualifierList() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- C99PointerType pointerType = new C99PointerType();
- pointerType.setConst(typeQualifiers.isConst);
- pointerType.setRestrict(typeQualifiers.isRestrict);
- pointerType.setVolatile(typeQualifiers.isVolatile);
-
- final DeclaratorFrame frame = declarationStack.getLast();
- frame.addPointerModifier(pointerType);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- frame.removeLastPointerModifier();
- }
- });
- }
-
-
- public void consumeTypeQualifiers() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- typeQualifiers = new TypeQualifiers();
-
- for(IToken token : parser.getRuleTokens()) {
- switch(token.getKind()) {
- case C99Parsersym.TK_const:
- typeQualifiers.isConst = true;
- break;
- case C99Parsersym.TK_restrict:
- typeQualifiers.isRestrict = true;
- break;
- case C99Parsersym.TK_volatile:
- typeQualifiers.isVolatile = true;
- break;
- }
- }
-
- // I don't think this is really necessary but I need an undo action anyway
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- typeQualifiers = null;
- }
- });
- }
-
-
-
- /**
- * Works for structs, unions and enums.
- * If the struct tag is not in the symbol table then it is treated
- * as a declaration.
- */
- public IBinding consumeTypeSpecifierElaborated(int kind) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- String tag = parser.getRightIToken().toString();
-
- IC99Binding structBinding = symbolTable.lookup(STRUCT_TAG, tag);
-
- final C99SymbolTable undoTable;
-
- final boolean isDeclaration = (structBinding == null);
-
- if(isDeclaration) { // declaration of an incomplete type
- if(kind == IASTElaboratedTypeSpecifier.k_enum)
- structBinding = new C99Enumeration();
- else
- structBinding = new C99Structure(kind);
-
- undoTable = symbolTable;
- symbolTable = symbolTable.insert(STRUCT_TAG, tag, structBinding);
- }
- else {
- undoTable = null; // final variable must be initialized
- }
-
- final DeclSpec declSpec = declarationStack.getLast().getDeclSpec();
- declSpec.setType((IType)structBinding); // upcast
-
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- declSpec.setType(null);
-
- if(isDeclaration) {
- assert undoTable != null;
- symbolTable = undoTable;
- }
- }
- });
-
- return structBinding;
- }
-
-
- /**
- * @param key A field in IASTCompositeTypeSpecifier.
- */
- public IBinding consumeTypeSpecifierComposite(final boolean hasName, int key) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- // If the symbol table isn't updated then its still ok to undo
- // because setting symbolTable to oldTable will effectively be a no-op.
- final C99SymbolTable oldTable = symbolTable;
-
- C99Structure struct;
- if(hasName) {
- String ident = parser.getRuleTokens().get(1).toString();
- struct = (C99Structure) symbolTable.lookup(STRUCT_TAG, ident); // structure may have already been declared
- if(struct == null) {
- struct = new C99Structure(ident, key);
- symbolTable = symbolTable.insert(STRUCT_TAG, ident, struct);
- }
- }
- else {
- struct = new C99Structure(key);
- }
-
- final DeclaratorFrame frame = declarationStack.getLast();
- for(IBinding binding : frame.getNestedDeclarations()) {
- // the parser may allow invalid declarations like typedefs inside of structures, ignore those
- if(binding instanceof C99Field) {
- C99Field field = (C99Field)binding;
- struct.addField(field);
- field.setCompositeTypeOwner(struct);
- }
- }
-
- frame.getDeclSpec().setType(struct);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- frame.getDeclSpec().setType(null);
- symbolTable = oldTable;
- }
- });
-
- return struct;
- }
-
-
- public IBinding consumeTypeSpecifierEnumeration(final boolean hasName) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- C99Enumeration enumeration = new C99Enumeration();
-
- final C99SymbolTable oldTable = symbolTable;
- if(hasName) {
- String ident = parser.getRuleTokens().get(1).toString();
- enumeration.setName(ident);
- symbolTable = symbolTable.insert(STRUCT_TAG, ident, enumeration);
- }
-
- final DeclaratorFrame frame = declarationStack.getLast();
- for(IBinding binding : frame.getNestedDeclarations()) {
- C99Enumerator enumerator = (C99Enumerator)binding;
- enumeration.addEnumerator(enumerator);
- enumerator.setType(enumeration);
- }
-
- frame.getDeclSpec().setType(enumeration);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- frame.getDeclSpec().setType(null);
- if(hasName)
- symbolTable = oldTable;
- }
- });
-
- return enumeration;
- }
-
-
-
- public IBinding consumeEnumerator() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- IToken token = parser.getLeftIToken();
- String ident = token.toString();
- C99Enumerator enumerator = new C99Enumerator(ident);
-
- final C99SymbolTable oldTable = symbolTable;
- symbolTable = symbolTable.insert(IDENTIFIER, ident, enumerator);
-
- // enumerators are not declarations in the standard sense, so a scope won't be opened for them
- declarationStack.getLast().addNestedDeclaration(enumerator);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- declarationStack.getLast().removeLastNestedDeclaration();
- symbolTable = oldTable;
- }
- });
-
- return enumerator;
- }
-
-
-
- public IField consumeDesignatorBaseField() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
-
- IType baseType = getInitializerType();
- String fieldName = parser.getRightIToken().toString();
-
- C99Field fieldBinding = computeFieldBinding(baseType, fieldName, false);
- IType type = fieldBinding == null ? C99ProblemBinding.badType() : fieldBinding.getType();
-
- exprTypeStack.push(type);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- }
- });
-
- return fieldBinding;
- }
-
-
-
- private IType getInitializerType() {
- List<IType> outerScope = exprTypeStack.outerScope();
- return outerScope.get(outerScope.size()-1);
- }
-
-
- public void consumeDesignatorBaseArray() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- IType baseType = getInitializerType();
-
- IType type = C99ProblemBinding.badType();
- if(baseType instanceof C99ArrayType) {
- type = ((C99ArrayType)baseType).getType();
- }
-
- exprTypeStack.push(type);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- }
- });
- }
-
- public void consumeInitializerStartPositional() {
- if(DEBUG) DebugUtil.printMethodTrace();
- DebugUtil.printMethodTrace();
-
- IType type = getInitializerType();
- type = rawType(type);
-
- IType positionType;
- if(type instanceof C99Structure) {
- int position = exprTypeStack.topScope().size();
- C99Field field = (C99Field)((C99Structure)type).getFields()[position];
- positionType = field.getType();
- }
- else if(type instanceof IArrayType) {
- positionType = ((C99ArrayType)type).getType();
- }
- else {
- positionType = C99ProblemBinding.badType();
- }
-
- exprTypeStack.push(positionType);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- }
- });
- }
-
-
- private static C99FunctionType createFunctionType(IType returnType, List<IBinding> parameterDeclarations) {
- C99FunctionType functionType = new C99FunctionType();
- functionType.setReturnType(returnType);
- for(IBinding b : parameterDeclarations) {
- C99Variable parameter = (C99Variable) b;
- functionType.addParameterType(parameter.getType());
- }
- return functionType;
- }
-
-
-
- // helper functions for creating binding objects
-
- private static C99Function createFunctionBinding(String ident, IFunctionType type, DeclSpec declSpec) {
- C99Function func = new C99Function(ident == null ? NO_IDENT : ident, type);
- declSpec.modifyBinding(func);
- return func;
- }
-
- private static C99Function createFunctionBinding(String ident, IFunctionType type, DeclSpec declSpec, List<IBinding> params) {
- C99Function func = createFunctionBinding(ident, type, declSpec);
- for(IBinding b : params) {
- func.addParameter((IParameter)b);
- }
- return func;
- }
-
- private static C99Field createFieldBinding(String ident, IType type, DeclSpec declSpec) {
- C99Field var = new C99Field(ident == null ? NO_IDENT : ident);
- var.setType(type);
- declSpec.modifyBinding(var);
- return var;
- }
-
- private static C99Parameter createParameterBinding(String ident, IType type, DeclSpec declSpec) {
- C99Parameter param = new C99Parameter(ident == null ? NO_IDENT : ident);
- param.setType(type);
- declSpec.modifyBinding(param);
- return param;
- }
-
- private static C99Variable createVariableBinding(String ident, IType type, DeclSpec declSpec) {
- C99Variable var = new C99Variable(ident == null ? NO_IDENT : ident);
- var.setType(type);
- declSpec.modifyBinding(var);
- return var;
- }
-
- private static C99Typedef createTypedefBinding(String ident, IType type) {
- return new C99Typedef(type, ident == null ? NO_IDENT : ident);
- }
-
-
-
- public void openTypeScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- exprTypeStack.openScope();
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.closeScope();
- }
- });
- }
-
-
- @SuppressWarnings("nls")
- public void consumeExpressionConstant(int kind) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- //super.consumeExpressionConstant(kind);
- // TODO: this is incomplete, what about double constants, int constants with long suffix etc
- String constant = parser.getRightIToken().toString();
-
- IType type = null;
- switch(kind) {
- case IASTLiteralExpression.lk_char_constant:
- if(constant.startsWith("L")) {//unsigned short int
- C99BasicType charType = new C99BasicType(IBasicType.t_int);
- charType.setShort(true);
- charType.setUnsigned(true);
- type = charType;
- }
- else
- type = new C99BasicType(IBasicType.t_char);
- break;
-
- case IASTLiteralExpression.lk_float_constant:
- C99BasicType floatType;
- if(constant.contains("f") || constant.contains("F"))
- floatType = new C99BasicType(IBasicType.t_float);
- else
- floatType = new C99BasicType(IBasicType.t_double);
-
- if(constant.contains("l") || constant.contains("L"))
- floatType.setLong(true);
-
- type = floatType;
- break;
-
- case IASTLiteralExpression.lk_integer_constant:
- C99BasicType intType = new C99BasicType(IBasicType.t_int);
- if(constant.contains("l") || constant.contains("L"))
- intType.setLong(true);
-
- if(constant.contains("ll") || constant.contains("LL")) {
- intType.setLongLong(true);
- intType.setLong(false);
- }
- if(constant.contains("u") || constant.contains("U"))
- intType.setUnsigned(true);
-
- type = intType;
- break;
-
- case IASTLiteralExpression.lk_string_literal:
- type = new C99PointerType(new C99BasicType(IBasicType.t_char));
- break;
-
- default:
- assert false : "can't get here"; //$NON-NLS-1$
- }
-
- exprTypeStack.push(type);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- }
- });
- }
-
-
- public IBinding consumeExpressionID() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- IToken token = parser.getRightIToken();
- String ident = token.toString();
- IBinding binding = symbolTable.lookup(IDENTIFIER, ident);
-
- IType type = C99ProblemBinding.badType();
- if(binding instanceof ITypeable)
- type = ((ITypeable)binding).getType();
-
- exprTypeStack.push(type);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- }
- });
-
- return binding;
- }
-
-
- public IField consumeExpressionFieldReference(boolean isPointerDereference) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- String memberName = parser.getRightIToken().toString();
- final IType identType = exprTypeStack.pop();
-
- C99Field field = computeFieldBinding(identType, memberName, isPointerDereference);
- IType resultType = field == null ? C99ProblemBinding.badType() : field.getType();
-
- exprTypeStack.push(resultType);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- exprTypeStack.push(identType);
- }
- });
-
- return field;
- }
-
- /**
- * Computes the type of a field member access in an expression.
- * eg) x.a; computes the type of a
- */
- private C99Field computeFieldBinding(IType identType, String memberName, boolean isPointerDereference) {
- try {
- IType type = identType;
- if(isPointerDereference) {
- if(type instanceof IPointerType)
- type = ((ITypeContainer)type).getType(); // do the dereference
- else
- return null;
- }
-
- type = rawType(type);
- if(type instanceof ICompositeType) {
- ICompositeType struct = (ICompositeType) type;
- return (C99Field) struct.findField(memberName);
- }
- } catch(DOMException _) {}
-
- return null;
- }
-
-
- // TODO In C a function name can be used without parenthesis, the result is the address of
- // the function (which is an int I think). This means an identifier that happens to be
- // a function name should probably evaluate to an int, and then if it subsequently gets parsed
- // as a function call we can look up its function type from the symbol table.
- public void consumeExpressionFunctionCall(final boolean hasArgs) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final List<IType> scope = hasArgs ? exprTypeStack.closeScope() : null;
- final IType identifierType = exprTypeStack.pop();
-
- IType resultType = C99ProblemBinding.badType();
-
- if(identifierType instanceof IFunctionType) {
- // TODO: check the parameter types
- IFunctionType functionType = (IFunctionType)identifierType;
- try {
- resultType = functionType.getReturnType();
- } catch (DOMException e) { } // do nothing, the problem binding is fine
- }
-
- exprTypeStack.push(resultType);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- exprTypeStack.push(identifierType);
- if(hasArgs)
- exprTypeStack.openScope(scope);
- }
- });
- }
-
-
- public void consumeExpressionArraySubscript() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- // Not doing type checking so it doesn't matter that this is integral type
- final IType subscriptType = exprTypeStack.pop();
- final IType exprType = exprTypeStack.pop();
-
- IType resultType = C99ProblemBinding.badType();
- if(exprType instanceof IArrayType) {
- IArrayType arrType = (IArrayType) exprType;
- try {
- resultType = arrType.getType(); // strip off the array type
- } catch (DOMException e) { }
- }
-
- exprTypeStack.push(resultType);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- exprTypeStack.push(exprType);
- exprTypeStack.push(subscriptType);
- }
- });
- }
-
-
- public void consumeExpressionUnaryOperator() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- // TODO: this is lazy, need to check the actual rules for types and operators
- final IType expressionType = exprTypeStack.pop();
-
- IType resultType = new C99BasicType(IBasicType.t_int);
- exprTypeStack.push(resultType);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- exprTypeStack.push(expressionType);
- }
- });
- }
-
-
- public void consumeExpressionUnarySizeofTypeName() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final IType typeNameType = exprTypeStack.pop();
-
- IType resultType = new C99BasicType(IBasicType.t_int);
- exprTypeStack.push(resultType);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- exprTypeStack.push(typeNameType);
- }
- });
- }
-
-
- public void consumeExpressionCast() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final IType exprType = exprTypeStack.pop();
-
- // pop then push is no-op
- //IType castType = exprTypeStack.pop();
- //exprTypeStack.push(castType);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.push(exprType);
- }
- });
- }
-
-
- public void consumeExpressionTypeIdInitializer() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- // Throw away the types of the initializer list
- final List<IType> scope = exprTypeStack.closeScope();
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.openScope(scope);
- }
- });
- }
-
- public void consumeExpressionInitializer() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final IType type = exprTypeStack.pop();
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- exprTypeStack.push(type);
- }
- });
- }
-
-
- public void consumeExpressionBinaryOperator(int op) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final IType op2type = exprTypeStack.pop();
- final IType op1type = exprTypeStack.pop();
-
- switch(op) {
- case IASTBinaryExpression.op_assign:
- case IASTBinaryExpression.op_multiplyAssign:
- case IASTBinaryExpression.op_divideAssign:
- case IASTBinaryExpression.op_moduloAssign:
- case IASTBinaryExpression.op_plusAssign:
- case IASTBinaryExpression.op_minusAssign:
- case IASTBinaryExpression.op_shiftLeftAssign:
- case IASTBinaryExpression.op_shiftRightAssign:
- case IASTBinaryExpression.op_binaryAndAssign:
- case IASTBinaryExpression.op_binaryXorAssign:
- case IASTBinaryExpression.op_binaryOrAssign:
- exprTypeStack.push(op1type);
- break;
-
- default:
- IType resultType = new C99BasicType(IBasicType.t_int);
- exprTypeStack.push(resultType);
- }
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- exprTypeStack.pop();
- exprTypeStack.push(op1type);
- exprTypeStack.push(op2type);
- }
- });
- }
-
- public void consumeExpressionConditional() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final IType expr2Type = exprTypeStack.pop();
- final IType expr1Type = exprTypeStack.pop();
- final IType condType = exprTypeStack.pop();
- exprTypeStack.push(expr1Type);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- exprTypeStack.pop();
- exprTypeStack.push(condType);
- exprTypeStack.push(expr1Type);
- exprTypeStack.push(expr2Type);
- }
- });
- }
-
-// // TODO: expression lists are changing
-// public void consumeExpressionList(boolean baseCase) {
-// // This is a hack, the type of an expression
-// // list will be the first expression in the list.
-// if(!baseCase) {
-// exprTypeStack.pop();
-// }
-// }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/C99TypedefTrackerParserAction.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/C99TypedefTrackerParserAction.java
deleted file mode 100644
index 7667e1d80d..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/C99TypedefTrackerParserAction.java
+++ /dev/null
@@ -1,355 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.action.deprecated;
-
-import java.util.LinkedList;
-
-import lpg.lpgjavaruntime.IToken;
-
-import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
-import org.eclipse.cdt.core.parser.util.DebugUtil;
-import org.eclipse.cdt.internal.core.dom.lrparser.symboltable.TypedefSymbolTable;
-/**
- * A simple set of trial and undo actions that just keep track
- * of typedef names. This information is then fed back to the parser
- * in order to disambiguate certain parser grammar rules.
- *
- * The command design pattern is used to implement undo actions.
- *
- * @author Mike Kucera
- */
-public class C99TypedefTrackerParserAction {
-
- private static final boolean DEBUG = true;
-
-
- // provides limited access to the token stream
- private final IParserActionTokenProvider parser;
-
- // The symbolTable currently in use
- private TypedefSymbolTable symbolTable = TypedefSymbolTable.EMPTY_TABLE;
-
- // A stack that keeps track of scopes in the symbol table, used to "close" scopes and to undo the opening of scopes
- private final LinkedList<TypedefSymbolTable> symbolTableScopeStack = new LinkedList<TypedefSymbolTable>();
-
- // keeps track of nested declarations
- private final LinkedList<DeclaratorFrame> declarationStack = new LinkedList<DeclaratorFrame>();
-
-
- // "For every action there is an equal and opposite reaction." - Newton's third law
- private final LinkedList<IUndoAction> undoStack = new LinkedList<IUndoAction>();
-
-
- /**
- * A command object that provides undo functionality.
- */
- private interface IUndoAction {
- void undo();
- }
-
-
- /**
- * Undoes the last fired action.
- */
- public void undo() {
- undoStack.removeLast().undo();
- }
-
-
- public C99TypedefTrackerParserAction(IParserActionTokenProvider parser) {
- this.parser = parser;
- }
-
-
- /**
- * Lexer feedback hack, used by the parser to identify typedefname tokens.
- */
- public boolean isTypedef(String ident) {
- return symbolTable.contains(ident);
- }
-
-
- /**
- * Methods used by tests, package local access.
- */
- TypedefSymbolTable getSymbolTable() {
- return symbolTable;
- }
-
- int undoStackSize() {
- return undoStack.size();
- }
-
- LinkedList<DeclaratorFrame> getDeclarationStack() {
- return declarationStack;
- }
-
-
- /**
- * Called from the grammar file in places where a scope is created.
- *
- * Scopes are created by compound statements, however special care
- * must also be taken with for loops because they may contain
- * declarations.
- *
- * TODO: scope object now need to be handled explicitly
- */
- public void openSymbolScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- symbolTableScopeStack.add(symbolTable);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- symbolTable = symbolTableScopeStack.removeLast();
- }
- });
- }
-
-
- public void closeSymbolScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final TypedefSymbolTable undoTable = symbolTable;
- symbolTable = symbolTableScopeStack.removeLast(); // close the scope
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- symbolTableScopeStack.add(symbolTable);
- symbolTable = undoTable;
- }
- });
- }
-
-
-
- /**
- * Called from the grammar before a declaration is about to be reduced.
- */
- public void openDeclarationScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declarationStack.add(new DeclaratorFrame());
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declarationStack.removeLast();
- }
- });
- }
-
-
- public void closeDeclarationScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame undoFrame = declarationStack.removeLast();
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declarationStack.add(undoFrame);
- }
- });
- }
-
-
- public void consumeFunctionDefinition() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.removeLast();
-
- final TypedefSymbolTable undoTable = symbolTable;
- symbolTable = symbolTableScopeStack.removeLast();
-
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- symbolTableScopeStack.add(symbolTable);
- symbolTable = undoTable;
-
- declarationStack.add(frame);
- }
- });
- }
-
-
-
-
- public void consumeDeclSpecToken() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- IToken token = parser.getRightIToken();
- final int kind = token.getKind();
-
- // creates a DeclSpec if there isn't one already
- DeclaratorFrame frame = declarationStack.getLast();
- final DeclSpec declSpec = frame.getDeclSpec();
- declSpec.add(kind);
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declSpec.remove(kind);
- }
- });
- }
-
-
-
- public void consumeDirectDeclaratorIdentifier() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
- frame.setDeclaratorName(parser.getRightIToken());
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- frame.setDeclaratorName(null);
- }
- });
- }
-
-
- public void consumeDeclaratorComplete() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.getLast();
-
- IToken token = frame.getDeclaratorName();
- DeclSpec declSpec = frame.getDeclSpec();
-
- String ident = (token == null) ? null : token.toString();
- //System.out.println("declarator complete: " + ident);
-
- final TypedefSymbolTable oldTable = symbolTable;
- if(declSpec.isTypedef()) {
- //System.out.println("adding typedef: " + ident);
- symbolTable = symbolTable.add(ident);
- }
-
- declarationStack.removeLast();
- declarationStack.add(new DeclaratorFrame(frame.getDeclSpec())); // reset the declarator
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declarationStack.removeLast();
- declarationStack.add(frame);
- symbolTable = oldTable;
- }
- });
- }
-
-
-
-
- public void consumeDeclaratorCompleteParameter() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.removeLast();
-
- //declarationStack.getLast().addNestedDeclaration(parameterBinding);
-
- // parameter declarations can only have one declarator, so don't reset
- //declarationStack.add(new DeclaratorFrame()); // reset
-
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- //declarationStack.removeLast();
- //declarationStack.getLast().removeLastNestedDeclaration();
- declarationStack.add(frame);
- }
- });
- }
-
-
- /**
- * This is a special case for the rule:
- * parameter_declaration ::= declaration_specifiers
- *
- * In this case there is no declarator at all
- *
- * TODO: creating bindings that have no identifier seems really dumb,
- * why does it need to be done? Why not just have a null binding or
- * for that matter don't even have a name node
- *
- */
- public void consumeParameterDeclarationWithoutDeclarator() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.removeLast();
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declarationStack.add(frame);
- }
- });
- }
-
-
- public void consumeDeclaratorCompleteField() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.removeLast();
-
- declarationStack.add(new DeclaratorFrame(frame.getDeclSpec())); // reset the declarator
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declarationStack.removeLast();
-
- declarationStack.add(frame);
- }
- });
- }
-
-
- /**
- * An abstract declarator used as part of an expression, eg) a cast.
- * Only need the type.
- *
- * TODO: this isn't enough, I need a binding for the abstract declarator
- * what I really need is a consumeDeclaratorCompleteTypeId similar to above
- */
- public void consumeTypeId() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- final DeclaratorFrame frame = declarationStack.removeLast();
-
- undoStack.add(new IUndoAction() {
- public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
- declarationStack.add(frame);
- }
- });
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/DeclSpec.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/DeclSpec.java
deleted file mode 100644
index a7930076d4..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/DeclSpec.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.action.deprecated;
-
-import static org.eclipse.cdt.internal.core.dom.lrparser.c99.C99Parsersym.*;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.cdt.core.dom.ast.IBasicType;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.C99Parsersym;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99BasicType;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Function;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99QualifierType;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Variable;
-
-/**
- * Keeps track of declaration specifiers during the parse.
- * Used to compute types and determine if a declarator is a typedef.
- *
- * @author Mike Kucera
- */
-class DeclSpec {
-
- // maps token kinds to the number of occurrences of that kind
- private Map<Integer,Integer> tokenKindMap = new HashMap<Integer,Integer>();
-
- private IType type = null;
-
-
- public void add(int kind) {
- tokenKindMap.put(kind, count(kind) + 1);
- }
-
- public void remove(final int kind) {
- Integer count = tokenKindMap.get(kind);
- if(count == null)
- return;
-
- if(count <= 1)
- tokenKindMap.remove(kind);
- else
- tokenKindMap.put(kind, count - 1);
- }
-
- public boolean contains(int kind) {
- return tokenKindMap.containsKey(kind);
- }
-
-
- public boolean isTypedef() {
- return contains(C99Parsersym.TK_typedef);
- }
-
- /**
- * Need to keep track of how many times a particular
- * declaration specifier appears in order to support
- * long long.
- */
- public int count(int kind) {
- Integer count = tokenKindMap.get(kind);
- return count == null ? 0 : count;
- }
-
- /**
- * Set if the type should be a structure.
- */
- public void setType(IType type) {
- this.type = type;
- }
-
-
-
- public IType getType() {
- if(type != null)
- return type;
- if(tokenKindMap.isEmpty()) // there are no type tokens, so it must be implicit int
- return new C99BasicType(IBasicType.t_int);
-
- C99BasicType basicType = new C99BasicType();
-
- for(int kind : tokenKindMap.keySet()) {
- switch(kind) {
- case TK_void:
- basicType.setType(IBasicType.t_void);
- break;
- case TK_char:
- basicType.setType(IBasicType.t_char);
- break;
- case TK_int:
- basicType.setType(IBasicType.t_int);
- break;
- case TK_float:
- basicType.setType(IBasicType.t_float);
- break;
- case TK_double:
- basicType.setType(IBasicType.t_double);
- break;
- case TK_long:
- boolean isLongLong = count(TK_long) > 1;
- basicType.setLongLong(isLongLong);
- basicType.setLong(!isLongLong);
- break;
- case TK_signed:
- basicType.setSigned(true);
- break;
- case TK_unsigned:
- basicType.setUnsigned(true);
- break;
- case TK_short:
- basicType.setShort(true);
- break;
- case TK__Bool:
- basicType.setType(ICBasicType.t_Bool);
- break;
- case TK__Complex:
- basicType.setComplex(true);
- break;
- case TK__Imaginary:
- basicType.setImaginary(true);
- break;
- }
- }
-
- boolean isConst = contains(TK_const);
- boolean isRestrict = contains(TK_restrict);
- boolean isVolatile = contains(TK_volatile);
-
- if(isConst || isRestrict || isVolatile)
- return new C99QualifierType(basicType, isConst, isVolatile, isRestrict);
- return basicType;
- }
-
-
- public void modifyBinding(C99Variable var) {
- if(!var.isAuto())
- var.setAuto(contains(TK_auto));
- if(!var.isExtern())
- var.setExtern(contains(TK_extern));
- if(!var.isRegister())
- var.setRegister(contains(TK_register));
- if(!var.isStatic())
- var.setStatic(contains(TK_static));
- }
-
- public void modifyBinding(C99Function function) {
- if(!function.isAuto())
- function.setAuto(contains(TK_auto));
- if(!function.isExtern())
- function.setExtern(contains(TK_extern));
- if(!function.isInline())
- function.setInline(contains(TK_inline));
- if(!function.isRegister())
- function.setRegister(contains(TK_register));
- if(!function.isStatic())
- function.setStatic(contains(TK_static));
- }
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/DeclaratorFrame.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/DeclaratorFrame.java
deleted file mode 100644
index 9adc96c9b5..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/DeclaratorFrame.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.action.deprecated;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import lpg.lpgjavaruntime.IToken;
-
-import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99PointerType;
-import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
-
-/**
- * Represents a frame on the declaration stack used by the resolver actions.
- *
- * TODO: document this class better
- *
- * @author Mike Kucera
- */
-@SuppressWarnings("restriction")
-public class DeclaratorFrame {
- private DeclSpec declSpec;
- //IBinding declarator;
- private IToken declaratorName;
- private boolean isDeclaratorBracketed;
- private boolean isFunctionDeclarator = false;
-
- // temporary storage for pointer modifiers
- private LinkedList<LinkedList<C99PointerType>> pointerModifiers = new LinkedList<LinkedList<C99PointerType>>();
-
- // stores pointer and array modifiers that are applied to the declarator
- private LinkedList<ITypeContainer> typeModifiers = new LinkedList<ITypeContainer>();
-
- private LinkedList<IBinding> nestedDeclarations = new LinkedList<IBinding>();
-
-
- public DeclaratorFrame() {
- }
-
- public DeclaratorFrame(DeclSpec declSpec) {
- this.declSpec = declSpec;
- }
-
-
- public DeclSpec getDeclSpec() {
- if(declSpec == null)
- declSpec = new DeclSpec();
-
- return declSpec;
- }
-
- public IType getDeclaratorType() {
- // the declSpec may be null, so use getDeclSpec()
- IType baseType = getDeclSpec().getType();
-
- if(typeModifiers.isEmpty())
- return baseType;
-
- IType type = typeModifiers.get(0);
-
- // link the types together
- for(int i = 1; i < typeModifiers.size(); i++) {
- ITypeContainer t1 = typeModifiers.get(i-1);
- ITypeContainer t2 = typeModifiers.get(i);
- t1.setType(t2);
- }
-
- ITypeContainer last = typeModifiers.get(typeModifiers.size()-1);
- last.setType(baseType);
- return type;
- }
-
- public IToken getDeclaratorName() {
- return declaratorName;
- }
- public void setDeclaratorName(IToken declaratorName) {
- this.declaratorName = declaratorName;
- }
- public boolean isDeclaratorBracketed() {
- return isDeclaratorBracketed;
- }
- public void setDeclaratorBracketed(boolean isDeclaratorBracketed) {
- this.isDeclaratorBracketed = isDeclaratorBracketed;
- }
- public boolean isFunctionDeclarator() {
- return isFunctionDeclarator;
- }
- public void setFunctionDeclarator(boolean isFunctionDeclarator) {
- this.isFunctionDeclarator = isFunctionDeclarator;
- }
-
- public List<IBinding> getNestedDeclarations() {
- return nestedDeclarations;
- }
-
- public void addNestedDeclaration(IBinding binding) {
- nestedDeclarations.add(binding);
- }
-
- public void removeLastNestedDeclaration() {
- nestedDeclarations.removeLast();
- }
-
- public void addTypeModifier(ITypeContainer x) {
- typeModifiers.add(x);
- }
-
- public void removeLastTypeModifier() {
- typeModifiers.removeLast();
- }
-
- public void addPointerModifier(C99PointerType x) {
- pointerModifiers.getLast().add(x);
- }
-
- public void removeLastPointerModifier() {
- pointerModifiers.getLast().removeLast();
- }
-
- public void openPointerModifierScope() {
- pointerModifiers.add(new LinkedList<C99PointerType>());
- }
-
- public void openPointerModifierScope(LinkedList<C99PointerType> scope) {
- pointerModifiers.add(scope);
- }
-
- public LinkedList<C99PointerType> closePointerModifierScope() {
- return pointerModifiers.removeLast();
- }
-}
-
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ArrayType.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ArrayType.java
deleted file mode 100644
index 3c593f31df..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ArrayType.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IASTExpression;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.ITypedef;
-import org.eclipse.cdt.core.dom.ast.c.ICArrayType;
-import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
-
-@SuppressWarnings("restriction")
-public class C99ArrayType implements ICArrayType, ITypeContainer {
-
- private boolean isConst;
- private boolean isRestrict;
- private boolean isStatic;
- private boolean isVolatile;
- private boolean isVariableLength;
-
- private IType type;
-
-
- public C99ArrayType() {
- }
-
- public C99ArrayType(IType type) {
- this.type = type;
- }
-
- public boolean isConst() {
- return isConst;
- }
-
- public void setConst(boolean isConst) {
- this.isConst = isConst;
- }
-
- public boolean isRestrict() {
- return isRestrict;
- }
-
- public void setRestrict(boolean isRestrict) {
- this.isRestrict = isRestrict;
- }
-
- public boolean isStatic() {
- return isStatic;
- }
-
- public void setStatic(boolean isStatic) {
- this.isStatic = isStatic;
- }
-
- public boolean isVolatile() {
- return isVolatile;
- }
-
- public void setVolatile(boolean isVolatile) {
- this.isVolatile = isVolatile;
- }
-
- public boolean isVariableLength() {
- return isVariableLength;
- }
-
- public void setVariableLength(boolean isVariableLength) {
- this.isVariableLength = isVariableLength;
- }
-
- public IASTExpression getArraySizeExpression() throws DOMException {
- return null;
- }
-
- public IType getType() {
- return type;
- }
-
- public void setType(IType type) {
- this.type = type;
- }
-
- public boolean isSameType(IType t) {
- if(t == this)
- return true;
- if(t instanceof ITypedef)
- return t.isSameType(this);
- if(t instanceof ICArrayType) {
- ICArrayType at = (ICArrayType)t;
- try {
- if(at.isConst() == isConst &&
- at.isRestrict() == isRestrict &&
- at.isStatic() == isStatic &&
- at.isVolatile() == isVolatile &&
- at.isVariableLength() == isVariableLength) {
- return at.isSameType(type);
- }
- } catch(DOMException _) { }
- }
- return false;
- }
-
-
- @Override
- public C99ArrayType clone() {
- C99ArrayType clone = null;
- try {
- clone = (C99ArrayType) super.clone();
- clone.type = (IType) type.clone();
- } catch (CloneNotSupportedException e) {
- assert false; // not going to happen
- }
- return clone;
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99BasicType.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99BasicType.java
deleted file mode 100644
index cf7cec8c0e..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99BasicType.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ast.IASTExpression;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
-
-public class C99BasicType implements ICBasicType {
-
- /* Type flags given in IBasicType */
- private int type;
-
- private boolean isLong;
- private boolean isShort;
- private boolean isSigned;
- private boolean isUnsigned;
- private boolean isComplex;
- private boolean isImaginary;
- private boolean isLongLong;
-
-
- public C99BasicType() {
- }
-
- public C99BasicType(int type) {
- this.type = type;
- }
-
- public int getType() {
- return type;
- }
-
- public void setType(int type) {
- this.type = type;
- }
-
- public boolean isLong() {
- return isLong;
- }
-
- public void setLong(boolean isLong) {
- this.isLong = isLong;
- }
-
- public boolean isShort() {
- return isShort;
- }
-
- public void setShort(boolean isShort) {
- this.isShort = isShort;
- }
-
- public boolean isSigned() {
- return isSigned;
- }
-
- public void setSigned(boolean isSigned) {
- this.isSigned = isSigned;
- }
-
- public boolean isUnsigned() {
- return isUnsigned;
- }
-
- public void setUnsigned(boolean isUnsigned) {
- this.isUnsigned = isUnsigned;
- }
-
- public boolean isComplex() {
- return isComplex;
- }
-
- public void setComplex(boolean isComplex) {
- this.isComplex = isComplex;
- }
-
- public boolean isImaginary() {
- return isImaginary;
- }
-
- public void setImaginary(boolean isImaginary) {
- this.isImaginary = isImaginary;
- }
-
- public boolean isLongLong() {
- return isLongLong;
- }
-
- public void setLongLong(boolean isLongLong) {
- this.isLongLong = isLongLong;
- }
-
- public IASTExpression getValue() {
- return null;
- }
-
- public boolean isSameType(IType t) {
- if(t == this)
- return true;
- if(!(t instanceof C99BasicType))
- return false;
-
- C99BasicType bt = (C99BasicType) t;
- return bt.type == this.type &&
- bt.isLong == this.isLong &&
- bt.isShort == this.isShort &&
- bt.isSigned == this.isSigned &&
- bt.isUnsigned == this.isUnsigned &&
- bt.isComplex == this.isComplex &&
- bt.isImaginary == this.isImaginary &&
- bt.isLongLong == this.isLongLong;
- }
-
- @Override
- public C99BasicType clone() {
- try {
- return (C99BasicType) super.clone();
- } catch (CloneNotSupportedException e) {
- assert false;
- return null;
- }
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99CompositeTypeScope.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99CompositeTypeScope.java
deleted file mode 100644
index 50a1059c45..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99CompositeTypeScope.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.ICompositeType;
-import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
-
-public class C99CompositeTypeScope extends C99Scope implements ICCompositeTypeScope {
-
-
- private ICompositeType struct;
-
-
- public C99CompositeTypeScope(ICompositeType struct) {
- this.struct = struct;
- }
-
- public ICompositeType getCompositeType() {
- return struct;
- }
-
- public IBinding getBinding(@SuppressWarnings("unused") char[] name) throws DOMException {
- throw new UnsupportedOperationException();
- }
-
-
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumeration.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumeration.java
deleted file mode 100644
index de7210b3a1..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumeration.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.ast.IEnumeration;
-import org.eclipse.cdt.core.dom.ast.IEnumerator;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.ITypedef;
-import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.core.runtime.PlatformObject;
-
-@SuppressWarnings("restriction")
-public class C99Enumeration extends PlatformObject implements IC99Binding, IEnumeration, ITypeable {
-
- private List<IEnumerator> enumerators = new ArrayList<IEnumerator>();
- private String name;
-
- private IScope scope;
-
-
- public C99Enumeration() {
- }
-
- public C99Enumeration(String name) {
- this.name = name;
- }
-
- public void addEnumerator(IEnumerator e) {
- enumerators.add(e);
- }
-
- public IEnumerator[] getEnumerators() {
- return enumerators.toArray(new IEnumerator[enumerators.size()]);
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public char[] getNameCharArray() {
- return name.toCharArray();
- }
-
-
- public IType getType() {
- return this;
- }
-
- public boolean isSameType(IType type) {
- if( type == this )
- return true;
- if( type instanceof ITypedef)
- return type.isSameType( this );
-
- return false;
- }
-
- @Override
- public C99Enumeration clone() {
- try {
- C99Enumeration clone = (C99Enumeration) super.clone();
- clone.enumerators = new ArrayList<IEnumerator>();
- for(IEnumerator e : enumerators) {
- // TODO this is wrong,
- // IEnumerator is not Cloneable so we are not returning a deep copy here
- clone.addEnumerator(e);
- }
- return clone;
- } catch (CloneNotSupportedException e1) {
- assert false;
- return null;
- }
-
- }
-
- public ILinkage getLinkage() {
- return Linkage.C_LINKAGE;
- }
-
- public IScope getScope() {
- return scope;
- }
-
- public void setScope(IScope scope) {
- this.scope = scope;
- }
-
-
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java
deleted file mode 100644
index f0f3a8a2f5..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.ast.IEnumerator;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.core.runtime.PlatformObject;
-
-@SuppressWarnings("restriction")
-public class C99Enumerator extends PlatformObject implements IC99Binding, IEnumerator, ITypeable {
-
- private String name;
- private IType type;
- private IScope scope;
-
-
- public C99Enumerator() {
- }
-
- public C99Enumerator(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public IType getType() {
- return type;
- }
-
- public void setType(IType type) {
- this.type = type;
- }
-
- public ILinkage getLinkage() {
- return Linkage.C_LINKAGE;
- }
-
- public char[] getNameCharArray() {
- return name.toCharArray();
- }
-
- public IScope getScope() {
- return scope;
- }
-
- public void setScope(IScope scope) {
- this.scope = scope;
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Field.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Field.java
deleted file mode 100644
index 502aed0de4..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Field.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.ICompositeType;
-import org.eclipse.cdt.core.dom.ast.IField;
-import org.eclipse.cdt.core.dom.ast.IScope;
-
-public class C99Field extends C99Variable implements IC99Binding, IField, ITypeable {
-
- private ICompositeType compositeTypeOwner;
-
-
- public C99Field() {
- }
-
- public C99Field(String name) {
- super(name);
- }
-
- public ICompositeType getCompositeTypeOwner() {
- return compositeTypeOwner;
- }
-
- public void setCompositeTypeOwner(ICompositeType compositeTypeOwner) {
- this.compositeTypeOwner = compositeTypeOwner;
- }
-
- @Override
- public IScope getScope() {
- try {
- return compositeTypeOwner.getCompositeScope();
- } catch (DOMException e) {
- return null; // should never happen
- }
- }
-
-
-} \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java
deleted file mode 100644
index 0570ea5b5c..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.ast.IFunction;
-import org.eclipse.cdt.core.dom.ast.IFunctionType;
-import org.eclipse.cdt.core.dom.ast.IParameter;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.core.runtime.PlatformObject;
-
-@SuppressWarnings("restriction")
-public class C99Function extends PlatformObject implements IC99Binding, IFunction, ITypeable {
-
- private String name;
- private IFunctionType type;
- private List<IParameter> parameters = new ArrayList<IParameter>();
-
- private boolean isAuto;
- private boolean isExtern;
- private boolean isInline;
- private boolean isRegister;
- private boolean isStatic;
- private boolean isVarArgs;
-
- // the scope that the function is in (must be the global scope, no?)
- private IScope scope;
-
- // the scope that represents the body of the function
- private IScope bodyScope;
-
-
- public C99Function() {
- }
-
- public C99Function(String name) {
- this.name = name;
- }
-
- public C99Function(String name, IFunctionType type) {
- this(name);
- this.type = type;
- }
-
-
- public IParameter[] getParameters() {
- return parameters.toArray(new IParameter[parameters.size()]);
- }
-
- public void addParameter(IParameter parameter) {
- parameters.add(parameter);
- }
-
- public IFunctionType getType() {
- return type;
- }
-
- public void setType(IFunctionType type) {
- this.type = type;
- }
-
- public boolean isAuto() {
- return isAuto;
- }
-
- public void setAuto(boolean isAuto) {
- this.isAuto = isAuto;
- }
-
- public boolean isExtern() {
- return isExtern;
- }
-
- public void setExtern(boolean isExtern) {
- this.isExtern = isExtern;
- }
-
- public boolean isInline() {
- return isInline;
- }
-
- public void setInline(boolean isInline) {
- this.isInline = isInline;
- }
-
- public boolean isRegister() {
- return isRegister;
- }
-
- public void setRegister(boolean isRegister) {
- this.isRegister = isRegister;
- }
-
- public boolean isStatic() {
- return isStatic;
- }
-
- public void setStatic(boolean isStatic) {
- this.isStatic = isStatic;
- }
-
- public boolean takesVarArgs() {
- return isVarArgs;
- }
-
- public void setTakesVarArgs(boolean isVarArgs) {
- this.isVarArgs = isVarArgs;
- }
-
- public ILinkage getLinkage() {
- return Linkage.C_LINKAGE;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public char[] getNameCharArray() {
- return name.toCharArray();
- }
-
- public IScope getScope() {
- return scope;
- }
-
- public IScope getFunctionScope() {
- return bodyScope;
- }
-
- public void setFunctionScope(IScope bodyScope) {
- this.bodyScope = bodyScope;
- }
-
- public void setScope(IScope scope) {
- this.scope = scope;
- }
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionScope.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionScope.java
deleted file mode 100644
index ad32845f8c..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionScope.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
-
-public class C99FunctionScope extends C99Scope implements ICFunctionScope {
-
-
- /**
- * Scope that represents the compound statement of the body of this scope.
- * Does not include the parameters which are part of this function scope.
- */
- private IScope bodyScope;
-
-
- public IBinding getBinding(@SuppressWarnings("unused") char[] name) throws DOMException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void setBodyScope(IScope bodyScope) {
- this.bodyScope = bodyScope;
- }
-
- public IScope getBodyScope() throws DOMException {
- return bodyScope;
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionType.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionType.java
deleted file mode 100644
index dca26f8098..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionType.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.cdt.core.dom.ast.IFunctionType;
-import org.eclipse.cdt.core.dom.ast.IType;
-
-public class C99FunctionType implements IFunctionType {
-
- private IType returnType;
- private List<IType> parameterTypes = new ArrayList<IType>();
-
- public IType[] getParameterTypes() {
- return parameterTypes.toArray(new IType[parameterTypes.size()]);
- }
-
- public void addParameterType(IType parameterType) {
- parameterTypes.add(parameterType);
- }
-
- public IType getReturnType() {
- return returnType;
- }
-
- public void setReturnType(IType returnType) {
- this.returnType = returnType;
- }
-
- public boolean isSameType(@SuppressWarnings("unused") IType type) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public C99FunctionType clone() {
- try {
- C99FunctionType clone = (C99FunctionType) super.clone();
- clone.setReturnType((IType)returnType.clone());
- clone.parameterTypes = new ArrayList<IType>();
- for(IType parameterType : parameterTypes) {
- clone.addParameterType((IType)parameterType.clone());
- }
- return clone;
- } catch (CloneNotSupportedException e) {
- assert false;
- return null;
- }
-
- }
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Label.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Label.java
deleted file mode 100644
index 6182aab8df..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Label.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
-import org.eclipse.cdt.core.dom.ast.ILabel;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.core.runtime.PlatformObject;
-
-@SuppressWarnings("restriction")
-public class C99Label extends PlatformObject implements IC99Binding, ILabel {
-
- private String name;
- private IScope scope;
-
- public C99Label() {
- }
-
- public C99Label(String name) {
- this.name = name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public char[] getNameCharArray() {
- return name.toCharArray();
- }
-
-
-
- public IASTLabelStatement getLabelStatement() {
- return null;
- }
-
- public ILinkage getLinkage() {
- return Linkage.C_LINKAGE;
- }
-
- public IScope getScope() {
- return scope;
- }
-
- public void setScope(IScope scope) {
- this.scope = scope;
- }
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Parameter.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Parameter.java
deleted file mode 100644
index 31e8aa81a2..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Parameter.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ast.IParameter;
-
-public class C99Parameter extends C99Variable implements IParameter, ITypeable {
-
- public C99Parameter() {
- }
-
- public C99Parameter(String name) {
- super(name);
- }
-
- public static C99Parameter valueOf(C99Variable var) {
- C99Parameter param = new C99Parameter(var.getName());
- param.setType(var.getType());
- param.setAuto(var.isAuto());
- param.setExtern(var.isExtern());
- param.setRegister(var.isRegister());
- param.setStatic(var.isStatic());
- return param;
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99PointerType.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99PointerType.java
deleted file mode 100644
index 97fd92596f..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99PointerType.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.c.ICPointerType;
-import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
-
-
-@SuppressWarnings("restriction")
-public class C99PointerType implements ITypeContainer, ICPointerType {
-
-
- private IType type;
- private boolean isConst;
- private boolean isRestrict;
- private boolean isVolatile;
-
- public C99PointerType() {
- }
-
-
- public C99PointerType(IType type) {
- this.type = type;
- }
-
- public IType getType() {
- return type;
- }
-
- public void setType(IType type) {
- this.type = type;
- }
-
- public boolean isConst() {
- return isConst;
- }
-
- public void setConst(boolean isConst) {
- this.isConst = isConst;
- }
-
- public boolean isRestrict() {
- return isRestrict;
- }
-
- public void setRestrict(boolean isRestrict) {
- this.isRestrict = isRestrict;
- }
-
- public boolean isVolatile() {
- return isVolatile;
- }
-
- public void setVolatile(boolean isVolatile) {
- this.isVolatile = isVolatile;
- }
-
-
- public boolean isSameType(IType t) {
- if(t == this)
- return true;
-
- if (t instanceof ICPointerType) {
- try {
- ICPointerType pointerType = (ICPointerType) t;
- if(pointerType.isConst() == isConst &&
- pointerType.isRestrict() == isRestrict &&
- pointerType.isVolatile() == isVolatile) {
- return type.isSameType(pointerType.getType());
- }
- } catch(DOMException _) { }
- }
- return false;
- }
-
-
-
- @Override
- public C99PointerType clone() {
- try {
- C99PointerType clone = (C99PointerType) super.clone();
- clone.type = (IType) type.clone();
- return clone;
- } catch (CloneNotSupportedException e) {
- assert false;
- return null;
- }
-
- }
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ProblemBinding.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ProblemBinding.java
deleted file mode 100644
index 1e21f93acb..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ProblemBinding.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ast.IProblemBinding;
-import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
-
-@SuppressWarnings("restriction")
-public class C99ProblemBinding extends ProblemBinding implements IProblemBinding {
-
-
- public C99ProblemBinding(int messageId) {
- super(null, messageId, null);
- }
-
- public C99ProblemBinding(int messageId, String arg) {
- super(null, messageId, arg.toCharArray());
- }
-
- public static C99ProblemBinding badType() {
- return new C99ProblemBinding(IProblemBinding.SEMANTIC_INVALID_TYPE);
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99QualifierType.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99QualifierType.java
deleted file mode 100644
index f9454b0f1c..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99QualifierType.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.c.ICQualifierType;
-import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
-
-@SuppressWarnings("restriction")
-public class C99QualifierType implements ICQualifierType, ITypeContainer {
-
- private boolean isRestrict;
- private boolean isConst;
- private boolean isVolatile;
-
- private IType type;
-
-
- public C99QualifierType() {
- }
-
- public C99QualifierType(IType type) {
- this.type = type;
- }
-
- public C99QualifierType(IType type, boolean isConst, boolean isVolatile, boolean isRestrict) {
- this.isConst = isConst;
- this.isRestrict = isRestrict;
- this.isVolatile = isVolatile;
- this.type = type;
- }
-
- public boolean isRestrict() {
- return isRestrict;
- }
-
- public void setRestrict(boolean isRestrict) {
- this.isRestrict = isRestrict;
- }
-
- public boolean isConst() {
- return isConst;
- }
-
- public void setConst(boolean isConst) {
- this.isConst = isConst;
- }
-
- public boolean isVolatile() {
- return isVolatile;
- }
-
- public void setVolatile(boolean isVolatile) {
- this.isVolatile = isVolatile;
- }
-
- public IType getType() {
- return type;
- }
-
- public void setType(IType type) {
- this.type = type;
- }
-
- public boolean isSameType(IType t) {
- if(t == this)
- return true;
-
- if (t instanceof ICQualifierType) {
- try {
- ICQualifierType pointerType = (ICQualifierType) t;
- if(pointerType.isConst() == isConst &&
- pointerType.isRestrict() == isRestrict &&
- pointerType.isVolatile() == isVolatile) {
- return type.isSameType(pointerType.getType());
- }
- } catch(DOMException _) { }
- }
- return false;
- }
-
-
- @Override
- public C99QualifierType clone() {
- try {
- C99QualifierType clone = (C99QualifierType) super.clone();
- clone.type = (IType) type.clone();
- return clone;
- } catch (CloneNotSupportedException e) {
- assert false;
- return null;
- }
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Scope.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Scope.java
deleted file mode 100644
index 96f476ebb1..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Scope.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.IName;
-import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.core.index.IIndexFileSet;
-import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
-
-/**
- * @author Mike Kucera
- *
- */
-@SuppressWarnings({"restriction","unused"})
-public class C99Scope implements IC99Scope, IASTInternalScope {
-
-
-
- private IScope parent;
- private IASTNode physicalNode;
- private IName scopeName;
-
-
-
-
-
- public IScope getParent() {
- return parent;
- }
-
- public void setParent(IScope parent) {
- this.parent = parent;
- }
-
- public IASTNode getPhysicalNode() {
- return physicalNode;
- }
-
- public void setPhysicalNode(IASTNode physicalNode) {
- this.physicalNode = physicalNode;
- }
-
- public IName getScopeName() {
- return scopeName;
- }
-
- public void setScopeName(IName scopeName) {
- this.scopeName = scopeName;
- }
-
-
- public IBinding[] find( String name) {
- throw new UnsupportedOperationException();
- }
-
- public IBinding getBinding(IASTName name, boolean resolve) {
- throw new UnsupportedOperationException();
- }
-
- public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) {
- throw new UnsupportedOperationException();
- }
-
-
-
-
- public void addBinding(IBinding binding) {
- throw new UnsupportedOperationException();
- }
-
- public void addName(IASTName name) {
- throw new UnsupportedOperationException();
- }
-
- public void flushCache() {
-
- }
-
- public boolean isFullyCached() {
- return true;
- }
-
- public void removeBinding(IBinding binding) {
-
- }
-
- public void setFullyCached(boolean b) {
-
- }
-
- public IBinding getBinding(IASTName name, boolean resolve,
- IIndexFileSet acceptLocalBindings) throws DOMException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public IBinding[] getBindings(IASTName name, boolean resolve,
- boolean prefixLookup, IIndexFileSet acceptLocalBindings)
- throws DOMException {
- // TODO Auto-generated method stub
- return null;
- }
-
-
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Structure.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Structure.java
deleted file mode 100644
index b6d315cb07..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Structure.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.ast.ICompositeType;
-import org.eclipse.cdt.core.dom.ast.IField;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.ITypedef;
-import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.core.runtime.PlatformObject;
-
-@SuppressWarnings("restriction")
-public class C99Structure extends PlatformObject implements IC99Binding, ICompositeType, ITypeable {
-
-
- private Map<String,IField> fields = new LinkedHashMap<String,IField>();
- private IField[] fieldArray = null;
-
- /** either t_union or t_structure defined in IASTCompositeTypeSpecifier */
- private int key;
- private String name;
-
- private IScope scope;
-
- public C99Structure() {
- }
-
- public C99Structure(String name) {
- this.name = name;
- }
-
- public C99Structure(int key) {
- this.key = key;
- }
-
- public C99Structure(String name, int key) {
- this.name = name;
- this.key = key;
- }
-
- public void addField(IField field) {
- fields.put(field.getName(), field);
- fieldArray = null;
- }
-
- public IField findField(String name) {
- return fields.get(name);
- }
-
- public IScope getCompositeScope() {
-// C99Scope scope = new C99CompositeTypeScope(this);
-// scope.setScopeName(nameNode);
-// return scope;
- return null;
- }
-
- public IField[] getFields() {
- if(fieldArray == null)
- fieldArray = fields.values().toArray(new IField[fields.size()]);
- return fieldArray;
- }
-
- public void setKey(int key) {
- this.key = key;
- }
-
- public int getKey() {
- return key;
- }
-
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public char[] getNameCharArray() {
- if(name == null)
- return new char[0];
-
- return name.toCharArray();
- }
-
-
- public ILinkage getLinkage() {
- return Linkage.C_LINKAGE;
- }
-
- public IType getType() {
- return this;
- }
-
- public boolean isSameType(IType type) {
- if(type == this)
- return true;
- if( type instanceof ITypedef)
- return type.isSameType( this );
- return false;
- }
-
- //private Map<String,IField> fields = new LinkedHashMap<String,IField>();
- //private IField[] fieldArray = null;
-
-
- //private IScope scope;
-
- @Override
- public C99Structure clone() {
- try {
- C99Structure clone = (C99Structure) super.clone();
- //clone.scope = (IScope) scope.clone(); TODO
- clone.fieldArray = null;
- clone.fields = new LinkedHashMap<String,IField>();
- for(IField field : fields.values())
- clone.addField(field); // TODO not a deep clone
- return clone;
- } catch (CloneNotSupportedException e) {
- assert false;
- return null;
- }
- }
-
- public IScope getScope() {
- return scope;
- }
-
- public void setScope(IScope scope) {
- this.scope = scope;
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Typedef.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Typedef.java
deleted file mode 100644
index 458697bfa7..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Typedef.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.ITypedef;
-import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
-import org.eclipse.core.runtime.PlatformObject;
-
-@SuppressWarnings("restriction")
-public class C99Typedef extends PlatformObject implements IC99Binding, ITypedef, ITypeContainer, ITypeable {
-
- private IType type;
- private String name;
-
- private IScope scope;
-
-
- public C99Typedef() {
- }
-
- public C99Typedef(IType type) {
- this.type = type;
- }
-
- public C99Typedef(IType type, String name) {
- this.type = type;
- this.name = name;
- }
-
-
- public IType getType() {
- return type;
- }
-
- public void setType(IType type) {
- this.type = type;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public char[] getNameCharArray() {
- return name.toCharArray();
- }
-
-
- public boolean isSameType(IType t) {
- if(t == this)
- return true;
-
- try {
- if(t instanceof ITypedef)
- return type.isSameType(((ITypedef)t).getType());
- return type.isSameType(t);
- } catch(DOMException _) {
- return false;
- }
- }
-
- @Override
- public C99Typedef clone() {
- try {
- C99Typedef clone = (C99Typedef) super.clone();
- clone.type = (IType) type.clone();
- return clone;
- } catch (CloneNotSupportedException e) {
- assert false;
- return null;
- }
- }
-
- public ILinkage getLinkage() {
- return Linkage.C_LINKAGE;
- }
-
- public IScope getScope() {
- return scope;
- }
-
- public void setScope(IScope scope) {
- this.scope = scope;
- }
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java
deleted file mode 100644
index d93ecdd74e..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.IVariable;
-import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.core.runtime.PlatformObject;
-
-@SuppressWarnings("restriction")
-public class C99Variable extends PlatformObject implements IC99Binding, IVariable, ITypeable {
-
-
- private boolean isAuto;
- private boolean isExtern;
- private boolean isRegister;
- private boolean isStatic;
-
- private String name;
- private IType type;
-
- private IScope scope;
-
- public C99Variable() {
-
- }
-
- public C99Variable(String name) {
- this.name = name;
- }
-
-
- public void setType(IType type) {
- this.type = type;
- }
-
- public IType getType() {
- return type;
- }
-
-
- public void setAuto(boolean auto) {
- this.isAuto = auto;
- }
-
- public boolean isAuto() {
- return isAuto;
- }
-
-
- public void setExtern(boolean extern) {
- this.isExtern = extern;
- }
-
- public boolean isExtern() {
- return isExtern;
- }
-
-
- public void setRegister(boolean isRegister) {
- this.isRegister = isRegister;
- }
-
- public boolean isRegister() {
- return isRegister;
- }
-
-
- public void setStatic(boolean isStatic) {
- this.isStatic = isStatic;
- }
-
- public boolean isStatic() {
- return isStatic;
- }
-
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public char[] getNameCharArray() {
- return name.toCharArray();
- }
-
- public ILinkage getLinkage() {
- return Linkage.C_LINKAGE;
- }
-
- public IScope getScope() {
- return scope;
- }
-
- public void setScope(IScope scope) {
- this.scope = scope;
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/IC99Binding.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/IC99Binding.java
deleted file mode 100644
index a928b923ce..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/IC99Binding.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IScope;
-
-public interface IC99Binding extends IBinding {
-
- void setScope(IScope scope);
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/IC99Scope.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/IC99Scope.java
deleted file mode 100644
index 629bd3c416..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/IC99Scope.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.IName;
-import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.core.dom.ast.c.ICScope;
-
-
-/**
- * TODO maybe rename to IC99InternalScope or something else.
- *
- * @author Mike Kucera
- */
-public interface IC99Scope extends ICScope {
-
- void setParent(IScope parent);
-
- void setPhysicalNode(IASTNode node);
-
- void setScopeName(IName name);
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/ITypeable.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/ITypeable.java
deleted file mode 100644
index ca9129e39d..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/ITypeable.java
+++ /dev/null
@@ -1,17 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings;
-
-import org.eclipse.cdt.core.dom.ast.IType;
-
-public interface ITypeable {
- IType getType();
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/C99SymbolTable.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/C99SymbolTable.java
deleted file mode 100644
index 53e954384d..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/C99SymbolTable.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
-
-
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.IC99Binding;
-
-/**
- * A facade for a FunctionalMap to make it behave like
- * a symbol table for C99.
- *
- * In particular we need to be able to lookup identifiers based both
- * on the String representation of the identifier and its "namespace".
- *
- * @author Mike Kucera
- */
-public class C99SymbolTable {
-
- /**
- * Adapter objects are used as the keys. The trick here is to implement
- * compareTo() in such a way that identifiers are separated by their namespace.
- */
- private static class Key implements Comparable<Key> {
- private final String ident;
- private final CNamespace namespace;
-
- public Key(CNamespace namespace, String ident) {
- if(namespace == null || ident == null)
- throw new NullPointerException();
-
- this.ident = ident;
- this.namespace = namespace;
- }
-
- public int compareTo(Key x) {
- // this separates namespaces in the symbol table
- int c = namespace.compareTo(x.namespace);
- // only if the namespace is the same do we check the identifier
- return (c == 0) ? ident.compareTo(x.ident) : c;
- }
-
- @Override public String toString() {
- return ident + "::" + namespace;//$NON-NLS-1$
- }
- }
-
- /**
- * Start with EMPTY_TABLE and build up a symbol table using insert().
- */
- public static final C99SymbolTable EMPTY_TABLE = new C99SymbolTable();
-
-
- // the map we are providing a facade for
- private final FunctionalMap<Key,IC99Binding> map;
-
-
- /**
- * Constructors are private, start with EMPTY_TABLE
- * and build it up using insert().
- */
- private C99SymbolTable() {
- map = FunctionalMap.emptyMap();
- }
-
- private C99SymbolTable(FunctionalMap<Key,IC99Binding> newRoot) {
- map = newRoot;
- }
-
- /**
- * Returns a new symbol table that contains the given mapping.
- * @throws NullPointerException if the namespace or key is null.
- */
- public C99SymbolTable insert(CNamespace ns, String key, IC99Binding binding) {
- return new C99SymbolTable(map.insert(new Key(ns, key), binding));
- }
-
- /**
- * Looks up the binding given its namespace and identifier.
- * @return null If there is no binding corresponding to the key.
- * @throws NullPointerException if the namespace or key is null.
- */
- public IC99Binding lookup(CNamespace ns, String key) {
- return map.lookup(new Key(ns, key));
- }
-
- public int size() {
- return map.size();
- }
-
- public boolean isEmpty() {
- return map.size() == 0;
- }
-
- @Override public String toString() {
- return map.toString();
- }
-
-// void printStructure() {
-// map.printStructure();
-// }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/CImperativeSymbolTable.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/CImperativeSymbolTable.java
deleted file mode 100644
index 5f06190c64..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/CImperativeSymbolTable.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.cdt.core.dom.ast.IBinding;
-
-
-/**
- * Used to compute binding resolution during the parse.
- *
- * Imperative style symbol table with destructive update.
- *
- * Consists of two data structures, a hash table for fast lookup
- * of bindings given their names, and a stack used to keep track
- * of scopes.
- *
- *
- * @author Mike Kucera
- */
-public class CImperativeSymbolTable {
-
- private static final int TABLE_SIZE = 256;
-
- private Bucket[] table = new Bucket[TABLE_SIZE];
-
- private LinkedList<SymbolScope> scopeStack = new LinkedList<SymbolScope>();
-
-
-
- /**
- * Represents a scope in the C language.
- */
- private static class SymbolScope {
-
- /**
- * List of buckets that have been modified in the current scope.
- * When the scope is closed these buckets are popped, returning the
- * symbol table to the state it was in before the scope was opened.
- */
- List<Integer> modifiedBuckets = new ArrayList<Integer>();
- }
-
-
- /**
- * A bucket object used to hold elements in the hash table.
- */
- private static class Bucket {
- String key;
- CNamespace namespace;
- IBinding binding;
- Bucket next;
-
- Bucket(Bucket next, CNamespace namespace, String key, IBinding binding) {
- this.key = key;
- this.namespace = namespace;
- this.binding = binding;
- this.next = next;
- }
- }
-
-
- public CImperativeSymbolTable() {
- openScope(); // open the global scope
- // TODO populate the global scope with built-ins
- }
-
-
- /**
- * Hashes a key into an index in the hash table.
- */
- private int index(String key) {
- return Math.abs(key.hashCode() % TABLE_SIZE);
- }
-
-
- /**
- * Adds a binding to the symbol table in the current scope.
- *
- * @param mask A bit mask used to identify the namespace of the identifier.
- */
- public void put(CNamespace namespace, String ident, IBinding b) {
- int index = index(ident);
- table[index] = new Bucket(table[index], namespace, ident, b);
-
- SymbolScope scope = scopeStack.getLast();
- scope.modifiedBuckets.add(index);
- }
-
-
- /**
- * Returns the binding associated with the given identifier, or
- * null if there is none.
- *
- * @param mask A bit mask used to identify the namespace of the identifier.
- */
- public IBinding get(CNamespace namespace, String ident) {
- Bucket b = table[index(ident)];
- while(b != null) {
- if(namespace == b.namespace && ident.equals(b.key))
- return b.binding;
- b = b.next;
- }
- return null;
- }
-
-
- /**
- * Opens a new inner scope for identifiers.
- *
- * If an identifier is added that already exists in an outer scope
- * then it will be shadowed.
- */
- public void openScope() {
- scopeStack.add(new SymbolScope());
- }
-
-
- /**
- * Remove all the symbols defined in the scope that is being closed.
- *
- * @param scope An IScope object that will be used to represent this scope.
- * @throws SymbolTableException If the global scope has already been closed or if bindingScope is null.
- */
- public void closeScope() {
- SymbolScope poppedScope = scopeStack.removeLast(); // pop the scopeStack
-
- // pop each bucket that was modified in the scope
- for(int index : poppedScope.modifiedBuckets)
- table[index] = table[index].next;
- }
-
-
- @SuppressWarnings("nls")
- @Override
- public String toString() {
- StringBuilder buff = new StringBuilder('[');
- for(Bucket b : table) {
- while(b != null) {
- buff.append('<').append(b.key).append(": ").append(b.binding).append(">, ");
- b = b.next;
- }
- }
- return buff.append(']').toString();
- }
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/CNamespace.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/CNamespace.java
deleted file mode 100644
index 321a81ccde..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/CNamespace.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
-
-/**
- * The C language has 4 namespaces for identifiers.
- * This enum represents three of them, the "member" namespace
- * is represented by IStructure.getFields().
- *
- * The symbol table uses these to mark identifiers and keep
- * the namespaces separate.
- *
- * @author Mike Kucera
- */
-public enum CNamespace {
-
- GOTO_LABEL, // goto labels
- STRUCT_TAG,// structs, unions, enums
- IDENTIFIER; // all other identifiers
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/FunctionalMap.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/FunctionalMap.java
deleted file mode 100644
index ca73f93bd8..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/FunctionalMap.java
+++ /dev/null
@@ -1,295 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
-
-
-/**
- * An immutable map, like you would find in a functional programming language.
- *
- * Inserting a new pair into the map leaves the original map untouched,
- * instead a new map that contains the pair is returned. Therefore
- * an assignment is needed to "modify" the map (just like with Strings).
- *
- * <code>
- * myMap = myMap.insert(key,value);
- * </code>
- *
- * There is no remove() method because it is not needed. In order to
- * "delete" a pair from the map simply save a reference to an old version
- * of the map and restore the map from that old reference. This makes
- * "undo" operations trivial to implement.
- *
- * <code>
- * FunctionalMap oldMap = myMap; // save a reference
- * myMap = myMap.insert(key,value); // insert the pair into the map
- * myMap = oldMap; // delete the pair from the map
- * </code>
- *
- * This map is implemented as a red-black tree data structure,
- * and is based on the implementation found at:
- * http://www.eecs.usma.edu/webs/people/okasaki/jfp99.ps
- *
- * @author Mike Kucera
- */
-public class FunctionalMap<K extends Comparable<K>, V> {
-
- private static final boolean
- RED = true,
- BLACK = false;
-
-
- private static class Node<K, V> {
- final K key;
- final V val;
- Node<K,V> left;
- Node<K,V> right;
- boolean color;
-
- public Node(K key, V val, boolean color, Node<K,V> left, Node<K,V> right) {
- this.key = key;
- this.val = val;
- this.left = left;
- this.right = right;
- this.color = color;
- }
-
- @SuppressWarnings("nls")
- @Override
- public String toString() {
- return "Node(" + key + "," + val + "," + (color ? "R" : "B") + ")";
- }
- }
-
-
- private Node<K,V> root = null;
-
-
- private FunctionalMap() {
- // private constructor, use static factory method to instantiate
- }
-
- // factory method makes it cleaner to instantiate objects
- public static <K extends Comparable<K>,V> FunctionalMap<K,V> emptyMap() {
- return new FunctionalMap<K,V>();
- }
-
-
- /**
- * Returns a new map that contains the key-value pair.
- * @throws NullPointerException if key is null
- */
- public FunctionalMap<K,V> insert(K key, V val) {
- if(key == null)
- throw new NullPointerException();
-
- FunctionalMap<K,V> newMap = new FunctionalMap<K,V>();
- newMap.root = insert(this.root, key, val);
- newMap.root.color = BLACK; // force the root to be black
-
- assert checkInvariants(newMap.root);
-
- return newMap;
- }
-
-
- private Node<K,V> insert(Node<K,V> n, K key, V val) {
- if(n == null)
- return new Node<K,V>(key, val, RED, null, null); // new nodes are always red
-
- int c = key.compareTo(n.key);
- if(c < 0)
- return balance(n.key, n.val, n.color, insert(n.left, key, val), n.right);
- else if(c > 0)
- return balance(n.key, n.val, n.color, n.left, insert(n.right, key, val));
- else // equal, create a new node that overwrites the old value
- return new Node<K,V>(key, val, n.color, n.left, n.right);
- }
-
-
- private Node<K,V> balance(K key, V val, boolean color, Node<K,V> left, Node<K,V> right) {
- if(color == RED)
- return new Node<K,V>(key, val, color, left, right);
-
- final Node<K,V> newLeft, newRight;
-
- // now for the madness...
-
- if(left != null && left.color == RED) {
- if(left.left != null && left.left.color == RED) {
- newLeft = new Node<K,V>(left.left.key, left.left.val, BLACK, left.left.left, left.left.right);
- newRight = new Node<K,V>(key, val, BLACK, left.right, right);
- return new Node<K,V>(left.key, left.val, RED, newLeft, newRight);
- }
- if(left.right != null && left.right.color == RED) {
- newLeft = new Node<K,V>(left.key, left.val, BLACK, left.left, left.right.left);
- newRight = new Node<K,V>(key, val, BLACK, left.right.right, right);
- return new Node<K,V>(left.right.key, left.right.val, RED, newLeft, newRight);
- }
- }
- if(right != null && right.color == RED) {
- if(right.left != null && right.left.color == RED) {
- newLeft = new Node<K,V>(key, val, BLACK, left, right.left.left);
- newRight = new Node<K,V>(right.key, right.val, BLACK, right.left.right, right.right);
- return new Node<K,V>(right.left.key, right.left.val, RED, newLeft, newRight);
- }
- if(right.right != null && right.right.color == RED) {
- newLeft = new Node<K,V>(key, val, BLACK, left, right.left);
- newRight = new Node<K,V>(right.right.key, right.right.val, BLACK, right.right.left, right.right.right);
- return new Node<K,V>(right.key, right.val, RED, newLeft, newRight);
- }
- }
-
- return new Node<K,V>(key, val, BLACK, left, right);
- }
-
-
- /**
- * Returns the value if it is in the map, null otherwise.
- * @throws NullPointerException if key is null
- */
- public V lookup(K key) {
- if(key == null)
- throw new NullPointerException();
-
- // no need for recursion here
- Node<K,V> n = root;
- while(n != null) {
- int x = key.compareTo(n.key); // throws NPE if key is null
- if(x == 0)
- return n.val;
- n = (x < 0) ? n.left : n.right;
- }
- return null;
- }
-
-
- /**
- * Returns true if there exists a mapping with the given key
- * in this map.
- * @throws NullPointerException if key is null
- */
- public boolean containsKey(K key) {
- if(key == null)
- throw new NullPointerException();
-
- // lookup uses an iterative algorithm
- Node<K,V> n = root;
- while(n != null) {
- int x = key.compareTo(n.key); // throws NPE if key is null
- if(x == 0)
- return true;
- n = (x < 0) ? n.left : n.right;
- }
- return false;
- }
-
-
- public boolean isEmpty() {
- return root == null;
- }
-
- @Override public String toString() {
- StringBuilder sb = new StringBuilder('[');
- inorderPrint(root, sb);
- sb.append(']');
- return sb.toString();
- }
-
- private static <K,V> void inorderPrint(Node<K,V> n, StringBuilder sb) {
- if(n == null)
- return;
-
- inorderPrint(n.left, sb);
- if(sb.length() > 1)
- sb.append(", ");//$NON-NLS-1$
- sb.append(n.toString());
- inorderPrint(n.right, sb);
- }
-
-
- void printStructure() {
- if(root == null)
- System.out.println("empty map"); //$NON-NLS-1$
- else
- printStructure(root, 0);
- }
-
- private static <K,V> void printStructure(Node<K,V> node, int level) {
- for(int i = 0; i < level; i++)
- System.out.print("--");//$NON-NLS-1$
-
- if(node == null) {
- System.out.println("null");//$NON-NLS-1$
- }
- else if(node.right == null && node.left == null) {
- System.out.println(node);
- }
- else {
- System.out.println(node);
- printStructure(node.right, level + 1);
- printStructure(node.left, level + 1);
- }
- }
-
-
- private static <K,V> int depth(Node<K,V> node) {
- if(node == null)
- return 0;
- return Math.max(depth(node.left), depth(node.right)) + 1;
- }
-
-
- /**
- * Warning, this is a linear operation.
- */
- public int size() {
- return size(root);
- }
-
- private static <K,V> int size(Node<K,V> node) {
- if(node == null)
- return 0;
- return size(node.left) + size(node.right) + 1;
- }
-
-
-
- /**********************************************************************************************
- * Built-in testing
- **********************************************************************************************/
-
-
- private boolean checkInvariants(Node<K,V> n) {
- // the number of black nodes on every path through the tree is the same
- assertBalanced(n);
- return true;
- }
-
- // not exactly sure if this is right
- private int assertBalanced(Node<K,V> node) {
- if(node == null)
- return 1; // nulls are considered as black children
-
- // both children of every red node are black
- if(node.color == RED) {
- assert node.left == null || node.left.color == BLACK;
- assert node.right == null || node.right.color == BLACK;
- }
-
- int left = assertBalanced(node.left);
- int right = assertBalanced(node.right);
-
- assert left == right;
-
- return left + (node.color == BLACK ? 1 : 0);
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/SymbolTableTests.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/SymbolTableTests.java
deleted file mode 100644
index 5226ff445f..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/SymbolTableTests.java
+++ /dev/null
@@ -1,219 +0,0 @@
-package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
-
-//import junit.framework.TestCase;
-
-import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Label;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Structure;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Variable;
-
-@SuppressWarnings("nls")
-public class SymbolTableTests {//extends TestCase {
- // TODO write tests for imperative symbol table
-
-
- private final String[] KEYS = { "pantera", "soulfly", "inflames", "megadeth", "archenemy", "carcass" };
-
- public void testPersistence() {
- FunctionalMap<String,Integer> st0 = FunctionalMap.emptyMap();
- assertTrue(st0.isEmpty());
-
- FunctionalMap<String,Integer> st1 = st0.insert(KEYS[0], 1);
-
- // empty symbol table does not change
- assertTrue(st0.isEmpty());
- assertNull(st0.lookup(KEYS[1]));
-
- // a new symbol table was created
- assertFalse(st1.isEmpty());
- assertEquals(new Integer(1), st1.lookup(KEYS[0]));
-
- FunctionalMap<String,Integer> st2 = st1.insert(KEYS[1], 2);
- FunctionalMap<String,Integer> st3 = st2.insert(KEYS[2], 3);
- FunctionalMap<String,Integer> st4 = st3.insert(KEYS[3], 4);
- FunctionalMap<String,Integer> st5 = st4.insert(KEYS[4], 5);
-
- assertMap(st0, KEYS, new Integer[] {null, null, null, null, null, null} );
- assertMap(st1, KEYS, new Integer[] {1, null, null, null, null, null} );
- assertMap(st2, KEYS, new Integer[] {1, 2, null, null, null, null} );
- assertMap(st3, KEYS, new Integer[] {1, 2, 3, null, null, null} );
- assertMap(st4, KEYS, new Integer[] {1, 2, 3, 4, null, null} );
- assertMap(st5, KEYS, new Integer[] {1, 2, 3, 4, 5, null} );
- }
-
-
- // these are here just to get the tests to compile
- // JUnit is not available in this plugin, this is old code that I just didn't want to delete
-
- @SuppressWarnings("unused")
- private void assertEquals( Integer integer, Integer lookup) {
- // TODO Auto-generated method stub
-
- }
-
-
- @SuppressWarnings("unused")
- private void assertFalse(boolean empty) {
- // TODO Auto-generated method stub
-
- }
-
-
- @SuppressWarnings("unused")
- private void assertNull(Integer lookup) {
- // TODO Auto-generated method stub
-
- }
-
-
- @SuppressWarnings("unused")
- private void assertTrue(boolean empty) {
- // TODO Auto-generated method stub
-
- }
-
-
-
- public void testOverride() {
- FunctionalMap<String,Integer> map1 = FunctionalMap.emptyMap();
- for(int i = 0; i < KEYS.length; i++) {
- map1 = map1.insert(KEYS[i], i);
- }
-
- assertMap(map1, KEYS, new Integer[] {0, 1, 2, 3, 4, 5});
-
- FunctionalMap<String,Integer> map2 = map1.insert(KEYS[5], 999);
- FunctionalMap<String,Integer> map3 = map2.insert(KEYS[5], null);
-
- assertEquals(new Integer(5), map1.lookup(KEYS[5]));
- assertEquals(new Integer(999), map2.lookup(KEYS[5]));
- assertNull(map3.lookup(KEYS[5]));
- }
-
-
- @SuppressWarnings("unchecked")
- private static void assertMap(FunctionalMap map, Comparable[] keys, Object[] vals) {
- assert keys.length == vals.length;
-
- for(int i = 0; i < keys.length; i++) {
- assertEquals( "the key '" + keys[i] + "' did not match", vals[i], map.lookup((keys[i])));
- if(vals[i] != null) {
- assertTrue("key '" + keys[i] + "' not in map", map.containsKey(keys[i]));
- }
- }
- }
-
- @SuppressWarnings("unused")
- private static void assertTrue(String string, boolean containsKey) {
- // TODO Auto-generated method stub
-
- }
-
-
- @SuppressWarnings("unused")
- private static void assertEquals(String string, Object object, Object lookup) {
- // TODO Auto-generated method stub
-
- }
-
-
-
- public void testFunctionalSymbolTable1() {
- C99SymbolTable st = C99SymbolTable.EMPTY_TABLE;
-
- for(String key : KEYS) {
- st = st.insert(CNamespace.IDENTIFIER, key, new C99Variable(key));
- }
- for(String key : KEYS) {
- st = st.insert(CNamespace.GOTO_LABEL, key, new C99Label(key));
- }
- for(String key : KEYS) {
- st = st.insert(CNamespace.STRUCT_TAG, key, new C99Structure(key));
- }
-
- assertFunctionalSymbolTableContainsAllThePairs(st);
- }
-
- public void testFunctionalSymbolTable2() {
- C99SymbolTable st = C99SymbolTable.EMPTY_TABLE;
-
- // same test as above but this time we insert the keys in a different order
- for(String key : KEYS) {
- st = st.insert(CNamespace.IDENTIFIER, key, new C99Variable(key));
- st = st.insert(CNamespace.GOTO_LABEL, key, new C99Label(key));
- st = st.insert(CNamespace.STRUCT_TAG, key, new C99Structure(key));
- }
-
- assertFunctionalSymbolTableContainsAllThePairs(st);
- }
-
- private void assertFunctionalSymbolTableContainsAllThePairs(C99SymbolTable st) {
- assertEquals(KEYS.length * 3, st.size());
- for(String key : KEYS) {
- IBinding b = st.lookup(CNamespace.IDENTIFIER, key);
- assertNotNull(b);
- C99Variable x = (C99Variable)b;
- assertEquals(key, x.getName());
- }
- for(String key : KEYS) {
- IBinding b = st.lookup(CNamespace.GOTO_LABEL, key);
- assertNotNull(b);
- C99Label x = (C99Label)b;
- assertEquals(key, x.getName());
- }
- for(String key : KEYS) {
- IBinding b = st.lookup(CNamespace.STRUCT_TAG, key);
- assertNotNull(b);
- C99Structure x = (C99Structure)b;
- assertEquals(key, x.getName());
- }
- }
-
- @SuppressWarnings("unused")
- private void assertEquals(String key, String name) {
- // TODO Auto-generated method stub
-
- }
-
-
- @SuppressWarnings("unused")
- private void assertNotNull(IBinding b) {
- // TODO Auto-generated method stub
-
- }
-
-
-
- public void testProperFail() {
- FunctionalMap<Integer,Integer> map = FunctionalMap.emptyMap();
- try {
- map.insert(null, 99);
- fail();
- } catch (NullPointerException _) {}
-
- try {
- map.containsKey(null);
- fail();
- } catch (NullPointerException _) {}
-
- try {
- map.lookup(null);
- fail();
- } catch (NullPointerException _) {}
-
- C99SymbolTable table = C99SymbolTable.EMPTY_TABLE;
- try {
- table.insert(null, null, new C99Variable("blah")); //$NON-NLS-1$
- fail();
- } catch (NullPointerException _) {}
-
- }
-
-
-
- private void fail() {
- // TODO Auto-generated method stub
-
- }
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/TypedefSymbolTable.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/TypedefSymbolTable.java
deleted file mode 100644
index 49fca096e3..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/TypedefSymbolTable.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.lrparser.symboltable;
-
-
-
-/**
- * A facade for a FunctionalMap that is used just to track typedef
- * declarations.
- *
- * This class acts like a set. No information needs to be associated
- * with a typedef declaration, all we need to know is if the identifier
- * has been declared as a typedef.
- *
- * @author Mike Kucera
- */
-public class TypedefSymbolTable {
-
- /**
- * Start with EMPTY_TABLE and build up a symbol table using add().
- */
- public static final TypedefSymbolTable EMPTY_TABLE = new TypedefSymbolTable();
-
-
- // the map we are providing a facade for
- private final FunctionalMap<String,Object> map;
-
-
- /**
- * Constructors are private, start with EMPTY_TABLE
- * and build it up using insert().
- */
- private TypedefSymbolTable() {
- map = FunctionalMap.emptyMap();
- }
-
- private TypedefSymbolTable(FunctionalMap<String,Object> newRoot) {
- map = newRoot;
- }
-
-
- public TypedefSymbolTable add(String typedefIdent) {
- return new TypedefSymbolTable(map.insert(typedefIdent, null));
- }
-
-
- public boolean contains(String typedef) {
- return map.containsKey(typedef);
- }
-
- public int size() {
- return map.size();
- }
-
- public boolean isEmpty() {
- return map.size() == 0;
- }
-
- @Override public String toString() {
- return map.toString();
- }
-
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/plugin.properties b/lrparser/org.eclipse.cdt.core.lrparser/plugin.properties
index 165e3722a9..f61638b3ad 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/plugin.properties
+++ b/lrparser/org.eclipse.cdt.core.lrparser/plugin.properties
@@ -1,16 +1,16 @@
###############################################################################
-# Copyright (c) 2007 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:
+# Copyright (c) 2007, 2009 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
###############################################################################
Bundle-Name.0 = LR Parser Plug-in
-Bundle-Vendor.0 = Eclipse.org
+Bundle-Vendor.0 = Eclipse CDT
Bundle-Name.1 = LR Parser Plug-in
# built-in languages
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/plugin.xml b/lrparser/org.eclipse.cdt.core.lrparser/plugin.xml
index abca5716d7..508db11400 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/plugin.xml
+++ b/lrparser/org.eclipse.cdt.core.lrparser/plugin.xml
@@ -2,6 +2,7 @@
<?eclipse version="3.2"?>
<plugin>
+ <!--
<extension point="org.eclipse.cdt.core.language">
<language
class="org.eclipse.cdt.core.dom.lrparser.c99.C99Language"
@@ -9,20 +10,22 @@
name="%language.name.c99">
</language>
<language
+ class="org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage"
+ id="gcc"
+ name="LR GCC">
+ </language>
+
+ <language
class="org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage"
id="isocpp"
name="%language.name.isocpp">
</language>
-
- <pdomLinkageFactory
- class="org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory"
- id="c99"/>
-
- <pdomLinkageFactory
- class="org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory"
- id="isocpp"/>
+ <language
+ class="org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage"
+ id="gpp"
+ name="LR GPP">
+ </language>
</extension>
+ -->
-
-
-</plugin>
+</plugin> \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java
index 36796131f3..6eb812267a 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java
@@ -1,15 +1,18 @@
/*******************************************************************************
- * 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:
+ * Copyright (c) 2006, 2009 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
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser;
+import java.util.HashMap;
+import java.util.Map;
+
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTName;
@@ -20,7 +23,9 @@ import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.model.ICLanguageKeywords;
+import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IScanner;
@@ -32,53 +37,30 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory;
+import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory;
import org.eclipse.core.runtime.CoreException;
/**
* Implementation of the ILanguage extension point,
* provides the ability to add LPG based languages to CDT.
- *
- * @author Mike Kucera
*/
-@SuppressWarnings("restriction")
-public abstract class BaseExtensibleLanguage extends AbstractLanguage implements ILanguage, ICLanguageKeywords {
+@SuppressWarnings({ "restriction", "nls" })
+public abstract class BaseExtensibleLanguage extends AbstractLanguage {
private static final boolean DEBUG_PRINT_GCC_AST = false;
private static final boolean DEBUG_PRINT_AST = false;
-
+
private ICLanguageKeywords keywords = null;
-
/**
* Retrieve the parser (runs after the preprocessor runs).
*
* Can be overridden in subclasses to provide a different parser
* for a language extension.
*/
- protected abstract IParser getParser();
-
-
- /**
- * A token map is used to map tokens from the DOM preprocessor
- * to the tokens defined by an LPG parser.
- */
- protected abstract IDOMTokenMap getTokenMap();
-
-
- /**
- * Normally all the AST nodes are created by the parser, but we
- * need the root node ahead of time.
- *
- * The preprocessor is responsible for creating preprocessor AST nodes,
- * so the preprocessor needs access to the translation unit so that it can
- * set the parent pointers on the AST nodes it creates.
- *
- * @return an IASTTranslationUnit object thats empty and will be filled in by the parser
- */
- protected abstract IASTTranslationUnit createASTTranslationUnit(IIndex index, IScanner preprocessor);
-
+ protected abstract IParser<IASTTranslationUnit> getParser(IScanner scanner, IIndex index, Map<String,String> properties);
/**
* Returns the ParserLanguage value that is to be used when creating
@@ -94,62 +76,48 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration();
-
- private void getCLanguageKeywords() {
- ParserLanguage lang = getParserLanguage();
- IScannerExtensionConfiguration config = getScannerExtensionConfiguration();
- keywords = new CLanguageKeywords(lang, config);
- }
-
-
- @SuppressWarnings("unchecked")
- @Override
- public Object getAdapter(Class adapter) {
- if (adapter == IPDOMLinkageFactory.class)
- return new PDOMCLinkageFactory();
-
- return super.getAdapter(adapter);
+ protected ICLanguageKeywords getCLanguageKeywords() {
+ if(keywords == null) {
+ ParserLanguage lang = getParserLanguage();
+ IScannerExtensionConfiguration config = getScannerExtensionConfiguration();
+ keywords = new CLanguageKeywords(lang, config);
+ }
+ return keywords;
}
-
-
- @SuppressWarnings("nls")
@Override
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log) throws CoreException {
IASTTranslationUnit gtu = null;
if(DEBUG_PRINT_GCC_AST) {
- ILanguage gppLanguage = GCCLanguage.getDefault();
- gtu = gppLanguage.getASTTranslationUnit(reader, scanInfo, fileCreator, index, log);
+ System.out.println("\n********************************************************\nParsing\nOptions: " + options);
- System.out.println();
- System.out.println("********************************************************");
- System.out.println("Parsing");
- System.out.println("Options: " + options);
- System.out.println("GPP AST:");
+ ILanguage gppLanguage = getParserLanguage() == ParserLanguage.CPP ? GPPLanguage.getDefault() : GCCLanguage.getDefault();
+ gtu = gppLanguage.getASTTranslationUnit(reader, scanInfo, fileCreator, index, options, log);
+
+ System.out.println(gppLanguage.getName() + " AST:");
ASTPrinter.print(gtu);
System.out.println();
}
- // TODO temporary
- IScannerExtensionConfiguration config = new ScannerExtensionConfiguration();
+ IScannerExtensionConfiguration config = getScannerExtensionConfiguration();
ParserLanguage pl = getParserLanguage();
IScanner preprocessor = new CPreprocessor(reader, scanInfo, pl, log, config, fileCreator);
- preprocessor.setScanComments((options & OPTION_ADD_COMMENTS) != 0);
preprocessor.setComputeImageLocations((options & ILanguage.OPTION_NO_IMAGE_LOCATIONS) == 0);
- IParser parser = getParser();
- IASTTranslationUnit tu = createASTTranslationUnit(index, preprocessor);
+ Map<String,String> parserProperties = new HashMap<String,String>();
+ parserProperties.put(LRParserProperties.TRANSLATION_UNIT_PATH, reader.getPath());
+ if((options & OPTION_SKIP_FUNCTION_BODIES) != 0)
+ parserProperties.put(LRParserProperties.SKIP_FUNCTION_BODIES, "true");
+ //if((options & OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS) != 0)
+ // parserProperties.put(LRParserProperties.SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS, "true");
- CPreprocessorAdapter.runCPreprocessor(preprocessor, parser, getTokenMap(), tu);
-
- parser.parse(tu); // the parser will fill in the rest of the AST
-
- // the TU is marked as either a source file or a header file
- tu.setIsHeaderUnit((options & OPTION_IS_SOURCE_UNIT) == 0);
+ IParser<IASTTranslationUnit> parser = getParser(preprocessor, index, parserProperties);
+ IASTTranslationUnit tu = parser.parse();
+ tu.setIsHeaderUnit((options & OPTION_IS_SOURCE_UNIT) == 0); // the TU is marked as either a source file or a header file
if(DEBUG_PRINT_AST) {
System.out.println("Base Extensible Language AST:");
@@ -168,7 +136,6 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
}
- @SuppressWarnings("nls")
public IASTCompletionNode getCompletionNode(CodeReader reader,
IScannerInfo scanInfo, ICodeReaderFactory fileCreator,
IIndex index, IParserLogService log, int offset) throws CoreException {
@@ -185,31 +152,28 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
printCompletionNode(cn);
}
- // TODO temporary
IScannerExtensionConfiguration config = getScannerExtensionConfiguration();
ParserLanguage pl = getParserLanguage();
IScanner preprocessor = new CPreprocessor(reader, scanInfo, pl, log, config, fileCreator);
preprocessor.setContentAssistMode(offset);
- IParser parser = getParser();
- IASTTranslationUnit tu = createASTTranslationUnit(index, preprocessor);
- CPreprocessorAdapter.runCPreprocessor(preprocessor, parser, getTokenMap(), tu);
+ Map<String,String> parserProperties = new HashMap<String,String>();
+ parserProperties.put(LRParserProperties.TRANSLATION_UNIT_PATH, reader.getPath());
+ parserProperties.put(LRParserProperties.SKIP_FUNCTION_BODIES, "true");
+ parserProperties.put(LRParserProperties.SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS, "true");
- // the parser will fill in the rest of the AST
- IASTCompletionNode completionNode = parser.parse(tu);
+ IParser<IASTTranslationUnit> parser = getParser(preprocessor, index, parserProperties);
+ parser.parse();
+
+ IASTCompletionNode completionNode = parser.getCompletionNode();
if(DEBUG_PRINT_AST) {
System.out.println("Base Extensible Language AST:");
printCompletionNode(completionNode);
}
-// List<String> messages = ASTComparer.compare(completionNode.getTranslationUnit(), cn.getTranslationUnit());
-// for(String m : messages) {
-// System.out.println(m);
-// }
-
return completionNode;
}
@@ -217,7 +181,6 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
/*
* For debugging.
*/
- @SuppressWarnings("nls")
private static void printCompletionNode(IASTCompletionNode cn) {
if(cn == null) {
System.out.println("Completion node is null");
@@ -241,25 +204,34 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage implements
return GCCLanguage.getDefault().getSelectedNames(ast, start, length);
}
+
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object getAdapter(Class adapter) {
+ if(IPDOMLinkageFactory.class.equals(adapter)) {
+ if(getParserLanguage().isCPP())
+ return new PDOMCPPLinkageFactory();
+ return new PDOMCLinkageFactory();
+ }
+
+ return super.getAdapter(adapter);
+ }
+
public String[] getBuiltinTypes() {
- if(keywords == null)
- getCLanguageKeywords();
-
- return keywords.getBuiltinTypes();
+ return getCLanguageKeywords().getBuiltinTypes();
}
public String[] getKeywords() {
- if(keywords == null)
- getCLanguageKeywords();
-
- return keywords.getKeywords();
+ return getCLanguageKeywords().getKeywords();
}
public String[] getPreprocessorKeywords() {
- if(keywords == null)
- getCLanguageKeywords();
-
- return keywords.getPreprocessorKeywords();
+ return getCLanguageKeywords().getPreprocessorKeywords();
+ }
+
+ public IContributedModelBuilder createModelBuilder(@SuppressWarnings("unused") ITranslationUnit tu) {
+ return null;
}
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CLanguageKeywords.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CLanguageKeywords.java
index 850792e166..0ca16b3176 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CLanguageKeywords.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CLanguageKeywords.java
@@ -33,7 +33,7 @@ import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
* @author Mike Kucera
*/
@SuppressWarnings({"restriction", "nls"})
-class CLanguageKeywords implements ICLanguageKeywords {
+public class CLanguageKeywords implements ICLanguageKeywords {
private final ParserLanguage language;
private final IScannerExtensionConfiguration config;
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CPreprocessorAdapter.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CPreprocessorAdapter.java
index 6a70f46e28..9960389350 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CPreprocessorAdapter.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CPreprocessorAdapter.java
@@ -1,11 +1,11 @@
/*******************************************************************************
- * 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:
+ * Copyright (c) 2006, 2009 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
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser;
@@ -13,7 +13,6 @@ package org.eclipse.cdt.core.dom.lrparser;
import lpg.lpgjavaruntime.IToken;
import lpg.lpgjavaruntime.Token;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
@@ -22,8 +21,10 @@ import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
* Adapts the CPreprocessor from the CDT core for use with LPG based parsers.
*
* @author Mike Kucera
+ * @noreference
+ * TODO move into an internal package
*/
-class CPreprocessorAdapter {
+public class CPreprocessorAdapter {
/**
* During content assist the preprocessor may return a completion token
@@ -45,13 +46,10 @@ class CPreprocessorAdapter {
* Collect the tokens generated by the preprocessor.
* TODO: should preprocessor.nextTokenRaw() be called instead?
*/
- @SuppressWarnings("restriction")
- public static void runCPreprocessor(IScanner preprocessor, ITokenCollector tokenCollector, IDOMTokenMap tokenMap, IASTTranslationUnit tu) {
+ public static void runCPreprocessor(IScanner preprocessor, ITokenCollector tokenCollector, IDOMTokenMap tokenMap) {
// LPG requires that the token stream start with a dummy token
tokenCollector.addToken(createDummyToken());
- preprocessor.getLocationResolver().setRootNode(tu);
-
org.eclipse.cdt.core.parser.IToken lastToken = null;
try {
while(true) {
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParser.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParser.java
index c713971342..b17ee9dbe8 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParser.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2009 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
@@ -12,7 +12,6 @@ package org.eclipse.cdt.core.dom.lrparser;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
/**
@@ -20,29 +19,27 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
*
* @author Mike Kucera
*/
-public interface IParser extends ITokenCollector {
+public interface IParser<N extends IASTNode> {
+
/**
* Performs the actual parse.
*
- * The given translation unit is assumed to not have any children, during the parse
- * it will have its declaration fields filled in, resulting in a complete AST.
- *
* If there were any errors during the parse these will be represented in the
* AST as problem nodes.
*
* If the parser encounters a completion token then a completion node
- * is returned, null is returned otherwise.
- *
- * @param tu An IASTTranslationUnit instance that will have its declarators filled in.
- * @return a completion node if a completion token is encountered during the parser, null otherwise.
+ * will be available via the getCompletionNode() method.
*/
- public IASTCompletionNode parse(IASTTranslationUnit tu);
+ public N parse();
/**
- * Returns the result of a secondary parser.
+ * Returns the completion node if a completion token was encountered
+ * during the parse, null otherwise.
*/
- public IASTNode getSecondaryParseResult();
+ public IASTCompletionNode getCompletionNode();
+
+
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ISecondaryParser.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ISecondaryParser.java
new file mode 100644
index 0000000000..866154c746
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ISecondaryParser.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.lrparser;
+
+import java.util.List;
+
+import lpg.lpgjavaruntime.IToken;
+
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+
+public interface ISecondaryParser<N extends IASTNode> extends IParser<N> {
+
+
+ /**
+ * Set the list of tokens that will be parsed.
+ *
+ * The given list does not need to contain dummy and EOF tokens,
+ * these will be added automatically.
+ *
+ * This method causes any tokens already contained in the parser
+ * to be removed.
+ *
+ * This method is mainly used by secondary parsers that are called
+ * from a main parser.
+ *
+ * @throws NullPointerException if tokens is null
+ */
+ public void setTokens(List<IToken> tokens);
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ITokenCollector.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ITokenCollector.java
index d8286687da..6036aee3b4 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ITokenCollector.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ITokenCollector.java
@@ -1,17 +1,15 @@
/*******************************************************************************
- * 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:
+ * Copyright (c) 2006, 2009 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
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser;
-import java.util.List;
-
import lpg.lpgjavaruntime.IToken;
/**
@@ -33,20 +31,5 @@ public interface ITokenCollector {
* @throws NullPointerException if token is null
*/
public void addToken(IToken token);
-
- /**
- * Set the list of tokens that will be parsed.
- *
- * The given list does not need to contain dummy and EOF tokens,
- * these will be added automatically.
- *
- * This method causes any tokens already contained in the parser
- * to be removed.
- *
- * This method is mainly used by secondary parsers that are called
- * from a main parser.
- *
- * @throws NullPointerException if tokens is null
- */
- public void setTokens(List<IToken> tokens);
+
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserPlugin.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserPlugin.java
new file mode 100644
index 0000000000..3a58250575
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserPlugin.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.lrparser;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.osgi.framework.BundleContext;
+
+
+public class LRParserPlugin extends Plugin {
+
+ public static final String PLUGIN_ID = "org.eclipse.cdt.core.lrparser"; //$NON-NLS-1$
+
+
+ private static LRParserPlugin plugin;
+
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ try {
+ // shutdown code goes here
+ plugin = null;
+ }
+ finally {
+ super.stop(context);
+ }
+ }
+
+ /**
+ * @noreference
+ */
+ public static IStatus createStatus(String msg, Throwable e) {
+ return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, msg, e);
+ }
+
+ /**
+ * @noreference
+ */
+ public static IStatus createStatus(Throwable e) {
+ return createStatus(e.getMessage(), e);
+ }
+
+ /**
+ * @noreference
+ */
+ public static void log(IStatus status) {
+ plugin.getLog().log(status);
+ }
+
+ /**
+ * @noreference
+ */
+ public static void logError(Throwable exception, String message) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, message, exception));
+ }
+
+ /**
+ * @noreference
+ */
+ public static void logError(Throwable exception) {
+ logError(exception, exception.getMessage());
+ }
+
+ /**
+ * @noreference
+ */
+ public static void logError(String message) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, message));
+ }
+
+ /**
+ * @noreference
+ */
+ public static void logInfo(String message) {
+ log(new Status(IStatus.INFO, PLUGIN_ID, message));
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserProperties.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserProperties.java
new file mode 100644
index 0000000000..ecfd9ee7b3
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserProperties.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.lrparser;
+
+
+@SuppressWarnings("nls")
+public final class LRParserProperties {
+
+ /**
+ * The LR parsers do not actually skip the parsing of function bodies,
+ * but this option does have the effect of not generating AST nodes
+ * for function bodies.
+ *
+ * TODO this is not implemented yet in the LR parser
+ *
+ * Possible values: "true", null
+ */
+ public static final String SKIP_FUNCTION_BODIES = "org.eclipse.cdt.core.dom.lrparser.skipFunctionBodies";
+
+ /**
+ * Instructs the parser not to create AST nodes for expressions
+ * within aggregate initializers when they do not contain names.
+ *
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=253690
+ *
+ * Possible values: "true", null
+ */
+ public static final String SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS = "org.eclipse.cdt.core.dom.lrparser.skipTrivialExpressionsInAggregateInitializers";
+
+ /**
+ * The location of the translation unit as given by the CodeReader.
+ */
+ public static final String TRANSLATION_UNIT_PATH = "org.eclipse.cdt.core.dom.lrparser.translationUnitPath";
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ScannerExtensionConfiguration.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ScannerExtensionConfiguration.java
index 273e687571..791d02ddda 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ScannerExtensionConfiguration.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ScannerExtensionConfiguration.java
@@ -8,9 +8,8 @@
******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser;
-import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.AbstractScannerExtensionConfiguration;
import org.eclipse.cdt.core.parser.IMacro;
-import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
/**
@@ -19,34 +18,32 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
* @author Mike Kucera
*
*/
-public class ScannerExtensionConfiguration implements IScannerExtensionConfiguration {
+@SuppressWarnings("nls")
+public class ScannerExtensionConfiguration extends AbstractScannerExtensionConfiguration {
- public CharArrayIntMap getAdditionalKeywords() {
- return null;
+
+ private ScannerExtensionConfiguration() {
}
-
- public IMacro[] getAdditionalMacros() {
- return null;
- }
-
- public CharArrayIntMap getAdditionalPreprocessorKeywords() {
- return null;
+
+ public static ScannerExtensionConfiguration createC() {
+ return new ScannerExtensionConfiguration() {
+ @Override public IMacro[] getAdditionalMacros() {
+ return new IMacro[] { createMacro("__null", "(void *)0") };
+ }
+ };
}
-
- public boolean initializeMacroValuesTo1() {
- return false;
+
+ public static ScannerExtensionConfiguration createCPP() {
+ return new ScannerExtensionConfiguration() {
+ @Override public IMacro[] getAdditionalMacros() {
+ return new IMacro[] { createMacro("__null", "0") };
+ }
+ };
}
+ @Override
public boolean support$InIdentifiers() {
return true;
}
- public char[] supportAdditionalNumericLiteralSuffixes() {
- return null;
- }
-
- public boolean supportMinAndMaxOperators() {
- return false;
- }
-
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ASTCompletionNode.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ASTCompletionNode.java
index 803d1341d5..9c387e4861 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ASTCompletionNode.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ASTCompletionNode.java
@@ -1,11 +1,11 @@
/*******************************************************************************
- * 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:
+ * Copyright (c) 2006, 2009 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
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action;
@@ -41,23 +41,24 @@ public class ASTCompletionNode implements IASTCompletionNode {
private final List<IASTName> names = new LinkedList<IASTName>();
private final String prefix;
- private final IASTTranslationUnit tu;
+ private IASTTranslationUnit tu;
/**
* Creates a completion node.
- * @throws NullPointerException if tu is null
- * @throws IllegalArgumentException if prefix is the empty string, it should be null instead
+ * @param prefix The completion prefix, set to null if the empty string is passed.
*/
public ASTCompletionNode(String prefix, IASTTranslationUnit tu) {
if("".equals(prefix)) //$NON-NLS-1$
- throw new IllegalArgumentException("prefix cannot be the empty string"); //$NON-NLS-1$
- if(tu == null)
- throw new NullPointerException("tu is null"); //$NON-NLS-1$
+ prefix = null;
this.prefix = prefix;
this.tu = tu;
}
+
+ public ASTCompletionNode(String prefix) {
+ this(prefix, null);
+ }
public void addName(IASTName name) {
@@ -87,9 +88,14 @@ public class ASTCompletionNode implements IASTCompletionNode {
public String getPrefix() {
return prefix;
}
+
+ public void setTranslationUnit(IASTTranslationUnit tu) {
+ this.tu = tu;
+ }
public IASTTranslationUnit getTranslationUnit() {
return tu;
}
+
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/AbstractParserAction.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/AbstractParserAction.java
new file mode 100644
index 0000000000..5c09ab5cf6
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/AbstractParserAction.java
@@ -0,0 +1,229 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.lrparser.action;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import lpg.lpgjavaruntime.IToken;
+
+import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.lrparser.ISecondaryParser;
+import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+
+@SuppressWarnings("restriction")
+public abstract class AbstractParserAction {
+
+
+ /**
+ * Used with very simple optional rules that just say
+ * that some particular token or keyword is optional.
+ * The presence of the PLACE_HOLDER on the stack means that the keyword
+ * was parsed, the presence of null means the keyword wasn't parsed.
+ *
+ * @see BuildASTParserAction#consumePlaceHolder()
+ * @see BuildASTParserAction#consumeEmpty()
+ */
+ protected static final Object PLACE_HOLDER = Boolean.TRUE; // any object will do
+
+
+
+ /** Provides an interface to the token stream */
+ protected final ITokenStream stream;
+
+ /** Stack that holds the intermediate nodes as the AST is being built */
+ protected final ScopedStack<Object> astStack;
+
+ /** The completion node, only generated during a completion parse */
+ protected ASTCompletionNode completionNode;
+
+ /** Options that change the behavior of the parser actions */
+ protected Map<String,String> properties = Collections.emptyMap();
+
+
+
+
+ /**
+ * Completion tokens are represented by different kinds by different parsers.
+ */
+ protected abstract boolean isCompletionToken(IToken token);
+
+
+ protected abstract IASTName createName(char[] image);
+
+
+
+ /**
+ * Create a new parser action.
+ * @param tu Root node of the AST, its list of declarations should be empty.
+ * @throws NullPointerException if any of the parameters are null
+ */
+ public AbstractParserAction(ITokenStream parser, ScopedStack<Object> astStack) {
+ if(parser == null)
+ throw new NullPointerException("parser is null"); //$NON-NLS-1$
+ if(astStack == null)
+ throw new NullPointerException("astStack is null"); //$NON-NLS-1$
+
+ this.stream = parser;
+ this.astStack = astStack;
+ }
+
+
+
+ protected void setOffsetAndLength(IASTNode node) {
+ int ruleOffset = stream.getLeftIToken().getStartOffset();
+ int ruleLength = stream.getRightIToken().getEndOffset() - ruleOffset;
+ ((ASTNode)node).setOffsetAndLength(ruleOffset, ruleLength < 0 ? 0 : ruleLength);
+ }
+
+ /**
+ * Creates a IASTName node from an identifier token.
+ * If the token is a completion token then it is added to the completion node.
+ */
+ protected IASTName createName(IToken token) {
+ IASTName name = createName(token.toString().toCharArray()); // TODO, token.toCharArray();
+ ParserUtil.setOffsetAndLength(name, token);
+
+ if(isCompletionToken(token))
+ addNameToCompletionNode(name, token.toString());
+
+ return name;
+ }
+
+ public void setParserProperties(Map<String,String> properties) {
+ this.properties = properties == null ? Collections.<String,String>emptyMap() : properties;
+ }
+
+ /**
+ * Creates a completion node if one does not yet exist and adds the
+ * given name to it.
+ */
+ protected void addNameToCompletionNode(IASTName name, String prefix) {
+ if(completionNode == null) {
+ completionNode = newCompletionNode(prefix);
+ }
+
+ completionNode.addName(name);
+ }
+
+ public ASTCompletionNode newCompletionNode(String prefix) {
+ return new ASTCompletionNode(prefix);
+ }
+
+ /**
+ * Returns the completion node if this is a completion parse, null otherwise.
+ */
+ public IASTCompletionNode getASTCompletionNode() {
+ return completionNode;
+ }
+
+ /**
+ * Returns the parse result.
+ * @return
+ */
+ public IASTNode getParseResult() {
+ return (IASTNode) astStack.peek();
+ }
+
+ /**
+ * Runs the given parser on the given token list.
+ *
+ */
+ protected <N extends IASTNode> N runSecondaryParser(ISecondaryParser<N> secondaryParser) {
+ return runSecondaryParser(secondaryParser, stream.getRuleTokens());
+ }
+
+
+ /**
+ * Runs the given parser on the tokens that make up the current rule.
+ */
+ protected <N extends IASTNode> N runSecondaryParser(ISecondaryParser<N> secondaryParser, List<IToken> tokens) {
+ // the secondary parser will alter the token kinds, which will need to be undone
+ int[] savedKinds = new int[tokens.size()];
+
+ int i = 0;
+ for(IToken token : tokens)
+ savedKinds[i++] = token.getKind();
+
+ secondaryParser.setTokens(tokens);
+ N result = secondaryParser.parse();
+
+ IASTCompletionNode compNode = secondaryParser.getCompletionNode();
+ if(compNode != null) {
+ for(IASTName name : compNode.getNames())
+ addNameToCompletionNode(name, compNode.getPrefix());
+ }
+
+ // restore the token kinds
+ i = 0;
+ for(IToken token : tokens)
+ token.setKind(savedKinds[i++]);
+
+ return result;
+ }
+
+
+
+ /*************************************************************************************************************
+ * Basic Actions
+ ************************************************************************************************************/
+
+
+ /**
+ * Method that is called by the special <openscope> production
+ * in order to create a new scope in the AST stack.
+ */
+ public void openASTScope() {
+ astStack.openScope();
+ }
+
+
+ /**
+ * Place null on the stack.
+ * Usually called for optional element to indicate the element
+ * was not parsed.
+ */
+ public void consumeEmpty() {
+ astStack.push(null);
+ }
+
+
+ /**
+ * Place a marker on the stack.
+ * Usually used for very simple optional elements to indicate
+ * the element was parsed. Usually the existence of an AST node
+ * on the stack is used instead of the marker, but for simple
+ * cases like an optional keyword this action is useful.
+ */
+ public void consumePlaceHolder() {
+ astStack.push(PLACE_HOLDER);
+ }
+
+
+ /**
+ * Just pops the stack, useful if you have a rule that generates
+ * a node but you don't need the node.
+ */
+ public void consumeIgnore() {
+ astStack.pop();
+ }
+
+
+ /**
+ * Gets the current token and places it on the stack for later consumption.
+ */
+ public void consumeToken() {
+ astStack.push(stream.getRightIToken());
+ }
+}
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 945ff7ceb3..7d8464afd4 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2009 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
@@ -10,11 +10,17 @@
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action;
+import static org.eclipse.cdt.core.dom.lrparser.action.ParserUtil.endOffset;
+import static org.eclipse.cdt.core.dom.lrparser.action.ParserUtil.length;
+import static org.eclipse.cdt.core.dom.lrparser.action.ParserUtil.offset;
+
import java.util.List;
import lpg.lpgjavaruntime.IToken;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
@@ -22,7 +28,6 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
-import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
@@ -52,7 +57,6 @@ import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
-import org.eclipse.cdt.core.dom.ast.IASTProblemExpression;
import org.eclipse.cdt.core.dom.ast.IASTProblemHolder;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
@@ -62,16 +66,24 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
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.dom.lrparser.ISecondaryParser;
+import org.eclipse.cdt.core.dom.lrparser.LRParserPlugin;
+import org.eclipse.cdt.core.dom.lrparser.LRParserProperties;
+import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
+import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.IProblem;
-import org.eclipse.cdt.core.parser.util.DebugUtil;
+import org.eclipse.cdt.core.parser.IScanner;
+import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
-
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
/**
* Parser semantic actions that are common to both C and C++.
@@ -79,47 +91,14 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
* @author Mike Kucera
*/
@SuppressWarnings("restriction")
-public abstract class BuildASTParserAction {
-
-
- /**
- * Used with very simple optional rules that just say
- * that some particular token or keyword is optional.
- * The presence of the PLACE_HOLDER on the stack means that the keyword
- * was parsed, the presence of null means the keyword wasn't parsed.
- *
- * @see BuildASTParserAction#consumePlaceHolder()
- * @see BuildASTParserAction#consumeEmpty()
- */
- protected static final Object PLACE_HOLDER = Boolean.TRUE; // any object will do
-
-
- // turn debug tracing on and off
- // TODO move this into an AspectJ project
- protected static final boolean TRACE_ACTIONS = false;
- protected static final boolean TRACE_AST_STACK = false;
+public abstract class BuildASTParserAction extends AbstractParserAction {
-
- /** Stack that holds the intermediate nodes as the AST is being built */
- protected final ScopedStack<Object> astStack = new ScopedStack<Object>();
-
- /** Provides an interface to the token stream */
- protected final IParserActionTokenProvider parser;
-
- /** The completion node, only generated during a completion parse */
- protected ASTCompletionNode completionNode;
-
- /** The root node is created outside the parser because it is also needed by the preprocessor */
- protected final IASTTranslationUnit tu;
/** Abstract factory for creating AST node objects */
- private final IASTNodeFactory nodeFactory;
+ private final INodeFactory nodeFactory;
-
- /**
- * Completion tokens are represented by different kinds by different parsers.
- */
- protected abstract boolean isCompletionToken(IToken token);
+ /** Abstract factory for creating secondary parsers */
+ private final ISecondaryParserFactory parserFactory;
/**
@@ -128,308 +107,82 @@ public abstract class BuildASTParserAction {
protected abstract boolean isIdentifierToken(IToken token);
- /**
- * Get the parser that will recognize expressions.
- */
- protected abstract IParser getExpressionParser();
-
-
- /**
- * Expression parser that does not recognize cast expressions,
- * used to disambiguate casts.
- */
- protected abstract IParser getNoCastExpressionParser();
-
-
- /**
- * Expression parser that treats all sizeof and typeid expressions
- * as unary expressions.
- */
- protected abstract IParser getSizeofExpressionParser();
-
-
+ protected IASTTranslationUnit tu = null;
+
/**
* Create a new parser action.
* @param tu Root node of the AST, its list of declarations should be empty.
* @throws NullPointerException if any of the parameters are null
*/
- public BuildASTParserAction(IASTNodeFactory nodeFactory, IParserActionTokenProvider parser, IASTTranslationUnit tu) {
+ public BuildASTParserAction(ITokenStream parser, ScopedStack<Object> astStack, INodeFactory nodeFactory, ISecondaryParserFactory parserFactory) {
+ super(parser, astStack);
+
if(nodeFactory == null)
throw new NullPointerException("nodeFactory is null"); //$NON-NLS-1$
- if(parser == null)
- throw new NullPointerException("parser is null"); //$NON-NLS-1$
- if(tu == null)
- throw new NullPointerException("tu is null"); //$NON-NLS-1$
+ if(parserFactory == null)
+ throw new NullPointerException("parserFactory is null"); //$NON-NLS-1$
this.nodeFactory = nodeFactory;
- this.parser = parser;
- this.tu = tu;
- }
-
-
- /**
- * Creates a completion node if one does not yet exist and adds the
- * given name to it.
- */
- protected void addNameToCompletionNode(IASTName name, String prefix) {
- if(completionNode == null) {
- prefix = (prefix == null || prefix.length() == 0) ? null : prefix;
- completionNode = nodeFactory.newCompletionNode(prefix, tu);
- }
-
- completionNode.addName(name);
- }
-
-
- /**
- * Used to combine completion nodes from secondary parsers into
- * the main completion node.
- */
- protected void addNameToCompletionNode(IASTCompletionNode node) {
- if(node == null)
- return;
-
- for(IASTName name : node.getNames())
- addNameToCompletionNode(name, node.getPrefix());
- }
-
-
- /**
- * Returns the completion node if this is a completion parse, null otherwise.
- */
- public IASTCompletionNode getASTCompletionNode() {
- return completionNode;
- }
-
-
- /**
- * Used to get the result of secondary parsers.
- */
- public IASTNode getSecondaryParseResult() {
- return (IASTNode) astStack.pop();
- }
-
-
-
- protected static int offset(IToken token) {
- return token.getStartOffset();
- }
-
- protected static int offset(IASTNode node) {
- return ((ASTNode)node).getOffset();
- }
-
- protected static int length(IToken token) {
- return endOffset(token) - offset(token);
- }
-
- protected static int length(IASTNode node) {
- return ((ASTNode)node).getLength();
- }
-
- protected static int endOffset(IASTNode node) {
- return offset(node) + length(node);
- }
-
- protected static int endOffset(IToken token) {
- return token.getEndOffset();
- }
-
-
- protected void setOffsetAndLength(IASTNode node) {
- int ruleOffset = parser.getLeftIToken().getStartOffset();
- int ruleLength = parser.getRightIToken().getEndOffset() - ruleOffset;
- ((ASTNode)node).setOffsetAndLength(ruleOffset, ruleLength < 0 ? 0 : ruleLength);
- }
-
- protected static void setOffsetAndLength(IASTNode node, IToken token) {
- ((ASTNode)node).setOffsetAndLength(offset(token), length(token));
- }
-
- protected static void setOffsetAndLength(IASTNode node, int offset, int length) {
- ((ASTNode)node).setOffsetAndLength(offset, length);
- }
-
-
- /**
- * Creates a IASTName node from an identifier token.
- * If the token is a completion token then it is added to the completion node.
- */
- protected IASTName createName(IToken token) {
- IASTName name = nodeFactory.newName(token.toString().toCharArray()); // TODO, token.toCharArray();
- setOffsetAndLength(name, token);
-
- if(isCompletionToken(token))
- addNameToCompletionNode(name, token.toString());
-
- return name;
+ this.parserFactory = parserFactory;
}
- /**
- * Runs the given parser on the given token list.
- *
- */
- protected IASTNode runSecondaryParser(IParser secondaryParser) {
- return runSecondaryParser(secondaryParser, parser.getRuleTokens());
- }
-
-
- /**
- * Runs the given parser on the tokens that make up the current rule.
- */
- protected IASTNode runSecondaryParser(IParser secondaryParser, List<IToken> tokens) {
- // the secondary parser will alter the token kinds, which will need to be undone
- int[] savedKinds = new int[tokens.size()];
-
- int i = 0;
- for(IToken token : tokens)
- savedKinds[i++] = token.getKind();
-
- secondaryParser.setTokens(tokens);
+ public void initializeTranslationUnit(IScanner scanner, IBuiltinBindingsProvider builtinBindingsProvider, IIndex index) {
+ tu = nodeFactory.newTranslationUnit();
+ tu.setIndex(index);
- // need to pass tu because any new completion nodes need to be linked directly to the root
- IASTCompletionNode compNode = secondaryParser.parse(tu);
- addNameToCompletionNode(compNode);
- IASTNode result = secondaryParser.getSecondaryParseResult();
-
- // restore the token kinds
- i = 0;
- for(IToken token : tokens)
- token.setKind(savedKinds[i++]);
-
- return result;
- }
-
-
-
- /**
- * Allows simple pattern match testing of lists of tokens.
- *
- * TODO: need to take token mapping into account
- *
- * @throws NullPointerException if source or pattern is null
- */
- public static boolean matchTokens(List<IToken> source, ITokenMap tokenMap, Integer ... pattern) {
- if(source.size() != pattern.length) // throws NPE if either parameter is null
- return false;
-
- for(int i = 0, n = pattern.length; i < n; i++) {
- if(tokenMap.mapKind(source.get(i).getKind()) != pattern[i].intValue())
- return false;
- }
- return true;
- }
-
-
- /**
- * Finds the tokens in the given list that are between startOffset and endOffset.
- * Note, the offsets have to be exact.
- */
- public static List<IToken> tokenOffsetSubList(List<IToken> tokens, int startOffset, int endOffset) {
- int first = 0, last = 0;
- int i = 0;
- for(IToken t : tokens) {
- if(offset(t) == startOffset) {
- first = i;
+ // add built-in names to the scope
+ if (builtinBindingsProvider != null) {
+ IScope tuScope = tu.getScope();
+ IBinding[] bindings = builtinBindingsProvider.getBuiltinBindings(tuScope);
+ try {
+ for (IBinding binding : bindings) {
+ ASTInternal.addBinding(tuScope, binding);
+ }
+ } catch (DOMException e) {
+ LRParserPlugin.logError(e);
}
- if(endOffset(t) == endOffset) {
- last = i;
- break;
- }
- i++;
}
- return tokens.subList(first, last + 1);
- }
-
-
- /*************************************************************************************************************
- * Start of actions.
- ************************************************************************************************************/
-
-
-
- /**
- * Method that is called by the special <openscope> production
- * in order to create a new scope in the AST stack.
- */
- public void openASTScope() {
- astStack.openScope();
- }
-
-
-
- /**
- * Place null on the stack.
- * Usually called for optional element to indicate the element
- * was not parsed.
- */
- public void consumeEmpty() {
- astStack.push(null);
- }
-
-
- /**
- * Place a marker on the stack.
- * Usually used for very simple optional elements to indicate
- * the element was parsed. Usually the existence of an AST node
- * on the stack is used instead of the marker, but for simple
- * cases like an optional keyword this action is useful.
- */
- public void consumePlaceHolder() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
- astStack.push(PLACE_HOLDER);
- }
-
-
-
- /**
- * Gets the current token and places it on the stack for later consumption.
- */
- public void consumeDeclSpecToken() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
- astStack.push(parser.getRightIToken());
-
- if(TRACE_AST_STACK) System.out.println(astStack);
- }
-
-
- /**
- * Gets the current token and places it on the stack for later consumption.
- */
- public void consumeToken() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- astStack.push(parser.getRightIToken());
-
- if(TRACE_AST_STACK) System.out.println(astStack);
+ if(tu instanceof ASTTranslationUnit) {
+ ((ASTTranslationUnit)tu).setLocationResolver(scanner.getLocationResolver());
+ }
}
-
-
+
public void consumeTranslationUnit() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
+ if(tu == null)
+ tu = nodeFactory.newTranslationUnit();
// can't close the outermost scope
- // the outermost scope may be empty if there are no tokens in the file
for(Object o : astStack.topScope()) {
tu.addDeclaration((IASTDeclaration)o);
}
+ while(!astStack.isEmpty()) {
+ astStack.pop();
+ }
// this is the same way that the DOM parser computes the length
IASTDeclaration[] declarations = tu.getDeclarations();
- if (declarations.length != 0) {
+ if(declarations.length != 0) {
IASTNode d = declarations[declarations.length-1];
- setOffsetAndLength(tu, 0, offset(d) + length(d));
+ ParserUtil.setOffsetAndLength(tu, 0, offset(d) + length(d));
}
- resolveAmbiguityNodes();
+ resolveAmbiguityNodes(tu);
+ //tu.freeze();
+
+ astStack.push(tu);
+ }
- if(TRACE_AST_STACK) System.out.println(astStack);
+
+ @Override
+ public ASTCompletionNode newCompletionNode(String prefix) {
+ return new ASTCompletionNode(prefix, tu);
}
+
/**
* Removes ambiguity nodes from the AST by resolving them.
@@ -442,14 +195,13 @@ public abstract class BuildASTParserAction {
* TODO Ambiguity resolution may be avoided in the case that no
* ambiguity nodes were created.
*/
- private void resolveAmbiguityNodes() {
+ private static void resolveAmbiguityNodes(IASTTranslationUnit tu) {
tu.accept(EMPTY_VISITOR);
if (tu instanceof ASTTranslationUnit) {
((ASTTranslationUnit)tu).cleanupAfterAmbiguityResolution();
}
}
-
/**
* When applied to the AST causes ambiguity nodes to be resolved.
*/
@@ -458,16 +210,11 @@ public abstract class BuildASTParserAction {
};
-
/**
* Consumes a single identifier token.
*/
public void consumeIdentifierName() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- astStack.push(createName(parser.getRightIToken()));
-
- if(TRACE_AST_STACK) System.out.println(astStack);
+ astStack.push(createName(stream.getRightIToken()));
}
@@ -477,8 +224,6 @@ public abstract class BuildASTParserAction {
* TODO, be careful where exactly in the grammar this is called, it may be called unnecessarily
*/
public void consumeStatementDeclarationWithDisambiguation() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTDeclaration decl = (IASTDeclaration) astStack.pop();
IASTDeclarationStatement declarationStatement = nodeFactory.newDeclarationStatement(decl);
setOffsetAndLength(declarationStatement);
@@ -486,51 +231,51 @@ public abstract class BuildASTParserAction {
// attempt to also parse the tokens as an expression
IASTExpressionStatement expressionStatement = null;
if(decl instanceof IASTSimpleDeclaration) {
- List<IToken> expressionTokens = parser.getRuleTokens();
+ List<IToken> expressionTokens = stream.getRuleTokens();
expressionTokens = expressionTokens.subList(0, expressionTokens.size()-1); // remove the semicolon at the end
- IParser expressionParser = getExpressionParser();
- IASTExpression expr = (IASTExpression) runSecondaryParser(expressionParser, expressionTokens);
+ ISecondaryParser<IASTExpression> expressionParser = parserFactory.getExpressionParser(stream, properties);
+ IASTExpression expr = runSecondaryParser(expressionParser, expressionTokens);
- if(expr != null && !(expr instanceof IASTProblemExpression)) { // the parse may fail
+ if(expr != null) { // the parse may fail
expressionStatement = nodeFactory.newExpressionStatement(expr);
setOffsetAndLength(expressionStatement);
}
}
- List<IToken> tokens = parser.getRuleTokens();
+ List<IToken> tokens = stream.getRuleTokens();
IASTNode result;
- if(expressionStatement == null)
+ if(expressionStatement == null)
result = declarationStatement;
+ else if(expressionStatement.getExpression() instanceof IASTFunctionCallExpression)
+ result = expressionStatement;
else if(tokens.size() == 2 && (isCompletionToken(tokens.get(0)) || isIdentifierToken(tokens.get(0)))) // identifier followed by semicolon
result = expressionStatement;
else if(isImplicitInt(decl))
result = expressionStatement;
else {
- result = nodeFactory.newAmbiguousStatement(declarationStatement, expressionStatement);
+ result = createAmbiguousStatement(declarationStatement, expressionStatement);
setOffsetAndLength(result);
}
astStack.push(result);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
+ protected abstract IASTAmbiguousStatement createAmbiguousStatement(IASTStatement ... statements);
+
+
+
/**
* Wrap a declaration in a DeclarationStatement.
*/
public void consumeStatementDeclaration() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTDeclaration decl = (IASTDeclaration) astStack.pop();
IASTDeclarationStatement declarationStatement = nodeFactory.newDeclarationStatement(decl);
setOffsetAndLength(declarationStatement);
astStack.push(declarationStatement);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -566,9 +311,7 @@ public abstract class BuildASTParserAction {
* @see ICPPASTLiteralExpression
*/
public void consumeExpressionLiteral(int kind) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IToken token = parser.getRightIToken();
+ IToken token = stream.getRightIToken();
String rep = token.toString();
// Strip the quotes from string literals, this is just to be consistent
@@ -579,49 +322,34 @@ public abstract class BuildASTParserAction {
// }
IASTLiteralExpression expr = nodeFactory.newLiteralExpression(kind, rep);
- setOffsetAndLength(expr, token);
+ ParserUtil.setOffsetAndLength(expr, token);
astStack.push(expr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
public void consumeExpressionBracketed() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression operand = (IASTExpression) astStack.pop();
IASTUnaryExpression expr = nodeFactory.newUnaryExpression(IASTUnaryExpression.op_bracketedPrimary, operand);
setOffsetAndLength(expr);
astStack.push(expr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
public void consumeExpressionID() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- //IASTName name = createName(parser.getRightIToken());
- IASTName name = createName(parser.getLeftIToken());
+ IASTName name = createName(stream.getLeftIToken());
IASTIdExpression expr = nodeFactory.newIdExpression(name);
setOffsetAndLength(expr);
astStack.push(expr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
public void consumeExpressionName() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTName name = (IASTName) astStack.pop();
IASTIdExpression expr = nodeFactory.newIdExpression(name);
setOffsetAndLength(expr);
astStack.push(expr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -629,21 +357,20 @@ public abstract class BuildASTParserAction {
* expression ::= <openscope-ast> expression_list_actual
*/
public void consumeExpressionList() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
List<Object> expressions = astStack.closeScope();
if(expressions.size() == 1) {
astStack.push(expressions.get(0));
}
else {
IASTExpressionList exprList = nodeFactory.newExpressionList();
+
for(Object o : expressions) {
exprList.addExpression((IASTExpression)o);
}
+
+ setOffsetAndLength(exprList);
astStack.push(exprList);
}
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -651,15 +378,11 @@ public abstract class BuildASTParserAction {
* postfix_expression ::= postfix_expression '[' expression ']'
*/
public void consumeExpressionArraySubscript() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression subscript = (IASTExpression) astStack.pop();
IASTExpression arrayExpr = (IASTExpression) astStack.pop();
IASTArraySubscriptExpression expr = nodeFactory.newArraySubscriptExpression(arrayExpr, subscript);
setOffsetAndLength(expr);
astStack.push(expr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -667,16 +390,12 @@ public abstract class BuildASTParserAction {
* postfix_expression ::= postfix_expression '(' expression_list_opt ')'
*/
public void consumeExpressionFunctionCall() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression argList = (IASTExpression) astStack.pop(); // may be null
IASTExpression idExpr = (IASTExpression) astStack.pop();
IASTFunctionCallExpression expr = nodeFactory.newFunctionCallExpression(idExpr, argList);
setOffsetAndLength(expr);
astStack.push(expr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -684,45 +403,40 @@ public abstract class BuildASTParserAction {
* @param operator constant for {@link ICPPASTCastExpression}
*/
public void consumeExpressionCast(int operator) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression operand = (IASTExpression) astStack.pop();
IASTTypeId typeId = (IASTTypeId) astStack.pop();
IASTCastExpression expr = nodeFactory.newCastExpression(operator, typeId, operand);
setOffsetAndLength(expr);
- IASTNode alternateExpr = null;
+ IASTExpression alternateExpr = null;
if(operator == IASTCastExpression.op_cast) { // don't reparse for dynamic_cast etc as those are not ambiguous
// try parsing as non-cast to resolve ambiguities
- IParser secondaryParser = getNoCastExpressionParser();
+ ISecondaryParser<IASTExpression> secondaryParser = parserFactory.getNoCastExpressionParser(stream, properties);
alternateExpr = runSecondaryParser(secondaryParser);
}
- if(alternateExpr == null || alternateExpr instanceof IASTProblemExpression)
+ if(alternateExpr == null)
astStack.push(expr);
else {
- IASTNode ambiguityNode = nodeFactory.newAmbiguousExpression(expr, (IASTExpression)alternateExpr);
+ IASTNode ambiguityNode = createAmbiguousExpression(expr, alternateExpr);
setOffsetAndLength(ambiguityNode);
astStack.push(ambiguityNode);
}
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
+ protected abstract IASTAmbiguousExpression createAmbiguousExpression(IASTExpression ... expressions);
+
+
/**
* Lots of rules, no need to list them.
* @param operator From IASTUnaryExpression
*/
public void consumeExpressionUnaryOperator(int operator) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression operand = (IASTExpression) astStack.pop();
IASTUnaryExpression expr = nodeFactory.newUnaryExpression(operator, operand);
setOffsetAndLength(expr);
astStack.push(expr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -732,27 +446,33 @@ public abstract class BuildASTParserAction {
* @see consumeExpressionUnaryOperator For the other use of sizeof
*/
public void consumeExpressionTypeId(int operator) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTTypeId typeId = (IASTTypeId) astStack.pop();
IASTTypeIdExpression expr = nodeFactory.newTypeIdExpression(operator, typeId);
setOffsetAndLength(expr);
// try parsing as an expression to resolve ambiguities
- IParser secondaryParser = getSizeofExpressionParser();
- IASTNode alternateExpr = runSecondaryParser(secondaryParser);
+ ISecondaryParser<IASTExpression> secondaryParser = parserFactory.getSizeofExpressionParser(stream, properties);
+ IASTExpression alternateExpr = runSecondaryParser(secondaryParser);
- if(alternateExpr == null || alternateExpr instanceof IASTProblemExpression)
+ if(alternateExpr == null)
astStack.push(expr);
+ else if(isFunctionType(expr)) // bug 252243
+ astStack.push(alternateExpr);
else {
- IASTNode ambiguityNode = nodeFactory.newAmbiguousExpression(expr, (IASTExpression)alternateExpr);
+ IASTNode ambiguityNode = createAmbiguousExpression(expr, alternateExpr);
setOffsetAndLength(ambiguityNode);
astStack.push(ambiguityNode);
}
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
+
+ private static boolean isFunctionType(IASTExpression expr) {
+ if(expr instanceof IASTTypeIdExpression) {
+ IASTTypeId typeId = ((IASTTypeIdExpression) expr).getTypeId();
+ return typeId.getAbstractDeclarator() instanceof IASTFunctionDeclarator;
+ }
+ return false;
+ }
/**
@@ -760,15 +480,11 @@ public abstract class BuildASTParserAction {
* @param op Field from IASTBinaryExpression
*/
public void consumeExpressionBinaryOperator(int op) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression expr2 = (IASTExpression) astStack.pop();
IASTExpression expr1 = (IASTExpression) astStack.pop();
IASTBinaryExpression binExpr = nodeFactory.newBinaryExpression(op, expr1, expr2);
setOffsetAndLength(binExpr);
astStack.push(binExpr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -776,16 +492,12 @@ public abstract class BuildASTParserAction {
* conditional_expression ::= logical_OR_expression '?' expression ':' conditional_expression
*/
public void consumeExpressionConditional() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression expr3 = (IASTExpression) astStack.pop();
IASTExpression expr2 = (IASTExpression) astStack.pop();
IASTExpression expr1 = (IASTExpression) astStack.pop();
IASTConditionalExpression condExpr = nodeFactory.newConditionalExpession(expr1, expr2, expr3);
setOffsetAndLength(condExpr);
astStack.push(condExpr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -793,46 +505,54 @@ public abstract class BuildASTParserAction {
* labeled_statement ::= label_identifier ':' statement
* label_identifier ::= identifier
*/
- public void consumeStatementLabeled(/*IBinding binding*/) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
+ public void consumeStatementLabeled() {
IASTStatement body = (IASTStatement) astStack.pop();
- IASTName label = createName(parser.getLeftIToken());
- //label.setBinding(binding);
+ IASTName label = createName(stream.getLeftIToken());
+
IASTLabelStatement stat = nodeFactory.newLabelStatement(label, body);
setOffsetAndLength(stat);
astStack.push(stat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
/**
- * labeled_statement ::= case constant_expression ':'
+ * labeled_statement ::= 'case' constant_expression ':' statement
*/
public void consumeStatementCase() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
+ IASTStatement body = (IASTStatement) astStack.pop();
IASTExpression expr = (IASTExpression) astStack.pop();
- IASTCaseStatement caseStatement = nodeFactory.newCaseStatement(expr);
- setOffsetAndLength(caseStatement);
- astStack.push(caseStatement);
- if(TRACE_AST_STACK) System.out.println(astStack);
+ IASTCaseStatement caseStatement = nodeFactory.newCaseStatement(expr);
+ setOffsetAndLength(caseStatement); // TODO this is wrong, need to adjust length to end of colon
+
+ // this is a hackey fix because case statements are not modeled correctly in the AST
+ IASTCompoundStatement compound = nodeFactory.newCompoundStatement();
+ setOffsetAndLength(compound);
+ compound.addStatement(caseStatement);
+ compound.addStatement(body);
+
+ astStack.push(compound);
}
/**
- * labeled_statement ::= default ':'
+ * labeled_statement ::= 'default' ':' <openscope-ast> statement
*/
public void consumeStatementDefault() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
+ IASTStatement body = (IASTStatement) astStack.pop();
IASTDefaultStatement stat = nodeFactory.newDefaultStatement();
- setOffsetAndLength(stat);
- astStack.push(stat);
+ List<IToken> tokens = stream.getRuleTokens();
+ IToken defaultToken = tokens.get(0);
+ IToken colonToken = tokens.get(1);
+ ParserUtil.setOffsetAndLength(stat, offset(defaultToken), offset(colonToken) - offset(defaultToken) + 1);
- if(TRACE_AST_STACK) System.out.println(astStack);
+ IASTCompoundStatement compound = nodeFactory.newCompoundStatement();
+ setOffsetAndLength(compound);
+ compound.addStatement(stat);
+ compound.addStatement(body);
+
+ astStack.push(compound);
}
@@ -841,13 +561,9 @@ public abstract class BuildASTParserAction {
* expression_statement ::= ';'
*/
public void consumeStatementNull() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTNullStatement stat = nodeFactory.newNullStatement();
setOffsetAndLength(stat);
astStack.push(stat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -855,14 +571,10 @@ public abstract class BuildASTParserAction {
* expression_statement ::= expression ';'
*/
public void consumeStatementExpression() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression expr = (IASTExpression) astStack.pop();
IASTExpressionStatement stat = nodeFactory.newExpressionStatement(expr);
setOffsetAndLength(stat);
astStack.push(stat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -873,8 +585,6 @@ public abstract class BuildASTParserAction {
* block_item_list ::= block_item | block_item_list block_item
*/
public void consumeStatementCompoundStatement(boolean hasStatementsInBody) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTCompoundStatement block = nodeFactory.newCompoundStatement();
if(hasStatementsInBody) {
@@ -885,8 +595,6 @@ public abstract class BuildASTParserAction {
setOffsetAndLength(block);
astStack.push(block);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -895,15 +603,11 @@ public abstract class BuildASTParserAction {
* ::= 'do' statement 'while' '(' expression ')' ';'
*/
public void consumeStatementDoLoop() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression condition = (IASTExpression) astStack.pop();
IASTStatement body = (IASTStatement) astStack.pop();
IASTDoStatement stat = nodeFactory.newDoStatement(body, condition);
setOffsetAndLength(stat);
astStack.push(stat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -911,16 +615,11 @@ public abstract class BuildASTParserAction {
/**
* jump_statement ::= goto goto_identifier ';'
*/
- public void consumeStatementGoto(/*IBinding binding*/) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IASTName name = createName(parser.getRuleTokens().get(1));
- //name.setBinding(binding);
+ public void consumeStatementGoto() {
+ IASTName name = createName(stream.getRuleTokens().get(1));
IASTGotoStatement gotoStat = nodeFactory.newGotoStatement(name);
setOffsetAndLength(gotoStat);
astStack.push(gotoStat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -928,13 +627,9 @@ public abstract class BuildASTParserAction {
* jump_statement ::= continue ';'
*/
public void consumeStatementContinue() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTContinueStatement stat = nodeFactory.newContinueStatement();
setOffsetAndLength(stat);
astStack.push(stat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -942,13 +637,9 @@ public abstract class BuildASTParserAction {
* jump_statement ::= break ';'
*/
public void consumeStatementBreak() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTBreakStatement stat = nodeFactory.newBreakStatement();
setOffsetAndLength(stat);
astStack.push(stat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -957,14 +648,10 @@ public abstract class BuildASTParserAction {
* jump_statement ::= return expression ';'
*/
public void consumeStatementReturn(boolean hasExpr) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression expr = hasExpr ? (IASTExpression) astStack.pop() : null;
IASTReturnStatement returnStat = nodeFactory.newReturnStatement(expr);
setOffsetAndLength(returnStat);
astStack.push(returnStat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -975,22 +662,18 @@ public abstract class BuildASTParserAction {
* | specifier_qualifier_list abstract_declarator
*/
public void consumeTypeId(boolean hasDeclarator) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTDeclarator declarator;
if(hasDeclarator)
declarator = (IASTDeclarator) astStack.pop();
else {
declarator = nodeFactory.newDeclarator(nodeFactory.newName());
- setOffsetAndLength(declarator, parser.getRightIToken().getEndOffset(), 0);
+ ParserUtil.setOffsetAndLength(declarator, stream.getRightIToken().getEndOffset(), 0);
}
IASTDeclSpecifier declSpecifier = (IASTDeclSpecifier) astStack.pop();
IASTTypeId typeId = nodeFactory.newTypeId(declSpecifier, declarator);
setOffsetAndLength(typeId);
astStack.push(typeId);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -1003,8 +686,6 @@ public abstract class BuildASTParserAction {
* | <openscope-ast> ptr_operator_seq direct_declarator
*/
public void consumeDeclaratorWithPointer(boolean hasDeclarator) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTDeclarator decl;
if(hasDeclarator)
decl = (IASTDeclarator) astStack.pop();
@@ -1016,8 +697,6 @@ public abstract class BuildASTParserAction {
setOffsetAndLength(decl);
astStack.push(decl);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -1030,8 +709,6 @@ public abstract class BuildASTParserAction {
* a default value without also specifying a named declarator
*/
public void consumeDeclaratorWithInitializer(boolean hasDeclarator) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTInitializer initializer = (IASTInitializer) astStack.pop();
IASTDeclarator declarator;
@@ -1047,10 +724,21 @@ public abstract class BuildASTParserAction {
declarator.setInitializer(initializer);
setOffsetAndLength(declarator); // adjust the length to include the initializer
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
+
+ /**
+ * asm_definition
+ * ::= 'asm' '(' 'stringlit' ')' ';'
+ */
+ public void consumeDeclarationASM() {
+ String s = stream.getRuleTokens().get(2).toString();
+ IASTASMDeclaration asm = nodeFactory.newASMDeclaration(s);
+
+ setOffsetAndLength(asm);
+ astStack.push(asm);
+ }
+
/**
@@ -1058,15 +746,11 @@ public abstract class BuildASTParserAction {
* | declaration_specifiers abstract_declarator
*/
public void consumeParameterDeclaration() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTDeclarator declarator = (IASTDeclarator) astStack.pop();
IASTDeclSpecifier declSpec = (IASTDeclSpecifier) astStack.pop();
IASTParameterDeclaration declaration = nodeFactory.newParameterDeclaration(declSpec, declarator);
setOffsetAndLength(declaration);
astStack.push(declaration);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -1074,25 +758,21 @@ public abstract class BuildASTParserAction {
* parameter_declaration ::= declaration_specifiers
*/
public void consumeParameterDeclarationWithoutDeclarator() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
// offsets need to be calculated differently in this case
- final int endOffset = parser.getRightIToken().getEndOffset();
+ final int endOffset = stream.getRightIToken().getEndOffset();
IASTName name = nodeFactory.newName();
- setOffsetAndLength(name, endOffset, 0);
+ ParserUtil.setOffsetAndLength(name, endOffset, 0);
// it appears that a declarator is always required in the AST here
IASTDeclarator declarator = nodeFactory.newDeclarator(name);
- setOffsetAndLength(declarator, endOffset, 0);
+ ParserUtil.setOffsetAndLength(declarator, endOffset, 0);
IASTDeclSpecifier declSpec = (IASTDeclSpecifier) astStack.pop();
IASTParameterDeclaration declaration = nodeFactory.newParameterDeclaration(declSpec, declarator);
setOffsetAndLength(declaration);
astStack.push(declaration);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -1146,15 +826,11 @@ public abstract class BuildASTParserAction {
* direct_declarator ::= '(' declarator ')'
*/
public void consumeDirectDeclaratorBracketed() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTDeclarator nested = (IASTDeclarator) astStack.pop();
IASTDeclarator declarator = nodeFactory.newDeclarator(nodeFactory.newName());
declarator.setNestedDeclarator(nested);
setOffsetAndLength(declarator);
astStack.push(declarator);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -1162,14 +838,10 @@ public abstract class BuildASTParserAction {
* direct_declarator ::= declarator_id_name
*/
public void consumeDirectDeclaratorIdentifier() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTName name = (IASTName) astStack.pop();
IASTDeclarator declarator = nodeFactory.newDeclarator(name);
setOffsetAndLength(declarator);
astStack.push(declarator);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -1179,14 +851,10 @@ public abstract class BuildASTParserAction {
* | '[' assignment_expression ']'
*/
public void consumeDirectDeclaratorArrayModifier(boolean hasAssignmentExpr) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression expr = hasAssignmentExpr ? (IASTExpression)astStack.pop() : null;
IASTArrayModifier arrayModifier = nodeFactory.newArrayModifier(expr);
setOffsetAndLength(arrayModifier);
astStack.push(arrayModifier);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -1198,8 +866,6 @@ public abstract class BuildASTParserAction {
* Special care is taken for nested declarators.
*/
protected void addArrayModifier(IASTArrayModifier arrayModifier) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTDeclarator node = (IASTDeclarator) astStack.pop();
// Its a nested declarator so create an new ArrayDeclarator
@@ -1210,7 +876,7 @@ public abstract class BuildASTParserAction {
int offset = offset(nested);
int length = endOffset(arrayModifier) - offset;
- setOffsetAndLength(declarator, offset, length);
+ ParserUtil.setOffsetAndLength(declarator, offset, length);
declarator.addArrayModifier(arrayModifier);
astStack.push(declarator);
@@ -1230,13 +896,11 @@ public abstract class BuildASTParserAction {
int offset = offset(name);
int length = endOffset(arrayModifier) - offset;
- setOffsetAndLength(decl, offset, length);
+ ParserUtil.setOffsetAndLength(decl, offset, length);
decl.addArrayModifier(arrayModifier);
astStack.push(decl);
}
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -1254,7 +918,7 @@ public abstract class BuildASTParserAction {
declarator.setNestedDeclarator(decl);
declarator.setName(nodeFactory.newName());
int offset = offset(decl);
- setOffsetAndLength(declarator, offset, endOffset - offset);
+ ParserUtil.setOffsetAndLength(declarator, offset, endOffset - offset);
astStack.push(declarator);
}
else {
@@ -1270,14 +934,12 @@ public abstract class BuildASTParserAction {
}
int offset = offset(name); // TODO
- setOffsetAndLength(declarator, offset, endOffset - offset);
+ ParserUtil.setOffsetAndLength(declarator, offset, endOffset - offset);
astStack.push(declarator);
}
-
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
+ // TODO why is this here
// /**
// * direct_declarator ::= direct_declarator array_modifier
// * consume the direct_declarator part and add the array modifier
@@ -1289,14 +951,13 @@ public abstract class BuildASTParserAction {
// addArrayModifier(arrayModifier);
// }
+
/**
* direct_abstract_declarator
* ::= array_modifier
* | direct_abstract_declarator array_modifier
*/
public void consumeDirectDeclaratorArrayDeclarator(boolean hasDeclarator) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTArrayModifier arrayModifier = (IASTArrayModifier) astStack.pop();
if(hasDeclarator) {
@@ -1307,8 +968,6 @@ public abstract class BuildASTParserAction {
decl.addArrayModifier(arrayModifier);
setOffsetAndLength(decl);
astStack.push(decl);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
}
@@ -1320,9 +979,7 @@ public abstract class BuildASTParserAction {
* | 'enum' enum_identifier '{' <openscope> enumerator_list_opt '}'
*/
public void consumeTypeSpecifierEnumeration(boolean hasIdent) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IASTName name = (hasIdent) ? createName(parser.getRuleTokens().get(1)) : nodeFactory.newName();
+ IASTName name = (hasIdent) ? createName(stream.getRuleTokens().get(1)) : nodeFactory.newName();
IASTEnumerationSpecifier enumSpec = nodeFactory.newEnumerationSpecifier(name);
@@ -1331,8 +988,6 @@ public abstract class BuildASTParserAction {
setOffsetAndLength(enumSpec);
astStack.push(enumSpec);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -1341,9 +996,7 @@ public abstract class BuildASTParserAction {
* | enum_identifier '=' constant_expression
*/
public void consumeEnumerator(boolean hasInitializer) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IASTName name = createName(parser.getLeftIToken());
+ IASTName name = createName(stream.getLeftIToken());
IASTExpression value = null;
if(hasInitializer)
@@ -1352,33 +1005,48 @@ public abstract class BuildASTParserAction {
IASTEnumerator enumerator = nodeFactory.newEnumerator(name, value);
setOffsetAndLength(enumerator);
astStack.push(enumerator);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
+ private int initializerListNestingLevel = 0;
+
+ public void initializerListStart() {
+ initializerListNestingLevel++;
+ }
+
+ public void initializerListEnd() {
+ initializerListNestingLevel--;
+ }
+
/**
* initializer ::= assignment_expression
*/
public void consumeInitializer() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression expr = (IASTExpression) astStack.pop();
+ if(discardInitializer(expr)) {
+ astStack.push(null);
+ return;
+ }
+
IASTInitializerExpression initializer = nodeFactory.newInitializerExpression(expr);
- setOffsetAndLength(initializer);
- astStack.push(initializer);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
+ setOffsetAndLength(initializer);
+ astStack.push(initializer);
}
+ private boolean discardInitializer(IASTExpression expression) {
+ return initializerListNestingLevel > 0
+ && "true".equals(properties.get(LRParserProperties.SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS)) //$NON-NLS-1$
+ && !ASTQueries.canContainName(expression);
+ }
+
+
+
/**
* initializer ::= '{' <openscope> initializer_list '}'
* | '{' <openscope> initializer_list ',' '}'
*/
public void consumeInitializerList() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTInitializerList list = nodeFactory.newInitializerList();
for(Object o : astStack.closeScope())
@@ -1386,20 +1054,18 @@ public abstract class BuildASTParserAction {
setOffsetAndLength(list);
astStack.push(list);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
+
+
/**
* struct_declarator
* ::= ':' constant_expression
* | declarator ':' constant_expression
*/
public void consumeBitField(boolean hasDeclarator) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression expr = (IASTExpression)astStack.pop();
IASTName name;
@@ -1411,20 +1077,15 @@ public abstract class BuildASTParserAction {
IASTFieldDeclarator fieldDecl = nodeFactory.newFieldDeclarator(name, expr);
setOffsetAndLength(fieldDecl);
astStack.push(fieldDecl);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
-
-
+
/**
* statement ::= ERROR_TOKEN
*/
public void consumeStatementProblem() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- consumeProblem(nodeFactory.newProblemStatement());
+ consumeProblem(nodeFactory.newProblemStatement(null));
}
/**
@@ -1432,18 +1093,14 @@ public abstract class BuildASTParserAction {
* constant_expression ::= ERROR_TOKEN
*/
public void consumeExpressionProblem() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- consumeProblem(nodeFactory.newProblemExpression());
+ consumeProblem(nodeFactory.newProblemExpression(null));
}
/**
* external_declaration ::= ERROR_TOKEN
*/
public void consumeDeclarationProblem() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- consumeProblem(nodeFactory.newProblemDeclaration());
+ consumeProblem(nodeFactory.newProblemDeclaration(null));
}
@@ -1453,8 +1110,6 @@ public abstract class BuildASTParserAction {
setOffsetAndLength(problem);
setOffsetAndLength((ASTNode)problemHolder);
astStack.push(problemHolder);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
} \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/IASTNodeFactory.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/INodeFactory.java
index 4b43b75ee1..da55f1d7c9 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/IASTNodeFactory.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/INodeFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2009 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
@@ -8,8 +8,10 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
+
package org.eclipse.cdt.core.dom.lrparser.action;
+
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
@@ -18,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
+import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
@@ -33,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
@@ -45,13 +49,16 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTPointer;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTProblemExpression;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
@@ -62,24 +69,54 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
-import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
-import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
+import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
+import org.eclipse.cdt.core.parser.IScanner;
/**
- * Abstract factory interface for creating AST node objects.
+ * Factory for creating AST nodes. This interface contains factory methods
+ * for nodes that are available for both C and C++.
+ *
+ * Extending interfaces should use covariant return types where appropriate to
+ * allow the construction of language-specific versions of certain nodes.
+ *
+ * Most methods accept child nodes as parameters when constructing a new node.
+ * For convenience it is always allowed to pass null for any of these parameters.
+ * In this case the newly constructed node may be initialized using its
+ * set() and add() methods instead.
+ *
+ * Nodes created by this factory are not frozen, i.e. for any node created by this
+ * factory the following holds <code> node.isFrozen() == false </code>.
+ *
+ * None of the factory methods should return null.
*
* @author Mike Kucera
+ * @since 5.1
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
*/
-@SuppressWarnings("restriction")
-public interface IASTNodeFactory {
-
- public IASTName newName(char[] name);
+public interface INodeFactory {
+ /**
+ * Creates a "dummy" name using an empty char array.
+ */
public IASTName newName();
+
+ public IASTName newName(char[] name);
+
+ /**
+ * @deprecated use {@link #newTranslationUnit(IScanner)}, instead.
+ */
+ @Deprecated
+ public IASTTranslationUnit newTranslationUnit();
- // TODO this should return IASTCompletionNode
- public ASTCompletionNode newCompletionNode(String prefix, IASTTranslationUnit tu);
+ /**
+ * Creates a new translation unit that cooperates with the given scanner in order
+ * to track macro-expansions and location information.
+ * @param scanner the preprocessor the translation unit interacts with.
+ * @since 5.2
+ */
+ public IASTTranslationUnit newTranslationUnit(IScanner scanner);
public IASTLiteralExpression newLiteralExpression(int kind, String rep);
@@ -99,6 +136,8 @@ public interface IASTNodeFactory {
public IASTConditionalExpression newConditionalExpession(IASTExpression expr1, IASTExpression expr2, IASTExpression expr3);
+ //public IASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer);
+
public IASTLabelStatement newLabelStatement(IASTName name, IASTStatement nestedStatement);
public IASTCaseStatement newCaseStatement(IASTExpression expr);
@@ -111,7 +150,7 @@ public interface IASTNodeFactory {
public IASTCompoundStatement newCompoundStatement();
- public IASTSwitchStatement newSwitchStatment(IASTExpression controller, IASTStatement body);
+ public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body);
public IASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause);
@@ -146,18 +185,16 @@ public interface IASTNodeFactory {
public IASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
IASTFunctionDeclarator declarator, IASTStatement bodyStatement);
-
- public IASTTranslationUnit newTranslationUnit();
public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name);
public IASTASMDeclaration newASMDeclaration(String assembly);
- public IASTProblemDeclaration newProblemDeclaration();
+ public IASTProblemDeclaration newProblemDeclaration(IASTProblem problem);
- public IASTProblemStatement newProblemStatement();
+ public IASTProblemStatement newProblemStatement(IASTProblem problem);
- public IASTProblemExpression newProblemExpression();
+ public IASTProblemExpression newProblemExpression(IASTProblem problem);
public IASTProblem newProblem(int id, char[] arg, boolean error);
@@ -174,11 +211,17 @@ public interface IASTNodeFactory {
public IASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator);
public IASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize);
+
+ public IASTSimpleDeclSpecifier newSimpleDeclSpecifier();
- public IASTAmbiguousStatement newAmbiguousStatement(IASTStatement... statements);
+ public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement);
- public IASTAmbiguousExpression newAmbiguousExpression(IASTExpression... expressions);
-
- public IASTDeclSpecifier newSimpleDeclSpecifier();
+ public IASTPointer newPointer();
+
+ public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner);
+ public IASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name);
+
+ public IASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
+
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ISecondaryParserFactory.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ISecondaryParserFactory.java
new file mode 100644
index 0000000000..5cee6bea4a
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ISecondaryParserFactory.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.lrparser.action;
+
+import java.util.Map;
+
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.lrparser.ISecondaryParser;
+
+
+/**
+ * Some ambiguities are resolved by spawning a secondary parser
+ * to re-parse a sequence of tokens using a modified grammar.
+ * This factory is used to create these secondary parsers.
+ *
+ * @author Mike Kucera
+ */
+public interface ISecondaryParserFactory {
+
+
+ /**
+ * Get the parser that will recognize expressions.
+ */
+ ISecondaryParser<IASTExpression> getExpressionParser(ITokenStream stream, Map<String,String> properties);
+
+
+ /**
+ * Expression parser that does not recognize cast expressions,
+ * used to disambiguate casts.
+ */
+ ISecondaryParser<IASTExpression> getNoCastExpressionParser(ITokenStream stream, Map<String,String> properties);
+
+
+ /**
+ * Expression parser that treats all sizeof and typeid expressions
+ * as unary expressions.
+ */
+ ISecondaryParser<IASTExpression> getSizeofExpressionParser(ITokenStream stream, Map<String,String> properties);
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParserActionTokenProvider.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenStream.java
index 5ef0f12631..9012e63c9a 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParserActionTokenProvider.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenStream.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2009 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
@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.core.dom.lrparser;
+package org.eclipse.cdt.core.dom.lrparser.action;
import java.util.List;
@@ -28,7 +28,7 @@ import lpg.lpgjavaruntime.IToken;
*
* @author Mike Kucera
*/
-public interface IParserActionTokenProvider {
+public interface ITokenStream {
/**
* Returns the tokens that were parsed to recognized
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ParserUtil.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ParserUtil.java
new file mode 100644
index 0000000000..cdc34e09fa
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ParserUtil.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.lrparser.action;
+
+import java.util.Arrays;
+import java.util.List;
+
+import lpg.lpgjavaruntime.IToken;
+
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+
+@SuppressWarnings("restriction")
+public final class ParserUtil {
+
+ private ParserUtil() {}
+
+
+ public static int offset(IToken token) {
+ return token.getStartOffset();
+ }
+
+ public static int offset(IASTNode node) {
+ return ((ASTNode)node).getOffset();
+ }
+
+ public static int length(IToken token) {
+ return endOffset(token) - offset(token);
+ }
+
+ public static int length(IASTNode node) {
+ return ((ASTNode)node).getLength();
+ }
+
+ public static int endOffset(IASTNode node) {
+ return offset(node) + length(node);
+ }
+
+ public static int endOffset(IToken token) {
+ return token.getEndOffset();
+ }
+
+
+
+
+ public static void setOffsetAndLength(IASTNode node, IToken token) {
+ ((ASTNode)node).setOffsetAndLength(offset(token), length(token));
+ }
+
+ public static void setOffsetAndLength(IASTNode node, int offset, int length) {
+ ((ASTNode)node).setOffsetAndLength(offset, length);
+ }
+
+ public static void setOffsetAndLength(IASTNode node, IASTNode from) {
+ setOffsetAndLength(node, offset(from), length(from));
+ }
+
+ // CHANGED removed getLookupKey() replaced with toCharArray()
+ public static boolean isSameName(IASTName name1, IASTName name2) {
+ return Arrays.equals(name1.toCharArray(), name2.toCharArray());
+ }
+
+
+ /**
+ * Allows simple pattern match testing of lists of tokens.
+ *
+ * @throws NullPointerException if source or pattern is null
+ */
+ public static boolean matchTokens(List<IToken> source, ITokenMap tokenMap, Integer ... pattern) {
+ if(source.size() != pattern.length) // throws NPE if either parameter is null
+ return false;
+
+ for(int i = 0, n = pattern.length; i < n; i++) {
+ if(tokenMap.mapKind(source.get(i).getKind()) != pattern[i].intValue())
+ return false;
+ }
+ return true;
+ }
+
+
+ /**
+ * Finds the tokens in the given list that are between startOffset and endOffset.
+ * Note, the offsets have to be exact.
+ */
+ public static List<IToken> tokenOffsetSubList(List<IToken> tokens, int startOffset, int endOffset) {
+ int first = 0, last = 0;
+ int i = 0;
+ for(IToken t : tokens) {
+ if(offset(t) == startOffset) {
+ first = i;
+ }
+ if(endOffset(t) == endOffset) {
+ last = i;
+ break;
+ }
+ i++;
+ }
+ return tokens.subList(first, last + 1);
+ }
+
+
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99BuildASTParserAction.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99BuildASTParserAction.java
index 6d5589cefa..65c5c4b702 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99BuildASTParserAction.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99BuildASTParserAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2009 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
@@ -11,6 +11,7 @@
package org.eclipse.cdt.core.dom.lrparser.action.c99;
+import static org.eclipse.cdt.core.dom.lrparser.action.ParserUtil.*;
import static org.eclipse.cdt.internal.core.dom.lrparser.c99.C99Parsersym.*;
import java.util.Collections;
@@ -18,6 +19,7 @@ import java.util.List;
import lpg.lpgjavaruntime.IToken;
+import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@@ -41,7 +43,6 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
@@ -56,18 +57,20 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
-import org.eclipse.cdt.core.dom.lrparser.IParser;
-import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
import org.eclipse.cdt.core.dom.lrparser.action.BuildASTParserAction;
+import org.eclipse.cdt.core.dom.lrparser.action.ISecondaryParserFactory;
import org.eclipse.cdt.core.dom.lrparser.action.ITokenMap;
+import org.eclipse.cdt.core.dom.lrparser.action.ITokenStream;
+import org.eclipse.cdt.core.dom.lrparser.action.ParserUtil;
+import org.eclipse.cdt.core.dom.lrparser.action.ScopedStack;
import org.eclipse.cdt.core.dom.lrparser.action.TokenMap;
import org.eclipse.cdt.core.parser.util.CollectionUtils;
-import org.eclipse.cdt.core.parser.util.DebugUtil;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.C99ExpressionParser;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.C99NoCastExpressionParser;
import org.eclipse.cdt.internal.core.dom.lrparser.c99.C99Parsersym;
-import org.eclipse.cdt.internal.core.dom.lrparser.c99.C99SizeofExpressionParser;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
+import org.eclipse.cdt.internal.core.dom.parser.c.CASTAmbiguousExpression;
+import org.eclipse.cdt.internal.core.dom.parser.c.CASTAmbiguousStatement;
/**
* Semantic actions called by the C99 parser to build an AST.
@@ -80,15 +83,16 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
private final ITokenMap tokenMap;
/** Used to create the AST node objects */
- protected final IC99ASTNodeFactory nodeFactory;
+ protected final ICNodeFactory nodeFactory;
/**
* @param parser
* @param orderedTerminalSymbols When an instance of this class is created for a parser
* that parsers token kinds will be mapped back to the base C99 parser's token kinds.
*/
- public C99BuildASTParserAction(IC99ASTNodeFactory nodeFactory, IParserActionTokenProvider parser, IASTTranslationUnit tu) {
- super(nodeFactory, parser, tu);
+ public C99BuildASTParserAction(ITokenStream parser, ScopedStack<Object> astStack, ICNodeFactory nodeFactory, ISecondaryParserFactory parserFactory) {
+ super(parser, astStack, nodeFactory, parserFactory);
+
this.nodeFactory = nodeFactory;
this.tokenMap = new TokenMap(C99Parsersym.orderedTerminalSymbols, parser.getOrderedTerminalSymbols());
}
@@ -109,19 +113,10 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
return baseKind(token) == TK_identifier;
}
- @Override
- protected IParser getExpressionParser() {
- return new C99ExpressionParser(parser.getOrderedTerminalSymbols());
- }
-
- @Override
- protected IParser getNoCastExpressionParser() {
- return new C99NoCastExpressionParser(parser.getOrderedTerminalSymbols());
- }
@Override
- protected IParser getSizeofExpressionParser() {
- return new C99SizeofExpressionParser(parser.getOrderedTerminalSymbols());
+ protected IASTName createName(char[] image) {
+ return nodeFactory.newName(image);
}
@@ -129,8 +124,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* Start of semantic actions.
********************************************************************/
-
-
/**
@@ -138,57 +131,25 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* postfix_expression ::= postfix_expression '->' ident
*/
public void consumeExpressionFieldReference(boolean isPointerDereference) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IASTName name = createName(parser.getRightIToken());
+ IASTName name = createName(stream.getRightIToken());
IASTExpression owner = (IASTExpression) astStack.pop();
- IASTFieldReference expr = nodeFactory.newFieldReference(name, owner, isPointerDereference);
+ IASTFieldReference expr = nodeFactory.newFieldReference(name, owner);
+ expr.setIsPointerDereference(isPointerDereference);
setOffsetAndLength(expr);
astStack.push(expr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
/**
- * postfix_expression ::= '(' type_name ')' '{' <openscope> initializer_list '}'
- * postfix_expression ::= '(' type_name ')' '{' <openscope> initializer_list ',' '}'
+ * postfix_expression ::= '(' type_id ')' initializer_list
*/
public void consumeExpressionTypeIdInitializer() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- consumeInitializerList(); // closes the scope
IASTInitializerList list = (IASTInitializerList) astStack.pop();
IASTTypeId typeId = (IASTTypeId) astStack.pop();
- ICASTTypeIdInitializerExpression expr = nodeFactory.newCTypeIdInitializerExpression(typeId, list);
+ ICASTTypeIdInitializerExpression expr = nodeFactory.newTypeIdInitializerExpression(typeId, list);
setOffsetAndLength(expr);
astStack.push(expr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
- }
-
-// /**
-// * Lots of rules, no need to list them.
-// * @param operator From IASTUnaryExpression
-// */
-// public void consumeExpressionSizeofTypeId() {
-// if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-//
-// IASTTypeId typeId = (IASTTypeId) astStack.pop();
-// IASTTypeIdExpression expr = nodeFactory.newTypeIdExpression(IASTTypeIdExpression.op_sizeof, typeId);
-// setOffsetAndLength(expr);
-//
-// // try parsing as an expression to resolve ambiguities
-// C99SizeofExpressionParser secondaryParser = new C99SizeofExpressionParser(C99Parsersym.orderedTerminalSymbols);
-// IASTNode alternateExpr = runSecondaryParser(secondaryParser);
-//
-// if(alternateExpr == null || alternateExpr instanceof IASTProblemExpression)
-// astStack.push(expr);
-// else
-// astStack.push(nodeFactory.newAmbiguousExpression(expr, (IASTExpression)alternateExpr));
-//
-// if(TRACE_AST_STACK) System.out.println(astStack);
-// }
+ }
/**
@@ -199,7 +160,7 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* Object as the type of the specifier, so that it may be overridden in subclasses
* and used with arbitrary objects as the specifier.
*/
- protected void setSpecifier(ICASTDeclSpecifier node, Object specifier) {
+ public void setSpecifier(ICASTDeclSpecifier node, Object specifier) {
if(!(specifier instanceof IToken))
return;
IToken token = (IToken)specifier;
@@ -270,11 +231,9 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
*/
public void consumeDirectDeclaratorModifiedArrayModifier(boolean isStatic,
boolean isVarSized, boolean hasTypeQualifierList, boolean hasAssignmentExpr) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
assert isStatic || isVarSized || hasTypeQualifierList;
- ICASTArrayModifier arrayModifier = nodeFactory.newModifiedArrayModifier();
+ ICASTArrayModifier arrayModifier = nodeFactory.newArrayModifier(null);
// consume all the stuff between the square brackets into an array modifier
arrayModifier.setStatic(isStatic);
@@ -288,8 +247,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(arrayModifier);
astStack.push(arrayModifier);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -298,13 +255,11 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* direct_declarator ::= direct_declarator '(' <openscope> identifier_list ')'
*/
public void consumeDirectDeclaratorFunctionDeclaratorKnR() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- ICASTKnRFunctionDeclarator declarator = nodeFactory.newCKnRFunctionDeclarator();
+ ICASTKnRFunctionDeclarator declarator = nodeFactory.newKnRFunctionDeclarator();
IASTName[] names = astStack.topScope().toArray(new IASTName[0]);
declarator.setParameterNames(names);
astStack.closeScope();
- int endOffset = endOffset(parser.getRightIToken());
+ int endOffset = endOffset(stream.getRightIToken());
addFunctionModifier(declarator, endOffset);
}
@@ -315,9 +270,7 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* | identifier_list ',' 'identifier'
*/
public void consumeIdentifierKnR() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IASTName name = createName(parser.getRightIToken());
+ IASTName name = createName(stream.getRightIToken());
astStack.push(name);
}
@@ -329,14 +282,10 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* | pointer '*'
*/
public void consumePointer() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IASTPointer pointer = nodeFactory.newCPointer();
- IToken star = parser.getRightIToken();
- setOffsetAndLength(pointer, star);
+ IASTPointer pointer = nodeFactory.newPointer();
+ IToken star = stream.getRightIToken();
+ ParserUtil.setOffsetAndLength(pointer, star);
astStack.push(pointer);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -345,9 +294,7 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* | pointer '*' <openscope> type_qualifier_list
*/
public void consumePointerTypeQualifierList() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- ICASTPointer pointer = nodeFactory.newCPointer();
+ ICASTPointer pointer = nodeFactory.newPointer();
for(Object o : astStack.closeScope()) {
IToken token = (IToken)o;
@@ -361,8 +308,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(pointer);
astStack.push(pointer);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -375,8 +320,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* | direct_abstract_declarator '(' <openscope> parameter_type_list ')'
*/
public void consumeDirectDeclaratorFunctionDeclarator(boolean hasDeclarator, boolean hasParameters) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTName name = nodeFactory.newName();
IASTStandardFunctionDeclarator declarator = nodeFactory.newFunctionDeclarator(name);
@@ -389,14 +332,12 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
}
if(hasDeclarator) {
- addFunctionModifier(declarator, endOffset(parser.getRightIToken()));
+ addFunctionModifier(declarator, endOffset(stream.getRightIToken()));
}
else {
setOffsetAndLength(declarator);
astStack.push(declarator);
}
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -405,18 +346,14 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* designated_initializer ::= <openscope> designation initializer
*/
public void consumeInitializerDesignated() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTInitializer initializer = (IASTInitializer)astStack.pop();
- ICASTDesignatedInitializer result = nodeFactory.newCDesignatedInitializer(initializer);
+ ICASTDesignatedInitializer result = nodeFactory.newDesignatedInitializer(initializer);
for(Object o : astStack.closeScope())
result.addDesignator((ICASTDesignator)o);
setOffsetAndLength(result);
astStack.push(result);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -424,14 +361,10 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* designator ::= '[' constant_expression ']'
*/
public void consumeDesignatorArray() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression expr = (IASTExpression) astStack.pop();
- ICASTArrayDesignator designator = nodeFactory.newCArrayDesignator(expr);
+ ICASTArrayDesignator designator = nodeFactory.newArrayDesignator(expr);
setOffsetAndLength(designator);
astStack.push(designator);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -439,14 +372,10 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* designator ::= '.' 'identifier'
*/
public void consumeDesignatorField() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IASTName name = createName(parser.getRightIToken());
- ICASTFieldDesignator designator = nodeFactory.newCFieldDesignator(name);
+ IASTName name = createName(stream.getRightIToken());
+ ICASTFieldDesignator designator = nodeFactory.newFieldDesignator(name);
setOffsetAndLength(designator);
astStack.push(designator);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -454,17 +383,13 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* declaration_specifiers ::= <openscope> simple_declaration_specifiers
*/
public void consumeDeclarationSpecifiersSimple() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- ICASTSimpleDeclSpecifier declSpec = nodeFactory.newCSimpleDeclSpecifier();
+ ICASTSimpleDeclSpecifier declSpec = nodeFactory.newSimpleDeclSpecifier();
for(Object specifier : astStack.closeScope())
setSpecifier(declSpec, specifier);
setOffsetAndLength(declSpec);
astStack.push(declSpec);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -473,8 +398,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* declaration_specifiers ::= <openscope> enum_declaration_specifiers
*/
public void consumeDeclarationSpecifiersStructUnionEnum() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
List<Object> topScope = astStack.closeScope();
ICASTDeclSpecifier declSpec = CollectionUtils.findFirstAndRemove(topScope, ICASTDeclSpecifier.class);
@@ -484,8 +407,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(declSpec);
astStack.push(declSpec);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -493,9 +414,7 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* declaration_specifiers ::= <openscope> typdef_name_declaration_specifiers
*/
public void consumeDeclarationSpecifiersTypedefName() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- ICASTTypedefNameSpecifier declSpec = nodeFactory.newCTypedefNameSpecifier();
+ ICASTTypedefNameSpecifier declSpec = nodeFactory.newTypedefNameSpecifier(null);
for(Object o : astStack.topScope()) {
if(o instanceof IToken) {
@@ -504,7 +423,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
int kind = baseKind(token);
if(kind == TK_identifier || kind == TK_Completion) {
IASTName name = createName(token);
- //name.setBinding(binding);
declSpec.setName(name);
}
else {
@@ -516,8 +434,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
astStack.closeScope();
setOffsetAndLength(declSpec);
astStack.push(declSpec);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -527,12 +443,10 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* declaration ::= declaration_specifiers ';'
*/
public void consumeDeclarationSimple(boolean hasDeclaratorList) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
List<Object> declarators = (hasDeclaratorList) ? astStack.closeScope() : Collections.emptyList();
IASTDeclSpecifier declSpecifier = (IASTDeclSpecifier) astStack.pop();
- List<IToken> ruleTokens = parser.getRuleTokens();
+ List<IToken> ruleTokens = stream.getRuleTokens();
if(ruleTokens.size() == 1 && baseKind(ruleTokens.get(0)) == TK_EndOfCompletion)
return; // do not generate nodes for extra EOC tokens
@@ -543,8 +457,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(declaration);
astStack.push(declaration);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -555,20 +467,15 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* TODO: doesn't the declaration need a name?
*/
public void consumeDeclarationEmpty() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
// Don't generate declaration nodes for extra EOC tokens
- // TODO: the token type must be converted
- if(baseKind(parser.getLeftIToken()) == C99Parsersym.TK_EndOfCompletion)
+ if(baseKind(stream.getLeftIToken()) == C99Parsersym.TK_EndOfCompletion)
return;
- IASTDeclSpecifier declSpecifier = nodeFactory.newCSimpleDeclSpecifier();
+ IASTDeclSpecifier declSpecifier = nodeFactory.newSimpleDeclSpecifier();
IASTSimpleDeclaration declaration = nodeFactory.newSimpleDeclaration(declSpecifier);
setOffsetAndLength(declSpecifier);
setOffsetAndLength(declaration);
astStack.push(declaration);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -582,8 +489,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* a struct declarator is a regular declarator plus bit fields
*/
public void consumeStructDeclaration(boolean hasDeclaration) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
consumeDeclarationSimple(hasDeclaration); // TODO this is ok as long as bit fields implement IASTDeclarator (see consumeDeclaration())
}
@@ -597,20 +502,23 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
*
* @param key either k_struct or k_union from IASTCompositeTypeSpecifier
*/
- public void consumeTypeSpecifierComposite(boolean hasName, int key) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
+ public void consumeTypeSpecifierComposite(boolean hasName) {
+
+ int key = 0;
+ switch(baseKind(stream.getLeftIToken())) {
+ case TK_struct: key = IASTCompositeTypeSpecifier.k_struct;
+ case TK_union: key = IASTCompositeTypeSpecifier.k_union;
+ }
- IASTName name = (hasName) ? createName(parser.getRuleTokens().get(1)) : nodeFactory.newName();
+ IASTName name = (hasName) ? createName(stream.getRuleTokens().get(1)) : nodeFactory.newName();
- ICASTCompositeTypeSpecifier typeSpec = nodeFactory.newCCompositeTypeSpecifier(key, name);
+ ICASTCompositeTypeSpecifier typeSpec = nodeFactory.newCompositeTypeSpecifier(key, name);
for(Object o : astStack.closeScope())
typeSpec.addMemberDeclaration((IASTDeclaration)o);
setOffsetAndLength(typeSpec);
astStack.push(typeSpec);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -622,14 +530,10 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* enum_specifier ::= 'enum' enum_identifier
*/
public void consumeTypeSpecifierElaborated(int kind) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IASTName name = createName(parser.getRuleTokens().get(1));
+ IASTName name = createName(stream.getRuleTokens().get(1));
IASTElaboratedTypeSpecifier typeSpec = nodeFactory.newElaboratedTypeSpecifier(kind, name);
setOffsetAndLength(typeSpec);
astStack.push(typeSpec);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -639,15 +543,11 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* iteration_statement ::= 'while' '(' expression ')' statement
*/
public void consumeStatementWhileLoop() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTStatement body = (IASTStatement) astStack.pop();
IASTExpression condition = (IASTExpression) astStack.pop();
IASTWhileStatement whileStatement = nodeFactory.newWhileStatement(condition, body);
setOffsetAndLength(whileStatement);
astStack.push(whileStatement);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -657,8 +557,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* ::= 'for' '(' expression_opt ';' expression_opt ';' expression_opt ')' statement
*/
public void consumeStatementForLoop() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTStatement body = (IASTStatement) astStack.pop();
// these two expressions may be null, see consumeExpressionOptional()
IASTExpression expr3 = (IASTExpression) astStack.pop();
@@ -676,25 +574,23 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
// bug 234463, fix for content assist to work in this case
int TK_EOC = TK_EndOfCompletion; // TODO: change this in the grammar file
- List<IToken> tokens = parser.getRuleTokens();
+ List<IToken> tokens = stream.getRuleTokens();
if(matchTokens(tokens, tokenMap,
TK_for, TK_LeftParen, TK_Completion, TK_EOC, TK_EOC, TK_EOC, TK_EOC)) {
IASTName name = createName(tokens.get(2));
IASTIdExpression idExpression = nodeFactory.newIdExpression(name);
- setOffsetAndLength(idExpression, offset(name), length(name));
+ ParserUtil.setOffsetAndLength(idExpression, offset(name), length(name));
initializer = nodeFactory.newExpressionStatement(idExpression);
- setOffsetAndLength(initializer, offset(name), length(name));
+ ParserUtil.setOffsetAndLength(initializer, offset(name), length(name));
}
if(node != null)
- setOffsetAndLength(initializer, offset(node), length(node));
+ ParserUtil.setOffsetAndLength(initializer, offset(node), length(node));
IASTForStatement forStat = nodeFactory.newForStatement(initializer, expr2, expr3, body);
setOffsetAndLength(forStat);
astStack.push(forStat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -703,21 +599,15 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* selection_statement ::= switch '(' expression ')' statement
*/
public void consumeStatementSwitch() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IASTStatement body = (IASTStatement) astStack.pop();
+ IASTStatement body = (IASTStatement) astStack.pop();
IASTExpression expr = (IASTExpression) astStack.pop();
- IASTSwitchStatement stat = nodeFactory.newSwitchStatment(expr, body);
+ IASTSwitchStatement stat = nodeFactory.newSwitchStatement(expr, body);
setOffsetAndLength(stat);
astStack.push(stat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
public void consumeStatementIf(boolean hasElse) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTStatement elseClause = null;
if(hasElse)
elseClause = (IASTStatement) astStack.pop();
@@ -728,8 +618,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
IASTIfStatement ifStatement = nodeFactory.newIfStatement(condition, thenClause, elseClause);
setOffsetAndLength(ifStatement);
astStack.push(ifStatement);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -742,8 +630,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* prevent a shift/reduce conflict in the grammar.
*/
public void consumeFunctionDefinition(boolean hasDeclSpecifiers) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace(String.valueOf(hasDeclSpecifiers));
-
IASTCompoundStatement body = (IASTCompoundStatement) astStack.pop();
IASTFunctionDeclarator decl = (IASTFunctionDeclarator) astStack.pop();
astStack.closeScope();
@@ -753,14 +639,12 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
declSpecifier = (IASTDeclSpecifier) astStack.pop();
}
else { // there are no decl specifiers, implicit int
- declSpecifier = nodeFactory.newCSimpleDeclSpecifier();
+ declSpecifier = nodeFactory.newSimpleDeclSpecifier();
}
IASTFunctionDefinition def = nodeFactory.newFunctionDefinition(declSpecifier, decl, body);
setOffsetAndLength(def);
astStack.push(def);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -771,8 +655,6 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
* <openscope> declaration_list compound_statement
*/
public void consumeFunctionDefinitionKnR() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTCompoundStatement body = (IASTCompoundStatement) astStack.pop();
IASTDeclaration[] declarations = astStack.topScope().toArray(new IASTDeclaration[0]);
@@ -792,7 +674,18 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
IASTFunctionDefinition def = nodeFactory.newFunctionDefinition(declSpecifier, decl, body);
setOffsetAndLength(def);
astStack.push(def);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
+
+
+
+ @Override
+ protected IASTAmbiguousExpression createAmbiguousExpression(IASTExpression... expressions) {
+ return new CASTAmbiguousExpression(expressions);
+ }
+
+
+ @Override
+ protected IASTAmbiguousStatement createAmbiguousStatement(IASTStatement... statements) {
+ return new CASTAmbiguousStatement(statements);
+ }
} \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99SecondaryParserFactory.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99SecondaryParserFactory.java
new file mode 100644
index 0000000000..45fe22320b
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99SecondaryParserFactory.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.lrparser.action.c99;
+
+import java.util.Map;
+
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.lrparser.ISecondaryParser;
+import org.eclipse.cdt.core.dom.lrparser.action.ISecondaryParserFactory;
+import org.eclipse.cdt.core.dom.lrparser.action.ITokenStream;
+import org.eclipse.cdt.internal.core.dom.lrparser.c99.C99ExpressionParser;
+import org.eclipse.cdt.internal.core.dom.lrparser.c99.C99NoCastExpressionParser;
+import org.eclipse.cdt.internal.core.dom.lrparser.c99.C99SizeofExpressionParser;
+
+public class C99SecondaryParserFactory implements ISecondaryParserFactory {
+
+ public static final C99SecondaryParserFactory DEFAULT_INSTANCE = new C99SecondaryParserFactory();
+
+ public static C99SecondaryParserFactory getDefault() {
+ return DEFAULT_INSTANCE;
+ }
+
+
+ public ISecondaryParser<IASTExpression> getExpressionParser(ITokenStream stream, Map<String,String> properties) {
+ return new C99ExpressionParser(stream, properties);
+ }
+
+ public ISecondaryParser<IASTExpression> getNoCastExpressionParser(ITokenStream stream, Map<String,String> properties) {
+ return new C99NoCastExpressionParser(stream, properties);
+ }
+
+ public ISecondaryParser<IASTExpression> getSizeofExpressionParser(ITokenStream stream, Map<String,String> properties) {
+ return new C99SizeofExpressionParser(stream, properties);
+ }
+} \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99ASTNodeFactory.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/CNodeFactory.java
index 1068c44a08..e6be5d7755 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99ASTNodeFactory.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/CNodeFactory.java
@@ -1,18 +1,18 @@
/*******************************************************************************
- * 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
+ * Copyright (c) 2006, 2009 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:
+ * Mike Kucera (IBM Corporation) - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
-import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
@@ -27,7 +27,6 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
-import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@@ -67,22 +66,22 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
+import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
+import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
-import org.eclipse.cdt.core.dom.lrparser.action.ASTCompletionNode;
-import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
-import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
+import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
+import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTASMDeclaration;
-import org.eclipse.cdt.internal.core.dom.parser.c.CASTAmbiguousExpression;
-import org.eclipse.cdt.internal.core.dom.parser.c.CASTAmbiguousStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTArrayDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTArrayDesignator;
-import org.eclipse.cdt.internal.core.dom.parser.c.CASTArrayModifier;
+import org.eclipse.cdt.internal.core.dom.parser.c.CASTArrayRangeDesignator;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTArraySubscriptExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTBinaryExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTBreakStatement;
@@ -90,6 +89,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CASTCaseStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTCastExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTCompositeTypeSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTCompoundStatement;
+import org.eclipse.cdt.internal.core.dom.parser.c.CASTCompoundStatementExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTConditionalExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTContinueStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTDeclarationStatement;
@@ -137,19 +137,35 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CASTTypeIdInitializerExpressio
import org.eclipse.cdt.internal.core.dom.parser.c.CASTTypedefNameSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTUnaryExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTWhileStatement;
+import org.eclipse.cdt.internal.core.dom.parser.c.GCCASTSimpleDeclSpecifier;
-@SuppressWarnings("restriction") // all AST node constructors are internal
/**
* Abstract factory implementation that creates AST nodes for C99.
* These can be overridden in subclasses to change the
* implementations of the nodes.
- *
- * @author Mike Kucera
*/
-public class C99ASTNodeFactory implements IC99ASTNodeFactory {
+@SuppressWarnings("restriction")
+public class CNodeFactory implements ICNodeFactory {
- public static final C99ASTNodeFactory DEFAULT_INSTANCE = new C99ASTNodeFactory();
+ private static final CNodeFactory DEFAULT_INSTANCE = new CNodeFactory();
+
+ public static CNodeFactory getDefault() {
+ return DEFAULT_INSTANCE;
+ }
+
+ public IASTTranslationUnit newTranslationUnit() {
+ return newTranslationUnit(null);
+ }
+ public IASTTranslationUnit newTranslationUnit(IScanner scanner) {
+ CASTTranslationUnit tu = new CASTTranslationUnit();
+
+ if (scanner != null) {
+ tu.setLocationResolver(scanner.getLocationResolver());
+ }
+ //tu.setASTNodeFactory(this);
+ return tu;
+ }
public IASTName newName(char[] name) {
return new CASTName(name);
@@ -159,13 +175,6 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTName();
}
- /**
- * TODO: this should return IASTCompletionNode
- */
- public ASTCompletionNode newCompletionNode(String prefix, IASTTranslationUnit tu) {
- return new ASTCompletionNode((prefix == null || prefix.length() == 0) ? null : prefix, tu);
- }
-
public IASTLiteralExpression newLiteralExpression(int kind, String rep) {
return new CASTLiteralExpression(kind, rep);
}
@@ -194,8 +203,8 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTExpressionList();
}
- public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner, boolean isPointerDereference) {
- return new CASTFieldReference(name, owner, isPointerDereference);
+ public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner) {
+ return new CASTFieldReference(name, owner);
}
public IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
@@ -206,8 +215,8 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTTypeIdExpression(operator, typeId);
}
- public ICASTTypeIdInitializerExpression newCTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializerList list) {
- return new CASTTypeIdInitializerExpression(typeId, list);
+ public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
+ return new CASTTypeIdInitializerExpression(typeId, initializer);
}
/**
@@ -229,23 +238,19 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTArrayDeclarator(name);
}
- public ICASTArrayModifier newModifiedArrayModifier() {
- return new CASTModifiedArrayModifier();
+ public ICASTArrayModifier newArrayModifier(IASTExpression expr) {
+ return new CASTModifiedArrayModifier(expr);
}
- public IASTArrayModifier newArrayModifier(IASTExpression expr) {
- return new CASTArrayModifier(expr);
- }
-
public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name) {
return new CASTFunctionDeclarator(name);
}
- public ICASTKnRFunctionDeclarator newCKnRFunctionDeclarator() {
+ public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator() {
return new CASTKnRFunctionDeclarator();
}
- public ICASTPointer newCPointer() {
+ public ICASTPointer newPointer() {
return new CASTPointer();
}
@@ -261,24 +266,20 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTInitializerList();
}
- public ICASTDesignatedInitializer newCDesignatedInitializer(IASTInitializer rhs) {
- return new CASTDesignatedInitializer(rhs);
+ public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializer operandInitializer) {
+ return new CASTDesignatedInitializer(operandInitializer);
}
- public ICASTArrayDesignator newCArrayDesignator(IASTExpression exp) {
+ public ICASTArrayDesignator newArrayDesignator(IASTExpression exp) {
return new CASTArrayDesignator(exp);
}
- public ICASTFieldDesignator newCFieldDesignator(IASTName name) {
+ public ICASTFieldDesignator newFieldDesignator(IASTName name) {
return new CASTFieldDesignator(name);
}
- public ICASTSimpleDeclSpecifier newCSimpleDeclSpecifier() {
- return new CASTSimpleDeclSpecifier();
- }
-
- public ICASTTypedefNameSpecifier newCTypedefNameSpecifier() {
- return new CASTTypedefNameSpecifier();
+ public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name) {
+ return new CASTTypedefNameSpecifier(name);
}
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
@@ -289,11 +290,11 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTFieldDeclarator(name, bitFieldSize);
}
- public ICASTCompositeTypeSpecifier newCCompositeTypeSpecifier(int key, IASTName name) {
+ public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) {
return new CASTCompositeTypeSpecifier(key, name);
}
- public IASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) {
+ public ICASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) {
return new CASTElaboratedTypeSpecifier(kind, name);
}
@@ -358,7 +359,7 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTDefaultStatement();
}
- public IASTSwitchStatement newSwitchStatment(IASTExpression controller, IASTStatement body) {
+ public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body) {
return new CASTSwitchStatement(controller, body);
}
@@ -371,47 +372,45 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTFunctionDefinition(declSpecifier, declarator, bodyStatement);
}
- public IASTProblemDeclaration newProblemDeclaration() {
- return new CASTProblemDeclaration();
+ public IASTProblemDeclaration newProblemDeclaration(IASTProblem problem) {
+ return new CASTProblemDeclaration(problem);
}
- public IASTProblemStatement newProblemStatement() {
- return new CASTProblemStatement();
+ public IASTProblemStatement newProblemStatement(IASTProblem problem) {
+ return new CASTProblemStatement(problem);
}
- public IASTProblemExpression newProblemExpression() {
- return new CASTProblemExpression();
+ public IASTProblemExpression newProblemExpression(IASTProblem problem) {
+ return new CASTProblemExpression(problem);
}
public IASTProblem newProblem(int id, char[] arg, boolean error) {
return new CASTProblem(id, arg, error);
}
- public IASTAmbiguousExpression newAmbiguousExpression(IASTExpression... expressions) {
- return new CASTAmbiguousExpression(expressions);
+ public IASTASMDeclaration newASMDeclaration(String assembly) {
+ return new CASTASMDeclaration(assembly);
}
- public IASTAmbiguousStatement newAmbiguousStatement(IASTStatement... statements) {
- return new CASTAmbiguousStatement(statements);
+ public ICASTEnumerationSpecifier newEnumerationSpecifier(IASTName name) {
+ return new CASTEnumerationSpecifier(name);
}
- public IASTTranslationUnit newTranslationUnit() {
- return new CASTTranslationUnit();
+ public ICASTSimpleDeclSpecifier newSimpleDeclSpecifier() {
+ return new CASTSimpleDeclSpecifier();
}
- public IASTASMDeclaration newASMDeclaration(String assembly) {
- return new CASTASMDeclaration(assembly);
+ public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) {
+ return new CASTCompoundStatementExpression(compoundStatement);
}
- public ICASTEnumerationSpecifier newEnumerationSpecifier(IASTName name) {
- return new CASTEnumerationSpecifier(name);
+ public IGCCASTArrayRangeDesignator newArrayRangeDesignatorGCC(IASTExpression floor, IASTExpression ceiling) {
+ return new CASTArrayRangeDesignator(floor, ceiling);
}
- public IASTDeclSpecifier newSimpleDeclSpecifier() {
- return newCSimpleDeclSpecifier();
+ public IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression) {
+ return new GCCASTSimpleDeclSpecifier(typeofExpression);
}
-
-
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/IC99ASTNodeFactory.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/IC99ASTNodeFactory.java
deleted file mode 100644
index 5b01c30a4d..0000000000
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/IC99ASTNodeFactory.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * 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
- *******************************************************************************/
-package org.eclipse.cdt.core.dom.lrparser.action.c99;
-
-import org.eclipse.cdt.core.dom.ast.IASTExpression;
-import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
-import org.eclipse.cdt.core.dom.ast.IASTInitializer;
-import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
-import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTTypeId;
-import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
-import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
-import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
-import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
-import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
-import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
-import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
-import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
-import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
-import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
-import org.eclipse.cdt.core.dom.lrparser.action.IASTNodeFactory;
-
-/**
- * Factory for AST nodes that are just used by C and not by C++.
- *
- * @author Mike Kucera
- */
-public interface IC99ASTNodeFactory extends IASTNodeFactory {
-
- public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner, boolean isPointerDereference);
-
- public ICASTTypeIdInitializerExpression newCTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializerList list);
-
- public ICASTArrayModifier newModifiedArrayModifier();
-
- public ICASTKnRFunctionDeclarator newCKnRFunctionDeclarator();
-
- public ICASTPointer newCPointer();
-
- public ICASTDesignatedInitializer newCDesignatedInitializer(IASTInitializer rhs);
-
- public ICASTArrayDesignator newCArrayDesignator(IASTExpression exp);
-
- public ICASTFieldDesignator newCFieldDesignator(IASTName name);
-
- public ICASTSimpleDeclSpecifier newCSimpleDeclSpecifier();
-
- public ICASTTypedefNameSpecifier newCTypedefNameSpecifier();
-
- public ICASTCompositeTypeSpecifier newCCompositeTypeSpecifier(int key, IASTName name);
-
-
-}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/ICNodeFactory.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/ICNodeFactory.java
new file mode 100644
index 0000000000..1cabd7871f
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/ICNodeFactory.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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
+ *******************************************************************************/
+
+package org.eclipse.cdt.core.dom.lrparser.action.c99;
+
+
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
+import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
+import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
+import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
+import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
+import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
+import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
+import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
+import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.lrparser.action.INodeFactory;
+
+/**
+ * Factory for AST nodes for the C programming language.
+ *
+ * @author Mike Kucera
+ * @since 5.1
+ *
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface ICNodeFactory extends INodeFactory {
+
+ public ICASTEnumerationSpecifier newEnumerationSpecifier(IASTName name);
+
+ public ICASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name);
+
+ public ICASTSimpleDeclSpecifier newSimpleDeclSpecifier();
+
+ public ICASTPointer newPointer();
+
+ public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name);
+
+ public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
+
+ public ICASTArrayModifier newArrayModifier(IASTExpression expr);
+
+ public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer);
+
+ public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator();
+
+ public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializer rhs);
+
+ public ICASTArrayDesignator newArrayDesignator(IASTExpression exp);
+
+ public ICASTFieldDesignator newFieldDesignator(IASTName name);
+
+ public IGCCASTArrayRangeDesignator newArrayRangeDesignatorGCC(IASTExpression floor, IASTExpression ceiling);
+
+ public IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression);
+} \ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java
index bd985d6304..9905b68b79 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2009 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
@@ -10,17 +10,21 @@
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.cpp;
+import static org.eclipse.cdt.core.dom.lrparser.action.ParserUtil.endOffset;
+import static org.eclipse.cdt.core.dom.lrparser.action.ParserUtil.length;
+import static org.eclipse.cdt.core.dom.lrparser.action.ParserUtil.matchTokens;
+import static org.eclipse.cdt.core.dom.lrparser.action.ParserUtil.offset;
import static org.eclipse.cdt.core.parser.util.CollectionUtils.findFirstAndRemove;
import static org.eclipse.cdt.core.parser.util.CollectionUtils.reverseIterable;
import static org.eclipse.cdt.internal.core.dom.lrparser.cpp.CPPParsersym.*;
+import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import lpg.lpgjavaruntime.IToken;
-import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
@@ -28,7 +32,6 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
-import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
@@ -37,16 +40,15 @@ import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTPointer;
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
-import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
@@ -60,6 +62,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
@@ -68,6 +71,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
@@ -86,21 +90,22 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
-import org.eclipse.cdt.core.dom.lrparser.IParser;
-import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
+import org.eclipse.cdt.core.dom.lrparser.ISecondaryParser;
import org.eclipse.cdt.core.dom.lrparser.LPGTokenAdapter;
import org.eclipse.cdt.core.dom.lrparser.action.BuildASTParserAction;
import org.eclipse.cdt.core.dom.lrparser.action.ITokenMap;
+import org.eclipse.cdt.core.dom.lrparser.action.ITokenStream;
+import org.eclipse.cdt.core.dom.lrparser.action.ParserUtil;
+import org.eclipse.cdt.core.dom.lrparser.action.ScopedStack;
import org.eclipse.cdt.core.dom.lrparser.action.TokenMap;
-import org.eclipse.cdt.core.parser.util.DebugUtil;
-import org.eclipse.cdt.internal.core.dom.lrparser.cpp.CPPExpressionParser;
-import org.eclipse.cdt.internal.core.dom.lrparser.cpp.CPPNoCastExpressionParser;
-import org.eclipse.cdt.internal.core.dom.lrparser.cpp.CPPNoFunctionDeclaratorParser;
import org.eclipse.cdt.internal.core.dom.lrparser.cpp.CPPParsersym;
-import org.eclipse.cdt.internal.core.dom.lrparser.cpp.CPPSizeofExpressionParser;
-import org.eclipse.cdt.internal.core.dom.lrparser.cpp.CPPTemplateTypeParameterParser;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
-import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTAmbiguousDeclarator;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTAmbiguousExpression;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTAmbiguousStatement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTAmbiguousTemplateArgument;
import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
/**
@@ -117,16 +122,24 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
private final ITokenMap tokenMap;
/** Used to create the AST node objects */
- protected final ICPPASTNodeFactory nodeFactory;
+ protected final ICPPNodeFactory nodeFactory;
+
+ protected final ICPPSecondaryParserFactory parserFactory;
+
+ /** Stack that provides easy access to the current class name, used to disambiguate declarators. */
+ protected final LinkedList<IASTName> classNames = new LinkedList<IASTName>();
+
/**
* @param parser
* @param orderedTerminalSymbols When an instance of this class is created for a parser
* that parsers token kinds will be mapped back to the base C99 parser's token kinds.
*/
- public CPPBuildASTParserAction(ICPPASTNodeFactory nodeFactory, IParserActionTokenProvider parser, IASTTranslationUnit tu) {
- super(nodeFactory, parser, tu);
+ public CPPBuildASTParserAction(ITokenStream parser, ScopedStack<Object> astStack, ICPPNodeFactory nodeFactory, ICPPSecondaryParserFactory parserFactory) {
+ super(parser, astStack, nodeFactory, parserFactory);
+
this.nodeFactory = nodeFactory;
+ this.parserFactory = parserFactory;
this.tokenMap = new TokenMap(CPPParsersym.orderedTerminalSymbols, parser.getOrderedTerminalSymbols());
}
@@ -145,58 +158,76 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
return baseKind(token) == TK_identifier;
}
-
- @Override
- protected IParser getExpressionParser() {
- return new CPPExpressionParser(parser.getOrderedTerminalSymbols());
- }
-
- @Override
- protected IParser getNoCastExpressionParser() {
- return new CPPNoCastExpressionParser(parser.getOrderedTerminalSymbols());
- }
-
@Override
- protected IParser getSizeofExpressionParser() {
- return new CPPSizeofExpressionParser(parser.getOrderedTerminalSymbols());
- }
-
- protected IParser getTemplateTypeParameterParser() {
- return new CPPTemplateTypeParameterParser(parser.getOrderedTerminalSymbols());
+ protected IASTName createName(char[] image) {
+ return nodeFactory.newName(image);
}
+
+
- protected IParser getNoFunctionDeclaratorParser() {
- return new CPPNoFunctionDeclaratorParser(parser.getOrderedTerminalSymbols());
+ public void consumeNewInitializer() {
+ if(astStack.peek() == null) { // if there is an empty set of parens
+ astStack.pop();
+ IASTExpression initializer = nodeFactory.newExpressionList();
+ setOffsetAndLength(initializer);
+ astStack.push(initializer);
+ }
}
-
+ // TODO can the new_array_expressions be removed? it looks like they parse as part of the type id
/**
* new_expression
* ::= dcolon_opt 'new' new_placement_opt new_type_id <openscope-ast> new_array_expressions_op new_initializer_opt
* | dcolon_opt 'new' new_placement_opt '(' type_id ')' <openscope-ast> new_array_expressions_op new_initializer_opt
*/
+ @SuppressWarnings("deprecation")
public void consumeExpressionNew(boolean isNewTypeId) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression initializer = (IASTExpression) astStack.pop(); // may be null
List<Object> arrayExpressions = astStack.closeScope();
IASTTypeId typeId = (IASTTypeId) astStack.pop();
IASTExpression placement = (IASTExpression) astStack.pop(); // may be null
boolean hasDoubleColon = astStack.pop() != null;
- ICPPASTNewExpression newExpression = nodeFactory.newCPPNewExpression(placement, initializer, typeId);
+ ICPPASTNewExpression newExpression = nodeFactory.newNewExpression(placement, initializer, typeId);
newExpression.setIsGlobal(hasDoubleColon);
newExpression.setIsNewTypeId(isNewTypeId);
+ setOffsetAndLength(newExpression);
for(Object expr : arrayExpressions)
newExpression.addNewTypeIdArrayExpression((IASTExpression)expr);
- setOffsetAndLength(newExpression);
- astStack.push(newExpression);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
+ // CHANGED commented out that entire section
+// // handle ambiguities of the form: (A)(B)
+// if(!isNewTypeId && initializer == null &&
+// placement instanceof IASTIdExpression &&
+// typeId != null && typeId.getDeclSpecifier() instanceof IASTNamedTypeSpecifier) {
+//
+// IASTName firstName = ((IASTIdExpression)placement).getName();
+// IASTName secondName = ((IASTNamedTypeSpecifier)typeId.getDeclSpecifier()).getName();
+//
+// IASTNamedTypeSpecifier newTypeSpecifier = nodeFactory.newTypedefNameSpecifier(firstName.copy());
+// ParserUtil.setOffsetAndLength(newTypeSpecifier, firstName);
+// IASTDeclarator newDeclarator = nodeFactory.newDeclarator(nodeFactory.newName());
+// ParserUtil.setOffsetAndLength(newDeclarator, endOffset(firstName), 0);
+// IASTTypeId newTypeId = nodeFactory.newTypeId(newTypeSpecifier, newDeclarator);
+// ParserUtil.setOffsetAndLength(newTypeId, firstName);
+//
+// IASTIdExpression newInitializer = nodeFactory.newIdExpression(secondName.copy());
+// ParserUtil.setOffsetAndLength(newInitializer, secondName);
+//
+// ICPPASTNewExpression alternate = nodeFactory.newNewExpression(null, newInitializer, newTypeId);
+// ParserUtil.setOffsetAndLength(alternate, newExpression);
+// newExpression.setIsGlobal(hasDoubleColon);
+// newExpression.setIsNewTypeId(isNewTypeId);
+//
+// IASTAmbiguousExpression ambiguity = createAmbiguousExpression(newExpression, alternate);
+// astStack.push(ambiguity);
+// }
+// else {
+ astStack.push(newExpression);
+// }
}
@@ -205,8 +236,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* ::= <openscope-ast> new_pointer_operators
*/
public void consumeNewDeclarator() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTName name = nodeFactory.newName();
IASTDeclarator declarator = nodeFactory.newDeclarator(name);
@@ -215,8 +244,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(declarator);
astStack.push(declarator);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -226,14 +253,10 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* | 'throw' assignment_expression
*/
public void consumeExpressionThrow(boolean hasExpr) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression operand = hasExpr ? (IASTExpression) astStack.pop() : null;
IASTUnaryExpression expr = nodeFactory.newUnaryExpression(ICPPASTUnaryExpression.op_throw, operand);
setOffsetAndLength(expr);
astStack.push(expr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -244,8 +267,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* @param isVectorized
*/
public void consumeExpressionDelete(boolean isVectorized) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression operand = (IASTExpression) astStack.pop();
boolean hasDoubleColon = astStack.pop() != null;
@@ -255,8 +276,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(deleteExpr);
astStack.push(deleteExpr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -264,16 +283,14 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
*
*/
public void consumeExpressionFieldReference(boolean isPointerDereference, boolean hasTemplateKeyword) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTName name = (IASTName) astStack.pop();
IASTExpression owner = (IASTExpression) astStack.pop();
- IASTFieldReference expr = nodeFactory.newFieldReference(name, owner, isPointerDereference, hasTemplateKeyword);
+ ICPPASTFieldReference expr = nodeFactory.newFieldReference(name, owner);
+ expr.setIsPointerDereference(isPointerDereference);
+ expr.setIsTemplate(hasTemplateKeyword);
setOffsetAndLength(expr);
astStack.push(expr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
/**
@@ -281,18 +298,14 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* ::= simple_type_specifier '(' expression_list_opt ')'
*/
public void consumeExpressionSimpleTypeConstructor() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression expression = (IASTExpression) astStack.pop();
IToken token = (IToken) astStack.pop();
int type = asICPPASTSimpleTypeConstructorExpressionType(token);
- ICPPASTSimpleTypeConstructorExpression typeConstructor = nodeFactory.newCPPSimpleTypeConstructorExpression(type, expression);
+ ICPPASTSimpleTypeConstructorExpression typeConstructor = nodeFactory.newSimpleTypeConstructorExpression(type, expression);
setOffsetAndLength(typeConstructor);
astStack.push(typeConstructor);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -326,8 +339,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
*/
@SuppressWarnings("unchecked")
public void consumeExpressionTypeName() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression expr = (IASTExpression) astStack.pop();
IASTName name = (IASTName) astStack.pop();
boolean isTemplate = astStack.pop() == PLACE_HOLDER;
@@ -340,12 +351,10 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
int endOffset = endOffset(name);
IASTName qualifiedName = createQualifiedName(nestedNames, startOffset, endOffset, dColon != null);
- ICPPASTTypenameExpression typenameExpr = nodeFactory.newCPPTypenameExpression(qualifiedName, expr, isTemplate);
+ ICPPASTTypenameExpression typenameExpr = nodeFactory.newTypenameExpression(qualifiedName, expr, isTemplate);
setOffsetAndLength(typenameExpr);
astStack.push(typenameExpr);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -354,14 +363,12 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* ::= type_specifier_seq declarator '=' assignment_expression
*/
public void consumeConditionDeclaration() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTExpression expr = (IASTExpression) astStack.pop();
IASTDeclarator declarator = (IASTDeclarator) astStack.pop();
IASTDeclSpecifier declSpec = (IASTDeclSpecifier) astStack.pop();
IASTInitializerExpression initializer = nodeFactory.newInitializerExpression(expr);
- setOffsetAndLength(initializer, offset(expr), length(expr));
+ ParserUtil.setOffsetAndLength(initializer, offset(expr), length(expr));
declarator.setInitializer(initializer);
IASTSimpleDeclaration declaration = nodeFactory.newSimpleDeclaration(declSpec);
@@ -369,8 +376,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(declaration);
astStack.push(declaration);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -382,12 +387,10 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* ::= operator_id '<' <openscope-ast> template_argument_list_opt '>'
*/
public void consumeTemplateId() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
List<Object> templateArguments = astStack.closeScope();
IASTName name = (IASTName) astStack.pop();
- ICPPASTTemplateId templateId = nodeFactory.newCPPTemplateId(name);
+ ICPPASTTemplateId templateId = nodeFactory.newTemplateId(name);
for(Object arg : templateArguments) {
if(arg instanceof IASTExpression)
@@ -400,8 +403,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(templateId);
astStack.push(templateId);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -409,10 +410,9 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* Disambiguates template arguments.
*/
public void consumeTemplateArgumentTypeId() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IParser secondaryParser = getExpressionParser();
- IASTNode result = runSecondaryParser(secondaryParser);
+ // TODO is this necessary? It should be able to tell if it looks like an id expression
+ ISecondaryParser<IASTExpression> secondaryParser = parserFactory.getExpressionParser(stream, properties);
+ IASTExpression result = runSecondaryParser(secondaryParser);
// The grammar rule allows assignment_expression, but the ambiguity
// only arises with id_expressions.
@@ -420,14 +420,42 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
return;
IASTTypeId typeId = (IASTTypeId) astStack.pop();
- IASTIdExpression idExpression = (IASTIdExpression) result;
+ IASTIdExpression expr = (IASTIdExpression) result;
- ICPPASTAmbiguousTemplateArgument ambiguityNode = nodeFactory.newAmbiguousTemplateArgument(typeId, idExpression);
+ ICPPASTAmbiguousTemplateArgument ambiguityNode = new CPPASTAmbiguousTemplateArgument(typeId, expr);
//setOffsetAndLength(ambiguityNode);
astStack.push(ambiguityNode);
+ }
+
+
+ /**
+ * Disambiguates template arguments.
+ * Qualified names parse as an expression, so generate the corresponding
+ * typeId and create an ambiguity node.
+ */
+ public void consumeTemplateArgumentExpression() {
+ IASTExpression expr = (IASTExpression) astStack.peek();
- if(TRACE_AST_STACK) System.out.println(astStack);
+ // CHANGED replaced name.copy() with newName()
+ if(expr instanceof IASTIdExpression) {
+ IASTName name = nodeFactory.newName(((IASTIdExpression)expr).getName().toCharArray());
+ ParserUtil.setOffsetAndLength(name, expr);
+
+ IASTNamedTypeSpecifier declSpec = nodeFactory.newTypedefNameSpecifier(name);
+ ParserUtil.setOffsetAndLength(declSpec, name);
+
+ IASTDeclarator declarator = nodeFactory.newDeclarator(nodeFactory.newName());
+ ParserUtil.setOffsetAndLength(declarator, endOffset(declSpec), 0);
+
+ IASTTypeId typeId = nodeFactory.newTypeId(declSpec, declarator);
+ setOffsetAndLength(typeId);
+
+ ICPPASTAmbiguousTemplateArgument ambiguityNode = new CPPASTAmbiguousTemplateArgument(typeId, expr);
+
+ astStack.pop();
+ astStack.push(ambiguityNode);
+ }
}
@@ -436,21 +464,17 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* ::= 'operator' overloadable_operator
*/
public void consumeOperatorName() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- List<IToken> tokens = parser.getRuleTokens();
+ List<IToken> tokens = stream.getRuleTokens();
tokens = tokens.subList(1, tokens.size());
OverloadableOperator operator = getOverloadableOperator(tokens);
- ICPPASTOperatorName name = nodeFactory.newCPPOperatorName(operator);
+ // CHANGED
+ ICPPASTOperatorName name = nodeFactory.newOperatorName(operator);
setOffsetAndLength(name);
- astStack.push(name);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
+ astStack.push(name);
}
-
private OverloadableOperator getOverloadableOperator(List<IToken> tokens) {
if(tokens.size() == 1) {
// TODO this is a hack that I did to save time
@@ -479,36 +503,58 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* ::= 'operator' conversion_type_id
*/
public void consumeConversionName() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- String rep = createStringRepresentation(parser.getRuleTokens());
+// Representation is computed by the conversion name itself, see bug 258054
+ String rep = createStringRepresentation(stream.getRuleTokens());
char[] chars = rep.toCharArray();
IASTTypeId typeId = (IASTTypeId) astStack.pop();
- ICPPASTConversionName name = nodeFactory.newCPPConversionName(chars, typeId);
+ ICPPASTConversionName name = nodeFactory.newConversionName(chars, typeId);
setOffsetAndLength(name);
astStack.push(name);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
+ private String createStringRepresentation(List<IToken> nameTokens) {
+ StringBuilder sb = new StringBuilder();
+ IToken prev = null;
+ for(IToken t : nameTokens) {
+ if(needSpaceBetween(prev, t))
+ sb.append(' ');
+ sb.append(t.toString());
+ prev = t;
+ }
+ return sb.toString();
+ }
+
+ private boolean needSpaceBetween(IToken prev, IToken iter) {
+ // this logic was copied from BasicTokenDuple.createCharArrayRepresentation()
+ if(prev == null)
+ return false;
+
+ int prevKind = baseKind(prev);
+ int iterKind = baseKind(iter);
+
+ return prevKind != TK_ColonColon &&
+ prevKind != TK_identifier &&
+ prevKind != TK_LT &&
+ prevKind != TK_Tilde &&
+ iterKind != TK_GT &&
+ prevKind != TK_LeftBracket &&
+ iterKind != TK_RightBracket &&
+ iterKind != TK_ColonColon;
+ }
/**
* unqualified_id
* ::= '~' identifier_token
*/
public void consumeDestructorName() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- char[] chars = ("~" + parser.getRightIToken()).toCharArray(); //$NON-NLS-1$
+ char[] chars = ("~" + stream.getRightIToken()).toCharArray(); //$NON-NLS-1$
IASTName name = nodeFactory.newName(chars);
setOffsetAndLength(name);
astStack.push(name);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -517,8 +563,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* ::= '~' template_id_name
*/
public void consumeDestructorNameTemplateId() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
ICPPASTTemplateId templateId = (ICPPASTTemplateId) astStack.peek();
IASTName oldName = templateId.getTemplateName();
@@ -526,13 +570,11 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
IASTName newName = nodeFactory.newName(newChars);
- int offset = offset(parser.getLeftIToken());
+ int offset = offset(stream.getLeftIToken());
int length = offset - endOffset(oldName);
- setOffsetAndLength(newName, offset, length);
+ ParserUtil.setOffsetAndLength(newName, offset, length);
templateId.setTemplateName(newName);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -545,19 +587,13 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
*/
public void consumeGlobalQualifiedId() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTName name = (IASTName) astStack.pop();
- ICPPASTQualifiedName qualifiedName = nodeFactory.newCPPQualifiedName();
+ ICPPASTQualifiedName qualifiedName = nodeFactory.newQualifiedName();
qualifiedName.addName(name);
qualifiedName.setFullyQualified(true);
- ((CPPASTQualifiedName)qualifiedName).setSignature("::" + name.toString()); //$NON-NLS-1$
-
setOffsetAndLength(qualifiedName);
astStack.push(qualifiedName);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -565,29 +601,22 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* selection_statement ::= switch '(' condition ')' statement
*/
public void consumeStatementSwitch() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
- IASTStatement body = (IASTStatement) astStack.pop();
+ IASTStatement body = (IASTStatement) astStack.pop();
Object condition = astStack.pop();
IASTSwitchStatement stat;
if(condition instanceof IASTExpression)
- stat = nodeFactory.newSwitchStatment((IASTExpression)condition, body);
+ stat = nodeFactory.newSwitchStatement((IASTExpression)condition, body);
else
- stat = nodeFactory.newSwitchStatment((IASTDeclaration)condition, body);
-
+ stat = nodeFactory.newSwitchStatement((IASTDeclaration)condition, body);
setOffsetAndLength(stat);
astStack.push(stat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
public void consumeStatementIf(boolean hasElse) {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTStatement elseClause = hasElse ? (IASTStatement)astStack.pop() : null;
IASTStatement thenClause = (IASTStatement) astStack.pop();
@@ -601,8 +630,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(ifStatement);
astStack.push(ifStatement);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -610,8 +637,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
* iteration_statement ::= 'while' '(' condition ')' statement
*/
public void consumeStatementWhileLoop() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTStatement body = (IASTStatement) astStack.pop();
Object condition = astStack.pop();
@@ -624,16 +649,12 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(whileStatement);
astStack.push(whileStatement);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
/**
*/
public void consumeStatementForLoop() {
- if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-
IASTStatement body = (IASTStatement) astStack.pop();
IASTExpression expr = (IASTExpression) astStack.pop();
Object condition = astStack.pop(); // can be an expression or a declaration
@@ -641,14 +662,14 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
// bug 234463, fix for content assist to work in this case
int TK_EOC = TK_EndOfCompletion; // TODO: change this in the grammar file
- List<IToken> tokens = parser.getRuleTokens();
+ List<IToken> tokens = stream.getRuleTokens();
if(matchTokens(tokens, tokenMap,
TK_for, TK_LeftParen, TK_Completion, TK_EOC, TK_EOC, TK_EOC, TK_EOC)) {
IASTName name = createName(tokens.get(2));
IASTIdExpression idExpression = nodeFactory.newIdExpression(name);
- setOffsetAndLength(idExpression, offset(name), length(name));
+ ParserUtil.setOffsetAndLength(idExpression, offset(name), length(name));
initializer = nodeFactory.newExpressionStatement(idExpression);
- setOffsetAndLength(initializer, offset(name), length(name));
+ ParserUtil.setOffsetAndLength(initializer, offset(name), length(name));
}
@@ -660,8 +681,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(forStat);
astStack.push(forStat);
-
- if(TRACE_AST_STACK) System.out.println(astStack);
}
@@ -670,8 +689,6 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {