Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonah Graham2018-11-20 16:20:42 +0000
committerJonah Graham2018-11-22 21:47:02 +0000
commit170e654b4796bad1453ae85a427b97317d67a69a (patch)
tree6ca9b8a8fedd5fd25f97eb79c408312e256ff981 /lrparser
parent35996a5c5ca5c254959ba48241eaada6dbf8628d (diff)
downloadorg.eclipse.cdt-170e654b4796bad1453ae85a427b97317d67a69a.tar.gz
org.eclipse.cdt-170e654b4796bad1453ae85a427b97317d67a69a.tar.xz
org.eclipse.cdt-170e654b4796bad1453ae85a427b97317d67a69a.zip
Bug 540373: Cleanup: Format & Remove trailing whitespace
This was done by selecting all projects in Eclipse then Source -> Clean Up... -> choosing: - Format source code - Remove trailing white spaces on all lines and completing the wizard Change-Id: I63685372c6bcc67719bcf145123bcb72e5b00394
Diffstat (limited to 'lrparser')
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/AbstractLRHangingTest.java95
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/AutomatedIntegrationSuite.java73
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPImplicitNameTests.java50
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecTest.java119
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPTests.java407
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecTests.java81
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCommentTests.java68
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompleteParser2Tests.java207
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionBasicTest.java97
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionHangingTest.java150
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionParseTest.java136
-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.java125
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDOMPreprocessorInformationTest.java37
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRDigraphTrigraphTests.java153
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCCompleteParseExtensionsTest.java53
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRGCCTests.java48
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRImageLocationTests.java53
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRInactiveCodeTests.java45
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRKnRTests.java104
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRNodeSelectorTest.java64
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRQuickParser2Tests.java304
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSelectionParseTest.java69
-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.java37
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTemplateTests.java205
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTests.java281
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRUtilOldTests.java49
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRUtilTests.java45
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java186
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/C99ResolveParserAction.java1218
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/C99TypedefTrackerParserAction.java254
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/DeclSpec.java143
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/action/deprecated/DeclaratorFrame.java66
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ArrayType.java32
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99BasicType.java32
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99CompositeTypeScope.java6
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumeration.java42
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Enumerator.java3
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Field.java4
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java20
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionScope.java7
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99FunctionType.java14
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Label.java10
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Parameter.java4
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99PointerType.java27
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99ProblemBinding.java7
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99QualifierType.java15
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Scope.java23
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Structure.java60
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Typedef.java25
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Variable.java36
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/IC99Scope.java7
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/C99SymbolTable.java57
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/CImperativeSymbolTable.java77
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/CNamespace.java8
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/FunctionalMap.java245
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/SymbolTableTests.java168
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/TypedefSymbolTable.java36
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java360
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CPreprocessorAdapter.java65
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IDOMTokenMap.java10
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParser.java17
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ISecondaryParser.java9
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ITokenCollector.java14
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LPGTokenAdapter.java22
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserPlugin.java26
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserProperties.java17
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ScannerExtensionConfiguration.java12
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ASTCompletionNode.java29
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/AbstractParserAction.java109
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/BuildASTParserAction.java697
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ISecondaryParserFactory.java20
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenMap.java6
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenStream.java30
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ParserUtil.java50
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ScopedStack.java99
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/TokenMap.java42
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99BuildASTParserAction.java556
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/c99/C99SecondaryParserFactory.java17
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java1909
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPSecondaryParserFactory.java26
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/ICPPSecondaryParserFactory.java12
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/gnu/GCCBuildASTParserAction.java39
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/gnu/GCCSecondaryParserFactory.java17
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/gnu/GNUBuildASTParserAction.java41
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/gnu/GPPBuildASTParserAction.java96
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/gnu/GPPSecondaryParserFactory.java26
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/c99/C99Language.java16
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/c99/DOMToC99TokenMap.java318
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/cpp/DOMToISOCPPTokenMap.java417
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/cpp/ISOCPPLanguage.java18
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/DOMToGCCTokenMap.java345
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/DOMToGPPTokenMap.java452
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GCCLanguage.java14
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GPPLanguage.java14
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/lpgextensions/AbstractTrialUndoActionProvider.java56
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/lpgextensions/FixedBacktrackingParser.java1264
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/lpgextensions/ITrialUndoActionProvider.java2
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/lpgextensions/ParserState.java19
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/lpgextensions/Rule.java4
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/lpgextensions/TrialUndoParser.java33
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99ExpressionParser.java2852
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99ExpressionParserprs.java1784
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99ExpressionParsersym.java219
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99NoCastExpressionParser.java2840
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99NoCastExpressionParserprs.java1769
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99NoCastExpressionParsersym.java219
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parser.java2807
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parserprs.java2252
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99Parsersym.java219
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99SizeofExpressionParser.java2840
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99SizeofExpressionParserprs.java1770
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/c99/C99SizeofExpressionParsersym.java219
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPExpressionParser.java4921
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPExpressionParserprs.java4683
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPExpressionParsersym.java285
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoCastExpressionParser.java4910
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoCastExpressionParserprs.java4676
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoCastExpressionParsersym.java285
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoFunctionDeclaratorParser.java4910
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoFunctionDeclaratorParserprs.java4666
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPNoFunctionDeclaratorParsersym.java285
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParser.java4865
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParserAction.java2
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParserprs.java4691
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPParsersym.java285
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPRules.java282
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPSizeofExpressionParser.java4896
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPSizeofExpressionParserprs.java4684
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPSizeofExpressionParsersym.java285
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPTemplateTypeParameterParser.java4924
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPTemplateTypeParameterParserprs.java4694
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/cpp/CPPTemplateTypeParameterParsersym.java285
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCParser.java3080
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCParserprs.java2904
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCParsersym.java234
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCSizeofExpressionParser.java3085
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCSizeofExpressionParserprs.java2747
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gcc/GCCSizeofExpressionParsersym.java234
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPParser.java5180
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPParserprs.java5789
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPParsersym.java305
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPSizeofExpressionParser.java5183
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPSizeofExpressionParserprs.java5650
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/internal/core/dom/lrparser/gpp/GPPSizeofExpressionParsersym.java305
146 files changed, 57212 insertions, 70238 deletions
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/AbstractLRHangingTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/AbstractLRHangingTest.java
index 274e9a9d59b..c62e1f76981 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/AbstractLRHangingTest.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/AbstractLRHangingTest.java
@@ -7,13 +7,12 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.tests;
-
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
@@ -21,21 +20,14 @@ import org.eclipse.cdt.core.model.ILanguage;
import junit.framework.TestCase;
+public class AbstractLRHangingTest extends TestCase {
-public class AbstractLRHangingTest extends TestCase{
-
-
-
-
public AbstractLRHangingTest() {
}
public AbstractLRHangingTest(String name) {
super(name);
}
-
-
-
protected ILanguage getCLanguage() {
return GCCLanguage.getDefault();
@@ -44,8 +36,8 @@ public class AbstractLRHangingTest extends TestCase{
protected ILanguage getCPPLanguage() {
return GPPLanguage.getDefault();
}
-
- protected void runThreadByLimitedTime(long limitTime, Thread testThread)throws Exception{
+
+ protected void runThreadByLimitedTime(long limitTime, Thread testThread) throws Exception {
testThread.start();
testThread.join(limitTime);
@@ -56,77 +48,72 @@ public class AbstractLRHangingTest extends TestCase{
// Finished
}
}
-
+
// 1mins
public static long THREAD_TIMEOUT_LIMIT = 1 * 60 * 1000;
- public static String CONTENT_ASIST_CURSOR =" /*<ctrl-space>*/ ";
-
- private String errMsg="";
-
- public void resetErrMsg(){
- errMsg="";
+ public static String CONTENT_ASIST_CURSOR = " /*<ctrl-space>*/ ";
+
+ private String errMsg = "";
+
+ public void resetErrMsg() {
+ errMsg = "";
}
-
- public void setErrMsg(String errMsg){
- this.errMsg=errMsg;
+
+ public void setErrMsg(String errMsg) {
+ this.errMsg = errMsg;
}
-
-
- protected void runTestCase(final String code, final ILanguage language)throws Exception{
-
-
+
+ protected void runTestCase(final String code, final ILanguage language) throws Exception {
+
Thread testThread = new Thread() {
-
-
+
@Override
public void run() {
-
- String errMsg="";
+
+ String errMsg = "";
resetErrMsg();
- String msg=null;
+ String msg = null;
int offset = code.indexOf(CONTENT_ASIST_CURSOR);
- int index=0;
- while(offset >=0){
-
+ int index = 0;
+ while (offset >= 0) {
+
IASTCompletionNode node = null;
try {
node = ParseHelper.getCompletionNode(code, language, offset);
} catch (Exception e) {
- if(errMsg.length()==0){
+ if (errMsg.length() == 0) {
errMsg = "caught an exception when the code is parsed for cursor number " + index;
- }else{
- errMsg = errMsg + "\n" + "caught an exception when the code is parsed for cursor number " + index;
+ } else {
+ errMsg = errMsg + "\n" + "caught an exception when the code is parsed for cursor number "
+ + index;
}
-
+
}
- if(node == null){
- if(errMsg.length()==0){
- errMsg = "return completion node is null when the code is parsed for cursor number " + index;
- }else{
- errMsg = errMsg + "\n" + "return completion node is null when the code is parsed for cursor number " + index;
+ if (node == null) {
+ if (errMsg.length() == 0) {
+ errMsg = "return completion node is null when the code is parsed for cursor number "
+ + index;
+ } else {
+ errMsg = errMsg + "\n"
+ + "return completion node is null when the code is parsed for cursor number "
+ + index;
}
-
+
}
offset = code.indexOf(CONTENT_ASIST_CURSOR, offset + 1);
index++;
}
setErrMsg(errMsg);
-
+
}
};
runThreadByLimitedTime(THREAD_TIMEOUT_LIMIT, testThread);
- if(errMsg.length()>0){
+ if (errMsg.length() > 0) {
//fail(errMsg);
}
-
- }
-
-
-
-
-
+ }
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/AutomatedIntegrationSuite.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/AutomatedIntegrationSuite.java
index 248e830739a..2fa9ff861b9 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/AutomatedIntegrationSuite.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/AutomatedIntegrationSuite.java
@@ -7,19 +7,17 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.tests;
-
-
import junit.framework.Test;
import junit.framework.TestSuite;
public class AutomatedIntegrationSuite extends TestSuite {
-
+
// TODO: the following test are not being reused
//
// DOMGCCSelectionParseExtensionsTest
@@ -28,39 +26,40 @@ public class AutomatedIntegrationSuite extends TestSuite {
// QuickParser2Tests
//
// and perhaps others
-
+
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(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(LRCompletionHangingTest.suite());
- addTest(LRCPPImplicitNameTests.suite());
- //addTest(LRInactiveCodeTests.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(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(LRCompletionHangingTest.suite());
+ addTest(LRCPPImplicitNameTests.suite());
+ //addTest(LRInactiveCodeTests.suite());
+ }
+ };
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPImplicitNameTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPImplicitNameTests.java
index 22f0b5b57a6..e077a6714d2 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPImplicitNameTests.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPImplicitNameTests.java
@@ -25,36 +25,38 @@ import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPImplicitNameTests;
public class LRCPPImplicitNameTests extends AST2CPPImplicitNameTests {
public static TestSuite suite() {
- return suite(LRCPPImplicitNameTests.class);
- }
-
+ return suite(LRCPPImplicitNameTests.class);
+ }
+
public LRCPPImplicitNameTests() {
}
-
+
public LRCPPImplicitNameTests(String name) {
super(name);
}
-
+
//TODO ??? overwrite some failed test cases
@Override
- public void testNew() throws Exception {}
-
-
+ public void testNew() throws Exception {
+ }
+
@Override
- protected IASTTranslationUnit parse( String code, ParserLanguage lang, @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems, int limitTrivialInitializers) {
- ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
- ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(expectNoProblems);
- options.setCheckPreprocessorProblems(expectNoProblems);
- options.setLimitTrivialInitializers(limitTrivialInitializers);
- return ParseHelper.parse(code, language, options);
- }
-
- protected ILanguage getCLanguage() {
- return GCCLanguage.getDefault();
- }
-
- protected ILanguage getCPPLanguage() {
- return GPPLanguage.getDefault();
- }
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang,
+ @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems,
+ int limitTrivialInitializers) {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setLimitTrivialInitializers(limitTrivialInitializers);
+ 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/LRCPPSpecTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecTest.java
index b94b201a24b..764716f4b98 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -25,49 +25,74 @@ 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); }
+ return suite(LRCPPSpecTest.class);
+ }
+
+ public LRCPPSpecTest() {
+ }
+
+ public LRCPPSpecTest(String name) {
+ super(name);
+ }
//TODO ??? overwrite some failed test cases
@Override
- public void test7_1_3s5b() throws Exception {}
+ public void test7_1_3s5b() throws Exception {
+ }
+
@Override
- public void test8_2s7a() throws Exception {}
+ public void test8_2s7a() throws Exception {
+ }
+
@Override
- public void test8_2s7b() throws Exception {}
+ public void test8_2s7b() throws Exception {
+ }
+
@Override
- public void test14_8_2s8a() throws Exception {}
+ public void test14_8_2s8a() throws Exception {
+ }
+
@Override
- public void test14_8_2_1s1a() throws Exception {}
+ public void test14_8_2_1s1a() throws Exception {
+ }
+
@Override
- public void test14_8_2_1s1b() throws Exception {}
+ public void test14_8_2_1s1b() throws Exception {
+ }
+
@Override
- public void test14_8_2_1s3() throws Exception {}
+ public void test14_8_2_1s3() throws Exception {
+ }
+
@Override
- public void test14_8_2_4s12() throws Exception {}
+ public void test14_8_2_4s12() throws Exception {
+ }
+
@Override
- public void test14_8_2_5s5() throws Exception {}
+ public void test14_8_2_5s5() throws Exception {
+ }
+
@Override
- public void test14_8_2_5s10() throws Exception {}
+ public void test14_8_2_5s10() throws Exception {
+ }
+
@Override
- public void test14_8_2_4s21() throws Exception {}
+ public void test14_8_2_4s21() throws Exception {
+ }
+
@Override
- public void test14_8_2_5s22() throws Exception {}
-
-
-
-
+ public void test14_8_2_5s22() throws Exception {
+ }
+
@Override
- protected void parseCandCPP( String code, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
- parse(code, ParserLanguage.C, checkBindings, expectedProblemBindings);
+ 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();
@@ -76,27 +101,30 @@ public class LRCPPSpecTest extends AST2CPPSpecTest {
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 {
+ 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, int limitTrivialInitializers) throws ParserException {
- ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
- ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(expectNoProblems);
- options.setCheckPreprocessorProblems(expectNoProblems);
- options.setLimitTrivialInitializers(limitTrivialInitializers);
- return ParseHelper.parse(code, language, options);
- }
-
+ }
+
+ @Override
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang,
+ @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems,
+ int limitTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setLimitTrivialInitializers(limitTrivialInitializers);
+ return ParseHelper.parse(code, language, options);
+ }
+
@Override
protected IASTTranslationUnit parse(String code, ParserLanguage lang, String[] problems) throws ParserException {
ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
@@ -104,16 +132,13 @@ public class LRCPPSpecTest extends AST2CPPSpecTest {
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
index 6845bbd03c2..fb7044795ac 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -25,230 +25,307 @@ import junit.framework.TestSuite;
@SuppressWarnings("restriction")
public class LRCPPTests extends AST2CPPTests {
-
+
public static TestSuite suite() {
- return suite(LRCPPTests.class);
- }
-
+ return suite(LRCPPTests.class);
+ }
+
public LRCPPTests() {
}
-
+
public LRCPPTests(String name) {
super(name);
}
-
-//the below test case are for C++0x features which are not included in XLC++ yet
-
-
+
+ //the below test case are for C++0x features which are not included in XLC++ yet
+
@Override
- public void testRValueReference_294730() throws Exception {}
+ public void testRValueReference_294730() throws Exception {
+ }
+
@Override
- public void testRValueReferenceTypedefs_294730() throws Exception {}
+ public void testRValueReferenceTypedefs_294730() throws Exception {
+ }
+
@Override
- public void testDirectBinding_294730() throws Exception {}
+ public void testDirectBinding_294730() throws Exception {
+ }
+
@Override
- public void testListInitialization_302412a() throws Exception {}
+ public void testListInitialization_302412a() throws Exception {
+ }
+
@Override
- public void testListInitialization_302412b() throws Exception {}
+ public void testListInitialization_302412b() throws Exception {
+ }
+
@Override
- public void testListInitialization_302412c() throws Exception {}
+ public void testListInitialization_302412c() throws Exception {
+ }
+
@Override
- public void testListInitialization_302412d() throws Exception {}
+ public void testListInitialization_302412d() throws Exception {
+ }
+
@Override
- public void testListInitialization_302412e() throws Exception {}
+ public void testListInitialization_302412e() throws Exception {
+ }
+
@Override
- public void testListInitialization_302412f() throws Exception {}
+ public void testListInitialization_302412f() throws Exception {
+ }
+
@Override
- public void testScopedEnums_305975a() throws Exception {}
+ public void testScopedEnums_305975a() throws Exception {
+ }
+
@Override
- public void testScopedEnums_305975b() throws Exception {}
+ public void testScopedEnums_305975b() throws Exception {
+ }
+
@Override
- public void testScopedEnums_305975c() throws Exception {}
+ public void testScopedEnums_305975c() throws Exception {
+ }
+
@Override
- public void testScopedEnums_305975d() throws Exception {}
+ public void testScopedEnums_305975d() throws Exception {
+ }
+
@Override
- public void testScopedEnums_305975e() throws Exception {}
+ public void testScopedEnums_305975e() throws Exception {
+ }
+
@Override
- public void testScopedEnums_305975g() throws Exception {}
+ public void testScopedEnums_305975g() throws Exception {
+ }
+
@Override
- public void testBug332114b() throws Exception {}
+ public void testBug332114b() throws Exception {
+ }
-
//unicode character type
@Override
- public void testNewCharacterTypes_305976() throws Exception {}
-
+ public void testNewCharacterTypes_305976() throws Exception {
+ }
+
//auto type
@Override
- public void testAutoType_289542() throws Exception {}
+ public void testAutoType_289542() throws Exception {
+ }
+
@Override
- public void testAutoType_305970() throws Exception {}
+ public void testAutoType_305970() throws Exception {
+ }
+
@Override
- public void testAutoType_305987() throws Exception {}
+ public void testAutoType_305987() throws Exception {
+ }
+
@Override
- public void testNewFunctionDeclaratorSyntax_305972() throws Exception {}
+ public void testNewFunctionDeclaratorSyntax_305972() throws Exception {
+ }
+
@Override
- public void testBug332114a() throws Exception {}
+ public void testBug332114a() throws Exception {
+ }
+
@Override
- public void testResolutionInTrailingReturnType_333256() throws Exception {}
+ public void testResolutionInTrailingReturnType_333256() throws Exception {
+ }
+
@Override
- public void testAutoTypeInRangeBasedFor_332883a() throws Exception {}
+ public void testAutoTypeInRangeBasedFor_332883a() throws Exception {
+ }
+
@Override
- public void testAutoTypeInRangeBasedFor_332883b() throws Exception {}
-
-
+ public void testAutoTypeInRangeBasedFor_332883b() throws Exception {
+ }
+
//DeclType
@Override
- public void testDecltype_294730() throws Exception {}
-
- //Defaulted and deleted functions
+ public void testDecltype_294730() throws Exception {
+ }
+
+ //Defaulted and deleted functions
@Override
- public void testDefaultedAndDeletedFunctions_305978() throws Exception {}
+ public void testDefaultedAndDeletedFunctions_305978() throws Exception {
+ }
+
@Override
- public void testDefaultedAndDeletedFunctions_305978b() throws Exception {}
-
+ public void testDefaultedAndDeletedFunctions_305978b() throws Exception {
+ }
+
//Inline namespaces
@Override
- public void testInlineNamespace_305980a() throws Exception {}
+ public void testInlineNamespace_305980a() throws Exception {
+ }
+
@Override
- public void testInlineNamespace_305980b() throws Exception {}
+ public void testInlineNamespace_305980b() throws Exception {
+ }
+
@Override
- public void testInlineNamespace_305980c() throws Exception {}
+ public void testInlineNamespace_305980c() throws Exception {
+ }
+
@Override
- public void testInlineNamespace_305980d() throws Exception {}
-
- //New wording for C++0x lambdas
+ public void testInlineNamespace_305980d() throws Exception {
+ }
+
+ //New wording for C++0x lambdas
@Override
- public void testLambdaExpression_316307a() throws Exception {}
+ public void testLambdaExpression_316307a() throws Exception {
+ }
+
@Override
- public void testLambdaExpression_316307b() throws Exception {}
-
+ public void testLambdaExpression_316307b() throws Exception {
+ }
+
//xvalue
@Override
- public void testXValueCategories() throws Exception {}
+ public void testXValueCategories() throws Exception {
+ }
+
@Override
- public void testRankingOfReferenceBindings_a() throws Exception {}
+ public void testRankingOfReferenceBindings_a() throws Exception {
+ }
+
@Override
- public void testRankingOfReferenceBindings_b() throws Exception {}
+ public void testRankingOfReferenceBindings_b() throws Exception {
+ }
+
@Override
- public void testInlineNamespaceLookup_324096() throws Exception {}
+ public void testInlineNamespaceLookup_324096() throws Exception {
+ }
+
@Override
- public void testCtorForAutomaticVariables_156668() throws Exception {}
+ public void testCtorForAutomaticVariables_156668() throws Exception {
+ }
+
@Override
- public void testRangeBasedForLoop_327223() throws Exception {}
-
+ public void testRangeBasedForLoop_327223() throws Exception {
+ }
+
//TODO ??? overwrite some failed test cases
@Override
- public void testOrderOfAmbiguityResolution_259373() throws Exception {}
+ public void testOrderOfAmbiguityResolution_259373() throws Exception {
+ }
+
@Override
- public void testPureVirtualVsInitDeclarator_267184() throws Exception {}
+ public void testPureVirtualVsInitDeclarator_267184() throws Exception {
+ }
+
@Override
- public void testDeclarationAmbiguity_269953() throws Exception {}
+ public void testDeclarationAmbiguity_269953() throws Exception {
+ }
+
@Override
- public void testInitSyntax_302412() throws Exception {}
+ public void testInitSyntax_302412() throws Exception {
+ }
+
@Override
- public void testStaticAssertions_294730() throws Exception {}
-
+ public void testStaticAssertions_294730() throws Exception {
+ }
+
//outer::foo x
@Override
- public void testAttributeInUsingDirective_351228() throws Exception {}
-
-
- @Override
- protected IASTTranslationUnit parse( String code, ParserLanguage lang, @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems, int limitTrivialInitializers) throws ParserException {
- ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
- ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(expectNoProblems);
- options.setCheckPreprocessorProblems(expectNoProblems);
- options.setLimitTrivialInitializers(limitTrivialInitializers);
- return ParseHelper.parse(code, language, options);
- }
-
- protected ILanguage getCLanguage() {
- return GCCLanguage.getDefault();
- }
-
- protected ILanguage getCPPLanguage() {
- return GPPLanguage.getDefault();
- }
-
-
- @Override
+ public void testAttributeInUsingDirective_351228() throws Exception {
+ }
+
+ @Override
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang,
+ @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems,
+ int limitTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setLimitTrivialInitializers(limitTrivialInitializers);
+ 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
+ // 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
- }
-
-
+ // 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
index e263dc3890e..6866836ad1a 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -23,25 +23,30 @@ 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"})
+@SuppressWarnings({ "restriction", "nls" })
public class LRCSpecTests extends AST2CSpecTest {
public static TestSuite suite() {
- return suite(LRCSpecTests.class);
- }
-
- public LRCSpecTests() { }
- public LRCSpecTests(String name) { super(name); }
+ 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);
+ 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 {
+ 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);
@@ -49,8 +54,8 @@ public class LRCSpecTests extends AST2CSpecTest {
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();
@@ -60,46 +65,36 @@ public class LRCSpecTests extends AST2CSpecTest {
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";
-
+ 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 _) { }
-// }
-
-
+ }
+
+ // @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*[]) {} ";
-
+ 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
index f81f896670f..08b9f1c51fa 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -29,50 +29,44 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
public class LRCommentTests extends CommentTests {
public static TestSuite suite() {
- return suite(LRCommentTests.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);
- }
-
-
- @Override
- @SuppressWarnings("unused")
- protected IASTTranslationUnit parse(String code, ParserLanguage lang,
- boolean useGNUExtensions, boolean expectNoProblems,
- int limitTrivialInitializers) throws ParserException {
-
- ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
- ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(expectNoProblems);
- options.setCheckPreprocessorProblems(expectNoProblems);
- options.setLimitTrivialInitializers(limitTrivialInitializers);
- return ParseHelper.commentParse(code, language);
- }
+ return suite(LRCommentTests.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);
+ }
+
+ @Override
+ @SuppressWarnings("unused")
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
+ boolean expectNoProblems, int limitTrivialInitializers) throws ParserException {
+
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setLimitTrivialInitializers(limitTrivialInitializers);
+ return ParseHelper.commentParse(code, language);
+ }
protected ILanguage getCLanguage() {
- return GCCLanguage.getDefault();
- }
-
+ 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";
-
+ String code = "#define MACRO 1000000000000 \n" + "int x = MACRO; \n" + "//comment\n";
+
IASTTranslationUnit tu = parse(code, ParserLanguage.C, false, false, 0);
-
+
IASTComment[] comments = tu.getComments();
assertEquals(1, comments.length);
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
index b7b0662e1e7..a532402c80f 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -26,9 +26,9 @@ import org.eclipse.cdt.core.parser.tests.ast2.CompleteParser2Tests;
public class LRCompleteParser2Tests extends CompleteParser2Tests {
public static TestSuite suite() {
- return suite(LRCompleteParser2Tests.class);
- }
-
+ return suite(LRCompleteParser2Tests.class);
+ }
+
public LRCompleteParser2Tests() {
}
@@ -37,119 +37,118 @@ public class LRCompleteParser2Tests extends CompleteParser2Tests {
}
@Override
- @SuppressWarnings("unused")
- protected IASTTranslationUnit parse(String code, boolean expectedToPass,
- ParserLanguage lang, boolean gcc) throws Exception {
+ @SuppressWarnings("unused")
+ 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();
- }
-
+ 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 expectedException) {
-// return;
-// } catch(Exception expectedException) {
-// return;
-// }
-// fail();
-// }
-
-// public void testPredefinedSymbol_bug70928_infinite_loop_test1() throws Exception { // gcc extension
-// try {
-// super.testPredefinedSymbol_bug70928_infinite_loop_test1();
-// fail();
-// } catch(AssertionError expectedException) { }
-// }
-//
-// public void testPredefinedSymbol_bug70928_infinite_loop_test2() throws Exception { // gcc extension
-// try {
-// super.testPredefinedSymbol_bug70928_infinite_loop_test2();
-// fail();
-// } catch(AssertionError expectedException) { }
-// }
-
-
-// @Override
-// public void testBug102376() throws Exception { // gcc extension
-// try {
-// super.testBug102376();
-// fail();
-// } catch(AssertionFailedError expectedException) { }
-// }
-
-// @Override
-// public void test158192_declspec_in_declarator() throws Exception {
-// try {
-// super.test158192_declspec_in_declarator();
-// fail();
-// } catch(AssertionFailedError expectedException) { }
-// }
-//
-// @Override
-// public void test158192_declspec_on_class() throws Exception {
-// try {
-// super.test158192_declspec_on_class();
-// fail();
-// } catch(AssertionFailedError expectedException) { }
-// }
-//
-// @Override
-// public void test158192_declspec_on_variable() throws Exception {
-// try {
-// super.test158192_declspec_on_variable();
-// fail();
-// } catch(AssertionFailedError expectedException) { }
-// }
-//
-// @Override
-// public void testPredefinedSymbol_bug70928() throws Exception {
-// try {
-// super.testPredefinedSymbol_bug70928();
-// fail();
-// } catch(AssertionFailedError expectedException) { }
-// }
-
+
+ // @Override
+ // public void testBug39676_tough() { // is this C99?
+ // try {
+ // super.testBug39676_tough();
+ // } catch(AssertionFailedError expectedException) {
+ // return;
+ // } catch(Exception expectedException) {
+ // return;
+ // }
+ // fail();
+ // }
+
+ // public void testPredefinedSymbol_bug70928_infinite_loop_test1() throws Exception { // gcc extension
+ // try {
+ // super.testPredefinedSymbol_bug70928_infinite_loop_test1();
+ // fail();
+ // } catch(AssertionError expectedException) { }
+ // }
+ //
+ // public void testPredefinedSymbol_bug70928_infinite_loop_test2() throws Exception { // gcc extension
+ // try {
+ // super.testPredefinedSymbol_bug70928_infinite_loop_test2();
+ // fail();
+ // } catch(AssertionError expectedException) { }
+ // }
+
+ // @Override
+ // public void testBug102376() throws Exception { // gcc extension
+ // try {
+ // super.testBug102376();
+ // fail();
+ // } catch(AssertionFailedError expectedException) { }
+ // }
+
+ // @Override
+ // public void test158192_declspec_in_declarator() throws Exception {
+ // try {
+ // super.test158192_declspec_in_declarator();
+ // fail();
+ // } catch(AssertionFailedError expectedException) { }
+ // }
+ //
+ // @Override
+ // public void test158192_declspec_on_class() throws Exception {
+ // try {
+ // super.test158192_declspec_on_class();
+ // fail();
+ // } catch(AssertionFailedError expectedException) { }
+ // }
+ //
+ // @Override
+ // public void test158192_declspec_on_variable() throws Exception {
+ // try {
+ // super.test158192_declspec_on_variable();
+ // fail();
+ // } catch(AssertionFailedError expectedException) { }
+ // }
+ //
+ // @Override
+ // public void testPredefinedSymbol_bug70928() throws Exception {
+ // try {
+ // super.testPredefinedSymbol_bug70928();
+ // fail();
+ // } catch(AssertionFailedError expectedException) { }
+ // }
+
@Override
public void testBug64010() throws Exception { // 10000 else-ifs, busts LPG's stack
try {
//super.testBug64010();
//fail();
- } catch(AssertionFailedError expectedException) { }
+ } catch (AssertionFailedError expectedException) {
+ }
}
-
-//
-// @Override
-// public void testGNUASMExtension() throws Exception {
-// try {
-// super.testGNUASMExtension();
-// fail();
-// } catch(AssertionFailedError expectedException) {
-// } catch(AssertionError expectedException) {
-// }
-// }
-//
-// @Override
-// public void testBug39551B() throws Exception {
-// try {
-// super.testBug39551B();
-// fail();
-// } catch(AssertionFailedError expectedException) { }
-// }
-//
-//
-//
-
+
+ //
+ // @Override
+ // public void testGNUASMExtension() throws Exception {
+ // try {
+ // super.testGNUASMExtension();
+ // fail();
+ // } catch(AssertionFailedError expectedException) {
+ // } catch(AssertionError expectedException) {
+ // }
+ // }
+ //
+ // @Override
+ // public void testBug39551B() throws Exception {
+ // try {
+ // super.testBug39551B();
+ // fail();
+ // } catch(AssertionFailedError expectedException) { }
+ // }
+ //
+ //
+ //
+
}
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
index a3a66686715..aa088b84eb9 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -26,98 +26,101 @@ 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"})
+@SuppressWarnings({ "restriction", "nls" })
public class LRCompletionBasicTest extends BasicCompletionTest {
public static TestSuite suite() {
- return new TestSuite(LRCompletionBasicTest.class);
- }
-
- public LRCompletionBasicTest() { }
-
+ return new TestSuite(LRCompletionBasicTest.class);
+ }
+
+ public LRCompletionBasicTest() {
+ }
+
//override the test failed case for 340664
@Override
- public void testCompletionInSizeof340664() throws Exception {}
-
-
- //override some failed test cases
+ public void testCompletionInSizeof340664() throws Exception {
+ }
+
+ //override some failed test cases
@Override
- public void testBug279931() throws Exception {}
+ public void testBug279931() throws Exception {
+ }
+
@Override
- public void testBug279931a() throws Exception {}
+ public void testBug279931a() throws Exception {
+ }
+
@Override
- public void testQualifiedMemberAccess_Bug300139() throws Exception {}
+ public void testQualifiedMemberAccess_Bug300139() throws Exception {
+ }
+
@Override
- public void testCastExpression_Bug301933() throws Exception {}
+ public void testCastExpression_Bug301933() throws Exception {
+ }
+
@Override
- public void testConditionalOperator_Bug308611() throws Exception {}
+ public void testConditionalOperator_Bug308611() throws Exception {
+ }
+
@Override
- public void testCompletionInDesignatedInitializor_353281a() throws Exception {}
+ public void testCompletionInDesignatedInitializor_353281a() throws Exception {
+ }
@Override
- @SuppressWarnings("unused")
- protected IASTCompletionNode getCompletionNode(String code,
- ParserLanguage lang, boolean useGNUExtensions)
+ @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();
- }
-
+ return GCCLanguage.getDefault();
+ }
+
protected ILanguage getCPPLanguage() {
return GPPLanguage.getDefault();
}
-
@Override
public void testFunction() throws Exception {
- String code =
- "void func(int x) { }" +
- "void func2() { fu";
-
+ 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());
+ 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());
+ assertEquals("func", ((IFunction) bindings[0]).getName());
+ assertEquals("func2", ((IFunction) bindings[1]).getName());
}
-
@Override
public void testTypedef() throws Exception {
- String code =
- "typedef int blah;" +
- "bl";
-
+ 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());
-
+ 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());
+ assertEquals("blah", ((ITypedef) bindings[0]).getName());
}
-
-
+
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionHangingTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionHangingTest.java
index 6535eed3c30..4a627c56d86 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionHangingTest.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCompletionHangingTest.java
@@ -7,160 +7,96 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.tests;
-
-
-
-
import junit.framework.TestSuite;
public class LRCompletionHangingTest extends AbstractLRHangingTest {
-
-
public static TestSuite suite() {
return new TestSuite(LRCompletionHangingTest.class);
}
-
-
-
-
-
+
//test c
public void testCompletionDoWhileForC() throws Exception {
- String code =
- "int main(int argc, char **argv) {" +
- "do{" +
- CONTENT_ASIST_CURSOR +
- "} while (i < 3);" +
- "}";
-
+ String code = "int main(int argc, char **argv) {" + "do{" + CONTENT_ASIST_CURSOR + "} while (i < 3);" + "}";
+
runTestCase(code, getCLanguage());
-
+
}
-
-
-
+
//test cpp
public void testCompletionDoWhileForCPP() throws Exception {
- String code =
- "int main(int argc, char **argv) {" +
- "do{" +
- CONTENT_ASIST_CURSOR +
- "} while (i < 3);" +
- "}";
+ String code = "int main(int argc, char **argv) {" + "do{" + CONTENT_ASIST_CURSOR + "} while (i < 3);" + "}";
runTestCase(code, getCPPLanguage());
}
-
+
public void testCompletionTryCatch() throws Exception {
- String code =
- "int main(int argc, char **argv) {" +
- "try {" +
- CONTENT_ASIST_CURSOR +
- "}" +
-
- "catch(x){}" +
- "}";
+ String code = "int main(int argc, char **argv) {" + "try {" + CONTENT_ASIST_CURSOR + "}" +
+
+ "catch(x){}" + "}";
runTestCase(code, getCPPLanguage());
-
+
}
-
-
-
public void testCompletionTemplateFunctionForCPP() throws Exception {
- String code =
- "template " + CONTENT_ASIST_CURSOR +"<class myType>" +
- "myType GetA (myType a) {" +
- "return a;" +
- "}" +
-
- "int main(int argc, char **argv) {" +
- "int x=0;" +
- "int y = GetA " + CONTENT_ASIST_CURSOR + " <int> (x);" +
- "}";
+ String code = "template " + CONTENT_ASIST_CURSOR + "<class myType>" + "myType GetA (myType a) {" + "return a;"
+ + "}" +
+
+ "int main(int argc, char **argv) {" + "int x=0;" + "int y = GetA " + CONTENT_ASIST_CURSOR
+ + " <int> (x);" + "}";
runTestCase(code, getCPPLanguage());
}
-
-
+
public void testCompletionIfForCPP() throws Exception {
- String code =
- "int main(int argc, char **argv) {" +
- "int x=0;" +
- "if" + CONTENT_ASIST_CURSOR +"(x>0){}" +
- "}";
+ String code = "int main(int argc, char **argv) {" + "int x=0;" + "if" + CONTENT_ASIST_CURSOR + "(x>0){}" + "}";
runTestCase(code, getCPPLanguage());
-
+
}
-
+
public void testCompletionTemplateClassForCPP() throws Exception {
- String code =
- "template" + CONTENT_ASIST_CURSOR +" <class T> " +
- "class Test {" +
- "T val;" +
- "public:Test(T arg){"+
- "val = arg;" +
- "}" +
- "~" + CONTENT_ASIST_CURSOR +"Test();"+
- "};" +
- "Test::" + CONTENT_ASIST_CURSOR +"~" + CONTENT_ASIST_CURSOR +"Test(){}" +
- "int main(int argc, char **argv) {" +
- CONTENT_ASIST_CURSOR +
- "Test<" + CONTENT_ASIST_CURSOR + "int> t(1);" +
- "Test<" + CONTENT_ASIST_CURSOR +"double>" + CONTENT_ASIST_CURSOR + "* dt = new dt(1.0);" +
- "S* s = dynamic_cast<S*" + CONTENT_ASIST_CURSOR +">(dt);" +
- "S* s = dynamic_cast" + CONTENT_ASIST_CURSOR +"<S*>(dt);" +
- "}";
+ String code = "template" + CONTENT_ASIST_CURSOR + " <class T> " + "class Test {" + "T val;"
+ + "public:Test(T arg){" + "val = arg;" + "}" + "~" + CONTENT_ASIST_CURSOR + "Test();" + "};" + "Test::"
+ + CONTENT_ASIST_CURSOR + "~" + CONTENT_ASIST_CURSOR + "Test(){}" + "int main(int argc, char **argv) {"
+ + CONTENT_ASIST_CURSOR + "Test<" + CONTENT_ASIST_CURSOR + "int> t(1);" + "Test<" + CONTENT_ASIST_CURSOR
+ + "double>" + CONTENT_ASIST_CURSOR + "* dt = new dt(1.0);" + "S* s = dynamic_cast<S*"
+ + CONTENT_ASIST_CURSOR + ">(dt);" + "S* s = dynamic_cast" + CONTENT_ASIST_CURSOR + "<S*>(dt);" + "}";
runTestCase(code, getCPPLanguage());
}
-
-
-
-
+
public void testCompletionSimpleIfForCPP() throws Exception {
- String code =
- "#" + CONTENT_ASIST_CURSOR + "include " + CONTENT_ASIST_CURSOR + "<iostream>" +
- "using " + CONTENT_ASIST_CURSOR + "namespace std;" +
- "if" + CONTENT_ASIST_CURSOR + "(i>0)){}" +
- "int " + CONTENT_ASIST_CURSOR + "*" + CONTENT_ASIST_CURSOR + " i " + CONTENT_ASIST_CURSOR + "=" + CONTENT_ASIST_CURSOR + " &" + CONTENT_ASIST_CURSOR + "j;" +
- "*" + CONTENT_ASIST_CURSOR + "j=0;" +
- "*" + CONTENT_ASIST_CURSOR + "j++;"+
- "*i" + CONTENT_ASIST_CURSOR + "++ = " + CONTENT_ASIST_CURSOR + "*j++;";
+ String code = "#" + CONTENT_ASIST_CURSOR + "include " + CONTENT_ASIST_CURSOR + "<iostream>" + "using "
+ + CONTENT_ASIST_CURSOR + "namespace std;" + "if" + CONTENT_ASIST_CURSOR + "(i>0)){}" + "int "
+ + CONTENT_ASIST_CURSOR + "*" + CONTENT_ASIST_CURSOR + " i " + CONTENT_ASIST_CURSOR + "="
+ + CONTENT_ASIST_CURSOR + " &" + CONTENT_ASIST_CURSOR + "j;" + "*" + CONTENT_ASIST_CURSOR + "j=0;" + "*"
+ + CONTENT_ASIST_CURSOR + "j++;" + "*i" + CONTENT_ASIST_CURSOR + "++ = " + CONTENT_ASIST_CURSOR
+ + "*j++;";
runTestCase(code, getCPPLanguage());
-
+
}
-
+
public void testCompletionStructForCPP() throws Exception {
- String code =
- "struct " + CONTENT_ASIST_CURSOR + "p " + CONTENT_ASIST_CURSOR + "{" +
- CONTENT_ASIST_CURSOR+
- "int w;" +
- "float p;" +
- "} " + CONTENT_ASIST_CURSOR + "a," + CONTENT_ASIST_CURSOR + "b,c;";
-
+ String code = "struct " + CONTENT_ASIST_CURSOR + "p " + CONTENT_ASIST_CURSOR + "{" + CONTENT_ASIST_CURSOR
+ + "int w;" + "float p;" + "} " + CONTENT_ASIST_CURSOR + "a," + CONTENT_ASIST_CURSOR + "b,c;";
+
runTestCase(code, getCPPLanguage());
-
+
}
-
+
public void testCompletionGnuCPP() throws Exception {
- String code =
- "if a>b ? " + CONTENT_ASIST_CURSOR + "g" + CONTENT_ASIST_CURSOR + ":l;" +
- "case 1..." + CONTENT_ASIST_CURSOR + "3 : ok; ";
+ String code = "if a>b ? " + CONTENT_ASIST_CURSOR + "g" + CONTENT_ASIST_CURSOR + ":l;" + "case 1..."
+ + CONTENT_ASIST_CURSOR + "3 : ok; ";
runTestCase(code, getCPPLanguage());
}
-
-
-
}
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
index de13c42c6a5..30252214fab 100644
--- 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
@@ -38,8 +38,8 @@ import junit.framework.TestSuite;
public class LRCompletionParseTest extends TestCase {
public static TestSuite suite() {
- return new TestSuite(LRCompletionParseTest.class);
- }
+ return new TestSuite(LRCompletionParseTest.class);
+ }
public LRCompletionParseTest() {
}
@@ -82,16 +82,8 @@ public class LRCompletionParseTest extends TestCase {
// 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";
+ String code = "int aVar; " + "struct D{ " + " int aField1; " + " int aField2; " + "}; " + "void foo() {"
+ + " struct D d; " + " d.a " + "}\n";
int index = code.indexOf("d.a");
@@ -108,19 +100,15 @@ public class LRCompletionParseTest extends TestCase {
IBinding[] bindings = getBindings(names);
assertEquals(2, bindings.length);
- assertEquals("aField1", ((IField)bindings[0]).getName());
- assertEquals("aField2", ((IField)bindings[1]).getName());
+ 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 ";
+ String code = "struct Cube { " + " int nLen; "
+ + " int nWidth; " + " int nHeight; "
+ + "}; " + "int volume(struct Cube * pCube) { "
+ + " pCube->SP ";
IASTCompletionNode node = parse(code, code.indexOf("SP"));
@@ -130,18 +118,14 @@ public class LRCompletionParseTest extends TestCase {
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());
+ 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";
+ 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 ");
@@ -157,14 +141,12 @@ public class LRCompletionParseTest extends TestCase {
assertEquals(3, bindings.length);
assertEquals("aBlockLocal", ((IVariable) bindings[0]).getName());
- assertEquals("aLocal", ((IVariable) bindings[1]).getName());
- assertEquals("aParameter", ((IVariable) bindings[2]).getName());
+ assertEquals("aLocal", ((IVariable) bindings[1]).getName());
+ assertEquals("aParameter", ((IVariable) bindings[2]).getName());
}
public void testCompletionTypedef() throws Exception {
- String code =
- "typedef int Int; " +
- "InSP";
+ String code = "typedef int Int; " + "InSP";
int index = code.indexOf("SP");
@@ -183,11 +165,8 @@ public class LRCompletionParseTest extends TestCase {
}
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";
+ 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");
@@ -201,20 +180,15 @@ public class LRCompletionParseTest extends TestCase {
}
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";
+ 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);
@@ -225,15 +199,9 @@ public class LRCompletionParseTest extends TestCase {
}
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";
+ 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");
@@ -251,10 +219,7 @@ public class LRCompletionParseTest extends TestCase {
}
public void _testCompletionSizeof() throws Exception {
- String code =
- "int f() {\n" +
- "short blah;\n" +
- "int x = sizeof(bl";
+ String code = "int f() {\n" + "short blah;\n" + "int x = sizeof(bl";
int index = code.indexOf("of(bl");
@@ -271,10 +236,7 @@ public class LRCompletionParseTest extends TestCase {
}
public void testCompletionForLoop() throws Exception {
- String code =
- "int f() {\n" +
- " int biSizeImage = 5;\n" +
- "for (int i = 0; i < bi ";
+ String code = "int f() {\n" + " int biSizeImage = 5;\n" + "for (int i = 0; i < bi ";
int index = code.indexOf("< bi");
@@ -291,10 +253,7 @@ public class LRCompletionParseTest extends TestCase {
}
public void testCompletionStructPointer() throws Exception {
- String code =
- " struct Temp { char * total; };" +
- " int f(struct Temp * t) {" +
- " t->t[5] = t->";
+ String code = " struct Temp { char * total; };" + " int f(struct Temp * t) {" + " t->t[5] = t->";
int index = code.indexOf("= t->");
@@ -311,18 +270,11 @@ public class LRCompletionParseTest extends TestCase {
}
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";
+ 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");
@@ -341,11 +293,8 @@ public class LRCompletionParseTest extends TestCase {
}
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].";
+ 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].");
@@ -373,11 +322,7 @@ public class LRCompletionParseTest extends TestCase {
}
public void testCompletionPreprocessorMacro() throws Exception {
- String code =
- "#define AMACRO 99 \n" +
- "int main() { \n" +
- " int AVAR; \n" +
- " int x = A \n";
+ String code = "#define AMACRO 99 \n" + "int main() { \n" + " int AVAR; \n" + " int x = A \n";
int index = code.indexOf("= A");
@@ -390,10 +335,7 @@ public class LRCompletionParseTest extends TestCase {
}
public void testCompletionInsidePreprocessorDirective() throws Exception {
- String code =
- "#define MAC1 99 \n" +
- "#define MAC2 99 \n" +
- "#ifdef MA";
+ String code = "#define MAC1 99 \n" + "#define MAC2 99 \n" + "#ifdef MA";
int index = code.length();
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
index eafe255b092..12baf426be5 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -27,42 +27,45 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
public class LRDOMLocationMacroTests extends DOMLocationMacroTests {
public static TestSuite suite() {
- return suite(LRDOMLocationMacroTests.class);
- }
-
- public LRDOMLocationMacroTests() {}
- public LRDOMLocationMacroTests(String name) { super(name); }
+ 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 {
+ @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);
- }
-
-
+ ParseHelper.Options options = new ParseHelper.Options().setCheckSyntaxProblems(expectNoProblems)
+ .setCheckPreprocessorProblems(expectNoProblems);
+ return ParseHelper.parse(code, language, options);
+ }
+
protected ILanguage getCLanguage() {
- return GCCLanguage.getDefault();
- }
-
+ 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) { }
-// }
-
+
+ /**
+ * 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
index 5bf09d45987..c6cd2a1c97e 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -28,71 +28,76 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
public class LRDOMLocationTests extends DOMLocationTests {
public static TestSuite suite() {
- return suite(LRDOMLocationTests.class);
- }
-
- public LRDOMLocationTests() { }
- public LRDOMLocationTests(String name) { super(name); }
-
+ return suite(LRDOMLocationTests.class);
+ }
+
+ public LRDOMLocationTests() {
+ }
+
+ public LRDOMLocationTests(String name) {
+ super(name);
+ }
+
//TODO ??? overwrite some failed test cases
@Override
- public void test162180_3() throws Exception {}
-
- @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();
- }
-
+ public void test162180_3() throws Exception {
+ }
+
+ @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
+ // 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) {}
-// }
+ 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
index ea82b2e310c..70479424f0f 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -27,24 +27,25 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
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();
- }
-
+ 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
index 3d93c975aba..95628e3b9c4 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -38,7 +38,6 @@ import org.eclipse.cdt.core.model.ILanguage;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-
/**
* TODO these tests can be moved into the core
*/
@@ -46,143 +45,129 @@ import junit.framework.TestSuite;
public class LRDigraphTrigraphTests extends TestCase {
public static TestSuite suite() {
- return new TestSuite(LRDigraphTrigraphTests.class);
- }
-
-
- public LRDigraphTrigraphTests() { }
- public LRDigraphTrigraphTests(String name) { super(name); }
+ return new TestSuite(LRDigraphTrigraphTests.class);
+ }
+ public LRDigraphTrigraphTests() {
+ }
+
+ public LRDigraphTrigraphTests(String name) {
+ super(name);
+ }
- protected IASTTranslationUnit parse(String code) {
+ protected IASTTranslationUnit parse(String code) {
ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(true);
- options.setCheckPreprocessorProblems(true);
+ 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";
-
+ 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];
+ IASTPreprocessorMacroDefinition macro = (IASTPreprocessorMacroDefinition) defines[0];
assertEquals("SIZE", macro.getName().toString());
//assertEquals("99", macro.getExpansion());
-
- IASTFunctionDefinition main = (IASTFunctionDefinition)tu.getDeclarations()[0];
+
+ 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];
+ 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();
+ 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();
+ 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();
+ 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();
+ IASTBinaryExpression cond2 = (IASTBinaryExpression) cond.getOperand1();
assertEquals(IASTBinaryExpression.op_binaryXor, cond2.getOperator());
- IASTUnaryExpression not = (IASTUnaryExpression)cond2.getOperand1();
+ IASTUnaryExpression not = (IASTUnaryExpression) cond2.getOperand1();
assertEquals(IASTUnaryExpression.op_tilde, not.getOperator());
-
+
// printf(\"%c??/n\", arr??(4??));
- IASTFunctionCallExpression expr2 = (IASTFunctionCallExpression)((IASTExpressionStatement)statements[2]).getExpression();
+ IASTFunctionCallExpression expr2 = (IASTFunctionCallExpression) ((IASTExpressionStatement) statements[2])
+ .getExpression();
IASTInitializerClause[] args = expr2.getArguments();
IASTArraySubscriptExpression arr_op2 = (IASTArraySubscriptExpression) args[1];
- assertEquals("4", ((IASTLiteralExpression)arr_op2.getSubscriptExpression()).toString());
+ 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";
+ 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";
-
+ 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];
+
+ 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];
+
+ 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();
+ 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";
-
+ 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];
+
+ 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();
+
+ IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) ((IASTDeclarationStatement) statements[0])
+ .getDeclaration();
IASTDeclarator declarator1 = decl1.getDeclarators()[0];
assertEquals("xy", declarator1.getName().toString());
- IASTLiteralExpression expr1 = (IASTLiteralExpression)((IASTEqualsInitializer)declarator1.getInitializer()).getInitializerClause();
+ IASTLiteralExpression expr1 = (IASTLiteralExpression) ((IASTEqualsInitializer) declarator1.getInitializer())
+ .getInitializerClause();
assertEquals(IASTLiteralExpression.lk_string_literal, expr1.getKind());
assertEquals("\"its all good\"", expr1.toString());
-
- IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration)((IASTDeclarationStatement)statements[1]).getDeclaration();
+
+ IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) ((IASTDeclarationStatement) statements[1])
+ .getDeclaration();
IASTDeclarator declarator2 = decl2.getDeclarators()[0];
assertEquals("ab", declarator2.getName().toString());
- IASTLiteralExpression expr2 = (IASTLiteralExpression)((IASTEqualsInitializer)declarator2.getInitializer()).getInitializerClause();
+ IASTLiteralExpression expr2 = (IASTLiteralExpression) ((IASTEqualsInitializer) declarator2.getInitializer())
+ .getInitializerClause();
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
index 393594ff56c..cb13ee933aa 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -27,32 +27,37 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
public class LRGCCCompleteParseExtensionsTest extends GCCCompleteParseExtensionsTest {
public static TestSuite suite() {
- return suite(LRGCCCompleteParseExtensionsTest.class);
- }
-
- public LRGCCCompleteParseExtensionsTest() {}
- public LRGCCCompleteParseExtensionsTest(String name) { super(name); }
-
+ return suite(LRGCCCompleteParseExtensionsTest.class);
+ }
+
+ public LRGCCCompleteParseExtensionsTest() {
+ }
+
+ public LRGCCCompleteParseExtensionsTest(String name) {
+ super(name);
+ }
+
//override the test failed case for 342683
@Override
- public void testTypeTraits_Bug342683() throws Exception {}
-
-
- @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();
- }
-
+ public void testTypeTraits_Bug342683() throws Exception {
+ }
+
+ @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
index 4549456e556..17d0191db73 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -27,28 +27,32 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
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();
- }
-
+ 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
index 5c22f1203d5..4db9e2cadd2 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -27,31 +27,34 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
public class LRImageLocationTests extends ImageLocationTests {
public static TestSuite suite() {
- return suite(LRImageLocationTests.class);
- }
-
- public LRImageLocationTests() { }
- public LRImageLocationTests(String name) { super(name); }
-
-
+ return suite(LRImageLocationTests.class);
+ }
+
+ public LRImageLocationTests() {
+ }
+
+ public LRImageLocationTests(String name) {
+ super(name);
+ }
+
@Override
@SuppressWarnings("unused")
- protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions,
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
boolean expectNoProblems, int limitTrivialInitializers) throws ParserException {
- ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
- ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(expectNoProblems);
- options.setCheckPreprocessorProblems(expectNoProblems);
- options.setLimitTrivialInitializers(limitTrivialInitializers);
- return ParseHelper.parse(code, language, options);
- }
-
- protected ILanguage getCLanguage() {
- return GCCLanguage.getDefault();
- }
-
- protected ILanguage getCPPLanguage() {
- return GPPLanguage.getDefault();
- }
-
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setLimitTrivialInitializers(limitTrivialInitializers);
+ 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/LRInactiveCodeTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRInactiveCodeTests.java
index 231b040d130..fb01e04ae34 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRInactiveCodeTests.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRInactiveCodeTests.java
@@ -25,32 +25,33 @@ import org.eclipse.cdt.core.parser.tests.ast2.ASTInactiveCodeTests;
public class LRInactiveCodeTests extends ASTInactiveCodeTests {
public static TestSuite suite() {
- return suite(LRInactiveCodeTests.class);
- }
-
+ return suite(LRInactiveCodeTests.class);
+ }
+
public LRInactiveCodeTests() {
}
-
+
public LRInactiveCodeTests(String name) {
super(name);
}
-
-
+
@Override
- protected IASTTranslationUnit parse( String code, ParserLanguage lang, @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems, int limitTrivialInitializers) {
- ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
- ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(expectNoProblems);
- options.setCheckPreprocessorProblems(expectNoProblems);
- options.setLimitTrivialInitializers(limitTrivialInitializers);
- return ParseHelper.parse(code, language, options);
- }
-
- protected ILanguage getCLanguage() {
- return GCCLanguage.getDefault();
- }
-
- protected ILanguage getCPPLanguage() {
- return GPPLanguage.getDefault();
- }
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang,
+ @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems,
+ int limitTrivialInitializers) {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setLimitTrivialInitializers(limitTrivialInitializers);
+ 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
index b76ff71f5ca..82c993e9b86 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -28,60 +28,64 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
*/
@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();
- }
-
+ 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
+
+ // LPG handles syntax errors differently than the DOM parser
// these tests look for syntax errors in specific places and they fail
-
- @Override
+
+ @Override
public void testKRCProblem3() throws Exception {
- try {
- super.testKRCProblem3();
- fail();
- } catch(Throwable expectedException) { }
- }
-
- @Override
- public void testKRCProblem4() throws Exception {
- try {
- super.testKRCProblem4();
- fail();
- } catch(Throwable expectedException) { }
- }
+ try {
+ super.testKRCProblem3();
+ fail();
+ } catch (Throwable expectedException) {
+ }
+ }
+
+ @Override
+ public void testKRCProblem4() throws Exception {
+ try {
+ super.testKRCProblem4();
+ fail();
+ } catch (Throwable expectedException) {
+ }
+ }
+
+ @Override
+ public void testKRCProblem5() throws Exception {
+ try {
+ super.testKRCProblem5();
+ fail();
+ } catch (Throwable expectedException) {
+ }
+ }
+
+ @Override
+ public void testKRCProblem2() throws Exception {
+ try {
+ super.testKRCProblem2();
+ fail();
+ } catch (Throwable expectedException) {
+ }
+ }
- @Override
- public void testKRCProblem5() throws Exception {
- try {
- super.testKRCProblem5();
- fail();
- } catch(Throwable expectedException) { }
- }
-
- @Override
- public void testKRCProblem2() throws Exception {
- try {
- super.testKRCProblem2();
- fail();
- } catch(Throwable expectedException) { }
- }
-
}
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
index ba36eea38dd..3beb172c7cb 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -27,39 +27,43 @@ 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); }
-
-
+ 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, int limitTrivialInitializers) throws ParserException {
- ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
- ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(expectNoProblems);
- options.setCheckPreprocessorProblems(expectNoProblems);
- options.setLimitTrivialInitializers(limitTrivialInitializers);
- return ParseHelper.parse(code, language, options);
- }
-
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang,
+ @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems,
+ int limitTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setLimitTrivialInitializers(limitTrivialInitializers);
+ 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);
+ 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();
}
-
-
- 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/LRQuickParser2Tests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRQuickParser2Tests.java
index 07e8aafbef8..29d803327b0 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -21,164 +21,164 @@ import org.eclipse.cdt.core.parser.tests.ast2.QuickParser2Tests;
public class LRQuickParser2Tests extends QuickParser2Tests {
- public LRQuickParser2Tests() {}
- public LRQuickParser2Tests(String name) { super(name); }
-
-
+ public LRQuickParser2Tests() {
+ }
+
+ public LRQuickParser2Tests(String name) {
+ super(name);
+ }
+
@Override
- protected void parse(String code, boolean expectedToPass,
- ParserLanguage lang, @SuppressWarnings("unused") boolean gcc) throws Exception {
+ 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);
+ 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
}
-
-
- 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 _) { }
-// }
+ // @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
index 26354566f11..968072dbdb8 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -32,68 +32,75 @@ 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); }
+ 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 {
+ 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 {
+ 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);
+ 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 ) {
+ }
+
+ 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);
-
+ 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 {
+ 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();
- }
-
+ 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
index 8d001d0ea2b..e3c4f1988d9 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -27,30 +27,33 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
public class LRSemanticsTests extends SemanticsTests {
public static TestSuite suite() {
- return suite(LRSemanticsTests.class);
- }
-
- public LRSemanticsTests() { }
- public LRSemanticsTests(String name) { super(name); }
-
-
- @SuppressWarnings("unused")
+ return suite(LRSemanticsTests.class);
+ }
+
+ public LRSemanticsTests() {
+ }
+
+ public LRSemanticsTests(String name) {
+ super(name);
+ }
+
+ @SuppressWarnings("unused")
@Override
- protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions,
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
boolean expectNoProblems, int limitTrivialInitializers) throws ParserException {
- ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
- ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(expectNoProblems);
- options.setCheckPreprocessorProblems(expectNoProblems);
- options.setLimitTrivialInitializers(limitTrivialInitializers);
- return ParseHelper.parse(code, language, options);
- }
-
- protected ILanguage getCLanguage() {
- return GCCLanguage.getDefault();
- }
-
- protected ILanguage getCPPLanguage() {
- return GPPLanguage.getDefault();
- }
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setLimitTrivialInitializers(limitTrivialInitializers);
+ 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
index 18eefd011f9..c39dd414d2a 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -27,28 +27,31 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
public class LRTaskParserTest extends TaskParserTest {
public static TestSuite suite() {
- return new TestSuite(LRTaskParserTest.class);
- }
-
+ return new TestSuite(LRTaskParserTest.class);
+ }
+
@Override
- protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
+ boolean expectNoProblems) throws ParserException {
return parse(code, lang, useGNUExtensions, expectNoProblems, -1);
- }
-
+ }
+
@Override
- protected IASTTranslationUnit parse( String code, ParserLanguage lang, @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems, int limitTrivialInitializers) throws ParserException {
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang,
+ @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems,
+ int limitTrivialInitializers) throws ParserException {
ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
- ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(expectNoProblems);
- options.setCheckPreprocessorProblems(expectNoProblems);
- options.setLimitTrivialInitializers(limitTrivialInitializers);
- return ParseHelper.parse(code, language, options);
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setLimitTrivialInitializers(limitTrivialInitializers);
+ return ParseHelper.parse(code, language, options);
}
-
+
protected ILanguage getCLanguage() {
- return GCCLanguage.getDefault();
- }
-
+ 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
index 10a4a0aff39..0101827f051 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -26,114 +26,187 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
@SuppressWarnings("restriction")
public class LRTemplateTests extends AST2TemplateTests {
-
public static TestSuite suite() {
- return suite(LRTemplateTests.class);
- }
-
+ return suite(LRTemplateTests.class);
+ }
+
//override the test failed cases of 341747
@Override
- public void testTemplateIDAmbiguity_341747a() throws Exception{}
+ public void testTemplateIDAmbiguity_341747a() throws Exception {
+ }
+
@Override
- public void testTemplateIDAmbiguity_341747b() throws Exception{}
+ public void testTemplateIDAmbiguity_341747b() throws Exception {
+ }
+
@Override
- public void testTemplateIDAmbiguity_341747c() throws Exception{}
+ public void testTemplateIDAmbiguity_341747c() throws Exception {
+ }
+
@Override
- public void testTemplateIDAmbiguity_341747d() throws Exception{}
-
+ public void testTemplateIDAmbiguity_341747d() throws Exception {
+ }
+
//override some failed test cases
@Override
- public void testNestedArguments_246079() throws Throwable {}
+ public void testNestedArguments_246079() throws Throwable {
+ }
+
@Override
- public void testTypeVsExpressionInArgsOfDependentTemplateID_257194() throws Exception {}
+ public void testTypeVsExpressionInArgsOfDependentTemplateID_257194() throws Exception {
+ }
+
@Override
- public void testCtorWithTemplateID_259600() throws Exception {}
+ public void testCtorWithTemplateID_259600() throws Exception {
+ }
+
@Override
- public void testClosingAngleBrackets1_261268() throws Exception {}
+ public void testClosingAngleBrackets1_261268() throws Exception {
+ }
+
@Override
- public void testClosingAngleBracketsAmbiguity_261268() throws Exception {}
+ public void testClosingAngleBracketsAmbiguity_261268() throws Exception {
+ }
+
@Override
- public void testFunctionParameterPacks_280909() throws Exception {}
+ public void testFunctionParameterPacks_280909() throws Exception {
+ }
+
@Override
- public void testTemplateParameterPacks_280909() throws Exception {}
+ public void testTemplateParameterPacks_280909() throws Exception {
+ }
+
@Override
- public void testParameterPackExpansions_280909() throws Exception {}
+ public void testParameterPackExpansions_280909() throws Exception {
+ }
+
@Override
- public void testTemplateParameterPacksAmbiguity_280909() throws Exception {}
+ public void testTemplateParameterPacksAmbiguity_280909() throws Exception {
+ }
+
@Override
- public void testNonTypeTemplateParameterPack_280909() throws Exception {}
-
+ public void testNonTypeTemplateParameterPack_280909() throws Exception {
+ }
+
//the below test case are for C++0x features which are not included in XLC++ yet
@Override
- public void testRValueReferences_294730() throws Exception {}
+ public void testRValueReferences_294730() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909a() throws Exception {}
+ public void testVariadicTemplateExamples_280909a() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909b() throws Exception {}
+ public void testVariadicTemplateExamples_280909b() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909c() throws Exception {}
+ public void testVariadicTemplateExamples_280909c() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909d() throws Exception {}
+ public void testVariadicTemplateExamples_280909d() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909e() throws Exception {}
+ public void testVariadicTemplateExamples_280909e() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909f() throws Exception {}
+ public void testVariadicTemplateExamples_280909f() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909g() throws Exception {}
+ public void testVariadicTemplateExamples_280909g() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909i() throws Exception {}
+ public void testVariadicTemplateExamples_280909i() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909j() throws Exception {}
+ public void testVariadicTemplateExamples_280909j() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909k() throws Exception {}
+ public void testVariadicTemplateExamples_280909k() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909n() throws Exception {}
+ public void testVariadicTemplateExamples_280909n() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909p() throws Exception {}
+ public void testVariadicTemplateExamples_280909p() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909q() throws Exception {}
+ public void testVariadicTemplateExamples_280909q() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909r() throws Exception {}
+ public void testVariadicTemplateExamples_280909r() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909s() throws Exception {}
+ public void testVariadicTemplateExamples_280909s() throws Exception {
+ }
+
@Override
- public void testExtendingVariadicTemplateTemplateParameters_302282() throws Exception {}
+ public void testExtendingVariadicTemplateTemplateParameters_302282() throws Exception {
+ }
+
@Override
- public void testVariadicTemplateExamples_280909h() throws Exception {}
+ public void testVariadicTemplateExamples_280909h() throws Exception {
+ }
+
@Override
- public void testInlineNamespaces_305980() throws Exception {}
+ public void testInlineNamespaces_305980() throws Exception {
+ }
+
@Override
- public void testFunctionParameterPacksInNonFinalPosition_324096() throws Exception {}
+ public void testFunctionParameterPacksInNonFinalPosition_324096() throws Exception {
+ }
+
//decltype related
@Override
- public void testFunctionCallOnDependentName_337686() throws Exception {}
- //variadic template
+ public void testFunctionCallOnDependentName_337686() throws Exception {
+ }
+
+ //variadic template
@Override
- public void testVariadicFunctionTemplate_333389() throws Exception {}
+ public void testVariadicFunctionTemplate_333389() throws Exception {
+ }
+
//auto
- @Override
- public void testRRefVsRef_351927() throws Exception {}
- //Variadic template arguments
@Override
- public void testTemplateTemplateParameterMatching_352859() throws Exception {}
-
+ public void testRRefVsRef_351927() throws Exception {
+ }
+
+ //Variadic template arguments
+ @Override
+ public void testTemplateTemplateParameterMatching_352859() throws Exception {
+ }
+
@Override
@SuppressWarnings("unused")
- protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, int limitTrivialInitializers) throws ParserException {
- ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
- ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(expectNoProblems);
- options.setCheckPreprocessorProblems(expectNoProblems);
- options.setLimitTrivialInitializers(limitTrivialInitializers);
- return ParseHelper.parse(code, language, options);
- }
-
- protected ILanguage getCLanguage() {
- return GCCLanguage.getDefault();
- }
-
- protected ILanguage getCPPLanguage() {
- return GPPLanguage.getDefault();
- }
-
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
+ boolean expectNoProblems, int limitTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setLimitTrivialInitializers(limitTrivialInitializers);
+ 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
index 9e9da297986..adf1affcaea 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -26,187 +26,228 @@ 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 static TestSuite suite() {
+ return suite(LRTests.class);
+ }
+
public LRTests(String name) {
super(name);
}
-
+
//TODO ??? overwrite some failed test cases
@Override
- public void testFnReturningPtrToFn() throws Exception {}
+ public void testFnReturningPtrToFn() throws Exception {
+ }
+
@Override
- public void testBug270275_int_is_equivalent_to_signed_int() throws Exception {}
+ public void testBug270275_int_is_equivalent_to_signed_int() throws Exception {
+ }
+
@Override
- public void testFunctionDefTypes() throws Exception {}
+ public void testFunctionDefTypes() throws Exception {
+ }
+
@Override
- public void testBug80171() throws Exception {}
+ public void testBug80171() throws Exception {
+ }
+
@Override
- public void testBug192165() throws Exception {}
+ public void testBug192165() throws Exception {
+ }
+
@Override
- public void testTypenameInExpression() throws Exception {}
+ public void testTypenameInExpression() throws Exception {
+ }
+
@Override
- public void testParamWithFunctionType_84242() throws Exception {}
+ public void testParamWithFunctionType_84242() throws Exception {
+ }
+
@Override
- public void testParamWithFunctionTypeCpp_84242() throws Exception {}
+ public void testParamWithFunctionTypeCpp_84242() throws Exception {
+ }
+
@Override
- public void testFunctionReturningPtrToArray_216609() throws Exception {}
+ public void testFunctionReturningPtrToArray_216609() throws Exception {
+ }
+
@Override
- public void testNestedFunctionDeclarators() throws Exception {}
+ public void testNestedFunctionDeclarators() throws Exception {
+ }
+
@Override
- public void testConstantExpressionBinding() throws Exception {}
+ public void testConstantExpressionBinding() throws Exception {
+ }
+
@Override
- public void testAmbiguousDeclaration_259373() throws Exception {}
+ public void testAmbiguousDeclaration_259373() throws Exception {
+ }
+
@Override
- public void testSizeofFunctionType_252243() throws Exception {}
+ public void testSizeofFunctionType_252243() throws Exception {
+ }
+
@Override
- public void testSkipAggregateInitializer_297550() throws Exception {}
+ public void testSkipAggregateInitializer_297550() throws Exception {
+ }
+
@Override
- public void testDeepElseif_298455() throws Exception {}
+ public void testDeepElseif_298455() throws Exception {
+ }
+
@Override
- public void testAttributeSyntax_298841() throws Exception {}
+ public void testAttributeSyntax_298841() throws Exception {
+ }
+
@Override
- public void testEmptyTrailingMacro_303152() throws Exception {}
+ public void testEmptyTrailingMacro_303152() throws Exception {
+ }
+
@Override // not applicable to lr parser memory usage.
- public void testLargeTrivialAggregateInitializer_253690() throws Exception {}
- @Override
- public void testMaximumTrivialExpressionsInInitializers_412380() throws Exception {}
- @Override
- public void testNoSkipTrivialAggregateInitializer_412380() throws Exception {}
- @Override
- public void testNoSkipNonTrivialAggregateInitializer_412380() throws Exception {}
-
- @Override
- protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
- return parse(code, lang, useGNUExtensions, expectNoProblems, -1);
- }
-
- @Override
- protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, int limitTrivialInitializers) throws ParserException {
- ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
- ParseHelper.Options options = new ParseHelper.Options();
- options.setCheckSyntaxProblems(expectNoProblems);
- options.setCheckPreprocessorProblems(expectNoProblems);
- options.setLimitTrivialInitializers(limitTrivialInitializers);
- 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 {
- StringBuilder sb = new StringBuilder();
- 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 {
- StringBuilder sb = new StringBuilder();
- 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 testLargeTrivialAggregateInitializer_253690() throws Exception {
+ }
+
+ @Override
+ public void testMaximumTrivialExpressionsInInitializers_412380() throws Exception {
+ }
+
+ @Override
+ public void testNoSkipTrivialAggregateInitializer_412380() throws Exception {
+ }
+
+ @Override
+ public void testNoSkipNonTrivialAggregateInitializer_412380() throws Exception {
+ }
+
+ @Override
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
+ boolean expectNoProblems) throws ParserException {
+ return parse(code, lang, useGNUExtensions, expectNoProblems, -1);
+ }
+
+ @Override
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions,
+ boolean expectNoProblems, int limitTrivialInitializers) throws ParserException {
+ ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage();
+ ParseHelper.Options options = new ParseHelper.Options();
+ options.setCheckSyntaxProblems(expectNoProblems);
+ options.setCheckPreprocessorProblems(expectNoProblems);
+ options.setLimitTrivialInitializers(limitTrivialInitializers);
+ 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 {
+ StringBuilder sb = new StringBuilder();
+ 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 {
+ StringBuilder sb = new StringBuilder();
+ 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());
- }
-
-
+ 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 {
+ public void testBug196468_emptyArrayInitializer() {
+ }
+
+ public void _testBug196468_emptyArrayInitializer() throws Exception {
super.testBug196468_emptyArrayInitializer();
}
-
-
-
+
/* LPG holds on to all the tokens as you parse, so I don't think
- * it would be easy to fix this bug.
+ * it would be easy to fix this bug.
*/
@Override
- public void testScalabilityOfLargeTrivialInitializer_253690() { }
- public void _testScalabilityOfLargeTrivialInitializer_253690() throws Exception {
-
+ public void testScalabilityOfLargeTrivialInitializer_253690() {
+ }
+
+ public void _testScalabilityOfLargeTrivialInitializer_253690() throws Exception {
+
super.testScalabilityOfLargeTrivialInitializer_253690();
}
-
-
+
/* 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_237057() { }
- public void _testBinaryVsCastAmbiguities_237057() throws Exception {
+ public void testBinaryVsCastAmbiguities_237057() {
+ }
+
+ public void _testBinaryVsCastAmbiguities_237057() throws Exception {
super.testBinaryVsCastAmbiguities_237057();
}
-
-
+
/* 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_237057() { }
- public void _testCastVsFunctionCallAmbiguities_237057() throws Exception {
+ public void testCastVsFunctionCallAmbiguities_237057() {
+ }
+
+ public void _testCastVsFunctionCallAmbiguities_237057() throws Exception {
super.testCastVsFunctionCallAmbiguities_237057();
}
-
+
/* The LR parser generates the AST for switch statements
* differently than the DOM parser.
*/
@Override
- public void testCaseRange_211882() { }
- public void _testCaseRange_211882() throws Exception {
+ public void testCaseRange_211882() {
+ }
+
+ public void _testCaseRange_211882() throws Exception {
super.testCaseRange_211882();
}
}
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
index dc7a384bfd8..ead99ae5ea9 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -28,32 +28,31 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
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();
- }
-
+ 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
+
+ @Override
public void testCastExpression() throws Exception { // A not typedefed
- try {
- super.testCastExpression();
- fail();
- } catch(AssertionFailedError expectedException) {}
- }
+ try {
+ super.testCastExpression();
+ fail();
+ } catch (AssertionFailedError expectedException) {
+ }
+ }
}
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
index c6fd937ebb8..d4a53f51b97 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -27,31 +27,32 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
public class LRUtilTests extends AST2UtilTests {
public static TestSuite suite() {
- return suite(LRUtilTests.class);
- }
-
+ 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 ) throws ParserException {
- return parse(code, lang, false, true );
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang, boolean useGNUExtensions)
+ throws ParserException {
+ return parse(code, lang, useGNUExtensions, true);
}
-
+
@Override
- protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions ) throws ParserException {
- return parse( code, lang, useGNUExtensions, true );
+ @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);
}
-
- @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 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
index 9b6297da45e..016cfcc5c81 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -39,26 +39,23 @@ import org.eclipse.core.runtime.CoreException;
/**
* Utility methods for parsing test code using the C99 LPG parser.
- *
+ *
* @author Mike Kucera
*/
-@SuppressWarnings({"restriction", "nls"})
+@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);
@@ -66,217 +63,224 @@ public class ParseHelper {
if (binding instanceof IProblemBinding) {
// Suppress assertion that would be thrown for computing string representation
// of template-ids. The flag will be reset by BaseTestCase.setUp().
- CPPASTNameBase.sAllowNameComputation= true;
+ CPPASTNameBase.sAllowNameComputation = true;
problemBindings.add(name.toString());
}
if (binding == null)
numNullBindings++;
return PROCESS_CONTINUE;
}
-
+
public IASTName getName(int idx) {
- if(idx < 0 || idx >= nameList.size())
+ if (idx < 0 || idx >= nameList.size())
return null;
return nameList.get(idx);
}
-
- public int size() {
- return nameList.size();
+
+ public int size() {
+ return nameList.size();
}
}
-
-
-
+
public static class Options {
-
+
boolean checkSyntaxProblems = true;
boolean checkPreprocessorProblems = true;
boolean checkBindings = false;
-
+
int expectedProblemBindings;
String[] problems;
int limitTrivialInitializers = -1;
-
+
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 setLimitTrivialInitializers(int limitTrivialInitializers) {
this.limitTrivialInitializers = limitTrivialInitializers;
return this;
}
-
+
}
-
-
+
public static IASTTranslationUnit parse(String code, ILanguage lang, boolean expectNoProblems) {
- Options options = new Options().setCheckSyntaxProblems(expectNoProblems).setCheckPreprocessorProblems(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) {
-
+
return parse(FileContent.create(AST2TestBase.TEST_CODE, code), 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.
* @Deprecated
*/
- public static IASTTranslationUnit parse(CodeReader codeReader, ILanguage language, IScannerInfo scanInfo,
- ICodeReaderFactory fileCreator, Options options) {
+ public static IASTTranslationUnit parse(CodeReader codeReader, ILanguage language, IScannerInfo scanInfo,
+ ICodeReaderFactory fileCreator, Options options) {
testsRun++;
-
+
IASTTranslationUnit tu;
try {
int languageOptions = 0;
- if(options.limitTrivialInitializers >= 0 && options.limitTrivialInitializers != Integer.MAX_VALUE)
+ if (options.limitTrivialInitializers >= 0 && options.limitTrivialInitializers != Integer.MAX_VALUE)
languageOptions |= ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS;
-
- tu = language.getASTTranslationUnit(codeReader, scanInfo, fileCreator, null, languageOptions, ParserUtil.getParserLogService());
+
+ 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.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 (options.checkPreprocessorProblems) {
if (tu.getPreprocessorProblems().length != 0) {
- throw new AssertionFailedError(language.getName() + " TranslationUnit has Preprocessor Problems " );
+ throw new AssertionFailedError(language.getName() + " TranslationUnit has Preprocessor Problems ");
}
- }
+ }
- // resolve all bindings
+ // 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++) {
+ 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));
+ if (!expected.equals(actual))
+ throw new AssertionFailedError(
+ String.format("Problem binding not equal, expected: %s, got: %s", expected, actual));
}
}
}
-
+
return tu;
}
-
+
/**
* 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(FileContent fileContent, ILanguage language, IScannerInfo scanInfo,
+ public static IASTTranslationUnit parse(FileContent fileContent, ILanguage language, IScannerInfo scanInfo,
IncludeFileContentProvider fileContentProvider, Options options) {
testsRun++;
-
+
IASTTranslationUnit tu;
try {
int languageOptions = 0;
- if(options.limitTrivialInitializers >= 0 && options.limitTrivialInitializers != Integer.MAX_VALUE)
+ if (options.limitTrivialInitializers >= 0 && options.limitTrivialInitializers != Integer.MAX_VALUE)
languageOptions |= ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS;
-
- tu = language.getASTTranslationUnit(fileContent, scanInfo, fileContentProvider, null, languageOptions, ParserUtil.getParserLogService());
+
+ tu = language.getASTTranslationUnit(fileContent, scanInfo, fileContentProvider, 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.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 (options.checkPreprocessorProblems) {
if (tu.getPreprocessorProblems().length != 0) {
- throw new AssertionFailedError(language.getName() + " TranslationUnit has Preprocessor Problems " );
+ throw new AssertionFailedError(language.getName() + " TranslationUnit has Preprocessor Problems ");
}
- }
+ }
- // resolve all bindings
+ // 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++) {
+ 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));
+ 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) {
-
+
IASTTranslationUnit tu;
try {
- tu = language.getASTTranslationUnit(FileContent.create(AST2TestBase.TEST_CODE, code.toCharArray()), new ScannerInfo(), null, null, ILanguage.OPTION_ADD_COMMENTS, ParserUtil.getParserLogService());
+ tu = language.getASTTranslationUnit(FileContent.create(AST2TestBase.TEST_CODE, code.toCharArray()),
+ 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) {
int offset = code.length();
- if(offset > 0 && '\n' == code.charAt(offset-1)){
+ if (offset > 0 && '\n' == code.charAt(offset - 1)) {
offset--;
}
return getCompletionNode(code, lang, offset);
}
-
-
+
public static IASTCompletionNode getCompletionNode(String code, ILanguage language, int offset) {
-
+
try {
- return language.getCompletionNode(FileContent.create(AST2TestBase.TEST_CODE, code.toCharArray()), new ScannerInfo(), null, null, ParserUtil.getParserLogService(), offset);
+ return language.getCompletionNode(FileContent.create(AST2TestBase.TEST_CODE, code.toCharArray()),
+ new ScannerInfo(), null, null, ParserUtil.getParserLogService(), offset);
} catch (CoreException e) {
throw new RuntimeException(e);
}
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
index 5d45d3f0069..89d6feb266f 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -62,75 +62,70 @@ 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 {
+@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 ITokenStream parser;
-
- // The symbolTable currently in use
+
+ // 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++) {
+ for (int i = 0; i < steps; i++) {
undo();
}
}
@@ -138,18 +133,16 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
public IC99Scope getCurrentScope() {
return bindingScopeStack.getLast();
}
-
-
+
public C99ResolveParserAction(ITokenStream parser) {
this.parser = parser;
bindingScopeStack.add(new C99Scope(EScopeKind.eGlobal)); // the global scope
System.out.println();
}
-
private static IType rawType(IType type) {
- while(type instanceof ITypedef) {
- type = ((C99Typedef)type).getType();
+ while (type instanceof ITypedef) {
+ type = ((C99Typedef) type).getType();
}
return type;
}
@@ -157,172 +150,172 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
/**
* Lexer feedback hack, used by the parser to identify typedefname tokens.
*/
- public boolean isTypedef(String ident) {
+ 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();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
symbolTableScopeStack.add(symbolTable);
bindingScopeStack.add(new C99Scope(EScopeKind.eLocal));
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
-
+
bindingScopeStack.removeLast();
symbolTable = symbolTableScopeStack.removeLast();
}
});
}
-
public IC99Scope closeSymbolScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final C99SymbolTable undoTable = symbolTable;
symbolTable = symbolTableScopeStack.removeLast(); // close the scope
final IC99Scope undoScope = bindingScopeStack.removeLast();
- if(!bindingScopeStack.isEmpty())
+ if (!bindingScopeStack.isEmpty())
undoScope.setParent(bindingScopeStack.getLast());
-
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.getLast();
frame.openPointerModifierScope();
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
declarationStack.add(new DeclaratorFrame());
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
declarationStack.removeLast();
}
});
}
-
-
+
public void closeDeclarationScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame undoFrame = declarationStack.removeLast();
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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);
-
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
symbolTableScopeStack.add(outerTable);
symbolTable = undoTable;
declarationStack.add(frame);
@@ -331,105 +324,109 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
});
}
-
public void consumeAbstractDeclaratorFunctionDeclarator() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.getLast();
frame.setFunctionDeclarator(true);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
frame.setFunctionDeclarator(false);
}
});
}
-
public void consumeDirectDeclaratorFunctionDeclarator() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.getLast();
frame.setFunctionDeclarator(true);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
frame.setFunctionDeclarator(false);
}
});
}
-
public void consumeDeclSpecToken() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
symbolTable = oldTable;
}
});
-
+
return labelBinding;
}
-
-
+
public IBinding consumeStatementGoto() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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) {
+ if (labelBinding == null) {
labelBinding = new C99Label(ident);
symbolTable = symbolTable.insert(GOTO_LABEL, ident, labelBinding);
}
@@ -437,413 +434,423 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
symbolTable = oldTable;
}
});
-
-
+
return labelBinding;
}
-
-
+
public IBinding consumeDeclarationSpecifiersTypedefName() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
// find the typedef token
String typedefName = null;
- for(IToken token : parser.getRuleTokens()) {
+ 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) {
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
declSpec.setType(null);
}
});
-
+
return binding;
}
-
-
public void consumeDirectDeclaratorIdentifier() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.getLast();
DebugUtil.printMethodTrace();
frame.setDeclaratorName(parser.getRightIToken());
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ 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();
-
+ 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)) {
+
+ for (C99PointerType pt : reverseIterable(scope)) {
frame.addTypeModifier(pt);
}
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
- for(int i = 0; i < scopeSize; i++) {
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+ for (int i = 0; i < scopeSize; i++) {
frame.removeLastTypeModifier();
}
frame.openPointerModifierScope(scope);
}
});
}
-
-
-
+
public void consumeDirectDeclaratorBracketed() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
frame.setDeclaratorBracketed(false);
}
});
}
-
-
+
public IBinding consumeDeclaratorComplete() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.getLast();
-
- IToken token = frame.getDeclaratorName();
- IType type = frame.getDeclaratorType();
- DeclSpec declSpec = frame.getDeclSpec();
+
+ IToken token = frame.getDeclaratorName();
+ IType type = frame.getDeclaratorType();
+ DeclSpec declSpec = frame.getDeclSpec();
boolean isFunction = frame.isFunctionDeclarator();
List<IBinding> nestedDeclarators = frame.getNestedDeclarations();
-
- if(isFunction)
+
+ if (isFunction)
type = createFunctionType(type, nestedDeclarators);
-
+
String ident = (token == null) ? null : token.toString();
-
+
// compute the binding
IC99Binding binding;
- if(declSpec.isTypedef())
+ if (declSpec.isTypedef())
binding = createTypedefBinding(ident, type);
- else if(isFunction && !frame.isDeclaratorBracketed())
- binding = createFunctionBinding(ident, (IFunctionType)type, declSpec, nestedDeclarators);
+ 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)
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final IType type = exprTypeStack.pop();
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
exprTypeStack.push(type);
}
});
}
-
-
+
public IBinding consumeFunctionDefinitionHeader() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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) {
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
symbolTable = oldTable;
}
});
-
+
return binding;
}
-
-
+
public IBinding consumeDeclaratorCompleteParameter() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.removeLast();
IToken token = frame.getDeclaratorName();
- IType type = frame.getDeclaratorType();
+ IType type = frame.getDeclaratorType();
DeclSpec declSpec = frame.getDeclSpec();
boolean isFunction = frame.isFunctionDeclarator();
-
+
// its a function pointer
- if(isFunction)
+ 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) {
+
+ 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];
+ 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) {
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ 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
- *
+ *
+ * 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();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
declarationStack.getLast().removeLastNestedDeclaration();
declarationStack.add(frame);
}
});
-
+
return param;
}
-
-
+
public IBinding consumeDeclaratorCompleteField() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.getLast();
IToken token = frame.getDeclaratorName();
- IType type = frame.getDeclaratorType();
-
+ IType type = frame.getDeclaratorType();
+
// its a function pointer
- if(frame.isFunctionDeclarator())
+ 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
+ declarationStack.add(new DeclaratorFrame(frame.getDeclSpec())); // reset the declarator
exprTypeStack.push(type);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ 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();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.removeLast();
IType type = frame.getDeclaratorType();
- if(frame.isFunctionDeclarator()) // its a function pointer
+ if (frame.isFunctionDeclarator()) // its a function pointer
type = createFunctionType(type, frame.getNestedDeclarations());
-
+
exprTypeStack.push(type);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.pop();
declarationStack.add(frame);
}
});
}
-
public void consumeDirectDeclaratorArrayModifier() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.getLast();
frame.addTypeModifier(new C99ArrayType());
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
frame.removeLastTypeModifier();
}
});
}
-
-
+
public void consumeAbstractDeclaratorArrayModifier() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.getLast();
frame.addTypeModifier(new C99ArrayType());
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
frame.removeLastTypeModifier();
}
});
}
+ public void consumeDirectDeclaratorModifiedArrayModifier(boolean isStatic, boolean isVarSized,
+ boolean hasTypeQualifierList) {
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
- 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) {
+
+ if (hasTypeQualifierList) {
arrayType.setConst(typeQualifiers.isConst);
arrayType.setRestrict(typeQualifiers.isRestrict);
arrayType.setVolatile(typeQualifiers.isVolatile);
@@ -851,595 +858,597 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
final DeclaratorFrame frame = declarationStack.getLast();
frame.addTypeModifier(arrayType);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
frame.removeLastTypeModifier();
}
});
}
-
-
public void consumePointer() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.getLast();
frame.addPointerModifier(new C99PointerType());
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
frame.removeLastPointerModifier();
}
});
}
-
-
+
public void consumePointerTypeQualifierList() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
frame.removeLastPointerModifier();
}
});
}
-
-
+
public void consumeTypeQualifiers() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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;
+
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ 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();
-
+ 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)
+
+ 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 {
+ } else {
undoTable = null; // final variable must be initialized
}
-
+
final DeclSpec declSpec = declarationStack.getLast().getDeclSpec();
- declSpec.setType((IType)structBinding); // upcast
-
-
+ declSpec.setType((IType) structBinding); // upcast
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
declSpec.setType(null);
-
- if(isDeclaration) {
+
+ 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
+ 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) {
+ 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);
+ if (struct == null) {
+ struct = new C99Structure(ident, key);
symbolTable = symbolTable.insert(STRUCT_TAG, ident, struct);
}
- }
- else {
+ } else {
struct = new C99Structure(key);
}
-
+
final DeclaratorFrame frame = declarationStack.getLast();
- for(IBinding binding : frame.getNestedDeclarations()) {
+ 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;
+ if (binding instanceof C99Field) {
+ C99Field field = (C99Field) binding;
struct.addField(field);
field.setCompositeTypeOwner(struct);
}
}
-
+
frame.getDeclSpec().setType(struct);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
frame.getDeclSpec().setType(null);
symbolTable = oldTable;
}
});
-
+
return struct;
}
-
-
+
public IBinding consumeTypeSpecifierEnumeration(final boolean hasName) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
C99Enumeration enumeration = new C99Enumeration();
-
+
final C99SymbolTable oldTable = symbolTable;
- if(hasName) {
- String ident = parser.getRuleTokens().get(1).toString();
+ 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;
+ for (IBinding binding : frame.getNestedDeclarations()) {
+ C99Enumerator enumerator = (C99Enumerator) binding;
enumeration.addEnumerator(enumerator);
enumerator.setType(enumeration);
}
-
+
frame.getDeclSpec().setType(enumeration);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
frame.getDeclSpec().setType(null);
- if(hasName)
+ if (hasName)
symbolTable = oldTable;
}
});
-
+
return enumeration;
}
-
-
public IBinding consumeEnumerator() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
declarationStack.getLast().removeLastNestedDeclaration();
symbolTable = oldTable;
}
});
-
+
return enumerator;
}
-
-
public IField consumeDesignatorBaseField() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.pop();
}
});
-
+
return fieldBinding;
}
-
-
private IType getInitializerType() {
List<IType> outerScope = exprTypeStack.outerScope();
- return outerScope.get(outerScope.size()-1);
+ return outerScope.get(outerScope.size() - 1);
}
-
-
+
public void consumeDesignatorBaseArray() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
IType baseType = getInitializerType();
-
+
IType type = C99ProblemBinding.badType();
- if(baseType instanceof C99ArrayType) {
- type = ((C99ArrayType)baseType).getType();
+ if (baseType instanceof C99ArrayType) {
+ type = ((C99ArrayType) baseType).getType();
}
-
+
exprTypeStack.push(type);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.pop();
}
});
}
public void consumeInitializerStartPositional() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
DebugUtil.printMethodTrace();
-
- IType type = getInitializerType();
+
+ IType type = getInitializerType();
type = rawType(type);
-
+
IType positionType;
- if(type instanceof C99Structure) {
+ if (type instanceof C99Structure) {
int position = exprTypeStack.topScope().size();
- C99Field field = (C99Field)((C99Structure)type).getFields()[position];
+ C99Field field = (C99Field) ((C99Structure) type).getFields()[position];
positionType = field.getType();
- }
- else if(type instanceof IArrayType) {
- positionType = ((C99ArrayType)type).getType();
- }
- else {
+ } else if (type instanceof IArrayType) {
+ positionType = ((C99ArrayType) type).getType();
+ } else {
positionType = C99ProblemBinding.badType();
}
-
+
exprTypeStack.push(positionType);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ 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) {
+ 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) {
+
+ 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);
+ 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();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
exprTypeStack.openScope();
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.closeScope();
}
});
}
-
-
+
@SuppressWarnings("nls")
public void consumeExpressionConstant(int kind) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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$
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.pop();
}
});
}
-
-
- public IBinding consumeExpressionID() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+
+ 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();
-
+ if (binding instanceof ITypeable)
+ type = ((ITypeable) binding).getType();
+
exprTypeStack.push(type);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.pop();
}
});
-
+
return binding;
}
-
public IField consumeExpressionFieldReference(boolean isPointerDereference) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ 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) {
IType type = identType;
- if(isPointerDereference) {
- if(type instanceof IPointerType)
- type = ((ITypeContainer)type).getType(); // do the dereference
+ if (isPointerDereference) {
+ if (type instanceof IPointerType)
+ type = ((ITypeContainer) type).getType(); // do the dereference
else
return null;
}
type = rawType(type);
- if(type instanceof ICompositeType) {
+ if (type instanceof ICompositeType) {
ICompositeType struct = (ICompositeType) type;
return (C99Field) struct.findField(memberName);
}
-
+
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
+ // 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();
-
+ 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) {
+
+ if (identifierType instanceof IFunctionType) {
// TODO: check the parameter types
- IFunctionType functionType = (IFunctionType)identifierType;
+ IFunctionType functionType = (IFunctionType) identifierType;
resultType = functionType.getReturnType();
}
exprTypeStack.push(resultType);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.pop();
exprTypeStack.push(identifierType);
- if(hasArgs)
+ if (hasArgs)
exprTypeStack.openScope(scope);
}
});
}
-
public void consumeExpressionArraySubscript() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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) {
+ if (exprType instanceof IArrayType) {
IArrayType arrType = (IArrayType) exprType;
resultType = arrType.getType(); // strip off the array type
}
-
+
exprTypeStack.push(resultType);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.pop();
exprTypeStack.push(exprType);
exprTypeStack.push(subscriptType);
@@ -1447,146 +1456,155 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
});
}
-
public void consumeExpressionUnaryOperator() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.pop();
exprTypeStack.push(expressionType);
}
});
}
-
public void consumeExpressionUnarySizeofTypeName() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final IType typeNameType = exprTypeStack.pop();
-
+
IType resultType = new C99BasicType(IBasicType.t_int);
exprTypeStack.push(resultType);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.pop();
exprTypeStack.push(typeNameType);
}
});
}
-
public void consumeExpressionCast() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.push(exprType);
}
});
}
-
public void consumeExpressionTypeIdInitializer() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
// Throw away the types of the initializer list
final List<IType> scope = exprTypeStack.closeScope();
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.openScope(scope);
}
});
}
-
+
public void consumeExpressionInitializer() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final IType type = exprTypeStack.pop();
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
exprTypeStack.push(type);
}
});
}
-
public void consumeExpressionBinaryOperator(int op) {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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);
+
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
exprTypeStack.pop();
exprTypeStack.push(op1type);
exprTypeStack.push(op2type);
}
});
}
-
+
public void consumeExpressionConditional() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
exprTypeStack.pop();
exprTypeStack.push(condType);
exprTypeStack.push(expr1Type);
@@ -1595,13 +1613,13 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
});
}
-// // 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();
-// }
-// }
-
+ // // 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
index 8be8c955970..d8161398fb8 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -20,57 +20,52 @@ import lpg.lpgjavaruntime.IToken;
import org.eclipse.cdt.core.dom.lrparser.action.ITokenStream;
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 ITokenStream parser;
-
- // The symbolTable currently in use
+
+ // 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(ITokenStream parser) {
this.parser = parser;
}
-
/**
* Lexer feedback hack, used by the parser to identify typedefname tokens.
@@ -78,265 +73,267 @@ public class C99TypedefTrackerParserAction {
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();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
symbolTableScopeStack.add(symbolTable);
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
symbolTable = symbolTableScopeStack.removeLast();
}
});
}
-
public void closeSymbolScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final TypedefSymbolTable undoTable = symbolTable;
symbolTable = symbolTableScopeStack.removeLast(); // close the scope
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
declarationStack.add(new DeclaratorFrame());
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
declarationStack.removeLast();
}
});
}
-
-
+
public void closeDeclarationScope() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame undoFrame = declarationStack.removeLast();
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
declarationStack.add(undoFrame);
}
});
}
-
-
+
public void consumeFunctionDefinition() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
final DeclaratorFrame frame = declarationStack.removeLast();
-
+
final TypedefSymbolTable undoTable = symbolTable;
symbolTable = symbolTableScopeStack.removeLast();
-
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
symbolTableScopeStack.add(symbolTable);
symbolTable = undoTable;
-
+
declarationStack.add(frame);
}
});
}
-
-
-
public void consumeDeclSpecToken() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
declSpec.remove(kind);
}
});
}
-
-
-
+
public void consumeDirectDeclaratorIdentifier() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.getLast();
frame.setDeclaratorName(parser.getRightIToken());
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
frame.setDeclaratorName(null);
}
});
}
-
-
- public void consumeDeclaratorComplete() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+
+ public void consumeDeclaratorComplete() {
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.getLast();
-
- IToken token = frame.getDeclaratorName();
- DeclSpec declSpec = frame.getDeclSpec();
+
+ 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()) {
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
declarationStack.removeLast();
declarationStack.add(frame);
symbolTable = oldTable;
}
});
}
-
-
-
-
+
public void consumeDeclaratorCompleteParameter() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ 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() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ 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
- *
+ *
+ * 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();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.removeLast();
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
declarationStack.add(frame);
}
});
}
-
-
+
public void consumeDeclaratorCompleteField() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.removeLast();
- declarationStack.add(new DeclaratorFrame(frame.getDeclSpec())); // reset the declarator
+ declarationStack.add(new DeclaratorFrame(frame.getDeclSpec())); // reset the declarator
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
declarationStack.removeLast();
declarationStack.add(frame);
@@ -344,27 +341,28 @@ public class C99TypedefTrackerParserAction {
});
}
-
/**
* 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();
-
+ if (DEBUG)
+ DebugUtil.printMethodTrace();
+
final DeclaratorFrame frame = declarationStack.removeLast();
-
+
undoStack.add(new IUndoAction() {
@Override
public void undo() {
- if(DEBUG) DebugUtil.printMethodTrace();
+ 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
index a8716076250..2c9b4554442 100644
--- 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
@@ -30,41 +30,39 @@ 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 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)
+ if (count == null)
return;
-
- if(count <= 1)
+
+ 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
@@ -74,98 +72,95 @@ class DeclSpec {
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)
+ if (type != null)
return type;
- if(tokenKindMap.isEmpty()) // there are no type tokens, so it must be implicit int
+ 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;
+
+ 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 isConst = contains(TK_const);
boolean isRestrict = contains(TK_restrict);
boolean isVolatile = contains(TK_volatile);
-
- if(isConst || isRestrict || isVolatile)
+
+ if (isConst || isRestrict || isVolatile)
return new C99QualifierType(basicType, isConst, isVolatile, isRestrict);
return basicType;
}
-
public void modifyBinding(C99Variable var) {
- if(!var.isAuto())
+ if (!var.isAuto())
var.setAuto(contains(TK_auto));
- if(!var.isExtern())
+ if (!var.isExtern())
var.setExtern(contains(TK_extern));
- if(!var.isRegister())
+ if (!var.isRegister())
var.setRegister(contains(TK_register));
- if(!var.isStatic())
+ if (!var.isStatic())
var.setStatic(contains(TK_static));
}
-
+
public void modifyBinding(C99Function function) {
- if(!function.isAuto())
+ if (!function.isAuto())
function.setAuto(contains(TK_auto));
- if(!function.isExtern())
+ if (!function.isExtern())
function.setExtern(contains(TK_extern));
- if(!function.isInline())
+ if (!function.isInline())
function.setInline(contains(TK_inline));
- if(!function.isRegister())
+ if (!function.isRegister())
function.setRegister(contains(TK_register));
- if(!function.isStatic())
+ 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
index 32726999144..6ea2e5b70d7 100644
--- 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
@@ -25,9 +25,9 @@ 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")
@@ -37,109 +37,111 @@ public class DeclaratorFrame {
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)
+ 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())
+
+ 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);
+ 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);
+
+ 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
index 97945ff9c54..c03186fd9e5 100644
--- 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
@@ -30,15 +30,14 @@ public class C99ArrayType implements ICArrayType, ITypeContainer {
private boolean isVariableLength;
private IType type;
-
-
+
public C99ArrayType() {
}
-
+
public C99ArrayType(IType type) {
this.type = type;
}
-
+
@Override
public boolean isConst() {
return isConst;
@@ -94,7 +93,7 @@ public class C99ArrayType implements ICArrayType, ITypeContainer {
public IType getType() {
return type;
}
-
+
@Override
public void setType(IType type) {
this.type = type;
@@ -107,29 +106,26 @@ public class C99ArrayType implements ICArrayType, ITypeContainer {
if (t instanceof ITypedef)
return t.isSameType(this);
if (t instanceof ICArrayType) {
- ICArrayType at = (ICArrayType)t;
- if (at.isConst() == isConst &&
- at.isRestrict() == isRestrict &&
- at.isStatic() == isStatic &&
- at.isVolatile() == isVolatile &&
- at.isVariableLength() == isVariableLength) {
+ ICArrayType at = (ICArrayType) t;
+ if (at.isConst() == isConst && at.isRestrict() == isRestrict && at.isStatic() == isStatic
+ && at.isVolatile() == isVolatile && at.isVariableLength() == isVariableLength) {
return at.isSameType(type);
}
}
return false;
}
-
- @Override
+
+ @Override
public IValue getSize() {
return null;
}
- @Override
- public boolean hasSize() {
- return false;
- }
+ @Override
+ public boolean hasSize() {
+ return false;
+ }
- @Override
+ @Override
public C99ArrayType clone() {
C99ArrayType clone = null;
try {
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
index c8a2950f7a0..e33c7e7c955 100644
--- 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
@@ -20,8 +20,8 @@ import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
public class C99BasicType implements ICBasicType {
/* Type flags given in IBasicType */
- private int type;
-
+ private int type;
+
private boolean isLong;
private boolean isShort;
private boolean isSigned;
@@ -30,14 +30,13 @@ public class C99BasicType implements ICBasicType {
private boolean isImaginary;
private boolean isLongLong;
-
public C99BasicType() {
}
-
+
public C99BasicType(int type) {
this.type = type;
}
-
+
@Override
public int getType() {
return type;
@@ -115,25 +114,20 @@ public class C99BasicType implements ICBasicType {
public IASTExpression getValue() {
return null;
}
-
+
@Override
public boolean isSameType(IType t) {
- if(t == this)
+ if (t == this)
return true;
- if(!(t instanceof C99BasicType))
+ 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;
- }
-
+ 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 {
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
index 2c3026bc026..6cbc4e7bdca 100644
--- 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
@@ -20,10 +20,8 @@ import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
public class C99CompositeTypeScope extends C99Scope implements ICCompositeTypeScope {
-
private ICompositeType struct;
-
-
+
public C99CompositeTypeScope(ICompositeType struct) {
super(EScopeKind.eClassType);
this.struct = struct;
@@ -33,7 +31,7 @@ public class C99CompositeTypeScope extends C99Scope implements ICCompositeTypeSc
public ICompositeType getCompositeType() {
return struct;
}
-
+
@Override
public IBinding getBinding(@SuppressWarnings("unused") char[] name) {
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
index 2721e2a0eab..e0b0f1b03ee 100644
--- 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
@@ -32,23 +32,22 @@ 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 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);
}
-
+
@Override
public IEnumerator[] getEnumerators() {
return enumerators.toArray(new IEnumerator[enumerators.size()]);
@@ -57,7 +56,7 @@ public class C99Enumeration extends PlatformObject implements IC99Binding, IEnum
public void setName(String name) {
this.name = name;
}
-
+
@Override
public String getName() {
return name;
@@ -68,42 +67,41 @@ public class C99Enumeration extends PlatformObject implements IC99Binding, IEnum
return name.toCharArray();
}
-
@Override
public IType getType() {
return this;
}
-
+
@Override
public boolean isSameType(IType type) {
- if( type == this )
- return true;
- if( type instanceof ITypedef)
- return type.isSameType( this );
+ if (type == this)
+ return true;
+ if (type instanceof ITypedef)
+ return type.isSameType(this);
- return false;
+ 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,
+ 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);
+ clone.addEnumerator(e);
}
return clone;
} catch (CloneNotSupportedException e1) {
assert false;
return null;
}
-
+
}
-
+
@Override
- public ILinkage getLinkage() {
+ public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
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
index b699dd94ff0..4d844050605 100644
--- 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
@@ -29,8 +29,7 @@ public class C99Enumerator extends PlatformObject implements IC99Binding, IEnume
private String name;
private IType type;
private IScope scope;
-
-
+
public C99Enumerator() {
}
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
index 0cbe112dccd..b26f6a3bc6d 100644
--- 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
@@ -21,10 +21,9 @@ public class C99Field extends C99Variable implements IC99Binding, IField, ITypea
private ICompositeType compositeTypeOwner;
-
public C99Field() {
}
-
+
public C99Field(String name) {
super(name);
}
@@ -43,5 +42,4 @@ public class C99Field extends C99Variable implements IC99Binding, IField, ITypea
return compositeTypeOwner.getCompositeScope();
}
-
} \ 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
index 250069b4bdf..28a449d23c1 100644
--- 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
@@ -31,7 +31,7 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio
private String name;
private IFunctionType type;
private List<IParameter> parameters = new ArrayList<IParameter>();
-
+
private boolean isAuto;
private boolean isExtern;
private boolean isInline;
@@ -39,20 +39,20 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio
private boolean isStatic;
private boolean isVarArgs;
private boolean isNoReturn;
-
+
// 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;
@@ -62,7 +62,7 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio
public IParameter[] getParameters() {
return parameters.toArray(new IParameter[parameters.size()]);
}
-
+
public void addParameter(IParameter parameter) {
parameters.add(parameter);
}
@@ -71,7 +71,7 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio
public IFunctionType getType() {
return type;
}
-
+
public void setType(IFunctionType type) {
this.type = type;
}
@@ -147,7 +147,7 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio
public void setName(String name) {
this.name = name;
}
-
+
@Override
public String getName() {
return name;
@@ -162,12 +162,12 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio
public IScope getScope() {
return scope;
}
-
+
@Override
public IScope getFunctionScope() {
return bodyScope;
}
-
+
public void setFunctionScope(IScope bodyScope) {
this.bodyScope = bodyScope;
}
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
index d4b9715e97e..f7f4131ef8f 100644
--- 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
@@ -30,8 +30,7 @@ public class C99FunctionScope extends C99Scope implements ICFunctionScope {
* Does not include the parameters which are part of this function scope.
*/
private IScope bodyScope;
-
-
+
@Override
public IBinding getBinding(@SuppressWarnings("unused") char[] name) throws DOMException {
// TODO Auto-generated method stub
@@ -39,9 +38,9 @@ public class C99FunctionScope extends C99Scope implements ICFunctionScope {
}
public void setBodyScope(IScope bodyScope) {
- this.bodyScope = bodyScope;
+ this.bodyScope = bodyScope;
}
-
+
@Override
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
index 7559a30a1b6..2580f7ee632 100644
--- 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
@@ -23,12 +23,12 @@ public class C99FunctionType implements IFunctionType {
private IType returnType;
private List<IType> parameterTypes = new ArrayList<IType>();
-
+
@Override
public IType[] getParameterTypes() {
return parameterTypes.toArray(new IType[parameterTypes.size()]);
}
-
+
public void addParameterType(IType parameterType) {
parameterTypes.add(parameterType);
}
@@ -37,7 +37,7 @@ public class C99FunctionType implements IFunctionType {
public IType getReturnType() {
return returnType;
}
-
+
public void setReturnType(IType returnType) {
this.returnType = returnType;
}
@@ -52,17 +52,17 @@ public class C99FunctionType implements IFunctionType {
public C99FunctionType clone() {
try {
C99FunctionType clone = (C99FunctionType) super.clone();
- clone.setReturnType((IType)returnType.clone());
+ clone.setReturnType((IType) returnType.clone());
clone.parameterTypes = new ArrayList<IType>();
- for(IType parameterType : parameterTypes) {
- clone.addParameterType((IType)parameterType.clone());
+ for (IType parameterType : parameterTypes) {
+ clone.addParameterType((IType) parameterType.clone());
}
return clone;
} catch (CloneNotSupportedException e) {
assert false;
return null;
}
-
+
}
@Override
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
index 25b866b576c..4c86975ce2d 100644
--- 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
@@ -28,14 +28,14 @@ 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;
}
@@ -50,13 +50,11 @@ public class C99Label extends PlatformObject implements IC99Binding, ILabel {
return name.toCharArray();
}
-
-
@Override
public IASTLabelStatement getLabelStatement() {
return null;
}
-
+
@Override
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
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
index c02134267ec..af7daf1bbd0 100644
--- 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
@@ -19,11 +19,11 @@ 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());
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
index ed69a079a1d..c9f3c604c3d 100644
--- 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
@@ -18,24 +18,21 @@ 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;
}
-
+
@Override
public IType getType() {
return type;
@@ -72,27 +69,23 @@ public class C99PointerType implements ITypeContainer, ICPointerType {
public void setVolatile(boolean isVolatile) {
this.isVolatile = isVolatile;
}
-
-
+
@Override
public boolean isSameType(IType t) {
- if(t == this)
+ if (t == this)
return true;
-
+
if (t instanceof ICPointerType) {
ICPointerType pointerType = (ICPointerType) t;
- if(pointerType.isConst() == isConst &&
- pointerType.isRestrict() == isRestrict &&
- pointerType.isVolatile() == isVolatile) {
+ if (pointerType.isConst() == isConst && pointerType.isRestrict() == isRestrict
+ && pointerType.isVolatile() == isVolatile) {
return type.isSameType(pointerType.getType());
}
}
return false;
}
-
-
-
+
@Override
public C99PointerType clone() {
try {
@@ -103,6 +96,6 @@ public class C99PointerType implements ITypeContainer, ICPointerType {
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
index f4ff7b4ab62..345438fc650 100644
--- 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
@@ -19,17 +19,16 @@ 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);
}
-
+
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
index b179144a990..3ff031e9b5b 100644
--- 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
@@ -24,9 +24,8 @@ public class C99QualifierType implements ICQualifierType, ITypeContainer {
private boolean isRestrict;
private boolean isConst;
private boolean isVolatile;
-
+
private IType type;
-
public C99QualifierType() {
}
@@ -81,23 +80,21 @@ public class C99QualifierType implements ICQualifierType, ITypeContainer {
@Override
public boolean isSameType(IType t) {
- if(t == this)
+ if (t == this)
return true;
-
+
if (t instanceof ICQualifierType) {
ICQualifierType pointerType = (ICQualifierType) t;
- if(pointerType.isConst() == isConst &&
- pointerType.isRestrict() == isRestrict &&
- pointerType.isVolatile() == isVolatile) {
+ if (pointerType.isConst() == isConst && pointerType.isRestrict() == isRestrict
+ && pointerType.isVolatile() == isVolatile) {
return type.isSameType(pointerType.getType());
}
}
return false;
}
-
-
+
@Override
public C99QualifierType clone() {
try {
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
index 559f66e565a..72beb896af3 100644
--- 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
@@ -27,17 +27,17 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
* @author Mike Kucera
*
*/
-@SuppressWarnings({"restriction","unused"})
+@SuppressWarnings({ "restriction", "unused" })
public class C99Scope implements IC99Scope, IASTInternalScope {
private IScope parent;
private IASTNode physicalNode;
private IName scopeName;
private final EScopeKind kind;
-
+
public C99Scope(EScopeKind eKind) {
- kind= eKind;
+ kind = eKind;
}
-
+
@Override
public IScope getParent() {
return parent;
@@ -47,7 +47,7 @@ public class C99Scope implements IC99Scope, IASTInternalScope {
public void setParent(IScope parent) {
this.parent = parent;
}
-
+
@Override
public IASTNode getPhysicalNode() {
return physicalNode;
@@ -57,7 +57,7 @@ public class C99Scope implements IC99Scope, IASTInternalScope {
public void setPhysicalNode(IASTNode physicalNode) {
this.physicalNode = physicalNode;
}
-
+
@Override
public final EScopeKind getKind() {
return kind;
@@ -72,13 +72,14 @@ public class C99Scope implements IC99Scope, IASTInternalScope {
public void setScopeName(IName scopeName) {
this.scopeName = scopeName;
}
-
+
@Override
public IBinding[] find(String name, IASTTranslationUnit tu) {
throw new UnsupportedOperationException();
}
- @Override @Deprecated
+ @Override
+ @Deprecated
public IBinding[] find(String name) {
throw new UnsupportedOperationException();
}
@@ -92,7 +93,7 @@ public class C99Scope implements IC99Scope, IASTInternalScope {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) {
throw new UnsupportedOperationException();
}
-
+
@Override
public void addBinding(IBinding binding) {
throw new UnsupportedOperationException();
@@ -121,8 +122,8 @@ public class C99Scope implements IC99Scope, IASTInternalScope {
*/
@Override
@Deprecated
- public IBinding[] getBindings(IASTName name, boolean resolve,
- boolean prefixLookup, IIndexFileSet acceptLocalBindings) {
+ public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
+ IIndexFileSet acceptLocalBindings) {
return getBindings(new ScopeLookupData(name, resolve, prefixLookup));
}
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
index 52df2db7c0e..1d8bf52e450 100644
--- 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
@@ -31,37 +31,36 @@ 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 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;
}
-
+
@Override
public IField findField(String name) {
return fields.get(name);
@@ -69,29 +68,28 @@ public class C99Structure extends PlatformObject implements IC99Binding, ICompos
@Override
public IScope getCompositeScope() {
-// C99Scope scope = new C99CompositeTypeScope(this);
-// scope.setScopeName(nameNode);
-// return scope;
+ // C99Scope scope = new C99CompositeTypeScope(this);
+ // scope.setScopeName(nameNode);
+ // return scope;
return null;
}
@Override
public IField[] getFields() {
- if(fieldArray == null)
+ if (fieldArray == null)
fieldArray = fields.values().toArray(new IField[fields.size()]);
return fieldArray;
}
-
+
public void setKey(int key) {
this.key = key;
}
-
+
@Override
public int getKey() {
return key;
}
-
public void setName(String name) {
this.name = name;
}
@@ -103,46 +101,44 @@ public class C99Structure extends PlatformObject implements IC99Binding, ICompos
@Override
public char[] getNameCharArray() {
- if(name == null)
+ if (name == null)
return new char[0];
-
+
return name.toCharArray();
}
-
@Override
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
-
+
@Override
public IType getType() {
return this;
}
-
+
@Override
public boolean isSameType(IType type) {
- if(type == this)
+ if (type == this)
return true;
- if( type instanceof ITypedef)
- return type.isSameType( this );
- return false;
+ 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.fields = new LinkedHashMap<String, IField>();
+ for (IField field : fields.values())
clone.addField(field); // TODO not a deep clone
return clone;
} catch (CloneNotSupportedException e) {
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
index f14bf34ca10..fa8bcef41e9 100644
--- 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
@@ -29,22 +29,21 @@ import org.eclipse.core.runtime.PlatformObject;
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;
}
-
+
@Override
public IType getType() {
return type;
@@ -52,14 +51,14 @@ public class C99Typedef extends PlatformObject implements IC99Binding, ITypedef,
@Override
public void setType(IType type) {
- this.type = type;
+ this.type = type;
}
@Override
public String getName() {
return name;
}
-
+
public void setName(String name) {
this.name = name;
}
@@ -71,11 +70,11 @@ public class C99Typedef extends PlatformObject implements IC99Binding, ITypedef,
@Override
public boolean isSameType(IType t) {
- if(t == this)
+ if (t == this)
return true;
-
- if(t instanceof ITypedef)
- return type.isSameType(((ITypedef)t).getType());
+
+ if (t instanceof ITypedef)
+ return type.isSameType(((ITypedef) t).getType());
return type.isSameType(t);
}
@@ -90,7 +89,7 @@ public class C99Typedef extends PlatformObject implements IC99Binding, ITypedef,
return null;
}
}
-
+
@Override
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
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
index 18d327e3a39..4c1faa00045 100644
--- 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
@@ -30,68 +30,68 @@ public class C99Variable extends PlatformObject implements IC99Binding, IVariabl
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;
}
-
+
@Override
public IType getType() {
return type;
}
-
+
public void setAuto(boolean auto) {
this.isAuto = auto;
}
-
+
@Override
public boolean isAuto() {
return isAuto;
}
-
+
public void setExtern(boolean extern) {
this.isExtern = extern;
}
-
+
@Override
public boolean isExtern() {
return isExtern;
}
-
+
public void setRegister(boolean isRegister) {
this.isRegister = isRegister;
}
-
+
@Override
public boolean isRegister() {
return isRegister;
}
-
+
public void setStatic(boolean isStatic) {
this.isStatic = isStatic;
}
-
+
@Override
- public boolean isStatic() {
+ public boolean isStatic() {
return isStatic;
}
public void setName(String name) {
this.name = name;
}
-
+
@Override
public String getName() {
return name;
@@ -101,7 +101,7 @@ public class C99Variable extends PlatformObject implements IC99Binding, IVariabl
public char[] getNameCharArray() {
return name.toCharArray();
}
-
+
@Override
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
@@ -121,7 +121,7 @@ public class C99Variable extends PlatformObject implements IC99Binding, IVariabl
public IBinding getOwner() {
if (scope == null)
return null;
-
+
return CVisitor.findDeclarationOwner((IASTNode) scope.getScopeName(), true);
}
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
index 8433cd69c08..899e88d03b8 100644
--- 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
@@ -18,17 +18,16 @@ 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/symboltable/C99SymbolTable.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/symboltable/C99SymbolTable.java
index 69416477350..66f5cbeb364 100644
--- 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
@@ -13,20 +13,19 @@
*******************************************************************************/
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 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.
@@ -34,11 +33,11 @@ public class C99SymbolTable {
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)
+ if (namespace == null || ident == null)
throw new NullPointerException();
-
+
this.ident = ident;
this.namespace = namespace;
}
@@ -50,34 +49,33 @@ public class C99SymbolTable {
// only if the namespace is the same do we check the identifier
return (c == 0) ? ident.compareTo(x.ident) : c;
}
-
- @Override public String toString() {
+
+ @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;
-
-
+ private final FunctionalMap<Key, IC99Binding> map;
+
/**
- * Constructors are private, start with EMPTY_TABLE
+ * Constructors are private, start with EMPTY_TABLE
* and build it up using insert().
*/
private C99SymbolTable() {
map = FunctionalMap.emptyMap();
}
-
- private C99SymbolTable(FunctionalMap<Key,IC99Binding> newRoot) {
+
+ 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.
@@ -94,21 +92,22 @@ public class C99SymbolTable {
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() {
+
+ @Override
+ public String toString() {
return map.toString();
}
-
-// void printStructure() {
-// map.printStructure();
-// }
-
+
+ // 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
index 7869f535a87..41dd3df62f4 100644
--- 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
@@ -19,43 +19,39 @@ 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
+ * 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.
*/
@@ -64,7 +60,7 @@ public class CImperativeSymbolTable {
CNamespace namespace;
IBinding binding;
Bucket next;
-
+
Bucket(Bucket next, CNamespace namespace, String key, IBinding binding) {
this.key = key;
this.namespace = namespace;
@@ -72,85 +68,78 @@ public class CImperativeSymbolTable {
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) {
+ 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))
+ 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
+ *
+ * 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() {
+ public void closeScope() {
SymbolScope poppedScope = scopeStack.removeLast(); // pop the scopeStack
-
+
// pop each bucket that was modified in the scope
- for(int index : poppedScope.modifiedBuckets)
+ 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) {
+ for (Bucket b : table) {
+ while (b != null) {
buff.append('<').append(b.key).append(": ").append(b.binding).append(">, ");
b = b.next;
}
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
index 84ec3882fc6..7e4a360f34b 100644
--- 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
@@ -15,18 +15,18 @@ 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
+ * 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
+ 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
index ef3fc7c0c71..098868ec851 100644
--- 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
@@ -13,286 +13,267 @@
*******************************************************************************/
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 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;
+ 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) {
+
+ 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
+ @Override
public String toString() {
- return "Node(" + key + "," + val + "," + (color ? "R" : "B") + ")";
+ return "Node(" + key + "," + val + "," + (color ? "R" : "B") + ")";
}
}
-
-
- private Node<K,V> root = null;
-
-
+
+ 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>();
+ 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)
+ public FunctionalMap<K, V> insert(K key, V val) {
+ if (key == null)
throw new NullPointerException();
-
- FunctionalMap<K,V> newMap = new FunctionalMap<K,V>();
+
+ 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
-
+
+ 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)
+ if (c < 0)
return balance(n.key, n.val, n.color, insert(n.left, key, val), n.right);
- else if(c > 0)
+ 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);
+ 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;
-
+
+ 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 != 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 (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 != 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);
+ 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);
+
+ 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)
+ if (key == null)
throw new NullPointerException();
-
+
// no need for recursion here
- Node<K,V> n = root;
- while(n != null) {
+ Node<K, V> n = root;
+ while (n != null) {
int x = key.compareTo(n.key); // throws NPE if key is null
- if(x == 0)
+ 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)
+ if (key == null)
throw new NullPointerException();
-
+
// lookup uses an iterative algorithm
- Node<K,V> n = root;
- while(n != null) {
+ Node<K, V> n = root;
+ while (n != null) {
int x = key.compareTo(n.key); // throws NPE if key is null
- if(x == 0)
+ if (x == 0)
return true;
n = (x < 0) ? n.left : n.right;
}
return false;
}
-
public boolean isEmpty() {
return root == null;
}
-
- @Override public String toString() {
+
+ @Override
+ public String toString() {
StringBuilder sb = new StringBuilder('[');
inorderPrint(root, sb);
sb.append(']');
- return sb.toString();
+ return sb.toString();
}
-
- private static <K,V> void inorderPrint(Node<K,V> n, StringBuilder sb) {
- if(n == null)
+
+ private static <K, V> void inorderPrint(Node<K, V> n, StringBuilder sb) {
+ if (n == null)
return;
-
+
inorderPrint(n.left, sb);
- if(sb.length() > 1)
+ if (sb.length() > 1)
sb.append(", ");//$NON-NLS-1$
sb.append(n.toString());
inorderPrint(n.right, sb);
}
-
-
+
void printStructure() {
- if(root == null)
+ 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++)
+
+ 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) {
+ if (node == null) {
System.out.println("null");//$NON-NLS-1$
- }
- else if(node.right == null && node.left == null) {
+ } else if (node.right == null && node.left == null) {
System.out.println(node);
- }
- else {
+ } 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)
+
+ 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)
+
+ 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) {
+
+ 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)
+ 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;
+ 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 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
index da214853df5..62dbb1beb87 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -23,135 +23,124 @@ 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();
+ FunctionalMap<String, Integer> st0 = FunctionalMap.emptyMap();
assertTrue(st0.isEmpty());
-
- FunctionalMap<String,Integer> st1 = st0.insert(KEYS[0], 1);
-
+
+ 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(Integer.valueOf(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} );
- }
-
-
+
+ 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) {
+ 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++) {
+ 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);
-
+
+ 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(Integer.valueOf(5), map1.lookup(KEYS[5]));
assertEquals(Integer.valueOf(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) {
+
+ 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) {
+
+ for (String key : KEYS) {
st = st.insert(CNamespace.IDENTIFIER, key, new C99Variable(key));
}
- for(String key : KEYS) {
+ for (String key : KEYS) {
st = st.insert(CNamespace.GOTO_LABEL, key, new C99Label(key));
}
- for(String key : KEYS) {
+ 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) {
+ 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));
@@ -159,74 +148,73 @@ public class SymbolTableTests {//extends TestCase {
assertFunctionalSymbolTableContainsAllThePairs(st);
}
-
+
private void assertFunctionalSymbolTableContainsAllThePairs(C99SymbolTable st) {
assertEquals(KEYS.length * 3, st.size());
- for(String key : KEYS) {
+ for (String key : KEYS) {
IBinding b = st.lookup(CNamespace.IDENTIFIER, key);
assertNotNull(b);
- C99Variable x = (C99Variable)b;
+ C99Variable x = (C99Variable) b;
assertEquals(key, x.getName());
}
- for(String key : KEYS) {
+ for (String key : KEYS) {
IBinding b = st.lookup(CNamespace.GOTO_LABEL, key);
assertNotNull(b);
- C99Label x = (C99Label)b;
+ C99Label x = (C99Label) b;
assertEquals(key, x.getName());
}
- for(String key : KEYS) {
+ for (String key : KEYS) {
IBinding b = st.lookup(CNamespace.STRUCT_TAG, key);
assertNotNull(b);
- C99Structure x = (C99Structure)b;
+ C99Structure x = (C99Structure) b;
assertEquals(key, x.getName());
}
}
-
- @SuppressWarnings("unused")
+
+ @SuppressWarnings("unused")
private void assertEquals(String key, String name) {
// TODO Auto-generated method stub
-
- }
+ }
- @SuppressWarnings("unused")
+ @SuppressWarnings("unused")
private void assertNotNull(IBinding b) {
// TODO Auto-generated method stub
-
- }
-
+ }
public void testProperFail() {
- FunctionalMap<Integer,Integer> map = FunctionalMap.emptyMap();
+ FunctionalMap<Integer, Integer> map = FunctionalMap.emptyMap();
try {
map.insert(null, 99);
fail();
- } catch (NullPointerException e) {}
-
+ } catch (NullPointerException e) {
+ }
+
try {
map.containsKey(null);
fail();
- } catch (NullPointerException e) {}
-
+ } catch (NullPointerException e) {
+ }
+
try {
map.lookup(null);
fail();
- } catch (NullPointerException e) {}
-
+ } catch (NullPointerException e) {
+ }
+
C99SymbolTable table = C99SymbolTable.EMPTY_TABLE;
try {
table.insert(null, null, new C99Variable("blah")); //$NON-NLS-1$
fail();
- } catch (NullPointerException e) {}
-
- }
-
+ } catch (NullPointerException e) {
+ }
+ }
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
index 3f7114bb707..6dcec3b674d 100644
--- 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
@@ -13,63 +13,57 @@
*******************************************************************************/
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;
-
-
+ private final FunctionalMap<String, Object> map;
+
/**
- * Constructors are private, start with EMPTY_TABLE
+ * Constructors are private, start with EMPTY_TABLE
* and build it up using insert().
*/
private TypedefSymbolTable() {
map = FunctionalMap.emptyMap();
}
-
- private TypedefSymbolTable(FunctionalMap<String,Object> newRoot) {
+
+ 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() {
+
+ @Override
+ public String toString() {
return map.toString();
}
-
-
+
}
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 d9d83ec1165..208b8403510 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -53,95 +53,96 @@ import org.eclipse.core.runtime.CoreException;
import lpg.lpgjavaruntime.IToken;
import lpg.lpgjavaruntime.PrsStream;
-
/**
- * Implementation of the ILanguage extension point,
+ * Implementation of the ILanguage extension point,
* provides the ability to add LPG based languages to CDT.
*/
@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 static final boolean DEBUG_PRINT_AST = false;
// default 0.5 min
private long parser_timeout_limit_lowerBoundary = 1 * 30 * 1000;
// default 2 mins
private long parser_timeout_limit_uppperBoundary = 1 * 60 * 1000;
//time limit for each token, 1ms
public static long UNIT_PARSER_TIMEOUT_LIMIT = 10;
-
+
private static long LONGEST_CORE_RUNTIME;
private static long LONGEST_LPR_RUNTIME;
-
-
+
public static boolean CATCH_TEMPLATEID_ERROR = 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<IASTTranslationUnit> getParser(IScanner scanner, IIndex index, Map<String,String> properties);
-
- protected IParser<IASTTranslationUnit> getCompleteParser(IScanner scanner, IIndex index, Map<String,String> properties){
+ protected abstract IParser<IASTTranslationUnit> getParser(IScanner scanner, IIndex index,
+ Map<String, String> properties);
+
+ protected IParser<IASTTranslationUnit> getCompleteParser(IScanner scanner, IIndex index,
+ Map<String, String> properties) {
return getParser(scanner, index, properties);
}
- protected ISecondaryParser<IASTTranslationUnit> getCompleteParser(ITokenStream stream, IScanner scanner, IIndex index, Map<String,String> properties){
- return (ISecondaryParser)getParser(scanner, index, properties);
+
+ protected ISecondaryParser<IASTTranslationUnit> getCompleteParser(ITokenStream stream, IScanner scanner,
+ IIndex index, Map<String, String> properties) {
+ return (ISecondaryParser) getParser(scanner, index, properties);
}
-
+
/**
* Returns the ParserLanguage value that is to be used when creating
* an instance of CPreprocessor.
- *
+ *
*/
protected abstract ParserLanguage getParserLanguage();
-
-
+
/**
* Returns the scanner extension configuration for this language, may not return null
*/
protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration();
-
- private class ParseThread<AST_TYPE> extends Thread{
- ParseThread(){
+
+ private class ParseThread<AST_TYPE> extends Thread {
+ ParseThread() {
super();
super.setName("ParserThread");
}
+
AST_TYPE astUnit = null;
- AST_TYPE getASTUnit(){
+
+ AST_TYPE getASTUnit() {
return astUnit;
}
}
-
- private <AST_TYPE> AST_TYPE runThreadByLimitedTime(long limitTime, ParseThread<AST_TYPE> parseThread) throws InterruptedException{
+
+ private <AST_TYPE> AST_TYPE runThreadByLimitedTime(long limitTime, ParseThread<AST_TYPE> parseThread)
+ throws InterruptedException {
parseThread.start();
-
+
parseThread.join(limitTime);
-
+
return parseThread.getASTUnit();
}
-
-
- @Override @Deprecated
+
+ @Override
+ @Deprecated
public IASTTranslationUnit getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader reader,
IScannerInfo scanInfo, ICodeReaderFactory codeReaderFactory, IIndex index, int options,
IParserLogService log) throws CoreException {
- return getASTTranslationUnit(FileContent.adapt(reader), scanInfo, IncludeFileContentProvider
- .adapt(codeReaderFactory), index, options, log);
+ return getASTTranslationUnit(FileContent.adapt(reader), scanInfo,
+ IncludeFileContentProvider.adapt(codeReaderFactory), index, options, log);
}
-
- public void setParser_timeout_limit_lowerBoundary(
- long parser_timeout_limit_lowerBoundary) {
+
+ public void setParser_timeout_limit_lowerBoundary(long parser_timeout_limit_lowerBoundary) {
this.parser_timeout_limit_lowerBoundary = parser_timeout_limit_lowerBoundary;
}
- public void setParser_timeout_limit_uppperBoundary(
- long parser_timeout_limit_uppperBoundary) {
+ public void setParser_timeout_limit_uppperBoundary(long parser_timeout_limit_uppperBoundary) {
this.parser_timeout_limit_uppperBoundary = parser_timeout_limit_uppperBoundary;
}
@@ -150,68 +151,72 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
final IncludeFileContentProvider fileCreator, final IIndex index, int options, final IParserLogService log)
throws CoreException {
CATCH_TEMPLATEID_ERROR = false;
- long startTime=0;
- java.util.Date today=null;
- if(log.isTracing()){
+ long startTime = 0;
+ java.util.Date today = null;
+ if (log.isTracing()) {
today = new java.util.Date();
startTime = today.getTime();
- log.traceLog("^^^^^^ Start parsing " + reader.getFileLocation() + " at " + new java.sql.Timestamp(startTime));
+ log.traceLog(
+ "^^^^^^ Start parsing " + reader.getFileLocation() + " at " + new java.sql.Timestamp(startTime));
}
IASTTranslationUnit gtu = null;
- if(DEBUG_PRINT_GCC_AST) {
- System.out.println("\n********************************************************\nParsing\nOptions: " + options);
-
- ILanguage gppLanguage = getParserLanguage() == ParserLanguage.CPP ? GPPLanguage.getDefault() : GCCLanguage.getDefault();
+ if (DEBUG_PRINT_GCC_AST) {
+ System.out.println(
+ "\n********************************************************\nParsing\nOptions: " + options);
+
+ 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();
}
final IScannerExtensionConfiguration config = getScannerExtensionConfiguration();
-
+
final ParserLanguage pl = getParserLanguage();
final IScanner preprocessor = new CPreprocessor(reader, scanInfo, pl, log, config, fileCreator);
preprocessor.setComputeImageLocations((options & ILanguage.OPTION_NO_IMAGE_LOCATIONS) == 0);
-
- final Map<String,String> parserProperties = new HashMap<String,String>();
+
+ final Map<String, String> parserProperties = new HashMap<String, String>();
parserProperties.put(LRParserProperties.TRANSLATION_UNIT_PATH, reader.getFileLocation());
- if((options & OPTION_SKIP_FUNCTION_BODIES) != 0)
+ if ((options & OPTION_SKIP_FUNCTION_BODIES) != 0)
parserProperties.put(LRParserProperties.SKIP_FUNCTION_BODIES, "true");
- if((options & OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS) != 0)
+ if ((options & OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS) != 0)
parserProperties.put(LRParserProperties.SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS, "true");
-
+
final IParser<IASTTranslationUnit> parser = getParser(preprocessor, index, parserProperties);
long parser_timeout_limit = parser_timeout_limit_uppperBoundary;
- if(parser instanceof PrsStream){
- int token_size = ((PrsStream)parser).getSize();
+ if (parser instanceof PrsStream) {
+ int token_size = ((PrsStream) parser).getSize();
parser_timeout_limit = token_size * UNIT_PARSER_TIMEOUT_LIMIT;
- if(parser_timeout_limit < parser_timeout_limit_lowerBoundary)
+ if (parser_timeout_limit < parser_timeout_limit_lowerBoundary)
parser_timeout_limit = parser_timeout_limit_lowerBoundary;
- if(parser_timeout_limit > parser_timeout_limit_uppperBoundary)
+ if (parser_timeout_limit > parser_timeout_limit_uppperBoundary)
parser_timeout_limit = parser_timeout_limit_uppperBoundary;
- log.traceLog("^^^^^^ adjusted time out limit with token size: " + token_size + " and the time out limit: " + parser_timeout_limit);
+ log.traceLog("^^^^^^ adjusted time out limit with token size: " + token_size + " and the time out limit: "
+ + parser_timeout_limit);
}
IASTTranslationUnit tu = null;
//real token size, substract a dummy token and a eof token
- final int orgTokenSize = ((PrsStream)parser).getTokens().size();
+ final int orgTokenSize = ((PrsStream) parser).getTokens().size();
//final List orginalTokens = copyList(((PrsStream)parser).getTokens());
ParseThread<IASTTranslationUnit> parseThread = new ParseThread<IASTTranslationUnit>() {
-
+
@Override
public void run() {
- try{
- astUnit = parser.parse();
- }
-
+ try {
+ astUnit = parser.parse();
+ }
+
catch (Exception e) {
-
+
/*
if(e instanceof TemplateIDErrorException){
//IScanner completePreprocessor = new CPreprocessor(reader, scanInfo, pl, log, config, fileCreator);
//IParser<IASTTranslationUnit> completeParser = getCompleteParser(preprocessor, index, parserProperties);
-
+
ISecondaryParser<IASTTranslationUnit> completeParser = getCompleteParser((ITokenStream)parser, preprocessor, index, parserProperties);
//completeParser.setAction(parser.getAction());
//((ISecondaryParser)completeParser).setTokenMap((ITokenStream)parser);
@@ -220,106 +225,111 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
astUnit = completeParser.parse();
}else{
*/
- if(log.isTracing()){
+ if (log.isTracing()) {
StringWriter stringW = new StringWriter();
- PrintWriter printW = new PrintWriter(stringW);
- e.printStackTrace(printW);
-
- log.traceLog("^^^^^^ PARSER_ERR_STACK" + stringW.toString());
+ PrintWriter printW = new PrintWriter(stringW);
+ e.printStackTrace(printW);
+
+ log.traceLog("^^^^^^ PARSER_ERR_STACK" + stringW.toString());
}
//}
-
+
}
-
+
}
-
+
};
-
+
try {
tu = runThreadByLimitedTime(parser_timeout_limit, parseThread);
} catch (InterruptedException e) {
-
+
StringWriter stringW = new StringWriter();
- PrintWriter printW = new PrintWriter(stringW);
- e.printStackTrace(printW);
+ PrintWriter printW = new PrintWriter(stringW);
+ e.printStackTrace(printW);
-
log.traceLog("^^^^^^_ERR_STACK" + stringW.toString());
//e.printStackTrace();
}
parseThread.stop();
- long lprFinishTime=0;
- long coreFinishTime=0;
- if(log.isTracing()){
+ long lprFinishTime = 0;
+ long coreFinishTime = 0;
+ if (log.isTracing()) {
today = new java.util.Date();
lprFinishTime = today.getTime();
}
-
- if(tu==null){
- long lpr_fail_time=0;
- if(log.isTracing()){
+
+ if (tu == null) {
+ long lpr_fail_time = 0;
+ if (log.isTracing()) {
lpr_fail_time = lprFinishTime;
- log.traceLog("^^^^^^ LR parser fails in parsing " + reader.getFileLocation() + " after running " + (lpr_fail_time-startTime)/1000 + " seconds");
+ log.traceLog("^^^^^^ LR parser fails in parsing " + reader.getFileLocation() + " after running "
+ + (lpr_fail_time - startTime) / 1000 + " seconds");
}
-
- ILanguage gppLanguage = getParserLanguage() == ParserLanguage.CPP ? GPPLanguage.getDefault() : GCCLanguage.getDefault();
+
+ ILanguage gppLanguage = getParserLanguage() == ParserLanguage.CPP ? GPPLanguage.getDefault()
+ : GCCLanguage.getDefault();
tu = gppLanguage.getASTTranslationUnit(reader, scanInfo, fileCreator, index, options, log);
- if(log.isTracing()){
+ if (log.isTracing()) {
today = new java.util.Date();
coreFinishTime = today.getTime();
-
- log.traceLog("^^^^^^ core parser parses " + reader.getFileLocation() + " in " + (coreFinishTime - lpr_fail_time)/1000 + " seconds");
+
+ log.traceLog("^^^^^^ core parser parses " + reader.getFileLocation() + " in "
+ + (coreFinishTime - lpr_fail_time) / 1000 + " seconds");
}
}
-
- if(DEBUG_PRINT_AST) {
+
+ if (DEBUG_PRINT_AST) {
System.out.println("Base Extensible Language AST:");
ASTPrinter.print(tu);
}
- long finishTime ;
- if(log.isTracing()){
- if(coreFinishTime>0){
+ long finishTime;
+ if (log.isTracing()) {
+ if (coreFinishTime > 0) {
//parsed by core parser.
finishTime = coreFinishTime;
long core_runtime = finishTime - startTime;
- log.traceLog("^^^^^^ Finish parsing with cdt core parser " + reader.getFileLocation() + " at " + new java.sql.Timestamp(finishTime) + " runtime: " + core_runtime);
- if(core_runtime > LONGEST_CORE_RUNTIME){
+ log.traceLog("^^^^^^ Finish parsing with cdt core parser " + reader.getFileLocation() + " at "
+ + new java.sql.Timestamp(finishTime) + " runtime: " + core_runtime);
+ if (core_runtime > LONGEST_CORE_RUNTIME) {
LONGEST_CORE_RUNTIME = core_runtime;
- log.traceLog("^^^^^^ CLCLCLCL so far the longest runtime with core parser is: " + core_runtime/1000);
+ log.traceLog(
+ "^^^^^^ CLCLCLCL so far the longest runtime with core parser is: " + core_runtime / 1000);
}
- }else{
+ } else {
finishTime = lprFinishTime;
long lpr_runtime = finishTime - startTime;
- log.traceLog("^^^^^^ Finish parsing " + reader.getFileLocation() + " at " + new java.sql.Timestamp(finishTime) + " runtime: " + lpr_runtime);
- if(lpr_runtime > LONGEST_LPR_RUNTIME){
+ log.traceLog("^^^^^^ Finish parsing " + reader.getFileLocation() + " at "
+ + new java.sql.Timestamp(finishTime) + " runtime: " + lpr_runtime);
+ if (lpr_runtime > LONGEST_LPR_RUNTIME) {
LONGEST_LPR_RUNTIME = lpr_runtime;
- log.traceLog("^^^^^^ LLLLLLLL so far the longest runtime by LPR Parser is: " + lpr_runtime/1000);
+ log.traceLog("^^^^^^ LLLLLLLL so far the longest runtime by LPR Parser is: " + lpr_runtime / 1000);
}
}
}
-
+
return tu;
}
-
+
public void copyTokensToParser(PrsStream parser, List<IToken> tokens) {
parser.resetTokenStream();
-
- for(IToken token : tokens) {
-
+
+ for (IToken token : tokens) {
+
parser.addToken(token);
}
-
+
}
-
- public List copyList(List orgList){
+
+ public List copyList(List orgList) {
List returnList = new ArrayList(orgList.size());
- for(int i=0; i<orgList.size(); i++){
+ for (int i = 0; i < orgList.size(); i++) {
returnList.add(orgList.get(i));
}
return returnList;
-
+
}
-
+
@Override
@Deprecated
public IASTTranslationUnit getASTTranslationUnit(org.eclipse.cdt.core.parser.CodeReader reader,
@@ -328,148 +338,146 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log);
}
-
+
@Override
@Deprecated
- public IASTCompletionNode getCompletionNode(org.eclipse.cdt.core.parser.CodeReader reader,
- IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log,
- int offset) throws CoreException {
- return getCompletionNode(FileContent.adapt(reader), scanInfo, IncludeFileContentProvider
- .adapt(fileCreator), index, log, offset);
+ public IASTCompletionNode getCompletionNode(org.eclipse.cdt.core.parser.CodeReader reader, IScannerInfo scanInfo,
+ ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException {
+ return getCompletionNode(FileContent.adapt(reader), scanInfo, IncludeFileContentProvider.adapt(fileCreator),
+ index, log, offset);
}
-
+
@Override
public IASTCompletionNode getCompletionNode(FileContent reader, IScannerInfo scanInfo,
IncludeFileContentProvider fileCreator, IIndex index, IParserLogService log, int offset)
- throws CoreException {
-
+ throws CoreException {
+
IASTCompletionNode cn;
- if(DEBUG_PRINT_GCC_AST) {
+ if (DEBUG_PRINT_GCC_AST) {
ILanguage gppLanguage = GCCLanguage.getDefault();
cn = gppLanguage.getCompletionNode(reader, scanInfo, fileCreator, index, log, offset);
-
+
System.out.println();
System.out.println("********************************************************");
System.out.println("GPP AST:");
printCompletionNode(cn);
}
-
+
IScannerExtensionConfiguration config = getScannerExtensionConfiguration();
-
+
ParserLanguage pl = getParserLanguage();
IScanner preprocessor = new CPreprocessor(reader, scanInfo, pl, log, config, fileCreator);
preprocessor.setContentAssistMode(offset);
-
-
- Map<String,String> parserProperties = new HashMap<String,String>();
+
+ Map<String, String> parserProperties = new HashMap<String, String>();
parserProperties.put(LRParserProperties.TRANSLATION_UNIT_PATH, reader.getFileLocation());
parserProperties.put(LRParserProperties.SKIP_FUNCTION_BODIES, "true");
parserProperties.put(LRParserProperties.SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS, "true");
-
+
final IParser<IASTTranslationUnit> parser = getParser(preprocessor, index, parserProperties);
-
+
long parser_timeout_limit = parser_timeout_limit_uppperBoundary;
- if(parser instanceof PrsStream){
- int token_size = ((PrsStream)parser).getSize();
+ if (parser instanceof PrsStream) {
+ int token_size = ((PrsStream) parser).getSize();
parser_timeout_limit = token_size * UNIT_PARSER_TIMEOUT_LIMIT;
- if(parser_timeout_limit < parser_timeout_limit_lowerBoundary)
+ if (parser_timeout_limit < parser_timeout_limit_lowerBoundary)
parser_timeout_limit = parser_timeout_limit_lowerBoundary;
- if(parser_timeout_limit > parser_timeout_limit_uppperBoundary)
+ if (parser_timeout_limit > parser_timeout_limit_uppperBoundary)
parser_timeout_limit = parser_timeout_limit_uppperBoundary;
- if(log.isTracing()){
- log.traceLog("^^^^^^ adjusted time out limit with token size: " + token_size + " and the time out limit: " + parser_timeout_limit);
+ if (log.isTracing()) {
+ log.traceLog("^^^^^^ adjusted time out limit with token size: " + token_size
+ + " and the time out limit: " + parser_timeout_limit);
}
}
ParseThread<IASTCompletionNode> parseThread = new ParseThread<IASTCompletionNode>() {
-
+
@Override
public void run() {
parser.parse();
astUnit = parser.getCompletionNode();
}
-
+
};
-
- IASTCompletionNode completionNode=null;
+
+ IASTCompletionNode completionNode = null;
try {
- completionNode = runThreadByLimitedTime(parser_timeout_limit*100, parseThread);
+ completionNode = runThreadByLimitedTime(parser_timeout_limit * 100, parseThread);
} catch (InterruptedException e) {
- if(log.isTracing()){
+ if (log.isTracing()) {
StringWriter stringW = new StringWriter();
- PrintWriter printW = new PrintWriter(stringW);
- e.printStackTrace(printW);
-
-
+ PrintWriter printW = new PrintWriter(stringW);
+ e.printStackTrace(printW);
+
log.traceLog("^^^^^^_ERR_STACK" + stringW.toString());
}
//e.printStackTrace();
}
parseThread.stop();
- if(completionNode==null){
+ if (completionNode == null) {
log.traceLog("LR parser fails in parsing " + reader.getFileLocation());
- if(log.isTracing()){
+ if (log.isTracing()) {
log.traceLog("LR parser fails in parsing " + reader.getFileLocation());
}
- ILanguage gppLanguage = getParserLanguage() == ParserLanguage.CPP ? GPPLanguage.getDefault() : GCCLanguage.getDefault();
- completionNode=gppLanguage.getCompletionNode(reader, scanInfo, fileCreator, index, log, offset);
+ ILanguage gppLanguage = getParserLanguage() == ParserLanguage.CPP ? GPPLanguage.getDefault()
+ : GCCLanguage.getDefault();
+ completionNode = gppLanguage.getCompletionNode(reader, scanInfo, fileCreator, index, log, offset);
}
-
- if(DEBUG_PRINT_AST) {
+
+ if (DEBUG_PRINT_AST) {
System.out.println("Base Extensible Language AST:");
printCompletionNode(completionNode);
}
-
+
return completionNode;
}
-
-
+
/*
* For debugging.
*/
private static void printCompletionNode(IASTCompletionNode cn) {
- if(cn == null) {
+ if (cn == null) {
System.out.println("Completion node is null");
return;
}
-
+
ASTPrinter.print(cn.getTranslationUnit());
- for(IASTName name : cn.getNames()) {
- ASTNode context = (ASTNode)name.getCompletionContext();
- System.out.printf("Name: %s, Context: %s, At: %d",
- name, DebugUtil.safeClassName(context), context == null ? null : context.getOffset());
- if(name.getTranslationUnit() == null) // some name nodes are not hooked up to the AST
+ for (IASTName name : cn.getNames()) {
+ ASTNode context = (ASTNode) name.getCompletionContext();
+ System.out.printf("Name: %s, Context: %s, At: %d", name, DebugUtil.safeClassName(context),
+ context == null ? null : context.getOffset());
+ if (name.getTranslationUnit() == null) // some name nodes are not hooked up to the AST
System.out.print(", not hooked up");
System.out.println();
}
System.out.println();
}
-
+
@Override
@Deprecated
public IASTName[] getSelectedNames(IASTTranslationUnit ast, int start, int length) {
return GCCLanguage.getDefault().getSelectedNames(ast, start, length);
}
-
- private ICLanguageKeywords cLanguageKeywords = new CLanguageKeywords(getParserLanguage(), getScannerExtensionConfiguration());
-
-
+
+ private ICLanguageKeywords cLanguageKeywords = new CLanguageKeywords(getParserLanguage(),
+ getScannerExtensionConfiguration());
+
@SuppressWarnings("unchecked")
@Override
public Object getAdapter(Class adapter) {
- if(ICLanguageKeywords.class.equals(adapter))
+ if (ICLanguageKeywords.class.equals(adapter))
return cLanguageKeywords;
- if(IPDOMLinkageFactory.class.equals(adapter)) {
- if(getParserLanguage().isCPP())
+ if (IPDOMLinkageFactory.class.equals(adapter)) {
+ if (getParserLanguage().isCPP())
return new PDOMCPPLinkageFactory();
return new PDOMCLinkageFactory();
}
-
+
return super.getAdapter(adapter);
}
-
+
@Override
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/CPreprocessorAdapter.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CPreprocessorAdapter.java
index b9e499c935c..bc126d97190 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -22,7 +22,7 @@ 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
@@ -31,83 +31,80 @@ public class CPreprocessorAdapter {
/**
* During content assist the preprocessor may return a completion token
* which represents the identifier on which the user invoked content assist.
- * Then the preprocessor normally returns arbitrarily many end-of-completion
+ * Then the preprocessor normally returns arbitrarily many end-of-completion
* (EOC) tokens.
- *
+ *
* A bottom-up parser cannot know ahead of time how many EOC tokens are
* needed in order for the parse to complete successfully. So we pick
* a number that seems arbitrarily large enough.
*/
private static final int NUM_EOC_TOKENS = 50;
-
- private static final int DUMMY_TOKEN_KIND = 0;
- private static final int tCOMPLETION = org.eclipse.cdt.core.parser.IToken.tCOMPLETION;
-
-
- /**
+
+ private static final int DUMMY_TOKEN_KIND = 0;
+ private static final int tCOMPLETION = org.eclipse.cdt.core.parser.IToken.tCOMPLETION;
+
+ /**
* Collect the tokens generated by the preprocessor.
* TODO: should preprocessor.nextTokenRaw() be called instead?
*/
public static void runCPreprocessor(IScanner preprocessor, ITokenCollector tokenCollector, IDOMTokenMap tokenMap) {
// LPG requires that the token stream start with a dummy token
tokenCollector.addToken(createDummyToken());
-
+
org.eclipse.cdt.core.parser.IToken lastToken = null;
try {
- while(true) {
+ while (true) {
// the preprocessor throws EndOfFileException when it reaches the end of input
org.eclipse.cdt.core.parser.IToken domToken = preprocessor.nextToken();
processDOMToken(domToken, tokenCollector, tokenMap);
lastToken = domToken;
-
- if(domToken.getType() == tCOMPLETION)
+
+ if (domToken.getType() == tCOMPLETION)
break;
}
- } catch(OffsetLimitReachedException e) {
+ } catch (OffsetLimitReachedException e) {
// preprocessor throws this when content assist is invoked inside a preprocessor directive
org.eclipse.cdt.core.parser.IToken domToken = e.getFinalToken();
assert domToken.getType() == tCOMPLETION;
processDOMToken(domToken, tokenCollector, tokenMap);
lastToken = domToken;
- } catch (EndOfFileException e) {
+ } catch (EndOfFileException e) {
// use thrown exception to break out of loop
- }
-
+ }
- // TODO
+ // TODO
// This computation is actually incorrect. The "offset" of the EOF token should
// be equal to the size of the file. But since the CPreprocessor throws an exception when it
// reaches the end we can't get this info. So we just use the offset of the last real token
// that was returned.
int eofTokenOffset = lastToken == null ? 0 : lastToken.getOffset();
-
+
// LPG requires that the token stream end with an EOF token
tokenCollector.addToken(createEOFToken(tokenMap, eofTokenOffset));
}
-
-
- private static void processDOMToken(org.eclipse.cdt.core.parser.IToken domToken, ITokenCollector tokenCollector, IDOMTokenMap tokenMap) {
- int newKind = tokenMap.mapKind(domToken);
+
+ private static void processDOMToken(org.eclipse.cdt.core.parser.IToken domToken, ITokenCollector tokenCollector,
+ IDOMTokenMap tokenMap) {
+ int newKind = tokenMap.mapKind(domToken);
tokenCollector.addToken(new LPGTokenAdapter(domToken, newKind));
-
- if(domToken.getType() == tCOMPLETION) {
+
+ if (domToken.getType() == tCOMPLETION) {
int offset = domToken.getOffset();
- for(int i = 0; i < NUM_EOC_TOKENS; i++)
+ for (int i = 0; i < NUM_EOC_TOKENS; i++)
tokenCollector.addToken(createEOCToken(tokenMap, offset));
}
}
-
-
+
private static IToken createEOCToken(IDOMTokenMap tokenMap, int offset) {
- return new Token(null, offset, offset+1, tokenMap.getEOCTokenKind());
+ return new Token(null, offset, offset + 1, tokenMap.getEOCTokenKind());
}
-
+
private static IToken createDummyToken() {
return new Token(null, 0, 0, DUMMY_TOKEN_KIND);
}
-
+
private static IToken createEOFToken(IDOMTokenMap tokenMap, int offset) {
- return new Token(null, offset, offset+1, tokenMap.getEOFTokenKind());
+ return new Token(null, offset, offset + 1, tokenMap.getEOFTokenKind());
}
-
+
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IDOMTokenMap.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IDOMTokenMap.java
index 0c48e59eb88..911de12803b 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IDOMTokenMap.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IDOMTokenMap.java
@@ -18,7 +18,7 @@ import org.eclipse.cdt.core.parser.IToken;
/**
* Maps tokens returned by CPreprocessor to the corresponding
* token kind used by an LPG based parser.
- *
+ *
* @author Mike Kucera
*/
public interface IDOMTokenMap {
@@ -28,15 +28,15 @@ public interface IDOMTokenMap {
* @throws NullPointerException if token is null
*/
int mapKind(IToken token);
-
+
/**
* Returns the LPG token type for End Of File (TK_EOF_TOKEN) token.
*/
- int getEOFTokenKind();
-
+ int getEOFTokenKind();
+
/**
* Returns the LPG token type for End Of Completion (TK_EndOfCompletion) token.
*/
int getEOCTokenKind();
-
+
}
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 7a3a3a220d1..97fad538d13 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
@@ -16,33 +16,28 @@ package org.eclipse.cdt.core.dom.lrparser;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTNode;
-
/**
* Represents a parser that can be used by BaseExtensibleLanguage.
- *
+ *
* @author Mike Kucera
*/
public interface IParser<N extends IASTNode> {
-
-
+
/**
* Performs the actual parse.
- *
+ *
* 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
* will be available via the getCompletionNode() method.
*/
public N parse();
-
-
+
/**
* Returns the completion node if a completion token was encountered
* during the parse, null otherwise.
*/
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
index 912b490ab11..6ef6f0bfe0d 100644
--- 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
@@ -21,19 +21,18 @@ 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 995d19b23b0..dd780f988bd 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -18,20 +18,20 @@ import lpg.lpgjavaruntime.IToken;
/**
* An LPG parser object is initialized with the list of tokens
* before parsing is invoked.
- *
+ *
* @author Mike Kucera
*/
public interface ITokenCollector {
-
+
/**
* Used to add one token at a time to the parser.
* If this method is used to add tokens then the dummy token
* and the EOF token must be added by the client.
- *
+ *
* This is really just an optimization, no intermediate data structures
- * are required between the preprocessor and the parser.
- *
- * @throws NullPointerException if token is null
+ * are required between the preprocessor and the parser.
+ *
+ * @throws NullPointerException if token is null
*/
public void addToken(IToken token);
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LPGTokenAdapter.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LPGTokenAdapter.java
index 50774d6e281..0ea784d88d5 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LPGTokenAdapter.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LPGTokenAdapter.java
@@ -13,30 +13,28 @@
*******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser;
-
import lpg.lpgjavaruntime.PrsStream;
/**
- * The CPreprocessor from the CDT core returns tokens that
+ * The CPreprocessor from the CDT core returns tokens that
* are of the type org.eclipse.cdt.core.parser.IToken,
* however LPG wants the tokens to be of the type lpg.lpgjavaruntime.IToken.
- *
+ *
* So these adapter objects are used to wrap the tokens returned
* by CPreprocessor so that they can be used with LPG.
- *
+ *
* @author Mike Kucera
*/
public class LPGTokenAdapter implements lpg.lpgjavaruntime.IToken {
-
+
/** The token object that is being wrapped */
private final org.eclipse.cdt.core.parser.IToken token;
-
-
+
private int tokenIndex;
private int adjunctIndex;
-
+
private int kind;
-
+
public LPGTokenAdapter(org.eclipse.cdt.core.parser.IToken token, int parserKind) {
this.token = token;
this.kind = parserKind;
@@ -45,7 +43,7 @@ public class LPGTokenAdapter implements lpg.lpgjavaruntime.IToken {
public org.eclipse.cdt.core.parser.IToken getWrappedToken() {
return token;
}
-
+
@Override
public int getAdjunctIndex() {
return adjunctIndex;
@@ -138,9 +136,9 @@ public class LPGTokenAdapter implements lpg.lpgjavaruntime.IToken {
this.tokenIndex = tokenIndex;
}
- @Override
+ @Override
public String toString() {
return token.toString();
}
-
+
}
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
index 7a43051fc6d..26e0eaa3315 100644
--- 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
@@ -18,14 +18,11 @@ 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 {
@@ -38,59 +35,58 @@ public class LRParserPlugin extends Plugin {
try {
// shutdown code goes here
plugin = null;
- }
- finally {
+ } 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
index 041ba7b25ee..c840d6e6443 100644
--- 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
@@ -13,27 +13,26 @@
*******************************************************************************/
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,
+ * 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
+ * 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";
@@ -42,5 +41,5 @@ public final class LRParserProperties {
* 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 ff88cb411f9..29d8c40e8d6 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
@@ -7,33 +7,31 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors: IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser;
import org.eclipse.cdt.core.dom.parser.AbstractScannerExtensionConfiguration;
-
/**
* A minimalistic scanner configuration for the LR parser.
- *
+ *
* @author Mike Kucera
*
*/
@SuppressWarnings("nls")
public class ScannerExtensionConfiguration extends AbstractScannerExtensionConfiguration {
-
private ScannerExtensionConfiguration() {
}
-
+
public static ScannerExtensionConfiguration createC() {
ScannerExtensionConfiguration sec = new ScannerExtensionConfiguration();
- sec.addMacro("__null", "(void *)0");
+ sec.addMacro("__null", "(void *)0");
return sec;
}
-
+
public static ScannerExtensionConfiguration createCPP() {
ScannerExtensionConfiguration sec = new ScannerExtensionConfiguration();
sec.addMacro("__null", "0");
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 5b00f8624ac..36eb0556c25 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -23,52 +23,49 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
/**
* An AST node that represents the location of content assist
* in the source file.
- *
+ *
* This node may contain the prefix text of an identifier up to the point. If
* there is no prefix, the completion occurred at the point where a new token
* would have begun.
- *
+ *
* Contains a list of name nodes, each name represents an identifier
* at the point where content assist was invoked. There is usually
* a single name node, however if an ambiguity is detected then that section
* of the source may be interpreted in more than one way (for example, as an expression then as a declaration).
* This results in an ambiguity node in the tree and one name node for each of the ways it can be interpreted.
- *
+ *
* The full AST may be accessed via getTranslationUnit() or by following
* the parent pointers of the name nodes.
- *
+ *
* @author Mike Kucera
*/
public class ASTCompletionNode implements IASTCompletionNode {
private final List<CompletionNameEntry> entries = new ArrayList<>();
-
+
private final String prefix;
private IASTTranslationUnit tu;
-
-
+
/**
* Creates a completion node.
* @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$
+ if ("".equals(prefix)) //$NON-NLS-1$
prefix = null;
-
+
this.prefix = prefix;
this.tu = tu;
}
-
+
public ASTCompletionNode(String prefix) {
this(prefix, null);
}
-
public void addName(IASTName name) {
entries.add(new CompletionNameEntry(name, name.getParent()));
}
-
/**
* Returns the length of the prefix.
*/
@@ -77,7 +74,6 @@ public class ASTCompletionNode implements IASTCompletionNode {
return prefix == null ? 0 : prefix.length();
}
-
@Override
public IASTName[] getNames() {
IASTName[] names = new IASTName[entries.size()];
@@ -87,18 +83,17 @@ public class ASTCompletionNode implements IASTCompletionNode {
return names;
}
-
/**
* If the point of completion was at the end of a potential identifier, this
* string contains the text of that identifier.
- *
+ *
* @returns a string of length >= 1 or null
*/
@Override
public String getPrefix() {
return prefix;
}
-
+
public void setTranslationUnit(IASTTranslationUnit tu) {
this.tu = 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
index c25df74bac1..87617550e74 100644
--- 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
@@ -28,109 +28,98 @@ 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.
- *
+ * 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();
-
-
-
-
+ 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)
+ if (parser == null)
throw new NullPointerException("parser is null"); //$NON-NLS-1$
- if(astStack == null)
+ 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);
+ ((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))
+ 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;
+
+ 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
+ * 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) {
+ 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
@@ -138,50 +127,46 @@ public abstract class AbstractParserAction {
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) {
+ 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)
+ 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())
+ if (compNode != null) {
+ for (IASTName name : compNode.getNames())
addNameToCompletionNode(name, compNode.getPrefix());
}
-
+
// restore the token kinds
i = 0;
- for(IToken token : tokens)
+ for (IToken token : tokens)
token.setKind(savedKinds[i++]);
-
+
return result;
}
-
-
/*************************************************************************************************************
* Basic Actions
************************************************************************************************************/
-
/**
* Method that is called by the special <openscope> production
@@ -190,8 +175,7 @@ public abstract class AbstractParserAction {
public void openASTScope() {
astStack.openScope();
}
-
-
+
/**
* Place null on the stack.
* Usually called for optional element to indicate the element
@@ -201,19 +185,17 @@ public abstract class AbstractParserAction {
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.
+ * 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.
@@ -221,8 +203,7 @@ public abstract class AbstractParserAction {
public void consumeIgnore() {
astStack.pop();
}
-
-
+
/**
* Gets the current token and places it on the stack for later consumption.
*/
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 8d9f007d956..5c5df984965 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
@@ -90,51 +90,48 @@ import lpg.lpgjavaruntime.IToken;
/**
* Parser semantic actions that are common to both C and C++.
- *
+ *
* @author Mike Kucera
*/
@SuppressWarnings("restriction")
public abstract class BuildASTParserAction extends AbstractParserAction {
-
/** Abstract factory for creating AST node objects */
private final INodeFactory nodeFactory;
-
+
/** Abstract factory for creating secondary parsers */
private final ISecondaryParserFactory parserFactory;
-
-
+
/**
* Returns true if the token is an identifier.
*/
protected abstract boolean isIdentifierToken(IToken token);
-
-
+
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(ITokenStream parser, ScopedStack<Object> astStack, INodeFactory nodeFactory, ISecondaryParserFactory parserFactory) {
+ public BuildASTParserAction(ITokenStream parser, ScopedStack<Object> astStack, INodeFactory nodeFactory,
+ ISecondaryParserFactory parserFactory) {
super(parser, astStack);
-
- if(nodeFactory == null)
+
+ if (nodeFactory == null)
throw new NullPointerException("nodeFactory is null"); //$NON-NLS-1$
- if(parserFactory == null)
+ if (parserFactory == null)
throw new NullPointerException("parserFactory is null"); //$NON-NLS-1$
-
+
this.nodeFactory = nodeFactory;
this.parserFactory = parserFactory;
}
-
-
- public void initializeTranslationUnit(IScanner scanner, IBuiltinBindingsProvider builtinBindingsProvider, IIndex index) {
+
+ public void initializeTranslationUnit(IScanner scanner, IBuiltinBindingsProvider builtinBindingsProvider,
+ IIndex index) {
tu = nodeFactory.newTranslationUnit(scanner);
tu.setIndex(index);
-
+
// add built-in names to the scope
if (builtinBindingsProvider != null) {
IScope tuScope = tu.getScope();
@@ -143,114 +140,106 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
ASTInternal.addBinding(tuScope, binding);
}
}
-
- if(tu instanceof ASTTranslationUnit) {
- ((ASTTranslationUnit)tu).setLocationResolver(scanner.getLocationResolver());
+
+ if (tu instanceof ASTTranslationUnit) {
+ ((ASTTranslationUnit) tu).setLocationResolver(scanner.getLocationResolver());
}
}
-
public void consumeTranslationUnit() {
- if(tu == null)
+ if (tu == null)
tu = nodeFactory.newTranslationUnit(null);
-
+
// can't close the outermost scope
- for(Object o : astStack.topScope()) {
- tu.addDeclaration((IASTDeclaration)o);
+ for (Object o : astStack.topScope()) {
+ tu.addDeclaration((IASTDeclaration) o);
}
- while(!astStack.isEmpty()) {
+ 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) {
- IASTNode d = declarations[declarations.length-1];
- ParserUtil.setOffsetAndLength(tu, 0, offset(d) + length(d));
- }
-
- resolveAmbiguityNodes(tu);
- tu.freeze();
-
- astStack.push(tu);
+ if (declarations.length != 0) {
+ IASTNode d = declarations[declarations.length - 1];
+ ParserUtil.setOffsetAndLength(tu, 0, offset(d) + length(d));
+ }
+
+ resolveAmbiguityNodes(tu);
+ tu.freeze();
+
+ astStack.push(tu);
}
-
@Override
public ASTCompletionNode newCompletionNode(String prefix) {
return new ASTCompletionNode(prefix, tu);
}
-
/**
* Removes ambiguity nodes from the AST by resolving them.
- *
+ *
* @see AbstractGNUSourceCodeParser#resolveAmbiguities()
*/
private static void resolveAmbiguityNodes(IASTTranslationUnit tu) {
if (tu instanceof ASTTranslationUnit) {
- ((ASTTranslationUnit)tu).resolveAmbiguities();
+ ((ASTTranslationUnit) tu).resolveAmbiguities();
}
}
-
- /**
- * Consumes a single identifier token.
- */
- public void consumeIdentifierName() {
- astStack.push(createName(stream.getRightIToken()));
- }
-
-
- /**
- * block_item ::= declaration | statement
- *
+
+ /**
+ * Consumes a single identifier token.
+ */
+ public void consumeIdentifierName() {
+ astStack.push(createName(stream.getRightIToken()));
+ }
+
+ /**
+ * block_item ::= declaration | statement
+ *
* TODO, be careful where exactly in the grammar this is called, it may be called unnecessarily
*/
public void consumeStatementDeclarationWithDisambiguation() {
IASTDeclaration decl = (IASTDeclaration) astStack.pop();
IASTDeclarationStatement declarationStatement = nodeFactory.newDeclarationStatement(decl);
setOffsetAndLength(declarationStatement);
-
+
// attempt to also parse the tokens as an expression
IASTExpressionStatement expressionStatement = null;
- if(decl instanceof IASTSimpleDeclaration) {
+ if (decl instanceof IASTSimpleDeclaration) {
List<IToken> expressionTokens = stream.getRuleTokens();
- expressionTokens = expressionTokens.subList(0, expressionTokens.size()-1); // remove the semicolon at the end
-
+ expressionTokens = expressionTokens.subList(0, expressionTokens.size() - 1); // remove the semicolon at the end
+
ISecondaryParser<IASTExpression> expressionParser = parserFactory.getExpressionParser(stream, properties);
IASTExpression expr = runSecondaryParser(expressionParser, expressionTokens);
-
- if(expr != null) { // the parse may fail
+
+ if (expr != null) { // the parse may fail
expressionStatement = nodeFactory.newExpressionStatement(expr);
setOffsetAndLength(expressionStatement);
}
}
-
-
+
List<IToken> tokens = stream.getRuleTokens();
-
+
IASTNode result;
- if(expressionStatement == null)
+ if (expressionStatement == null)
result = declarationStatement;
- else if(expressionStatement.getExpression() instanceof IASTFunctionCallExpression)
+ 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
+ else if (tokens.size() == 2 && (isCompletionToken(tokens.get(0)) || isIdentifierToken(tokens.get(0)))) // identifier followed by semicolon
result = expressionStatement;
- else if(isImplicitInt(decl))
+ else if (isImplicitInt(decl))
result = expressionStatement;
else {
result = createAmbiguousStatement(declarationStatement, expressionStatement);
setOffsetAndLength(result);
}
-
+
astStack.push(result);
}
-
-
- protected abstract IASTAmbiguousStatement createAmbiguousStatement(IASTStatement ... statements);
-
-
-
+
+ protected abstract IASTAmbiguousStatement createAmbiguousStatement(IASTStatement... statements);
+
/**
* Wrap a declaration in a DeclarationStatement.
*/
@@ -260,34 +249,32 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(declarationStatement);
astStack.push(declarationStatement);
}
-
-
+
/**
* Returns true if the given declaration has unspecified type,
- * in this case the type defaults to int and is know as "implicit int".
- *
+ * in this case the type defaults to int and is know as "implicit int".
+ *
* With implicit int a lot of language constructs can be accidentally parsed
* as declarations:
- *
+ *
* eg) x = 1;
* Should be an assignment statement but can also be parsed as a declaration
* of a variable x, of unspecified type, initialized to 1.
- *
+ *
* These cases are easy to detect (using this method) and the wrong interpretation
* as a declaration is discarded.
- */
- protected static boolean isImplicitInt(IASTDeclaration declaration) {
- if(declaration instanceof IASTSimpleDeclaration) {
- IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)declaration).getDeclSpecifier();
- if(declSpec instanceof IASTSimpleDeclSpecifier &&
- ((IASTSimpleDeclSpecifier)declSpec).getType() == IASTSimpleDeclSpecifier.t_unspecified) {
- return true;
- }
- }
- return false;
- }
-
-
+ */
+ protected static boolean isImplicitInt(IASTDeclaration declaration) {
+ if (declaration instanceof IASTSimpleDeclaration) {
+ IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration) declaration).getDeclSpecifier();
+ if (declSpec instanceof IASTSimpleDeclSpecifier
+ && ((IASTSimpleDeclSpecifier) declSpec).getType() == IASTSimpleDeclSpecifier.t_unspecified) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* @param kind One of the kind flags from IASTLiteralExpression or ICPPASTLiteralExpression
* @see IASTLiteralExpression
@@ -296,67 +283,59 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
public void consumeExpressionLiteral(int kind) {
IToken token = stream.getRightIToken();
String rep = token.toString();
-
+
// Strip the quotes from string literals, this is just to be consistent
// with the dom parser (i.e. to make a test pass)
-// if(kind == IASTLiteralExpression.lk_string_literal &&
-// rep.startsWith("\"") && rep.endsWith("\"")) {
-// rep = rep.substring(1, rep.length()-1);
-// }
-
+ // if(kind == IASTLiteralExpression.lk_string_literal &&
+ // rep.startsWith("\"") && rep.endsWith("\"")) {
+ // rep = rep.substring(1, rep.length()-1);
+ // }
+
IASTLiteralExpression expr = nodeFactory.newLiteralExpression(kind, rep);
ParserUtil.setOffsetAndLength(expr, token);
astStack.push(expr);
}
-
-
public void consumeExpressionBracketed() {
IASTExpression operand = (IASTExpression) astStack.pop();
IASTUnaryExpression expr = nodeFactory.newUnaryExpression(IASTUnaryExpression.op_bracketedPrimary, operand);
- setOffsetAndLength(expr);
+ setOffsetAndLength(expr);
astStack.push(expr);
}
-
-
public void consumeExpressionID() {
IASTName name = createName(stream.getLeftIToken());
IASTIdExpression expr = nodeFactory.newIdExpression(name);
- setOffsetAndLength(expr);
- astStack.push(expr);
+ setOffsetAndLength(expr);
+ astStack.push(expr);
}
-
-
+
public void consumeExpressionName() {
IASTName name = (IASTName) astStack.pop();
IASTIdExpression expr = nodeFactory.newIdExpression(name);
- setOffsetAndLength(expr);
- astStack.push(expr);
+ setOffsetAndLength(expr);
+ astStack.push(expr);
}
-
-
+
/**
* expression ::= <openscope-ast> expression_list_actual
*/
public void consumeExpressionList() {
List<Object> expressions = astStack.closeScope();
- if(expressions.size() == 1) {
+ if (expressions.size() == 1) {
astStack.push(expressions.get(0));
- }
- else {
+ } else {
IASTExpressionList exprList = nodeFactory.newExpressionList();
-
- for(Object o : expressions) {
- exprList.addExpression((IASTExpression)o);
+
+ for (Object o : expressions) {
+ exprList.addExpression((IASTExpression) o);
}
-
+
setOffsetAndLength(exprList);
astStack.push(exprList);
}
}
-
-
+
/**
* postfix_expression ::= postfix_expression '[' expression ']'
*/
@@ -367,21 +346,19 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(expr);
astStack.push(expr);
}
-
-
+
/**
* postfix_expression ::= postfix_expression '(' expression_list_opt ')'
*/
public void consumeExpressionFunctionCall() {
IASTExpression argList = (IASTExpression) astStack.pop(); // may be null
- IASTExpression idExpr = (IASTExpression) astStack.pop();
-
+ IASTExpression idExpr = (IASTExpression) astStack.pop();
+
IASTFunctionCallExpression expr = nodeFactory.newFunctionCallExpression(idExpr, argList);
setOffsetAndLength(expr);
astStack.push(expr);
}
-
/**
* @param operator constant for {@link ICPPASTCastExpression}
*/
@@ -390,15 +367,16 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
IASTTypeId typeId = (IASTTypeId) astStack.pop();
IASTCastExpression expr = nodeFactory.newCastExpression(operator, typeId, operand);
setOffsetAndLength(expr);
-
+
IASTExpression alternateExpr = null;
- if(operator == IASTCastExpression.op_cast) { // don't reparse for dynamic_cast etc as those are not ambiguous
+ 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
- ISecondaryParser<IASTExpression> secondaryParser = parserFactory.getNoCastExpressionParser(stream, properties);
+ ISecondaryParser<IASTExpression> secondaryParser = parserFactory.getNoCastExpressionParser(stream,
+ properties);
alternateExpr = runSecondaryParser(secondaryParser);
}
-
- if(alternateExpr == null)
+
+ if (alternateExpr == null)
astStack.push(expr);
else {
IASTNode ambiguityNode = createAmbiguousExpression(expr, alternateExpr);
@@ -406,11 +384,9 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
astStack.push(ambiguityNode);
}
}
-
-
- protected abstract IASTAmbiguousExpression createAmbiguousExpression(IASTExpression ... expressions);
-
-
+
+ protected abstract IASTAmbiguousExpression createAmbiguousExpression(IASTExpression... expressions);
+
/**
* Lots of rules, no need to list them.
* @param operator From IASTUnaryExpression
@@ -421,9 +397,7 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(expr);
astStack.push(expr);
}
-
-
-
+
/**
* unary_operation ::= 'sizeof' '(' type_name ')'
* @see consumeExpressionUnaryOperator For the other use of sizeof
@@ -432,14 +406,14 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
IASTTypeId typeId = (IASTTypeId) astStack.pop();
IASTTypeIdExpression expr = nodeFactory.newTypeIdExpression(operator, typeId);
setOffsetAndLength(expr);
-
+
// try parsing as an expression to resolve ambiguities
- ISecondaryParser<IASTExpression> secondaryParser = parserFactory.getSizeofExpressionParser(stream, properties);
+ ISecondaryParser<IASTExpression> secondaryParser = parserFactory.getSizeofExpressionParser(stream, properties);
IASTExpression alternateExpr = runSecondaryParser(secondaryParser);
-
- if(alternateExpr == null)
+
+ if (alternateExpr == null)
astStack.push(expr);
- else if(isFunctionType(expr)) // bug 252243
+ else if (isFunctionType(expr)) // bug 252243
astStack.push(alternateExpr);
else {
IASTNode ambiguityNode = createAmbiguousExpression(expr, alternateExpr);
@@ -447,17 +421,15 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
astStack.push(ambiguityNode);
}
}
-
-
+
private static boolean isFunctionType(IASTExpression expr) {
- if(expr instanceof IASTTypeIdExpression) {
+ if (expr instanceof IASTTypeIdExpression) {
IASTTypeId typeId = ((IASTTypeIdExpression) expr).getTypeId();
return typeId.getAbstractDeclarator() instanceof IASTFunctionDeclarator;
}
return false;
}
-
-
+
/**
* Lots of rules, no need to list them all.
* @param op Field from IASTBinaryExpression
@@ -469,8 +441,7 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(binExpr);
astStack.push(binExpr);
}
-
-
+
/**
* conditional_expression ::= logical_OR_expression '?' expression ':' conditional_expression
*/
@@ -482,11 +453,10 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(condExpr);
astStack.push(condExpr);
}
-
-
+
/**
* labeled_statement ::= label_identifier ':' statement
- * label_identifier ::= identifier
+ * label_identifier ::= identifier
*/
public void consumeStatementLabeled() {
IASTStatement body = (IASTStatement) astStack.pop();
@@ -496,50 +466,46 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(stat);
astStack.push(stat);
}
-
-
+
/**
* labeled_statement ::= 'case' constant_expression ':' statement
*/
- public void consumeStatementCase() {
+ public void consumeStatementCase() {
IASTStatement body = (IASTStatement) astStack.pop();
IASTExpression expr = (IASTExpression) astStack.pop();
-
- IASTCaseStatement caseStatement = nodeFactory.newCaseStatement(expr);
+
+ 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' ':' <openscope-ast> statement
*/
public void consumeStatementDefault() {
IASTStatement body = (IASTStatement) astStack.pop();
-
+
IASTDefaultStatement stat = nodeFactory.newDefaultStatement();
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);
-
+
IASTCompoundStatement compound = nodeFactory.newCompoundStatement();
setOffsetAndLength(compound);
compound.addStatement(stat);
compound.addStatement(body);
-
+
astStack.push(compound);
}
-
-
-
+
/**
* expression_statement ::= ';'
*/
@@ -548,8 +514,7 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(stat);
astStack.push(stat);
}
-
-
+
/**
* expression_statement ::= expression ';'
*/
@@ -559,42 +524,37 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(stat);
astStack.push(stat);
}
-
-
-
+
/**
* compound_statement ::= <openscope> '{' block_item_list '}'
- *
+ *
* block_item_list ::= block_item | block_item_list block_item
*/
public void consumeStatementCompoundStatement(boolean hasStatementsInBody) {
IASTCompoundStatement block = nodeFactory.newCompoundStatement();
-
- if(hasStatementsInBody) {
- for(Object o : astStack.closeScope()) {
- block.addStatement((IASTStatement)o);
+
+ if (hasStatementsInBody) {
+ for (Object o : astStack.closeScope()) {
+ block.addStatement((IASTStatement) o);
}
}
-
+
setOffsetAndLength(block);
astStack.push(block);
}
-
/**
* iteration_statement_matched
* ::= 'do' statement 'while' '(' expression ')' ';'
* | 'do' statement
*/
public void consumeStatementDoLoop(boolean hasWhileBlock) {
- IASTExpression condition = hasWhileBlock? (IASTExpression) astStack.pop() : null;
+ IASTExpression condition = hasWhileBlock ? (IASTExpression) astStack.pop() : null;
IASTStatement body = (IASTStatement) astStack.pop();
IASTDoStatement stat = nodeFactory.newDoStatement(body, condition);
setOffsetAndLength(stat);
astStack.push(stat);
}
-
-
/**
* jump_statement ::= goto goto_identifier ';'
@@ -605,8 +565,7 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(gotoStat);
astStack.push(gotoStat);
}
-
-
+
/**
* jump_statement ::= continue ';'
*/
@@ -615,18 +574,16 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(stat);
astStack.push(stat);
}
-
-
+
/**
* jump_statement ::= break ';'
*/
- public void consumeStatementBreak() {
+ public void consumeStatementBreak() {
IASTBreakStatement stat = nodeFactory.newBreakStatement();
setOffsetAndLength(stat);
astStack.push(stat);
}
-
-
+
/**
* jump_statement ::= return ';'
* jump_statement ::= return expression ';'
@@ -638,174 +595,161 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
astStack.push(returnStat);
}
-
-
-
/**
* type_name ::= specifier_qualifier_list
- * | specifier_qualifier_list abstract_declarator
+ * | specifier_qualifier_list abstract_declarator
*/
public void consumeTypeId(boolean hasDeclarator) {
IASTDeclarator declarator;
- if(hasDeclarator)
+ if (hasDeclarator)
declarator = (IASTDeclarator) astStack.pop();
else {
declarator = nodeFactory.newDeclarator(nodeFactory.newName());
ParserUtil.setOffsetAndLength(declarator, stream.getRightIToken().getEndOffset(), 0);
}
-
+
IASTDeclSpecifier declSpecifier = (IASTDeclSpecifier) astStack.pop();
IASTTypeId typeId = nodeFactory.newTypeId(declSpecifier, declarator);
setOffsetAndLength(typeId);
astStack.push(typeId);
}
-
-
+
/**
* declarator
- * ::= <openscope-ast> ptr_operator_seq direct_declarator
- *
- * abstract_declarator
- * ::= <openscope-ast> ptr_operator_seq
- * | <openscope-ast> ptr_operator_seq direct_declarator
+ * ::= <openscope-ast> ptr_operator_seq direct_declarator
+ *
+ * abstract_declarator
+ * ::= <openscope-ast> ptr_operator_seq
+ * | <openscope-ast> ptr_operator_seq direct_declarator
*/
public void consumeDeclaratorWithPointer(boolean hasDeclarator) {
IASTDeclarator decl;
- if(hasDeclarator)
+ if (hasDeclarator)
decl = (IASTDeclarator) astStack.pop();
else
decl = nodeFactory.newDeclarator(nodeFactory.newName());
-
- for(Object pointer : astStack.closeScope())
- decl.addPointerOperator((IASTPointerOperator)pointer);
-
+
+ for (Object pointer : astStack.closeScope())
+ decl.addPointerOperator((IASTPointerOperator) pointer);
+
setOffsetAndLength(decl);
astStack.push(decl);
}
-
-
-
- /**
- * init_declarator
- * ::= declarator initializer
- *
- * @param hasDeclarator in C++ its possible for a parameter declaration to specifiy
- * a default value without also specifying a named declarator
- */
- public void consumeDeclaratorWithInitializer(boolean hasDeclarator) {
- IASTInitializer initializer = (IASTInitializer) astStack.pop();
-
- IASTDeclarator declarator;
- if(hasDeclarator) {
- declarator = (IASTDeclarator) astStack.peek();
- }
- else {
- IASTName emptyName = nodeFactory.newName();
- declarator = nodeFactory.newDeclarator(emptyName);
- setOffsetAndLength(emptyName);
- astStack.push(declarator);
- }
-
+
+ /**
+ * init_declarator
+ * ::= declarator initializer
+ *
+ * @param hasDeclarator in C++ its possible for a parameter declaration to specifiy
+ * a default value without also specifying a named declarator
+ */
+ public void consumeDeclaratorWithInitializer(boolean hasDeclarator) {
+ IASTInitializer initializer = (IASTInitializer) astStack.pop();
+
+ IASTDeclarator declarator;
+ if (hasDeclarator) {
+ declarator = (IASTDeclarator) astStack.peek();
+ } else {
+ IASTName emptyName = nodeFactory.newName();
+ declarator = nodeFactory.newDeclarator(emptyName);
+ setOffsetAndLength(emptyName);
+ astStack.push(declarator);
+ }
+
declarator.setInitializer(initializer);
setOffsetAndLength(declarator); // adjust the length to include the initializer
- }
-
-
+ }
+
/**
* asm_definition
- * ::= 'asm' '(' 'stringlit' ')' ';'
+ * ::= 'asm' '(' 'stringlit' ')' ';'
*/
public void consumeDeclarationASM() {
String s = stream.getRuleTokens().get(2).toString();
IASTASMDeclaration asm = nodeFactory.newASMDeclaration(s);
-
+
setOffsetAndLength(asm);
astStack.push(asm);
}
-
-
-
- /**
+
+ /**
* parameter_declaration ::= declaration_specifiers declarator
- * | declaration_specifiers abstract_declarator
+ * | declaration_specifiers abstract_declarator
*/
public void consumeParameterDeclaration() {
- IASTDeclarator declarator = (IASTDeclarator) astStack.pop();
+ IASTDeclarator declarator = (IASTDeclarator) astStack.pop();
IASTDeclSpecifier declSpec = (IASTDeclSpecifier) astStack.pop();
IASTParameterDeclaration declaration = nodeFactory.newParameterDeclaration(declSpec, declarator);
setOffsetAndLength(declaration);
astStack.push(declaration);
}
-
-
+
/**
- * parameter_declaration ::= declaration_specifiers
+ * parameter_declaration ::= declaration_specifiers
*/
public void consumeParameterDeclarationWithoutDeclarator() {
- // offsets need to be calculated differently in this case
+ // offsets need to be calculated differently in this case
final int endOffset = stream.getRightIToken().getEndOffset();
-
+
IASTName name = nodeFactory.newName();
ParserUtil.setOffsetAndLength(name, endOffset, 0);
-
+
// it appears that a declarator is always required in the AST here
IASTDeclarator declarator = nodeFactory.newDeclarator(name);
ParserUtil.setOffsetAndLength(declarator, endOffset, 0);
-
+
IASTDeclSpecifier declSpec = (IASTDeclSpecifier) astStack.pop();
IASTParameterDeclaration declaration = nodeFactory.newParameterDeclaration(declSpec, declarator);
-
+
setOffsetAndLength(declaration);
astStack.push(declaration);
}
-
-
+
/**
* TODO: do I really want to share declaration rules between the two parsers.
- * Even if there is potential for reuse it still may be cleaner to leave the
+ * Even if there is potential for reuse it still may be cleaner to leave the
* common stuff to just simple expressions and statements.
- *
+ *
* For C99:
- *
+ *
* declaration ::= declaration_specifiers <openscope> init_declarator_list ';'
* declaration ::= declaration_specifiers ';'
- *
- *
+ *
+ *
* For C++:
- *
+ *
* simple_declaration
- * ::= declaration_specifiers_opt <openscope-ast> init_declarator_list_opt ';'
- *
- *
- * TODO Make both grammars the same here.
+ * ::= declaration_specifiers_opt <openscope-ast> init_declarator_list_opt ';'
+ *
+ *
+ * TODO Make both grammars the same here.
*/
-// public void consumeDeclarationSimple(boolean hasDeclaratorList) {
-// if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-//
-// List<Object> declarators = (hasDeclaratorList) ? astStack.closeScope() : Collections.emptyList();
-// IASTDeclSpecifier declSpecifier = (IASTDeclSpecifier) astStack.pop(); // may be null
-//
-// // do not generate nodes for extra EOC tokens
-// if(matchTokens(parser.getRuleTokens(), CPPParsersym.TK_EndOfCompletion))
-// return;
-//
-// if(declSpecifier == null) { // can happen if implicit int is used
-// declSpecifier = nodeFactory.newSimpleDeclSpecifier();
-// setOffsetAndLength(declSpecifier, parser.getLeftIToken().getStartOffset(), 0);
-// }
-//
-// IASTSimpleDeclaration declaration = nodeFactory.newSimpleDeclaration(declSpecifier);
-//
-// for(Object declarator : declarators)
-// declaration.addDeclarator((IASTDeclarator)declarator);
-//
-// setOffsetAndLength(declaration);
-// astStack.push(declaration);
-//
-// if(TRACE_AST_STACK) System.out.println(astStack);
-// }
-
-
+ // public void consumeDeclarationSimple(boolean hasDeclaratorList) {
+ // if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
+ //
+ // List<Object> declarators = (hasDeclaratorList) ? astStack.closeScope() : Collections.emptyList();
+ // IASTDeclSpecifier declSpecifier = (IASTDeclSpecifier) astStack.pop(); // may be null
+ //
+ // // do not generate nodes for extra EOC tokens
+ // if(matchTokens(parser.getRuleTokens(), CPPParsersym.TK_EndOfCompletion))
+ // return;
+ //
+ // if(declSpecifier == null) { // can happen if implicit int is used
+ // declSpecifier = nodeFactory.newSimpleDeclSpecifier();
+ // setOffsetAndLength(declSpecifier, parser.getLeftIToken().getStartOffset(), 0);
+ // }
+ //
+ // IASTSimpleDeclaration declaration = nodeFactory.newSimpleDeclaration(declSpecifier);
+ //
+ // for(Object declarator : declarators)
+ // declaration.addDeclarator((IASTDeclarator)declarator);
+ //
+ // setOffsetAndLength(declaration);
+ // astStack.push(declaration);
+ //
+ // if(TRACE_AST_STACK) System.out.println(astStack);
+ // }
+
/**
* direct_declarator ::= '(' declarator ')'
*/
@@ -816,8 +760,7 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(declarator);
astStack.push(declarator);
}
-
-
+
/**
* direct_declarator ::= declarator_id_name
*/
@@ -827,21 +770,19 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
setOffsetAndLength(declarator);
astStack.push(declarator);
}
-
-
+
/**
- * array_modifier
- * ::= '[' ']'
- * | '[' assignment_expression ']'
- */
+ * array_modifier
+ * ::= '[' ']'
+ * | '[' assignment_expression ']'
+ */
public void consumeDirectDeclaratorArrayModifier(boolean hasAssignmentExpr) {
- IASTExpression expr = hasAssignmentExpr ? (IASTExpression)astStack.pop() : null;
+ IASTExpression expr = hasAssignmentExpr ? (IASTExpression) astStack.pop() : null;
IASTArrayModifier arrayModifier = nodeFactory.newArrayModifier(expr);
setOffsetAndLength(arrayModifier);
astStack.push(arrayModifier);
}
-
-
+
/**
* When the identifier part of a declarator is parsed it will put a plain IASTDeclarator on the stack.
* When the array modifier part is parsed we will need to throw away the plain
@@ -851,165 +792,156 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
*/
protected void addArrayModifier(IASTArrayModifier arrayModifier) {
IASTDeclarator node = (IASTDeclarator) astStack.pop();
-
+
// Its a nested declarator so create an new ArrayDeclarator
- if(node.getNestedDeclarator() != null) { //node.getPropertyInParent() == IASTDeclarator.NESTED_DECLARATOR) {
+ if (node.getNestedDeclarator() != null) { //node.getPropertyInParent() == IASTDeclarator.NESTED_DECLARATOR) {
IASTArrayDeclarator declarator = nodeFactory.newArrayDeclarator(nodeFactory.newName());
IASTDeclarator nested = node;
declarator.setNestedDeclarator(nested);
-
+
int offset = offset(nested);
int length = endOffset(arrayModifier) - offset;
ParserUtil.setOffsetAndLength(declarator, offset, length);
-
+
declarator.addArrayModifier(arrayModifier);
astStack.push(declarator);
}
// There is already an array declarator so just add the modifier to it
- else if(node instanceof IASTArrayDeclarator) {
+ else if (node instanceof IASTArrayDeclarator) {
IASTArrayDeclarator decl = (IASTArrayDeclarator) node;
- ((ASTNode)decl).setLength(endOffset(arrayModifier) - offset(decl));
-
+ ((ASTNode) decl).setLength(endOffset(arrayModifier) - offset(decl));
+
decl.addArrayModifier(arrayModifier);
astStack.push(decl);
}
// The declarator is an identifier so create a new array declarator
- else {
+ else {
IASTName name = node.getName();
IASTArrayDeclarator decl = nodeFactory.newArrayDeclarator(name);
-
+
int offset = offset(name);
int length = endOffset(arrayModifier) - offset;
ParserUtil.setOffsetAndLength(decl, offset, length);
-
+
decl.addArrayModifier(arrayModifier);
astStack.push(decl);
}
}
-
-
+
/**
- * Pops a simple declarator from the stack, converts it into
+ * Pops a simple declarator from the stack, converts it into
* a FunctionDeclator, then pushes it.
* TODO: is this the best way of doing this?
* TODO, rename this method, its an accidental overload
*/
protected void addFunctionModifier(IASTFunctionDeclarator declarator, int endOffset) {
IASTDeclarator decl = (IASTDeclarator) astStack.pop();
-
- if(decl.getNestedDeclarator() != null) {
+
+ if (decl.getNestedDeclarator() != null) {
decl = decl.getNestedDeclarator(); // need to remove one level of nesting for function pointers
declarator.setNestedDeclarator(decl);
declarator.setName(nodeFactory.newName());
int offset = offset(decl);
ParserUtil.setOffsetAndLength(declarator, offset, endOffset - offset);
astStack.push(declarator);
- }
- else {
+ } else {
IASTName name = decl.getName();
- if(name == null) {
+ if (name == null) {
name = nodeFactory.newName();
}
declarator.setName(name);
-
+
IASTPointerOperator[] pointers = decl.getPointerOperators();
for (IASTPointerOperator pointer : pointers) {
declarator.addPointerOperator(pointer);
}
-
+
int offset = offset(name); // TODO
ParserUtil.setOffsetAndLength(declarator, offset, endOffset - offset);
astStack.push(declarator);
}
}
-
+
// TODO why is this here
-// /**
-// * direct_declarator ::= direct_declarator array_modifier
-// * consume the direct_declarator part and add the array modifier
-// */
-// public void consumeDirectDeclaratorArrayDeclarator() {
-// if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
-//
-// IASTArrayModifier arrayModifier = (IASTArrayModifier) astStack.pop();
-// addArrayModifier(arrayModifier);
-// }
-
-
+ // /**
+ // * direct_declarator ::= direct_declarator array_modifier
+ // * consume the direct_declarator part and add the array modifier
+ // */
+ // public void consumeDirectDeclaratorArrayDeclarator() {
+ // if(TRACE_ACTIONS) DebugUtil.printMethodTrace();
+ //
+ // IASTArrayModifier arrayModifier = (IASTArrayModifier) astStack.pop();
+ // addArrayModifier(arrayModifier);
+ // }
+
/**
- * direct_abstract_declarator
- * ::= array_modifier
- * | direct_abstract_declarator array_modifier
+ * direct_abstract_declarator
+ * ::= array_modifier
+ * | direct_abstract_declarator array_modifier
*/
public void consumeDirectDeclaratorArrayDeclarator(boolean hasDeclarator) {
IASTArrayModifier arrayModifier = (IASTArrayModifier) astStack.pop();
-
- if(hasDeclarator) {
+
+ if (hasDeclarator) {
addArrayModifier(arrayModifier);
- }
- else {
+ } else {
IASTArrayDeclarator decl = nodeFactory.newArrayDeclarator(nodeFactory.newName());
decl.addArrayModifier(arrayModifier);
setOffsetAndLength(decl);
astStack.push(decl);
}
}
-
-
-
-
+
/**
* enum_specifier ::= 'enum' '{' <openscope> enumerator_list_opt '}'
- * | 'enum' enum_identifier '{' <openscope> enumerator_list_opt '}'
+ * | 'enum' enum_identifier '{' <openscope> enumerator_list_opt '}'
*/
public void consumeTypeSpecifierEnumeration(boolean hasIdent) {
IASTName name = (hasIdent) ? createName(stream.getRuleTokens().get(1)) : nodeFactory.newName();
-
+
IASTEnumerationSpecifier enumSpec = nodeFactory.newEnumerationSpecifier(name);
- for(Object o : astStack.closeScope())
- enumSpec.addEnumerator((IASTEnumerator)o);
+ for (Object o : astStack.closeScope())
+ enumSpec.addEnumerator((IASTEnumerator) o);
setOffsetAndLength(enumSpec);
astStack.push(enumSpec);
}
-
-
+
/**
* enumerator ::= enum_identifier
- * | enum_identifier '=' constant_expression
+ * | enum_identifier '=' constant_expression
*/
public void consumeEnumerator(boolean hasInitializer) {
IASTName name = createName(stream.getLeftIToken());
-
+
IASTExpression value = null;
- if(hasInitializer)
+ if (hasInitializer)
value = (IASTExpression) astStack.pop();
-
+
IASTEnumerator enumerator = nodeFactory.newEnumerator(name, value);
setOffsetAndLength(enumerator);
astStack.push(enumerator);
}
-
-
+
private int initializerListNestingLevel = 0;
-
+
public void initializerListStart() {
initializerListNestingLevel++;
}
-
+
public void initializerListEnd() {
initializerListNestingLevel--;
}
-
+
/**
* initializer ::= assignment_expression
*/
public void consumeInitializer() {
//CDT_70_FIX_FROM_50-#4
- IASTInitializerClause initClause = (IASTInitializerClause) astStack.pop();
- if(initClause instanceof IASTExpression){
- if(discardInitializer((IASTExpression)initClause)) {
+ IASTInitializerClause initClause = (IASTInitializerClause) astStack.pop();
+ if (initClause instanceof IASTExpression) {
+ if (discardInitializer((IASTExpression) initClause)) {
astStack.push(null);
return;
}
@@ -1021,53 +953,45 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
astStack.push(initializer);
}
-
private boolean discardInitializer(IASTExpression expression) {
return initializerListNestingLevel > 0
- && Boolean.parseBoolean(properties.get(LRParserProperties.SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS))
- && !ASTQueries.canContainName(expression);
+ && Boolean.parseBoolean(
+ properties.get(LRParserProperties.SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS))
+ && !ASTQueries.canContainName(expression);
}
-
-
-
+
/**
* initializer ::= '{' <openscope> initializer_list '}'
- * | '{' <openscope> initializer_list ',' '}'
+ * | '{' <openscope> initializer_list ',' '}'
*/
public void consumeInitializerList() {
IASTInitializerList list = nodeFactory.newInitializerList();
- for(Object o : astStack.closeScope())
- list.addInitializer((IASTInitializer)o);
-
+ for (Object o : astStack.closeScope())
+ list.addInitializer((IASTInitializer) o);
+
setOffsetAndLength(list);
astStack.push(list);
}
-
-
-
-
-
+
/**
* struct_declarator
- * ::= ':' constant_expression
- * | declarator ':' constant_expression
+ * ::= ':' constant_expression
+ * | declarator ':' constant_expression
*/
public void consumeBitField(boolean hasDeclarator) {
- IASTExpression expr = (IASTExpression)astStack.pop();
-
+ IASTExpression expr = (IASTExpression) astStack.pop();
+
IASTName name;
- if(hasDeclarator) // it should have been parsed into a regular declarator
+ if (hasDeclarator) // it should have been parsed into a regular declarator
name = ((IASTDeclarator) astStack.pop()).getName();
else
name = nodeFactory.newName();
-
+
IASTFieldDeclarator fieldDecl = nodeFactory.newFieldDeclarator(name, expr);
setOffsetAndLength(fieldDecl);
astStack.push(fieldDecl);
}
-
-
/**
* statement ::= ERROR_TOKEN
@@ -1091,12 +1015,11 @@ public abstract class BuildASTParserAction extends AbstractParserAction {
consumeProblem(nodeFactory.newProblemDeclaration(null));
}
-
private void consumeProblem(IASTProblemHolder problemHolder) {
IASTProblem problem = nodeFactory.newProblem(IProblem.SYNTAX_ERROR, new char[0], true);
- problemHolder.setProblem(problem);
+ problemHolder.setProblem(problem);
setOffsetAndLength(problem);
- setOffsetAndLength((ASTNode)problemHolder);
+ setOffsetAndLength((ASTNode) problemHolder);
astStack.push(problemHolder);
}
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
index 3312e1ab9cd..1a4b03fb744 100644
--- 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
@@ -18,34 +18,30 @@ 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);
-
-
+ ISecondaryParser<IASTExpression> getExpressionParser(ITokenStream stream, Map<String, String> properties);
+
/**
* Expression parser that does not recognize cast expressions,
- * used to disambiguate casts.
+ * used to disambiguate casts.
*/
- ISecondaryParser<IASTExpression> getNoCastExpressionParser(ITokenStream stream, Map<String,String> properties);
-
-
+ 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);
-
+ 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/action/ITokenMap.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenMap.java
index 03aade0e5e0..400dbf281ff 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenMap.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenMap.java
@@ -13,13 +13,11 @@
*********************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action;
-
-
/**
* Maps tokens defined in parser extensions back to the token kinds
* defined in the lr parsers.
- *
- *
+ *
+ *
* @author Mike Kucera
*/
public interface ITokenMap {
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenStream.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenStream.java
index 5a344cd2a97..a1f6933512b 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenStream.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ITokenStream.java
@@ -20,51 +20,49 @@ import lpg.lpgjavaruntime.IToken;
/**
* Provides an interface to the token stream that
* can be used by the parser semantic actions.
- *
- * Allows the semantic actions to directly inspect the token
- * stream. Used to calculate AST node offsets and for
+ *
+ * Allows the semantic actions to directly inspect the token
+ * stream. Used to calculate AST node offsets and for
* other purposes.
- *
- * TODO There are still issues with getLeftIToken() and
+ *
+ * TODO There are still issues with getLeftIToken() and
* getRightIToken(), they should return null when used with
* an empty rule but currently they don't.
- *
+ *
* @author Mike Kucera
*/
public interface ITokenStream {
-
+
/**
* Returns the tokens that were parsed to recognized
* the currently executing rule.
- *
+ *
* @returns a read-only list of tokens, will not be null but may be empty
*/
public List<IToken> getRuleTokens();
-
+
/**
* Usually equivalent to getRuleTokens().get(0); but more efficient.
- *
+ *
* However, when called during an empty rule it will return the token to the
* left of the location of the empty rule.
*/
public IToken getLeftIToken();
-
+
/**
* Usually equivalent to getRuleTokens().get(getRuleTokens().size()-1); but more efficient.
- *
+ *
* However, when called during an empty rule it will return the token to the
* right of the location of the empty rule.
*/
- public IToken getRightIToken();
-
+ public IToken getRightIToken();
/**
* Returns the orderedTerminalSymbol field of the corresponding sym class
* generated by LPG.
*/
public String[] getOrderedTerminalSymbols();
-
-
+
/**
* Returns the parser's name, useful for debugging.
*/
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
index 8e405eb5996..091d0e57a2e 100644
--- 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
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -25,15 +25,15 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@SuppressWarnings("restriction")
public final class ParserUtil {
- private ParserUtil() {}
-
-
+ private ParserUtil() {
+ }
+
public static int offset(IToken token) {
return token.getStartOffset();
}
public static int offset(IASTNode node) {
- return ((ASTNode)node).getOffset();
+ return ((ASTNode) node).getOffset();
}
public static int length(IToken token) {
@@ -41,7 +41,7 @@ public final class ParserUtil {
}
public static int length(IASTNode node) {
- return ((ASTNode)node).getLength();
+ return ((ASTNode) node).getLength();
}
public static int endOffset(IASTNode node) {
@@ -52,44 +52,38 @@ public final class ParserUtil {
return token.getEndOffset();
}
-
-
-
public static void setOffsetAndLength(IASTNode node, IToken token) {
- ((ASTNode)node).setOffsetAndLength(offset(token), length(token));
+ ((ASTNode) node).setOffsetAndLength(offset(token), length(token));
}
public static void setOffsetAndLength(IASTNode node, int offset, int length) {
- ((ASTNode)node).setOffsetAndLength(offset, length);
+ ((ASTNode) node).setOffsetAndLength(offset, length);
}
-
+
public static void setOffsetAndLength(IASTNode node, IASTNode from) {
setOffsetAndLength(node, offset(from), length(from));
}
-
public static boolean isSameName(IASTName name1, IASTName name2) {
return Arrays.equals(name1.getLookupKey(), name2.getLookupKey());
}
-
-
+
/**
* 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
+ 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())
+
+ 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.
@@ -97,11 +91,11 @@ public final class ParserUtil {
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) {
+ for (IToken t : tokens) {
+ if (offset(t) == startOffset) {
first = i;
}
- if(endOffset(t) == endOffset) {
+ if (endOffset(t) == endOffset) {
last = i;
break;
}
@@ -109,7 +103,5 @@ public final class ParserUtil {
}
return tokens.subList(first, last + 1);
}
-
-
-
+
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ScopedStack.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ScopedStack.java
index 509ac9fd8c2..4cc9c773963 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ScopedStack.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ScopedStack.java
@@ -25,46 +25,44 @@ import java.util.NoSuchElementException;
* A stack that can be "marked", that is the stack can be divided
* into chunks that can be conveniently processed. There is always at
* least one open scope.
- *
- *
- * This stack was designed to be used to store AST nodes while
+ *
+ *
+ * This stack was designed to be used to store AST nodes while
* the AST is built during the parse, however it is useful for other
* purposes as well.
- *
+ *
* Some grammar rules have arbitrary length lists on the right side.
- * For example the rule for compound statements (where block_item_list is any
+ * For example the rule for compound statements (where block_item_list is any
* number of statements or declarations):
- *
+ *
* compound-statement ::= '{' <openscope-ast> block_item_list '}'
- *
+ *
* There is a problem when trying to build the AST node for the compound statement...
- * you don't know how many block_items are contained in the compound statement, so
+ * you don't know how many block_items are contained in the compound statement, so
* you don't know how many times to pop the AST stack.
- *
+ *
* One inelegant solution is to count the block-items as they are parsed. This
* is inelegant because nested compound-statements are allowed so you would
* have to maintain several counts at the same time.
- *
+ *
* Another solution would be to build the list of block-items as part of the
* block_item_list rule, but just using this stack is simpler.
- *
+ *
* This class can be used as an AST stack that is implemented as a stack of "AST Scopes".
- * There is a special grammar rule <openscope-ast> that creates a new AST Scope.
- * So, in order to consume all the block_items, all that has to be done is
+ * There is a special grammar rule <openscope-ast> that creates a new AST Scope.
+ * So, in order to consume all the block_items, all that has to be done is
* iterate over the topmost scope and then close it when done.
- *
- *
+ *
+ *
* @author Mike Kucera
*/
public class ScopedStack<T> {
private LinkedList<T> topScope;
-
+
// A stack of stacks, used to implement scoping
private final LinkedList<LinkedList<T>> scopeStack;
-
-
-
+
/**
* Creates a new ScopedStack with the first scope already open.
*/
@@ -72,82 +70,81 @@ public class ScopedStack<T> {
topScope = new LinkedList<T>();
scopeStack = new LinkedList<LinkedList<T>>();
}
-
-
+
/**
* Opens a new scope.
*/
public void openScope() {
- scopeStack.add(topScope);
+ scopeStack.add(topScope);
topScope = new LinkedList<T>();
}
-
+
/**
* Opens a scope then pushes all the items in the given list.
- *
+ *
* @throws NullPointerException if items is null
*/
public void openScope(Collection<T> items) {
openScope();
- for(T item : items)
+ for (T item : items)
push(item);
}
-
+
/**
* Marks the stack then pushes all the items in the given array.
- *
+ *
* @throws NullPointerException if items is null
*/
- public void openScope(T[] items) {
+ public void openScope(T[] items) {
// looks the same as above but compiles into different bytecode
openScope();
- for(T item : items)
+ for (T item : items)
push(item);
}
-
+
/**
* Pops all the items in the topmost scope.
* The outermost scope cannot be closed.
- *
+ *
* @throws NoSuchElementException If the outermost scope is closed.
*/
public List<T> closeScope() {
- if(scopeStack.isEmpty())
+ if (scopeStack.isEmpty())
throw new NoSuchElementException("cannot close outermost scope"); //$NON-NLS-1$
-
+
List<T> top = topScope;
topScope = scopeStack.removeLast();
return top;
}
-
+
/**
* Pushes an item onto the topmost scope.
*/
public void push(T o) {
topScope.add(o);
}
-
+
/**
* @throws NoSuchElementException if the topmost scope is empty
*/
public T pop() {
return topScope.removeLast();
}
-
+
/**
* @throws NoSuchElementException if the topmost scope is empty
*/
public T peek() {
return topScope.getLast();
}
-
+
/**
* Returns the entire top scope as a List.
*/
public List<T> topScope() {
return topScope;
}
-
+
/**
* Returns the next outermost scope.
* @throws NoSuchElementException if size() < 2
@@ -155,13 +152,11 @@ public class ScopedStack<T> {
public List<T> outerScope() {
return scopeStack.getLast();
}
-
public boolean isEmpty() {
return topScope.isEmpty() && scopeStack.isEmpty();
}
-
-
+
/**
* Why oh why does java not have reverse iterators?????
*/
@@ -169,27 +164,27 @@ public class ScopedStack<T> {
final String separator = "----------"; //$NON-NLS-1$
System.out.println();
System.out.println('-');
-
+
printScope(topScope);
System.out.println(separator);
-
- for(List<T> list : reverseIterable(scopeStack)) {
+
+ for (List<T> list : reverseIterable(scopeStack)) {
printScope(list);
}
-
+
System.out.println();
}
private void printScope(List<T> scope) {
- for(T t : reverseIterable(scope)) {
+ for (T t : reverseIterable(scope)) {
System.out.println(t);
}
}
-
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- for(List<T> scope : scopeStack)
+ for (List<T> scope : scopeStack)
appendScopeContents(sb, scope);
appendScopeContents(sb, topScope);
return sb.toString();
@@ -198,14 +193,14 @@ public class ScopedStack<T> {
private void appendScopeContents(StringBuilder sb, List<T> scope) {
sb.append('[');
boolean first = true;
- for(T t : scope) {
- if(first)
+ for (T t : scope) {
+ if (first)
first = false;
else
sb.append(',');
sb.append(t);
}
sb.append(']');
- }
-
+ }
+
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/TokenMap.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/TokenMap.java
index 4173c165f29..49939895471 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/TokenMap.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/TokenMap.java
@@ -15,11 +15,10 @@ package org.eclipse.cdt.core.dom.lrparser.action;
import java.util.HashMap;
-
/**
* Maps token kinds from a sub-parser back to the corresponding
* token kinds in a base parser.
- *
+ *
* @author Mike Kucera
*/
public class TokenMap implements ITokenMap {
@@ -27,10 +26,9 @@ public class TokenMap implements ITokenMap {
// LPG token kinds start at 0
// the kind is not part of the base language parser
public static final int INVALID_KIND = -1;
-
- private final int[] kindMap;
-
-
+
+ private final int[] kindMap;
+
/**
* @param toSymbols An array of symbols where the index is the token kind and the
* element data is a string representing the token kind. It is expected
@@ -39,45 +37,43 @@ public class TokenMap implements ITokenMap {
*/
public TokenMap(String[] toSymbols, String[] fromSymbols) {
// If this map is not being used with an extension then it becomes an "identity map".
- if(toSymbols == fromSymbols) {
+ if (toSymbols == fromSymbols) {
kindMap = null;
return;
}
-
+
kindMap = new int[fromSymbols.length];
-
- HashMap<String,Integer> toMap = new HashMap<String,Integer>();
- for(int i = 0, n = toSymbols.length; i < n; i++) {
+
+ HashMap<String, Integer> toMap = new HashMap<String, Integer>();
+ for (int i = 0, n = toSymbols.length; i < n; i++) {
toMap.put(toSymbols[i], i);
}
-
- for(int i = 0, n = fromSymbols.length; i < n; i++) {
+
+ for (int i = 0, n = fromSymbols.length; i < n; i++) {
Integer kind = toMap.get(fromSymbols[i]);
kindMap[i] = kind == null ? INVALID_KIND : kind;
}
}
-
-
+
/**
* Maps a token kind back to the corresponding kind define in the base C99 parser.
*/
@Override
public int mapKind(int kind) {
- if(kindMap == null)
+ if (kindMap == null)
return kind;
- if(kind < 0 || kind >= kindMap.length)
+ if (kind < 0 || kind >= kindMap.length)
return INVALID_KIND;
-
+
return kindMap[kind];
}
-
- @Override
+ @Override
public String toString() {
- StringBuilder sb = new StringBuilder('(') ;
+ StringBuilder sb = new StringBuilder('(');
boolean first = true;
- for(int i = 0, n = kindMap.length; i < n; i++) {
- if(!first)
+ for (int i = 0, n = kindMap.length; i < n; i++) {
+ if (!first)
sb.append(", "); //$NON-NLS-1$
sb.append(i).append('=').append(kindMap[i]);
first = false;
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 80318884002..46034b94d4b 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
@@ -81,61 +81,56 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CASTAmbiguousStatement;
/**
* Semantic actions called by the C99 parser to build an AST.
- *
+ *
* @author Mike Kucera
*/
@SuppressWarnings("restriction")
-public class C99BuildASTParserAction extends BuildASTParserAction {
+public class C99BuildASTParserAction extends BuildASTParserAction {
private final ITokenMap tokenMap;
-
+
/** Used to create the AST node objects */
protected final ICNodeFactory nodeFactory;
-
+
private final ISecondaryParserFactory parserFactory;
-
+
/**
* @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(ITokenStream parser, ScopedStack<Object> astStack, ICNodeFactory nodeFactory, ISecondaryParserFactory parserFactory) {
+ public C99BuildASTParserAction(ITokenStream parser, ScopedStack<Object> astStack, ICNodeFactory nodeFactory,
+ ISecondaryParserFactory parserFactory) {
super(parser, astStack, nodeFactory, parserFactory);
-
+
this.nodeFactory = nodeFactory;
this.parserFactory = parserFactory;
this.tokenMap = new TokenMap(C99Parsersym.orderedTerminalSymbols, parser.getOrderedTerminalSymbols());
}
-
-
-
+
private int baseKind(IToken token) {
return tokenMap.mapKind(token.getKind());
}
-
- @Override
+
+ @Override
protected boolean isCompletionToken(IToken token) {
return baseKind(token) == TK_Completion;
}
-
+
@Override
protected boolean isIdentifierToken(IToken token) {
return baseKind(token) == TK_identifier;
}
-
-
+
@Override
protected IASTName createName(char[] image) {
return nodeFactory.newName(image);
}
-
-
+
/********************************************************************
* Start of semantic actions.
********************************************************************/
-
-
/**
* postfix_expression ::= postfix_expression '.' ident
* postfix_expression ::= postfix_expression '->' ident
@@ -148,10 +143,9 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(expr);
astStack.push(expr);
}
-
-
+
/**
- * postfix_expression ::= '(' type_id ')' initializer_list
+ * postfix_expression ::= '(' type_id ')' initializer_list
*/
public void consumeExpressionTypeIdInitializer() {
IASTInitializerList list = (IASTInitializerList) astStack.pop();
@@ -160,107 +154,145 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(expr);
astStack.push(expr);
}
-
-
+
/**
* Applies a specifier to a decl spec node.
- *
+ *
* In plain C99 specifiers are always just single tokens, but in language
* extensions specifiers may be more complex. Thats why this method takes
* Object as the type of the specifier, so that it may be overridden in subclasses
* and used with arbitrary objects as the specifier.
*/
public void setSpecifier(ICASTDeclSpecifier node, Object specifier) {
- if(!(specifier instanceof IToken))
+ if (!(specifier instanceof IToken))
return;
- IToken token = (IToken)specifier;
-
+ IToken token = (IToken) specifier;
+
int kind = baseKind(token);
- switch(kind){
- case TK_typedef: node.setStorageClass(IASTDeclSpecifier.sc_typedef); return;
- case TK_extern: node.setStorageClass(IASTDeclSpecifier.sc_extern); return;
- case TK_static: node.setStorageClass(IASTDeclSpecifier.sc_static); return;
- case TK_auto: node.setStorageClass(IASTDeclSpecifier.sc_auto); return;
- case TK_register: node.setStorageClass(IASTDeclSpecifier.sc_register); return;
- case TK_inline: node.setInline(true); return;
- case TK_const: node.setConst(true); return;
- case TK_restrict: node.setRestrict(true); return;
- case TK_volatile: node.setVolatile(true); return;
+ switch (kind) {
+ case TK_typedef:
+ node.setStorageClass(IASTDeclSpecifier.sc_typedef);
+ return;
+ case TK_extern:
+ node.setStorageClass(IASTDeclSpecifier.sc_extern);
+ return;
+ case TK_static:
+ node.setStorageClass(IASTDeclSpecifier.sc_static);
+ return;
+ case TK_auto:
+ node.setStorageClass(IASTDeclSpecifier.sc_auto);
+ return;
+ case TK_register:
+ node.setStorageClass(IASTDeclSpecifier.sc_register);
+ return;
+ case TK_inline:
+ node.setInline(true);
+ return;
+ case TK_const:
+ node.setConst(true);
+ return;
+ case TK_restrict:
+ node.setRestrict(true);
+ return;
+ case TK_volatile:
+ node.setVolatile(true);
+ return;
}
-
- if(node instanceof ICASTSimpleDeclSpecifier) {
+
+ if (node instanceof ICASTSimpleDeclSpecifier) {
ICASTSimpleDeclSpecifier n = (ICASTSimpleDeclSpecifier) node;
- switch(kind) {
- case TK_void: n.setType(IASTSimpleDeclSpecifier.t_void); break;
- case TK_char: n.setType(IASTSimpleDeclSpecifier.t_char); break;
- case TK__Bool: n.setType(ICASTSimpleDeclSpecifier.t_Bool); break;
- case TK_int: n.setType(IASTSimpleDeclSpecifier.t_int); break;
- case TK_float: n.setType(IASTSimpleDeclSpecifier.t_float); break;
- case TK_double: n.setType(IASTSimpleDeclSpecifier.t_double); break;
- case TK_signed: n.setSigned(true); break;
- case TK_unsigned: n.setUnsigned(true); break;
- case TK_short: n.setShort(true); break;
- case TK__Complex: n.setComplex(true); break;
- case TK_long:
- boolean isLong = n.isLong();
- n.setLongLong(isLong);
- n.setLong(!isLong);
- break;
+ switch (kind) {
+ case TK_void:
+ n.setType(IASTSimpleDeclSpecifier.t_void);
+ break;
+ case TK_char:
+ n.setType(IASTSimpleDeclSpecifier.t_char);
+ break;
+ case TK__Bool:
+ n.setType(ICASTSimpleDeclSpecifier.t_Bool);
+ break;
+ case TK_int:
+ n.setType(IASTSimpleDeclSpecifier.t_int);
+ break;
+ case TK_float:
+ n.setType(IASTSimpleDeclSpecifier.t_float);
+ break;
+ case TK_double:
+ n.setType(IASTSimpleDeclSpecifier.t_double);
+ break;
+ case TK_signed:
+ n.setSigned(true);
+ break;
+ case TK_unsigned:
+ n.setUnsigned(true);
+ break;
+ case TK_short:
+ n.setShort(true);
+ break;
+ case TK__Complex:
+ n.setComplex(true);
+ break;
+ case TK_long:
+ boolean isLong = n.isLong();
+ n.setLongLong(isLong);
+ n.setLong(!isLong);
+ break;
}
}
}
-
-
-
+
/**
* type_qualifier ::= const | restrict | volatile
*/
private void collectArrayModifierTypeQualifiers(ICASTArrayModifier arrayModifier) {
- for(Object o : astStack.closeScope()) {
- switch(baseKind((IToken)o)) {
- case TK_const: arrayModifier.setConst(true); break;
- case TK_restrict: arrayModifier.setRestrict(true); break;
- case TK_volatile: arrayModifier.setVolatile(true); break;
+ for (Object o : astStack.closeScope()) {
+ switch (baseKind((IToken) o)) {
+ case TK_const:
+ arrayModifier.setConst(true);
+ break;
+ case TK_restrict:
+ arrayModifier.setRestrict(true);
+ break;
+ case TK_volatile:
+ arrayModifier.setVolatile(true);
+ break;
}
}
}
-
-
+
/**
- * array_modifier
- * ::= '[' <openscope> type_qualifier_list ']'
- * | '[' <openscope> type_qualifier_list assignment_expression ']'
- * | '[' 'static' assignment_expression ']'
- * | '[' 'static' <openscope> type_qualifier_list assignment_expression ']'
- * | '[' <openscope> type_qualifier_list 'static' assignment_expression ']'
- * | '[' '*' ']'
- * | '[' <openscope> type_qualifier_list '*' ']'
- *
- * The main reason to separate array_modifier into its own rule is to
- * make calculating the offset and length much easier.
+ * array_modifier
+ * ::= '[' <openscope> type_qualifier_list ']'
+ * | '[' <openscope> type_qualifier_list assignment_expression ']'
+ * | '[' 'static' assignment_expression ']'
+ * | '[' 'static' <openscope> type_qualifier_list assignment_expression ']'
+ * | '[' <openscope> type_qualifier_list 'static' assignment_expression ']'
+ * | '[' '*' ']'
+ * | '[' <openscope> type_qualifier_list '*' ']'
+ *
+ * The main reason to separate array_modifier into its own rule is to
+ * make calculating the offset and length much easier.
*/
- public void consumeDirectDeclaratorModifiedArrayModifier(boolean isStatic,
- boolean isVarSized, boolean hasTypeQualifierList, boolean hasAssignmentExpr) {
+ public void consumeDirectDeclaratorModifiedArrayModifier(boolean isStatic, boolean isVarSized,
+ boolean hasTypeQualifierList, boolean hasAssignmentExpr) {
assert isStatic || isVarSized || hasTypeQualifierList;
-
+
ICASTArrayModifier arrayModifier = nodeFactory.newArrayModifier(null);
-
+
// consume all the stuff between the square brackets into an array modifier
arrayModifier.setStatic(isStatic);
arrayModifier.setVariableSized(isVarSized);
-
- if(hasAssignmentExpr)
- arrayModifier.setConstantExpression((IASTExpression)astStack.pop());
-
- if(hasTypeQualifierList)
+
+ if (hasAssignmentExpr)
+ arrayModifier.setConstantExpression((IASTExpression) astStack.pop());
+
+ if (hasTypeQualifierList)
collectArrayModifierTypeQualifiers(arrayModifier);
setOffsetAndLength(arrayModifier);
astStack.push(arrayModifier);
}
-
-
/**
* direct_declarator ::= direct_declarator '(' <openscope> identifier_list ')'
*/
@@ -272,101 +304,97 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
int endOffset = endOffset(stream.getRightIToken());
addFunctionModifier(declarator, endOffset);
}
-
-
+
/**
* identifier_list
- * ::= 'identifier'
- * | identifier_list ',' 'identifier'
+ * ::= 'identifier'
+ * | identifier_list ',' 'identifier'
*/
public void consumeIdentifierKnR() {
IASTName name = createName(stream.getRightIToken());
astStack.push(name);
}
-
-
-
/**
* pointer ::= '*'
- * | pointer '*'
- */
+ * | pointer '*'
+ */
public void consumePointer() {
IASTPointer pointer = nodeFactory.newPointer();
IToken star = stream.getRightIToken();
ParserUtil.setOffsetAndLength(pointer, star);
astStack.push(pointer);
}
-
-
+
/**
* pointer ::= '*' <openscope> type_qualifier_list
- * | pointer '*' <openscope> type_qualifier_list
+ * | pointer '*' <openscope> type_qualifier_list
*/
public void consumePointerTypeQualifierList() {
ICASTPointer pointer = nodeFactory.newPointer();
- for(Object o : astStack.closeScope()) {
- IToken token = (IToken)o;
- switch(baseKind(token)) {
- default: assert false;
- case TK_const: pointer.setConst(true); break;
- case TK_volatile: pointer.setVolatile(true); break;
- case TK_restrict: pointer.setRestrict(true); break;
+ for (Object o : astStack.closeScope()) {
+ IToken token = (IToken) o;
+ switch (baseKind(token)) {
+ default:
+ assert false;
+ case TK_const:
+ pointer.setConst(true);
+ break;
+ case TK_volatile:
+ pointer.setVolatile(true);
+ break;
+ case TK_restrict:
+ pointer.setRestrict(true);
+ break;
}
}
setOffsetAndLength(pointer);
astStack.push(pointer);
}
-
-
-
+
/**
- * direct_abstract_declarator
+ * direct_abstract_declarator
* ::= '(' ')'
- * | direct_abstract_declarator '(' ')'
- * | '(' <openscope> parameter_type_list ')'
- * | direct_abstract_declarator '(' <openscope> parameter_type_list ')'
+ * | direct_abstract_declarator '(' ')'
+ * | '(' <openscope> parameter_type_list ')'
+ * | direct_abstract_declarator '(' <openscope> parameter_type_list ')'
*/
public void consumeDirectDeclaratorFunctionDeclarator(boolean hasDeclarator, boolean hasParameters) {
IASTName name = nodeFactory.newName();
IASTStandardFunctionDeclarator declarator = nodeFactory.newFunctionDeclarator(name);
-
- if(hasParameters) {
+
+ if (hasParameters) {
boolean isVarArgs = astStack.pop() == PLACE_HOLDER;
declarator.setVarArgs(isVarArgs);
-
- for(Object param : astStack.closeScope())
- declarator.addParameterDeclaration((IASTParameterDeclaration)param);
+
+ for (Object param : astStack.closeScope())
+ declarator.addParameterDeclaration((IASTParameterDeclaration) param);
}
-
- if(hasDeclarator) {
+
+ if (hasDeclarator) {
addFunctionModifier(declarator, endOffset(stream.getRightIToken()));
- }
- else {
+ } else {
setOffsetAndLength(declarator);
astStack.push(declarator);
}
}
-
-
/**
* designated_initializer ::= <openscope> designation initializer
*/
public void consumeInitializerDesignated() {
- IASTInitializer initializer = (IASTInitializer)astStack.pop();
+ IASTInitializer initializer = (IASTInitializer) astStack.pop();
ICASTDesignatedInitializer result = nodeFactory.newDesignatedInitializer(initializer);
-
- for(Object o : astStack.closeScope())
- result.addDesignator((ICASTDesignator)o);
-
+
+ for (Object o : astStack.closeScope())
+ result.addDesignator((ICASTDesignator) o);
+
setOffsetAndLength(result);
astStack.push(result);
}
-
-
+
/**
* designator ::= '[' constant_expression ']'
*/
@@ -376,8 +404,7 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(designator);
astStack.push(designator);
}
-
-
+
/**
* designator ::= '.' 'identifier'
*/
@@ -387,22 +414,20 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(designator);
astStack.push(designator);
}
-
-
+
/**
* declaration_specifiers ::= <openscope> simple_declaration_specifiers
*/
public void consumeDeclarationSpecifiersSimple() {
ICASTSimpleDeclSpecifier declSpec = nodeFactory.newSimpleDeclSpecifier();
-
- for(Object specifier : astStack.closeScope())
+
+ for (Object specifier : astStack.closeScope())
setSpecifier(declSpec, specifier);
-
+
setOffsetAndLength(declSpec);
astStack.push(declSpec);
}
-
-
+
/**
* declaration_specifiers ::= <openscope> struct_or_union_declaration_specifiers
* declaration_specifiers ::= <openscope> enum_declaration_specifiers
@@ -410,32 +435,30 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
public void consumeDeclarationSpecifiersStructUnionEnum() {
List<Object> topScope = astStack.closeScope();
ICASTDeclSpecifier declSpec = CollectionUtils.findFirstAndRemove(topScope, ICASTDeclSpecifier.class);
-
+
// now apply the rest of the specifiers
- for(Object specifier : topScope)
+ for (Object specifier : topScope)
setSpecifier(declSpec, specifier);
-
+
setOffsetAndLength(declSpec);
astStack.push(declSpec);
}
-
-
+
/**
* declaration_specifiers ::= <openscope> typdef_name_declaration_specifiers
*/
public void consumeDeclarationSpecifiersTypedefName() {
ICASTTypedefNameSpecifier declSpec = nodeFactory.newTypedefNameSpecifier(null);
-
- for(Object o : astStack.topScope()) {
- if(o instanceof IToken) {
+
+ for (Object o : astStack.topScope()) {
+ if (o instanceof IToken) {
IToken token = (IToken) o;
// There is one identifier token on the stack
int kind = baseKind(token);
- if(kind == TK_identifier || kind == TK_Completion) {
+ if (kind == TK_identifier || kind == TK_Completion) {
IASTName name = createName(token);
declSpec.setName(name);
- }
- else {
+ } else {
setSpecifier(declSpec, token);
}
}
@@ -445,9 +468,7 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(declSpec);
astStack.push(declSpec);
}
-
-
-
+
/**
* declaration ::= declaration_specifiers <openscope> init_declarator_list ';'
* declaration ::= declaration_specifiers ';'
@@ -455,89 +476,86 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
public void consumeDeclarationSimple(boolean hasDeclaratorList) {
List<Object> declarators = (hasDeclaratorList) ? astStack.closeScope() : Collections.emptyList();
IASTDeclSpecifier declSpecifier = (IASTDeclSpecifier) astStack.pop();
-
+
List<IToken> ruleTokens = stream.getRuleTokens();
- if(ruleTokens.size() == 1 && baseKind(ruleTokens.get(0)) == TK_EndOfCompletion)
+ if (ruleTokens.size() == 1 && baseKind(ruleTokens.get(0)) == TK_EndOfCompletion)
return; // do not generate nodes for extra EOC tokens
-
+
IASTSimpleDeclaration declaration = nodeFactory.newSimpleDeclaration(declSpecifier);
-
- for(Object declarator : declarators)
- declaration.addDeclarator((IASTDeclarator)declarator);
+
+ for (Object declarator : declarators)
+ declaration.addDeclarator((IASTDeclarator) declarator);
setOffsetAndLength(declaration);
astStack.push(declaration);
}
-
-
-
+
/**
* external_declaration ::= ';'
- *
+ *
* TODO: doesn't the declaration need a name?
*/
public void consumeDeclarationEmpty() {
// Don't generate declaration nodes for extra EOC tokens
- if(baseKind(stream.getLeftIToken()) == C99Parsersym.TK_EndOfCompletion)
+ if (baseKind(stream.getLeftIToken()) == C99Parsersym.TK_EndOfCompletion)
return;
-
- IASTDeclSpecifier declSpecifier = nodeFactory.newSimpleDeclSpecifier();
+
+ IASTDeclSpecifier declSpecifier = nodeFactory.newSimpleDeclSpecifier();
IASTSimpleDeclaration declaration = nodeFactory.newSimpleDeclaration(declSpecifier);
setOffsetAndLength(declSpecifier);
setOffsetAndLength(declaration);
astStack.push(declaration);
}
-
-
+
/**
* a declaration inside of a struct
- *
+ *
* struct_declaration ::= specifier_qualifier_list <openscope> struct_declarator_list ';'
- *
+ *
* specifier_qualifier_list is a subset of declaration_specifiers,
* struct_declarators are declarators that are allowed inside a struct,
* a struct declarator is a regular declarator plus bit fields
*/
public void consumeStructDeclaration(boolean hasDeclaration) {
consumeDeclarationSimple(hasDeclaration); // TODO this is ok as long as bit fields implement IASTDeclarator (see consumeDeclaration())
- }
-
-
+ }
+
/**
* struct_or_union_specifier
- * ::= 'struct' '{' <openscope> struct_declaration_list_opt '}'
- * | 'union' '{' <openscope> struct_declaration_list_opt '}'
- * | 'struct' struct_or_union_identifier '{' <openscope> struct_declaration_list_opt '}'
- * | 'union' struct_or_union_identifier '{' <openscope> struct_declaration_list_opt '}'
- *
+ * ::= 'struct' '{' <openscope> struct_declaration_list_opt '}'
+ * | 'union' '{' <openscope> struct_declaration_list_opt '}'
+ * | 'struct' struct_or_union_identifier '{' <openscope> struct_declaration_list_opt '}'
+ * | 'union' struct_or_union_identifier '{' <openscope> struct_declaration_list_opt '}'
+ *
* @param key either k_struct or k_union from IASTCompositeTypeSpecifier
*/
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;
+ switch (baseKind(stream.getLeftIToken())) {
+ case TK_struct:
+ key = IASTCompositeTypeSpecifier.k_struct;
+ case TK_union:
+ key = IASTCompositeTypeSpecifier.k_union;
}
-
+
IASTName name = (hasName) ? createName(stream.getRuleTokens().get(1)) : nodeFactory.newName();
-
+
ICASTCompositeTypeSpecifier typeSpec = nodeFactory.newCompositeTypeSpecifier(key, name);
-
- for(Object o : astStack.closeScope())
- typeSpec.addMemberDeclaration((IASTDeclaration)o);
-
+
+ for (Object o : astStack.closeScope())
+ typeSpec.addMemberDeclaration((IASTDeclaration) o);
+
setOffsetAndLength(typeSpec);
astStack.push(typeSpec);
}
-
-
+
/**
* struct_or_union_specifier
- * ::= 'struct' struct_or_union_identifier
- * | 'union' struct_or_union_identifier
- *
- * enum_specifier ::= 'enum' enum_identifier
+ * ::= 'struct' struct_or_union_identifier
+ * | 'union' struct_or_union_identifier
+ *
+ * enum_specifier ::= 'enum' enum_identifier
*/
public void consumeTypeSpecifierElaborated(int kind) {
IASTName name = createName(stream.getRuleTokens().get(1));
@@ -545,23 +563,18 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(typeSpec);
astStack.push(typeSpec);
}
-
-
-
-
+
/**
* iteration_statement ::= 'while' '(' expression ')' statement
*/
public void consumeStatementWhileLoop() {
- IASTStatement body = (IASTStatement) astStack.pop();
+ IASTStatement body = (IASTStatement) astStack.pop();
IASTExpression condition = (IASTExpression) astStack.pop();
IASTWhileStatement whileStatement = nodeFactory.newWhileStatement(condition, body);
setOffsetAndLength(whileStatement);
astStack.push(whileStatement);
}
-
-
-
+
/**
* iteration_statement_matched
* ::= 'for' '(' expression_opt ';' expression_opt ';' expression_opt ')' statement
@@ -572,74 +585,71 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
IASTExpression expr3 = (IASTExpression) astStack.pop();
IASTExpression expr2 = (IASTExpression) astStack.pop();
IASTNode node = (IASTNode) astStack.pop(); // may be an expression or a declaration
-
+
IASTStatement initializer;
- if(node instanceof IASTExpression)
- initializer = nodeFactory.newExpressionStatement((IASTExpression)node);
- else if(node instanceof IASTDeclaration)
- initializer = nodeFactory.newDeclarationStatement((IASTDeclaration)node);
+ if (node instanceof IASTExpression)
+ initializer = nodeFactory.newExpressionStatement((IASTExpression) node);
+ else if (node instanceof IASTDeclaration)
+ initializer = nodeFactory.newDeclarationStatement((IASTDeclaration) node);
else // its null
initializer = nodeFactory.newNullStatement();
-
-
+
// 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 = stream.getRuleTokens();
- if(matchTokens(tokens, tokenMap,
- TK_for, TK_LeftParen, TK_Completion, TK_EOC, TK_EOC, TK_EOC, TK_EOC)) {
+ 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);
ParserUtil.setOffsetAndLength(idExpression, offset(name), length(name));
initializer = nodeFactory.newExpressionStatement(idExpression);
ParserUtil.setOffsetAndLength(initializer, offset(name), length(name));
}
-
+
//initializer could be an expression or a declaration
int TK_SC = TK_SemiColon;
IASTExpressionStatement expressionStatement = null;
- if(initializer instanceof IASTDeclarationStatement) {
+ if (initializer instanceof IASTDeclarationStatement) {
IASTDeclarationStatement declarationStatement = (IASTDeclarationStatement) initializer;
List<IToken> expressionTokens = stream.getRuleTokens();
-
+
//find the first semicolon
int end_pos = -1;
- for(int i = 0, n = expressionTokens.size(); i < n; i++) {
- if(tokenMap.mapKind(expressionTokens.get(i).getKind()) == TK_SC) {
+ for (int i = 0, n = expressionTokens.size(); i < n; i++) {
+ if (tokenMap.mapKind(expressionTokens.get(i).getKind()) == TK_SC) {
end_pos = i;
break;
}
}
-
- if (end_pos != -1) {
+
+ if (end_pos != -1) {
expressionTokens = expressionTokens.subList(2, end_pos);
-
- ISecondaryParser<IASTExpression> expressionParser = parserFactory.getExpressionParser(stream, properties);
+
+ ISecondaryParser<IASTExpression> expressionParser = parserFactory.getExpressionParser(stream,
+ properties);
IASTExpression expr1 = runSecondaryParser(expressionParser, expressionTokens);
-
- if(expr1 != null) { // the parse may fail
+
+ if (expr1 != null) { // the parse may fail
expressionStatement = nodeFactory.newExpressionStatement(expr1);
setOffsetAndLength(expressionStatement);
}
}
-
- if(expressionStatement == null)
+
+ if (expressionStatement == null)
initializer = declarationStatement;
else {
initializer = createAmbiguousStatement(expressionStatement, declarationStatement);
setOffsetAndLength(initializer);
}
}
-
- if(node != null)
+
+ if (node != null)
ParserUtil.setOffsetAndLength(initializer, offset(node), length(node));
-
+
IASTForStatement forStat = nodeFactory.newForStatement(initializer, expr2, expr3, body);
setOffsetAndLength(forStat);
astStack.push(forStat);
}
-
-
-
+
/**
* selection_statement ::= switch '(' expression ')' statement
*/
@@ -650,85 +660,77 @@ public class C99BuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(stat);
astStack.push(stat);
}
-
public void consumeStatementIf(boolean hasElse) {
IASTStatement elseClause = null;
- if(hasElse)
+ if (hasElse)
elseClause = (IASTStatement) astStack.pop();
-
+
IASTStatement thenClause = (IASTStatement) astStack.pop();
IASTExpression condition = (IASTExpression) astStack.pop();
-
+
IASTIfStatement ifStatement = nodeFactory.newIfStatement(condition, thenClause, elseClause);
setOffsetAndLength(ifStatement);
astStack.push(ifStatement);
}
-
-
+
/**
* function_definition
- * ::= declaration_specifiers <openscope> declarator compound_statement
- * | function_declarator compound_statement
- *
- * The seemingly pointless <openscope> is just there to
- * prevent a shift/reduce conflict in the grammar.
- */
+ * ::= declaration_specifiers <openscope> declarator compound_statement
+ * | function_declarator compound_statement
+ *
+ * The seemingly pointless <openscope> is just there to
+ * prevent a shift/reduce conflict in the grammar.
+ */
public void consumeFunctionDefinition(boolean hasDeclSpecifiers) {
- IASTCompoundStatement body = (IASTCompoundStatement) astStack.pop();
+ IASTCompoundStatement body = (IASTCompoundStatement) astStack.pop();
IASTFunctionDeclarator decl = (IASTFunctionDeclarator) astStack.pop();
astStack.closeScope();
-
+
IASTDeclSpecifier declSpecifier;
- if(hasDeclSpecifiers) {
+ if (hasDeclSpecifiers) {
declSpecifier = (IASTDeclSpecifier) astStack.pop();
- }
- else { // there are no decl specifiers, implicit int
+ } else { // there are no decl specifiers, implicit int
declSpecifier = nodeFactory.newSimpleDeclSpecifier();
}
-
+
IASTFunctionDefinition def = nodeFactory.newFunctionDefinition(declSpecifier, decl, body);
setOffsetAndLength(def);
astStack.push(def);
}
-
-
-
- /**
- * function_definition
- * ::= declaration_specifiers <openscope-ast> knr_function_declarator
- * <openscope-ast> declaration_list compound_statement
- */
+
+ /**
+ * function_definition
+ * ::= declaration_specifiers <openscope-ast> knr_function_declarator
+ * <openscope-ast> declaration_list compound_statement
+ */
public void consumeFunctionDefinitionKnR() {
- IASTCompoundStatement body = (IASTCompoundStatement) astStack.pop();
-
- IASTDeclaration[] declarations = astStack.topScope().toArray(new IASTDeclaration[0]);
- astStack.closeScope();
-
- ICASTKnRFunctionDeclarator decl = (ICASTKnRFunctionDeclarator) astStack.pop();
- astStack.closeScope();
-
- ICASTDeclSpecifier declSpecifier = (ICASTDeclSpecifier) astStack.pop();
- decl.setParameterDeclarations(declarations);
-
+ IASTCompoundStatement body = (IASTCompoundStatement) astStack.pop();
+
+ IASTDeclaration[] declarations = astStack.topScope().toArray(new IASTDeclaration[0]);
+ astStack.closeScope();
+
+ ICASTKnRFunctionDeclarator decl = (ICASTKnRFunctionDeclarator) astStack.pop();
+ astStack.closeScope();
+
+ ICASTDeclSpecifier declSpecifier = (ICASTDeclSpecifier) astStack.pop();
+ decl.setParameterDeclarations(declarations);
+
// re-compute the length of the declaration to take the parameter declarations into account
- ASTNode lastDeclaration = (ASTNode) declarations[declarations.length-1];
+ ASTNode lastDeclaration = (ASTNode) declarations[declarations.length - 1];
int endOffset = lastDeclaration.getOffset() + lastDeclaration.getLength();
- ((ASTNode)decl).setLength(endOffset - offset(decl));
-
+ ((ASTNode) decl).setLength(endOffset - offset(decl));
+
IASTFunctionDefinition def = nodeFactory.newFunctionDefinition(declSpecifier, decl, body);
setOffsetAndLength(def);
- astStack.push(def);
- }
-
-
+ astStack.push(def);
+ }
@Override
protected IASTAmbiguousExpression createAmbiguousExpression(IASTExpression... expressions) {
return new CASTAmbiguousExpression(expressions);
}
-
@Override
protected IASTAmbiguousStatement createAmbiguousStatement(IASTStatement... statements) {
return new CASTAmbiguousStatement(statements);
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
index d81b2807088..cd2c43b13b9 100644
--- 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
@@ -26,24 +26,25 @@ 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;
}
-
-
+
@Override
- public ISecondaryParser<IASTExpression> getExpressionParser(ITokenStream stream, Map<String,String> properties) {
- return new C99ExpressionParser(stream, properties);
+ public ISecondaryParser<IASTExpression> getExpressionParser(ITokenStream stream, Map<String, String> properties) {
+ return new C99ExpressionParser(stream, properties);
}
@Override
- public ISecondaryParser<IASTExpression> getNoCastExpressionParser(ITokenStream stream, Map<String,String> properties) {
+ public ISecondaryParser<IASTExpression> getNoCastExpressionParser(ITokenStream stream,
+ Map<String, String> properties) {
return new C99NoCastExpressionParser(stream, properties);
}
-
+
@Override
- public ISecondaryParser<IASTExpression> getSizeofExpressionParser(ITokenStream stream, Map<String,String> 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/cpp/CPPBuildASTParserAction.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java
index c25d87050e6..6b5f482d5dc 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
@@ -119,10 +119,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorInitializer
import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
/**
- * Semantic actions that build the AST during the parse.
+ * Semantic actions that build the AST during the parse.
* These are the actions that are specific to the C++ parser, the superclass
* contains actions that can be shared with the C99 parser.
- *
+ *
* @author Mike Kucera
*/
@SuppressWarnings("restriction")
@@ -130,54 +130,51 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
/** Allows code in this class to refer to the token kinds in CPPParsersym */
private final ITokenMap tokenMap;
-
+
/** Used to create the AST node objects */
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(ITokenStream parser, ScopedStack<Object> astStack, ICPPNodeFactory nodeFactory, ICPPSecondaryParserFactory parserFactory) {
+ 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());
}
-
-
+
private int baseKind(IToken token) {
return tokenMap.mapKind(token.getKind());
}
-
- @Override
+
+ @Override
protected boolean isCompletionToken(IToken token) {
return baseKind(token) == TK_Completion;
}
-
+
@Override
protected boolean isIdentifierToken(IToken token) {
return baseKind(token) == TK_identifier;
}
-
+
@Override
protected IASTName createName(char[] image) {
return nodeFactory.newName(image);
}
-
-
public void consumeNewInitializer() {
IASTExpression expr;
- if(astStack.peek() == null) { // if there is an empty set of parens
+ if (astStack.peek() == null) { // if there is an empty set of parens
astStack.pop();
expr = nodeFactory.newExpressionList();
setOffsetAndLength(expr);
@@ -188,14 +185,12 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
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
+ * ::= 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
*/
public void consumeExpressionNew(boolean isNewTypeId) {
ICPPASTConstructorInitializer initializer = (ICPPASTConstructorInitializer) astStack.pop(); // may be null
@@ -203,67 +198,64 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
IASTTypeId typeId = (IASTTypeId) astStack.pop();
IASTExpression placement = (IASTExpression) astStack.pop(); // may be null
boolean hasDoubleColon = astStack.pop() != null;
-
- ICPPASTNewExpression newExpression = nodeFactory.newNewExpression(new IASTExpression[] {placement}, initializer, typeId);
+
+ ICPPASTNewExpression newExpression = nodeFactory.newNewExpression(new IASTExpression[] { placement },
+ initializer, typeId);
newExpression.setIsGlobal(hasDoubleColon);
newExpression.setIsNewTypeId(isNewTypeId);
setOffsetAndLength(newExpression);
-
- for(Object expr : arrayExpressions)
- newExpression.addNewTypeIdArrayExpression((IASTExpression)expr);
-
+
+ for (Object expr : arrayExpressions)
+ newExpression.addNewTypeIdArrayExpression((IASTExpression) expr);
+
// 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();
-
+ 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 {
+ } else {
astStack.push(newExpression);
}
}
-
-
+
/**
* new_declarator -- pointer operators are part of the type id, held in an empty declarator
- * ::= <openscope-ast> new_pointer_operators
+ * ::= <openscope-ast> new_pointer_operators
*/
public void consumeNewDeclarator() {
IASTName name = nodeFactory.newName();
IASTDeclarator declarator = nodeFactory.newDeclarator(name);
-
- for(Object pointer : astStack.closeScope())
- declarator.addPointerOperator((IASTPointerOperator)pointer);
-
+
+ for (Object pointer : astStack.closeScope())
+ declarator.addPointerOperator((IASTPointerOperator) pointer);
+
setOffsetAndLength(declarator);
astStack.push(declarator);
}
-
-
+
/**
* throw_expression
- * ::= 'throw'
- * | 'throw' assignment_expression
+ * ::= 'throw'
+ * | 'throw' assignment_expression
*/
public void consumeExpressionThrow(boolean hasExpr) {
IASTExpression operand = hasExpr ? (IASTExpression) astStack.pop() : null;
@@ -271,29 +263,27 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(expr);
astStack.push(expr);
}
-
-
+
/**
* delete_expression
- * ::= dcolon_opt 'delete' cast_expression
- * | dcolon_opt 'delete' '[' ']' cast_expression
+ * ::= dcolon_opt 'delete' cast_expression
+ * | dcolon_opt 'delete' '[' ']' cast_expression
* @param isVectorized
*/
public void consumeExpressionDelete(boolean isVectorized) {
IASTExpression operand = (IASTExpression) astStack.pop();
boolean hasDoubleColon = astStack.pop() != null;
-
+
ICPPASTDeleteExpression deleteExpr = nodeFactory.newDeleteExpression(operand);
deleteExpr.setIsGlobal(hasDoubleColon);
deleteExpr.setIsVectored(isVectorized);
-
+
setOffsetAndLength(deleteExpr);
astStack.push(deleteExpr);
}
-
-
+
/**
- *
+ *
*/
public void consumeExpressionFieldReference(boolean isPointerDereference, boolean hasTemplateKeyword) {
IASTName name = (IASTName) astStack.pop();
@@ -301,11 +291,11 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
ICPPASTFieldReference expr = nodeFactory.newFieldReference(name, owner);
expr.setIsPointerDereference(isPointerDereference);
expr.setIsTemplate(hasTemplateKeyword);
-
+
setOffsetAndLength(expr);
astStack.push(expr);
}
-
+
/**
* postfix_expression
* ::= simple_type_specifier '(' expression_list_opt ')'
@@ -315,77 +305,108 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
IToken token = (IToken) astStack.pop();
////CDT_70_FIX_FROM_50-#3
//int type = asICPPASTSimpleTypeConstructorExpressionType(token);
- ICPPASTConstructorInitializer init=null;
- if(expression!=null){
+ ICPPASTConstructorInitializer init = null;
+ if (expression != null) {
init = new CPPASTConstructorInitializer();
init.setExpression(expression);
-
- ((ASTNode)init).setOffsetAndLength(((ASTNode)expression).getOffset(),((ASTNode)expression).getLength());
- }
- ICPPASTDeclSpecifier declspec = transformIntoSimpleTypeSpecifier(token);
- ICPPASTSimpleTypeConstructorExpression typeConstructor = nodeFactory.newSimpleTypeConstructorExpression(declspec, init);
-
+
+ ((ASTNode) init).setOffsetAndLength(((ASTNode) expression).getOffset(), ((ASTNode) expression).getLength());
+ }
+ ICPPASTDeclSpecifier declspec = transformIntoSimpleTypeSpecifier(token);
+ ICPPASTSimpleTypeConstructorExpression typeConstructor = nodeFactory
+ .newSimpleTypeConstructorExpression(declspec, init);
+
setOffsetAndLength(typeConstructor);
astStack.push(typeConstructor);
}
-
-
+
private int asICPPASTSimpleTypeConstructorExpressionType(IToken token) {
assert token != null;
-
- switch(baseKind(token)) {
- case TK_char : return ICPPASTSimpleTypeConstructorExpression.t_char;
- case TK_wchar_t : return ICPPASTSimpleTypeConstructorExpression.t_wchar_t;
- case TK_bool : return ICPPASTSimpleTypeConstructorExpression.t_bool;
- case TK_short : return ICPPASTSimpleTypeConstructorExpression.t_short;
- case TK_int : return ICPPASTSimpleTypeConstructorExpression.t_int;
- case TK_long : return ICPPASTSimpleTypeConstructorExpression.t_long;
- case TK_signed : return ICPPASTSimpleTypeConstructorExpression.t_signed;
- case TK_unsigned : return ICPPASTSimpleTypeConstructorExpression.t_unsigned;
- case TK_float : return ICPPASTSimpleTypeConstructorExpression.t_float;
- case TK_double : return ICPPASTSimpleTypeConstructorExpression.t_double;
- case TK_void : return ICPPASTSimpleTypeConstructorExpression.t_void;
-
- default:
- assert false : "type parsed wrong"; //$NON-NLS-1$
- return ICPPASTSimpleTypeConstructorExpression.t_unspecified;
+
+ switch (baseKind(token)) {
+ case TK_char:
+ return ICPPASTSimpleTypeConstructorExpression.t_char;
+ case TK_wchar_t:
+ return ICPPASTSimpleTypeConstructorExpression.t_wchar_t;
+ case TK_bool:
+ return ICPPASTSimpleTypeConstructorExpression.t_bool;
+ case TK_short:
+ return ICPPASTSimpleTypeConstructorExpression.t_short;
+ case TK_int:
+ return ICPPASTSimpleTypeConstructorExpression.t_int;
+ case TK_long:
+ return ICPPASTSimpleTypeConstructorExpression.t_long;
+ case TK_signed:
+ return ICPPASTSimpleTypeConstructorExpression.t_signed;
+ case TK_unsigned:
+ return ICPPASTSimpleTypeConstructorExpression.t_unsigned;
+ case TK_float:
+ return ICPPASTSimpleTypeConstructorExpression.t_float;
+ case TK_double:
+ return ICPPASTSimpleTypeConstructorExpression.t_double;
+ case TK_void:
+ return ICPPASTSimpleTypeConstructorExpression.t_void;
+
+ default:
+ assert false : "type parsed wrong"; //$NON-NLS-1$
+ return ICPPASTSimpleTypeConstructorExpression.t_unspecified;
}
}
-
- private ICPPASTDeclSpecifier transformIntoSimpleTypeSpecifier(IToken token){
- ICPPASTSimpleDeclSpecifier declspec= nodeFactory.newSimpleDeclSpecifier();
- switch(baseKind(token)) {
- case TK_char : declspec.setType(Kind.eChar); break;
- case TK_wchar_t : declspec.setType(Kind.eWChar); break;
- case TK_bool : declspec.setType(Kind.eBoolean);break;
- case TK_short : declspec.setShort(true); break;
- case TK_int : declspec.setType(Kind.eInt); break;
- case TK_long : declspec.setLong(true); break;
- case TK_signed : declspec.setSigned(true); break;
- case TK_unsigned : declspec.setUnsigned(true); break;
- case TK_float : declspec.setType(Kind.eFloat); break;
- case TK_double : declspec.setType(Kind.eDouble); break;
- case TK_void : declspec.setType(Kind.eVoid); break;
-
- default:
- assert false : "type parsed wrong"; //$NON-NLS-1$
- declspec.setType(Kind.eUnspecified);
- break;
+
+ private ICPPASTDeclSpecifier transformIntoSimpleTypeSpecifier(IToken token) {
+ ICPPASTSimpleDeclSpecifier declspec = nodeFactory.newSimpleDeclSpecifier();
+ switch (baseKind(token)) {
+ case TK_char:
+ declspec.setType(Kind.eChar);
+ break;
+ case TK_wchar_t:
+ declspec.setType(Kind.eWChar);
+ break;
+ case TK_bool:
+ declspec.setType(Kind.eBoolean);
+ break;
+ case TK_short:
+ declspec.setShort(true);
+ break;
+ case TK_int:
+ declspec.setType(Kind.eInt);
+ break;
+ case TK_long:
+ declspec.setLong(true);
+ break;
+ case TK_signed:
+ declspec.setSigned(true);
+ break;
+ case TK_unsigned:
+ declspec.setUnsigned(true);
+ break;
+ case TK_float:
+ declspec.setType(Kind.eFloat);
+ break;
+ case TK_double:
+ declspec.setType(Kind.eDouble);
+ break;
+ case TK_void:
+ declspec.setType(Kind.eVoid);
+ break;
+
+ default:
+ assert false : "type parsed wrong"; //$NON-NLS-1$
+ declspec.setType(Kind.eUnspecified);
+ break;
}
((ASTNode) declspec).setOffset(token.getStartOffset());
int ruleLength = token.getEndOffset() - token.getStartOffset();
((ASTNode) declspec).setLength(ruleLength < 0 ? 0 : ruleLength);
-
+
return declspec;
-
-
+
}
-
-
+
/**
* postfix_expression
* ::= 'typename' dcolon_opt nested_name_specifier <empty> identifier_name '(' expression_list_opt ')'
- * | 'typename' dcolon_opt nested_name_specifier template_opt template_id '(' expression_list_opt ')'
+ * | 'typename' dcolon_opt nested_name_specifier template_opt template_id '(' expression_list_opt ')'
*/
@SuppressWarnings("unchecked")
public void consumeExpressionTypeName() {
@@ -396,21 +417,20 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
IToken dColon = (IToken) astStack.pop();
nestedNames.addFirst(name);
-
+
int startOffset = dColon == null ? offset(nestedNames.getLast()) : offset(dColon);
- int endOffset = endOffset(name);
+ int endOffset = endOffset(name);
IASTName qualifiedName = createQualifiedName(nestedNames, startOffset, endOffset, dColon != null);
-
+
ICPPASTTypenameExpression typenameExpr = nodeFactory.newTypenameExpression(qualifiedName, expr, isTemplate);
-
+
setOffsetAndLength(typenameExpr);
astStack.push(typenameExpr);
}
-
-
+
/**
* condition
- * ::= type_specifier_seq declarator '=' assignment_expression
+ * ::= type_specifier_seq declarator '=' assignment_expression
*/
public void consumeConditionDeclaration() {
IASTExpression expr = (IASTExpression) astStack.pop();
@@ -421,41 +441,39 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
IASTEqualsInitializer initializer = nodeFactory.newEqualsInitializer(expr);
ParserUtil.setOffsetAndLength(initializer, offset(expr), length(expr));
declarator.setInitializer(initializer);
-
+
IASTSimpleDeclaration declaration = nodeFactory.newSimpleDeclaration(declSpec);
declaration.addDeclarator(declarator);
-
+
setOffsetAndLength(declaration);
astStack.push(declaration);
}
-
-
+
/**
* template_id
- * ::= identifier_name '<' <openscope-ast> template_argument_list_opt '>'
- *
- * operator_function_id
- * ::= operator_id '<' <openscope-ast> template_argument_list_opt '>'
+ * ::= identifier_name '<' <openscope-ast> template_argument_list_opt '>'
+ *
+ * operator_function_id
+ * ::= operator_id '<' <openscope-ast> template_argument_list_opt '>'
*/
public void consumeTemplateId() {
List<Object> templateArguments = astStack.closeScope();
IASTName name = (IASTName) astStack.pop();
-
+
ICPPASTTemplateId templateId = nodeFactory.newTemplateId(name);
-
- for(Object arg : templateArguments) {
- if(arg instanceof IASTExpression)
- templateId.addTemplateArgument((IASTExpression)arg);
- else if(arg instanceof IASTTypeId)
- templateId.addTemplateArgument((IASTTypeId)arg);
- else if(arg instanceof ICPPASTAmbiguousTemplateArgument)
- templateId.addTemplateArgument((ICPPASTAmbiguousTemplateArgument)arg);
+
+ for (Object arg : templateArguments) {
+ if (arg instanceof IASTExpression)
+ templateId.addTemplateArgument((IASTExpression) arg);
+ else if (arg instanceof IASTTypeId)
+ templateId.addTemplateArgument((IASTTypeId) arg);
+ else if (arg instanceof ICPPASTAmbiguousTemplateArgument)
+ templateId.addTemplateArgument((ICPPASTAmbiguousTemplateArgument) arg);
}
-
+
setOffsetAndLength(templateId);
astStack.push(templateId);
}
-
/**
* Disambiguates template arguments.
@@ -464,22 +482,21 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
// 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.
- if(!(result instanceof IASTIdExpression))
+ if (!(result instanceof IASTIdExpression))
return;
-
+
IASTTypeId typeId = (IASTTypeId) astStack.pop();
IASTIdExpression expr = (IASTIdExpression) result;
-
+
ICPPASTAmbiguousTemplateArgument ambiguityNode = new CPPASTAmbiguousTemplateArgument(typeId, expr);
//setOffsetAndLength(ambiguityNode);
-
+
astStack.push(ambiguityNode);
}
-
-
+
/**
* Disambiguates template arguments.
* Qualified names parse as an expression, so generate the corresponding
@@ -487,190 +504,173 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
*/
public void consumeTemplateArgumentExpression() {
IASTExpression expr = (IASTExpression) astStack.peek();
-
- if(expr instanceof IASTIdExpression) {
- IASTName name = ((IASTIdExpression)expr).getName().copy();
-
+
+ if (expr instanceof IASTIdExpression) {
+ IASTName name = ((IASTIdExpression) expr).getName().copy();
+
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);
}
}
-
-
+
/**
* operator_id
- * ::= 'operator' overloadable_operator
+ * ::= 'operator' overloadable_operator
*/
public void consumeOperatorName() {
List<IToken> tokens = stream.getRuleTokens();
tokens = tokens.subList(1, tokens.size());
OverloadableOperator operator = getOverloadableOperator(tokens);
-
+
ICPPASTOperatorName name = nodeFactory.newOperatorName(operator.toCharArray());
setOffsetAndLength(name);
astStack.push(name);
}
-
private OverloadableOperator getOverloadableOperator(List<IToken> tokens) {
- if(tokens.size() == 1) {
+ if (tokens.size() == 1) {
// TODO this is a hack that I did to save time
LPGTokenAdapter coreToken = (LPGTokenAdapter) tokens.get(0);
return OverloadableOperator.valueOf(coreToken.getWrappedToken());
- }
- else if(matchTokens(tokens, tokenMap, TK_new, TK_LeftBracket, TK_RightBracket)) {
+ } else if (matchTokens(tokens, tokenMap, TK_new, TK_LeftBracket, TK_RightBracket)) {
return OverloadableOperator.NEW_ARRAY;
- }
- else if(matchTokens(tokens, tokenMap, TK_delete, TK_LeftBracket, TK_RightBracket)) {
+ } else if (matchTokens(tokens, tokenMap, TK_delete, TK_LeftBracket, TK_RightBracket)) {
return OverloadableOperator.DELETE_ARRAY;
- }
- else if(matchTokens(tokens, tokenMap, TK_LeftBracket, TK_RightBracket)) {
+ } else if (matchTokens(tokens, tokenMap, TK_LeftBracket, TK_RightBracket)) {
return OverloadableOperator.BRACKET;
- }
- else if(matchTokens(tokens, tokenMap, TK_LeftParen, TK_RightParen)) {
+ } else if (matchTokens(tokens, tokenMap, TK_LeftParen, TK_RightParen)) {
return OverloadableOperator.PAREN;
}
-
+
return null;
}
-
-
+
/**
* conversion_function_id
- * ::= 'operator' conversion_type_id
+ * ::= 'operator' conversion_type_id
*/
public void consumeConversionName() {
-// Representation is computed by the conversion name itself, see bug 258054
-// String rep = createStringRepresentation(parser.getRuleTokens());
-// char[] chars = rep.toCharArray();
-
+ // Representation is computed by the conversion name itself, see bug 258054
+ // String rep = createStringRepresentation(parser.getRuleTokens());
+ // char[] chars = rep.toCharArray();
+
IASTTypeId typeId = (IASTTypeId) astStack.pop();
ICPPASTConversionName name = nodeFactory.newConversionName(typeId);
setOffsetAndLength(name);
astStack.push(name);
}
-
-
-
-
- /**
- * unqualified_id
- * ::= '~' identifier_token
- */
- public void consumeDestructorName() {
- char[] chars = ("~" + stream.getRightIToken()).toCharArray(); //$NON-NLS-1$
-
- IASTName name = nodeFactory.newName(chars);
- setOffsetAndLength(name);
- astStack.push(name);
- }
-
-
- /**
- * destructor_type_name
- * ::= '~' template_id_name
- */
- public void consumeDestructorNameTemplateId() {
- ICPPASTTemplateId templateId = (ICPPASTTemplateId) astStack.peek();
-
- IASTName oldName = templateId.getTemplateName();
- char[] newChars = ("~" + oldName).toCharArray(); //$NON-NLS-1$
-
- IASTName newName = nodeFactory.newName(newChars);
-
- int offset = offset(stream.getLeftIToken());
- int length = offset - endOffset(oldName);
- ParserUtil.setOffsetAndLength(newName, offset, length);
-
- templateId.setTemplateName(newName);
- }
-
-
-
- /**
- * qualified_id
- * ::= '::' identifier_name
- * | '::' operator_function_id
- * | '::' template_id
- */
+
+ /**
+ * unqualified_id
+ * ::= '~' identifier_token
+ */
+ public void consumeDestructorName() {
+ char[] chars = ("~" + stream.getRightIToken()).toCharArray(); //$NON-NLS-1$
+
+ IASTName name = nodeFactory.newName(chars);
+ setOffsetAndLength(name);
+ astStack.push(name);
+ }
+
+ /**
+ * destructor_type_name
+ * ::= '~' template_id_name
+ */
+ public void consumeDestructorNameTemplateId() {
+ ICPPASTTemplateId templateId = (ICPPASTTemplateId) astStack.peek();
+
+ IASTName oldName = templateId.getTemplateName();
+ char[] newChars = ("~" + oldName).toCharArray(); //$NON-NLS-1$
+
+ IASTName newName = nodeFactory.newName(newChars);
+
+ int offset = offset(stream.getLeftIToken());
+ int length = offset - endOffset(oldName);
+ ParserUtil.setOffsetAndLength(newName, offset, length);
+
+ templateId.setTemplateName(newName);
+ }
+
+ /**
+ * qualified_id
+ * ::= '::' identifier_name
+ * | '::' operator_function_id
+ * | '::' template_id
+ */
public void consumeGlobalQualifiedId() {
- IASTName name = (IASTName) astStack.pop();
-
- ICPPASTQualifiedName qualifiedName = nodeFactory.newQualifiedName();
- qualifiedName.addName(name);
- qualifiedName.setFullyQualified(true);
- setOffsetAndLength(qualifiedName);
- astStack.push(qualifiedName);
- }
-
-
- /**
+ IASTName name = (IASTName) astStack.pop();
+
+ ICPPASTQualifiedName qualifiedName = nodeFactory.newQualifiedName();
+ qualifiedName.addName(name);
+ qualifiedName.setFullyQualified(true);
+ setOffsetAndLength(qualifiedName);
+ astStack.push(qualifiedName);
+ }
+
+ /**
* selection_statement ::= switch '(' condition ')' statement
*/
public void consumeStatementSwitch() {
IASTStatement body = (IASTStatement) astStack.pop();
-
+
Object condition = astStack.pop();
-
+
IASTSwitchStatement stat;
- if(condition instanceof IASTExpression)
- stat = nodeFactory.newSwitchStatement((IASTExpression)condition, body);
+ if (condition instanceof IASTExpression)
+ stat = nodeFactory.newSwitchStatement((IASTExpression) condition, body);
else
- stat = nodeFactory.newSwitchStatement((IASTDeclaration)condition, body);
-
+ stat = nodeFactory.newSwitchStatement((IASTDeclaration) condition, body);
+
setOffsetAndLength(stat);
astStack.push(stat);
}
-
public void consumeStatementIf(boolean hasElse) {
- IASTStatement elseClause = hasElse ? (IASTStatement)astStack.pop() : null;
+ IASTStatement elseClause = hasElse ? (IASTStatement) astStack.pop() : null;
IASTStatement thenClause = (IASTStatement) astStack.pop();
-
+
Object condition = astStack.pop();
-
+
IASTIfStatement ifStatement;
- if(condition instanceof IASTExpression)
- ifStatement = nodeFactory.newIfStatement((IASTExpression)condition, thenClause, elseClause);
+ if (condition instanceof IASTExpression)
+ ifStatement = nodeFactory.newIfStatement((IASTExpression) condition, thenClause, elseClause);
else
- ifStatement = nodeFactory.newIfStatement((IASTDeclaration)condition, thenClause, elseClause);
-
+ ifStatement = nodeFactory.newIfStatement((IASTDeclaration) condition, thenClause, elseClause);
+
setOffsetAndLength(ifStatement);
astStack.push(ifStatement);
}
-
-
+
/**
* iteration_statement ::= 'while' '(' condition ')' statement
*/
public void consumeStatementWhileLoop() {
IASTStatement body = (IASTStatement) astStack.pop();
-
+
Object condition = astStack.pop();
-
+
IASTWhileStatement whileStatement;
- if(condition instanceof IASTExpression)
- whileStatement = nodeFactory.newWhileStatement((IASTExpression)condition, body);
+ if (condition instanceof IASTExpression)
+ whileStatement = nodeFactory.newWhileStatement((IASTExpression) condition, body);
else
- whileStatement = nodeFactory.newWhileStatement((IASTDeclaration)condition, body);
-
+ whileStatement = nodeFactory.newWhileStatement((IASTDeclaration) condition, body);
+
setOffsetAndLength(whileStatement);
astStack.push(whileStatement);
}
-
-
+
/**
*/
public void consumeStatementForLoop() {
@@ -678,505 +678,522 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
IASTExpression expr = (IASTExpression) astStack.pop();
Object condition = astStack.pop(); // can be an expression or a declaration
IASTStatement initializer = (IASTStatement) astStack.pop();
-
+
// 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 = stream.getRuleTokens();
- if(matchTokens(tokens, tokenMap,
- TK_for, TK_LeftParen, TK_Completion, TK_EOC, TK_EOC, TK_EOC, TK_EOC)) {
+ 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);
ParserUtil.setOffsetAndLength(idExpression, offset(name), length(name));
initializer = nodeFactory.newExpressionStatement(idExpression);
ParserUtil.setOffsetAndLength(initializer, offset(name), length(name));
}
-
+
int TK_SC = TK_SemiColon;
IASTExpressionStatement expressionStatement = null;
- if(initializer instanceof IASTDeclarationStatement) {
+ if (initializer instanceof IASTDeclarationStatement) {
IASTDeclarationStatement declarationStatement = (IASTDeclarationStatement) initializer;
List<IToken> expressionTokens = stream.getRuleTokens();
-
+
//find the first semicolon
int end_pos = -1;
- for(int i = 0, n = expressionTokens.size(); i < n; i++) {
- if(tokenMap.mapKind(expressionTokens.get(i).getKind()) == TK_SC) {
+ for (int i = 0, n = expressionTokens.size(); i < n; i++) {
+ if (tokenMap.mapKind(expressionTokens.get(i).getKind()) == TK_SC) {
end_pos = i;
break;
}
- }
-
- if (end_pos != -1) {
+ }
+
+ if (end_pos != -1) {
expressionTokens = expressionTokens.subList(2, end_pos);
-
- ISecondaryParser<IASTExpression> expressionParser = parserFactory.getExpressionParser(stream, properties);
+
+ ISecondaryParser<IASTExpression> expressionParser = parserFactory.getExpressionParser(stream,
+ properties);
IASTExpression expr1 = runSecondaryParser(expressionParser, expressionTokens);
-
- if(expr1 != null) { // the parse may fail
+
+ if (expr1 != null) { // the parse may fail
expressionStatement = nodeFactory.newExpressionStatement(expr1);
setOffsetAndLength(expressionStatement);
}
}
-
- if(expressionStatement == null)
+
+ if (expressionStatement == null)
initializer = declarationStatement;
else {
initializer = createAmbiguousStatement(declarationStatement, expressionStatement);
setOffsetAndLength(initializer);
}
- }
-
-
+ }
+
IASTForStatement forStat;
- if(condition instanceof IASTExpression)
- forStat = nodeFactory.newForStatement(initializer, (IASTExpression)condition, expr, body);
+ if (condition instanceof IASTExpression)
+ forStat = nodeFactory.newForStatement(initializer, (IASTExpression) condition, expr, body);
else // its a declaration or its null
- forStat = nodeFactory.newForStatement(initializer, (IASTDeclaration)condition, expr, body);
-
+ forStat = nodeFactory.newForStatement(initializer, (IASTDeclaration) condition, expr, body);
+
setOffsetAndLength(forStat);
astStack.push(forStat);
}
-
-
+
/**
* try_block
- * ::= 'try' compound_statement <openscope-ast> handler_seq
- */
+ * ::= 'try' compound_statement <openscope-ast> handler_seq
+ */
public void consumeStatementTryBlock(boolean hasCatchBlock) {
List<Object> handlerSeq = hasCatchBlock ? astStack.closeScope() : Collections.emptyList();
IASTStatement body = (IASTStatement) astStack.pop();
-
+
ICPPASTTryBlockStatement tryStatement = nodeFactory.newTryBlockStatement(body);
-
- for(Object handler : handlerSeq)
- tryStatement.addCatchHandler((ICPPASTCatchHandler)handler);
-
+
+ for (Object handler : handlerSeq)
+ tryStatement.addCatchHandler((ICPPASTCatchHandler) handler);
+
setOffsetAndLength(tryStatement);
astStack.push(tryStatement);
}
-
-
+
/**
* handler
- * ::= 'catch' '(' exception_declaration ')' compound_statement
- * | 'catch' '(' '...' ')' compound_statement
+ * ::= 'catch' '(' exception_declaration ')' compound_statement
+ * | 'catch' '(' '...' ')' compound_statement
*/
- public void consumeStatementCatchHandler(boolean hasEllipsis) {
- IASTStatement body = (IASTStatement) astStack.pop();
- IASTDeclaration decl = hasEllipsis ? null : (IASTDeclaration) astStack.pop();
-
- ICPPASTCatchHandler catchHandler = nodeFactory.newCatchHandler(decl, body);
- catchHandler.setIsCatchAll(hasEllipsis);
-
- setOffsetAndLength(catchHandler);
- astStack.push(catchHandler);
- }
-
-
+ public void consumeStatementCatchHandler(boolean hasEllipsis) {
+ IASTStatement body = (IASTStatement) astStack.pop();
+ IASTDeclaration decl = hasEllipsis ? null : (IASTDeclaration) astStack.pop();
+
+ ICPPASTCatchHandler catchHandler = nodeFactory.newCatchHandler(decl, body);
+ catchHandler.setIsCatchAll(hasEllipsis);
+
+ setOffsetAndLength(catchHandler);
+ astStack.push(catchHandler);
+ }
+
/**
* nested_name_specifier
- * ::= class_or_namespace_name '::' nested_name_specifier_with_template
- * | class_or_namespace_name '::'
- *
- * nested_name_specifier_with_template
- * ::= class_or_namespace_name_with_template '::' nested_name_specifier_with_template
- * | class_or_namespace_name_with_template '::'
- *
- *
- * Creates and updates a list of the nested names on the stack.
- * Important: the names in the list are in *reverse* order,
- * this is because the actions fire in reverse order.
+ * ::= class_or_namespace_name '::' nested_name_specifier_with_template
+ * | class_or_namespace_name '::'
+ *
+ * nested_name_specifier_with_template
+ * ::= class_or_namespace_name_with_template '::' nested_name_specifier_with_template
+ * | class_or_namespace_name_with_template '::'
+ *
+ *
+ * Creates and updates a list of the nested names on the stack.
+ * Important: the names in the list are in *reverse* order,
+ * this is because the actions fire in reverse order.
*/
@SuppressWarnings("unchecked")
public void consumeNestedNameSpecifier(final boolean hasNested) {
LinkedList<IASTName> names;
- if(hasNested)
+ if (hasNested)
names = (LinkedList<IASTName>) astStack.pop();
else
names = new LinkedList<IASTName>();
-
+
IASTName name = (IASTName) astStack.pop();
names.add(name);
-
+
astStack.push(names);
}
-
public void consumeNestedNameSpecifierEmpty() {
// can't use Collections.EMPTY_LIST because we need a list thats mutable
astStack.push(new LinkedList<IASTName>());
}
-
-
-
-
+
/**
* The template keyword is optional but must be the leftmost token.
- *
+ *
* This just throws away the template keyword.
*/
- public void consumeNameWithTemplateKeyword() {
+ public void consumeNameWithTemplateKeyword() {
IASTName name = (IASTName) astStack.pop();
astStack.pop(); // pop the template keyword
astStack.push(name);
}
-
-
/**
* qualified_id
- * ::= dcolon_opt nested_name_specifier any_name
+ * ::= dcolon_opt nested_name_specifier any_name
*/
public void consumeQualifiedId(boolean hasTemplateKeyword) {
IASTName qualifiedName = subRuleQualifiedName(hasTemplateKeyword);
astStack.push(qualifiedName);
}
-
-
- private IASTName createQualifiedName(LinkedList<IASTName> nestedNames, int startOffset, int endOffset, boolean startsWithColonColon) {
+
+ private IASTName createQualifiedName(LinkedList<IASTName> nestedNames, int startOffset, int endOffset,
+ boolean startsWithColonColon) {
return createQualifiedName(nestedNames, startOffset, endOffset, startsWithColonColon, false);
}
-
-
+
/**
* Creates a qualified name from a list of names (that must be in reverse order).
- *
+ *
* @param names List of name nodes in reverse order
*/
- private IASTName createQualifiedName(LinkedList<IASTName> names, int startOffset, int endOffset, boolean startsWithColonColon, boolean endsWithColonColon) {
- if(!endsWithColonColon && !startsWithColonColon && names.size() == 1)
+ private IASTName createQualifiedName(LinkedList<IASTName> names, int startOffset, int endOffset,
+ boolean startsWithColonColon, boolean endsWithColonColon) {
+ if (!endsWithColonColon && !startsWithColonColon && names.size() == 1)
return names.getFirst(); // its actually an unqualified name
ICPPASTQualifiedName qualifiedName = nodeFactory.newQualifiedName();
qualifiedName.setFullyQualified(startsWithColonColon);
ParserUtil.setOffsetAndLength(qualifiedName, startOffset, endOffset - startOffset);
- for(IASTName name : reverseIterable(names))
+ for (IASTName name : reverseIterable(names))
qualifiedName.addName(name);
-
+
// there must be a dummy name in the AST after the last double colon, this happens with pointer to member names
- if(endsWithColonColon) {
+ if (endsWithColonColon) {
IASTName dummyName = nodeFactory.newName();
ParserUtil.setOffsetAndLength(dummyName, endOffset, 0);
qualifiedName.addName(dummyName);
}
-
+
return qualifiedName;
}
-
-
/**
* Consumes grammar sub-rules of the following form:
- *
+ *
* dcolon_opt nested_name_specifier_opt keyword_opt name
- *
+ *
* Where name is any rule that produces an IASTName node on the stack.
* Does not place the resulting node on the stack, returns it instead.
*/
@SuppressWarnings("unchecked")
private IASTName subRuleQualifiedName(boolean hasOptionalKeyword) {
IASTName lastName = (IASTName) astStack.pop();
-
- if(hasOptionalKeyword) // this is usually a template keyword and can be ignored
+
+ if (hasOptionalKeyword) // this is usually a template keyword and can be ignored
astStack.pop();
-
+
LinkedList<IASTName> nestedNames = (LinkedList<IASTName>) astStack.pop();
IToken dColon = (IToken) astStack.pop();
-
- if(nestedNames.isEmpty() && dColon == null) { // then its not a qualified name
+
+ if (nestedNames.isEmpty() && dColon == null) { // then its not a qualified name
return lastName;
}
nestedNames.addFirst(lastName); // the list of names is in reverse order
-
+
int startOffset = dColon == null ? offset(nestedNames.getLast()) : offset(dColon);
int endOffset = endOffset(lastName);
-
+
return createQualifiedName(nestedNames, startOffset, endOffset, dColon != null);
}
-
-
-
+
/**
* pseudo_destructor_name
- * ::= dcolon_opt nested_name_specifier_opt type_name '::' destructor_type_name
- * | dcolon_opt nested_name_specifier 'template' template_id '::' destructor_type_name
- * | dcolon_opt nested_name_specifier_opt destructor_type_name
- */
+ * ::= dcolon_opt nested_name_specifier_opt type_name '::' destructor_type_name
+ * | dcolon_opt nested_name_specifier 'template' template_id '::' destructor_type_name
+ * | dcolon_opt nested_name_specifier_opt destructor_type_name
+ */
@SuppressWarnings("unchecked")
public void consumePsudoDestructorName(boolean hasExtraTypeName) {
IASTName destructorTypeName = (IASTName) astStack.pop();
IASTName extraName = hasExtraTypeName ? (IASTName) astStack.pop() : null;
LinkedList<IASTName> nestedNames = (LinkedList<IASTName>) astStack.pop();
IToken dColon = (IToken) astStack.pop();
-
- if(hasExtraTypeName)
+
+ if (hasExtraTypeName)
nestedNames.addFirst(extraName);
-
+
nestedNames.addFirst(destructorTypeName);
-
+
int startOffset = dColon == null ? offset(nestedNames.getLast()) : offset(dColon);
int endOffset = endOffset(destructorTypeName);
IASTName qualifiedName = createQualifiedName(nestedNames, startOffset, endOffset, dColon != null);
-
+
setOffsetAndLength(qualifiedName);
astStack.push(qualifiedName);
}
-
-
+
/**
* namespace_alias_definition
- * ::= 'namespace' 'identifier' '=' dcolon_opt nested_name_specifier_opt namespace_name ';'
- */
+ * ::= 'namespace' 'identifier' '=' dcolon_opt nested_name_specifier_opt namespace_name ';'
+ */
public void consumeNamespaceAliasDefinition() {
IASTName qualifiedName = subRuleQualifiedName(false);
-
+
IASTName alias = createName(stream.getRuleTokens().get(1));
ICPPASTNamespaceAlias namespaceAlias = nodeFactory.newNamespaceAlias(alias, qualifiedName);
-
+
setOffsetAndLength(namespaceAlias);
astStack.push(namespaceAlias);
}
-
-
+
/**
* using_declaration
- * ::= 'using' typename_opt dcolon_opt nested_name_specifier_opt unqualified_id ';'
+ * ::= 'using' typename_opt dcolon_opt nested_name_specifier_opt unqualified_id ';'
*/
public void consumeUsingDeclaration() {
IASTName qualifiedName = subRuleQualifiedName(false);
boolean hasTypenameKeyword = astStack.pop() == PLACE_HOLDER;
-
+
ICPPASTUsingDeclaration usingDeclaration = nodeFactory.newUsingDeclaration(qualifiedName);
usingDeclaration.setIsTypename(hasTypenameKeyword);
-
+
setOffsetAndLength(usingDeclaration);
astStack.push(usingDeclaration);
}
-
-
+
/**
* using_directive
- * ::= 'using' 'namespace' dcolon_opt nested_name_specifier_opt namespace_name ';'
+ * ::= 'using' 'namespace' dcolon_opt nested_name_specifier_opt namespace_name ';'
*/
public void consumeUsingDirective() {
IASTName qualifiedName = subRuleQualifiedName(false);
-
+
ICPPASTUsingDirective usingDirective = nodeFactory.newUsingDirective(qualifiedName);
setOffsetAndLength(usingDirective);
astStack.push(usingDirective);
}
-
-
+
/**
* linkage_specification
- * ::= 'extern' 'stringlit' '{' <openscope-ast> declaration_seq_opt '}'
- * | 'extern' 'stringlit' <openscope-ast> declaration
+ * ::= 'extern' 'stringlit' '{' <openscope-ast> declaration_seq_opt '}'
+ * | 'extern' 'stringlit' <openscope-ast> declaration
*/
public void consumeLinkageSpecification() {
String name = stream.getRuleTokens().get(1).toString();
ICPPASTLinkageSpecification linkageSpec = nodeFactory.newLinkageSpecification(name);
-
- for(Object declaration : astStack.closeScope())
- linkageSpec.addDeclaration((IASTDeclaration)declaration);
-
+
+ for (Object declaration : astStack.closeScope())
+ linkageSpec.addDeclaration((IASTDeclaration) declaration);
+
setOffsetAndLength(linkageSpec);
astStack.push(linkageSpec);
}
-
-
-
+
/**
* original_namespace_definition
- * ::= 'namespace' identifier_name '{' <openscope-ast> declaration_seq_opt '}'
- *
- * extension_namespace_definition
- * ::= 'namespace' original_namespace_name '{' <openscope-ast> declaration_seq_opt '}'
- *
- * unnamed_namespace_definition
- * ::= 'namespace' '{' <openscope-ast> declaration_seq_opt '}'
+ * ::= 'namespace' identifier_name '{' <openscope-ast> declaration_seq_opt '}'
+ *
+ * extension_namespace_definition
+ * ::= 'namespace' original_namespace_name '{' <openscope-ast> declaration_seq_opt '}'
+ *
+ * unnamed_namespace_definition
+ * ::= 'namespace' '{' <openscope-ast> declaration_seq_opt '}'
*/
public void consumeNamespaceDefinition(boolean hasName) {
List<Object> declarations = astStack.closeScope();
- IASTName namespaceName = hasName ? (IASTName)astStack.pop() : nodeFactory.newName();
-
+ IASTName namespaceName = hasName ? (IASTName) astStack.pop() : nodeFactory.newName();
+
ICPPASTNamespaceDefinition definition = nodeFactory.newNamespaceDefinition(namespaceName);
-
- for(Object declaration : declarations)
- definition.addDeclaration((IASTDeclaration)declaration);
-
+
+ for (Object declaration : declarations)
+ definition.addDeclaration((IASTDeclaration) declaration);
+
setOffsetAndLength(definition);
astStack.push(definition);
}
-
-
+
/**
* template_declaration
- * ::= export_opt 'template' '<' <openscope-ast> template_parameter_list '>' declaration
+ * ::= export_opt 'template' '<' <openscope-ast> template_parameter_list '>' declaration
*/
public void consumeTemplateDeclaration() {
IASTDeclaration declaration = (IASTDeclaration) astStack.pop();
-
+
// For some reason ambiguous declarators cause bugs when they are a part of a template declaration.
// But it shouldn't be ambiguous anyway, so just throw away the ambiguity node.
resolveAmbiguousDeclaratorsToFunction(declaration);
-
+
ICPPASTTemplateDeclaration templateDeclaration = nodeFactory.newTemplateDeclaration(declaration);
-
- for(Object param : astStack.closeScope())
- templateDeclaration.addTemplateParamter((ICPPASTTemplateParameter)param);
+
+ for (Object param : astStack.closeScope())
+ templateDeclaration.addTemplateParamter((ICPPASTTemplateParameter) param);
boolean hasExportKeyword = astStack.pop() == PLACE_HOLDER;
templateDeclaration.setExported(hasExportKeyword);
-
+
setOffsetAndLength(templateDeclaration);
astStack.push(templateDeclaration);
}
-
-
+
/**
* If we know that a declarator must be a function declarator then we can resolve
* the ambiguity without resorting to binding resolution.
*/
private static void resolveAmbiguousDeclaratorsToFunction(IASTDeclaration declaration) {
- if(declaration instanceof IASTSimpleDeclaration) {
- for(IASTDeclarator declarator : ((IASTSimpleDeclaration)declaration).getDeclarators()) {
- if(declarator instanceof CPPASTAmbiguousDeclarator) {
+ if (declaration instanceof IASTSimpleDeclaration) {
+ for (IASTDeclarator declarator : ((IASTSimpleDeclaration) declaration).getDeclarators()) {
+ if (declarator instanceof CPPASTAmbiguousDeclarator) {
IASTAmbiguityParent owner = (IASTAmbiguityParent) declaration;
- CPPASTAmbiguousDeclarator ambiguity = (CPPASTAmbiguousDeclarator)declarator;
+ CPPASTAmbiguousDeclarator ambiguity = (CPPASTAmbiguousDeclarator) declarator;
owner.replace(ambiguity, ambiguity.getDeclarators()[0]);
}
}
}
}
-
-
- /**
- * explicit_instantiation
- * ::= 'template' declaration
- */
+
+ /**
+ * explicit_instantiation
+ * ::= 'template' declaration
+ */
public void consumeTemplateExplicitInstantiation() {
IASTDeclaration declaration = (IASTDeclaration) astStack.pop();
ICPPASTExplicitTemplateInstantiation instantiation = nodeFactory.newExplicitTemplateInstantiation(declaration);
-
+
setOffsetAndLength(instantiation);
astStack.push(instantiation);
}
-
-
+
/**
* explicit_specialization
- * ::= 'template' '<' '>' declaration
- */
+ * ::= 'template' '<' '>' declaration
+ */
public void consumeTemplateExplicitSpecialization() {
IASTDeclaration declaration = (IASTDeclaration) astStack.pop();
ICPPASTTemplateSpecialization specialization = nodeFactory.newTemplateSpecialization(declaration);
-
+
setOffsetAndLength(specialization);
astStack.push(specialization);
}
-
-
+
/**
* Sets a token specifier.
* Needs to be overrideable for new decl spec keywords.
- *
+ *
* @param token Allows subclasses to override this method and use any
* object to determine how to set a specifier.
*/
public void setSpecifier(ICPPASTDeclSpecifier node, Object specifier) {
- if(!(specifier instanceof IToken))
+ if (!(specifier instanceof IToken))
return;
-
- IToken token = (IToken)specifier;
+
+ IToken token = (IToken) specifier;
int kind = baseKind(token);
- switch(kind){
- case TK_typedef: node.setStorageClass(IASTDeclSpecifier.sc_typedef); return;
- case TK_extern: node.setStorageClass(IASTDeclSpecifier.sc_extern); return;
- case TK_static: node.setStorageClass(IASTDeclSpecifier.sc_static); return;
- case TK_auto: node.setStorageClass(IASTDeclSpecifier.sc_auto); return;
- case TK_register: node.setStorageClass(IASTDeclSpecifier.sc_register); return;
- case TK_mutable: node.setStorageClass(ICPPASTDeclSpecifier.sc_mutable); return;
-
- case TK_inline: node.setInline(true); return;
- case TK_const: node.setConst(true); return;
- case TK_friend: node.setFriend(true); return;
- case TK_virtual: node.setVirtual(true); return;
- case TK_volatile: node.setVolatile(true); return;
- case TK_explicit: node.setExplicit(true); return;
+ switch (kind) {
+ case TK_typedef:
+ node.setStorageClass(IASTDeclSpecifier.sc_typedef);
+ return;
+ case TK_extern:
+ node.setStorageClass(IASTDeclSpecifier.sc_extern);
+ return;
+ case TK_static:
+ node.setStorageClass(IASTDeclSpecifier.sc_static);
+ return;
+ case TK_auto:
+ node.setStorageClass(IASTDeclSpecifier.sc_auto);
+ return;
+ case TK_register:
+ node.setStorageClass(IASTDeclSpecifier.sc_register);
+ return;
+ case TK_mutable:
+ node.setStorageClass(ICPPASTDeclSpecifier.sc_mutable);
+ return;
+
+ case TK_inline:
+ node.setInline(true);
+ return;
+ case TK_const:
+ node.setConst(true);
+ return;
+ case TK_friend:
+ node.setFriend(true);
+ return;
+ case TK_virtual:
+ node.setVirtual(true);
+ return;
+ case TK_volatile:
+ node.setVolatile(true);
+ return;
+ case TK_explicit:
+ node.setExplicit(true);
+ return;
}
-
- if(node instanceof ICPPASTSimpleDeclSpecifier) {
+
+ if (node instanceof ICPPASTSimpleDeclSpecifier) {
ICPPASTSimpleDeclSpecifier n = (ICPPASTSimpleDeclSpecifier) node;
- switch(kind) {
- case TK_void: n.setType(IASTSimpleDeclSpecifier.t_void); return;
- case TK_char: n.setType(IASTSimpleDeclSpecifier.t_char); return;
- case TK_int: n.setType(IASTSimpleDeclSpecifier.t_int); return;
- case TK_float: n.setType(IASTSimpleDeclSpecifier.t_float); return;
- case TK_double: n.setType(IASTSimpleDeclSpecifier.t_double); return;
- case TK_bool: n.setType(ICPPASTSimpleDeclSpecifier.t_bool); return;
- case TK_wchar_t: n.setType(ICPPASTSimpleDeclSpecifier.t_wchar_t); return;
-
- case TK_signed: n.setSigned(true); return;
- case TK_unsigned: n.setUnsigned(true); return;
- //if it is a longlong, donot set long, CDT_70_FIX_FROM_50-#8
- case TK_long: if(!n.isLongLong()) n.setLong(true); return;
- case TK_short: n.setShort(true); return;
+ switch (kind) {
+ case TK_void:
+ n.setType(IASTSimpleDeclSpecifier.t_void);
+ return;
+ case TK_char:
+ n.setType(IASTSimpleDeclSpecifier.t_char);
+ return;
+ case TK_int:
+ n.setType(IASTSimpleDeclSpecifier.t_int);
+ return;
+ case TK_float:
+ n.setType(IASTSimpleDeclSpecifier.t_float);
+ return;
+ case TK_double:
+ n.setType(IASTSimpleDeclSpecifier.t_double);
+ return;
+ case TK_bool:
+ n.setType(ICPPASTSimpleDeclSpecifier.t_bool);
+ return;
+ case TK_wchar_t:
+ n.setType(ICPPASTSimpleDeclSpecifier.t_wchar_t);
+ return;
+
+ case TK_signed:
+ n.setSigned(true);
+ return;
+ case TK_unsigned:
+ n.setUnsigned(true);
+ return;
+ //if it is a longlong, donot set long, CDT_70_FIX_FROM_50-#8
+ case TK_long:
+ if (!n.isLongLong())
+ n.setLong(true);
+ return;
+ case TK_short:
+ n.setShort(true);
+ return;
}
}
}
-
-
+
public void consumeDeclarationSpecifiersSimple() {
ICPPASTDeclSpecifier declSpec = nodeFactory.newSimpleDeclSpecifier();
-
- for(Object token : astStack.closeScope())
+
+ for (Object token : astStack.closeScope())
setSpecifier(declSpec, token);
-
+
setOffsetAndLength(declSpec);
astStack.push(declSpec);
}
-
/**
* TODO: maybe move this into the superclass
*/
public void consumeDeclarationSpecifiersComposite() {
List<Object> topScope = astStack.closeScope();
-
+
// There's already a composite or elaborated or enum type specifier somewhere on the stack, find it.
ICPPASTDeclSpecifier declSpec = findFirstAndRemove(topScope, ICPPASTDeclSpecifier.class);
-
+
// now apply the rest of the specifiers
- for(Object token : topScope)
+ for (Object token : topScope)
setSpecifier(declSpec, token);
-
+
setOffsetAndLength(declSpec);
astStack.push(declSpec);
}
-
-
-
-
-// /**
-// * declaration_specifiers ::= <openscope> type_name_declaration_specifiers
-// */
+
+ // /**
+ // * declaration_specifiers ::= <openscope> type_name_declaration_specifiers
+ // */
public void consumeDeclarationSpecifiersTypeName() {
List<Object> topScope = astStack.closeScope();
- // There's a name somewhere on the stack, find it
+ // There's a name somewhere on the stack, find it
IASTName typeName = findFirstAndRemove(topScope, IASTName.class);
-
+
// TODO what does the second argument mean?
ICPPASTNamedTypeSpecifier declSpec = nodeFactory.newTypedefNameSpecifier(typeName);
-
+
// now apply the rest of the specifiers
- for(Object token : topScope) {
+ for (Object token : topScope) {
setSpecifier(declSpec, token);
}
-
+
// the only way there could be a typename token
- for(IToken token : stream.getRuleTokens()) {
- if(baseKind(token) == TK_typename) {
+ for (IToken token : stream.getRuleTokens()) {
+ if (baseKind(token) == TK_typename) {
declSpec.setIsTypename(true);
break;
}
@@ -1185,92 +1202,90 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(declSpec);
astStack.push(declSpec);
}
-
-
+
/**
* elaborated_type_specifier
- * ::= class_keyword dcolon_opt nested_name_specifier_opt identifier_name
- * | class_keyword dcolon_opt nested_name_specifier_opt template_opt template_id_name
- * | 'enum' dcolon_opt nested_name_specifier_opt identifier_name
+ * ::= class_keyword dcolon_opt nested_name_specifier_opt identifier_name
+ * | class_keyword dcolon_opt nested_name_specifier_opt template_opt template_id_name
+ * | 'enum' dcolon_opt nested_name_specifier_opt identifier_name
*/
public void consumeTypeSpecifierElaborated(boolean hasOptionalTemplateKeyword) {
IASTName name = subRuleQualifiedName(hasOptionalTemplateKeyword);
int kind = getElaboratedTypeSpecifier(stream.getLeftIToken());
-
+
IASTElaboratedTypeSpecifier typeSpecifier = nodeFactory.newElaboratedTypeSpecifier(kind, name);
-
+
setOffsetAndLength(typeSpecifier);
astStack.push(typeSpecifier);
}
-
-
+
private int getElaboratedTypeSpecifier(IToken token) {
int kind = baseKind(token);
- switch(kind) {
- default: assert false : "wrong token kind: " + kind; //$NON-NLS-1$
- case TK_struct: return IASTElaboratedTypeSpecifier.k_struct;
- case TK_union: return IASTElaboratedTypeSpecifier.k_union;
- case TK_enum: return IASTElaboratedTypeSpecifier.k_enum;
- case TK_class: return ICPPASTElaboratedTypeSpecifier.k_class;
+ switch (kind) {
+ default:
+ assert false : "wrong token kind: " + kind; //$NON-NLS-1$
+ case TK_struct:
+ return IASTElaboratedTypeSpecifier.k_struct;
+ case TK_union:
+ return IASTElaboratedTypeSpecifier.k_union;
+ case TK_enum:
+ return IASTElaboratedTypeSpecifier.k_enum;
+ case TK_class:
+ return ICPPASTElaboratedTypeSpecifier.k_class;
}
}
-
-
-
+
/**
* simple_declaration
- * ::= declaration_specifiers_opt <openscope-ast> init_declarator_list_opt ';'
+ * ::= declaration_specifiers_opt <openscope-ast> init_declarator_list_opt ';'
*/
public void consumeDeclarationSimple(boolean hasDeclaratorList) {
List<Object> declarators = hasDeclaratorList ? astStack.closeScope() : new ArrayList<Object>();
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) astStack.pop(); // may be null
-
+
List<IToken> ruleTokens = stream.getRuleTokens();
IToken nameToken = null;
-
-
+
// do not generate nodes for extra EOC tokens
- if(matchTokens(ruleTokens, tokenMap, TK_EndOfCompletion)) {
+ if (matchTokens(ruleTokens, tokenMap, TK_EndOfCompletion)) {
return;
}
-
+
// In the case that a single completion token is parsed then it needs
// to be interpreted as a named type specifier for content assist to work.
- else if(matchTokens(ruleTokens, tokenMap, TK_Completion, TK_EndOfCompletion)) {
+ else if (matchTokens(ruleTokens, tokenMap, TK_Completion, TK_EndOfCompletion)) {
IASTName name = createName(stream.getLeftIToken());
declSpec = nodeFactory.newTypedefNameSpecifier(name);
ParserUtil.setOffsetAndLength(declSpec, offset(name), length(name));
declarators = new ArrayList<Object>(); // throw away the bogus declarator
}
-
+
// can happen if implicit int is used
- else if(declSpec == null) {
+ else if (declSpec == null) {
declSpec = nodeFactory.newSimpleDeclSpecifier();
ParserUtil.setOffsetAndLength(declSpec, stream.getLeftIToken().getStartOffset(), 0);
}
-
-
- else if(declarators.size() == 1 && disambiguateToConstructor(declSpec, (IASTDeclarator)declarators.get(0))) { // puts results of disambiguation onto stack
- declSpec = (ICPPASTDeclSpecifier) astStack.pop();
+
+ else if (declarators.size() == 1 && disambiguateToConstructor(declSpec, (IASTDeclarator) declarators.get(0))) { // puts results of disambiguation onto stack
+ declSpec = (ICPPASTDeclSpecifier) astStack.pop();
declarators = Arrays.asList(astStack.pop());
}
-
+
// bug 80171, check for situation similar to: static var;
// this will get parsed wrong, the following is a hack to rebuild the AST as it should have been parsed
// exclude syntax "friend xxx"
- else if(declarators.isEmpty() &&
- declSpec instanceof ICPPASTNamedTypeSpecifier && ! declSpec.isFriend() &&
- ruleTokens.size() >= 2 &&
- baseKind(nameToken = ruleTokens.get(ruleTokens.size() - 2)) == TK_identifier) {
-
+ else if (declarators.isEmpty() && declSpec instanceof ICPPASTNamedTypeSpecifier && !declSpec.isFriend()
+ && ruleTokens.size() >= 2
+ && baseKind(nameToken = ruleTokens.get(ruleTokens.size() - 2)) == TK_identifier) {
+
declSpec = nodeFactory.newSimpleDeclSpecifier();
- for(IToken t : ruleTokens.subList(0, ruleTokens.size()-1))
+ for (IToken t : ruleTokens.subList(0, ruleTokens.size() - 1))
setSpecifier(declSpec, t);
-
+
int offset = offset(stream.getLeftIToken());
- int length = endOffset(ruleTokens.get(ruleTokens.size()-2)) - offset;
+ int length = endOffset(ruleTokens.get(ruleTokens.size() - 2)) - offset;
ParserUtil.setOffsetAndLength(declSpec, offset, length);
-
+
IASTName name = createName(nameToken);
IASTDeclarator declarator = nodeFactory.newDeclarator(name);
ParserUtil.setOffsetAndLength(declarator, nameToken);
@@ -1279,184 +1294,181 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
IASTSimpleDeclaration declaration = nodeFactory.newSimpleDeclaration(declSpec);
setOffsetAndLength(declaration);
- for(Object declarator : declarators)
- declaration.addDeclarator((IASTDeclarator)declarator);
-
+ for (Object declarator : declarators)
+ declaration.addDeclarator((IASTDeclarator) declarator);
+
// simple ambiguity resolutions
-// if(declSpecifier.isFriend())
-// resolveAmbiguousDeclaratorsToFunction(declaration);
-//
-// if(declSpecifier instanceof IASTSimpleDeclSpecifier) {
-// IASTSimpleDeclSpecifier simple = (IASTSimpleDeclSpecifier) declSpecifier;
-// if(simple.getType() == IASTSimpleDeclSpecifier.t_void && declaration.getDeclarators()[0].getPointerOperators().length == 0)
-// resolveAmbiguousDeclaratorsToFunction(declaration);
-//
-// }
-
+ // if(declSpecifier.isFriend())
+ // resolveAmbiguousDeclaratorsToFunction(declaration);
+ //
+ // if(declSpecifier instanceof IASTSimpleDeclSpecifier) {
+ // IASTSimpleDeclSpecifier simple = (IASTSimpleDeclSpecifier) declSpecifier;
+ // if(simple.getType() == IASTSimpleDeclSpecifier.t_void && declaration.getDeclarators()[0].getPointerOperators().length == 0)
+ // resolveAmbiguousDeclaratorsToFunction(declaration);
+ //
+ // }
+
astStack.push(declaration);
}
-
-
private boolean disambiguateToConstructor(IASTDeclSpecifier declSpec, IASTDeclarator declarator) {
- if(!(declSpec instanceof IASTNamedTypeSpecifier))
+ if (!(declSpec instanceof IASTNamedTypeSpecifier))
return false;
-
+
IASTNamedTypeSpecifier namedTypeSpecifier = (IASTNamedTypeSpecifier) declSpec;
IASTName name = namedTypeSpecifier.getName();
IASTDeclarator nested = declarator.getNestedDeclarator();
-
+
ICPPASTSimpleDeclSpecifier simpleDeclSpec = nodeFactory.newSimpleDeclSpecifier(); // empty
ParserUtil.setOffsetAndLength(simpleDeclSpec, stream.getLeftIToken().getStartOffset(), 0);
-
- if(!classNames.isEmpty() && nested != null && ParserUtil.isSameName(name, classNames.getLast())) {
- IASTName paramTypeName = nested.getName(); // reuse the parameter name node
+ if (!classNames.isEmpty() && nested != null && ParserUtil.isSameName(name, classNames.getLast())) {
+
+ IASTName paramTypeName = nested.getName(); // reuse the parameter name node
IASTNamedTypeSpecifier paramName = nodeFactory.newTypedefNameSpecifier(paramTypeName);
ParserUtil.setOffsetAndLength(paramName, paramTypeName);
-
+
IASTDeclarator paramDeclarator = nodeFactory.newDeclarator(nodeFactory.newName());
ParserUtil.setOffsetAndLength(paramDeclarator, offset(paramName) + length(paramName), 0);
-
+
ICPPASTParameterDeclaration parameter = nodeFactory.newParameterDeclaration(paramName, paramDeclarator);
ParserUtil.setOffsetAndLength(parameter, paramName);
-
+
ICPPASTFunctionDeclarator constructorDeclarator = nodeFactory.newFunctionDeclarator(name); // reuse the name node
constructorDeclarator.addParameterDeclaration(parameter);
- ParserUtil.setOffsetAndLength(constructorDeclarator, offset(simpleDeclSpec), endOffset(paramDeclarator) - offset(simpleDeclSpec) + 1);
-
+ ParserUtil.setOffsetAndLength(constructorDeclarator, offset(simpleDeclSpec),
+ endOffset(paramDeclarator) - offset(simpleDeclSpec) + 1);
+
astStack.push(constructorDeclarator);
astStack.push(simpleDeclSpec);
return true;
}
-
- if(declarator instanceof IASTFunctionDeclarator && declarator.getName() instanceof ICPPASTQualifiedName) {
+
+ if (declarator instanceof IASTFunctionDeclarator && declarator.getName() instanceof ICPPASTQualifiedName) {
ICPPASTQualifiedName qualifiedName = (ICPPASTQualifiedName) declarator.getName();
//IASTName lastName = qualifiedName.getLastName();
-
- if(qualifiedName.isFullyQualified()) {
-
+
+ if (qualifiedName.isFullyQualified()) {
+
ICPPASTQualifiedName newQualifiedName = nodeFactory.newQualifiedName();
newQualifiedName.addName(name);
- for(ICPPASTNameSpecifier n : qualifiedName.getQualifier())
+ for (ICPPASTNameSpecifier n : qualifiedName.getQualifier())
newQualifiedName.addNameSpecifier(n);
newQualifiedName.addName(qualifiedName.getLastName());
-
- ParserUtil.setOffsetAndLength(newQualifiedName, offset(name), endOffset(qualifiedName.getLastName()) - offset(name));
-
-
+
+ ParserUtil.setOffsetAndLength(newQualifiedName, offset(name),
+ endOffset(qualifiedName.getLastName()) - offset(name));
+
declarator.setName(newQualifiedName);
- ParserUtil.setOffsetAndLength(declarator, offset(name), length(declarator) + offset(declarator) - offset(name));
-
+ ParserUtil.setOffsetAndLength(declarator, offset(name),
+ length(declarator) + offset(declarator) - offset(name));
+
astStack.push(declarator);
astStack.push(simpleDeclSpec);
return true;
}
}
-
+
return false;
}
-
-
public void consumeInitDeclaratorComplete() {
// Don't do disambiguation when parsing for content assist,
// trust me this makes things work out a lot better.
- if(completionNode != null)
+ if (completionNode != null)
return;
-
+
IASTDeclarator declarator = (IASTDeclarator) astStack.peek();
- if(!(declarator instanceof IASTFunctionDeclarator))
+ if (!(declarator instanceof IASTFunctionDeclarator))
return;
-
- ISecondaryParser<IASTDeclarator> secondaryParser = parserFactory.getNoFunctionDeclaratorParser(stream, properties);
+
+ ISecondaryParser<IASTDeclarator> secondaryParser = parserFactory.getNoFunctionDeclaratorParser(stream,
+ properties);
IASTDeclarator notFunctionDeclarator = runSecondaryParser(secondaryParser);
-
- if(notFunctionDeclarator == null)
+
+ if (notFunctionDeclarator == null)
return;
-
+
astStack.pop();
IASTNode ambiguityNode = new CPPASTAmbiguousDeclarator(declarator, notFunctionDeclarator);
setOffsetAndLength(ambiguityNode);
- astStack.push(ambiguityNode);
+ astStack.push(ambiguityNode);
}
-
-
-
+
/**
* visibility_label
- * ::= access_specifier_keyword ':'
+ * ::= access_specifier_keyword ':'
*/
public void consumeVisibilityLabel() {
- IToken specifier = (IToken)astStack.pop();
+ IToken specifier = (IToken) astStack.pop();
int visibility = getAccessSpecifier(specifier);
ICPPASTVisibilityLabel visibilityLabel = nodeFactory.newVisibilityLabel(visibility);
setOffsetAndLength(visibilityLabel);
astStack.push(visibilityLabel);
}
-
-
+
private int getAccessSpecifier(IToken token) {
int kind = baseKind(token);
- switch(kind) {
- default: assert false : "wrong token kind: " + kind; //$NON-NLS-1$
- case TK_private: return ICPPASTVisibilityLabel.v_private;
- case TK_public: return ICPPASTVisibilityLabel.v_public;
- case TK_protected: return ICPPASTVisibilityLabel.v_protected;
+ switch (kind) {
+ default:
+ assert false : "wrong token kind: " + kind; //$NON-NLS-1$
+ case TK_private:
+ return ICPPASTVisibilityLabel.v_private;
+ case TK_public:
+ return ICPPASTVisibilityLabel.v_public;
+ case TK_protected:
+ return ICPPASTVisibilityLabel.v_protected;
}
}
-
-
+
/**
* base_specifier
- * ::= dcolon_opt nested_name_specifier_opt class_name
- * | 'virtual' access_specifier_keyword_opt dcolon_opt nested_name_specifier_opt class_name
- * | access_specifier_keyword 'virtual' dcolon_opt nested_name_specifier_opt class_name
- * | access_specifier_keyword dcolon_opt nested_name_specifier_opt class_name
+ * ::= dcolon_opt nested_name_specifier_opt class_name
+ * | 'virtual' access_specifier_keyword_opt dcolon_opt nested_name_specifier_opt class_name
+ * | access_specifier_keyword 'virtual' dcolon_opt nested_name_specifier_opt class_name
+ * | access_specifier_keyword dcolon_opt nested_name_specifier_opt class_name
*/
public void consumeBaseSpecifier(boolean hasAccessSpecifier, boolean isVirtual) {
IASTName name = subRuleQualifiedName(false);
-
+
int visibility = 0; // this is the default value that the DOM parser uses
- if(hasAccessSpecifier) {
+ if (hasAccessSpecifier) {
IToken accessSpecifierToken = (IToken) astStack.pop();
- if(accessSpecifierToken != null)
+ if (accessSpecifierToken != null)
visibility = getAccessSpecifier(accessSpecifierToken);
}
-
+
ICPPASTBaseSpecifier baseSpecifier = nodeFactory.newBaseSpecifier(name, visibility, isVirtual);
setOffsetAndLength(baseSpecifier);
astStack.push(baseSpecifier);
}
-
-
+
/**
* class_specifier
- * ::= class_head '{' <openscope-ast> member_declaration_list_opt '}'
- */
+ * ::= class_head '{' <openscope-ast> member_declaration_list_opt '}'
+ */
public void consumeClassSpecifier() {
List<Object> declarations = astStack.closeScope();
-
+
// the class specifier is created by the rule for class_head
IASTCompositeTypeSpecifier classSpecifier = (IASTCompositeTypeSpecifier) astStack.peek();
-
- for(Object declaration : declarations)
- classSpecifier.addMemberDeclaration((IASTDeclaration)declaration);
-
+
+ for (Object declaration : declarations)
+ classSpecifier.addMemberDeclaration((IASTDeclaration) declaration);
+
setOffsetAndLength(classSpecifier);
-
+
classNames.removeLast(); // pop the stack of class names
}
-
-
+
/**
- * class_head
- * ::= class_keyword identifier_name_opt <openscope-ast> base_clause_opt
- * | class_keyword template_id <openscope-ast> base_clause_opt
- * | class_keyword nested_name_specifier identifier_name <openscope-ast> base_clause_opt
- * | class_keyword nested_name_specifier template_id <openscope-ast> base_clause_opt
+ * class_head
+ * ::= class_keyword identifier_name_opt <openscope-ast> base_clause_opt
+ * | class_keyword template_id <openscope-ast> base_clause_opt
+ * | class_keyword nested_name_specifier identifier_name <openscope-ast> base_clause_opt
+ * | class_keyword nested_name_specifier template_id <openscope-ast> base_clause_opt
*/
@SuppressWarnings("unchecked")
public void consumeClassHead(boolean hasNestedNameSpecifier) {
@@ -1464,8 +1476,8 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
List<Object> baseSpecifiers = astStack.closeScope();
// may be null, but if it is then hasNestedNameSpecifier == false
IASTName className = (IASTName) astStack.pop();
-
- if(hasNestedNameSpecifier) {
+
+ if (hasNestedNameSpecifier) {
LinkedList<IASTName> nestedNames = (LinkedList<IASTName>) astStack.pop();
nestedNames.addFirst(className);
int startOffset = offset(nestedNames.getLast());
@@ -1473,382 +1485,377 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
className = createQualifiedName(nestedNames, startOffset, endOffset, false);
}
- if(className == null)
+ if (className == null)
className = nodeFactory.newName();
-
+
ICPPASTCompositeTypeSpecifier classSpecifier = nodeFactory.newCompositeTypeSpecifier(key, className);
-
- for(Object base : baseSpecifiers)
- classSpecifier.addBaseSpecifier((ICPPASTBaseSpecifier)base);
-
+
+ for (Object base : baseSpecifiers)
+ classSpecifier.addBaseSpecifier((ICPPASTBaseSpecifier) base);
+
// the offset and length are set in consumeClassSpecifier()
astStack.push(classSpecifier);
classNames.add(className); // push
}
-
-
+
private int getCompositeTypeSpecifier(IToken token) {
final int kind = baseKind(token);
- switch(kind) {
- default: assert false : "wrong token kind: " + kind; //$NON-NLS-1$
- case TK_struct: return IASTCompositeTypeSpecifier.k_struct;
- case TK_union: return IASTCompositeTypeSpecifier.k_union;
- case TK_class: return ICPPASTCompositeTypeSpecifier.k_class;
+ switch (kind) {
+ default:
+ assert false : "wrong token kind: " + kind; //$NON-NLS-1$
+ case TK_struct:
+ return IASTCompositeTypeSpecifier.k_struct;
+ case TK_union:
+ return IASTCompositeTypeSpecifier.k_union;
+ case TK_class:
+ return ICPPASTCompositeTypeSpecifier.k_class;
}
}
-
-
+
/**
* ptr_operator
- * ::= '*' <openscope-ast> cv_qualifier_seq_opt
- */
- public void consumePointer() {
- IASTPointer pointer = nodeFactory.newPointer();
- List<Object> tokens = astStack.closeScope();
- addCVQualifiersToPointer(pointer, tokens);
+ * ::= '*' <openscope-ast> cv_qualifier_seq_opt
+ */
+ public void consumePointer() {
+ IASTPointer pointer = nodeFactory.newPointer();
+ List<Object> tokens = astStack.closeScope();
+ addCVQualifiersToPointer(pointer, tokens);
setOffsetAndLength(pointer);
astStack.push(pointer);
- }
-
-
- protected void addCVQualifiersToPointer(IASTPointer pointer, List<Object> tokens) {
- for(Object t : tokens) {
- switch(baseKind((IToken) t)) {
- case TK_const: pointer.setConst(true); break;
- case TK_volatile: pointer.setVolatile(true); break;
+ }
+
+ protected void addCVQualifiersToPointer(IASTPointer pointer, List<Object> tokens) {
+ for (Object t : tokens) {
+ switch (baseKind((IToken) t)) {
+ case TK_const:
+ pointer.setConst(true);
+ break;
+ case TK_volatile:
+ pointer.setVolatile(true);
+ break;
}
}
- }
-
- /**
+ }
+
+ /**
* ptr_operator
- * ::= '&'
- */
- public void consumeReferenceOperator() {
- ICPPASTReferenceOperator referenceOperator = nodeFactory.newReferenceOperator();
- setOffsetAndLength(referenceOperator);
+ * ::= '&'
+ */
+ public void consumeReferenceOperator() {
+ ICPPASTReferenceOperator referenceOperator = nodeFactory.newReferenceOperator();
+ setOffsetAndLength(referenceOperator);
astStack.push(referenceOperator);
- }
-
-
- /**
+ }
+
+ /**
* ptr_operator
- * ::= dcolon_opt nested_name_specifier '*' <openscope-ast> cv_qualifier_seq_opt
- */
- @SuppressWarnings("unchecked")
+ * ::= dcolon_opt nested_name_specifier '*' <openscope-ast> cv_qualifier_seq_opt
+ */
+ @SuppressWarnings("unchecked")
public void consumePointerToMember() {
- List<Object> qualifiers = astStack.closeScope();
- LinkedList<IASTName> nestedNames = (LinkedList<IASTName>) astStack.pop();
- IToken dColon = (IToken) astStack.pop();
-
- int startOffset = dColon == null ? offset(nestedNames.getLast()) : offset(dColon);
- int endOffset = endOffset(nestedNames.getFirst()); // temporary
-
- // find the last double colon by searching for it
- for(IToken t : reverseIterable(stream.getRuleTokens())) {
- if(baseKind(t) == TK_ColonColon) {
- endOffset = endOffset(t);
- break;
- }
- }
-
- IASTName name = createQualifiedName(nestedNames, startOffset, endOffset, dColon != null, true);
-
- ICPPASTPointerToMember pointer = nodeFactory.newPointerToMember(name);
- addCVQualifiersToPointer(pointer, qualifiers);
- setOffsetAndLength(pointer);
- astStack.push(pointer);
- }
-
-
-
- /**
- * initializer
- * ::= '(' expression_list ')'
- */
- public void consumeInitializerConstructor() {
- //CDT_70_FIX_FROM_50-#5
- Object o = astStack.pop();
- IASTInitializerClause[] initClauseList =null;
- if(o instanceof IASTExpressionList){
- initClauseList = ((IASTExpressionList) o).getExpressions();
- }else if(o instanceof IASTInitializerClause){
- initClauseList = new IASTInitializerClause[]{(IASTInitializerClause)o};
- }
-
- ICPPASTConstructorInitializer initializer = nodeFactory.newConstructorInitializer(initClauseList);
- setOffsetAndLength(initializer);
- astStack.push(initializer);
- }
-
-
- /**
- * function_direct_declarator
- * ::= basic_direct_declarator '(' <openscope-ast> parameter_declaration_clause ')'
- * <openscope-ast> cv_qualifier_seq_opt <openscope-ast> exception_specification_opt
- */
- public void consumeDirectDeclaratorFunctionDeclarator(boolean hasDeclarator) {
- IASTName name = nodeFactory.newName();
- ICPPASTFunctionDeclarator declarator = nodeFactory.newFunctionDeclarator(name);
-
- List<Object> typeIds = astStack.closeScope();
- if(typeIds.size() == 1 && typeIds.get(0) == PLACE_HOLDER) { // fix for bug 86943
- declarator.setEmptyExceptionSpecification();
- }
- else {
- for(Object typeId : typeIds) {
- declarator.addExceptionSpecificationTypeId((IASTTypeId) typeId);
- }
- }
-
- for(Object token : astStack.closeScope()) {
- int kind = baseKind((IToken)token);
- switch(kind) {
- default: assert false : "wrong token kind: " + kind; //$NON-NLS-1$
- case TK_const: declarator.setConst(true); break;
- case TK_volatile: declarator.setVolatile(true); break;
- }
- }
-
- boolean isVarArgs = astStack.pop() == PLACE_HOLDER;
- declarator.setVarArgs(isVarArgs);
-
- for(Object o : astStack.closeScope()) {
- declarator.addParameterDeclaration((IASTParameterDeclaration)o);
- }
-
- if(hasDeclarator) {
- int endOffset = endOffset(stream.getRightIToken());
- addFunctionModifier(declarator, endOffset);
- }
- else {
- setOffsetAndLength(declarator);
+ List<Object> qualifiers = astStack.closeScope();
+ LinkedList<IASTName> nestedNames = (LinkedList<IASTName>) astStack.pop();
+ IToken dColon = (IToken) astStack.pop();
+
+ int startOffset = dColon == null ? offset(nestedNames.getLast()) : offset(dColon);
+ int endOffset = endOffset(nestedNames.getFirst()); // temporary
+
+ // find the last double colon by searching for it
+ for (IToken t : reverseIterable(stream.getRuleTokens())) {
+ if (baseKind(t) == TK_ColonColon) {
+ endOffset = endOffset(t);
+ break;
+ }
+ }
+
+ IASTName name = createQualifiedName(nestedNames, startOffset, endOffset, dColon != null, true);
+
+ ICPPASTPointerToMember pointer = nodeFactory.newPointerToMember(name);
+ addCVQualifiersToPointer(pointer, qualifiers);
+ setOffsetAndLength(pointer);
+ astStack.push(pointer);
+ }
+
+ /**
+ * initializer
+ * ::= '(' expression_list ')'
+ */
+ public void consumeInitializerConstructor() {
+ //CDT_70_FIX_FROM_50-#5
+ Object o = astStack.pop();
+ IASTInitializerClause[] initClauseList = null;
+ if (o instanceof IASTExpressionList) {
+ initClauseList = ((IASTExpressionList) o).getExpressions();
+ } else if (o instanceof IASTInitializerClause) {
+ initClauseList = new IASTInitializerClause[] { (IASTInitializerClause) o };
+ }
+
+ ICPPASTConstructorInitializer initializer = nodeFactory.newConstructorInitializer(initClauseList);
+ setOffsetAndLength(initializer);
+ astStack.push(initializer);
+ }
+
+ /**
+ * function_direct_declarator
+ * ::= basic_direct_declarator '(' <openscope-ast> parameter_declaration_clause ')'
+ * <openscope-ast> cv_qualifier_seq_opt <openscope-ast> exception_specification_opt
+ */
+ public void consumeDirectDeclaratorFunctionDeclarator(boolean hasDeclarator) {
+ IASTName name = nodeFactory.newName();
+ ICPPASTFunctionDeclarator declarator = nodeFactory.newFunctionDeclarator(name);
+
+ List<Object> typeIds = astStack.closeScope();
+ if (typeIds.size() == 1 && typeIds.get(0) == PLACE_HOLDER) { // fix for bug 86943
+ declarator.setEmptyExceptionSpecification();
+ } else {
+ for (Object typeId : typeIds) {
+ declarator.addExceptionSpecificationTypeId((IASTTypeId) typeId);
+ }
+ }
+
+ for (Object token : astStack.closeScope()) {
+ int kind = baseKind((IToken) token);
+ switch (kind) {
+ default:
+ assert false : "wrong token kind: " + kind; //$NON-NLS-1$
+ case TK_const:
+ declarator.setConst(true);
+ break;
+ case TK_volatile:
+ declarator.setVolatile(true);
+ break;
+ }
+ }
+
+ boolean isVarArgs = astStack.pop() == PLACE_HOLDER;
+ declarator.setVarArgs(isVarArgs);
+
+ for (Object o : astStack.closeScope()) {
+ declarator.addParameterDeclaration((IASTParameterDeclaration) o);
+ }
+
+ if (hasDeclarator) {
+ int endOffset = endOffset(stream.getRightIToken());
+ addFunctionModifier(declarator, endOffset);
+ } else {
+ setOffsetAndLength(declarator);
astStack.push(declarator);
- }
- }
-
-
- /**
- * Consume an empty bracketed abstract declarator.
- */
- public void consumeAbstractDeclaratorEmpty() {
- IASTName name = nodeFactory.newName();
- ParserUtil.setOffsetAndLength(name, offset(stream.getLeftIToken())+1, 0);
- IASTDeclarator declarator = nodeFactory.newDeclarator(name);
- setOffsetAndLength(declarator);
- astStack.push(declarator);
- }
-
-
- /**
- * mem_initializer
- * ::= mem_initializer_id '(' expression_list_opt ')'
- */
- public void consumeConstructorChainInitializer() {
+ }
+ }
+
+ /**
+ * Consume an empty bracketed abstract declarator.
+ */
+ public void consumeAbstractDeclaratorEmpty() {
+ IASTName name = nodeFactory.newName();
+ ParserUtil.setOffsetAndLength(name, offset(stream.getLeftIToken()) + 1, 0);
+ IASTDeclarator declarator = nodeFactory.newDeclarator(name);
+ setOffsetAndLength(declarator);
+ astStack.push(declarator);
+ }
+
+ /**
+ * mem_initializer
+ * ::= mem_initializer_id '(' expression_list_opt ')'
+ */
+ public void consumeConstructorChainInitializer() {
Object o = astStack.pop();
IASTName name = (IASTName) astStack.pop();
- IASTInitializerClause[] initClauseList =null;
- if(o instanceof IASTExpressionList){
+ IASTInitializerClause[] initClauseList = null;
+ if (o instanceof IASTExpressionList) {
initClauseList = ((IASTExpressionList) o).getExpressions();
- }else if(o instanceof IASTInitializerClause){
- initClauseList = new IASTInitializerClause[]{(IASTInitializerClause)o};
+ } else if (o instanceof IASTInitializerClause) {
+ initClauseList = new IASTInitializerClause[] { (IASTInitializerClause) o };
}
ICPPASTConstructorInitializer init = nodeFactory.newConstructorInitializer(initClauseList);
int rule_start_offset = stream.getLeftIToken().getStartOffset();
int initClauseList_offset = ParserUtil.offset(initClauseList[0]);
List<IToken> ruleTokens = stream.getRuleTokens();
int start_offset = -1;
-
- for (int i = initClauseList_offset, n = rule_start_offset; i >= n; i--){
- if(tokenMap.mapKind(ruleTokens.get(i).getKind()) == TK_LeftParen) {
+
+ for (int i = initClauseList_offset, n = rule_start_offset; i >= n; i--) {
+ if (tokenMap.mapKind(ruleTokens.get(i).getKind()) == TK_LeftParen) {
start_offset = ruleTokens.get(i).getStartOffset();
break;
}
}
int ruleLength = stream.getRightIToken().getEndOffset() - start_offset;
ParserUtil.setOffsetAndLength(init, start_offset, ruleLength < 0 ? 0 : ruleLength);
-
- ICPPASTConstructorChainInitializer initializer = nodeFactory.newConstructorChainInitializer(name, init);
- setOffsetAndLength(initializer);
+
+ ICPPASTConstructorChainInitializer initializer = nodeFactory.newConstructorChainInitializer(name, init);
+ setOffsetAndLength(initializer);
astStack.push(initializer);
- }
-
-
-
- /**
- * function_definition
- * ::= declaration_specifiers_opt function_direct_declarator
- * <openscope-ast> ctor_initializer_list_opt function_body
- *
- * | declaration_specifiers_opt function_direct_declarator
- * 'try' <openscope-ast> ctor_initializer_list_opt function_body <openscope-ast> handler_seq
- *
- */
- public void consumeFunctionDefinition(boolean isTryBlockDeclarator) {
- List<Object> handlers = isTryBlockDeclarator ? astStack.closeScope() : Collections.emptyList();
- IASTCompoundStatement body = (IASTCompoundStatement) astStack.pop();
- List<Object> initializers = astStack.closeScope();
- Object o = astStack.pop();
- IASTFunctionDeclarator declarator = (IASTFunctionDeclarator) o;
- Object o2 = astStack.pop();
- IASTDeclSpecifier declSpec = (IASTDeclSpecifier) o2; // may be null
-
- if(declSpec == null) { // can happen if implicit int is used
- declSpec = nodeFactory.newSimpleDeclSpecifier();
- ParserUtil.setOffsetAndLength(declSpec, stream.getLeftIToken().getStartOffset(), 0);
- }
- else if(disambiguateToConstructor(declSpec, declarator)) {
- declSpec = (IASTDeclSpecifier) astStack.pop();
+ }
+
+ /**
+ * function_definition
+ * ::= declaration_specifiers_opt function_direct_declarator
+ * <openscope-ast> ctor_initializer_list_opt function_body
+ *
+ * | declaration_specifiers_opt function_direct_declarator
+ * 'try' <openscope-ast> ctor_initializer_list_opt function_body <openscope-ast> handler_seq
+ *
+ */
+ public void consumeFunctionDefinition(boolean isTryBlockDeclarator) {
+ List<Object> handlers = isTryBlockDeclarator ? astStack.closeScope() : Collections.emptyList();
+ IASTCompoundStatement body = (IASTCompoundStatement) astStack.pop();
+ List<Object> initializers = astStack.closeScope();
+ Object o = astStack.pop();
+ IASTFunctionDeclarator declarator = (IASTFunctionDeclarator) o;
+ Object o2 = astStack.pop();
+ IASTDeclSpecifier declSpec = (IASTDeclSpecifier) o2; // may be null
+
+ if (declSpec == null) { // can happen if implicit int is used
+ declSpec = nodeFactory.newSimpleDeclSpecifier();
+ ParserUtil.setOffsetAndLength(declSpec, stream.getLeftIToken().getStartOffset(), 0);
+ } else if (disambiguateToConstructor(declSpec, declarator)) {
+ declSpec = (IASTDeclSpecifier) astStack.pop();
declarator = (IASTFunctionDeclarator) astStack.pop();
- }
-
- ICPPASTFunctionDefinition definition;
- if (isTryBlockDeclarator) {
- ICPPASTFunctionWithTryBlock tryblock= nodeFactory.newFunctionTryBlock(declSpec, declarator, body);
- for(Object handler : handlers)
- tryblock.addCatchHandler((ICPPASTCatchHandler)handler);
- definition = tryblock;
- } else {
- definition = nodeFactory.newFunctionDefinition(declSpec, declarator, body);
- }
-
-
- if(initializers != null && !initializers.isEmpty()) {
- for(Object initializer : initializers)
- definition.addMemberInitializer((ICPPASTConstructorChainInitializer)initializer);
- }
-
- setOffsetAndLength(definition);
+ }
+
+ ICPPASTFunctionDefinition definition;
+ if (isTryBlockDeclarator) {
+ ICPPASTFunctionWithTryBlock tryblock = nodeFactory.newFunctionTryBlock(declSpec, declarator, body);
+ for (Object handler : handlers)
+ tryblock.addCatchHandler((ICPPASTCatchHandler) handler);
+ definition = tryblock;
+ } else {
+ definition = nodeFactory.newFunctionDefinition(declSpec, declarator, body);
+ }
+
+ if (initializers != null && !initializers.isEmpty()) {
+ for (Object initializer : initializers)
+ definition.addMemberInitializer((ICPPASTConstructorChainInitializer) initializer);
+ }
+
+ setOffsetAndLength(definition);
astStack.push(definition);
- }
-
-
- /**
- * member_declaration
- * ::= dcolon_opt nested_name_specifier template_opt unqualified_id_name ';'
- */
- public void consumeMemberDeclarationQualifiedId() {
- IASTName qualifiedId = subRuleQualifiedName(true);
-
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=92793
- ICPPASTUsingDeclaration declaration = nodeFactory.newUsingDeclaration(qualifiedId);
- setOffsetAndLength(declaration);
-
- astStack.push(declaration);
- }
-
-
- /**
- * member_declarator
- * ::= declarator constant_initializer
- */
-
- public void consumeMemberDeclaratorWithInitializer() {
-
- //CDT_70_FIX_FROM_50-#2
- //IASTInitializerExpression initializer = (IASTInitializerExpression) astStack.pop();
- IASTEqualsInitializer initializer = (IASTEqualsInitializer) astStack.pop();
- IASTDeclarator declarator = (IASTDeclarator) astStack.peek();
- setOffsetAndLength(declarator);
-
- if(declarator instanceof ICPPASTFunctionDeclarator) {
- IASTExpression expr = (IASTExpression)initializer.getInitializerClause();
- if(expr instanceof IASTLiteralExpression && "0".equals(expr.toString())) { //$NON-NLS-1$
- ((ICPPASTFunctionDeclarator)declarator).setPureVirtual(true);
- return;
- }
- }
-
- declarator.setInitializer(initializer);
- }
-
-
- /**
- * type_parameter
- * ::= 'class' identifier_name_opt -- simple type template parameter
- * | 'class' identifier_name_opt '=' type_id
- * | 'typename' identifier_name_opt
- * | 'typename' identifier_name_opt '=' type_id
- */
- public void consumeSimpleTypeTemplateParameter(boolean hasTypeId) {
- IASTTypeId typeId = hasTypeId ? (IASTTypeId)astStack.pop() : null;
-
- IASTName name = (IASTName)astStack.pop();
- if(name == null)
- name = nodeFactory.newName();
-
- int type = getTemplateParameterType(stream.getLeftIToken());
-
- ICPPASTSimpleTypeTemplateParameter templateParameter = nodeFactory.newSimpleTypeTemplateParameter(type, name, typeId);</