From 7788841cb39466c4a85abb6a88176187af16ee56 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Tue, 20 Nov 2007 10:57:40 +0000 Subject: [PATCH] Removal of old parser (bug 209772). --- .../META-INF/MANIFEST.MF | 2 - .../parser/failedTests/ASTFailedTests.java | 112 - .../FailedCompleteParseASTTest.java | 142 - .../parser/failedTests/STLFailedTests.java | 50 - .../failedTests/SelectionParseFailedTest.java | 23 - .../tests/StructuralCModelElementsTests.java | 1 + .../core/parser/tests/AutomatedFramework.java | 6 +- .../cdt/core/parser/tests/AutomatedTest.java | 131 - .../cdt/core/parser/tests/BaseASTTest.java | 196 - .../core/parser/tests/CharArrayUtilsTest.java | 58 +- .../tests/CompleteParseASTExpressionTest.java | 1106 --- .../CompleteParseASTSymbolIteratorTest.java | 424 - .../tests/CompleteParseASTTemplateTest.java | 1242 --- .../parser/tests/CompleteParseASTTest.java | 2562 ------ .../parser/tests/CompleteParseBaseTest.java | 1039 --- .../parser/tests/CompleteParsePluginTest.java | 273 - .../tests/CompleteParseProblemTest.java | 139 - .../parser/tests/CompletionParseBaseTest.java | 126 - .../parser/tests/CompletionParseTest.java | 1274 --- .../parser/tests/FailingTemplateTests.java | 206 - .../core/parser/tests/FileBasePluginTest.java | 209 - .../parser/tests/FractionalAutomatedTest.java | 260 - .../tests/GCCCompleteParseExtensionsTest.java | 288 - .../tests/GCCParserExtensionTestSuite.java | 34 - .../tests/GCCQuickParseExtensionsTest.java | 184 - .../GCCSelectionParseExtensionsTest.java | 34 - .../parser/tests/IScannerInfoPluginTest.java | 123 - .../tests/{scanner2 => }/ObjectMapTest.java | 4 +- .../tests/ParserSymbolTableTemplateTests.java | 2632 ------- .../parser/tests/ParserSymbolTableTest.java | 3520 --------- .../core/parser/tests/ParserTestSuite.java | 34 +- .../core/parser/tests/PerformanceTests.java | 45 - .../tests/PreprocessorConditionalTest.java | 109 - .../tests/QuickParseASTQualifiedNameTest.java | 114 - .../core/parser/tests/QuickParseASTTests.java | 2245 ------ .../parser/tests/QuickParseProblemTests.java | 42 - .../parser/tests/ScannerParserLoopTest.java | 130 - .../core/parser/tests/ScannerSpeedTest.java | 116 - .../parser/tests/SelectionParseBaseTest.java | 68 - .../core/parser/tests/SelectionParseTest.java | 742 -- .../cdt/core/parser/tests/SpeedTest.java | 191 - .../parser/tests/StructuralParseTest.java | 141 - .../cdt/core/parser/tests/TortureTest.java | 289 - .../cdt/core/parser/tests/ast2/AST2Tests.java | 3 +- .../parser/tests/ast2/DOMScannerTests.java | 9 - .../tests/scanner/PortedScannerTests.java | 10 +- .../tests/scanner/PreprocessorTestsBase.java | 1 - .../tests/scanner2/BaseScanner2Test.java | 256 - .../tests/scanner2/DOMScannerSpeedTest.java | 5 +- .../scanner2/GCCScannerExtensionsTest.java | 78 - .../parser/tests/scanner2/IncludeTest.java | 186 - .../parser/tests/scanner2/Scanner2Test.java | 2692 ------- .../parser/tests/scanner2/SpeedTest2.java | 61 +- .../cdt/core/tests/RegressionTestSuite.java | 47 - .../core/tests/SelectionRegressionTest.java | 807 -- .../core/suite/AutomatedIntegrationSuite.java | 22 +- .../org.eclipse.cdt.core/META-INF/MANIFEST.MF | 8 - .../internal/core/model/CModelBuilder.java | 848 -- .../c/GCCScannerExtensionConfiguration.java | 20 - .../core/parser/DefaultProblemHandler.java | 50 - .../eclipse/cdt/core/parser/IOffsetDuple.java | 21 - .../org/eclipse/cdt/core/parser/IParser.java | 66 - .../cdt/core/parser/IQuickParseCallback.java | 29 - .../org/eclipse/cdt/core/parser/IScanner.java | 12 +- .../ISourceElementCallbackDelegate.java | 23 - .../core/parser/ISourceElementRequestor.java | 118 - .../org/eclipse/cdt/core/parser/IToken.java | 30 - .../eclipse/cdt/core/parser/ITokenDuple.java | 27 +- .../parser/NullSourceElementRequestor.java | 491 -- .../parser/OffsetLimitReachedException.java | 26 +- .../cdt/core/parser/ParserFactory.java | 92 +- .../cdt/core/parser/ParserFactoryError.java | 47 - .../cdt/core/parser/ast/ASTClassKind.java | 31 - .../ast/ASTExpressionEvaluationException.java | 19 - .../ast/ASTNotImplementedException.java | 19 - .../core/parser/ast/ASTPointerOperator.java | 44 - .../core/parser/ast/ASTSemanticException.java | 49 - .../eclipse/cdt/core/parser/ast/ASTUtil.java | 700 -- .../core/parser/ast/IASTASMDefinition.java | 22 - .../parser/ast/IASTAbstractDeclaration.java | 30 - .../IASTAbstractTypeSpecifierDeclaration.java | 21 - .../core/parser/ast/IASTArrayModifier.java | 23 - .../core/parser/ast/IASTBaseSpecifier.java | 28 - .../core/parser/ast/IASTClassReference.java | 20 - .../core/parser/ast/IASTClassSpecifier.java | 46 - .../cdt/core/parser/ast/IASTCodeScope.java | 32 - .../core/parser/ast/IASTCompilationUnit.java | 21 - .../core/parser/ast/IASTCompletionNode.java | 45 +- .../ast/IASTConstructorMemberInitializer.java | 25 - .../cdt/core/parser/ast/IASTDeclaration.java | 22 - .../cdt/core/parser/ast/IASTDesignator.java | 42 - .../ast/IASTElaboratedTypeSpecifier.java | 26 - .../parser/ast/IASTEnumerationReference.java | 19 - .../parser/ast/IASTEnumerationSpecifier.java | 29 - .../cdt/core/parser/ast/IASTEnumerator.java | 27 - .../parser/ast/IASTEnumeratorReference.java | 19 - .../ast/IASTExceptionSpecification.java | 22 - .../cdt/core/parser/ast/IASTExpression.java | 339 - .../cdt/core/parser/ast/IASTFactory.java | 275 - .../cdt/core/parser/ast/IASTField.java | 22 - .../core/parser/ast/IASTFieldReference.java | 19 - .../cdt/core/parser/ast/IASTFunction.java | 43 - .../parser/ast/IASTFunctionReference.java | 19 - .../cdt/core/parser/ast/IASTInclusion.java | 29 - .../parser/ast/IASTInitializerClause.java | 53 - .../parser/ast/IASTLinkageSpecification.java | 21 - .../cdt/core/parser/ast/IASTMacro.java | 27 - .../cdt/core/parser/ast/IASTMember.java | 20 - .../cdt/core/parser/ast/IASTMethod.java | 35 - .../core/parser/ast/IASTMethodReference.java | 19 - .../core/parser/ast/IASTNamespaceAlias.java | 24 - .../parser/ast/IASTNamespaceDefinition.java | 20 - .../parser/ast/IASTNamespaceReference.java | 19 - .../eclipse/cdt/core/parser/ast/IASTNode.java | 74 - .../parser/ast/IASTOffsetableElement.java | 30 - .../ast/IASTOffsetableNamedElement.java | 27 - .../parser/ast/IASTParameterDeclaration.java | 25 - .../parser/ast/IASTParameterReference.java | 19 - .../parser/ast/IASTPointerOperatorOwner.java | 20 - .../parser/ast/IASTQualifiedNameElement.java | 21 - .../cdt/core/parser/ast/IASTReference.java | 27 - .../cdt/core/parser/ast/IASTScope.java | 22 - .../core/parser/ast/IASTScopedElement.java | 20 - .../parser/ast/IASTScopedTypeSpecifier.java | 19 - .../parser/ast/IASTSimpleTypeSpecifier.java | 58 - .../cdt/core/parser/ast/IASTTemplate.java | 21 - .../parser/ast/IASTTemplateDeclaration.java | 23 - .../parser/ast/IASTTemplateInstantiation.java | 21 - .../parser/ast/IASTTemplateParameter.java | 43 - .../parser/ast/IASTTemplateParameterList.java | 22 - .../ast/IASTTemplateParameterReference.java | 26 - .../ast/IASTTemplateSpecialization.java | 19 - .../parser/ast/IASTTemplatedDeclaration.java | 20 - .../cdt/core/parser/ast/IASTTypeId.java | 44 - .../core/parser/ast/IASTTypeSpecifier.java | 19 - .../parser/ast/IASTTypeSpecifierOwner.java | 20 - .../parser/ast/IASTTypedefDeclaration.java | 24 - .../core/parser/ast/IASTTypedefReference.java | 19 - .../core/parser/ast/IASTUsingDeclaration.java | 26 - .../core/parser/ast/IASTUsingDirective.java | 21 - .../cdt/core/parser/ast/IASTVariable.java | 33 - .../parser/ast/IASTVariableReference.java | 19 - .../parser/ast/gcc/IASTGCCDesignator.java | 37 - .../parser/ast/gcc/IASTGCCExpression.java | 38 - .../ast/gcc/IASTGCCSimpleTypeSpecifier.java | 38 - .../parser/extension/ExtensionDialect.java | 31 - .../extension/IASTFactoryExtension.java | 78 - .../parser/extension/IParserExtension.java | 83 - .../extension/IParserExtensionFactory.java | 24 - .../cdt/core/parser/util/CharArrayPool.java | 87 - .../dom/parser/GCCBuiltinSymbolProvider.java | 25 +- .../dom/parser/c/CASTTranslationUnit.java | 4 +- .../core/dom/parser/c/GNUCSourceParser.java | 3 +- .../dom/parser/cpp/CPPASTTranslationUnit.java | 4 +- .../core/parser/BacktrackException.java | 90 - .../core/parser/DeclarationWrapper.java | 794 -- .../cdt/internal/core/parser/Declarator.java | 439 -- .../core/parser/{ast => }/EmptyIterator.java | 4 +- .../core/parser/GCCParserExtension.java | 491 -- .../cdt/internal/core/parser/IDeclarator.java | 46 - .../core/parser/IDeclaratorOwner.java | 23 - .../core/parser/IParameterCollection.java | 23 - .../cdt/internal/core/parser/IParserData.java | 121 - .../core/parser/ParameterCollection.java | 37 - .../cdt/internal/core/parser/Parser.java | 6957 ----------------- .../core/parser/ParserExtensionFactory.java | 54 - .../core/parser/ParserProblemFactory.java | 64 - .../core/parser/QuickParseCallback.java | 221 - .../core/parser/StructuralParseCallback.java | 267 - .../cdt/internal/core/parser/TypeId.java | 102 - .../parser/ast/ASTAbstractDeclaration.java | 148 - .../core/parser/ast/ASTArrayModifier.java | 62 - .../core/parser/ast/ASTCompletionNode.java | 102 - .../core/parser/ast/ASTDesignator.java | 91 - .../core/parser/ast/ASTInclusion.java | 214 - .../internal/core/parser/ast/ASTMacro.java | 180 - .../parser/ast/ASTQualifiedNamedElement.java | 83 - .../core/parser/ast/BaseASTFactory.java | 86 - .../core/parser/ast/GCCASTExtension.java | 156 - .../core/parser/ast/SymbolIterator.java | 92 - .../parser/ast/complete/ASTASMDefinition.java | 121 - .../ASTAbstractTypeSpecifierDeclaration.java | 218 - .../ast/complete/ASTAnonymousDeclaration.java | 39 - .../parser/ast/complete/ASTBaseSpecifier.java | 108 - .../ast/complete/ASTBinaryExpression.java | 96 - .../ast/complete/ASTClassReference.java | 86 - .../ast/complete/ASTClassSpecifier.java | 385 - .../parser/ast/complete/ASTCodeScope.java | 116 - .../ast/complete/ASTCompilationUnit.java | 93 - .../complete/ASTConditionalExpression.java | 99 - .../ASTConstructorMemberInitializer.java | 105 - .../complete/ASTElaboratedTypeSpecifier.java | 231 - .../ast/complete/ASTEmptyExpression.java | 96 - .../ast/complete/ASTEnumerationReference.java | 77 - .../ast/complete/ASTEnumerationSpecifier.java | 221 - .../parser/ast/complete/ASTEnumerator.java | 188 - .../ast/complete/ASTEnumeratorReference.java | 77 - .../complete/ASTExceptionSpecification.java | 42 - .../parser/ast/complete/ASTExpression.java | 302 - .../core/parser/ast/complete/ASTField.java | 74 - .../ast/complete/ASTFieldReference.java | 74 - .../core/parser/ast/complete/ASTFunction.java | 401 - .../ast/complete/ASTFunctionReference.java | 74 - .../parser/ast/complete/ASTIdExpression.java | 110 - .../ast/complete/ASTInitializerClause.java | 159 - .../ast/complete/ASTLinkageSpecification.java | 150 - .../ast/complete/ASTLiteralExpression.java | 101 - .../core/parser/ast/complete/ASTMethod.java | 252 - .../ast/complete/ASTMethodReference.java | 71 - .../ast/complete/ASTNamespaceAlias.java | 191 - .../ast/complete/ASTNamespaceDefinition.java | 223 - .../ast/complete/ASTNamespaceReference.java | 78 - .../parser/ast/complete/ASTNewDescriptor.java | 115 - .../parser/ast/complete/ASTNewExpression.java | 171 - .../core/parser/ast/complete/ASTNode.java | 180 - .../ast/complete/ASTParameterDeclaration.java | 251 - .../ast/complete/ASTParameterReference.java | 78 - .../ast/complete/ASTProblemFactory.java | 66 - .../parser/ast/complete/ASTReference.java | 90 - .../core/parser/ast/complete/ASTScope.java | 58 - .../ast/complete/ASTSimpleTypeSpecifier.java | 158 - .../core/parser/ast/complete/ASTSymbol.java | 85 - .../parser/ast/complete/ASTSymbolOwner.java | 43 - .../ast/complete/ASTTemplateDeclaration.java | 237 - .../complete/ASTTemplateInstantiation.java | 196 - .../ast/complete/ASTTemplateParameter.java | 224 - .../ASTTemplateParameterReference.java | 76 - .../complete/ASTTemplateSpecialization.java | 31 - .../core/parser/ast/complete/ASTTypeId.java | 252 - .../ast/complete/ASTTypeIdExpression.java | 118 - .../core/parser/ast/complete/ASTTypedef.java | 235 - .../ast/complete/ASTTypedefReference.java | 72 - .../ast/complete/ASTUnaryExpression.java | 141 - .../ast/complete/ASTUnaryIdExpression.java | 92 - .../complete/ASTUnaryTypeIdExpression.java | 75 - .../ast/complete/ASTUsingDeclaration.java | 221 - .../ast/complete/ASTUsingDirective.java | 215 - .../core/parser/ast/complete/ASTVariable.java | 289 - .../ast/complete/ASTVariableReference.java | 75 - .../ast/complete/CompleteParseASTFactory.java | 4142 ---------- .../ast/complete/ExpressionFactory.java | 59 - .../parser/ast/complete/ExpressionResult.java | 60 - .../ast/complete/ExpressionResultList.java | 65 - .../complete/UnresolvedReferenceDuple.java | 38 - .../gcc/ASTGCCSimpleTypeSpecifier.java | 57 - .../complete/gcc/GCCASTCompleteExtension.java | 707 -- .../core/parser/ast/gcc/ASTGCCDesignator.java | 56 - .../parser/ast/quick/ASTASMDefinition.java | 124 - .../ASTAbstractTypeSpecifierDeclaration.java | 217 - .../parser/ast/quick/ASTBaseSpecifier.java | 106 - .../parser/ast/quick/ASTBinaryExpression.java | 46 - .../parser/ast/quick/ASTClassSpecifier.java | 266 - .../parser/ast/quick/ASTCompilationUnit.java | 76 - .../ast/quick/ASTConditionalExpression.java | 47 - .../ASTConstructorMemberInitializer.java | 71 - .../core/parser/ast/quick/ASTDeclaration.java | 37 - ...DesignatedExpressionInitializerClause.java | 44 - ...natedInitializerListInitializerClause.java | 47 - .../ast/quick/ASTElaboratedTypeSpecifier.java | 202 - .../parser/ast/quick/ASTEmptyExpression.java | 34 - .../ast/quick/ASTEnumerationSpecifier.java | 197 - .../core/parser/ast/quick/ASTEnumerator.java | 192 - .../ast/quick/ASTExceptionSpecification.java | 67 - .../core/parser/ast/quick/ASTExpression.java | 295 - .../quick/ASTExpressionInitializerClause.java | 41 - .../core/parser/ast/quick/ASTField.java | 85 - .../core/parser/ast/quick/ASTFunction.java | 347 - .../parser/ast/quick/ASTIdExpression.java | 49 - .../ast/quick/ASTInitializerClause.java | 112 - .../ASTInitializerListInitializerClause.java | 46 - .../ast/quick/ASTLinkageSpecification.java | 150 - .../ast/quick/ASTLiteralExpression.java | 43 - .../core/parser/ast/quick/ASTMethod.java | 224 - .../parser/ast/quick/ASTNamespaceAlias.java | 188 - .../ast/quick/ASTNamespaceDefinition.java | 203 - .../parser/ast/quick/ASTNewDescriptor.java | 73 - .../parser/ast/quick/ASTNewExpression.java | 53 - .../core/parser/ast/quick/ASTNode.java | 41 - .../ast/quick/ASTParameterDeclaration.java | 170 - .../ast/quick/ASTScopedTypeSpecifier.java | 50 - .../ast/quick/ASTSimpleTypeSpecifier.java | 146 - .../ast/quick/ASTTemplateDeclaration.java | 174 - .../ast/quick/ASTTemplateInstantiation.java | 163 - .../ast/quick/ASTTemplateParameter.java | 219 - .../ast/quick/ASTTemplateSpecialization.java | 68 - .../core/parser/ast/quick/ASTTypeId.java | 184 - .../parser/ast/quick/ASTTypeIdExpression.java | 48 - .../ast/quick/ASTTypedefDeclaration.java | 203 - .../parser/ast/quick/ASTUnaryExpression.java | 43 - .../ast/quick/ASTUnaryIdExpression.java | 40 - .../ast/quick/ASTUnaryTypeIdExpression.java | 49 - .../parser/ast/quick/ASTUsingDeclaration.java | 197 - .../parser/ast/quick/ASTUsingDirective.java | 184 - .../core/parser/ast/quick/ASTVariable.java | 276 - .../parser/ast/quick/ExpressionFactory.java | 73 - .../ast/quick/GCCASTExpressionExtension.java | 145 - .../parser/ast/quick/IASTQClassSpecifier.java | 26 - .../core/parser/ast/quick/IASTQScope.java | 23 - .../ast/quick/QuickParseASTFactory.java | 393 - .../parser/pst/AbstractSymbolExtension.java | 50 - .../internal/core/parser/pst/BasicSymbol.java | 191 - .../core/parser/pst/BasicTypeInfo.java | 312 - .../core/parser/pst/ContainerSymbol.java | 1213 --- .../parser/pst/DeferredTemplateInstance.java | 115 - .../parser/pst/DerivableContainerSymbol.java | 523 -- .../core/parser/pst/ExtensibleSymbol.java | 78 - .../parser/pst/ExtensibleSymbolExtension.java | 67 - .../pst/ForewardDeclaredSymbolExtension.java | 109 - .../core/parser/pst/IContainerSymbol.java | 145 - .../parser/pst/IDeferredTemplateInstance.java | 24 - .../parser/pst/IDerivableContainerSymbol.java | 86 - .../core/parser/pst/IExtensibleSymbol.java | 39 - .../core/parser/pst/IParameterizedSymbol.java | 48 - .../core/parser/pst/ISpecializedSymbol.java | 41 - .../cdt/internal/core/parser/pst/ISymbol.java | 72 - .../core/parser/pst/ISymbolASTExtension.java | 35 - .../core/parser/pst/ISymbolOwner.java | 20 - .../core/parser/pst/ITemplateFactory.java | 23 - .../core/parser/pst/ITemplateSymbol.java | 83 - .../internal/core/parser/pst/ITypeInfo.java | 254 - .../parser/pst/IUsingDeclarationSymbol.java | 33 - .../parser/pst/IUsingDirectiveSymbol.java | 16 - .../parser/pst/NamespaceSymbolExtension.java | 99 - .../core/parser/pst/ParameterizedSymbol.java | 317 - .../core/parser/pst/ParserSymbolTable.java | 2509 ------ .../parser/pst/ParserSymbolTableError.java | 36 - .../pst/ParserSymbolTableException.java | 87 - .../core/parser/pst/SpecializedSymbol.java | 164 - .../parser/pst/StandardSymbolExtension.java | 94 - .../core/parser/pst/TemplateEngine.java | 1372 ---- .../core/parser/pst/TemplateFactory.java | 895 --- .../parser/pst/TemplateParameterTypeInfo.java | 36 - .../core/parser/pst/TemplateSymbol.java | 508 -- .../parser/pst/TemplateSymbolExtension.java | 50 - .../internal/core/parser/pst/TypeFilter.java | 136 - .../internal/core/parser/pst/TypeInfo.java | 95 - .../core/parser/pst/TypeInfoProvider.java | 282 - .../parser/pst/UndefinedTemplateSymbol.java | 756 -- .../parser/pst/UsingDeclarationSymbol.java | 35 - .../core/parser/pst/UsingDirectiveSymbol.java | 26 - .../core/parser/scanner/CPreprocessor.java | 19 +- .../internal/core/parser/scanner/Token.java | 25 - .../core/parser/scanner2/BaseScanner.java | 47 +- .../core/parser/scanner2/DOMScanner.java | 39 +- .../parser/scanner2/ExpressionEvaluator.java | 16 +- .../core/parser/scanner2/Scanner2.java | 360 - .../scanner2/ScannerCallbackManager.java | 67 - .../core/parser/scanner2/ScannerUtility.java | 52 +- .../core/parser/token/AbstractToken.java | 26 +- .../core/parser/token/BasicTokenDuple.java | 33 +- .../parser/token/ImagedExpansionToken.java | 46 - .../core/parser/token/ImagedToken.java | 68 - .../core/parser/token/OffsetDuple.java | 45 - .../core/parser/token/OperatorTokenDuple.java | 64 +- .../parser/token/SimpleExpansionToken.java | 42 - .../core/parser/token/SimpleToken.java | 11 +- .../core/parser/token/TemplateTokenDuple.java | 40 +- .../core/parser/token/TokenFactory.java | 38 +- .../org/eclipse/cdt/core/CConventions.java | 35 +- .../cdt/core/parser/CodeReaderCache.java | 2 +- .../cdt/core/parser/ParserTimeOut.java | 125 - .../PartialWorkingCopyCodeReaderFactory.java | 2 +- .../eclipse/cdt/ui/tests/DOMAST/DOMAST.java | 2 +- 363 files changed, 117 insertions(+), 73741 deletions(-) delete mode 100644 core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java delete mode 100644 core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/STLFailedTests.java delete mode 100644 core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/SelectionParseFailedTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseASTTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTSymbolIteratorTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseProblemTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseBaseTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FailingTemplateTests.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteParseExtensionsTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCParserExtensionTestSuite.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCQuickParseExtensionsTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCSelectionParseExtensionsTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/IScannerInfoPluginTest.java rename core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/{scanner2 => }/ObjectMapTest.java (98%) delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTemplateTests.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PerformanceTests.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTQualifiedNameTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseProblemTests.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerParserLoopTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerSpeedTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseBaseTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SpeedTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/StructuralParseTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/GCCScannerExtensionsTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/IncludeTest.java delete mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java delete mode 100644 core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/RegressionTestSuite.java delete mode 100644 core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SelectionRegressionTest.java delete mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/DefaultProblemHandler.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IOffsetDuple.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IQuickParseCallback.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementCallbackDelegate.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/NullSourceElementRequestor.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactoryError.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTClassKind.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTExpressionEvaluationException.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTNotImplementedException.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTPointerOperator.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTSemanticException.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTUtil.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTASMDefinition.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractTypeSpecifierDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTArrayModifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTBaseSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCodeScope.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompilationUnit.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTConstructorMemberInitializer.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDesignator.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTElaboratedTypeSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerationReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerationSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerator.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumeratorReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExceptionSpecification.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTField.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFieldReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFunction.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFunctionReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInclusion.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTLinkageSpecification.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMacro.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMember.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMethod.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMethodReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceAlias.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceDefinition.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableElement.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTParameterDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTParameterReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerOperatorOwner.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTQualifiedNameElement.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScope.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedElement.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedTypeSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTSimpleTypeSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplate.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateInstantiation.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameter.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameterList.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameterReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateSpecialization.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplatedDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeId.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeSpecifierOwner.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedefDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedefReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTVariable.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTVariableReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCDesignator.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCSimpleTypeSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/ExtensionDialect.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IASTFactoryExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IParserExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IParserExtensionFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayPool.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/BacktrackException.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/{ast => }/EmptyIterator.java (91%) delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/GCCParserExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IDeclarator.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IDeclaratorOwner.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParameterCollection.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserData.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParameterCollection.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserExtensionFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserProblemFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/StructuralParseCallback.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TypeId.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTAbstractDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTArrayModifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTCompletionNode.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTDesignator.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTQualifiedNamedElement.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/SymbolIterator.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTASMDefinition.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAbstractTypeSpecifierDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAnonymousDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBaseSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBinaryExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCodeScope.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCompilationUnit.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConditionalExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConstructorMemberInitializer.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTElaboratedTypeSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEmptyExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerator.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumeratorReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExceptionSpecification.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFieldReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunctionReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTIdExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTInitializerClause.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLinkageSpecification.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLiteralExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethodReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceAlias.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceDefinition.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewDescriptor.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTParameterDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTParameterReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTProblemFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTScope.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSimpleTypeSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbolOwner.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateInstantiation.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateParameter.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateParameterReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateSpecialization.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeId.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeIdExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypedef.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypedefReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryIdExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryTypeIdExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDirective.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariableReference.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionResult.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionResultList.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/UnresolvedReferenceDuple.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/ASTGCCSimpleTypeSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/GCCASTCompleteExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/gcc/ASTGCCDesignator.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTASMDefinition.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTAbstractTypeSpecifierDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTBaseSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTBinaryExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTClassSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTCompilationUnit.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTConditionalExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTConstructorMemberInitializer.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTDesignatedExpressionInitializerClause.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTDesignatedInitializerListInitializerClause.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTElaboratedTypeSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEmptyExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerationSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTEnumerator.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExceptionSpecification.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpressionInitializerClause.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTField.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTIdExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerClause.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerListInitializerClause.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLiteralExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTMethod.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceAlias.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNode.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTParameterDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTScopedTypeSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTSimpleTypeSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateInstantiation.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateParameter.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateSpecialization.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypeId.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypeIdExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedefDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryIdExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryTypeIdExpression.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ExpressionFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/GCCASTExpressionExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/IASTQClassSpecifier.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/IASTQScope.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/QuickParseASTFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/AbstractSymbolExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/BasicSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/BasicTypeInfo.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbolExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ForewardDeclaredSymbolExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IDeferredTemplateInstance.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IDerivableContainerSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IExtensibleSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IParameterizedSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISpecializedSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolOwner.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITemplateFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITemplateSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITypeInfo.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDeclarationSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDirectiveSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/NamespaceSymbolExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableError.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableException.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/SpecializedSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/StandardSymbolExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateFactory.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateParameterTypeInfo.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbolExtension.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfoProvider.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UndefinedTemplateSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDirectiveSymbol.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerCallbackManager.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedExpansionToken.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedToken.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/OffsetDuple.java delete mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleExpansionToken.java delete mode 100644 core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserTimeOut.java diff --git a/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF index ed632e3b1d3..1501d60234c 100644 --- a/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core.tests/META-INF/MANIFEST.MF @@ -9,8 +9,6 @@ Export-Package: org.eclipse.cdt.core.cdescriptor.tests, org.eclipse.cdt.core.internal.errorparsers.tests, org.eclipse.cdt.core.model.failedTests, org.eclipse.cdt.core.model.tests, - org.eclipse.cdt.core.parser.failedTests, - org.eclipse.cdt.core.parser.tests, org.eclipse.cdt.core.parser.tests.ast2, org.eclipse.cdt.core.parser.tests.prefix, org.eclipse.cdt.core.parser.tests.scanner2, diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java deleted file mode 100644 index 3ac0b6cc2e0..00000000000 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/ASTFailedTests.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.failedTests; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; - -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.tests.BaseASTTest; -/** - * @author jcamelon - * - */ -public class ASTFailedTests extends BaseASTTest -{ - - public ASTFailedTests(String name) - { - super(name); - } - public void testBug36730() throws Exception - { - assertCodeFailsParse("FUNCTION_MACRO( 1, a )\n int i;"); - } - - - //Here C99-specific section ends - //Here GCC-specific section starts - public void testBug39676() throws Exception - { - assertCodeFailsParse("struct { int e1, e2; } v = { e2: 0 }"); - } - - - public void testBug39679() throws Exception - { - assertCodeFailsParse("Foo blat() return f(4) {}"); - } - - - public void testBug39682() throws Exception - { - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)parse("typedef name = (a+1);").getDeclarations().next(); - assertFalse( - "The expected error did not occur.", - typedef.getName().equals( "name" ) ); - } - - public void testBug39687() throws Exception - { - assertCodeFailsParse("struct entry tester (int len; char data[len][len], int len) {}"); - } -// public void testBug39688() throws Exception -// { -// Writer code = new StringWriter(); -// try -// { -// code.write("#define decl(type, vars...) \\\n"); -// code.write(" type vars ;\n"); -// code.write("decl(int, x, y)\n"); -// } -// catch (IOException ioe) -// { -// } -// assertCodeFailsParse(code.toString()); -// } - - - public void testBug39695A() throws Exception - { - assertCodeFailsParse("int foo asm (\"myfoo\") = 2;"); - } - public void testBug39695B() throws Exception - { - assertCodeFailsParse("extern func () asm (\"FUNC\");"); - } - public void testBug39695C() throws Exception - { - assertCodeFailsParse("register int *foo asm (\"a5\");"); - } - - public void testBug39702() throws Exception - { - Writer code = new StringWriter(); - try - { - code.write("signature T {\n"); - code.write(" int f (int);\n"); - code.write(" int f0 () { return f (0); };\n"); - code.write("};\n"); - } - catch (IOException ioe) - { - } - assertCodeFailsFullParse(code.toString()); - } - - - public void testBug40422() throws Exception { - // Parse and get the translaton unit - parse("int A::* x = 0;").getDeclarations().next(); - } - -} diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java deleted file mode 100644 index c7f8028bc85..00000000000 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/FailedCompleteParseASTTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.failedTests; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest; -import org.eclipse.cdt.internal.core.parser.ParserException; -/** - * @author jcamelon - * - */ -public class FailedCompleteParseASTTest extends CompleteParseBaseTest -{ - /** - * - */ - public FailedCompleteParseASTTest() - { - super(); - } - /** - * @param name - */ - public FailedCompleteParseASTTest(String name) - { - super(name); - } - - public void testPMDotStarPointerToMemberFunction_Bug43242() throws Exception - { - //parse no longer passes - try{ - parse ("class A { int m(int); }; \n A a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a.*pm)(5));"); //$NON-NLS-1$ - fail(); - } catch ( ParserException e ){ - assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ - } -// Iterator i = parse ("class A { int m(int); }; \n A a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a.*pm)(5));").getDeclarations(); -// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); -// Iterator members = getDeclarations(cl); -// IASTMethod method = (IASTMethod)members.next(); -// IASTVariable a = (IASTVariable) i.next(); -// IASTVariable pm = (IASTVariable) i.next(); -// IASTFunction f1 = (IASTFunction) i.next(); -// IASTFunction f2 = (IASTFunction) i.next(); -// IASTVariable x = (IASTVariable) i.next(); -// -// assertAllReferences( 5 /* should be 8 */, -// createTaskList( new Task( cl, 2 /* should be 3 */ ), new Task( method ), new Task( a ), new Task( pm ) /* should be ,new Task( f2 ) */ -// )); - } - public void testPMArrowStarPointerToMemberFunction_Bug43242() throws Exception - { - //parse no longer passes - try{ - parse ("class A { int m(int); }; \n A * a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a->*pm)(5));"); //$NON-NLS-1$ - fail(); - } catch ( ParserException e ){ - assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ - } -// Iterator i = parse ("class A { int m(int); }; \n A * a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a->*pm)(5));").getDeclarations(); -// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); -// Iterator members = getDeclarations(cl); -// IASTMethod method = (IASTMethod)members.next(); -// IASTVariable a = (IASTVariable) i.next(); -// IASTVariable pm = (IASTVariable) i.next(); -// IASTFunction f1 = (IASTFunction) i.next(); -// IASTFunction f2 = (IASTFunction) i.next(); -// IASTVariable x = (IASTVariable) i.next(); -// -// assertAllReferences( 5 /* should be more */, -// createTaskList( new Task( cl, 2 ), new Task( method ), new Task( a /*, 2 */), new Task( pm )/* ,new Task( f2 )*/)); -// - } - public void testUnaryStarCastexpressionPointerToFunction_Bug43241() throws Exception - { - Iterator i = parse ("int m(int); \n int *pm = &m; \n int f(){} \n int f(int); \n int x = f((*pm)(5));").getDeclarations(); //$NON-NLS-1$ - IASTFunction m = (IASTFunction) i.next(); - IASTVariable pm = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 2 /* should be 3 */, - createTaskList( new Task( m ), new Task( pm ) /* ,new Task( f2 )*/)); - } - - // Kind DELETE_CASTEXPRESSION - // Kind DELETE_VECTORCASTEXPRESSION - // Kind CASTEXPRESSION - // Kind PM_DOTSTAR - public void testPMDotStar_bug43579() throws Exception - { - //parse no longer passes - try{ - parse ( "class A { int m; }; \n A a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a.*pm);" ); //$NON-NLS-1$ - fail(); - } catch ( ParserException e ){ - assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ - } -// Iterator i = parse ("class A { int m; }; \n A a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a.*pm);").getDeclarations(); -// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); -// IASTVariable a = (IASTVariable) i.next(); -// IASTVariable pm = (IASTVariable) i.next(); -// IASTFunction f1 = (IASTFunction) i.next(); -// IASTFunction f2 = (IASTFunction) i.next(); -// IASTVariable x = (IASTVariable) i.next(); -// assertFalse( i.hasNext() ); -// assertAllReferences( 4 /*should be 5 */, createTaskList( new Task( cl /* , 2 */ ), new Task( a), new Task( pm), new Task( f2))); - } - - // Kind PM_ARROWSTAR - public void testPMArrowStar_bug43579() throws Exception - { - //parse no longer passes - try{ - parse ("class A { int m; }; \n A * a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a->*pm);"); //$NON-NLS-1$ - fail(); - } catch ( ParserException e ){ - assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ - } -// Iterator i = parse ("class A { int m; }; \n A * a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a->*pm);").getDeclarations(); -// IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); -// IASTVariable a = (IASTVariable) i.next(); -// IASTVariable pm = (IASTVariable) i.next(); -// IASTFunction f1 = (IASTFunction) i.next(); -// IASTFunction f2 = (IASTFunction) i.next(); -// IASTVariable x = (IASTVariable) i.next(); -// assertFalse( i.hasNext() ); -// assertAllReferences( 4 /*should be 5 */, createTaskList( new Task( cl /* , 2 */ ), new Task( a), new Task( pm), new Task( f2))); - } -} diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/STLFailedTests.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/STLFailedTests.java deleted file mode 100644 index d516c3d5eb1..00000000000 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/STLFailedTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.failedTests; -import java.io.StringWriter; -import java.io.Writer; - -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.tests.BaseASTTest; - -/** - * @author hamer - */ -public class STLFailedTests extends BaseASTTest { - - public STLFailedTests(String name) { - super(name); - } - - public void testBug36805() throws Exception{ - Writer code = new StringWriter(); - code.write("__STL_BEGIN_NAMESPACE\n"); - code.write("template class char_traits\n"); - code.write(": public __char_traits_base<_CharT, _CharT>\n"); - code.write("{};\n"); - assertCodeFailsParse(code.toString()); - } - - public void testBug40714() throws Exception{ - // templates of variables - Writer code = new StringWriter(); - code.write("template \n"); - code.write("char* default_alloc_template<__threads, __inst>::_S_start_free = 0;\n"); - IASTCompilationUnit cu = parse(code.toString()); - IASTTemplateDeclaration templateDecl = (IASTTemplateDeclaration) cu.getDeclarations().next(); - // should not get this exception - IASTVariable v = (IASTVariable) templateDecl.getOwnedDeclaration(); - assertEquals( v, null ); - } - -} diff --git a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/SelectionParseFailedTest.java b/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/SelectionParseFailedTest.java deleted file mode 100644 index 60157f1efec..00000000000 --- a/core/org.eclipse.cdt.core.tests/failures/org/eclipse/cdt/core/parser/failedTests/SelectionParseFailedTest.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.failedTests; - -import org.eclipse.cdt.core.parser.tests.SelectionParseBaseTest; - -/** - * @author johnc - * - */ -public class SelectionParseFailedTest extends SelectionParseBaseTest { - - - -} diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java index 8a7493d592a..afb8b7f5065 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java @@ -88,6 +88,7 @@ public class StructuralCModelElementsTests extends TestCase { e.printStackTrace(); } } + CCorePlugin.getIndexManager().joinIndexer(10000, new NullProgressMonitor()); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedFramework.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedFramework.java index 87a65a07194..a1404537d55 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedFramework.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedFramework.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. + * Copyright (c) 2001, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -24,9 +24,6 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; - /** * @author aniefer * @@ -157,7 +154,6 @@ public abstract class AutomatedFramework extends TestCase { return suite; } - protected static ISourceElementRequestor nullCallback = new NullSourceElementRequestor(); protected static Properties properties = new Properties(); protected static String defaultNature; protected static String outputFile = null; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java deleted file mode 100644 index 44bf62e6ca2..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/AutomatedTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ - -package org.eclipse.cdt.core.parser.tests; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.NoSuchElementException; -import java.util.StringTokenizer; - -import junit.framework.AssertionFailedError; -import junit.framework.Test; - -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.testplugin.CTestPlugin; -import org.eclipse.core.runtime.Path; - - - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class AutomatedTest extends AutomatedFramework { - - public AutomatedTest() { - } - public AutomatedTest(String name){ - super(name); - } - - public void doFile() throws Throwable { - assertNotNull( fileList ); - - File file = null; - IParser parser = null; - - try{ - file = (File)fileList.removeFirst(); - - String filePath = file.getCanonicalPath(); - ParserLanguage language = ((String)natures.get( filePath )).equalsIgnoreCase("cpp") ? ParserLanguage.CPP : ParserLanguage.C; //$NON-NLS-1$ - parser = ParserFactory.createParser( ParserFactory.createScanner(filePath, new ScannerInfo(), ParserMode.QUICK_PARSE, language, nullCallback, null, null ), nullCallback, ParserMode.QUICK_PARSE, language, null); - - assertTrue( parser.parse() ); - } - catch( Throwable e ) - { - String output = null; - if( e instanceof AssertionFailedError ){ - output = file.getCanonicalPath() + ": Parse failed on line "; //$NON-NLS-1$ - output += parser.getLastErrorLine() + "\n"; //$NON-NLS-1$ - } else { - output = file.getCanonicalPath() + ": " + e.getClass().toString(); //$NON-NLS-1$ - output += " on line " + parser.getLastErrorLine() + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ - } - if( report != null ){ - report.write( output.getBytes() ); - } - - fail( output ); - } - } - - protected AutomatedFramework newTest( String name ){ - return new AutomatedTest( name ); - } - - public static Test suite() - { - AutomatedFramework frame = new AutomatedTest(); - - return frame.createSuite(); - } - - protected void tearDown () throws Exception { - if( fileList != null && fileList.size() == 0 && report != null ){ - report.flush(); - report.close(); - } - } - - protected void loadProperties() throws Exception{ - String resourcePath = CTestPlugin.getDefault().find(new Path("/")).getFile(); //$NON-NLS-1$ //$NON-NLS-2$ - resourcePath += "resources/parser/AutomatedTest"; //$NON-NLS-1$ - - try{ - FileInputStream propertiesIn = new FileInputStream( resourcePath + "/AutomatedTest.properties"); //$NON-NLS-1$ - properties.load( propertiesIn ); - - outputFile = properties.getProperty( "outputFile", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - String sourceInfo = properties.getProperty( "source", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - if( sourceInfo.equals("") ) //$NON-NLS-1$ - throw new FileNotFoundException(); - - StringTokenizer tokenizer = new StringTokenizer( sourceInfo, "," ); //$NON-NLS-1$ - String str = null, val = null; - try{ - while( tokenizer.hasMoreTokens() ){ - str = tokenizer.nextToken().trim(); - val = tokenizer.nextToken().trim(); - - testSources.put( str, val ); - } - } catch ( NoSuchElementException e ){ - //only way to get here is to have a missing val, assume cpp for that str - testSources.put( str, "cpp" ); //$NON-NLS-1$ - } - - } catch ( FileNotFoundException e ){ - testSources.put( resourcePath + "/defaultCpp", "cpp" ); //$NON-NLS-1$ //$NON-NLS-2$ - testSources.put( resourcePath + "/defaultC", "c" ); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseASTTest.java deleted file mode 100644 index 9b7ea0139d0..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseASTTest.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ParserException; -import org.eclipse.cdt.internal.core.parser.QuickParseCallback; - -/** - * @author jcamelon - * - */ -public class BaseASTTest extends TestCase -{ - /** - * @author jcamelon - * - */ - public class ProblemCallback extends QuickParseCallback implements - ISourceElementRequestor { - - List problems = new ArrayList(); - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem) - */ - public boolean acceptProblem(IProblem problem) { - problems.add( problem ); - return super.acceptProblem( problem ); - } - } - public BaseASTTest( String a ) - { - super( a ); - } - - protected ProblemCallback quickParseCallback; - protected IParser parser; - - protected IASTCompilationUnit parse( String code, boolean quick, boolean throwExceptionOnError, ParserLanguage lang ) throws ParserException, ParserFactoryError - { - ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; - quickParseCallback = new ProblemCallback(); - parser = ParserFactory.createParser( ParserFactory.createScanner( new CodeReader(code.toCharArray()), new ScannerInfo(), mode, lang, quickParseCallback, new NullLogService(), null), quickParseCallback, mode, lang, null ); //$NON-NLS-1$ - if( ! parser.parse() && throwExceptionOnError ) - throw new ParserException("Parse failure"); //$NON-NLS-1$ - return ((QuickParseCallback)quickParseCallback).getCompilationUnit(); - } - - - protected IASTCompilationUnit parse( String code, boolean quick, boolean throwExceptionOnError ) throws ParserException, ParserFactoryError - { - return parse( code, quick, throwExceptionOnError, ParserLanguage.CPP ); - } - - protected IASTCompilationUnit parse( String code )throws ParserException, ParserFactoryError - { - return parse( code, true, true ); - } - - protected IASTCompilationUnit fullParse( String code ) throws ParserException, ParserFactoryError - { - return parse( code, false, true ); - } - - protected IASTDeclaration assertSoleDeclaration( String code ) throws ParserException, ParserFactoryError - { - return assertSoleDeclaration( code, ParserLanguage.CPP ); - } - - protected IASTDeclaration assertSoleDeclaration( String code, ParserLanguage language ) throws ParserException, ParserFactoryError - { - Iterator declarationIter = null; - try - { - declarationIter = parse(code, true, true, language).getDeclarations(); - } - catch (ASTNotImplementedException e1) - { - // TODO Auto-generated catch block - } - - assertNotNull( declarationIter ); - assertTrue( declarationIter.hasNext() ); - IASTDeclaration returnValue = (IASTDeclaration)declarationIter.next(); - assertFalse( declarationIter.hasNext() ); - return returnValue; - } - - public void assertCodeFailsParse( String code ) - { - assertCodeFailsParse( code, true, true, ParserLanguage.CPP ); - } - - public void assertCodeFailsParse(String code, boolean quick, boolean throwOnError, ParserLanguage CPP ) { - boolean testPassed = false; - try { - parse(code, quick, throwOnError, CPP ); - testPassed = true; - fail( "We should not reach this point"); //$NON-NLS-1$ - } catch (Throwable e) { - if (!(e instanceof ParserException)) - fail("Unexpected Error: " + e.getMessage()); //$NON-NLS-1$ - } - if (testPassed) - fail("The expected error did not occur."); //$NON-NLS-1$ - } - - public void assertCodeFailsFullParse(String code) { - boolean testPassed = false; - try { - fullParse(code); - testPassed = true; - fail( "We should not reach this point"); //$NON-NLS-1$ - } catch (Throwable e) { - if (!(e instanceof ParserException)) - fail("Unexpected Error: " + e.getMessage()); //$NON-NLS-1$ - } - if (testPassed) - fail("The expected error did not occur."); //$NON-NLS-1$ - } - - protected void assertSimpleReturnType(IASTFunction function, IASTSimpleTypeSpecifier.Type type) - { - assertEquals( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).getType(), type ); - } - - protected void assertSimpleType(IASTTypedefDeclaration variable, IASTSimpleTypeSpecifier.Type type) - { - assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclarator().getTypeSpecifier()).getType(), type ); - } - - - protected void assertSimpleType(IASTVariable variable, IASTSimpleTypeSpecifier.Type type) - { - assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getType(), type ); - } - - protected void assertParameterSimpleType(IASTParameterDeclaration variable, IASTSimpleTypeSpecifier.Type type) - { - assertEquals( ((IASTSimpleTypeSpecifier)variable.getTypeSpecifier()).getType(), type ); - } - - protected void failedAsExpected() - { - assertFalse( "The expected error did not occur.", false ); //$NON-NLS-1$ - } - - protected void assertNotReached() - { - fail( "We should not reach this point"); //$NON-NLS-1$ - } - - protected void assertQualifiedName(String [] fromAST, String [] theTruth) - { - assertNotNull( fromAST ); - assertNotNull( theTruth ); - assertEquals( fromAST.length, theTruth.length ); - for( int i = 0; i < fromAST.length; ++i ) - { - assertEquals( fromAST[i], theTruth[i]); - } - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CharArrayUtilsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CharArrayUtilsTest.java index c3540b0b8d7..eca36f1e4e7 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CharArrayUtilsTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CharArrayUtilsTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,68 +13,12 @@ package org.eclipse.cdt.core.parser.tests; import junit.framework.TestCase; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.core.parser.util.CharArrayPool; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; /** * @author Doug Schaefer */ public class CharArrayUtilsTest extends TestCase { - public void testPoolAdd() { - CharArrayPool dict = new CharArrayPool(1); - - char[] str1 = new char[] {'h', 'e', 'l', 'l', 'o'}; - char[] str2 = dict.add(str1); - assertTrue(CharArrayUtils.equals(str1, str2)); - assertNotSame(str1, str2); - char[] str3 = dict.add(str1); - assertSame(str2, str3); - - char[] str4 = new char[] {'w', 'o', 'r', 'l', 'd'}; - char[] str5 = dict.add(str4, 0, str4.length); - assertTrue(CharArrayUtils.equals(str4, str5)); - assertNotSame(str4, str5); - char[] str6 = dict.add(str4); - assertSame(str5, str6); - - char[] str7 = dict.add(str1, 0, str1.length); - assertTrue(CharArrayUtils.equals(str1, str7)); - assertNotSame(str1, str7); - char[] str8 = dict.add(str1); - assertSame(str7, str8); - } - - public void testPoolConflict() { - CharArrayPool dict = new CharArrayPool(2); - - char[] str1 = new char[] {'h', 'e', 'l', 'l', 'o'}; - char[] str2 = dict.add(str1); - - // The hash algorithm should give this the same hash code - char[] str3 = new char[] {'h', 'o', 'l', 'l', 'e'}; - char[] str4 = dict.add(str3); - assertNotSame(str2, str4); - - char[] str5 = dict.add(str1); - assertTrue(CharArrayUtils.equals(str1, str5)); - - char[] str6 = new char[] {'w', 'o', 'r', 'l', 'd'}; - char[] str7 = dict.add(str6); - assertTrue(CharArrayUtils.equals(str6, str7)); - - char[] str8 = dict.add(str3); - assertSame(str4, str8); - - char[] str9 = dict.add(str1); - assertNotSame(str2, str9); - - // This should be the same since the removals are done by addition time, - // not access time - char[] str10 = dict.add(str6); - assertSame(str7, str10); - } - public void testMapAdd() { CharArrayObjectMap map = new CharArrayObjectMap(4); char[] key1 = "key1".toCharArray(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java deleted file mode 100644 index 21e42dedc31..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTExpressionTest.java +++ /dev/null @@ -1,1106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Rational Software - initial implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; - -/** - * @author hamer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class CompleteParseASTExpressionTest extends CompleteParseBaseTest{ - - public CompleteParseASTExpressionTest(String a) - { - super(a); - } - // Kind PRIMARY_EMPTY : void - public void testPrimaryEmpty() throws Exception - { - Iterator i = parse ("int f(char); \r\n int f(void); \r\n int x = f();").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences(1, createTaskList( new Task( f2 ) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f()" ); //$NON-NLS-1$ - } - // Kind PRIMARY_INTEGER_LITERAL : int - public void testPrimaryIntegerLiteral() throws Exception - { - Iterator i = parse ("int f(int, int); \n int f(int); \n int x = f(1, 2+3);").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f1 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(1, 2 + 3)" ); //$NON-NLS-1$ - } - // Kind PRIMARY_CHAR_LITERAL : char - public void testPrimaryCharLiteral() throws Exception - { - Iterator i = parse ("int f(char, int); \n int f(char); \n int x = f('c');").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f('c')" ); //$NON-NLS-1$ - } - // Kind PRIMARY_FLOAT_LITERAL : float - public void testPrimaryFloatLiteral() throws Exception - { - Iterator i = parse ("int f(char); \n int f(float); \n int x = f(1.13);").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(1.13)" ); //$NON-NLS-1$ - } - // Kind PRIMARY_STRING_LITERAL : char* - public void testPrimaryStringLiteral() throws Exception - { - Iterator i = parse ("int f(char); \n int f(char*); \n int x = f(\"str\");").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(\"str\")" ); //$NON-NLS-1$ - } - // Kind PRIMARY_BOOLEAN_LITERAL : bool - public void testPrimaryBooleanLiteral() throws Exception - { - Iterator i = parse ("int f(bool); \n int f(float); \n int x = f(true);").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f1 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(true)" ); //$NON-NLS-1$ - } - // Kind PRIMARY_THIS : type of inner most enclosing structure scope - public void testPrimaryThis() throws Exception - { - Iterator i = parse ("class A{ int m(); }; A a; \n int f(void); \n int f(A * a); \n int A::m(){ int x = f(this); }").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator members = getDeclarations(cl); - IASTMethod method = (IASTMethod)members.next(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTMethod m = (IASTMethod) i.next(); - Iterator r = callback.getReferences().iterator(); - assertAllReferences( 4, createTaskList( new Task( cl, 3 ), new Task( f2 ))); - - Iterator body = getDeclarations( m ); - IASTVariable x = (IASTVariable) body.next(); - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(this)" ); //$NON-NLS-1$ - } - // Kind PRIMARY_BRACKETED_EXPRESSION : LHS - public void testPrimaryBracketedExpression() throws Exception - { - Iterator i = parse ("int f(int, int); \n int f(int); \n int x = f(1, (2+3));").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f1 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(1, (2 + 3))" ); //$NON-NLS-1$ - } - // Kind ID_EXPRESSION : type of the ID - public void testIdExpression() throws Exception - { - Iterator i = parse ("class A{}a; \n int f(A a); \n int f(void); \n int x = f(a);").getDeclarations(); //$NON-NLS-1$ - - IASTVariable a = (IASTVariable) i.next(); - IASTClassSpecifier cl = (IASTClassSpecifier)a.getAbstractDeclaration().getTypeSpecifier(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - - assertAllReferences( 3, createTaskList( new Task( cl ), new Task( f1 ),new Task( a ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(a)" ); //$NON-NLS-1$ - } - // Kind ID_EXPRESSION ( refers to a pointer ) : pointer to type of ID - public void testIdExpressionToPointer() throws Exception - { - Iterator i = parse ("class A {}; \n A * pa; \n int f(A *ia){} \n int f(void); \n int x = f(pa);").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task( cl, 2 ), new Task( f1 ), new Task( a ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(pa)" ); //$NON-NLS-1$ - } - // Kind POSTFIX_SUBSCRIPT - public void testPostfixSubscript() throws Exception - { - Iterator i = parse ("int pa[10]; \n int f(int ia){} \n int f(void); \n int x = f(pa[1]);").getDeclarations(); //$NON-NLS-1$ - IASTVariable pa = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(pa[1])" ); //$NON-NLS-1$ - } - - public void testPostfixSubscriptA() throws Exception - { - Iterator i = parse ("int pa[10][5] ; \n int f(int ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations(); //$NON-NLS-1$ - IASTVariable pa = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(pa[1][2])" ); //$NON-NLS-1$ - } - - public void testPostfixSubscriptB() throws Exception - { - Iterator i = parse ("int* pa[10][5] ; \n int f(int* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations(); //$NON-NLS-1$ - IASTVariable pa = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 2, createTaskList( new Task( f1 ), new Task( pa ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(pa[1][2])" ); //$NON-NLS-1$ - } - - public void testPostfixSubscriptWithReferences() throws Exception - { - Iterator i = parse ("class A{}; \n A *pa[10][5] ; \n int f(A* ia){} \n int f(void); \n int x = f(pa[1][2]);").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable pa = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task( cl, 2 ), new Task( pa ), new Task( f1 ))); - } - - // Kind POSTFIX_FUNCTIONCALL : return type of called function - public void testPostfixFunctioncallBug42822() throws Exception - { - Iterator i = parse( "int foo( float b ); int bar( int a, int b ); int test( void ) { int x = bar( foo( 3.0 ), foo( 5.0 ) ) ; }").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction bar = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( bar ), new Task( foo, 2 ))); - - i = getDeclarations( test ); - IASTVariable x = (IASTVariable) i.next(); - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "bar(foo(3.0), foo(5.0))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_SIMPLETYPE_* : simple type - public void testPostfixSimpletypesBug42823() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "void foo( int anInt, short aShort, double aDouble, float aFloat, char aChar, wchar_t aWchar, signed aSigned, unsigned anUnsigned, bool aBool, long aLong );"); //$NON-NLS-1$ - buffer.append( "void test( void ) { int someInt = foo( int(3), short(4), double(3.0), float(4.0), char( 'a'), wchar_t( 'a' ), signed( 2 ), unsigned( 3 ), bool( false ), long( 3L ) ); }"); //$NON-NLS-1$ - Iterator i = parse( buffer.toString() ).getDeclarations(); - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 1, createTaskList( new Task( foo ))); - - i = getDeclarations( test ); - IASTVariable someInt = (IASTVariable) i.next(); - IASTExpression exp = someInt.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(int(3), short(4), double(3.0), float(4.0), char('a'), wchar_t('a'), signed(2), unsigned(3), bool(false), long(3L))" ); //$NON-NLS-1$ - } - - // Kind POSTFIX_TYPENAME_IDENTIFIER - public void testPostfixTypenameIdentifier() throws Exception{ - Iterator i = parse( "class A {}; \n int foo(); int foo( A a ); \n int x = foo( typename A() );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 3, createTaskList( new Task( cl, 2 ), new Task( f2) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typename A())" ); //$NON-NLS-1$ - } - - // Kind POSTFIX_TYPENAME_TEMPLATEID - public void testPostfixTypeNameTemplateId() throws Exception{ - Iterator i = parse( " template class A {}; int foo( A a ); \n int x = foo( typename template A< int >() );").getDeclarations(); //$NON-NLS-1$ - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - IASTFunction f = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 3, createTaskList( new Task( A, 2 ), new Task( f ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typename template A())" ); //$NON-NLS-1$ - } - - public void testPostfixTypeNameTemplateId_2() throws Exception{ - Iterator i = parse( "namespace NS{ template class A {}; } int foo( NS::A a ); \n int x = foo( typename NS::template A< int >() );").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition NS = (IASTNamespaceDefinition) i.next(); - IASTFunction f = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - - i = getDeclarations( NS ); - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - - assertAllReferences( 5, createTaskList( new Task( NS, 2 ), new Task( A, 2 ), new Task( f ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typename NS::template A())" ); //$NON-NLS-1$ - } - - // Kind POSTFIX_DOT_IDEXPRESSION : type of member in the scope of the container - public void testPostfixDotExpression() throws Exception{ - Iterator i = parse( "class A {int m;}; \n A a; \n int foo(char); int foo( int ); \n int x = foo( a.m );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - Iterator members = getDeclarations(cl); - IASTField m = (IASTField)members.next(); - assertAllReferences( 4, createTaskList( new Task(cl), new Task(a), new Task(m), new Task(f2) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a.m)" ); //$NON-NLS-1$ - } - // Kind POSTFIX_ARROW_IDEXPRESSION : type of member in the scope of the container - public void testPostfixArrowExpression() throws Exception{ - Iterator i = parse( "class A {int m;}; \n A * a; \n int foo(char); int foo( int ); \n int x = foo( a->m );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - Iterator members = getDeclarations(cl); - IASTField m = (IASTField)members.next(); - assertAllReferences( 4, createTaskList( new Task(cl), new Task(a), new Task(m), new Task(f2) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a->m)" ); //$NON-NLS-1$ - } - // Kind POSTFIX_DOT_TEMPL_IDEXPRESS - // Kind POSTFIX_ARROW_TEMPL_IDEXP - - // Kind POSTFIX_DOT_DESTRUCTOR - // Kind POSTFIX_ARROW_DESTRUCTOR - - // Kind POSTFIX_INCREMENT : LHS - public void testPostfixIncrement() throws Exception - { - Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( x++ ); } ").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - Iterator subDecls = getDeclarations( test ); - IASTVariable x = (IASTVariable)subDecls.next(); - IASTVariable y = (IASTVariable)subDecls.next(); - assertFalse( subDecls.hasNext() ); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(x++)" ); //$NON-NLS-1$ - } - // Kind POSTFIX_DECREMENT : LHS - public void testPostfixDecrement() throws Exception - { - Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( x-- ); } ").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - Iterator subDecls = getDeclarations( test ); - IASTVariable x = (IASTVariable)subDecls.next(); - IASTVariable y = (IASTVariable)subDecls.next(); - assertFalse( subDecls.hasNext() ); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(x--)" ); //$NON-NLS-1$ - } - // Kind POSTFIX_DYNAMIC_CAST - public void testPostfixDynamicCast() throws Exception{ - Iterator i = parse( "class A {}; class B : public A{}; \n A *a; \n int foo(); int foo( B* ); \n int x = foo( dynamic_cast(a) );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 6, createTaskList( new Task( cla, 2 ), new Task( clb, 2), new Task(a), new Task(f2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(dynamic_cast(a))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_REINTERPRET_CAST - public void testPostfixReinterpretCast() throws Exception{ - Iterator i = parse( "int *a; \n int foo(); int foo( double* ); \n int x = foo( reinterpret_cast(a) );").getDeclarations(); //$NON-NLS-1$ - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(reinterpret_cast(a))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_STATIC_CAST - public void testPostfixStaticCast() throws Exception{ - Iterator i = parse( "int a; \n int foo(); int foo( char ); \n int x = foo( static_cast(a) );").getDeclarations(); //$NON-NLS-1$ - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(static_cast(a))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_CONST_CAST - public void testPostfixConstCast() throws Exception{ - Iterator i = parse( "const int a; \n int foo(); int foo( int * ); \n int x = foo( const_cast(&a) );").getDeclarations(); //$NON-NLS-1$ - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(a), new Task(f2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(const_cast(&a))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_TYPEID_EXPRESSION : LHS - public void testPostfixTypeIdExpression() throws Exception{ - Iterator i = parse( "int foo(char); int foo( int ); \n int x = foo( typeid(5) );").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 1, createTaskList( new Task( f2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typeid(5))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_TYPEID_EXPRESSION : type of the ID - public void testPostfixTypeIdExpression2() throws Exception{ - Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(a) );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task(cl, 2),new Task(a),new Task(f1))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typeid(a))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_TYPEID_TYPEID : type of the ID - public void testPostfixTypeIdTypeId() throws Exception{ - Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(A) );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typeid(A))" ); //$NON-NLS-1$ - } - // Kind POSTFIX_TYPEID_TYPEID : type of the ID - public void testPostfixTypeIdTypeId2() throws Exception{ - Iterator i = parse( "class A {}; \n A a; \n int foo(A); int foo( int ); \n int x = foo( typeid(const A) );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task(cl, 3), new Task(f1))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(typeid(const A))" ); //$NON-NLS-1$ - } - // Kind UNARY_INCREMENT : LHS - public void testUnaryIncrement() throws Exception - { - Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( ++x ); } ").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - Iterator subDecls = getDeclarations( test ); - IASTVariable x = (IASTVariable)subDecls.next(); - IASTVariable y = (IASTVariable)subDecls.next(); - assertFalse( subDecls.hasNext() ); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(foo2), new Task(x) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(++x)" ); //$NON-NLS-1$ - } - // Kind UNARY_DECREMENT : LHS - public void testUnaryDecrement() throws Exception - { - Iterator i = parse( "void foo(); int foo( int ); void test( void ) { int x = 5; int y = foo( --x ); } ").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTFunction test = (IASTFunction)i.next(); - Iterator subDecls = getDeclarations( test ); - IASTVariable x = (IASTVariable)subDecls.next(); - IASTVariable y = (IASTVariable)subDecls.next(); - assertFalse( subDecls.hasNext() ); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(foo2), new Task(x) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(--x)" ); //$NON-NLS-1$ - } - // Kind UNARY_STAR_CASTEXPRESSION : LHS + t_pointer - public void testUnaryStarCastExpression() throws Exception - { - Iterator i = parse ("class A {}; \n A * pa; \n int f(A ia){} \n int f(void); \n int x = f(*pa);").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task(cl, 2 ), new Task( a ), new Task(f1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(*pa)" ); //$NON-NLS-1$ - } - // Kind UNARY_AMPSND_CASTEXPRESSION : LHS + t_reference - public void testUnaryAmpersandCastExpression() throws Exception - { - Iterator i = parse ("class A {}; \n A * pa; \n int f(A ** ia){} \n int f(void); \n int x = f(&pa);").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertAllReferences( 4, createTaskList( new Task(cl, 2 ), new Task( a ), new Task(f1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "f(&pa)" ); //$NON-NLS-1$ - } - // Kind UNARY_PLUS_CASTEXPRESSION : LHS - public void testUnaryPlusCastExpression() throws Exception { - Iterator i = parse( "void foo(); int foo( int ); int x = foo( +5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 1, createTaskList( new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(+5)" ); //$NON-NLS-1$ - } - // Kind UNARY_MINUS_CASTEXPRESSION : LHS - public void testUnaryMinusCastExpression() throws Exception { - Iterator i = parse( "void foo(); int foo( int ); int x = foo( -5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 1, createTaskList( new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(-5)" ); //$NON-NLS-1$ - } - // Kind UNARY_NOT_CASTEXPRESSION : LHS - public void testUnaryNotCastExpression() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); bool b=true; int x = foo( !b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( b ), new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(!b)" ); //$NON-NLS-1$ - } - // Kind UNARY_TILDE_CASTEXPRESSION : LHS - public void testTildeNotCastExpression() throws Exception { - Iterator i = parse( "void foo(); int foo( int ); int x = 5; int y = foo( ~x );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - IASTVariable y = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(~x)" ); //$NON-NLS-1$ - } - // Kind UNARY_SIZEOF_UNARYEXPRESSION : unsigned int - public void testUnarySizeofUnaryExpression() throws Exception { - Iterator i = parse( "void foo(); int foo( int ); int x = 5; int y = foo( sizeof(5) );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - IASTVariable y = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 1, createTaskList( new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(sizeof (5))" ); //$NON-NLS-1$ - } - // Kind UNARY_SIZEOF_TYPEID : unsigned int - public void testUnarySizeofTypeId() throws Exception { - Iterator i = parse( "void foo(); int foo( int ); int x = 5; int y = foo( sizeof(x) );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - IASTVariable y = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( x ), new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "5" ); //$NON-NLS-1$ - exp = y.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(sizeof (x))" ); //$NON-NLS-1$ - } - // Kind NEW_NEWTYPEID - // Kind NEW_TYPEID - public void testNewTypeId() throws Exception { - Iterator i = parse( "class A{}; void foo(); int foo( A * a ); int x = foo( new A() );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( cl, 2), new Task( foo2 ))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(new A())" ); //$NON-NLS-1$ - } - - // Kind DELETE_CASTEXPRESSION - // Kind DELETE_VECTORCASTEXPRESSION - - // Kind CASTEXPRESSION - public void testCastExpression() throws Exception{ - Iterator i = parse( "class A {}; class B : public A{}; \n B *b; \n int foo(); int foo( A* ); \n int x = foo( (A*)b );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable b = (IASTVariable) i.next(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - IASTVariable x = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 6, createTaskList( new Task( cla, 3 ), new Task( clb, 1), new Task(b), new Task(f2))); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo((A*)b)" ); //$NON-NLS-1$ - } - - // Kind PM_DOTSTAR - // failed - - // Kind PM_ARROWSTAR - // failed - - // Kind MULTIPLICATIVE_MULTIPLY : usual arithmetic conversions - public void testMultiplicativeMultiply() throws Exception { - Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( a * b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 3 ); - assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a * b)" ); //$NON-NLS-1$ - } - // Kind MULTIPLICATIVE_DIVIDE : usual arithmetic conversions - public void testMultiplicativeDivide() throws Exception { - Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b / a );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b / a)" ); //$NON-NLS-1$ - } - // Kind MULTIPLICATIVE_MODULUS : usual arithmetic conversions - public void testMultiplicativeModulus() throws Exception { - Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b % a );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b % a)" ); //$NON-NLS-1$ - } - // Kind ADDITIVE_PLUS : usual arithmetic conversions - public void testAdditivePlus() throws Exception { - Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b + a );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b + a)" ); //$NON-NLS-1$ - } - // Kind ADDITIVE_MINUS : usual arithmetic conversions - public void testAdditiveMinus() throws Exception { - Iterator i = parse( "int foo(int); int foo( float ); int a = 3; float b=5.1 ; int x = foo( b - a );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task(a), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b - a)" ); //$NON-NLS-1$ - } - // Kind SHIFT_LEFT : LHS - public void testShiftLeft() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a << 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a << 5)" ); //$NON-NLS-1$ - } - // Kind SHIFT_RIGHT : LHS - public void testShiftRight() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a >> 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(a), new Task( foo1 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a >> 5)" ); //$NON-NLS-1$ - } - // Kind RELATIONAL_LESSTHAN : bool - public void testRelationalLessThan() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b < 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b < 3)" ); //$NON-NLS-1$ - } - // Kind RELATIONAL_GREATERTHAN : bool - public void testRelationalGreaterThan() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b > 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b > 3)" ); //$NON-NLS-1$ - } - // Kind RELATIONAL_LESSTHANEQUALTO : bool - public void testRelationalLessThanOrEqual() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b <= 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b <= 3)" ); //$NON-NLS-1$ - } - // Kind RELATIONAL_GREATERTHANEQUALTO : bool - public void testRelationalGreaterThanOrEqual() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b >= 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b >= 3)" ); //$NON-NLS-1$ - } - // Kind EQUALITY_EQUALS : bool - public void testEqualityEquals() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b == 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b == 3)" ); //$NON-NLS-1$ - } - // Kind EQUALITY_NOTEQUALS : bool - public void testEqualityNotEquals() throws Exception { - Iterator i = parse( "void foo(); int foo( bool ); int b=5; int x = foo( b != 3 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 2, createTaskList( new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(b != 3)" ); //$NON-NLS-1$ - } - // Kind ANDEXPRESSION : usual arithmetic conversions - public void testAndExpression() throws Exception { - Iterator i = parse( "int foo(); int foo( int ); int a = 3; int b= 5; int x = foo( a & b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a & b)" ); //$NON-NLS-1$ - } - // Kind EXCLUSIVEOREXPRESSION : usual arithmetic conversions - public void testExclusiveOrExpression() throws Exception { - Iterator i = parse( "int foo(); int foo( int ); int a = 3; int b= 5; int x = foo( a ^ b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a ^ b)" ); //$NON-NLS-1$ - } - // Kind INCLUSIVEOREXPRESSION : : usual arithmetic conversions - public void testInclusiveOrExpression() throws Exception { - Iterator i = parse( "int foo(); int foo( int ); int a = 3; int b= 5; int x = foo( a | b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a | b)" ); //$NON-NLS-1$ - } - // Kind LOGICALANDEXPRESSION : bool - public void testLogicalAndExpression() throws Exception { - Iterator i = parse( "int foo(); int foo( bool ); bool a = true; bool b= false; int x = foo( a && b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a && b)" ); //$NON-NLS-1$ - } - // Kind LOGICALOREXPRESSION : bool - public void testLogicalOrExpression() throws Exception { - Iterator i = parse( "int foo(); int foo( bool ); bool a = true; bool b= false; int x = foo( a || b );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 3, createTaskList( new Task( a ), new Task(b), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a || b)" ); //$NON-NLS-1$ - } - // Kind CONDITIONALEXPRESSION : conditional Expression Conversions - public void testConditionalExpression() throws Exception { - Iterator i = parse( "int foo(bool); int foo(int); int a = 10, b = 4, c = 2; int x = foo( a > 5 ? b : c );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable c = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 4, createTaskList( new Task( a ), new Task(b), new Task( c ), new Task( foo2 ) ) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a > 5 ? b : c)" ); //$NON-NLS-1$ - } - // Kind CONDITIONALEXPRESSION with references : conditional Expression Conversions - public void testConditionalExpressionWithReferencesA() throws Exception { - Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A*); A *a ; B *b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable c = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(8, createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c ), new Task( b ), new Task( a ), new Task( foo2 )) ); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(c > 5 ? b : a)" ); //$NON-NLS-1$ - } - public void testConditionalExpressionWithReferencesB_Bug43106() throws Exception { - Iterator i = parse( "class A{}; class B : public A{}; int foo(); int foo(A&); A a ; B b; int c = 0; int x = foo( c > 5 ? b : a );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier cla = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier clb = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable b = (IASTVariable)i.next(); - IASTVariable c = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 8, - createTaskList( new Task( cla, 3 ), new Task( clb ), new Task( c), new Task( b ), new Task( a ), new Task( foo2) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(c > 5 ? b : a)" ); //$NON-NLS-1$ - } - // Kind THROWEXPRESSION - - // Kind ASSIGNMENTEXPRESSION_NORMAL : LHS - public void testAssignmentExpressionNormal() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a = 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a = 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_PLUS : LHS - public void testAssignmentExpressionPlus() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a += 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a += 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_MINUS : LHS - public void testAssignmentExpressionMinus() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a -= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a -= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_MULT : LHS - public void testAssignmentExpressionMulti() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a *= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a *= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_DIV : LHS - public void testAssignmentExpressionDiv() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a /= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a /= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_MOD : LHS - public void testAssignmentExpressionMod() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a %= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a %= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_LSHIFT : LHS - public void testAssignmentExpressionLShift() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a >>= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a >>= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_RSHIFT : LHS - public void testAssignmentExpressionRShift() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a <<= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a <<= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_AND : LHS - public void testAssignmentExpressionAnd() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a &= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a &= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_OR : LHS - public void testAssignmentExpressionOr() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a |= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a |= 5)" ); //$NON-NLS-1$ - } - // Kind ASSIGNMENTEXPRESSION_XOR : LHS - public void testAssignmentExpressionXOr() throws Exception { - Iterator i = parse( "int foo(int); int foo( bool ); int a = 10; int x = foo( a ^= 5 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)i.next(); - IASTVariable x = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences(2, createTaskList( new Task(a), new Task(foo1) )); - - IASTExpression exp = x.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.toString(), "foo(a ^= 5)" ); //$NON-NLS-1$ - } - // Kind EXPRESSIONLIST : list of LHS, RHS - // Already tested with each test trying to find a reference to function. - - - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTSymbolIteratorTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTSymbolIteratorTest.java deleted file mode 100644 index 69d2cec30aa..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTSymbolIteratorTest.java +++ /dev/null @@ -1,424 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Feb 25, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.Iterator; -import java.util.NoSuchElementException; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ParserException; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class CompleteParseASTSymbolIteratorTest extends CompleteParseBaseTest { - public CompleteParseASTSymbolIteratorTest(String a) - { - super(a); - } - - public static class CompilationUnitCallback extends NullSourceElementRequestor implements ISourceElementRequestor { - IASTCompilationUnit compilationUnit; - - public void enterCompilationUnit(IASTCompilationUnit compUnit) - { - compilationUnit = compUnit; - } - - public IASTCompilationUnit getCompilationUnit(){ - return compilationUnit; - } - } - - protected CompilationUnitCallback localCallback; - - protected IASTScope parse(String code, boolean throwOnError, ParserLanguage language) throws ParserException, ParserFactoryError - { - localCallback = new CompilationUnitCallback(); - IParser parser = ParserFactory.createParser( - ParserFactory.createScanner( new CodeReader(code.toCharArray()), new ScannerInfo(), - ParserMode.COMPLETE_PARSE, language, localCallback, new NullLogService(), null ), localCallback, ParserMode.COMPLETE_PARSE, language, null - ); - if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ - - return localCallback.getCompilationUnit(); - } - - protected Iterator getDeclarations(IASTScope scope) - { - //don't want to use this - assertTrue( false ); - return null; - } - - public void testEmptyCompilationUnit() throws Exception - { - IASTScope compilationUnit = parse( "// no real code "); //$NON-NLS-1$ - - assertNotNull( compilationUnit ); - assertFalse( compilationUnit.getDeclarations().hasNext() ); - try{ - compilationUnit.getDeclarations().next(); - assertTrue( false ); - } catch( NoSuchElementException e ){ - - } - } - - public void testSimpleNamespace() throws Exception - { - Iterator declarations = parse( "namespace A { }").getDeclarations(); //$NON-NLS-1$ - - IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); - assertEquals( namespaceDefinition.getName(), "A" ); //$NON-NLS-1$ - assertFalse( namespaceDefinition.getDeclarations().hasNext() ); - - try{ - declarations.remove(); - assertTrue( false ); - } catch( UnsupportedOperationException e ){ - } - } - - public void testMultipleNamespaceDefinitions() throws Exception - { - Iterator declarations = parse( "namespace A { } namespace A { }").getDeclarations(); //$NON-NLS-1$ - - IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); - assertEquals( namespaceDefinition.getName(), "A" ); //$NON-NLS-1$ - assertFalse( declarations.hasNext() ); - } - - public void testNestedNamespaceDefinitions() throws Exception - { - Iterator declarations = parse( "namespace A { namespace B { } }").getDeclarations(); //$NON-NLS-1$ - - IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); - assertEquals( namespaceDefinition.getName(), "A" ); //$NON-NLS-1$ - assertFalse( declarations.hasNext() ); - - Iterator subDeclarations = namespaceDefinition.getDeclarations(); - IASTNamespaceDefinition subDeclaration = (IASTNamespaceDefinition)subDeclarations.next(); - assertEquals( subDeclaration.getName(), "B" ); //$NON-NLS-1$ - assertFalse( subDeclarations.hasNext() ); - } - - public void testEmptyClassDeclaration() throws Exception - { - Iterator declarations = parse( "class A { };").getDeclarations(); //$NON-NLS-1$ - - IASTClassSpecifier classSpec = (IASTClassSpecifier)declarations.next(); - assertEquals( classSpec.getName(), "A"); //$NON-NLS-1$ - assertFalse( classSpec.getDeclarations().hasNext() ); - assertFalse( declarations.hasNext() ); - } - - public void testNestedSubclass() throws Exception - { - Iterator declarations = parse( "namespace N { class A { }; } class B : protected virtual N::A { };").getDeclarations(); //$NON-NLS-1$ - - IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); - - Iterator nsDecls = namespaceDefinition.getDeclarations(); - IASTClassSpecifier classA = (IASTClassSpecifier)nsDecls.next(); - assertFalse( nsDecls.hasNext() ); - - IASTClassSpecifier classB = (IASTClassSpecifier)declarations.next(); - - Iterator baseClauses = classB.getBaseClauses(); - IASTBaseSpecifier baseClass = (IASTBaseSpecifier)baseClauses.next(); - assertEquals( classA, baseClass.getParentClassSpecifier() ); - } - - public void testSimpleVariable() throws Exception - { - Iterator declarations = parse( "int x;").getDeclarations(); //$NON-NLS-1$ - IASTVariable v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertFalse( declarations.hasNext() ); - } - - public void testSimpleClassReferenceVariable() throws Exception - { - Iterator declarations = parse( "class A { } a; A x;").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next(); - assertFalse( classA.getDeclarations().hasNext() ); - - IASTVariable a = (IASTVariable)declarations.next(); - assertEquals( a.getName(), "a"); //$NON-NLS-1$ - - IASTVariable v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA ); - assertFalse( declarations.hasNext() ); - } - - public void testMultipleDeclaratorsVariable() throws Exception - { - Iterator declarations = parse( "class A { }; A x, y, z;").getDeclarations(); //$NON-NLS-1$ - - IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next(); - - IASTVariable v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - - v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "y"); //$NON-NLS-1$ - - v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "z"); //$NON-NLS-1$ - - assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA ); - - assertFalse( declarations.hasNext() ); - } - - public void testSimpleField() throws Exception - { - Iterator declarations = parse( "class A { double x; };").getDeclarations(); //$NON-NLS-1$ - - IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next(); - - Iterator fields = classA.getDeclarations(); - - IASTField f = (IASTField)fields.next(); - - assertEquals( f.getName(), "x" ); //$NON-NLS-1$ - - assertFalse( fields.hasNext() ); - assertFalse( declarations.hasNext() ); - } - - - - public void testSimpleFunction() throws Exception - { - Iterator declarations = parse( "void foo( void );").getDeclarations(); //$NON-NLS-1$ - IASTFunction function = (IASTFunction)declarations.next(); - assertEquals( function.getName(), "foo" ); //$NON-NLS-1$ - assertFalse( declarations.hasNext() ); - } - - public void testSimpleMethod() throws Exception - { - Iterator declarations = parse( "class A { void foo(); };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next(); - - IASTMethod method = (IASTMethod) classA.getDeclarations().next(); - assertEquals( method.getName(), "foo" ); //$NON-NLS-1$ - } - - public void testLinkageSpec() throws Exception - { - Iterator declarations = parse( "extern \"C\" { int foo(); }").getDeclarations(); //$NON-NLS-1$ - - //7.5-4 A linkage specification does not establish a scope - IASTFunction f = (IASTFunction)declarations.next(); - assertEquals( f.getName(),"foo"); //$NON-NLS-1$ - assertFalse( declarations.hasNext() ); - } - - public void testSimpleTypedef() throws Exception - { - Iterator iter = parse( "typedef int myInt;\n myInt var;").getDeclarations(); //$NON-NLS-1$ - - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)iter.next(); - - assertEquals( typedef.getName(), "myInt"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)typedef.getAbstractDeclarator().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - - IASTVariable v = (IASTVariable)iter.next(); - assertEquals( v.getName(), "var"); //$NON-NLS-1$ - - assertFalse( iter.hasNext() ); - - } - - public void testOverride() throws Exception - { - Iterator i = parse( "void foo();\n void foo( int );\n").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction)i.next(); - IASTFunction f2 = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - } - - public void testEnumerations() throws Exception - { - Iterator declarations = parse( "namespace A { enum E { e1, e2, e3 }; E varE;}").getDeclarations(); //$NON-NLS-1$ - - IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)declarations.next(); - - Iterator namespaceMembers = namespaceA.getDeclarations(); - - IASTEnumerationSpecifier enumE = (IASTEnumerationSpecifier)namespaceMembers.next(); - - assertEquals( enumE.getName(), "E"); //$NON-NLS-1$ - assertQualifiedName( enumE.getFullyQualifiedName(), new String [] { "A", "E" } ); //$NON-NLS-1$ //$NON-NLS-2$ - - Iterator enumerators = enumE.getEnumerators(); - IASTEnumerator enumerator_e1 = (IASTEnumerator)enumerators.next(); - IASTEnumerator enumerator_e2 = (IASTEnumerator)enumerators.next(); - IASTEnumerator enumerator_e3 = (IASTEnumerator)enumerators.next(); - assertFalse( enumerators.hasNext() ); - assertEquals( enumerator_e1.getName(), "e1"); //$NON-NLS-1$ - assertEquals( enumerator_e2.getName(), "e2"); //$NON-NLS-1$ - assertEquals( enumerator_e3.getName(), "e3"); //$NON-NLS-1$ - - IASTVariable varE = (IASTVariable)namespaceMembers.next(); - assertEquals( ((IASTSimpleTypeSpecifier)varE.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), enumE ); - - assertFalse( namespaceMembers.hasNext() ); - assertFalse( declarations.hasNext() ); - } - - public void testMethodDefinitions() throws Exception - { - Iterator i = parse( " class A { void f(); }; void A::f(){ }" ).getDeclarations(); //$NON-NLS-1$ - - IASTClassSpecifier classA = (IASTClassSpecifier) i.next(); - assertFalse( i.hasNext() ); - - i = classA.getDeclarations(); - - IASTMethod f = (IASTMethod)i.next(); - - assertFalse( i.hasNext() ); - } - - public void testConstructorsDestructors() throws Exception - { - Iterator i = parse( "class A { A(); ~A(); }; A::A(){} A::~A(){}" ).getDeclarations(); //$NON-NLS-1$ - - IASTClassSpecifier classA = (IASTClassSpecifier) i.next(); - - assertFalse( i.hasNext() ); - - i = classA.getDeclarations(); - assertTrue( i.hasNext() ); - - IASTMethod constructor = (IASTMethod) i.next(); - assertTrue( constructor.getName().equals( "A" ) ); //$NON-NLS-1$ - IASTMethod destructor = (IASTMethod) i.next(); - assertTrue( destructor.getName().equals( "~A" ) ); //$NON-NLS-1$ - - assertFalse( i.hasNext() ); - } - - public void testUsingDirectives() throws Exception - { - Iterator i = parse( "namespace NS { int i; } using namespace NS;" ).getDeclarations(); //$NON-NLS-1$ - - IASTNamespaceDefinition ns = (IASTNamespaceDefinition) i.next(); - IASTUsingDirective using = (IASTUsingDirective) i.next(); - assertFalse( i.hasNext() ); - } - - public void testUsingDeclaration() throws Exception - { - Iterator i = parse( "namespace NS{ void f(); void f( int ); }; using NS::f;" ).getDeclarations(); //$NON-NLS-1$ - - IASTNamespaceDefinition ns = (IASTNamespaceDefinition) i.next(); - IASTUsingDeclaration using = (IASTUsingDeclaration) i.next(); - assertFalse( i.hasNext() ); - } - - public void testBug75482() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "class A { friend class B * helper(); };" ); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier A = (IASTClassSpecifier) i.next(); - IASTFunction helper = (IASTFunction) i.next(); - i = A.getDeclarations(); - IASTElaboratedTypeSpecifier B = (IASTElaboratedTypeSpecifier) i.next(); - assertFalse( i.hasNext() ); - - i = A.getFriends(); - assertEquals( i.next(), helper ); - assertFalse( i.hasNext() ); - } - - public void testBug77010() throws Exception - { - Writer writer = new StringWriter(); - writer.write(" struct Example{ \n"); //$NON-NLS-1$ - writer.write(" int *deref(); \n"); //$NON-NLS-1$ - writer.write(" int const *deref() const; \n"); //$NON-NLS-1$ - writer.write(" int volatile *deref() volatile; \n"); //$NON-NLS-1$ - writer.write(" int const volatile *deref() const volatile; \n"); //$NON-NLS-1$ - writer.write(" }; \n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier Example = (IASTClassSpecifier) i.next(); - assertFalse( i.hasNext() ); - i = Example.getDeclarations(); - IASTMethod deref = (IASTMethod) i.next(); - assertFalse( deref.getReturnType().isConst() ); - assertFalse( deref.getReturnType().isVolatile() ); - assertFalse( deref.isConst() ); - assertFalse( deref.isVolatile() ); - - deref = (IASTMethod) i.next(); - assertTrue( deref.getReturnType().isConst() ); - assertFalse( deref.getReturnType().isVolatile() ); - assertTrue( deref.isConst() ); - assertFalse( deref.isVolatile() ); - - deref = (IASTMethod) i.next(); - assertFalse( deref.getReturnType().isConst() ); - assertTrue( deref.getReturnType().isVolatile() ); - assertFalse( deref.isConst() ); - assertTrue( deref.isVolatile() ); - - deref = (IASTMethod) i.next(); - assertTrue( deref.getReturnType().isConst() ); - assertTrue( deref.getReturnType().isVolatile() ); - assertTrue( deref.isConst() ); - assertTrue( deref.isVolatile() ); - assertFalse( i.hasNext() ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java deleted file mode 100644 index b671c96e43e..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTemplateTest.java +++ /dev/null @@ -1,1242 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ - /* - * Created on Mar 30, 2004 - */ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ParserException; - -/** - * @author aniefer - */ -public class CompleteParseASTTemplateTest extends CompleteParseBaseTest { - /** - * @param name - */ - public CompleteParseASTTemplateTest(String name) { - super(name); - } - - public void testTemplateClassDeclaration() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < class T > class A { T t; }; " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - Iterator params = template.getTemplateParameters(); - - IASTTemplateParameter T = (IASTTemplateParameter) params.next(); - assertEquals( T.getIdentifier(), "T" ); //$NON-NLS-1$ - assertFalse( params.hasNext() ); - assertFalse( i.hasNext() ); - - i = getDeclarations( template ); - - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertEquals( classA.getName(), "A" ); //$NON-NLS-1$ - - assertFalse( i.hasNext() ); - - i = getDeclarations( classA ); - - IASTField t = (IASTField) i.next(); - assertEquals( t.getName(), "t" ); //$NON-NLS-1$ - - IASTSimpleTypeSpecifier specifier = (IASTSimpleTypeSpecifier) t.getAbstractDeclaration().getTypeSpecifier(); - assertEquals( specifier.getTypename(), "T" ); //$NON-NLS-1$ - //assertEquals( specifier.getTypeSpecifier(), T ); //TODO uncomment when bug 54029 is fixed - } - - public void testTemplateFunction() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < class T > void f( T t ){} " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - - Iterator params = template.getTemplateParameters(); - - IASTTemplateParameter T = (IASTTemplateParameter) params.next(); - assertEquals( T.getIdentifier(), "T" ); //$NON-NLS-1$ - assertFalse( params.hasNext() ); - assertFalse( i.hasNext() ); - - i = getDeclarations( template ); - IASTFunction f = (IASTFunction) i.next(); - assertEquals( f.getName(), "f" ); //$NON-NLS-1$ - - params = f.getParameters(); - IASTParameterDeclaration t = (IASTParameterDeclaration) params.next(); - assertEquals( t.getName(), "t" ); //$NON-NLS-1$ - IASTSimpleTypeSpecifier typeSpec = (IASTSimpleTypeSpecifier) t.getTypeSpecifier(); - assertEquals( typeSpec.getTypename(), "T" ); //$NON-NLS-1$ - //assertEquals( typeSpec.getTypeSpecifier(), T ); //TODO uncomment when bug 54029 is fixed - } - - public void testTemplateFunctionDefinition() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template void f( T t );" ); //$NON-NLS-1$ - writer.write( "template void f( U u ) { }" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - - Iterator params = template.getTemplateParameters(); - - IASTTemplateParameter T = (IASTTemplateParameter) params.next(); - assertEquals( T.getIdentifier(), "T" ); //$NON-NLS-1$ - assertFalse( params.hasNext() ); - - Iterator tempDecls = getDeclarations( template ); - IASTFunction f = (IASTFunction) tempDecls.next(); - assertEquals( f.getName(), "f" ); //$NON-NLS-1$ - assertFalse( f.hasFunctionBody() ); - assertFalse( tempDecls.hasNext() ); - - params = f.getParameters(); - IASTParameterDeclaration t = (IASTParameterDeclaration) params.next(); - assertEquals( t.getName(), "t" ); //$NON-NLS-1$ - IASTSimpleTypeSpecifier typeSpec = (IASTSimpleTypeSpecifier) t.getTypeSpecifier(); - assertEquals( typeSpec.getTypename(), "T" ); //$NON-NLS-1$ - //assertEquals( typeSpec.getTypeSpecifier(), T ); //TODO uncomment when bug 54029 is fixed - - IASTTemplateDeclaration template2 = (IASTTemplateDeclaration) i.next(); - - params = template2.getTemplateParameters(); - - IASTTemplateParameter U = (IASTTemplateParameter) params.next(); - assertEquals( U.getIdentifier(), "U" ); //$NON-NLS-1$ - assertFalse( params.hasNext() ); - - tempDecls = getDeclarations( template2 ); - IASTFunction f2 = (IASTFunction) tempDecls.next(); - assertEquals( f2.getName(), "f" ); //$NON-NLS-1$ - assertTrue( f2.previouslyDeclared() ); - - params = f2.getParameters(); - IASTParameterDeclaration u = (IASTParameterDeclaration) params.next(); - assertEquals( u.getName(), "u" ); //$NON-NLS-1$ - typeSpec = (IASTSimpleTypeSpecifier) u.getTypeSpecifier(); - assertEquals( typeSpec.getTypename(), "U" ); //$NON-NLS-1$ - //assertEquals( typeSpec.getTypeSpecifier(), U ); //TODO uncomment when bug 54029 is fixed - - assertFalse( i.hasNext() ); - } - - public void testClassMemberTemplate() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "namespace N { " ); //$NON-NLS-1$ - writer.write( " class A { " ); //$NON-NLS-1$ - writer.write( " template < class T > T f();" ); //$NON-NLS-1$ - writer.write( " }; " ); //$NON-NLS-1$ - writer.write( "}" ); //$NON-NLS-1$ - writer.write( "template U N::A::f() {} " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTNamespaceDefinition N = (IASTNamespaceDefinition) i.next(); - - Iterator i2 = getDeclarations( N ); - - IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i2.next()).getTypeSpecifier(); - assertFalse( i2.hasNext() ); - - i2 = getDeclarations( A ); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i2.next(); - Iterator params = template.getTemplateParameters(); - IASTTemplateParameter T = (IASTTemplateParameter) params.next(); - assertFalse( params.hasNext() ); - assertFalse( i2.hasNext() ); - - i2 = getDeclarations( template ); - - IASTMethod f = (IASTMethod) i2.next(); - assertEquals( ((IASTSimpleTypeSpecifier)f.getReturnType().getTypeSpecifier()).getTypename(), "T" ); //$NON-NLS-1$ - assertFalse( i2.hasNext() ); - - IASTTemplateDeclaration template2 = (IASTTemplateDeclaration) i.next(); - params = template.getTemplateParameters(); - IASTTemplateParameter U = (IASTTemplateParameter) params.next(); - assertFalse( params.hasNext() ); - assertFalse( i.hasNext() ); - - i2 = getDeclarations( template2 ); - - IASTMethod f2 = (IASTMethod) i2.next(); - assertEquals( ((IASTSimpleTypeSpecifier)f2.getReturnType().getTypeSpecifier()).getTypename(), "U" ); //$NON-NLS-1$ - assertQualifiedName( f2.getFullyQualifiedName(), new String [] { "N", "A", "f" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - assertTrue( f2.previouslyDeclared() ); - assertFalse( i2.hasNext() ); - } - - public void testOverloadedFunctionTemplates() throws Exception - { - Writer writer = new StringWriter(); - writer.write( " template < class T > void f ( T ) {} " ); //$NON-NLS-1$ - writer.write( " template < class T > void f ( T * ) {} " ); //$NON-NLS-1$ - writer.write( " int * p;" ); //$NON-NLS-1$ - writer.write( " void main () {" ); //$NON-NLS-1$ - writer.write( " f( p );" ); //$NON-NLS-1$ - writer.write( " f( *p );" ); //$NON-NLS-1$ - writer.write( " }" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T1 = (IASTTemplateParameter) template1.getTemplateParameters().next(); - - IASTFunction f1 = (IASTFunction) template1.getOwnedDeclaration(); - - IASTTemplateDeclaration template2 = (IASTTemplateDeclaration) i.next(); - IASTFunction f2 = (IASTFunction) template2.getOwnedDeclaration(); - IASTTemplateParameter T2 = (IASTTemplateParameter) template2.getTemplateParameters().next(); - - IASTVariable p = (IASTVariable) i.next(); - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - assertAllReferences( 6, createTaskList( new Task( T1 ), - new Task( T2 ), - new Task( f1, 1, false, false ), - new Task( p, 2 ), - new Task( f2, 1, false, false ) ) ); - - } - - public void testOverloadedFunctionTemplates_2() throws Exception - { - Writer writer = new StringWriter(); - writer.write("template< class T > struct A { }; \n"); //$NON-NLS-1$ - writer.write("template< class T > void h( const T & ); //#1 \n"); //$NON-NLS-1$ - writer.write("template< class T > void h( A& ); //#2 \n"); //$NON-NLS-1$ - writer.write("void foo() { \n"); //$NON-NLS-1$ - writer.write(" A z; \n"); //$NON-NLS-1$ - writer.write(" h( z ); //calls 2 \n"); //$NON-NLS-1$ - - writer.write(" const A z2; \n"); //$NON-NLS-1$ - writer.write(" h( z2 ); //calls 1 because 2 is not callable. \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateA = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateh1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateh2 = (IASTTemplateDeclaration) i.next(); - - IASTClassSpecifier A = (IASTClassSpecifier) templateA.getOwnedDeclaration(); - IASTFunction h1 = (IASTFunction) templateh1.getOwnedDeclaration(); - IASTFunction h2 = (IASTFunction) templateh2.getOwnedDeclaration(); - - IASTTemplateParameter T1 = (IASTTemplateParameter) templateA.getTemplateParameters().next(); - IASTTemplateParameter T2 = (IASTTemplateParameter) templateh1.getTemplateParameters().next(); - IASTTemplateParameter T3 = (IASTTemplateParameter) templateh2.getTemplateParameters().next(); - - IASTFunction foo = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - i = getDeclarations( foo ); - IASTVariable z = (IASTVariable) i.next(); - IASTVariable z2 = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - - assertEquals( ((IASTSimpleTypeSpecifier)z.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A ); - assertEquals( ((IASTSimpleTypeSpecifier)z2.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A ); - - assertAllReferences( 9, createTaskList( new Task( T2 ), - new Task( T3 ), - new Task( A, 3 ), - new Task( z ), - new Task( z2 ), - new Task( h1, 1, false, false ), - new Task( h2, 1, false, false ) ) ); - - - } - - public void testTemplateClassPartialSpecialization() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < class T1, class T2, int I > class A {}; //#1\n" ); //$NON-NLS-1$ - writer.write( "template < class T, int I > class A < T, T*, I > {}; //#2\n"); //$NON-NLS-1$ - writer.write( "template < class T1, class T2, int I > class A < T1*, T2, I > {}; //#3\n"); //$NON-NLS-1$ - writer.write( "template < class T > class A < int, T*, 5 > {}; //#4\n"); //$NON-NLS-1$ - writer.write( "template < class T1, class T2, int I > class A < T1, T2*, I > {}; //#5\n"); //$NON-NLS-1$ - - writer.write( "A a1; //uses #1 \n"); //$NON-NLS-1$ - writer.write( "A a2; //uses #2, T is int, I is 1 \n"); //$NON-NLS-1$ - writer.write( "A a4; //uses #4, T is char \n"); //$NON-NLS-1$ - writer.write( "A a5; //uses #5, T is int, T2 is char, I is1 \n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - writer.write( " A amgiguous; //ambiguous, matches #3 & #5 \n"); //$NON-NLS-1$ - - try{ - //we expect this parse to fail because of the ambiguity in the last line - parse( writer.toString() ); - assertFalse( true ); - } catch ( ParserException e ){ - assertEquals( e.getMessage(), "FAILURE" ); //$NON-NLS-1$ - } - - IASTTemplateDeclaration template1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec2 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec3 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec4 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec5 = (IASTTemplateDeclaration) i.next(); - - IASTVariable a1 = (IASTVariable) i.next(); - IASTVariable a2 = (IASTVariable) i.next(); - IASTVariable a4 = (IASTVariable) i.next(); - IASTVariable a5 = (IASTVariable) i.next(); - - assertFalse( i.hasNext() ); - - IASTClassSpecifier A1 = (IASTClassSpecifier)template1.getOwnedDeclaration(); - IASTClassSpecifier A2 = (IASTClassSpecifier)spec2.getOwnedDeclaration(); - IASTClassSpecifier A3 = (IASTClassSpecifier)spec3.getOwnedDeclaration(); - IASTClassSpecifier A4 = (IASTClassSpecifier)spec4.getOwnedDeclaration(); - IASTClassSpecifier A5 = (IASTClassSpecifier)spec5.getOwnedDeclaration(); - - assertEquals( ((IASTSimpleTypeSpecifier)a1.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A1 ); - assertEquals( ((IASTSimpleTypeSpecifier)a2.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A2 ); - assertEquals( ((IASTSimpleTypeSpecifier)a4.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A4 ); - assertEquals( ((IASTSimpleTypeSpecifier)a5.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), A5 ); - - } - - public void testTemplateInstanceAsBaseClause() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template< class T > class A { T t; }; \n" ); //$NON-NLS-1$ - writer.write( "class B : public A< int > {}; \n" ); //$NON-NLS-1$ - writer.write( "void f( int ); \n" ); //$NON-NLS-1$ - - writer.write( "void main(){ \n" ); //$NON-NLS-1$ - writer.write( " B b; \n" ); //$NON-NLS-1$ - writer.write( " f( b.t ); \n" ); //if this function call is good, it implies that b.t is type int //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T = (IASTTemplateParameter) template.getTemplateParameters().next(); - IASTClassSpecifier B = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction f = (IASTFunction) i.next(); - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - i = getDeclarations( A ); - IASTField t = (IASTField) i.next(); - assertFalse( i.hasNext() ); - - i = getDeclarations( main ); - - IASTVariable b = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - - assertAllReferences( 6, createTaskList( new Task( T ), - new Task( A ), - new Task( B ), - new Task( b ), - new Task( t ), - new Task( f ) ) ); - } - - public void testTemplateParameterAsBaseClause() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < class T > class A : public T {}; \n" ); //$NON-NLS-1$ - writer.write( "class B { int i; }; \n" ); //$NON-NLS-1$ - writer.write( "void main() { \n" ); //$NON-NLS-1$ - writer.write( " A a; \n" ); //$NON-NLS-1$ - writer.write( " a.i; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "\n" ); //$NON-NLS-1$ - - Iterator iter = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) iter.next(); - IASTTemplateParameter T = (IASTTemplateParameter) template.getTemplateParameters().next(); - IASTClassSpecifier B = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)iter.next()).getTypeSpecifier(); - IASTFunction main = (IASTFunction) iter.next(); - assertFalse( iter.hasNext() ); - - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - - iter = getDeclarations( B ); - IASTVariable i = (IASTVariable) iter.next(); - - iter = getDeclarations( main ); - IASTVariable a = (IASTVariable) iter.next(); - - assertAllReferences( 5, createTaskList( new Task( T ), new Task( A ), new Task( B ), new Task( a ), new Task( i ) ) ); - } - - public void testTypedefedTemplate() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template < class T > class _A{ int x; }; \n" ); //$NON-NLS-1$ - writer.write( "typedef _A < char > A; \n" ); //$NON-NLS-1$ - writer.write( "void foo() { \n" ); //$NON-NLS-1$ - writer.write( " A a; \n" ); //$NON-NLS-1$ - writer.write( " a.x; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration _A = (IASTTemplateDeclaration) i.next(); - IASTTypedefDeclaration A = (IASTTypedefDeclaration) i.next(); - IASTFunction foo = (IASTFunction) i.next(); - - IASTClassSpecifier classA = (IASTClassSpecifier) _A.getOwnedDeclaration(); - IASTVariable x = (IASTVariable) getDeclarations( classA ).next(); - IASTVariable a = (IASTVariable) getDeclarations( foo ).next(); - - assertAllReferences( 4, createTaskList( new Task( classA ), new Task( A ), new Task( a ), new Task( x ) ) ); - } - - public void testTypedefedTemplate_2() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template < class T > struct A { T x; }; \n" ); //$NON-NLS-1$ - writer.write( "template < class U > struct B { \n" ); //$NON-NLS-1$ - writer.write( " typedef A< U > AU; \n" ); //$NON-NLS-1$ - writer.write( " void f( U ); \n" ); //$NON-NLS-1$ - writer.write( " void f( char ); \n" ); //$NON-NLS-1$ - writer.write( " void g(){ \n" ); //$NON-NLS-1$ - writer.write( " AU au; \n" ); //$NON-NLS-1$ - writer.write( " f( au.x ); \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void f2( int ); \n" ); //$NON-NLS-1$ - writer.write( "void f2( char ); \n" ); //$NON-NLS-1$ - writer.write( "void h(){ \n" ); //$NON-NLS-1$ - writer.write( " B< int >::AU b; \n" ); //$NON-NLS-1$ - writer.write( " f2( b.x ); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration tA = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T = (IASTTemplateParameter) tA.getTemplateParameters().next(); - IASTClassSpecifier A = (IASTClassSpecifier) tA.getOwnedDeclaration(); - IASTField x = (IASTField) getDeclarations( A ).next(); - IASTTemplateDeclaration tB = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier B = (IASTClassSpecifier) tB.getOwnedDeclaration(); - IASTTemplateParameter U = (IASTTemplateParameter) tB.getTemplateParameters().next(); - IASTFunction f21 = (IASTFunction) i.next(); - IASTFunction f22 = (IASTFunction) i.next(); - IASTFunction h = (IASTFunction) i.next(); - - i = getDeclarations( B ); - IASTTypedefDeclaration AU = (IASTTypedefDeclaration) i.next(); - IASTMethod f11 = (IASTMethod) i.next(); - IASTMethod f12 = (IASTMethod) i.next(); - IASTMethod g = (IASTMethod) i.next(); - - IASTVariable au = (IASTVariable) getDeclarations( g ).next(); - IASTVariable b = (IASTVariable) getDeclarations( h ).next(); - - assertAllReferences( 13, createTaskList( new Task( A ), - new Task( T ), - new Task( U, 2 ), - new Task( AU, 2 ), - new Task( au ), - new Task( x, 2 ), - new Task( f11, 1, false, false ), - new Task( B ), - new Task( b ), - new Task( f21, 1, false, false ) ) ); - } - - public void testInstantiatingDeferredInstances() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template < class T > struct A { A < T > next; }; \n" ); //$NON-NLS-1$ - writer.write( "A< int > a; \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T = (IASTTemplateParameter) template.getTemplateParameters().next(); - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - IASTField next = (IASTField) getDeclarations( A ).next(); - IASTVariable a = (IASTVariable) i.next(); - - assertAllReferences( 3, createTaskList( new Task( A, 2 ), new Task( T ) ) ); - } - - public void testTemplateArgumentDeduction() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template< class T > struct B {}; \n" ); //$NON-NLS-1$ - writer.write( "template< class T > struct D : public B < T > {}; \n" ); //$NON-NLS-1$ - writer.write( "struct D2 : public B< int > {}; \n" ); //$NON-NLS-1$ - writer.write( "template< class T > T f( B & ) {} \n" ); //$NON-NLS-1$ - writer.write( "void test( int ); \n" ); //$NON-NLS-1$ - writer.write( "void test( char ); \n" ); //$NON-NLS-1$ - writer.write( "void main() { \n" ); //$NON-NLS-1$ - writer.write( " D d; \n" ); //$NON-NLS-1$ - writer.write( " D2 d2; \n" ); //$NON-NLS-1$ - writer.write( " test( f( d ) ); \n" ); //$NON-NLS-1$ - writer.write( " test( f( d2 ) ); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateB = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateD = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier D2 = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTTemplateDeclaration templateF = (IASTTemplateDeclaration) i.next(); - IASTFunction test1 = (IASTFunction) i.next(); - IASTFunction test2 = (IASTFunction) i.next(); - IASTFunction main = (IASTFunction) i.next(); - - assertFalse( i.hasNext() ); - assertReferenceTask( new Task( test1, 2, false, false ) ); - } - public void testClassTemplateStaticMemberDefinition() throws Exception { - Writer writer = new StringWriter(); - writer.write( "template< class T > class A{ \n" ); //$NON-NLS-1$ - writer.write( " typedef T * PT; \n" ); //$NON-NLS-1$ - writer.write( " static T * member; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "template< class T> A::PT A::member = null; \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T1 = (IASTTemplateParameter) template.getTemplateParameters().next(); - IASTTemplateDeclaration template2 = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T2 = (IASTTemplateParameter) template2.getTemplateParameters().next(); - - IASTField member = (IASTField) getDeclarations( template2 ).next(); - assertEquals( member.getName(), "member" ); //$NON-NLS-1$ - - assertReferenceTask( new Task( T1, 2, false, false ) ); - assertReferenceTask( new Task( T2, 2, false, false ) ); - } - - public void testTemplateTemplateParameter() throws Exception{ - Writer writer = new StringWriter(); - writer.write( " template< class T > class A { "); //$NON-NLS-1$ - writer.write( " int x; "); //$NON-NLS-1$ - writer.write( " }; "); //$NON-NLS-1$ - writer.write( " template < class T > class A < T * > { "); //$NON-NLS-1$ - writer.write( " long x; "); //$NON-NLS-1$ - writer.write( " }; "); //$NON-NLS-1$ - writer.write( " template< template< class U > class V > class C{ "); //$NON-NLS-1$ - writer.write( " V< int > y; "); //$NON-NLS-1$ - writer.write( " V< int * > z; "); //$NON-NLS-1$ - writer.write( " }; "); //$NON-NLS-1$ - writer.write( " void f( int ); "); //$NON-NLS-1$ - writer.write( " void f( long ); "); //$NON-NLS-1$ - writer.write( " void main() { "); //$NON-NLS-1$ - writer.write( " C< A > c; "); //$NON-NLS-1$ - writer.write( " f( c.y.x ); "); //$NON-NLS-1$ - writer.write( " f( c.z.x ); "); //$NON-NLS-1$ - writer.write( " } "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateA = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateA2 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateC = (IASTTemplateDeclaration) i.next(); - - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - - IASTFunction main = (IASTFunction) i.next(); - IASTVariable c = (IASTVariable) getDeclarations( main ).next(); - - IASTSimpleTypeSpecifier spec = (IASTSimpleTypeSpecifier) c.getAbstractDeclaration().getTypeSpecifier(); - IASTClassSpecifier C = (IASTClassSpecifier) spec.getTypeSpecifier(); - - assertReferenceTask( new Task( f1, 1, false, false ) ); - assertReferenceTask( new Task( f2, 1, false, false ) ); - } - - public void testBug56834() throws Exception{ - Iterator i = parse( "template < class T, class U = T > class A;" ).getDeclarations(); //$NON-NLS-1$ - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - - assertFalse( i.hasNext() ); - - i = template.getTemplateParameters(); - - IASTTemplateParameter T = (IASTTemplateParameter) i.next(); - IASTTemplateParameter U = (IASTTemplateParameter) i.next(); - } - - public void testDefaultTemplateParameters() throws Exception { - Iterator i = parse( "template < class T = int > class A{}; A<> a;" ).getDeclarations(); //$NON-NLS-1$ - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTVariable a = (IASTVariable) i.next(); - } - - public void testBug56834WithInstantiation() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template< class T, class U = T > class A {};" ); //$NON-NLS-1$ - writer.write( "A< char > a;" ); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTVariable a = (IASTVariable) i.next(); - } - - public void testDefaultTemplateParameterWithDeferedInstance() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template < class T > class A; \n" ); //$NON-NLS-1$ - writer.write( "template < class U, class V = A< U > > class B; \n" ); //$NON-NLS-1$ - writer.write( "B< int > b;" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateA = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateB = (IASTTemplateDeclaration) i.next(); - IASTVariable b = (IASTVariable) i.next(); - } - - public void testExplicitInstantiation() throws Exception{ - - Writer writer = new StringWriter(); - writer.write( "template < class T > class A { }; " ); //$NON-NLS-1$ - writer.write( "template class A< int >; " ); //$NON-NLS-1$ - writer.write( "A< int > a; " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier A = (IASTClassSpecifier) template.getOwnedDeclaration(); - IASTTemplateInstantiation instance = (IASTTemplateInstantiation) i.next(); - IASTVariable var = (IASTVariable) i.next(); - - assertAllReferences( 2, createTaskList( new Task( A, 2 ) ) ); - } - - public void testTemplateParametersInExpressions() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < typename _Tp > power( _Tp, unsigned int ); \n" ); //$NON-NLS-1$ - writer.write( "template < typename _Tp > _Tp helper( _Tp __x, int _n ) \n" ); //$NON-NLS-1$ - writer.write( "{ " ); //$NON-NLS-1$ - writer.write( " return n < 0 ? _Tp( 1 ) / power( __x, -__n ) \n" ); //$NON-NLS-1$ - writer.write( " : power( __x, __n ); \n" ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - - parse( writer.toString () ); - } - - public void testBug44338() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < bool T > class A { "); //$NON-NLS-1$ - writer.write( " void foo( bool b = T ); "); //$NON-NLS-1$ - writer.write( "}; "); //$NON-NLS-1$ - writer.write( "typedef A< 1 < 2 > A_TRUE; "); //$NON-NLS-1$ - writer.write( "typedef A< ( 1 > 2 ) > A_FALSE; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTypedefDeclaration a_true = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration a_false = (IASTTypedefDeclaration) i.next(); - } - - public void testBug44338_2() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < int i > class X {}; "); //$NON-NLS-1$ - writer.write( "template < class T > class Y {}; "); //$NON-NLS-1$ - writer.write( "Y< X < 1 > > y1; "); //$NON-NLS-1$ - writer.write( "Y< X < 6 >> 1 > > y2; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateX = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateY = (IASTTemplateDeclaration) i.next(); - IASTVariable y1 = (IASTVariable) i.next(); - IASTVariable y2 = (IASTVariable) i.next(); - } - - public void testBug4338_3() throws Exception - { - try{ - //this is expected to fail the parse - parse( "template < int i > class X {}; X< 1 > 2 > x; " ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserException e ){ - assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ - } - } - - public void testBug57754() throws Exception - { - Writer writer = new StringWriter(); - writer.write("template < class T > class A{ "); //$NON-NLS-1$ - writer.write(" typedef int _type; "); //$NON-NLS-1$ - writer.write(" void f( _type, T ); "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - writer.write("template < class T > void A< T >::f( _type, T ) {} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier cls = (IASTClassSpecifier) template.getOwnedDeclaration(); - - i = getDeclarations( cls ); - IASTTypedefDeclaration _type = (IASTTypedefDeclaration) i.next(); - - assertReferenceTask( new Task( _type, 2 ) ); - } - - public void testContructorsAndExplicitSpecialization() throws Exception - { - Writer writer = new StringWriter(); - writer.write("template < class T > class A { "); //$NON-NLS-1$ - writer.write(" A(); "); //$NON-NLS-1$ - writer.write(" A( int ); "); //$NON-NLS-1$ - writer.write(" ~A(); "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - writer.write("template <> A< char >::~A(); "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateSpecialization spec = (IASTTemplateSpecialization) i.next(); - } - - public void testTemplateMemberTemplateDefinition() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template< typename _Tp > "); //$NON-NLS-1$ - writer.write( "class list "); //$NON-NLS-1$ - writer.write( "{ "); //$NON-NLS-1$ - writer.write( " template void merge(list&, _S); "); //$NON-NLS-1$ - writer.write( "}; "); //$NON-NLS-1$ - - writer.write( "template < typename _Tp > "); //$NON-NLS-1$ - writer.write( "template < typename _S > "); //$NON-NLS-1$ - writer.write( "void list<_Tp>::merge(list<_Tp>& __x, _S __comp) "); //$NON-NLS-1$ - writer.write( "{} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration temp2 = (IASTTemplateDeclaration) i.next(); - } - - public void test_14_7_3__5_ExplicitSpecialization() throws Exception - { - Writer writer = new StringWriter(); - writer.write("template< class T > struct A { "); //$NON-NLS-1$ - writer.write(" void f( T ) {} "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - writer.write("template <> struct A< int >{ "); //$NON-NLS-1$ - writer.write(" void f( int ); "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - writer.write("void A< int >::f( int ){ } "); //$NON-NLS-1$ - - writer.write("void main(){ "); //$NON-NLS-1$ - writer.write(" A a; "); //$NON-NLS-1$ - writer.write(" a.f( 1 ); "); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateParameter T = (IASTTemplateParameter) template.getTemplateParameters().next(); - IASTTemplateSpecialization spec = (IASTTemplateSpecialization) i.next(); - IASTMethod f = (IASTMethod) i.next(); - IASTFunction main = (IASTFunction) i.next(); - - IASTClassSpecifier ASpec = (IASTClassSpecifier) spec.getOwnedDeclaration(); - - i = getDeclarations( main ); - IASTVariable a = (IASTVariable) i.next(); - - assertAllReferences( 5, createTaskList( new Task( T ), new Task( ASpec, 2 ), new Task( a ), new Task( f ) ) ); - } - public void test_14_7_3__11_ExplicitSpecializationArgumentDeduction() throws Exception - { - Writer writer = new StringWriter(); - writer.write("template < class T > class Array { }; "); //$NON-NLS-1$ - writer.write("template < class T > void sort( Array< T > & ); "); //$NON-NLS-1$ - writer.write("template<> void sort( Array< int > & ){} "); //$NON-NLS-1$ - writer.write("void f(){ "); //$NON-NLS-1$ - writer.write(" Array a1; "); //$NON-NLS-1$ - writer.write(" Array a2; "); //$NON-NLS-1$ - writer.write(" sort( a1 ); "); //$NON-NLS-1$ - writer.write(" sort( a2 ); "); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration templateArray = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration templateSort = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration sortSpec = (IASTTemplateDeclaration) i.next(); - IASTFunction f = (IASTFunction) i.next(); - - IASTFunction sort1 = (IASTFunction) templateSort.getOwnedDeclaration(); - IASTFunction sort2 = (IASTFunction) sortSpec.getOwnedDeclaration(); - - assertReferenceTask( new Task( sort1, 1, false, false ) ); - assertReferenceTask( new Task( sort2, 1, false, false ) ); - } - - public void test_14_8_1__2_ExplicitArgumentSpecification() throws Exception{ - Writer writer = new StringWriter(); - writer.write("void f( int ){} //#1 \n"); //$NON-NLS-1$ - writer.write("template < class T > void f( T ){} //#2 \n"); //$NON-NLS-1$ - writer.write("int main(){ \n"); //$NON-NLS-1$ - writer.write(" f( 1 ); //calls #1 \n"); //$NON-NLS-1$ - writer.write(" f( 1 ); //calls #2 \n"); //$NON-NLS-1$ - writer.write(" f<> ( 1 ); //calls #2 \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTFunction f1 = (IASTFunction) i.next(); - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTFunction f2 = (IASTFunction) template.getOwnedDeclaration(); - IASTFunction main = (IASTFunction) i.next(); - - assertReferenceTask( new Task( f1, 1, false, false ) ); - assertReferenceTask( new Task( f2, 2, false, false ) ); - } - - public void test_14_7_3__12_ExplicitSpecializationOverloadedFunction() throws Exception{ - Writer writer = new StringWriter(); - writer.write("template< class T > void f( T ); "); //$NON-NLS-1$ - writer.write("template< class T > void f( T * ); "); //$NON-NLS-1$ - writer.write("template <> void f< int*>( int * );"); //$NON-NLS-1$ - writer.write("template <> void f< int >( int * );"); //$NON-NLS-1$ - writer.write("template <> void f( char ); "); //$NON-NLS-1$ - - parse( writer.toString() ); - } - - public void testPartialSpecializationDefinitions() throws Exception{ - Writer writer = new StringWriter(); - writer.write("template < class T1, class T2 > class A { void f(); };"); //$NON-NLS-1$ - writer.write("template < class T > class A < T, T > { void f(); };"); //$NON-NLS-1$ - writer.write("template < class T > class A < char, T > { void f(); };"); //$NON-NLS-1$ - - writer.write("template < class U, class V > void A::f(){} "); //$NON-NLS-1$ - writer.write("template < class W > void A < W, W >::f(){} "); //$NON-NLS-1$ - writer.write("template < class X > void A < char, X >::f(){} "); //$NON-NLS-1$ - - writer.write("void main(){ "); //$NON-NLS-1$ - writer.write(" A< int, char > a1; "); //$NON-NLS-1$ - writer.write(" a1.f(); "); //$NON-NLS-1$ - writer.write(" A< int, int > a2; "); //$NON-NLS-1$ - writer.write(" a2.f(); "); //$NON-NLS-1$ - writer.write(" A< char, int > a3; "); //$NON-NLS-1$ - writer.write(" a3.f(); "); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration t1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration t2 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration t3 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration t4 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration t5 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration t6 = (IASTTemplateDeclaration) i.next(); - - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - IASTMethod f1 = (IASTMethod) t4.getOwnedDeclaration(); - IASTMethod f2 = (IASTMethod) t5.getOwnedDeclaration(); - IASTMethod f3 = (IASTMethod) t6.getOwnedDeclaration(); - - assertReferenceTask( new Task( f1, 1, false, false ) ); - assertReferenceTask( new Task( f2, 1, false, false ) ); - assertReferenceTask( new Task( f3, 1, false, false ) ); - } - - public void test_14_5_2__2_MemberFunctionTemplates() throws Exception{ - Writer writer = new StringWriter(); - writer.write("template < class T > struct A { "); //$NON-NLS-1$ - writer.write(" void f( int ); "); //$NON-NLS-1$ - writer.write(" template < class T2 > void f( T2 ); "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - - writer.write("template <> void A::f(int) {} //non-template member \n"); //$NON-NLS-1$ - writer.write("template <> template<> void A::f<>( int ) {} //template member \n"); //$NON-NLS-1$ - - writer.write("int main(){ "); //$NON-NLS-1$ - writer.write(" A< int > ac; "); //$NON-NLS-1$ - writer.write(" ac.f( 1 ); //non-template \n"); //$NON-NLS-1$ - writer.write(" ac.f( 'c' ); //template \n"); //$NON-NLS-1$ - writer.write(" ac.f<>(1); //template \n"); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration spec2 = (IASTTemplateDeclaration) i.next(); - - IASTMethod f1 = (IASTMethod) spec1.getOwnedDeclaration(); - IASTMethod f2 = (IASTMethod) spec2.getOwnedDeclaration(); - - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - assertReferenceTask( new Task( f1, 1, false, false ) ); - //we aren't going to be completely correct about references to explicit specializations - //due to limitations in the implementation, see bug 59811 - } - - public void testBug64753() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "template < class _T > void foo () { \n" ); //$NON-NLS-1$ - writer.write( " if( 1 ) { \n" ); //$NON-NLS-1$ - writer.write( " _T p1, p2; \n" ); //$NON-NLS-1$ - writer.write( " int n = p1 - p2; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration foo = (IASTTemplateDeclaration) i.next(); - } - - public void testBug64919() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class Foo{}; "); //$NON-NLS-1$ - writer.write("class Bar{}; "); //$NON-NLS-1$ - writer.write("template class A {}; "); //$NON-NLS-1$ - writer.write("template < class X > class A < X, X > : public A< X, Bar> "); //$NON-NLS-1$ - writer.write("{ typedef int TYPE; }; "); //$NON-NLS-1$ - writer.write("template < class X > class A < X, Foo > : public A< X, X > "); //$NON-NLS-1$ - writer.write("{ void f ( TYPE ); }; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier Foo = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier Bar = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTTemplateDeclaration T1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration T2 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration T3 = (IASTTemplateDeclaration) i.next(); - - IASTClassSpecifier A1 = (IASTClassSpecifier) T1.getOwnedDeclaration(); - IASTClassSpecifier A2 = (IASTClassSpecifier) T2.getOwnedDeclaration(); - IASTClassSpecifier A3 = (IASTClassSpecifier) T3.getOwnedDeclaration(); - - IASTBaseSpecifier parent = (IASTBaseSpecifier) A2.getBaseClauses().next(); - assertEquals( parent.getParentClassSpecifier(), A1 ); - - parent = (IASTBaseSpecifier) A3.getBaseClauses().next(); - assertEquals( parent.getParentClassSpecifier(), A2 ); - } - - public void testBug64939() throws Exception - { - try{ - parse( "template < class T > class A : public A< T * > {}; A a;" ).getDeclarations(); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserException e ){ - assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ - } - - try{ - parse( "template < class T > class A { A f(); }; A< int > a;" ).getDeclarations(); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserException e ){ - assertTrue( e.getMessage().equals( "FAILURE" ) ); //$NON-NLS-1$ - } - } - - public void testBug65114() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < typename _Tp, typename _Alloc > class _simple_alloc {}; \n" ); //$NON-NLS-1$ - writer.write( "template < int _inst > class __malloc_alloc {}; \n" ); //$NON-NLS-1$ - writer.write( "template < typename _Tp, int __inst> \n" ); //$NON-NLS-1$ - writer.write( "struct _Alloc_traits { \n" ); //$NON-NLS-1$ - writer.write( " typedef _simple_alloc< _Tp, __malloc_alloc<__inst> > _Alloc_type; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration simple_alloc = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration malloc_alloc = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration alloc_traits = (IASTTemplateDeclaration) i.next(); - - IASTClassSpecifier alloc = (IASTClassSpecifier) alloc_traits.getOwnedDeclaration(); - i = alloc_traits.getTemplateParameters(); - IASTTemplateParameter _Tp = (IASTTemplateParameter) i.next(); - IASTTemplateParameter inst = (IASTTemplateParameter) i.next(); - - IASTClassSpecifier simple = (IASTClassSpecifier) simple_alloc.getOwnedDeclaration(); - IASTClassSpecifier malloc = (IASTClassSpecifier) malloc_alloc.getOwnedDeclaration(); - - assertAllReferences( 4, createTaskList( new Task( simple ), new Task( _Tp ), - new Task( malloc ), new Task( inst ) ) ); - } - - public void testBug655114_2() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < typename _Alloc > class base_allocator { int _Tp; }; \n"); //$NON-NLS-1$ - writer.write( "template < class T > class B {}; \n"); //$NON-NLS-1$ - writer.write( "template <> class B < int > {}; \n"); //$NON-NLS-1$ - writer.write( "template < typename _Alloc > class allocator; \n"); //$NON-NLS-1$ - writer.write( "template < typename _Tp > class allocator : base_allocator<_Tp>, B<_Tp> {}; \n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration base = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier baseCls = (IASTClassSpecifier) base.getOwnedDeclaration(); - - IASTTemplateDeclaration B1 = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration B2 = (IASTTemplateDeclaration) i.next(); - - IASTClassSpecifier B1cls = (IASTClassSpecifier) B1.getOwnedDeclaration(); - IASTClassSpecifier B2cls = (IASTClassSpecifier) B2.getOwnedDeclaration(); - - IASTTemplateDeclaration forward = (IASTTemplateDeclaration) i.next(); - IASTTemplateDeclaration allocator = (IASTTemplateDeclaration) i.next(); - - IASTClassSpecifier cls = (IASTClassSpecifier) allocator.getOwnedDeclaration(); - i = cls.getBaseClauses(); - IASTBaseSpecifier clause = (IASTBaseSpecifier) i.next(); - assertEquals( clause.getParentClassSpecifier(), baseCls ); - clause = (IASTBaseSpecifier) i.next(); - assertEquals( clause.getParentClassSpecifier(), B1cls ); - - } - - public void testInheritsFromTemplateParameter_bug71410() throws Exception { - // An inner type definition inherits from a template parameter - Iterator i = parse("template \n class A { \n struct B : U { T* mT; }; \n B mB; \n T* getVal() { return mB.mT; } \n }; \n").getDeclarations();//$NON-NLS-1$ - IASTTemplateDeclaration td = (IASTTemplateDeclaration)i.next(); - assertFalse(i.hasNext()); - IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration(); - Iterator j = cs.getDeclarations(); - IASTClassSpecifier cs2 = (IASTClassSpecifier) j.next(); - IASTField f = (IASTField) j.next(); - IASTMethod m = (IASTMethod) j.next(); - assertFalse(j.hasNext()); - } - - public void testThisInTemplatedMemberFunction_bug71331() throws Exception { - Iterator i = parse("class A { \n int f() {return 0;} \n template int g(T*) { return this->f(); } \n }; \n").getDeclarations();//$NON-NLS-1$ - IASTAbstractTypeSpecifierDeclaration cd = (IASTAbstractTypeSpecifierDeclaration) i.next(); - assertFalse(i.hasNext()); - IASTClassSpecifier cs = (IASTClassSpecifier) cd.getTypeSpecifier(); - Iterator j = cs.getDeclarations(); - IASTMethod md = (IASTMethod) j.next(); - IASTTemplateDeclaration tmd = (IASTTemplateDeclaration) j.next(); - assertFalse(j.hasNext()); - } - - public void testTemplateFunctionInsideTemplateType_bug71588() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("template \r\n"); //$NON-NLS-1$ - writer.write("class A { \n"); //$NON-NLS-1$ - writer.write("template \n"); //$NON-NLS-1$ - writer.write("T* foo(V); \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("template \n"); //$NON-NLS-1$ - writer.write("template \n"); //$NON-NLS-1$ - writer.write("T* A::foo(V) { return (T*)0; } \n"); //$NON-NLS-1$ - - Iterator i = parse(writer.toString()).getDeclarations(); - IASTTemplateDeclaration td = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration(); - Iterator j = cs.getDeclarations(); - IASTTemplateDeclaration td2 = (IASTTemplateDeclaration) j.next(); - assertFalse(j.hasNext()); - IASTMethod mdec = (IASTMethod) td2.getOwnedDeclaration(); - IASTTemplateDeclaration td3 = (IASTTemplateDeclaration) i.next(); - assertFalse(i.hasNext()); - IASTMethod mdef = (IASTMethod) td3.getOwnedDeclaration(); - } - - public void testParametrizedTypeDefinition_bug69751() throws Exception { - // a typedef refers to an unknown type in a template parameter - Iterator i = parse("template \n class A { \n typedef typename T::size_type size_type; \n void foo() { size_type i; } \n }; \n").getDeclarations();//$NON-NLS-1$ - IASTTemplateDeclaration td = (IASTTemplateDeclaration)i.next(); - assertFalse(i.hasNext()); - IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration(); - Iterator j = cs.getDeclarations(); - IASTTypedefDeclaration tdd = (IASTTypedefDeclaration) j.next(); - IASTMethod m = (IASTMethod) j.next(); - assertFalse(j.hasNext()); - Iterator k = m.getDeclarations(); - IASTVariable v = (IASTVariable) k.next(); - assertFalse(k.hasNext()); - } - - public void testParametrizedTypeDefinition_bug69751_2() throws Exception { - Writer writer = new StringWriter(); - writer.write("template class A { \n"); - writer.write("void foo(); };\n"); - writer.write("template \n"); - writer.write("void A::foo() { \n"); - writer.write("typedef typename T::B::s_type l_type; \n"); - writer.write("typedef typename T::B::s2_type l2_type; \n"); - writer.write("l_type i; \n"); - writer.write("l2_type j; } \n"); - Iterator i = parse(writer.toString()).getDeclarations();//$NON-NLS-1$ - IASTTemplateDeclaration td1 = (IASTTemplateDeclaration)i.next(); - IASTTemplateDeclaration td2 = (IASTTemplateDeclaration)i.next(); - assertFalse(i.hasNext()); - IASTClassSpecifier cs = (IASTClassSpecifier) td1.getOwnedDeclaration(); - Iterator j = cs.getDeclarations(); - IASTMethod mdecl = (IASTMethod) j.next(); - assertFalse(j.hasNext()); - IASTMethod mdef = (IASTMethod) td2.getOwnedDeclaration(); - Iterator k = mdef.getDeclarations(); - IASTTypedefDeclaration tdd1 = (IASTTypedefDeclaration) k.next(); - IASTTypedefDeclaration tdd2 = (IASTTypedefDeclaration) k.next(); - IASTVariable v1 = (IASTVariable) k.next(); - IASTVariable v2 = (IASTVariable) k.next(); - assertFalse(k.hasNext()); - } - - public void testParametrizedTypeDefinition_bug69751_3() throws Exception { - Writer writer = new StringWriter(); - writer.write("template class A { \n"); - // T::U is not the same as template parameter U - writer.write("typedef typename T::U::s_type l_type; \n"); - writer.write("l_type m_l; \n"); - writer.write("typename U::s_type m_s; } \n"); - Iterator i = parse(writer.toString()).getDeclarations();//$NON-NLS-1$ - IASTTemplateDeclaration td = (IASTTemplateDeclaration)i.next(); - assertFalse(i.hasNext()); - Iterator j = td.getTemplateParameters(); - IASTTemplateParameter tpT = (IASTTemplateParameter) j.next(); - IASTTemplateParameter tpU = (IASTTemplateParameter) j.next(); - assertFalse(j.hasNext()); - IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration(); - Iterator k = cs.getDeclarations(); - IASTTypedefDeclaration tdd = (IASTTypedefDeclaration) k.next(); - IASTField f1 = (IASTField) k.next(); - IASTField f2 = (IASTField) k.next(); - assertFalse(k.hasNext()); - assertAllReferences(3, createTaskList(new Task(tpT), new Task(tpU), new Task(tdd))); - } - - public void testParametrizedTypeDefinition_bug69751_4() throws Exception { - Writer writer = new StringWriter(); - writer.write("class B { typedef char size_type; };"); - writer.write("template class A { \n"); - writer.write("typedef typename T::size_type size_type; };\n"); - writer.write("A::size_type c; \n"); - writer.write("void f(char) {} \n"); - writer.write("void f(int) {} \n"); - writer.write("void main() { f(c); } \n"); - Iterator i = parse(writer.toString()).getDeclarations(); - IASTAbstractTypeSpecifierDeclaration ad = (IASTAbstractTypeSpecifierDeclaration)i.next(); - IASTTemplateDeclaration td = (IASTTemplateDeclaration)i.next(); - IASTVariable v = (IASTVariable)i.next(); - IASTFunction fc = (IASTFunction) i.next(); - IASTFunction fi = (IASTFunction) i.next(); - IASTFunction fm = (IASTFunction) i.next(); - assertFalse(i.hasNext()); - assertReferenceTask(new Task(fc, 1, true, false)); - } - - public void testTemplateParametersInExpressions_bug72546() throws Exception { - Iterator i = parse("template \n int add(T * x, T * y) { \n return x->value + y->value; }; \n").getDeclarations();//$NON-NLS-1$ - IASTTemplateDeclaration td = (IASTTemplateDeclaration)i.next(); - assertFalse(i.hasNext()); - Iterator j = td.getTemplateParameters(); - IASTTemplateParameter tp = (IASTTemplateParameter) j.next(); - assertFalse(j.hasNext()); - IASTFunction f = (IASTFunction) td.getOwnedDeclaration(); - Iterator k = f.getParameters(); - IASTParameterDeclaration x = (IASTParameterDeclaration) k.next(); - IASTParameterDeclaration y = (IASTParameterDeclaration) k.next(); - assertFalse(k.hasNext()); - IASTAbstractDeclaration ad = f.getReturnType(); - assertTrue(ad != null); - assertAllReferences(4, createTaskList(new Task(tp, 2), new Task(x), new Task(y))); - } - - public void testInstantiatingTemplateWithDTI_bug69604() throws Exception { - Writer writer = new StringWriter(); - writer.write("template class A {}; \n"); - writer.write("template class B {}; \n"); - writer.write("template > > class C {}; \n"); - writer.write("C c_int;\n"); - Iterator i = parse(writer.toString()).getDeclarations(); - IASTTemplateDeclaration td1 = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier cs1 = (IASTClassSpecifier) td1.getOwnedDeclaration(); - IASTTemplateDeclaration td2 = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier cs2 = (IASTClassSpecifier) td2.getOwnedDeclaration(); - IASTTemplateDeclaration td3 = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier cs3 = (IASTClassSpecifier) td3.getOwnedDeclaration(); - Iterator j = td3.getTemplateParameters(); - IASTTemplateParameter tp1 = (IASTTemplateParameter) j.next(); - IASTTemplateParameter tp2 = (IASTTemplateParameter) j.next(); - assertFalse(j.hasNext()); - IASTVariable cr = (IASTVariable) i.next(); - assertFalse(i.hasNext()); - assertReferenceTask(new Task(cs1, 1)); - assertReferenceTask(new Task(cs2, 1)); - } - - public void testTemplatedBaseClass_bug74359() throws Exception { - Writer writer = new StringWriter(); - writer.write("template class A {}; \n"); - writer.write("template class B {}; \n"); - writer.write("template class C : public B > {}; \n"); - writer.write("C c_int;\n"); - Iterator i = parse(writer.toString()).getDeclarations(); - IASTTemplateDeclaration td1 = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier cs1 = (IASTClassSpecifier) td1.getOwnedDeclaration(); - IASTTemplateDeclaration td2 = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier cs2 = (IASTClassSpecifier) td2.getOwnedDeclaration(); - IASTTemplateDeclaration td3 = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier cs3 = (IASTClassSpecifier) td3.getOwnedDeclaration(); - Iterator j = cs3.getBaseClauses(); - IASTBaseSpecifier bs = (IASTBaseSpecifier) j.next(); - assertFalse(j.hasNext()); - IASTVariable cr = (IASTVariable) i.next(); - assertFalse(i.hasNext()); - assertReferenceTask(new Task(cs1, 1)); - assertReferenceTask(new Task(cs2, 1)); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java deleted file mode 100644 index 360518aa37b..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java +++ /dev/null @@ -1,2562 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTClassReference; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTReference; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTVariableReference; -import org.eclipse.cdt.internal.core.parser.ParserException; - - -/** - * @author jcamelon - * - */ -public class CompleteParseASTTest extends CompleteParseBaseTest -{ - /** - * @param a - */ - public CompleteParseASTTest(String a) - { - super(a); - } - - public void testEmptyCompilationUnit() throws Exception - { - IASTScope compilationUnit = parse( "// no real code "); //$NON-NLS-1$ - assertNotNull( compilationUnit ); - assertFalse( compilationUnit.getDeclarations().hasNext() ); - } - - public void testSimpleNamespace() throws Exception - { - Iterator declarations = parse( "namespace A { }").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); - assertEquals( namespaceDefinition.getName(), "A" ); //$NON-NLS-1$ - assertFalse( getDeclarations( namespaceDefinition ).hasNext() ); - } - - public void testMultipleNamespaceDefinitions() throws Exception - { - Iterator declarations = parse( "namespace A { } namespace A { }").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); - assertEquals( namespaceDefinition.getName(), "A" ); //$NON-NLS-1$ - namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); - assertEquals( namespaceDefinition.getName(), "A" ); //$NON-NLS-1$ - assertFalse( getDeclarations( namespaceDefinition ).hasNext() ); - } - - public void testNestedNamespaceDefinitions() throws Exception - { - Iterator declarations = parse( "namespace A { namespace B { } }").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); - assertEquals( namespaceDefinition.getName(), "A" ); //$NON-NLS-1$ - assertFalse( declarations.hasNext() ); - Iterator subDeclarations = getDeclarations( namespaceDefinition ); - IASTNamespaceDefinition subDeclaration = (IASTNamespaceDefinition)subDeclarations.next(); - assertEquals( subDeclaration.getName(), "B" ); //$NON-NLS-1$ - assertFalse( subDeclarations.hasNext() ); - } - - public void testEmptyClassDeclaration() throws Exception - { - Iterator declarations = parse( "class A { };").getDeclarations(); //$NON-NLS-1$ - IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)declarations.next(); - IASTClassSpecifier classSpec = (IASTClassSpecifier)abs.getTypeSpecifier(); - assertEquals( classSpec.getName(), "A"); //$NON-NLS-1$ - assertFalse( getDeclarations( classSpec ).hasNext() ); - assertFalse( declarations.hasNext() ); - } - - public void testSimpleSubclass() throws Exception - { - Iterator declarations = parse( "class A { }; class B : public A { };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - Iterator parentClasses = classB.getBaseClauses(); - IASTBaseSpecifier baseClass = (IASTBaseSpecifier)parentClasses.next(); - assertEquals( classA, baseClass.getParentClassSpecifier() ); - assertEquals( baseClass.getParentClassName(), "A"); //$NON-NLS-1$ - assertEquals( baseClass.getAccess(), ASTAccessVisibility.PUBLIC); - assertFalse( baseClass.isVirtual() ); - } - - public void testNestedSubclass() throws Exception - { - Iterator declarations = parse( "namespace N { class A { }; } class B : protected virtual N::A { };").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)getDeclarations( namespaceDefinition).next() ).getTypeSpecifier(); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - Iterator baseClauses = classB.getBaseClauses(); - IASTBaseSpecifier baseClass = (IASTBaseSpecifier)baseClauses.next(); - assertEquals( classA, baseClass.getParentClassSpecifier() ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testSimpleVariable() throws Exception - { - Iterator declarations = parse( "int x;").getDeclarations(); //$NON-NLS-1$ - IASTVariable v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - } - - public void testSimpleClassReferenceVariable() throws Exception - { - Iterator declarations = parse( "class A { }; A x;").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTVariable v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA ); - assertAllReferences( 1, createTaskList( new Task( classA ))); - } - - public void testNestedClassReferenceVariable() throws Exception - { - Iterator declarations = parse( "namespace N { class A { }; } N::A x;").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespace = (IASTNamespaceDefinition)declarations.next(); - Iterator iter = getDeclarations( namespace ); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)iter.next()).getTypeSpecifier(); - IASTVariable v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testMultipleDeclaratorsVariable() throws Exception - { - Iterator declarations = parse( "class A { }; A x, y, z;").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTVariable v = (IASTVariable)declarations.next(); - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA ); - assertEquals( callback.getReferences().size(), 3 ); - Iterator i = callback.getReferences().iterator(); - while( i.hasNext() ) - assertEquals( ((IASTReference)i.next()).getReferencedElement(), classA ); - } - - public void testSimpleField() throws Exception - { - Iterator declarations = parse( "class A { double x; };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - Iterator fields =getDeclarations(classA); - IASTField f = (IASTField)fields.next(); - assertEquals( f.getName(), "x" ); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)f.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.DOUBLE ); - } - - public void testUsingClauses() throws Exception - { - Iterator declarations = parse( "namespace A { namespace B { int x; class C { static int y = 5; }; } } \n using namespace A::B;\n using A::B::x;using A::B::C;using A::B::C::y;").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)declarations.next(); - IASTNamespaceDefinition namespaceB = (IASTNamespaceDefinition)getDeclarations( namespaceA ).next(); - Iterator i = getDeclarations( namespaceB ); - IASTVariable variableX = (IASTVariable)i.next(); - IASTClassSpecifier classC = ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier()); - IASTField fieldY = (IASTField)getDeclarations( classC ).next(); - assertQualifiedName( fieldY.getFullyQualifiedName(), new String [] { "A", "B", "C", "y" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - IASTUsingDirective directive = (IASTUsingDirective)declarations.next(); - assertEquals( directive.getNamespaceDefinition(), namespaceB ); - assertEquals( directive.getNamespaceName(), "A::B" ); //$NON-NLS-1$ - IASTUsingDeclaration declaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( declaration.getUsingTypes().next(), variableX ); - declaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( declaration.getUsingTypes().next(), classC ); - declaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( declaration.getUsingTypes().next(), fieldY ); - assertEquals( callback.getReferences().size(), 12 ); - - } - - public void testEnumerations() throws Exception - { - Iterator declarations = parse( "namespace A { enum E { e1, e2, e3 }; E varE;}").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)declarations.next(); - Iterator namespaceMembers = getDeclarations( namespaceA ); - IASTEnumerationSpecifier enumE = (IASTEnumerationSpecifier)((IASTAbstractTypeSpecifierDeclaration)namespaceMembers.next()).getTypeSpecifier(); - assertEquals( enumE.getName(), "E"); //$NON-NLS-1$ - assertQualifiedName( enumE.getFullyQualifiedName(), new String [] { "A", "E" } ); //$NON-NLS-1$ //$NON-NLS-2$ - Iterator enumerators = enumE.getEnumerators(); - IASTEnumerator enumerator_e1 = (IASTEnumerator)enumerators.next(); - IASTEnumerator enumerator_e2 = (IASTEnumerator)enumerators.next(); - IASTEnumerator enumerator_e3 = (IASTEnumerator)enumerators.next(); - assertFalse( enumerators.hasNext() ); - assertEquals( enumerator_e1.getName(), "e1"); //$NON-NLS-1$ - assertEquals( enumerator_e2.getName(), "e2"); //$NON-NLS-1$ - assertEquals( enumerator_e3.getName(), "e3"); //$NON-NLS-1$ - IASTVariable varE = (IASTVariable)namespaceMembers.next(); - assertEquals( ((IASTSimpleTypeSpecifier)varE.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), enumE ); - } - - public void testSimpleFunction() throws Exception - { - Iterator declarations = parse( "void foo( void );").getDeclarations(); //$NON-NLS-1$ - IASTFunction function = (IASTFunction)declarations.next(); - assertEquals( function.getName(), "foo" ); //$NON-NLS-1$ - assertEquals( callback.getReferences().size(), 0 ); - } - - public void testSimpleFunctionWithTypes() throws Exception - { - Iterator declarations = parse( "class A { public: \n class B { }; }; const A::B & foo( A * myParam );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - Iterator classDecls = getDeclarations(classA); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)classDecls.next()).getTypeSpecifier(); - IASTFunction function = (IASTFunction)declarations.next(); - assertAllReferences( 3, createTaskList( new Task( classA ,2), new Task(classB))); - } - - public void testSimpleMethod() throws Exception - { - Iterator declarations = parse( "class A { void foo(); };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTMethod method = (IASTMethod)getDeclarations( classA ).next(); - assertEquals( method.getName(), "foo" ); //$NON-NLS-1$ - } - - public void testSimpleMethodWithTypes() throws Exception - { - Iterator declarations = parse( "class U { }; class A { U foo( U areDumb ); };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classU = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTMethod method = (IASTMethod)getDeclarations( classA ).next(); - assertEquals( method.getName(), "foo" ); //$NON-NLS-1$ - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testUsingDeclarationWithFunctionsAndMethods() throws Exception - { - Iterator declarations = parse( "namespace N { int foo(void); } class A { static int bar(void); }; using N::foo; using ::A::bar;" ).getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceN = (IASTNamespaceDefinition)declarations.next(); - IASTFunction fooFunction = (IASTFunction)(getDeclarations(namespaceN).next()); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTMethod methodM = (IASTMethod)(getDeclarations(classA).next()); - IASTUsingDeclaration using1 = (IASTUsingDeclaration)declarations.next(); - IASTUsingDeclaration using2 = (IASTUsingDeclaration)declarations.next(); - assertEquals( callback.getReferences().size(), 4 ); - Iterator references = callback.getReferences().iterator(); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), namespaceN ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), fooFunction ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), classA ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), methodM ); - } - - public void testLinkageSpec() throws Exception - { - IASTLinkageSpecification linkage = (IASTLinkageSpecification)parse( "extern \"C\" { int foo(); }").getDeclarations().next(); //$NON-NLS-1$ - Iterator i = getDeclarations( linkage ); - IASTFunction f = (IASTFunction)i.next(); - assertEquals( f.getName(),"foo"); //$NON-NLS-1$ - } - - - public void testBogdansExample() throws Exception - { - IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)parse( "namespace A { namespace B { enum e1{e_1,e_2}; int x; class C { static int y = 5; }; }} ").getDeclarations().next(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceB = (IASTNamespaceDefinition)(getDeclarations(namespaceA).next()); - Iterator subB = getDeclarations( namespaceB ); - IASTEnumerationSpecifier enumE1 = (IASTEnumerationSpecifier)((IASTAbstractTypeSpecifierDeclaration)subB.next()).getTypeSpecifier(); - Iterator enumerators = enumE1.getEnumerators(); - IASTEnumerator enumeratorE_1 = (IASTEnumerator)enumerators.next(); - assertEquals( enumeratorE_1.getOwnerEnumerationSpecifier(), enumE1 ); - IASTVariable variableX = (IASTVariable)subB.next(); - IASTClassSpecifier classC = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)subB.next()).getTypeSpecifier(); - } - - public void testAndrewsExample() throws Exception - { - Iterator declarations = parse( "namespace N{ class A {}; } using namespace N; class B: public A{};").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceN = (IASTNamespaceDefinition)declarations.next(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)getDeclarations( namespaceN ).next()).getTypeSpecifier(); - IASTUsingDirective usingClause = (IASTUsingDirective)declarations.next(); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTBaseSpecifier baseSpec = (IASTBaseSpecifier)classB.getBaseClauses().next(); - assertEquals( baseSpec.getParentClassSpecifier(), classA ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testSimpleTypedef() throws Exception - { - Iterator iter = parse( "typedef int myInt;\n myInt var;").getDeclarations(); //$NON-NLS-1$ - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)iter.next(); - assertEquals( typedef.getName(), "myInt"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)typedef.getAbstractDeclarator().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - IASTVariable v = (IASTVariable)iter.next(); - assertEquals( v.getName(), "var"); //$NON-NLS-1$ - assertEquals( callback.getReferences().size(), 1 ); - } - - public void testComplexTypedef() throws Exception - { - Iterator declarations = parse( "class A{ }; typedef A ** A_DOUBLEPTR;").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)declarations.next(); - assertEquals( ((IASTSimpleTypeSpecifier)typedef.getAbstractDeclarator().getTypeSpecifier()).getTypeSpecifier(), classA ); - assertEquals( callback.getReferences().size(), 1 ); - } - - - protected void assertQualifiedName(String [] fromAST, String [] theTruth) - { - assertNotNull( fromAST ); - assertNotNull( theTruth ); - assertEquals( fromAST.length, theTruth.length ); - for( int i = 0; i < fromAST.length; ++i ) - { - assertEquals( fromAST[i], theTruth[i]); - } - } - - public void testBug40842() throws Exception{ - Writer code = new StringWriter(); - - code.write("class A {} a;\n"); //$NON-NLS-1$ - Iterator i = parse(code.toString()).getDeclarations(); - IASTVariable instanceA = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 0 ); - } - - public void testNestedClassname() throws Exception - { - Iterator declarations = parse( "namespace A { } \n class A::B { };").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)declarations.next(); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertEquals( classB.getOwnerScope(), namespaceA ); - assertEquals( callback.getReferences().size(), 1 ); - } - - public void testForwardDeclaration() throws Exception - { - Iterator i = parse( "class forward;").getDeclarations(); //$NON-NLS-1$ - assertTrue( i.hasNext() ); - IASTAbstractTypeSpecifierDeclaration d = (IASTAbstractTypeSpecifierDeclaration)i.next(); - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)d.getTypeSpecifier(); - assertEquals( elab.getName(), "forward"); //$NON-NLS-1$ - assertEquals( elab.getClassKind(), ASTClassKind.CLASS ); - } - - public void testElaboratedType() throws Exception - { - Iterator i = parse( "class A; class A * a;").getDeclarations(); //$NON-NLS-1$ - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertEquals( elab.getName(), "A" ); //$NON-NLS-1$ - IASTVariable variableA = (IASTVariable)i.next(); - assertEquals( variableA.getName(), "a"); //$NON-NLS-1$ - assertEquals( variableA.getAbstractDeclaration().getTypeSpecifier(), elab ); - } - - public void testForewardDeclarationWithUsage() throws Exception - { - Iterator declarations = parse( "class A; A * anA;class A { };").getDeclarations(); //$NON-NLS-1$ - IASTAbstractTypeSpecifierDeclaration forewardDecl = (IASTAbstractTypeSpecifierDeclaration)declarations.next(); - IASTVariable variable = (IASTVariable)declarations.next(); - IASTAbstractTypeSpecifierDeclaration classDecl = (IASTAbstractTypeSpecifierDeclaration)declarations.next(); - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)forewardDecl.getTypeSpecifier(); - IASTClassSpecifier clasSpec = (IASTClassSpecifier)classDecl.getTypeSpecifier(); - assertEquals( elab.getName(), clasSpec.getName() ); - String [] fqnClass = clasSpec.getFullyQualifiedName(); - String [] fqnElab = elab.getFullyQualifiedName(); - assertEquals( fqnClass.length, fqnElab.length ); - for( int i = 0; i < fqnClass.length; ++i ) - assertEquals( fqnClass[i], fqnElab[i]); - assertEquals( callback.getReferences().size(), 1 ); - assertEquals( callback.getForewardDecls().size(), 1 ); - IASTClassReference ref = (IASTClassReference)callback.getReferences().get(0); - assertTrue( ref.getReferencedElement() instanceof IASTElaboratedTypeSpecifier ); - assertEquals( ref.getReferencedElement(), elab ); - } - - - public void testASM() throws Exception - { - IASTASMDefinition asm = (IASTASMDefinition)parse( "asm ( \"blah blah blah\" );" ).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( asm.getBody(), "blah blah blah"); //$NON-NLS-1$ - } - - public void testOverride() throws Exception - { - Iterator i = parse( "void foo();\n void foo( int );\n").getDeclarations(); //$NON-NLS-1$ - IASTFunction f1 = (IASTFunction)i.next(); - IASTFunction f2 = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - } - - public void testSimpleExpression() throws Exception - { - Iterator i = parse( "int x; int y = x;").getDeclarations(); //$NON-NLS-1$ - IASTVariable varX = (IASTVariable)i.next(); - IASTVariable varY = (IASTVariable)i.next(); - assertEquals( callback.getReferences().size(), 1 ); - } - - public void testParameterExpressions() throws Exception - { - Iterator i = parse( "int x = 5; void foo( int sub = x ) { }").getDeclarations(); //$NON-NLS-1$ - IASTVariable varX = (IASTVariable)i.next(); - IASTFunction funFoo = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - } - - public void testNestedNamespaceExpression() throws Exception - { - Iterator i = parse( "namespace A { int x = 666; } int y = A::x;").getDeclarations(); //$NON-NLS-1$ - IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)i.next(); - IASTVariable variableY = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testConstructorChain() throws Exception - { - Iterator i = parse( "int x = 5;\n class A \n{ public : \n int a; \n A() : a( x ) { } };").getDeclarations(); //$NON-NLS-1$ - IASTVariable variableX = (IASTVariable)i.next(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - Iterator s = getDeclarations( classA ); - IASTField fieldA = (IASTField)s.next(); - IASTMethod methodA = (IASTMethod)s.next(); - assertFalse( s.hasNext() ); - assertAllReferences( 2, createTaskList( new Task( fieldA), new Task( variableX ))); - } - - public void testArrayModExpression() throws Exception - { - Iterator i = parse( "const int x = 5; int y [ x ]; ").getDeclarations(); //$NON-NLS-1$ - IASTVariable varX = (IASTVariable)i.next(); - IASTVariable varY = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - } - - - public void testPointerVariable() throws Exception - { - Iterator i = parse( "class A { }; A * anA;").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable varAnA = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - IASTClassReference ref = (IASTClassReference)callback.getReferences().get(0); - assertEquals( ref.getReferencedElement(), classA ); - } - - public void testExceptionSpecification() throws Exception - { - Iterator i = parse( "class A { }; void foo( void ) throw ( A );").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction function = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - IASTClassReference ref = (IASTClassReference)callback.getReferences().get(0); - assertEquals( ref.getReferencedElement(), classA ); - } - - public void testNewExpressions() throws Exception - { - Iterator declarations = parse( "int A; int B; int C; int D; int P; int*p = new (P) (A)[B][C][D];" ).getDeclarations(); //$NON-NLS-1$ - IASTVariable variableA = (IASTVariable)declarations.next(); - IASTVariable variableB = (IASTVariable)declarations.next(); - IASTVariable variableC = (IASTVariable)declarations.next(); - IASTVariable variableD = (IASTVariable)declarations.next(); - IASTVariable variableP = (IASTVariable)declarations.next(); - IASTVariable variablep = (IASTVariable)declarations.next(); - assertEquals( callback.getReferences().size(), 5 ); - Iterator references = callback.getReferences().iterator(); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableA ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableP ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableB ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableC ); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), variableD ); - } - - public void testBug41520() throws Exception - { - Iterator i = parse( "const int x = 666; const int y( x );").getDeclarations(); //$NON-NLS-1$ - IASTVariable variableX = (IASTVariable)i.next(); - IASTVariable variableY = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - } - - public void testNewXReferences() throws Exception - { - Iterator declarations = parse( "const int max = 5;\n int * x = new int[max];").getDeclarations(); //$NON-NLS-1$ - IASTVariable max = (IASTVariable) declarations.next(); - IASTVariable x = (IASTVariable) declarations.next(); - assertFalse( declarations.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - IASTVariableReference maxRef = (IASTVariableReference) callback.getReferences().get(0); - assertEquals( maxRef.getReferencedElement(), max ); - } - - public void testQualifiedNameReferences() throws Exception - { - // Used to cause AST Semantic exception - Iterator i = parse( "class A{ class B{ class C { public: int cMethod(); }; }; }; \n int A::B::C::cMethod() {}; \n" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(classA); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)j.next()).getTypeSpecifier(); - Iterator k = getDeclarations(classB); - IASTClassSpecifier classC = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)k.next()).getTypeSpecifier(); - // Note : this used to be considered a function, not a method - IASTMethod method = (IASTMethod)i.next(); - - assertAllReferences( 3, createTaskList( new Task( classA ), new Task( classB ), new Task( classC ))); - - } - - public void testIsConstructor() throws Exception - { - Iterator i = parse( "class A{ public: A(); }; \n A::A() {}; \n" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod method = (IASTMethod)i.next(); - assertTrue (method.isConstructor()); - } - - public void testIsDestructor() throws Exception - { - Iterator i = parse( "class A{ public: ~A(); }; \n A::~A() {}; \n" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod method = (IASTMethod)i.next(); - assertTrue (method.isDestructor()); - } - - public void testBug41445() throws Exception - { - Iterator i = parse( "class A { }; namespace N { class B : public A { struct A {}; }; }").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTNamespaceDefinition namespaceN = (IASTNamespaceDefinition)i.next(); - Iterator sub = getDeclarations( namespaceN ); - IASTClassSpecifier classB = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)sub.next()).getTypeSpecifier(); - IASTClassSpecifier structA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)( getDeclarations( classB ).next())).getTypeSpecifier(); - } - - public void testSimpleFunctionBody() throws Exception - { - Iterator i = parse( "class A { int f1(); }; const int x = 4; int f() { return x; } int A::f1() { return x; }").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod method_prototype = (IASTMethod)getDeclarations(classA).next(); - IASTVariable x = (IASTVariable) i.next(); - IASTFunction function_f = (IASTFunction) i.next(); - IASTMethod method_f = (IASTMethod)i.next(); - assertEquals( method_f.getName(), method_prototype.getName() ); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 3 ); - IASTVariableReference referenceX = (IASTVariableReference) callback.getReferences().get(0); - assertEquals( referenceX.getReferencedElement(), x ); - IASTClassReference referenceA = (IASTClassReference) callback.getReferences().get(1); - assertEquals( referenceA.getReferencedElement(), classA ); - referenceX = (IASTVariableReference) callback.getReferences().get(2); - assertEquals( referenceX.getReferencedElement(), x ); - } - - - public void testSimpleForLoop() throws Exception - { - Iterator i = parse( "const int FIVE = 5; void f() { int x = 0; for( int i = 0; i < FIVE; ++i ) { x += i; } }").getDeclarations(); //$NON-NLS-1$ - IASTVariable five = (IASTVariable) i.next(); - IASTFunction f = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 5 ); - i = parse( "const int FIVE = 5; void f() { int x = 0; for( int i = 0; i < FIVE; ++i ) x += i; }").getDeclarations(); //$NON-NLS-1$ - five = (IASTVariable) i.next(); - f = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 5 ); - - i = parse( "class A { }; void f() { for( int i = 0; i < (A*)0; ++i ) { A anA; } }").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - f = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 4 ); - } - - public void testBug42541() throws Exception - { - Iterator i = parse( "union{ int v; char a; } id;" ).getDeclarations(); //$NON-NLS-1$ - IASTVariable id = (IASTVariable)i.next(); - - IASTClassSpecifier union = (IASTClassSpecifier) id.getAbstractDeclaration().getTypeSpecifier(); - Iterator sub = getDeclarations( union ); - IASTField intV = (IASTField)sub.next(); - IASTField charA = (IASTField)sub.next(); - } - - - - public void testSimpleIfStatement() throws Exception - { - Iterator i = parse( "const bool T = true; int foo() { if( T ) { return 5; } else if( ! T ) return 20; else { return 10; } }").getDeclarations(); //$NON-NLS-1$ - IASTVariable t = (IASTVariable)i.next(); - IASTFunction foo = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testSimpleWhileStatement() throws Exception - { - Iterator i = parse( "const bool T = true; void foo() { int x = 0; while( T ) { ++x; if( x == 100 ) break; } }").getDeclarations(); //$NON-NLS-1$ - IASTVariable t = (IASTVariable)i.next(); - IASTFunction foo = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 3 ); - } - - public void testSimpleSwitchStatement() throws Exception - { - Iterator i = parse( "const int x = 5; const int y = 10; void foo() { switch( x ) { case 1: break; case 2: goto blah; case y: continue; default: break;} }").getDeclarations(); //$NON-NLS-1$ - IASTVariable x = (IASTVariable)i.next(); - IASTVariable y = (IASTVariable)i.next(); - IASTFunction foo = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testSimpleDoStatement() throws Exception - { - Iterator i = parse( "const int x = 3; int counter = 0; void foo() { do { ++counter; } while( counter != x ); } ").getDeclarations(); //$NON-NLS-1$ - IASTVariable x = (IASTVariable)i.next(); - IASTVariable counter = (IASTVariable)i.next(); - IASTFunction foo = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 3 ); - } - - public void testThrowStatement() throws Exception - { - Iterator i = parse( "class A { }; void foo() throw ( A ) { throw A; throw; } ").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction functionF = (IASTFunction)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - for( int j = 0; j < 2; ++j ) - assertEquals( ((IASTReference)callback.getReferences().get(j) ).getReferencedElement(), classA ); - } - - public void testScoping() throws Exception - { - Iterator i = parse( "void foo() { int x = 3; if( x == 1 ) { int x = 4; } else int x = 2; }").getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)i.next(); - Iterator subDeclarations = getDeclarations(f); - IASTVariable topX = (IASTVariable)subDeclarations.next(); - assertEquals( topX.getInitializerClause().getAssigmentExpression().getLiteralString(), "3"); //$NON-NLS-1$ - assertEquals( topX.getName(), "x"); //$NON-NLS-1$ - assertFalse( subDeclarations.hasNext() ); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 1 ); - assertEquals( ((IASTReference)callback.getReferences().get(0)).getReferencedElement(), topX ); - - Iterator level1 = getNestedScopes( f ); - IASTCodeScope codeScope = (IASTCodeScope)level1.next(); - Iterator subSubDeclarations = getDeclarations(codeScope); - IASTVariable secondX = (IASTVariable)subSubDeclarations.next(); - assertEquals( secondX.getInitializerClause().getAssigmentExpression().getLiteralString(), "4"); //$NON-NLS-1$ - codeScope = (IASTCodeScope)level1.next(); - assertFalse( level1.hasNext() ); - subSubDeclarations = getDeclarations(codeScope); - IASTVariable thirdX = (IASTVariable)subSubDeclarations.next(); - assertEquals( thirdX.getInitializerClause().getAssigmentExpression().getLiteralString(), "2"); //$NON-NLS-1$ - - } - - public void testEnumeratorReferences() throws Exception - { - Iterator i = parse( "enum E { e1, e2, e3 }; E anE = e1;").getDeclarations(); //$NON-NLS-1$ - IASTEnumerationSpecifier enumE = (IASTEnumerationSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable anE = (IASTVariable)i.next(); - IASTEnumerator e1 = (IASTEnumerator)enumE.getEnumerators().next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - assertEquals( ((IASTReference)callback.getReferences().get(0)).getReferencedElement(), enumE ); - assertEquals( ((IASTReference)callback.getReferences().get(1)).getReferencedElement(), e1 ); - } - - public void testBug42840() throws Exception - { - Iterator i = parse( "void foo(); void foo() { } class SearchMe { };").getDeclarations(); //$NON-NLS-1$ - IASTFunction fooDeclaration = (IASTFunction)i.next(); - IASTFunction fooDefinition = (IASTFunction)i.next(); - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - assertTrue( callback.getReferences().isEmpty()); - - i = parse( "class A { void f ( A ); }; void A::f( A ){ return; }" ).getDeclarations(); //$NON-NLS-1$ - classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod fooMethodDefinition = (IASTMethod)i.next(); - assertFalse( i.hasNext() ); - Iterator subIterator = getDeclarations( classSpec ); - IASTMethod fooMethodDeclaration = (IASTMethod)subIterator.next(); - assertFalse( subIterator.hasNext()); - Iterator references = callback.getReferences().iterator(); - assertEquals( callback.getReferences().size(), 3 ); - for( int j = 0; j < 3; ++j) - assertEquals( ((IASTReference)callback.getReferences().get( j )).getReferencedElement(), classSpec ); - - } - - public void testBug42872() throws Exception - { - Iterator i = parse( "struct B {}; struct D : B {}; void foo(D* dp) { B* bp = dynamic_cast(dp); }" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier structB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier structD = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction foo = (IASTFunction)i.next(); - IASTVariable bp = (IASTVariable)getDeclarations(foo).next(); - assertFalse( i.hasNext() ); - } - - public void testBug43503A() throws Exception { - Iterator i = parse("class SD_01 { void f_SD_01() {}}; int main(){ SD_01 * a = new SD_01(); a->f_SD_01(); } ").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(classA); - IASTMethod f = (IASTMethod)j.next(); - assertFalse(j.hasNext()); - IASTFunction main = (IASTFunction) i.next(); - assertFalse(i.hasNext()); - Iterator k = getDeclarations(main); - assertTrue(k.hasNext()); - } - - - public void testBug42979() throws Exception - { - Writer code = new StringWriter(); - code.write( "class OperatorOverload{\n" ); //$NON-NLS-1$ - code.write( "public:\n" ); //$NON-NLS-1$ - code.write( " bool operator==( const class OperatorOverload& that )\n" ); //$NON-NLS-1$ - code.write( " { return true; }\n" ); //$NON-NLS-1$ - code.write( " bool operator!=( const class OperatorOverload& that );\n" ); //$NON-NLS-1$ - code.write( "}; \n" ); //$NON-NLS-1$ - - code.write( "bool OperatorOverload::operator!=( const class OperatorOverload& that )\n" ); //$NON-NLS-1$ - code.write( "{ return false; }\n" ); //$NON-NLS-1$ - - Iterator i = parse( code.toString() ).getDeclarations(); - IASTClassSpecifier classOp = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator subDeclarations = getDeclarations(classOp); - IASTMethod operatorEqualsDeclaration = (IASTMethod)subDeclarations.next(); - IASTMethod operatorNotEqualsDeclaration = (IASTMethod)subDeclarations.next(); - IASTMethod operatorNotEqualDefinition = (IASTMethod)i.next(); - assertEquals( operatorNotEqualDefinition.getName(), operatorNotEqualsDeclaration.getName() ); - assertFalse( i.hasNext()); - assertEquals( callback.getReferences().size(), 4 ); - for( int j =0; j < 4; ++j ) - assertFalse( classOp.getNameOffset() == ((IASTReference)callback.getReferences().get(j)).getOffset() ); - } - /** - * class A { static int x; } int A::x = 5; - */ - public void testBug43373() throws Exception - { - Iterator i = parse( "class A { static int x; }; int A::x = 5;" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(classA); - IASTField field1 = (IASTField) j.next(); - // Note : this used to be considered a variable, not a field - IASTField field2 = (IASTField)i.next(); - assertTrue (field1.getVisiblity() == field2.getVisiblity()); - assertAllReferences( 1, createTaskList( new Task( classA ))); - } - - public void testBug39504() throws Exception - { - Iterator i = parse( "const int w = 2; int x[ 5 ]; int y = sizeof (x[w]);" ).getDeclarations(); //$NON-NLS-1$ - IASTVariable varW = (IASTVariable)i.next(); - IASTVariable varX = (IASTVariable)i.next(); - IASTVariable vary = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertEquals( callback.getReferences().size(), 2 ); - } - - public void testBug43375() throws Exception - { - IASTVariable varX = (IASTVariable)parse( "extern int x;").getDeclarations().next(); //$NON-NLS-1$ - assertTrue( varX.isExtern() ); - } - - public void testBug43503() throws Exception - { - StringBuffer buff = new StringBuffer(); - - buff.append( "class SD_02 {"); //$NON-NLS-1$ - buff.append( " public:"); //$NON-NLS-1$ - buff.append( " void f_SD_02();"); //$NON-NLS-1$ - buff.append( " };"); //$NON-NLS-1$ - buff.append( "class SD_01 {\n"); //$NON-NLS-1$ - buff.append( " public:\n"); //$NON-NLS-1$ - buff.append( " SD_02 *next;"); // REFERENCE SD_02 //$NON-NLS-1$ - buff.append( " void f_SD_01();\n"); //$NON-NLS-1$ - buff.append( "};\n"); //$NON-NLS-1$ - buff.append( "int main(){\n"); //$NON-NLS-1$ - buff.append( " SD_01 a = new SD_01();\n"); // REFERENCE SD_01 * 2 //$NON-NLS-1$ - buff.append( " a->f_SD_01();\n"); // REFERENCE a && REFERENCE f_SD_01 //$NON-NLS-1$ - buff.append( "}\n"); //$NON-NLS-1$ - buff.append( "void SD_01::f_SD_01()\n"); // REFERENCE SD_01 //$NON-NLS-1$ - buff.append( "{\n"); //$NON-NLS-1$ - buff.append( " next->f_SD_02();\n"); // REFERENCE next && reference f_SD_02 //$NON-NLS-1$ - buff.append( "}\n"); //$NON-NLS-1$ - Iterator i = parse( buff.toString() ).getDeclarations(); - IASTClassSpecifier SD_02 = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod f_SD_02 = (IASTMethod)getDeclarations( SD_02 ).next(); - IASTClassSpecifier SD_01 = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTField next= (IASTField)getDeclarations( SD_01 ).next(); - IASTFunction main = (IASTFunction)i.next(); - IASTVariable a = (IASTVariable)getDeclarations(main).next(); - IASTMethod f_SD_01 = (IASTMethod)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 8, createTaskList( new Task( SD_02), new Task( SD_01, 3 ), new Task( a ), new Task( f_SD_01 ), new Task( f_SD_02 ), new Task( next ) )); - } - - public void testBug43679_A () throws Exception - { - try{ // this used to throw a null pointer exception - Iterator i = parse( "struct Sample { int size() const; }; extern const Sample * getSample(); int trouble() { return getSample()->size(); } ", false ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(A); - IASTMethod s = (IASTMethod) j.next(); - assertFalse (j.hasNext()); - IASTFunction g = (IASTFunction) i.next(); - IASTFunction t = (IASTFunction) i.next(); - assertFalse (i.hasNext()); - Iterator ref = callback.getReferences().iterator(); - assertAllReferences( 3, createTaskList( new Task(A) , new Task( s ) , new Task (g) )); - - } catch(Exception e){ - fail(); - } - } - public void testBug43679_B () throws Exception - { - try{ // this used to throw a class cast exception - Iterator i = parse( "struct Sample{int size() const; }; struct Sample; ", false ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(A); - IASTMethod s = (IASTMethod) j.next(); - assertFalse (j.hasNext()); - IASTAbstractTypeSpecifierDeclaration forwardDecl = (IASTAbstractTypeSpecifierDeclaration)i.next(); - assertFalse (i.hasNext()); - Iterator ref = callback.getReferences().iterator(); - assertFalse (ref.hasNext()); - - } catch(Exception e){ - fail(); - } - } - - public void testBug43951() throws Exception - { - Iterator i = parse( "class B{ B(); ~B(); }; B::B(){} B::~B(){}", false ).getDeclarations(); //$NON-NLS-1$ - - IASTClassSpecifier b = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertEquals( b.getName(), "B"); //$NON-NLS-1$ - IASTMethod constructor = (IASTMethod) i.next(); - assertEquals( constructor.getName(), "B" ); //$NON-NLS-1$ - assertTrue( constructor.previouslyDeclared() ); - } - - public void testBug44342() throws Exception { - try{ - IASTScope scope = parse("class A { void f(){} void f(int){} }; int main(){ A * a = new A(); a->f();} "); //$NON-NLS-1$ - Iterator i = scope.getDeclarations(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(classA); - IASTMethod f = (IASTMethod)j.next(); - IASTMethod f2 = (IASTMethod)j.next(); - assertFalse(j.hasNext()); - IASTFunction main = (IASTFunction) i.next(); - assertFalse(i.hasNext()); - Iterator k = getDeclarations(main); - assertTrue(k.hasNext()); - IASTVariable a = (IASTVariable)k.next(); - Iterator ref = callback.getReferences().iterator(); - assertAllReferences( 4, createTaskList( new Task(classA , 2) , new Task( a ) , new Task (f) )); - - }catch (ParserException e){ - // parsing fails for now - fail(); - } - } - - - public void testCDesignatedInitializers() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "struct Inner { int a,b,c; };"); //$NON-NLS-1$ - buffer.append( "struct A { int x; int y[]; struct Inner innerArray[]; int z []; };"); //$NON-NLS-1$ - buffer.append( "struct A myA = { .x = 4, .y[3] = 4, .y[4] = 3, .innerArray[0].a = 3, .innerArray[1].b = 5, .innerArray[2].c=6, .z = { 1,4,5} };"); //$NON-NLS-1$ - Iterator i = parse( buffer.toString(), true, ParserLanguage.C ).getDeclarations(); - IASTClassSpecifier Inner = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator members = getDeclarations(Inner); - IASTField a = (IASTField)members.next(); - IASTField b = (IASTField)members.next(); - IASTField c = (IASTField)members.next(); - assertFalse( members.hasNext()); - IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - members = getDeclarations( A ); - IASTField x = (IASTField)members.next(); - IASTField y = (IASTField)members.next(); - IASTField innerArray = (IASTField)members.next(); - IASTField z = (IASTField)members.next(); - assertFalse( members.hasNext() ); - IASTVariable myA = (IASTVariable)i.next(); - assertFalse( i.hasNext() ); - assertAllReferences( 12, createTaskList( new Task( A ), - new Task( x ), - new Task( y, 2 ), - new Task( Inner ), - new Task( innerArray, 3), - new Task( a ), - new Task( b ), - new Task( c ), - new Task( z ) ) ); - } - - public void testBug39551A() throws Exception - { - IASTFunction function = (IASTFunction)parse("extern float _Complex conjf (float _Complex);", true, ParserLanguage.C).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( function.getName(), "conjf"); //$NON-NLS-1$ - assertTrue( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).isComplex() ); - } - - - - public void testCBool() throws Exception - { - IASTVariable variable = (IASTVariable)parse( "_Bool x;", true, ParserLanguage.C ).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type._BOOL ); - } - - public void testCBoolAsParameter() throws Exception - { - Iterator i = parse( "void f( _Bool b ) {} " + //$NON-NLS-1$ - "_Bool g( _Bool b ) {} " + //$NON-NLS-1$ - "void main(){" + //$NON-NLS-1$ - " _Bool b; " + //$NON-NLS-1$ - " f(b);" + //$NON-NLS-1$ - " f( g( (_Bool) 1 ) );" + //$NON-NLS-1$ - "}", //$NON-NLS-1$ - true, ParserLanguage.C ).getDeclarations(); - - IASTFunction f = (IASTFunction) i.next(); - IASTFunction g = (IASTFunction) i.next(); - IASTFunction main = (IASTFunction) i.next(); - IASTVariable b = (IASTVariable) getDeclarations( main ).next(); - - assertAllReferences( 4, createTaskList( new Task( f, 2 ), new Task( b ), new Task( g ) ) ); - } - - public void testBug44510() throws Exception - { - Iterator i = parse( "int initialize(); " + //$NON-NLS-1$ - "int initialize( char ){} " + //$NON-NLS-1$ - "int initialize(){ return 1; } " + //$NON-NLS-1$ - "void main(){ int i = initialize(); }" ).getDeclarations(); //$NON-NLS-1$ - - IASTFunction function1 = (IASTFunction) i.next(); - assertEquals( function1.previouslyDeclared(), false ); - - IASTFunction function2 = (IASTFunction) i.next(); - assertEquals( function2.previouslyDeclared(), false ); - - IASTFunction function3 = (IASTFunction) i.next(); - assertEquals( function3.previouslyDeclared(), true ); - - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - assertAllReferences( 1, createTaskList( new Task( function3 ) ) ); - } - - public void testBug44925() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "class MyClass { };"); //$NON-NLS-1$ - buffer.append( "class MyClass myObj1;"); //$NON-NLS-1$ - buffer.append( "enum MyEnum { Item1 };"); //$NON-NLS-1$ - buffer.append( "enum MyEnum myObj2;"); //$NON-NLS-1$ - Iterator i = parse( buffer.toString() ).getDeclarations(); - - IASTClassSpecifier MyClass = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable myObj1 = (IASTVariable) i.next(); - IASTEnumerationSpecifier MyEnum = (IASTEnumerationSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable myObj2 = (IASTVariable) i.next(); - - assertFalse( i.hasNext() ); - - assertAllReferences( 2, createTaskList( new Task( MyClass ), new Task( MyEnum ) ) ); - } - - public void testBug44838() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "class A { int myX; A( int x ); };\n"); //$NON-NLS-1$ - buffer.append( "A::A( int x ) : myX( x ) { if( x == 5 ) myX++; }\n"); //$NON-NLS-1$ - Iterator i = parse( buffer.toString() ).getDeclarations(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTField myX = (IASTField)getDeclarations( classA ).next(); - IASTMethod constructor = (IASTMethod)i.next(); - IASTParameterDeclaration parmX = (IASTParameterDeclaration)constructor.getParameters().next(); - assertTrue( constructor.isConstructor()); - assertFalse(i.hasNext()); - } - - public void testBug46165() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "class A { int myX; A( int x ); };\n"); //$NON-NLS-1$ - buffer.append( "A::A( int x ) : myX( x ) { if( x == 5 ) myX++; }\n"); //$NON-NLS-1$ - Iterator i = parse( buffer.toString() ).getDeclarations(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTField myX = (IASTField)getDeclarations( classA ).next(); - IASTMethod constructor = (IASTMethod)i.next(); - IASTParameterDeclaration parmX = (IASTParameterDeclaration)constructor.getParameters().next(); - assertTrue( constructor.isConstructor()); - assertAllReferences( 4, createTaskList( new Task( classA ), new Task( myX, 2 ), new Task( parmX ))); - assertFalse(i.hasNext()); - } - - public void testBug47624() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "struct s { }; \n" ); //$NON-NLS-1$ - buffer.append( "void f ( int s ) { \n" ); //$NON-NLS-1$ - buffer.append( " struct s sInstance; \n" ); //$NON-NLS-1$ - buffer.append( "}\n"); //$NON-NLS-1$ - - Iterator i = parse( buffer.toString() ).getDeclarations(); - IASTClassSpecifier structS = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTFunction function = (IASTFunction) i.next(); - Iterator fnIter = getDeclarations( function ); - IASTVariable sInstance = (IASTVariable) fnIter.next(); - IASTElaboratedTypeSpecifier elaborated = (IASTElaboratedTypeSpecifier) sInstance.getAbstractDeclaration().getTypeSpecifier(); - assertFalse( fnIter.hasNext() ); - - assertAllReferences( 1, createTaskList( new Task( structS ) ) ); - assertFalse( i.hasNext() ); - } - - public void testQualifiedLookup() throws Exception{ - //this is meant to test that on a->f, the lookup for f is qualified - //the namespace is necessary because of bug 47926 - StringBuffer buffer = new StringBuffer(); - buffer.append( "namespace N {" ); //$NON-NLS-1$ - buffer.append( " void f () {} \n" ); //$NON-NLS-1$ - buffer.append( " class A { }; \n" ); //$NON-NLS-1$ - buffer.append( "}" ); //$NON-NLS-1$ - buffer.append( "void main() { N::A * a = new N::A(); a->f(); } "); //$NON-NLS-1$ - - Iterator i = parse( buffer.toString() ).getDeclarations(); - - IASTNamespaceDefinition namespace = (IASTNamespaceDefinition) i.next(); - Iterator nsIter = getDeclarations( namespace ); - - IASTFunction f = (IASTFunction) nsIter.next(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)nsIter.next()).getTypeSpecifier(); - - assertFalse( nsIter.hasNext() ); - - IASTFunction main = (IASTFunction) i.next(); - - Iterator fnIter = getDeclarations( main ); - IASTVariable a = (IASTVariable) fnIter.next(); - - assertAllReferences( 5, createTaskList( new Task( namespace, 2 ), new Task( classA, 2 ), new Task( a ) ) ); - } - - public void testBug43110() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append("void x( int y, ... );\n"); //$NON-NLS-1$ - buffer.append("void y( int x... );\n"); //$NON-NLS-1$ - buffer.append("void z(...);"); //$NON-NLS-1$ - Iterator i = parse(buffer.toString() ).getDeclarations(); - while( i.hasNext() ) - assertTrue( ((IASTFunction)i.next()).takesVarArgs() ); - } - - public void testBug43110_XRef() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "void foo( ... ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void main( ){ foo( 1 ); }\n" ); //$NON-NLS-1$ - - Iterator i = parse( buffer.toString() ).getDeclarations(); - IASTFunction foo = (IASTFunction)i.next(); - assertTrue( foo.takesVarArgs() ); - assertAllReferences( 1, createTaskList( new Task( foo ) ) ); - - buffer = new StringBuffer(); - buffer.append( "void foo( ... ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void foo( int x ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void main( ){ foo( 1 ); }\n" ); //$NON-NLS-1$ - - i = parse( buffer.toString() ).getDeclarations(); - IASTFunction foo1 = (IASTFunction)i.next(); - IASTFunction foo2 = (IASTFunction)i.next(); - assertTrue( foo1.takesVarArgs() ); - assertFalse( foo2.takesVarArgs() ); - assertAllReferences( 1, createTaskList( new Task( foo2 ) ) ); - - buffer = new StringBuffer(); - buffer.append( "void foo( ... ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void foo( int x = 1) {}\n" ); //$NON-NLS-1$ - buffer.append( "void main( ){ foo(); }\n" ); //$NON-NLS-1$ - - i = parse( buffer.toString() ).getDeclarations(); - foo1 = (IASTFunction)i.next(); - foo2 = (IASTFunction)i.next(); - assertTrue( foo1.takesVarArgs() ); - assertFalse( foo2.takesVarArgs() ); - assertAllReferences( 1, createTaskList( new Task( foo2 ) ) ); - - buffer = new StringBuffer(); - buffer.append( "void foo( int x ... ) {}\n" ); //$NON-NLS-1$ - buffer.append( "void main( ){ foo( 1, 2, 'a' ); }\n" ); //$NON-NLS-1$ - - i = parse( buffer.toString() ).getDeclarations(); - foo = (IASTFunction)i.next(); - assertTrue( foo.takesVarArgs() ); - assertAllReferences( 1, createTaskList( new Task( foo ) ) ); - } - - public void testErrorHandling_1() throws Exception - { - Iterator i = parse( "A anA; int x = c; class A {}; A * anotherA = &anA; int b;", false ).getDeclarations(); //$NON-NLS-1$ - IASTVariable x = (IASTVariable)i.next(); - assertEquals( x.getName(), "x"); //$NON-NLS-1$ - IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertEquals( A.getName(), "A"); //$NON-NLS-1$ - IASTVariable anotherA = (IASTVariable)i.next(); - assertEquals( anotherA.getName(), "anotherA"); //$NON-NLS-1$ - IASTVariable b = (IASTVariable)i.next(); - assertEquals( b.getName(), "b"); //$NON-NLS-1$ - assertFalse(i.hasNext()); // should be true - } - - public void testBug44340() throws Exception { - // inline function with reference to variables declared after them - IASTScope scope = parse ("class A{ int getX() {return x[1];} int x[10];};", false ); //$NON-NLS-1$ - Iterator i = scope.getDeclarations(); - IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator j = getDeclarations(classA); - IASTMethod g = (IASTMethod)j.next(); - IASTField x = (IASTField)j.next(); - assertFalse(j.hasNext()); - assertAllReferences( 1, createTaskList( new Task( x ))); - } - - public void testBug47628() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void h(char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(unsigned char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(signed char) { } // not shown in outline, parsed as char\n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTFunction h1 = (IASTFunction) i.next(); - assertEquals( h1.getName(), "h"); //$NON-NLS-1$ - Iterator parms = h1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "char" ); //$NON-NLS-1$ - - IASTFunction h2 = (IASTFunction) i.next(); - assertEquals( h2.getName(), "h"); //$NON-NLS-1$ - parms = h2.getParameters(); - parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "unsigned char" ); //$NON-NLS-1$ - - IASTFunction h3 = (IASTFunction) i.next(); - assertEquals( h3.getName(), "h"); //$NON-NLS-1$ - parms = h3.getParameters(); - parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "signed char" ); //$NON-NLS-1$ - - assertFalse( i.hasNext() ); - } - - public void testBug47636() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void f( char [] ); \n" ); //$NON-NLS-1$ - writer.write( "void f( char * ){} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTFunction fDec = (IASTFunction) i.next(); - assertEquals( fDec.getName(), "f"); //$NON-NLS-1$ - - - IASTFunction fDef = (IASTFunction) i.next(); - assertEquals( fDef.getName(), "f"); //$NON-NLS-1$ - - assertTrue( fDef.previouslyDeclared() ); - - assertFalse( i.hasNext() ); - } - - public void testBug45697() throws Exception - { - Writer writer = new StringWriter(); - writer.write( " int f( bool ); \n"); //$NON-NLS-1$ - writer.write( " int f( char ){ } "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTFunction f1 = (IASTFunction) i.next(); - assertEquals( f1.getName(), "f"); //$NON-NLS-1$ - Iterator parms = f1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "bool" ); //$NON-NLS-1$ - - IASTFunction f2 = (IASTFunction) i.next(); - assertEquals( f2.getName(), "f"); //$NON-NLS-1$ - parms = f2.getParameters(); - parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "char" ); //$NON-NLS-1$ - assertFalse( f2.previouslyDeclared() ); - assertFalse( i.hasNext() ); - } - - public void testBug54639() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "typedef enum _A { } A, *pA; " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)i.next(); - assertEquals( typedef.getName(), "A" ); //$NON-NLS-1$ - IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) typedef.getAbstractDeclarator().getTypeSpecifier(); - assertEquals( enumSpec.getName(), "_A" ); //$NON-NLS-1$ - - IASTTypedefDeclaration typedef2 = (IASTTypedefDeclaration)i.next(); - assertEquals( typedef2.getName(), "pA" ); //$NON-NLS-1$ - assertEquals( typedef2.getAbstractDeclarator().getPointerOperators().next(), ASTPointerOperator.POINTER ); - enumSpec = (IASTEnumerationSpecifier) typedef2.getAbstractDeclarator().getTypeSpecifier(); - assertEquals( enumSpec.getName(), "_A" ); //$NON-NLS-1$ - - assertFalse( i.hasNext() ); - } - - public void testBug55163() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void foo() { \n"); //$NON-NLS-1$ - writer.write( " int i, n; \n"); //$NON-NLS-1$ - writer.write( " double di; \n"); //$NON-NLS-1$ - writer.write( " for( i = n - 1, di = (double)( i + i ); i > 0; i-- ){ } \n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - - Iterator iter = parse( writer.toString() ).getDeclarations(); - - IASTFunction foo = (IASTFunction) iter.next(); - assertFalse( iter.hasNext() ); - iter = getDeclarations( foo ); - IASTVariable i = (IASTVariable)iter.next(); - IASTVariable n = (IASTVariable)iter.next(); - IASTVariable di = (IASTVariable)iter.next(); - - assertAllReferences( 7, createTaskList( new Task( n ), new Task( i, 5 ), new Task( di ) ) ); - - } - public void testBug55673() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "struct Example { int i; int ( * pfi ) ( int ); }; "); //$NON-NLS-1$ - - Iterator iter = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier example = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)iter.next()).getTypeSpecifier(); - assertFalse( iter.hasNext() ); - - iter = getDeclarations( example ); - - IASTField i = (IASTField) iter.next(); - IASTField pfi = (IASTField) iter.next(); - - assertFalse( iter.hasNext() ); - } - - public void testBug54531() throws Exception - { - Iterator i = parse( "typedef enum _A {} A, *pA;" ).getDeclarations(); //$NON-NLS-1$ - IASTTypedefDeclaration theEnum = (IASTTypedefDeclaration) i.next(); - assertEquals( theEnum.getName(), "A"); //$NON-NLS-1$ - IASTTypedefDeclaration thePointer = (IASTTypedefDeclaration) i.next(); - assertEquals( thePointer.getName(), "pA" ); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug56516() throws Exception - { - Iterator i = parse( "typedef struct blah sb;").getDeclarations(); //$NON-NLS-1$ - IASTTypedefDeclaration sb = (IASTTypedefDeclaration) i.next(); - assertEquals( sb.getName(), "sb"); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - IASTElaboratedTypeSpecifier elab = ((IASTElaboratedTypeSpecifier)sb.getAbstractDeclarator().getTypeSpecifier()); - assertEquals( elab.getName(), "blah"); //$NON-NLS-1$ - assertEquals( elab.getClassKind(), ASTClassKind.STRUCT ); - } - - public void testBug53786() throws Exception - { - Iterator i = parse( "struct Example { struct Data * data; };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier Example = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - assertEquals( Example.getName(), "Example"); //$NON-NLS-1$ - assertEquals( Example.getClassKind(), ASTClassKind.STRUCT ); - Iterator j = getDeclarations( Example ); - IASTField data = (IASTField) j.next(); - assertFalse( j.hasNext() ); - assertEquals( data.getName(), "data" ); //$NON-NLS-1$ - } - - public void testBug54029() throws Exception - { - Iterator i = parse( "typedef int T; T i;" ).getDeclarations(); //$NON-NLS-1$ - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration) i.next(); - assertEquals( typedef.getName(), "T"); //$NON-NLS-1$ - assertTrue( typedef.getAbstractDeclarator().getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)typedef.getAbstractDeclarator().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - IASTVariable variable = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertEquals( variable.getName(), "i"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getTypename(), "T" ); //$NON-NLS-1$ - assertNotNull( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier() ); - assertEquals( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), typedef ); - } - - public void testBug47625() throws Exception - { - Writer writer = new StringWriter(); - writer.write("struct s { int num; }; "); //$NON-NLS-1$ - writer.write("namespace ns{ "); //$NON-NLS-1$ - writer.write(" struct s { double num; };"); //$NON-NLS-1$ - writer.write(" s inner = { 3.14 };"); //$NON-NLS-1$ - writer.write(" ::s outer = { 42 };"); //$NON-NLS-1$ - writer.write("}"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier outerS = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTNamespaceDefinition ns = (IASTNamespaceDefinition) i.next(); - - i = getDeclarations( ns ); - IASTClassSpecifier innerS = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable inner = (IASTVariable) i.next(); - IASTVariable outer = (IASTVariable) i.next(); - - assertAllReferences( 2, createTaskList( new Task( outerS ), new Task( innerS ) ) ); - } - - public void testBug57754() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct X { " ); //$NON-NLS-1$ - writer.write( " typedef int T; " ); //$NON-NLS-1$ - writer.write( " void f( T ); " ); //$NON-NLS-1$ - writer.write( "}; " ); //$NON-NLS-1$ - writer.write( "void X::f( T ) { } " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier X = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTMethod f = (IASTMethod) i.next(); - - assertTrue( f.previouslyDeclared() ); - - i = getDeclarations( X ); - IASTTypedefDeclaration T = (IASTTypedefDeclaration) i.next(); - - assertAllReferences( 3, createTaskList( new Task( X ), new Task( T, 2 ) ) ); - } - - public void testBug57800() throws Exception - { - Writer writer= new StringWriter(); - writer.write( "class G2 { int j; };"); //$NON-NLS-1$ - writer.write( "typedef G2 AltG2;"); //$NON-NLS-1$ - writer.write( "class AltG3 : AltG2 { int x;};"); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier G2 = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTTypedefDeclaration AltG2 = (IASTTypedefDeclaration) i.next(); - IASTClassSpecifier AltG3 = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - Iterator baseClauses = AltG3.getBaseClauses(); - IASTBaseSpecifier baseClause = (IASTBaseSpecifier) baseClauses.next(); - assertFalse( baseClauses.hasNext() ); - assertEquals( baseClause.getParentClassSpecifier(), AltG2 ); - } - - public void testBug46246() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct A { "); //$NON-NLS-1$ - writer.write( " struct B { int ab; } b; "); //$NON-NLS-1$ - writer.write( " int a; "); //$NON-NLS-1$ - writer.write( "}; "); //$NON-NLS-1$ - writer.write( "struct A a1; "); //$NON-NLS-1$ - writer.write( "struct B b1; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString(), true, ParserLanguage.C ).getDeclarations(); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTVariable a1 = (IASTVariable) i.next(); - IASTVariable b1 = (IASTVariable) i.next(); - i = getDeclarations( A ); - IASTField b = (IASTField) i.next(); - IASTField a = (IASTField) i.next(); - IASTClassSpecifier B = (IASTClassSpecifier) b.getAbstractDeclaration().getTypeSpecifier(); - - assertAllReferences( 2, createTaskList( new Task( A ), new Task( B ) ) ); - } - - public void testBug45235() throws Exception - { - Iterator i = parse( "class A { friend class B; friend void f(); }; " ).getDeclarations(); //$NON-NLS-1$ - - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - i = getDeclarations( A ); - - IASTAbstractTypeSpecifierDeclaration forewardDecl = (IASTAbstractTypeSpecifierDeclaration)i.next(); - IASTFunction f = (IASTFunction) i.next(); - - assertTrue( forewardDecl.isFriendDeclaration() ); - assertTrue( f.isFriend() ); - } - - public void testBug57791() throws Exception - { - Writer writer = new StringWriter(); - writer.write(" void f() { "); //$NON-NLS-1$ - writer.write(" struct astruct astruct; "); //$NON-NLS-1$ - writer.write(" astruct.foo++; "); //$NON-NLS-1$ - writer.write(" }"); //$NON-NLS-1$ - - parse( writer.toString(), true, ParserLanguage.C ); - } - - public void testBug44249() throws Exception - { - - Iterator i = parse( "class SD_01 { public:\n void SD_01::f_SD_01();};" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier SD_01 = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - i = getDeclarations( SD_01 ); - IASTMethod f_SD_01 = (IASTMethod) i.next(); - assertFalse( i.hasNext() ); - assertEquals( f_SD_01.getName(), "f_SD_01"); //$NON-NLS-1$ - assertAllReferences( 1, createTaskList( new Task( SD_01 ))); - } - - public void testBug59149() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A{ friend class B; friend class B; };" ); //$NON-NLS-1$ - writer.write( "class B{ };" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier B = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - } - - public void testBug59302() throws Exception - { - Writer writer = new StringWriter(); - writer.write("class A { class N{}; }; "); //$NON-NLS-1$ - writer.write("class B { friend class A::N; }; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTClassSpecifier B = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - i = getDeclarations( A ); - IASTClassSpecifier N = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - assertFalse( A.getFriends().hasNext() ); - assertEquals( B.getFriends().next(), N ); - } - - - - public void testULong() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#ifndef ASMINCLUDE\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned short ushort;\n"); //$NON-NLS-1$ - writer.write( "typedef volatile unsigned long semaphore;\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned long ulong;\n"); //$NON-NLS-1$ - writer.write( "#ifndef _NO_LONGLONG\n"); //$NON-NLS-1$ - writer.write( "typedef long long longlong;\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned long long ulonglong;\n"); //$NON-NLS-1$ - writer.write( "#endif /* _NO_LONGLONG */\n"); //$NON-NLS-1$ - writer.write( "#endif /* ASMINCLUDE */\n"); //$NON-NLS-1$ - writer.write( "typedef struct section_type_ {\n"); //$NON-NLS-1$ - writer.write( "ulong source;\n"); //$NON-NLS-1$ - writer.write( "ulong dest;\n"); //$NON-NLS-1$ - writer.write( "ulong bytes;\n"); //$NON-NLS-1$ - writer.write( "} section_type;\n"); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTTypedefDeclaration ushort = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration semaphore = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration ulong = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration longlong = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration ulonglong = (IASTTypedefDeclaration) i.next(); - IASTTypedefDeclaration section_type = (IASTTypedefDeclaration) i.next(); - IASTClassSpecifier section_type_ = (IASTClassSpecifier) section_type.getAbstractDeclarator().getTypeSpecifier(); - Iterator fields = getDeclarations(section_type_); - IASTField source = (IASTField) fields.next(); - assertEquals( ((IASTSimpleTypeSpecifier)source.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), ulong ); - IASTField dest = (IASTField) fields.next(); - assertEquals( ((IASTSimpleTypeSpecifier)dest.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), ulong ); - IASTField bytes = (IASTField) fields.next(); - assertEquals( ((IASTSimpleTypeSpecifier)bytes.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), ulong ); - - assertFalse( i.hasNext() ); - - } - - public void testBug47926() throws Exception - { - Iterator i = parse( "void f() {} class A {}; void main() { A * a = new A(); a->f(); }", false ).getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction) i.next(); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - IASTFunction main = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - i = getDeclarations( main ); - IASTVariable a = (IASTVariable) i.next(); - assertAllReferences( 3, createTaskList( new Task( A, 2 ), new Task( a ))); - } - - public void testBug50984_ASTMethod_getOwnerClassSpecifier_ClassCastException() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < typename _OutIter > " ); //$NON-NLS-1$ - writer.write( "class num_put { " ); //$NON-NLS-1$ - writer.write( " typedef _OutIter iter_type; " ); //$NON-NLS-1$ - writer.write( " template< typename _ValueT > " ); //$NON-NLS-1$ - writer.write( " iter_type _M_convert_float( iter_type ); " ); //$NON-NLS-1$ - writer.write( "}; " ); //$NON-NLS-1$ - writer.write( "template < typename _OutIter > " ); //$NON-NLS-1$ - writer.write( "template < typename _ValueT > " ); //$NON-NLS-1$ - writer.write( "_OutIter num_put<_OutIter>::_M_convert_float( _OutIter ) { } " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier num_put = (IASTClassSpecifier) template.getOwnedDeclaration(); - IASTTemplateDeclaration defn = (IASTTemplateDeclaration) i.next(); - IASTMethod convert = (IASTMethod) defn.getOwnedDeclaration(); - - assertEquals( convert.getOwnerClassSpecifier(), num_put ); - } - - public void testGloballyQualifiedUsingDeclaration() throws Exception - { - Iterator declarations = parse( "int iii; namespace N { using ::iii; }" ).getDeclarations(); //$NON-NLS-1$ - - IASTVariable iii = (IASTVariable) declarations.next(); - IASTNamespaceDefinition namespaceN = (IASTNamespaceDefinition)declarations.next(); - - IASTUsingDeclaration using = (IASTUsingDeclaration)(getDeclarations(namespaceN).next()); - - assertEquals( callback.getReferences().size(), 1 ); - - Iterator references = callback.getReferences().iterator(); - assertEquals( ((IASTReference)references.next()).getReferencedElement(), iii ); - } - - public void test57513_new() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A{ A(); A( int ); }; \n" ); //$NON-NLS-1$ - writer.write( " void f() { \n" ); //$NON-NLS-1$ - writer.write( " A * a1 = new A; \n" ); //$NON-NLS-1$ - writer.write( " A * a2 = new(1)A(); \n" ); //$NON-NLS-1$ - writer.write( " A * a3 = new A( 1 ); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - IASTFunction f = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - i = getDeclarations( A ); - IASTMethod constructor1 = (IASTMethod) i.next(); - IASTMethod constructor2 = (IASTMethod) i.next(); - assertFalse( i.hasNext() ); - - assertReferenceTask( new Task( constructor1, 2, false, false ) ); - assertReferenceTask( new Task( constructor2, 1, false, false ) ); - assertReferenceTask( new Task( A, 3, false, false ) ); - } - - public void test57513_NoConstructor() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A{ }; \n" ); //$NON-NLS-1$ - writer.write( " void f() { \n" ); //$NON-NLS-1$ - writer.write( " A * a1 = new A; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - IASTFunction f = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - - assertReferenceTask( new Task( A, 2, false, false ) ); - } - - public void test57513_ctorinit() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A{ A(); A( A * ); }; \n" ); //$NON-NLS-1$ - writer.write( "class B : public A { B(); }; \n" ); //$NON-NLS-1$ - writer.write( "B::B():A( new A ){} \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - IASTClassSpecifier B = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - IASTMethod constructorB = (IASTMethod) i.next(); - assertFalse( i.hasNext() ); - - i = getDeclarations( A ); - IASTMethod constructor1 = (IASTMethod) i.next(); - IASTMethod constructor2 = (IASTMethod) i.next(); - assertFalse( i.hasNext() ); - - assertReferenceTask( new Task( constructor1, 1, false, false ) ); - assertReferenceTask( new Task( constructor2, 1, false, false ) ); - assertReferenceTask( new Task( A, 2, false, false ) ); - } - - public void test575513_qualified() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "namespace Foo{ " ); //$NON-NLS-1$ - writer.write( " class Bar{ public : Bar(); }; " ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - writer.write( "void main(){ " ); //$NON-NLS-1$ - writer.write( " Foo::Bar * bar = new Foo::Bar(); " ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTNamespaceDefinition namespace = (IASTNamespaceDefinition) i.next(); - IASTFunction main = (IASTFunction) i.next(); - i = getDeclarations( namespace ); - IASTClassSpecifier Bar = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next() ).getTypeSpecifier(); - i = getDeclarations( Bar ); - IASTMethod constructor = (IASTMethod) i.next(); - - assertAllReferences( 4, createTaskList( new Task(namespace, 2 ), new Task( Bar, 1 ), new Task( constructor, 1 ) ) ); - } - - public void testBug60944() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "typedef int OurInt;\n"); //$NON-NLS-1$ - writer.write( "class A { int x; };\n"); //$NON-NLS-1$ - writer.write( "typedef A AnotherA;\n"); //$NON-NLS-1$ - writer.write( "typedef AnotherA SecondA;\n"); //$NON-NLS-1$ - writer.write( "typedef OurInt AnotherInt;\n" ); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTTypedefDeclaration OurInt = (IASTTypedefDeclaration) i.next(); - assertTrue( OurInt.getFinalTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)OurInt.getFinalTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTTypedefDeclaration AnotherA = (IASTTypedefDeclaration) i.next(); - assertEquals( AnotherA.getFinalTypeSpecifier(), A ); - IASTTypedefDeclaration SecondA = (IASTTypedefDeclaration) i.next(); - assertEquals( SecondA.getFinalTypeSpecifier(), A ); - IASTTypedefDeclaration AnotherInt = (IASTTypedefDeclaration) i.next(); - assertTrue( AnotherInt.getFinalTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)AnotherInt.getFinalTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - - assertFalse( i.hasNext() ); - } - - public void testDestructorReference() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class ABC {\n"); //$NON-NLS-1$ - writer.write( " public:\n"); //$NON-NLS-1$ - writer.write( " ~ABC(){ }\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "int main() { ABC * abc = new ABC();\n"); //$NON-NLS-1$ - writer.write( "abc->~ABC();\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - - Iterator declarations = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier ABC = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - IASTFunction main = (IASTFunction) declarations.next(); - assertFalse( declarations.hasNext() ); - Iterator members = getDeclarations(ABC); - IASTFunction destructor = (IASTFunction) members.next(); - assertFalse( members.hasNext() ); - Iterator localVariables = getDeclarations( main ); - IASTVariable variable = (IASTVariable) localVariables.next(); - assertFalse( localVariables.hasNext() ); - assertAllReferences( 4, createTaskList( new Task( ABC, 2 ), new Task( variable ), new Task( destructor ))); - } - - public void testBug39676_tough() throws Exception - { - parse( "int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };", true, ParserLanguage.C ); //$NON-NLS-1$ - } - - public void testBug60939() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - Writer writer = new StringWriter(); - writer.write( "namespace ABC { class DEF { }; }\n"); //$NON-NLS-1$ - if( i == 0 ) - writer.write( "using namespace ABC;\n"); //$NON-NLS-1$ - else - writer.write( "using ABC::DEF;\n"); //$NON-NLS-1$ - writer.write( "class GHI : public DEF { };"); //$NON-NLS-1$ - Iterator d = parse( writer.toString() ).getDeclarations(); - IASTNamespaceDefinition ABC = (IASTNamespaceDefinition) d.next(); - if( i == 0 ) - assertTrue( d.next() instanceof IASTUsingDirective ); - else - assertTrue( d.next() instanceof IASTUsingDeclaration ); - IASTClassSpecifier GHI = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)d.next()).getTypeSpecifier(); - Iterator baseClauses = GHI.getBaseClauses(); - IASTBaseSpecifier baseClause = (IASTBaseSpecifier) baseClauses.next(); - IASTClassSpecifier DEF = (IASTClassSpecifier) baseClause.getParentClassSpecifier(); - String [] theTruth = new String[2]; - theTruth[0] = "ABC"; //$NON-NLS-1$ - theTruth[1] = "DEF"; //$NON-NLS-1$ - qualifiedNamesEquals( DEF.getFullyQualifiedName(), theTruth ); - } - - - } - - public void testBug64010() throws Exception - { - Writer writer = new StringWriter(); - writer.write( " #define ONE else if (0) { } \n"); //$NON-NLS-1$ - writer.write( " #define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE \n "); //$NON-NLS-1$ - writer.write( " #define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN \n "); //$NON-NLS-1$ - writer.write( " #define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN \n"); //$NON-NLS-1$ - writer.write("void foo() "); //$NON-NLS-1$ - writer.write("{ "); //$NON-NLS-1$ - writer.write(" if (0) { } "); //$NON-NLS-1$ - writer.write(" /* 11,000 else if's. */ "); //$NON-NLS-1$ - writer.write(" THOU THOU THOU THOU THOU THOU THOU THOU THOU THOU THOU "); //$NON-NLS-1$ - writer.write("} "); //$NON-NLS-1$ - - Iterator d = parse( writer.toString() ).getDeclarations(); - - IASTFunction f = (IASTFunction) d.next(); - } - - public void testBug64271() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "typedef int DWORD;\n" ); //$NON-NLS-1$ - writer.write( "typedef char BYTE;\n"); //$NON-NLS-1$ - writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n"); //$NON-NLS-1$ - writer.write( "enum e {\n"); //$NON-NLS-1$ - writer.write( "blah1 = 5,\n"); //$NON-NLS-1$ - writer.write( "blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n"); //$NON-NLS-1$ - writer.write( "blah3\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "e mye = blah;\n"); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug47752() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class BBC\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( "int x;\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "void func( BBC bar )\n"); //$NON-NLS-1$ - writer.write( "try\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "catch ( BBC error )\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( " //... error handling code ...\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - parse( writer.toString() ); - assertEquals( callback.getReferences().size(), 2 ); - } - public void testBug61972() throws Exception - { - parse( "#define DEF1(A1) A1\n#define DEF2 DEF1(DEF2)\nDEF2;", false ); //$NON-NLS-1$ - } - - public void testBug65569() throws Exception - { - parse( "class Sample;\nstruct Sample { /* ... */ };" ); //$NON-NLS-1$ - } - - public void testBug64268() throws Exception - { - Writer writer = new StringWriter(); - writer.write("#define BODY \\\n"); //$NON-NLS-1$ - writer.write("for (;;) { \\\n"); //$NON-NLS-1$ - writer.write("/* this multi-line comment messes \\\n"); //$NON-NLS-1$ - writer.write("up the parser. */ }\n"); //$NON-NLS-1$ - writer.write(" void abc() {\n"); //$NON-NLS-1$ - writer.write("BODY\n"); //$NON-NLS-1$ - writer.write("}\n"); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug67622() throws Exception - { - parse( "const char * x = __FILE__;"); //$NON-NLS-1$ - } - - public void testBug67680() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template < class T> class Base {}; \n" ); //$NON-NLS-1$ - writer.write( "class Derived : public Base, Base, foo {}; \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString(), false ).getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier base = (IASTClassSpecifier) template.getOwnedDeclaration(); - IASTClassSpecifier derived = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - //only Base is a valid parent, Base and foo are not expected to show up in the iterator. - i = derived.getBaseClauses(); - IASTBaseSpecifier parent = (IASTBaseSpecifier) i.next(); - assertFalse( i.hasNext() ); - - assertEquals( parent.getParentClassSpecifier(), base ); - } - - public void testTypeIDSignature() throws Exception - { - IASTVariable v = (IASTVariable) parse( "int * v = (int*)0;").getDeclarations().next();//$NON-NLS-1$ - IASTTypeId typeId = v.getInitializerClause().getAssigmentExpression().getTypeId(); - assertEquals( typeId.getFullSignature(), "int *"); //$NON-NLS-1$ - } - - public void testUnaryAmperCast() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "void f( char * ); \r\n "); //$NON-NLS-1$ - writer.write( "void f( char ); \n "); //$NON-NLS-1$ - writer.write( "void main() { \n "); //$NON-NLS-1$ - writer.write( " char * t = new char [ 5 ]; \n "); //$NON-NLS-1$ - writer.write( " f( &t[1] ); \n "); //$NON-NLS-1$ - writer.write( "} \n "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTFunction f1 = (IASTFunction) i.next(); - IASTFunction f2 = (IASTFunction) i.next(); - - IASTFunction main = (IASTFunction) i.next(); - IASTVariable t = (IASTVariable) getDeclarations( main ).next(); - - assertAllReferences( 2, createTaskList( new Task( f1, 1, false, false), new Task( t ) ) ); - } - - public void testBug68235() throws Exception{ - Writer writer = new StringWriter(); - writer.write( " struct xTag { int x; }; "); //$NON-NLS-1$ - writer.write( " typedef xTag xType; "); //$NON-NLS-1$ - writer.write( " typedef struct yTag { int x; } yType; "); //$NON-NLS-1$ - writer.write( " class C1 { xType x; yType y; }; "); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - - IASTClassSpecifier xTag = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - IASTTypedefDeclaration xType = (IASTTypedefDeclaration) i.next(); - IASTSimpleTypeSpecifier typeSpec = (IASTSimpleTypeSpecifier) xType.getAbstractDeclarator().getTypeSpecifier(); - assertEquals( typeSpec.getTypeSpecifier(), xTag ); - - IASTTypedefDeclaration yType = (IASTTypedefDeclaration) i.next(); - IASTClassSpecifier yTag = (IASTClassSpecifier) yType.getAbstractDeclarator().getTypeSpecifier(); - - IASTClassSpecifier C1 = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - i = getDeclarations( C1 ); - - IASTField x = (IASTField) i.next(); - IASTField y = (IASTField) i.next(); - assertFalse( i.hasNext() ); - - IASTSimpleTypeSpecifier simple = (IASTSimpleTypeSpecifier) x.getAbstractDeclaration().getTypeSpecifier(); - assertEquals( simple.getTypeSpecifier(), xType ); - simple = (IASTSimpleTypeSpecifier) y.getAbstractDeclaration().getTypeSpecifier(); - assertEquals( simple.getTypeSpecifier(), yType ); - } - - public void testBug60407() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct ZZZ { int x, y, z; };\r\n" ); //$NON-NLS-1$ - writer.write( "typedef struct ZZZ _FILE;\n" ); //$NON-NLS-1$ - writer.write( "typedef _FILE FILE;\n" ); //$NON-NLS-1$ - writer.write( "static void static_function(FILE * lcd){}\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( "FILE * file = 0;\n" ); //$NON-NLS-1$ - writer.write( "static_function( file );\n" ); //$NON-NLS-1$ - writer.write( "return 0;\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug68623() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "class A { \n" ); //$NON-NLS-1$ - writer.write( " A(); \n" ); //$NON-NLS-1$ - writer.write( " class sub{}; \n" ); //$NON-NLS-1$ - writer.write( " sub * x; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "A::A() : x( (sub *) 0 ) {} \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); - - writer = new StringWriter(); - writer.write( "class A { \n" ); //$NON-NLS-1$ - writer.write( " A() : x (0) {} \n" ); //$NON-NLS-1$ - writer.write( " int x; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - i = A.getDeclarations(); - IASTMethod constructor = (IASTMethod) i.next(); - IASTField x = (IASTField) i.next(); - - assertAllReferences( 1, createTaskList( new Task( x ) ) ); - } - - public void testBug69798() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "enum Flags { FLAG1, FLAG2 }; \n" ); //$NON-NLS-1$ - writer.write( "int f() { int a, b; b = ( a ? FLAG1 : 0 ) | FLAG2; } \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); - } - - public void testBug69662() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "class A { operator float * (); }; \n" ); //$NON-NLS-1$ - writer.write( "A::operator float * () { } \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); - } - - - public void testBug68528() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "namespace N526026\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "template \n" ); //$NON-NLS-1$ - writer.write( "class T526026\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "typedef int diff;\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "\n" ); //$NON-NLS-1$ - writer.write( "template\n" ); //$NON-NLS-1$ - writer.write( "inline T526026< T >\n" ); //$NON-NLS-1$ - writer.write( "operator+(typename T526026::diff d, const T526026 & x )\n" ); //$NON-NLS-1$ - writer.write( "{ return T526026< T >(); }\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString(), false ); - } - - public void testBug71094() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "using namespace DOESNOTEXIST;\n" ); //$NON-NLS-1$ - writer.write( "class A { int x; };\n" ); //$NON-NLS-1$ - Iterator i = parse( writer.toString(), false ).getDeclarations(); - assertTrue( i.hasNext() ); - assertTrue( i.next() instanceof IASTAbstractTypeSpecifierDeclaration ); - assertFalse( i.hasNext() ); - } - - public void testPredefinedSymbol_bug70928() throws Exception { - // GNU builtin storage class type __cdecl preceded by a custom return type - Iterator i = parse("typedef int size_t; \n int __cdecl foo(); \n").getDeclarations();//$NON-NLS-1$ - IASTTypedefDeclaration td = (IASTTypedefDeclaration) i.next(); - IASTFunction fd = (IASTFunction) i.next(); - assertFalse(i.hasNext()); - } - - public void testBug73652() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "#define DoSuperMethodA IDoSuperMethodA\n" ); //$NON-NLS-1$ - writer.write( "#define IDoSuperMethodA(a,b,c) IIntuition->IDoSuperMethodA(a,b,c)\n" ); //$NON-NLS-1$ - writer.write( "void hang(void)\n" ); //$NON-NLS-1$ - writer.write( "{\n" ); //$NON-NLS-1$ - writer.write( "DoSuperMethodA(0,0,0);\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString() , false ); - } - - public void testBug73428() throws Exception - { - parse( "namespace { }");//$NON-NLS-1$ - assertTrue( callback.problems.isEmpty() ); - parse( "namespace { };");//$NON-NLS-1$ - assertTrue( callback.problems.isEmpty() ); - parse( "namespace { int abc; };");//$NON-NLS-1$ - assertTrue( callback.problems.isEmpty() ); - parse( "namespace { int abc; }");//$NON-NLS-1$ - assertTrue( callback.problems.isEmpty() ); - } - - public void testBug73615() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - StringWriter writer = new StringWriter(); - if( i == 0 ) - writer.write( "class B;\n"); //$NON-NLS-1$ - writer.write( "class A { A( B * ); };\n"); //$NON-NLS-1$ - if( i == 0 ) - parse( writer.toString() ); - else - parse( writer.toString(), false ); - } - } - - public void testBug74180() throws Exception - { - parse( "enum DHCPFOBoolean { false, true } additionalHB, more_payload; \n", true, ParserLanguage.C ); //$NON-NLS-1$ - assertTrue( callback.problems.isEmpty() ); - } - - public void testBug72691() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "PINT pint; \n" ); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - assertTrue( i.next() instanceof IASTTypedefDeclaration ); - assertTrue( i.next() instanceof IASTTypedefDeclaration ); - assertTrue( i.next() instanceof IASTVariable); - assertFalse( i.hasNext() ); - assertTrue( callback.problems.isEmpty() ); - } - - public void testBug72691_2() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "namespace N { \n" ); //$NON-NLS-1$ - writer.write( " typedef int * PINT; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "using namespace N; \n" ); //$NON-NLS-1$ - writer.write( "PINT pint; \n" ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug74328() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "int\n" ); //$NON-NLS-1$ - writer.write( "main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( " char *sign;\n" ); //$NON-NLS-1$ - writer.write( "sign = \"\"; // IProblem generated here, syntax error\n" ); //$NON-NLS-1$ - writer.write( "return argc;\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug71733() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void foo( int );\n"); //$NON-NLS-1$ - writer.write( "#define BLAH() \\\n"); //$NON-NLS-1$ - writer.write( " foo ( /* slash / is misinterpreted as end of comment */ \\\n"); //$NON-NLS-1$ - writer.write( " 4 );\n"); //$NON-NLS-1$ - writer.write( "int f() { BLAH() }\n"); //$NON-NLS-1$ - parse( writer.toString() ); - assertEquals( callback.getReferences().size(), 1 ); - } - - public void testBug69526() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "unsigned inkernel;\n" ); //$NON-NLS-1$ - writer.write( "#define lock_kernel() (inkernel |= 0x01)" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {" ); //$NON-NLS-1$ - writer.write( "lock_kernel();" ); //$NON-NLS-1$ - writer.write( "}" ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug69454() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define CATCH_ALL_EXCEPTIONS() \\\n" ); //$NON-NLS-1$ - writer.write( " catch( Exception &ex ) { handleException( ex ); } \\\n" ); //$NON-NLS-1$ - writer.write( " catch( ... ) { handleException(); } \n" ); //$NON-NLS-1$ - writer.write( "class Exception; \n" ); //$NON-NLS-1$ - writer.write( "void handleException( Exception & ex ) {} \n" ); //$NON-NLS-1$ - writer.write( "void handleException() {} \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " try { int i; } \n" ); //$NON-NLS-1$ - writer.write( " CATCH_ALL_EXCEPTIONS(); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - parse( writer.toString() ); - assertFalse( callback.getProblems().hasNext() ); - } - - - public void testBug72692A() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "extern double pow(double, double);\n"); //$NON-NLS-1$ - writer.write( "extern double pow2(double, double){}\n"); //$NON-NLS-1$ - writer.write( "namespace DS {\n"); //$NON-NLS-1$ - writer.write( "using ::pow;\n"); //$NON-NLS-1$ - writer.write( "using ::pow2;\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "using DS::pow;\n"); //$NON-NLS-1$ - writer.write( "using DS::pow2;\n"); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug72692B() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "extern double pow(double, double);\n"); //$NON-NLS-1$ - writer.write( "namespace DS {\n"); //$NON-NLS-1$ - writer.write( "using ::pow;\n"); //$NON-NLS-1$ - writer.write( "inline float pow(float __x, float __y)\n" ); //$NON-NLS-1$ - writer.write( "{ return ::pow(static_cast(__x), static_cast(__y)); }\n" ); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "using namespace DS;\n"); //$NON-NLS-1$ - writer.write( "float foo() { double d1 = 3.0, d2 = 4.0; return pow(d1, d2); }"); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug72692C() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "extern double pow(double, double){}\n"); //$NON-NLS-1$ - writer.write( "namespace DS {\n"); //$NON-NLS-1$ - writer.write( "using ::pow;\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "using DS::pow;\n"); //$NON-NLS-1$ - parse( writer.toString() ); - } - - - public void testBug74575A() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "double pow(double, double);\n"); //$NON-NLS-1$ - writer.write( "float pow(float __x, float __y)\n" ); //$NON-NLS-1$ - writer.write( "{ return 0; }\n"); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTFunction doublePow = (IASTFunction) i.next(); - IASTFunction floatPow = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - assertEquals( floatPow.getName(), "pow" ); //$NON-NLS-1$ - assertEquals( doublePow.getName(), "pow"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)doublePow.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.DOUBLE ); - assertEquals( ((IASTSimpleTypeSpecifier)floatPow.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); - assertFalse( doublePow.hasFunctionBody() ); - assertTrue( floatPow.hasFunctionBody() ); - } - - public void testBug75338() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class Thrown { };\n"); //$NON-NLS-1$ - writer.write( "void foo() throw( Thrown );"); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - assertTrue( i.next() instanceof IASTAbstractTypeSpecifierDeclaration ); - IASTFunction foo = (IASTFunction) i.next(); - assertFalse( i.hasNext() ); - IASTExceptionSpecification exSpec = foo.getExceptionSpec(); - assertNotNull( exSpec ); - Iterator typeIds = exSpec.getTypeIds(); - assertTrue( typeIds.hasNext() ); - IASTTypeId typeId = (IASTTypeId) typeIds.next(); - assertEquals( typeId.getTypeOrClassName(), "Thrown" ); //$NON-NLS-1$ - } - - public void testBug75532() throws Exception - { - try { - Writer writer = new StringWriter(); - writer.write( "#if 2147483647 == 0x7fffffff\n"); // check reported hex problem //$NON-NLS-1$ - writer.write( "#error This was equal, but not for the eclipse.\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "#if 010 == 8\n"); // check octal //$NON-NLS-1$ - writer.write( "#error octal test\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - - parse( writer.toString() ); - - assertTrue(false); - } catch (ParserException pe) { - // expected IProblem - } finally { - Iterator probs = callback.getProblems(); - assertTrue( probs.hasNext() ); - Object ipo = probs.next(); - assertTrue( ipo instanceof IProblem ); - IProblem ip = (IProblem)ipo; - assertTrue(ip.getArguments().indexOf("This was equal, but not for the eclipse") >= 0); //$NON-NLS-1$ - assertTrue( probs.hasNext() ); - ipo = probs.next(); - assertTrue( ipo instanceof IProblem ); - ip = (IProblem)ipo; - assertTrue(ip.getArguments().indexOf("octal test") >= 0); //$NON-NLS-1$ - } - } - - public void testBug74847() throws Exception { - String code = "class A : public FOO {};"; //$NON-NLS-1$ - Iterator i = parse( code, false ).getDeclarations(); - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( A.getBaseClauses().hasNext() ); - i = callback.getProblems(); - IProblem problem = (IProblem) i.next(); - assertEquals( problem.getID(), IProblem.SEMANTIC_NAME_NOT_FOUND ); - assertEquals( problem.getSourceStart(), code.indexOf( "FOO" ) ); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug76696() throws Exception{ - Writer writer = new StringWriter(); - writer.write(" void f(){ \n"); //$NON-NLS-1$ - writer.write(" if( A a) { \n"); //$NON-NLS-1$ - writer.write(" } else { \n"); //$NON-NLS-1$ - writer.write(" } \n"); //$NON-NLS-1$ - writer.write(" } \n"); //$NON-NLS-1$ - - parse( writer.toString(), false ); - Iterator i = callback.getProblems(); - IProblem problem = (IProblem) i.next(); - assertEquals( IProblem.SYNTAX_ERROR, problem.getID() ); - assertFalse( i.hasNext() ); - } - - public void testBug74069() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "int f() { \n"); //$NON-NLS-1$ - writer.write( " int a, b, c; \n"); //$NON-NLS-1$ - writer.write( " if( a < b ) \n"); //$NON-NLS-1$ - writer.write( " if( b < c ) \n"); //$NON-NLS-1$ - writer.write( " return b; \n"); //$NON-NLS-1$ - writer.write( " else if ( a < c ) \n"); //$NON-NLS-1$ - writer.write( " return c; \n"); //$NON-NLS-1$ - writer.write( " else \n"); //$NON-NLS-1$ - writer.write( " return a; \n"); //$NON-NLS-1$ - writer.write( " else if( a < c ) \n"); //$NON-NLS-1$ - writer.write( " return a; \n"); //$NON-NLS-1$ - writer.write( " else if( b < c ) \n"); //$NON-NLS-1$ - writer.write( " return c; \n"); //$NON-NLS-1$ - writer.write( " else \n"); //$NON-NLS-1$ - writer.write( " return b; \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - - parse( writer.toString() ); - Iterator i = callback.getProblems(); - assertFalse( i.hasNext() ); - } - public void testBug77805() throws Exception { - Writer writer = new StringWriter(); - writer.write("#if X // Do something only if X is true\n"); //$NON-NLS-1$ - writer.write("/* some statements */\n"); //$NON-NLS-1$ - writer.write("#endif\n"); //$NON-NLS-1$ - parse(writer.toString()); - } - - public void testBug77821() throws Exception { - Writer writer = new StringWriter(); - writer.write("typedef struct { /* ... */ }TYPE;\n"); //$NON-NLS-1$ - writer.write("void ptrArith(const TYPE* pType) {\n"); //$NON-NLS-1$ - writer.write("TYPE *temp = 0;\n"); //$NON-NLS-1$ - writer.write("temp = (TYPE*)(pType + 1); /* Parser error is here */\n}\n"); //$NON-NLS-1$ - parse(writer.toString()); - } - - public void testBug77009() throws Exception - { - Iterator i = parse("int foo(volatile int &);\n").getDeclarations(); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction) i.next(); - Iterator parms = foo.getParameters(); - IASTParameterDeclaration blank = (IASTParameterDeclaration)parms.next(); - assertEquals( ASTUtil.getType( blank ), "volatile int&" ); //$NON-NLS-1$ - } - - - public void testBug77281() throws Exception { - Writer writer = new StringWriter(); - writer.write("void fun2(float a, float b) {}\n"); //$NON-NLS-1$ - writer.write("int main() { fun2(0.24f, 0.25f); }\n"); //$NON-NLS-1$ - parse(writer.toString()); - } - - public void testBug77921() throws Exception { - Writer writer = new StringWriter(); - writer.write("void f()\n{\n"); //$NON-NLS-1$ - writer.write("static float v0[] = { -1.0f, -1.0f, 1.0f };\n}\n"); //$NON-NLS-1$ - parse(writer.toString()); - } - - public void testBug76763() throws Exception - { - Writer writer = new StringWriter(); - writer.write("#error oops!"); //$NON-NLS-1$ - try { - parse(writer.toString()); - } catch (ParserException pe) { - // expected IProblem - } finally { - Iterator i = callback.getProblems(); - assertTrue( i.hasNext() ); - Object ipo = i.next(); - assertTrue( ipo instanceof IProblem ); - IProblem ip = (IProblem)ipo; - assertTrue(new String(ip.getArguments()).equals("oops!")); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - } - public void testBug71317A() throws Exception { - Writer writer = new StringWriter(); - writer.write("void f();\n"); //$NON-NLS-1$ - writer.write("namespace NS {\n"); //$NON-NLS-1$ - writer.write("using ::f;\n"); //$NON-NLS-1$ - writer.write("using ::f;\n}"); //$NON-NLS-1$ - parse(writer.toString()); - } - - public void testBug71317B() throws Exception { - Writer writer = new StringWriter(); - writer.write("void f();\n"); //$NON-NLS-1$ - writer.write("namespace NS {\n"); //$NON-NLS-1$ - writer.write("void f();\n"); //$NON-NLS-1$ - writer.write("using ::f;\n}"); //$NON-NLS-1$ - - try{ - parse(writer.toString()); - assertTrue(false); - } catch (ParserException pe) { - // expected IProblem - } finally { - Iterator probs = callback.getProblems(); - assertTrue( probs.hasNext() ); - Object ipo = probs.next(); - assertTrue( ipo instanceof IProblem ); - IProblem ip = (IProblem)ipo; - assertEquals(ip.getSourceLineNumber(), 4); - } - } - - public void testBug77097() throws Exception { - Writer writer = new StringWriter(); - writer.write("#define SOME_MACRO() { \\\r\n"); //$NON-NLS-1$ - writer.write("printf(\"Hello World\"); \\\r\n"); //$NON-NLS-1$ - writer.write("printf(\"Good morning\"); \\\r\n"); //$NON-NLS-1$ - parse(writer.toString()); - } - - public void testBug77276() throws Exception { - Writer writer = new StringWriter(); - writer.write("#if (!defined(OS_LIBMODE_R) && !defined(OS_LIBMODE_RP) && \\\r\n"); //$NON-NLS-1$ - writer.write("!defined(OS_LIBMODE_T))\r\n"); //$NON-NLS-1$ - writer.write("#define OS_LIBMODE_DP\r\n"); //$NON-NLS-1$ - writer.write("#endif\r\n"); //$NON-NLS-1$ - parse(writer.toString()); - } - - public void testBug78165() throws Exception { - Writer writer = new StringWriter(); - writer.write("struct Node {\n"); //$NON-NLS-1$ - writer.write("struct Node* Next; // OK: Refers to Node at global scope\n"); //$NON-NLS-1$ - writer.write("struct Data* Data; // OK: Declares type Data at global scope and member Data\n"); //$NON-NLS-1$ - writer.write("};\n"); //$NON-NLS-1$ - writer.write("struct Data {\n"); //$NON-NLS-1$ - writer.write("struct Node* Node; // OK: Refers to Node at global scope\n"); //$NON-NLS-1$ - writer.write("friend struct Glob; // OK: Refers to (as yet) undeclared Glob at global scope.\n"); //$NON-NLS-1$ - writer.write("};\n"); //$NON-NLS-1$ - writer.write("struct Base {\n"); //$NON-NLS-1$ - writer.write("struct Data; // OK: Declares nested Data\n"); //$NON-NLS-1$ - writer.write("struct ::Data* thatData; // OK: Refers to ::Data\n"); //$NON-NLS-1$ - writer.write("struct Base::Data* thisData; // OK: Refers to nested Data\n"); //$NON-NLS-1$ - writer.write("friend class ::Data; // OK: global Data is a friend\n"); //$NON-NLS-1$ - writer.write("friend class Data; // OK: nested Data is a friend\n"); //$NON-NLS-1$ - writer.write("struct Data { /* ... */ }; // Defines nested Data\n"); //$NON-NLS-1$ - writer.write("struct Data; // OK: Redeclares nested Data\n"); //$NON-NLS-1$ - writer.write("};\n"); //$NON-NLS-1$ - writer.write("struct Data; // OK: Redeclares Data at global scope\n"); //$NON-NLS-1$ - writer.write("struct Base::Data* pBase; // OK: refers to nested Data\n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTAbstractTypeSpecifierDeclaration node = (IASTAbstractTypeSpecifierDeclaration)i.next(); - assertEquals(node.getStartingLine(), 1); - assertTrue(node.getTypeSpecifier() instanceof IASTClassSpecifier); - IASTClassSpecifier typeSpec = (IASTClassSpecifier)node.getTypeSpecifier(); - assertEquals(typeSpec.getName(), "Node"); //$NON-NLS-1$ - IASTAbstractTypeSpecifierDeclaration data = (IASTAbstractTypeSpecifierDeclaration)i.next(); - assertEquals(data.getStartingLine(), 5); - assertTrue(data.getTypeSpecifier() instanceof IASTClassSpecifier); - typeSpec = (IASTClassSpecifier)data.getTypeSpecifier(); - assertEquals(typeSpec.getName(), "Data"); //$NON-NLS-1$ - IASTAbstractTypeSpecifierDeclaration base = (IASTAbstractTypeSpecifierDeclaration)i.next(); - assertEquals(base.getStartingLine(), 9); - assertTrue(base.getTypeSpecifier() instanceof IASTClassSpecifier); - typeSpec = (IASTClassSpecifier)base.getTypeSpecifier(); - assertEquals(typeSpec.getName(), "Base"); //$NON-NLS-1$ - IASTAbstractTypeSpecifierDeclaration data2 = (IASTAbstractTypeSpecifierDeclaration)i.next(); - assertEquals(data2.getStartingLine(), 18); - assertTrue(data2.getTypeSpecifier() instanceof IASTElaboratedTypeSpecifier); - IASTElaboratedTypeSpecifier typeSpec2 = (IASTElaboratedTypeSpecifier)data2.getTypeSpecifier(); - assertEquals(typeSpec2.getName(), "Data"); //$NON-NLS-1$ - IASTVariable pBase = (IASTVariable)i.next(); - assertEquals(pBase.getStartingLine(), 19); - } - - public void testBug79471() throws Exception { - Writer writer = new StringWriter(); - writer.write("void testFloatAccess(float * fp) {\n"); //$NON-NLS-1$ - writer.write("#define VAL 2.0f\n"); //$NON-NLS-1$ - writer.write("if(*fp > VAL) { /* Syntax error is here */\n}\n}\n"); //$NON-NLS-1$ - parse(writer.toString()); - writer = new StringWriter(); - writer.write("void testFloatAccess(float * fp) {\n"); //$NON-NLS-1$ - writer.write("#define VAL 2.0l\n"); //$NON-NLS-1$ - writer.write("if(*fp > VAL) { /* Syntax error is here */\n}\n}\n"); //$NON-NLS-1$ - parse(writer.toString()); - writer = new StringWriter(); - writer.write("void testFloatAccess(float * fp) {\n"); //$NON-NLS-1$ - writer.write("#define VAL 2.0f\n"); //$NON-NLS-1$ - writer.write("if(VAL > VAL) { /* Syntax error is here */\n}\n}\n"); //$NON-NLS-1$ - parse(writer.toString()); - } - - public void testBug79787() throws Exception { - try { - parse("#error what?\r\n"); - } catch (ParserException pe) { - // expected IProblem - } finally { - Iterator probs = callback.getProblems(); - assertTrue(probs.hasNext()); - Object ipo = probs.next(); - assertTrue(ipo instanceof IProblem); - IProblem ip = (IProblem) ipo; - assertEquals(ip.getArguments(), "what?"); - } - } - - public void testBug79810A() throws Exception { - Writer writer = new StringWriter(); - writer.write("void foo() {\n"); //$NON-NLS-1$ - writer.write("int test;\n"); //$NON-NLS-1$ - writer.write("if ((__extension__ ({ union { int __in; int __i; } __u; __u.__in = (test); __u.__i; })) & 0x7f) {}\n}\n"); //$NON-NLS-1$ - parse(writer.toString()); - - writer = new StringWriter(); - writer.write("#define __WTERMSIG(status) ((status) & 0x7f)\n"); //$NON-NLS-1$ - writer.write("#define __WIFEXITED(status) (__WTERMSIG(status) == 0)\n"); //$NON-NLS-1$ - writer.write("#define __WAIT_INT(status) (__extension__ ({ union { int __in; int __i; } __u; \\\n"); //$NON-NLS-1$ - writer.write(" __u.__in = (test); __u.__i; }))\n"); //$NON-NLS-1$ - writer.write("#define WIFEXITED(status) __WIFEXITED(__WAIT_INT(status))\n"); //$NON-NLS-1$ - writer.write("void foo() {\n"); //$NON-NLS-1$ - writer.write("int test;\n"); //$NON-NLS-1$ - writer.write("if (WIFEXITED(test)) {}\n}\n"); //$NON-NLS-1$ - parse(writer.toString()); - } - - public void testBug79921_79227() throws Exception { - Writer writer = new StringWriter(); - writer.write("/* some\n* commented\n* code\n*/\n"); //$NON-NLS-1$ - writer.write("#define g_message(...) g_log (1, 2, __VA_ARGS__);\n"); //$NON-NLS-1$ - writer.write("int g_log (int a, int b, ...) { return 0; }\n"); //$NON-NLS-1$ - writer.write("int foo2() {\n"); //$NON-NLS-1$ - writer.write("g_message(\"a string [as] f%2.2x (%2)\") \\\n"); //$NON-NLS-1$ - writer.write("// ^ the culprit\n}\n"); //$NON-NLS-1$ - parse(writer.toString()); - } - - public void testBug100992() throws Exception { - Writer writer = new StringWriter(); - writer.write( "class String { public: String(); ~String(); };"); //$NON-NLS-1$ - writer.write( "String::String(){}"); //$NON-NLS-1$ - writer.write( "String::~String(){}"); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTAbstractTypeSpecifierDeclaration StringDecl = (IASTAbstractTypeSpecifierDeclaration) i.next(); - Iterator members = ((IASTClassSpecifier)StringDecl.getTypeSpecifier()).getDeclarations(); - IASTMethod cons_decl = (IASTMethod) members.next(); - assertTrue( cons_decl.isConstructor() ); - IASTMethod dest_decl = (IASTMethod) members.next(); - assertTrue( dest_decl.isDestructor() ); - assertFalse( members.hasNext() ); - IASTMethod cons_defn = (IASTMethod) i.next(); - assertTrue( cons_defn.isConstructor() ); - IASTMethod dest_defn = (IASTMethod) i.next(); - assertTrue( dest_defn.isDestructor() ); - assertFalse( i.hasNext() ); - } - - -} - diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java deleted file mode 100644 index 6b507df2aa6..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseBaseTest.java +++ /dev/null @@ -1,1039 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.Stack; - -import junit.framework.TestCase; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ParserUtil; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassReference; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTEnumeratorReference; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFieldReference; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTFunctionReference; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTMethodReference; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTParameterReference; -import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; -import org.eclipse.cdt.core.parser.ast.IASTReference; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypedefReference; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTVariableReference; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ParserException; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTClassReference; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTEnumerationReference; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTEnumeratorReference; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTFieldReference; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTFunctionReference; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTMethodReference; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTNamespaceReference; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTParameterReference; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateParameterReference; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTypedefReference; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTVariableReference; - -/** - * @author jcamelon - * - */ -public class CompleteParseBaseTest extends TestCase -{ - /** - * - */ - public CompleteParseBaseTest() - { - super(); - // TODO Auto-generated constructor stub - } - /** - * @param name - */ - public CompleteParseBaseTest(String name) - { - super(name); - // TODO Auto-generated constructor stub - } - public static class Scope implements IASTScope - { - private List decls = new ArrayList(); - private final IASTScope scope; - public Scope( IASTScope scope ) - { - this.scope = scope; - } - - public void addDeclaration( IASTDeclaration d ) - { - decls.add(d); - } - - public Iterator getDeclarations() - { - return decls.iterator(); - } - - /** - * @return - */ - public IASTScope getScope() - { - - return scope; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind, org.eclipse.cdt.core.parser.ast.IASTNode) - */ - public ILookupResult lookup(String prefix, LookupKind[] kind, IASTNode context, IASTExpression functionParameters) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNode#getFileIndex() - */ - public int getFileIndex() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNode#setFileIndex(int) - */ - public void setFileIndex(int index) { - // TODO Auto-generated method stub - - } - - } - - public static class CodeScope extends Scope implements IASTCodeScope - { - private List nestedScopes = new ArrayList(); - /** - * @param scope - */ - public CodeScope(IASTCodeScope scope) - { - super(scope); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCodeScope#getOwnerCodeScope() - */ - public IASTCodeScope getOwnerCodeScope() - { - return ((IASTCodeScope)getScope()).getOwnerCodeScope(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - public void addNewScope( IASTCodeScope s ) - { - nestedScopes.add( s ); - } - - public Iterator getCodeBlocks() - { - return nestedScopes.iterator(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCodeScope#getContainingFunction() - */ - public IASTFunction getContainingFunction() { - // TODO Auto-generated method stub - return null; - } - } - - public static class FullParseCallback implements ISourceElementRequestor - { - private List references = new ArrayList(); - private List forewardDecls = new ArrayList(); - private Stack inclusions = new Stack(); - private Scope compilationUnit; - - public FullParseCallback() - { -// System.out.println( "NEW"); -// System.out.println(); - } - - public void finalize() - { -// System.out.println( ); - } - - public IASTScope getCompilationUnit() - { - return compilationUnit; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable) - */ - public void acceptVariable(IASTVariable variable) - { - getCurrentScope().addDeclaration( variable ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void acceptFunctionDeclaration(IASTFunction function) - { - getCurrentScope().addDeclaration(function); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDirective(org.eclipse.cdt.core.parser.ast.IASTUsingDirective) - */ - public void acceptUsingDirective(IASTUsingDirective usageDirective) - { - getCurrentScope().addDeclaration(usageDirective); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration) - */ - public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) - { - getCurrentScope().addDeclaration(usageDeclaration); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptASMDefinition(org.eclipse.cdt.core.parser.ast.IASTASMDefinition) - */ - public void acceptASMDefinition(IASTASMDefinition asmDefinition) - { - getCurrentScope().addDeclaration(asmDefinition); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefDeclaration(org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration) - */ - public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef) - { - getCurrentScope().addDeclaration(typedef); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier) - */ - public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration) - */ - public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) - { - getCurrentScope().addDeclaration( abstractDeclaration ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void enterFunctionBody(IASTFunction function) - { - pushCodeScope( function ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void exitFunctionBody(IASTFunction function) - { - popScope(); - getCurrentScope().addDeclaration(function); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void enterCompilationUnit(IASTCompilationUnit cu) - { - pushScope( cu ); - this.compilationUnit = getCurrentScope(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void enterInclusion(IASTInclusion inclusion) - { - pushInclusion( inclusion ); - } - - /** - * @param inclusion - */ - private void pushInclusion(IASTInclusion inclusion) - { - inclusions.push( inclusion ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) - { - pushScope( namespaceDefinition ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#entesrClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - public void enterClassSpecifier(IASTClassSpecifier classSpecification) - { - pushScope( classSpecification ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) - { - pushScope( linkageSpec ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) - */ - public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) - { - pushScope( declaration ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) - */ - public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) - */ - public void enterTemplateInstantiation(IASTTemplateInstantiation instantiation) - { - pushScope( instantiation ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void acceptMethodDeclaration(IASTMethod method) - { - getCurrentScope().addDeclaration( method ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void enterMethodBody(IASTMethod method) - { - pushCodeScope(method); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void exitMethodBody(IASTMethod method) - { - popScope(); - getCurrentScope().addDeclaration(method); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField) - */ - public void acceptField(IASTField field) - { - getCurrentScope().addDeclaration(field); - - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) - */ - public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) - { - popScope(); - getCurrentScope().addDeclaration( declaration ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) - */ - public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) - */ - public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) - { - popScope(); - getCurrentScope().addDeclaration( instantiation ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) - { - popScope(); - getCurrentScope().addDeclaration(linkageSpec); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - public void exitClassSpecifier(IASTClassSpecifier classSpecification) - { - popScope(); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) - { - popScope(); - getCurrentScope().addDeclaration(namespaceDefinition); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void exitInclusion(IASTInclusion inclusion) - { - popInclusion(); - } - - /** - * - */ - private void popInclusion() - { - inclusions.pop(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void exitCompilationUnit(IASTCompilationUnit cu ) - { - popScope(); - } - - - - private Stack scopes = new Stack(); - protected Scope getCurrentScope() - { - return (Scope)scopes.peek(); - } - - protected CodeScope getCurrentCodeScope() - { - if( scopes.peek() instanceof CodeScope ) - return (CodeScope)scopes.peek(); - return null; - } - - protected Scope popScope() - { - Scope s = (Scope)scopes.pop(); - h.put( s.getScope(), s ); - --depth; - return s; - } - - protected void pushScope( IASTScope scope ) - { - scopes.push( new Scope( scope )); - ++depth; - } - - Hashtable h = new Hashtable(); - - public Scope lookup( IASTScope s) - { - return (Scope)h.get(s); - } - - public CodeScope lookup( IASTCodeScope s ) - { - return (CodeScope)h.get(s); - } - - - List problems = new ArrayList(); - private int depth = 0; - - public Iterator getProblems() { - return problems.iterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem) - */ - public boolean acceptProblem(IProblem problem) - { - problems.add( problem ); - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro) - */ - public void acceptMacro(IASTMacro macro) - { - // TODO Auto-generated method stub - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassReference) - */ - public void acceptClassReference(IASTClassReference reference) - { - processReference( reference ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefReference(org.eclipse.cdt.core.parser.ast.IASTTypedefReference) - */ - public void acceptTypedefReference(IASTTypedefReference reference) - { - processReference( reference ); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptNamespaceReference(org.eclipse.cdt.core.parser.ast.IASTNamespaceReference) - */ - public void acceptNamespaceReference(IASTNamespaceReference reference) - { - processReference( reference ); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationReference(org.eclipse.cdt.core.parser.ast.IASTEnumerationReference) - */ - public void acceptEnumerationReference(IASTEnumerationReference reference) - { - processReference( reference ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariableReference(org.eclipse.cdt.core.parser.ast.IASTVariableReference) - */ - public void acceptVariableReference(IASTVariableReference reference) - { - processReference( reference ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionReference(org.eclipse.cdt.core.parser.ast.IASTFunctionReference) - */ - public void acceptFunctionReference(IASTFunctionReference reference) - { - processReference(reference); - } - - protected void processReference(IASTReference reference) - { - ISourceElementCallbackDelegate referencedElement = reference.getReferencedElement(); - IASTReference r = null; - if (referencedElement instanceof IASTTypedefDeclaration) - r = new ASTTypedefReference(reference.getOffset(), - (IASTTypedefDeclaration) referencedElement); - if (referencedElement instanceof IASTEnumerationSpecifier) - r = new ASTEnumerationReference(reference.getOffset(), - (IASTEnumerationSpecifier) referencedElement); - if (referencedElement instanceof IASTTemplateParameter) - r = new ASTTemplateParameterReference(reference.getOffset(), - (IASTTemplateParameter) referencedElement); - if (referencedElement instanceof IASTParameterDeclaration) - r = new ASTParameterReference(reference.getOffset(), - (IASTParameterDeclaration) referencedElement); - if (referencedElement instanceof IASTTypeSpecifier) - r = new ASTClassReference(reference.getOffset(), - (IASTTypeSpecifier) referencedElement); - if (referencedElement instanceof IASTNamespaceDefinition) - r = new ASTNamespaceReference(reference.getOffset(), - (IASTNamespaceDefinition) referencedElement); - if (referencedElement instanceof IASTFunction) - r = new ASTFunctionReference(reference.getOffset(), - (IASTFunction) referencedElement); - if (referencedElement instanceof IASTMethod) - r = new ASTMethodReference(reference.getOffset(), (IASTMethod) referencedElement); - if (referencedElement instanceof IASTField) - r = new ASTFieldReference(reference.getOffset(), (IASTField) referencedElement); - if (referencedElement instanceof IASTVariable) - r = new ASTVariableReference(reference.getOffset(), - (IASTVariable) referencedElement); - if (referencedElement instanceof IASTEnumerator) - r = new ASTEnumeratorReference(reference.getOffset(), - (IASTEnumerator) referencedElement); - if( r != null ) - references.add( r ); -// System.out.println( "Callback received Reference to " + reference.getName() + " @ offset " + reference.getOffset() ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFieldReference(org.eclipse.cdt.core.parser.ast.IASTFieldReference) - */ - public void acceptFieldReference(IASTFieldReference reference) - { - processReference( reference ); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodReference(org.eclipse.cdt.core.parser.ast.IASTMethodReference) - */ - public void acceptMethodReference(IASTMethodReference reference) - { - processReference( reference ); - - } - - public List getReferences() - { - return references; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier) - */ - public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType) - { - forewardDecls.add( elaboratedType ); - } - /** - * @return - */ - public List getForewardDecls() - { - return forewardDecls; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCodeBlock(org.eclipse.cdt.core.parser.ast.IASTScope) - */ - public void enterCodeBlock(IASTCodeScope scope) { - pushCodeScope( scope ); - } - - /** - * @param scope - */ - protected void pushCodeScope(IASTCodeScope scope) - { - scopes.push( new CodeScope( scope ) ); - ++depth; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCodeBlock(org.eclipse.cdt.core.parser.ast.IASTScope) - */ - public void exitCodeBlock(IASTCodeScope scope) { - popScope(); - if( getCurrentCodeScope() != null ) - getCurrentCodeScope().addNewScope(scope); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumeratorReference(org.eclipse.cdt.core.parser.ast.IASTEnumerationReference) - */ - public void acceptEnumeratorReference(IASTEnumeratorReference reference) - { - processReference( reference ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptParameterReference(org.eclipse.cdt.internal.core.parser.ast.complete.ASTParameterReference) - */ - public void acceptParameterReference(IASTParameterReference reference) - { - processReference( reference ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String) - */ - public CodeReader createReader(String finalPath, Iterator workingCopies) { - return ParserUtil.createReader(finalPath,workingCopies); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTemplateParameterReference(org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference) - */ - public void acceptTemplateParameterReference(IASTTemplateParameterReference reference) { - processReference( reference ); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFriendDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void acceptFriendDeclaration(IASTDeclaration declaration) { - getCurrentScope().addDeclaration( declaration ); - } - - /** - * @return - */ - public boolean isBalanced() { - return depth == 0; - } - } - - protected Iterator getNestedScopes( IASTCodeScope scope ) - { - CodeScope s = callback.lookup( scope ); - if( s != null ) - return s.getCodeBlocks(); - return null; - - } - protected Iterator getDeclarations(IASTScope scope) - { - Scope s = callback.lookup( scope ); - if( s != null ) - return s.getDeclarations(); - return null; - } - protected FullParseCallback callback; - - protected IASTScope parse( String code ) throws ParserException, ParserFactoryError - { - return parse( code, true, ParserLanguage.CPP ); - } - - protected IASTScope parse( String code, boolean throwOnError ) throws ParserException, ParserFactoryError - { - return parse( code, throwOnError, ParserLanguage.CPP ); - } - - protected IASTScope parse(String code, boolean throwOnError, ParserLanguage language) throws ParserException, ParserFactoryError - { - callback = new FullParseCallback(); - IParser parser = ParserFactory.createParser( - ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), //$NON-NLS-1$ - ParserMode.COMPLETE_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.COMPLETE_PARSE, language, null - ); - boolean parseResult = parser.parse(); - // throw exception if there are generated IProblems - if( (! parseResult || callback.getProblems().hasNext() ) && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ - if( parseResult ) - { - assertTrue( ((Parser)parser).validateCaches()); - assertTrue( callback.isBalanced() ); - } - return callback.getCompilationUnit(); - } - - protected void assertReferences( - ISourceElementCallbackDelegate element, - int expectedDistinctReferenceCount, - boolean allowDuplicates, boolean allowNameMatching ) - { - Set matches = new HashSet(); - Iterator allReferences = callback.getReferences().iterator(); - while( allReferences.hasNext() ) - { - IASTReference r = (IASTReference)allReferences.next(); - if( r.getReferencedElement() == element ) - { - assertEquals( r.getName(), ((IASTOffsetableNamedElement)element).getName() ); - if( ! matches.add( r ) && ! allowDuplicates ) - fail( "Duplicate reference found for ISourceElementCallbackDelegate: " + element + " @ offset " + r.getOffset() ); //$NON-NLS-1$ //$NON-NLS-2$ - } - else - { - if( r.getReferencedElement() instanceof IASTQualifiedNameElement && - element instanceof IASTQualifiedNameElement && - allowNameMatching ) - { - if( qualifiedNamesEquals( - ((IASTQualifiedNameElement)r.getReferencedElement()).getFullyQualifiedName(), - ((IASTQualifiedNameElement)element).getFullyQualifiedName() - ) - ) - { - - if( ! matches.add( r ) && ! allowDuplicates ) - fail( "Duplicate reference found for ISourceElementCallbackDelegate: " + element + " @ offset " + r.getOffset() ); //$NON-NLS-1$ //$NON-NLS-2$ - } - - } - } - } - - assertEquals( expectedDistinctReferenceCount, matches.size() ); - } - - protected static class Task - { - private final boolean allowNameMatching; - private final boolean unique; - private final int count; - private final ISourceElementCallbackDelegate element; - - - public Task( ISourceElementCallbackDelegate element, int referenceCount, boolean distinct, boolean matchNames ){ - this.element = element; - this.count = referenceCount; - this.unique = distinct; - this.allowNameMatching = matchNames; - } - - public Task( ISourceElementCallbackDelegate element, int referenceCount, boolean distinct ) - { - this( element, referenceCount, distinct, true ); - } - - public Task( ISourceElementCallbackDelegate element, int referenceCount ) - { - this( element, referenceCount, true ); - } - - public Task( ISourceElementCallbackDelegate element ) - { - this( element, 1, false ); - } - - /** - * @return - */ - public int getCount() - { - return count; - } - - /** - * @return - */ - public ISourceElementCallbackDelegate getElement() - { - return element; - } - - /** - * @return - */ - public boolean isUnique() - { - return unique; - } - - public boolean allowNameMatching(){ - return allowNameMatching; - } - - } - - protected void assertReferenceTask( Task task ) - { - assertReferences( task.getElement(), task.getCount(), task.isUnique(), task.allowNameMatching() ); - } - - protected void assertAllReferences( int count, List tasks ) - { - assertEquals( callback.getReferences().size(), count ); - if( tasks == null ) return; - Iterator i = tasks.iterator(); - while( i.hasNext() ) - { - assertReferenceTask( (Task)i.next() ); - } - } - - protected List createTaskList( Task t1 ) - { - List result = new ArrayList(); - result.add( t1 ); - return result; - } - - protected List createTaskList( Task t1, Task t2 ) - { - List result = createTaskList(t1); - result.add( t2 ); - return result; - } - - protected List createTaskList( Task t1, Task t2, Task t3 ) - { - List result = createTaskList(t1, t2); - result.add( t3 ); - return result; - } - - protected List createTaskList( Task t1, Task t2, Task t3, Task t4 ) - { - List result = createTaskList(t1, t2, t3); - result.add( t4 ); - return result; - } - - protected List createTaskList( Task t1, Task t2, Task t3, Task t4, Task t5 ) - { - List result = createTaskList(t1, t2, t3, t4); - result.add( t5 ); - return result; - } - /** - * @param task - * @param task2 - * @param task3 - * @param task4 - * @param task5 - * @param task6 - * @return - */ - protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6) - { - List result = createTaskList( task, task2, task3, task4, task5 ); - result.add( task6 ); - return result; - } - - protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6, Task task7) - { - List result = createTaskList( task, task2, task3, task4, task5, task6 ); - result.add( task7 ); - return result; - } - - protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6, Task task7, Task task8 ) - { - List result = createTaskList( task, task2, task3, task4, task5, task6, task7 ); - result.add( task8 ); - return result; - } - - protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6, Task task7, Task task8, Task task9 ) - { - List result = createTaskList( task, task2, task3, task4, task5, task6, task7, task8 ); - result.add( task9 ); - return result; - } - - protected List createTaskList(Task task, Task task2, Task task3, Task task4, Task task5, Task task6, Task task7, Task task8, Task task9, Task task10 ) - { - List result = createTaskList( task, task2, task3, task4, task5, task6, task7, task8, task9 ); - result.add( task10 ); - return result; - } - - public boolean qualifiedNamesEquals( String [] fromAST, String [] theTruth) - { - if( fromAST == null || theTruth == null ) return false; - if( fromAST.length != theTruth.length ) return false; - for( int i = 0; i < fromAST.length; ++i ) - { - if( !( fromAST[i].equals( theTruth[i] ) ) ) - return false; - } - return true; - } - - protected void assertQualifiedName(String [] fromAST, String [] theTruth) - { - assertTrue( qualifiedNamesEquals( fromAST, theTruth )); - } - - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java deleted file mode 100644 index 94d3ac0187b..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParsePluginTest.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Aug 23, 2004 - */ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.core.resources.IFile; - -/** - * @author aniefer - */ -public class CompleteParsePluginTest extends FileBasePluginTest { - - /** - * @param name - */ - public CompleteParsePluginTest(String name) - { - super(name, CompleteParsePluginTest.class); - } - - public static Test suite() { - TestSuite suite = new TestSuite( CompleteParsePluginTest.class ); - suite.addTest( new CompleteParsePluginTest("cleanupProject") ); //$NON-NLS-1$ - return suite; - } - - public void testBug72219() throws Exception { - String foo = "int FOO;"; //$NON-NLS-1$ - String code = "#include \"foo.h\" \n int bar;"; //$NON-NLS-1$ - - importFile( "foo.h", foo ); //$NON-NLS-1$ - IFile cpp = importFile( "code.cpp", code ); //$NON-NLS-1$ - - List calls = new ArrayList(); - Iterator i = parse( cpp, calls ).getDeclarations(); - - assertTrue( i.next() instanceof IASTVariable ); - assertTrue( i.next() instanceof IASTVariable ); - assertFalse( i.hasNext() ); - - i = calls.iterator(); - assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT ); - assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT ); - assertFalse( i.hasNext() ); - } - - public void testBug72219_2() throws Exception { - String foo = "int FOO;"; //$NON-NLS-1$ - String code = "int bar; \n #include \"foo.h\""; //$NON-NLS-1$ - - importFile( "foo.h", foo ); //$NON-NLS-1$ - IFile cpp = importFile( "code.cpp", code ); //$NON-NLS-1$ - - List calls = new ArrayList(); - Iterator i = parse( cpp, calls ).getDeclarations(); - - assertTrue( i.next() instanceof IASTVariable ); - assertTrue( i.next() instanceof IASTVariable ); - assertFalse( i.hasNext() ); - - i = calls.iterator(); - assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION ); - assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT ); - assertFalse( i.hasNext() ); - } - - public void testBug72219_3() throws Exception { - String defs = "#define A \n #define B \n"; //$NON-NLS-1$ - String code = "int foo; \n #include \"defs.h\" \n int bar;"; //$NON-NLS-1$ - - importFile( "defs.h", defs); //$NON-NLS-1$ - IFile cpp = importFile( "code.cpp", code ); //$NON-NLS-1$ - - List calls = new ArrayList(); - Iterator i = parse( cpp, calls ).getDeclarations(); - - assertTrue( i.next() instanceof IASTVariable ); - assertTrue( i.next() instanceof IASTVariable ); - assertFalse( i.hasNext() ); - - i = calls.iterator(); - assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION ); - assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO ); - assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO ); - assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT ); - assertFalse( i.hasNext() ); - } - - public void test72219_4() throws Exception{ - String code = "int a; \n #define A\n int b;\n #define B\n"; //$NON-NLS-1$ - - IFile cpp = importFile( "code.cpp", code ); //$NON-NLS-1$ - List calls = new ArrayList(); - - parse( cpp, calls ); - - Iterator i = calls.iterator(); - assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO ); - assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT ); - assertFalse( i.hasNext() ); - } - - public void testBug72506() throws Exception{ - String vers = "int i;\n"; //$NON-NLS-1$ - String code = "#define INCFILE(x) vers ## x\n" + //$NON-NLS-1$ - "#define xstr(x) str(x)\n" + //$NON-NLS-1$ - "#define str(x) #x\n" + //$NON-NLS-1$ - "#include xstr(INCFILE(2).h)\n"; //$NON-NLS-1$ - - importFile( "vers2.h", vers ); //$NON-NLS-1$ - IFile cpp = importFile( "code.cpp", code ); //$NON-NLS-1$ - - List calls = new ArrayList(); - - parse( cpp, calls ); - - Iterator i = calls.iterator(); - assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT ); - assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO ); - assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO ); - assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO ); - assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION ); - assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT ); - assertFalse( i.hasNext() ); - } - - public void testExpressionEvalProblems() throws Exception - { - String h = " #if 09 == 9 \n" + //$NON-NLS-1$ //bad octal - " #endif \n"; //$NON-NLS-1$ - - String code = "int i1; \n" + //$NON-NLS-1$ - "#include \"h.h\"\n" + //$NON-NLS-1$ - "int i2; \n"; //$NON-NLS-1$ - - importFile( "h.h", h ); //$NON-NLS-1$ - IFile cpp = importFile( "c.cpp", code ); //$NON-NLS-1$ - - List calls = new ArrayList(); - parse( cpp, calls ); - - Iterator i = calls.iterator(); - - assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION ); - assertEquals( i.next(), CallbackTracker.ACCEPT_PROBLEM ); - assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT ); - assertFalse( i.hasNext() ); - } - - public void testBug79339() throws Exception{ - Writer writer = new StringWriter(); - writer.write("#ifndef _HEADER_\n"); //$NON-NLS-1$ - writer.write("#define _HEADER_\n"); //$NON-NLS-1$ - writer.write("#define ONE 1\n"); //$NON-NLS-1$ - writer.write("int foo(int);\n"); //$NON-NLS-1$ - writer.write("#endif // _HEADER_\n"); //$NON-NLS-1$ - String header = writer.toString(); - importFile( "header.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"header.h\" \n"); //$NON-NLS-1$ - writer.write( "int foo2(){\n"); //$NON-NLS-1$ - writer.write( " return foo(ONE);\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "test.cpp", source ); //$NON-NLS-1$ - - int start = source.indexOf( "foo(ONE)" ); //$NON-NLS-1$ - - List calls = new ArrayList(); - IASTNode node = parse( cpp, calls, start, start + 3 ); //$NON-NLS-1$ - assertTrue(node instanceof IASTFunction); - IASTFunction foo = (IASTFunction)node; - assertEquals(foo.getStartingLine(), 4); - assertEquals(foo.getNameOffset(), 52); - assertEquals(foo.getName(), "foo"); //$NON-NLS-1$ - assertTrue(new String(foo.getFilename()).indexOf("header.h") > 0); //$NON-NLS-1$ - } - - public void testBug79810B() throws Exception { - Writer writer = new StringWriter(); - writer.write("#define __WTERMSIG(status) ((status) & 0x7f)\n"); //$NON-NLS-1$ - writer.write("#define __WIFEXITED(status) (__WTERMSIG(status) == 0)\n"); //$NON-NLS-1$ - writer.write("#define __WAIT_INT(status) (__extension__ ({ union { int __in; int __i; } __u; \\\n"); //$NON-NLS-1$ - writer.write(" __u.__in = (test); __u.__i; }))\n"); //$NON-NLS-1$ - writer.write("#define WIFEXITED(status) __WIFEXITED(__WAIT_INT(status))\n"); //$NON-NLS-1$ - importFile( "header.h", writer.toString() ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"header.h\" \n"); //$NON-NLS-1$ - writer.write("void foo() {\n"); //$NON-NLS-1$ - writer.write("int test;\n"); //$NON-NLS-1$ - writer.write("if (WIFEXITED(test)) {}\n}\n"); //$NON-NLS-1$ - IFile cpp = importFile( "test.cpp", writer.toString() ); //$NON-NLS-1$ - - List calls = new ArrayList(); - parse( cpp, calls ); - - Iterator i = calls.iterator(); - - assertEquals( i.next(), CallbackTracker.ENTER_COMPILATION_UNIT ); - assertEquals( i.next(), CallbackTracker.ENTER_INCLUSION ); - assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO ); - assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO ); - assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO ); - assertEquals( i.next(), CallbackTracker.ACCEPT_MACRO ); - assertEquals( i.next(), CallbackTracker.EXIT_INCLUSION ); - assertEquals( i.next(), CallbackTracker.ENTER_FUNCTION ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.ENTER_CODE_BLOCK ); - assertEquals( i.next(), CallbackTracker.ENTER_CLASS_SPEC ); - assertEquals( i.next(), CallbackTracker.ACCEPT_FIELD ); - assertEquals( i.next(), CallbackTracker.ACCEPT_FIELD ); - assertEquals( i.next(), CallbackTracker.EXIT_CLASS ); - assertEquals( i.next(), CallbackTracker.ACCEPT_VARIABLE ); - assertEquals( i.next(), CallbackTracker.ACCEPT_REFERENCE ); - assertEquals( i.next(), CallbackTracker.ACCEPT_REFERENCE ); - assertEquals( i.next(), CallbackTracker.ACCEPT_REFERENCE ); - assertEquals( i.next(), CallbackTracker.ACCEPT_REFERENCE ); - assertEquals( i.next(), CallbackTracker.ACCEPT_REFERENCE ); - assertEquals( i.next(), CallbackTracker.EXIT_CODE_BLOCK ); - assertEquals( i.next(), CallbackTracker.ENTER_CODE_BLOCK ); - assertEquals( i.next(), CallbackTracker.EXIT_CODE_BLOCK ); - assertEquals( i.next(), CallbackTracker.EXIT_FUNCTION ); - assertEquals( i.next(), CallbackTracker.EXIT_COMPILATION_UNIT ); - assertFalse( i.hasNext() ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseProblemTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseProblemTest.java deleted file mode 100644 index fd9b0a2d9cf..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseProblemTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ParserException; - -/** - * @author jcamelon - * - */ -public class CompleteParseProblemTest extends CompleteParseBaseTest { - - /** - * - */ - public CompleteParseProblemTest() { - super(); - } - - /** - * @param name - */ - public CompleteParseProblemTest(String name) { - super(name); - } - - public void testBadClassName() throws Exception - { - validateInvalidClassName("12345"); //$NON-NLS-1$ - validateInvalidClassName("*"); //$NON-NLS-1$ - } - - /** - * @throws ParserException - * @throws ParserFactoryError - */ - protected void validateInvalidClassName( String name ) throws ParserException, ParserFactoryError { - StringBuffer buffer = new StringBuffer( "class "); //$NON-NLS-1$ - - buffer.append( name ); - buffer.append( " { };"); //$NON-NLS-1$ - String code = buffer.toString(); - parse( code, false ); - assertFalse( callback.problems.isEmpty() ); - assertEquals( callback.problems.size(), 1 ); - IProblem p = (IProblem) callback.problems.get( 0 ); - assertTrue( p.checkCategory( IProblem.SYNTAX_RELATED )); - assertEquals( p.getID(), IProblem.SYNTAX_ERROR ); - assertEquals( p.getSourceStart(), code.indexOf( name )); //$NON-NLS-1$ - assertEquals( p.getSourceEnd(), code.indexOf( name ) + name.length() ); //$NON-NLS-1$ - } - - public void testBug68306() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "class Foo { int bar( int ); };\n" ); //$NON-NLS-1$ - buffer.append( "int Foo::bar( int ){}\n" ); //$NON-NLS-1$ - buffer.append( "int Foo::bar( int ){} //error\n" ); //$NON-NLS-1$ - String code = buffer.toString(); - parse( code, false ); - assertFalse( callback.problems.isEmpty() ); - assertEquals( callback.problems.size(), 1 ); - IProblem p = (IProblem) callback.problems.get( 0 ); - assertTrue( p.checkCategory( IProblem.SEMANTICS_RELATED )); - - } - - public void testBug68931() throws Exception - { - String code = "void foo(){ SomeUnknownType t; } "; //$NON-NLS-1$ - parse( code, false ); - - int start = code.indexOf( "SomeUnknownType" ); //$NON-NLS-1$ - int end = start + 15; - - assertFalse( callback.problems.isEmpty() ); - assertEquals( callback.problems.size(), 1 ); - IProblem p = (IProblem) callback.problems.get( 0 ); - assertTrue( p.checkCategory( IProblem.SEMANTICS_RELATED )); - assertEquals( p.getSourceStart(), start ); - assertEquals( p.getSourceEnd(), end ); - assertEquals( p.getID(), IProblem.SEMANTIC_NAME_NOT_FOUND ); - } - - public void testBug69744() throws Exception - { - String code = "int f() { try { } catch( foo bar ) {} catch ( ... ) {} } int i;"; //$NON-NLS-1$ - - Iterator i = parse( code, false ).getDeclarations(); - - int start = code.indexOf( "foo" ); //$NON-NLS-1$ - int end = start + 3; - - assertEquals( callback.problems.size(), 1 ); - IProblem p = (IProblem) callback.problems.get( 0 ); - - assertEquals( p.getSourceStart(), start ); - assertEquals( p.getSourceEnd(), end ); - assertEquals( p.getID(), IProblem.SEMANTIC_NAME_NOT_FOUND ); - - IASTFunction f = (IASTFunction) i.next(); - IASTVariable varI = (IASTVariable) i.next(); - } - - public void testBug69745() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "namespace NS{ template < class T > int foo(){}; } \n" ); //$NON-NLS-1$ - buffer.append( "void f() { using NS::foo; using NS::foo; } \n" ); //$NON-NLS-1$ - - String code = buffer.toString(); - - parse( code, false ); - - int start = code.indexOf( "using NS::foo;" ); //$NON-NLS-1$ - int end = start + "using NS::foo;".length(); //$NON-NLS-1$ - - assertEquals( callback.problems.size(), 1 ); - IProblem p = (IProblem) callback.problems.get( 0 ); - - assertEquals( p.getSourceStart(), start ); - assertEquals( p.getSourceEnd(), end ); - assertEquals( p.getID(), IProblem.SEMANTIC_INVALID_USING ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseBaseTest.java deleted file mode 100644 index 004484630a1..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseBaseTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; -import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult; - -/** - * @author johnc - */ -public class CompletionParseBaseTest extends CompleteParseBaseTest { - /** - * - */ - public CompletionParseBaseTest() { - super(); - } - /** - * @param name - */ - public CompletionParseBaseTest(String name) { - super(name); - } - - protected IASTCompletionNode parse(String code, int offset) throws Exception { - callback = new FullParseCallback(); - IParser parser = null; - - parser = - ParserFactory.createParser( - ParserFactory.createScanner( - new CodeReader(code.toCharArray()), - new ScannerInfo(), - ParserMode.COMPLETION_PARSE, - ParserLanguage.CPP, - callback, - new NullLogService(), null), - callback, - ParserMode.COMPLETION_PARSE, - ParserLanguage.CPP, - null); - - return parser.parse( offset ); - - } - protected IASTCompletionNode parse(String code, int offset, ParserLanguage lang) throws Exception { - callback = new FullParseCallback(); - IParser parser = null; - - parser = - ParserFactory.createParser( - ParserFactory.createScanner( - new CodeReader(code.toCharArray()), - new ScannerInfo(), - ParserMode.COMPLETION_PARSE, - lang, - callback, - new NullLogService(), null), - callback, - ParserMode.COMPLETION_PARSE, - lang, - null); - - return parser.parse( offset ); - - } - /** - * @param result - */ - protected void validateLookupResult(ILookupResult result, Set matches) { - - assertNotNull( matches ); - assertEquals( result.getResultsSize(), matches.size() ); - - Iterator iter = result.getNodes(); - while( iter.hasNext() ) - { - IASTOffsetableNamedElement element = (IASTOffsetableNamedElement) iter.next(); - assertTrue( matches.contains( element.getName() )); - } - } - /** - * @return - */ - protected IASTCompilationUnit getCompilationUnit() { - IASTCompilationUnit compilationUnit = (IASTCompilationUnit) ((Scope) callback.getCompilationUnit()).getScope(); - return compilationUnit; - } - /** - * @param node - * @param hasKeywords - */ - protected void validateCompletionNode(IASTCompletionNode node, String prefix, CompletionKind kind, IASTNode context, boolean hasKeywords) { - assertNotNull( node ); - assertEquals( node.getCompletionPrefix(), prefix); - assertEquals( node.getCompletionKind(), kind ); - assertEquals( node.getCompletionContext(), context ); - if( hasKeywords ) - assertTrue( node.getKeywords().hasNext() ); - else - assertFalse( node.getKeywords().hasNext() ); - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseTest.java deleted file mode 100644 index 24436446a78..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompletionParseTest.java +++ /dev/null @@ -1,1274 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Dec 8, 2003 - * - * To change the template for this generated file go to Window - Preferences - - * Java - Code Generation - Code and Comments - */ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.cdt.core.parser.KeywordSetKey; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; -import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult; -import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind; -import org.eclipse.cdt.internal.core.parser.token.KeywordSets; - -/** - * @author jcamelon - * - * To change the template for this generated type comment go to Window - - * Preferences - Java - Code Generation - Code and Comments - */ -public class CompletionParseTest extends CompletionParseBaseTest { - - - public CompletionParseTest(String name) { - super(name); - } - - public void testBaseCase_SimpleDeclaration() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "class ABC " ); //$NON-NLS-1$ - writer.write( "{int x;}; " ); //$NON-NLS-1$ - writer.write( "AB\n\n" ); //$NON-NLS-1$ - - IASTCompletionNode node = null; - Iterator keywords = null; - - node = parse( writer.toString(), 21); - assertNotNull( node ); - assertNotNull( node.getCompletionPrefix() ); - assertEquals( node.getCompletionScope(), ((Scope)callback.getCompilationUnit()).getScope() ); - assertEquals( node.getCompletionPrefix(), "A"); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.VARIABLE_TYPE ); - keywords = node.getKeywords(); - assertFalse( keywords.hasNext() ); - - node = parse( writer.toString(), 12); - assertNotNull( node ); - assertNotNull( node.getCompletionPrefix() ); - assertTrue( node.getCompletionScope() instanceof IASTClassSpecifier ); - assertEquals( node.getCompletionPrefix(), "i"); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.FIELD_TYPE ); - keywords = node.getKeywords(); - assertTrue( keywords.hasNext() ); - assertEquals( (String) keywords.next(), "inline"); //$NON-NLS-1$ - assertEquals( (String) keywords.next(), "int"); //$NON-NLS-1$ - assertFalse( keywords.hasNext() ); - - node = parse( writer.toString(), 22); - assertNotNull( node ); - assertNotNull( node.getCompletionPrefix() ); - assertEquals( node.getCompletionScope(), ((Scope)callback.getCompilationUnit()).getScope() ); - assertEquals( node.getCompletionPrefix(), "AB"); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.VARIABLE_TYPE ); - keywords = node.getKeywords(); - assertFalse( keywords.hasNext() ); - - node = parse( writer.toString(), 6); - assertNotNull( node ); - assertNotNull( node.getCompletionPrefix() ); - assertEquals( node.getCompletionScope(), ((Scope)callback.getCompilationUnit()).getScope() ); - assertEquals( node.getCompletionPrefix(), ""); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.CLASS_REFERENCE ); - keywords = node.getKeywords(); - assertFalse( keywords.hasNext() ); - } - - public void testCompletionLookup_Unqualified() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "int aVar; " ); //$NON-NLS-1$ - writer.write( "void foo( ) { " ); //$NON-NLS-1$ - writer.write( " int anotherVar; " ); //$NON-NLS-1$ - writer.write( " a " ); //$NON-NLS-1$ - writer.write( "} " ); //$NON-NLS-1$ - - String code = writer.toString(); - - for( int i = 0; i < 2; ++i ) - { - int index = ( i == 0 ? code.indexOf( " a " ) + 2 : code.indexOf( " a ") + 1 ); //$NON-NLS-1$ //$NON-NLS-2$ - - IASTCompletionNode node = parse( code, index ); - assertNotNull( node ); - - String prefix = node.getCompletionPrefix(); - assertNotNull( prefix ); - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertEquals( prefix, i == 0 ? "a" :"" ); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - - IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1]; - kinds[0] = IASTNode.LookupKind.ALL; - ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - - IASTVariable anotherVar = (IASTVariable) iter.next(); - - IASTVariable aVar = (IASTVariable) iter.next(); - - if( i != 0 ) - { - IASTFunction foo = (IASTFunction) iter.next(); - assertEquals( foo.getName(), "foo"); //$NON-NLS-1$ - } - - assertFalse( iter.hasNext() ); - assertEquals( anotherVar.getName(), "anotherVar" ); //$NON-NLS-1$ - assertEquals( aVar.getName(), "aVar" ); //$NON-NLS-1$ - } - } - - public void testCompletionLookup_Qualified() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "int aVar; " ); //$NON-NLS-1$ - writer.write( "struct D{ " ); //$NON-NLS-1$ - writer.write( " int aField; " ); //$NON-NLS-1$ - writer.write( " void aMethod(); " ); //$NON-NLS-1$ - writer.write( "}; " ); //$NON-NLS-1$ - writer.write( "void foo(){" ); //$NON-NLS-1$ - writer.write( " D d; " ); //$NON-NLS-1$ - writer.write( " d.a " ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "d.a" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 3 ); - assertNotNull( node ); - - String prefix = node.getCompletionPrefix(); - assertNotNull( prefix ); - assertEquals( prefix, "a" ); //$NON-NLS-1$ - - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); - assertNotNull( node.getCompletionContext() ); - assertTrue( node.getCompletionContext() instanceof IASTVariable ); - - IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1]; - kinds[0] = IASTNode.LookupKind.ALL; - ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - - IASTField aField = (IASTField) iter.next(); - IASTMethod aMethod = (IASTMethod) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( aMethod.getName(), "aMethod" ); //$NON-NLS-1$ - assertEquals( aField.getName(), "aField" ); //$NON-NLS-1$ - } - - public void testMemberCompletion_Arrow() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "class A {" ); //$NON-NLS-1$ - writer.write( " public: void aPublicBaseMethod();" ); //$NON-NLS-1$ - writer.write( " private: void aPrivateBaseMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "class B : public A {" ); //$NON-NLS-1$ - writer.write( " public: void aMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "void foo(){" ); //$NON-NLS-1$ - writer.write( " B * b = new B();" ); //$NON-NLS-1$ - writer.write( " b-> \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "b->" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 3 ); - assertNotNull(node); - assertEquals( node.getCompletionPrefix(), "" ); //$NON-NLS-1$ - - assertEquals(node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE); - assertTrue(node.getCompletionScope() instanceof IASTFunction ); - assertEquals( ((IASTFunction)node.getCompletionScope()).getName(), "foo" ); //$NON-NLS-1$ - assertTrue(node.getCompletionContext() instanceof IASTVariable ); - assertEquals( ((IASTVariable)node.getCompletionContext()).getName(), "b" ); //$NON-NLS-1$ - } - - public void testMemberCompletion_Dot() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "class A {" ); //$NON-NLS-1$ - writer.write( " public: void aPublicBaseMethod();" ); //$NON-NLS-1$ - writer.write( " private: void aPrivateBaseMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "class B : public A {" ); //$NON-NLS-1$ - writer.write( " public: void aMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "void foo(){" ); //$NON-NLS-1$ - writer.write( " B b;" ); //$NON-NLS-1$ - writer.write( " b. \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "b." ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 2 ); - assertNotNull(node); - assertEquals( node.getCompletionPrefix(), "" ); //$NON-NLS-1$ - - assertEquals(node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE); - assertTrue(node.getCompletionScope() instanceof IASTFunction ); - assertEquals( ((IASTFunction)node.getCompletionScope()).getName(), "foo" ); //$NON-NLS-1$ - assertTrue(node.getCompletionContext() instanceof IASTVariable ); - assertEquals( ((IASTVariable)node.getCompletionContext()).getName(), "b" ); //$NON-NLS-1$ - } - - - public void testCompletionLookup_Pointer() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "class A {" ); //$NON-NLS-1$ - writer.write( " public: void aPublicBaseMethod();" ); //$NON-NLS-1$ - writer.write( " private: void aPrivateBaseMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "class B : public A {" ); //$NON-NLS-1$ - writer.write( " public: void aMethod();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "void foo(){" ); //$NON-NLS-1$ - writer.write( " B * b = new B();" ); //$NON-NLS-1$ - writer.write( " b->a \n" ); //$NON-NLS-1$ - - for( int i = 0; i < 2; ++i ) - { - String code = writer.toString(); - - int index; - - index = (i == 0 )? (code.indexOf( "b->a" )+4) :(code.indexOf( "b->") + 3); //$NON-NLS-1$ //$NON-NLS-2$ - - IASTCompletionNode node = parse( code, index); - - assertNotNull( node ); - String prefix = node.getCompletionPrefix(); - - assertEquals( prefix, ( i == 0 ) ? "a" :""); //$NON-NLS-1$ //$NON-NLS-2$ - - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); - assertNotNull( node.getCompletionContext() ); - assertTrue( node.getCompletionContext() instanceof IASTVariable ); - - IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1]; - kinds[0] = IASTNode.LookupKind.METHODS; - ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - IASTMethod method = (IASTMethod) iter.next(); - IASTMethod baseMethod = (IASTMethod) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( method.getName(), "aMethod" ); //$NON-NLS-1$ - assertEquals( baseMethod.getName(), "aPublicBaseMethod" ); //$NON-NLS-1$ - } - } - - public void testCompletionLookup_FriendClass_1() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "class A {" ); //$NON-NLS-1$ - writer.write( " private: void aPrivateMethod();" ); //$NON-NLS-1$ - writer.write( " friend class C;" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - - writer.write( "class C {" ); //$NON-NLS-1$ - writer.write( " void foo();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - - writer.write( "void C::foo(){" ); //$NON-NLS-1$ - writer.write( " A a;" ); //$NON-NLS-1$ - writer.write( " a.a \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "a.a" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 3 ); - - assertNotNull( node ); - - String prefix = node.getCompletionPrefix(); - assertEquals( prefix, "a" ); //$NON-NLS-1$ - - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); - assertNotNull( node.getCompletionContext() ); - assertTrue( node.getCompletionContext() instanceof IASTVariable ); - - ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.METHODS }, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - assertTrue( iter.hasNext() ); - - IASTMethod method = (IASTMethod) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( method.getName(), "aPrivateMethod" ); //$NON-NLS-1$ - } - - public void testCompletionLookup_FriendClass_2() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "class C {" ); //$NON-NLS-1$ - writer.write( " void foo();" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "class A {" ); //$NON-NLS-1$ - writer.write( " private: void aPrivateMethod();" ); //$NON-NLS-1$ - writer.write( " friend class C;" ); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - - writer.write( "void C::foo(){" ); //$NON-NLS-1$ - writer.write( " A a;" ); //$NON-NLS-1$ - writer.write( " a.a \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "a.a" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 3 ); - - assertNotNull( node ); - - String prefix = node.getCompletionPrefix(); - assertEquals( prefix, "a" ); //$NON-NLS-1$ - - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); - assertNotNull( node.getCompletionContext() ); - assertTrue( node.getCompletionContext() instanceof IASTVariable ); - - ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.METHODS }, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - assertTrue( iter.hasNext() ); - - IASTMethod method = (IASTMethod) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( method.getName(), "aPrivateMethod" ); //$NON-NLS-1$ - } - - - public void testCompletionLookup_ParametersAsLocalVariables() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "int foo( int aParameter ){" ); //$NON-NLS-1$ - writer.write( " int aLocal;" ); //$NON-NLS-1$ - writer.write( " if( aLocal != 0 ){" ); //$NON-NLS-1$ - writer.write( " int aBlockLocal;" ); //$NON-NLS-1$ - writer.write( " a \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( " a " ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 2 ); - - assertNotNull( node ); - - String prefix = node.getCompletionPrefix(); - assertEquals( prefix, "a" ); //$NON-NLS-1$ - - assertTrue( node.getCompletionScope() instanceof IASTCodeScope ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - assertNull( node.getCompletionContext() ); - - ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.LOCAL_VARIABLES }, node.getCompletionContext(), null ); - assertEquals( result.getPrefix(), prefix ); - - Iterator iter = result.getNodes(); - - IASTVariable aBlockLocal = (IASTVariable) iter.next(); - IASTVariable aLocal = (IASTVariable) iter.next(); - IASTParameterDeclaration aParameter = (IASTParameterDeclaration) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( aBlockLocal.getName(), "aBlockLocal" ); //$NON-NLS-1$ - assertEquals( aLocal.getName(), "aLocal" ); //$NON-NLS-1$ - assertEquals( aParameter.getName(), "aParameter" ); //$NON-NLS-1$ - } - - public void testCompletionLookup_LookupKindTHIS() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "int aGlobalVar;" ); //$NON-NLS-1$ - writer.write( "namespace NS { " ); //$NON-NLS-1$ - writer.write( " int aNamespaceFunction(){}" ); //$NON-NLS-1$ - writer.write( " class Base { " ); //$NON-NLS-1$ - writer.write( " protected: int aBaseField;" ); //$NON-NLS-1$ - writer.write( " };" ); //$NON-NLS-1$ - writer.write( " class Derived : public Base {" ); //$NON-NLS-1$ - writer.write( " int aMethod();" ); //$NON-NLS-1$ - writer.write( " };" ); //$NON-NLS-1$ - writer.write( "}" ); //$NON-NLS-1$ - writer.write( "int NS::Derived::aMethod(){"); //$NON-NLS-1$ - writer.write( " int aLocal;" ); //$NON-NLS-1$ - writer.write( " a "); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( " a " ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index + 2 ); - - assertNotNull( node ); - - assertEquals( node.getCompletionPrefix(), "a" ); //$NON-NLS-1$ - assertTrue( node.getCompletionScope() instanceof IASTMethod ); - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[] { IASTNode.LookupKind.THIS }, - node.getCompletionContext(), null ); - - assertEquals( result.getResultsSize(), 2 ); - - Iterator iter = result.getNodes(); - IASTMethod method = (IASTMethod) iter.next(); - IASTField field = (IASTField) iter.next(); - assertFalse( iter.hasNext() ); - assertEquals( method.getName(), "aMethod" ); //$NON-NLS-1$ - assertEquals( field.getName(), "aBaseField" ); //$NON-NLS-1$ - - result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[] { IASTNode.LookupKind.THIS, IASTNode.LookupKind.METHODS }, - node.getCompletionContext(), null ); - - assertEquals( result.getResultsSize(), 1 ); - iter = result.getNodes(); - method = (IASTMethod) iter.next(); - assertFalse( iter.hasNext() ); - assertEquals( method.getName(), "aMethod" ); //$NON-NLS-1$ - } - - public void testCompletionInConstructor() throws Exception - { - Writer writer = new StringWriter(); - writer.write("class SimpleTest{"); //$NON-NLS-1$ - writer.write(" public:"); //$NON-NLS-1$ - writer.write("SimpleTest();"); //$NON-NLS-1$ - writer.write("~SimpleTest();"); //$NON-NLS-1$ - writer.write("int a, b, c, aa, bb, cc, abc;"); //$NON-NLS-1$ - writer.write("};"); //$NON-NLS-1$ - writer.write("SimpleTest::~SimpleTest()"); //$NON-NLS-1$ - writer.write("{}"); //$NON-NLS-1$ - writer.write("SimpleTest::SimpleTest()"); //$NON-NLS-1$ - writer.write("{"); //$NON-NLS-1$ - writer.write("/**/a"); //$NON-NLS-1$ - writer.write("}"); //$NON-NLS-1$ - - IASTCompletionNode node = parse( writer.toString(), writer.toString().indexOf("/**/a") + 5 ); //$NON-NLS-1$ - assertNotNull(node); - assertEquals(node.getCompletionPrefix(), "a"); //$NON-NLS-1$ - assertTrue(node.getCompletionScope() instanceof IASTMethod); - IASTMethod inquestion = (IASTMethod)node.getCompletionScope(); - assertEquals( inquestion.getName(), "SimpleTest"); //$NON-NLS-1$ - assertTrue(inquestion.isConstructor()); - - assertEquals(node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - assertNull(node.getCompletionContext()); - LookupKind[] kinds = new LookupKind[ 1 ]; - kinds[0] = LookupKind.FIELDS; - - ILookupResult result = inquestion.lookup( "a", kinds, null, null ); //$NON-NLS-1$ - assertEquals(result.getResultsSize(), 3 ); - } - - public void testCompletionInDestructor() throws Exception - { - Writer writer = new StringWriter(); - writer.write("class SimpleTest{"); //$NON-NLS-1$ - writer.write(" public:"); //$NON-NLS-1$ - writer.write("SimpleTest();"); //$NON-NLS-1$ - writer.write("~SimpleTest();"); //$NON-NLS-1$ - writer.write("int a, b, c, aa, bb, cc, abc;"); //$NON-NLS-1$ - writer.write("};"); //$NON-NLS-1$ - writer.write("SimpleTest::SimpleTest()"); //$NON-NLS-1$ - writer.write("{}"); //$NON-NLS-1$ - writer.write("SimpleTest::~SimpleTest()"); //$NON-NLS-1$ - writer.write("{"); //$NON-NLS-1$ - writer.write("/**/a"); //$NON-NLS-1$ - writer.write("}"); //$NON-NLS-1$ - - IASTCompletionNode node = parse( writer.toString(), writer.toString().indexOf("/**/a") + 5 ); //$NON-NLS-1$ - assertNotNull(node); - assertEquals(node.getCompletionPrefix(), "a"); //$NON-NLS-1$ - assertTrue(node.getCompletionScope() instanceof IASTMethod); - IASTMethod inquestion = (IASTMethod)node.getCompletionScope(); - assertEquals( inquestion.getName(), "~SimpleTest"); //$NON-NLS-1$ - assertTrue(inquestion.isDestructor()); - - assertEquals(node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - assertNull(node.getCompletionContext()); - LookupKind[] kinds = new LookupKind[ 1 ]; - kinds[0] = LookupKind.FIELDS; - - ILookupResult result = inquestion.lookup( "a", kinds, null, null ); //$NON-NLS-1$ - assertEquals(result.getResultsSize(), 3 ); - } - - public void testBug48307_FriendFunction_1() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class A{ public : void foo(); }; " ); //$NON-NLS-1$ - writer.write( "class B{ "); //$NON-NLS-1$ - writer.write( " private : int aPrivate;" ); //$NON-NLS-1$ - writer.write( " friend void A::foo(); "); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "void A::foo(){" ); //$NON-NLS-1$ - writer.write( " B b;"); //$NON-NLS-1$ - writer.write( " b.aP" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "b.aP" ); //$NON-NLS-1$ - IASTCompletionNode node = parse( code, index + 4 ); - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - - assertNotNull( result ); - assertEquals( result.getResultsSize(), 1 ); - IASTField field = (IASTField) result.getNodes().next(); - assertEquals( field.getName(), "aPrivate" ); //$NON-NLS-1$ - } - - public void testBug48307_FriendFunction_2() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "void global();" ); //$NON-NLS-1$ - writer.write( "class B{ "); //$NON-NLS-1$ - writer.write( " private : int aPrivate;" ); //$NON-NLS-1$ - writer.write( " friend void global(); "); //$NON-NLS-1$ - writer.write( "};" ); //$NON-NLS-1$ - writer.write( "void global(){" ); //$NON-NLS-1$ - writer.write( " B b;"); //$NON-NLS-1$ - writer.write( " b.aP" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "b.aP" ); //$NON-NLS-1$ - IASTCompletionNode node = parse( code, index + 4 ); - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - - assertNotNull( result ); - assertEquals( result.getResultsSize(), 1 ); - IASTField field = (IASTField) result.getNodes().next(); - assertEquals( field.getName(), "aPrivate" ); //$NON-NLS-1$ - } - - public void testBug51260() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( " class A { public: void a(); }; " ); //$NON-NLS-1$ - writer.write( " class B : public virtual A { public: void b(); };" ); //$NON-NLS-1$ - writer.write( " class C : public virtual A { public: void c(); };" ); //$NON-NLS-1$ - writer.write( " class D : public B, C { public: void d(); };" ); //$NON-NLS-1$ - - writer.write( " void A::a(){} "); //$NON-NLS-1$ - writer.write( " void B::b(){} "); //$NON-NLS-1$ - writer.write( " void C::c(){} "); //$NON-NLS-1$ - writer.write( " void D::d(){ SP }" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "SP" ); //$NON-NLS-1$ - IASTCompletionNode node = parse( code, index ); - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.THIS }, - node.getCompletionContext(), null ); - - assertTrue( node.getCompletionScope() instanceof IASTMethod ); - assertEquals( ((IASTMethod)node.getCompletionScope()).getName(), "d" ); //$NON-NLS-1$ - assertEquals( result.getResultsSize(), 4 ); - - Iterator iter = result.getNodes(); - IASTMethod d = (IASTMethod) iter.next(); - IASTMethod b = (IASTMethod) iter.next(); - IASTMethod a = (IASTMethod) iter.next(); - IASTMethod c = (IASTMethod) iter.next(); - - assertFalse( iter.hasNext() ); - - assertEquals( a.getName(), "a" ); //$NON-NLS-1$ - assertEquals( b.getName(), "b" ); //$NON-NLS-1$ - assertEquals( c.getName(), "c" ); //$NON-NLS-1$ - assertEquals( d.getName(), "d" ); //$NON-NLS-1$ - - } - - public void testBug52948() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "typedef int Int; "); //$NON-NLS-1$ - writer.write( "InSP" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "SP" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.TYPEDEFS }, - node.getCompletionContext(), null ); - - assertEquals( result.getResultsSize(), 1 ); - - Iterator iter = result.getNodes(); - IASTTypedefDeclaration typeDef = (IASTTypedefDeclaration) iter.next(); - - assertEquals( typeDef.getName(), "Int" ); //$NON-NLS-1$ - assertFalse( iter.hasNext() ); - } - - - public void testCompletionInFunctionBodyFullyQualified() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "int aInteger = 5;\n"); //$NON-NLS-1$ - writer.write( "namespace NMS { \n"); //$NON-NLS-1$ - writer.write( " int foo() { \n"); //$NON-NLS-1$ - writer.write( "::A "); //$NON-NLS-1$ - writer.write( "}\n}\n"); //$NON-NLS-1$ - String code = writer.toString(); - - for( int i = 0; i < 2; ++i ) - { - String stringToCompleteAfter = ( i == 0 ) ? "::" : "::A"; //$NON-NLS-1$ //$NON-NLS-2$ - IASTCompletionNode node = parse( code, code.indexOf( stringToCompleteAfter) + stringToCompleteAfter.length() ); - - validateCompletionNode(node, ( i == 0 ? "" : "A"), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE, getCompilationUnit(), false ); //$NON-NLS-1$ //$NON-NLS-2$ - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - - Set results = new HashSet(); - results.add( "aInteger"); //$NON-NLS-1$ - if( i == 0 ) - { - results.add( "NMS"); //$NON-NLS-1$ - results.add( "__builtin_va_list "); //$NON-NLS-1$ - results.add("__builtin_expect"); //$NON-NLS-1$ - results.add("__builtin_prefetch"); //$NON-NLS-1$ - results.add("__builtin_huge_val"); //$NON-NLS-1$ - results.add("__builtin_huge_valf"); //$NON-NLS-1$ - results.add("__builtin_huge_vall"); //$NON-NLS-1$ - results.add("__builtin_inf"); //$NON-NLS-1$ - results.add("__builtin_inff"); //$NON-NLS-1$ - results.add("__builtin_infl"); //$NON-NLS-1$ - results.add("__builtin_nan"); //$NON-NLS-1$ - results.add("__builtin_nanf"); //$NON-NLS-1$ - results.add("__builtin_nanl"); //$NON-NLS-1$ - results.add("__builtin_nans"); //$NON-NLS-1$ - results.add("__builtin_nansf"); //$NON-NLS-1$ - results.add("__builtin_nansl"); //$NON-NLS-1$ - results.add("__builtin_ffs"); //$NON-NLS-1$ - results.add("__builtin_clz"); //$NON-NLS-1$ - results.add("__builtin_ctz"); //$NON-NLS-1$ - results.add("__builtin_popcount"); //$NON-NLS-1$ - results.add("__builtin_parity"); //$NON-NLS-1$ - results.add("__builtin_ffsl"); //$NON-NLS-1$ - results.add("__builtin_clzl"); //$NON-NLS-1$ - results.add("__builtin_ctzl"); //$NON-NLS-1$ - results.add("__builtin_popcountl"); //$NON-NLS-1$ - results.add("__builtin_parityl"); //$NON-NLS-1$ - results.add("__builtin_ffsll"); //$NON-NLS-1$ - results.add("__builtin_clzll"); //$NON-NLS-1$ - results.add("__builtin_ctzll"); //$NON-NLS-1$ - results.add("__builtin_popcountll"); //$NON-NLS-1$ - results.add("__builtin_parityll"); //$NON-NLS-1$ - results.add("__builtin_types_compatible_p"); //$NON-NLS-1$ - } - validateLookupResult(result, results ); - } - } - - public void testCompletionInFunctionBodyQualifiedName() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "namespace ABC {\n"); //$NON-NLS-1$ - writer.write( " struct DEF { int x; }; \n" ); //$NON-NLS-1$ - writer.write( " struct GHI { float y;};\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - writer.write( "int main() { ABC::D }\n"); //$NON-NLS-1$ - String code = writer.toString(); - - for( int j = 0; j< 2; ++j ) - { - String stringToCompleteAfter = (j == 0 ) ? "::" : "::D"; //$NON-NLS-1$ //$NON-NLS-2$ - IASTCompletionNode node = parse( code, code.indexOf( stringToCompleteAfter) + stringToCompleteAfter.length() ); - - IASTNamespaceDefinition namespaceDefinition = null; - Iterator i = callback.getCompilationUnit().getDeclarations(); - while( i.hasNext() ) - { - IASTDeclaration d = (IASTDeclaration) i.next(); - if( d instanceof IASTNamespaceDefinition ) - if( ((IASTNamespaceDefinition)d).getName().equals( "ABC") ) //$NON-NLS-1$ - { - namespaceDefinition = (IASTNamespaceDefinition) d; - break; - } - } - assertNotNull( namespaceDefinition ); - validateCompletionNode( node, - ( j == 0 ) ? "" : "D", //$NON-NLS-1$ //$NON-NLS-2$ - IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE, namespaceDefinition, false ); - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - - Set results = new HashSet(); - results.add( "DEF"); //$NON-NLS-1$ - if( j == 0 ) - results.add( "GHI"); //$NON-NLS-1$ - validateLookupResult(result, results ); - } - - } - - public void testCompletionWithTemplateInstanceAsParent() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "template < class T > class A { public : int a_member; }; "); //$NON-NLS-1$ - writer.write( "template < class T > class B : public A< T > { public : int b_member; }; "); //$NON-NLS-1$ - writer.write( "void f() { "); //$NON-NLS-1$ - writer.write( " B< int > b; "); //$NON-NLS-1$ - writer.write( " b.SP "); //$NON-NLS-1$ - - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$ - - ILookupResult result = node.getCompletionScope().lookup( "", //$NON-NLS-1$ - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 2 ); - - Iterator i = result.getNodes(); - - assertTrue( i.next() instanceof IASTField ); - assertTrue( i.next() instanceof IASTField ); - assertFalse( i.hasNext() ); - } - - public void testBug58178() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define GL_T 0x2001\n"); //$NON-NLS-1$ - writer.write( "#define GL_TRUE 0x1\n"); //$NON-NLS-1$ - writer.write( "typedef unsigned char GLboolean;\n"); //$NON-NLS-1$ - writer.write( "static GLboolean should_rotate = GL_T"); //$NON-NLS-1$ - String code = writer.toString(); - final String where = "= GL_T"; //$NON-NLS-1$ - IASTCompletionNode node = parse( code, code.indexOf( where ) + where.length() ); - assertEquals( node.getCompletionPrefix(), "GL_T"); //$NON-NLS-1$ - } - - public void testBug52253() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class CMyClass {public:\n void doorBell(){ return; }};"); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {CMyClass mc; mc.do }"); //$NON-NLS-1$ - String code = writer.toString(); - final String where = "mc.do"; //$NON-NLS-1$ - IASTCompletionNode node = parse( code, code.indexOf( where) + where.length() ); - assertEquals( node.getCompletionPrefix(), "do"); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), CompletionKind.MEMBER_REFERENCE ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 1 ); - Iterator i = result.getNodes(); - IASTMethod doorBell = (IASTMethod) i.next(); - assertFalse( i.hasNext() ); - assertEquals( doorBell.getName(), "doorBell"); //$NON-NLS-1$ - - } - - public void testBug58492() throws Exception - { - Writer writer = new StringWriter(); - writer.write("struct Cube { "); //$NON-NLS-1$ - writer.write(" int nLen; "); //$NON-NLS-1$ - writer.write(" int nWidth; "); //$NON-NLS-1$ - writer.write(" int nHeight; "); //$NON-NLS-1$ - writer.write("}; "); //$NON-NLS-1$ - writer.write("int volume( struct Cube * pCube ) { "); //$NON-NLS-1$ - writer.write(" pCube->SP "); //$NON-NLS-1$ - - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf("SP"), ParserLanguage.C ); //$NON-NLS-1$ - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[] {IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 3 ); - Iterator i = result.getNodes(); - assertTrue( i.next() instanceof IASTField ); - assertTrue( i.next() instanceof IASTField ); - assertTrue( i.next() instanceof IASTField ); - } - - public void testCompletionOnExpression() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class ABC { public: void voidMethod(); };\n"); //$NON-NLS-1$ - writer.write( "ABC * someFunction(void) { return new ABC(); }\n"); //$NON-NLS-1$ - writer.write( "void testFunction( void ) { someFunction()->V }\n" ); //$NON-NLS-1$ - String code = writer.toString(); - for( int i = 0; i < 2; ++i ) - { - int index = code.indexOf( "V"); //$NON-NLS-1$ - if( i == 1 ) ++index; - IASTCompletionNode node = parse( code, index ); - assertEquals( node.getCompletionPrefix(), (i == 0 )? "": "V"); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals( node.getCompletionKind(), CompletionKind.MEMBER_REFERENCE ); - assertTrue( node.getCompletionContext() instanceof IASTExpression ); - } - - } - - public void testCompletionInTypeDef() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "struct A { int name; }; \n" ); //$NON-NLS-1$ - writer.write( "typedef struct A * PA; \n" ); //$NON-NLS-1$ - writer.write( "int main() { \n" ); //$NON-NLS-1$ - writer.write( " PA a; \n" ); //$NON-NLS-1$ - writer.write( " a->SP \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "SP" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 1 ); - - Iterator iter = result.getNodes(); - IASTField name = (IASTField) iter.next(); - - assertEquals( name.getName(), "name" ); //$NON-NLS-1$ - assertFalse( iter.hasNext() ); - } - - public void testBug59134() throws Exception - { - String code = "int main(){ siz }"; //$NON-NLS-1$ - IASTCompletionNode node = parse( code, code.indexOf("siz") ); //$NON-NLS-1$ - assertNotNull( node ); - Iterator keywords = node.getKeywords(); - boolean passed = false; - while( keywords.hasNext() ) - { - String keyword = (String) keywords.next(); - if( keyword.equals( "sizeof")) //$NON-NLS-1$ - passed = true; - } - assertTrue( passed ); - - } - - public void testBug59893() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "struct A { \n" ); //$NON-NLS-1$ - writer.write( " void f1() const volatile; \n" ); //$NON-NLS-1$ - writer.write( " void f2() const; \n" ); //$NON-NLS-1$ - writer.write( " void f3() volatile; \n" ); //$NON-NLS-1$ - writer.write( " void f4(); \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void main( const A& a1 ) \n" ); //$NON-NLS-1$ - writer.write( "{ \n" ); //$NON-NLS-1$ - writer.write( " const volatile A * a2; \n" ); //$NON-NLS-1$ - writer.write( " const A * a3; \n" ); //$NON-NLS-1$ - writer.write( " volatile A * a4; \n" ); //$NON-NLS-1$ - writer.write( " A * a5; \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - - IASTCompletionNode node = parse( code + "a1. ", code.length() + 3 ); //$NON-NLS-1$ - - assertNotNull( node ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 2 ); - - node = parse( code + "a2-> ", code.length() + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 1 ); - - node = parse( code + "a3-> ", code.length() + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 2 ); - - node = parse( code + "a4-> ", code.length() + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 2 ); - - node = parse( code + "a5-> ", code.length() + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 4 ); - } - - public void testBug59893_Expression() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "struct A { \n" ); //$NON-NLS-1$ - writer.write( " void f2() const; \n" ); //$NON-NLS-1$ - writer.write( " void f4(); \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "const A * foo(){} \n" ); //$NON-NLS-1$ - writer.write( "void main( ) \n" ); //$NON-NLS-1$ - writer.write( "{ \n" ); //$NON-NLS-1$ - writer.write( " foo()->SP \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "SP" ); //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, index ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 1 ); - } - - public void testParameterListFunctionReference() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "int foo( int firstParam, int secondParam );\n"); //$NON-NLS-1$ - writer.write( "void main() { \n"); //$NON-NLS-1$ - writer.write( " int abc;\n"); //$NON-NLS-1$ - writer.write( " int x;\n" ); //$NON-NLS-1$ - writer.write( " foo( x,a"); //$NON-NLS-1$ - String code = writer.toString(); - for( int i = 0; i < 2; ++i ) - { - int index = code.indexOf( "x,a") + 2; //$NON-NLS-1$ - if( i == 1 ) index++; - IASTCompletionNode node = parse( code, index ); - validateCompletionNode(node, (( i == 0 ) ? "" : "a" ), CompletionKind.FUNCTION_REFERENCE, null, true ); //$NON-NLS-1$ //$NON-NLS-2$ - assertNotNull( node.getFunctionParameters() ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.LOCAL_VARIABLES }, - node.getCompletionContext(), null ); - assertNotNull(result); - assertEquals( result.getResultsSize(), ( i == 0 ) ? 2 : 1 ); - } - } - - public void testParameterListConstructorReference() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class A { \n"); //$NON-NLS-1$ - writer.write( "public:\n"); //$NON-NLS-1$ - writer.write( " A( int first, int second );\n"); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "void main() { \n"); //$NON-NLS-1$ - writer.write( " int four, x;"); //$NON-NLS-1$ - writer.write( " A * a = new A( x,f "); //$NON-NLS-1$ - String code = writer.toString(); - for( int i = 0; i < 2; ++i ) - { - int index = code.indexOf( "x,f") + 2; //$NON-NLS-1$ - if( i == 1 ) index++; - IASTCompletionNode node = parse( code, index ); - validateCompletionNode(node, (( i == 0 ) ? "" : "f" ), CompletionKind.CONSTRUCTOR_REFERENCE, null, true ); //$NON-NLS-1$ //$NON-NLS-2$ - assertNotNull( node.getFunctionParameters() ); - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.LOCAL_VARIABLES }, - node.getCompletionContext(), null ); - assertNotNull(result); - assertEquals( result.getResultsSize(), ( i == 0 ) ? 2 : 1 ); - } - } - - public void testConstructors() throws Exception - { - String code = "class Foo{ public: Foo(); }; Foo::SP "; //$NON-NLS-1$ - - IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$ - - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.CONSTRUCTORS }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 1 ); - IASTMethod constructor = (IASTMethod) result.getNodes().next(); - assertEquals( constructor.getName(), "Foo" ); //$NON-NLS-1$ - } - - public void testBug50807() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void foo();" ); //$NON-NLS-1$ - writer.write( "void foo( int );" ); //$NON-NLS-1$ - writer.write( "void foo( int, char );" ); //$NON-NLS-1$ - writer.write( "void foo( int, int, int );" ); //$NON-NLS-1$ - writer.write( "void bar(){ " ); //$NON-NLS-1$ - - String code = writer.toString() + "foo( SP"; //$NON-NLS-1$ - IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$ - - assertEquals( node.getCompletionPrefix(), "" ); //$NON-NLS-1$ - assertEquals( node.getFunctionName(), "foo" ); //$NON-NLS-1$ - ILookupResult result = node.getCompletionScope().lookup( node.getFunctionName(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.FUNCTIONS }, - node.getCompletionContext(), null ); - assertEquals( result.getResultsSize(), 4 ); - - code = writer.toString() + "foo( 1, SP"; //$NON-NLS-1$ - node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$ - - assertEquals( node.getCompletionPrefix(), "" ); //$NON-NLS-1$ - assertEquals( node.getFunctionName(), "foo" ); //$NON-NLS-1$ - result = node.getCompletionScope().lookup( node.getFunctionName(), - new IASTNode.LookupKind[]{ IASTNode.LookupKind.FUNCTIONS }, - node.getCompletionContext(), node.getFunctionParameters() ); - - assertEquals( result.getResultsSize(), 2 ); - } - - public void testBug60298() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class ABC { public: ABC(); int myInt(); };\n"); //$NON-NLS-1$ - writer.write( "int ABC::" ); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "::") + 2 ); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), CompletionKind.SINGLE_NAME_REFERENCE ); - - } - - public void testBug62344() throws Exception - { - Writer writer = new StringWriter(); - writer.write( " namespace Foo{ class bar{}; } "); //$NON-NLS-1$ - writer.write( " void main() { "); //$NON-NLS-1$ - writer.write( " Foo::bar * foobar = new Foo::SP "); //$NON-NLS-1$ - - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "SP" ) ); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), CompletionKind.NEW_TYPE_REFERENCE ); - } - - public void testBug62339() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct Cube { int nLength; int nWidth; int nHeight; };\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) { struct Cube * pCube;\n" ); //$NON-NLS-1$ - writer.write( " pCube = (str" ); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "(str") + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - boolean foundStruct = false; - Iterator i = node.getKeywords(); - while( i.hasNext() ) - if( ((String) i.next()).equals( "struct")) //$NON-NLS-1$ - foundStruct = true; - assertTrue( foundStruct ); - } - - public void testBug62721() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "int f() {\n" ); //$NON-NLS-1$ - writer.write( "short blah;\n" ); //$NON-NLS-1$ - writer.write( "int x = sizeof(bl" ); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "of(bl") + 3); //$NON-NLS-1$ - assertNotNull( node ); - assertEquals( node.getCompletionKind(), CompletionKind.SINGLE_NAME_REFERENCE ); - assertNull( node.getCompletionContext() ); - IASTNode.LookupKind [] kinds = new IASTNode.LookupKind[1]; - kinds[0] = IASTNode.LookupKind.LOCAL_VARIABLES; - IASTNode.ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), kinds, null, null ); - assertEquals( result.getResultsSize(), 1 ); - IASTNode blah = (IASTNode) result.getNodes().next(); - assertTrue( blah instanceof IASTVariable ); - assertEquals( ((IASTVariable)blah).getName(), "blah" ); //$NON-NLS-1$ - } - - public void testBug62725() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "int f() {\n" ); //$NON-NLS-1$ - writer.write( " int biSizeImage = 5;\n" ); //$NON-NLS-1$ - writer.write( "for (int i = 0; i < bi " ); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "< bi") + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - assertEquals( node.getCompletionPrefix(), "bi"); //$NON-NLS-1$\ - assertNull( node.getCompletionContext() ); - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertTrue( ((IASTFunction)node.getCompletionScope()).getName().equals( "f" ) ); //$NON-NLS-1$ - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - } - - public void testBug62728() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct Temp { char * t; };" ); //$NON-NLS-1$ - writer.write( "int f(Temp * t) {\n" ); //$NON-NLS-1$ - writer.write( "t->t[5] = t-> "); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "= t->") + 5 ); //$NON-NLS-1$ - assertNotNull( node ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.MEMBER_REFERENCE ); - assertTrue( node.getCompletionScope() instanceof IASTFunction ); - assertTrue( ((IASTFunction)node.getCompletionScope()).getName().equals( "f" ) ); //$NON-NLS-1$ - assertNotNull( node.getCompletionContext() ); - } - - public void testBug64271() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "typedef int DWORD;\n" ); //$NON-NLS-1$ - writer.write( "typedef char BYTE;\n"); //$NON-NLS-1$ - writer.write( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n"); //$NON-NLS-1$ - writer.write( "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n"); //$NON-NLS-1$ - writer.write( "enum e {\n"); //$NON-NLS-1$ - writer.write( "blah1 = 5,\n"); //$NON-NLS-1$ - writer.write( "blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n"); //$NON-NLS-1$ - writer.write( "blah3\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "e mye = bl\n"); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "= bl") + 4); //$NON-NLS-1$ - assertNotNull( node ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE ); - assertEquals( node.getCompletionPrefix(), "bl"); //$NON-NLS-1$ - assertNull( node.getCompletionContext() ); - assertFalse( node.getKeywords().hasNext() ); - - LookupKind[] kind = new LookupKind[1]; - kind[0] = LookupKind.ENUMERATORS; - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), kind, null, null ); - assertNotNull( result ); - assertEquals( result.getResultsSize(), 3 ); - } - - public void testBug52988() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - ParserLanguage language = ( i == 0 ) ? ParserLanguage.C : ParserLanguage.CPP; - String code = "void foo() { "; //$NON-NLS-1$ - Set kset = KeywordSets.getKeywords( KeywordSetKey.STATEMENT, language ); - - validateAllKeywordsAndPrefixes( code, kset, language ); - } - } - - /** - * @param startingCode - * @param keywordsToTry - * @param language - * @throws Exception - */ - private void validateAllKeywordsAndPrefixes(String startingCode, Set keywordsToTry, ParserLanguage language) throws Exception { - Iterator keywordIterator = keywordsToTry.iterator(); - while( keywordIterator.hasNext() ) - { - String keyword = (String) keywordIterator.next(); - for( int i = 0; i < keyword.length(); ++i ) - { - String substring = keyword.subSequence( 0, i ).toString(); - String totalCode = (startingCode + substring); - IASTCompletionNode node = parse( totalCode, totalCode.length() - 1, language ); - assertNotNull( node ); - assertTrue( "Failure on keyword=" + keyword + " prefix=" + substring, setContainsKeyword( node.getKeywords(), keyword )); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - } - - /** - * @param keywords - * @param keyword - * @return - */ - private boolean setContainsKeyword(Iterator keywords, String keyword) { - while( keywords.hasNext() ) - { - if( keywords.next().equals( keyword )) return true; - } - return false; - } - - public void testBug66543() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct packet { int a; int b; };\n" ); //$NON-NLS-1$ - writer.write( "struct packet buffer[5];\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( " buffer[2]." ); //$NON-NLS-1$ - String code = writer.toString(); - IASTCompletionNode node = parse( code, code.indexOf( "[2].") + 4 ); //$NON-NLS-1$ - assertNotNull( node ); - assertNotNull( node.getCompletionContext() ); - IASTNode.LookupKind [] kinds = new LookupKind[ 1 ]; - kinds[0] = LookupKind.FIELDS; - ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(), kinds, node.getCompletionContext(), node.getFunctionParameters() ); - assertNotNull( result ); - assertEquals( result.getResultsSize(), 2 ); - } - - public void testBug69439() throws Exception - { - String code = "float f = 123."; //$NON-NLS-1$ - IASTCompletionNode node = parse( code, code.indexOf( ".") + 1 ); //$NON-NLS-1$ - assertNotNull( node ); - assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.NO_SUCH_KIND ); - - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FailingTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FailingTemplateTests.java deleted file mode 100644 index d0ed48f7295..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FailingTemplateTests.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import junit.framework.TestCase; - -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; - -/** - * @author aniefer - */ -public class FailingTemplateTests extends TestCase { - - public ParserSymbolTable table = null; - - public FailingTemplateTests( String arg ) - { - super( arg ); - } - - public ParserSymbolTable newTable(){ - return newTable( ParserLanguage.CPP ); - } - - public ParserSymbolTable newTable( ParserLanguage language ){ - table = new ParserSymbolTable( language, ParserMode.COMPLETE_PARSE ); - return table; - } - - /** - * These tests represent code snippets from the ANSI C++ spec - */ - - - /** - * A specialization of a member function template does not override a virtual - * function from a base class. - * - * class B { - * virtual void f( int ); - * }; - * - * class D : public B{ - * template < class T > void f( T ); - * }; - * - * template <> void D::f< int > ( int ) {} //does not override B::f( int ); - * - * void main(){ - * D d; - * d.f( 1 ); //calls B::f( int ) - * d.f<>( 1 ); //calls D::f( int ); - * } - * @throws Exception - */ - public void test_14_5_2__4_VirtualBaseClassFunctions() throws Exception{ - //bug 51483 TBD - } - - /** - * template < class T = int > struct A { - * static int x; - * }; - * - * template <> struct A< double > {}; //specialize T == double - * template <> struct A<> {}; //specialize T == int - * - * template <> int A< char >::x = 0; - * template <> int A< float >::x = 0.5; - * - * @throws Exception - */ - public void test_14_7__3_ExplicitSpecialization() throws Exception{ - //bug 51485 - } - - /** - * Each class template specialization instantiated from a template has its own - * copy of any static members - * - * template < class T > class X { - * static T s; - * } - * - * template < class T > T X::s = 0; - * - * X a; //a.s has type int - * X b; //b.s has type char * - * @throws Exception - */ - public void test_14_7__6_ExplicitSpecializationStaticMembers() throws Exception{ - //bug 51485 - } - - /** - * template void f( void (*) (T, int) ); - * template void foo( T, int ); - * - * void g( int, int ); - * void g( char, int ); - * - * void h( int, int, int ); - * void h( char, int ); - * - * int m(){ - * f( &g ); //error, ambiguous - * f( &h ); //ok, h(char, int) is a unique match - * f( &foo ); //error, foo is a template - * } - * - * @throws Exception - */ - public void test_14_8_2_4__16_ArgumentDeduction() throws Exception{ - //This test will require resolving the address of an overloaded function - //without arguments. bug 45764 - -// newTable(); -// -// ITemplateSymbol templateF = table.newTemplateSymbol( "f" ); -// -// ISymbol T = table.newSymbol( "T", TypeInfo.t_templateParameter ); -// templateF.addParameter( T ); -// -// IParameterizedSymbol f = table.newParameterizedSymbol( "f", TypeInfo.t_function ); -// -// IParameterizedSymbol fParam = table.newParameterizedSymbol( "", TypeInfo.t_function ); -// fParam.setIsTemplateMember( true ); -// fParam.setReturnType( table.newSymbol( "", TypeInfo.t_void ) ); -// fParam.addParameter( T, null, false ); -// fParam.addParameter( TypeInfo.t_int, 0, null, false ); -// fParam.addPtrOperator( new PtrOp( PtrOp.t_pointer ) ); -// -// f.addParameter( fParam ); -// -// templateF.addSymbol( f ); -// table.getCompilationUnit().addSymbol( templateF ); -// -// ITemplateSymbol templateFoo = table.newTemplateSymbol( "foo" ); -// T = table.newSymbol( "T", TypeInfo.t_templateParameter ); -// templateFoo.addParameter( T ); -// -// IParameterizedSymbol foo = table.newParameterizedSymbol( "foo", TypeInfo.t_function ); -// foo.setReturnType( table.newSymbol( "", TypeInfo.t_void ) ); -// foo.addParameter( T, null, false ); -// foo.addParameter( TypeInfo.t_int, 0, null, false ); -// -// templateFoo.addSymbol( foo ); -// table.getCompilationUnit().addSymbol( templateFoo ); -// -// IParameterizedSymbol g1 = table.newParameterizedSymbol( "g", TypeInfo.t_function ); -// g1.addParameter( TypeInfo.t_int, 0, null, false ); -// g1.addParameter( TypeInfo.t_int, 0, null, false ); -// table.getCompilationUnit().addSymbol( g1 ); -// -// IParameterizedSymbol g2 = table.newParameterizedSymbol( "g", TypeInfo.t_function ); -// g2.addParameter( TypeInfo.t_char, 0, null, false ); -// g2.addParameter( TypeInfo.t_int, 0, null, false ); -// table.getCompilationUnit().addSymbol( g2 ); -// -// IParameterizedSymbol h1 = table.newParameterizedSymbol( "h", TypeInfo.t_function ); -// h1.addParameter( TypeInfo.t_int, 0, null, false ); -// h1.addParameter( TypeInfo.t_int, 0, null, false ); -// h1.addParameter( TypeInfo.t_int, 0, null, false ); -// table.getCompilationUnit().addSymbol( h1 ); -// -// IParameterizedSymbol h2 = table.newParameterizedSymbol( "h", TypeInfo.t_function ); -// h2.addParameter( TypeInfo.t_char, 0, null, false ); -// h2.addParameter( TypeInfo.t_int, 0, null, false ); -// table.getCompilationUnit().addSymbol( h2 ); -// -// -// -// List args = new LinkedList(); -// -// -// ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", args ); -// assertTrue( look != null ); -// assertTrue( look.isTemplateInstance() ); -// assertEquals( look.getInstantiatedSymbol(), f ); -// -// look = table.getCompilationUnit().lookup( "foo" ); -// assertTrue( look != null ); -// args.clear(); -// TypeInfo arg = new TypeInfo( TypeInfo.t_type, 0, look ); -// arg.addOperatorExpression( TypeInfo.OperatorExpression.addressof ); -// args.add( arg ); -// -// try{ -// look = table.getCompilationUnit().unqualifiedFunctionLookup( "f", args ); -// assertTrue( false ); -// }catch ( ParserSymbolTableException e ){ -// assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateParameter ); -// } - - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java index 24618669622..713d6b8b6dc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FileBasePluginTest.java @@ -16,63 +16,14 @@ package org.eclipse.cdt.core.parser.tests; import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.util.Iterator; -import java.util.List; import junit.framework.TestCase; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ParserUtil; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassReference; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumeratorReference; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFieldReference; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTFunctionReference; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTMethodReference; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTParameterReference; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypedefReference; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTVariableReference; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -207,164 +158,4 @@ public class FileBasePluginTest extends TestCase { return file; } - - public static class CallbackTracker implements ISourceElementRequestor{ - private List callbacks; - private IASTScope compUnit; - public CallbackTracker( List callbacks ){ - this.callbacks = callbacks; - } - - public IASTScope getCompilationUnit() - { - return compUnit; - } - public static final String ACCEPT_PROBLEM = "ACCEPT_PROBLEM"; //$NON-NLS-1$ - public static final String ACCEPT_MACRO = "ACCEPT_MACRO"; //$NON-NLS-1$ - public static final String ACCEPT_VARIABLE = "ACCEPT_VARIABLE"; //$NON-NLS-1$ - public static final String ACCEPT_FUNCTION_DECL = "ACCEPT_FUNCTION_DECL"; //$NON-NLS-1$ - public static final String ACCEPT_USING_DIRECTIVE = "ACCEPT_USING_DIRECTIVE"; //$NON-NLS-1$ - public static final String ACCEPT_USING_DECL = "ACCEPT_USING_DECL"; //$NON-NLS-1$ - public static final String ACCEPT_ASM_DEF = "ACCEPT_ASM_DEF"; //$NON-NLS-1$ - public static final String ACCEPT_TYPEDEF = "ACCEPT_TYPEDEF"; //$NON-NLS-1$ - public static final String ACCEPT_ENUMERATION = "ACCEPT_ENUMERATION"; //$NON-NLS-1$ - public static final String ACCEPT_ELABORATED = "ACCEPT_ELABORATED"; //$NON-NLS-1$ - public static final String ACCEPT_ABSTRACT_TYPESPEC = "ACCEPT_ABSTRACT_TYPESPEC"; //$NON-NLS-1$ - public static final String ACCEPT_METHOD = "ACCEPT_METHOD"; //$NON-NLS-1$ - public static final String ACCEPT_FIELD = "ACCEPT_FIELD"; //$NON-NLS-1$ - public static final String ACCEPT_REFERENCE = "ACCEPT_REFERENCE"; //$NON-NLS-1$ - public static final String ACCEPT_FRIEND = "ACCEPT_FRIEND"; //$NON-NLS-1$ - public static final String ENTER_FUNCTION = "ENTER_FUNCTION"; //$NON-NLS-1$ - public static final String ENTER_CODE_BLOCK = "ENTER_CODE_BLOCK"; //$NON-NLS-1$ - public static final String ENTER_COMPILATION_UNIT = "ENTER_COMPILATION_UNIT"; //$NON-NLS-1$ - public static final String ENTER_INCLUSION = "ENTER_INCLUSION"; //$NON-NLS-1$ - public static final String ENTER_NAMESPACE = "ENTER_NAMESPACE"; //$NON-NLS-1$ - public static final String ENTER_CLASS_SPEC = "ENTER_CLASS_SPEC"; //$NON-NLS-1$ - public static final String ENTER_LINKAGE = "ENTER_LINKAGE"; //$NON-NLS-1$ - public static final String ENTER_TEMPLATE_DECL = "ENTER_TEMPLATE_DECL"; //$NON-NLS-1$ - public static final String ENTER_TEMPLATE_SPEC = "ENTER_TEMPLATE_SPEC"; //$NON-NLS-1$ - public static final String ENTER_TEMPLATE_INSTANCE = "ENTER_TEMPLATE_INSTANCE"; //$NON-NLS-1$ - public static final String ENTER_METHOD = "ENTER_METHOD"; //$NON-NLS-1$ - public static final String EXIT_FUNCTION = "EXIT_FUNCTION"; //$NON-NLS-1$ - public static final String EXIT_CODE_BLOCK = "EXIT_CODE_BLOCK"; //$NON-NLS-1$ - public static final String EXIT_METHOD = "EXIT_METHOD"; //$NON-NLS-1$ - public static final String EXIT_TEMPLATE_DECL = "EXIT_TEMPLATE_DECL"; //$NON-NLS-1$ - public static final String EXIT_TEMPLATE_SPEC = "EXIT_TEMPLATE_SPEC"; //$NON-NLS-1$ - public static final String EXIT_TEMPLATE_INSTANCE = "EXIT_TEMPLATE_INSTANCE"; //$NON-NLS-1$ - public static final String EXIT_LINKAGE = "EXIT_LINKAGE"; //$NON-NLS-1$ - public static final String EXIT_CLASS = "EXIT_CLASS"; //$NON-NLS-1$ - public static final String EXIT_NAMESPACE = "EXIT_NAMESPACE"; //$NON-NLS-1$ - public static final String EXIT_INCLUSION = "EXIT_INCLUSION"; //$NON-NLS-1$ - public static final String EXIT_COMPILATION_UNIT = "EXIT_COMPILATION_UNIT"; //$NON-NLS-1$ - - - public boolean acceptProblem( IProblem problem ) { - callbacks.add( ACCEPT_PROBLEM ); - return false; - } - public void acceptMacro( IASTMacro macro ) { callbacks.add( ACCEPT_MACRO ); } - public void acceptVariable( IASTVariable variable ) { callbacks.add( ACCEPT_VARIABLE ); } - public void acceptFunctionDeclaration( IASTFunction function ) { callbacks.add( ACCEPT_FUNCTION_DECL); } - public void acceptUsingDirective( IASTUsingDirective usageDirective ) { callbacks.add( ACCEPT_USING_DIRECTIVE ); } - public void acceptUsingDeclaration( IASTUsingDeclaration usageDeclaration ) { callbacks.add( ACCEPT_USING_DECL ); } - public void acceptASMDefinition( IASTASMDefinition asmDefinition ) { callbacks.add( ACCEPT_ASM_DEF ); } - public void acceptTypedefDeclaration( IASTTypedefDeclaration typedef ) { callbacks.add( ACCEPT_TYPEDEF ); } - public void acceptEnumerationSpecifier( IASTEnumerationSpecifier enumeration ) { callbacks.add( ACCEPT_ENUMERATION); } - public void acceptElaboratedForewardDeclaration( IASTElaboratedTypeSpecifier elaboratedType ) { callbacks.add( ACCEPT_ELABORATED ); } - public void acceptAbstractTypeSpecDeclaration( IASTAbstractTypeSpecifierDeclaration abstractDeclaration ) { callbacks.add( ACCEPT_ABSTRACT_TYPESPEC); } - public void enterFunctionBody( IASTFunction function ) { callbacks.add( ENTER_FUNCTION ); } - public void exitFunctionBody( IASTFunction function ) { callbacks.add( EXIT_FUNCTION ); } - public void enterCodeBlock( IASTCodeScope scope ) { callbacks.add( ENTER_CODE_BLOCK ); } - public void exitCodeBlock( IASTCodeScope scope ) { callbacks.add( EXIT_CODE_BLOCK ); } - public void enterInclusion( IASTInclusion inclusion ) { callbacks.add( ENTER_INCLUSION ); } - public void enterNamespaceDefinition( IASTNamespaceDefinition namespaceDefinition ) { callbacks.add( ENTER_NAMESPACE ); } - public void enterClassSpecifier( IASTClassSpecifier classSpecification ) { callbacks.add( ENTER_CLASS_SPEC ); } - public void enterLinkageSpecification( IASTLinkageSpecification linkageSpec ) { callbacks.add( ENTER_LINKAGE ); } - public void enterTemplateDeclaration( IASTTemplateDeclaration declaration ) { callbacks.add( ENTER_TEMPLATE_DECL ); } - public void enterTemplateSpecialization( IASTTemplateSpecialization specialization ) { callbacks.add( ENTER_TEMPLATE_SPEC ); } - public void enterTemplateInstantiation( IASTTemplateInstantiation instantiation ) { callbacks.add( ENTER_TEMPLATE_INSTANCE ); } - public void acceptMethodDeclaration( IASTMethod method ) { callbacks.add( ACCEPT_METHOD ); } - public void enterMethodBody( IASTMethod method ) { callbacks.add( ENTER_METHOD ); } - public void exitMethodBody( IASTMethod method ) { callbacks.add( EXIT_METHOD ); } - public void acceptField( IASTField field ) { callbacks.add( ACCEPT_FIELD ); } - public void acceptClassReference( IASTClassReference reference ) { callbacks.add( ACCEPT_REFERENCE ); } - public void acceptTypedefReference( IASTTypedefReference reference ) { callbacks.add( ACCEPT_REFERENCE ); } - public void acceptNamespaceReference( IASTNamespaceReference reference ) { callbacks.add( ACCEPT_REFERENCE ); } - public void acceptEnumerationReference( IASTEnumerationReference reference ) { callbacks.add( ACCEPT_REFERENCE ); } - public void acceptVariableReference( IASTVariableReference reference ) { callbacks.add( ACCEPT_REFERENCE ); } - public void acceptFunctionReference( IASTFunctionReference reference ) { callbacks.add( ACCEPT_REFERENCE ); } - public void acceptFieldReference( IASTFieldReference reference ) { callbacks.add( ACCEPT_REFERENCE ); } - public void acceptMethodReference( IASTMethodReference reference ) { callbacks.add( ACCEPT_REFERENCE ); } - public void acceptEnumeratorReference( IASTEnumeratorReference reference ) { callbacks.add( ACCEPT_REFERENCE ); } - public void acceptParameterReference( IASTParameterReference reference ) { callbacks.add( ACCEPT_REFERENCE ); } - public void acceptTemplateParameterReference( IASTTemplateParameterReference reference ) { callbacks.add( ACCEPT_REFERENCE ); } - public void acceptFriendDeclaration( IASTDeclaration declaration ) { callbacks.add( ACCEPT_FRIEND ); } - public void exitTemplateDeclaration( IASTTemplateDeclaration declaration ) { callbacks.add( EXIT_TEMPLATE_DECL); } - public void exitTemplateSpecialization( IASTTemplateSpecialization specialization ) { callbacks.add( EXIT_TEMPLATE_SPEC ); } - public void exitTemplateExplicitInstantiation( IASTTemplateInstantiation instantiation ) { callbacks.add( EXIT_TEMPLATE_INSTANCE ); } - public void exitLinkageSpecification( IASTLinkageSpecification linkageSpec ) { callbacks.add( ACCEPT_MACRO ); } - public void exitClassSpecifier( IASTClassSpecifier classSpecification ) { callbacks.add( EXIT_CLASS ); } - public void exitNamespaceDefinition( IASTNamespaceDefinition namespaceDefinition ) { callbacks.add( EXIT_NAMESPACE); } - public void exitInclusion( IASTInclusion inclusion ) { callbacks.add( EXIT_INCLUSION ); } - public void exitCompilationUnit( IASTCompilationUnit compilationUnit ) { callbacks.add( EXIT_COMPILATION_UNIT ); } - public void enterCompilationUnit( IASTCompilationUnit compilationUnit ) - { - callbacks.add( ENTER_COMPILATION_UNIT ); - compUnit = compilationUnit; - } - public CodeReader createReader( String finalPath, Iterator workingCopies ) { - return ParserUtil.createReader(finalPath,workingCopies); - } - - } - public CallbackTracker callback; - protected IASTScope parse( IFile code, List callbacks ) throws Exception - { - return parse( code, callbacks, ParserLanguage.CPP ); - } - - protected IASTScope parse(IFile code, List callbackList, ParserLanguage language) throws Exception - { - callback = new CallbackTracker( callbackList ); - InputStream stream = code.getContents(); - IParser parser = ParserFactory.createParser( - ParserFactory.createScanner( new CodeReader( code.getLocation().toOSString(), stream ), new ScannerInfo(), //$NON-NLS-1$ - ParserMode.COMPLETE_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.COMPLETE_PARSE, language, null - ); - stream.close(); - boolean parseResult = parser.parse(); - // throw exception if there are generated IProblems - if( !parseResult ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ - if( parseResult ) - { - assertTrue( ((Parser)parser).validateCaches()); - } - return callback.getCompilationUnit(); - } - - protected IASTNode parse(IFile code, List callbacks, int start, int end) throws Exception - { - return parse(code, callbacks, start, end, true, ParserLanguage.CPP); - - } - - protected IASTNode parse(IFile code, List callbacks, int offset1, int offset2, boolean expectedToPass, ParserLanguage language) throws Exception { - callback = new CallbackTracker( callbacks ); - - IParser parser = ParserFactory.createParser( - ParserFactory.createScanner( new CodeReader( code.getLocation().toOSString(), code.getCharset() ), new ScannerInfo(), //$NON-NLS-1$ - ParserMode.SELECTION_PARSE, language, callback, new NullLogService(), null ), callback, ParserMode.SELECTION_PARSE, language, null - ); - - IParser.ISelectionParseResult result =parser.parse( offset1, offset2 ); - if( expectedToPass ) - { - assertNotNull( result ); - String filename = result.getFilename(); - assertNotNull( filename ); - assertTrue( !filename.equals( "")); //$NON-NLS-1$ - return (IASTNode) result.getOffsetableNamedElement(); - } - return null; - } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java deleted file mode 100644 index d70ddc26b7a..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/FractionalAutomatedTest.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.StringWriter; -import java.util.NoSuchElementException; -import java.util.StringTokenizer; - -import junit.framework.Test; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.testplugin.CTestPlugin; -import org.eclipse.core.runtime.Path; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class FractionalAutomatedTest extends AutomatedFramework { - - public FractionalAutomatedTest() { - super(); - } - - public FractionalAutomatedTest(String name) { - super(name); - } - - protected AutomatedFramework newTest( String name ){ - return new FractionalAutomatedTest( name ); - } - protected void loadProperties() throws Exception{ - String resourcePath = CTestPlugin.getDefault().find(new Path("/")).getFile(); //$NON-NLS-1$ //$NON-NLS-2$ - resourcePath += "resources/parser/AutomatedTest"; //$NON-NLS-1$ - - try{ - FileInputStream propertiesIn = new FileInputStream( resourcePath + "/FractionalAutomatedTest.properties"); //$NON-NLS-1$ - properties.load( propertiesIn ); - - outputFile = properties.getProperty( "outputFile", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - String sourceInfo = properties.getProperty( "source", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - - stepSize = Integer.parseInt( properties.getProperty( "stepSize", "50" ) ); //$NON-NLS-1$ //$NON-NLS-2$ - windowSize = Integer.parseInt( properties.getProperty( "windowSize", "200" ) ); //$NON-NLS-1$ //$NON-NLS-2$ - timeOut = Integer.parseInt( properties.getProperty( "timeOut", "5000" )); //$NON-NLS-1$ //$NON-NLS-2$ - outputDir = properties.getProperty( "outDir", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - - if( sourceInfo.equals("") ) //$NON-NLS-1$ - throw new FileNotFoundException(); - else{ - StringTokenizer tokenizer = new StringTokenizer( sourceInfo, "," ); //$NON-NLS-1$ - String str = null, val = null; - try{ - while( tokenizer.hasMoreTokens() ){ - str = tokenizer.nextToken().trim(); - val = tokenizer.nextToken().trim(); - - testSources.put( str, val ); - } - } catch ( NoSuchElementException e ){ - //only way to get here is to have a missing val, assume cpp for that str - testSources.put( str, "cpp" ); //$NON-NLS-1$ - } - - } - } catch ( FileNotFoundException e ){ - testSources.put( resourcePath + "/defaultCpp", "cpp" ); //$NON-NLS-1$ //$NON-NLS-2$ - testSources.put( resourcePath + "/defaultC", "c" ); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - public static Test suite() - { - AutomatedFramework frame = new FractionalAutomatedTest(); - - return frame.createSuite(); - } - - static private String outputFile( String code ) { - if( outputDir == null || outputDir.equals("") ) //$NON-NLS-1$ - return ""; //$NON-NLS-1$ - - File output = new File( outputDir ); - - try{ - if( output.exists() ){ - if( output.isFile() ){ - output.delete(); - output.createNewFile(); - FileOutputStream stream = new FileOutputStream( output ); - stream.write( code.getBytes() ); - stream.flush(); - stream.close(); - return outputDir; - } - } else { - output.mkdir(); - } - File file = new File( outputDir + "/" + failures++ + ".tmp" ); //$NON-NLS-1$ //$NON-NLS-2$ - if( file.exists() ) - file.delete(); - file.createNewFile(); - FileOutputStream stream = new FileOutputStream( file ); - stream.write( code.getBytes() ); - stream.flush(); - stream.close(); - - return file.getCanonicalPath(); - - } catch ( Exception e ) - {} - return ""; //$NON-NLS-1$ - } - - static public void reportHang( String code, String file ){ - String output = outputFile( code.toString() ); - if( output.equals("") ) //$NON-NLS-1$ - output = "Parser hang while parsing " + file + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ - else - output = "Parser hang while parsing " + output + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ - - if( report != null ){ - try{ - report.write( output.getBytes() ); - } catch ( IOException e ) {} - } - - fail( output ); - } - - static public void reportException( String code, String file, String exception ){ - String output = outputFile( code.toString() ); - - if( output.equals("") ) //$NON-NLS-1$ - output = exception.getClass().toString() + " encountered in " + file + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ - else - output = exception.getClass().toString() + " encountered in " + output + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ - - if( report != null ){ - try{ - report.write( output.getBytes() ); - } catch ( IOException e ) {} - } - - fail( output ); - } - - public void doFile() throws Throwable { - assertNotNull( fileList ); - - File file = (File)fileList.removeFirst(); - FileInputStream stream = new FileInputStream( file ); - - String filePath = file.getCanonicalPath(); - String nature = (String)natures.get( filePath ); - - boolean cppNature = nature.equalsIgnoreCase("cpp"); //$NON-NLS-1$ - - StringWriter code = new StringWriter(); - - ParseThread thread = new ParseThread(); - - byte b[] = new byte[stepSize]; - int n = stream.read( b ); - while( n != -1 ){ - code.write( new String( b ) ); - - thread.code = code.toString(); - thread.cppNature = cppNature; - thread.start(); - thread.join( timeOut ); - - if( thread.isAlive() ){ - //Use deprecated Thread.stop() for now - //alternative is to create a callback which could stop the parse on a flag - //by throwing something, but that has the disadvantage of being unable to - //stop any loops that don't involve callbacks. - thread.stop(); - reportHang( code.toString(), filePath ); - } else if( thread.result != null ) { - reportException( code.toString(), filePath, thread.result ); - } - - n = stream.read( b ); - } - - String fullCode = code.toString(); - String windowedCode = null; - int length = fullCode.length(); - int curPos = 0; - - while( curPos + windowSize < length){ - windowedCode = fullCode.substring( 0, curPos ); - windowedCode += "\n" + fullCode.substring( curPos + windowSize, length ); //$NON-NLS-1$ - - thread.code = windowedCode; - thread.cppNature = cppNature; - thread.file = filePath; - thread.start(); - thread.join( timeOut ); - - if( thread.isAlive() ) - { - thread.stop(); - reportHang( windowedCode, filePath ); - } else if( thread.result != null ) { - reportException( windowedCode, filePath, thread.result ); - } - - curPos += stepSize; - } - } - - static class ParseThread extends Thread{ - public String code; - public boolean cppNature; - public String file; - public String result; - - public void run(){ - try{ - result = null; - ParserLanguage language = cppNature ? ParserLanguage.CPP : ParserLanguage.C; - IParser parser = ParserFactory.createParser( - ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), ParserMode.QUICK_PARSE, language, nullCallback, new NullLogService(), null ), nullCallback, ParserMode.QUICK_PARSE, language, null ); - - parser.parse(); - } catch ( Exception e ){ - result = e.getClass().toString(); - } - } - } - - static protected int stepSize = 50; - static protected int windowSize = 200; - static protected int timeOut = 5000; - static protected String outputDir = null; - static protected int failures = 0; -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteParseExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteParseExtensionsTest.java deleted file mode 100644 index 6d48dd8918e..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteParseExtensionsTest.java +++ /dev/null @@ -1,288 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCSimpleTypeSpecifier; - -/** - * @author jcamelon - * - */ -public class GCCCompleteParseExtensionsTest extends CompleteParseBaseTest { - - /** - * - */ - public GCCCompleteParseExtensionsTest() { - super(); - } - - /** - * @param name - */ - public GCCCompleteParseExtensionsTest(String name) { - super(name); - } - - public void testBug39695() throws Exception - { - Iterator i = parse("int a = __alignof__ (int);").getDeclarations(); //$NON-NLS-1$ - IASTVariable a = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - IASTExpression exp = a.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.getExpressionKind(), IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID ); - assertEquals( exp.toString(), "__alignof__(int)"); //$NON-NLS-1$ - } - - public void testBug39684() throws Exception - { - IASTFunction bar = (IASTFunction) parse("typeof(foo(1)) bar () { return foo(1); }").getDeclarations().next(); //$NON-NLS-1$ - - IASTSimpleTypeSpecifier simpleTypeSpec = ((IASTSimpleTypeSpecifier)bar.getReturnType().getTypeSpecifier()); - assertEquals( simpleTypeSpec.getType(), IASTGCCSimpleTypeSpecifier.Type.TYPEOF ); - } - - public void testBug39698A() throws Exception - { - Iterator i = parse("int c = a ? b;").getDeclarations(); //$NON-NLS-1$ - IASTVariable c = (IASTVariable) i.next(); - IASTExpression exp = c.getInitializerClause().getAssigmentExpression(); - assertEquals( ASTUtil.getExpressionString( exp ), "a >? b" ); //$NON-NLS-1$ - } - - public void testPredefinedSymbol_bug69791() throws Exception { - Iterator i = parse("typedef __builtin_va_list __gnuc_va_list; \n").getDeclarations();//$NON-NLS-1$ - assertTrue( i.next() instanceof IASTTypedefDeclaration ); - assertFalse(i.hasNext()); - } - - public void testBug39697() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "__asm__( \"CODE\" );\n" ); //$NON-NLS-1$ - writer.write( "__inline__ int foo() { return 4; }\n"); //$NON-NLS-1$ - writer.write( "__const__ int constInt;\n"); //$NON-NLS-1$ - writer.write( "__volatile__ int volInt;\n"); //$NON-NLS-1$ - writer.write( "__signed__ int signedInt;\n"); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTASMDefinition asmDefinition = (IASTASMDefinition) i.next(); - assertEquals( asmDefinition.getBody(), "CODE"); //$NON-NLS-1$ - IASTFunction foo = (IASTFunction) i.next(); - assertTrue( foo.isInline() ); - IASTVariable constInt = (IASTVariable) i.next(); - assertTrue( constInt.getAbstractDeclaration().isConst()); - IASTVariable volInt = (IASTVariable) i.next(); - assertTrue( volInt.getAbstractDeclaration().isVolatile() ); - IASTVariable signedInt = (IASTVariable) i.next(); - assertTrue( ((IASTSimpleTypeSpecifier) signedInt.getAbstractDeclaration().getTypeSpecifier()).isSigned() ); - assertFalse( i.hasNext() ); - for( int j = 0; j < 2; ++j ) - { - writer = new StringWriter(); - writer.write( "int * __restrict__ resPointer1;\n"); //$NON-NLS-1$ - writer.write( "int * __restrict resPointer2;\n"); //$NON-NLS-1$ - i = parse( writer.toString(), true, ((j == 0 )? ParserLanguage.C : ParserLanguage.CPP) ).getDeclarations(); - int count = 0; - while( i.hasNext() ) - { - ++count; - IASTVariable resPointer = (IASTVariable) i.next(); - Iterator pOps = resPointer.getAbstractDeclaration().getPointerOperators(); - assertTrue( pOps.hasNext() ); - ASTPointerOperator op = (ASTPointerOperator) pOps.next(); - assertFalse( pOps.hasNext() ); - assertEquals( op, ASTPointerOperator.RESTRICT_POINTER ); - } - - assertEquals( count, 2 ); - } - } - - public void testBug73954A() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write("void f(){ \n");//$NON-NLS-1$ - writer.write(" __builtin_expect( 23, 2); \n");//$NON-NLS-1$ - writer.write(" __builtin_prefetch( (const void *)0, 1, 2); \n");//$NON-NLS-1$ - writer.write(" __builtin_huge_val(); \n");//$NON-NLS-1$ - writer.write(" __builtin_huge_valf(); \n");//$NON-NLS-1$ - writer.write(" __builtin_huge_vall(); \n");//$NON-NLS-1$ - writer.write(" __builtin_inf(); \n");//$NON-NLS-1$ - writer.write(" __builtin_inff(); \n");//$NON-NLS-1$ - writer.write(" __builtin_infl(); \n");//$NON-NLS-1$ - writer.write(" __builtin_nan(\"\"); \n");//$NON-NLS-1$ - writer.write(" __builtin_nanf(\"\"); \n");//$NON-NLS-1$ - writer.write(" __builtin_nanl(\"\"); \n");//$NON-NLS-1$ - writer.write(" __builtin_nans(\"\"); \n");//$NON-NLS-1$ - writer.write(" __builtin_nansf(\"\"); \n");//$NON-NLS-1$ - writer.write(" __builtin_nansl(\"\"); \n");//$NON-NLS-1$ - writer.write(" __builtin_ffs (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_clz (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_ctz (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_popcount (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_parity (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_ffsl (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_clzl (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_ctzl (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_popcountl (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_parityl (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_ffsll (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_clzll (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_ctzll (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_popcountll (0); \n");//$NON-NLS-1$ - writer.write(" __builtin_parityll (0); \n");//$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - - parse( writer.toString() ); - } - - public void testBug39686() throws Exception - { - Writer code = new StringWriter(); - code.write("__complex__ double x; // complex double\n"); //$NON-NLS-1$ - code.write("__complex__ short int a; // complex short int\n"); //$NON-NLS-1$ - code.write("__complex__ float y = 2.5fi; // 2.5 imaginary float literal\n"); //$NON-NLS-1$ - code.write("__complex__ int z = 3i; // imaginary intege r literal\n"); //$NON-NLS-1$ - code.write("double v = __real__ x; // real part of expression\n"); //$NON-NLS-1$ - code.write("double w = __imag__ x; // imaginary part of expression\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug39551B() throws Exception - { - //this used to be 99.99 * __I__, but I don't know where the __I__ came from, its not in C99, nor in GCC - IASTVariable variable = (IASTVariable)parse("_Imaginary double id = 99.99 * 1i;", true, ParserLanguage.C).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( variable.getName(), "id"); //$NON-NLS-1$ - assertTrue( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).isImaginary() ); - } - - public void testBug39681() throws Exception - { - Writer code = new StringWriter(); - code.write("double\n"); //$NON-NLS-1$ - code.write("foo (double a, double b)\n"); //$NON-NLS-1$ - code.write("{\n"); //$NON-NLS-1$ - code.write(" double square (double z) { return z * z; }\n"); //$NON-NLS-1$ - code.write(" return square (a) + square (b);\n"); //$NON-NLS-1$ - code.write("}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug39677() throws Exception - { - parse("class B { public: B(); int a;}; B::B() : a(({ 1; })) {}"); //$NON-NLS-1$ - Writer writer = new StringWriter(); - writer.write( "B::B() : a(( { int y = foo (); int z;\n" ); //$NON-NLS-1$ - writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$ - writer.write( "else z = - y;\n" );//$NON-NLS-1$ - writer.write( "z; }))\n" );//$NON-NLS-1$ - parse( writer.toString() ); - - writer = new StringWriter(); - writer.write( "int x = ({ int y = foo (); int z;\n" ); //$NON-NLS-1$ - writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$ - writer.write( "else z = - y;\n" );//$NON-NLS-1$ - writer.write( "z; });\n" );//$NON-NLS-1$ - parse( writer.toString() ); - - writer = new StringWriter(); - writer.write( "int foo(); \n" ); //$NON-NLS-1$ - writer.write( "typeof({ int y = foo (); \n" ); //$NON-NLS-1$ - writer.write( " int z; \n" ); //$NON-NLS-1$ - writer.write( " if (y > 0) z = y; \n" ); //$NON-NLS-1$ - writer.write( " else z = - y; \n" ); //$NON-NLS-1$ - writer.write( " z; \n" ); //$NON-NLS-1$ - writer.write( " }) zoot; \n" ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug75401() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define va_arg __builtin_va_arg \n"); //$NON-NLS-1$ - writer.write( "#define va_list __builtin_va_list \n"); //$NON-NLS-1$ - writer.write( "void main( int argc, char** argv ) { \n"); //$NON-NLS-1$ - writer.write( " va_list v; \n"); //$NON-NLS-1$ - writer.write( " long l = va_arg( v, long ); \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - - parse( writer.toString() ); - } - - public void testBug73954B() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "#define foo(x) \\\n"); //$NON-NLS-1$ - writer.write( " __builtin_choose_expr( 1, foo_d(x), (void)0 ) \n"); //$NON-NLS-1$ - writer.write( "int foo_d( int x ); \n"); //$NON-NLS-1$ - writer.write( "int main() { \n"); //$NON-NLS-1$ - writer.write( " if( __builtin_constant_p(1) && \n"); //$NON-NLS-1$ - writer.write( " __builtin_types_compatible_p( 1, 'c') ) \n"); //$NON-NLS-1$ - writer.write( " foo(1); \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - - parse( writer.toString(), true, ParserLanguage.C ); - } - - public void testGNUExternalTemplate_bug71603() throws Exception { - Iterator i = parse("template \n class A {}; \n extern template class A; \n").getDeclarations(); //$NON-NLS-1$ - IASTTemplateDeclaration td = (IASTTemplateDeclaration) i.next(); - IASTClassSpecifier cs = (IASTClassSpecifier) td.getOwnedDeclaration(); - IASTTemplateInstantiation ti = (IASTTemplateInstantiation) i.next(); - assertFalse(i.hasNext()); - } - - public void testBug74190_g_assert_1() throws Exception { - Writer writer = new StringWriter(); - writer.write( "void log( int ); \n"); //$NON-NLS-1$ - writer.write( "void f() { \n"); //$NON-NLS-1$ - writer.write( " int a = 1; \n"); //$NON-NLS-1$ - writer.write( " (void)({ if( a ){ } \n"); //$NON-NLS-1$ - writer.write( " else{ log( a ); } \n"); //$NON-NLS-1$ - writer.write( " }); \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - - parse( writer.toString() ); - } - - public void testBug74190_g_return_if_fail() throws Exception { - Writer writer = new StringWriter(); - writer.write( "void f() { \n"); //$NON-NLS-1$ - writer.write( " (void)({ if( ( ({ 0; }) ) ) \n"); //$NON-NLS-1$ - writer.write( " { } \n"); //$NON-NLS-1$ - writer.write( " }); \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - - parse( writer.toString() ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCParserExtensionTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCParserExtensionTestSuite.java deleted file mode 100644 index 887cf3b59d3..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCParserExtensionTestSuite.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import org.eclipse.cdt.core.parser.tests.scanner2.GCCScannerExtensionsTest; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * @author jcamelon - * - */ -public class GCCParserExtensionTestSuite extends TestCase { - - public static Test suite() { - TestSuite suite= new TestSuite(GCCParserExtensionTestSuite.class.getName()); - suite.addTestSuite( GCCScannerExtensionsTest.class ); - suite.addTestSuite( GCCQuickParseExtensionsTest.class ); - suite.addTestSuite( GCCCompleteParseExtensionsTest.class ); - suite.addTestSuite( GCCSelectionParseExtensionsTest.class); - return suite; - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCQuickParseExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCQuickParseExtensionsTest.java deleted file mode 100644 index a8d326f350d..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCQuickParseExtensionsTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTVariable; - -/** - * @author jcamelon - * - */ -public class GCCQuickParseExtensionsTest extends BaseASTTest { - - /** - * @param a - */ - public GCCQuickParseExtensionsTest(String a) { - super(a); - // TODO Auto-generated constructor stub - } - - public void testBug39694() throws Exception - { - IASTVariable variable = (IASTVariable)parse("int ab$cd = 1;").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( variable.getName(), "ab$cd"); //$NON-NLS-1$ - } - - public void testBug39704A() throws Exception - { - IASTVariable foo = (IASTVariable) assertSoleDeclaration("__declspec (dllimport) int foo;"); //$NON-NLS-1$ - assertEquals( foo.getName(), "foo"); //$NON-NLS-1$ - } - public void testBug39704D() throws Exception - { - IASTFunction func1 = (IASTFunction) assertSoleDeclaration("__declspec(dllexport) int func1 (int a) {}"); //$NON-NLS-1$ - assertEquals( func1.getName(), "func1"); //$NON-NLS-1$ - } - - public void testBug39695() throws Exception - { - parse("int a = __alignof__ (int);"); //$NON-NLS-1$ - } - - public void testBug39684() throws Exception - { - parse("typeof(foo(1)) bar () { return foo(1); }"); //$NON-NLS-1$ - } - - public void testBug39703() throws Exception - { - Writer code = new StringWriter(); - code.write("/* __extension__ enables GNU C mode for the duration of the declaration. */\n"); //$NON-NLS-1$ - code.write("__extension__ struct G {\n"); //$NON-NLS-1$ - code.write(" struct { char z; };\n"); //$NON-NLS-1$ - code.write(" char g;\n"); //$NON-NLS-1$ - code.write("};\n"); //$NON-NLS-1$ - IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration(code.toString()); - IASTClassSpecifier G = ((IASTClassSpecifier)abs.getTypeSpecifier()); - assertEquals( G.getName(), "G" ); //$NON-NLS-1$ - assertEquals( G.getClassKind(), ASTClassKind.STRUCT ); - Iterator i = G.getDeclarations(); - assertEquals( ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier()).getName(), "" ); //$NON-NLS-1$ - assertEquals( ((IASTField)i.next()).getName(), "g" ); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug39698A() throws Exception - { - parse("int c = a ? b;"); //$NON-NLS-1$ - } - - public void testBug39554() throws Exception - { - parse("_Pragma(\"foobar\")", true, true, ParserLanguage.C ); //$NON-NLS-1$ - } - - public void testBug39704B() throws Exception - { - IASTVariable d = (IASTVariable)assertSoleDeclaration("extern int (* import) (void) __attribute__((dllimport));"); //$NON-NLS-1$ - assertEquals( d.getName(), "import"); // false assertion //$NON-NLS-1$ - } - public void testBug39704C() throws Exception - { - IASTFunction f = (IASTFunction)assertSoleDeclaration("int func2 (void) __attribute__((dllexport));"); //$NON-NLS-1$ - assertEquals( f.getName(), "func2"); //$NON-NLS-1$ - } - - public void testBug39704E() throws Exception - { - IASTVariable d = (IASTVariable)assertSoleDeclaration("extern int * __attribute__((dllimport)) (* import) (void);"); //$NON-NLS-1$ - assertEquals( d.getName(), "import"); // false assertion //$NON-NLS-1$ - } - - public void testBug39704F() throws Exception - { - IASTVariable d = (IASTVariable)assertSoleDeclaration("extern int __attribute__((dllimport)) (* import) (void);"); //$NON-NLS-1$ - assertEquals( d.getName(), "import"); // false assertion //$NON-NLS-1$ - } - - public void testBug39704G() throws Exception - { - IASTVariable d = (IASTVariable)assertSoleDeclaration("int x __attribute__ ((aligned (16))) = 0;"); //$NON-NLS-1$ - assertEquals( d.getName(), "x"); // false assertion //$NON-NLS-1$ - } - - public void testBug39686() throws Exception - { - Writer code = new StringWriter(); - code.write("__complex__ double x; // complex double\n"); //$NON-NLS-1$ - code.write("__complex__ short int a; // complex short int\n"); //$NON-NLS-1$ - code.write("__complex__ float y = 2.5fi; // 2.5 imaginary float literal\n"); //$NON-NLS-1$ - code.write("__complex__ int a = 3i; // imaginary intege r literal\n"); //$NON-NLS-1$ - code.write("double v = __real__ x; // real part of expression\n"); //$NON-NLS-1$ - code.write("double w = __imag__ x; // imaginary part of expression\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug39681() throws Exception - { - Writer code = new StringWriter(); - code.write("double\n"); //$NON-NLS-1$ - code.write("foo (double a, double b)\n"); //$NON-NLS-1$ - code.write("{\n"); //$NON-NLS-1$ - code.write(" double square (double z) { return z * z; }\n"); //$NON-NLS-1$ - code.write(" return square (a) + square (b);\n"); //$NON-NLS-1$ - code.write("}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug39677() throws Exception - { - parse("B::B() : a(({ 1; })) {}"); //$NON-NLS-1$ - Writer writer = new StringWriter(); - writer.write( "B::B() : a(( { int y = foo (); int z;\n" ); //$NON-NLS-1$ - writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$ - writer.write( "else z = - y;\n" );//$NON-NLS-1$ - writer.write( "z; }))\n" );//$NON-NLS-1$ - parse( writer.toString() ); - writer = new StringWriter(); - writer.write( "int x = ({ int y = foo (); int z;\n" ); //$NON-NLS-1$ - writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$ - writer.write( "else z = - y;\n" );//$NON-NLS-1$ - writer.write( "z; });\n" );//$NON-NLS-1$ - writer = new StringWriter(); - writer.write( "typeof({ int y = foo (); int z;\n" ); //$NON-NLS-1$ - writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$ - writer.write( "else z = - y;\n" );//$NON-NLS-1$ - writer.write( "z; }) zoot;\n" );//$NON-NLS-1$ - } - - public void testBug39701A() throws Exception - { - parse("extern template int max (int, int);"); //$NON-NLS-1$ - } - public void testBug39701B() throws Exception - { - parse("inline template class Foo;"); //$NON-NLS-1$ - } - public void testBug39701C() throws Exception - { - parse("static template class Foo;"); //$NON-NLS-1$ - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCSelectionParseExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCSelectionParseExtensionsTest.java deleted file mode 100644 index 9ce1ea0881a..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCSelectionParseExtensionsTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; - -import org.eclipse.cdt.core.parser.ast.IASTNode; - -/** - * @author jcamelon - * - */ -public class GCCSelectionParseExtensionsTest extends SelectionParseBaseTest { - - public void testBug43021() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "extern int johnc(__const char *__restrict __format, ...);\n" ); //$NON-NLS-1$ - writer.write( "void m() {johnc(\"HI\");}" ); //$NON-NLS-1$ - String code = writer.toString(); - int startIndex = code.indexOf( "{johnc") + 1; //$NON-NLS-1$ - IASTNode node = parse( code, startIndex, startIndex + 5 ); - assertNotNull( node ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/IScannerInfoPluginTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/IScannerInfoPluginTest.java deleted file mode 100644 index ebac160abbb..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/IScannerInfoPluginTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.io.InputStream; -import java.util.Collections; -import java.util.Iterator; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.ExtendedScannerInfo; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest.Scope; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ParserException; -import org.eclipse.core.resources.IFile; - -/** - * @author jcamelon - * - */ -public class IScannerInfoPluginTest extends FileBasePluginTest { - - private static final String [] EMPTY_STRING_ARRAY = new String[0]; - - /** - * @param name - * @param className - */ - public IScannerInfoPluginTest(String name) { - super(name, IScannerInfoPluginTest.class); - } - - public static Test suite() { - TestSuite suite = new TestSuite( IScannerInfoPluginTest.class ); - suite.addTest( new CompleteParsePluginTest("cleanupProject") ); //$NON-NLS-1$ - return suite; - } - - protected Iterator getDeclarations(IASTScope scope) - { - Scope s = c.lookup( scope ); - if( s != null ) - return s.getDeclarations(); - return null; - } - - CompleteParseBaseTest.FullParseCallback c; - - protected IASTScope parse(IFile code, ParserLanguage language, IScannerInfo scannerInfo ) throws Exception - { - c = new CompleteParseBaseTest.FullParseCallback(); - InputStream stream = code.getContents(); - IParser parser = ParserFactory.createParser( - ParserFactory.createScanner( new CodeReader( code.getLocation().toOSString(), stream ), scannerInfo, - ParserMode.COMPLETE_PARSE, language, c, new NullLogService(), null ), c, ParserMode.COMPLETE_PARSE, language, null - ); - stream.close(); - boolean parseResult = parser.parse(); - // throw exception if there are generated IProblems - if( !parseResult ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ - assertTrue( ((Parser)parser).validateCaches()); - return c.getCompilationUnit(); - } - - - public void testMacroFileLoading() throws Exception - { - String imacroContent = "#define ONE 1\n"; //$NON-NLS-1$ - IFile imacroFile = importFile( "imacros.h", imacroContent ); //$NON-NLS-1$ - String code = "int x = ONE;\n"; //$NON-NLS-1$ - IFile sourceCode = importFile( "source.cpp", code ); //$NON-NLS-1$ - String[] isp= {imacroFile.getParent().getLocation().toString()}; - String[] imacroz= {imacroFile.getName()}; - IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, isp, imacroz, EMPTY_STRING_ARRAY ); - Iterator i = parse( sourceCode, ParserLanguage.C, scannerInfo ).getDeclarations(); - assertTrue( i.hasNext() ); - IASTVariable x = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertEquals( x.getName(), "x" ); //$NON-NLS-1$ - assertNotNull( x.getInitializerClause() ); - assertNotNull( x.getInitializerClause().getAssigmentExpression() ); - assertEquals( x.getInitializerClause().getAssigmentExpression().toString(), "1"); //$NON-NLS-1$ - } - - public void testIncludeFileLoading() throws Exception - { - String inclContent = "int x = 4;\n\n"; //$NON-NLS-1$ - IFile inclFile = importFile( "includeMe.h", inclContent ); //$NON-NLS-1$ - String code = "int y = x;\n"; //$NON-NLS-1$ - IFile sourceCode = importFile( "source.cpp", code ); //$NON-NLS-1$ - String[] isp= {inclFile.getParent().getLocation().toString()}; - String [] includez = {inclFile.getName()}; - IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, isp, EMPTY_STRING_ARRAY, includez ); - Iterator i = parse( sourceCode, ParserLanguage.C, scannerInfo ).getDeclarations(); - assertTrue( i.hasNext() ); - assertTrue(i.next() instanceof IASTVariable ); - IASTVariable y = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - assertEquals( y.getName(), "y" ); //$NON-NLS-1$ - assertNotNull( y.getInitializerClause() ); - assertNotNull( y.getInitializerClause().getAssigmentExpression() ); - assertEquals( y.getInitializerClause().getAssigmentExpression().toString(), "x"); //$NON-NLS-1$ - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/ObjectMapTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ObjectMapTest.java similarity index 98% rename from core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/ObjectMapTest.java rename to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ObjectMapTest.java index a7791d70b2c..768292623a5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/ObjectMapTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ObjectMapTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,7 +12,7 @@ /* * Created on Jul 19, 2004 */ -package org.eclipse.cdt.core.parser.tests.scanner2; +package org.eclipse.cdt.core.parser.tests; import junit.framework.TestCase; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTemplateTests.java deleted file mode 100644 index 43ae536fd26..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTemplateTests.java +++ /dev/null @@ -1,2632 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IDeferredTemplateInstance; -import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISpecializedSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITemplateFactory; -import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; -import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider; - -/** - * @author aniefer - */ - -public class ParserSymbolTableTemplateTests extends TestCase { - - public ParserSymbolTable table = null; - public TypeInfoProvider provider = null; - - public ParserSymbolTableTemplateTests( String arg ) - { - super( arg ); - } - - public ParserSymbolTable newTable(){ - return newTable( ParserLanguage.CPP ); - } - - public ParserSymbolTable newTable( ParserLanguage language ){ - table = new ParserSymbolTable( language, ParserMode.COMPLETE_PARSE ); - provider = table.getTypeInfoProvider(); - return table; - } - - /** - * - * @throws Exception - * - * template < class T > class A : public T {}; - * - * class B - * { - * int i; - * } - * - * A a; - * a.i; //finds B::i; - */ - public void testTemplateParameterAsParent() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol param = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( param ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( A ); - A.addParent( param ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - ISymbol i = table.newSymbol( "i".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - B.addSymbol( i ); - table.getCompilationUnit().addSymbol( B ); - - ITypeInfo type = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, B ); - ArrayList args = new ArrayList(); - args.add( type ); - - IContainerSymbol instance = (IContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertEquals( instance.getInstantiatedSymbol(), A ); - - ISymbol a = table.newSymbol( "a".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( instance ); - - table.getCompilationUnit().addSymbol( a ); - - ISymbol look = table.getCompilationUnit().lookup( "a".toCharArray() ); //$NON-NLS-1$ - - assertEquals( look, a ); - - ISymbol symbol = a.getTypeSymbol(); - assertEquals( symbol, instance ); - - look = instance.lookup( "i".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, i ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * template < class T > class A { T t; } - * class B : public A< int > { } - * - * B b; - * b.t; //finds A::t, will be type int - */ - public void testTemplateInstanceAsParent() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A".toCharArray() ); //$NON-NLS-1$ - - ISymbol param = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( param ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( A ); - - ISymbol t = table.newSymbol( "t".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - ISymbol look = template.lookup( "T".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, param ); - t.setTypeSymbol( param ); - A.addSymbol( t ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( B ); - - ITypeInfo type = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0 , null ); - ArrayList args = new ArrayList(); - args.add( type ); - - look = table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A ); - - B.addParent( look ); - - ISymbol b = table.newSymbol( "b".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - b.setTypeSymbol( B ); - table.getCompilationUnit().addSymbol( b ); - - look = table.getCompilationUnit().lookup( "b".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, b ); - - look = ((IDerivableContainerSymbol) b.getTypeSymbol()).lookup( "t".toCharArray() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), t ); - assertTrue( look.isType( ITypeInfo.t_int ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * The scope of a template-parameter extends from its point of declaration - * until the end of its template. In particular, a template parameter can be used - * in the declaration of a subsequent template-parameter and its default arguments. - * @throws Exception - * - * template< class T, class U = T > class X - * { - * T t; - * U u; - * }; - * - * X< char > x; - * x.t; - * x.u; - */ - public void testTemplateParameterDefaults() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X".toCharArray() ); //$NON-NLS-1$ - - ISymbol paramT = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( paramT ); - - ISymbol look = template.lookup( "T".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, paramT ); - ISymbol paramU = table.newSymbol( "U".toCharArray() ); //$NON-NLS-1$ - paramU.setTypeInfo( TypeInfoProvider.newTypeInfo( ITypeInfo.t_templateParameter, 0, null, null, - TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, look ) ) ); - template.addTemplateParameter( paramU ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( X ); - - look = X.lookup( "T".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, paramT ); - ISymbol t = table.newSymbol( "t".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - t.setTypeSymbol( look ); - X.addSymbol( t ); - - look = X.lookup( "U".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, paramU ); - ISymbol u = table.newSymbol( "u".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - u.setTypeSymbol( look ); - X.addSymbol( u ); - - ITypeInfo type = TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ); - ArrayList args = new ArrayList(); - args.add( type ); - IDerivableContainerSymbol lookX = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "X".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( lookX.isTemplateInstance() ); - assertEquals( lookX.getInstantiatedSymbol(), X ); - - - look = lookX.lookup( "t".toCharArray() ); //$NON-NLS-1$ - - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), t ); - assertTrue( look.isType( ITypeInfo.t_char ) ); - - look = lookX.lookup( "u".toCharArray() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), u ); - assertTrue( look.isType( ITypeInfo.t_char ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * template < class T > class A { - * T t; - * }; - * class B {}; - * void f( char c ) {} - * void f( A b ) { ... } - * void f( int i ) {} - * - * A a; - * f( a ); //calls f( A ) - * - */ - public void testTemplateParameterAsFunctionArgument() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol paramT = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( paramT ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( A ); - - ISymbol t = table.newSymbol( "t".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - t.setTypeSymbol( paramT ); - A.addSymbol( t ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( B ); - - ArrayList args = new ArrayList(); - ITypeInfo arg = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, B ); - args.add( arg ); - - IDerivableContainerSymbol lookA = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( lookA.isTemplateInstance() ); - assertEquals( lookA.getInstantiatedSymbol(), A ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_char, 0, null, false ); - table.getCompilationUnit().addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( lookA, 0, null, false ); - table.getCompilationUnit().addSymbol( f2 ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f3.addParameter( ITypeInfo.t_int, 0, null, false ); - table.getCompilationUnit().addSymbol( f3 ); - - args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, B ) ); - IDerivableContainerSymbol lookA2 = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertEquals( lookA2, lookA ); - - - ISymbol a = table.newSymbol( "a".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( lookA ); - table.getCompilationUnit().addSymbol( a ); - - ArrayList params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ) ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( look, f2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - - /** - * class T { }; - * int i; - * - * template< class T, T i > void f( T t ) - * { - * T t1 = i; //template parameters T & i - * } - */ - public void test_14_1__3_ParameterLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol T = table.newDerivableContainerSymbol( "T".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( T ); - - ISymbol i = table.newSymbol( "i".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( i ); - - ITemplateSymbol template = table.newTemplateSymbol( "f".toCharArray() ); //$NON-NLS-1$ - - ISymbol paramT = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( paramT ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - ISymbol parami = table.newSymbol( "i".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - parami.getTypeInfo().setTemplateParameterType( ITypeInfo.t_type ); - - ISymbol look = factory.lookup( "T".toCharArray() ); //$NON-NLS-1$ - - assertEquals( look, paramT ); - parami.setTypeSymbol( look ); - template.addTemplateParameter( parami ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - ISymbol fParam = table.newSymbol( "t".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - fParam.setTypeSymbol( paramT ); - f.addParameter( fParam ); - - factory.addSymbol( f ); - - look = f.lookup( "T".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, paramT ); - - look = f.lookup( "i".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, parami ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * A non-type template parameter of type "array of T" or "function returning T" is adjusted to - * be of type "pointer to T" or "pointer to function returning T" respectively - * - * template < int *a > struct R {}; - * template < int b[5] > struct S {}; - * - * int *p; - * R

w; //ok - * S

x; //ok due to parameter adjustment - * int v[5]; - * R y; //ok due to implicit argument conversion - * S z; //ok due to adjustment and conversion - * @throws Exception - */ - public void test_14_1__8_ParameterAdjustment() throws Exception{ - newTable(); - - ITemplateSymbol templateR = table.newTemplateSymbol( "R".toCharArray() ); //$NON-NLS-1$ - - ISymbol paramA = table.newSymbol( "a".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - paramA.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - paramA.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - templateR.addTemplateParameter( paramA ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateR ); - - IDerivableContainerSymbol R = table.newDerivableContainerSymbol( "R".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( R ); - - ITemplateSymbol templateS = table.newTemplateSymbol( "S".toCharArray() ); //$NON-NLS-1$ - - ISymbol paramB = table.newSymbol( "b".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - paramB.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - paramB.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_array ) ); - templateS.addTemplateParameter( paramB ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateS ); - - IDerivableContainerSymbol S = table.newDerivableContainerSymbol( "S".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( S ); - - ISymbol look = table.getCompilationUnit().lookup( "S".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, templateS ); - - Iterator iter = templateS.getParameterList().iterator(); - ISymbol param = (ISymbol) iter.next(); - assertFalse( iter.hasNext() ); - iter = param.getTypeInfo().getPtrOperators().iterator(); - ITypeInfo.PtrOp ptr = (ITypeInfo.PtrOp) iter.next(); - assertFalse( iter.hasNext() ); - assertEquals( ptr.getType(), ITypeInfo.PtrOp.t_pointer ); - - ISymbol p = table.newSymbol( "p".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - p.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - table.getCompilationUnit().addSymbol( p ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, p ) ); - - look = table.getCompilationUnit().lookupTemplateId( "R".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), R ); - - look = table.getCompilationUnit().lookupTemplateId( "S".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), S ); - - ISymbol v = table.newSymbol( "v".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - v.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_array ) ); - table.getCompilationUnit().addSymbol( v ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, v ) ); - - look = table.getCompilationUnit().lookupTemplateId( "R".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), R ); - - look = table.getCompilationUnit().lookupTemplateId( "S".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), S ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * When default template-arguments are used, a template-argument list can be empty. In that - * case, the empty <> brackets shall still be used as the template-argument list - * - * template< class T = char > class String; - * String <> * p; //ok, T = char - * - * @throws Exception - */ - public void test_14_3__4_ParameterDefaults() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "String".toCharArray() ); //$NON-NLS-1$ - - ISymbol param = table.newSymbol( "T".toCharArray() ); //$NON-NLS-1$ - param.setTypeInfo( TypeInfoProvider.newTypeInfo( ITypeInfo.t_templateParameter, 0, null, null, - TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) )); - template.addTemplateParameter( param ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol string = table.newDerivableContainerSymbol( "String".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( string ); - - List args = new ArrayList(); - ISymbol look = table.getCompilationUnit().lookupTemplateId( "String".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), string ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * A local type, a type with no linkage, an unnamed type or a type compounded from - * any of these type shall not be used as a template-argument for a template-parameter - * - * template class X { }; - * void f(){ - * struct S { }; - * - * X x; //error - * X y; //error - * } - * @throws Exception - */ - public void test_14_3_1__2_TypeArgumentRestrictions() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X".toCharArray() ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - factory.addSymbol( table.newDerivableContainerSymbol( "X".toCharArray(), ITypeInfo.t_class ) ); //$NON-NLS-1$ - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( f ); - - IDerivableContainerSymbol S = table.newDerivableContainerSymbol( "S".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - f.addSymbol( S ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, S ) ); - try{ - f.lookupTemplateId( "X".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, S, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - try{ - f.lookupTemplateId( "X".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * A String literal is not an acceptable template-argument for a non-type, non-template parameter - * because a string literal is an object with internal linkage - * - * template< class T, char* p> class X {}; - * - * X< int, "Studebaker" > x1; //error - * - * char p [] = "Vivisectionist"; - * X< int, p > x2; //ok - * - * @throws Exception - */ - public void test_14_3_2__2_NonTypeArgumentRestrictions() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X".toCharArray() ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ISymbol param2 = table.newSymbol( "p".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - param2.getTypeInfo().setTemplateParameterType( ITypeInfo.t_char ); - param2.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - template.addTemplateParameter( param2 ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( X ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - provider.beginTypeConstruction(); - provider.setType( ITypeInfo.t_char ); - provider.setDefaultObj( "Studebaker".toCharArray() ); //$NON-NLS-1$ - ITypeInfo info = provider.completeConstruction(); - info.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - args.add( info ); //$NON-NLS-1$ - - try{ - table.getCompilationUnit().lookupTemplateId( "X".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - - ISymbol p = table.newSymbol( "p".toCharArray(), ITypeInfo.t_char ); //$NON-NLS-1$ - p.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_array ) ); - table.getCompilationUnit().addSymbol( p ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, p ) ); - - ISymbol look = table.getCompilationUnit().lookupTemplateId( "X".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), X ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * names or addresses of non-static class members are not acceptable non-type template arguments - * - * template < int * p > class X {}; - * - * struct S - * { - * int m; - * static int s; - * int * t; - * } s; - * - * X<&s.m> x1; //error, address of non-static member - * X x2; //error, name of non-static member - * X<&S::s> x3; //ok, address of static member - * - * @throws Exception - */ - public void test_14_3_2__3_NonTypeArgumentRestrictions() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X".toCharArray() ); //$NON-NLS-1$ - - ISymbol param = table.newSymbol( "p".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - param.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - param.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - template.addTemplateParameter( param ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( X ); - - IDerivableContainerSymbol S = table.newDerivableContainerSymbol( "S".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( S ); - - ISymbol m = table.newSymbol( "m".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - S.addSymbol( m ); - ISymbol s = table.newSymbol( "s".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - s.getTypeInfo().setBit( true, ITypeInfo.isStatic ); - S.addSymbol( s ); - ISymbol t = table.newSymbol( "t".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - t.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - S.addSymbol( t ); - - List args = new ArrayList(); - ITypeInfo arg = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, m ); - arg.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - args.add( arg ); - - try - { - table.getCompilationUnit().lookupTemplateId( "X".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, t ) ); - - try - { - table.getCompilationUnit().lookupTemplateId( "X".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - - args.clear(); - arg = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, s ); - arg.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - args.add( arg ); - - assertNotNull( table.getCompilationUnit().lookupTemplateId( "X".toCharArray(), args ) ); //$NON-NLS-1$ - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * Tempories, unnamed lvalues, and named lvalues that do not have external linkage are - * not acceptable template-arguments when the corresponding template-parameter has - * reference type - * - * template< const int & I > struct B {}; - * - * B<1> b1; //error, temporary would be required - * int c = 1; - * B b2; //ok - * @throws Exception - */ - public void test_14_3_2__4_NonTypeArgumentRestrictions() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "B".toCharArray() ); //$NON-NLS-1$ - - ISymbol I = table.newSymbol( "I".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - I.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - I.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, true, false ) ); - template.addTemplateParameter( I ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( B ); - - List args = new ArrayList( ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "1".toCharArray() ) ); //$NON-NLS-1$ - - try{ - table.getCompilationUnit().lookupTemplateId( "B".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateArgument ); - } - - ISymbol c = table.newSymbol( "c".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( c ); - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, c ) ); - - ISymbol look = table.getCompilationUnit().lookupTemplateId( "B".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), B ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > class A { - * int x; - * }; - * - * template < class T > class A < T * > { - * long x; - * }; - * - * template< template< class U > class V > class C{ - * V< int > y; - * V< int * > z; - * } - * - * C< A > c; //V uses primary template, so C.y.x is type int - * //V uses partial specialization, so C.z.x is type long - * - * @throws Exception - */ - public void test_14_3_3__2_PartialSpecialization_TemplateTemplateParameter() throws Exception{ - //TODO - newTable(); - - ITemplateSymbol templateA = table.newTemplateSymbol( "A".toCharArray() ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( templateA ); - - templateA.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - IDerivableContainerSymbol A1 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - templateA.addSymbol( A1 ); - - ISymbol x1 = table.newSymbol( "x".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - A1.addSymbol( x1 ); - - ISpecializedSymbol specialization = table.newSpecializedSymbol( "A".toCharArray() ); //$NON-NLS-1$ - templateA.addSpecialization( specialization ); - - ISymbol T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - specialization.addTemplateParameter( T ); - specialization.addArgument( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - - IDerivableContainerSymbol A2 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - specialization.addSymbol( A2 ); - - ISymbol x2 = table.newSymbol( "x".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - x2.getTypeInfo().setBit( true, ITypeInfo.isLong ); - A2.addSymbol( x2 ); - - ITemplateSymbol templateC = table.newTemplateSymbol( "C".toCharArray() ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( templateC ); - - ITemplateSymbol templateV = table.newTemplateSymbol( "V".toCharArray() ); //$NON-NLS-1$ - templateV.setTypeInfo( TypeInfoProvider.newTypeInfo( ITypeInfo.t_templateParameter ) ); - templateV.getTypeInfo().setTemplateParameterType( ITypeInfo.t_template ); - ISymbol U = table.newSymbol( "U".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - templateV.addTemplateParameter( U ); - - templateC.addTemplateParameter( templateV ); - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - templateC.addSymbol( C ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - ISymbol look = templateC.lookupTemplateId( "V".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look != null ); - assertTrue( look instanceof IDeferredTemplateInstance ); - - ISymbol y = table.newSymbol( "y".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - y.setTypeSymbol( look ); - - C.addSymbol( y ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - - look = templateC.lookupTemplateId( "V".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look != null ); - assertTrue( look instanceof IDeferredTemplateInstance ); - - ISymbol z = table.newSymbol( "z".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - z.setTypeSymbol( look ); - C.addSymbol( z ); - - look = table.getCompilationUnit().lookup( "A".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, templateA ); - - args.clear(); - args.add ( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, look ) ); - look = table.getCompilationUnit().lookupTemplateId( "C".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), C ); - - IDerivableContainerSymbol lookC = (IDerivableContainerSymbol)look; - look = lookC.lookup( "y".toCharArray() ); //$NON-NLS-1$ - - assertEquals( look.getType(), ITypeInfo.t_type ); - ISymbol symbol = look.getTypeSymbol(); - assertTrue( symbol instanceof IContainerSymbol ); - assertTrue( symbol.isTemplateInstance() ); - assertEquals( symbol.getInstantiatedSymbol(), A1 ); - - look = ((IContainerSymbol) symbol).lookup( "x".toCharArray() ); //$NON-NLS-1$ - - assertEquals( look.getType(), ITypeInfo.t_int ); - assertEquals( look.getTypeInfo().checkBit( ITypeInfo.isLong ), false ); - - look = lookC.lookup( "z".toCharArray() ); //$NON-NLS-1$ - assertEquals( look.getType(), ITypeInfo.t_type ); - symbol = look.getTypeSymbol(); - assertTrue( symbol instanceof IContainerSymbol ); - assertTrue( symbol.isTemplateInstance() ); - assertEquals( symbol.getInstantiatedSymbol(), A2 ); - look = ((IContainerSymbol)symbol).lookup( "x".toCharArray() ); //$NON-NLS-1$ - - assertEquals( look.getType(), ITypeInfo.t_int ); - assertEquals( look.getTypeInfo().checkBit( ITypeInfo.isLong ), true ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T1, class T2 > struct A { - * T1 f1(); - * void f2(); - * }; - * - * template U A< U, V >::f1() {} //ok - * - * template void A< Y, X >::f2() {} //error - * - * - * @throws Exception - */ - public void test_14_5_1__3_MemberFunctions() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY ); - ISymbol primaryT1 = table.newSymbol( "T1".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol primaryT2 = table.newSymbol( "T2".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( primaryT1 ); - template.addTemplateParameter( primaryT2 ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - - factory.addSymbol( A ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f1".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - - ISymbol look = A.lookup( "T1".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, primaryT1 ); - - f1.setIsForwardDeclaration( true ); - f1.setReturnType( look ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f2".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.setIsForwardDeclaration( true ); - - A.addSymbol( f1 ); - A.addSymbol( f2 ); - - ITemplateSymbol temp = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY ); - ISymbol U = table.newSymbol( "U".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol V = table.newSymbol( "V".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - temp.addTemplateParameter( U ); - temp.addTemplateParameter( V ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - ISymbol returnType = factory.lookup( "U".toCharArray() ); //$NON-NLS-1$ - assertEquals( returnType, U ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, U ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, V ) ); - - look = factory.lookupTemplateIdForDefinition( "A".toCharArray(), args ); //$NON-NLS-1$ - assertEquals( look, A ); - factory.pushTemplateId( look, args ); - - IParameterizedSymbol lookF = factory.lookupMethodForDefinition( "f1".toCharArray(), new ArrayList() ); //$NON-NLS-1$ - assertEquals( lookF, f1 ); - assertTrue( lookF.isForwardDeclaration() ); - - IParameterizedSymbol defnd = table.newParameterizedSymbol( "f1".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.setForwardSymbol( defnd ); - defnd.setReturnType( returnType ); - factory.addSymbol( defnd ); - - //Test that the adding was all good by doing a lookup - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - - IDerivableContainerSymbol lookA = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( lookA.isTemplateInstance() ); - assertEquals( lookA.getInstantiatedSymbol(), A ); - - List params = new ArrayList(); - look = lookA.qualifiedFunctionLookup( "f1".toCharArray(), params ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), defnd ); - assertTrue( ((IParameterizedSymbol)look).getReturnType().isType( ITypeInfo.t_int ) ); - - params.clear(); - args.clear(); - - temp = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY ); - ISymbol X = table.newSymbol( "X".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol Y = table.newSymbol( "Y".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - temp.addTemplateParameter( X ); - temp.addTemplateParameter( Y ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, Y ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, X ) ); - - try{ - look = factory.lookupTemplateIdForDefinition( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplate ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template struct A{ - * class B; - * }; - * template< class U > class A::B { U i; }; - * A::B b; - * - * @throws Exception - */ - public void test_14_5_1_2_MemberClass() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol primaryT = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( primaryT ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( A ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - B.setIsForwardDeclaration( true ); - A.addSymbol( B ); - - ISymbol U = table.newSymbol( "U".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ITemplateSymbol temp = table.newTemplateSymbol( "".toCharArray() ); //$NON-NLS-1$ - temp.addTemplateParameter( U ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, U ) ); - - IContainerSymbol lookA = factory.lookupTemplateIdForDefinition( "A".toCharArray(), args ); //$NON-NLS-1$ - assertEquals( lookA, A ); - factory.pushTemplateId( lookA, args ); - - ISymbol look = lookA.lookupMemberForDefinition( "B".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, B ); - - IDerivableContainerSymbol newB = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - look.setForwardSymbol( newB ); - - factory.addSymbol( newB ); - - ISymbol i = table.newSymbol( "i".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - look = newB.lookup( "U".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, U ); - i.setTypeSymbol( U ); - newB.addSymbol( i ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A ); - - assertTrue( look instanceof IDerivableContainerSymbol ); - lookA = (IDerivableContainerSymbol) look; - look = lookA.qualifiedLookup( "B".toCharArray() ); //$NON-NLS-1$ - - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), newB ); - - look = ((IDerivableContainerSymbol) look).lookup( "i".toCharArray() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), i ); - assertEquals( look.getType(), ITypeInfo.t_int ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T> class X{ - * static T s; - * }; - * - * template U X::s = 0; - * - * @throws Exception - */ - public void test_14_5_1_3_StaticDataMember() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X".toCharArray() ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( X ); - - ISymbol look = X.lookup( "T".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, T ); - - ISymbol s = table.newSymbol( "s".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - s.setTypeSymbol( look ); - s.getTypeInfo().setBit( true, ITypeInfo.isStatic ); - s.setIsForwardDeclaration( true ); - X.addSymbol( s ); - - ITemplateSymbol temp = table.newTemplateSymbol( "".toCharArray() ); //$NON-NLS-1$ - ISymbol paramU = table.newSymbol( "U".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - temp.addTemplateParameter( paramU ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, paramU ) ); - - look = factory.lookupTemplateIdForDefinition( "X".toCharArray(), args ); //$NON-NLS-1$ - assertEquals( look, X ); - factory.pushTemplateId( X, args ); - - look = ((IContainerSymbol)look).lookupMemberForDefinition("s".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, s ); - assertTrue( look.isForwardDeclaration() ); - - ISymbol newS = table.newSymbol( "s".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - newS.setTypeSymbol( paramU ); - - look.setForwardSymbol( newS ); - - factory.addSymbol( newS ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_float, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "X".toCharArray(), args ); //$NON-NLS-1$ - - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), X ); - - look = ((IContainerSymbol)look).qualifiedLookup( "s".toCharArray() ); //$NON-NLS-1$ - - assertTrue( look.isType( ITypeInfo.t_float ) ); - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), newS ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > class string{ - * template< class T2 > T2 compare( const T2 & ); - * }; - * - * template< class U > template< class V > V string::compare( const V & ) { - * U u; - * } - * @throws Exception - */ - public void test_14_5_2__1_MemberTemplates() throws Exception{ - newTable(); - - ITemplateSymbol template1 = table.newTemplateSymbol( "string".toCharArray() ); //$NON-NLS-1$ - template1.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template1 ); - - IDerivableContainerSymbol string = table.newDerivableContainerSymbol( "string".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( string ); - - ITemplateSymbol template2 = table.newTemplateSymbol( "compare".toCharArray() ); //$NON-NLS-1$ - ISymbol T2 = table.newSymbol( "T2".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template2.addTemplateParameter( T2 ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( string ); - factory.pushTemplate( template2 ); - - IParameterizedSymbol compare = table.newParameterizedSymbol( "compare".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - compare.setIsForwardDeclaration( true ); - compare.addParameter( T2, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, true, false ), false ); - ISymbol returnType = table.newSymbol( "".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - returnType.setTypeSymbol( T2 ); - compare.setReturnType( returnType ); - factory.addSymbol( compare ); - - ITemplateSymbol temp = table.newTemplateSymbol( "".toCharArray() ); //$NON-NLS-1$ - ISymbol U = table.newSymbol( "U".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - temp.addTemplateParameter( U ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - ITemplateSymbol temp2 = table.newTemplateSymbol( "".toCharArray() ); //$NON-NLS-1$ - ISymbol V = table.newSymbol( "V".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - temp2.addTemplateParameter( V ); - - factory.pushTemplate( temp2 ); - - ISymbol lookV = factory.lookup( "V".toCharArray() ); //$NON-NLS-1$ - assertEquals( lookV, V ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, U ) ); - - ISymbol look = factory.lookupTemplateIdForDefinition( "string".toCharArray(), args ); //$NON-NLS-1$ - assertEquals( look, string ); - factory.pushTemplateId( look, args ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, lookV, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, true, false ), false ) ); - - look = ((IContainerSymbol)look).lookupMethodForDefinition( "compare".toCharArray(), args ); //$NON-NLS-1$ - assertEquals( look, compare ); - - IParameterizedSymbol compareDef = table.newParameterizedSymbol( "compare".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - compareDef.addParameter( lookV, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, true, false ), false ); - ISymbol defReturn = table.newSymbol( "".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - defReturn.setTypeSymbol( lookV ); - compareDef.setReturnType( defReturn ); - compare.setForwardSymbol( compareDef ); - factory.addSymbol( compareDef ); - - look = compareDef.lookup( "U".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, U ); - - ISymbol u = table.newSymbol( "u".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - u.setTypeSymbol( look ); - - compareDef.addSymbol( u ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "string".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), string ); - - look = ((IDerivableContainerSymbol)look).lookupTemplateId( "compare".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertTrue( look.getInstantiatedSymbol().isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol().getInstantiatedSymbol(), compareDef ); - - assertTrue( ((IParameterizedSymbol)look).getReturnType().isType( ITypeInfo.t_int ) ); - - look = ((IContainerSymbol)look).lookup( "u".toCharArray() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertTrue( look.getInstantiatedSymbol().isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol().getInstantiatedSymbol(), u ); - assertTrue( look.isType( ITypeInfo.t_int ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * A member function template shall not be virtual - * - * template< class T > struct A { - * template < class C > virtual void g( C ); //error - * virtual void f(); //ok - * }; - * @throws Exception - */ - public void test_14_5_2__3_VirtualMemberFunctionTemplate() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A".toCharArray() ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( A ); - - ITemplateSymbol memberTemplate = table.newTemplateSymbol( "g".toCharArray() ); //$NON-NLS-1$ - ISymbol C = table.newSymbol( "C".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - memberTemplate.addTemplateParameter( C ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( A ); - factory.pushTemplate( memberTemplate ); - - IParameterizedSymbol g = table.newParameterizedSymbol( "g".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - g.addParameter( C, 0, null, false ); - g.getTypeInfo().setBit( true, ITypeInfo.isVirtual ); - - try{ - factory.addSymbol( memberTemplate ); - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplate ); - } - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f.getTypeInfo().setBit( true, ITypeInfo.isVirtual ); - - A.addSymbol( f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * Partial specialization declarations are not found by name lookup, Rather, when the primary - * template name is used, any previously declared partial template specializations of the - * primary template are also considered. - * One consequence is that a using-declaration which refers to a class template does not restrict - * the set of partial specializations which may be found through the using-declaration. - * - * namespace N{ - * template< class T1, class T2 > class A {}; - * } - * - * using N::A; - * - * namespace N{ - * template< class T> class A < T, T * > {}; - * } - * - * A< int, int * > a; //uses partial specialization - * - * @throws Exception - */ - public void test_14_5_4__7_PartialSpecializationLookup() throws Exception{ - //TODO - newTable(); - - IContainerSymbol N = table.newContainerSymbol( "N".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - - table.getCompilationUnit().addSymbol( N ); - - ITemplateSymbol template = table.newTemplateSymbol( "A".toCharArray() ); //$NON-NLS-1$ - - template.addTemplateParameter( table.newSymbol( "T1".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "T2".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - IDerivableContainerSymbol A1 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - - template.addSymbol( A1 ); - - N.addSymbol( template ); - - table.getCompilationUnit().addUsingDeclaration( "A".toCharArray(), N ); //$NON-NLS-1$ - - ISpecializedSymbol spec = table.newSpecializedSymbol( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - spec.addTemplateParameter( T ); - spec.addArgument( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T ) ); - spec.addArgument( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - - IDerivableContainerSymbol A2 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - spec.addSymbol( A2 ); - template.addSpecialization( spec ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - - ISymbol look = table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look != null ); - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * template < class T1, class T2, int I > class A {} //#1 - * template < class T, int I > class A < T, T*, I > {} //#2 - * template < class T1, class T2, int I > class A < T1*, T2, I > {} //#3 - * template < class T > class A < int, T*, 5 > {} //#4 - * template < class T1, class T2, int I > class A < T1, T2*, I > {} //#5 - * - * A a1; //uses #1 - * A a2; //uses #2, T is int, I is 1 - * A a3; //uses #4, T is char - * A a4; //uses #5, T is int, T2 is char, I is1 - * A a5; //ambiguous, matches #3 & #5. - * - * @throws Exception - */ - public void test_14_5_4_1__2_MatchingTemplateSpecializations() throws Exception{ - //TODO - newTable(); - - IDerivableContainerSymbol cls1 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol cls2 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol cls3 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol cls4 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol cls5 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - - ITemplateSymbol template1 = table.newTemplateSymbol( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol T1p1 = table.newSymbol( "T1".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T1p2 = table.newSymbol( "T2".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T1p3 = table.newSymbol( "I".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - T1p3.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - - template1.addTemplateParameter( T1p1 ); - template1.addTemplateParameter( T1p2 ); - template1.addTemplateParameter( T1p3 ); - template1.addSymbol( cls1 ); - table.getCompilationUnit().addSymbol( template1 ); - - ISpecializedSymbol template2 = table.newSpecializedSymbol( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol T2p1 = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T2p2 = table.newSymbol( "I".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - T2p2.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - - template2.addTemplateParameter( T2p1 ); - template2.addTemplateParameter( T2p2 ); - - ITypeInfo T2a1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T2p1 ); - ITypeInfo T2a2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T2p1, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - ITypeInfo T2a3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T2p2 ); - - template2.addArgument( T2a1 ); - template2.addArgument( T2a2 ); - template2.addArgument( T2a3 ); - template2.addSymbol( cls2 ); - template1.addSpecialization( template2 ); - - ISpecializedSymbol template3 = table.newSpecializedSymbol( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol T3p1 = table.newSymbol( "T1".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T3p2 = table.newSymbol( "T2".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T3p3 = table.newSymbol( "I".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - T3p3.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - - template3.addTemplateParameter( T3p1 ); - template3.addTemplateParameter( T3p2 ); - template3.addTemplateParameter( T3p3 ); - - ITypeInfo T3a1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T3p1, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - ITypeInfo T3a2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T3p2 ); - ITypeInfo T3a3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T3p3 ); - - template3.addArgument( T3a1 ); - template3.addArgument( T3a2 ); - template3.addArgument( T3a3 ); - template3.addSymbol( cls3 ); - template1.addSpecialization( template3 ); - - ISpecializedSymbol template4 = table.newSpecializedSymbol( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol T4p1 = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template4.addTemplateParameter( T4p1 ); - - ITypeInfo T4a1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ); - ITypeInfo T4a2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T4p1, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - ITypeInfo T4a3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "5".toCharArray() ); //$NON-NLS-1$ - - template4.addArgument( T4a1 ); - template4.addArgument( T4a2 ); - template4.addArgument( T4a3 ); - template4.addSymbol( cls4 ); - template1.addSpecialization( template4 ); - - ISpecializedSymbol template5 = table.newSpecializedSymbol( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol T5p1 = table.newSymbol( "T1".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T5p2 = table.newSymbol( "T2".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T5p3 = table.newSymbol( "I".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - T5p3.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - - template5.addTemplateParameter( T5p1 ); - template5.addTemplateParameter( T5p2 ); - template5.addTemplateParameter( T5p3 ); - - ITypeInfo T5a1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T5p1 ); - ITypeInfo T5a2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T5p2, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - ITypeInfo T5a3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T5p3 ); - - template5.addArgument( T5a1 ); - template5.addArgument( T5a2 ); - template5.addArgument( T5a3 ); - template5.addSymbol( cls5 ); - template1.addSpecialization( template5 ); - - ITemplateSymbol a = (ITemplateSymbol) table.getCompilationUnit().lookup( "A".toCharArray() ); //$NON-NLS-1$ - assertEquals( a, template1 ); - - ArrayList args = new ArrayList(); - - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "1".toCharArray() ) ); //$NON-NLS-1$ - - IContainerSymbol a1 = (IContainerSymbol) a.instantiate( args ); - assertTrue( a1.isTemplateInstance() ); - assertEquals( a1.getInstantiatedSymbol(), cls1 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "1".toCharArray() ) ); //$NON-NLS-1$ - - IContainerSymbol a2 = (IContainerSymbol) a.instantiate( args ); - assertTrue( a2.isTemplateInstance() ); - assertEquals( a2.getInstantiatedSymbol(), cls2 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "5".toCharArray() ) ); //$NON-NLS-1$ - IContainerSymbol a3 = (IContainerSymbol) a.instantiate( args ); - assertTrue( a3.isTemplateInstance() ); - assertEquals( a3.getInstantiatedSymbol(), cls4 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "1".toCharArray() ) ); //$NON-NLS-1$ - IContainerSymbol a4 = (IContainerSymbol) a.instantiate( args ); - assertTrue( a4.isTemplateInstance() ); - assertEquals( a4.getInstantiatedSymbol(), cls5 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, null, "2".toCharArray() ) ); //$NON-NLS-1$ - - try{ - a.instantiate( args ); - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > void f( T ); //#1 - * template< class T > void f( T* ); //#2 - * template< class T > void f( const T* ); //#3 - * - * const int *p; - * f( p ); //calls f( const T * ) , 3 is more specialized than 1 or 2 - * - * @throws Exception - * - */ - public void test_14_5_5_2__5_OrderingFunctionTemplates_1() throws Exception{ - newTable(); - - ITemplateSymbol template1 = table.newTemplateSymbol( "f".toCharArray() ); //$NON-NLS-1$ - template1.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template1 ); - - ISymbol T = template1.lookup( "T".toCharArray() ); //$NON-NLS-1$ - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( T, 0, null, false ); - factory.addSymbol( f1 ); - - ITemplateSymbol template2 = table.newTemplateSymbol( "f".toCharArray() ); //$NON-NLS-1$ - template2.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template2 ); - - T = template2.lookup( "T".toCharArray() ); //$NON-NLS-1$ - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( T, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - factory.addSymbol( f2 ); - - ITemplateSymbol template3 = table.newTemplateSymbol( "f".toCharArray() ); //$NON-NLS-1$ - template3.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template3 ); - - T = template3.lookup( "T".toCharArray() ); //$NON-NLS-1$ - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f3.addParameter( T, ITypeInfo.isConst, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ), false ); - factory.addSymbol( f3 ); - - ISymbol p = table.newSymbol( "p".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - p.getTypeInfo().setBit( true, ITypeInfo.isConst ); - p.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) ); - table.getCompilationUnit().addSymbol( p ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, p ) ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f3 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > void g( T ); //#1 - * template< class T > void g( T& ); //#2 - - * float x; - * g( x ); //ambiguous 1 or 2 - * - * @throws Exception - */ - public void test_14_5_5_2__5_OrderingFunctionTemplates_2() throws Exception{ - newTable(); - - ITemplateSymbol template1 = table.newTemplateSymbol( "g".toCharArray() ); //$NON-NLS-1$ - template1.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template1 ); - - ISymbol T = template1.lookup( "T".toCharArray() ); //$NON-NLS-1$ - IParameterizedSymbol g1 = table.newParameterizedSymbol( "g".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - g1.addParameter( T, 0, null, false ); - factory.addSymbol( g1 ); - - ITemplateSymbol template2 = table.newTemplateSymbol( "g".toCharArray() ); //$NON-NLS-1$ - template2.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template2 ); - - T = template2.lookup( "T".toCharArray() ); //$NON-NLS-1$ - IParameterizedSymbol g2 = table.newParameterizedSymbol( "g".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - g2.addParameter( T, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - factory.addSymbol( g2 ); - - ISymbol x = table.newSymbol( "x".toCharArray(), ITypeInfo.t_float ); //$NON-NLS-1$ - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, x ) ); - try{ - table.getCompilationUnit().unqualifiedFunctionLookup( "g".toCharArray(), params ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > struct A { }; - * - * template< class T > void h( const T & ); //#1 - * template< class T > void h( A& ); //#2 - * - * A z; - * h( z ); //calls 2 - * - * const A z2; - * h( z2 ); //calls 1 because 2 is not callable. - * @throws Exception - */ - public void test_14_5_5_2__5_OrderingFunctionTemplates_3() throws Exception{ - newTable(); - - ITemplateSymbol templateA = table.newTemplateSymbol( "A".toCharArray() ); //$NON-NLS-1$ - templateA.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateA ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( A ); - - ITemplateSymbol template1 = table.newTemplateSymbol( "h".toCharArray() ); //$NON-NLS-1$ - template1.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template1 ); - - ISymbol T = template1.lookup( "T".toCharArray() ); //$NON-NLS-1$ - IParameterizedSymbol h1 = table.newParameterizedSymbol( "h".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - h1.addParameter( T, ITypeInfo.isConst, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, false, false ),false ); - factory.addSymbol( h1 ); - - ITemplateSymbol template2 = table.newTemplateSymbol( "h".toCharArray() ); //$NON-NLS-1$ - template2.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template2 ); - - T = template2.lookup( "T".toCharArray() ); //$NON-NLS-1$ - - IParameterizedSymbol h2 = table.newParameterizedSymbol( "h".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - List argList = new ArrayList(); - argList.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T ) ); - h2.addParameter( templateA.instantiate( argList ), 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - factory.addSymbol( h2 ); - - ISymbol z = table.newSymbol( "z".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - ISymbol look = table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A ); - z.setTypeSymbol( look ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, z ) ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "h".toCharArray(), params ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), h2 ); - - ISymbol z2 = table.newSymbol( "z2".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - look = table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A ); - z2.setTypeSymbol( look ); - z2.getTypeInfo().setBit( true, ITypeInfo.isConst ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, z2 ) ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "h".toCharArray(), params ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), h1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * Within the scope of a class template, when the name of the template is neither qualified - * nor followed by <, it is equivalent to the name of the template followed by the template-parameters - * enclosed in <>. - * - * template < class T > class X { - * X* p; //meaning X< T > - * }; - * - * @throws Exception - */ - public void test_14_6_1__1_TemplateName() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "X".toCharArray() ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol X = table.newDerivableContainerSymbol( "X".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( X ); - - ISymbol look = X.lookup( "X".toCharArray() ); //$NON-NLS-1$ - - assertTrue( look != null ); - assertTrue( look instanceof IDeferredTemplateInstance ); - IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) look; - assertEquals( deferred.getTemplate(), template ); - - Iterator iter = deferred.getArguments().iterator(); - ITypeInfo type = (ITypeInfo) iter.next(); - assertTrue( type.isType( ITypeInfo.t_type ) ); - assertEquals( type.getTypeSymbol(), T ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * Within the scope of a class template specialization or partial specialization, when the name of the - * template is neither qualified nor followed by <, it is equivalent to the name of the template - * followed by the template-arguments enclosed in <> - * - * template< class T > class Y; - * - * template<> class Y< int > { - * Y* p; //meaning Y - * } - * @throws Exception - */ - public void test_14_6_1__2_SpecializationName() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "Y".toCharArray() ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - IDerivableContainerSymbol Y1 = table.newDerivableContainerSymbol( "Y".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - template.addSymbol( Y1 ); - - table.getCompilationUnit().addSymbol( template ); - - ISpecializedSymbol spec = table.newSpecializedSymbol( "Y".toCharArray() ); //$NON-NLS-1$ - spec.addArgument( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - template.addSpecialization( spec ); - - IDerivableContainerSymbol Y2 = table.newDerivableContainerSymbol( "Y".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - spec.addSymbol( Y2 ); - - ISymbol look = Y2.lookup( "Y".toCharArray() ); //$NON-NLS-1$ - assertTrue( look != null ); - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), Y2 ); - - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * A template-parameter shall not be redeclared within its scope. A template-parameter shall - * not have the same name as the template name. - * - * template< class T, int i > class Y { - * int T; //error - * void f(){ - * char T; //error - * } - * }; - * - * template class X {}; //error - * - * @throws Exception - */ - public void test_14_6_1__4_ParameterRedeclaration() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "Y".toCharArray() ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ISymbol i = table.newSymbol( "i".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - i.getTypeInfo().setTemplateParameterType( ITypeInfo.t_int ); - template.addTemplateParameter( i ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol Y = table.newDerivableContainerSymbol( "Y".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( Y ); - - ISymbol T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - try{ - Y.addSymbol( T ); - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_RedeclaredTemplateParam ); - } - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - Y.addSymbol( f ); - - try{ - f.addSymbol( table.newSymbol( "T".toCharArray(), ITypeInfo.t_char ) ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_RedeclaredTemplateParam ); - } - - ITemplateSymbol template2 = table.newTemplateSymbol( "X".toCharArray() ); //$NON-NLS-1$ - try{ - template2.addTemplateParameter( table.newSymbol( "X".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_BadTemplateParameter ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - - /** - * A member of an explicitly specialized class shall be explicitly defined in the same - * manner as members of normal classes - * - * template< class T > struct A { - * void f( T ) {} - * }; - * - * template <> struct A< int >{ - * void f( int ); - * } - * - * void A< int >::f( int ){ } - * - * @throws Exception - */ - public void test_14_7_3__5_ExplicitSpecialization() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( A ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f.addParameter( T, 0, null, false ); - - A.addSymbol( f ); - - ITemplateSymbol temp = table.newTemplateSymbol( "".toCharArray() ); //$NON-NLS-1$ - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - ArrayList args = new ArrayList(); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - ITemplateSymbol templateSpec = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY ); - factory.pushTemplate( templateSpec ); - - IDerivableContainerSymbol ASpec = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - factory.addTemplateId( ASpec, args ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_int, 0, null, false ); - f2.setIsForwardDeclaration( true ); - ASpec.addSymbol( f2 ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f3.addParameter( ITypeInfo.t_int, 0, null, false ); - - IDerivableContainerSymbol look = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), ASpec ); - - ISymbol flook = look.lookupMethodForDefinition( "f".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( flook.isTemplateInstance() ); - assertEquals( flook.getInstantiatedSymbol(), f2 ); - flook.setForwardSymbol( f3 ); - - look.addSymbol( f3 ); - - look = (IDerivableContainerSymbol) table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - flook = look.qualifiedFunctionLookup( "f".toCharArray(), args ); //$NON-NLS-1$ - - assertEquals( flook, f3 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template < class T > class Array { }; - * template < class T > void sort( Array< T > & ); - * - * template<> void sort( Array< int > & ){} //T deduced as int - * - * @throws Exception - */ - public void test_14_7_3__11_ExplicitSpecializationArgumentDeduction() throws Exception{ - newTable(); - - ITemplateSymbol templateArray = table.newTemplateSymbol( "Array".toCharArray() ); //$NON-NLS-1$ - templateArray.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateArray ); - - IDerivableContainerSymbol array = table.newDerivableContainerSymbol( "Array".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( array ); - - ITemplateSymbol templateSort = table.newTemplateSymbol( "sort".toCharArray() ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - templateSort.addTemplateParameter( T ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateSort ); - - IParameterizedSymbol sort = table.newParameterizedSymbol( "sort".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T ) ); - - ISymbol arrayLook = factory.lookupTemplateId( "Array".toCharArray(), args ); //$NON-NLS-1$ - sort.addParameter( arrayLook, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - - factory.addSymbol( sort ); - - ITemplateSymbol temp = table.newTemplateSymbol( "".toCharArray() ); //$NON-NLS-1$ - factory = table.newTemplateFactory(); - - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( temp ); - - IParameterizedSymbol newSort = table.newParameterizedSymbol( "sort".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - arrayLook = table.getCompilationUnit().lookupTemplateId( "Array".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( arrayLook.isTemplateInstance() ); - assertEquals( arrayLook.getInstantiatedSymbol(), array ); - newSort.addParameter( arrayLook, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - - factory.addSymbol( newSort ); - - ISymbol a = table.newSymbol( "a".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( arrayLook ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ) ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "sort".toCharArray(), args ); //$NON-NLS-1$ - - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), newSort ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * It is possible for a specialization with a given function signature to be instantiated from more - * than one function-template. In such cases, explicit specification of the template arguments must be used - * to uniquely identify the function template specialization being specialized - * - * template< class T > void f( T ); - * template< class T > void f( T * ); - * - * template <> void f( int * ); - * template <> void f< int >( int * ); - * template <> void f( char ); - * - * @throws Exception - */ - public void test_14_7_3__12_ExplicitSpecializationOverloadedFunction() throws Exception{ - newTable(); - - ITemplateSymbol template1 = table.newTemplateSymbol( "f".toCharArray() ); //$NON-NLS-1$ - ISymbol T1 = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template1.addTemplateParameter( T1 ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template1 ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( T1, 0, null, false ); - - factory.addSymbol( f1 ); - - ITemplateSymbol template2 = table.newTemplateSymbol( "f".toCharArray() ); //$NON-NLS-1$ - ISymbol T2 = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template2.addTemplateParameter( T2 ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template2 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( T2, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - - factory.addSymbol( f2 ); - - factory = table.newTemplateFactory(); - ITemplateSymbol template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY ); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f3.addParameter( ITypeInfo.t_int, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ) ); - factory.addTemplateId( f3, args ); - - args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY ); - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol f4 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f4.addParameter( ITypeInfo.t_int, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - factory.addTemplateId( f4, args ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - - template = table.newTemplateSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY ); - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol f5 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f5.addParameter( ITypeInfo.t_char, 0, null, false ); - factory.addSymbol( f5 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f5 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - - /** - * template < class T > void f( T x, T y ) { } - * struct A {}; - * struct B : A {}; - * - * A a; - * B b; - * - * f( a, b ); //error, T could be A or B - * f( b, a ); //error, T could be A or B - * f( a, a ); //ok, T is A - * f( b, b ); //ok, T is B - * @throws Exception - */ - public void test_14_8_2_4__5_ArgumentDeduction() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "f".toCharArray() ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - - ISymbol lookT = template.lookup( "T".toCharArray() ); //$NON-NLS-1$ - assertEquals( lookT, T ); - - ISymbol paramX = table.newSymbol( "x".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - paramX.setTypeSymbol( lookT ); - - ISymbol paramY = table.newSymbol( "y".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - paramY.setTypeSymbol( lookT ); - - f.addParameter( paramX ); - f.addParameter( paramY ); - - factory.addSymbol( f ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( A ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - B.addParent( A ); - table.getCompilationUnit().addSymbol( B ); - - ISymbol a = table.newSymbol( "a".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( A ); - - ISymbol b = table.newSymbol( "b".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - b.setTypeSymbol( B ); - - table.getCompilationUnit().addSymbol( a ); - table.getCompilationUnit().addSymbol( b ); - - List argList = new ArrayList(); - ITypeInfo aParam = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ); - ITypeInfo bParam = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, b ); - - argList.add( aParam ); - argList.add( bParam ); - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), argList ); //$NON-NLS-1$ - assertEquals( look, null ); - - argList.clear(); - argList.add( bParam ); - argList.add( aParam ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), argList ); //$NON-NLS-1$ - assertEquals( look, null ); - - argList.clear(); - argList.add( aParam ); - argList.add( aParam ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), argList ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f ); - - argList.clear(); - argList.add( bParam ); - argList.add( bParam ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), argList ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance()); - assertEquals( look.getInstantiatedSymbol(), f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T, class U > void f( T (*)( T, U, U ) ); - * int g1( int, float, float ); - * char g2( int, float, float ); - * int g3( int, char, float ); - * - * f( g1 ); //OK, T is int and U is float - * f( g2 ); //error, T could be char or int - * f( g3 ); //error, U could be char or float - * - * @throws Exception - */ - public void test_14_8_2_4__6_ArgumentDeduction() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "f".toCharArray() ); //$NON-NLS-1$ - - template.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - template.addTemplateParameter( table.newSymbol( "U".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol paramFunction = table.newParameterizedSymbol( "".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - paramFunction.setIsTemplateMember( true ); - - ISymbol T = template.lookup( "T".toCharArray() ); //$NON-NLS-1$ - ISymbol U = template.lookup( "U".toCharArray() ); //$NON-NLS-1$ - - paramFunction.setReturnType( T ); - paramFunction.addParameter( T, 0, null, false ); - paramFunction.addParameter( U, 0, null, false ); - paramFunction.addParameter( U, 0, null, false ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f.addParameter( paramFunction, 0, null, false ); - - factory.addSymbol( f ); - - IParameterizedSymbol g1 = table.newParameterizedSymbol( "g1".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - g1.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_int ) ); //$NON-NLS-1$ - g1.addParameter( ITypeInfo.t_int, 0, null, false ); - g1.addParameter( ITypeInfo.t_float, 0, null, false ); - g1.addParameter( ITypeInfo.t_float, 0, null, false ); - - table.getCompilationUnit().addSymbol( g1 ); - - IParameterizedSymbol g2 = table.newParameterizedSymbol( "g2".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - g2.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_char ) ); //$NON-NLS-1$ - g2.addParameter( ITypeInfo.t_int, 0, null, false ); - g2.addParameter( ITypeInfo.t_float, 0, null, false ); - g2.addParameter( ITypeInfo.t_float, 0, null, false ); - - table.getCompilationUnit().addSymbol( g2); - - IParameterizedSymbol g3 = table.newParameterizedSymbol( "g3".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - g3.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_int ) ); //$NON-NLS-1$ - g3.addParameter( ITypeInfo.t_int, 0, null, false ); - g3.addParameter( ITypeInfo.t_char, 0, null, false ); - g3.addParameter( ITypeInfo.t_float, 0, null, false ); - - table.getCompilationUnit().addSymbol( g3); - - ITypeInfo arg = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, g1 ); - List argList = new ArrayList(); - argList.add( arg ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), argList ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f ); - - arg.setTypeSymbol( g2 ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), argList ); //$NON-NLS-1$ - assertEquals( look, null ); - - arg.setTypeSymbol( g3 ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), argList ); //$NON-NLS-1$ - assertEquals( look, null ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - /** - * template< class T > void f( const T * ){} - * - * int *p; - * - * f( p ); //f ( const int * ) - * - * @throws Exception - */ - public void test_14_8_2_4__7_ArgumentDeduction() throws Exception{ - newTable(); - - ITemplateSymbol template = table.newTemplateSymbol( "f".toCharArray() ); //$NON-NLS-1$ - ISymbol T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f.addParameter( T, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, true, false ), false ); - factory.addSymbol( f ); - - ISymbol p = table.newSymbol( "p".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - p.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, p ) ); - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - - assertTrue( look != null ); - assertTrue( look.isTemplateInstance() ); - - assertEquals( look.getInstantiatedSymbol(), f ); - - IParameterizedSymbol fn = (IParameterizedSymbol) look; - Iterator iter = fn.getParameterList().iterator(); - ISymbol param = (ISymbol) iter.next(); - assertTrue( param.isType( ITypeInfo.t_int ) ); - - assertFalse( iter.hasNext() ); - - iter = param.getTypeInfo().getPtrOperators().iterator(); - ITypeInfo.PtrOp op = (ITypeInfo.PtrOp) iter.next(); - assertTrue( op.isConst() ); - assertEquals( op.getType(), ITypeInfo.PtrOp.t_pointer ); - assertFalse( iter.hasNext() ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * template< class T > struct B {}; - * - * template< class T > struct D : public B< T > {}; - * - * struct D2 : public B< int > {}; - * - * template< class T > void f( B & ) {} - * - * D d; - * D2 d2; - * - * f( d ); //f( B & ) - * f( d2 ); //f( B & ) - * @throws Exception - */ - public void test_14_8_2_4__8_ArgumentDeduction() throws Exception{ - newTable(); - - ITemplateSymbol templateB = table.newTemplateSymbol( "B".toCharArray() ); //$NON-NLS-1$ - templateB.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateB ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( B ); - - ITemplateSymbol templateD = table.newTemplateSymbol( "D".toCharArray() ); //$NON-NLS-1$ - templateD.addTemplateParameter( table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ) ); //$NON-NLS-1$ - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templateD ); - - IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - factory.addSymbol( D ); - - ISymbol T = templateD.lookup( "T".toCharArray() ); //$NON-NLS-1$ - List args = new ArrayList (); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T ) ); - ISymbol look = table.getCompilationUnit().lookupTemplateId( "B".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look instanceof IDeferredTemplateInstance ); - assertEquals( ((IDeferredTemplateInstance)look).getTemplate(), templateB ); - - D.addParent( look ); - - IDerivableContainerSymbol D2 = table.newDerivableContainerSymbol( "D2".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - look = table.getCompilationUnit().lookupTemplateId( "B".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), B ); - - D2.addParent( look ); - - table.getCompilationUnit().addSymbol( D2 ); - - ITemplateSymbol templatef = table.newTemplateSymbol( "f".toCharArray() ); //$NON-NLS-1$ - T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - templatef.addTemplateParameter( T ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( templatef ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, T ) ); - - look = table.getCompilationUnit().lookupTemplateId( "B".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look instanceof IDeferredTemplateInstance ); - assertEquals( ((IDeferredTemplateInstance)look).getTemplate(), templateB ); - - ISymbol param = table.newSymbol( "".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - param.setTypeSymbol( look ); - param.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ) ); - f.addParameter( param ); - - factory.addSymbol( f ); - - ISymbol d = table.newSymbol( "d".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - look = table.getCompilationUnit().lookupTemplateId( "D".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), D ); - - d.setTypeSymbol( look ); - table.getCompilationUnit().addSymbol( d ); - - ISymbol d2 = table.newSymbol( "d2".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - d2.setTypeSymbol( D2 ); - table.getCompilationUnit().addSymbol( d2 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, d ) ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look != null ); - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, d2 ) ); - ISymbol look2 = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look2 != null ); - assertTrue( look2.isTemplateInstance() ); - assertEquals( look2.getInstantiatedSymbol(), f ); - - //both are the template function instantiated with int, should be the same instance. - assertEquals( look, look2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - - - - /** - * template < class T1, class T2 > class A { void f(); }; //#1 - * - * template < class T > class A < T, T > { void f(); }; //#2 - * template < class T > class A < char, T > { void f(); }; //#3 - * - * template < class U, class V > void A::f(){ - * int c; - * } - * - * template < class W > void A < W, W >::f(){ - * char c; - * } - * - * template < class X > void A< char, X >::f(){ - * float c; - * } - * - * A< int, char > a1; //#1 - * a1.f(); //#1 - * - * A< int, int > a2; //#2 - * a2.f(); //#2 - * - * A< char, int > a3; //#3 - * a3.f(); //#3 - * - * @throws Exception - */ - public void testPartialSpecializationDefinitions() throws Exception{ - newTable(); - - //template < class T1, class T2 > class A { void f(); }; - ITemplateSymbol template = table.newTemplateSymbol( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol T1 = table.newSymbol( "T1".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol T2 = table.newSymbol( "T2".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - template.addTemplateParameter( T1 ); - template.addTemplateParameter( T2 ); - - ITemplateFactory factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( template ); - - IDerivableContainerSymbol A1 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addSymbol( A1 ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.setIsForwardDeclaration( true ); - A1.addSymbol( f1 ); - - //template < class T > class A < T, T > { void f(); }; - ITemplateSymbol spec1 = table.newTemplateSymbol("".toCharArray()); //$NON-NLS-1$ - ISymbol spec1_T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - spec1.addTemplateParameter( spec1_T ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( spec1 ); - - List args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, spec1_T ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, spec1_T ) ); - - IDerivableContainerSymbol A2 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addTemplateId( A2, args ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.setIsForwardDeclaration( true ); - A2.addSymbol( f2 ); - - //template < class T > class A < char, T > { void f(); }; - ITemplateSymbol spec2 = table.newTemplateSymbol("".toCharArray()); //$NON-NLS-1$ - ISymbol spec2_T = table.newSymbol( "T".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - spec2.addTemplateParameter( spec2_T ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( spec2 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, spec2_T ) ); - - IDerivableContainerSymbol A3 = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - factory.addTemplateId( A3, args ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f3.setIsForwardDeclaration( true ); - A3.addSymbol( f3 ); - - //template < class U, class V > void A::f(){ int c; } - ITemplateSymbol templateDef = table.newTemplateSymbol("".toCharArray()); //$NON-NLS-1$ - ISymbol U = table.newSymbol( "U".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - ISymbol V = table.newSymbol( "V".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - templateDef.addTemplateParameter( U ); - templateDef.addTemplateParameter( V ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( spec2 ); - - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, U ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, V ) ); - - ISymbol symbol = factory.lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertEquals( ((IDeferredTemplateInstance)symbol).getTemplate(), template ); - factory.pushTemplateId( symbol, args ); - - ISymbol look = factory.lookupMethodForDefinition( "f".toCharArray(), new ArrayList() ); //$NON-NLS-1$ - assertEquals( look, f1 ); - IParameterizedSymbol f1Def = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.setForwardSymbol( f1Def ); - factory.addSymbol( f1Def ); - - ISymbol c1 = table.newSymbol( "c".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - f1Def.addSymbol( c1 ); - - //template < class W > void A < W, W >::f(){ char c; } - ITemplateSymbol specDef1 = table.newTemplateSymbol("".toCharArray()); //$NON-NLS-1$ - ISymbol W = table.newSymbol( "W".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - specDef1.addTemplateParameter( W ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( specDef1 ); - - args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, W ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, W ) ); - - symbol = factory.lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - factory.pushTemplateId( symbol, args ); - - look = factory.lookupMethodForDefinition( "f".toCharArray(), new ArrayList() ); //$NON-NLS-1$ - assertEquals( look, f2 ); - IParameterizedSymbol f2Def = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.setForwardSymbol( f2Def ); - factory.addSymbol( f2Def ); - - ISymbol c2 = table.newSymbol( "c".toCharArray(), ITypeInfo.t_char ); //$NON-NLS-1$ - f2Def.addSymbol( c2 ); - - //template < class X > void < char, X >::f(){ float c; } - ITemplateSymbol specDef2 = table.newTemplateSymbol("".toCharArray()); //$NON-NLS-1$ - ISymbol X = table.newSymbol( "X".toCharArray(), ITypeInfo.t_templateParameter ); //$NON-NLS-1$ - specDef2.addTemplateParameter( X ); - - factory = table.newTemplateFactory(); - factory.setContainingSymbol( table.getCompilationUnit() ); - factory.pushTemplate( specDef1 ); - - args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, X ) ); - - symbol = factory.lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - factory.pushTemplateId( symbol, args ); - - look = factory.lookupMethodForDefinition( "f".toCharArray(), new ArrayList() ); //$NON-NLS-1$ - assertEquals( look, f3 ); - IParameterizedSymbol f3Def = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f3.setForwardSymbol( f3Def ); - factory.addSymbol( f3Def ); - - ISymbol c3 = table.newSymbol( "c".toCharArray(), ITypeInfo.t_float ); //$NON-NLS-1$ - f3Def.addSymbol( c3 ); - - //A< int, char > a1; - args = new ArrayList(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A1 ); - - look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f".toCharArray(), new ArrayList() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f1Def ); - - look = ((IContainerSymbol)look).qualifiedLookup( "c".toCharArray() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), c1 ); - assertTrue( look.isType( ITypeInfo.t_int ) ); - - //A< int, int > a2; - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A2 ); - - look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f".toCharArray(), new ArrayList() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f2Def ); - - look = ((IContainerSymbol)look).qualifiedLookup( "c".toCharArray() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), c2 ); - assertTrue( look.isType( ITypeInfo.t_char ) ); - - //A< char, int > a3; - args.clear(); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ) ); - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - look = table.getCompilationUnit().lookupTemplateId( "A".toCharArray(), args ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), A3 ); - - look = ((IContainerSymbol)look).qualifiedFunctionLookup( "f".toCharArray(), new ArrayList() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), f3Def ); - - look = ((IContainerSymbol)look).qualifiedLookup( "c".toCharArray() ); //$NON-NLS-1$ - assertTrue( look.isTemplateInstance() ); - assertEquals( look.getInstantiatedSymbol(), c3 ); - assertTrue( look.isType( ITypeInfo.t_float ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java deleted file mode 100644 index fe382fed698..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java +++ /dev/null @@ -1,3520 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.core.parser.tests; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; -import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind; -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTClassSpecifier; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTCompilationUnit; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTField; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.pst.IUsingDeclarationSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IUsingDirectiveSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; -import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension; -import org.eclipse.cdt.internal.core.parser.pst.TypeFilter; -import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider; - - - - -/** - * @author aniefer - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class ParserSymbolTableTest extends TestCase { - - private static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); - public ParserSymbolTable table = null; - public TypeInfoProvider provider = null; - - public ParserSymbolTableTest( String arg ) - { - super( arg ); - } - - public ParserSymbolTable newTable(){ - return newTable( ParserLanguage.CPP, ParserMode.COMPLETE_PARSE ); - } - - public ParserSymbolTable newTable( ParserLanguage language, ParserMode mode ){ - table = new ParserSymbolTable( language, mode ); - provider = table.getTypeInfoProvider(); - return table; - } - /** - * testSimpleAdd. - * Add a declaration to the table and confirm it is there. - * - * @throws Exception - */ - public void testSimpleAdd() throws Exception{ - newTable(); //create the symbol table - - ISymbol x = table.newSymbol( "x".toCharArray() ); //$NON-NLS-1$ - x.setTypeInfo( TypeInfoProvider.newTypeInfo() ); - IContainerSymbol compUnit = table.getCompilationUnit(); - compUnit.addSymbol( x ); - - CharArrayObjectMap declarations = compUnit.getContainedSymbols(); - assertEquals( 1, declarations.size() ); - - ISymbol contained = (ISymbol) declarations.getAt( 0 ); - - assertEquals( declarations.size(), 1 ); - assertEquals( x, contained ); - assertTrue( CharArrayUtils.equals(contained.getName(), "x".toCharArray()) ); //$NON-NLS-1$ - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testSimpleLookup - * Add a declaration to the table, then look it up. - * @throws Exception - */ - public void testSimpleLookup() throws Exception{ - newTable(); //new symbol table - - ISymbol x = table.newSymbol( "x".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( x ); - - ISymbol look = table.getCompilationUnit().lookup( "x".toCharArray() ); //$NON-NLS-1$ - - assertEquals( x, look ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - public void testLookupNonExistant() throws Exception{ - newTable(); - - ISymbol look = table.getCompilationUnit().lookup("boo".toCharArray()); //$NON-NLS-1$ - assertEquals( look, null ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - public void testSimpleSetGetObject() throws Exception{ - newTable(); - - IContainerSymbol x = table.newContainerSymbol( "x".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - - ISymbolASTExtension extension = new StandardSymbolExtension(x,null); - - x.setASTExtension( extension ); - - table.getCompilationUnit().addSymbol( x ); - - ISymbol look = table.getCompilationUnit().lookup( "x".toCharArray() ); //$NON-NLS-1$ - - assertEquals( look.getASTExtension(), extension ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testHide - * test that a declaration in a scope hides declarations in containing - * scopes - * @throws Exception - */ - public void testHide() throws Exception{ - newTable(); - - ISymbol firstX = table.newSymbol("x".toCharArray()); //$NON-NLS-1$ - firstX.setTypeInfo( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - table.getCompilationUnit().addSymbol( firstX ); - - IDerivableContainerSymbol firstClass = table.newDerivableContainerSymbol("class".toCharArray()); //$NON-NLS-1$ - firstClass.setType( ITypeInfo.t_class ); - table.getCompilationUnit().addSymbol( firstClass ); - - ISymbol look = firstClass.lookup( "x".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, firstX ); - - ISymbol secondX = table.newSymbol("x".toCharArray()); //$NON-NLS-1$ - firstClass.addSymbol( secondX ); - - look = firstClass.lookup( "x".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, secondX ); - - look = table.getCompilationUnit().lookup( "x".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, firstX ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testContainingScopeLookup - * test lookup of something declared in the containing scope - * @throws Exception - */ - public void testContainingScopeLookup() throws Exception{ - newTable(); - - ISymbol x = table.newSymbol("x".toCharArray()); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( x ); - - IDerivableContainerSymbol decl = table.newDerivableContainerSymbol("class".toCharArray()); //$NON-NLS-1$ - decl.setType( ITypeInfo.t_class ); - table.getCompilationUnit().addSymbol( decl ); - - ISymbol look = decl.lookup( "x".toCharArray() ); //$NON-NLS-1$ - - assertEquals( x, look ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testParentLookup - * test lookup of a variable declaration in the parent - * - * @throws Exception - */ - public void testParentLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol parent = table.newDerivableContainerSymbol("parent".toCharArray()); //$NON-NLS-1$ - parent.setType( ITypeInfo.t_class ); - - IDerivableContainerSymbol class1 = table.newDerivableContainerSymbol("class".toCharArray()); //$NON-NLS-1$ - class1.setType( ITypeInfo.t_class ); - class1.addParent( parent ); - - ISymbol decl = table.newSymbol( "x".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - parent.addSymbol( decl ); - - table.getCompilationUnit().addSymbol( parent ); - table.getCompilationUnit().addSymbol( class1 ); - - ISymbol look = class1.lookup( "x".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, decl ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testAmbiguousParentLookup - * calls testParentLookup - * - * tests that if a variable is declared in two parents that the lookup - * returns an ambiguous result. - * - * @throws Exception - */ - public void testAmbiguousParentLookup() throws Exception{ - testParentLookup(); - - IDerivableContainerSymbol parent2 = table.newDerivableContainerSymbol("parent2".toCharArray()); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( parent2 ); - - IDerivableContainerSymbol class1 = (IDerivableContainerSymbol) table.getCompilationUnit().lookup( "class".toCharArray() ); //$NON-NLS-1$ - class1.addParent( parent2 ); - - ISymbol decl = table.newSymbol( "x".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - parent2.addSymbol( decl ); - - try{ - class1.lookup( "x".toCharArray() ); //$NON-NLS-1$ - assertTrue( false ); - } - catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * test for circular inheritance - */ - public void testCircularParentLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol a = table.newDerivableContainerSymbol("a".toCharArray()); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( a ); - - IDerivableContainerSymbol b = table.newDerivableContainerSymbol("b".toCharArray()); //$NON-NLS-1$ - b.addParent( a ); - table.getCompilationUnit().addSymbol( b ); - - a.addParent( b ); - - try{ - a.lookup("foo".toCharArray()); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e) { - assertEquals( e.reason, ParserSymbolTableException.r_CircularInheritance ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - /** - * testVirtualParentLookup - * - * @throws Exception - * tests lookup of name in virtual baseclass C - * - * C - * / \ - * A B - * \ / - * class - */ - public void testVirtualParentLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol decl = table.newDerivableContainerSymbol("class".toCharArray()); //$NON-NLS-1$ - IDerivableContainerSymbol c = table.newDerivableContainerSymbol("C".toCharArray()); //$NON-NLS-1$ - - IDerivableContainerSymbol a = table.newDerivableContainerSymbol("A".toCharArray()); //$NON-NLS-1$ - a.addParent( c, true, ASTAccessVisibility.PUBLIC, 3, null ); - - IDerivableContainerSymbol b = table.newDerivableContainerSymbol("B".toCharArray()); //$NON-NLS-1$ - b.addParent( c, true, ASTAccessVisibility.PUBLIC, 6, null ); - - decl.addParent( a ); - decl.addParent( b ); - - IContainerSymbol compUnit = table.getCompilationUnit(); - compUnit.addSymbol( c ); - - ISymbol x = table.newSymbol( "x".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - c.addSymbol( x ); - - compUnit.addSymbol( decl ); - compUnit.addSymbol( a ); - compUnit.addSymbol( b ); - - ISymbol look = decl.lookup( "x".toCharArray() ); //$NON-NLS-1$ - - assertEquals( look, x ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testAmbiguousVirtualParentLookup - * @throws Exception - * - * tests lookup of name in base class C in the following hierarchy - * C C - * / \ | - * A B D - * \ / / - * class - */ - public void testAmbiguousVirtualParentLookup() throws Exception{ - testVirtualParentLookup(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol cls = (IDerivableContainerSymbol) compUnit.lookup("class".toCharArray()); //$NON-NLS-1$ - IDerivableContainerSymbol c = (IDerivableContainerSymbol) compUnit.lookup("C".toCharArray()); //$NON-NLS-1$ - IDerivableContainerSymbol d = table.newDerivableContainerSymbol("D".toCharArray()); //$NON-NLS-1$ - - d.addParent( c ); - cls.addParent( d ); - - compUnit.addSymbol( d ); - - try{ - cls.lookup( "x".toCharArray() ); //$NON-NLS-1$ - assertTrue( false ); - } - catch( ParserSymbolTableException e){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testStaticEnumParentLookup - * - * @throws Exception - * - * D D - * | | - * B C - * \ / - * A - * - * Things defined in D are not ambiguous if they are static or an enum - */ - public void testStaticEnumParentLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol a = table.newDerivableContainerSymbol("a".toCharArray() ); //$NON-NLS-1$ - IDerivableContainerSymbol b = table.newDerivableContainerSymbol( "b".toCharArray() ); //$NON-NLS-1$ - IDerivableContainerSymbol c = table.newDerivableContainerSymbol( "c".toCharArray() ); //$NON-NLS-1$ - IDerivableContainerSymbol d = table.newDerivableContainerSymbol( "d".toCharArray() ); //$NON-NLS-1$ - - IContainerSymbol compUnit = table.getCompilationUnit(); - - compUnit.addSymbol( a ); - compUnit.addSymbol( b ); - compUnit.addSymbol( c ); - compUnit.addSymbol( d ); - - IContainerSymbol enum1 = table.newContainerSymbol( "enum".toCharArray(), ITypeInfo.t_enumeration ); //$NON-NLS-1$ - - ISymbol enumerator = table.newSymbol( "enumerator".toCharArray(), ITypeInfo.t_enumerator ); //$NON-NLS-1$ - - ISymbol stat = table.newSymbol( "static".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - stat.getTypeInfo().setBit( true, ITypeInfo.isStatic ); - - ISymbol x = table.newSymbol( "x".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - - d.addSymbol( enum1 ); - d.addSymbol( stat ); - d.addSymbol( x ); - - enum1.addSymbol( enumerator ); - - a.addParent( b ); - a.addParent( c ); - b.addParent( d ); - c.addParent( d ); - - try{ - a.lookup( "enumerator".toCharArray() ); //$NON-NLS-1$ - assertTrue( true ); - } - catch ( ParserSymbolTableException e){ - assertTrue( false ); - } - - try{ - a.lookup( "static".toCharArray() ); //$NON-NLS-1$ - assertTrue( true ); - } - catch ( ParserSymbolTableException e){ - assertTrue( false ); - } - - try{ - a.lookup( "x".toCharArray() ); //$NON-NLS-1$ - assertTrue( false ); - } - catch ( ParserSymbolTableException e){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testElaboratedLookup - * @throws Exception - * test lookup of hidden names using elaborated type spec - */ - public void testElaboratedLookup() throws Exception{ - newTable(); - - IDerivableContainerSymbol cls = table.newDerivableContainerSymbol( "class".toCharArray() ); //$NON-NLS-1$ - cls.setType( ITypeInfo.t_class ); - - IDerivableContainerSymbol struct = table.newDerivableContainerSymbol("struct".toCharArray()); //$NON-NLS-1$ - struct.setType( ITypeInfo.t_struct ); - - IContainerSymbol union = table.newContainerSymbol("union".toCharArray()); //$NON-NLS-1$ - union.setType( ITypeInfo.t_union ); - - IDerivableContainerSymbol hideCls = table.newDerivableContainerSymbol( "class".toCharArray() ); //$NON-NLS-1$ - hideCls.setType( ITypeInfo.t_int ); - IDerivableContainerSymbol hideStruct = table.newDerivableContainerSymbol("struct".toCharArray()); //$NON-NLS-1$ - hideStruct.setType( ITypeInfo.t_int ); - IContainerSymbol hideUnion = table.newContainerSymbol("union".toCharArray()); //$NON-NLS-1$ - hideUnion.setType( ITypeInfo.t_int ); - - IDerivableContainerSymbol a = table.newDerivableContainerSymbol("a".toCharArray()); //$NON-NLS-1$ - IDerivableContainerSymbol b = table.newDerivableContainerSymbol("b".toCharArray()); //$NON-NLS-1$ - - a.addSymbol(hideCls); - a.addSymbol(hideStruct); - a.addSymbol(hideUnion); - - a.addParent( b ); - - b.addSymbol(cls); - b.addSymbol(struct); - b.addSymbol(union); - - table.getCompilationUnit().addSymbol( a ); - table.getCompilationUnit().addSymbol( b ); - - ISymbol look = a.elaboratedLookup( ITypeInfo.t_class, "class".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, cls ); - look = a.elaboratedLookup( ITypeInfo.t_struct, "struct".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, struct ); - look = a.elaboratedLookup( ITypeInfo.t_union, "union".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, union ); - - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testDeclarationType - * @throws Exception - * test the use of ParserSymbolTable.Declaration type in the scenario - * A a; - * a.member <=...>; - * where A was previously declared - */ - public void testDeclarationType() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - //pre-condition - IContainerSymbol A = table.newContainerSymbol("A".toCharArray()); //$NON-NLS-1$ - compUnit.addSymbol(A); - - ISymbol member = table.newSymbol("member".toCharArray()); //$NON-NLS-1$ - A.addSymbol(member); - - //at time of "A a;" - ISymbol look = compUnit.lookup("A".toCharArray()); //$NON-NLS-1$ - assertEquals( look, A ); - ISymbol a = table.newSymbol("a".toCharArray()); //$NON-NLS-1$ - a.setTypeSymbol( look ); - compUnit.addSymbol( a ); - - //later "a.member" - look = compUnit.lookup("a".toCharArray()); //$NON-NLS-1$ - assertEquals( look, a ); - IContainerSymbol type = (IContainerSymbol) look.getTypeSymbol(); - assertEquals( type, A ); - - look = type.lookup("member".toCharArray()); //$NON-NLS-1$ - assertEquals( look, member ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * struct stat { - * //... - * } - * int stat( struct stat* ); - * void f() - * { - * struct stat *ps; - * stat(ps); - * } - */ - public void testFunctionHidesClass() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol struct = table.newDerivableContainerSymbol("stat".toCharArray()); //$NON-NLS-1$ - struct.setType( ITypeInfo.t_struct ); - compUnit.addSymbol( struct ); - - IParameterizedSymbol function = table.newParameterizedSymbol( "stat".toCharArray() ); //$NON-NLS-1$ - function.setType( ITypeInfo.t_function ); - compUnit.addSymbol( function ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f".toCharArray()); //$NON-NLS-1$ - f.setType( ITypeInfo.t_function ); - compUnit.addSymbol( f ); - - ISymbol look = f.elaboratedLookup( ITypeInfo.t_struct, "stat".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, struct ); - - look = f.lookup( "stat".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, function ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * namespace A { - * int i; - * namespace B { - * namespace C{ - * int i; - * } - * using namespace A::B::C; - * void f1() { - * i = 5; //OK, C::i visible and hides A::i - * } - * } - * namespace D{ - * using namespace B; - * using namespace C; - * void f2(){ - * i = 5; //ambiguous, B::C and A::i - * } - * } - * void f3() { - * i = 5; //uses A::i - * } - * } - * void f4(){ - * i = 5; //no i is visible here - * } - * - */ - public void testUsingDirectives_1() throws Exception{ - newTable(); - - IContainerSymbol nsA = table.newContainerSymbol("A".toCharArray()); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - table.getCompilationUnit().addSymbol( nsA ); - - ISymbol nsA_i = table.newSymbol("i".toCharArray()); //$NON-NLS-1$ - nsA.addSymbol( nsA_i ); - - IContainerSymbol nsB = table.newContainerSymbol("B".toCharArray()); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - nsA.addSymbol( nsB ); - - IContainerSymbol nsC = table.newContainerSymbol("C".toCharArray()); //$NON-NLS-1$ - nsC.setType( ITypeInfo.t_namespace ); - nsB.addSymbol( nsC ); - - ISymbol nsC_i = table.newSymbol("i".toCharArray()); //$NON-NLS-1$ - nsC.addSymbol( nsC_i ); - - ISymbol look = nsB.lookup("C".toCharArray()); //$NON-NLS-1$ - assertEquals( look, nsC ); - nsB.addUsingDirective( nsC ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol("f".toCharArray()); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - - nsB.addSymbol( f1 ); - - look = f1.lookup( "i".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, nsC_i ); //C::i visible and hides A::i - - IContainerSymbol nsD = table.newContainerSymbol("D".toCharArray()); //$NON-NLS-1$ - nsD.setType( ITypeInfo.t_namespace ); - nsA.addSymbol( nsD ); - - look = nsD.lookup("B".toCharArray()); //$NON-NLS-1$ - assertEquals( look, nsB ); - nsD.addUsingDirective( nsB ); - - look = nsD.lookup("C".toCharArray()); //$NON-NLS-1$ - assertEquals( look, nsC ); - nsD.addUsingDirective( nsC ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f2".toCharArray() ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - nsD.addSymbol( f2 ); - - try - { - look = f2.lookup( "i".toCharArray() ); //$NON-NLS-1$ - assertTrue( false ); - } - catch ( ParserSymbolTableException e ) - { - //ambiguous B::C::i and A::i - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - - IParameterizedSymbol f3 = table.newParameterizedSymbol("f3".toCharArray()); //$NON-NLS-1$ - f3.setType( ITypeInfo.t_function ); - nsA.addSymbol( f3 ); - - look = f3.lookup("i".toCharArray()); //$NON-NLS-1$ - assertEquals( look, nsA_i ); //uses A::i - - IParameterizedSymbol f4 = table.newParameterizedSymbol("f4".toCharArray()); //$NON-NLS-1$ - f4.setType( ITypeInfo.t_function ); - table.getCompilationUnit().addSymbol( f4 ); - - look = f4.lookup("i".toCharArray()); //$NON-NLS-1$ - assertEquals( look, null );//neither i is visible here. - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - /** - * - * @throws Exception - * - * namespace M { - * int i; - * } - * namespace N { - * int i; - * using namespace M; - * } - * - * void f() { - * using namespace N; - * i = 7; //error, both M::i and N::i are visible - * N::i = 5; //ok, i directly declared in N, using M not - * considered (since this is a qualified lookup) - * } - * - */ - public void testTransitiveUsingDirective() throws Exception - { - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsM = table.newContainerSymbol( "M".toCharArray() ); //$NON-NLS-1$ - nsM.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( nsM ); - - ISymbol nsM_i = table.newSymbol("i".toCharArray()); //$NON-NLS-1$ - nsM.addSymbol( nsM_i ); - - IContainerSymbol nsN = table.newContainerSymbol( "N".toCharArray() ); //$NON-NLS-1$ - nsN.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( nsN ); - - ISymbol nsN_i = table.newSymbol("i".toCharArray()); //$NON-NLS-1$ - nsN.addSymbol( nsN_i ); - nsN.addUsingDirective( nsM ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f".toCharArray()); //$NON-NLS-1$ - compUnit.addSymbol( f ); - - f.addUsingDirective( nsN ); - - ISymbol look = null; - try - { - look = f.lookup( "i".toCharArray() ); //$NON-NLS-1$ - assertTrue( false ); - } - catch ( ParserSymbolTableException e ) - { - //ambiguous, both M::i and N::i are visible. - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - - look = f.lookupNestedNameSpecifier("N".toCharArray()); //$NON-NLS-1$ - assertEquals( look, nsN ); - - look = ((IContainerSymbol) look).qualifiedLookup("i".toCharArray()); //ok //$NON-NLS-1$ - assertEquals( look, nsN_i ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * The same declaration found more than once is not an ambiguity - * namespace A{ - * int a; - * } - * namespace B{ - * using namespace A; - * } - * namespace C{ - * using namespace A; - * } - * - * namespace BC{ - * using namespace B; - * using namespace C; - * } - * - * void f(){ - * BC::a++; //ok - * } - */ - public void testUsing_SameDeclarationTwice() throws Exception - { - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsA = table.newContainerSymbol("A".toCharArray()); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsA ); - - ISymbol a = table.newSymbol("a".toCharArray()); //$NON-NLS-1$ - nsA.addSymbol( a ); - - IContainerSymbol nsB = table.newContainerSymbol("B".toCharArray()); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsB ); - nsB.addUsingDirective( nsA ); - - IContainerSymbol nsC = table.newContainerSymbol("C".toCharArray()); //$NON-NLS-1$ - nsC.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsC ); - nsC.addUsingDirective( nsA ); - - IContainerSymbol nsBC = table.newContainerSymbol("BC".toCharArray()); //$NON-NLS-1$ - nsBC.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsBC ); - nsBC.addUsingDirective( nsB ); - nsBC.addUsingDirective( nsC ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f".toCharArray()); //$NON-NLS-1$ - f.setType(ITypeInfo.t_function); - compUnit.addSymbol( f ); - - ISymbol look = f.lookupNestedNameSpecifier("BC".toCharArray()); //$NON-NLS-1$ - assertEquals( look, nsBC ); - look = ((IContainerSymbol)look).qualifiedLookup("a".toCharArray()); //$NON-NLS-1$ - assertEquals( look, a ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * namespace B { - * int b; - * } - * namespace A { - * using namespace B; - * int a; - * } - * namespace B { - * using namespace A; - * } - * - * void f(){ - * A::a++; //ok - * A::b++; //ok - * B::a++; //ok - * B::b++; //ok - * } - */ - public void testUsing_SearchedOnce() throws Exception - { - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsB = table.newContainerSymbol( "B".toCharArray() ); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsB ); - - ISymbol b = table.newSymbol("b".toCharArray()); //$NON-NLS-1$ - nsB.addSymbol( b ); - - IContainerSymbol nsA = table.newContainerSymbol( "A".toCharArray() ); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsA ); - - nsA.addUsingDirective( nsB ); - - ISymbol a = table.newSymbol("a".toCharArray()); //$NON-NLS-1$ - nsA.addSymbol( a ); - - nsB.addUsingDirective( nsA ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f".toCharArray()); //$NON-NLS-1$ - compUnit.addSymbol(f); - - ISymbol lookA = f.lookupNestedNameSpecifier("A".toCharArray()); //$NON-NLS-1$ - assertEquals( lookA, nsA ); - assertTrue( lookA instanceof IContainerSymbol); - - ISymbol look = ((IContainerSymbol) lookA).qualifiedLookup("a".toCharArray()); //$NON-NLS-1$ - assertEquals( look, a ); - - look = ((IContainerSymbol) lookA).qualifiedLookup("b".toCharArray()); //$NON-NLS-1$ - assertEquals( look, b ); - - ISymbol lookB = f.lookupNestedNameSpecifier("B".toCharArray()); //$NON-NLS-1$ - assertTrue( lookB instanceof IContainerSymbol); - look = ((IContainerSymbol) lookB).qualifiedLookup("a".toCharArray()); //$NON-NLS-1$ - assertEquals( look, a ); - - look = ((IContainerSymbol) lookB).qualifiedLookup("b".toCharArray()); //$NON-NLS-1$ - assertEquals( look, b ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * we pass if we don't go into an infinite loop. - * TBD: we need a mechanism to detect failure of this - * test instead of just looping forever. - * - * @throws Exception - * - * namespace A{ - * } - * namespace B{ - * using namespace A; - * } - * namespace A{ - * using namespace B; - * } - * void f(){ - * using namespace A; - * using namespace B; - * i = 1; //not declared anywhere. - * } - */ - public void testUsing_SearchedOnce_2() throws Exception - { - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsA = table.newContainerSymbol( "A".toCharArray() ); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsA ); - - IContainerSymbol nsB = table.newContainerSymbol( "B".toCharArray() ); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsB ); - nsB.addUsingDirective( nsA ); - - nsA.addUsingDirective( nsB ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f".toCharArray()); //$NON-NLS-1$ - compUnit.addSymbol(f); - f.addUsingDirective(nsA); - f.addUsingDirective(nsB); - - ISymbol look = f.lookup("i".toCharArray()); //$NON-NLS-1$ - assertEquals( look, null ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * During lookup of a qualified namespace member name, if the lookup finds - * more than one declaration of the member, non-type names hide class or - * enumeration names if and only if the declarations are from the same - * namespace - * @throws Exception - * - * namespace A { - * struct x { }; - * int x; - * int y; - * } - * namespace B { - * struct y { }; - * } - * - * namespace C { - * using namespace A; - * using namespace B; - * - * int i = C::x; //ok, finds A::x - * int j = C::y; //ambiguous, A::y or B::y - * } - */ - public void testNamespaceMemberHiding() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsA = table.newContainerSymbol("A".toCharArray()); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( nsA ); - - IContainerSymbol structX = table.newContainerSymbol("x".toCharArray()); //$NON-NLS-1$ - structX.setType( ITypeInfo.t_struct ); - nsA.addSymbol( structX ); - - ISymbol intX = table.newSymbol("x".toCharArray()); //$NON-NLS-1$ - intX.setType( ITypeInfo.t_int ); - nsA.addSymbol( intX ); - - ISymbol intY = table.newSymbol("y".toCharArray()); //$NON-NLS-1$ - intY.setType( ITypeInfo.t_int ); - nsA.addSymbol( intY ); - - IContainerSymbol nsB = table.newContainerSymbol("B".toCharArray()); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( nsB ); - IContainerSymbol structY = table.newContainerSymbol("y".toCharArray()); //$NON-NLS-1$ - structY.setType( ITypeInfo.t_struct ); - nsB.addSymbol( structY ); - - IContainerSymbol nsC = table.newContainerSymbol("C".toCharArray()); //$NON-NLS-1$ - nsC.setType( ITypeInfo.t_namespace); - compUnit.addSymbol( nsC ); - - ISymbol look = nsC.lookup("A".toCharArray()); //$NON-NLS-1$ - assertEquals( look, nsA ); - nsC.addUsingDirective( nsA ); - - look = nsC.lookup("B".toCharArray()); //$NON-NLS-1$ - assertEquals( look, nsB ); - nsC.addUsingDirective( nsB ); - - //lookup C::x - look = nsC.lookupNestedNameSpecifier("C".toCharArray()); //$NON-NLS-1$ - assertEquals( look, nsC ); - look = ((IContainerSymbol)look).qualifiedLookup( "x".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, intX ); - - //lookup C::y - look = nsC.lookupNestedNameSpecifier("C".toCharArray()); //$NON-NLS-1$ - assertEquals( look, nsC ); - - try{ - look = ((IContainerSymbol)look).qualifiedLookup( "y".toCharArray() ); //$NON-NLS-1$ - assertTrue(false); - } catch ( ParserSymbolTableException e ) { - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * In a definition for a namespace member in which the declarator-id is a - * qualified-id, given that the qualified-id for the namespace member has - * the form "nested-name-specifier unqualified-id".toCharArray(), the unqualified-id shall - * name a member of the namespace designated by the nested-name-specifier. - * - * namespace A{ - * namespace B{ - * void f1(int); - * } - * using namespace B; - * } - * void A::f1(int) { ... } //ill-formed, f1 is not a member of A - */ - public void testLookupMemberForDefinition() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol nsA = table.newContainerSymbol( "A".toCharArray() ); //$NON-NLS-1$ - nsA.setType( ITypeInfo.t_namespace ); - compUnit.addSymbol( nsA ); - - IContainerSymbol nsB = table.newContainerSymbol( "B".toCharArray() ); //$NON-NLS-1$ - nsB.setType( ITypeInfo.t_namespace ); - nsA.addSymbol( nsB ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol("f1".toCharArray()); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - nsB.addSymbol( f1 ); - - nsA.addUsingDirective( nsB ); - - ISymbol lookA = compUnit.lookupNestedNameSpecifier( "A".toCharArray() ); //$NON-NLS-1$ - assertEquals( nsA, lookA ); - assertTrue( lookA instanceof IContainerSymbol); - - ISymbol look = ((IContainerSymbol) lookA).lookupMemberForDefinition( "f1".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, null ); - - //but notice if you wanted to do A::f1 as a function call, it is ok - look = ((IContainerSymbol) lookA).qualifiedLookup( "f1".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, f1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testUsingDeclaration - * @throws Exception - * 7.3.3-4 A using-declaration used as a member-declaration shall refer to a - * member of a base-class of the class being defined, shall refer to a - * member of an anonymous union that is a member of a base class of the - * class being defined or shall refer to an enumerator for an enumeration - * type that is a member of a base class of the class being defined - * - * struct B { - * void f( char ); - * enum E { e }; - * union { int x; }; - * }; - * class C { - * int g(); - * } - * struct D : B { - * using B::f; //ok, B is a base class of D - * using B::e; //ok, e is an enumerator in base class B - * using B::x; //ok, x is an union member of base class B - * using C::g; //error, C isn't a base class of D - * } - */ - public void testUsingDeclaration() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B".toCharArray()); //$NON-NLS-1$ - B.setType( ITypeInfo.t_struct ); - compUnit.addSymbol( B ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f".toCharArray()); //$NON-NLS-1$ - f.setType( ITypeInfo.t_function ); - B.addSymbol( f ); - - IContainerSymbol E = table.newContainerSymbol( "E".toCharArray() ); //$NON-NLS-1$ - E.setType( ITypeInfo.t_enumeration ); - B.addSymbol( E ); - - ISymbol e = table.newSymbol( "e".toCharArray() ); //$NON-NLS-1$ - e.setType( ITypeInfo.t_enumerator ); - E.addSymbol( e ); - - /** - * TBD: Anonymous unions are not yet implemented - */ - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C".toCharArray() ); //$NON-NLS-1$ - C.setType( ITypeInfo.t_class ); - compUnit.addSymbol( C ); - - IParameterizedSymbol g = table.newParameterizedSymbol( "g".toCharArray() ); //$NON-NLS-1$ - g.setType( ITypeInfo.t_function ); - C.addSymbol( g ); - - IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D".toCharArray() ); //$NON-NLS-1$ - D.setType( ITypeInfo.t_struct ); - ISymbol look = compUnit.lookup( "B".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, B ); - D.addParent( B ); - - compUnit.addSymbol( D ); - - ISymbol lookB = D.lookupNestedNameSpecifier("B".toCharArray()); //$NON-NLS-1$ - assertEquals( lookB, B ); - assertTrue( lookB instanceof IContainerSymbol); - - D.addUsingDeclaration( "f".toCharArray(), (IContainerSymbol)lookB ); //$NON-NLS-1$ - D.addUsingDeclaration( "e".toCharArray(), (IContainerSymbol)lookB ); //$NON-NLS-1$ - - //TBD anonymous union - //D.addUsingDeclaration( "x".toCharArray(), lookB ); - - look = D.lookupNestedNameSpecifier("C".toCharArray()); //$NON-NLS-1$ - assertEquals( look, C ); - - try{ - D.addUsingDeclaration( "g".toCharArray(), C ); //$NON-NLS-1$ - assertTrue( false ); - } - catch ( ParserSymbolTableException exception ){ - assertTrue( true ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testUsingDeclaration_2 - * @throws Exception - * 7.3.3-9 The entity declared by a using-declaration shall be known in the - * context using it according to its definition at the point of the using- - * declaration. Definitions added to the namespace after the using- - * declaration are not considered when a use of the name is made. - * - * namespace A { - * void f(int); - * } - * using A::f; - * - * namespace A { - * void f(char); - * } - * void foo(){ - * f('a'); //calls f( int ) - * } - * void bar(){ - * using A::f; - * f('a'); //calls f( char ); - * } - */ - public void testUsingDeclaration_2() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol A = table.newContainerSymbol( "A".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - compUnit.addSymbol( A ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_void ) ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - A.addSymbol( f1 ); - - ISymbol look = compUnit.lookupNestedNameSpecifier("A".toCharArray()); //$NON-NLS-1$ - assertEquals( look, A ); - - IUsingDeclarationSymbol using = compUnit.addUsingDeclaration( "f".toCharArray(), A ); //$NON-NLS-1$ - assertEquals( using.getReferencedSymbols().size(), 1 ); - - assertEquals( using.getReferencedSymbols().get(0), f1 ); - - IParameterizedSymbol usingF = (IParameterizedSymbol)using.getReferencedSymbols().get(0); - - look = compUnit.lookup("A".toCharArray()); //$NON-NLS-1$ - assertEquals( look, A ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol("f".toCharArray()); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_void ) ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_char, 0, null, false ); - - A.addSymbol( f2 ); - - IParameterizedSymbol foo = table.newParameterizedSymbol("foo".toCharArray()); //$NON-NLS-1$ - foo.setType( ITypeInfo.t_function ); - compUnit.addSymbol( foo ); - - ArrayList paramList = new ArrayList(); - ITypeInfo param = TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ); - paramList.add( param ); - - look = foo.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, usingF ); - assertTrue( usingF.hasSameParameters( f1 ) ); - - IParameterizedSymbol bar = table.newParameterizedSymbol( "bar".toCharArray() ); //$NON-NLS-1$ - bar.setType( ITypeInfo.t_function ); - bar.addParameter( ITypeInfo.t_char, 0, null, false ); - compUnit.addSymbol( bar ); - - look = bar.lookupNestedNameSpecifier( "A".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, A ); - - using = bar.addUsingDeclaration( "f".toCharArray(), A ); //$NON-NLS-1$ - - List list = using.getReferencedSymbols(); - assertTrue( list.contains( f1 ) ); - assertTrue( list.contains( f2 ) ); - assertEquals( list.size(), 2 ); - - look = bar.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertTrue( look != null ); - assertEquals( look, f2); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testThisPointer - * @throws Exception - * In the body of a nonstatic member function... the type of this of a class - * X is X*. If the member function is declared const, the type of this is - * const X*, if the member function is declared volatile, the type of this - * is volatile X*.... - */ - public void testThisPointer() throws Exception{ - newTable(); - - IDerivableContainerSymbol cls = table.newDerivableContainerSymbol( "class".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - - IParameterizedSymbol fn = table.newParameterizedSymbol("function".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - fn.setType( ITypeInfo.t_function ); - fn.getTypeInfo().setBit( true, ITypeInfo.isConst ); - - table.getCompilationUnit().addSymbol( cls ); - cls.addSymbol( fn ); - - ISymbol look = fn.lookup("this".toCharArray()); //$NON-NLS-1$ - assertTrue( look != null ); - - assertEquals( look.getType(), ITypeInfo.t_type ); - assertEquals( look.getTypeSymbol(), cls ); - assertTrue( look.getTypeInfo().checkBit( ITypeInfo.isConst ) ); - assertEquals( ((ITypeInfo.PtrOp)look.getPtrOperators().iterator().next()).getType(), ITypeInfo.PtrOp.t_pointer ); - - assertEquals( look.getContainingSymbol(), fn ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testEnumerator - * @throws Exception - * Following the closing brace of an enum-specifier, each enumerator has the - * type of its enumeration. - * The enum-name and each enumerator declared by an enum-specifier is - * declared in the scope that immediately contains the enum-specifier - */ - public void testEnumerator() throws Exception{ - newTable(); - - IContainerSymbol cls = table.newContainerSymbol("class".toCharArray()); //$NON-NLS-1$ - cls.setType( ITypeInfo.t_class ); - - IContainerSymbol enumeration = table.newContainerSymbol("enumeration".toCharArray()); //$NON-NLS-1$ - enumeration.setType( ITypeInfo.t_enumeration ); - - table.getCompilationUnit().addSymbol( cls ); - cls.addSymbol( enumeration ); - - ISymbol enumerator = table.newSymbol( "enumerator".toCharArray() ); //$NON-NLS-1$ - enumerator.setType( ITypeInfo.t_enumerator ); - enumeration.addSymbol( enumerator ); - - ISymbol look = cls.lookup( "enumerator".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, enumerator ); - assertEquals( look.getContainingSymbol(), cls ); - assertEquals( look.getTypeSymbol(), enumeration ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * namespace NS{ - * class T {}; - * void f( T ); - * } - * NS::T parm; - * int main(){ - * f( parm ); //ok, calls NS::f - * } - */ - public void testArgumentDependentLookup() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol NS = table.newContainerSymbol("NS".toCharArray()); //$NON-NLS-1$ - NS.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( NS ); - - IDerivableContainerSymbol T = table.newDerivableContainerSymbol("T".toCharArray()); //$NON-NLS-1$ - T.setType( ITypeInfo.t_class ); - - NS.addSymbol( T ); - - IParameterizedSymbol f = table.newParameterizedSymbol("f".toCharArray()); //$NON-NLS-1$ - f.setType( ITypeInfo.t_function ); - f.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_void ) ); //$NON-NLS-1$ - - ISymbol look = NS.lookup( "T".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, T ); - f.addParameter( look, 0, null, false ); - - NS.addSymbol( f ); - - look = compUnit.lookupNestedNameSpecifier( "NS".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, NS ); - look = NS.qualifiedLookup( "T".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, T ); - - ISymbol param = table.newSymbol("parm".toCharArray()); //$NON-NLS-1$ - param.setType( ITypeInfo.t_type ); - param.setTypeSymbol( look ); - compUnit.addSymbol( param ); - - IParameterizedSymbol main = table.newParameterizedSymbol("main".toCharArray()); //$NON-NLS-1$ - main.setType( ITypeInfo.t_function ); - main.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_int ) ); //$NON-NLS-1$ - compUnit.addSymbol( main ); - - ArrayList paramList = new ArrayList(); - look = main.lookup( "parm".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, param ); - ITypeInfo p = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, look ); - paramList.add( p ); - - look = main.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testArgumentDependentLookup_2 - * @throws Exception - * in the following, NS2 is an associated namespace of class B which is an - * associated namespace of class A, so we should find f in NS2, we should - * not find f in NS1 because usings are ignored for associated scopes. - * - * - * namespace NS1{ - * void f( void * ){}; - * } - * namespace NS2{ - * using namespace NS1; - * class B {}; - * void f( void * ){}; - * } - * - * class A : public NS2::B {}; - * - * A a; - * f( &a ); - * - */ - public void testArgumentDependentLookup_2() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IContainerSymbol NS1 = table.newContainerSymbol( "NS1".toCharArray() ); //$NON-NLS-1$ - NS1.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( NS1 ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_void ) ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_void, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - NS1.addSymbol( f1 ); - - IContainerSymbol NS2 = table.newContainerSymbol( "NS2".toCharArray() ); //$NON-NLS-1$ - NS2.setType( ITypeInfo.t_namespace ); - - compUnit.addSymbol( NS2 ); - - ISymbol look = NS2.lookup( "NS1".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, NS1 ); - NS2.addUsingDirective( NS1 ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray() ); //$NON-NLS-1$ - B.setType( ITypeInfo.t_class ); - NS2.addSymbol( B ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray() ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_void ) ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_void, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - NS2.addSymbol( f2 ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray() ); //$NON-NLS-1$ - A.setType( ITypeInfo.t_class ); - look = compUnit.lookupNestedNameSpecifier( "NS2".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, NS2 ); - - look = NS2.qualifiedLookup( "B".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, B ); - A.addParent( B ); - - compUnit.addSymbol( A ); - - look = compUnit.lookup( "A".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, A ); - ISymbol a = table.newSymbol( "a".toCharArray() ); //$NON-NLS-1$ - a.setType( ITypeInfo.t_type ); - a.setTypeSymbol( look ); - compUnit.addSymbol( a ); - - ArrayList paramList = new ArrayList(); - look = compUnit.lookup( "a".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, a ); - ITypeInfo param = TypeInfoProvider.newTypeInfo( look.getType(), 0, look, null, false ); - //new PtrOp( PtrOp.t_reference ) - param.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - paramList.add( param ); - - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * testFunctionOverloading - * @throws Exception - * Note that this test has been contrived to not strain the resolution as - * that aspect is not yet complete. - * - * class C - * { - * void foo( int i ); - * void foo( int i, char c ); - * void foo( int i, char c, C * ptr ); - * } - * - * C * c = new C; - * c->foo( 1 ); - * c->foo( 1, 'a' ); - * c->foo( 1, 'a', c ); - * - */ - - public void testFunctionOverloading() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C".toCharArray() ); //$NON-NLS-1$ - C.setType( ITypeInfo.t_class ); - compUnit.addSymbol(C); - - IParameterizedSymbol f1 = table.newParameterizedSymbol("foo".toCharArray()); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_void ) ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - C.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol("foo".toCharArray()); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_void ) ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_int, 0, null, false ); - f2.addParameter( ITypeInfo.t_char, 0, null, false ); - C.addSymbol( f2 ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol("foo".toCharArray()); //$NON-NLS-1$ - f3.setType( ITypeInfo.t_function ); - f3.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_void ) ); //$NON-NLS-1$ - f3.addParameter( ITypeInfo.t_int, 0, null, false ); - f3.addParameter( ITypeInfo.t_char, 0, null, false ); - f3.addParameter( C, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - C.addSymbol( f3 ); - - ISymbol look = compUnit.lookup("C".toCharArray()); //$NON-NLS-1$ - assertEquals( look, C ); - - ISymbol c = table.newSymbol("c".toCharArray()); //$NON-NLS-1$ - c.setType( ITypeInfo.t_type ); - c.setTypeSymbol( look ); - c.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) ); - compUnit.addSymbol( c ); - - look = compUnit.lookup( "c".toCharArray() ); //$NON-NLS-1$ - assertEquals( look, c ); - assertEquals( look.getTypeSymbol(), C ); - - ArrayList paramList = new ArrayList(); - - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ); - ITypeInfo p2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ); - ITypeInfo p3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, c ); - - paramList.add( p1 ); - look = C.memberFunctionLookup( "foo".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - paramList.add( p2 ); - look = C.memberFunctionLookup( "foo".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - paramList.add( p3 ); - look = C.memberFunctionLookup( "foo".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f3 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * test basic function resolution - * - * void f( int i ); - * void f( char c = 'c' ); - * - * f( 1 ); //calls f( int ); - * f( 'b' ); //calls f( char ); - * f(); //calls f( char ); - */ - public void testFunctionResolution() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IParameterizedSymbol f1 = table.newParameterizedSymbol("f".toCharArray()); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - compUnit.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol("f".toCharArray()); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.addParameter( ITypeInfo.t_char, 0, null, true ); - compUnit.addSymbol( f2 ); - - ArrayList paramList = new ArrayList(); - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ); - paramList.add( p1 ); - - ISymbol look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - paramList.clear(); - ITypeInfo p2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ); - paramList.add( p2 ); - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - paramList.clear(); - ITypeInfo p3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_bool, 0, null ); - paramList.add( p3 ); - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), null ); //$NON-NLS-1$ - assertEquals( look, f2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * class A { }; - * class B : public A {}; - * class C : public B {}; - * - * void f ( A * ); - * void f ( B * ); - * - * A* a = new A(); - * C* c = new C(); - * - * f( a ); //calls f( A * ); - * f( c ); //calls f( B * ); - */ - public void testFunctionResolution_PointersAndBaseClasses() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray() ); //$NON-NLS-1$ - A.setType( ITypeInfo.t_class ); - compUnit.addSymbol( A ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray() ); //$NON-NLS-1$ - B.setType( ITypeInfo.t_class ); - B.addParent( A ); - compUnit.addSymbol( B ); - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C".toCharArray() ); //$NON-NLS-1$ - C.setType( ITypeInfo.t_class ); - C.addParent( B ); - compUnit.addSymbol( C ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray() ); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.addParameter( A, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - compUnit.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray() ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.addParameter( B, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - compUnit.addSymbol( f2 ); - - ISymbol a = table.newSymbol( "a".toCharArray() ); //$NON-NLS-1$ - a.setType( ITypeInfo.t_type ); - a.setTypeSymbol( A ); - a.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) ); - - ISymbol c = table.newSymbol( "c".toCharArray() ); //$NON-NLS-1$ - c.setType( ITypeInfo.t_type ); - c.setTypeSymbol( C ); - c.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) ); - - ArrayList paramList = new ArrayList(); - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ); - paramList.add( p1 ); - ISymbol look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - paramList.clear(); - ITypeInfo p2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, c ); - paramList.add( p2 ); - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * class A {}; - * typedef A * B; - * - * void f( A * ); - * void f( A ); - * - * A a; - * B b; - * A [] array; - * - * f( a ); //calls f( A ); - * f( &a ); //calls f( A * ); - * f( b ); //calls f( A * ); - * f( *b ); //calls f( A ); - * f( array ); //calls f( A * ); - */ - public void testFunctionResolution_TypedefsAndPointers() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray() ); //$NON-NLS-1$ - A.setType( ITypeInfo.t_class ); - compUnit.addSymbol( A ); - - ISymbol B = table.newSymbol( "B".toCharArray() ); //$NON-NLS-1$ - B.setType( ITypeInfo.t_type ); - B.setTypeSymbol( A ); - B.getTypeInfo().setBit( true, ITypeInfo.isTypedef ); - B.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) ); - compUnit.addSymbol( B ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray() ); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.addParameter( A, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - compUnit.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray() ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.addParameter( A, 0, null, false ); - compUnit.addSymbol( f2 ); - - ISymbol a = table.newSymbol( "a".toCharArray() ); //$NON-NLS-1$ - a.setType( ITypeInfo.t_type ); - a.setTypeSymbol( A ); - compUnit.addSymbol( a ); - - ISymbol b = table.newSymbol( "b".toCharArray() ); //$NON-NLS-1$ - b.setType( ITypeInfo.t_type ); - b.setTypeSymbol( B ); - compUnit.addSymbol( b ); - - ISymbol array = table.newSymbol( "array".toCharArray() ); //$NON-NLS-1$ - array.setType( ITypeInfo.t_type ); - array.setTypeSymbol( A ); - array.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_array, false, false ) ); - - ArrayList paramList = new ArrayList(); - ITypeInfo p = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ); - paramList.add( p ); - - ISymbol look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - p.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - p.setTypeSymbol( b ); - p.getPtrOperators().clear(); - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - p = p.getFinalType( null ); - p.applyOperatorExpression( ITypeInfo.OperatorExpression.indirection ); - paramList.clear(); - paramList.add( p ); - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - p.setTypeSymbol( array ); - p.getPtrOperators().clear(); - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * class A {}; - * - * class B - * { - * B( A a ){ }; - * }; - * - * void f( B b ){}; - * - * A a; - * f( a ); - */ - public void testUserDefinedConversionSequences() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray() ); //$NON-NLS-1$ - A.setType( ITypeInfo.t_class ); - compUnit.addSymbol( A ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray() ); //$NON-NLS-1$ - B.setType( ITypeInfo.t_class ); - compUnit.addSymbol( B ); - - IParameterizedSymbol constructor = table.newParameterizedSymbol("B".toCharArray()); //$NON-NLS-1$ - constructor.setType( ITypeInfo.t_constructor ); - constructor.addParameter( A, 0, null, false ); - B.addConstructor( constructor ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray() ); //$NON-NLS-1$ - f.setType( ITypeInfo.t_function ); - f.addParameter( B, 0, null, false ); - compUnit.addSymbol( f ); - - ISymbol a = table.newSymbol( "a".toCharArray() ); //$NON-NLS-1$ - a.setTypeInfo( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type ) ); - a.setTypeSymbol( A ); - compUnit.addSymbol( a ); - - ArrayList paramList = new ArrayList(); - ITypeInfo p = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ); - paramList.add( p ); - - ISymbol look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * void f( const int *, short ); - * void f( int *, int ); - * - * int i; - * short s; - * - * void main() { - * f( &i, s ); //ambiguous because &i->int* is better than &i->const int * - * //but s-> short is better than s->int - * f( &i, 1L ); //calls f(int *, int) because &i->int* is better than &i->const int * - * //and 1L->short and 1L->int are indistinguishable - * f( &i, 'c' ); //calls f( int*, int) because &i->int * is better than &i->const int * - * //and c->int is better than c->short - * f( (const int *)&i, 1L ); //calls f(const int *, short ) because const &i->int* is better than &i->int * - * //and 1L->short and 1L->int are indistinguishable - * } - */ - public void testOverloadRanking() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray() ); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.addParameter( ITypeInfo.t_int, ITypeInfo.isConst, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ), false ); - f1.addParameter( ITypeInfo.t_int, ITypeInfo.isShort, null, false ); - - compUnit.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray() ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.addParameter( ITypeInfo.t_int, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - f2.addParameter( ITypeInfo.t_int, 0, null, false ); - compUnit.addSymbol( f2 ); - - ISymbol i = table.newSymbol( "i".toCharArray() ); //$NON-NLS-1$ - i.setType( ITypeInfo.t_int ); - compUnit.addSymbol( i ); - - ISymbol s = table.newSymbol( "s".toCharArray() ); //$NON-NLS-1$ - s.setType( ITypeInfo.t_int ); - s.getTypeInfo().setBit( true, ITypeInfo.isShort ); - compUnit.addSymbol( s ); - - IParameterizedSymbol main = table.newParameterizedSymbol( "main".toCharArray() ); //$NON-NLS-1$ - main.setType( ITypeInfo.t_function ); - compUnit.addSymbol( main ); - - ArrayList params = new ArrayList(); - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, i ); - p1.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - ITypeInfo p2 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, s ); - params.add( p1 ); - params.add( p2 ); - - ISymbol look = null; - - try{ - look = main.unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - - params.clear(); - ITypeInfo p3 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, ITypeInfo.isLong, null ); - params.add( p1 ); - params.add( p3 ); - look = main.unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - params.clear(); - ITypeInfo p4 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_char, 0, null ); - params.add( p1 ); - params.add( p4 ); - look = main.unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - params.clear(); - p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, ITypeInfo.isConst, null, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ), false ); - - params.add( p1 ); - params.add( p3 ); - look = main.unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( look, f1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * class B; - * class A { A( B& ); }; - * class B { operator A(); }; - * - * void f(A){} - * - * B b; - * f( b ); //ambiguous because b->A via constructor or conversion - * - * class C { C( B& ); }; - * - * void f(C){} - * - * f( b ); //ambiguous because b->C via constructor and b->a via constructor/conversion - * - * void f(B){} - * - * f( b ); //calls f(B) - */ - - public void testUserDefinedConversionByOperator() throws Exception{ - newTable(); - - IContainerSymbol compUnit = table.getCompilationUnit(); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray() ); //$NON-NLS-1$ - B.setType( ITypeInfo.t_class ); - - compUnit.addSymbol( B ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray() ); //$NON-NLS-1$ - A.setType( ITypeInfo.t_class ); - compUnit.addSymbol( A ); - - IParameterizedSymbol constructA = table.newParameterizedSymbol( "A".toCharArray() ); //$NON-NLS-1$ - constructA.setType( ITypeInfo.t_constructor ); - constructA.addParameter( B, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - A.addConstructor( constructA ); - - IParameterizedSymbol operator = table.newParameterizedSymbol( "operator A".toCharArray() ); //$NON-NLS-1$ - operator.setType( ITypeInfo.t_function ); - B.addSymbol( operator ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray() ); //$NON-NLS-1$ - f1.setType( ITypeInfo.t_function ); - f1.addParameter( A, 0, null, false ); - compUnit.addSymbol( f1 ); - - ISymbol b = table.newSymbol( "b".toCharArray() ); //$NON-NLS-1$ - b.setType( ITypeInfo.t_type ); - b.setTypeSymbol( B ); - - ArrayList params = new ArrayList(); - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, b ); - params.add( p1 ); - - ISymbol look = null; - - try{ - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol("C".toCharArray()); //$NON-NLS-1$ - C.setType( ITypeInfo.t_class ); - compUnit.addSymbol( C ); - - IParameterizedSymbol constructC = table.newParameterizedSymbol("C".toCharArray()); //$NON-NLS-1$ - constructC.setType( ITypeInfo.t_constructor ); - constructC.addParameter( B, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - C.addConstructor( constructC ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray() ); //$NON-NLS-1$ - f2.setType( ITypeInfo.t_function ); - f2.addParameter( C, 0, null, false ); - compUnit.addSymbol( f2 ); - - try{ - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f".toCharArray() ); //$NON-NLS-1$ - f3.setType( ITypeInfo.t_function ); - f3.addParameter( B, 0, null, false ); - compUnit.addSymbol( f3 ); - - look = compUnit.unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( look, f3 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - -// public void testMarkRollback() throws Exception{ -// newTable(); -// -// IDerivableContainerSymbol A = table.newDerivableContainerSymbol("A".toCharArray()); -// A.setType( TypeInfo.t_class ); -// table.getCompilationUnit().addSymbol( A ); -// -// Mark mark = table.setMark(); -// -// ISymbol f = table.newSymbol("f".toCharArray()); -// A.addSymbol( f ); -// -// ISymbol look = A.lookup("f".toCharArray()); -// assertEquals( look, f ); -// -// assertTrue( table.rollBack( mark ) ); -// -// look = A.lookup("f".toCharArray()); -// assertEquals( look, null ); -// -// IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B".toCharArray()); -// B.setType( TypeInfo.t_class ); -// -// mark = table.setMark(); -// table.getCompilationUnit().addSymbol( B ); -// Mark mark2 = table.setMark(); -// A.addParent( B ); -// Mark mark3 = table.setMark(); -// -// IParameterizedSymbol C = table.newParameterizedSymbol("C".toCharArray()); -// C.addParameter( TypeInfo.t_class, 0, null, false ); -// -// assertEquals( C.getParameterList().size(), 1 ); -// table.rollBack( mark3 ); -// assertEquals( C.getParameterList().size(), 0 ); -// assertEquals( A.getParents().size(), 1 ); -// table.rollBack( mark2 ); -// assertEquals( A.getParents().size(), 0 ); -// -// assertFalse( table.commit( mark2 ) ); -// assertFalse( table.rollBack( mark2 ) ); -// -// B.setType( TypeInfo.t_namespace ); -// -// mark = table.setMark(); -// C.addUsingDirective( B ); -// assertEquals( C.getUsingDirectives().size(), 1 ); -// table.rollBack( mark ); -// assertEquals( C.getUsingDirectives().size(), 0 ); -// } - - /** - * class A; - * - * A * a; - * - * class A {}; - * - * @throws Exception - */ - public void testForwardClassDeclaration() throws Exception{ - newTable(); - - ISymbol forwardSymbol = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - forwardSymbol.setIsForwardDeclaration( true ); - - table.getCompilationUnit().addSymbol( forwardSymbol ); - - /*...*/ - - ISymbol lookup = table.getCompilationUnit().lookup( "A".toCharArray() ); //$NON-NLS-1$ - ISymbol otherLookup = table.getCompilationUnit().elaboratedLookup( ITypeInfo.t_class, "A".toCharArray() ); //$NON-NLS-1$ - - assertEquals( lookup, otherLookup ); - assertEquals( lookup, forwardSymbol ); - - ISymbol a = table.newSymbol( "a".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( forwardSymbol ); - a.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - - table.getCompilationUnit().addSymbol( a ); - - /*...*/ - - lookup = table.getCompilationUnit().lookup( "A".toCharArray() ); //$NON-NLS-1$ - IDerivableContainerSymbol classA = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - assertTrue( lookup.isForwardDeclaration() ); - lookup.setForwardSymbol( classA ); - - table.getCompilationUnit().addSymbol( classA ); - - lookup = table.getCompilationUnit().lookup( "a".toCharArray() ); //$NON-NLS-1$ - assertEquals( lookup, a ); - assertEquals( a.getTypeSymbol(), classA ); - - lookup = table.getCompilationUnit().lookup( "A".toCharArray() ); //$NON-NLS-1$ - assertEquals( lookup, classA ); - - lookup = table.getCompilationUnit().elaboratedLookup( ITypeInfo.t_class, "A".toCharArray() ); //$NON-NLS-1$ - assertEquals( lookup, classA ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * class A; - * - * class B { - * static void f( A * ); - * static void f( int ); - * }; - * - * A* a1; - * - * class A {}; - * - * void B::f( A * ) {} - * void B::f( int ) {} - * - * A* a2; - * - * B::f( a1 ); - * B::f( a2 ); - * - * @throws Exception - */ - public void testForwardDeclarationUsedAsFunctionParam() throws Exception{ - newTable(); - - ISymbol forwardSymbol = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - forwardSymbol.setIsForwardDeclaration( true ); - table.getCompilationUnit().addSymbol( forwardSymbol ); - - /*...*/ - - IDerivableContainerSymbol classB = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - - IParameterizedSymbol fn1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - ISymbol lookup = table.getCompilationUnit().lookup( "A".toCharArray() ); //$NON-NLS-1$ - assertEquals( lookup, forwardSymbol ); - fn1.addParameter( lookup, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - fn1.getTypeInfo().setBit( true, ITypeInfo.isStatic ); - classB.addSymbol( fn1 ); - - IParameterizedSymbol fn2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - fn2.addParameter( ITypeInfo.t_int, 0, null, false ); - fn2.getTypeInfo().setBit( true, ITypeInfo.isStatic ); - classB.addSymbol( fn2 ); - - table.getCompilationUnit().addSymbol( classB ); - - /*...*/ - - ISymbol a1 = table.newSymbol( "a1".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - lookup = table.getCompilationUnit().lookup( "A".toCharArray() ); //$NON-NLS-1$ - assertEquals( lookup, forwardSymbol ); - a1.setTypeSymbol( lookup ); - a1.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - - table.getCompilationUnit().addSymbol( a1 ); - - /*...*/ - - lookup = table.getCompilationUnit().lookup( "A".toCharArray() ); //$NON-NLS-1$ - IDerivableContainerSymbol classA = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - assertTrue( lookup.isForwardDeclaration() ); - lookup.setForwardSymbol( classA ); - table.getCompilationUnit().addSymbol( classA ); - - /*..*/ - ISymbol a2 = table.newSymbol( "a2".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - lookup = table.getCompilationUnit().lookup( "A".toCharArray() ); //$NON-NLS-1$ - assertEquals( lookup, classA ); - a2.setTypeSymbol( lookup ); - a2.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - - table.getCompilationUnit().addSymbol( a2 ); - - /*..*/ - - ArrayList paramList = new ArrayList(); - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a1 ); - paramList.add( p1 ); - ISymbol look = classB.memberFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, fn1 ); - - paramList.clear(); - p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a2 ); - paramList.add( p1 ); - look = classB.memberFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, fn1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - public void testConstructors() throws Exception{ - newTable(); - - IDerivableContainerSymbol classA = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - - IParameterizedSymbol constructor1 = table.newParameterizedSymbol( "A".toCharArray(), ITypeInfo.t_constructor ); //$NON-NLS-1$ - constructor1.addParameter( classA, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - - IParameterizedSymbol constructor2 = table.newParameterizedSymbol( "A".toCharArray(), ITypeInfo.t_constructor ); //$NON-NLS-1$ - constructor2.addParameter( ITypeInfo.t_int, 0, null, false ); - - IParameterizedSymbol constructor3 = table.newParameterizedSymbol( "A".toCharArray(), ITypeInfo.t_constructor ); //$NON-NLS-1$ - constructor3.addParameter( ITypeInfo.t_char, 0, null, false ); - - classA.addConstructor( constructor1 ); - classA.addConstructor( constructor2 ); - classA.addConstructor( constructor3 ); - - assertEquals( classA.getConstructors().size(), 3 ); - - IParameterizedSymbol cloned = (IParameterizedSymbol) constructor2.clone(); - try{ - classA.addConstructor( cloned ); - } catch ( ParserSymbolTableException e ) { - assertEquals( e.reason, ParserSymbolTableException.r_InvalidOverload ); - } - - ArrayList paramList = new ArrayList(); - paramList.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - ISymbol lookup = classA.lookupConstructor( paramList ); - - assertEquals( lookup, constructor2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * namespace A - * { - * int x; - * } - * namespace B = A; - * - * ++B::x; - */ - public void testNamespaceAlias() throws Exception{ - newTable(); - - IContainerSymbol NSA = table.newContainerSymbol( "A".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( NSA ); - - ISymbol x = table.newSymbol( "x".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - NSA.addSymbol( x ); - - IContainerSymbol NSB = table.newContainerSymbol( "B".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - NSB.setForwardSymbol( NSA ); //alias B to A - - table.getCompilationUnit().addSymbol( NSB ); - - ISymbol lookup = table.getCompilationUnit().lookup( "B".toCharArray() ); //$NON-NLS-1$ - assertEquals( lookup, NSB ); - - lookup = NSB.lookup( "x".toCharArray() ); //$NON-NLS-1$ - assertEquals( lookup, x ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * namespace A - * { - * void f( ); - * } - * namespace B = A; - * - * B::f(); - * - * using namespace B; - * f(); - */ - public void testUsingNamespaceAlias() throws Exception{ - newTable(); - - IContainerSymbol NSA = table.newContainerSymbol( "A".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( NSA ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_void ) ); //$NON-NLS-1$ - - NSA.addSymbol( f ); - - IContainerSymbol NSB = table.newContainerSymbol( "B".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - NSB.setForwardSymbol( NSA ); - table.getCompilationUnit().addSymbol( NSB ); - - //look for function that has no parameters - ArrayList paramList = new ArrayList(); - ISymbol look = NSB.qualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f ); - - table.getCompilationUnit().addUsingDirective( NSB ); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - assertEquals( look, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * The general rule is that when you set a TypeInfo's type to be t_type, you - * should set the type symbol to be something. This is to test that the function - * resolution can handle a bad typeInfo that has a null symbol without throwing a NPE - */ - public void testBadParameterInfo() throws Exception{ - newTable(); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f.setReturnType( table.newSymbol( "".toCharArray(), ITypeInfo.t_void ) ); //$NON-NLS-1$ - - IDerivableContainerSymbol a = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( a ); - - f.addParameter( a, 0, null, false ); - - table.getCompilationUnit().addSymbol( f ); - - ArrayList paramList = new ArrayList (); - - ITypeInfo param = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, null ); - - paramList.add( param ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - - assertEquals( look, null ); - - ISymbol intermediate = table.newSymbol( "".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - - param.setTypeSymbol( intermediate ); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), paramList ); //$NON-NLS-1$ - - assertEquals( look, null ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * class A { - * A ( C ) {}; - * } a; - * class B : public A {} b; - * class C { - * C ( A ) {}; - * } c; - * - * isTrue ? &a : &b; //expect type = 2nd operand ( A ) - * isTrue ? &a : &c; //expect null, neither converts - * isTrue ? a : c; //expect exception, both convert - * - * @throws Exception - */ - public void testGetConditionalOperand_bug43106() throws Exception{ - newTable(); - - IDerivableContainerSymbol clsA = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol clsB = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - - clsB.addParent( clsA ); - - table.getCompilationUnit().addSymbol( clsA ); - table.getCompilationUnit().addSymbol( clsB ); - - ISymbol a = table.newSymbol( "a".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( clsA ); - - ISymbol b = table.newSymbol( "b".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - b.setTypeSymbol( clsB ); - - table.getCompilationUnit().addSymbol( a ); - table.getCompilationUnit().addSymbol( b ); - - ITypeInfo secondOp = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a ); - secondOp.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - ITypeInfo thirdOp = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, b ); - thirdOp.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - - ITypeInfo returned = table.getConditionalOperand( secondOp, thirdOp ); - assertEquals( returned, secondOp ); - - IDerivableContainerSymbol clsC = table.newDerivableContainerSymbol( "C".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( clsC ); - ISymbol c = table.newSymbol( "c".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - c.setTypeSymbol( clsC ); - table.getCompilationUnit().addSymbol( c ); - - ITypeInfo anotherOp = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, c ); - anotherOp.applyOperatorExpression( ITypeInfo.OperatorExpression.addressof ); - - returned = table.getConditionalOperand( secondOp, anotherOp ); - assertEquals( returned, null ); - - IParameterizedSymbol constructorA = table.newParameterizedSymbol( "A".toCharArray(), ITypeInfo.t_constructor ); //$NON-NLS-1$ - constructorA.addParameter( clsC, 0, null, false ); - clsA.addConstructor( constructorA ); - - IParameterizedSymbol constructorC = table.newParameterizedSymbol( "C".toCharArray(), ITypeInfo.t_constructor ); //$NON-NLS-1$ - constructorC.addParameter( clsA, 0, null, false ); - clsC.addConstructor( constructorC ); - - secondOp.getPtrOperators().clear(); - anotherOp.getPtrOperators().clear(); - try{ - - returned = table.getConditionalOperand( secondOp, anotherOp ); - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - //good - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * class A {}; - * class B : public A {} b; - * class C : private A {} c; - * int f ( A & ); - * - * int i = f ( b ); //calls f( A & ); - * - * int f ( B & ); - * i = f( b ); //now calls f( B& ); - * - * i = f( c ); //exception, A is not an accessible base class - */ - public void testDerivedReference() throws Exception{ - newTable(); - - IDerivableContainerSymbol clsA = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol clsB = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - IDerivableContainerSymbol clsC = table.newDerivableContainerSymbol( "C".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - - clsB.addParent( clsA ); - clsC.addParent( clsA, false, ASTAccessVisibility.PRIVATE, 0, null ); - - ISymbol b = table.newSymbol("b".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - b.setTypeSymbol( clsB ); - - ISymbol c = table.newSymbol("c".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - c.setTypeSymbol( clsC ); - - table.getCompilationUnit().addSymbol( clsA ); - table.getCompilationUnit().addSymbol( clsB ); - table.getCompilationUnit().addSymbol( clsC ); - table.getCompilationUnit().addSymbol( b ); - table.getCompilationUnit().addSymbol( c ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( clsA, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - table.getCompilationUnit().addSymbol( f1 ); - - ArrayList parameters = new ArrayList(); - ITypeInfo param = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, b ); - parameters.add( param ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), parameters ); //$NON-NLS-1$ - assertEquals( look, f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( clsB, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference ), false ); - table.getCompilationUnit().addSymbol( f2 ); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), parameters ); //$NON-NLS-1$ - assertEquals( look, f2 ); - - parameters.clear(); - param = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, c ); - parameters.add( param ); - try{ - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), parameters ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - //good - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * @throws Exception - * - * class A { - * private : - * A ( const A & ) {} - * } a; - * - * class B : public A { - * } b; - * - * 1 > 2 ? a : b; //fails, b can't be converted to a without the A( const A & ) copy constructor - * ----------------------- - * class A { - * A ( const A & ) {} - * } a; - * class B : public A {} b; - * - * 1 > 2 ? a : b; //succeeds, b can be converted to a using copy constructor - * - */ - public void testAddCopyConstructor() throws Exception { - newTable(); - - IDerivableContainerSymbol clsA = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( clsA ); - - ISymbol a = table.newSymbol( "a".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - a.setTypeSymbol( clsA ); - table.getCompilationUnit().addSymbol( a ); - - IDerivableContainerSymbol clsB = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - clsB.addParent( clsA ); - table.getCompilationUnit().addSymbol( clsB ); - - ISymbol b = table.newSymbol( "b".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - b.setTypeSymbol( clsB ); - table.getCompilationUnit().addSymbol( b ); - - ITypeInfo secondOp = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, a, null, false ); - ITypeInfo thirdOp = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, b, null, false ); - - ITypeInfo returned = table.getConditionalOperand( secondOp, thirdOp ); - assertEquals( returned, null ); - - clsA.addCopyConstructor(); - clsB.addCopyConstructor(); - - returned = table.getConditionalOperand( secondOp, thirdOp ); - assertEquals( returned, secondOp ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - public void testbug43834() throws Exception{ - newTable(); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( f ); - - ArrayList parameters = new ArrayList(); - ITypeInfo param = TypeInfoProvider.newTypeInfo( ITypeInfo.t_void, 0, null ); - parameters.add( param ); - - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), parameters ); //$NON-NLS-1$ - assertEquals( look, f ); - - f.addParameter( ITypeInfo.t_void, 0, null, false ); - - parameters.clear(); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), parameters ); //$NON-NLS-1$ - assertEquals( look, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * - * namespace A{ - * void f(); - * } - * namespace B{ - * int f; - * } - * namespace C{ - * using namespace A; - * using namespace B; - * using f; //ambiguous, int f or void f()? - * } - */ - public void testBug43503_AmbiguousUsing() throws Exception{ - newTable(); - IContainerSymbol NSA = table.newContainerSymbol( "A".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( NSA ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - NSA.addSymbol( f1 ); - - IContainerSymbol NSB = table.newContainerSymbol( "B".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( NSB ); - - ISymbol f2 = table.newSymbol( "f".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - NSB.addSymbol( f2 ); - - IContainerSymbol NSC = table.newContainerSymbol( "C".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( NSC ); - NSC.addUsingDirective( NSA ); - NSC.addUsingDirective( NSB ); - - try{ - NSC.addUsingDeclaration( "f".toCharArray() ); //$NON-NLS-1$ - assertTrue( false ); - } catch ( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void f( void ); - * void f( int ); - * - * void * pF = &f; //lookup without function parameters, should be ambiguous - * @throws Exception - */ - public void testBug43503_UnableToResolveFunction() throws Exception{ - newTable(); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_int, 0, null, false ); - - table.getCompilationUnit().addSymbol( f1 ); - table.getCompilationUnit().addSymbol( f2 ); - - try{ - table.getCompilationUnit().lookup( "f".toCharArray() ); //$NON-NLS-1$ - assertTrue( false ); - } catch( ParserSymbolTableException e ){ - assertEquals( e.reason, ParserSymbolTableException.r_UnableToResolveFunction ); - } - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int initialize(); - * int initialize(){ - * return 3; - * } - * - * int i = initialize(); - * - * @throws Exception - */ - public void testBug44510() throws Exception{ - newTable(); - - IParameterizedSymbol init1 = table.newParameterizedSymbol( "initialize".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - - table.getCompilationUnit().addSymbol( init1 ); - - IParameterizedSymbol init2 = table.newParameterizedSymbol( "initialize".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "initialize".toCharArray(), new ArrayList() ); //$NON-NLS-1$ - assertEquals( look, init1 ); - - init1.setIsForwardDeclaration( true ); - init1.setForwardSymbol( init2 ); - - table.getCompilationUnit().addSymbol( init2 ); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "initialize".toCharArray(), new ArrayList() ); //$NON-NLS-1$ - - assertEquals( look, init2 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * class A { - * void f( int ) {} - * void f( ) {} - * }; - * class B : public A { - * void f( char ) { } - * } b; - * - * b.f( 1 ); //calls B::f - * b.f(); //error - * @throws Exception - */ - public void testBug46882() throws Exception{ - newTable(); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - - table.getCompilationUnit().addSymbol( A ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - A.addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - A.addSymbol( f2 ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - B.addParent( A ); - - table.getCompilationUnit().addSymbol( B ); - - IParameterizedSymbol f3 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f3.addParameter( ITypeInfo.t_char, 0, null, false ); - B.addSymbol( f3 ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - - ISymbol look = B.qualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( look, f3 ); - - params.clear(); - look = B.qualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( look, null ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int aVar; - * void foo( ) { - * int anotherVar; - * a(CTRL+SPACE) - * } - */ - public void testPrefixLookup_Unqualified() throws Exception { - newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE ); - - ISymbol aVar = table.newSymbol( "aVar".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( aVar ); - - IParameterizedSymbol foo = table.newParameterizedSymbol( "foo".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( foo ); - - ISymbol anotherVar = table.newSymbol( "anotherVar".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - foo.addSymbol( anotherVar ); - - List results = foo.prefixLookup( null, "a".toCharArray(), false, null ); //$NON-NLS-1$ - assertTrue( results != null ); - assertEquals( results.size(), 2 ); - - assertTrue( results.contains( aVar ) ); - assertTrue( results.contains( anotherVar ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int aVar; //not a member of D, not reported - * - * class D{ - * int aField; - * void aMethod(); - * }; - * - * D d; - * d.a(CTRL+SPACE) - */ - public void testPrefixLookup_Qualified() throws Exception { - newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE ); - - ISymbol aVar = table.newSymbol( "aVar".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( aVar ); - - IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( D ); - - ISymbol aField = table.newSymbol( "aField".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - IParameterizedSymbol aMethod = table.newParameterizedSymbol( "aMethod".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - - D.addSymbol( aField ); - D.addSymbol( aMethod ); - - List results = D.prefixLookup( null, "a".toCharArray(), true, null ); //$NON-NLS-1$ - - assertTrue( results != null ); - assertEquals( results.size(), 2 ); - - assertTrue( !results.contains( aVar ) ); - assertTrue( results.contains( aField ) ); - assertTrue( results.contains( aMethod ) ); - - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * class A { - * int aVar - * int anotherVar; //hidden, not reported - * void af (); //hidden, not reported - * }; - * - * class B : public A { - * int anotherVar; - * void af( char ); - * } b; - * - * b.a(CTRL+SPACE) - * @throws Exception - */ - public void testPrefixLookup_Inheritance() throws Exception { - newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( A ); - - ISymbol aVar = table.newSymbol( "aVar".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - ISymbol anotherVar1 = table.newSymbol( "anotherVar".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - A.addSymbol( aVar ); - A.addSymbol( anotherVar1 ); - - IParameterizedSymbol af1 = table.newParameterizedSymbol( "af".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - A.addSymbol( af1 ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - B.addParent( A ); - - table.getCompilationUnit().addSymbol( B ); - - ISymbol anotherVar2 = table.newSymbol( "anotherVar".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - B.addSymbol( anotherVar2 ); - - IParameterizedSymbol af2 = table.newParameterizedSymbol( "af".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - af2.addParameter( ITypeInfo.t_char, 0, null, false ); - B.addSymbol( af2 ); - - - List results = B.prefixLookup( null, "a".toCharArray(), true, null ); //$NON-NLS-1$ - - assertTrue( results != null ); - assertEquals( results.size(), 3 ); - assertTrue( ! results.contains( anotherVar1 ) ); - assertTrue( ! results.contains( af1 ) ); - assertTrue( results.contains( aVar ) ); - assertTrue( results.contains( anotherVar2 ) ); - assertTrue( results.contains( af2 ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int aa; - * namespace { - * namespace U { - * int a; - * } - * namespace V{ - * int a; - * } - * namespace W{ - * int a; - * } - * - * void f(){ - * using namespace U; - * using namespace V; - * using namespace W; - * a(CTRL+SPACE) - * } - * } - * - * @throws Exception - */ - public void testPrefixLookup_Ambiguities() throws Exception{ - newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE ); - - ISymbol aa = table.newSymbol( "aa".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( aa ); - - IContainerSymbol ns = table.newContainerSymbol( "".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( ns ); - - IContainerSymbol U = table.newContainerSymbol( "U".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - ns.addSymbol( U ); - ISymbol a1 = table.newSymbol( "a".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - U.addSymbol( a1 ); - - IContainerSymbol V = table.newContainerSymbol( "V".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - ns.addSymbol( V ); - ISymbol a2 = table.newSymbol( "a".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - V.addSymbol( a2 ); - - IContainerSymbol W = table.newContainerSymbol( "W".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - ns.addSymbol( W ); - ISymbol a3 = table.newSymbol( "a".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - W.addSymbol( a3 ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - ns.addSymbol( f ); - - f.addUsingDirective( U ); - f.addUsingDirective( V ); - f.addUsingDirective( W ); - - List results = f.prefixLookup( null, "a".toCharArray(), false, null ); //$NON-NLS-1$ - - assertTrue( results != null ); - assertEquals( results.size(), 1 ); - assertTrue( results.contains( aa ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int i; - * class A { - * void g(){ - * A a; - * a.i++; //fail qualified lookup, no i in A - * i++; //success unqualified lookup - * } - * }; - * - * @throws Exception - */ - public void testQualifiedUnqualifiedLookup() throws Exception{ - newTable(); - - ISymbol i = table.newSymbol( "i".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( i ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( A ); - - IParameterizedSymbol g = table.newParameterizedSymbol( "g".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - A.addSymbol( g ); - - assertEquals( null, A.qualifiedLookup( "i".toCharArray() ) ); //$NON-NLS-1$ - assertEquals( i, g.lookup( "i".toCharArray() ) ); //$NON-NLS-1$ - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * class D { }; - * class A { - * public: static int i; - * private: static int j; - * friend class D; - * }; - * class B : private A {}; - * class C : public B, public A {}; - * - * - * @throws Exception - */ - public void testVisibilityDetermination() throws Exception{ - newTable(); - - IDerivableContainerSymbol D = table.newDerivableContainerSymbol( "D".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( D ); - - IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - ISymbol i = table.newSymbol( "i".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - ISymbol j = table.newSymbol( "j".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - - table.getCompilationUnit().addSymbol( A ); - - ISymbol friend = A.lookupForFriendship( "D".toCharArray() ); //$NON-NLS-1$ - assertEquals( friend, D ); - A.addFriend( friend ); - - A.addSymbol( i ); - A.addSymbol( j ); - - IASTCompilationUnit compUnit = new ASTCompilationUnit(table.getCompilationUnit() ); - ISymbolASTExtension cuExtension = new StandardSymbolExtension( table.getCompilationUnit(), (ASTSymbol) compUnit ); - table.getCompilationUnit().setASTExtension( cuExtension ); - - IASTClassSpecifier clsSpec = new ASTClassSpecifier( A, ASTClassKind.CLASS, ClassNameType.IDENTIFIER, ASTAccessVisibility.PUBLIC, 0, 0, 0, 0, 0, new ArrayList( ), EMPTY_CHAR_ARRAY ); //$NON-NLS-1$ - ISymbolASTExtension clsExtension = new StandardSymbolExtension( A, (ASTSymbol) clsSpec ); - A.setASTExtension( clsExtension ); - - IASTField field = new ASTField(i, null, null, null, 0, 0, 0, 0, 0, new ArrayList(), false, null, ASTAccessVisibility.PUBLIC, EMPTY_CHAR_ARRAY ); - ISymbolASTExtension extension = new StandardSymbolExtension( i, (ASTSymbol) field ); - i.setASTExtension( extension ); - - field = new ASTField(i, null, null, null, 0, 0, 0, 0, 0, new ArrayList(), false, null, ASTAccessVisibility.PRIVATE, EMPTY_CHAR_ARRAY ); - extension = new StandardSymbolExtension( j, (ASTSymbol) field ); - j.setASTExtension( extension ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - B.addParent( A, false, ASTAccessVisibility.PRIVATE, 0, null ); - table.getCompilationUnit().addSymbol( B ); - - IDerivableContainerSymbol C = table.newDerivableContainerSymbol( "C".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - C.addParent( B ); - C.addParent( A ); - table.getCompilationUnit().addSymbol( C ); - - assertTrue( table.getCompilationUnit().isVisible( i, A ) ); - assertFalse( table.getCompilationUnit().isVisible( i, B ) ); - assertTrue( table.getCompilationUnit().isVisible(i, C ) ); - assertTrue( D.isVisible( j, A ) ); - assertFalse( D.isVisible( j, B ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * struct a1{}; - * void aFoo() {} - * int aa; - * class A2{ - * struct a3 {}; - * int a3; - * void aF(); - * void f() { - * int aLocal; - * A(CTRL+SPACE) - * }; - * }; - * @throws Exception - */ - public void testPrefixFiltering() throws Exception{ - newTable( ParserLanguage.CPP, ParserMode.COMPLETION_PARSE ); - IDerivableContainerSymbol a1 = table.newDerivableContainerSymbol( "a1".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( a1 ); - - IParameterizedSymbol aFoo = table.newParameterizedSymbol( "aFoo".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( aFoo ); - - ISymbol aa = table.newSymbol( "aa".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( aa ); - - IDerivableContainerSymbol A2 = table.newDerivableContainerSymbol( "A2".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( A2 ); - - IDerivableContainerSymbol a3 = table.newDerivableContainerSymbol( "a3".toCharArray(), ITypeInfo.t_struct ); //$NON-NLS-1$ - A2.addSymbol( a3 ); - - ISymbol a3_int = table.newSymbol( "a3".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - A2.addSymbol( a3_int ); - - IParameterizedSymbol aF = table.newParameterizedSymbol( "aF".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - A2.addSymbol( aF ); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - A2.addSymbol( f ); - - ISymbol aLocal = table.newSymbol( "aLocal".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - f.addSymbol( aLocal ); - - List results = f.prefixLookup( new TypeFilter( LookupKind.STRUCTURES ), "A".toCharArray(), false, null ); //$NON-NLS-1$ - - assertEquals( results.size(), 3 ); - - assertTrue( results.contains( a1 ) ); - assertTrue( results.contains( A2 ) ); - assertTrue( results.contains( a3 ) ); - - results = f.prefixLookup( null, "a".toCharArray(), false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 7 ); - assertTrue( results.contains( aF ) ); - assertTrue( results.contains( A2 ) ); - assertTrue( results.contains( a3_int ) ); - assertTrue( results.contains( a1 ) ); - assertTrue( results.contains( aFoo ) ); - assertTrue( results.contains( aa ) ); - assertTrue( results.contains( aLocal ) ); - - results = f.prefixLookup( new TypeFilter( LookupKind.FUNCTIONS ), "a".toCharArray(), false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 1 ); - assertTrue( results.contains( aFoo ) ); - - results = f.prefixLookup( new TypeFilter( LookupKind.METHODS ), "a".toCharArray(), false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 1 ); - assertTrue( results.contains( aF ) ); - - results = f.prefixLookup( new TypeFilter( LookupKind.LOCAL_VARIABLES ), "a".toCharArray(), false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 1 ); - assertTrue( results.contains( aLocal ) ); - - results = f.prefixLookup( new TypeFilter( LookupKind.VARIABLES ), "a".toCharArray(), false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 1 ); - assertTrue( results.contains( aa ) ); - - results = f.prefixLookup( new TypeFilter( LookupKind.FIELDS), "a".toCharArray(), false, null ); //$NON-NLS-1$ - assertEquals( results.size(), 1 ); - assertTrue( results.contains( a3_int ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void foo( ... ){ } - * - * foo( 1 ); - * - * @throws Exception - */ - public void testBug43110_Ellipses() throws Exception{ - newTable(); - - IParameterizedSymbol foo = table.newParameterizedSymbol( "foo".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - foo.setHasVariableArgs( true ); - - table.getCompilationUnit().addSymbol( foo ); - - List params = new ArrayList(); - - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ); - params.add( p1 ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo".toCharArray(), params ); //$NON-NLS-1$ - - assertEquals( foo, look ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void foo( ... ) {}; //#1 - * void foo( int i ) {}; //#2 - * - * foo( 1 ); // calls foo #2 - * @throws Exception - */ - public void testBug43110_EllipsesRanking() throws Exception{ - newTable(); - - IParameterizedSymbol foo1 = table.newParameterizedSymbol( "foo".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - foo1.setHasVariableArgs( true ); - - table.getCompilationUnit().addSymbol( foo1 ); - - IParameterizedSymbol foo2 = table.newParameterizedSymbol( "foo".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - foo2.addParameter( ITypeInfo.t_int, 0, null, false ); - table.getCompilationUnit().addSymbol( foo2 ); - - List params = new ArrayList(); - - ITypeInfo p1 = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ); - params.add( p1 ); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo".toCharArray(), params ); //$NON-NLS-1$ - - assertEquals( foo2, look ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void foo( int i = 0 ) {}; //#1 - * void foo( ... ) {}; //#2 - * - * foo(); //calls #1 - * @throws Exception - */ - public void testBug43110_ElipsesRanking_2() throws Exception{ - newTable(); - - IParameterizedSymbol foo1 = table.newParameterizedSymbol( "foo".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - foo1.addParameter( ITypeInfo.t_int, 0, null, true ); - table.getCompilationUnit().addSymbol( foo1 ); - - IParameterizedSymbol foo2 = table.newParameterizedSymbol( "foo".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - foo2.setHasVariableArgs( true ); - table.getCompilationUnit().addSymbol( foo2 ); - - List params = new ArrayList(); - - ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo".toCharArray(), params ); //$NON-NLS-1$ - - assertEquals( foo1, look ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int global; - * class A { - * A(); - * int var; - * void foo(); - * }; - * - */ - public void testIterator_1() throws Exception{ - newTable(); - - ISymbol global = table.newSymbol( "global".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( global ); - - IDerivableContainerSymbol cls = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ - - table.getCompilationUnit().addSymbol( cls ); - - IParameterizedSymbol constructor = table.newParameterizedSymbol( "A".toCharArray(), ITypeInfo.t_constructor ); //$NON-NLS-1$ - cls.addConstructor( constructor ); - - ISymbol var = table.newSymbol( "var".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ - cls.addSymbol( var ); - - IParameterizedSymbol foo = table.newParameterizedSymbol( "foo".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - cls.addSymbol( foo ); - - - Iterator iter = table.getCompilationUnit().getContentsIterator(); - assertEquals( iter.next(), global ); - IContainerSymbol symbol = (IContainerSymbol) iter.next(); - assertEquals( symbol, cls ); - assertFalse( iter.hasNext() ); - - iter = symbol.getContentsIterator(); - assertEquals( iter.next(), constructor ); - assertEquals( iter.next(), var ); - assertEquals( iter.next(), foo ); - assertFalse( iter.hasNext() ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * int foo(); - * namespace A{ - * int bar(); - * int bar( int ); - * }; - * class B{ - * void func(){ - * using namespace A; - * } - * }; - * @throws Exception - */ - public void testIterator_2() throws Exception{ - newTable(); - - IParameterizedSymbol foo = table.newParameterizedSymbol( "foo".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( foo ); - - IContainerSymbol nsA = table.newContainerSymbol( "A".toCharArray(), ITypeInfo.t_namespace ); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( nsA ); - - IParameterizedSymbol bar1 = table.newParameterizedSymbol( "bar".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - nsA.addSymbol( bar1 ); - - IParameterizedSymbol bar2 = table.newParameterizedSymbol( "bar".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - bar2.addParameter( ITypeInfo.t_int, 0, null, false ); - nsA.addSymbol( bar2 ); - - IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B".toCharArray(), ITypeInfo.t_class); //$NON-NLS-1$ - table.getCompilationUnit().addSymbol( B ); - - B.addCopyConstructor(); - - IParameterizedSymbol func = table.newParameterizedSymbol( "func".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - B.addSymbol( func ); - - IUsingDirectiveSymbol using = func.addUsingDirective( nsA ); - - Iterator iter = table.getCompilationUnit().getContentsIterator(); - - assertEquals( iter.next(), foo ); - - IContainerSymbol s1 = (IContainerSymbol) iter.next(); - assertEquals( s1, nsA ); - - IContainerSymbol s2 = (IContainerSymbol) iter.next(); - assertEquals( s2, B ); - - assertFalse( iter.hasNext() ); - - iter = s1.getContentsIterator(); - assertEquals( iter.next(), bar1 ); - assertEquals( iter.next(), bar2 ); - assertFalse( iter.hasNext() ); - - iter = s2.getContentsIterator(); - - //Copy constructor!! - ISymbol copy = (ISymbol) iter.next(); - assertTrue( copy instanceof IParameterizedSymbol ); - assertTrue( CharArrayUtils.equals(copy.getName(), "B".toCharArray() ) ); //$NON-NLS-1$ - assertEquals( copy.getType(), ITypeInfo.t_constructor ); - - assertEquals( iter.next(), func ); - assertFalse( iter.hasNext() ); - - iter = func.getContentsIterator(); - //this pointer!! - ISymbol th = (ISymbol) iter.next(); - assertTrue( CharArrayUtils.equals(th.getName(), "this".toCharArray() ) ); //$NON-NLS-1$ - assertEquals( th.getTypeSymbol(), B ); - - assertEquals( iter.next(), using ); - - assertFalse( iter.hasNext() ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void f( long long int ){} //#1 - * void f( long int ) {} //#2 - * - * f( 1L ); //#2 - * f( 1LL ); //#1 - * - * @throws Exception - */ - public void testLongLong() throws Exception{ - newTable(); - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, ITypeInfo.isLongLong, null, false ); - table.getCompilationUnit().addSymbol( f1 ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_int, ITypeInfo.isLong, null, false ); - table.getCompilationUnit().addSymbol( f2 ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, ITypeInfo.isLong, null ) ); - - IParameterizedSymbol lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( lookup, f2 ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, ITypeInfo.isLongLong, null ) ); - lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( lookup, f1 ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void f( float _Complex ){} - * void g( float ) {} - * - * float _Complex c; - * float fl; - * float _Imaginary i; - * - * f( c ); - * f( fl ); - * g( c ); - * g( i ); - * @throws Exception - */ - public void testComplex() throws Exception{ - newTable(); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f.addParameter( ITypeInfo.t_float, ITypeInfo.isComplex, null, false ); - - table.getCompilationUnit().addSymbol( f ); - - IParameterizedSymbol g = table.newParameterizedSymbol( "g".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - g.addParameter( ITypeInfo.t_float, 0, null, false ); - table.getCompilationUnit().addSymbol( g ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_float, ITypeInfo.isComplex, null ) ); - - IParameterizedSymbol lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - - assertEquals( lookup, f ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_float, 0, null ) ); - lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( lookup, f ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_float, ITypeInfo.isComplex, null ) ); - lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "g".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( lookup, g ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_float, ITypeInfo.isImaginary, null ) ); - lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "g".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( lookup, g ); - - lookup = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( lookup, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - public void test_Bool() throws Exception{ - newTable(); - - IParameterizedSymbol f = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f.addParameter( ITypeInfo.t__Bool, 0, null, false ); - - table.getCompilationUnit().addSymbol( f ); - - IParameterizedSymbol g = table.newParameterizedSymbol( "g".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - g.addParameter( ITypeInfo.t_int, 0, null, false ); - - table.getCompilationUnit().addSymbol( g ); - - List params = new ArrayList(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t__Bool, 0, null ) ); - - IParameterizedSymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( look, f ); - - look = table.getCompilationUnit().unqualifiedFunctionLookup( "g".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( look, g ); - - params.clear(); - params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); - look = table.getCompilationUnit().unqualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ - assertEquals( look, f ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * typedef int Int; - * void f( int i ); - * void f( Int i ); - * - * - * @throws Exception - */ - public void testBug47636FunctionParameterComparisons_1() throws Exception{ - newTable(); - - ISymbol Int = table.newSymbol( "Int".toCharArray(), ITypeInfo.t_type ); //$NON-NLS-1$ - Int.getTypeInfo().setBit( true, ITypeInfo.isTypedef ); - Int.setTypeSymbol( table.newSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY, ITypeInfo.t_int ) ); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( Int, 0, null, false ); - - assertTrue( f1.hasSameParameters( f2 ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void g( char * ); - * void g( char [] ); - */ - public void testBug47636FunctionParameterComparisons_2() throws Exception{ - newTable(); - - IParameterizedSymbol g1 = table.newParameterizedSymbol( "g".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - g1.addParameter( ITypeInfo.t_char, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - - IParameterizedSymbol g2 = table.newParameterizedSymbol( "g".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - g2.addParameter( ITypeInfo.t_char, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_array ), false ); - - assertTrue( g1.hasSameParameters( g2 ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * void h( int() ); - * void h( int (*) () ); - */ - public void testBug47636FunctionParameterComparisons_3() throws Exception{ - newTable(); - - IParameterizedSymbol f = table.newParameterizedSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY, ITypeInfo.t_function ); - f.setReturnType( table.newSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY, ITypeInfo.t_int ) ); - - IParameterizedSymbol h1 = table.newParameterizedSymbol( "h".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - h1.addParameter( f, 0, null, false ); - - IParameterizedSymbol h2 = table.newParameterizedSymbol( "h".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - h2.addParameter( f, 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ), false ); - - assertTrue( h1.hasSameParameters( h2 ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - - /** - * f( int ); - * f( const int ); - */ - public void testBug47636FunctionParameterComparisons_4() throws Exception{ - newTable(); - - IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f1.addParameter( ITypeInfo.t_int, 0, null, false ); - - IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ - f2.addParameter( ITypeInfo.t_int, ITypeInfo.isConst, null, false ); - - assertTrue( f1.hasSameParameters( f2 ) ); - assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); - } - -// public void testBug52111RemoveSymbol() throws Exception{ -// newTable(); -// -// IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ -// table.getCompilationUnit().addSymbol( A ); -// -// ISymbol i = table.newSymbol( "i".toCharArray(), ITypeInfo.t_int ); //$NON-NLS-1$ -// A.addSymbol( i ); -// -// IParameterizedSymbol f1 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ -// A.addSymbol( f1 ); -// -// IParameterizedSymbol f2 = table.newParameterizedSymbol( "f".toCharArray(), ITypeInfo.t_function ); //$NON-NLS-1$ -// f2.addParameter( ITypeInfo.t_int, 0, null, false ); -// -// A.addSymbol( f2 ); -// -// IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B".toCharArray(), ITypeInfo.t_class ); //$NON-NLS-1$ -// B.addParent( A ); -// -// table.getCompilationUnit().addSymbol( B ); -// -// ISymbol look = B.qualifiedLookup( "i".toCharArray() ); //$NON-NLS-1$ -// assertEquals( look, i ); -// -// Iterator iter = A.getContentsIterator(); -// assertEquals( iter.next(), i ); -// assertEquals( iter.next(), f1 ); -// assertEquals( iter.next(), f2 ); -// assertFalse( iter.hasNext() ); -// -// assertTrue( A.removeSymbol( i ) ); -// -// iter = A.getContentsIterator(); -// assertEquals( iter.next(), f1 ); -// assertEquals( iter.next(), f2 ); -// assertFalse( iter.hasNext() ); -// -// look = B.qualifiedLookup( "i".toCharArray() ); //$NON-NLS-1$ -// assertNull( look ); -// -// List params = new ArrayList(); -// -// look = B.qualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ -// assertEquals( look, f1 ); -// -// assertTrue( A.removeSymbol( f1 ) ); -// iter = A.getContentsIterator(); -// assertEquals( iter.next(), f2 ); -// assertFalse( iter.hasNext() ); -// -// look = B.qualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ -// assertNull( look ); -// -// params.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_int, 0, null ) ); -// look = B.qualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ -// -// assertEquals( look, f2 ); -// assertTrue( A.removeSymbol( f2 ) ); -// -// iter = A.getContentsIterator(); -// assertFalse( iter.hasNext() ); -// -// look = B.qualifiedFunctionLookup( "f".toCharArray(), params ); //$NON-NLS-1$ -// assertNull( look ); -// -// assertEquals( A.getContainedSymbols().size(), 0 ); -// assertEquals( table.getTypeInfoProvider().numAllocated(), 0 ); -// } -} - diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java index d05df5b78df..ab574a70f16 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. + * Copyright (c) 2002, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -19,44 +19,18 @@ import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests; import org.eclipse.cdt.core.parser.tests.ast2.DOMGCCParserExtensionTestSuite; import org.eclipse.cdt.core.parser.tests.ast2.DOMParserTestSuite; import org.eclipse.cdt.core.parser.tests.scanner.ScannerTestSuite; -import org.eclipse.cdt.core.parser.tests.scanner2.IncludeTest; -import org.eclipse.cdt.core.parser.tests.scanner2.ObjectMapTest; -import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test; /** - * @author jcamelon - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments + * Combines all tests for the parsers. */ public class ParserTestSuite extends TestCase { public static Test suite() { TestSuite suite= new TestSuite(ParserTestSuite.class.getName()); suite.addTestSuite(ArrayUtilsTest.class); - suite.addTestSuite(Scanner2Test.class ); - suite.addTestSuite(QuickParseASTTests.class); - suite.addTestSuite(ParserSymbolTableTest.class); - suite.addTestSuite(ParserSymbolTableTemplateTests.class ); + suite.addTestSuite(CharArrayUtilsTest.class); suite.addTestSuite(CModelElementsTests.class); suite.addTestSuite(StructuralCModelElementsTests.class); - suite.addTestSuite(CompletionParseTest.class); - suite.addTestSuite(QuickParseProblemTests.class); -// suite.addTestSuite(MacroTests.class); - suite.addTestSuite( PreprocessorConditionalTest.class ); - suite.addTestSuite( QuickParseASTQualifiedNameTest.class); - suite.addTestSuite( CompleteParseASTTest.class ); - suite.addTestSuite( CompleteParseProblemTest.class ); - suite.addTestSuite( SelectionParseTest.class ); - suite.addTestSuite( CompleteParseASTExpressionTest.class ); - suite.addTestSuite( CompleteParseASTSymbolIteratorTest.class ); - suite.addTestSuite( CompleteParseASTTemplateTest.class ); - suite.addTestSuite( StructuralParseTest.class ); - suite.addTestSuite( ObjectMapTest.class ); - suite.addTest( CompleteParsePluginTest.suite() ); - suite.addTest( IScannerInfoPluginTest.suite() ); - suite.addTestSuite( IncludeTest.class ); - suite.addTest( ScannerParserLoopTest.suite() ); - suite.addTest( GCCParserExtensionTestSuite.suite() ); + suite.addTestSuite(ObjectMapTest.class ); suite.addTest( ScannerTestSuite.suite() ); suite.addTest( DOMParserTestSuite.suite() ); suite.addTest( DOMGCCParserExtensionTestSuite.suite() ); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PerformanceTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PerformanceTests.java deleted file mode 100644 index 816af1a19ba..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PerformanceTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; - -import org.eclipse.cdt.core.parser.tests.BaseASTTest; - -/** - * @author vmozgin - * - */ -public class PerformanceTests extends BaseASTTest -{ - public PerformanceTests(String name) - { - super(name); - } - - public void testBug39523() throws Exception - { - Writer code = new StringWriter(); - try { - code.write("#define e0 \"a\"\n"); //$NON-NLS-1$ - code.write("#define e1 e0 e0 e0 e0 e0 e0 e0 e0 e0 e0\n"); //$NON-NLS-1$ - code.write("#define e2 e1 e1 e1 e1 e1 e1 e1 e1 e1 e1\n"); //$NON-NLS-1$ - code.write("#define e3 e2 e2 e2 e2 e2 e2 e2 e2 e2 e2\n"); //$NON-NLS-1$ - code.write("#define e4 e3 e3 e3 e3 e3 e3 e3 e3 e3 e3\n"); //$NON-NLS-1$ - code.write("#define e5 e4 e4 e4 e4 e4 e4 e4 e4 e4 e4\n"); //$NON-NLS-1$ - code.write("void foo() { (void)(e5); }\n"); //$NON-NLS-1$ - } catch( IOException ioe ){} - - parse(code.toString()); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java deleted file mode 100644 index 7ca2cc94cc2..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/PreprocessorConditionalTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.EndOfFileException; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.tests.scanner2.BaseScanner2Test; - -/** - * @author jcamelon - * - */ -public class PreprocessorConditionalTest extends BaseScanner2Test -{ - - private ISourceElementRequestor nullSourceElementRequestor = new NullSourceElementRequestor(); - - - protected void initializeScanner(String input, Map definitions ) throws Exception - { - scanner= ParserFactory.createScanner( new CodeReader(input.toCharArray()), new ScannerInfo( definitions ), ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, nullSourceElementRequestor, null, null ); - } - - protected void evaluateConditionalsPositive( String conditional, Map definitions ) throws Exception - { - - StringBuffer buff = new StringBuffer(); - buff.append( "#if " ); //$NON-NLS-1$ - buff.append( conditional ); - buff.append( "\n int x;\n#else\n#error NEVER\n#endif\n"); //$NON-NLS-1$ - initializeScanner( buff.toString(), definitions ); - evaluate(); - } - - protected void evaluateConditionalsNegative( String conditional, Map definitions )throws Exception - { - - StringBuffer buff = new StringBuffer(); - buff.append( "#if " ); //$NON-NLS-1$ - buff.append( conditional ); - buff.append( "\n#error NEVER\n#else\n int x;\n#endif\n"); //$NON-NLS-1$ - initializeScanner( buff.toString(), definitions ); - evaluate(); - } - - /** - * - */ - private void evaluate() throws Exception - { - try - { - validateToken( IToken.t_int ); - validateIdentifier( "x"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - scanner.nextToken(); - fail( "Should have hit EOF by now"); //$NON-NLS-1$ - } - catch( EndOfFileException eof ) - { - // expected - } - } - - - /** - * @param x - */ - public PreprocessorConditionalTest(String x) - { - super(x); - } - - public void testConditionals()throws Exception - { - Map definitions = new HashMap(); - definitions.put( "DEFED", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - definitions.put( "VALUE", "30 "); //$NON-NLS-1$ //$NON-NLS-2$ - - evaluateConditionalsPositive( "defined( DEFED )", definitions ); //$NON-NLS-1$ - evaluateConditionalsNegative( "defined( NOTDEFED )", definitions ); //$NON-NLS-1$ - - evaluateConditionalsNegative( "! defined( DEFED )", definitions ); //$NON-NLS-1$ - evaluateConditionalsPositive( "! defined( NOTDEFED )", definitions ); //$NON-NLS-1$ - - evaluateConditionalsPositive( "defined( VALUE ) && VALUE == 30", definitions ); //$NON-NLS-1$ - evaluateConditionalsNegative( "defined( VALUE ) && VALUE == 40", definitions ); //$NON-NLS-1$ - - - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTQualifiedNameTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTQualifiedNameTest.java deleted file mode 100644 index 64834ca0589..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTQualifiedNameTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; - -/** - * @author jcamelon - * - */ -public class QuickParseASTQualifiedNameTest extends BaseASTTest -{ - /** - * @param a - */ - public QuickParseASTQualifiedNameTest(String a) - { - super(a); - } - - public void testNamespace() throws Exception - { - IASTNamespaceDefinition namespace = (IASTNamespaceDefinition)assertSoleDeclaration("namespace A { namespace B { int x; } }"); //$NON-NLS-1$ - assertQualifiedName( namespace.getFullyQualifiedName(), new String [] {"A" } ); //$NON-NLS-1$ - IASTNamespaceDefinition namespace2 = (IASTNamespaceDefinition)namespace.getDeclarations().next(); - assertQualifiedName( namespace2.getFullyQualifiedName(), new String [] { "A", "B" } ); //$NON-NLS-1$ //$NON-NLS-2$ - - } - - public void testClass() throws Exception - { - IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration( "class A { class B { int a; }; };"); //$NON-NLS-1$ - IASTClassSpecifier classSpec = (IASTClassSpecifier)abs.getTypeSpecifier(); - assertQualifiedName( classSpec.getFullyQualifiedName(), new String [] { "A" } ); //$NON-NLS-1$ - Iterator subDecls = classSpec.getDeclarations(); - abs = (IASTAbstractTypeSpecifierDeclaration)subDecls.next(); - assertFalse( subDecls.hasNext() ); - classSpec = (IASTClassSpecifier)abs.getTypeSpecifier(); - assertQualifiedName( classSpec.getFullyQualifiedName(), new String [] { "A", "B" } ); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void testEnum() throws Exception - { - Iterator declarations = parse( "class A { enum E1 { enumerator = 1 }; };\n namespace N { enum E2 { enumerator = 4 }; }\n" ).getDeclarations(); //$NON-NLS-1$ - IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)declarations.next(); - IASTClassSpecifier classSpec = (IASTClassSpecifier)abs.getTypeSpecifier(); - IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier)(((IASTAbstractTypeSpecifierDeclaration)classSpec.getDeclarations().next()).getTypeSpecifier()); - assertQualifiedName( enumSpec.getFullyQualifiedName(), new String[] { "A", "E1" } ); //$NON-NLS-1$ //$NON-NLS-2$ - IASTNamespaceDefinition nms = (IASTNamespaceDefinition)declarations.next(); - enumSpec = (IASTEnumerationSpecifier)(((IASTAbstractTypeSpecifierDeclaration)nms.getDeclarations().next()).getTypeSpecifier()); - assertQualifiedName( enumSpec.getFullyQualifiedName(), new String[] { "N", "E2" } ); //$NON-NLS-1$ //$NON-NLS-2$ - assertFalse( declarations.hasNext() ); - } - - public void testVariable() throws Exception - { - IASTNamespaceDefinition topNMS = (IASTNamespaceDefinition)assertSoleDeclaration("namespace A { int x; namespace B { int y; } }"); //$NON-NLS-1$ - Iterator level1 = topNMS.getDeclarations(); - IASTVariable var = (IASTVariable)level1.next(); - assertQualifiedName( var.getFullyQualifiedName(), new String[] {"A","x"}); //$NON-NLS-1$ //$NON-NLS-2$ - Iterator level2 = ((IASTNamespaceDefinition)level1.next()).getDeclarations(); - assertFalse( level1.hasNext()); - var = (IASTVariable)level2.next(); - assertQualifiedName( var.getFullyQualifiedName(), new String[] {"A","B","y"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - public void testTypedef() throws Exception - { - IASTNamespaceDefinition topNMS = (IASTNamespaceDefinition) - assertSoleDeclaration("namespace FLEA { typedef int GODS_INT; class ANTHONY { typedef ANTHONY * tonyPointer; }; }"); //$NON-NLS-1$ - Iterator level1 = topNMS.getDeclarations(); - assertQualifiedName( ((IASTTypedefDeclaration)level1.next()).getFullyQualifiedName(), new String [] { "FLEA", "GODS_INT" } ); //$NON-NLS-1$ //$NON-NLS-2$ - assertQualifiedName( ((IASTTypedefDeclaration)((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)level1.next()).getTypeSpecifier()).getDeclarations().next()).getFullyQualifiedName(), new String [] { "FLEA", "ANTHONY", "tonyPointer" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - - public void testMembers() throws Exception - { - IASTNamespaceDefinition topNMS = - (IASTNamespaceDefinition)assertSoleDeclaration( "namespace John { class David { int Shannon; void Camelon(); }; } "); //$NON-NLS-1$ - Iterator members = - ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)topNMS.getDeclarations().next()).getTypeSpecifier()).getDeclarations(); - assertQualifiedName( ((IASTField)members.next()).getFullyQualifiedName(), new String[] { "John", "David", "Shannon" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - assertQualifiedName( ((IASTMethod)members.next()).getFullyQualifiedName(), new String[] { "John", "David", "Camelon" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - public void testFunction() throws Exception - { - IASTNamespaceDefinition topNMS = - (IASTNamespaceDefinition)assertSoleDeclaration( "namespace Bogdan { void Wears(); namespace Fancy { int Pants(); } }" ); //$NON-NLS-1$ - Iterator members = topNMS.getDeclarations(); - assertQualifiedName( ((IASTFunction)members.next()).getFullyQualifiedName(), new String[] { "Bogdan", "Wears" } ); //$NON-NLS-1$ //$NON-NLS-2$ - assertQualifiedName( ((IASTFunction)((IASTNamespaceDefinition)members.next()).getDeclarations().next()).getFullyQualifiedName(), new String[] { "Bogdan", "Fancy", "Pants" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java deleted file mode 100644 index b983f79aafb..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java +++ /dev/null @@ -1,2245 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ParserException; -/** - * @author jcamelon - * - */ -public class QuickParseASTTests extends BaseASTTest -{ - public QuickParseASTTests(String a) - { - super(a); - } - /** - * Test code: int x = 5; - * Purpose: to test the simple decaration in it's simplest form. - */ - public void testIntGlobal() throws Exception - { - // Parse and get the translation Unit - IASTCompilationUnit translationUnit = parse("int x = 5;"); //$NON-NLS-1$ - Iterator i = translationUnit.getDeclarations(); - assertTrue(i.hasNext()); - IASTVariable var = (IASTVariable)i.next(); - assertTrue( - var.getAbstractDeclaration().getTypeSpecifier() - instanceof IASTSimpleTypeSpecifier); - assertTrue( - ((IASTSimpleTypeSpecifier)var - .getAbstractDeclaration() - .getTypeSpecifier()) - .getType() - == IASTSimpleTypeSpecifier.Type.INT); - assertEquals(var.getName(), "x"); //$NON-NLS-1$ - assertNull(var.getInitializerClause()); - assertFalse(i.hasNext()); - } - /** - * Test code: class A { } a; - * Purpose: tests the use of a classSpecifier in - */ - public void testEmptyClass() throws Exception - { - // Parse and get the translation unit - Writer code = new StringWriter(); - code.write("class A { } a;"); //$NON-NLS-1$ - IASTCompilationUnit translationUnit = parse(code.toString()); - Iterator i = translationUnit.getDeclarations(); - assertTrue(i.hasNext()); - IASTVariable var = (IASTVariable)i.next(); - assertEquals(var.getName(), "a"); //$NON-NLS-1$ - assertTrue( - var.getAbstractDeclaration().getTypeSpecifier() - instanceof IASTClassSpecifier); - IASTClassSpecifier classSpec = - (IASTClassSpecifier)var.getAbstractDeclaration().getTypeSpecifier(); - assertEquals(classSpec.getName(), "A"); //$NON-NLS-1$ - assertFalse(classSpec.getDeclarations().hasNext()); - assertFalse(i.hasNext()); - } - /** - * Test code: class A { public: int x; }; - * Purpose: tests a declaration in a class scope. - */ - public void testSimpleClassMember() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("class A { public: int x; };"); //$NON-NLS-1$ - IASTCompilationUnit cu = parse(code.toString()); - Iterator i = cu.getDeclarations(); - assertTrue(i.hasNext()); - IASTAbstractTypeSpecifierDeclaration declaration = - (IASTAbstractTypeSpecifierDeclaration)i.next(); - assertFalse(i.hasNext()); - assertTrue( - declaration.getTypeSpecifier() instanceof IASTClassSpecifier); - assertTrue( - ((IASTClassSpecifier)declaration.getTypeSpecifier()).getClassKind() - == ASTClassKind.CLASS); - Iterator j = - ((IASTClassSpecifier)declaration.getTypeSpecifier()) - .getDeclarations(); - assertTrue(j.hasNext()); - IASTField field = (IASTField)j.next(); - assertFalse(j.hasNext()); - assertTrue(field.getName().equals("x")); //$NON-NLS-1$ - assertTrue( - field.getAbstractDeclaration().getTypeSpecifier() - instanceof IASTSimpleTypeSpecifier); - assertTrue( - ((IASTSimpleTypeSpecifier)field - .getAbstractDeclaration() - .getTypeSpecifier()) - .getType() - == IASTSimpleTypeSpecifier.Type.INT); - } - public void testNamespaceDefinition() throws Exception - { - for (int i = 0; i < 2; ++i) - { - IASTCompilationUnit translationUnit; - if (i == 0) - translationUnit = parse("namespace KingJohn { int x; }"); //$NON-NLS-1$ - else - translationUnit = parse("namespace { int x; }"); //$NON-NLS-1$ - Iterator iter = translationUnit.getDeclarations(); - assertTrue(iter.hasNext()); - IASTNamespaceDefinition namespaceDefinition = - (IASTNamespaceDefinition)iter.next(); - assertFalse(iter.hasNext()); - if (i == 0) - assertTrue(namespaceDefinition.getName().equals("KingJohn")); //$NON-NLS-1$ - else - assertEquals(namespaceDefinition.getName(), ""); //$NON-NLS-1$ - Iterator j = namespaceDefinition.getDeclarations(); - assertTrue(j.hasNext()); - IASTVariable var = (IASTVariable)j.next(); - assertFalse(j.hasNext()); - assertTrue( - var.getAbstractDeclaration().getTypeSpecifier() - instanceof IASTSimpleTypeSpecifier); - assertTrue( - ((IASTSimpleTypeSpecifier)var - .getAbstractDeclaration() - .getTypeSpecifier()) - .getType() - == IASTSimpleTypeSpecifier.Type.INT); - assertEquals(var.getName(), "x"); //$NON-NLS-1$ - } - } - - public void testLinkageSpecification() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - IASTCompilationUnit compilationUnit; - if( i == 0 ) - compilationUnit = parse("extern \"C\" { int x(void); }"); //$NON-NLS-1$ - else - compilationUnit = parse("extern \"ADA\" int x(void);"); //$NON-NLS-1$ - - Iterator declarations = compilationUnit.getDeclarations(); - assertTrue( declarations.hasNext() ); - IASTLinkageSpecification linkage = (IASTLinkageSpecification)declarations.next(); - assertFalse( declarations.hasNext() ); - - if( i == 0 ) - assertEquals( "C", linkage.getLinkageString() ); //$NON-NLS-1$ - else - assertEquals( "ADA", linkage.getLinkageString() ); //$NON-NLS-1$ - - Iterator subDeclarations = linkage.getDeclarations(); - assertTrue( subDeclarations.hasNext() ); - IASTFunction function = (IASTFunction)subDeclarations.next(); - assertFalse( subDeclarations.hasNext()); - - assertEquals( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( function.getName(), "x"); //$NON-NLS-1$ - - Iterator parameters = function.getParameters(); - assertTrue( parameters.hasNext() ); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - } - } - - public void testEnumSpecifier() throws Exception - { - Writer code = new StringWriter(); - code.write( "enum { yo, go = 3, away };\n"); //$NON-NLS-1$ - code.write( "enum hasAString { last = 666 };"); //$NON-NLS-1$ - IASTCompilationUnit translationUnit = parse( code.toString() ); - Iterator declarations = translationUnit.getDeclarations(); - - for( int i = 0; i < 2; ++i ) - { - assertTrue( declarations.hasNext() ); - IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declarations.next(); - IASTEnumerationSpecifier enumerationSpec = (IASTEnumerationSpecifier)abstractDeclaration.getTypeSpecifier(); - if( i == 0 ) - assertEquals( enumerationSpec.getName(), "" ); //$NON-NLS-1$ - else - assertEquals( enumerationSpec.getName(), "hasAString" ); //$NON-NLS-1$ - Iterator j = enumerationSpec.getEnumerators(); - - if( i == 0 ) - { - IASTEnumerator enumerator1 = (IASTEnumerator)j.next(); - assertEquals( enumerator1.getName(), "yo"); //$NON-NLS-1$ - assertNull( enumerator1.getInitialValue() ); - IASTEnumerator enumerator2 = (IASTEnumerator)j.next(); - assertNotNull( enumerator2.getInitialValue() ); - assertEquals( enumerator2.getInitialValue().getLiteralString(), "3"); //$NON-NLS-1$ - assertEquals( enumerator2.getInitialValue().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); - assertEquals( enumerator2.getName(), "go"); //$NON-NLS-1$ - IASTEnumerator enumerator3 = (IASTEnumerator)j.next(); - assertEquals( enumerator3.getName(), "away"); //$NON-NLS-1$ - assertNull( enumerator3.getInitialValue() ); - assertFalse( j.hasNext() ); - } - else - { - IASTEnumerator enumerator2 = (IASTEnumerator)j.next(); - assertNotNull( enumerator2.getInitialValue() ); - assertEquals( enumerator2.getInitialValue().getLiteralString(), "666"); //$NON-NLS-1$ - assertEquals( enumerator2.getInitialValue().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); - assertEquals( enumerator2.getName(), "last"); //$NON-NLS-1$ - assertFalse( j.hasNext() ); - } - } - } - - public void testTypedef() throws Exception - { - Iterator i = parse( "typedef const struct A * const cpStructA;").getDeclarations(); //$NON-NLS-1$ - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)i.next(); - assertFalse( i.hasNext() ); - assertTrue( typedef.getAbstractDeclarator().isConst() ); - assertTrue( typedef.getAbstractDeclarator().getTypeSpecifier() instanceof IASTElaboratedTypeSpecifier ); - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)typedef.getAbstractDeclarator().getTypeSpecifier(); - assertEquals( elab.getName(), "A"); //$NON-NLS-1$ - assertEquals( elab.getClassKind(), ASTClassKind.STRUCT ); - assertTrue( typedef.getAbstractDeclarator().getPointerOperators().hasNext() ); - Iterator pIter = typedef.getAbstractDeclarator().getPointerOperators(); - ASTPointerOperator po =(ASTPointerOperator)pIter.next(); - assertEquals( po, ASTPointerOperator.CONST_POINTER ); - assertFalse( pIter.hasNext() ); - assertEquals( typedef.getName(), "cpStructA"); //$NON-NLS-1$ - - } - - public void testUsingClauses() throws Exception - { - Writer code = new StringWriter(); - - code.write("using namespace A::B::C;\n"); //$NON-NLS-1$ - code.write("using namespace C;\n"); //$NON-NLS-1$ - code.write("using B::f;\n"); //$NON-NLS-1$ - code.write("using ::f;\n"); //$NON-NLS-1$ - code.write("using typename crap::de::crap;"); //$NON-NLS-1$ - Iterator declarations = parse(code.toString()).getDeclarations(); - - IASTUsingDirective usingDirective = (IASTUsingDirective)declarations.next(); - assertEquals( usingDirective.getNamespaceName(), "A::B::C" ); //$NON-NLS-1$ - - usingDirective = (IASTUsingDirective)declarations.next(); - assertEquals( usingDirective.getNamespaceName(), "C" ); //$NON-NLS-1$ - - IASTUsingDeclaration usingDeclaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( usingDeclaration.usingTypeName(), "B::f" ); //$NON-NLS-1$ - - usingDeclaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( usingDeclaration.usingTypeName(), "::f" ); //$NON-NLS-1$ - usingDeclaration = (IASTUsingDeclaration)declarations.next(); - assertEquals( usingDeclaration.usingTypeName(), "crap::de::crap" ); //$NON-NLS-1$ - assertTrue( usingDeclaration.isTypename() ); - - assertFalse( declarations.hasNext()); - } - - /** - * Test code: class A : public B, private C, virtual protected D { public: int x, y; float a,b,c; } - * Purpose: tests a declaration in a class scope. - */ - public void testSimpleClassMembers() throws Exception { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("class A : public B, private C, virtual protected D { public: int x, y; float a,b,c; };"); //$NON-NLS-1$ - Iterator declarations = parse( code.toString() ).getDeclarations(); - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertFalse( declarations.hasNext() ); - Iterator baseClauses = classSpec.getBaseClauses(); - IASTBaseSpecifier baseSpec = (IASTBaseSpecifier)baseClauses.next(); - assertEquals( baseSpec.getParentClassName(), "B" ); //$NON-NLS-1$ - assertEquals( baseSpec.getAccess(), ASTAccessVisibility.PUBLIC ); - baseSpec = (IASTBaseSpecifier)baseClauses.next(); - assertEquals( baseSpec.getParentClassName(), "C" ); //$NON-NLS-1$ - assertEquals( baseSpec.getAccess(), ASTAccessVisibility.PRIVATE); - baseSpec = (IASTBaseSpecifier)baseClauses.next(); - assertEquals( baseSpec.getAccess(), ASTAccessVisibility.PROTECTED ); - assertTrue( baseSpec.isVirtual() ); - assertEquals( baseSpec.getParentClassName(), "D" ); //$NON-NLS-1$ - assertFalse( baseClauses.hasNext() ); - - Iterator members = classSpec.getDeclarations(); - IASTField field = (IASTField)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( field.getName(), "x" ); //$NON-NLS-1$ - - field = (IASTField)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( field.getName(), "y" ); //$NON-NLS-1$ - - field = (IASTField)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); - assertEquals( field.getName(), "a" ); //$NON-NLS-1$ - field = (IASTField)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); - assertEquals( field.getName(), "b" ); //$NON-NLS-1$ - field = (IASTField)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)field.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); - assertEquals( field.getName(), "c" ); //$NON-NLS-1$ - assertFalse( members.hasNext() ); - - } - - /** - * Test code: int myFunction( void ); - */ - public void testSimpleFunctionDeclaration() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("void myFunction( void );"); //$NON-NLS-1$ - Iterator declarations = parse( code.toString()).getDeclarations(); - IASTFunction f1 = (IASTFunction)declarations.next(); - assertFalse( declarations.hasNext() ); - assertEquals( f1.getName(), "myFunction"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)f1.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); - Iterator parameters = f1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); - - } - - /** - * Test code: bool myFunction( int parm1 = 3 * 4, double parm2 ); - * @throws Exception - */ - public void testFunctionDeclarationWithParameters() throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("bool myFunction( int parm1 = 3 * 4, double parm2 );"); //$NON-NLS-1$ - Iterator declarations = parse(code.toString()).getDeclarations(); - IASTFunction f1 = (IASTFunction)declarations.next(); - assertFalse( declarations.hasNext() ); - assertEquals( f1.getName(), "myFunction"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)f1.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.BOOL ); - Iterator parameters = f1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertEquals( parm.getName(), "parm1" ); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( parm.getDefaultValue().getAssigmentExpression().getExpressionKind(), IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY ); - - parm = (IASTParameterDeclaration)parameters.next(); - assertEquals( parm.getName(), "parm2" ); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.DOUBLE ); - assertNull( parm.getDefaultValue() ); - assertFalse( parameters.hasNext()); - - } - - public void testAssignmentExpressions() throws Exception - { - parse( "int x = y = z = 5;"); //$NON-NLS-1$ - } - - public void testBug39348() throws Exception - { - parse("unsigned char a[sizeof (struct sss)];"); //$NON-NLS-1$ - } - - public void testBug39501() throws Exception - { - parse("struct A { A() throw (int); };"); //$NON-NLS-1$ - } - - public void testBug39349() throws Exception - { - parse( "enum foo { foo1 = 0, foo2 = 0xffffffffffffffffULL, foo3 = 0xf0fffffffffffffeLLU };" ); //$NON-NLS-1$ - } - - public void testBug39544() throws Exception { - parse("wchar_t wc = L'X';"); //$NON-NLS-1$ - } - - public void testBug36290() throws Exception { - parse("typedef void ( A:: * pMethod ) ( void ); "); //$NON-NLS-1$ - parse("typedef void (boo) ( void ); "); //$NON-NLS-1$ - parse("typedef void boo (void); "); //$NON-NLS-1$ - } - - public void testBug36769B() throws Exception { - parse("class X { operator int(); } \n"); //$NON-NLS-1$ - parse("class X { operator int*(); } \n"); //$NON-NLS-1$ - parse("class X { operator int&(); } \n"); //$NON-NLS-1$ - parse("class X { operator A(); } \n"); //$NON-NLS-1$ - parse("class X { operator A*(); } \n"); //$NON-NLS-1$ - parse("class X { operator A&(); } \n"); //$NON-NLS-1$ - - parse("X::operator int() { } \n"); //$NON-NLS-1$ - parse("X::operator int*() { } \n"); //$NON-NLS-1$ - parse("X::operator int&() { } \n"); //$NON-NLS-1$ - parse("X::operator A() { } \n"); //$NON-NLS-1$ - parse("X::operator A*() { } \n"); //$NON-NLS-1$ - parse("X::operator A&() { } \n"); //$NON-NLS-1$ - - parse("template class X { operator int(); } \n"); //$NON-NLS-1$ - parse("template class X { operator int*(); } \n"); //$NON-NLS-1$ - parse("template class X { operator int&(); } \n"); //$NON-NLS-1$ - parse("template class X { operator A(); } \n"); //$NON-NLS-1$ - parse("template class X { operator A*(); } \n"); //$NON-NLS-1$ - parse("template class X { operator A&(); } \n"); //$NON-NLS-1$ - - parse("template X::operator int() { } \n"); //$NON-NLS-1$ - parse("template X::operator int*() { } \n"); //$NON-NLS-1$ - parse("template X::operator int&() { } \n"); //$NON-NLS-1$ - parse("template X::operator A() { } \n"); //$NON-NLS-1$ - parse("template X::operator A*() { } \n"); //$NON-NLS-1$ - parse("template X::operator A&() { } \n"); //$NON-NLS-1$ - } - public void testBug36932C() throws Exception { - parse("X::X( ) : var( new int ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new int[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new A ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new A[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (int) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (int)[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (A) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (A)[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (0) int ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) int[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (0) A ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) A[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (0) (int) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (int)[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (0) (A) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (0) (A)[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (P) int ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) int[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (P) A ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) A[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (P) (int) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (int)[B][C][D] ) {}"); //$NON-NLS-1$ - - parse("X::X( ) : var( new (P) (A) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)(5) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)(B) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)(B,C) ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)[5] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)[5][10] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)[B] ) {}"); //$NON-NLS-1$ - parse("X::X( ) : var( new (P) (A)[B][C][D] ) {}"); //$NON-NLS-1$ - } - - - public void testBugSingleton192() throws Exception { - parse("int Test::* pMember_;" ); //$NON-NLS-1$ - } - public void testBug36931() throws Exception { - parse("A::nested::nested(){}; "); //$NON-NLS-1$ - parse("int A::nested::foo() {} "); //$NON-NLS-1$ - parse("int A::nested::operator+() {} "); //$NON-NLS-1$ - parse("A::nested::operator int() {} "); //$NON-NLS-1$ - parse("static const int A::nested::i = 1; "); //$NON-NLS-1$ - - parse("template A::nested::nested(){}; "); //$NON-NLS-1$ - parse("template int A::nested::foo() {} "); //$NON-NLS-1$ - parse("template int A::nested::operator+() {} "); //$NON-NLS-1$ - parse("template A::nested::operator int() {} "); //$NON-NLS-1$ - } - - public void testBug37019() throws Exception { - parse("static const A a( 1, 0 );"); //$NON-NLS-1$ - } - - public void testBug36766and36769A() throws Exception { - Writer code = new StringWriter(); - code.write("template \n"); //$NON-NLS-1$ - code.write("rope<_CharT, _Alloc>::rope(size_t __n, _CharT __c,\n"); //$NON-NLS-1$ - code.write("const allocator_type& __a): _Base(__a)\n"); //$NON-NLS-1$ - code.write("{}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36766and36769B() throws Exception { - Writer code = new StringWriter(); - code.write("template\n"); //$NON-NLS-1$ - code.write("bool _Rope_insert_char_consumer<_CharT>::operator()\n"); //$NON-NLS-1$ - code.write("(const _CharT* __leaf, size_t __n)\n"); //$NON-NLS-1$ - code.write("{}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36766and36769C() throws Exception { - Writer code = new StringWriter(); - code.write("template \n"); //$NON-NLS-1$ - code.write("_Rope_char_ref_proxy<_CharT, _Alloc>&\n"); //$NON-NLS-1$ - code.write( - "_Rope_char_ref_proxy<_CharT, _Alloc>::operator= (_CharT __c)\n"); //$NON-NLS-1$ - code.write("{}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36766and36769D() throws Exception { - Writer code = new StringWriter(); - code.write("template \n"); //$NON-NLS-1$ - code.write("rope<_CharT, _Alloc>::~rope()\n"); //$NON-NLS-1$ - code.write("{}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36932A() throws Exception { - parse("A::A( ) : var( new char [ (unsigned)bufSize ] ) {}"); //$NON-NLS-1$ - } - - public void testBug36932B() throws Exception { - parse(" p = new int; "); //$NON-NLS-1$ - parse(" p = new int(5); "); //$NON-NLS-1$ - parse(" p = new int(B); "); //$NON-NLS-1$ - parse(" p = new int(B,C); "); //$NON-NLS-1$ - parse(" p = new int[5]; "); //$NON-NLS-1$ - parse(" p = new int[5][10]; "); //$NON-NLS-1$ - parse(" p = new int[B]; "); //$NON-NLS-1$ - parse(" p = new int[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new A; "); //$NON-NLS-1$ - parse(" p = new A(5); "); //$NON-NLS-1$ - parse(" p = new A(B); "); //$NON-NLS-1$ - parse(" p = new A(B,C); "); //$NON-NLS-1$ - parse(" p = new A[5]; "); //$NON-NLS-1$ - parse(" p = new A[5][10]; "); //$NON-NLS-1$ - parse(" p = new A[B]; "); //$NON-NLS-1$ - parse(" p = new A[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (int); "); //$NON-NLS-1$ - parse(" p = new (int)(5); "); //$NON-NLS-1$ - parse(" p = new (int)(B); "); //$NON-NLS-1$ - parse(" p = new (int)(B,C); "); //$NON-NLS-1$ - parse(" p = new (int)[5]; "); //$NON-NLS-1$ - parse(" p = new (int)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (int)[B]; "); //$NON-NLS-1$ - parse(" p = new (int)[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (A); "); //$NON-NLS-1$ - parse(" p = new (A)(5); "); //$NON-NLS-1$ - parse(" p = new (A)(B); "); //$NON-NLS-1$ - parse(" p = new (A)(B,C); "); //$NON-NLS-1$ - parse(" p = new (A)[5]; "); //$NON-NLS-1$ - parse(" p = new (A)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (A)[B]; "); //$NON-NLS-1$ - parse(" p = new (A)[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (0) int; "); //$NON-NLS-1$ - parse(" p = new (0) int(5); "); //$NON-NLS-1$ - parse(" p = new (0) int(B); "); //$NON-NLS-1$ - parse(" p = new (0) int(B,C); "); //$NON-NLS-1$ - parse(" p = new (0) int[5]; "); //$NON-NLS-1$ - parse(" p = new (0) int[5][10]; "); //$NON-NLS-1$ - parse(" p = new (0) int[B]; "); //$NON-NLS-1$ - parse(" p = new (0) int[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (0) A; "); //$NON-NLS-1$ - parse(" p = new (0) A(5); "); //$NON-NLS-1$ - parse(" p = new (0) A(B); "); //$NON-NLS-1$ - parse(" p = new (0) A(B,C); "); //$NON-NLS-1$ - parse(" p = new (0) A[5]; "); //$NON-NLS-1$ - parse(" p = new (0) A[5][10]; "); //$NON-NLS-1$ - parse(" p = new (0) A[B]; "); //$NON-NLS-1$ - parse(" p = new (0) A[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (0) (int); "); //$NON-NLS-1$ - parse(" p = new (0) (int)(5); "); //$NON-NLS-1$ - parse(" p = new (0) (int)(B); "); //$NON-NLS-1$ - parse(" p = new (0) (int)(B,C); "); //$NON-NLS-1$ - parse(" p = new (0) (int)[5]; "); //$NON-NLS-1$ - parse(" p = new (0) (int)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (0) (int)[B]; "); //$NON-NLS-1$ - parse(" p = new (0) (int)[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (0) (A); "); //$NON-NLS-1$ - parse(" p = new (0) (A)(5); "); //$NON-NLS-1$ - parse(" p = new (0) (A)(B); "); //$NON-NLS-1$ - parse(" p = new (0) (A)(B,C); "); //$NON-NLS-1$ - parse(" p = new (0) (A)[5]; "); //$NON-NLS-1$ - parse(" p = new (0) (A)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (0) (A)[B]; "); //$NON-NLS-1$ - parse(" p = new (0) (A)[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (P) int; "); //$NON-NLS-1$ - parse(" p = new (P) int(5); "); //$NON-NLS-1$ - parse(" p = new (P) int(B); "); //$NON-NLS-1$ - parse(" p = new (P) int(B,C); "); //$NON-NLS-1$ - parse(" p = new (P) int[5]; "); //$NON-NLS-1$ - parse(" p = new (P) int[5][10]; "); //$NON-NLS-1$ - parse(" p = new (P) int[B]; "); //$NON-NLS-1$ - parse(" p = new (P) int[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (P) A; "); //$NON-NLS-1$ - parse(" p = new (P) A(5); "); //$NON-NLS-1$ - parse(" p = new (P) A(B); "); //$NON-NLS-1$ - parse(" p = new (P) A(B,C); "); //$NON-NLS-1$ - parse(" p = new (P) A[5]; "); //$NON-NLS-1$ - parse(" p = new (P) A[5][10]; "); //$NON-NLS-1$ - parse(" p = new (P) A[B]; "); //$NON-NLS-1$ - parse(" p = new (P) A[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (P) (int); "); //$NON-NLS-1$ - parse(" p = new (P) (int)(5); "); //$NON-NLS-1$ - parse(" p = new (P) (int)(B); "); //$NON-NLS-1$ - parse(" p = new (P) (int)(B,C); "); //$NON-NLS-1$ - parse(" p = new (P) (int)[5]; "); //$NON-NLS-1$ - parse(" p = new (P) (int)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (P) (int)[B]; "); //$NON-NLS-1$ - parse(" p = new (P) (int)[B][C][D]; "); //$NON-NLS-1$ - - parse(" p = new (P) (A); "); //$NON-NLS-1$ - parse(" p = new (P) (A)(5); "); //$NON-NLS-1$ - parse(" p = new (P) (A)(B); "); //$NON-NLS-1$ - parse(" p = new (P) (A)(B,C); "); //$NON-NLS-1$ - parse(" p = new (P) (A)[5]; "); //$NON-NLS-1$ - parse(" p = new (P) (A)[5][10]; "); //$NON-NLS-1$ - parse(" p = new (P) (A)[B]; "); //$NON-NLS-1$ - parse(" p = new (P) (A)[B][C][D]; "); //$NON-NLS-1$ - } - - public void testBug36769A() throws Exception { - Writer code = new StringWriter(); - code.write("template cls::operator op &() const {}\n"); //$NON-NLS-1$ - code.write("template cls::cls() {}\n"); //$NON-NLS-1$ - code.write("template cls::~cls() {}\n"); //$NON-NLS-1$ - - parse( code.toString()); - } - - public void testBug36714() throws Exception { - Writer code = new StringWriter(); - code.write("unsigned long a = 0UL;\n"); //$NON-NLS-1$ - code.write("unsigned long a2 = 0L; \n"); //$NON-NLS-1$ - - parse( code.toString() ); - } - - public void testBugFunctor758() throws Exception { - parse( "template Functor(Fun fun) : spImpl_(new FunctorHandler(fun)){}" ); //$NON-NLS-1$ - } - - public void testBug36932() throws Exception - { - parse( "A::A(): b( new int( 5 ) ), b( new B ), c( new int ) {}" ); //$NON-NLS-1$ - } - - public void testBug36704() throws Exception { - Writer code = new StringWriter(); - code.write( "template \n" ); //$NON-NLS-1$ - code.write( "struct Length< Typelist >\n" ); //$NON-NLS-1$ - code.write( "{\n" ); //$NON-NLS-1$ - code.write( "enum { value = 1 + Length::value };\n" ); //$NON-NLS-1$ - code.write( "};\n" ); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36699() throws Exception { - Writer code = new StringWriter(); - code.write( - "template < template class ThreadingModel = DEFAULT_THREADING,\n"); //$NON-NLS-1$ - code.write("std::size_t chunkSize = DEFAULT_CHUNK_SIZE,\n"); //$NON-NLS-1$ - code.write( - "std::size_t maxSmallObjectSize = MAX_SMALL_OBJECT_SIZE >\n"); //$NON-NLS-1$ - code.write("class SmallObject : public ThreadingModel<\n"); //$NON-NLS-1$ - code.write( - "SmallObject >\n"); //$NON-NLS-1$ - code.write("{};\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36691() throws Exception { - Writer code = new StringWriter(); - code.write("template \n"); //$NON-NLS-1$ - code.write( - "typename H::template Rebind::Result& Field(H& obj)\n"); //$NON-NLS-1$ - code.write("{ return obj; }\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - - - public void testBug36702() throws Exception - { - Writer code = new StringWriter(); - code.write( "void mad_decoder_init(struct mad_decoder *, void *,\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *, struct mad_stream *),\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *, struct mad_header const *),\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_stream const *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_frame *),\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_header const *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_pcm *),\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_stream *,\n" ); //$NON-NLS-1$ - code.write( " struct mad_frame *),\n" ); //$NON-NLS-1$ - code.write( " enum mad_flow (*)(void *, void *, unsigned int *)\n" ); //$NON-NLS-1$ - code.write( ");\n" ); //$NON-NLS-1$ - - parse( code.toString() ); - - } - - public void testBug36852() throws Exception - { - Writer code = new StringWriter(); - code.write( "int CBT::senseToAllRect( double id_standardQuot = DOSE, double id_minToleranz =15.0,\n" ); //$NON-NLS-1$ - code.write( "double id_maxToleranz = 15.0, unsigned int iui_minY = 0, \n" ); //$NON-NLS-1$ - code.write( "unsigned int iui_maxY = HEIGHT );\n" ); //$NON-NLS-1$ - parse( code.toString() ); - } - - public void testBug36689() throws Exception { - Writer code = new StringWriter(); - code.write("template\n"); //$NON-NLS-1$ - code.write("<\n"); //$NON-NLS-1$ - code.write("class AbstractFact,\n"); //$NON-NLS-1$ - code.write( - "template class Creator = OpNewFactoryUnit,\n"); //$NON-NLS-1$ - code.write("class TList = typename AbstractFact::ProductList\n"); //$NON-NLS-1$ - code.write(">\n"); //$NON-NLS-1$ - code.write("class ConcreteFactory\n"); //$NON-NLS-1$ - code.write(": public GenLinearHierarchy<\n"); //$NON-NLS-1$ - code.write( - "typename TL::Reverse::Result, Creator, AbstractFact>\n"); //$NON-NLS-1$ - code.write("{\n"); //$NON-NLS-1$ - code.write("public:\n"); //$NON-NLS-1$ - code.write( - "typedef typename AbstractFact::ProductList ProductList;\n"); //$NON-NLS-1$ - code.write("typedef TList ConcreteProductList;\n"); //$NON-NLS-1$ - code.write("};\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36707() throws Exception { - parse("enum { exists = sizeof(typename H::Small) == sizeof((H::Test(H::MakeT()))) };"); //$NON-NLS-1$ - } - - public void testBug36717() throws Exception { - parse("enum { eA = A::b };"); //$NON-NLS-1$ - } - - public void testBug36693() throws Exception { - parse("FixedAllocator::Chunk* FixedAllocator::VicinityFind(void* p){}"); //$NON-NLS-1$ - } - - public void testWeirdExpression() throws Exception - { - parse( "int x = rhs.spImpl_.get();"); //$NON-NLS-1$ - } - - public void testBug36696() throws Exception { - Writer code = new StringWriter(); - code.write( - "template RefCounted(const RefCounted& rhs)\n"); //$NON-NLS-1$ - code.write( - ": pCount_(reinterpret_cast(rhs).pCount_) {}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testArrayOfPointerToFunctions() throws Exception - { - parse( "unsigned char (*main_data)[MAD_BUFFER_MDLEN];"); //$NON-NLS-1$ - } - - public void testBug36073() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "class A{\n" ); //$NON-NLS-1$ - writer.write( "int x;\n" ); //$NON-NLS-1$ - writer.write( "public:\n" ); //$NON-NLS-1$ - writer.write( "A(const A&);\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "A::A(const A&v) : x(v.x) { }\n" ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - - public void testTemplateSpecialization() throws Exception - { - Iterator declarations = parse( "template<> class stream { /* ... */ };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier specifier = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)((IASTTemplateSpecialization)declarations.next()).getOwnedDeclaration()).getTypeSpecifier(); - assertFalse( declarations.hasNext()); - assertEquals( specifier.getName(), "stream"); //$NON-NLS-1$ - assertFalse( specifier.getDeclarations().hasNext() ); - } - - public void testTemplateInstantiation() throws Exception - { - Iterator declarations = parse( "template class Array;").getDeclarations(); //$NON-NLS-1$ - IASTElaboratedTypeSpecifier specifier = (IASTElaboratedTypeSpecifier)((IASTAbstractTypeSpecifierDeclaration)((IASTTemplateInstantiation)declarations.next()).getOwnedDeclaration()).getTypeSpecifier(); - assertFalse( declarations.hasNext() ); - assertEquals( specifier.getName(), "Array"); //$NON-NLS-1$ - assertEquals( specifier.getClassKind(), ASTClassKind.CLASS ); - } - - /** - * Test code: "class A { int floor( double input ), someInt; };" - */ - public void testMultipleDeclarators() throws Exception - { - // Parse and get the translaton unit - Iterator declarations = parse("class A { int floor( double input ), someInt; };").getDeclarations(); //$NON-NLS-1$ - Iterator members = ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier()).getDeclarations(); - assertFalse( declarations.hasNext() ); - IASTMethod decl1 = (IASTMethod)members.next(); - assertEquals( ((IASTSimpleTypeSpecifier)decl1.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - Iterator parameters = decl1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.DOUBLE ); - assertFalse( parameters.hasNext()); - assertEquals( parm.getName(), "input"); //$NON-NLS-1$ - - IASTField decl2 = (IASTField)members.next(); - assertEquals( decl2.getName(), "someInt"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)decl2.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertFalse( members.hasNext()); - } - - public void testFunctionModifiers() throws Exception - { - Iterator declarations = parse( "class A {virtual void foo( void ) const throw ( yay, nay, we::dont::care ) = 0;};").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertFalse( declarations.hasNext()); - Iterator members = classSpec.getDeclarations(); - IASTMethod method = (IASTMethod)members.next(); - assertFalse( members.hasNext() ); - assertTrue( method.isVirtual()); - assertEquals( method.getName(), "foo"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)method.getReturnType().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); - Iterator parameters = method.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.VOID ); - assertFalse( parameters.hasNext()); - assertEquals( parm.getName(), ""); //$NON-NLS-1$ - assertTrue( method.isConst() ); - assertTrue( method.isPureVirtual() ); - assertNotNull( method.getExceptionSpec() ); - Iterator exceptions = method.getExceptionSpec().getTypeIds(); - assertEquals( (String)exceptions.next(), "yay"); //$NON-NLS-1$ - assertEquals( (String)exceptions.next(), "nay"); //$NON-NLS-1$ - assertEquals( (String)exceptions.next(), "we::dont::care"); //$NON-NLS-1$ - assertFalse( exceptions.hasNext() ); - } - - - public void testArrays() throws Exception - { - Iterator declarations = parse("int x [5][];").getDeclarations(); //$NON-NLS-1$ - IASTVariable x = (IASTVariable)declarations.next(); - assertFalse( declarations.hasNext() ); - assertEquals( ((IASTSimpleTypeSpecifier)x.getAbstractDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( x.getName(), "x"); //$NON-NLS-1$ - Iterator arrayMods = x.getAbstractDeclaration().getArrayModifiers(); - IASTArrayModifier mod = (IASTArrayModifier)arrayMods.next(); - assertEquals( mod.getExpression().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); - assertEquals( mod.getExpression().getLiteralString(), "5" ); //$NON-NLS-1$ - mod = (IASTArrayModifier)arrayMods.next(); - assertNull( mod.getExpression()); - assertFalse( arrayMods.hasNext() ); - } - - public void testElaboratedParms() throws Exception - { - Iterator declarations = parse( "int x( struct A myA ) { /* junk */ }" ).getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)declarations.next(); - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); - Iterator parms = f.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); - assertFalse( parms.hasNext()); - assertEquals( parm.getName(), "myA"); //$NON-NLS-1$ - assertEquals( ((IASTElaboratedTypeSpecifier)parm.getTypeSpecifier()).getName(), "A" ); //$NON-NLS-1$ - assertEquals( ((IASTElaboratedTypeSpecifier)parm.getTypeSpecifier()).getClassKind(), ASTClassKind.STRUCT ); - assertFalse( declarations.hasNext()); - } - - public void testMemberDeclarations() throws Exception - { - Writer code = new StringWriter(); - code.write( "class A {\n" ); //$NON-NLS-1$ - code.write( "public:\n"); //$NON-NLS-1$ - code.write( " int is0;\n" ); //$NON-NLS-1$ - code.write( "private:\n"); //$NON-NLS-1$ - code.write( " int is1;\n" ); //$NON-NLS-1$ - code.write( "protected:\n"); //$NON-NLS-1$ - code.write( " int is2;\n" ); //$NON-NLS-1$ - code.write( "};"); //$NON-NLS-1$ - Iterator declarations = parse( code.toString()).getDeclarations(); - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertFalse(declarations.hasNext()); - Iterator members = classSpec.getDeclarations(); - for( int i = 0; i < 3; ++i ) - { - IASTField field = (IASTField)members.next(); - assertEquals( field.getName(), "is"+ new Integer( i ).toString()); //$NON-NLS-1$ - ASTAccessVisibility visibility = null; - switch( i ) - { - case 0: - visibility = ASTAccessVisibility.PUBLIC; - break; - - case 1: - visibility = ASTAccessVisibility.PRIVATE; - break; - - default: - visibility = ASTAccessVisibility.PROTECTED; - break; - } - assertEquals( field.getVisiblity(), visibility ); - } - assertFalse( members.hasNext()); - } - - public void testPointerOperators() throws Exception - { - Iterator declarations = parse("int * x = 0, & y, * const * volatile * z;").getDeclarations(); //$NON-NLS-1$ - for( int i = 0; i < 3; ++i ) - { - IASTVariable v = (IASTVariable)declarations.next(); - assertSimpleType( v, IASTSimpleTypeSpecifier.Type.INT ); - Iterator pointerOperators = v.getAbstractDeclaration().getPointerOperators(); - ASTPointerOperator pointerOp = (ASTPointerOperator)pointerOperators.next(); - - switch( i ) - { - case 0: - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertEquals( pointerOp, ASTPointerOperator.POINTER ); - assertFalse( pointerOperators.hasNext()); - break; - case 1: - assertEquals( v.getName(), "y"); //$NON-NLS-1$ - assertEquals( pointerOp, ASTPointerOperator.REFERENCE); - assertFalse( pointerOperators.hasNext()); - break; - case 2: - assertEquals( v.getName(), "z"); //$NON-NLS-1$ - assertEquals( pointerOp, ASTPointerOperator.CONST_POINTER ); - assertEquals( pointerOperators.next(), ASTPointerOperator.VOLATILE_POINTER ); - assertEquals( pointerOperators.next(), ASTPointerOperator.POINTER ); - assertFalse( pointerOperators.hasNext()); - break; - } - } - assertFalse( declarations.hasNext() ); - } - - public void testBug26467() throws Exception - { - StringWriter code = new StringWriter(); - code.write( "struct foo { int fooInt; char fooChar; };\n" ); //$NON-NLS-1$ - code.write( "typedef struct foo fooStruct;\n" ); //$NON-NLS-1$ - code.write( "typedef struct { int anonInt; char anonChar; } anonStruct;\n" ); //$NON-NLS-1$ - Iterator declarations = parse( code.toString()).getDeclarations(); - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertEquals( classSpec.getClassKind(), ASTClassKind.STRUCT); - assertEquals( classSpec.getName(), "foo" ); //$NON-NLS-1$ - Iterator members = classSpec.getDeclarations(); - IASTField field = (IASTField)members.next(); - assertSimpleType(field, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( field.getName(), "fooInt"); //$NON-NLS-1$ - field = (IASTField)members.next(); - assertSimpleType(field, IASTSimpleTypeSpecifier.Type.CHAR ); - assertEquals( field.getName(), "fooChar"); //$NON-NLS-1$ - assertFalse( members.hasNext()); - IASTTypedefDeclaration firstTypeDef = (IASTTypedefDeclaration)declarations.next(); - assertEquals( ((IASTElaboratedTypeSpecifier)firstTypeDef.getAbstractDeclarator().getTypeSpecifier()).getClassKind(), ASTClassKind.STRUCT ); - assertEquals( ((IASTElaboratedTypeSpecifier)firstTypeDef.getAbstractDeclarator().getTypeSpecifier()).getName(), "foo"); //$NON-NLS-1$ - assertEquals( firstTypeDef.getName(), "fooStruct"); //$NON-NLS-1$ - IASTTypedefDeclaration secondTypeDef = (IASTTypedefDeclaration)declarations.next(); - classSpec = (IASTClassSpecifier)secondTypeDef.getAbstractDeclarator().getTypeSpecifier(); - assertEquals( classSpec.getClassKind(), ASTClassKind.STRUCT); - assertEquals( classSpec.getName(), "" ); //$NON-NLS-1$ - members = classSpec.getDeclarations(); - field = (IASTField)members.next(); - assertSimpleType(field, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( field.getName(), "anonInt"); //$NON-NLS-1$ - field = (IASTField)members.next(); - assertSimpleType(field, IASTSimpleTypeSpecifier.Type.CHAR ); - assertEquals( field.getName(), "anonChar"); //$NON-NLS-1$ - assertFalse( members.hasNext()); - assertEquals( secondTypeDef.getName(), "anonStruct"); //$NON-NLS-1$ - - } - - public void testASMDefinition() throws Exception - { - Iterator declarations = parse( "asm( \"mov ep1 ds2\");" ).getDeclarations(); //$NON-NLS-1$ - IASTASMDefinition asm = (IASTASMDefinition)declarations.next(); - assertFalse( declarations.hasNext()); - assertEquals( asm.getBody(), "mov ep1 ds2"); //$NON-NLS-1$ - } - - public void testConstructorChain() throws Exception - { - Iterator declarations = parse( "TrafficLight_Actor::TrafficLight_Actor( RTController * rtg_rts, RTActorRef * rtg_ref ) : RTActor( rtg_rts, rtg_ref ), myId( 0 ) {}" ).getDeclarations(); //$NON-NLS-1$ - declarations.next(); // cannot properly do this test now with new callback structure in quickparse mode - } - - public void testBug36237() throws Exception - { - parse( "A::A():B( (char *)0 ){}" ); //$NON-NLS-1$ - } - - public void testBug36532() throws Exception - { - try - { - parse( "template") + 1); //$NON-NLS-1$ - - - IASTMacro m = (IASTMacro)macros.next(); - assertEquals( m.getName(), "DEF" ); //$NON-NLS-1$ - assertEquals( m.getStartingOffset(), code.indexOf("#define") ); //$NON-NLS-1$ - assertEquals( m.getNameOffset(), code.indexOf("DEF") ); //$NON-NLS-1$ - assertEquals( m.getEndingOffset(), code.indexOf("VALUE") + 5); //$NON-NLS-1$ - } - - public void testTemplateDeclarationOfFunction() throws Exception - { - Iterator declarations = parse( "template A aTemplatedFunction( B bInstance );").getDeclarations(); //$NON-NLS-1$ - IASTTemplateDeclaration templateDeclaration = (IASTTemplateDeclaration)declarations.next(); - assertFalse( declarations.hasNext()); - Iterator templateParms = templateDeclaration.getTemplateParameters(); - IASTTemplateParameter parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); - assertEquals( parm.getIdentifier(), "A"); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TYPENAME ); - assertEquals( parm.getIdentifier(), "B"); //$NON-NLS-1$ - assertEquals( parm.getDefaultValueIdExpression(), "C" ); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)templateDeclaration.getOwnedDeclaration(); - assertEquals( f.getName(), "aTemplatedFunction" ); //$NON-NLS-1$ - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); - assertEquals( ((IASTSimpleTypeSpecifier)f.getReturnType().getTypeSpecifier()).getTypename(), "A" ); //$NON-NLS-1$ - Iterator parameters = f.getParameters(); - IASTParameterDeclaration parmDeclaration = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertEquals( parmDeclaration.getName(), "bInstance"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parmDeclaration.getTypeSpecifier()).getType(),IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); - assertEquals( ((IASTSimpleTypeSpecifier)parmDeclaration.getTypeSpecifier()).getTypename(), "B" ); //$NON-NLS-1$ - } - - public void testTemplateDeclarationOfClass() throws Exception { - Iterator declarations = parse( "template class, template class AClass> class myarray { /* ... */ };").getDeclarations(); //$NON-NLS-1$ - IASTTemplateDeclaration templateDeclaration = (IASTTemplateDeclaration)declarations.next(); - assertFalse( declarations.hasNext()); - Iterator templateParms = templateDeclaration.getTemplateParameters(); - IASTTemplateParameter parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); - assertEquals( parm.getIdentifier(), "T"); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TYPENAME ); - assertEquals( parm.getIdentifier(), "Tibor"); //$NON-NLS-1$ - assertEquals( parm.getDefaultValueIdExpression(), "junk"); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); - assertEquals( parm.getIdentifier(), ""); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TYPENAME ); - assertEquals( parm.getIdentifier(), ""); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.PARAMETER ); - assertEquals( parm.getParameterDeclaration().getName(), "x"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parm.getParameterDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT ); - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.PARAMETER ); - assertEquals( parm.getParameterDeclaration().getName(), "y"); //$NON-NLS-1$ - assertEquals( ((IASTSimpleTypeSpecifier)parm.getParameterDeclaration().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.FLOAT ); - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TEMPLATE_LIST); - assertEquals( parm.getIdentifier(), ""); //$NON-NLS-1$ - Iterator subParms = parm.getTemplateParameters(); - parm = (IASTTemplateParameter)subParms.next(); - assertFalse( subParms.hasNext() ); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); - assertEquals( parm.getIdentifier(), "Y" ); //$NON-NLS-1$ - parm = (IASTTemplateParameter)templateParms.next(); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.TEMPLATE_LIST); - assertEquals( parm.getIdentifier(), "AClass"); //$NON-NLS-1$ - subParms = parm.getTemplateParameters(); - parm = (IASTTemplateParameter)subParms.next(); - assertFalse( subParms.hasNext() ); - assertEquals( parm.getTemplateParameterKind(), IASTTemplateParameter.ParamKind.CLASS ); - assertEquals( parm.getIdentifier(), "A" ); //$NON-NLS-1$ - assertFalse( templateParms.hasNext() ); - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)templateDeclaration.getOwnedDeclaration()).getTypeSpecifier(); - assertEquals( classSpec.getName(), "myarray"); //$NON-NLS-1$ - assertFalse( classSpec.getDeclarations().hasNext() ); - } - - public void testBug35906() throws Exception - { - StringWriter code = new StringWriter(); - code.write( "void TTest::MTest() {}\n" ); //$NON-NLS-1$ - code.write( "struct TTest::STest *TTest::FTest (int i) {}\n" ); //$NON-NLS-1$ - Iterator declarations = parse( code.toString() ).getDeclarations(); - IASTFunction f = (IASTFunction)declarations.next(); - assertEquals( f.getName(), "TTest::MTest"); //$NON-NLS-1$ - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.VOID ); - f = (IASTFunction)declarations.next(); - assertFalse( declarations.hasNext()); - assertEquals( f.getName(), "TTest::FTest"); //$NON-NLS-1$ - assertEquals( ((IASTElaboratedTypeSpecifier)f.getReturnType().getTypeSpecifier()).getClassKind(), ASTClassKind.STRUCT ); - assertEquals( ((IASTElaboratedTypeSpecifier)f.getReturnType().getTypeSpecifier()).getName(), "TTest::STest"); //$NON-NLS-1$ - Iterator pointerOperators = f.getReturnType().getPointerOperators(); - assertEquals( pointerOperators.next(), ASTPointerOperator.POINTER ); - assertFalse( pointerOperators.hasNext() ); - Iterator parameters = f.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertEquals( parm.getName(), "i"); //$NON-NLS-1$ - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); - } - - public void testBug36288() throws Exception - { - Iterator declarations = parse( "int foo() {}\nlong foo2(){}" ).getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)declarations.next(); - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( f.getName(), "foo"); //$NON-NLS-1$ - f = (IASTFunction)declarations.next(); - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); - assertTrue( ((IASTSimpleTypeSpecifier)f.getReturnType().getTypeSpecifier()).isLong() ); - assertEquals( f.getName(), "foo2"); //$NON-NLS-1$ - assertFalse( declarations.hasNext() ); - } - - public void testBug36250() throws Exception - { - Iterator declarations = parse( "int f( int = 0 );").getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)declarations.next(); - assertFalse( declarations.hasNext() ); - assertSimpleReturnType( f, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( f.getName(), "f"); //$NON-NLS-1$ - Iterator parameters = f.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - assertEquals( parm.getDefaultValue().getKind(), IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION ); - assertEquals( parm.getDefaultValue().getAssigmentExpression().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); - assertEquals( parm.getDefaultValue().getAssigmentExpression().getLiteralString(), "0" ); //$NON-NLS-1$ - } - - public void testBug36240() throws Exception - { - Iterator declarations = parse( "A & A::operator=( A ){}").getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)declarations.next(); - IASTSimpleTypeSpecifier typeSpec = (IASTSimpleTypeSpecifier)f.getReturnType().getTypeSpecifier(); - assertEquals( typeSpec.getType(), IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); - assertEquals( typeSpec.getTypename(), "A"); //$NON-NLS-1$ - Iterator pointerOps = f.getReturnType().getPointerOperators(); - assertEquals( pointerOps.next(), ASTPointerOperator.REFERENCE ); - assertFalse( pointerOps.hasNext() ); - assertEquals( f.getName(), "A::operator ="); //$NON-NLS-1$ - Iterator parms = f.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - typeSpec = (IASTSimpleTypeSpecifier)parm.getTypeSpecifier(); - assertEquals( typeSpec.getType(), IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); - assertEquals( typeSpec.getTypename(), "A" ); //$NON-NLS-1$ - } - - public void testBug36254() throws Exception - { - Iterator declarations = parse( "unsigned i;\nvoid f( unsigned p1 = 0 );").getDeclarations(); //$NON-NLS-1$ - IASTVariable v = (IASTVariable)declarations.next(); - assertSimpleType( v, IASTSimpleTypeSpecifier.Type.INT); - assertTrue( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).isUnsigned() ); - IASTFunction f = (IASTFunction)declarations.next(); - assertSimpleReturnType(f, IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( f.getName(), "f"); //$NON-NLS-1$ - Iterator parms = f.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); - assertEquals( parm.getName(), "p1"); //$NON-NLS-1$ - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); - assertTrue( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).isUnsigned() ); - assertEquals( parm.getDefaultValue().getKind(), IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION ); - assertEquals( parm.getDefaultValue().getAssigmentExpression().getExpressionKind(), IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ); - assertEquals( parm.getDefaultValue().getAssigmentExpression().getLiteralString(), "0" ); //$NON-NLS-1$ - assertFalse( declarations.hasNext()); - } - - public void testBug36432() throws Exception - { - Writer code = new StringWriter(); - code.write( "#define CMD_GET \"g\"\n" ); //$NON-NLS-1$ - code.write( "#define CMD_ACTION \"a\"\n" ); //$NON-NLS-1$ - code.write( "#define CMD_QUIT \"q\"\n" ); //$NON-NLS-1$ - code.write( "static const memevent_cmd_func memevent_cmd_funcs[sizeof memevent_cmds - 1] = {\n"); //$NON-NLS-1$ - code.write( "memevent_get,\n"); //$NON-NLS-1$ - code.write( "memevent_action,\n"); //$NON-NLS-1$ - code.write( "memevent_quit,\n"); //$NON-NLS-1$ - code.write( "};\n"); //$NON-NLS-1$ - parse( code.toString() ); - } - - public void testBug36594() throws Exception - { - parse( "const int n = sizeof(A) / sizeof(B);"); //$NON-NLS-1$ - } - - public void testBug36794() throws Exception - { - parse( "template<> class allocator {};"); //$NON-NLS-1$ - Iterator i = quickParseCallback.iterateOffsetableElements(); - while( i.hasNext() ) - assertNotNull( i.next() ); - } - - public void testBug36799() throws Exception - { - parse( "static const int __WORD_BIT = int(CHAR_BIT*sizeof(unsigned int));"); //$NON-NLS-1$ - } - - - public void testBug36764() throws Exception - { - parse( "struct{ int x : 4; int y : 8; };" ); //$NON-NLS-1$ - } - - public void testOrder() throws Exception - { - Writer code = new StringWriter(); - code.write( "#define __SGI_STL_INTERNAL_ALGOBASE_H\n" ); //$NON-NLS-1$ - code.write( "#include \n" ); //$NON-NLS-1$ - code.write( "template \n" ); //$NON-NLS-1$ - code.write( "inline void swap(_Tp& __a, _Tp& __b) {\n" ); //$NON-NLS-1$ - code.write( "__STL_REQUIRES(_Tp, _Assignable);\n" ); //$NON-NLS-1$ - code.write( "_Tp __tmp = __a;\n" ); //$NON-NLS-1$ - code.write( "__a = __b;\n" ); //$NON-NLS-1$ - code.write( "__b = __tmp;\n" ); //$NON-NLS-1$ - code.write( "}\n" ); //$NON-NLS-1$ - - parse( code.toString() ); - Iterator i = quickParseCallback.iterateOffsetableElements(); - assertTrue( i.hasNext() ); - assertTrue( i.next() instanceof IASTMacro ); - assertTrue( i.hasNext() ); - assertTrue( i.next() instanceof IASTInclusion ); - assertTrue( i.hasNext() ); - assertTrue( i.next() instanceof IASTDeclaration ); - assertFalse( i.hasNext() ); - } - - public void testBug36771() throws Exception { - Writer code = new StringWriter(); - code.write("#include /**/ \"foo.h\"\n"); //$NON-NLS-1$ - - parse( code.toString() ); - - Iterator includes = quickParseCallback.getInclusions(); - - IASTInclusion include = (IASTInclusion)includes.next(); - assertTrue( include.getName().equals("foo.h") ); //$NON-NLS-1$ - assertFalse( includes.hasNext() ); - } - - - public void testBug36811() throws Exception - { - Writer code = new StringWriter(); - code.write( "using namespace std;\n" ); //$NON-NLS-1$ - code.write( "class Test {};" ); //$NON-NLS-1$ - parse( code.toString() ); - Iterator i = quickParseCallback.iterateOffsetableElements(); - while( i.hasNext() ) - assertNotNull( i.next() ); - } - - public void testBug36708() throws Exception { - Iterator declarations = parse("enum { isPointer = PointerTraits::result };").getDeclarations(); //$NON-NLS-1$ - IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier)((IASTAbstractTypeSpecifierDeclaration)declarations.next()).getTypeSpecifier(); - assertFalse( declarations.hasNext() ); - Iterator enumerators = enumSpec.getEnumerators(); - IASTEnumerator enumerator = (IASTEnumerator)enumerators.next(); - assertFalse( enumerators.hasNext() ); - assertEquals( enumerator.getName(), "isPointer"); //$NON-NLS-1$ - assertEquals( enumerator.getInitialValue().getExpressionKind(), IASTExpression.Kind.ID_EXPRESSION ); - assertEquals( enumerator.getInitialValue().getIdExpression(), "PointerTraits::result"); //$NON-NLS-1$ - } - - public void testBug36690() throws Exception { - parse("Functor(const Functor& rhs) : spImpl_(Impl::Clone(rhs.spImpl_.get())){}").getDeclarations(); //$NON-NLS-1$ - } - - public void testBug36703() throws Exception { - parse("const std::type_info& Get() const;"); //$NON-NLS-1$ - } - - public void testBug36692() throws Exception { - Writer code = new StringWriter(); - code.write("template \n"); //$NON-NLS-1$ - code.write("void SetLongevity(T* pDynObject, unsigned int longevity,\n"); //$NON-NLS-1$ - code.write("Destroyer d = Private::Deleter::Delete){}\n"); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testBug36551() throws Exception - { - Writer code = new StringWriter(); - code.write( "class TextFrame {\n" ); //$NON-NLS-1$ - code.write( "BAD_MACRO()\n"); //$NON-NLS-1$ - code.write( "};"); //$NON-NLS-1$ - parse( code.toString(), true, false ); - } - - public void testBug36247() throws Exception - { - Writer code = new StringWriter(); - code.write( "class A {\n" ); //$NON-NLS-1$ - code.write( "INLINE_DEF int f ();\n" ); //$NON-NLS-1$ - code.write( "INLINE_DEF A g ();" ); //$NON-NLS-1$ - code.write( "INLINE_DEF A * h ();" ); //$NON-NLS-1$ - code.write( "INLINE_DEF A & unlock( void );"); //$NON-NLS-1$ - code.write( "};" ); //$NON-NLS-1$ - parse(code.toString()); - } - - public void testStruct() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "struct mad_bitptr { unsigned char const *byte;\n" ); //$NON-NLS-1$ - writer.write( "unsigned short cache;\n unsigned short left;};" ); //$NON-NLS-1$ - parse( writer.toString() ); - } - - public void testBug36559() throws Exception - { - Writer code = new StringWriter(); - code.write( "namespace myNameSpace {\n" ); //$NON-NLS-1$ - code.write( "template class B {};\n" ); //$NON-NLS-1$ - code.write( "template<> class B {};\n" ); //$NON-NLS-1$ - code.write( "}\n" ); //$NON-NLS-1$ - parse( code.toString() ); - } - - public void testPointersToFunctions() throws Exception - { - Writer code = new StringWriter(); - code.write( "void (*name)( void );\n"); //$NON-NLS-1$ - code.write( "static void * (* const orig_malloc_hook)(const char *file, int line, size_t size);\n"); //$NON-NLS-1$ - - Iterator declarations = parse( code.toString() ).getDeclarations(); - IASTVariable p2f = (IASTVariable)declarations.next(); - assertSimpleType( p2f, IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( p2f.getName(), "name" ); //$NON-NLS-1$ - Iterator parameters = p2f.getAbstractDeclaration().getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - - p2f = (IASTVariable)declarations.next(); - assertSimpleType( p2f, IASTSimpleTypeSpecifier.Type.VOID ); - assertTrue( p2f.isStatic() ); - Iterator rtPo = p2f.getAbstractDeclaration().getPointerOperators(); - assertEquals( rtPo.next(), ASTPointerOperator.POINTER ); - assertFalse( rtPo.hasNext() ); - parameters = p2f.getAbstractDeclaration().getParameters(); - parm = (IASTParameterDeclaration)parameters.next(); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.CHAR ); - assertEquals( parm.getName(), "file" ); //$NON-NLS-1$ - assertTrue( parm.isConst() ); - assertTrue( parm.getPointerOperators().hasNext() ); - parm = (IASTParameterDeclaration)parameters.next(); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( parm.getName(), "line" ); //$NON-NLS-1$ - parm = (IASTParameterDeclaration)parameters.next(); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ); - assertEquals( parm.getName(), "size" ); //$NON-NLS-1$ - assertFalse( parameters.hasNext() ); - } - - public void testBug36600() throws Exception - { - IASTVariable p2f = (IASTVariable)parse( "enum mad_flow (*input_func)(void *, struct mad_stream *);").getDeclarations().next(); //$NON-NLS-1$ - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier)p2f.getAbstractDeclaration().getTypeSpecifier(); - assertEquals( elab.getName(), "mad_flow"); //$NON-NLS-1$ - assertEquals( elab.getClassKind(), ASTClassKind.ENUM ); - assertEquals( p2f.getName(), "input_func"); //$NON-NLS-1$ - Iterator parms = p2f.getAbstractDeclaration().getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parms.next(); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - assertEquals( parm.getPointerOperators().next(), ASTPointerOperator.POINTER); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.VOID); - parm = (IASTParameterDeclaration)parms.next(); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - assertEquals( parm.getPointerOperators().next(), ASTPointerOperator.POINTER); - elab = (IASTElaboratedTypeSpecifier)parm.getTypeSpecifier(); - assertEquals( elab.getName(), "mad_stream"); //$NON-NLS-1$ - assertEquals( elab.getClassKind(), ASTClassKind.STRUCT ); - - - } - - public void testBug36713() throws Exception { - Writer code = new StringWriter(); - code.write("A ( * const fPtr) (void *); \n"); //$NON-NLS-1$ - code.write("A (* const fPtr2) ( A * ); \n"); //$NON-NLS-1$ - parse(code.toString()).getDeclarations(); - } - - // K&R Test hasn't been ported from DOMTests - // still need to figure out how to represent these in the AST -// public void testOldKRFunctionDeclarations() throws Exception -// { -// // Parse and get the translaton unit -// Writer code = new StringWriter(); -// code.write("bool myFunction( parm1, parm2, parm3 )\n"); -// code.write("const char* parm1;\n"); -// code.write("int (*parm2)(float);\n"); -// code.write("{}"); -// TranslationUnit translationUnit = parse(code.toString()); -// -// // Get the declaration -// List declarations = translationUnit.getDeclarations(); -// assertEquals(1, declarations.size()); -// SimpleDeclaration simpleDeclaration = (SimpleDeclaration)declarations.get(0); -// assertEquals( simpleDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_bool ); -// List declarators = simpleDeclaration.getDeclarators(); -// assertEquals( 1, declarators.size() ); -// Declarator functionDeclarator = (Declarator)declarators.get( 0 ); -// assertEquals( functionDeclarator.getName().toString(), "myFunction" ); -// -// ParameterDeclarationClause pdc = functionDeclarator.getParms(); -// assertNotNull( pdc ); -// List parameterDecls = pdc.getDeclarations(); -// assertEquals( 3, parameterDecls.size() ); -// ParameterDeclaration parm1 = (ParameterDeclaration)parameterDecls.get( 0 ); -// assertNotNull( parm1.getDeclSpecifier().getName() ); -// assertEquals( "parm1", parm1.getDeclSpecifier().getName().toString() ); -// List parm1Decls = parm1.getDeclarators(); -// assertEquals( 1, parm1Decls.size() ); -// -// ParameterDeclaration parm2 = (ParameterDeclaration)parameterDecls.get( 1 ); -// assertNotNull( parm2.getDeclSpecifier().getName() ); -// assertEquals( "parm2", parm2.getDeclSpecifier().getName().toString() ); -// List parm2Decls = parm2.getDeclarators(); -// assertEquals( 1, parm2Decls.size() ); -// -// ParameterDeclaration parm3 = (ParameterDeclaration)parameterDecls.get( 2 ); -// assertNotNull( parm3.getDeclSpecifier().getName() ); -// assertEquals( "parm3", parm3.getDeclSpecifier().getName().toString() ); -// List parm3Decls = parm3.getDeclarators(); -// assertEquals( 1, parm3Decls.size() ); -// -// OldKRParameterDeclarationClause clause = pdc.getOldKRParms(); -// assertNotNull( clause ); -// assertEquals( clause.getDeclarations().size(), 2 ); -// SimpleDeclaration decl1 = (SimpleDeclaration)clause.getDeclarations().get(0); -// assertEquals( decl1.getDeclarators().size(), 1 ); -// assertTrue(decl1.getDeclSpecifier().isConst()); -// assertFalse(decl1.getDeclSpecifier().isVolatile()); -// assertEquals( decl1.getDeclSpecifier().getType(), DeclSpecifier.t_char); -// Declarator declarator1 = (Declarator)decl1.getDeclarators().get( 0 ); -// assertEquals( declarator1.getName().toString(), "parm1" ); -// List ptrOps1 = declarator1.getPointerOperators(); -// assertNotNull( ptrOps1 ); -// assertEquals( 1, ptrOps1.size() ); -// PointerOperator po1 = (PointerOperator)ptrOps1.get(0); -// assertNotNull( po1 ); -// assertFalse( po1.isConst() ); -// assertFalse( po1.isVolatile() ); -// assertEquals( po1.getType(), PointerOperator.t_pointer ); -// -// SimpleDeclaration declaration = (SimpleDeclaration)clause.getDeclarations().get(1); -// assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_int ); -// assertEquals( declaration.getDeclarators().size(), 1); -// assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() ); -// assertNotNull( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() ); -// assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), "parm2" ); -// ParameterDeclarationClause clause2 = ((Declarator)declaration.getDeclarators().get(0)).getParms(); -// assertEquals( clause2.getDeclarations().size(), 1 ); -// assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().size(), 1 ); -// assertNull( ((Declarator)((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclarators().get(0)).getName() ); -// assertEquals( ((ParameterDeclaration)clause2.getDeclarations().get(0)).getDeclSpecifier().getType(), DeclSpecifier.t_float ); -// } - - public void testPointersToMemberFunctions() throws Exception - { - IASTVariable p2m = (IASTVariable)parse("void (A::*name)(void);").getDeclarations().next(); //$NON-NLS-1$ - assertSimpleType( p2m, IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( p2m.getName(), "A::* name"); //$NON-NLS-1$ - assertEquals( p2m.getAbstractDeclaration().getPointerToFunctionOperator(), ASTPointerOperator.POINTER); - Iterator parameters = p2m.getAbstractDeclaration().getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.next(); - assertFalse( parameters.hasNext() ); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.VOID ); - assertEquals( parm.getName(), "" ); //$NON-NLS-1$ - } - - public void testBug39550() throws Exception - { - parse("double x = 0x1.fp1;").getDeclarations().next(); //$NON-NLS-1$ - } - - // digraphs/trigraphs have been temporarily remove - public void testBug39552A(int x) throws Exception - { - Writer code = new StringWriter(); - - code.write("%:define glue(x, y) x %:%: y /* #define glue(x, y) x ## y. */\n"); //$NON-NLS-1$ - code.write("#ifndef glue\n"); //$NON-NLS-1$ - code.write("#error glue not defined!\n"); //$NON-NLS-1$ - code.write("#endif\n"); //$NON-NLS-1$ - - code.write("%:define str(x) %:x /* #define str(x) #x */\n"); //$NON-NLS-1$ - - code.write("int main (int argc, char *argv<::>) /* argv[] */\n"); //$NON-NLS-1$ - code.write("glue (<, %) /* { */\n"); //$NON-NLS-1$ - code.write(" /* di_str[] = */\n"); //$NON-NLS-1$ - code.write(" const char di_str glue(<, :)glue(:, >) = str(%:%:<::><%%>%:);\n"); //$NON-NLS-1$ - code.write(" /* Check the glue macro actually pastes, and that the spelling of\n"); //$NON-NLS-1$ - code.write(" all digraphs is preserved. */\n"); //$NON-NLS-1$ - code.write(" if (glue(strc, mp) (di_str, \"%:%:<::><%%>%:\"))\n"); //$NON-NLS-1$ - code.write(" err (\"Digraph spelling not preserved!\");\n"); //$NON-NLS-1$ - code.write(" return 0;\n"); //$NON-NLS-1$ - code.write("glue (%, >) /* } */\n"); //$NON-NLS-1$ - - parse(code.toString()); - } - - // digraphs/trigraphs have been temporarily remove - public void testBug39552B(int x) throws Exception - { - Writer code = new StringWriter(); - - code.write("??=include \n"); //$NON-NLS-1$ - code.write("??=define TWELVE 1??/\n"); //$NON-NLS-1$ - code.write("2\n"); //$NON-NLS-1$ - - code.write("static const char str??(??) = \"0123456789??/n\";\n"); //$NON-NLS-1$ - - code.write("int\n"); //$NON-NLS-1$ - code.write("main(void)\n"); //$NON-NLS-1$ - code.write("??<\n"); //$NON-NLS-1$ - code.write(" unsigned char x = 5;\n"); //$NON-NLS-1$ - code.write(" if (sizeof str != TWELVE)\n"); //$NON-NLS-1$ - code.write(" abort ();\n"); //$NON-NLS-1$ - code.write(" /* Test ^=, the only multi-character token to come from trigraphs. */\n"); //$NON-NLS-1$ - code.write(" x ??'= 3;\n"); //$NON-NLS-1$ - code.write(" if (x != 6)\n"); //$NON-NLS-1$ - code.write(" abort ();\n"); //$NON-NLS-1$ - code.write(" if ((5 ??! 3) != 7)\n"); //$NON-NLS-1$ - code.write(" abort ();\n"); //$NON-NLS-1$ - code.write(" return 0;\n"); //$NON-NLS-1$ - code.write("??>\n"); //$NON-NLS-1$ - - parse(code.toString()); - } - - public void testBug39553() throws Exception - { - parse("#define COMP_INC \"foobar.h\" \n" + "#include COMP_INC\n"); //$NON-NLS-1$ //$NON-NLS-2$ - assertTrue( quickParseCallback.getInclusions().hasNext() ); - } - - public void testBug39537() throws Exception - { - parse("typedef foo<(U::id > 0)> foobar;"); //$NON-NLS-1$ - assertTrue( quickParseCallback.getCompilationUnit().getDeclarations().hasNext() ); - } - - public void testBug39546() throws Exception - { - parse("signed char c = (signed char) 0xffffffff;"); //$NON-NLS-1$ - assertTrue( quickParseCallback.getCompilationUnit().getDeclarations().hasNext() ); - } - - public void testIndirectDeclarators() throws Exception - { - IASTVariable v = (IASTVariable)parse( "void (*x)( int );").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( v.getName(), "x"); //$NON-NLS-1$ - assertSimpleType( v, IASTSimpleTypeSpecifier.Type.VOID ); - assertParameterSimpleType( (IASTParameterDeclaration)v.getAbstractDeclaration().getParameters().next(), IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( v.getAbstractDeclaration().getPointerToFunctionOperator(), ASTPointerOperator.POINTER ); - - v = (IASTVariable)parse( "const int * (* const something)( const int * const * const );").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( v.getName(), "something"); //$NON-NLS-1$ - assertEquals( v.getAbstractDeclaration().getPointerToFunctionOperator(), ASTPointerOperator.CONST_POINTER); - assertTrue( v.getAbstractDeclaration().isConst() ); - assertSimpleType( v, IASTSimpleTypeSpecifier.Type.INT ); - assertEquals( v.getAbstractDeclaration().getPointerOperators().next(), ASTPointerOperator.POINTER ); - IASTParameterDeclaration parm = (IASTParameterDeclaration)v.getAbstractDeclaration().getParameters().next(); - assertParameterSimpleType( parm, IASTSimpleTypeSpecifier.Type.INT ); - Iterator pointerOps = parm.getPointerOperators(); - assertEquals( pointerOps.next(), ASTPointerOperator.CONST_POINTER ); - assertEquals( pointerOps.next(), ASTPointerOperator.CONST_POINTER ); - assertFalse( pointerOps.hasNext() ); - - IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)parse( "typedef void (*life)(int);").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( typedef.getName(), "life"); //$NON-NLS-1$ - assertSimpleType( typedef, IASTSimpleTypeSpecifier.Type.VOID ); - assertParameterSimpleType( (IASTParameterDeclaration)typedef.getAbstractDeclarator().getParameters().next(), IASTSimpleTypeSpecifier.Type.INT ); - - IASTFunction f = (IASTFunction)parse( "void (f)(void);").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( f.getName(), "f"); //$NON-NLS-1$ - - typedef = (IASTTypedefDeclaration)parse( "typedef void (life)(int);").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( typedef.getName(), "life"); //$NON-NLS-1$ - - } - - public void testBug39532() throws Exception - { - parse("class N1::N2::B : public A {};"); //$NON-NLS-1$ - assertTrue( quickParseCallback.getCompilationUnit().getDeclarations().hasNext() ); - } - - public void testBug39540() throws Exception - { - parse("class {} const null;"); //$NON-NLS-1$ - assertTrue( quickParseCallback.getCompilationUnit().getDeclarations().hasNext() ); - } - - public void testBug39530() throws Exception - { - parse( "X sPassed(-1)"); //$NON-NLS-1$ - } - - public void testBug39526() throws Exception - { - parse("UnitList unit_list (String(\"keV\"));"); //$NON-NLS-1$ - } - - public void testBug39535() throws Exception - { - parse("namespace bar = foo;"); //$NON-NLS-1$ - } - - public void testBug39504B() throws Exception - { - parse("int y = sizeof (int*);"); //$NON-NLS-1$ - } - public void testBug39505A() throws Exception - { - parse("int AD::* gp_down = static_cast(gp_stat);"); //$NON-NLS-1$ - } - public void testBug39505B() throws Exception - { - parse("int* gp_down = static_cast(gp_stat);"); //$NON-NLS-1$ - } - - public void testBug42985() throws Exception - { - parse( "const int x = 4; int y = ::x;"); //$NON-NLS-1$ - } - - public void testBug40419() throws Exception - { - Writer code = new StringWriter(); - try - { - code.write( "template struct SuperSubclass {\n" ); //$NON-NLS-1$ - code.write( "enum { value = (::Loki::Conversion::exists && \n" ); //$NON-NLS-1$ - code.write( "!::Loki::Conversion::sameType) }; };" ); //$NON-NLS-1$ - } catch( IOException ioe ){} - parse( code.toString() ); - } - - public void testBug39556() throws Exception - { - parse("int *restrict ip_fn (void);", true, true, ParserLanguage.C).getDeclarations().next(); //$NON-NLS-1$ - - } - - /** - * Test code: struct Example { Example(); Example(int); ~Example();}; - * Purpose: tests a declaration in a class scope. - */ - public void testBug43371 () throws Exception - { - // Parse and get the translaton unit - Writer code = new StringWriter(); - code.write("struct Example { Example(); Example(int); ~Example();};"); //$NON-NLS-1$ - IASTCompilationUnit cu = parse(code.toString()); - Iterator i = cu.getDeclarations(); - assertTrue(i.hasNext()); - IASTAbstractTypeSpecifierDeclaration declaration = - (IASTAbstractTypeSpecifierDeclaration)i.next(); - assertFalse(i.hasNext()); - assertTrue( declaration.getTypeSpecifier() instanceof IASTClassSpecifier); - assertTrue(((IASTClassSpecifier)declaration.getTypeSpecifier()).getClassKind()== ASTClassKind.STRUCT); - Iterator j =((IASTClassSpecifier)declaration.getTypeSpecifier()).getDeclarations(); - assertTrue(j.hasNext()); - IASTMethod m1 = (IASTMethod)j.next(); - IASTMethod m2 = (IASTMethod)j.next(); - IASTMethod m3 = (IASTMethod)j.next(); - assertFalse(j.hasNext()); - assertTrue(m1.getVisiblity() == ASTAccessVisibility.PUBLIC); - assertTrue(m2.getVisiblity() == ASTAccessVisibility.PUBLIC); - assertTrue(m3.getVisiblity() == ASTAccessVisibility.PUBLIC); - } - - public void testBug43644() throws Exception - { - Iterator i = parse( "void foo();{ int x; }", true, false ).getDeclarations(); //$NON-NLS-1$ - IASTFunction f = (IASTFunction)i.next(); - assertEquals( f.getName(), "foo"); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug43062() throws Exception - { - Iterator i = parse( "class X { operator short (); operator int unsigned(); operator int signed(); };").getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classX = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertFalse( i.hasNext() ); - Iterator members = classX.getDeclarations(); - IASTMethod shortMethod = (IASTMethod)members.next(); - IASTMethod unsignedMethod = (IASTMethod)members.next(); - IASTMethod signedMethod = (IASTMethod)members.next(); - assertFalse( members.hasNext() ); - assertEquals( shortMethod.getName(), "operator short"); //$NON-NLS-1$ - assertEquals( unsignedMethod.getName(), "operator int unsigned"); //$NON-NLS-1$ - assertEquals( signedMethod.getName(), "operator int signed"); //$NON-NLS-1$ - } - - public void testBug39531() throws Exception - { - parse("class AString { operator char const *() const; };"); //$NON-NLS-1$ - } - - public void testBug40007() throws Exception - { - assertCodeFailsParse("int y = #;"); //$NON-NLS-1$ - } - - public void testBug40759() throws Exception - { - IASTClassSpecifier classSpec = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration( "#define X SomeName \n class X {};" )).getTypeSpecifier(); //$NON-NLS-1$ - assertEquals( classSpec.getNameOffset() + 1, classSpec.getNameEndOffset() ); - assertEquals( classSpec.getName(), "SomeName"); //$NON-NLS-1$ - } - - public void testBug44633() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template class A {};\n" ); //$NON-NLS-1$ - writer.write( "class B { template friend class A;\n" ); //$NON-NLS-1$ - writer.write( "void method();\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - - assertTrue( i.next() instanceof IASTTemplateDeclaration ); - IASTClassSpecifier classB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - Iterator members = classB.getDeclarations(); - assertTrue (members.next() instanceof IASTTemplateDeclaration ); - assertTrue( members.next() instanceof IASTMethod ); - assertFalse( i.hasNext() ); - } - - public void testBug39525() throws Exception - { - parse("C &(C::*DD)(const C &x) = &C::operator=;"); //$NON-NLS-1$ - } - - public void testBug41935() throws Exception - { - Iterator i = parse( "namespace A { int x; } namespace B = A;" ).getDeclarations(); //$NON-NLS-1$ - assertTrue( i.next() instanceof IASTNamespaceDefinition ); - IASTNamespaceAlias a = (IASTNamespaceAlias)i.next(); - assertEquals( a.getName(), "B" ); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug39528() throws Exception - { - Writer code = new StringWriter(); - try - { - code.write("struct B: public A {\n"); //$NON-NLS-1$ - code.write(" A a;\n"); //$NON-NLS-1$ - code.write(" B() try : A(1), a(2)\n"); //$NON-NLS-1$ - code.write(" { throw 1; }\n"); //$NON-NLS-1$ - code.write(" catch (...)\n"); //$NON-NLS-1$ - code.write(" { if (c != 3) r |= 1; }\n"); //$NON-NLS-1$ - code.write("};\n"); //$NON-NLS-1$ - } - catch (IOException ioe) - { - } - IASTClassSpecifier structB = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration(code.toString())).getTypeSpecifier(); - Iterator members = structB.getDeclarations(); - assertTrue( members.next() instanceof IASTField); - IASTMethod b = (IASTMethod)members.next(); - assertFalse( members.hasNext() ); - assertTrue( b.hasFunctionTryBlock() ); - } - - public void testBug39538() throws Exception - { - parse("template C::operator int ();"); //$NON-NLS-1$ - } - - public void testBug39536() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "template\n" ); //$NON-NLS-1$ - writer.write( "class X {\n" ); //$NON-NLS-1$ - writer.write( "X(); // This fails \n" ); //$NON-NLS-1$ - writer.write( "inline X(int); // This also fails \n" ); //$NON-NLS-1$ - writer.write( "inline ~X(); // This works fine \n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - IASTTemplateDeclaration template = (IASTTemplateDeclaration)assertSoleDeclaration( writer.toString() ); - IASTClassSpecifier X = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)template.getOwnedDeclaration()).getTypeSpecifier(); - Iterator members = X.getDeclarations(); - for( int i = 0; i < 3; ++i ) - assertTrue( members.next() instanceof IASTMethod ); - assertFalse( members.hasNext() ); - } - - public void testBug39536A() throws Exception - { - IASTTemplateDeclaration template = (IASTTemplateDeclaration)parse("template class X { X(); };").getDeclarations().next(); //$NON-NLS-1$ - IASTClassSpecifier classX = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)template.getOwnedDeclaration()).getTypeSpecifier(); - IASTDeclaration d = (IASTDeclaration)classX.getDeclarations().next(); - assertTrue( d instanceof IASTMethod); - } - public void testBug39536B() throws Exception - { - parse("template class X { inline X(int); };"); //$NON-NLS-1$ - } - - public void testBug39542() throws Exception - { - parse("void f(int a, struct {int b[a];} c) {}"); //$NON-NLS-1$ - } - - //Here starts C99-specific section - public void testBug39549() throws Exception - { - parse("struct X x = { .b = 40, .z = { sizeof(X), 42 }, .t[3] = 2, .t.f[3].x = A * B };", true, true, ParserLanguage.C); //$NON-NLS-1$ - // with trailing commas - parse("struct X x = { .b = 40, .z = { sizeof(X), 42,}, .t[3] = 2, .t.f[3].x = A * B ,};", true, true, ParserLanguage.C); //$NON-NLS-1$ - } - - public void testBug39551A() throws Exception - { - IASTFunction function = (IASTFunction)parse("extern float _Complex conjf (float _Complex);", true, true, ParserLanguage.C).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( function.getName(), "conjf"); //$NON-NLS-1$ - assertTrue( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).isComplex() ); - } - - public void testBug39551B() throws Exception - { - IASTVariable variable = (IASTVariable)parse("_Imaginary double id = 99.99 * __I__;", true, true, ParserLanguage.C).getDeclarations().next(); //$NON-NLS-1$ - assertEquals( variable.getName(), "id"); //$NON-NLS-1$ - assertTrue( ((IASTSimpleTypeSpecifier)variable.getAbstractDeclaration().getTypeSpecifier()).isImaginary() ); - } - - public void testCBool() throws Exception - { - IASTVariable variable = (IASTVariable)assertSoleDeclaration( "_Bool x;", ParserLanguage.C ); //$NON-NLS-1$ - assertSimpleType( variable, IASTSimpleTypeSpecifier.Type._BOOL ); - } - - public void testBug39678() throws Exception - { - IASTVariable variable = (IASTVariable) assertSoleDeclaration("char *s = L\"a\" \"b\";"); //$NON-NLS-1$ - } - - public void testBug43110() throws Exception - { - IASTFunction function = (IASTFunction) assertSoleDeclaration( "void x( int y, ... );"); //$NON-NLS-1$ - assertTrue( function.takesVarArgs() ); - function = (IASTFunction) assertSoleDeclaration( "void x( int y... );"); //$NON-NLS-1$ - assertTrue( function.takesVarArgs() ); - } - -// public void testBug44370() throws Exception -// { -// parse( "#define SWAP(x,y) {x|=y;y|=x;x|=y;}\n"); //$NON-NLS-1$ -// Iterator macros = quickParseCallback.getMacros(); -// assertNotNull(macros); -// assertTrue( macros.hasNext()); -// IASTMacro swap = (IASTMacro) macros.next(); -// assertFalse( macros.hasNext() ); -// assertEquals( swap.getName(), "SWAP"); //$NON-NLS-1$ -// assertEquals( swap.getMacroType(), IMacroDescriptor.MacroType.FUNCTION_LIKE ); -// String [] params = swap.getParameters(); -// assertEquals( params.length, 2 ); -// assertEquals( params[0], "x"); //$NON-NLS-1$ -// assertEquals( params[1], "y"); //$NON-NLS-1$ -// String completeSignature = swap.getCompleteSignature().trim(); -// assertEquals( completeSignature, "#define SWAP(x,y) {x|=y;y|=x;x|=y;}"); //$NON-NLS-1$ -// assertEquals( swap.getExpansionSignature().trim(),"{x|=y;y|=x;x|=y;}"); //$NON-NLS-1$ -// IToken [] tokens = swap.getTokenizedExpansion(); -// validateToken( tokens[0], IToken.tLBRACE); -// validateIdentifier( tokens[1], "x"); //$NON-NLS-1$ -// validateToken( tokens[2], IToken.tBITORASSIGN ); -// validateIdentifier( tokens[3], "y"); //$NON-NLS-1$ -// validateToken( tokens[4], IToken.tSEMI ); -// validateIdentifier( tokens[5], "y"); //$NON-NLS-1$ -// validateToken( tokens[6], IToken.tBITORASSIGN ); -// validateIdentifier( tokens[7], "x"); //$NON-NLS-1$ -// validateToken( tokens[8], IToken.tSEMI ); -// validateIdentifier( tokens[9], "x"); //$NON-NLS-1$ -// validateToken( tokens[10], IToken.tBITORASSIGN ); -// validateIdentifier( tokens[11], "y"); //$NON-NLS-1$ -// validateToken( tokens[12], IToken.tSEMI ); -// validateToken( tokens[13], IToken.tRBRACE ); -// } -// /** -// * @param token -// * @param string -// */ -// private void validateIdentifier(IToken token, String identifierName ) { -// validateToken( token, IToken.tIDENTIFIER); -// assertEquals( token.getImage(), identifierName ); -// } -// /** -// * @param token -// * @param i -// */ -// private void validateToken(IToken token, int signal) { -// assertEquals( token.getType(), signal ); -// } - - public void testBug47752() throws Exception - { - parse("void func( cFoo bar ) try { } catch ( const char * error ){ }" ); //$NON-NLS-1$ - } - - public void testBug47628() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void h(char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(unsigned char) { }\n"); //$NON-NLS-1$ - writer.write( "void h(signed char) { } // not shown in outline, parsed as char\n"); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTFunction h1 = (IASTFunction) i.next(); - assertEquals( h1.getName(), "h"); //$NON-NLS-1$ - Iterator parms = h1.getParameters(); - IASTParameterDeclaration parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "char" ); //$NON-NLS-1$ - IASTFunction h2 = (IASTFunction) i.next(); - assertEquals( h2.getName(), "h"); //$NON-NLS-1$ - parms = h2.getParameters(); - parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "unsigned char" ); //$NON-NLS-1$ - - IASTFunction h3 = (IASTFunction) i.next(); - assertEquals( h3.getName(), "h"); //$NON-NLS-1$ - parms = h3.getParameters(); - parm = (IASTParameterDeclaration) parms.next(); - assertTrue( parm.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ); - assertEquals( ((IASTSimpleTypeSpecifier)parm.getTypeSpecifier()).getTypename(), "signed char" ); //$NON-NLS-1$ - - assertFalse( i.hasNext() ); - } - - public void testBug44336() throws Exception - { - Iterator i = parse( "class A {}; typedef typename A foo;" ).getDeclarations(); //$NON-NLS-1$ - IASTClassSpecifier classA = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - assertEquals( classA.getClassKind(), ASTClassKind.CLASS ); - assertEquals( classA.getName(), "A"); //$NON-NLS-1$ - IASTTypedefDeclaration typedefDeclaration = (IASTTypedefDeclaration) i.next(); - assertFalse( i.hasNext() ); - } - - public void testBug39705() throws Exception - { - parse("#ident \"@(#)filename.c 1.3 90/02/12\""); //$NON-NLS-1$ - } - - - - - - - - - public void testBug45235() throws Exception - { - Iterator i = parse( "class A { friend class B; friend void f(); }; " ).getDeclarations(); //$NON-NLS-1$ - - IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - i = A.getDeclarations(); - - IASTAbstractTypeSpecifierDeclaration forewardDecl = (IASTAbstractTypeSpecifierDeclaration)i.next(); - IASTFunction f = (IASTFunction) i.next(); - - assertTrue( forewardDecl.isFriendDeclaration() ); - assertTrue( f.isFriend() ); - } - - public void testBug59179() throws Exception - { - Iterator i = parse( "class __decl main{ int main; };", true, false ).getDeclarations(); //$NON-NLS-1$ - // Bug 66496 - added in handling for things like this - // changing assertFalse to assertTrue - // however, I don't think this is really testing the bug... - assertTrue( i.hasNext() ); - } - - public void testBug57652() throws Exception - { - parse("struct file_operations driver_fops = { open: device_open, release: device_release };", true, true, ParserLanguage.C ).getDeclarations(); //$NON-NLS-1$ - } - - public void testBug60142() throws Exception - { - IASTVariable var = (IASTVariable) assertSoleDeclaration( "unsigned long var;"); //$NON-NLS-1$ - assertEquals( var.getName(), "var"); //$NON-NLS-1$ - IASTSimpleTypeSpecifier specifier = ((IASTSimpleTypeSpecifier)var.getAbstractDeclaration().getTypeSpecifier()); - assertEquals( specifier.getTypename(), "unsigned long" ); //$NON-NLS-1$ - assertTrue( specifier.isLong() ); - assertTrue( specifier.isUnsigned() ); - assertEquals( specifier.getType(), IASTSimpleTypeSpecifier.Type.INT ); - } - - public void testBug61431() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - ParserLanguage language = ( i == 0 ) ? ParserLanguage.C : ParserLanguage.CPP; - Iterator iter = parse( "int k[][] = { {0, {1}, {2,3}};", true, false, language ).getDeclarations(); //$NON-NLS-1$ - assertFalse( iter.hasNext() ); - } - } - - public void testBadIdentifier() throws Exception - { - parse( "class 0302 { private: int stinks; };", true, false ); //$NON-NLS-1$ - } - - public void testBug67622() throws Exception - { - parse( "const char * x = __FILE__;"); //$NON-NLS-1$ - } - - public void testBug68116() throws Exception - { - StringBuffer buffer = new StringBuffer( "char dummy[] = \"0123456789" ); //$NON-NLS-1$ - for( int i = 0; i < 5000; ++i ) - buffer.append( "0123456789"); //$NON-NLS-1$ - buffer.append( "\";"); //$NON-NLS-1$ - parse( buffer.toString() ); - } - - public void testBug69161() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define MACRO(s) s\n "); //$NON-NLS-1$ - writer.write( "char *testQueries[] =\n"); //$NON-NLS-1$ - writer.write( "{\n"); //$NON-NLS-1$ - writer.write( "MACRO(\",\"),\n"); //$NON-NLS-1$ - writer.write( "MACRO(\"(\"),\n"); //$NON-NLS-1$ - writer.write( "MACRO(\")\")\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - IASTVariable t = (IASTVariable) assertSoleDeclaration( writer.toString() ); - assertTrue( quickParseCallback.problems.isEmpty() ); - assertEquals( t.getName(), "testQueries"); //$NON-NLS-1$ - } - - public void testBug73524() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "static char fmt_1002[] = \"(/,\\002At iterate\\002,i5,4x,\\002f= \\002,1p,d12\\\r\n" ); //$NON-NLS-1$ - writer.write( ".5,4x,\\002|proj g|= \\002,1p,d12.5)\";" ); //$NON-NLS-1$ - IASTVariable v = (IASTVariable) assertSoleDeclaration( writer.toString(), ParserLanguage.C ); - } - - public void testBug100992() throws Exception { - Writer writer = new StringWriter(); - writer.write( "class String { public: String(); ~String(); };"); //$NON-NLS-1$ - writer.write( "String::String(){}"); //$NON-NLS-1$ - writer.write( "String::~String(){}"); //$NON-NLS-1$ - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTAbstractTypeSpecifierDeclaration StringDecl = (IASTAbstractTypeSpecifierDeclaration) i.next(); - Iterator members = ((IASTClassSpecifier)StringDecl.getTypeSpecifier()).getDeclarations(); - IASTMethod cons_decl = (IASTMethod) members.next(); - // this unfortunately doesn't work in QUICK_PARSE -// assertTrue( cons_decl.isConstructor() ); - IASTMethod dest_decl = (IASTMethod) members.next(); -// assertTrue( dest_decl.isDestructor() ); - assertFalse( members.hasNext() ); - IASTFunction cons_defn = (IASTFunction) i.next(); - assertFalse( cons_defn instanceof IASTMethod ); - IASTFunction dest_defn = (IASTFunction) i.next(); - assertFalse( dest_defn instanceof IASTMethod ); - assertFalse( i.hasNext() ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseProblemTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseProblemTests.java deleted file mode 100644 index 6e8537ffeed..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseProblemTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import org.eclipse.cdt.core.parser.IProblem; - -/** - * @author jcamelon - * - */ -public class QuickParseProblemTests extends BaseASTTest { - - /** - * @param a - */ - public QuickParseProblemTests(String a) { - super(a); - } - - public void testBadClassName() throws Exception - { - String code = "class 12345 { };";//$NON-NLS-1$ - parse( code, true, false ); - assertFalse( quickParseCallback.problems.isEmpty() ); - assertEquals( quickParseCallback.problems.size(), 1 ); - IProblem p = (IProblem) quickParseCallback.problems.get( 0 ); - assertTrue( p.checkCategory( IProblem.SYNTAX_RELATED )); - assertEquals( p.getID(), IProblem.SYNTAX_ERROR ); - assertEquals( p.getSourceStart(), code.indexOf( "12345")); //$NON-NLS-1$ - assertEquals( p.getSourceEnd(), code.indexOf( "12345") + 5 ); //$NON-NLS-1$ - } - - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerParserLoopTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerParserLoopTest.java deleted file mode 100644 index 40fd18864c8..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerParserLoopTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Sept 30, 2004 - */ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParseError; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.core.resources.IFile; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.core.parser.ast.IASTVariable; - -/** - * @author dsteffle - */ -public class ScannerParserLoopTest extends FileBasePluginTest { - private static final int NUMBER_ITERATIONS = 30000; - - public ScannerParserLoopTest(String name) { - super(name, ScannerParserLoopTest.class); - } - - public static Test suite() { - TestSuite suite = new TestSuite(ScannerParserLoopTest.class); - suite.addTest(new ScannerParserLoopTest("cleanupProject")); //$NON-NLS-1$ - return suite; - } - - // test scanner cancel() - public void testBug72611A() throws Exception { - Writer writer = new StringWriter(); - - for (int i = 0; i < NUMBER_ITERATIONS; i++) { - writer.write("#define A"); - writer.write(String.valueOf(i)); - writer.write(" B"); - writer.write(String.valueOf(i)); - writer.write("\n"); - writer.write("#define B"); - writer.write(String.valueOf(i)); - writer.write(" C"); - writer.write(String.valueOf(i)); - writer.write("\n"); - writer.write("#define C"); - writer.write(String.valueOf(i)); - writer.write(" D"); - writer.write(String.valueOf(i)); - writer.write("\n"); - } - - runCancelTest(writer); - } - - // test parser cancel() - public void testBug72611B() throws Exception { - Writer writer = new StringWriter(); - - for (int i = 0; i < NUMBER_ITERATIONS; i++) { - writer.write("int a"); - writer.write(String.valueOf(i)); - writer.write("; // comment\n"); - } - - runCancelTest(writer); - } - - private void runCancelTest(Writer writer) throws Exception { - IFile file = importFile("code.cpp", writer.toString()); //$NON-NLS-1$ - - try { - TimeoutCallback callback = new TimeoutCallback(); - IParser parser = ParserFactory.createParser(ParserFactory - .createScanner(new CodeReader(file.getRawLocation() - .toString()), new ScannerInfo(), //$NON-NLS-1$ - ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, - callback, new NullLogService(), null), callback, - ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, null); - - callback.setParser(parser); - parser.parse(); - - assertTrue(false); // fail if parse succeeds before being cancelled - } catch (ParseError pe) { // expected - assertEquals(pe.getErrorKind(), - ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED); - } - } - - private static class TimeoutCallback extends NullSourceElementRequestor - implements ISourceElementRequestor { - private IParser parser; -// private boolean timerStarted = false; - - public void setParser(IParser parser) { - this.parser = parser; - } - - public void acceptMacro(IASTMacro macro) { - parser.cancel(); - } - - public void acceptVariable(IASTVariable variable) { - parser.cancel(); - } - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerSpeedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerSpeedTest.java deleted file mode 100644 index dd1bc0ce88b..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerSpeedTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Jun 8, 2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.cdt.core.parser.tests; - -import java.io.FileOutputStream; -import java.io.PrintStream; -import java.util.Collections; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.EndOfFileException; -import org.eclipse.cdt.core.parser.IScanner; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; - -/** - * @author Doug Schaefer - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ -public class ScannerSpeedTest extends SpeedTest { - - private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor(); - private PrintStream stream; - - public static void main(String[] args) { - try { - PrintStream stream = null; - if (args.length > 0) - stream = new PrintStream(new FileOutputStream(args[0])); - - new ScannerSpeedTest().runTest(stream, 1); - } catch (Exception e) { - System.out.println(e); - } - } - - public void test() throws Exception { - runTest(10); - } - - private void runTest(PrintStream stream, int n) throws Exception { - this.stream = stream; - runTest(n); - } - - private void runTest(int n) throws Exception { - String code = - "#include \n" + - "#include \n" + - "#include \n"; - - CodeReader reader = new CodeReader(code.toCharArray()); - IScannerInfo info = getScannerInfo(false); - long totalTime = 0; - for (int i = 0; i < n; ++i) { - long time = testScan(reader, false, info, ParserLanguage.CPP); - if (i > 0) - totalTime += time; - } - - if (n > 1) { - System.out.println("Average Time: " + (totalTime / (n - 1)) + " millisecs"); - } - } - - /** - * @param path - * @param quick TODO - */ - protected long testScan(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception { - ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; - IScanner scanner = ParserFactory.createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST ); - long startTime = System.currentTimeMillis(); - int count = 0; - try { - while (true) { - - IToken t = scanner.nextToken(); - - if (stream != null) - stream.println(t.getImage()); - - if (t == null) - break; - ++count; - - } - } catch (EndOfFileException e2) { - } - long totalTime = System.currentTimeMillis() - startTime; - System.out.println( "Resulting scan took " + totalTime + " millisecs " + - count + " tokens"); - return totalTime; - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseBaseTest.java deleted file mode 100644 index 62dd401bebd..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseBaseTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.ast.IASTNode; - -/** - * @author johnc - * - */ -public class SelectionParseBaseTest extends CompleteParseBaseTest { - - protected IASTNode parse(String code, int offset1, int offset2) throws Exception { - return parse( code, offset1, offset2, true ); - } - - /** - * @param code - * @param offset1 - * @param offset2 - * @param b - * @return - */ - protected IASTNode parse(String code, int offset1, int offset2, boolean expectedToPass) throws Exception { - callback = new FullParseCallback(); - IParser parser = null; - - parser = - ParserFactory.createParser( - ParserFactory.createScanner( - new CodeReader(code.toCharArray()), - new ScannerInfo(), - ParserMode.SELECTION_PARSE, - ParserLanguage.CPP, - callback, - new NullLogService(), null), - callback, - ParserMode.SELECTION_PARSE, - ParserLanguage.CPP, - ParserFactory.createDefaultLogService()); - - IParser.ISelectionParseResult result =parser.parse( offset1, offset2 ); - if( expectedToPass ) - { - assertNotNull( result ); - String filename = result.getFilename(); - assertNotNull( filename ); - assertTrue( !filename.equals( "")); //$NON-NLS-1$ - return (IASTNode) result.getOffsetableNamedElement(); - } - return null; - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java deleted file mode 100644 index 46916dd9389..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SelectionParseTest.java +++ /dev/null @@ -1,742 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; - -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTNamespaceDefinition; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTParameterDeclaration; - -/** - * @author jcamelon - */ -public class SelectionParseTest extends SelectionParseBaseTest { - - public void testBaseCase_VariableReference() throws Exception - { - String code = "void f() { int x; x=3; }"; //$NON-NLS-1$ - int offset1 = code.indexOf( "x=" ); //$NON-NLS-1$ - int offset2 = code.indexOf( '='); - IASTNode node = parse( code, offset1, offset2 ); - assertTrue( node instanceof IASTVariable ); - assertEquals( ((IASTVariable)node).getName(), "x" ); //$NON-NLS-1$ - } - - public void testBaseCase_FunctionReference() throws Exception - { - String code = "int x(){x( );}"; //$NON-NLS-1$ - int offset1 = code.indexOf( "x( " ); //$NON-NLS-1$ - int offset2 = code.indexOf( "( )"); //$NON-NLS-1$ - IASTNode node = parse( code, offset1, offset2 ); - assertTrue( node instanceof IASTFunction ); - assertEquals( ((IASTFunction)node).getName(), "x" ); //$NON-NLS-1$ - } - - public void testBaseCase_Error() throws Exception - { - String code = "int x() { y( ) }"; //$NON-NLS-1$ - int offset1 = code.indexOf( "y( " ); //$NON-NLS-1$ - int offset2 = code.indexOf( "( )"); //$NON-NLS-1$ - assertNull( parse( code, offset1, offset2, false )); - } - - public void testBaseCase_FunctionDeclaration() throws Exception - { - String code = "int x(); x( );"; //$NON-NLS-1$ - int offset1 = code.indexOf( "x()" ); //$NON-NLS-1$ - int offset2 = code.indexOf( "()"); //$NON-NLS-1$ - IASTNode node = parse( code, offset1, offset2 ); - assertTrue( node instanceof IASTFunction ); - assertEquals( ((IASTFunction)node).getName(), "x" ); //$NON-NLS-1$ - } - - public void testBaseCase_FunctionDeclaration2() throws Exception - { - String code = "int printf( const char *, ... ); "; //$NON-NLS-1$ - int offset1 = code.indexOf( "printf" ); //$NON-NLS-1$ - int offset2 = code.indexOf( "( const"); //$NON-NLS-1$ - IASTNode node = parse( code, offset1, offset2 ); - assertTrue( node instanceof IASTFunction ); - assertEquals( ((IASTFunction)node).getName(), "printf" ); //$NON-NLS-1$ - } - - public void testBaseCase_VariableDeclaration() throws Exception - { - String code = "int x = 3;"; //$NON-NLS-1$ - int offset1 = code.indexOf( "x" ); //$NON-NLS-1$ - int offset2 = code.indexOf( " ="); //$NON-NLS-1$ - IASTNode node = parse( code, offset1, offset2 ); - assertNotNull( node ); - assertTrue( node instanceof IASTVariable ); - assertEquals( ((IASTVariable)node).getName(), "x" ); //$NON-NLS-1$ - } - - public void testBaseCase_Parameter() throws Exception - { - String code = "int main( int argc ) { int x = argc; }"; //$NON-NLS-1$ - int offset1 = code.indexOf( "argc;" ); //$NON-NLS-1$ - int offset2 = code.indexOf( ";" ); //$NON-NLS-1$ - IASTNode node = parse( code, offset1, offset2 ); - assertNotNull( node ); - assertTrue( node instanceof IASTParameterDeclaration ); - assertEquals( ((IASTParameterDeclaration)node).getName(), "argc" ); //$NON-NLS-1$ - } - - public void testBug57898() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class Gonzo { public: void playHorn(); };\n" ); //$NON-NLS-1$ - writer.write( "void Gonzo::playHorn() { return; }\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) { Gonzo gonzo; gonzo.playHorn(); }\n" ); //$NON-NLS-1$ - String code = writer.toString(); - for( int i = 0; i < 3; ++i ) - { - int start = -1, stop = -1; - switch( i ) - { - case 0: - start = code.indexOf( "void playHorn") + 5; //$NON-NLS-1$ - break; - case 1: - start = code.indexOf( "::playHorn") + 2; //$NON-NLS-1$ - break; - case 2: - start = code.indexOf( ".playHorn") + 1; //$NON-NLS-1$ - break; - } - stop = start + 8; - IASTNode node = parse( code, start, stop ); - assertNotNull( node ); - assertTrue( node instanceof IASTMethod ); - IASTMethod method = (IASTMethod) node; - assertEquals( method.getName(), "playHorn"); //$NON-NLS-1$ - IASTClassSpecifier gonzo = method.getOwnerClassSpecifier(); - assertEquals( gonzo.getName(), "Gonzo"); //$NON-NLS-1$ - } - } - - public void testConstructorDestructorDeclaration() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class Gonzo { Gonzo(); ~Gonzo(); };"); //$NON-NLS-1$ - String code = writer.toString(); - int offset = code.indexOf( " Gonzo()") + 1; //$NON-NLS-1$ - IASTNode node = parse( code, offset, offset + 5 ); - assertNotNull( node ); - assertTrue( node instanceof IASTMethod ); - IASTMethod constructor = ((IASTMethod)node); - assertEquals( constructor.getName(), "Gonzo" ); //$NON-NLS-1$ - assertTrue( constructor.isConstructor() ); - offset = code.indexOf( "~Gonzo"); //$NON-NLS-1$ - node = parse( code, offset, offset + 6 ); - assertNotNull( node ); - assertTrue( node instanceof IASTMethod ); - IASTMethod destructor = ((IASTMethod)node); - assertEquals( destructor.getName(), "~Gonzo" ); //$NON-NLS-1$ - assertTrue( destructor.isDestructor() ); - } - - public void testBug60264() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "namespace Muppets { int i; }\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) { Muppets::i = 1; }\n" ); //$NON-NLS-1$ - String code = writer.toString(); - int index = code.indexOf( "Muppets::"); //$NON-NLS-1$ - IASTNode node = parse( code, index, index + 7 ); - assertNotNull( node ); - assertTrue( node instanceof IASTNamespaceDefinition ); - IASTNamespaceDefinition namespace = (IASTNamespaceDefinition) node; - assertEquals( namespace.getName(), "Muppets"); //$NON-NLS-1$ - assertEquals( namespace.getStartingLine(), 1 ); - - index = code.indexOf( "e Muppets") + 2; //$NON-NLS-1$ - node = parse( code, index, index + 7 ); - assertTrue( node instanceof IASTNamespaceDefinition ); - namespace = (IASTNamespaceDefinition) node; - assertEquals( namespace.getName(), "Muppets"); //$NON-NLS-1$ - assertEquals( namespace.getStartingLine(), 1 ); - - } - - public void testBug61613() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class Foo { // ** (A) **\n" ); //$NON-NLS-1$ - writer.write( " public:\n" ); //$NON-NLS-1$ - writer.write( "Foo() {};\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "int \n" ); //$NON-NLS-1$ - writer.write( "main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( "Foo foo; // ** (B) **\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - String code = writer.toString(); - int index = code.indexOf( "class Foo") + 6; //$NON-NLS-1$ - IASTNode node = parse( code, index, index + 3 ); - assertTrue( node instanceof IASTClassSpecifier ); - IASTClassSpecifier foo = (IASTClassSpecifier) node; - assertEquals( foo.getName(), "Foo"); //$NON-NLS-1$ - } - - public void testBug60038() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class Gonzo {\n"); //$NON-NLS-1$ - writer.write( "public:\n"); //$NON-NLS-1$ - writer.write( "Gonzo( const Gonzo & other ){}\n"); //$NON-NLS-1$ - writer.write( "Gonzo() {}\n"); //$NON-NLS-1$ - writer.write( "~Gonzo(){}\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {\n"); //$NON-NLS-1$ - writer.write( " Gonzo * g = new Gonzo();\n"); //$NON-NLS-1$ - writer.write( " Gonzo * g2 = new Gonzo( *g );\n"); //$NON-NLS-1$ - writer.write( " g->~Gonzo();\n"); //$NON-NLS-1$ - writer.write( " return (int) g2;\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - String code = writer.toString(); - for( int i = 0; i < 3; ++i ) - { - int startOffset = 0, endOffset = 0; - switch( i ) - { - case 0: - startOffset = code.indexOf( "new Gonzo()") + 4; //$NON-NLS-1$ - endOffset = startOffset + 5; - break; - case 1: - startOffset = code.indexOf( "new Gonzo( ") + 4; //$NON-NLS-1$ - endOffset = startOffset + 5; - break; - default: - startOffset = code.indexOf( "->~") + 2; //$NON-NLS-1$ - endOffset = startOffset + 6; - } - IASTNode node = parse( code, startOffset, endOffset ); - assertTrue( node instanceof IASTMethod ); - IASTMethod method = (IASTMethod) node; - switch( i ) - { - case 0: - case 1: - assertTrue( method.isConstructor() ); - assertFalse( method.isDestructor() ); - break; - default: - assertFalse( method.isConstructor() ); - assertTrue( method.isDestructor() ); - break; - - } - } - } - - public void testMethodReference() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class Sample { public:\n"); //$NON-NLS-1$ - writer.write( " int getAnswer() const;\n"); //$NON-NLS-1$ - writer.write( "};\n"); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( " Sample * s = new Sample();\n" ); //$NON-NLS-1$ - writer.write( " return s->getAnswer();\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - String code = writer.toString(); - int startIndex = code.indexOf( "->getAnswer") + 2; //$NON-NLS-1$ - IASTNode node = parse( code, startIndex, startIndex+9); - assertTrue( node instanceof IASTMethod ); - assertEquals( ((IASTMethod)node).getName(), "getAnswer" ); //$NON-NLS-1$ - } - - public void testConstructorDefinition() throws Exception - { - String code = "class ABC { public: ABC(); }; ABC::ABC(){}"; //$NON-NLS-1$ - int startIndex = code.indexOf( "::ABC") + 2; //$NON-NLS-1$ - IASTNode node = parse( code, startIndex, startIndex + 3 ); - assertTrue( node instanceof IASTMethod ); - IASTMethod constructor = (IASTMethod) node; - assertTrue( constructor.isConstructor() ); - } - - public void testBug63966() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "void foo(int a) {}\n" ); //$NON-NLS-1$ - writer.write( "void foo(long a) {}\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( "foo(1); \n }" ); //$NON-NLS-1$ - String code = writer.toString(); - int startIndex = code.indexOf( "foo(1)"); //$NON-NLS-1$ - parse( code, startIndex, startIndex + 3 ); - } - - public void testBug66744() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "enum EColours { RED, GREEN, BLUE }; \n" ); //$NON-NLS-1$ - writer.write( "void foo() { EColours color = GREEN; } \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int startIndex = code.indexOf( "EColours color"); //$NON-NLS-1$ - parse( code, startIndex, startIndex + 8 ); - } - - - - public void testBug68527() throws Exception - { - Writer writer = new StringWriter(); - writer.write("struct X;\n"); //$NON-NLS-1$ - writer.write("struct X anA;"); //$NON-NLS-1$ - String code = writer.toString(); - int startIndex = code.indexOf( "X anA"); //$NON-NLS-1$ - parse( code, startIndex, startIndex + 1 ); - } - - public void testBug60407() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "struct ZZZ { int x, y, z; };\n" ); //$NON-NLS-1$ - writer.write( "typedef struct ZZZ _FILE;\n" ); //$NON-NLS-1$ - writer.write( "typedef _FILE FILE;\n" ); //$NON-NLS-1$ - writer.write( "static void static_function(FILE * lcd){}\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( "FILE * file = 0;\n" ); //$NON-NLS-1$ - writer.write( "static_function( file );\n" ); //$NON-NLS-1$ - writer.write( "return 0;\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - String code = writer.toString(); - int startIndex = code.indexOf( "static_function( file )"); //$NON-NLS-1$ - parse( code, startIndex, startIndex + "static_function".length() ); //$NON-NLS-1$ - } - - public void testBug61800() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class B {};\n"); //$NON-NLS-1$ - writer.write( "class ABCDEF {\n"); //$NON-NLS-1$ - writer.write( " static B stInt; };\n"); //$NON-NLS-1$ - writer.write( "B ABCDEF::stInt = 5;\n"); //$NON-NLS-1$ - String code = writer.toString(); - int startIndex = code.indexOf( "::stInt") + 2; //$NON-NLS-1$ - - IASTNode node = parse( code, startIndex, startIndex+ 5 ); - assertTrue( node instanceof IASTField ); - assertEquals( ((IASTField)node).getName(), "stInt" ); //$NON-NLS-1$ - } - - public void testBug68739() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "int fprintf( int *, const char *, ... ); \n" ); //$NON-NLS-1$ - writer.write( "void boo( int * lcd ) { \n" ); //$NON-NLS-1$ - writer.write( " /**/fprintf( lcd, \"%c%s 0x%x\", ' ', \"bbb\", 2 ); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String code = writer.toString(); - int startIndex = code.indexOf( "/**/fprintf") + 4; //$NON-NLS-1$ - - IASTNode node = parse( code, startIndex, startIndex+ 7 ); - - assertTrue( node instanceof IASTFunction ); - assertEquals( ((IASTFunction)node).getName(), "fprintf" ); //$NON-NLS-1$ - } - - public void testBug72818() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "union Squaw { int x; double u; };\n" ); //$NON-NLS-1$ - writer.write( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$ - writer.write( "return sizeof( Squaw );\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - String code = writer.toString(); - int startIndex = code.indexOf( "sizeof( ") + "sizeof( ".length(); //$NON-NLS-1$ //$NON-NLS-2$ - IASTNode node = parse( code, startIndex, startIndex + 5 ); - assertTrue( node instanceof IASTClassSpecifier ); - IASTClassSpecifier classSpecifier = (IASTClassSpecifier) node; - assertEquals( classSpecifier.getClassKind(), ASTClassKind.UNION ); - assertEquals( classSpecifier.getName(), "Squaw"); //$NON-NLS-1$ - } - - public void test72220() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "const int FOUND_ME = 1;\n" ); //$NON-NLS-1$ - writer.write( "class Test{\n" ); //$NON-NLS-1$ - writer.write( "public:\n" ); //$NON-NLS-1$ - writer.write( "const int findCode() const;\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "const int Test::findCode() const {\n" ); //$NON-NLS-1$ - writer.write( "return FOUND_ME;\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - String code = writer.toString(); - int startIndex = code.indexOf( "return ") + "return ".length(); //$NON-NLS-1$ //$NON-NLS-2$ - IASTNode node = parse( code, startIndex, startIndex + 8 ); - assertTrue( node instanceof IASTVariable ); - assertEquals( ((IASTVariable)node).getName(), "FOUND_ME" ); //$NON-NLS-1$ - } - - public void testBug72721() throws Exception{ - Writer writer = new StringWriter(); - writer.write(" class ABC { public: ABC(int); }; \n"); //$NON-NLS-1$ - writer.write("void f() { \n"); //$NON-NLS-1$ - writer.write(" int j = 1; \n"); //$NON-NLS-1$ - writer.write(" new ABC( j + 1 ); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - - String code = writer.toString(); - int startIndex = code.indexOf( "ABC(" ); //$NON-NLS-1$ - IASTNode node = parse( code, startIndex, startIndex + 3 ); - assertTrue( node instanceof IASTMethod ); - assertEquals( ((IASTMethod)node).getName(), "ABC" ); //$NON-NLS-1$ - assertTrue( ((IASTMethod)node).isConstructor() ); - } - - public void testBug72372() throws Exception{ - Writer writer = new StringWriter(); - writer.write("namespace B { \n"); //$NON-NLS-1$ - writer.write(" class SD_02 { void f_SD(); }; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("using namespace B; \n"); //$NON-NLS-1$ - writer.write("void SD_02::f_SD(){} \n"); //$NON-NLS-1$ - - String code = writer.toString(); - int startIndex = code.indexOf( ":f_SD" ); //$NON-NLS-1$ - IASTNode node = parse( code, startIndex + 1, startIndex + 5 ); - assertTrue( node instanceof IASTMethod ); - assertEquals( ((IASTMethod)node).getName(), "f_SD" ); //$NON-NLS-1$ - } - public void testBug72372_2() throws Exception{ - Writer writer = new StringWriter(); - writer.write("namespace A { \n"); //$NON-NLS-1$ - writer.write(" namespace B { \n"); //$NON-NLS-1$ - writer.write(" void f_SD(); \n"); //$NON-NLS-1$ - writer.write(" } \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("namespace C { \n"); //$NON-NLS-1$ - writer.write(" using namespace A; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("void C::B::f_SD(){} \n"); //$NON-NLS-1$ - - String code = writer.toString(); - int startIndex = code.indexOf( ":f_SD" ); //$NON-NLS-1$ - IASTNode node = parse( code, startIndex + 1, startIndex + 5 ); - assertTrue( node instanceof IASTFunction ); - assertEquals( ((IASTFunction)node).getName(), "f_SD" ); //$NON-NLS-1$ - } - - public void testBug72713() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "class Deck{ void initialize(); }; \n"); //$NON-NLS-1$ - writer.write( "void Deck::initialize(){} \n"); //$NON-NLS-1$ - - String code = writer.toString(); - int startIndex = code.indexOf( ":initialize" ); //$NON-NLS-1$ - IASTNode node = parse( code, startIndex + 1, startIndex + 11 ); - assertTrue( node instanceof IASTMethod ); - assertFalse( ((IASTMethod)node).previouslyDeclared() ); - assertEquals( ((IASTMethod) node).getNameOffset(), code.indexOf( " initialize();" ) + 1 ); //$NON-NLS-1$ - } - - public void testBug72712() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "class B{ public: B(); }; void f(){ B* b; b = new B(); }" ); //$NON-NLS-1$ - - String code = writer.toString(); - int startIndex = code.indexOf( "new B" ) + 4; //$NON-NLS-1$ - - IASTNode node = parse( code, startIndex, startIndex + 1 ); - assertTrue( node instanceof IASTMethod ); - assertTrue( ((IASTMethod) node).isConstructor() ); - } - - public void testBug72712_2() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "class A {}; \n"); //$NON-NLS-1$ - writer.write( "class B{ public: B( A* ); }; \n"); //$NON-NLS-1$ - writer.write( "void f(){ B* b; b = new B( (A*)0 ); } \n"); //$NON-NLS-1$ - - String code = writer.toString(); - int startIndex = code.indexOf( "(A*)" ) + 1; //$NON-NLS-1$ - - IASTNode node = parse( code, startIndex, startIndex + 1 ); - assertTrue( node instanceof IASTClassSpecifier ); - assertEquals( ((IASTClassSpecifier)node).getName(), "A" ); //$NON-NLS-1$ - } - - public void testBug72814() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "namespace N{ \n"); //$NON-NLS-1$ - writer.write( " template < class T > class AAA { T _t };\n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - writer.write( "N::AAA a; \n"); //$NON-NLS-1$ - - String code = writer.toString(); - int startIndex = code.indexOf( "AAA" ); //$NON-NLS-1$ - IASTNode node = parse( code, startIndex, startIndex + 3 ); - - assertTrue( node instanceof IASTClassSpecifier ); - assertEquals( ((IASTClassSpecifier)node).getName(), "AAA" ); //$NON-NLS-1$ - - node = parse( code, startIndex, startIndex + 8 ); - - assertTrue( node instanceof IASTClassSpecifier ); - assertEquals( ((IASTClassSpecifier)node).getName(), "AAA" ); //$NON-NLS-1$ - } - - public void testBug72710() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "class Card{\n" ); //$NON-NLS-1$ - writer.write( " Card( int rank );\n" ); //$NON-NLS-1$ - writer.write( " int rank;\n" ); //$NON-NLS-1$ - writer.write( "};\n" ); //$NON-NLS-1$ - writer.write( "Card::Card( int rank ) {\n" ); //$NON-NLS-1$ - writer.write( "this->rank = rank;\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - String code = writer.toString(); - int index = code.indexOf( "this->rank") + 6; //$NON-NLS-1$ - IASTNode node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTField ); - IASTField rank = (IASTField) node; - assertEquals( rank.getName(), "rank"); //$NON-NLS-1$ - } - - - public void testBug75731() throws Exception - { - Writer writer = new StringWriter(); - writer.write("int rank() {\n"); //$NON-NLS-1$ - writer.write("return 5;\n}\n"); //$NON-NLS-1$ - writer.write("class Card{\n"); //$NON-NLS-1$ - writer.write("private:\n"); //$NON-NLS-1$ - writer.write("Card( int rank );\n"); //$NON-NLS-1$ - writer.write("int rank;\n"); //$NON-NLS-1$ - writer.write("public:\n"); //$NON-NLS-1$ - writer.write("int getRank();\n};\n"); //$NON-NLS-1$ - writer.write("Card::Card( int rank )\n{\n"); //$NON-NLS-1$ - writer.write("this->rank = ::rank();\n"); //$NON-NLS-1$ - writer.write("this->rank = this->rank;\n"); //$NON-NLS-1$ - writer.write("this->rank = rank;\n"); //$NON-NLS-1$ - writer.write("this->rank = Card::rank;\n"); //$NON-NLS-1$ - writer.write("this->rank = getRank();\n}\n"); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "int rank() {") + 4; //$NON-NLS-1$ - IASTNode node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTFunction ); - IASTFunction rank1 = (IASTFunction) node; - assertEquals( rank1.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank1.getNameOffset(), index ); - - index = code.indexOf( "class Card{") + 6; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTClassSpecifier ); - IASTClassSpecifier card1 = (IASTClassSpecifier) node; - assertEquals( card1.getName(), "Card"); //$NON-NLS-1$ - assertEquals( card1.getNameOffset(), index ); - - index = code.indexOf( "Card( int rank );"); //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTMethod ); - IASTMethod card2 = (IASTMethod) node; - assertEquals( card2.getName(), "Card"); //$NON-NLS-1$ - assertEquals( card2.getNameOffset(), index ); - - index = code.indexOf( "Card( int rank );") + 10; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTParameterDeclaration ); - IASTParameterDeclaration rank2 = (IASTParameterDeclaration) node; - assertEquals( rank2.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank2.getNameOffset(), index ); - - index = code.indexOf( "int rank;") + 4; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTField ); - IASTField rank3 = (IASTField) node; - assertEquals( rank3.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank3.getNameOffset(), index ); - - index = code.indexOf( "int getRank();") + 4; //$NON-NLS-1$ - node = parse( code, index, index + 7 ); - assertTrue( node instanceof IASTMethod ); - IASTMethod getRank1 = (IASTMethod) node; - assertEquals( getRank1.getName(), "getRank"); //$NON-NLS-1$ - assertEquals( getRank1.getNameOffset(), index ); - - index = code.indexOf( "Card::Card( int rank )"); //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTClassSpecifier ); - IASTClassSpecifier card3 = (IASTClassSpecifier) node; - assertEquals( card3.getName(), "Card"); //$NON-NLS-1$ - assertEquals( card3.getNameOffset(), card1.getNameOffset() ); - - index = code.indexOf( "Card::Card( int rank )") + 6; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTMethod ); - IASTMethod card4 = (IASTMethod) node; - assertEquals( card4.getName(), "Card"); //$NON-NLS-1$ - assertEquals( card4.getNameOffset(), card2.getNameOffset() ); - - index = code.indexOf( "Card::Card( int rank )") + 16; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTParameterDeclaration ); - IASTParameterDeclaration rank4 = (IASTParameterDeclaration) node; - assertEquals( rank4.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank4.getNameOffset(), index ); - - index = code.indexOf( "this->rank = ::rank();") + 6; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTField ); - IASTField rank5 = (IASTField) node; - assertEquals( rank5.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank5.getNameOffset(), rank3.getNameOffset() ); - - index = code.indexOf( "this->rank = ::rank();") + 15; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTFunction ); - IASTFunction rank6 = (IASTFunction) node; - assertEquals( rank6.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank6.getNameOffset(), rank1.getNameOffset() ); - - index = code.indexOf( "this->rank = this->rank;") + 6; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTField ); - IASTField rank7 = (IASTField) node; - assertEquals( rank7.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank7.getNameOffset(), rank3.getNameOffset() ); - - index = code.indexOf( "this->rank = this->rank;") + 19; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTField ); - IASTField rank8 = (IASTField) node; - assertEquals( rank8.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank8.getNameOffset(), rank3.getNameOffset() ); - - index = code.indexOf( "this->rank = rank;") + 6; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTField ); - IASTField rank9 = (IASTField) node; - assertEquals( rank9.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank9.getNameOffset(), rank3.getNameOffset() ); - - index = code.indexOf( "this->rank = rank;") + 13; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTParameterDeclaration ); - IASTParameterDeclaration rank10 = (IASTParameterDeclaration) node; - assertEquals( rank10.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank10.getNameOffset(), rank4.getNameOffset() ); - - index = code.indexOf( "this->rank = Card::rank;") + 6; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTField ); - IASTField rank11 = (IASTField) node; - assertEquals( rank11.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank11.getNameOffset(), rank3.getNameOffset() ); - - index = code.indexOf( "this->rank = Card::rank;") + 19; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTField ); - IASTField rank12 = (IASTField) node; - assertEquals( rank12.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank12.getNameOffset(), rank3.getNameOffset() ); - - index = code.indexOf( "this->rank = getRank();") + 6; //$NON-NLS-1$ - node = parse( code, index, index + 4 ); - assertTrue( node instanceof IASTField ); - IASTField rank13 = (IASTField) node; - assertEquals( rank13.getName(), "rank"); //$NON-NLS-1$ - assertEquals( rank13.getNameOffset(), rank3.getNameOffset() ); - - index = code.indexOf( "this->rank = getRank();") + 13; //$NON-NLS-1$ - node = parse( code, index, index + 7 ); - assertTrue( node instanceof IASTMethod ); - IASTMethod getRank2 = (IASTMethod) node; - assertEquals( getRank2.getName(), "getRank"); //$NON-NLS-1$ - assertEquals( getRank2.getNameOffset(), getRank1.getNameOffset() ); - } - - public void testBug77989() throws Exception { - Writer writer = new StringWriter(); - writer.write("namespace N { /* A */\n"); //$NON-NLS-1$ - writer.write("class C{};\n}\n"); //$NON-NLS-1$ - writer.write("using namespace N; /* B */\n"); //$NON-NLS-1$ - writer.write("N::C c; /* C */\n"); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "using namespace N;") + 16; //$NON-NLS-1$ - IASTNode node = parse( code, index, index + 1 ); - assertTrue( node instanceof ASTNamespaceDefinition ); - ASTNamespaceDefinition n = (ASTNamespaceDefinition) node; - assertEquals( n.getName(), "N"); //$NON-NLS-1$ - assertEquals( n.getNameOffset(), 10 ); - assertEquals( n.getStartingLine(), 1 ); - } - - public void testBug78435() throws Exception { - Writer writer = new StringWriter(); - writer.write("int itself; //A\n"); //$NON-NLS-1$ - writer.write("void f(int itself){} //B\n"); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf( "void f(int itself){}") + 11; //$NON-NLS-1$ - IASTNode node = parse( code, index, index + 6 ); - assertTrue( node instanceof ASTParameterDeclaration ); - ASTParameterDeclaration n = (ASTParameterDeclaration) node; - assertEquals( n.getName(), "itself"); //$NON-NLS-1$ - assertEquals( n.getNameOffset(), 36 ); - assertEquals( n.getStartingLine(), 2 ); - } - - public void testBug78231A() throws Exception { - Writer writer = new StringWriter(); - writer.write("struct Base {\n"); //$NON-NLS-1$ - writer.write("int Data; // 1\n"); //$NON-NLS-1$ - writer.write("struct Data; // 2\n};\n"); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf("struct Data;") + 7; //$NON-NLS-1$ - IASTNode node = parse( code, index, index + 4 ); - assertTrue(node instanceof IASTOffsetableNamedElement); - IASTOffsetableNamedElement n = (IASTOffsetableNamedElement)node; - assertEquals(n.getName(), "Data"); //$NON-NLS-1$ - assertEquals(n.getNameOffset(), 36); - assertEquals(n.getStartingLine(), 3); - } - - public void testBug78231B() throws Exception { - Writer writer = new StringWriter(); - writer.write("int Data;\n"); //$NON-NLS-1$ - writer.write("struct Base {\n"); //$NON-NLS-1$ - writer.write("int Data; // 1\n"); //$NON-NLS-1$ - writer.write("struct Data; // 2\n};\n"); //$NON-NLS-1$ - - String code = writer.toString(); - int index = code.indexOf("struct Data;") + 7; //$NON-NLS-1$ - IASTNode node = parse( code, index, index + 4 ); - assertTrue(node instanceof IASTOffsetableNamedElement); - IASTOffsetableNamedElement n = (IASTOffsetableNamedElement)node; - assertEquals(n.getName(), "Data"); //$NON-NLS-1$ - assertEquals(n.getNameOffset(), 46); - assertEquals(n.getStartingLine(), 4); - } -} - diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SpeedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SpeedTest.java deleted file mode 100644 index b289d2c09b6..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/SpeedTest.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.util.Collections; -import java.util.Hashtable; -import java.util.Map; - -import junit.framework.TestCase; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IScanner; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; - -// A test that just calculates the speed of the parser -// Eventually, we'll peg a max time and fail the test if it exceeds it -public class SpeedTest extends TestCase { - - public static void main(String[] args) { - try { - new SpeedTest().runTest(1); - } catch (Exception e) { - System.out.println(e); - } - } - - public void test() throws Exception { - runTest(20); - } - - private void runTest(int n) throws Exception { - String code = - "#include \n" + - "#include \n" + - "#include \n"; - - CodeReader reader = new CodeReader(code.toCharArray()); - IScannerInfo info = getScannerInfo(false); - long totalTime = 0; - for (int i = 0; i < n; ++i) { - long time = testParse(reader, false, info, ParserLanguage.CPP); - if (i > 4) - totalTime += time; - } - - if (n > 5) { - System.out.println("Average Time: " + (totalTime / (n - 5)) + " millisecs"); - } - } - - /** - * @param path - * @param quick TODO - */ - protected long testParse(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception { - ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; - IScanner scanner = ParserFactory.createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST ); - IParser parser = ParserFactory.createParser( scanner, CALLBACK, mode, lang, null); - long startTime = System.currentTimeMillis(); - long totalTime; - parser.parse(); - totalTime = System.currentTimeMillis() - startTime; - System.out.println( "Resulting parse took " + totalTime + " millisecs " + - scanner.getCount() + " tokens"); - return totalTime; - } - - private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor(); - - protected IScannerInfo getScannerInfo(boolean quick) { - if (quick) - return new ScannerInfo(); - - String config = System.getProperty("speedTest.config"); - - if (config == null) - return mingwScannerInfo(false); - - if (config.equals("msvc")) - return msvcScannerInfo(false); - else if (config.equals("ydl")) - return ydlScannerInfo(false); - else - return mingwScannerInfo(false); - } - - private IScannerInfo msvcScannerInfo(boolean quick) { - if( quick ) - return new ScannerInfo(); - Map definitions = new Hashtable(); - //definitions.put( "__GNUC__", "3" ); //$NON-NLS-1$ //$NON-NLS-2$ - - String [] includePaths = new String[] { - "C:\\Program Files\\Microsoft SDK\\Include", - "C:\\Program Files\\Microsoft Visual C++ Toolkit 2003\\include" - }; - return new ScannerInfo( definitions, includePaths ); - } - - private IScannerInfo mingwScannerInfo(boolean quick) { - // TODO It would be easier and more flexible if we used discovery for this - if( quick ) - return new ScannerInfo(); - Map definitions = new Hashtable(); - definitions.put("__GNUC__", "3"); - definitions.put("__GNUC_MINOR__", "2"); - definitions.put("__GNUC_PATCHLEVEL__", "3"); - definitions.put("__GXX_ABI_VERSION", "102"); - definitions.put("_WIN32", ""); - definitions.put("__WIN32", ""); - definitions.put("__WIN32__", ""); - definitions.put("WIN32", ""); - definitions.put("__MINGW32__", ""); - definitions.put("__MSVCRT__", ""); - definitions.put("WINNT", ""); - definitions.put("_X86_", "1"); - definitions.put("__WINNT", ""); - definitions.put("_NO_INLINE__", ""); - definitions.put("__STDC_HOSTED__", "1"); - definitions.put("i386", ""); - definitions.put("__i386", ""); - definitions.put("__i386__", ""); - definitions.put("__tune_i586__", ""); - definitions.put("__tune_pentium__", ""); - definitions.put("__stdcall", "__attribute__((__stdcall__))"); - definitions.put("__cdecl", "__attribute__((__cdecl__))"); - definitions.put("__fastcall", "__attribute__((__fastcall__))"); - definitions.put("_stdcall", "__attribute__((__stdcall__))"); - definitions.put("_cdecl", "__attribute__((__cdecl__))"); - definitions.put("_fastcall", "__attribute__((__fastcall__))"); - definitions.put("__declspec(x)", "__attribute__((x))"); - definitions.put("__DEPRECATED", ""); - definitions.put("__EXCEPTIONS", ""); - - String [] includePaths = new String[] { - "c:/mingw/include/c++/3.2.3", - "c:/mingw/include/c++/3.2.3/mingw32", - "c:/mingw/include/c++/3.2.3/backward", - "c:/mingw/include", - "c:/mingw/lib/gcc-lib/mingw32/3.2.3/include" - }; - - return new ScannerInfo( definitions, includePaths ); - } - - private IScannerInfo ydlScannerInfo(boolean quick) { - // TODO It would be easier and more flexible if we used discovery for this - if( quick ) - return new ScannerInfo(); - Map definitions = new Hashtable(); - definitions.put("__GNUC__", "3"); - definitions.put("__GNUC_MINOR__", "3"); - definitions.put("__GNUC_PATCHLEVEL__", "3"); - definitions.put("_GNU_SOURCE", ""); - definitions.put("__unix__", ""); - definitions.put("__gnu_linux__", ""); - definitions.put("__linux__", ""); - definitions.put("unix", ""); - definitions.put("__unix", ""); - definitions.put("linux", ""); - definitions.put("__linux", ""); - definitions.put("__GNUG__", "3"); - - String [] includePaths = new String[] { - "/usr/include/g++", - "/usr/include/g++/powerpc-yellowdog-linux", - "/usr/include/g++/backward", - "/usr/local/include", - "/usr/lib/gcc-lib/powerpc-yellowdog-linux/3.3.3/include", - "/usr/include" - }; - - return new ScannerInfo( definitions, includePaths ); - } - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/StructuralParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/StructuralParseTest.java deleted file mode 100644 index c9b82087d49..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/StructuralParseTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on Apr 29, 2004 - */ -package org.eclipse.cdt.core.parser.tests; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.Iterator; - -import junit.framework.TestCase; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ParserException; -import org.eclipse.cdt.internal.core.parser.StructuralParseCallback; - -/** - * @author aniefer - */ -public class StructuralParseTest extends TestCase { - - public StructuralParseTest() - { - super(); - } - - protected StructuralParseCallback callback; - - protected IASTCompilationUnit parse( String code ) throws ParserException, ParserFactoryError - { - return parse( code, true, ParserLanguage.CPP ); - } - - protected IASTCompilationUnit parse( String code, boolean throwOnError ) throws ParserException, ParserFactoryError - { - return parse( code, throwOnError, ParserLanguage.CPP ); - } - - protected IASTCompilationUnit parse(String code, boolean throwOnError, ParserLanguage language) throws ParserException, ParserFactoryError - { - callback = new StructuralParseCallback(); - IParser parser = ParserFactory.createParser( - ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), //$NON-NLS-1$ - ParserMode.STRUCTURAL_PARSE, language, callback, new NullLogService(), null ), - callback, ParserMode.STRUCTURAL_PARSE, language, null - ); - if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ - return callback.getCompilationUnit(); - } - - public void testBug60149() throws Exception - { - IASTCompilationUnit cu = parse( "extern \"C\" { int v; } " ); //$NON-NLS-1$ - - Iterator i = cu.getDeclarations(); - - IASTLinkageSpecification ls = (IASTLinkageSpecification) i.next(); - assertFalse( i.hasNext() ); - - i = ls.getDeclarations(); - IASTVariable v = (IASTVariable) i.next(); - assertEquals( v.getName(), "v" ); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug60480() throws Exception - { - IASTCompilationUnit cu = parse( "template < int > void foo();" ); //$NON-NLS-1$ - Iterator i = cu.getDeclarations(); - - IASTTemplateDeclaration template = (IASTTemplateDeclaration) i.next(); - assertFalse( i.hasNext() ); - - IASTFunction foo = (IASTFunction) template.getOwnedDeclaration(); - assertEquals( foo.getName(), "foo" ); //$NON-NLS-1$ - } - - public void testBug77010() throws Exception - { - Writer writer = new StringWriter(); - writer.write(" struct Example{ \n"); //$NON-NLS-1$ - writer.write(" int *deref(); \n"); //$NON-NLS-1$ - writer.write(" int const *deref() const; \n"); //$NON-NLS-1$ - writer.write(" int volatile *deref() volatile; \n"); //$NON-NLS-1$ - writer.write(" int const volatile *deref() const volatile; \n"); //$NON-NLS-1$ - writer.write(" }; \n"); //$NON-NLS-1$ - - Iterator i = parse( writer.toString() ).getDeclarations(); - IASTClassSpecifier Ex = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); - - i = Ex.getDeclarations(); - IASTMethod deref = (IASTMethod) i.next(); - assertFalse( deref.getReturnType().isConst() ); - assertFalse( deref.getReturnType().isVolatile() ); - assertFalse( deref.isConst() ); - assertFalse( deref.isVolatile() ); - - deref = (IASTMethod) i.next(); - assertTrue( deref.getReturnType().isConst() ); - assertFalse( deref.getReturnType().isVolatile() ); - assertTrue( deref.isConst() ); - assertFalse( deref.isVolatile() ); - - deref = (IASTMethod) i.next(); - assertFalse( deref.getReturnType().isConst() ); - assertTrue( deref.getReturnType().isVolatile() ); - assertFalse( deref.isConst() ); - assertTrue( deref.isVolatile() ); - - deref = (IASTMethod) i.next(); - assertTrue( deref.getReturnType().isConst() ); - assertTrue( deref.getReturnType().isVolatile() ); - assertTrue( deref.isConst() ); - assertTrue( deref.isVolatile() ); - assertFalse( i.hasNext() ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java deleted file mode 100644 index e869a780a41..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java +++ /dev/null @@ -1,289 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.StringWriter; -import java.util.NoSuchElementException; -import java.util.StringTokenizer; - -import junit.framework.AssertionFailedError; -import junit.framework.Test; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.testplugin.CTestPlugin; -import org.eclipse.core.runtime.Path; - - -/** - * @author vmozgin - * - * Automated parser test framework, to use with GCC testsuites - */ -public class TortureTest extends FractionalAutomatedTest { - - static protected boolean isEnabled = false; - static protected boolean quickParse = true; - - public TortureTest () { - super(); - } - - public TortureTest (String name) { - super(name); - } - - protected AutomatedFramework newTest (String name){ - return new TortureTest (name); - } - - protected void loadProperties() throws Exception{ - String resourcePath = CTestPlugin.getDefault().find(new Path("/")).getFile(); //$NON-NLS-1$ //$NON-NLS-2$ - resourcePath += "resources/parser/TortureTest"; //$NON-NLS-1$ - - try { - FileInputStream propertiesIn = new FileInputStream(resourcePath + "/TortureTest.properties"); //$NON-NLS-1$ - properties.load (propertiesIn); - - isEnabled = properties.getProperty("enabled", "false").equalsIgnoreCase("true"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - quickParse = properties.getProperty("quickParse", "true").equalsIgnoreCase("true"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - String sourceInfo = properties.getProperty("source", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - stepSize = Integer.parseInt(properties.getProperty("stepSize", "25000")); //$NON-NLS-1$ //$NON-NLS-2$ - outputFile = properties.getProperty("outputFile", ""); //$NON-NLS-1$ //$NON-NLS-2$ - timeOut = Integer.parseInt(properties.getProperty("timeOut", "60000")); //$NON-NLS-1$ //$NON-NLS-2$ - outputDir = properties.getProperty("outDir", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - if (sourceInfo.equals("")) //$NON-NLS-1$ - throw new FileNotFoundException(); - - StringTokenizer tokenizer = new StringTokenizer(sourceInfo, ","); //$NON-NLS-1$ - String str = null, val = null; - try { - while (tokenizer.hasMoreTokens()) { - str = tokenizer.nextToken().trim(); - val = tokenizer.nextToken().trim(); - - testSources.put(str, val); - } - } catch (NoSuchElementException e){ - //only way to get here is to have a missing val, assume cpp for that str - testSources.put(str, "cpp"); //$NON-NLS-1$ - } - } catch (FileNotFoundException e){ - testSources.put(resourcePath, "cpp"); //$NON-NLS-1$ - } - - if (!isEnabled) testSources.clear(); - } - - - public static Test suite() - { - AutomatedFramework frame = new TortureTest(); - return frame.createSuite(); - } - - - static protected void reportException (Throwable e, String file, IParser parser){ - String output = null; - int lineNumber = -1; - - lineNumber = parser.getLastErrorLine(); - - if (e instanceof AssertionFailedError) { - output = file + ": Parse failed on line "; //$NON-NLS-1$ - output += lineNumber + "\n"; //$NON-NLS-1$ - } else { - output = file + ": " + e.getClass().toString(); //$NON-NLS-1$ - output += " on line " + lineNumber + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ - } - try { - if (report != null) { - report.write(output.getBytes()); - } - } catch (IOException ex) {} - - fail(output); - } - - - static protected boolean isExpectedToPass (String testCode, File file) - { - String fileName = file.getName(); - - // Filter out gcc-specific tests that are not easy to detect automatically - if ( fileName.equals("init-2.c") //$NON-NLS-1$ - || fileName.equals("init-3.c") //$NON-NLS-1$ - || fileName.equals("struct-ini-4.c")) { //$NON-NLS-1$ - - // gcc-specific (and deprecated) designated initializers - // struct { int e1, e2; } v = { e2: 0 }; - - return false; - } - - if ( fileName.equals("stmtexpr3.C")) { //$NON-NLS-1$ - - // statements in expressions - // B() : a(({ 1; })) {} - - return false; - } - - if ( fileName.equals("widechar-1.c")) { //$NON-NLS-1$ - - // concatenation of incompatible literals - // char *s = L"a" "b"; - - return false; - } - - if ( fileName.equals("bf-common.h") //$NON-NLS-1$ - || fileName.equals("class-tests-1.h") //$NON-NLS-1$ - || fileName.equals("unclaimed-category-1.h")) { //$NON-NLS-1$ - - // ObjectiveC header file - - return false; - } - - // Process some DejaGNU instructions - if (testCode.indexOf("{ dg-error") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("// ERROR") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("- ERROR") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("// XFAIL") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("- XFAIL") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("{ xfail") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("{ dg-preprocess") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("{ dg-do preprocess") >= 0) return false; //$NON-NLS-1$ - - // gcc extensions - if (testCode.indexOf("__attribute") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("__extension") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("__restrict") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("__const") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("__declspec") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("__alignof") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("__label") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("__real") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("__imag") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("extern template") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("inline template") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("static template") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("typeof") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf(" asm") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf(") return") >= 0) return false; //$NON-NLS-1$ - if (testCode.indexOf("#ident") >= 0) return false; //$NON-NLS-1$ - - // These are expected errors (not marked in the code) - if (testCode.indexOf("#include_next") >= 0) return false; //$NON-NLS-1$ - - // Long long literals are part of ANSI C99 - // if (containsLongLongLiterals(testCode)) return false; - - if (testCode.indexOf("{ dg-do run") >= 0) return true; //$NON-NLS-1$ - if (testCode.indexOf("{ dg-do link") >= 0) return true; //$NON-NLS-1$ - - return true; - } - - - public void doFile() throws Throwable { - int timeOut = FractionalAutomatedTest.timeOut; - - assertNotNull (fileList); - - File file = (File)fileList.removeFirst(); - FileInputStream stream = new FileInputStream(file); - - String filePath = file.getCanonicalPath(); - String nature = (String)natures.get(filePath); - - StringWriter code = new StringWriter(); - - byte b[] = new byte[stepSize]; - int n = stream.read(b); - while( n != -1 ){ - code.write(new String(b)); - n = stream.read(b); - } - - String testCode = code.toString(); - - if ( file.getName().equals("concat1.C")) { //$NON-NLS-1$ - // This is a really time-consuming test, - // override timeout - timeOut = 600000; - } - - if (isExpectedToPass(testCode, file)) { - ParseThread thread = new ParseThread(); - - thread.quickParseFlag = quickParse; - thread.code = testCode; - thread.cppNature = nature.equalsIgnoreCase("cpp"); //$NON-NLS-1$ - thread.file = filePath; - - thread.start(); - thread.join(timeOut); - - if (thread.isAlive()) { - thread.stop(); - reportHang(testCode, filePath); - } else if (thread.result != null) { - reportException(thread.result, filePath, thread.parser); - } - } else { - // gcc probably didn't expect this test to pass. - // It doesn't mean that it should pass CDT parser, - // as it is more relaxed - // Result - 'inconclusive', but we report 'pass' - assertTrue(true); - } - } - - - - static class ParseThread extends Thread { - public String code; - public boolean cppNature; - public String file; - public Throwable result = null; - public IParser parser = null; - public boolean quickParseFlag = true; - - public void run(){ - try { - ParserMode parserMode = quickParseFlag ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; - ParserLanguage language = cppNature ? ParserLanguage.CPP : ParserLanguage.C; - parser = ParserFactory.createParser( - ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), parserMode, language, nullCallback, new NullLogService(), null ), nullCallback, parserMode, language, null); - - assertTrue(parser.parse()); - } - catch( Throwable e ) - { - result = e; - } - } - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index 73afd4368b1..95012655a2d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -4085,8 +4085,7 @@ public class AST2Tests extends AST2BaseTest { assertField(col.getName(43).resolveBinding(), "y", "Point"); assertField(col.getName(44).resolveBinding(), "x", "Point"); assertField(col.getName(45).resolveBinding(), "y", "Point"); - } - +} // struct S1 { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMScannerTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMScannerTests.java index 30faefd3b74..512c27f5b67 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMScannerTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMScannerTests.java @@ -29,10 +29,8 @@ import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; @@ -91,7 +89,6 @@ public class DOMScannerTests extends BaseTestCase { try { for(;;) { IToken t= fScanner.nextToken(); - assertTrue(t.getType() <= IToken.tLAST); } } catch ( EndOfFileException e){ @@ -1658,12 +1655,6 @@ public class DOMScannerTests extends BaseTestCase { StringBuffer buffer = new StringBuffer( "#if CONST \n #endif \n #elif CONST \n int"); final List problems = new ArrayList(); - ISourceElementRequestor requestor = new NullSourceElementRequestor() { - public boolean acceptProblem(IProblem problem) { - problems.add(problem); - return super.acceptProblem(problem); - } - }; initializeScanner(buffer.toString()); validateToken(IToken.t_int); validateProblemCount(1); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PortedScannerTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PortedScannerTests.java index 20718a92b5b..11505ed54e7 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PortedScannerTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PortedScannerTests.java @@ -2388,7 +2388,7 @@ public class PortedScannerTests extends PreprocessorTestsBase { } public void testBug39698() throws Exception { - initializeScanner( "?"); //$NON-NLS-1$ + initializeScanner( "?"); validateToken( IGCCToken.tMIN ); validateToken( IGCCToken.tMAX ); validateEOF(); @@ -2396,8 +2396,8 @@ public class PortedScannerTests extends PreprocessorTestsBase { public void test__attribute__() throws Exception { initializeScanner( - "#define __cdecl __attribute__((cdecl))\n" + //$NON-NLS-1$ - "__cdecl;"); //$NON-NLS-1$ + "#define __cdecl __attribute__((cdecl))\n" + + "__cdecl;"); validateToken(IGCCToken.t__attribute__); validateToken(IToken.tLPAREN); validateToken(IToken.tLPAREN); @@ -2409,8 +2409,8 @@ public class PortedScannerTests extends PreprocessorTestsBase { } public void testImaginary() throws Exception { - initializeScanner( "3i", ParserLanguage.C ); //$NON-NLS-1$ - validateInteger( "3i" ); //$NON-NLS-1$ + initializeScanner( "3i", ParserLanguage.C ); + validateInteger( "3i" ); validateEOF(); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java index 31ca62949d6..18b81a0d96d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorTestsBase.java @@ -88,7 +88,6 @@ public abstract class PreprocessorTestsBase extends BaseTestCase { try { for(;;) { IToken t= fScanner.nextToken(); - assertTrue(t.getType() <= IToken.tLAST); } } catch ( EndOfFileException e){ diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java deleted file mode 100644 index 2624be9a0b2..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java +++ /dev/null @@ -1,256 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - * Markus Schorn (Wind River Systems) - *******************************************************************************/ - -package org.eclipse.cdt.core.parser.tests.scanner2; - -import java.util.List; - -import junit.framework.ComparisonFailure; -import junit.framework.TestCase; - -import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; -import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; -import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.EndOfFileException; -import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IScanner; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro; -import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2; - -/** - * @author jcamelon - * - */ -public class BaseScanner2Test extends TestCase { - - protected IScanner scanner; - - public BaseScanner2Test( String x ) - { - super(x); - } - - protected void initializeScanner( String input, ParserMode mode ) throws ParserFactoryError - { - initializeScanner( input, mode, new NullSourceElementRequestor( mode )); - } - - protected void initializeScanner( String input, ParserMode mode, ISourceElementRequestor requestor ) throws ParserFactoryError - { - scanner = createScanner( new CodeReader(input.toCharArray()), new ScannerInfo(), mode, ParserLanguage.CPP, requestor, null, null ); //$NON-NLS-1$ - } - - protected void initializeScanner( String input, ParserLanguage language ) throws ParserFactoryError - { - scanner = createScanner( new CodeReader(input.toCharArray()), - new ScannerInfo(), ParserMode.COMPLETE_PARSE, language, - new NullSourceElementRequestor( ParserMode.COMPLETE_PARSE ), null, null ); - } - - protected void initializeScanner(String input) throws ParserFactoryError - { - initializeScanner( input, ParserMode.COMPLETE_PARSE ); - } - - public static Scanner2 createScanner( CodeReader code, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError - { - if( config == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_CONFIG ); - if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE ); - IParserLogService logService = ( log == null ) ? ParserFactory.createDefaultLogService() : log; - ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode ); - ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor ); - IScannerExtensionConfiguration configuration = null; - if( language == ParserLanguage.C ) - configuration = new GCCScannerExtensionConfiguration(); - else - configuration = new GPPScannerExtensionConfiguration(); - return new Scanner2( code, config, ourRequestor, ourMode, language, logService, workingCopies, configuration ); - } - - public int fullyTokenize() throws Exception - { - try - { - IToken t= scanner.nextToken(); - while (t != null) - { - if (verbose) - System.out.println("Token t = " + t); //$NON-NLS-1$ - - if ((t.getType()> IToken.tLAST)) - System.out.println("Unknown type for token " + t); //$NON-NLS-1$ - t= scanner.nextToken(); - } - } - catch ( EndOfFileException e) - { - } - return scanner.getCount(); - } - public void validateIdentifier(String expectedImage) throws Exception - { - try { - IToken t= scanner.nextToken(); - assertNotNull(t); - assertEquals(IToken.tIDENTIFIER, t.getType()); - assertEquals(expectedImage, t.getImage()); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - public void validateInteger(String expectedImage) throws Exception - { - try { - IToken t= scanner.nextToken(); - assertTrue(t.getType() == IToken.tINTEGER); - assertTrue(t.getImage().equals(expectedImage)); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - public void validateFloatingPointLiteral(String expectedImage) throws Exception - { - try { - IToken t= scanner.nextToken(); - assertTrue(t.getType() == IToken.tFLOATINGPT); - assertTrue(t.getImage().equals(expectedImage)); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - public void validateChar( char expected )throws Exception - { - try { - IToken t= scanner.nextToken(); - assertTrue(t.getType() == IToken.tCHAR ); - Character c = new Character( expected ); - assertEquals( t.getImage(), '\'' + c.toString() + '\'' ); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - public void validateChar( String expected ) throws Exception - { - try { - IToken t= scanner.nextToken(); - assertTrue(t.getType() == IToken.tCHAR ); - assertEquals( t.getImage(), '\'' + expected + '\''); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - public void validateString( String expectedImage ) throws Exception - { - validateString( expectedImage, false ); - } - - public void validateString(String expectedImage, boolean lString ) throws Exception - { - try { - IToken t= scanner.nextToken(); - if( lString ) - assertEquals(IToken.tLSTRING, t.getType()); - else - assertEquals(IToken.tSTRING, t.getType()); - assertEquals(expectedImage, t.getImage()); - } catch (EndOfFileException e) { - fail("EOF received"); //$NON-NLS-1$ - } - } - - public void validateToken(int tokenType) throws Exception - { - try { - IToken t= scanner.nextToken(); - assertEquals(tokenType, t.getType()); - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - public void validateBalance(int expected) - { - // This isn't kept track of any more - //assertTrue(scanner.getDepth() == expected); - } - - public void validateEOF() throws Exception - { - try { - assertNull(scanner.nextToken()); - } catch (EndOfFileException e) { - } - } - - public static void assertCharArrayEquals(char[] expected, char[] actual) { - if (!CharArrayUtils.equals(expected, actual)) - throw new ComparisonFailure(null, new String(expected), new String(actual)); - } - - public void validateDefinition(String name, String value) - { - Object expObject = scanner.getRealDefinitions().get(name.toCharArray()); - assertNotNull(expObject); - assertTrue(expObject instanceof ObjectStyleMacro); - assertCharArrayEquals(value.toCharArray(), ((ObjectStyleMacro)expObject).getExpansion()); - } - - public void validateDefinition(String name, int value) - { - validateDefinition(name, String.valueOf(value)); - } - - public void validateAsUndefined(String name) - { - assertNull(scanner.getDefinitions().get(name.toCharArray())); - } - - public static final String EXCEPTION_THROWN = "Exception thrown "; //$NON-NLS-1$ - - public static final String EXPECTED_FAILURE = "This statement should not be reached " //$NON-NLS-1$ - + "as we sent in bad preprocessor input to the scanner"; //$NON-NLS-1$ - - public static final boolean verbose = false; - - - /** - * @param string - */ - protected void validateWideChar(String string) throws Exception - { - try { - IToken t= scanner.nextToken(); - assertEquals(IToken.tLCHAR, t.getType()); - assertEquals(t.getImage(), "L\'" + string + "\'"); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (EndOfFileException e) { - assertTrue(false); - } - } - - -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/DOMScannerSpeedTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/DOMScannerSpeedTest.java index 09323702c2c..72889b28aa5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/DOMScannerSpeedTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/DOMScannerSpeedTest.java @@ -18,9 +18,7 @@ import java.util.Collections; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; @@ -33,7 +31,6 @@ import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner; */ public class DOMScannerSpeedTest extends SpeedTest2 { - private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor(); private PrintStream stream; public static void main(String[] args) { @@ -83,7 +80,7 @@ public class DOMScannerSpeedTest extends SpeedTest2 { */ protected long testScan(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception { ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; - DOMScanner scanner = createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST ); + DOMScanner scanner = createScanner(reader, info, mode, lang, null, Collections.EMPTY_LIST ); long startTime = System.currentTimeMillis(); int count = 0; try { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/GCCScannerExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/GCCScannerExtensionsTest.java deleted file mode 100644 index a98ebcf872d..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/GCCScannerExtensionsTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests.scanner2; - -import java.io.StringWriter; -import java.io.Writer; - -import org.eclipse.cdt.core.parser.IGCCToken; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.ParserLanguage; - -/** - * @author jcamelon - * - */ -public class GCCScannerExtensionsTest extends BaseScanner2Test { - - /** - * @param x - */ - public GCCScannerExtensionsTest(String x) { - super(x); - } - - public void testBug39698() throws Exception - { - initializeScanner( "?"); //$NON-NLS-1$ - validateToken( IGCCToken.tMIN ); - validateToken( IGCCToken.tMAX ); - validateEOF(); - } - - public void test__attribute__() throws Exception { - initializeScanner( - "#define __cdecl __attribute__((cdecl))\n" + //$NON-NLS-1$ - "__cdecl;"); //$NON-NLS-1$ - validateToken(IGCCToken.t__attribute__); - validateToken(IToken.tLPAREN); - validateToken(IToken.tLPAREN); - validateToken(IToken.tIDENTIFIER); - validateToken(IToken.tRPAREN); - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - } - - public void testBug73954B() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "#define foo(x) \\\n"); //$NON-NLS-1$ - writer.write( " __builtin_choose_expr( \\\n"); //$NON-NLS-1$ - writer.write( " __builtin_types_compatible_p( typeof(x), double ), \\\n"); //$NON-NLS-1$ - writer.write( " foo_double( x ), (void)0 ) \n"); //$NON-NLS-1$ - writer.write( "__builtin_constant_p(1) \n"); //$NON-NLS-1$ - writer.write( "foo( 1 ) \n"); //$NON-NLS-1$ - - initializeScanner( writer.toString(), ParserLanguage.C ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_void ); - validateToken( IToken.tRPAREN ); - validateInteger( "0" ); //$NON-NLS-1$ - } - - public void testImaginary() throws Exception - { - initializeScanner( "3i", ParserLanguage.C ); //$NON-NLS-1$ - validateInteger( "3i" ); //$NON-NLS-1$ - validateEOF(); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/IncludeTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/IncludeTest.java deleted file mode 100644 index 6635770b84e..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/IncludeTest.java +++ /dev/null @@ -1,186 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.tests.scanner2; - -import java.io.InputStream; -import java.util.Collections; -import java.util.Iterator; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.ExtendedScannerInfo; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest; -import org.eclipse.cdt.core.parser.tests.CompleteParsePluginTest; -import org.eclipse.cdt.core.parser.tests.FileBasePluginTest; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ParserException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; - -/** - * @author jcamelon - * - */ -public class IncludeTest extends FileBasePluginTest { - - private static final String [] EMPTY_STRING_ARRAY = new String[0]; - - /** - * @param name - * @param className - */ - public IncludeTest(String name) { - super(name, IncludeTest.class); - } - - public static Test suite() { - TestSuite suite = new TestSuite( IncludeTest.class ); - suite.addTest( new CompleteParsePluginTest("cleanupProject") ); //$NON-NLS-1$ - return suite; - } - CompleteParseBaseTest.FullParseCallback c; - - protected IASTScope parse(IFile code, ParserLanguage language, IScannerInfo scannerInfo ) throws Exception - { - c = new CompleteParseBaseTest.FullParseCallback(); - InputStream stream = code.getContents(); - IParser parser = ParserFactory.createParser( - ParserFactory.createScanner( new CodeReader( code.getLocation().toOSString(), stream ), scannerInfo, //$NON-NLS-1$ - ParserMode.COMPLETE_PARSE, language, c, new NullLogService(), null ), c, ParserMode.COMPLETE_PARSE, language, null - ); - stream.close(); - boolean parseResult = parser.parse(); - // throw exception if there are generated IProblems - if( !parseResult ) throw new ParserException( "FAILURE"); //$NON-NLS-1$ - assertTrue( ((Parser)parser).validateCaches()); - return c.getCompilationUnit(); - } - - - public void testIncludeNext() throws Exception - { - String baseFile = "int zero; \n#include \"foo.h\""; //$NON-NLS-1$ - String i1Next = "int one; \n#include_next "; //$NON-NLS-1$ - String i2Next = "int two; \n#include_next \"foo.h\""; //$NON-NLS-1$ - String i3Next = "int three; \n"; //$NON-NLS-1$ - - - IFile base = importFile( "base.cpp", baseFile ); //$NON-NLS-1$ - importFile( "foo.h", i1Next ); //$NON-NLS-1$ - IFolder twof = importFolder("two"); //$NON-NLS-1$ - IFolder threef = importFolder("three"); //$NON-NLS-1$ - importFile( "two/foo.h", i2Next ); //$NON-NLS-1$ - importFile( "three/foo.h", i3Next ); //$NON-NLS-1$ - - String [] path = new String[2]; - path[0] = twof.getFullPath().toOSString(); - path[1] = threef.getFullPath().toOSString(); - - IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, EMPTY_STRING_ARRAY, path ); - Iterator i = parse( base, ParserLanguage.C, scannerInfo ).getDeclarations(); - IASTVariable v; - - assertTrue( i.hasNext() ); - v = (IASTVariable) i.next(); - assertEquals( v.getName(), "zero" ); //$NON-NLS-1$ - - assertTrue( i.hasNext() ); - v = (IASTVariable) i.next(); - assertEquals( v.getName(), "one" ); //$NON-NLS-1$ - - assertTrue( i.hasNext() ); - v = (IASTVariable) i.next(); - assertEquals( v.getName(), "two" ); //$NON-NLS-1$ - - assertTrue( i.hasNext() ); - v = (IASTVariable) i.next(); - assertEquals( v.getName(), "three" ); //$NON-NLS-1$ - - assertFalse( i.hasNext() ); - } - - public void testIncludePathOrdering() throws Exception - { - // create directory structure: - // project/base.cpp - // project/foo.h - // project/two/foo.h - // project/three/foo.h - - // this test sets the include path to be two;three and include foo.h (we should see the contents of two/foo.h - // then we change to three;two and we should see the contents of three/foo.h. - - String baseFile = "#include "; //$NON-NLS-1$ - String i1Next = "int one;\n"; //$NON-NLS-1$ - String i2Next = "int two;\n"; //$NON-NLS-1$ - String i3Next = "int three;\n"; //$NON-NLS-1$ - - IFile base = importFile( "base.cpp", baseFile ); //$NON-NLS-1$ - importFile( "foo.h", i1Next ); //$NON-NLS-1$ - IFolder twof = importFolder("two"); //$NON-NLS-1$ - IFolder threef = importFolder("three"); //$NON-NLS-1$ - importFile( "two/foo.h", i2Next ); //$NON-NLS-1$ - importFile( "three/foo.h", i3Next ); //$NON-NLS-1$ - - String [] path = new String[2]; - path[0] = twof.getFullPath().toOSString(); - path[1] = threef.getFullPath().toOSString(); - - IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, EMPTY_STRING_ARRAY, path ); - Iterator i = parse( base, ParserLanguage.C, scannerInfo ).getDeclarations(); - IASTVariable v; - - assertTrue( i.hasNext() ); - v = (IASTVariable) i.next(); - assertEquals( v.getName(), "two" ); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - - path[0] = threef.getFullPath().toOSString(); - path[1] = twof.getFullPath().toOSString(); - - scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, EMPTY_STRING_ARRAY, path ); - i = parse( base, ParserLanguage.C, scannerInfo ).getDeclarations(); - - assertTrue( i.hasNext() ); - v = (IASTVariable) i.next(); - assertEquals( v.getName(), "three" ); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug91086() throws Exception { - IFile inclusion = importFile( "file.h", "#define FOUND 666\n" ); //$NON-NLS-1$ //$NON-NLS-2$ - StringBuffer buffer = new StringBuffer( "#include \"" ); //$NON-NLS-1$ - buffer.append( inclusion.getLocation().toOSString() ); - buffer.append( "\"\n"); //$NON-NLS-1$ - buffer.append( "int var = FOUND;\n"); //$NON-NLS-1$ - IFile code = importFile( "code.c", buffer.toString() ); //$NON-NLS-1$ - for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP - : null) { - Iterator i = parse( code, p, new ScannerInfo() ).getDeclarations(); - IASTVariable var = (IASTVariable) i.next(); - assertEquals( var.getInitializerClause().getAssigmentExpression().getLiteralString(), "666" ); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java deleted file mode 100644 index 13cb12c48aa..00000000000 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java +++ /dev/null @@ -1,2692 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - * Markus Schorn (Wind River Systems) - * Anton Leherbauer (Wind River Systems) - *******************************************************************************/ - -package org.eclipse.cdt.core.parser.tests.scanner2; - -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.internal.core.parser.QuickParseCallback; -import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro; - -/** - * @author jcamelon - */ -public class Scanner2Test extends BaseScanner2Test -{ - - public void testBug102825_1() throws Exception { - StringBuffer buffer = new StringBuffer("#define CURLOPTTYPE_OBJECTPOINT 10000\n" ); //$NON-NLS-1$ - buffer.append("#define CINIT = CURLOPTTYPE_##OBJECTPOINT + 1\n" ); //$NON-NLS-1$ - buffer.append("CINIT\n" ); //$NON-NLS-1$ - initializeScanner(buffer.toString()); - validateToken( IToken.tASSIGN ); - validateInteger( "10000"); //$NON-NLS-1$ - } - - - public void testBug102825_2() throws Exception { - StringBuffer buffer = new StringBuffer("#define CURLOPTTYPE_OBJECTPOINT 10000\n" ); //$NON-NLS-1$ - buffer.append("#define CINIT(name,type,number) = CURLOPTTYPE_##type + number\n" ); //$NON-NLS-1$ - buffer.append("CINIT(FILE, OBJECTPOINT, 1)\n" ); //$NON-NLS-1$ - initializeScanner(buffer.toString()); - validateToken( IToken.tASSIGN ); - validateInteger( "10000"); //$NON-NLS-1$ - } - - public void testBug102825_3() throws Exception { - StringBuffer buffer = new StringBuffer("#define CURLOPTTYPE_OBJECTPOINT 10000\n" ); //$NON-NLS-1$ - buffer.append("#define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type + number\n" ); //$NON-NLS-1$ - buffer.append("CINIT(FILE, OBJECTPOINT, 1)\n" ); //$NON-NLS-1$ - initializeScanner(buffer.toString()); - validateIdentifier( "CURLOPT_FILE"); //$NON-NLS-1$ - validateToken( IToken.tASSIGN ); - validateInteger( "10000"); //$NON-NLS-1$ - } - - public void testBug102825_4() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define glue( a, b ) a ## b\n"); //$NON-NLS-1$ - buffer.append("#define HIGHLOW \"hello\"\n"); //$NON-NLS-1$ - buffer.append("glue( HIGH, LOW )\n"); //$NON-NLS-1$ - - initializeScanner(buffer.toString()); - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( buffer.toString(), ParserMode.QUICK_PARSE, callback ); - validateString( "hello"); //$NON-NLS-1$ - assertEquals( callback.problems.size(), 0 ); - } - - public void testBug195610_1() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define glue(x, y, z) x ## y ## z\n"); //$NON-NLS-1$ - buffer.append("glue(, b, c)\n"); //$NON-NLS-1$ - - initializeScanner(buffer.toString()); - Callback callback = new Callback(ParserMode.QUICK_PARSE); - initializeScanner(buffer.toString(), ParserMode.QUICK_PARSE, callback); - validateIdentifier("bc"); //$NON-NLS-1$ - assertEquals(callback.problems.size(), 0); - } - - public void testBug195610_2() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define glue(x, y, z) x ## y ## z\n"); //$NON-NLS-1$ - buffer.append("glue(a, , c)\n"); //$NON-NLS-1$ - - initializeScanner(buffer.toString()); - Callback callback = new Callback(ParserMode.QUICK_PARSE); - initializeScanner(buffer.toString(), ParserMode.QUICK_PARSE, callback); - validateIdentifier("ac"); //$NON-NLS-1$ - assertEquals(callback.problems.size(), 0); - } - - public void testBug195610_3() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define glue(x, y, z) x ## y ## z\n"); //$NON-NLS-1$ - buffer.append("glue(a, b, )\n"); //$NON-NLS-1$ - - initializeScanner(buffer.toString()); - Callback callback = new Callback(ParserMode.QUICK_PARSE); - initializeScanner(buffer.toString(), ParserMode.QUICK_PARSE, callback); - validateIdentifier("ab"); //$NON-NLS-1$ - assertEquals(callback.problems.size(), 0); - } - - public class TableRow - { - private int[] values; - private int length; - - public TableRow(int[] v) - { - length= v.length; - values= new int[length]; - System.arraycopy(v, 0, values, 0, length); - } - - public String toString() - { - StringBuffer s= new StringBuffer(); - for (int i= 0; i < length; ++i) - { - s.append("var").append(i).append("=").append(values[i]).append(" "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - return s.toString(); - } - - public String symbolName(int index) - { - return "DEFINITION" + index; //$NON-NLS-1$ - } - - public int symbolValue(int index) - { - return new Long(Math.round(Math.pow(index, index))).intValue(); - } - - public String generateCode() - { - if (length < 2) - { - return "Array must have at least 2 elements"; //$NON-NLS-1$ - } - int numberOfElsifs= length - 1; - StringBuffer buffer= new StringBuffer(); - buffer.append("#if ").append(values[0]).append("\n#\tdefine "); //$NON-NLS-1$ //$NON-NLS-2$ - buffer.append(symbolName(0)).append(" ").append(symbolValue(0)); //$NON-NLS-1$ - for (int i= 0; i < numberOfElsifs; ++i) - buffer - .append("\n#elif ") //$NON-NLS-1$ - .append(values[1 + i]) - .append("\n#\tdefine ") //$NON-NLS-1$ - .append(symbolName(i + 1)) - .append(" ") //$NON-NLS-1$ - .append(symbolValue(i + 1)); - buffer - .append("\n#else \n#\tdefine ") //$NON-NLS-1$ - .append(symbolName(length)) - .append(" ") //$NON-NLS-1$ - .append(symbolValue(length)) - .append("\n#endif"); //$NON-NLS-1$ - return buffer.toString(); - } - - public int selectWinner() - { - for (int i= 0; i < values.length; ++i) - { - if (values[i] != 0) - { - return i; - } - } - return length; - } - /** - * Returns the length. - * @return int - */ - public int getLength() - { - return length; - } - - } - - public class TruthTable - { - private int numberOfVariables; - private int numberOfRows; - public TableRow[] rows; - - public TruthTable(int n) - { - numberOfVariables= n; - numberOfRows= new Long(Math.round(Math.pow(2, n))).intValue(); - - rows= new TableRow[numberOfRows]; - for (int i= 0; i < numberOfRows; ++i) - { - String Z= Integer.toBinaryString(i); - - int[] input= new int[numberOfVariables]; - for (int j= 0; j < numberOfVariables; ++j) - { - int padding= numberOfVariables - Z.length(); - int k= 0; - for (; k < padding; ++k) - { - input[k]= 0; - } - for (int l= 0; l < Z.length(); ++l) - { - char c= Z.charAt(l); - int value= Character.digit(c, 10); - input[k++]= value; - } - } - rows[i]= new TableRow(input); - } - } - /** - * Returns the numberOfRows. - * @return int - */ - public int getNumberOfRows() - { - return numberOfRows; - } - - } - - public final static int SIZEOF_TRUTHTABLE = 10; - - - public void testWeirdStrings() throws Exception - { - initializeScanner( "Living Life L\"LONG\""); //$NON-NLS-1$ - validateIdentifier( "Living" ); //$NON-NLS-1$ - validateIdentifier( "Life" ); //$NON-NLS-1$ - validateString("LONG", true); //$NON-NLS-1$ - validateEOF(); - - } - - - public void testNumerics()throws Exception - { - initializeScanner("3.0 0.9 .5 3. 4E5 2.01E-03 ..."); //$NON-NLS-1$ - validateFloatingPointLiteral( "3.0"); //$NON-NLS-1$ - validateFloatingPointLiteral( "0.9"); //$NON-NLS-1$ - validateFloatingPointLiteral( ".5"); //$NON-NLS-1$ - validateFloatingPointLiteral( "3."); //$NON-NLS-1$ - validateFloatingPointLiteral( "4E5"); //$NON-NLS-1$ - validateFloatingPointLiteral( "2.01E-03" ); //$NON-NLS-1$ - validateToken( IToken.tELLIPSIS ); - validateEOF(); - - } - - - /** - * Constructor for ScannerTestCase. - * @param name - */ - public Scanner2Test(String name) - { - super(name); - } - - public void testPreprocessorDefines()throws Exception - { - initializeScanner("#define SIMPLE_NUMERIC 5\nint x = SIMPLE_NUMERIC"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("x"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner("#define SIMPLE_STRING \"This is a simple string.\"\n\nconst char * myVariable = SIMPLE_STRING;"); //$NON-NLS-1$ - validateToken(IToken.t_const); - validateDefinition("SIMPLE_STRING", "\"This is a simple string.\""); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.t_char); - validateToken(IToken.tSTAR); - validateIdentifier("myVariable"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateString("This is a simple string."); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define FOOL 5 \n int tryAFOOL = FOOL + FOOL;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("tryAFOOL"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define FOOL 5 \n int FOOLer = FOOL;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("FOOLer"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - // the case we were failing against in ctype.h - // this is a definition, not a macro! - initializeScanner("#define _ALPHA (0x0100|_UPPER|_LOWER)"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("_ALPHA", "(0x0100|_UPPER|_LOWER)"); //$NON-NLS-1$ //$NON-NLS-2$ - - // test for comments after the macro - initializeScanner("#define NO_COMMENT// ignore me"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("NO_COMMENT", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define NO_COMMENT/* ignore me*/"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("NO_COMMENT", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define ANSWER 42 // i think"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("ANSWER", "42"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define ANSWER 42 /* i think */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("ANSWER", "42"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define MULTILINE 3 /* comment \n that goes more than one line */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MULTILINE", "3"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define MULTICOMMENT X /* comment1 */ + Y /* comment 2 */"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MULTICOMMENT", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define SIMPLE_STRING This is a simple string.\n"); //$NON-NLS-1$ - validateEOF(); - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string."); //$NON-NLS-1$ - - initializeScanner("# define SIMPLE_NUMERIC 5\n"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("# define SIMPLE_NUMERIC 5\n"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("SIMPLE_NUMERIC", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define SIMPLE_STRING \"This is a simple string.\"\n"); //$NON-NLS-1$ - validateEOF(); - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "\"This is a simple string.\""); //$NON-NLS-1$ - - initializeScanner("#define SIMPLE_STRING This is a simple string.\n"); //$NON-NLS-1$ - validateEOF(); - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string."); //$NON-NLS-1$ - - initializeScanner("#define FLAKE\n\nFLAKE"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("FLAKE", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#define SIMPLE_STRING This is a simple string.\\\n Continue please."); //$NON-NLS-1$ - validateEOF(); - validateDefinition( - "SIMPLE_STRING", //$NON-NLS-1$ - "This is a simple string. Continue please."); //$NON-NLS-1$ - } - public void testBug67834() throws Exception { - initializeScanner( - "#if ! BAR\n" + //$NON-NLS-1$ - "foo\n" + //$NON-NLS-1$ - "#else\n" + //$NON-NLS-1$ - "bar\n" + //$NON-NLS-1$ - "#endif\n" //$NON-NLS-1$ - ); - validateIdentifier("foo"); //$NON-NLS-1$ - validateEOF(); - initializeScanner( - "#if ! (BAR)\n" + //$NON-NLS-1$ - "foo\n" + //$NON-NLS-1$ - "#else\n" + //$NON-NLS-1$ - "bar\n" + //$NON-NLS-1$ - "#endif\n" //$NON-NLS-1$ - ); - validateIdentifier("foo"); //$NON-NLS-1$ - validateEOF(); - } - - public void testConcatenation() - { - try - { - initializeScanner("#define F1 3\n#define F2 F1##F1\nint x=F2;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("F1", "3"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition( "F2", "F1##F1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("x"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("33"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define PREFIX RT_\n#define RUN PREFIX##Run"); //$NON-NLS-1$ - validateEOF(); - validateDefinition( "PREFIX", "RT_" ); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition( "RUN", "PREFIX##Run" ); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner( "#define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name\n DECLARE_HANDLE( joe )" ); //$NON-NLS-1$ - validateToken( IToken.t_struct ); - validateIdentifier( "joe__"); //$NON-NLS-1$ - validateToken( IToken.tLBRACE); - validateToken( IToken.t_int ); - validateIdentifier( "unused"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateToken( IToken.tRBRACE ); - validateToken( IToken.tSEMI ); - validateToken( IToken.t_typedef ); - validateToken( IToken.t_struct ); - validateIdentifier( "joe__" ); //$NON-NLS-1$ - validateToken( IToken.tSTAR ); - validateIdentifier( "joe"); //$NON-NLS-1$ - validateEOF(); - } - catch( Exception e ) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testSimpleIfdef() - { - try - { - - initializeScanner("#define SYMBOL 5\n#ifdef SYMBOL\nint counter(SYMBOL);\n#endif"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("counter"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define SYMBOL 5\n#ifndef SYMBOL\nint counter(SYMBOL);\n#endif"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner("#ifndef DEFINED\n#define DEFINED 100\n#endif\nint count = DEFINED;"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateDefinition("DEFINED", "100"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateIdentifier("count"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("100"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#ifndef DEFINED\n#define DEFINED 100\n#endif\nint count = DEFINED;"); //$NON-NLS-1$ - addDefinition("DEFINED", "101"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("DEFINED", "101"); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.t_int); - validateIdentifier("count"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("101"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner( "/* NB: This is #if 0'd out */"); //$NON-NLS-1$ - validateEOF(); - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - /** - * @param string - * @param string2 - */ - private void addDefinition(String string, String string2) { - scanner.addDefinition( string.toCharArray(), string2.toCharArray() ); - } - - - public void testMultipleLines() throws Exception - { - Writer code = new StringWriter(); - code.write( "#define COMPLEX_MACRO 33 \\\n"); //$NON-NLS-1$ - code.write( " + 44\n\nCOMPLEX_MACRO"); //$NON-NLS-1$ - initializeScanner( code.toString() ); - validateInteger( "33" ); //$NON-NLS-1$ - validateToken( IToken.tPLUS ); - validateInteger( "44" ); //$NON-NLS-1$ - } - - public void testSlightlyComplexIfdefStructure() - { - try - { - initializeScanner("#ifndef BASE\n#define BASE 10\n#endif\n#ifndef BASE\n#error BASE is defined\n#endif"); //$NON-NLS-1$ - validateEOF(); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#ifndef ONE\n#define ONE 1\n#ifdef TWO\n#define THREE ONE + TWO\n#endif\n#endif\nint three(THREE);"); //$NON-NLS-1$ - - validateToken(IToken.t_int); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateAsUndefined("TWO"); //$NON-NLS-1$ - validateAsUndefined("THREE"); //$NON-NLS-1$ - validateIdentifier("three"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateIdentifier("THREE"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - initializeScanner("#ifndef ONE\n#define ONE 1\n#ifdef TWO\n#define THREE ONE + TWO\n#endif\n#endif\nint three(THREE);"); //$NON-NLS-1$ - addDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.t_int); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("THREE", "ONE + TWO"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateIdentifier("three"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("2"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - initializeScanner("#ifndef FOO\n#define FOO 4\n#else\n#undef FOO\n#define FOO 6\n#endif"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("FOO", "4"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef FOO\n#define FOO 4\n#else\n#undef FOO\n#define FOO 6\n#endif"); //$NON-NLS-1$ - addDefinition("FOO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateDefinition("FOO", "6"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "ONE + ONE"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner( - "#ifndef ONE\r\n" + //$NON-NLS-1$ - "# define ONE 1\n" + //$NON-NLS-1$ - "# ifndef TWO\n" + //$NON-NLS-1$ - "# define TWO ONE + ONE \n" + //$NON-NLS-1$ - "# else\n" + //$NON-NLS-1$ - "# undef TWO\n" + //$NON-NLS-1$ - "# define TWO 2 \n" + //$NON-NLS-1$ - "# endif\n" + //$NON-NLS-1$ - "#else\n" + //$NON-NLS-1$ - "# ifndef TWO\n" + //$NON-NLS-1$ - "# define TWO ONE + ONE \n" + //$NON-NLS-1$ - "# else\n" + //$NON-NLS-1$ - "# undef TWO\n" + //$NON-NLS-1$ - "# define TWO 2 \n" + //$NON-NLS-1$ - "# endif\n" + //$NON-NLS-1$ - "#endif\n"); //$NON-NLS-1$" + - - addDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "ONE + ONE"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$ - addDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - addDefinition("TWO", "two"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateDefinition("ONE", "one"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#ifndef ONE\n# define ONE 1\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#else\n# ifndef TWO\n# define TWO ONE + ONE \n# else\n# undef TWO\n# define TWO 2 \n# endif\n#endif\n"); //$NON-NLS-1$ - addDefinition("TWO", "two"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "2"); //$NON-NLS-1$ //$NON-NLS-2$ - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testIfs() throws Exception - { - try - { - initializeScanner("#if 0\n#error NEVER\n#endif\n"); //$NON-NLS-1$ - validateEOF(); - initializeScanner("#define X 5\n#define Y 7\n#if (X < Y)\n#define Z X + Y\n#endif"); //$NON-NLS-1$ - validateEOF(); - validateDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Z", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - - initializeScanner("#if T < 20\n#define Z T + 1\n#endif"); //$NON-NLS-1$ - addDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - addDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$ - addDefinition("T", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateDefinition("X", "5"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Y", "7"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("T", "X + Y"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("Z", "T + 1"); //$NON-NLS-1$ //$NON-NLS-2$ - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - try - { - initializeScanner("#if ( 10 / 5 ) != 2\n#error 10/5 seems to not equal 2 anymore\n#endif\n"); //$NON-NLS-1$ - validateEOF(); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( - "#ifndef FIVE \n" + //$NON-NLS-1$ - "#define FIVE 5\n" + //$NON-NLS-1$ - "#endif \n" + //$NON-NLS-1$ - "#ifndef TEN\n" + //$NON-NLS-1$ - "#define TEN 2 * FIVE\n" + //$NON-NLS-1$ - "#endif\n" + //$NON-NLS-1$ - "#if TEN != 10\n" + //$NON-NLS-1$ - "#define MISTAKE 1\n" + //$NON-NLS-1$ - "#error Five does not equal 10\n" + //$NON-NLS-1$ - "#endif\n", ParserMode.QUICK_PARSE, callback); //$NON-NLS-1$ - addDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$ - validateEOF(); - validateDefinition("FIVE", "55"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TEN", "2 * FIVE"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("MISTAKE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - assertFalse( callback.problems.isEmpty() ); - - try - { - initializeScanner("#if ((( FOUR / TWO ) * THREE )< FIVE )\n#error 6 is not less than 5 \n#endif\n#if ( ( FIVE * ONE ) != (( (FOUR) + ONE ) * ONE ) )\n#error 5 should equal 5\n#endif \n"); //$NON-NLS-1$ - - addDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - addDefinition("TWO", "(ONE + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - addDefinition("THREE", "(TWO + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - addDefinition("FOUR", "(TWO * TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - addDefinition("FIVE", "(THREE + TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - - validateEOF(); - validateDefinition("ONE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TWO", "(ONE + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("THREE", "(TWO + ONE)"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("FOUR", "(TWO * TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("FIVE", "(THREE + TWO)"); //$NON-NLS-1$ //$NON-NLS-2$ - - TruthTable table= new TruthTable(SIZEOF_TRUTHTABLE); - int numberOfRows= table.getNumberOfRows(); - TableRow[] rows= table.rows; - - for (int i= 0; i < numberOfRows; ++i) - { - TableRow row= rows[i]; - String code= row.generateCode(); - if (verbose) - System.out.println("\n\nRow " + i + " has code\n" + code); //$NON-NLS-1$ //$NON-NLS-2$ - initializeScanner(code); - validateEOF(); - validateAllDefinitions(row); - } - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - initializeScanner("#if ! 0\n#error Correct!\n#endif"); //$NON-NLS-1$ - validateEOF(); - } - - public void testPreprocessorMacros() - { - try - { - initializeScanner("#define GO(x) x+1\nint y(5);\ny = GO(y);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - - /* Macros don't work this way anymore - IMacroDescriptor descriptor= - scanner.getDefinition("GO"); //$NON-NLS-1$ - String [] parms= descriptor.getParameters(); - assertNotNull(parms); - assertTrue(parms.length == 1); - String parm1= parms[0]; - assertTrue(parm1.equals("x")); //$NON-NLS-1$ - IToken [] expansion= descriptor.getTokenizedExpansion(); - assertNotNull(parms); - assertTrue(expansion.length == 3); - assertTrue((expansion[0]).getType() == IToken.tIDENTIFIER); - assertTrue((expansion[0]).getImage().equals("x")); //$NON-NLS-1$ - assertTrue((expansion[1]).getType() == IToken.tPLUS); - assertTrue((expansion[2]).getType() == IToken.tINTEGER); - assertTrue((expansion[2]).getImage().equals("1")); //$NON-NLS-1$ */ - - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - initializeScanner( - "#define ONE 1\n" //$NON-NLS-1$ - + "#define SUM(a,b,c,d,e,f,g) ( a + b + c + d + e + f + g )\n" //$NON-NLS-1$ - + "int daSum = SUM(ONE,3,5,7,9,11,13);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("daSum"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("3"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("5"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("7"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("9"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("11"); //$NON-NLS-1$ - validateToken(IToken.tPLUS); - validateInteger("13"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - /* - IMacroDescriptor macro= scanner.getDefinition("SUM"); //$NON-NLS-1$ - String [] params= macro.getParameters(); - assertNotNull(params); - assertTrue(params.length == 7); - - IToken [] tokens= macro.getTokenizedExpansion(); - assertNotNull(tokens); - assertTrue(tokens.length == 15); */ - - initializeScanner("#define LOG( format, var1) printf( format, var1 )\nLOG( \"My name is %s\", \"Bogdan\" );\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateString("My name is %s"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateString("Bogdan"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define INCR( x ) ++x\nint y(2);\nINCR(y);"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateInteger("2"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateToken(IToken.tINCR); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define CHECK_AND_SET( x, y, z ) if( x ) { \\\n y = z; \\\n }\n\nCHECK_AND_SET( 1, balance, 5000 );\nCHECK_AND_SET( confused(), you, dumb );"); //$NON-NLS-1$ - validateToken(IToken.t_if); - validateToken(IToken.tLPAREN); - validateInteger("1"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tLBRACE); - validateIdentifier("balance"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("5000"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateToken(IToken.tRBRACE); - validateToken(IToken.tSEMI); - - validateToken(IToken.t_if); - validateToken(IToken.tLPAREN); - validateIdentifier("confused"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateToken(IToken.tRPAREN); - validateToken(IToken.tRPAREN); - validateToken(IToken.tLBRACE); - validateIdentifier("you"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateIdentifier("dumb"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateToken(IToken.tRBRACE); - validateToken(IToken.tSEMI); - validateEOF(); - - initializeScanner("#define ON 7\n#if defined(ON)\nint itsOn = ON;\n#endif"); //$NON-NLS-1$ - validateToken(IToken.t_int); - validateBalance(1); - validateIdentifier("itsOn"); //$NON-NLS-1$ - validateToken(IToken.tASSIGN); - validateInteger("7"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateEOF(); - initializeScanner("#if defined( NOTHING ) \nint x = NOTHING;\n#endif"); //$NON-NLS-1$ - validateEOF(); - - - - - - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - public void testQuickScan() throws Exception - { - initializeScanner( "#if X + 5 < 7\n int found = 1;\n#endif", ParserMode.QUICK_PARSE ); //$NON-NLS-1$ - validateToken( IToken.t_int ); - validateIdentifier( "found" ); //$NON-NLS-1$ - validateToken( IToken.tASSIGN ); - validateInteger( "1"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateEOF(); - - initializeScanner( "#if 0\n int error = 666;\n#endif" ); //$NON-NLS-1$ - validateEOF(); - - } - - - public void testOtherPreprocessorCommands() throws ParserFactoryError - { - try - { - initializeScanner("#\n#\t\n#define MAX_SIZE 1024\n#\n# "); //$NON-NLS-1$ - validateEOF(); - validateDefinition("MAX_SIZE", "1024"); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - - for (int i= 0; i < 4; ++i) - { - switch (i) - { - case 0 : - initializeScanner("# ape"); //$NON-NLS-1$ - break; - case 1 : - initializeScanner("# #"); //$NON-NLS-1$ - break; - case 2 : - initializeScanner("# 32"); //$NON-NLS-1$ - break; - case 3 : - initializeScanner("# defines"); //$NON-NLS-1$ - break; - } - - try - { - validateEOF(); - // These are no longer scanner exceptions, the are simply ignored. - //fail(EXPECTED_FAILURE); - } - catch (Exception e) - { - fail(EXCEPTION_THROWN + e.toString()); - } - } - - } - - public void validateAllDefinitions(TableRow row) - { - int winner= row.selectWinner(); - int rowLength= row.getLength(); - for (int i= 0; i <= rowLength; ++i) - { - if (i == winner) - validateDefinition(row.symbolName(i), row.symbolValue(i)); - else - validateAsUndefined(row.symbolName(i)); - } - } - - public void testBug36287() throws Exception - { - initializeScanner( "X::X( const X & rtg_arg ) : U( rtg_arg ) , Z( rtg_arg.Z ) , er( rtg_arg.er ){}" ); //$NON-NLS-1$ - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tCOLONCOLON); - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_const ); - validateIdentifier("X"); //$NON-NLS-1$ - validateToken( IToken.tAMPER ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOLON ); - validateIdentifier( "U"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOMMA ); - validateIdentifier( "Z"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tDOT ); - validateIdentifier( "Z"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOMMA ); - validateIdentifier( "er"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateIdentifier( "rtg_arg"); //$NON-NLS-1$ - validateToken( IToken.tDOT ); - validateIdentifier( "er"); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE); - validateToken( IToken.tRBRACE); - validateEOF(); - - initializeScanner( "foo.*bar"); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateToken( IToken.tDOTSTAR ); - validateIdentifier("bar"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner( "foo...bar"); //$NON-NLS-1$ - validateIdentifier("foo"); //$NON-NLS-1$ - validateToken( IToken.tELLIPSIS ); - validateIdentifier("bar"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug35892() throws Exception - { - initializeScanner( "'c'" ); //$NON-NLS-1$ - validateChar( 'c' ); - validateEOF(); - } - - public void testBug36045() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( '"' ); - buffer.append( '\\'); - buffer.append( '"'); - buffer.append( '"'); - - buffer.append( '"'); - buffer.append( '\\'); - buffer.append( '\\'); - buffer.append( '"'); - buffer.append( "\n\n"); //$NON-NLS-1$ - initializeScanner( buffer.toString()); - validateString( "\\\"\\\\"); //$NON-NLS-1$ - } - - public void testConditionalWithBraces() throws Exception - { - for( int i = 0; i < 4; ++i ) - { - initializeScanner( "int foobar(int a) { if(a == 0) {\n#ifdef THIS\n} else {}\n#elif THAT\n} else {}\n#endif\nreturn 0;}" ); //$NON-NLS-1$ - switch( i ) - { - case 0: - addDefinition( "THIS", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - addDefinition( "THAT", "1" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 1: - addDefinition( "THIS", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - addDefinition( "THAT", "0" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 2: - addDefinition( "THAT", "1" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - case 3: - addDefinition( "THAT", "0" ); //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - - validateToken( IToken.t_int ); - validateIdentifier( "foobar"); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_int ); - validateIdentifier( "a" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.t_if ); - validateToken( IToken.tLPAREN ); - validateIdentifier( "a" ); //$NON-NLS-1$ - validateToken( IToken.tEQUAL ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE ); - - if( i <= 1 ) - { - validateToken( IToken.tRBRACE ); - validateToken( IToken.t_else ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.tRBRACE ); - } - - if( i == 2 ) - { - validateToken( IToken.tRBRACE ); - validateToken( IToken.t_else ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.tRBRACE ); - } - - validateToken( IToken.t_return ); - validateInteger( "0"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateToken( IToken.tRBRACE ); - validateEOF(); - } - - } - - public void testNestedRecursiveDefines() throws Exception - { - initializeScanner( "#define C B A\n#define B C C\n#define A B\nA" ); //$NON-NLS-1$ - - validateIdentifier("B"); //$NON-NLS-1$ - validateDefinition("A", "B"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("B", "C C"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("C", "B A"); //$NON-NLS-1$ //$NON-NLS-2$ - validateIdentifier("A"); //$NON-NLS-1$ - validateIdentifier("B"); //$NON-NLS-1$ - validateIdentifier("A"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36316() throws Exception - { - initializeScanner( "#define A B->A\nA" ); //$NON-NLS-1$ - - validateIdentifier("B"); //$NON-NLS-1$ - validateDefinition("A", "B->A"); //$NON-NLS-1$ //$NON-NLS-2$ - validateToken(IToken.tARROW); - validateIdentifier("A"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36434() throws Exception - { - initializeScanner( "#define X(Y)\nX(55)"); //$NON-NLS-1$ - validateEOF(); - /*IMacroDescriptor macro = scanner.getDefinition( "X" ); //$NON-NLS-1$ - assertNotNull( macro ); - assertEquals( macro.getParameters().length, 1 ); - assertEquals( macro.getParameters()[0], "Y" ); //$NON-NLS-1$ - assertEquals( macro.getTokenizedExpansion().length, 0 );*/ - } - - public void testBug36047() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "# define MAD_VERSION_STRINGIZE(str) #str\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_STRING(num) MAD_VERSION_STRINGIZE(num)\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION MAD_VERSION_STRING(MAD_VERSION_MAJOR) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_MINOR) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_PATCH) \".\" \\\n" ); //$NON-NLS-1$ - writer.write( " MAD_VERSION_STRING(MAD_VERSION_EXTRA)\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_MAJOR 2\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_MINOR 1\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_PATCH 3\n" ); //$NON-NLS-1$ - writer.write( "# define MAD_VERSION_EXTRA boo\n" ); //$NON-NLS-1$ - writer.write( "MAD_VERSION\n" ); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - - validateString( "2.1.3.boo" ); //$NON-NLS-1$ - - validateEOF(); - } - - public void testBug36475() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( " \"A\" \"B\" \"C\" " ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - validateString( "ABC" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36509() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define debug(s, t) printf(\"x\" # s \"= %d, x\" # t \"= %s\", \\\n"); //$NON-NLS-1$ - writer.write(" x ## s, x ## t) \n"); //$NON-NLS-1$ - writer.write("debug(1, 2);"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - //printf("x1=%d, x2= %s", x1, x2); - validateIdentifier( "printf" ); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateString("x1= %d, x2= %s"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("x1"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("x2"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - validateEOF(); - } - - public void testBug36695() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("\'\\4\' \'\\n\'"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - - validateChar( "\\4" ); //$NON-NLS-1$ - validateChar( "\\n" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug36521() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write("#define str(s) # s\n"); //$NON-NLS-1$ - writer.write("fputs(str(strncmp(\"abc\\0d\", \"abc\", \'\\4\')\n"); //$NON-NLS-1$ - writer.write(" == 0), s);\n"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateIdentifier("fputs"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - - //TODO as in 36701B, whitespace is not properly replaced inside the string, ok for now. - //validateString("strncmp(\\\"abc\\\\0d\\\", \\\"abc\\\", '\\\\4') == 0"); //$NON-NLS-1$ - validateString("strncmp(\\\"abc\\\\0d\\\", \\\"abc\\\", '\\\\4') == 0"); //$NON-NLS-1$ - - validateToken(IToken.tCOMMA); - validateIdentifier("s"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - } - - public void testBug36770() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "#define A 0\n" ); //$NON-NLS-1$ - writer.write( "#if ( A == 1 )\n"); //$NON-NLS-1$ - writer.write( "# define foo 1\n"); //$NON-NLS-1$ - writer.write( "#else\n"); //$NON-NLS-1$ - writer.write( "# define foo 2\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "foo\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateInteger( "2" ); //$NON-NLS-1$ - validateEOF(); - } - - - public void testBug36816() throws Exception - { - Callback c; - c = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( "#include \"foo.h", ParserMode.QUICK_PARSE, c ); //$NON-NLS-1$ - validateEOF(); -// assertTrue( ((IProblem)c.problems.get(0)).getID() == IProblem.PREPROCESSOR_INVALID_DIRECTIVE ); - - c = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( "#include \n" ); //$NON-NLS-1$ - - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( buffer.toString(), ParserMode.QUICK_PARSE, callback ); - validateEOF(); - assertEquals( callback.problems.size(), 0 ); - assertEquals( callback.inclusions.size(), 1 ); - assertEquals( callback.inclusions.get(0), "stdio.h"); //$NON-NLS-1$ - } - - public void testBug46402() throws Exception - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "#define X 5\n" ); //$NON-NLS-1$ - buffer.append( "#if defined( X )\n" ); //$NON-NLS-1$ - buffer.append( "// blah\n" ); //$NON-NLS-1$ - buffer.append( "#elif Y > 5 \n" ); //$NON-NLS-1$ - buffer.append( "// coo\n" ); //$NON-NLS-1$ - buffer.append( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( buffer.toString(), ParserMode.COMPLETE_PARSE ); - validateEOF(); - } - - public void testBug50821() throws Exception - { - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( "\'\n\n\n", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - scanner.nextToken(); - assertEquals( callback.problems.size(), 1 ); - } - - - public void test54778() throws Exception - { - initializeScanner("#if 1 || 0 < 3 \n printf \n #endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - initializeScanner("#if !defined FOO || FOO > 3\nprintf\n#endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - initializeScanner("#if !defined FOO || FOO < 3\nprintf\n#endif\n"); //$NON-NLS-1$ - validateIdentifier("printf"); //$NON-NLS-1$ - validateEOF(); - } - - public void test68229() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "#define COUNT 0 \n" ); //$NON-NLS-1$ - writer.write( "1 \n" ); //$NON-NLS-1$ - writer.write( "#if COUNT \n" ); //$NON-NLS-1$ - writer.write( " 2 \n" ); //$NON-NLS-1$ - writer.write( "#endif \n" ); //$NON-NLS-1$ - writer.write( "3 \n" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - IToken t1 = scanner.nextToken(); - IToken t3 = scanner.nextToken(); - - assertEquals( t1.getImage(), "1" ); //$NON-NLS-1$ - assertEquals( t3.getImage(), "3" ); //$NON-NLS-1$ - assertEquals( t1.getNext(), t3 ); - validateEOF(); - - writer = new StringWriter(); - writer.write( "#define FOO( x ) x \n" ); //$NON-NLS-1$ - writer.write( "1 FOO( 2 ) 3 \n" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - t1 = scanner.nextToken(); - IToken t2 = scanner.nextToken(); - t3 = scanner.nextToken(); - validateEOF(); - - assertEquals( t1.getImage(), "1" ); //$NON-NLS-1$ - assertEquals( t2.getImage(), "2" ); //$NON-NLS-1$ - assertEquals( t3.getImage(), "3" ); //$NON-NLS-1$ - - assertEquals( t1.getNext(), t2 ); - } - - - public void testBug56517() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#if 0 \n"); //$NON-NLS-1$ - writer.write( "char * x = \"#boo\";\n" ); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateEOF(); - } - - public void testBug36770B() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define A 0\n" ); //$NON-NLS-1$ - writer.write( "#if ( A == 1 )\n" ); //$NON-NLS-1$ - writer.write( "# define foo\n" ); //$NON-NLS-1$ - writer.write( "#else\n" ); //$NON-NLS-1$ - writer.write( "# define bar\n" ); //$NON-NLS-1$ - writer.write( "#endif\n" ); //$NON-NLS-1$ - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE ); - validateEOF(); - validateDefinition( "A", 0 ); //$NON-NLS-1$ - validateDefinition( "bar", "" ); //$NON-NLS-1$ //$NON-NLS-2$ - - } - - public void testBug47797() throws Exception - { - initializeScanner( "\"\\uABCD\" \'\\uABCD\' \\uABCD_ident \\u001A01BC_ident ident\\U01AF ident\\u01bc00AF"); //$NON-NLS-1$ - validateString( "\\uABCD"); //$NON-NLS-1$ - validateChar( "\\uABCD"); //$NON-NLS-1$ - validateIdentifier( "\\uABCD_ident"); //$NON-NLS-1$ - validateIdentifier( "\\u001A01BC_ident"); //$NON-NLS-1$ - validateIdentifier( "ident\\U01AF" ); //$NON-NLS-1$ - validateIdentifier( "ident\\u01bc00AF" ); //$NON-NLS-1$ - validateEOF(); - } - - - public void testBug59768() throws Exception - { - initializeScanner( "#define A A\nA"); //$NON-NLS-1$ - validateIdentifier( "A"); //$NON-NLS-1$ - validateEOF(); - /*IMacroDescriptor d = scanner.getDefinition( "A"); //$NON-NLS-1$ - assertTrue( d.isCircular() );*/ - } - - public void testBug60764() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define P a,b\n"); //$NON-NLS-1$ - writer.write( "#define M(x) M1(x)\n"); //$NON-NLS-1$ - writer.write( "#define M1(x,y) #x #y\n"); //$NON-NLS-1$ - writer.write( "M(P)\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateString( "ab"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug62042() throws Exception - { - Callback callback = new Callback(ParserMode.QUICK_PARSE); - initializeScanner( "0x", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - validateInteger("0x"); // to me this is a valid number //$NON-NLS-1$ - validateEOF(); - //assertFalse( callback.problems.isEmpty() ); - } - - public void testBug61968() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "unsigned int ui = 2172748163; //ok \n" ); //$NON-NLS-1$ - writer.write( "int big = 999999999999999;//ok \n" ); //$NON-NLS-1$ - writer.write( "void main() { \n" ); //$NON-NLS-1$ - writer.write( "caller(4); //ok\n" ); //$NON-NLS-1$ - writer.write( "caller(2172748163);//causes java.lang.NumberFormatException \n" ); //$NON-NLS-1$ - writer.write( "caller(999999999999999); //also causes NumberFormatException \n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - Callback callback = new Callback(ParserMode.QUICK_PARSE); - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE, callback ); - fullyTokenize(); - assertTrue( callback.problems.isEmpty() ); - } - - public void testBug62378() throws Exception - { - initializeScanner( "\"\\?\\?<\""); //$NON-NLS-1$ - validateString("\\?\\?<" ); //$NON-NLS-1$ - } - - public void testBug62384() throws Exception - { - initializeScanner( "18446744073709551615LL"); //$NON-NLS-1$ - validateInteger( "18446744073709551615LL"); //$NON-NLS-1$ - } - - public void testBug62390() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define f(x) x\n"); //$NON-NLS-1$ - writer.write( "#if f(\n"); //$NON-NLS-1$ - writer.write( "5) == 5\n"); //$NON-NLS-1$ - writer.write( "true1\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "#if A\n"); //$NON-NLS-1$ - writer.write( "#elif f(\n"); //$NON-NLS-1$ - writer.write( "5) == 5\n"); //$NON-NLS-1$ - writer.write( "true2\n"); //$NON-NLS-1$ - writer.write( "#endif\n"); //$NON-NLS-1$ - writer.write( "#undef f\n"); //$NON-NLS-1$ - writer.write( "#define f(x) \"A0I70_001.h\"\n"); //$NON-NLS-1$ - writer.write( "#include f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "#undef f\n"); //$NON-NLS-1$ - writer.write( "#define f(x) 1467\n"); //$NON-NLS-1$ - writer.write( "#line f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "#pragma f(\n"); //$NON-NLS-1$ - writer.write( "5\n"); //$NON-NLS-1$ - writer.write( ")\n"); //$NON-NLS-1$ - writer.write( "}\n"); //$NON-NLS-1$ - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( writer.toString(), ParserMode.QUICK_PARSE, callback ); - fullyTokenize(); - } - - public void testBug62009() throws Exception - { - Callback callback = new Callback( ParserMode.QUICK_PARSE ); - initializeScanner( "#define def(x) (x#)\ndef(orange)\n", ParserMode.QUICK_PARSE, callback ); //$NON-NLS-1$ - fullyTokenize(); - assertFalse( callback.problems.isEmpty() ); - } - - public void testBug61972() throws Exception - { - initializeScanner( "#define DEF1(A1) A1\n#define DEF2 DEF1(DEF2)\nDEF2;" ); //$NON-NLS-1$ - validateIdentifier( "DEF2"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateEOF(); - } - - public void testBug64268() throws Exception - { - Writer writer = new StringWriter(); - writer.write("#define BODY \\\n"); //$NON-NLS-1$ - writer.write(" { \\\n"); //$NON-NLS-1$ - writer.write(" /* this multi-line comment messes \\\n"); //$NON-NLS-1$ - writer.write(" up the parser. */ }\n"); //$NON-NLS-1$ - writer.write("BODY "); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateToken( IToken.tLBRACE); - validateToken( IToken.tRBRACE); - validateEOF(); - } - - - - public void testUndef() throws Exception { - initializeScanner( - "#define A 5\n" + //$NON-NLS-1$ - "#define B 10\n" + //$NON-NLS-1$ - "#undef A\n" + //$NON-NLS-1$ - "A B"); //$NON-NLS-1$ - validateIdentifier("A"); //$NON-NLS-1$ - validateInteger("10"); //$NON-NLS-1$ - validateEOF(); - } - - public void testWackyFunctionMacros() throws Exception { - initializeScanner( - "#define A(X) hi##X\n" + //$NON-NLS-1$ - "#define B(Y) A(Y)\n" + //$NON-NLS-1$ - "B(there)"); //$NON-NLS-1$ - validateIdentifier("hithere"); //$NON-NLS-1$ - validateEOF(); - } - - public void testSlashes() throws Exception { - initializeScanner("__q / __n"); //$NON-NLS-1$ - validateIdentifier("__q"); //$NON-NLS-1$ - validateToken(IToken.tDIV); - validateIdentifier("__n"); //$NON-NLS-1$ - validateEOF(); - } - - public void testStringify() throws Exception { - initializeScanner("#define xS(s) #s\n#define S(s) xS(s)\n#define X hi\nS(X)"); //$NON-NLS-1$ - validateString("hi"); //$NON-NLS-1$ - validateEOF(); - } - - public void testWideToNarrowConcatenation() throws Exception - { - initializeScanner( "\"ONE\" L\"TWO\""); //$NON-NLS-1$ - validateString( "ONETWO", true); //$NON-NLS-1$ - validateEOF(); - } - - public void testEmptyIncludeDirective() throws Exception - { - QuickParseCallback qpc = new QuickParseCallback(); - initializeScanner( "#include \n#include \n", ParserMode.QUICK_PARSE, qpc ); //$NON-NLS-1$ - validateEOF(); - Iterator i = qpc.getInclusions(); - assertTrue( i.hasNext() ); - IASTInclusion inc = (IASTInclusion) i.next(); - assertFalse( i.hasNext() ); - assertEquals( inc.getName(), "foo.h"); //$NON-NLS-1$ - } - - public void testBug69412() throws Exception - { - Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); - initializeScanner( "\'\\\\\'", ParserMode.COMPLETE_PARSE, callback ); //$NON-NLS-1$ - validateChar( "\\\\"); //$NON-NLS-1$ - validateEOF(); - assertTrue( callback.problems.isEmpty()); - } - - public void testBug70072() throws Exception - { - initializeScanner( "#if 1/0\nint i;\n#elif 2/0\nint j;\n#endif\nint k;\n" ); //$NON-NLS-1$ - fullyTokenize(); - } - - public void testBug70261() throws Exception - { - initializeScanner( "0X0"); //$NON-NLS-1$ - validateInteger( "0X0"); //$NON-NLS-1$ - } - - public void testBug62571() throws Exception - { - StringBuffer buffer = new StringBuffer( "#define J(X,Y) X##Y\n"); //$NON-NLS-1$ - buffer.append( "J(A,1Xxyz)\n"); //$NON-NLS-1$ - buffer.append( "J(B,1X1X1Xxyz)\n"); //$NON-NLS-1$ - buffer.append( "J(C,0Xxyz)\n"); //$NON-NLS-1$ - buffer.append( "J(CC,0Xxyz)\n"); //$NON-NLS-1$ - buffer.append( "J(D,0xxyz)\n"); //$NON-NLS-1$ - buffer.append( "J(E,0x0x0xxyz)\n"); //$NON-NLS-1$ - initializeScanner( buffer.toString() ); - validateIdentifier( "A1Xxyz"); //$NON-NLS-1$ - validateIdentifier( "B1X1X1Xxyz"); //$NON-NLS-1$ - validateIdentifier( "C0Xxyz"); //$NON-NLS-1$ - validateIdentifier( "CC0Xxyz"); //$NON-NLS-1$ - validateIdentifier( "D0xxyz"); //$NON-NLS-1$ - validateIdentifier( "E0x0x0xxyz"); //$NON-NLS-1$ - } - - public void testBug69134() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "# ifdef YYDEBUG\n" ); //$NON-NLS-1$ - writer.write( "if (yyDebug) {\n" ); //$NON-NLS-1$ - writer.write( "(void) fprintf (yyTrace,\n" ); //$NON-NLS-1$ - writer.write( "\" # |Position|State|Mod|Lev|Action |Terminal and Lookahead or Rule\n\");\n" ); //$NON-NLS-1$ - writer.write( "yyNl ();\n" ); //$NON-NLS-1$ - writer.write( "}\n" ); //$NON-NLS-1$ - writer.write( "# endif\n" ); //$NON-NLS-1$ - Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); - initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback ); - fullyTokenize(); - assertTrue( callback.problems.isEmpty() ); - - } - - public void testBug70073() throws Exception - { - StringBuffer buffer = new StringBuffer( "#if CONST \n #endif \n #elif CONST \n int" ); //$NON-NLS-1$ - final List problems = new ArrayList(); - ISourceElementRequestor requestor = new NullSourceElementRequestor() { - public boolean acceptProblem(IProblem problem) - { - problems.add( problem ); - return super.acceptProblem( problem ); - } - }; - initializeScanner( buffer.toString(), ParserMode.COMPLETE_PARSE, requestor ); - validateToken( IToken.t_int ); - assertEquals( problems.size(), 1 ); - } - - public void testBug73652() throws Exception - { - StringWriter writer = new StringWriter(); - writer.write( "#define DoSuperMethodA IDoSuperMethodA\n" ); //$NON-NLS-1$ - writer.write( "#define IDoSuperMethodA(a,b,c) IIntuition->IDoSuperMethodA(a,b,c)\n" ); //$NON-NLS-1$ - writer.write( "DoSuperMethodA(0,0,0);\n" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - validateIdentifier( "IIntuition" ); //$NON-NLS-1$ - validateToken( IToken.tARROW ); - validateIdentifier( "IDoSuperMethodA" ); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tCOMMA ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tCOMMA ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tSEMI ); - validateEOF(); - } - - public void testBug73652_2() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write( "#define DoSuperMethodA DoSuperMethodB //doobalie\n" ); //$NON-NLS-1$ - writer.write( "#define DoSuperMethodB DoSuperMethodC /*oogalie*/ \n" ); //$NON-NLS-1$ - writer.write( "#define DoSuperMethodC IDoSuperMethodA \\\n\n" ); //$NON-NLS-1$ - writer.write( "#define IDoSuperMethodA(a,b,c) IIntuition->IDoSuperMethodA(a,b,c)\n" ); //$NON-NLS-1$ - writer.write( "DoSuperMethodA (0,0,0);\n" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - validateIdentifier( "IIntuition" ); //$NON-NLS-1$ - validateToken( IToken.tARROW ); - validateIdentifier( "IDoSuperMethodA" ); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tCOMMA ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tCOMMA ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tSEMI ); - validateEOF(); - - } - public void testBug72997() throws Exception - { - initializeScanner( "'\\\\'"); //$NON-NLS-1$ - validateChar( "\\\\"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug72725() throws Exception - { - for( int i = 0; i < 2; ++i ) - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "#define a \\" ); //$NON-NLS-1$ - if( i == 0 ) - buffer.append( "\r"); //$NON-NLS-1$ - buffer.append( "\n"); //$NON-NLS-1$ - buffer.append( "long macro stuff" ); //$NON-NLS-1$ - if( i == 0 ) - buffer.append( "\r"); //$NON-NLS-1$ - buffer.append( "\n"); //$NON-NLS-1$ - - Callback callback = new Callback(ParserMode.COMPLETE_PARSE); - initializeScanner( buffer.toString(), ParserMode.COMPLETE_PARSE, callback ); - validateEOF(); - assertTrue( callback.problems.isEmpty() ); - } - } - - public void testBug72506() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write("#define INCFILE(x) ver ## x\n"); //$NON-NLS-1$ - writer.write("#define xstr(x) str(x)\n"); //$NON-NLS-1$ - writer.write("#define str(x) #x\n"); //$NON-NLS-1$ - writer.write("xstr(INCFILE(2).h)\n"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateString("ver2.h"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug72506_2() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write("#define str(x) #x\n"); //$NON-NLS-1$ - writer.write("#define A B\n"); //$NON-NLS-1$ - writer.write("#define B A\n"); //$NON-NLS-1$ - writer.write("str(B)\n"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateString( "B" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testMacroPastingError() throws Exception{ - StringWriter writer = new StringWriter(); - writer.write("#define m(expr) \\\r\n"); //$NON-NLS-1$ - writer.write(" foo( #expr ) \r\n"); //$NON-NLS-1$ - - Callback callback = new Callback(ParserMode.COMPLETE_PARSE); - initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback ); - validateEOF(); - assertTrue( callback.problems.isEmpty() ); - } - - public void testBug74176() throws Exception{ - initializeScanner( "#define MYSTRING \"X Y Z " ); //$NON-NLS-1$ - validateEOF(); - - initializeScanner( "#define m(b) #"); //$NON-NLS-1$ - validateEOF(); - - initializeScanner( "#define m(foo,b) #b"); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug74180() throws Exception{ - initializeScanner( "true false", ParserLanguage.C ); //$NON-NLS-1$ - validateIdentifier( "true" ); //$NON-NLS-1$ - validateIdentifier( "false" ); //$NON-NLS-1$ - - initializeScanner( "true false", ParserLanguage.CPP ); //$NON-NLS-1$ - validateToken( IToken.t_true ); - validateToken( IToken.t_false); - } - - public void testBug73492() throws Exception{ - String code = "#define PTR void *\n" + //$NON-NLS-1$ - "PTR;\n"; //$NON-NLS-1$ - - int offset = code.indexOf("PTR;"); //$NON-NLS-1$ - initializeScanner( code ); - - IToken t = scanner.nextToken(); - assertEquals( t.getType(), IToken.t_void ); - assertEquals( t.getOffset(), offset ); - assertEquals( t.getLineNumber(), 2 ); - - t = scanner.nextToken(); - assertEquals( t.getType(), IToken.tSTAR ); - assertEquals( t.getOffset(), offset ); - assertEquals( t.getLineNumber(), 2 ); - - t = scanner.nextToken(); - assertEquals( t.getType(), IToken.tSEMI ); - assertEquals( t.getOffset(), offset + 3 ); - assertEquals( t.getLineNumber(), 2 ); - } - - public void testBug74328() throws Exception - { - initializeScanner( "\"\";\n" ); //$NON-NLS-1$ - validateString( ""); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateEOF(); - } - - public void testBug72537() throws Exception - { - initializeScanner( "FOO BAR(boo)" ); //$NON-NLS-1$ - scanner.addDefinition( "FOO".toCharArray(), "foo".toCharArray() ); //$NON-NLS-1$//$NON-NLS-2$ - scanner.addDefinition( "BAR(x)".toCharArray(), "x".toCharArray() ); //$NON-NLS-1$//$NON-NLS-2$ - - validateIdentifier( "foo" ); //$NON-NLS-1$ - validateIdentifier( "boo" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug75083() throws Exception - { - String code = "#define blah() { extern foo\n blah()\n"; //$NON-NLS-1$ - initializeScanner( code ); - - int idx = code.indexOf( "\n blah()" ) + 2; //$NON-NLS-1$ - IToken t = scanner.nextToken(); - assertEquals( t.getType(), IToken.tLBRACE ); - assertEquals( t.getOffset(), idx ); - assertEquals( t.getEndOffset(), idx + 6 ); - - t = scanner.nextToken(); - assertEquals( t.getType(), IToken.t_extern ); - assertEquals( t.getOffset(), idx ); - assertEquals( t.getEndOffset(), idx + 6 ); - - t = scanner.nextToken(); - assertEquals( t.getType(), IToken.tIDENTIFIER ); - assertEquals( t.getOffset(), idx ); - assertEquals( t.getEndOffset(), idx + 6 ); - } - - // when fixing 75532 several IProblems were added to ExpressionEvaluator and one to Scanner2, this is to test them - public void testBug75532IProblems() throws Exception { - Writer writer = new StringWriter(); - writer.write("#if 09 == 9\n#endif\n"); // malformed octal //$NON-NLS-1$ - writer.write("#if 1A == 0x1A\n#endif\n"); // malformed decimal //$NON-NLS-1$ - writer.write("#if 0x == 0x0\n#endif\n"); // malformed hex //$NON-NLS-1$ - writer.write("#if 0xAX == 0xA\n#endif\n"); // malformed hex //$NON-NLS-1$ - writer.write("#if 1/0 == 1\n#endif\n"); // division by zero //$NON-NLS-1$ - writer.write("#if defined ( sadf a\n#endif\n"); // missing ')' in defined //$NON-NLS-1$ - writer.write("#if defined ( sadf\n#endif\n"); // missing ')' in defined //$NON-NLS-1$ - writer.write("#if defined ( 2sadf )\n#endif\n"); // illegal identifier in defined //$NON-NLS-1$ - writer.write("#if ( 1 == 1 ? 1\n#endif\n"); // bad conditional expression //$NON-NLS-1$ - writer.write("#if ( \n#endif\n"); // expression syntax error //$NON-NLS-1$ - writer.write("#if @\n#endif\n"); // expression syntax error //$NON-NLS-1$ - writer.write("#if \n#endif\n"); // expression syntax error //$NON-NLS-1$ - writer.write("#if -\n#endif\n"); // expression syntax error //$NON-NLS-1$ - writer.write("#if ( 1 == 1\n#endif\n"); // missing ')' //$NON-NLS-1$ - writer.write("#if 1 = 1\n#endif\n"); // assignment not allowed //$NON-NLS-1$ - - writer.write("int main(int argc, char **argv) {\n"); //$NON-NLS-1$ - writer.write("if ( 09 == 9 )\n"); // added while fixing this bug, IProblem on invalid octal number //$NON-NLS-1$ - writer.write("return 1;\nreturn 0;\n}\n"); //$NON-NLS-1$ - - Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); - initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback ); - fullyTokenize(); - assertTrue( callback.problems.size() == 16 ); - Iterator probs = callback.problems.iterator(); - assertTrue( probs.hasNext() ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_BAD_OCTAL_FORMAT ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_BAD_DECIMAL_FORMAT ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_BAD_HEX_FORMAT ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_BAD_HEX_FORMAT ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_DIVIDE_BY_ZERO ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_MISSING_R_PAREN ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_MISSING_R_PAREN ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_ILLEGAL_IDENTIFIER ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_MISSING_R_PAREN ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED ); - assertTrue(((IProblem)probs.next()).getID() == IProblem.SCANNER_BAD_OCTAL_FORMAT ); - } - - public void testExpressionEvalProblems() throws Exception - { - Writer writer = new StringWriter(); - writer.write(" #if 1 == 1L \n" ); //$NON-NLS-1$ - writer.write(" #endif \n" ); //$NON-NLS-1$ - - Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); - initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback ); - validateEOF(); - - assertEquals( 0, callback.problems.size() ); - } - - public void testExpressionEvalProblems_2() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define FOO( a, b ) a##b \n"); //$NON-NLS-1$ - writer.write( "#if FOO ( 1, 0 ) == 10 \n"); //$NON-NLS-1$ - writer.write( "1 \n"); //$NON-NLS-1$ - writer.write( "#endif \n"); //$NON-NLS-1$ - - Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); - initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback ); - validateInteger( "1" ); //$NON-NLS-1$ - validateEOF(); - - assertEquals( 0, callback.problems.size() ); - } - - public void testUnExpandedFunctionMacro() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "#define foo( a ) #a \n"); //$NON-NLS-1$ - writer.write( "foo( 1 ) foo \n"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateString( "1" ); //$NON-NLS-1$ - validateIdentifier( "foo" ); //$NON-NLS-1$ - validateEOF(); - } - - public void testBug39688A() throws Exception { // test valid IProblems - Writer writer = new StringWriter(); - writer.write("#define decl1(type, ... \\\n ) type var;\n"); //$NON-NLS-1$ - writer.write("decl1(int, x, y, z)\n"); //$NON-NLS-1$ - writer.write("#define decl2(type, args...) type args;"); //$NON-NLS-1$ - writer.write("decl2(int, a, b, c, x, y, z)\n"); //$NON-NLS-1$ - writer.write("#define decl3(type, args...) \\\n type args;"); //$NON-NLS-1$ - writer.write("decl3(int, a, b, c, x, y)\n"); //$NON-NLS-1$ - writer.write("#define decl4(type, args... \\\n ) type args;"); //$NON-NLS-1$ - writer.write("decl4(int, a, b, z)\n"); //$NON-NLS-1$ - writer.write("#define decl5(type, ...) type __VA_ARGS__;"); //$NON-NLS-1$ - writer.write("decl5(int, z)\n"); //$NON-NLS-1$ - writer.write("#define decl6(type, ... \\\n) type __VA_ARGS__;"); //$NON-NLS-1$ - writer.write("decl6(int, a, b, c, x)\n"); //$NON-NLS-1$ - writer.write("#define foo(a) a __VA_ARGS__;\n"); //$NON-NLS-1$ C99: 6.10.3.5 this should produce an IProblem - writer.write("#define foo2(a) a #__VA_ARGS__;\n"); //$NON-NLS-1$ C99: 6.10.3.5 this should produce an IProblem - - Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); - initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback ); - fullyTokenize(); - Iterator probs = callback.problems.iterator(); - assertTrue( probs.hasNext() ); - assertTrue( ((IProblem)probs.next()).getID() == IProblem.PREPROCESSOR_INVALID_VA_ARGS ); - assertTrue( probs.hasNext() ); - assertTrue( ((IProblem)probs.next()).getID() == IProblem.PREPROCESSOR_MACRO_PASTING_ERROR ); - assertFalse( probs.hasNext() ); - } - - public void testBug39688B() throws Exception { // test C99 - Writer writer = new StringWriter(); - writer.write("#define debug(...) fprintf(stderr, __VA_ARGS__)\n"); //$NON-NLS-1$ - writer.write("#define showlist(...) puts(#__VA_ARGS__)\n"); //$NON-NLS-1$ - writer.write("#define report(test, ...) ((test)?puts(#test):\\\n printf(__VA_ARGS__))\n"); //$NON-NLS-1$ - writer.write("int main() {\n"); //$NON-NLS-1$ - writer.write("debug(\"Flag\");\n"); //$NON-NLS-1$ - writer.write("debug(\"X = %d\\n\", x);\n"); //$NON-NLS-1$ - writer.write("showlist(The first, second, and third items.);\n"); //$NON-NLS-1$ - writer.write("report(x>y, \"x is %d but y is %d\", x, y);\n"); //$NON-NLS-1$ - writer.write("return 0; }\n"); //$NON-NLS-1$ - - Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); - initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback ); - fullyTokenize(); - Iterator probs = callback.problems.iterator(); - assertFalse( probs.hasNext() ); - - Map defs = scanner.getDefinitions(); - assertTrue(defs.containsKey("debug")); //$NON-NLS-1$ - assertTrue(defs.containsKey("showlist")); //$NON-NLS-1$ - assertTrue(defs.containsKey("report")); //$NON-NLS-1$ - FunctionStyleMacro debug = (FunctionStyleMacro)defs.get("debug"); //$NON-NLS-1$ - assertTrue(new String(debug.arglist[0]).equals("__VA_ARGS__")); //$NON-NLS-1$ - assertTrue(debug.hasVarArgs()); - assertFalse(debug.hasGCCVarArgs()); - assertTrue(new String(debug.getExpansion()).equals("fprintf(stderr, __VA_ARGS__)") ); //$NON-NLS-1$ - FunctionStyleMacro showlist = (FunctionStyleMacro)defs.get("showlist"); //$NON-NLS-1$ - assertTrue(new String(showlist.arglist[0]).equals("__VA_ARGS__")); //$NON-NLS-1$ - assertTrue(showlist.hasVarArgs()); - assertFalse(showlist.hasGCCVarArgs()); - assertTrue(new String(showlist.getExpansion()).equals("puts(#__VA_ARGS__)")); //$NON-NLS-1$ - FunctionStyleMacro report = (FunctionStyleMacro)defs.get("report"); //$NON-NLS-1$ - assertTrue(new String(report.arglist[0]).equals("test")); //$NON-NLS-1$ - assertTrue(new String(report.arglist[1]).equals("__VA_ARGS__")); //$NON-NLS-1$ - assertTrue(report.hasVarArgs()); - assertFalse(report.hasGCCVarArgs()); - assertTrue(new String(report.getExpansion()).equals("((test)?puts(#test): printf(__VA_ARGS__))")); //$NON-NLS-1$ - - validate39688Common(writer, callback); - } - - public void testBug39688C() throws Exception { // test GCC - Writer writer = new StringWriter(); - writer.write("#define debug(vars...) fprintf(stderr, vars)\n"); //$NON-NLS-1$ - writer.write("#define showlist(vars...) puts(#vars)\n"); //$NON-NLS-1$ - writer.write("#define report(test, vars...) ((test)?puts(#test):\\\n printf(vars))\n"); //$NON-NLS-1$ - writer.write("int main() {\n"); //$NON-NLS-1$ - writer.write("debug(\"Flag\");\n"); //$NON-NLS-1$ - writer.write("debug(\"X = %d\\n\", x);\n"); //$NON-NLS-1$ - writer.write("showlist(The first, second, and third items.);\n"); //$NON-NLS-1$ - writer.write("report(x>y, \"x is %d but y is %d\", x, y);\n"); //$NON-NLS-1$ - writer.write("return 0; }\n"); //$NON-NLS-1$ - - Callback callback = new Callback( ParserMode.COMPLETE_PARSE ); - initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback ); - fullyTokenize(); - Iterator probs = callback.problems.iterator(); - assertFalse( probs.hasNext() ); - - Map defs = scanner.getDefinitions(); - assertTrue(defs.containsKey("debug")); //$NON-NLS-1$ - assertTrue(defs.containsKey("showlist")); //$NON-NLS-1$ - assertTrue(defs.containsKey("report")); //$NON-NLS-1$ - FunctionStyleMacro debug = (FunctionStyleMacro)defs.get("debug"); //$NON-NLS-1$ - assertTrue(new String(debug.arglist[0]).equals("vars")); //$NON-NLS-1$ - assertFalse(debug.hasVarArgs()); - assertTrue(debug.hasGCCVarArgs()); - assertTrue(new String(debug.getExpansion()).equals("fprintf(stderr, vars)") ); //$NON-NLS-1$ - FunctionStyleMacro showlist = (FunctionStyleMacro)defs.get("showlist"); //$NON-NLS-1$ - assertTrue(new String(showlist.arglist[0]).equals("vars")); //$NON-NLS-1$ - assertFalse(showlist.hasVarArgs()); - assertTrue(showlist.hasGCCVarArgs()); - assertTrue(new String(showlist.getExpansion()).equals("puts(#vars)")); //$NON-NLS-1$ - FunctionStyleMacro report = (FunctionStyleMacro)defs.get("report"); //$NON-NLS-1$ - assertTrue(new String(report.arglist[0]).equals("test")); //$NON-NLS-1$ - assertTrue(new String(report.arglist[1]).equals("vars")); //$NON-NLS-1$ - assertFalse(report.hasVarArgs()); - assertTrue(report.hasGCCVarArgs()); - assertTrue(new String(report.getExpansion()).equals("((test)?puts(#test): printf(vars))")); //$NON-NLS-1$ - - validate39688Common(writer, callback); - } - - private void validate39688Common(Writer writer, Callback callback) throws Exception { - initializeScanner( writer.toString(), ParserMode.COMPLETE_PARSE, callback ); - - validateToken(IToken.t_int); - validateIdentifier("main"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateToken(IToken.tRPAREN); - validateToken(IToken.tLBRACE); - - validateIdentifier("fprintf"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateIdentifier("stderr"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateString("Flag"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - - validateIdentifier("fprintf"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateIdentifier("stderr"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateString("X = %d\\n"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("x"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - - validateIdentifier("puts"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateString("The first, second, and third items."); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - - validateToken(IToken.tLPAREN); - validateToken(IToken.tLPAREN); - validateIdentifier("x"); //$NON-NLS-1$ - validateToken(IToken.tGT); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tQUESTION); - validateIdentifier("puts"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateString("x>y"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tCOLON); - validateIdentifier("printf"); //$NON-NLS-1$ - validateToken(IToken.tLPAREN); - validateString("x is %d but y is %d"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("x"); //$NON-NLS-1$ - validateToken(IToken.tCOMMA); - validateIdentifier("y"); //$NON-NLS-1$ - validateToken(IToken.tRPAREN); - validateToken(IToken.tRPAREN); - validateToken(IToken.tSEMI); - - validateToken(IToken.t_return); - validateInteger("0"); //$NON-NLS-1$ - validateToken(IToken.tSEMI); - validateToken(IToken.tRBRACE); - - validateEOF(); - } - - public void testMacroArgumentExpansion() throws Exception { - Writer writer = new StringWriter(); - writer.write( "#define g_return( expr ) ( expr ) \n" ); //$NON-NLS-1$ - writer.write( "#define ETH( obj ) ( CHECK( (obj), boo ) ) \n" ); //$NON-NLS-1$ - writer.write( "#define CHECK CHECK_INSTANCE \n" ); //$NON-NLS-1$ - writer.write( "#define CHECK_INSTANCE( instance, type ) (foo((instance), (type))) \n" ); //$NON-NLS-1$ - writer.write( "g_return( ETH(ooga) ) \n" ); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - - validateToken( IToken.tLPAREN ); - validateToken( IToken.tLPAREN ); - validateToken( IToken.tLPAREN ); - validateIdentifier( "foo" ); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.tLPAREN ); - validateToken( IToken.tLPAREN ); - validateIdentifier( "ooga" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tRPAREN ); - validateToken( IToken.tCOMMA ); - validateToken( IToken.tLPAREN ); - validateIdentifier( "boo" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tRPAREN ); - validateToken( IToken.tRPAREN ); - validateToken( IToken.tRPAREN ); - validateToken( IToken.tRPAREN ); - } - - public void testBug75956() throws Exception - { - Writer writer = new StringWriter(); - writer.write( "#define ROPE( name ) name##Alloc\n"); //$NON-NLS-1$ - writer.write( "#define _C 040 \n"); //$NON-NLS-1$ - writer.write( "ROPE( _C ) \n"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateIdentifier( "_CAlloc" ); //$NON-NLS-1$ - validateEOF(); - - writer = new StringWriter(); - writer.write( "#define ROPE( name ) Alloc ## name \n"); //$NON-NLS-1$ - writer.write( "#define _C 040 \n"); //$NON-NLS-1$ - writer.write( "ROPE( _C ) \n"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateIdentifier( "Alloc_C" ); //$NON-NLS-1$ - validateEOF(); - - writer = new StringWriter(); - writer.write( "#define ROPE( name ) name##Alloc\n"); //$NON-NLS-1$ - writer.write( "#define _C 040 \n"); //$NON-NLS-1$ - writer.write( "#define _CAlloc ooga \n"); //$NON-NLS-1$ - writer.write( "ROPE( _C ) \n"); //$NON-NLS-1$ - - initializeScanner( writer.toString() ); - validateIdentifier( "ooga" ); //$NON-NLS-1$ - validateEOF(); - } - public void testUnExpandedFunctionMacros() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "#define ETH(x) x \n" ); //$NON-NLS-1$ - writer.write( "#define E ETH \n" ); //$NON-NLS-1$ - writer.write( "ETH( c ), ETH, E; \n" ); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateIdentifier( "c" ); //$NON-NLS-1$ - validateToken( IToken.tCOMMA ); - validateIdentifier("ETH"); //$NON-NLS-1$ - validateToken( IToken.tCOMMA ); - validateIdentifier("ETH"); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateEOF(); - } - - public void testBug79490A() throws Exception { - Writer writer = new StringWriter(); - writer.write("#define TEST 'n'\n"); //$NON-NLS-1$ - writer.write("#if TEST == 'y'\n"); //$NON-NLS-1$ - writer.write("#define TRUE 1\n"); //$NON-NLS-1$ - writer.write("#else\n"); //$NON-NLS-1$ - writer.write("#define FALSE 1\n"); //$NON-NLS-1$ - writer.write("#endif\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateEOF(); - validateDefinition("TEST", "'n'"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("FALSE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void testBug79490B() throws Exception { - Writer writer = new StringWriter(); - writer.write("#define TEST 'y'\n"); //$NON-NLS-1$ - writer.write("#if TEST == 'y'\n"); //$NON-NLS-1$ - writer.write("#define TRUE 1\n"); //$NON-NLS-1$ - writer.write("#else\n"); //$NON-NLS-1$ - writer.write("#define FALSE 1\n"); //$NON-NLS-1$ - writer.write("#endif\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateEOF(); - validateDefinition("TEST", "'y'"); //$NON-NLS-1$ //$NON-NLS-2$ - validateDefinition("TRUE", "1"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void testBug102568A() throws Exception { - initializeScanner("///*\r\nint x;\r\n"); //$NON-NLS-1$ - validateToken( IToken.t_int ); - validateIdentifier( "x" ); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateEOF(); - } - - public void testBug102568B() throws Exception { - initializeScanner("// bla some thing /* ... \r\nint x;\r\n"); //$NON-NLS-1$ - validateToken( IToken.t_int ); - validateIdentifier( "x" ); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateEOF(); - } - - public void testbug84270() throws Exception { - Writer writer = new StringWriter(); - writer.write("#define h g( ~\n"); //$NON-NLS-1$ - writer.write("#define g f\n"); //$NON-NLS-1$ - writer.write("#define f(a) f(x * (a))\n"); //$NON-NLS-1$ - writer.write("h 5) \n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - fullyTokenize(); - } - - public void testBug107150() throws Exception { - Writer writer = new StringWriter(); - writer.write("#define FUNC_PROTOTYPE_PARAMS(list) list\r\n"); //$NON-NLS-1$ - writer.write("int func2 FUNC_PROTOTYPE_PARAMS\r\n"); //$NON-NLS-1$ - writer.write("((int arg1)){\r\n"); //$NON-NLS-1$ - writer.write(" return 0;\r\n"); //$NON-NLS-1$ - writer.write("}\r\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateToken( IToken.t_int ); - validateIdentifier( "func2" ); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_int ); - validateIdentifier( "arg1" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.t_return ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateToken( IToken.tRBRACE ); - validateEOF(); - - writer = new StringWriter(); - writer.write("#define FUNC_PROTOTYPE_PARAMS(list) list\n"); //$NON-NLS-1$ - writer.write("int func2 FUNC_PROTOTYPE_PARAMS\n"); //$NON-NLS-1$ - writer.write("((int arg1)){\n"); //$NON-NLS-1$ - writer.write(" return 0;\n"); //$NON-NLS-1$ - writer.write("}\n"); //$NON-NLS-1$ - initializeScanner( writer.toString() ); - validateToken( IToken.t_int ); - validateIdentifier( "func2" ); //$NON-NLS-1$ - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_int ); - validateIdentifier( "arg1" ); //$NON-NLS-1$ - validateToken( IToken.tRPAREN ); - validateToken( IToken.tLBRACE ); - validateToken( IToken.t_return ); - validateInteger( "0" ); //$NON-NLS-1$ - validateToken( IToken.tSEMI ); - validateToken( IToken.tRBRACE ); - validateEOF(); - } - - public void testBug126136() throws Exception { - StringBuffer buffer = new StringBuffer("#define C C\n"); //$NON-NLS-1$ - buffer.append("#if !C\n"); //$NON-NLS-1$ - buffer.append("true\n"); //$NON-NLS-1$ - buffer.append("#endif\n"); //$NON-NLS-1$ - initializeScanner(buffer.toString(), ParserLanguage.CPP); - fullyTokenize(); - } - - public void testBug156137() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#if (3 % 2 == 1) \n"); - buffer.append("C \n"); - buffer.append("#endif \n"); - - initializeScanner(buffer.toString()); - validateIdentifier("C"); - validateEOF(); - } - - public void testBug162214() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#ifdef xxx // is not defined \n"); - buffer.append("A \n"); - buffer.append("#endif \n"); - buffer.append("B \n"); - - initializeScanner(buffer.toString()); - validateIdentifier("B"); - validateEOF(); - - buffer.setLength(0); - buffer.append("#ifdef xxx //* is not defined \n"); - buffer.append("A \n"); - buffer.append("#endif \n"); - buffer.append("B \n"); - - initializeScanner(buffer.toString()); - validateIdentifier("B"); - validateEOF(); - } - - public void testBug156988() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define a \n"); - buffer.append("#define b \" \n"); - buffer.append("#define c < \n"); - buffer.append("#define d \"\" \n"); - buffer.append("#define e <> \n"); - buffer.append("#define f f \n"); - buffer.append("#define g gg \n"); - buffer.append("#include a \n"); - buffer.append("#include b \n"); - buffer.append("#include c \n"); - buffer.append("#include d \n"); - buffer.append("#include e \n"); - buffer.append("#include f \n"); - buffer.append("#include g \n"); - buffer.append("A \n"); - - initializeScanner(buffer.toString()); - validateIdentifier("A"); - validateEOF(); - } - - public void testBug156988_1() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define a(x) x \n"); - buffer.append("#define b \" \n"); - buffer.append("#define c < \n"); - buffer.append("#define d \"\" \n"); - buffer.append("#define e <> \n"); - buffer.append("#define f f \n"); - buffer.append("#define g gg \n"); - buffer.append("#include a() \n"); - buffer.append("#include a(<) \n"); - buffer.append("#include a(\"\") \n"); - buffer.append("#include a(<>) \n"); - buffer.append("#include a(f) \n"); - buffer.append("#include a(gg) \n"); - buffer.append("#include a(g\\\ng) \n"); - buffer.append("A \n"); - - initializeScanner(buffer.toString()); - validateIdentifier("A"); - validateEOF(); - } - - public void testBug162410() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#pragma message (\"test\") \n"); - buffer.append("a \n"); - initializeScanner(buffer.toString()); - validateIdentifier("a"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=180172 - public void testBug180172() throws Exception { - StringBuffer buffer = new StringBuffer(); - String value= "\"https://bugs.eclipse.org/bugs/show_bug.cgi?id=180172\""; - buffer.append("#define bug180172 ").append(value).append(" // bla \n"); - initializeScanner(buffer.toString()); - fullyTokenize(); - validateDefinition("bug180172", value); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=182180 - public void testBug182180_1() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer - .append("#ifdef _bug_182180_\n") - .append("printf(\"Hello World /*.ap\\n\");\n") - .append("#endif\n") - .append("bug182180\n"); - initializeScanner(buffer.toString()); - validateIdentifier("bug182180"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=182180 - public void testBug182180_2() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer - .append("#ifdef _bug_182180_\n") - .append("char c='\"'; printf(\"Hello World /*.ap\\n\");\n") - .append("#endif\n") - .append("bug182180\n"); - initializeScanner(buffer.toString()); - validateIdentifier("bug182180"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=182180 - public void testBug182180_3() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer - .append("#ifdef _bug_182180_\n") - .append("char c1='\\'',c2='\\\"'; printf(\"Hello World /*.ap\\n\");\n") - .append("#endif\n") - .append("bug182180\n"); - initializeScanner(buffer.toString()); - validateIdentifier("bug182180"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=182180 - public void testBug182180_4() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer - .append("#ifdef _bug_182180_\n") - .append("printf(\"Hello '\"'World /*.ap\\n\");\n") - .append("#endif\n") - .append("bug182180\n"); - initializeScanner(buffer.toString()); - validateIdentifier("bug182180"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=182180 - public void testBug182180_5() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer - .append("#ifdef _bug_182180_\n") - .append("printf(\"Hello \\\"World /*.ap\\n\");\n") - .append("#endif\n") - .append("bug182180\n"); - initializeScanner(buffer.toString()); - validateIdentifier("bug182180"); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=200830 - public void testBug200830_1() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define string BROKEN\r\n"); - buffer.append("#define macro(inst) (char*)inst\r\n"); - buffer.append("macro(\"string\");\r\n"); - initializeScanner( buffer.toString() ); - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_char ); - validateToken( IToken.tSTAR ); - validateToken( IToken.tRPAREN ); - validateString( "string" ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=200830 - public void testBug200830_2() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define string BROKEN\r\n"); - buffer.append("#define macro(inst) (char*)inst\r\n"); - buffer.append("macro(\" string \");\r\n"); - initializeScanner( buffer.toString() ); - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_char ); - validateToken( IToken.tSTAR ); - validateToken( IToken.tRPAREN ); - validateString( " string " ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=200830 - public void testBug200830_3() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define string BROKEN\r\n"); - buffer.append("#define macro(inst) (char*)inst\r\n"); - buffer.append("macro(\"\\\"string \");\r\n"); - initializeScanner( buffer.toString() ); - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_char ); - validateToken( IToken.tSTAR ); - validateToken( IToken.tRPAREN ); - validateString( "\\\"string " ); - } - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=200830 - public void testBug200830_4() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define s B\r\n"); - buffer.append("#define macro(inst) (char*)inst\r\n"); - buffer.append("macro('s');\r\n"); - initializeScanner( buffer.toString() ); - validateToken( IToken.tLPAREN ); - validateToken( IToken.t_char ); - validateToken( IToken.tSTAR ); - validateToken( IToken.tRPAREN ); - validateChar( "s" ); - } - - public void testBug185120_1() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define TEST_DEFINE 1UL\n"); - buffer.append("#if TEST_DEFINE != 1UL\n"); - buffer.append("-\n"); - buffer.append("#else\n"); - buffer.append("+\n"); - buffer.append("#endif\n"); - initializeScanner( buffer.toString() ); - validateToken( IToken.tPLUS ); - } - - public void testBug185120_2() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define TEST_DEFINE 1LLU\n"); - buffer.append("#if TEST_DEFINE != 1ULL\n"); - buffer.append("-\n"); - buffer.append("#else\n"); - buffer.append("+\n"); - buffer.append("#endif\n"); - initializeScanner( buffer.toString() ); - validateToken( IToken.tPLUS ); - } -} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/SpeedTest2.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/SpeedTest2.java index 7ab81c33091..7d6022c42d7 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/SpeedTest2.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/SpeedTest2.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.scanner2; -import java.util.Collections; import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -21,14 +20,9 @@ import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration; import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserFactoryError; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ScannerInfo; @@ -38,63 +32,11 @@ import org.eclipse.cdt.internal.core.parser.scanner2.FileCodeReaderFactory; // A test that just calculates the speed of the parser // Eventually, we'll peg a max time and fail the test if it exceeds it public class SpeedTest2 extends TestCase { - - public static void main(String[] args) { - try { - new SpeedTest2().runTest(1); - } catch (Exception e) { - System.out.println(e); - } - } - - public void test() throws Exception { - runTest(20); - } - private void runTest(int n) throws Exception { - String code = - "#include \n" + - "#include \n" + - "#include \n"; - - CodeReader reader = new CodeReader(code.toCharArray()); - IScannerInfo info = getScannerInfo(false); - long totalTime = 0; - for (int i = 0; i < n; ++i) { - long time = testParse(reader, false, info, ParserLanguage.CPP); - if (i > 4) - totalTime += time; - } - - if (n > 5) { - System.out.println("Average Time: " + (totalTime / (n - 5)) + " millisecs"); - } - } - - /** - * @param path - * @param quick TODO - */ - protected long testParse(CodeReader reader, boolean quick, IScannerInfo info, ParserLanguage lang) throws Exception { - ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE; - IScanner scanner = createScanner(reader, info, mode, lang, CALLBACK, null, Collections.EMPTY_LIST ); - IParser parser = ParserFactory.createParser( scanner, CALLBACK, mode, lang, null); - long startTime = System.currentTimeMillis(); - long totalTime; - parser.parse(); - totalTime = System.currentTimeMillis() - startTime; - System.out.println( "Resulting parse took " + totalTime + " millisecs " + - scanner.getCount() + " tokens"); - return totalTime; - } - - public static DOMScanner createScanner( CodeReader code, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError + public static DOMScanner createScanner( CodeReader code, IScannerInfo config, ParserMode mode, ParserLanguage language, IParserLogService log, List workingCopies ) { - if( config == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_CONFIG ); - if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE ); IParserLogService logService = ( log == null ) ? ParserFactory.createDefaultLogService() : log; ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode ); - ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor ); IScannerExtensionConfiguration configuration = null; if( language == ParserLanguage.C ) configuration = new GCCScannerExtensionConfiguration(); @@ -103,7 +45,6 @@ public class SpeedTest2 extends TestCase { return new DOMScanner( code, config, ourMode, language, logService, configuration, FileCodeReaderFactory.getInstance() ); } - private static final ISourceElementRequestor CALLBACK = new NullSourceElementRequestor(); protected IScannerInfo getScannerInfo(boolean quick) { if (quick) diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/RegressionTestSuite.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/RegressionTestSuite.java deleted file mode 100644 index 2a90ec75589..00000000000 --- a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/RegressionTestSuite.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Oct 4, 2004 - */ -package org.eclipse.cdt.core.tests; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * @author aniefer - */ -public class RegressionTestSuite extends TestSuite { - public RegressionTestSuite() { - super(); - } - - public RegressionTestSuite(Class theClass, String name) { - super(theClass, name); - } - - public RegressionTestSuite(Class theClass) { - super(theClass); - } - - public RegressionTestSuite(String name) { - super(name); - } - - public static Test suite() { - final RegressionTestSuite suite = new RegressionTestSuite(); - - suite.addTest( SelectionRegressionTest.suite( false ) ); - - return suite; - } -} diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SelectionRegressionTest.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SelectionRegressionTest.java deleted file mode 100644 index e98433e02aa..00000000000 --- a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SelectionRegressionTest.java +++ /dev/null @@ -1,807 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Nov 1, 2004 - */ -package org.eclipse.cdt.core.tests; - -import java.io.StringWriter; -import java.io.Writer; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.dom.IPDOMManager; -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.IParser.ISelectionParseResult; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest.FullParseCallback; -import org.eclipse.cdt.core.testplugin.CProjectHelper; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; - -/** - * @author aniefer - */ -public class SelectionRegressionTest extends BaseTestFramework { - - public SelectionRegressionTest() - { - super(); - } - /** - * @param name - */ - public SelectionRegressionTest(String name) - { - super(name); - } - - public static Test suite(){ - return suite( true ); - } - public static Test suite( boolean cleanup ) { - TestSuite suite = new TestSuite("SelectionRegressionTests"); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest("testSimpleOpenDeclaration") ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testClass" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testClassRHS" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testStruct" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testStructRHS" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testEnumeration" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testEnumerationArg" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testEnumerator" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testMethod" ) ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new SelectionRegressionTest( "testMethodRHS78656" ), 78656 )); //$NON-NLS-1$ - suite.addTest( new FailingTest( new SelectionRegressionTest( "testMethod78114" ), 78114 )); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testMethod78118" ) ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new SelectionRegressionTest( "testOverloadedMethod78389" ), 78389 )); //$NON-NLS-1$ - suite.addTest( new FailingTest( new SelectionRegressionTest( "testConstructor78625" ), 78625) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testClassField" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testStructField" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testNamespace" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testNamespace77989" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testFunction" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testFunctionArg" ) ); //$NON-NLS-1$ - suite.addTest( new FailingTest(new SelectionRegressionTest( "testFunctionArg78435" ), 78435 )); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testVariable" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testVariableStruct" ) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testVariableArg" ) ); //$NON-NLS-1$ - suite.addTest( new FailingTest (new SelectionRegressionTest( "testVariableArg77996" ), 77996 )); //$NON-NLS-1$ - suite.addTest( new FailingTest (new SelectionRegressionTest( "testVariable77996" ), 77996) ); //$NON-NLS-1$ - suite.addTest( new SelectionRegressionTest( "testUnion" ) ); //$NON-NLS-1$ - - if( cleanup ) - suite.addTest( new SelectionRegressionTest( "cleanupProject" ) ); //$NON-NLS-1$ - - return suite; - } - - protected void setUp() throws Exception { - super.setUp(); - try{ - if (project == null){ - cproject = CProjectHelper.createCCProject("RegressionTestProject", "bin", IPDOMManager.ID_NO_INDEXER); //$NON-NLS-1$ //$NON-NLS-2$ - project = cproject.getProject(); - } - } catch ( CoreException e ) { //boo - } - } - - protected void tearDown() throws Exception { - if( project == null || !project.exists() ) - return; - - try{ - project.delete(true,true,new NullProgressMonitor()); - project = null; - } catch ( CoreException e ) { //boo - } - super.tearDown(); - } - - protected IASTNode getSelection(IFile code, int startOffset, int endOffset) throws Exception { - return getSelection( code, startOffset, endOffset, ParserLanguage.CPP ); - } - - /** - * @param code - * @param offset1 - * @param offset2 - * @param b - * @return - */ - protected IASTNode getSelection(IFile file, int startOffset, int endOffset, ParserLanguage language ) throws Exception { - FullParseCallback callback = new FullParseCallback(); - IParser parser = ParserFactory.createParser( - ParserFactory.createScanner( - new CodeReader( file.getLocation().toOSString(), file.getContents() ), - new ScannerInfo(), - ParserMode.SELECTION_PARSE, - ParserLanguage.CPP, - callback, - new NullLogService(), null), - callback, - ParserMode.SELECTION_PARSE, - ParserLanguage.CPP, - ParserFactory.createDefaultLogService() - ); - - ISelectionParseResult result = parser.parse( startOffset, endOffset ); - - return (IASTNode) ( (result != null) ? result.getOffsetableNamedElement() : null ); - } - - protected void assertNodeLocation( IASTNode result, IFile file, int offset ) throws Exception { - if( result != null && result instanceof IASTOffsetableNamedElement ){ - IASTOffsetableNamedElement el = (IASTOffsetableNamedElement) result; - assertEquals( file.getLocation().toOSString(), new String( el.getFilename() ) ); - assertEquals( offset, el.getNameOffset() ); - return; - } - fail("Node not found in " + file.getLocation().toOSString() + " offset " + offset); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - protected void assertNodeNull( IASTNode node ) throws Exception { - if (node == null) { - return; - } - if (node instanceof IASTOffsetableNamedElement) { - IASTOffsetableNamedElement el = (IASTOffsetableNamedElement) node; - fail ("node found at " + new String( el.getFilename()) + " offset " + el.getNameOffset() ); //$NON-NLS-1$ //$NON-NLS-2$ - return; - } - fail("Node found when none expected."); //$NON-NLS-1$ - } - public void testSimpleOpenDeclaration() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class A{}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " A a; \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - - int start = source.indexOf( "A" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$ - } - public void testClass() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class A{}; \n"); //$NON-NLS-1$ - writer.write("namespace N { \n"); //$NON-NLS-1$ - writer.write(" class B { \n"); //$NON-NLS-1$ - writer.write(" class C{}; \n"); //$NON-NLS-1$ - writer.write(" }; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "A/*vp1*/ a; \n"); //$NON-NLS-1$ - writer.write( "N::B/*vp2*/ b; \n"); //$NON-NLS-1$ - writer.write( "using namespace N; \n"); //$NON-NLS-1$ - writer.write( "B::C/*vp3*/ c; \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global; Seln global - int start = source.indexOf( "A/*vp1*/" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$ - //vp2 Decln in namespace; Seln global, scoped - start = source.indexOf( "N::B/*vp2*/" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 4 ); - assertNodeLocation( node, h, header.indexOf("B")); //$NON-NLS-1$ - //vp3 Decln in namespace and nested class; Seln in partially scoped ref - start = source.indexOf( "C/*vp3*/" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("C")); //$NON-NLS-1$ - - } - public void testClassRHS() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class A{ \n"); //$NON-NLS-1$ - writer.write(" enum{E0}; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "int a=A::E0; \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp 1 Decln global, Seln global, on rhs of assignment - int start = source.indexOf( "A" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$ - } - public void testStruct() throws Exception{ - Writer writer = new StringWriter(); - writer.write("struct A{};//vp1 \n"); //$NON-NLS-1$ - writer.write("class B{ \n"); //$NON-NLS-1$ - writer.write(" public: struct C{}; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("namespace N{ \n"); //$NON-NLS-1$ - writer.write(" struct A{};//vp3 \n"); //$NON-NLS-1$ - writer.write(" struct D{}; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " A a;//vp1 \n"); //$NON-NLS-1$ - writer.write( " B::C d;//vp2 \n"); //$NON-NLS-1$ - writer.write( " N::A e;//vp3 \n"); //$NON-NLS-1$ - writer.write( " using namespace N; \n"); //$NON-NLS-1$ - writer.write( " A/*vp4*/ f; \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global; Seln in function - int start = source.indexOf( "A a;//vp1" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("A{};//vp1")); //$NON-NLS-1$ - //vp2 Decln in class; Seln in function, in :: scope - start = source.indexOf( "C" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("C")); //$NON-NLS-1$ - //vp3 Decln in namespace; Seln in function, fully qualified - start = source.indexOf( "N::A" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 4 ); - assertNodeLocation( node, h, header.indexOf("A{};//vp3")); //$NON-NLS-1$ //$NON-NLS-2$ - //vp4 Decln ambiguous; Seln in function, unqualified - start = source.indexOf( "A/*vp4*/" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 1 ); - assertNodeNull( node ); - } - public void testStructRHS() throws Exception{ - Writer writer = new StringWriter(); - writer.write("struct A{ \n"); //$NON-NLS-1$ - writer.write(" static const float pi=3.14; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " float f=A::pi; \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global; Seln in function, rhs of assignment - int start = source.indexOf( "A" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$ - } - public void testEnumeration() throws Exception{ - Writer writer = new StringWriter(); - writer.write("enum A{}; \n"); //$NON-NLS-1$ - writer.write("class B{ \n"); //$NON-NLS-1$ - writer.write(" public: \n"); //$NON-NLS-1$ - writer.write(" enum C {enum2}; \n"); //$NON-NLS-1$ - writer.write(" void boo(); \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " A/*vp1*/ a; \n"); //$NON-NLS-1$ - writer.write( " B::C/*vp2*/ c; \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global; Seln in function - int start = source.indexOf( "A" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$ - //vp2 Decln in class; Seln in function, fully qualified - start = source.indexOf( "B::C" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 4 ); - assertNodeLocation( node, h, header.indexOf("C")); //$NON-NLS-1$ - } - public void testEnumerationArg() throws Exception{ - Writer writer = new StringWriter(); - writer.write("enum A{}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(A a){}; \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global; Seln in argument list of function - int start = source.indexOf( "A" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$ - } - public void testEnumerator() throws Exception{ - Writer writer = new StringWriter(); - writer.write("enum A{enum1}; \n"); //$NON-NLS-1$ - writer.write("class B{ \n"); //$NON-NLS-1$ - writer.write(" public: \n"); //$NON-NLS-1$ - writer.write(" enum {enum2}; \n"); //$NON-NLS-1$ - writer.write(" enum {enum3} f1; \n"); //$NON-NLS-1$ - writer.write(" void boo(); \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " A a; \n"); //$NON-NLS-1$ - writer.write( " a=enum1;//vp1 \n"); //$NON-NLS-1$ - writer.write( " int i=B::enum2;//vp2 \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - writer.write( "void B::boo() { \n"); //$NON-NLS-1$ - writer.write( " f1=enum3;//vp3 \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global; Seln in function, on rhs of assignment - int start = source.indexOf( "enum1" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 5 ); - assertNodeLocation( node, h, header.indexOf("enum1")); //$NON-NLS-1$ - //vp2 Decln in class, in anon enumeration; Seln in function, on rhs of assignment, in :: scope - start = source.indexOf( "enum2" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 5 ); - assertNodeLocation( node, h, header.indexOf("enum2")); //$NON-NLS-1$ - //vp3 Decln in class, in anon enumeration with field; Seln in method, on rhs of assignment - start = source.indexOf( "enum3" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 5 ); - assertNodeLocation( node, h, header.indexOf("enum3")); //$NON-NLS-1$ - } - public void testMethod() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class A{ \n"); //$NON-NLS-1$ - writer.write("int method1(){} \n"); //$NON-NLS-1$ - writer.write("static const int method2(); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " A a; \n"); //$NON-NLS-1$ - writer.write( " a.method1();//vp1 \n"); //$NON-NLS-1$ - writer.write( " A *b=new A(); \n"); //$NON-NLS-1$ - writer.write( " b->method1();//vp2 \n"); //$NON-NLS-1$ - writer.write( " A::method2();//vp3 \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln private; Seln in function, in dot reference - int start = source.indexOf( "method1();//vp1" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 7 ); - assertNodeLocation( node, h, header.indexOf("method1")); //$NON-NLS-1$ - //vp2 Decln private; Seln in function, in arrow reference - start = source.indexOf( "method1();//vp2" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 7 ); - assertNodeLocation( node, h, header.indexOf("method1")); //$NON-NLS-1$ - //vp3 Decln private; Seln in function, in scope reference - start = source.indexOf( "method2();//vp3" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 7 ); - assertNodeLocation( node, h, header.indexOf("method2")); //$NON-NLS-1$ //$NON-NLS-2$ - } - public void testMethodRHS78656() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class A{ \n"); //$NON-NLS-1$ - writer.write("int method1(){} \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " A a; \n"); //$NON-NLS-1$ - writer.write( " int i=a.method1();//vp1 \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln private; Seln in dot reference, on RHS of assignment - //defect is node not found - int start = source.indexOf( "method1();//vp1" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 7 ); - assertNodeLocation( node, h, header.indexOf("method1")); //$NON-NLS-1$ - } - public void testMethod78114() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class Point{ \n"); //$NON-NLS-1$ - writer.write(" public: \n"); //$NON-NLS-1$ - writer.write(" Point(): xCoord(0){} \n"); //$NON-NLS-1$ - writer.write(" private: int xCoord; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " Point &p2 = *(new Point()); \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln public; Seln on rhs in code scope - //defect is class is found rather than constructor - int start = source.indexOf( "Point()" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 5 ); - assertNodeLocation( node, h, header.indexOf("Point()")); //$NON-NLS-1$ - } - public void testMethod78118() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class Point{ \n"); //$NON-NLS-1$ - writer.write(" public: \n"); //$NON-NLS-1$ - writer.write(" Point(): xCoord(0){} \n"); //$NON-NLS-1$ - writer.write(" Point& operator=(const Point &rhs){return *this}; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " Point a; \n"); //$NON-NLS-1$ - writer.write( " const Point zero; \n"); //$NON-NLS-1$ - writer.write( " a.operator=(zero);//vp1 \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln in class, public; Seln in function, in dot reference - //defect is npe; parser field, greaterContextDuple is null - int start = source.indexOf( "operator=" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 9 ); - assertNodeLocation( node, h, header.indexOf("operator=")); //$NON-NLS-1$ //$NON-NLS-2$ - } - public void testOverloadedMethod78389() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class Point{ \n"); //$NON-NLS-1$ - writer.write(" public: \n"); //$NON-NLS-1$ - writer.write(" void method1(){} \n"); //$NON-NLS-1$ - writer.write(" void method1(int i){} \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " Point a; \n"); //$NON-NLS-1$ - writer.write( " a.method1(3); \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln public; Seln in function, in dot reference - //defect is operation unavailable on current selection - int start = source.indexOf( "method1" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 7 ); - assertNodeLocation( node, h, header.indexOf("method1(int i)")); //$NON-NLS-1$ //$NON-NLS-2$ - - } - public void testConstructor78625() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class Mammal { \n" ); //$NON-NLS-1$ - writer.write(" public: \n" ); //$NON-NLS-1$ - writer.write(" Mammal(bool b): isCarnivore(b){} \n" ); //$NON-NLS-1$ - writer.write(" private: \n" ); //$NON-NLS-1$ - writer.write(" bool isCarnivore; \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - writer.write("class Bear : Mammal{ \n" ); //$NON-NLS-1$ - writer.write("public: \n" ); //$NON-NLS-1$ - writer.write(" Bear(int s): Mammal(true){}//vp1 \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln public; Seln in initializer list of derived class cctor - int start = source.indexOf( "Mammal(true)" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 6 ); - assertNodeLocation( node, cpp, source.indexOf("Mammal(bool b)")); //$NON-NLS-1$ - - } - - public void testClassField() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class A{; \n"); //$NON-NLS-1$ - writer.write("int bee; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " A *a=new A(); \n"); //$NON-NLS-1$ - writer.write( " a->bee;//vp1 \n"); //$NON-NLS-1$ - writer.write( " A b; \n"); //$NON-NLS-1$ - writer.write( " b.bee;//vp2 \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln in class; Seln in function, in arrow reference - int start = source.indexOf( "bee;//vp1" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 3 ); - assertNodeLocation( node, h, header.indexOf("bee")); //$NON-NLS-1$ - //vp2 Decln in class; Seln in function, in dot reference - start = source.indexOf( "bee;//vp2" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 3 ); - assertNodeLocation( node, h, header.indexOf("bee")); //$NON-NLS-1$ - } - public void testStructField() throws Exception{ - Writer writer = new StringWriter(); - writer.write("namespace N{ \n"); //$NON-NLS-1$ - writer.write("struct A{ \n"); //$NON-NLS-1$ - writer.write("int bee; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " N::A *a; \n"); //$NON-NLS-1$ - writer.write( " a->bee;//vp1 \n"); //$NON-NLS-1$ - writer.write( " using namespace N; \n"); //$NON-NLS-1$ - writer.write( " A b; \n"); //$NON-NLS-1$ - writer.write( " b.bee;//vp2 \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln in struct in namespace; Seln in function, in arrow reference - int start = source.indexOf( "bee;//vp1" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 3 ); - assertNodeLocation( node, h, header.indexOf("bee")); //$NON-NLS-1$ //$NON-NLS-2$ - //vp2 Decln in struct in namespace; Seln in function, in dot reference - start = source.indexOf( "bee;//vp2" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 3 ); - assertNodeLocation( node, h, header.indexOf("bee")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void testNamespace() throws Exception{ - Writer writer = new StringWriter(); - writer.write("namespace N{ \n"); //$NON-NLS-1$ - writer.write("class A{}; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " N::A a; \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global; Seln in function - int start = source.indexOf( "N::A a;" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("N")); //$NON-NLS-1$ //$NON-NLS-2$ - - } - public void testNamespace77989() throws Exception{ - Writer writer = new StringWriter(); - writer.write("namespace N{ \n"); //$NON-NLS-1$ - writer.write("class A{}; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " using namespace N;//vp1 \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global; Seln in function, in using statement - //defect is decln found at the selection, not in the header - int start = source.indexOf( "N;//vp1" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("N")); //$NON-NLS-1$ - - } - public void testFunction() throws Exception{ - Writer writer = new StringWriter(); - writer.write("namespace N{ \n"); //$NON-NLS-1$ - writer.write("char *foo(){} \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " N::foo();//vp1 \n"); //$NON-NLS-1$ - writer.write( " char* x = N::foo();//vp2 \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln in namespace; Seln in function, in scope reference - int start = source.indexOf( "foo();//vp1" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 3 ); - assertNodeLocation( node, h, header.indexOf("foo")); //$NON-NLS-1$ - //vp2 Decln in namespace; Seln in function, scoped, on rhs of assignment - start = source.indexOf( "N::foo();//vp2" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 6 ); - assertNodeLocation( node, h, header.indexOf("foo")); //$NON-NLS-1$ - } - public void testFunctionArg() throws Exception{ - Writer writer = new StringWriter(); - writer.write("double f(double){return 2.0;}; \n"); //$NON-NLS-1$ - writer.write("double g(double){return 2.0;}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "double sum_sq(double (*foo)(double), double d){} \n"); //$NON-NLS-1$ - writer.write( "void hi() {double x = sum_sq(g,g(3.2));} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global; Seln in function, in actual parameter list of caller - int start = source.indexOf( "g,g(3.2)" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("g")); //$NON-NLS-1$ - //vp2 Decln global; Seln in function, in actual parameter list of caller - start = source.indexOf( "g(3.2)" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("g")); //$NON-NLS-1$ - } - public void testFunctionArg78435() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "double sum_sq(double (*foo)/*vp1*/(double), double d){} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln is inside formal parameter list; Seln is declaration - //defect is that operation is unavailable on current selection - int start = source.indexOf( "foo" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 3 ); - assertNodeLocation( node, cpp, source.indexOf("foo")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - - public void testVariable() throws Exception{ - Writer writer = new StringWriter(); - writer.write("char* a_pc=\"hello\"; \n"); //$NON-NLS-1$ - writer.write("union B{int x; char y;} b_u; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " int s=(sizeof(a_pc));//vp1 \n"); //$NON-NLS-1$ - writer.write( " b_u=3; \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global, type char*; Seln in function, on rhs, in actual parameter list of caller - int start = source.indexOf( "a_pc" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 4 ); - assertNodeLocation( node, h, header.indexOf("a_pc")); //$NON-NLS-1$ - //vp2 Decln global, type union; Seln in function - start = source.indexOf( "b_u" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 3 ); - assertNodeLocation( node, h, header.indexOf("b_u")); //$NON-NLS-1$ - } - public void testVariableArg78435() throws Exception{ - - Writer writer = new StringWriter(); - writer.write( "int aa; \n"); //$NON-NLS-1$ - writer.write( "void f(int aa){} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Variable: Decln is in formal parameter list; Seln is itself - //defect is the global aa is found instead - int start = source.indexOf( "aa" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 2 ); - assertNodeLocation( node, cpp, source.indexOf("aa){}")); //$NON-NLS-1$ - } - public void testVariableStruct() throws Exception{ - Writer writer = new StringWriter(); - writer.write("struct C {int i;}; \n"); //$NON-NLS-1$ - writer.write("C c; \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " c.i/*vp1*/=3; \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global, type struct also defined globally; Seln in function - int start = source.indexOf( "c.i/*vp1*/" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("c;")); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public void testVariableArg() throws Exception{ - Writer writer = new StringWriter(); - writer.write( "int aa=3; \n"); //$NON-NLS-1$ - writer.write( "void f(int aa){//decl \n"); //$NON-NLS-1$ - writer.write( " int bb=aa;//vp1 \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln in formal argument list of function; Seln in function definition, on rhs of assignment - int start = source.indexOf( "aa;" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 2 ); - assertNodeLocation( node, cpp, source.indexOf("aa){//decl")); //$NON-NLS-1$ //$NON-NLS-2$ - } - public void testVariableClass77996() throws Exception{ - Writer writer = new StringWriter(); - writer.write("class C {public: int i;}; \n"); //$NON-NLS-1$ - String header = writer.toString(); - importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " C c; \n"); //$NON-NLS-1$ - writer.write( " c.i/*vp1*/=3; \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln in function, type declared outside function, Seln in function - int start = source.indexOf( "c.i/*vp1*/" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, cpp, source.indexOf("c;")); //$NON-NLS-1$ - } - public void testUnion() throws Exception{ - Writer writer = new StringWriter(); - writer.write("union A{}; \n"); //$NON-NLS-1$ - writer.write("class B{ \n"); //$NON-NLS-1$ - writer.write(" union C{} c; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "a.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"a.h\" \n"); //$NON-NLS-1$ - writer.write( "void f(){ \n"); //$NON-NLS-1$ - writer.write( " A a; //vp1 \n"); //$NON-NLS-1$ - writer.write( " B::C c; //vp2 \n"); //$NON-NLS-1$ - writer.write( "} \n"); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "a.cpp", source ); //$NON-NLS-1$ - //vp1 Decln global; Seln in function - int start = source.indexOf( "A" ); //$NON-NLS-1$ - IASTNode node = getSelection( cpp, start, start + 1 ); - assertNodeLocation( node, h, header.indexOf("A")); //$NON-NLS-1$ - //vp2 Decln in class; Seln in function, scoped - start = source.indexOf( "B::C" ); //$NON-NLS-1$ - node = getSelection( cpp, start, start + 4 ); - assertNodeLocation( node, h, header.indexOf("C")); //$NON-NLS-1$ - } -} diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index 593e0a6013a..fbf3420192a 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -29,9 +29,6 @@ import org.eclipse.cdt.core.model.tests.AllCoreTests; import org.eclipse.cdt.core.model.tests.BinaryTests; import org.eclipse.cdt.core.model.tests.ElementDeltaTests; import org.eclipse.cdt.core.model.tests.WorkingCopyTests; -import org.eclipse.cdt.core.parser.failedTests.ASTFailedTests; -import org.eclipse.cdt.core.parser.failedTests.FailedCompleteParseASTTest; -import org.eclipse.cdt.core.parser.failedTests.STLFailedTests; import org.eclipse.cdt.core.parser.tests.ParserTestSuite; import org.eclipse.cdt.core.tests.templateengine.AllTemplateEngineTests; import org.eclipse.cdt.internal.index.tests.IndexTests; @@ -72,26 +69,11 @@ public class AutomatedIntegrationSuite extends TestSuite { suite.addTest(WorkingCopyTests.suite()); suite.addTest(PositionTrackerTests.suite()); suite.addTest(AllLanguageTests.suite()); - - // TODO turning off indexer/search tests until the PDOM - // settles. These'll probably have to be rewritten anyway. -// suite.addTest(SearchTestSuite.suite()); -// suite.addTest(DependencyTests.suite()); -// suite.addTest(RegressionTestSuite.suite()); - //Indexer Tests need to be run after any indexer client tests - //as the last test shuts down the indexing thread -// suite.addTest(DOMSourceIndexerTests.suite()); - // Last test to trigger report generation - + // Add in PDOM tests suite.addTest(PDOMTests.suite()); suite.addTest(IndexTests.suite()); - - // Add all failed tests - suite.addTestSuite(ASTFailedTests.class); - suite.addTestSuite(STLFailedTests.class); - suite.addTestSuite(FailedCompleteParseASTTest.class); - + suite.addTest(AllTemplateEngineTests.suite()); return suite; diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index 079e3799363..5a343694fd9 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -29,8 +29,6 @@ Export-Package: org.eclipse.cdt.core, org.eclipse.cdt.core.model.util, org.eclipse.cdt.core.parser, org.eclipse.cdt.core.parser.ast, - org.eclipse.cdt.core.parser.ast.gcc, - org.eclipse.cdt.core.parser.extension, org.eclipse.cdt.core.parser.util, org.eclipse.cdt.core.resources, org.eclipse.cdt.core.settings.model, @@ -54,13 +52,7 @@ Export-Package: org.eclipse.cdt.core, org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring", org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui", org.eclipse.cdt.internal.core.parser;x-internal:=true, - org.eclipse.cdt.internal.core.parser.ast;x-internal:=true, - org.eclipse.cdt.internal.core.parser.ast.complete;x-internal:=true, - org.eclipse.cdt.internal.core.parser.ast.complete.gcc;x-internal:=true, - org.eclipse.cdt.internal.core.parser.ast.gcc;x-internal:=true, - org.eclipse.cdt.internal.core.parser.ast.quick;x-internal:=true, org.eclipse.cdt.internal.core.parser.problem;x-internal:=true, - org.eclipse.cdt.internal.core.parser.pst;x-internal:=true, org.eclipse.cdt.internal.core.parser.scanner;x-internal:=true, org.eclipse.cdt.internal.core.parser.scanner2;x-internal:=true, org.eclipse.cdt.internal.core.parser.token;x-friends:="org.eclipse.cdt.ui", diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java deleted file mode 100644 index 148db2dd999..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java +++ /dev/null @@ -1,848 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Rational Software - initial implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IParent; -import org.eclipse.cdt.core.model.IProblemRequestor; -import org.eclipse.cdt.core.model.IStructure; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.ExtendedScannerInfo; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.IQuickParseCallback; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.IScannerInfoProvider; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ParserUtil; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifierOwner; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ParserException; -import org.eclipse.cdt.internal.core.parser.StructuralParseCallback; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; - - -public class CModelBuilder { - - private org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit; - private Map newElements; - private IQuickParseCallback quickParseCallback; - private static char[] EMPTY_CHAR_ARRAY = {}; - // indicator if the unit has parse errors - private boolean hasNoErrors = false; - - class ProblemCallback extends StructuralParseCallback { - IProblemRequestor problemRequestor; - - public ProblemCallback(IProblemRequestor requestor) { - problemRequestor = requestor; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.QuickParseCallback#acceptProblem(org.eclipse.cdt.core.parser.IProblem) - */ - public boolean acceptProblem(IProblem problem) { - // Do not worry for now about problems in other files. - if (inclusionLevel == 0) { - problemRequestor.acceptProblem(problem); - } - return true; - } - } - - public CModelBuilder(org.eclipse.cdt.internal.core.model.TranslationUnit tu, Map newElements) { - this.translationUnit = tu ; - this.newElements = newElements; - } - - private IASTCompilationUnit parse(boolean quickParseMode, boolean throwExceptionOnError) throws ParserException - { - IProject currentProject = null; - boolean hasCppNature = true; - char[] code = EMPTY_CHAR_ARRAY; - - // get the current project - if (translationUnit != null && translationUnit.getCProject() != null) { - currentProject = translationUnit.getCProject().getProject(); - } - // check the project's nature - if (currentProject != null) { - hasCppNature = CoreModel.hasCCNature(currentProject); - } - // get the code to parse - try { - code = translationUnit.getBuffer().getCharacters(); - } catch (CModelException e) { - - } - - final IProblemRequestor problemRequestor = translationUnit.getProblemRequestor(); - // use quick or structural parse mode - ParserMode mode = quickParseMode ? ParserMode.QUICK_PARSE : ParserMode.STRUCTURAL_PARSE; - if (problemRequestor == null) { - quickParseCallback = (quickParseMode) ? ParserFactory.createQuickParseCallback() : - ParserFactory.createStructuralParseCallback(); - } else { - quickParseCallback = new ProblemCallback(problemRequestor); - } - - // pick the language - ParserLanguage language; - if (hasCppNature) { - language = ParserLanguage.CPP; - } else { - // for C project try to guess. - language = translationUnit.isCXXLanguage() ? ParserLanguage.CPP : ParserLanguage.C; - } - - // create the parser - IParser parser = null; - try { - IScannerInfo scanInfo = null; - IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(currentProject); - if (provider != null){ - IScannerInfo buildScanInfo = null; - IResource res = translationUnit.getResource(); - if (res != null) { - buildScanInfo = provider.getScannerInformation(res); - } - // Technically we should not do this. But the managed scanner providers - // may rely on this behaviour i.e. only provide scannerInfo for projects - if (buildScanInfo == null) { - buildScanInfo = provider.getScannerInformation(currentProject); - } - if (buildScanInfo != null){ - scanInfo = new ExtendedScannerInfo(buildScanInfo); - } - } - if (scanInfo == null) { - scanInfo = new ExtendedScannerInfo(); - } - - IResource resource = translationUnit.getUnderlyingResource(); - CodeReader reader = - resource != null && resource.getLocation() != null - ? new CodeReader(translationUnit.getUnderlyingResource().getLocation().toOSString(), code) - : new CodeReader(code); - parser = ParserFactory.createParser( - ParserFactory.createScanner( - reader, - scanInfo, - mode, - language, - quickParseCallback, - quickParseMode ? new NullLogService() : ParserUtil.getScannerLogService(), null) - ,quickParseCallback, - mode, - language, - ParserUtil.getParserLogService() ); - } catch(ParserFactoryError pfe) { - throw new ParserException( ""); //$NON-NLS-1$ - } - // call parse - if (problemRequestor != null) { - problemRequestor.beginReporting(); - } - hasNoErrors = parser.parse(); - if (problemRequestor != null) { - problemRequestor.endReporting(); - } - if( (!hasNoErrors) && throwExceptionOnError ) - throw new ParserException(""); //$NON-NLS-1$ - return quickParseCallback.getCompilationUnit(); - } - - - public Map parse(boolean quickParseMode) throws Exception { - long startTime = System.currentTimeMillis(); - try { - parse(quickParseMode, true); - } catch( ParserException e ) { - Util.debugLog( "Parse Exception in CModelBuilder", IDebugLogConstants.MODEL ); //$NON-NLS-1$ - //e.printStackTrace(); - } - Util.debugLog("CModelBuilder: parsing " //$NON-NLS-1$ - + translationUnit.getElementName() - + " mode="+ (quickParseMode ? "quick " : "structural ") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - + " time="+ ( System.currentTimeMillis() - startTime ) + "ms", //$NON-NLS-1$ //$NON-NLS-2$ - IDebugLogConstants.MODEL, false); - - startTime = System.currentTimeMillis(); - try { - generateModelElements(); - // important to know if the unit has parse errors or not - translationUnit.getElementInfo().setIsStructureKnown(hasNoErrors && quickParseCallback.hasNoProblems()); - } catch( NullPointerException npe ) { - Util.debugLog( "NullPointer exception in CModelBuilder", IDebugLogConstants.MODEL); //$NON-NLS-1$ - } - - // For the debuglog to take place, you have to call - // Util.setDebugging(true); - // Or set debug to true in the core plugin preference - Util.debugLog("CModelBuilder: building " //$NON-NLS-1$ - +"children="+ translationUnit.getElementInfo().internalGetChildren().size() //$NON-NLS-1$ - +" time="+ (System.currentTimeMillis() - startTime) + "ms", //$NON-NLS-1$ //$NON-NLS-2$ - IDebugLogConstants.MODEL, false); - return this.newElements; - - } - - private void generateModelElements() throws CModelException{ - Iterator i = quickParseCallback.iterateOffsetableElements(); - while (i.hasNext()){ - IASTOffsetableElement offsetable = (IASTOffsetableElement)i.next(); - if(offsetable instanceof IASTInclusion){ - IASTInclusion inc = (IASTInclusion) offsetable; - if( ! inc.isImplicit() ) - createInclusion(translationUnit, inc ); - } - else if(offsetable instanceof IASTMacro){ - - IASTMacro macro = (IASTMacro) offsetable; - if( ! macro.isImplicit() ) - createMacro(translationUnit, macro); - }else if(offsetable instanceof IASTDeclaration){ - try{ - generateModelElements (translationUnit, (IASTDeclaration) offsetable); - } catch(ASTNotImplementedException e){ - } - } - } - } - - private void generateModelElements (Parent parent, IASTDeclaration declaration) throws CModelException, ASTNotImplementedException - { - if(declaration instanceof IASTNamespaceDefinition ) { - generateModelElements(parent, (IASTNamespaceDefinition) declaration); - } - - if(declaration instanceof IASTAbstractTypeSpecifierDeclaration ) { - generateModelElements(parent, (IASTAbstractTypeSpecifierDeclaration) declaration); - } - - if(declaration instanceof IASTTemplateDeclaration ) { - generateModelElements(parent, (IASTTemplateDeclaration) declaration); - } - - if(declaration instanceof IASTTypedefDeclaration ) { - generateModelElements(parent, (IASTTypedefDeclaration) declaration); - } - - if(declaration instanceof IASTLinkageSpecification) { - generateModelElements(parent, (IASTLinkageSpecification)declaration); - } - - if (declaration instanceof IASTUsingDirective) { - createUsingDirective(parent, (IASTUsingDirective)declaration); - } - - if (declaration instanceof IASTUsingDeclaration) { - createUsingDeclaration(parent, (IASTUsingDeclaration)declaration); - } - createSimpleElement(parent, declaration, false); - } - - private void generateModelElements (Parent parent, IASTNamespaceDefinition declaration) throws CModelException, ASTNotImplementedException{ - // IASTNamespaceDefinition - IParent namespace = createNamespace(parent, declaration); - Iterator nsDecls = declaration.getDeclarations(); - while (nsDecls.hasNext()){ - IASTDeclaration subNsDeclaration = (IASTDeclaration) nsDecls.next(); - generateModelElements((Parent)namespace, subNsDeclaration); - } - } - - private void generateModelElements (Parent parent, IASTLinkageSpecification declaration) throws CModelException, ASTNotImplementedException{ - // IASTLinkageSpecification - Iterator nsDecls = declaration.getDeclarations(); - while (nsDecls.hasNext()){ - IASTDeclaration subNsDeclaration = (IASTDeclaration) nsDecls.next(); - generateModelElements(parent, subNsDeclaration); - } - } - - private void generateModelElements (Parent parent, IASTAbstractTypeSpecifierDeclaration abstractDeclaration) throws CModelException, ASTNotImplementedException - { - // IASTAbstractTypeSpecifierDeclaration - createAbstractElement(parent, abstractDeclaration, false, true); - } - - private void generateModelElements (Parent parent, IASTTemplateDeclaration templateDeclaration) throws CModelException, ASTNotImplementedException - { - CElement element = null; - // Template Declaration - IASTDeclaration declaration = templateDeclaration.getOwnedDeclaration(); - if (declaration instanceof IASTAbstractTypeSpecifierDeclaration){ - // Class Template Declation ? - IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declaration ; - element = createAbstractElement(parent, abstractDeclaration , true, true); - String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration); - if (element instanceof StructureTemplate) { - // set the template parameters - StructureTemplate classTemplate = (StructureTemplate) element; - classTemplate.setTemplateParameterTypes(parameterTypes); - } else if (element instanceof StructureTemplateDeclaration) { - // set the template parameters - StructureTemplateDeclaration classTemplate = (StructureTemplateDeclaration) element; - classTemplate.setTemplateParameterTypes(parameterTypes); - } - } else if (declaration instanceof IASTClassSpecifier){ - // special case for Structural parse - // Class template definiton ? - IASTClassSpecifier classSpecifier = (IASTClassSpecifier)declaration ; - element = createClassSpecifierElement(parent, classSpecifier , true); - String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration); - if (element instanceof StructureTemplate) { - // set the template parameters - StructureTemplate classTemplate = (StructureTemplate) element; - classTemplate.setTemplateParameterTypes(parameterTypes); - } else if (element instanceof StructureTemplateDeclaration) { - // set the template parameters - StructureTemplateDeclaration classTemplate = (StructureTemplateDeclaration) element; - classTemplate.setTemplateParameterTypes(parameterTypes); - } - } else if (declaration instanceof IASTVariable) { - // Template variable - element = createSimpleElement(parent, declaration, true); - // set the template parameters - String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration); - VariableTemplate varTemplate = (VariableTemplate) element; - varTemplate.setTemplateParameterTypes(parameterTypes); - } else if (declaration instanceof IASTFunction) { - // Function template declaration/Definition - element = createSimpleElement(parent, declaration, true); - String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration); - if (element instanceof FunctionTemplate) { - // set the template parameters - FunctionTemplate functionTemplate = (FunctionTemplate) element; - functionTemplate.setTemplateParameterTypes(parameterTypes); - } else if (element instanceof FunctionTemplateDeclaration) { - // set the template parameters - FunctionTemplateDeclaration functionTemplate = (FunctionTemplateDeclaration) element; - functionTemplate.setTemplateParameterTypes(parameterTypes); - } else if (element instanceof MethodTemplate) { - MethodTemplate methodTemplate = (MethodTemplate) element; - methodTemplate.setTemplateParameterTypes(parameterTypes); - } else if (element instanceof MethodTemplateDeclaration) { - MethodTemplateDeclaration methodTemplate = (MethodTemplateDeclaration) element; - methodTemplate.setTemplateParameterTypes(parameterTypes); - } - } - if (element instanceof SourceManipulation){ - SourceManipulation sourceRef = (SourceManipulation)element; - // set the element position - sourceRef.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset()); - sourceRef.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() ); - } - } - - private void generateModelElements (Parent parent, IASTTypedefDeclaration declaration) throws CModelException, ASTNotImplementedException - { - Parent typeDef= createTypeDef(parent, declaration); - if (typeDef instanceof IParent) { - // create nested - parent= typeDef; - } - IASTAbstractDeclaration abstractDeclaration = declaration.getAbstractDeclarator(); - if (abstractDeclaration != null && !(abstractDeclaration.getTypeSpecifier() instanceof IASTElaboratedTypeSpecifier)) { - createAbstractElement(parent, abstractDeclaration, false, true); - } - } - - private CElement createClassSpecifierElement(Parent parent, IASTClassSpecifier classSpecifier, boolean isTemplate)throws ASTNotImplementedException, CModelException{ - CElement element = null; - IParent classElement = createClass(parent, classSpecifier, isTemplate); - element = (CElement) classElement; - - // create the sub declarations - Iterator j = classSpecifier.getDeclarations(); - while (j.hasNext()){ - IASTDeclaration subDeclaration = (IASTDeclaration)j.next(); - generateModelElements((Parent)classElement, subDeclaration); - } // end while j - return element; - } - - private CElement createAbstractElement(Parent parent, IASTTypeSpecifierOwner abstractDeclaration, boolean isTemplate, boolean isDeclaration)throws ASTNotImplementedException, CModelException{ - CElement element = null; - if (abstractDeclaration != null){ - IASTTypeSpecifier typeSpec = abstractDeclaration.getTypeSpecifier(); - // IASTEnumerationSpecifier - if (typeSpec instanceof IASTEnumerationSpecifier) { - IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) typeSpec; - IParent enumElement = createEnumeration (parent, enumSpecifier); - element = (CElement) enumElement; - } else if (typeSpec instanceof IASTClassSpecifier) { - // IASTClassSpecifier - IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpec; - element = createClassSpecifierElement (parent, classSpecifier, isTemplate); - } else if (isDeclaration && typeSpec instanceof IASTElaboratedTypeSpecifier) { - // This is not a model element, so we don't create anything here. - // However, do we need to do anything else? - IASTElaboratedTypeSpecifier elabSpecifier = (IASTElaboratedTypeSpecifier) typeSpec; - element = createElaboratedTypeSpecifier(parent, elabSpecifier, isTemplate); - } - } - return element; - } - - private CElement createSimpleElement(Parent parent, IASTDeclaration declaration, boolean isTemplate)throws CModelException, ASTNotImplementedException{ - - CElement element = null; - if (declaration instanceof IASTVariable) - { - element = createVariableSpecification(parent, (IASTVariable)declaration, isTemplate); - } - // function or method - else if(declaration instanceof IASTFunction ) - { - element = createFunctionSpecification(parent, (IASTFunction)declaration, isTemplate); - } - return element; - } - - private StructureDeclaration createElaboratedTypeSpecifier(Parent parent, IASTElaboratedTypeSpecifier typeSpec, boolean isTemplate) throws CModelException{ - // create element - ASTClassKind classkind = typeSpec.getClassKind(); - int kind = -1; - if (classkind == ASTClassKind.CLASS) { - kind = (isTemplate) ? ICElement.C_TEMPLATE_CLASS_DECLARATION : ICElement.C_CLASS_DECLARATION; - } else if (classkind == ASTClassKind.STRUCT) { - kind = (isTemplate) ? ICElement.C_TEMPLATE_STRUCT_DECLARATION : ICElement.C_STRUCT_DECLARATION; - } else if (classkind == ASTClassKind.UNION) { - kind = (isTemplate) ? ICElement.C_TEMPLATE_UNION_DECLARATION : ICElement.C_UNION_DECLARATION; - } - String className = (typeSpec.getName() == null) - ? "" //$NON-NLS-1$ - : typeSpec.getName().toString(); - - StructureDeclaration element; - if (isTemplate) { - element = new StructureTemplateDeclaration(parent, kind, className); - } else { - element = new StructureDeclaration(parent, className, kind); - } - - // add to parent - parent.addChild(element); - // set position - element.setIdPos(typeSpec.getNameOffset(), typeSpec.getNameEndOffset() - typeSpec.getNameOffset()); - element.setPos(typeSpec.getStartingOffset(), typeSpec.getEndingOffset() - typeSpec.getStartingOffset()); - element.setLines(typeSpec.getStartingLine(), typeSpec.getEndingLine()); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private Include createInclusion(Parent parent, IASTInclusion inclusion) throws CModelException{ - // create element - Include element = new Include(parent, inclusion.getName(), !inclusion.isLocal()); - element.setFullPathName(inclusion.getFullFileName()); - // add to parent - parent.addChild(element); - // set position - element.setIdPos(inclusion.getNameOffset(), inclusion.getNameEndOffset() - inclusion.getNameOffset()); - element.setPos(inclusion.getStartingOffset(), inclusion.getEndingOffset() - inclusion.getStartingOffset()); - element.setLines( inclusion.getStartingLine(), inclusion.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private Macro createMacro(Parent parent, IASTMacro macro) throws CModelException{ - // create element - org.eclipse.cdt.internal.core.model.Macro element = new Macro(parent, macro.getName()); - // add to parent - parent.addChild(element); - // set position - element.setIdPos(macro.getNameOffset(), macro.getNameEndOffset() - macro.getNameOffset()); - element.setPos(macro.getStartingOffset(), macro.getEndingOffset() - macro.getStartingOffset()); - element.setLines( macro.getStartingLine(), macro.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - - } - - private Namespace createNamespace(Parent parent, IASTNamespaceDefinition nsDef) throws CModelException{ - // create element - String type = "namespace"; //$NON-NLS-1$ - String nsName = (nsDef.getName() == null ) - ? "" //$NON-NLS-1$ - : nsDef.getName().toString(); - Namespace element = new Namespace (parent, nsName ); - // add to parent - parent.addChild(element); - element.setIdPos(nsDef.getNameOffset(), - (nsName.length() == 0) ? type.length() : (nsDef.getNameEndOffset() - nsDef.getNameOffset())); - element.setPos(nsDef.getStartingOffset(), nsDef.getEndingOffset() - nsDef.getStartingOffset()); - element.setLines( nsDef.getStartingLine(), nsDef.getEndingLine() ); - element.setTypeName(type); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private Enumeration createEnumeration(Parent parent, IASTEnumerationSpecifier enumSpecifier) throws CModelException{ - // create element - String type = "enum"; //$NON-NLS-1$ - String enumName = (enumSpecifier.getName() == null ) - ? "" //$NON-NLS-1$ - : enumSpecifier.getName().toString(); - Enumeration element = new Enumeration (parent, enumName ); - // add to parent - parent.addChild(element); - Iterator i = enumSpecifier.getEnumerators(); - while (i.hasNext()){ - // create sub element - IASTEnumerator enumDef = (IASTEnumerator) i.next(); - createEnumerator(element, enumDef); - } - // set enumeration position - element.setIdPos(enumSpecifier.getNameOffset(), - (enumName.length() == 0) ? type.length() : (enumSpecifier.getNameEndOffset() - enumSpecifier.getNameOffset() )); - element.setPos(enumSpecifier.getStartingOffset(), enumSpecifier.getEndingOffset() - enumSpecifier.getStartingOffset()); - element.setLines( enumSpecifier.getStartingLine(), enumSpecifier.getEndingLine() ); - element.setTypeName(type); - - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private Enumerator createEnumerator(Parent enumarator, IASTEnumerator enumDef) throws CModelException{ - Enumerator element = new Enumerator (enumarator, enumDef.getName().toString()); - IASTExpression initialValue = enumDef.getInitialValue(); - if(initialValue != null){ - element.setConstantExpression( ASTUtil.getExpressionString( initialValue ) ); - } - // add to parent - enumarator.addChild(element); - // set enumerator position - element.setIdPos(enumDef.getStartingOffset(), (enumDef.getNameEndOffset() - enumDef.getNameOffset())); - element.setPos(enumDef.getStartingOffset(), enumDef.getEndingOffset() - enumDef.getStartingOffset()); - element.setLines( enumDef.getStartingLine(), enumDef.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private Structure createClass(Parent parent, IASTClassSpecifier classSpecifier, boolean isTemplate) throws CModelException{ - // create element - String className = ""; //$NON-NLS-1$ - String type = ""; //$NON-NLS-1$ - int kind = ICElement.C_CLASS; - ASTClassKind classkind = classSpecifier.getClassKind(); - if(classkind == ASTClassKind.CLASS){ - kind = (isTemplate) ? ICElement.C_TEMPLATE_CLASS : ICElement.C_CLASS; - type = "class"; //$NON-NLS-1$ - } else if(classkind == ASTClassKind.STRUCT){ - kind = (isTemplate) ? ICElement.C_TEMPLATE_STRUCT : ICElement.C_STRUCT; - type = "struct"; //$NON-NLS-1$ - } else if(classkind == ASTClassKind.UNION){ - kind = (isTemplate) ? ICElement.C_TEMPLATE_UNION : ICElement.C_UNION; - type = "union"; //$NON-NLS-1$ - } - - className = (classSpecifier.getName() == null ) ? "" : classSpecifier.getName().toString(); //$NON-NLS-1$ - - Structure element; - if(!isTemplate){ - Structure classElement = new Structure( parent, kind, className ); - element = classElement; - } else { - StructureTemplate classTemplate = new StructureTemplate( parent, kind, className ); - element = classTemplate; - } - - // store super classes names - Iterator baseClauses = classSpecifier.getBaseClauses(); - while (baseClauses.hasNext()){ - IASTBaseSpecifier baseSpec = (IASTBaseSpecifier)baseClauses.next(); - element.addSuperClass(baseSpec.getParentClassName(), baseSpec.getAccess()); - } - - // add to parent - parent.addChild(element); - // set element position - element.setIdPos( classSpecifier.getNameOffset(), - (className.length() == 0) ? type.length() : (classSpecifier.getNameEndOffset() - classSpecifier.getNameOffset() )); - element.setTypeName( type ); - if(!isTemplate){ - // set the element position - element.setPos(classSpecifier.getStartingOffset(), classSpecifier.getEndingOffset() - classSpecifier.getStartingOffset()); - } - element.setLines( classSpecifier.getStartingLine(), classSpecifier.getEndingLine() ); - - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private TypeDef createTypeDef(Parent parent, IASTTypedefDeclaration typeDefDeclaration) throws CModelException{ - // create the element - String name = typeDefDeclaration.getName(); - - TypeDef element = new TypeDef( parent, name ); - - StringBuffer typeName = new StringBuffer(ASTUtil.getType(typeDefDeclaration.getAbstractDeclarator())); - element.setTypeName(typeName.toString()); - - // add to parent - parent.addChild(element); - - // set positions - element.setIdPos(typeDefDeclaration.getNameOffset(), (typeDefDeclaration.getNameEndOffset() - typeDefDeclaration.getNameOffset())); - element.setPos(typeDefDeclaration.getStartingOffset(), typeDefDeclaration.getEndingOffset() - typeDefDeclaration.getStartingOffset()); - element.setLines( typeDefDeclaration.getStartingLine(), typeDefDeclaration.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private VariableDeclaration createVariableSpecification(Parent parent, IASTVariable varDeclaration, boolean isTemplate)throws CModelException, ASTNotImplementedException - { - String variableName = varDeclaration.getName(); - if((variableName == null) || (variableName.length() <= 0)){ - // something is wrong, skip this element - return null; - } - - IASTAbstractDeclaration abstractDeclaration = varDeclaration.getAbstractDeclaration(); - createAbstractElement (parent, abstractDeclaration , isTemplate, false); - - VariableDeclaration element = null; - if(varDeclaration instanceof IASTField){ - IASTField fieldDeclaration = (IASTField) varDeclaration; - // field - Field newElement = new Field( parent, variableName); - newElement.setMutable(fieldDeclaration.isMutable()); - newElement.setVisibility(fieldDeclaration.getVisiblity()); - element = newElement; - } else { - if (isTemplate) { - // variable - VariableTemplate newElement = new VariableTemplate( parent, variableName ); - element = newElement; - } else { - if(varDeclaration.isExtern()){ - // variableDeclaration - VariableDeclaration newElement = new VariableDeclaration( parent, variableName ); - element = newElement; - } else { - // variable - Variable newElement = new Variable( parent, variableName ); - element = newElement; - } - } - } - element.setTypeName ( ASTUtil.getType(varDeclaration.getAbstractDeclaration()) ); - element.setConst(varDeclaration.getAbstractDeclaration().isConst()); - element.setVolatile(varDeclaration.getAbstractDeclaration().isVolatile()); - element.setStatic(varDeclaration.isStatic()); - // add to parent - parent.addChild( element ); - - // set position - element.setIdPos( varDeclaration.getNameOffset(), (varDeclaration.getNameEndOffset() - varDeclaration.getNameOffset()) ); - if(!isTemplate){ - // set element position - element.setPos(varDeclaration.getStartingOffset(), varDeclaration.getEndingOffset() - varDeclaration.getStartingOffset()); - } - element.setLines( varDeclaration.getStartingLine(), varDeclaration.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private FunctionDeclaration createFunctionSpecification(Parent parent, IASTFunction functionDeclaration, boolean isTemplate) throws CModelException - { - String name = functionDeclaration.getName(); - if ((name == null) || (name.length() <= 0)) { - // Something is wrong, skip this element - return null; - } - - // get parameters types - String[] parameterTypes = ASTUtil.getFunctionParameterTypes(functionDeclaration); - - FunctionDeclaration element = null; - - if( functionDeclaration instanceof IASTMethod && parent instanceof IStructure) - { - IASTMethod methodDeclaration = (IASTMethod) functionDeclaration; - MethodDeclaration methodElement = null; - if (methodDeclaration.hasFunctionBody()) - { - // method - if(!isTemplate){ - Method newElement = new Method( parent, name ); - methodElement = newElement; - }else { - MethodTemplate newElement = new MethodTemplate(parent, name); - methodElement = newElement; - } - } - else - { - // method declaration - if(!isTemplate){ - MethodDeclaration newElement = new MethodDeclaration( parent, name ); - methodElement = newElement; - }else { - MethodTemplateDeclaration newElement = new MethodTemplateDeclaration(parent, name); - methodElement = newElement; - } - - } - methodElement.setParameterTypes(parameterTypes); - methodElement.setReturnType( ASTUtil.getType(functionDeclaration.getReturnType()) ); - methodElement.setStatic(functionDeclaration.isStatic()); - - // Common settings for method declaration - methodElement.setVisibility(methodDeclaration.getVisiblity()); - methodElement.setVolatile(methodDeclaration.isVolatile()); - methodElement.setConst(methodDeclaration.isConst()); - methodElement.setVirtual(methodDeclaration.isVirtual()); - methodElement.setPureVirtual(methodDeclaration.isPureVirtual()); - methodElement.setInline(methodDeclaration.isInline()); - methodElement.setFriend(methodDeclaration.isFriend()); - methodElement.setConstructor(methodDeclaration.isConstructor()); - methodElement.setDestructor(methodDeclaration.isDestructor()); - element = methodElement; - } - else // instance of IASTFunction - { - if (parent instanceof ITranslationUnit) { - String[] names = functionDeclaration.getFullyQualifiedName(); - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < names.length; ++i) { - if (buf.length() != 0) { - buf.append("::"); //$NON-NLS-1$ - } - buf.append(names[i]); - } - name = buf.toString(); - } - - FunctionDeclaration functionElement = null; - if (functionDeclaration.hasFunctionBody()) - { - // function - if(!isTemplate){ - Function newElement = new Function( parent, name ); - functionElement = newElement; - } else { - FunctionTemplate newElement = new FunctionTemplate( parent, name ); - functionElement = newElement; - } - } - else - { - // functionDeclaration - if(!isTemplate){ - FunctionDeclaration newElement = new FunctionDeclaration( parent, name ); - functionElement = newElement; - } else { - FunctionTemplateDeclaration newElement = new FunctionTemplateDeclaration( parent, name ); - functionElement = newElement; - } - } - functionElement.setParameterTypes(parameterTypes); - functionElement.setReturnType( ASTUtil.getType(functionDeclaration.getReturnType()) ); - functionElement.setStatic(functionDeclaration.isStatic()); - element = functionElement; - } - // add to parent - parent.addChild( element ); - - // hook up the offsets - element.setIdPos( functionDeclaration.getNameOffset(), (functionDeclaration.getNameEndOffset() - functionDeclaration.getNameOffset()) ); - if(!isTemplate){ - // set the element position - element.setPos(functionDeclaration.getStartingOffset(), functionDeclaration.getEndingOffset() - functionDeclaration.getStartingOffset()); - } - element.setLines( functionDeclaration.getStartingLine(), functionDeclaration.getEndingLine() ); - - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private Using createUsingDirective(Parent parent, IASTUsingDirective usingDirDeclaration) throws CModelException{ - // create the element - String name = usingDirDeclaration.getNamespaceName(); - - Using element = new Using( parent, name, true ); - - // add to parent - parent.addChild(element); - - // set positions - element.setIdPos(usingDirDeclaration.getNameOffset(), (usingDirDeclaration.getNameEndOffset() - usingDirDeclaration.getNameOffset())); - element.setPos(usingDirDeclaration.getStartingOffset(), usingDirDeclaration.getEndingOffset() - usingDirDeclaration.getStartingOffset()); - element.setLines(usingDirDeclaration.getStartingLine(), usingDirDeclaration.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private Using createUsingDeclaration(Parent parent, IASTUsingDeclaration usingDeclaration) throws CModelException{ - // create the element - String name = usingDeclaration.usingTypeName(); - - Using element = new Using(parent, name, false); - - // add to parent - parent.addChild(element); - - // set positions - element.setIdPos(usingDeclaration.getNameOffset(), (usingDeclaration.getNameEndOffset() - usingDeclaration.getNameOffset())); - element.setPos(usingDeclaration.getStartingOffset(), usingDeclaration.getEndingOffset() - usingDeclaration.getStartingOffset()); - element.setLines(usingDeclaration.getStartingLine(), usingDeclaration.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - /** - * @return Returns the newElements. - */ - public Map getNewElements() { - return newElements; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java index 83366f2aafd..93172a05a64 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java @@ -16,8 +16,6 @@ import org.eclipse.cdt.core.parser.GCCKeywords; import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.internal.core.parser.scanner2.DynamicFunctionStyleMacro; -import org.eclipse.cdt.internal.core.parser.scanner2.ExpressionEvaluator; import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro; /** @@ -37,23 +35,6 @@ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfigu emptyCharArray, new char[][] { "arg".toCharArray() } ); //$NON-NLS-1$ - private final DynamicFunctionStyleMacro __builtin_choose_expr = - new DynamicFunctionStyleMacro( "__builtin_choose_expr".toCharArray(), //$NON-NLS-1$ - new char[][] { "const_exp".toCharArray(), "exp1".toCharArray(), "exp2".toCharArray() } ) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - { - public char [] execute( CharArrayObjectMap argmap ){ - ExpressionEvaluator evaluator = new ExpressionEvaluator(); - char[] const_exp = (char[]) argmap.get( arglist[0] ); - long exp = 0; - if( const_exp != null) - exp = evaluator.evaluate( const_exp, 0, const_exp.length, CharArrayObjectMap.EMPTY_MAP ); - - if( exp != 0 ) - return (char[])argmap.get( arglist[1] ); - return (char[])argmap.get( arglist[2] ); - } - }; - /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalMacros() @@ -61,7 +42,6 @@ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfigu public CharArrayObjectMap getAdditionalMacros() { CharArrayObjectMap result = super.getAdditionalMacros(); result.put(_Pragma.name, _Pragma ); - result.put( __builtin_choose_expr.name, __builtin_choose_expr ); return result; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/DefaultProblemHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/DefaultProblemHandler.java deleted file mode 100644 index 4276d0c81a7..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/DefaultProblemHandler.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser; - - -/** - * @author jcamelon - * - */ -public class DefaultProblemHandler -{ - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IProblemHandler#ruleOnProblem(org.eclipse.cdt.core.parser.IProblem) - */ - public static boolean ruleOnProblem( IProblem p, ParserMode mode ) - { - if( p == null ) return true; - if( p.checkCategory( IProblem.SCANNER_RELATED ) || p.checkCategory( IProblem.PREPROCESSOR_RELATED )) - { - switch( p.getID() ) - { - case IProblem.PREPROCESSOR_INVALID_DIRECTIVE: - return false; - case IProblem.PREPROCESSOR_POUND_ERROR: - case IProblem.PREPROCESSOR_UNBALANCE_CONDITION: - case IProblem.PREPROCESSOR_INVALID_MACRO_DEFN: -// case IProblem.PREPROCESSOR_MACRO_USAGE_ERROR: - case IProblem.PREPROCESSOR_MACRO_PASTING_ERROR: - case IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR: - case IProblem.SCANNER_UNEXPECTED_EOF: - case IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN: - if( mode == ParserMode.COMPLETE_PARSE ) - return false; - default: - return true; - } - } - return true; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IOffsetDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IOffsetDuple.java deleted file mode 100644 index 2efe87ba9cb..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IOffsetDuple.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser; - -/** - * @author jcamelon - * - */ -public interface IOffsetDuple -{ - public int getCeilingOffset(); - public int getFloorOffset(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java deleted file mode 100644 index a28bfc9016c..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IParser.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser; - -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; - - -/** - * This is the external interface that all C and C++ parsers in the CDT - * must implement. - * - * @author jcamelon - */ -public interface IParser { - - - /** - * Request a parse from a pre-configured parser to parse a whole translation unit or file. - * - * @return whether or not the parse was successful - */ - public boolean parse(); - - /** - * @param offset offset in the input file where code completion is being requested for - * @return an IASTCompletionConstruct that provides a mechanism for determining C/C++ code completion contributions - */ - public IASTCompletionNode parse( int offset) throws ParseError; - - - public static interface ISelectionParseResult - { - public IASTOffsetableNamedElement getOffsetableNamedElement(); - public String getFilename(); - } - /** - * - * @param startingOffset - * @param endingOffset - * @return - */ - public ISelectionParseResult parse( int startingOffset, int endingOffset ) throws ParseError; - - public void cancel(); - - - /** - * If an error was encountered, give us the offset of the token that caused the error. - * - * @return -1 for no error, otherwise the character offset where we encountered - * our first unrecoverable error. - */ - public int getLastErrorOffset(); - - public int getLastErrorLine(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IQuickParseCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IQuickParseCallback.java deleted file mode 100644 index d62144b9920..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IQuickParseCallback.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser; -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -/** - * @author jcamelon - * - */ -public interface IQuickParseCallback extends ISourceElementRequestor -{ - public abstract Iterator getInclusions(); - public abstract Iterator getMacros(); - /** - * @return - */ - public abstract IASTCompilationUnit getCompilationUnit(); - public abstract Iterator iterateOffsetableElements(); - public boolean hasNoProblems(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java index e65b9f67905..8bfd35e2734 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java @@ -13,7 +13,6 @@ package org.eclipse.cdt.core.parser; import java.util.Map; import org.eclipse.cdt.core.dom.IMacroCollector; -import org.eclipse.cdt.core.parser.ast.IASTFactory; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver; @@ -30,12 +29,11 @@ import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver; */ public interface IScanner extends IMacroCollector { - /** @deprecated */ public static final int tPOUNDPOUND = IToken.tPOUNDPOUND; - /** @deprecated */ public static final int tPOUND = IToken.tPOUND; - - public void setOffsetBoundary( int offset ); + /** + * Puts the scanner into content assist mode. + */ public void setContentAssistMode( int offset ); - public void setASTFactory( IASTFactory f ); + /** * Turns on/off comment parsing. * @since 4.0 @@ -50,7 +48,6 @@ public interface IScanner extends IMacroCollector { public void setComputeImageLocations(boolean val); public IMacro addDefinition(char[] key, char[] value); - public IMacro addDefinition(char[] name, char[][] params, char[] expansion); public void addDefinition(IMacro macro); public Map getDefinitions(); @@ -65,7 +62,6 @@ public interface IScanner extends IMacroCollector { public boolean isOnTopContext(); public CharArrayObjectMap getRealDefinitions(); public void cancel(); - public char[] getMainFilename(); public ILocationResolver getLocationResolver(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementCallbackDelegate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementCallbackDelegate.java deleted file mode 100644 index f2723da8729..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementCallbackDelegate.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser; - - -/** - * @author jcamelon - * - */ -public interface ISourceElementCallbackDelegate -{ - public void acceptElement( ISourceElementRequestor requestor ); - public void enterScope( ISourceElementRequestor requestor ); - public void exitScope( ISourceElementRequestor requestor ); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java deleted file mode 100644 index 160e17f91c5..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ISourceElementRequestor.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassReference; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumeratorReference; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFieldReference; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTFunctionReference; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTMethodReference; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference; -import org.eclipse.cdt.core.parser.ast.IASTParameterReference; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypedefReference; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTVariableReference; - -/** - * @author jcamelon - * - */ -public interface ISourceElementRequestor { - - public boolean acceptProblem( IProblem problem ); - - public void acceptMacro( IASTMacro macro ); - public void acceptVariable( IASTVariable variable ); - public void acceptFunctionDeclaration( IASTFunction function ); - public void acceptUsingDirective( IASTUsingDirective usageDirective ); - public void acceptUsingDeclaration( IASTUsingDeclaration usageDeclaration ); - public void acceptASMDefinition( IASTASMDefinition asmDefinition ); - public void acceptTypedefDeclaration( IASTTypedefDeclaration typedef ); - public void acceptEnumerationSpecifier( IASTEnumerationSpecifier enumeration ); - public void acceptElaboratedForewardDeclaration( IASTElaboratedTypeSpecifier elaboratedType ); - public void acceptAbstractTypeSpecDeclaration( IASTAbstractTypeSpecifierDeclaration abstractDeclaration ); - - public void enterFunctionBody( IASTFunction function ); - public void exitFunctionBody( IASTFunction function ); - - public void enterCodeBlock( IASTCodeScope scope ); - public void exitCodeBlock( IASTCodeScope scope ); - - public void enterCompilationUnit( IASTCompilationUnit compilationUnit ); - public void enterInclusion( IASTInclusion inclusion ); - public void enterNamespaceDefinition( IASTNamespaceDefinition namespaceDefinition ); - public void enterClassSpecifier( IASTClassSpecifier classSpecification ); - public void enterLinkageSpecification( IASTLinkageSpecification linkageSpec ); - - public void enterTemplateDeclaration( IASTTemplateDeclaration declaration ); - public void enterTemplateSpecialization( IASTTemplateSpecialization specialization ); - public void enterTemplateInstantiation( IASTTemplateInstantiation instantiation ); - - public void acceptMethodDeclaration( IASTMethod method ); - public void enterMethodBody( IASTMethod method ); - public void exitMethodBody( IASTMethod method ); - public void acceptField( IASTField field ); - - public void acceptClassReference( IASTClassReference reference ); - public void acceptTypedefReference( IASTTypedefReference reference ); - public void acceptNamespaceReference( IASTNamespaceReference reference ); - public void acceptEnumerationReference( IASTEnumerationReference reference ); - public void acceptVariableReference( IASTVariableReference reference ); - public void acceptFunctionReference( IASTFunctionReference reference ); - public void acceptFieldReference( IASTFieldReference reference ); - public void acceptMethodReference( IASTMethodReference reference ); - public void acceptEnumeratorReference( IASTEnumeratorReference reference ); - public void acceptParameterReference(IASTParameterReference reference); - public void acceptTemplateParameterReference( IASTTemplateParameterReference reference ); - public void acceptFriendDeclaration( IASTDeclaration declaration ); - - public void exitTemplateDeclaration( IASTTemplateDeclaration declaration ); - public void exitTemplateSpecialization( IASTTemplateSpecialization specialization ); - public void exitTemplateExplicitInstantiation( IASTTemplateInstantiation instantiation ); - - public void exitLinkageSpecification( IASTLinkageSpecification linkageSpec ); - public void exitClassSpecifier( IASTClassSpecifier classSpecification ); - public void exitNamespaceDefinition( IASTNamespaceDefinition namespaceDefinition ); - public void exitInclusion( IASTInclusion inclusion ); - public void exitCompilationUnit( IASTCompilationUnit compilationUnit ); - - /** - * @param finalPath - * @return - */ - public CodeReader createReader(String finalPath, Iterator workingCopies ); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java index 2b88a8b003a..024c66b7b38 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IToken.java @@ -32,34 +32,6 @@ public interface IToken { public void setType(int i); public boolean isOperator(); - - /** - * @deprecated semantics is unclear, depends on the parser. - * will be removed in 5.0 - */ - public boolean isPointer(); - - /** - * @deprecated semantics is unclear, depends on the parser. - * will be removed in 5.0 - */ - public boolean canBeAPrefix(); - - /** - * @deprecated semantics is unclear, depends on the parser. - * will be removed in 5.0 - */ - public boolean looksLikeExpression(); - - /** - * @deprecated will be removed in 5.0 - */ - public int getLineNumber(); - - /** - * @deprecated will be removed in 5.0 - */ - public char [] getFilename(); // Token types int FIRST_RESERVED_PREPROCESSOR= -200; @@ -240,8 +212,6 @@ public interface IToken { static public final int tCOMMENT = 142; /** @deprecated don't use it */ static public final int tBLOCKCOMMENT = 143; - /** @deprecated don't use it */ - static public final int tLAST = 143; static public final int tEND_OF_INPUT= 144; int FIRST_RESERVED_IGCCToken = 150; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java index 643f551e6cd..4204d6a44f9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ITokenDuple.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. + * Copyright (c) 2002, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -36,37 +36,14 @@ public interface ITokenDuple { public abstract Iterator iterator(); public abstract String toString(); public char [] toCharArray(); - - public char [] getFilename(); - - public abstract boolean isIdentifier(); + public abstract int length(); - public abstract ITokenDuple getSubrange( int startIndex, int endIndex ); public IToken getToken(int index); public ITokenDuple[] getSegments(); - public int findLastTokenType( int type ); - public int getStartOffset(); public int getEndOffset(); - public int getLineNumber(); - /** - * @return - */ - public abstract boolean syntaxOfName(); public char[] extractNameFromTemplateId(); - /** - * @param duple - * @return - */ - public boolean contains(ITokenDuple duple); - /** - * @return - */ - public abstract String [] toQualifiedName(); - - public void freeReferences( ); - public void acceptElement( ISourceElementRequestor requestor ); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/NullSourceElementRequestor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/NullSourceElementRequestor.java deleted file mode 100644 index 3779d2fd4db..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/NullSourceElementRequestor.java +++ /dev/null @@ -1,491 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser; - - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassReference; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumeratorReference; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFieldReference; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTFunctionReference; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTMethodReference; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference; -import org.eclipse.cdt.core.parser.ast.IASTParameterReference; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypedefReference; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTVariableReference; -import org.eclipse.cdt.internal.core.parser.InternalParserUtil; - - -public class NullSourceElementRequestor implements ISourceElementRequestor -{ - private ParserMode mode = ParserMode.COMPLETE_PARSE; - - public NullSourceElementRequestor() - { - } - - public NullSourceElementRequestor( ParserMode mode ) - { - this.mode = mode; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem) - */ - public boolean acceptProblem(IProblem problem) - { - return DefaultProblemHandler.ruleOnProblem( problem, mode ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro) - */ - public void acceptMacro(IASTMacro macro) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable) - */ - public void acceptVariable(IASTVariable variable) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void acceptFunctionDeclaration(IASTFunction function) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDirective(org.eclipse.cdt.core.parser.ast.IASTUsingDirective) - */ - public void acceptUsingDirective(IASTUsingDirective usageDirective) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration) - */ - public void acceptUsingDeclaration(IASTUsingDeclaration usageDeclaration) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptASMDefinition(org.eclipse.cdt.core.parser.ast.IASTASMDefinition) - */ - public void acceptASMDefinition(IASTASMDefinition asmDefinition) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedef(org.eclipse.cdt.core.parser.ast.IASTTypedef) - */ - public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier) - */ - public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void enterFunctionBody(IASTFunction function) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void exitFunctionBody(IASTFunction function) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void enterCompilationUnit(IASTCompilationUnit compilationUnit) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void enterInclusion(IASTInclusion inclusion) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - public void enterClassSpecifier(IASTClassSpecifier classSpecification) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) - */ - public void enterTemplateDeclaration(IASTTemplateDeclaration declaration) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) - */ - public void enterTemplateSpecialization(IASTTemplateSpecialization specialization) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) - */ - public void enterTemplateInstantiation(IASTTemplateInstantiation instantiation) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void acceptMethodDeclaration(IASTMethod method) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void enterMethodBody(IASTMethod method) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void exitMethodBody(IASTMethod method) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField) - */ - public void acceptField(IASTField field) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptClassReference(org.eclipse.cdt.core.parser.ast.IASTClassReference) - */ - public void acceptClassReference(IASTClassReference reference) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration) - */ - public void exitTemplateDeclaration(IASTTemplateDeclaration declaration) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization) - */ - public void exitTemplateSpecialization(IASTTemplateSpecialization specialization) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitTemplateExplicitInstantiation(org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation) - */ - public void exitTemplateExplicitInstantiation(IASTTemplateInstantiation instantiation) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - public void exitClassSpecifier(IASTClassSpecifier classSpecification) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void exitInclusion(IASTInclusion inclusion) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void exitCompilationUnit(IASTCompilationUnit compilationUnit) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration) - */ - public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) - { - // TODO Auto-generated method stub - - } - - - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefReference(org.eclipse.cdt.core.parser.ast.IASTTypedefReference) - */ - public void acceptTypedefReference(IASTTypedefReference reference) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptNamespaceReference(org.eclipse.cdt.core.parser.ast.IASTNamespaceReference) - */ - public void acceptNamespaceReference(IASTNamespaceReference reference) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationReference(org.eclipse.cdt.core.parser.ast.IASTEnumerationReference) - */ - public void acceptEnumerationReference(IASTEnumerationReference reference) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariableReference(org.eclipse.cdt.core.parser.ast.IASTVariableReference) - */ - public void acceptVariableReference(IASTVariableReference reference) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionReference(org.eclipse.cdt.core.parser.ast.IASTFunctionReference) - */ - public void acceptFunctionReference(IASTFunctionReference reference) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFieldReference(org.eclipse.cdt.core.parser.ast.IASTFieldReference) - */ - public void acceptFieldReference(IASTFieldReference reference) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodReference(org.eclipse.cdt.core.parser.ast.IASTMethodReference) - */ - public void acceptMethodReference(IASTMethodReference reference) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier) - */ - public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCodeBlock(org.eclipse.cdt.core.parser.ast.IASTScope) - */ - public void enterCodeBlock(IASTCodeScope scope) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCodeBlock(org.eclipse.cdt.core.parser.ast.IASTScope) - */ - public void exitCodeBlock(IASTCodeScope scope) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumeratorReference(org.eclipse.cdt.core.parser.ast.IASTEnumerationReference) - */ - public void acceptEnumeratorReference(IASTEnumeratorReference reference) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptParameterReference(org.eclipse.cdt.internal.core.parser.ast.complete.ASTParameterReference) - */ - public void acceptParameterReference(IASTParameterReference reference) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#createReader(java.lang.String) - */ - public CodeReader createReader(String finalPath, Iterator workingCopies) { - return InternalParserUtil.createFileReader( finalPath ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTemplateParameterReference(org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference) - */ - public void acceptTemplateParameterReference(IASTTemplateParameterReference reference) - { - // TODO Auto-generated method stub - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFriendDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void acceptFriendDeclaration(IASTDeclaration declaration) { - // TODO Auto-generated method stub - - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java index feb71db582d..a3062c556ac 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java @@ -6,11 +6,11 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.parser; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; /** * The exception is thrown, when content-assist is requested within a context that is handled @@ -34,13 +34,18 @@ public class OffsetLimitReachedException extends EndOfFileException { public static final int ORIGIN_INACTIVE_CODE = 3; public static final int ORIGIN_MACRO_EXPANSION = 4; - private final IASTCompletionNode node; + private final String prefix; private final IToken finalToken; private final int fOrigin; - public OffsetLimitReachedException( IASTCompletionNode node ) + /** + * mstodo- scanner removal + * @deprecated + * @param prefix + */ + public OffsetLimitReachedException( String prefix ) { - this.node = node; + this.prefix= prefix; finalToken = null; fOrigin= ORIGIN_UNKNOWN; } @@ -48,14 +53,14 @@ public class OffsetLimitReachedException extends EndOfFileException { public OffsetLimitReachedException( IToken token ) { fOrigin= ORIGIN_UNKNOWN; + prefix= token.getImage(); finalToken = token; - node = null; } public OffsetLimitReachedException(int origin, IToken lastToken) { fOrigin= origin; + prefix= lastToken.getImage(); finalToken= lastToken; - node= null; } /** @@ -73,10 +78,11 @@ public class OffsetLimitReachedException extends EndOfFileException { } /** + * mstodo- scanner removal * @return returns the IASTCompletionNode + * @deprecated */ - public IASTCompletionNode getCompletionNode() - { - return node; + public String getPrefix() { + return prefix; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java index 31f399850e0..f589d60a8fa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactory.java @@ -10,24 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser; -import java.io.IOException; -import java.util.List; import java.util.Set; -import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; -import org.eclipse.cdt.core.parser.ast.IASTFactory; -import org.eclipse.cdt.core.parser.extension.ExtensionDialect; -import org.eclipse.cdt.core.parser.extension.IParserExtension; -import org.eclipse.cdt.core.parser.extension.IParserExtensionFactory; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ParserExtensionFactory; -import org.eclipse.cdt.internal.core.parser.QuickParseCallback; -import org.eclipse.cdt.internal.core.parser.StructuralParseCallback; -import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory; -import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory; -import org.eclipse.cdt.internal.core.parser.scanner2.GCCOldScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.GPPOldScannerExtensionConfiguration; -import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2; import org.eclipse.cdt.internal.core.parser.token.KeywordSets; @@ -36,81 +20,7 @@ import org.eclipse.cdt.internal.core.parser.token.KeywordSets; * */ public class ParserFactory { - - private static IParserExtensionFactory extensionFactory = new ParserExtensionFactory( ExtensionDialect.GCC ); - - public static IASTFactory createASTFactory( ParserMode mode, ParserLanguage language ) - { - if( mode == ParserMode.QUICK_PARSE ) - return new QuickParseASTFactory(extensionFactory.createASTExtension( mode )); - return new CompleteParseASTFactory( language, mode, extensionFactory.createASTExtension( mode )); - } - - - - /** - * @param scanner tokenizer to retrieve C/C++ tokens - * @param callback the callback that reports results to the client - * @param mode the parser mode you wish to use - * @param language C or C++ - * @param log a log utility to output errors - * @return - * @throws ParserFactoryError - erroneous input provided - */ - public static IParser createParser( IScanner scanner, ISourceElementRequestor callback, ParserMode mode, ParserLanguage language, IParserLogService log ) throws ParserFactoryError - { - if( scanner == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_SCANNER ); - if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE ); - IParserLogService logService = ( log == null ) ? createDefaultLogService() : log; - ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode ); - ISourceElementRequestor ourCallback = (( callback == null) ? new NullSourceElementRequestor() : callback ); - IParserExtension extension = extensionFactory.createParserExtension(); - return new Parser( scanner, ourMode, ourCallback, language, logService, extension ); - } - - /** - * @param input the java.io.Reader that reads the source-code input you want parsed - * @param fileName the absolute path of the file you are parsing (necessary for determining location of local inclusions) - * @param config represents the include-paths and preprocessor definitions you wish to initialize the scanner with - * @param mode the parser mode you wish to use - * @param language C or C++ - * @param requestor the callback that reports results to the client - * @param log a log utility to output errors - * @param workingCopies a java.util.List of IWorkingCopy buffers if you wish for include files to use CDT Working Copies rather than saved files - * @return - * @throws ParserFactoryError - erroneous input provided - */ - public static IScanner createScanner( CodeReader code, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError - { - if( config == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_CONFIG ); - if( language == null ) throw new ParserFactoryError( ParserFactoryError.Kind.NULL_LANGUAGE ); - IParserLogService logService = ( log == null ) ? createDefaultLogService() : log; - ParserMode ourMode = ( (mode == null )? ParserMode.COMPLETE_PARSE : mode ); - ISourceElementRequestor ourRequestor = (( requestor == null) ? new NullSourceElementRequestor() : requestor ); - IScannerExtensionConfiguration configuration = null; - if( language == ParserLanguage.C ) - configuration = new GCCOldScannerExtensionConfiguration(); - else - configuration = new GPPOldScannerExtensionConfiguration(); - - return new Scanner2( code, config, ourRequestor, ourMode, language, logService, workingCopies, configuration ); - } - - public static IScanner createScanner( String fileName, IScannerInfo config, ParserMode mode, ParserLanguage language, ISourceElementRequestor requestor, IParserLogService log, List workingCopies ) throws ParserFactoryError, IOException - { - return createScanner(new CodeReader(fileName), config, mode, language, requestor, log, workingCopies); - } - - public static IQuickParseCallback createQuickParseCallback() - { - return new QuickParseCallback(); - } - - public static IQuickParseCallback createStructuralParseCallback() - { - return new StructuralParseCallback(); - } - + public static IParserLogService createDefaultLogService() { return defaultLogService; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactoryError.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactoryError.java deleted file mode 100644 index f415331af5d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ParserFactoryError.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser; - -/** - * @author jcamelon - * - */ -public class ParserFactoryError extends Error { - - private static final long serialVersionUID= -2692315766161768983L; - - public static class Kind extends Enum { - - public static final Kind NULL_READER = new Kind( 1 ); - public static final Kind NULL_FILENAME = new Kind( 2 ); - public static final Kind NULL_CONFIG = new Kind( 3 ); - public static final Kind NULL_LANGUAGE = new Kind( 4 ); - public static final Kind NULL_SCANNER = new Kind( 5 ); - public static final Kind BAD_DIALECT = new Kind( 6 ); - - protected Kind( int arg ) - { - super( arg ); - } - } - - public ParserFactoryError( Kind e ) - { - kind = e; - } - - public Kind getKind() - { - return kind; - } - - private Kind kind; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTClassKind.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTClassKind.java deleted file mode 100644 index 2047613bf96..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTClassKind.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.Enum; - -/** - * @author jcamelon - * - */ -public class ASTClassKind extends Enum { - - public final static ASTClassKind CLASS = new ASTClassKind( 1 ); - public final static ASTClassKind STRUCT = new ASTClassKind( 2 ); - public final static ASTClassKind UNION = new ASTClassKind( 3 ); - public final static ASTClassKind ENUM = new ASTClassKind( 4 ); - - private ASTClassKind( int value ) - { - super( value ); - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTExpressionEvaluationException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTExpressionEvaluationException.java deleted file mode 100644 index b5985e3e364..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTExpressionEvaluationException.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public class ASTExpressionEvaluationException extends Exception -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTNotImplementedException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTNotImplementedException.java deleted file mode 100644 index dfeb52648a2..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTNotImplementedException.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public class ASTNotImplementedException extends Exception -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTPointerOperator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTPointerOperator.java deleted file mode 100644 index 1ca0e5c860f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTPointerOperator.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.Enum; - -/** - * @author jcamelon - * - */ -public class ASTPointerOperator extends Enum -{ - public static final ASTPointerOperator REFERENCE = new ASTPointerOperator( 0 ); - public static final ASTPointerOperator POINTER = new ASTPointerOperator( 1 ); - public static final ASTPointerOperator CONST_POINTER = new ASTPointerOperator( 2 ); - public static final ASTPointerOperator VOLATILE_POINTER = new ASTPointerOperator( 3 ); - public static final ASTPointerOperator RESTRICT_POINTER = new ASTPointerOperator( 4 ); - - /** - * @param enumValue - */ - protected ASTPointerOperator(int enumValue) - { - super(enumValue); - } - - public boolean isStarOperator() - { - return ( ( this == VOLATILE_POINTER ) || ( this == CONST_POINTER ) || ( this == RESTRICT_POINTER ) || ( this == POINTER )); - } - - public boolean isReferenceOperator() - { - return ( this == REFERENCE ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTSemanticException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTSemanticException.java deleted file mode 100644 index 12169f10f97..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTSemanticException.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.IProblem; - -/** - * @author jcamelon - * - */ -public class ASTSemanticException extends Exception -{ - private final IProblem theProblem; - - /** - * - */ - public ASTSemanticException( IProblem reason ) - { - super(); - theProblem = reason; - } - - - /** - * @param e - */ - public ASTSemanticException(ASTSemanticException e) { - theProblem = e.getProblem(); - } - - - /** - * @return - */ - public IProblem getProblem() - { - return theProblem; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTUtil.java deleted file mode 100644 index c69d76385d9..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/ASTUtil.java +++ /dev/null @@ -1,700 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Rational Software - initial implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.parser.Keywords; -import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; -import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; - - -/** - * This is a utility class to help convert AST elements to Strings. - */ - -public class ASTUtil { - public static String[] getTemplateParameters(IASTTemplateDeclaration templateDeclaration){ - // add the parameters - Iterator i = templateDeclaration.getTemplateParameters(); - return getTemplateParameters(i); - } - public static String[] getTemplateParameters(Iterator templateParams){ - List paramList = new ArrayList(); - while (templateParams.hasNext()){ - StringBuffer paramType = new StringBuffer(); - IASTTemplateParameter parameter = (IASTTemplateParameter)templateParams.next(); - IASTTemplateParameter.ParamKind kind = parameter.getTemplateParameterKind(); - if(kind == IASTTemplateParameter.ParamKind.CLASS){ - if((parameter.getIdentifier() != null) && (parameter.getIdentifier().length() != 0)) - { - paramType.append(parameter.getIdentifier().toString()); - }else { - paramType.append("class"); //$NON-NLS-1$ - } - } - if(kind == IASTTemplateParameter.ParamKind.TYPENAME){ - if((parameter.getIdentifier() != null) && (parameter.getIdentifier().length() != 0)) - { - paramType.append(parameter.getIdentifier().toString()); - }else { - paramType.append("typename"); //$NON-NLS-1$ - } - } - if(kind == IASTTemplateParameter.ParamKind.TEMPLATE_LIST){ - paramType.append("template<"); //$NON-NLS-1$ - String[] subParams = getTemplateParameters(parameter.getTemplateParameters()); - int p = 0; - if ( subParams.length > 0) - paramType.append(subParams[p++]); - while( p < subParams.length){ - paramType.append(", "); //$NON-NLS-1$ - paramType.append(subParams[p++]); - } - paramType.append(">"); //$NON-NLS-1$ - } - if(kind == IASTTemplateParameter.ParamKind.PARAMETER){ - paramType.append(getType(parameter.getParameterDeclaration())); - } - paramList.add(paramType.toString()); - }// end while - String[] parameterTypes = new String[paramList.size()]; - for(int j=0; j 0){ - initializer.append("="); //$NON-NLS-1$ - initializer.append(init); - } - } - } - } - return initializer.toString(); - } - public static String getPointerToFunctionType(IASTAbstractDeclaration declaration){ - StringBuffer type = new StringBuffer(); - ASTPointerOperator po = declaration.getPointerToFunctionOperator(); - if(po != null){ - type.append("("); //$NON-NLS-1$ - type.append(getPointerOperator(po)); - type.append(")"); //$NON-NLS-1$ - String[] parameters =getParameterTypes(declaration.getParameters(), false /* replace with takeVarArgs() later*/); - type.append(getParametersString(parameters)); - } - return type.toString(); - } - public static String getDeclarationType(IASTAbstractDeclaration declaration){ - StringBuffer type = new StringBuffer(); - - if(declaration.isConst()) - type.append("const "); //$NON-NLS-1$ - if(declaration.isVolatile()) - type.append("volatile "); //$NON-NLS-1$ - IASTTypeSpecifier typeSpecifier = declaration.getTypeSpecifier(); - if(typeSpecifier instanceof IASTElaboratedTypeSpecifier){ - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) typeSpecifier; - type.append(getElaboratedTypeSignature(elab)); - }else if(typeSpecifier instanceof IASTSimpleTypeSpecifier){ - IASTSimpleTypeSpecifier simpleSpecifier = (IASTSimpleTypeSpecifier) typeSpecifier; - type.append(simpleSpecifier.getTypename()); - }else if(typeSpecifier instanceof IASTClassSpecifier){ - IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpecifier; - type.append(classSpecifier.getName()); - }else if(typeSpecifier instanceof IASTEnumerationSpecifier){ - IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) typeSpecifier; - type.append(enumSpecifier.getName()); - } - return type.toString(); - } - - public static String getElaboratedTypeSignature(IASTElaboratedTypeSpecifier elab){ - StringBuffer type = new StringBuffer(); - ASTClassKind t = elab.getClassKind(); - if( t == ASTClassKind.CLASS){ - type.append("class"); //$NON-NLS-1$ - } - else if( t == ASTClassKind.STRUCT){ - type.append("struct"); //$NON-NLS-1$ - } - else if( t == ASTClassKind.UNION){ - type.append("union"); //$NON-NLS-1$ - } - else if( t == ASTClassKind.STRUCT){ - type.append("enum"); //$NON-NLS-1$ - } - type.append(" "); //$NON-NLS-1$ - type.append(elab.getName().toString()); - return type.toString(); - } - - public static String getPointerOperation(IASTAbstractDeclaration declaration){ - StringBuffer pointerString = new StringBuffer(); - Iterator i = declaration.getPointerOperators(); - while(i.hasNext()){ - ASTPointerOperator po = (ASTPointerOperator) i.next(); - pointerString.append(getPointerOperator(po)); - } - return pointerString.toString(); - } - - public static String getPointerOperator(ASTPointerOperator po){ - String pointerString =""; //$NON-NLS-1$ - if(po == ASTPointerOperator.POINTER) - pointerString = ("*"); //$NON-NLS-1$ - - if(po == ASTPointerOperator.REFERENCE) - pointerString =("&"); //$NON-NLS-1$ - - if(po == ASTPointerOperator.CONST_POINTER) - pointerString =("* const"); //$NON-NLS-1$ - - if(po == ASTPointerOperator.VOLATILE_POINTER) - pointerString =("* volatile"); //$NON-NLS-1$ - - if(po == ASTPointerOperator.RESTRICT_POINTER) - pointerString =("* restrict"); //$NON-NLS-1$ - - return pointerString; - } - - public static String getArrayQualifiers(IASTAbstractDeclaration declaration){ - StringBuffer arrayString = new StringBuffer(); - Iterator i = declaration.getArrayModifiers(); - while (i.hasNext()){ - i.next(); - arrayString.append("[]"); //$NON-NLS-1$ - } - return arrayString.toString(); - } - - public static String[] getFunctionParameterTypes(IASTFunction functionDeclaration) - { - Iterator parameters = functionDeclaration.getParameters(); - return getParameterTypes(parameters, functionDeclaration.takesVarArgs()); - } - - public static String[] getParameterTypes(Iterator parameters, boolean takesVarArgs){ - List paramList = new ArrayList(); - while (parameters.hasNext()){ - IASTParameterDeclaration param = (IASTParameterDeclaration)parameters.next(); - paramList.add(getType(param)); - } - int paramListSize = paramList.size(); - if(takesVarArgs) - paramListSize++; - String[] parameterTypes = new String[paramListSize]; - for(int i=0; i 0)) { - parameters.append("("); //$NON-NLS-1$ - int i = 0; - parameters.append(parameterTypes[i++]); - while (i < parameterTypes.length) { - parameters.append(", "); //$NON-NLS-1$ - parameters.append(parameterTypes[i++]); - } - parameters.append(")"); //$NON-NLS-1$ - } else { - if (parameterTypes != null) parameters.append("()"); //$NON-NLS-1$ - } - - return parameters.toString(); - } - - public static String getTypeId( IASTTypeId id ){ - StringBuffer type = new StringBuffer(); - - if( id.isTypename() ){ - type.append( Keywords.TYPENAME ); - type.append( ' ' ); - } - type.append( id.getFullSignature() ); - -// Iterator i = id.getPointerOperators(); -// while(i.hasNext()){ -// ASTPointerOperator po = (ASTPointerOperator) i.next(); -// type.append(getPointerOperator(po)); -// } -// -// i = id.getArrayModifiers(); -// while (i.hasNext()){ -// i.next(); -// type.append("[]"); //$NON-NLS-1$ -// } - - return type.toString(); - } - - public static final String EMPTY_STRING = ""; //$NON-NLS-1$ - /** - * Return a string for the given expression. Expressions having an extension kind should - * provide their own toString method which will be called by this. - * @param expression - * @return - */ - public static String getExpressionString( IASTExpression expression ){ - - if( expression.getExpressionKind().isExtensionKind() ) - return expression.toString(); - - String literal = expression.getLiteralString(); - String idExpression = expression.getIdExpression(); - - IASTExpression lhs = expression.getLHSExpression(); - IASTExpression rhs = expression.getRHSExpression(); - IASTExpression third = expression.getThirdExpression(); - IASTNewExpressionDescriptor descriptor = expression.getNewExpressionDescriptor(); - IASTTypeId typeId = expression.getTypeId(); - - if( literal != null && !literal.equals( EMPTY_STRING ) && ( idExpression == null || idExpression.equals( EMPTY_STRING ) ) ) - return getLiteralExpression( expression ); - - if( idExpression != null && !idExpression.equals( EMPTY_STRING ) && lhs == null ) - return getIdExpression( expression ); - - if( third != null ) - return getConditionalExpression( expression ); - - if( descriptor != null ) - return getNewExpression( expression ); - - if( lhs != null && rhs != null ) - return getBinaryExpression( expression ); - - if( lhs != null && typeId != null ) - return getUnaryTypeIdExpression( expression ); - - if( lhs != null && ( idExpression != null && !idExpression.equals( EMPTY_STRING ) ) ) - return getUnaryIdExpression( expression ); - - if( lhs != null ) - return getUnaryExpression( expression ); - - if( typeId != null ) - return getTypeIdExpression( expression ); - - return getEmptyExpression( expression ); - } - - private static String getEmptyExpression( IASTExpression expression ){ - if( expression.getExpressionKind() == Kind.PRIMARY_THIS ) - return Keywords.THIS; - - return EMPTY_STRING; - } - - private static String getLiteralExpression( IASTExpression expression ){ - Kind kind = expression.getExpressionKind(); - - if( kind != Kind.PRIMARY_CHAR_LITERAL && kind != Kind.PRIMARY_STRING_LITERAL ) - return expression.getLiteralString(); - - StringBuffer buffer = new StringBuffer(); - boolean quoted = false; - String literalString = expression.getLiteralString(); - if( kind == Kind.PRIMARY_CHAR_LITERAL ){ - quoted = ( literalString.charAt(0) == literalString.charAt(literalString.length() - 1 ) && - literalString.charAt(0) == '\'' ); - if( !quoted ) - buffer.append( '\'' ); - buffer.append( literalString ); - if( !quoted ) - buffer.append( '\'' ); - } else if( kind == Kind.PRIMARY_STRING_LITERAL ) { - quoted = ( literalString.charAt(0) == literalString.charAt(literalString.length() - 1 ) && - literalString.charAt(0) == '\"' ); - if( !quoted ) - buffer.append( '"' ); - buffer.append( expression.getLiteralString() ); - if( !quoted ) - buffer.append( '"' ); - } - return buffer.toString(); - } - - private static String getIdExpression( IASTExpression expression ){ - return expression.getIdExpression(); - } - private static String getConditionalExpression( IASTExpression expression ){ - StringBuffer buffer = new StringBuffer(); - - buffer.append( getExpressionString( expression.getLHSExpression() ) ); - buffer.append( " ? " ); //$NON-NLS-1$ - buffer.append( getExpressionString( expression.getRHSExpression() ) ); - buffer.append( " : " ); //$NON-NLS-1$ - buffer.append( getExpressionString( expression.getThirdExpression() ) ); - - return buffer.toString(); - } - private static String getNewExpression( IASTExpression expression ){ - StringBuffer buffer = new StringBuffer(); - - buffer.append( Keywords.NEW ); - buffer.append( ' ' ); - - IASTNewExpressionDescriptor descriptor = expression.getNewExpressionDescriptor(); - Iterator iter = descriptor.getNewPlacementExpressions(); - if( iter.hasNext() ){ - buffer.append( '(' ); - buffer.append( getExpressionString( (IASTExpression) iter.next() ) ); - buffer.append( ") " ); //$NON-NLS-1$ - } - - iter = descriptor.getNewTypeIdExpressions(); - if( iter.hasNext() ){ - buffer.append( getExpressionString( (IASTExpression) iter.next() ) ); - buffer.append( ' ' ); - } - - if( expression.getTypeId() != null ){ - buffer.append( getTypeId( expression.getTypeId() ) ); - } - - iter = descriptor.getNewInitializerExpressions(); - if( iter.hasNext() ){ - buffer.append( '(' ); - buffer.append( getExpressionString( (IASTExpression) iter.next() ) ); - buffer.append( ')' ); - } - - return buffer.toString(); - } - private static String getBinaryExpression( IASTExpression expression ){ - Kind kind = expression.getExpressionKind(); - StringBuffer buffer = new StringBuffer(); - buffer.append( getExpressionString( expression.getLHSExpression() ) ); - - boolean appendSpace = false; - if( kind != Kind.EXPRESSIONLIST && - kind != Kind.PM_DOTSTAR && - kind != Kind.PM_ARROWSTAR && - kind != Kind.POSTFIX_SUBSCRIPT && - kind != Kind.POSTFIX_FUNCTIONCALL && - kind != Kind.POSTFIX_DOT_TEMPL_IDEXPRESS && - kind != Kind.POSTFIX_DOT_IDEXPRESSION && - kind != Kind.POSTFIX_DOT_DESTRUCTOR && - kind != Kind.POSTFIX_ARROW_TEMPL_IDEXP && - kind != Kind.POSTFIX_ARROW_IDEXPRESSION && - kind != Kind.POSTFIX_ARROW_DESTRUCTOR) - { - appendSpace = true; - buffer.append( ' ' ); - } - - if( kind == Kind.ANDEXPRESSION || - kind == Kind.EXPRESSIONLIST || - kind == Kind.EXCLUSIVEOREXPRESSION || - kind == Kind.PM_DOTSTAR || - kind == Kind.PM_ARROWSTAR || - kind == Kind.LOGICALANDEXPRESSION || - kind == Kind.LOGICALOREXPRESSION || - kind == Kind.RELATIONAL_GREATERTHAN || - kind == Kind.RELATIONAL_LESSTHAN || - kind == Kind.RELATIONAL_LESSTHANEQUALTO || - kind == Kind.RELATIONAL_GREATERTHANEQUALTO || - kind == Kind.EQUALITY_EQUALS || - kind == Kind.EQUALITY_NOTEQUALS || - kind == Kind.ADDITIVE_PLUS || - kind == Kind.ADDITIVE_MINUS || - kind == Kind.INCLUSIVEOREXPRESSION || - kind == Kind.MULTIPLICATIVE_MULTIPLY || - kind == Kind.MULTIPLICATIVE_DIVIDE || - kind == Kind.MULTIPLICATIVE_MODULUS || - kind == Kind.POSTFIX_DOT_TEMPL_IDEXPRESS || - kind == Kind.POSTFIX_DOT_IDEXPRESSION || - kind == Kind.POSTFIX_DOT_DESTRUCTOR || - kind == Kind.POSTFIX_ARROW_TEMPL_IDEXP || - kind == Kind.POSTFIX_ARROW_IDEXPRESSION || - kind == Kind.POSTFIX_ARROW_DESTRUCTOR || - kind == Kind.ASSIGNMENTEXPRESSION_NORMAL || - kind == Kind.ASSIGNMENTEXPRESSION_MULT || - kind == Kind.ASSIGNMENTEXPRESSION_DIV || - kind == Kind.ASSIGNMENTEXPRESSION_MOD || - kind == Kind.ASSIGNMENTEXPRESSION_PLUS || - kind == Kind.ASSIGNMENTEXPRESSION_MINUS || - kind == Kind.ASSIGNMENTEXPRESSION_RSHIFT || - kind == Kind.ASSIGNMENTEXPRESSION_LSHIFT || - kind == Kind.ASSIGNMENTEXPRESSION_AND || - kind == Kind.ASSIGNMENTEXPRESSION_XOR || - kind == Kind.ASSIGNMENTEXPRESSION_OR || - kind == Kind.SHIFT_LEFT || - kind == Kind.SHIFT_RIGHT) - { - buffer.append( ASTUtil.getStringForKind( kind ) ); - } else if( kind == Kind.POSTFIX_SUBSCRIPT ) - buffer.append( '[' ); - else if( kind == Kind.POSTFIX_FUNCTIONCALL ) - buffer.append( '(' ); - - if( kind == Kind.POSTFIX_DOT_TEMPL_IDEXPRESS || - kind == IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP) - { - buffer.append( ' ' ); - buffer.append( Keywords.TEMPLATE ); - buffer.append( ' ' ); - } - - if( appendSpace || kind == Kind.EXPRESSIONLIST ) - buffer.append( ' ' ); - - buffer.append( getExpressionString( expression.getRHSExpression() ) ); - - if( kind == Kind.POSTFIX_SUBSCRIPT ) - buffer.append( ']' ); - else if( kind == Kind.POSTFIX_FUNCTIONCALL ) - buffer.append( ')' ); - - return buffer.toString(); - } - - private static String getUnaryTypeIdExpression( IASTExpression expression ){ - StringBuffer buffer = new StringBuffer(); - - Kind kind = expression.getExpressionKind(); - if( kind == Kind.CASTEXPRESSION ){ - buffer.append( '(' ); - buffer.append( getTypeId( expression.getTypeId() ) ); - buffer.append( ')' ); - buffer.append( getExpressionString( expression.getLHSExpression() ) ); - - } else if ( kind == Kind.POSTFIX_DYNAMIC_CAST || - kind == Kind.POSTFIX_STATIC_CAST || - kind == Kind.POSTFIX_REINTERPRET_CAST || - kind == Kind.POSTFIX_CONST_CAST ) - { - buffer.append( ASTUtil.getStringForKind( kind ) ); - buffer.append( '<' ); - buffer.append( getTypeId( expression.getTypeId() ) ); - buffer.append( ">(" ); //$NON-NLS-1$ - buffer.append( getExpressionString( expression.getLHSExpression() ) ); - buffer.append( ')' ); - } - - return buffer.toString(); - } - - private static String getUnaryIdExpression( IASTExpression expression ){ - StringBuffer buffer = new StringBuffer(); - - buffer.append( Keywords.TYPENAME ); - buffer.append( ' ' ); - if( expression.getExpressionKind() == Kind.POSTFIX_TYPENAME_TEMPLATEID ){ - buffer.append( Keywords.TEMPLATE ); - buffer.append( ' ' ); - } - buffer.append( expression.getIdExpression() ); - buffer.append( '(' ); - buffer.append( getExpressionString( expression.getLHSExpression() ) ); - buffer.append( ')' ); - - return buffer.toString(); - } - private static String getUnaryExpression( IASTExpression expression ){ - StringBuffer buffer = new StringBuffer(); - Kind kind = expression.getExpressionKind(); - - boolean bracketsAroundExpression = ( kind == Kind.PRIMARY_BRACKETED_EXPRESSION ); - - if ( kind == Kind.UNARY_SIZEOF_UNARYEXPRESSION ){ - buffer.append( Keywords.SIZEOF ); - buffer.append( ' ' ); - } - else if ( kind == Kind.UNARY_STAR_CASTEXPRESSION || - kind == Kind.UNARY_AMPSND_CASTEXPRESSION || - kind == Kind.UNARY_PLUS_CASTEXPRESSION || - kind == Kind.UNARY_MINUS_CASTEXPRESSION || - kind == Kind.UNARY_NOT_CASTEXPRESSION || - kind == Kind.UNARY_TILDE_CASTEXPRESSION || - kind == Kind.UNARY_DECREMENT || - kind == Kind.THROWEXPRESSION - ) - { - buffer.append( ASTUtil.getStringForKind( kind ) ); - } - else if ( kind == Kind.UNARY_INCREMENT ) - buffer.append( "++" ); //$NON-NLS-1$ - else if( kind == Kind.DELETE_VECTORCASTEXPRESSION || kind == Kind.DELETE_CASTEXPRESSION ){ - buffer.append( Keywords.DELETE ); - buffer.append(' '); - if( kind == Kind.DELETE_VECTORCASTEXPRESSION ) - buffer.append( "[ ] " ); //$NON-NLS-1$ - } else if( kind == Kind.POSTFIX_SIMPLETYPE_CHAR || - kind == Kind.POSTFIX_SIMPLETYPE_WCHART || - kind == Kind.POSTFIX_SIMPLETYPE_BOOL || - kind == Kind.POSTFIX_SIMPLETYPE_SHORT || - kind == Kind.POSTFIX_SIMPLETYPE_INT || - kind == Kind.POSTFIX_SIMPLETYPE_LONG || - kind == Kind.POSTFIX_SIMPLETYPE_SIGNED || - kind == Kind.POSTFIX_SIMPLETYPE_UNSIGNED || - kind == Kind.POSTFIX_SIMPLETYPE_FLOAT || - kind == Kind.POSTFIX_SIMPLETYPE_DOUBLE - ) - { - buffer.append( ASTUtil.getStringForKind( kind ) ); - bracketsAroundExpression = true; - } else if( kind == Kind.POSTFIX_TYPEID_EXPRESSION ) - { - buffer.append( Keywords.TYPEID ); - bracketsAroundExpression = true; - } - - if( bracketsAroundExpression ) - buffer.append( '(' ); - - buffer.append( getExpressionString( expression.getLHSExpression() ) ); - - if( bracketsAroundExpression ) - buffer.append( ')' ); - - if( kind == Kind.POSTFIX_INCREMENT || - kind == Kind.POSTFIX_DECREMENT ) - { - buffer.append( ASTUtil.getStringForKind( kind ) ); - } - - return buffer.toString(); - } - private static String getTypeIdExpression( IASTExpression expression ){ - StringBuffer buffer = new StringBuffer(); - - Kind kind = expression.getExpressionKind(); - - boolean addBrackets = false; - if( kind == Kind.UNARY_SIZEOF_TYPEID ){ - buffer.append( Keywords.SIZEOF ); - buffer.append( ' ' ); - addBrackets = true; - } else if( kind == Kind.POSTFIX_TYPEID_TYPEID ){ - buffer.append( Keywords.TYPEID ); - addBrackets = true; - } - - if( addBrackets ) - buffer.append( '(' ); - buffer.append( ASTUtil.getTypeId( expression.getTypeId() ) ); - if( addBrackets ) - buffer.append( ')' ); - - return buffer.toString(); - } - - private static final Map expressionKindStringMap = new HashMap(); - static { - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DYNAMIC_CAST, Keywords.DYNAMIC_CAST ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_STATIC_CAST, Keywords.STATIC_CAST ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_REINTERPRET_CAST, Keywords.REINTERPRET_CAST ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_CONST_CAST, Keywords.CONST_CAST ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR, Keywords.CHAR ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART, Keywords.WCHAR_T ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL, Keywords.BOOL ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT, Keywords.SHORT ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT, Keywords.INT ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG, Keywords.LONG ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED, Keywords.SIGNED ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED, Keywords.UNSIGNED ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT, Keywords.FLOAT ); - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE, Keywords.DOUBLE ); - expressionKindStringMap.put( IASTExpression.Kind.THROWEXPRESSION, Keywords.THROW ); - expressionKindStringMap.put( IASTExpression.Kind.ANDEXPRESSION, "&" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION, "&" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.EXPRESSIONLIST, "," ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.EXCLUSIVEOREXPRESSION, "^" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.PM_DOTSTAR, ".*" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.PM_ARROWSTAR, "->*" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.LOGICALANDEXPRESSION, "&&" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.LOGICALOREXPRESSION, "||" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_GREATERTHAN, ">" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_LESSTHAN, "<" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO, "<=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO, ">=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.EQUALITY_EQUALS, "==" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.EQUALITY_NOTEQUALS, "!=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION, "*" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY, "*" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION, "+" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ADDITIVE_PLUS, "+" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION, "-" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ADDITIVE_MINUS, "-" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION, "!" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION, "~" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.UNARY_DECREMENT, "--" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DECREMENT, "--" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.UNARY_INCREMENT, "++" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_INCREMENT, "++" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.INCLUSIVEOREXPRESSION, "|" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.MULTIPLICATIVE_DIVIDE, "/" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.MULTIPLICATIVE_MODULUS, "%" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS, "." ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION, "." ); //$NON-NLS-1$ | - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_DOT_DESTRUCTOR, "." ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP, "->" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_ARROW_DESTRUCTOR, "->" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION, "->" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL, "=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT, "*=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV, "/=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD, "%=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS, "+=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS, "-=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT, ">>=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT, "<<=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND, "&=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR, "^=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR, "|=" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.SHIFT_LEFT, "<<" ); //$NON-NLS-1$ - expressionKindStringMap.put( IASTExpression.Kind.SHIFT_RIGHT, ">>" ); //$NON-NLS-1$ - - } - private static String getStringForKind( IASTExpression.Kind kind ){ - return (String) expressionKindStringMap.get( kind ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTASMDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTASMDefinition.java deleted file mode 100644 index 3bbd364925f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTASMDefinition.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - - -/** - * @author jcamelon - * - */ -public interface IASTASMDefinition extends IASTOffsetableElement, IASTDeclaration { - - public String getBody(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractDeclaration.java deleted file mode 100644 index 995e8019177..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractDeclaration.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTAbstractDeclaration extends IASTTypeSpecifierOwner, ISourceElementCallbackDelegate -{ - public boolean isConst(); - public boolean isVolatile(); - public Iterator getPointerOperators(); - public Iterator getArrayModifiers(); - public Iterator getParameters(); - public ASTPointerOperator getPointerToFunctionOperator(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractTypeSpecifierDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractTypeSpecifierDeclaration.java deleted file mode 100644 index 4581424c8f2..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTAbstractTypeSpecifierDeclaration.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTAbstractTypeSpecifierDeclaration - extends IASTDeclaration, IASTTypeSpecifierOwner, IASTTemplatedDeclaration, IASTOffsetableNamedElement -{ - public boolean isFriendDeclaration(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTArrayModifier.java deleted file mode 100644 index 3e2ca04f6c4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTArrayModifier.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - - -/** - * @author jcamelon - * - */ -public interface IASTArrayModifier extends ISourceElementCallbackDelegate -{ - public IASTExpression getExpression(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTBaseSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTBaseSpecifier.java deleted file mode 100644 index 1de6b6531b9..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTBaseSpecifier.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - - -/** - * @author jcamelon - * - */ -public interface IASTBaseSpecifier extends ISourceElementCallbackDelegate { - - public ASTAccessVisibility getAccess(); - public boolean isVirtual(); - public String getParentClassName(); - public IASTTypeSpecifier getParentClassSpecifier() throws ASTNotImplementedException; - public int getNameOffset(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassReference.java deleted file mode 100644 index ae77683d61c..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassReference.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTClassReference extends IASTReference -{ - public boolean isResolved(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java deleted file mode 100644 index 1675db64866..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTClassSpecifier.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.Enum; -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTClassSpecifier extends IASTScope, IASTOffsetableNamedElement, IASTScopedTypeSpecifier, ISourceElementCallbackDelegate { - - public class ClassNameType extends Enum { - - public static final ClassNameType IDENTIFIER = new ClassNameType( 1 ); - public static final ClassNameType TEMPLATE = new ClassNameType( 2 ); - - private ClassNameType( int t ) - { - super( t ); - } - } - - public ClassNameType getClassNameType(); - - public ASTClassKind getClassKind(); - - public Iterator getBaseClauses(); - - public Iterator getFriends(); - - public ASTAccessVisibility getCurrentVisibilityMode(); - public void setCurrentVisibility( ASTAccessVisibility visibility ); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCodeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCodeScope.java deleted file mode 100644 index 984e4e5fa9b..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCodeScope.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Sep 2, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public interface IASTCodeScope extends IASTScope, ISourceElementCallbackDelegate{ - - public IASTCodeScope getOwnerCodeScope(); - public IASTFunction getContainingFunction(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompilationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompilationUnit.java deleted file mode 100644 index 582b975aa34..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompilationUnit.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTCompilationUnit extends IASTScope, ISourceElementCallbackDelegate { - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java index 919df670059..fc4973d2de6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. + * Copyright (c) 2002, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,20 +10,16 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser.ast; -import java.util.Iterator; - import org.eclipse.cdt.core.parser.Enum; + /** * @author jcamelon * */ public interface IASTCompletionNode { - public static class CompletionKind extends Enum - { - // x.[ ] x->[ ] - public static final CompletionKind MEMBER_REFERENCE = new CompletionKind( 0 ); + public static class CompletionKind extends Enum { // class member declaration type reference public static final CompletionKind FIELD_TYPE = new CompletionKind( 2 ); @@ -92,42 +88,9 @@ public interface IASTCompletionNode { * @return kind of completion expected */ public CompletionKind getCompletionKind(); - - /** - * @return the scope the code completion is within - * should never be null - */ - public IASTScope getCompletionScope(); - - /** - * @return the context (inter-statement) - * e.g. LHS of postfix expression a->b, a.b or qualified name a::b is 'a' - * this can be null - */ - public IASTNode getCompletionContext(); - - /** - * @return the name of the function/constructor being completed in - * CONSTRUCTOR_REFERENCE - * FUNCTION_REFERENCE - */ - public String getFunctionName(); - - /** - * - * @return the IASTExpression representing the number of parameters - * input in the CONSTRUCTOR_REFERENCE/FUNCTION_REFERENCE context. - */ - public IASTExpression getFunctionParameters(); - + /** * @return the prefix */ public String getCompletionPrefix(); - - /** - * @return iterator of string keywords - */ - public Iterator getKeywords(); - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTConstructorMemberInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTConstructorMemberInitializer.java deleted file mode 100644 index af34ae87fa6..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTConstructorMemberInitializer.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTConstructorMemberInitializer extends ISourceElementCallbackDelegate -{ - public IASTExpression getExpressionList(); - public String getName(); - public char[] getNameCharArray(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDeclaration.java deleted file mode 100644 index ae8dce42870..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDeclaration.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTDeclaration extends IASTScopedElement, ISourceElementCallbackDelegate { - - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDesignator.java deleted file mode 100644 index 6d57bba9b4d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTDesignator.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.Enum; -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTDesignator extends ISourceElementCallbackDelegate -{ - public static class DesignatorKind extends Enum - { - public static final DesignatorKind FIELD = new DesignatorKind( 0 ); - public static final DesignatorKind SUBSCRIPT = new DesignatorKind( 1 ); - protected static final int LAST_KIND = 1; - /** - * @param enumValue - */ - protected DesignatorKind(int enumValue) - { - super(enumValue); - // TODO Auto-generated constructor stub - } - } - - public DesignatorKind getKind(); - public IASTExpression arraySubscriptExpression(); - public String fieldName(); - public int fieldOffset(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTElaboratedTypeSpecifier.java deleted file mode 100644 index 8d569b903f8..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTElaboratedTypeSpecifier.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - - - -/** - * @author jcamelon - * - */ -public interface IASTElaboratedTypeSpecifier extends IASTTypeSpecifier, IASTQualifiedNameElement, ISourceElementCallbackDelegate, IASTOffsetableNamedElement { - - public String getName(); - public ASTClassKind getClassKind(); - public boolean isResolved() throws ASTNotImplementedException; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerationReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerationReference.java deleted file mode 100644 index 7c3bd4fccd8..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerationReference.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTEnumerationReference extends IASTReference -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerationSpecifier.java deleted file mode 100644 index 58b73e41c88..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerationSpecifier.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTEnumerationSpecifier extends ISourceElementCallbackDelegate, IASTScopedTypeSpecifier, IASTOffsetableNamedElement { - - public Iterator getEnumerators(); - - /** - * @param referenceManager - */ - public void freeReferences(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerator.java deleted file mode 100644 index db09c8dd821..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumerator.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTEnumerator extends IASTOffsetableNamedElement, IASTNode, ISourceElementCallbackDelegate { - - public IASTEnumerationSpecifier getOwnerEnumerationSpecifier(); - public IASTExpression getInitialValue(); - /** - * @param referenceManager - */ - public void freeReferences(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumeratorReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumeratorReference.java deleted file mode 100644 index 4d29df72a35..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTEnumeratorReference.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTEnumeratorReference extends IASTReference -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExceptionSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExceptionSpecification.java deleted file mode 100644 index 4387e94c221..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExceptionSpecification.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - -/** - * @author jcamelon - * - */ -public interface IASTExceptionSpecification -{ - public Iterator getTypeIds(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java deleted file mode 100644 index ae977829548..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTExpression.java +++ /dev/null @@ -1,339 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Hashtable; -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.Enum; -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTExpression extends ISourceElementCallbackDelegate, IASTNode, IASTOffsetableElement -{ - public class Kind extends Enum - { - public static final Kind PRIMARY_EMPTY = new Kind( -1 ); - public static final Kind PRIMARY_INTEGER_LITERAL = new Kind( 0 ); - public static final Kind PRIMARY_CHAR_LITERAL = new Kind( 1 ); - public static final Kind PRIMARY_FLOAT_LITERAL = new Kind( 2 ); - public static final Kind PRIMARY_STRING_LITERAL = new Kind( 3 ); - public static final Kind PRIMARY_BOOLEAN_LITERAL = new Kind( 4 ); - public static final Kind PRIMARY_THIS = new Kind( 5 ); - public static final Kind PRIMARY_BRACKETED_EXPRESSION = new Kind( 6 ); - public static final Kind ID_EXPRESSION = new Kind( 7 ); - public static final Kind POSTFIX_SUBSCRIPT = new Kind( 8 ); - public static final Kind POSTFIX_FUNCTIONCALL = new Kind( 9 ); - public static final Kind POSTFIX_SIMPLETYPE_INT = new Kind( 10 ); - public static final Kind POSTFIX_SIMPLETYPE_SHORT = new Kind( 11 ); - public static final Kind POSTFIX_SIMPLETYPE_DOUBLE = new Kind( 12 ); - public static final Kind POSTFIX_SIMPLETYPE_FLOAT = new Kind( 13 ); - public static final Kind POSTFIX_SIMPLETYPE_CHAR = new Kind( 14 ); - public static final Kind POSTFIX_SIMPLETYPE_WCHART = new Kind( 15 ); - public static final Kind POSTFIX_SIMPLETYPE_SIGNED = new Kind( 16 ); - public static final Kind POSTFIX_SIMPLETYPE_UNSIGNED = new Kind( 17 ); - public static final Kind POSTFIX_SIMPLETYPE_BOOL = new Kind( 18 ); - public static final Kind POSTFIX_SIMPLETYPE_LONG = new Kind( 19 ); - public static final Kind POSTFIX_TYPENAME_IDENTIFIER = new Kind( 20 ); - public static final Kind POSTFIX_TYPENAME_TEMPLATEID = new Kind( 21 ); - public static final Kind POSTFIX_DOT_IDEXPRESSION = new Kind( 22 ); - public static final Kind POSTFIX_ARROW_IDEXPRESSION = new Kind( 23 ); - public static final Kind POSTFIX_DOT_TEMPL_IDEXPRESS = new Kind( 24 ); - public static final Kind POSTFIX_ARROW_TEMPL_IDEXP = new Kind( 25 ); - public static final Kind POSTFIX_DOT_DESTRUCTOR = new Kind( 26 ); - public static final Kind POSTFIX_ARROW_DESTRUCTOR = new Kind( 27 ); - public static final Kind POSTFIX_INCREMENT = new Kind( 28 ); - public static final Kind POSTFIX_DECREMENT = new Kind( 29 ); - public static final Kind POSTFIX_DYNAMIC_CAST = new Kind( 30 ); - public static final Kind POSTFIX_REINTERPRET_CAST = new Kind( 31 ); - public static final Kind POSTFIX_STATIC_CAST = new Kind( 32 ); - public static final Kind POSTFIX_CONST_CAST = new Kind( 33 ); - public static final Kind POSTFIX_TYPEID_EXPRESSION = new Kind( 34 ); - public static final Kind POSTFIX_TYPEID_TYPEID = new Kind( 35 ); - public static final Kind UNARY_INCREMENT = new Kind( 36 ); - public static final Kind UNARY_DECREMENT = new Kind( 37 ); - public static final Kind UNARY_STAR_CASTEXPRESSION = new Kind( 38 ); - public static final Kind UNARY_AMPSND_CASTEXPRESSION = new Kind( 39 ); - public static final Kind UNARY_PLUS_CASTEXPRESSION = new Kind( 40 ); - public static final Kind UNARY_MINUS_CASTEXPRESSION = new Kind( 41 ); - public static final Kind UNARY_NOT_CASTEXPRESSION = new Kind( 42 ); - public static final Kind UNARY_TILDE_CASTEXPRESSION = new Kind( 43 ); - public static final Kind UNARY_SIZEOF_UNARYEXPRESSION = new Kind( 44 ); - public static final Kind UNARY_SIZEOF_TYPEID = new Kind( 45 ); - public static final Kind NEW_NEWTYPEID = new Kind( 46 ); - public static final Kind NEW_TYPEID = new Kind( 47 ); - public static final Kind DELETE_CASTEXPRESSION = new Kind( 48 ); - public static final Kind DELETE_VECTORCASTEXPRESSION = new Kind( 49 ); - public static final Kind CASTEXPRESSION = new Kind( 50 ); - public static final Kind PM_DOTSTAR = new Kind( 51 ); - public static final Kind PM_ARROWSTAR = new Kind( 52 ); - public static final Kind MULTIPLICATIVE_MULTIPLY = new Kind( 53 ); - public static final Kind MULTIPLICATIVE_DIVIDE = new Kind( 54 ); - public static final Kind MULTIPLICATIVE_MODULUS = new Kind( 55 ); - public static final Kind ADDITIVE_PLUS = new Kind( 56 ); - public static final Kind ADDITIVE_MINUS = new Kind( 57 ); - public static final Kind SHIFT_LEFT = new Kind( 58 ); - public static final Kind SHIFT_RIGHT = new Kind( 59 ); - public static final Kind RELATIONAL_LESSTHAN = new Kind( 60 ); - public static final Kind RELATIONAL_GREATERTHAN = new Kind( 61 ); - public static final Kind RELATIONAL_LESSTHANEQUALTO = new Kind( 62 ); - public static final Kind RELATIONAL_GREATERTHANEQUALTO= new Kind( 63 ); - public static final Kind EQUALITY_EQUALS = new Kind( 64 ); - public static final Kind EQUALITY_NOTEQUALS = new Kind( 65 ); - public static final Kind ANDEXPRESSION = new Kind( 66 ); - public static final Kind EXCLUSIVEOREXPRESSION = new Kind( 67 ); - public static final Kind INCLUSIVEOREXPRESSION = new Kind( 68 ); - public static final Kind LOGICALANDEXPRESSION = new Kind( 69 ); - public static final Kind LOGICALOREXPRESSION = new Kind( 70 ); - public static final Kind CONDITIONALEXPRESSION = new Kind( 71 ); - public static final Kind THROWEXPRESSION = new Kind( 72 ); - public static final Kind ASSIGNMENTEXPRESSION_NORMAL = new Kind( 73 ); - public static final Kind ASSIGNMENTEXPRESSION_PLUS = new Kind( 74 ); - public static final Kind ASSIGNMENTEXPRESSION_MINUS = new Kind( 75 ); - public static final Kind ASSIGNMENTEXPRESSION_MULT = new Kind( 76 ); - public static final Kind ASSIGNMENTEXPRESSION_DIV = new Kind( 77 ); - public static final Kind ASSIGNMENTEXPRESSION_MOD = new Kind( 78 ); - public static final Kind ASSIGNMENTEXPRESSION_LSHIFT = new Kind( 79 ); - public static final Kind ASSIGNMENTEXPRESSION_RSHIFT = new Kind( 80 ); - public static final Kind ASSIGNMENTEXPRESSION_AND = new Kind( 81 ); - public static final Kind ASSIGNMENTEXPRESSION_OR = new Kind( 82 ); - public static final Kind ASSIGNMENTEXPRESSION_XOR = new Kind( 83 ); - public static final Kind EXPRESSIONLIST = new Kind( 84 ); - - protected static final int LAST_KIND = 84; - - - /** - * @param enumValue - */ - protected Kind(int enumValue) - { - super(enumValue); - } - - public boolean isExtensionKind(){ - return getEnumValue() > LAST_KIND; - } - - private static final Hashtable names; - static - { - names = new Hashtable(); - names.put( PRIMARY_EMPTY, "PRIMARY_EMPTY" ); //$NON-NLS-1$ - names.put( PRIMARY_INTEGER_LITERAL , "PRIMARY_INTEGER_LITERAL" ); //$NON-NLS-1$ - names.put( PRIMARY_CHAR_LITERAL , "PRIMARY_CHAR_LITERAL" ); //$NON-NLS-1$ - names.put( PRIMARY_FLOAT_LITERAL , "PRIMARY_FLOAT_LITERAL" ); //$NON-NLS-1$ - names.put( PRIMARY_STRING_LITERAL , "PRIMARY_STRING_LITERAL" ); //$NON-NLS-1$ - names.put( PRIMARY_BOOLEAN_LITERAL , "PRIMARY_BOOLEAN_LITERAL" ); //$NON-NLS-1$ - names.put( PRIMARY_THIS , "PRIMARY_THIS"); //$NON-NLS-1$ - names.put( PRIMARY_BRACKETED_EXPRESSION , "PRIMARY_BRACKETED_EXPRESSION"); //$NON-NLS-1$ - names.put( ID_EXPRESSION , "ID_EXPRESSION"); //$NON-NLS-1$ - names.put( POSTFIX_SUBSCRIPT , "POSTFIX_SUBSCRIPT"); //$NON-NLS-1$ - names.put( POSTFIX_FUNCTIONCALL , "POSTFIX_FUNCTIONCALL"); //$NON-NLS-1$ - names.put( POSTFIX_SIMPLETYPE_INT , "POSTFIX_SIMPLETYPE_INT"); //$NON-NLS-1$ - names.put( POSTFIX_SIMPLETYPE_SHORT , "POSTFIX_SIMPLETYPE_SHORT"); //$NON-NLS-1$ - names.put( POSTFIX_SIMPLETYPE_DOUBLE , "POSTFIX_SIMPLETYPE_DOUBLE"); //$NON-NLS-1$ - names.put( POSTFIX_SIMPLETYPE_FLOAT , "POSTFIX_SIMPLETYPE_FLOAT"); //$NON-NLS-1$ - names.put( POSTFIX_SIMPLETYPE_CHAR , "POSTFIX_SIMPLETYPE_CHAR"); //$NON-NLS-1$ - names.put( POSTFIX_SIMPLETYPE_WCHART , "POSTFIX_SIMPLETYPE_WCHART"); //$NON-NLS-1$ - names.put( POSTFIX_SIMPLETYPE_SIGNED , "POSTFIX_SIMPLETYPE_SIGNED"); //$NON-NLS-1$ - names.put( POSTFIX_SIMPLETYPE_UNSIGNED , "POSTFIX_SIMPLETYPE_UNSIGNED"); //$NON-NLS-1$ - names.put( POSTFIX_SIMPLETYPE_BOOL , "POSTFIX_SIMPLETYPE_BOOL"); //$NON-NLS-1$ - names.put( POSTFIX_SIMPLETYPE_LONG , "POSTFIX_SIMPLETYPE_LONG"); //$NON-NLS-1$ - names.put( POSTFIX_TYPENAME_IDENTIFIER , "POSTFIX_TYPENAME_IDENTIFIER"); //$NON-NLS-1$ - names.put( POSTFIX_TYPENAME_TEMPLATEID, "POSTFIX_TYPENAME_TEMPLATEID" ); //$NON-NLS-1$ - names.put( POSTFIX_DOT_IDEXPRESSION , "POSTFIX_DOT_IDEXPRESSION"); //$NON-NLS-1$ - names.put( POSTFIX_ARROW_IDEXPRESSION , "POSTFIX_ARROW_IDEXPRESSION"); //$NON-NLS-1$ - names.put( POSTFIX_DOT_TEMPL_IDEXPRESS , "POSTFIX_DOT_TEMPL_IDEXPRESS"); //$NON-NLS-1$ - names.put( POSTFIX_ARROW_TEMPL_IDEXP , "POSTFIX_ARROW_TEMPL_IDEXP"); //$NON-NLS-1$ - names.put( POSTFIX_DOT_DESTRUCTOR , "POSTFIX_DOT_DESTRUCTOR"); //$NON-NLS-1$ - names.put( POSTFIX_ARROW_DESTRUCTOR , "POSTFIX_ARROW_DESTRUCTOR"); //$NON-NLS-1$ - names.put( POSTFIX_INCREMENT , "POSTFIX_INCREMENT"); //$NON-NLS-1$ - names.put( POSTFIX_DECREMENT , "POSTFIX_DECREMENT"); //$NON-NLS-1$ - names.put( POSTFIX_DYNAMIC_CAST , "POSTFIX_DYNAMIC_CAST"); //$NON-NLS-1$ - names.put( POSTFIX_REINTERPRET_CAST , "POSTFIX_REINTERPRET_CAST"); //$NON-NLS-1$ - names.put( POSTFIX_STATIC_CAST , "POSTFIX_STATIC_CAST"); //$NON-NLS-1$ - names.put( POSTFIX_CONST_CAST , "POSTFIX_CONST_CAST"); //$NON-NLS-1$ - names.put( POSTFIX_TYPEID_EXPRESSION , "POSTFIX_TYPEID_EXPRESSION"); //$NON-NLS-1$ - names.put( POSTFIX_TYPEID_TYPEID , "POSTFIX_TYPEID_TYPEID"); //$NON-NLS-1$ - names.put( UNARY_INCREMENT , "UNARY_INCREMENT"); //$NON-NLS-1$ - names.put( UNARY_DECREMENT , "UNARY_DECREMENT"); //$NON-NLS-1$ - names.put( UNARY_STAR_CASTEXPRESSION , "UNARY_STAR_CASTEXPRESSION"); //$NON-NLS-1$ - names.put( UNARY_AMPSND_CASTEXPRESSION , "UNARY_AMPSND_CASTEXPRESSION"); //$NON-NLS-1$ - names.put( UNARY_PLUS_CASTEXPRESSION , "UNARY_PLUS_CASTEXPRESSION"); //$NON-NLS-1$ - names.put( UNARY_MINUS_CASTEXPRESSION , "UNARY_MINUS_CASTEXPRESSION"); //$NON-NLS-1$ - names.put( UNARY_NOT_CASTEXPRESSION , "UNARY_NOT_CASTEXPRESSION"); //$NON-NLS-1$ - names.put( UNARY_TILDE_CASTEXPRESSION , "UNARY_TILDE_CASTEXPRESSION"); //$NON-NLS-1$ - names.put( UNARY_SIZEOF_UNARYEXPRESSION , "UNARY_SIZEOF_UNARYEXPRESSION"); //$NON-NLS-1$ - names.put( UNARY_SIZEOF_TYPEID , "UNARY_SIZEOF_TYPEID"); //$NON-NLS-1$ - names.put( NEW_NEWTYPEID , "NEW_NEWTYPEID"); //$NON-NLS-1$ - names.put( NEW_TYPEID , "NEW_TYPEID"); //$NON-NLS-1$ - names.put( DELETE_CASTEXPRESSION , "DELETE_CASTEXPRESSION"); //$NON-NLS-1$ - names.put( DELETE_VECTORCASTEXPRESSION , "DELETE_VECTORCASTEXPRESSION"); //$NON-NLS-1$ - names.put( CASTEXPRESSION , "CASTEXPRESSION"); //$NON-NLS-1$ - names.put( PM_DOTSTAR , "PM_DOTSTAR"); //$NON-NLS-1$ - names.put( PM_ARROWSTAR , "PM_ARROWSTAR"); //$NON-NLS-1$ - names.put( MULTIPLICATIVE_MULTIPLY , "MULTIPLICATIVE_MULTIPLY"); //$NON-NLS-1$ - names.put( MULTIPLICATIVE_DIVIDE , "MULTIPLICATIVE_DIVIDE"); //$NON-NLS-1$ - names.put( MULTIPLICATIVE_MODULUS , "MULTIPLICATIVE_MODULUS"); //$NON-NLS-1$ - names.put( ADDITIVE_PLUS , "ADDITIVE_PLUS"); //$NON-NLS-1$ - names.put( ADDITIVE_MINUS , "ADDITIVE_MINUS"); //$NON-NLS-1$ - names.put( SHIFT_LEFT , "SHIFT_LEFT"); //$NON-NLS-1$ - names.put( SHIFT_RIGHT , "SHIFT_RIGHT"); //$NON-NLS-1$ - names.put( RELATIONAL_LESSTHAN , "RELATIONAL_LESSTHAN"); //$NON-NLS-1$ - names.put( RELATIONAL_GREATERTHAN , "RELATIONAL_GREATERTHAN"); //$NON-NLS-1$ - names.put( RELATIONAL_LESSTHANEQUALTO , "RELATIONAL_LESSTHANEQUALTO"); //$NON-NLS-1$ - names.put( RELATIONAL_GREATERTHANEQUALTO, "RELATIONAL_GREATERTHANEQUALTO" ); //$NON-NLS-1$ - names.put( EQUALITY_EQUALS , "EQUALITY_EQUALS"); //$NON-NLS-1$ - names.put( EQUALITY_NOTEQUALS , "EQUALITY_NOTEQUALS"); //$NON-NLS-1$ - names.put( ANDEXPRESSION , "ANDEXPRESSION"); //$NON-NLS-1$ - names.put( EXCLUSIVEOREXPRESSION , "EXCLUSIVEOREXPRESSION"); //$NON-NLS-1$ - names.put( INCLUSIVEOREXPRESSION , "INCLUSIVEOREXPRESSION"); //$NON-NLS-1$ - names.put( LOGICALANDEXPRESSION , "LOGICALANDEXPRESSION"); //$NON-NLS-1$ - names.put( LOGICALOREXPRESSION , "LOGICALOREXPRESSION"); //$NON-NLS-1$ - names.put( CONDITIONALEXPRESSION , "CONDITIONALEXPRESSION"); //$NON-NLS-1$ - names.put( THROWEXPRESSION , "THROWEXPRESSION"); //$NON-NLS-1$ - names.put( ASSIGNMENTEXPRESSION_NORMAL , "ASSIGNMENTEXPRESSION_NORMAL"); //$NON-NLS-1$ - names.put( ASSIGNMENTEXPRESSION_PLUS , "ASSIGNMENTEXPRESSION_PLUS"); //$NON-NLS-1$ - names.put( ASSIGNMENTEXPRESSION_MINUS , "ASSIGNMENTEXPRESSION_MINUS"); //$NON-NLS-1$ - names.put( ASSIGNMENTEXPRESSION_MULT , "ASSIGNMENTEXPRESSION_MULT"); //$NON-NLS-1$ - names.put( ASSIGNMENTEXPRESSION_DIV , "ASSIGNMENTEXPRESSION_DIV"); //$NON-NLS-1$ - names.put( ASSIGNMENTEXPRESSION_MOD , "ASSIGNMENTEXPRESSION_MOD"); //$NON-NLS-1$ - names.put( ASSIGNMENTEXPRESSION_LSHIFT , "ASSIGNMENTEXPRESSION_LSHIFT"); //$NON-NLS-1$ - names.put( ASSIGNMENTEXPRESSION_RSHIFT , "ASSIGNMENTEXPRESSION_RSHIFT"); //$NON-NLS-1$ - names.put( ASSIGNMENTEXPRESSION_AND , "ASSIGNMENTEXPRESSION_AND"); //$NON-NLS-1$ - names.put( ASSIGNMENTEXPRESSION_OR , "ASSIGNMENTEXPRESSION_OR"); //$NON-NLS-1$ - names.put( ASSIGNMENTEXPRESSION_XOR , "ASSIGNMENTEXPRESSION_XOR"); //$NON-NLS-1$ - names.put( EXPRESSIONLIST , "EXPRESSIONLIST"); //$NON-NLS-1$ - - } - /** - * @return - */ - public String getKindName() { - - Object check = names.get(this); - if( check != null ) - return (String) check; - return "EXTENSION SPECIFIED"; //$NON-NLS-1$ - } - - public boolean isPostfixMemberReference() - { - if( this == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION || - this == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION || - this == IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS || - this == IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP || - this == IASTExpression.Kind.POSTFIX_ARROW_DESTRUCTOR || - this == IASTExpression.Kind.POSTFIX_DOT_DESTRUCTOR || - this == IASTExpression.Kind.PM_DOTSTAR || - this == IASTExpression.Kind.PM_ARROWSTAR ) - return true; - return false; - - } - - /** - * @return - */ - public boolean isLiteral() { - if( this == PRIMARY_INTEGER_LITERAL || - this == PRIMARY_CHAR_LITERAL || - this == PRIMARY_FLOAT_LITERAL || - this == PRIMARY_STRING_LITERAL || - this == PRIMARY_BOOLEAN_LITERAL ) - return true; - return false; - } - - public boolean isBasicType(){ - if(this == PRIMARY_EMPTY - || this == THROWEXPRESSION - || this == POSTFIX_DOT_DESTRUCTOR - || this == POSTFIX_ARROW_DESTRUCTOR - || this == DELETE_CASTEXPRESSION - || this == DELETE_VECTORCASTEXPRESSION - || this == PRIMARY_INTEGER_LITERAL - || this == POSTFIX_SIMPLETYPE_INT - || this == UNARY_SIZEOF_TYPEID - || this == UNARY_SIZEOF_UNARYEXPRESSION - || this == PRIMARY_CHAR_LITERAL - || this == POSTFIX_SIMPLETYPE_CHAR - || this == PRIMARY_STRING_LITERAL - || this == PRIMARY_FLOAT_LITERAL - || this == POSTFIX_SIMPLETYPE_FLOAT - || this == POSTFIX_SIMPLETYPE_DOUBLE - || this == POSTFIX_SIMPLETYPE_WCHART - || this == PRIMARY_BOOLEAN_LITERAL - || this == POSTFIX_SIMPLETYPE_BOOL - || this == RELATIONAL_GREATERTHAN - || this == RELATIONAL_GREATERTHANEQUALTO - || this == RELATIONAL_LESSTHAN - || this == RELATIONAL_LESSTHANEQUALTO - || this == EQUALITY_EQUALS - || this == EQUALITY_NOTEQUALS - || this == LOGICALANDEXPRESSION - || this == LOGICALOREXPRESSION - ) - return true; - return false; - } - public boolean isPostfixSimpleType(){ - if((this == POSTFIX_SIMPLETYPE_INT) - || (this == POSTFIX_SIMPLETYPE_SHORT) - || (this == POSTFIX_SIMPLETYPE_DOUBLE) - || (this == POSTFIX_SIMPLETYPE_FLOAT) - || (this == POSTFIX_SIMPLETYPE_CHAR) - || (this == POSTFIX_SIMPLETYPE_WCHART) - || (this == POSTFIX_SIMPLETYPE_SIGNED) - || (this == POSTFIX_SIMPLETYPE_UNSIGNED) - || (this == POSTFIX_SIMPLETYPE_BOOL) - || (this == POSTFIX_SIMPLETYPE_LONG) ) - { - return true; - } - return false; - } - } - - public interface IASTNewExpressionDescriptor extends ISourceElementCallbackDelegate - { - public Iterator getNewPlacementExpressions(); - public Iterator getNewTypeIdExpressions(); - public Iterator getNewInitializerExpressions(); - public void freeReferences( ); - } - - - - public Kind getExpressionKind(); - public IASTExpression getLHSExpression(); - public IASTExpression getRHSExpression(); - public IASTExpression getThirdExpression(); - public String getLiteralString(); - public String getIdExpression(); - public char[] getIdExpressionCharArray(); - public IASTTypeId getTypeId(); - public IASTNewExpressionDescriptor getNewExpressionDescriptor(); - - public long evaluateExpression() throws ASTExpressionEvaluationException; - public void reconcileReferences() throws ASTNotImplementedException; - public void purgeReferences() throws ASTNotImplementedException; - /** - * @param manager TODO - * - */ - public void freeReferences(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java deleted file mode 100644 index 8b049dec0f7..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFactory.java +++ /dev/null @@ -1,275 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; -import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; -/** - * @author jcamelon - * - */ -public interface IASTFactory -{ - public IASTMacro createMacro( - char[] name, - int startingOffset, - int startingLine, - int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn, boolean isImplicit); - - public IASTInclusion createInclusion( - char[] name, - char[] fileName, - boolean local, - int startingOffset, - int startingLine, - int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn, boolean isImplicit) ; - - public IASTUsingDirective createUsingDirective( - IASTScope scope, - ITokenDuple duple, int startingOffset, int startingLine, int endingOffset, int endingLine) - throws ASTSemanticException; - - public IASTUsingDeclaration createUsingDeclaration( - IASTScope scope, - boolean isTypeName, - ITokenDuple name, int startingOffset, int startingLine, int endingOffset, int endingLine) throws ASTSemanticException; - - public IASTASMDefinition createASMDefinition( - IASTScope scope, - char[] assembly, - int startingOffset, - int startingLine, int endingOffset, int endingLine, char[] fn); - - public IASTNamespaceDefinition createNamespaceDefinition( - IASTScope scope, - char[] identifier, - int startingOffset, - int startingLine, int nameOffset, int nameEndOffset, int nameLineNumber, char[] fn) throws ASTSemanticException; - - public IASTNamespaceAlias createNamespaceAlias( - IASTScope scope, - char[] identifier, - ITokenDuple alias, - int startingOffset, - int startingLine, - int nameOffset, int nameEndOffset, int nameLine, int endOffset, int endingLine ) throws ASTSemanticException; - - public IASTCompilationUnit createCompilationUnit() ; - - public IASTLinkageSpecification createLinkageSpecification( - IASTScope scope, - char[] spec, int startingOffset, int startingLine, char[] fn) ; - - public IASTClassSpecifier createClassSpecifier( - IASTScope scope, - ITokenDuple name, - ASTClassKind kind, - ClassNameType type, - ASTAccessVisibility access, - int startingOffset, - int startingLine, int nameOffset, int nameEndOffset, int nameLine, char[] fn) throws ASTSemanticException; - - /** - * @param astClassSpec - * @param isVirtual - * @param visibility - * @param string - */ - public void addBaseSpecifier( - IASTClassSpecifier astClassSpec, - boolean isVirtual, - ASTAccessVisibility visibility, - ITokenDuple parentClassName) throws ASTSemanticException; - - public IASTElaboratedTypeSpecifier createElaboratedTypeSpecifier( - IASTScope scope, - ASTClassKind elaboratedClassKind, - ITokenDuple typeName, - int startingOffset, int startingLine, int endOffset, int endingLine, boolean isForewardDecl, boolean isFriend) throws ASTSemanticException; - - public IASTEnumerationSpecifier createEnumerationSpecifier( - IASTScope scope, - char[] name, - int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, char[] fn) throws ASTSemanticException; - - public IASTEnumerator addEnumerator( - IASTEnumerationSpecifier enumeration, - char[] string, - int startingOffset, - int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endLine, IASTExpression initialValue, char[] fn)throws ASTSemanticException; - - public IASTExpression createExpression( - IASTScope scope, - IASTExpression.Kind kind, - IASTExpression lhs, - IASTExpression rhs, - IASTExpression thirdExpression, - IASTTypeId typeId, - ITokenDuple idExpression, char[] literal, IASTNewExpressionDescriptor newDescriptor, ITokenDuple extra) throws ASTSemanticException; - - public IASTExpression.IASTNewExpressionDescriptor createNewDescriptor(List newPlacementExpressions,List newTypeIdExpressions,List newInitializerExpressions); - - public IASTInitializerClause createInitializerClause( - IASTScope scope, - IASTInitializerClause.Kind kind, - IASTExpression assignmentExpression, List initializerClauses, List designators) ; - - public IASTExceptionSpecification createExceptionSpecification(IASTScope scope, List typeIds) throws ASTSemanticException; - - /** - * @param exp - */ - public IASTArrayModifier createArrayModifier(IASTExpression exp); - - /** - * @param duple - * @param expressionList - * @return - */ - - public IASTConstructorMemberInitializer createConstructorMemberInitializer( - IASTScope scope, - ITokenDuple duple, IASTExpression expressionList) throws ASTSemanticException; - - public IASTSimpleTypeSpecifier createSimpleTypeSpecifier( - IASTScope scope, - IASTSimpleTypeSpecifier.Type kind, - ITokenDuple typeName, - boolean isShort, - boolean isLong, - boolean isSigned, - boolean isUnsigned, - boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map map ) throws ASTSemanticException; - - public IASTFunction createFunction( - IASTScope scope, - ITokenDuple name, - List parameters, - IASTAbstractDeclaration returnType, - IASTExceptionSpecification exception, - boolean isInline, - boolean isFriend, - boolean isStatic, - int startOffset, - int startLine, - int nameOffset, - int nameEndOffset, - int nameLine, - IASTTemplate ownerTemplate, - boolean isConst, - boolean isVolatile, - boolean isVirtual, boolean isExplicit, boolean isPureVirtual, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments ) throws ASTSemanticException; - - - public IASTAbstractDeclaration createAbstractDeclaration( - boolean isConst, - boolean isVolatile, - IASTTypeSpecifier typeSpecifier, - List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOperator); - - public IASTMethod createMethod( - IASTScope scope, - ITokenDuple name, - List parameters, - IASTAbstractDeclaration returnType, - IASTExceptionSpecification exception, - boolean isInline, - boolean isFriend, - boolean isStatic, - int startOffset, - int startLine, - int nameOffset, - int nameEndOffset, - int nameLine, - IASTTemplate ownerTemplate, - boolean isConst, - boolean isVolatile, - boolean isVirtual, boolean isExplicit, boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isDefinition, boolean hasFunctionTryBlock, boolean hasVariableArguments) throws ASTSemanticException; - - public IASTVariable createVariable(IASTScope scope, ITokenDuple name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, - IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression, char[] fn ) throws ASTSemanticException; - - public IASTField createField( IASTScope scope, ITokenDuple name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression, ASTAccessVisibility visibility, char[] fn) throws ASTSemanticException; - - public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier, Map extensionParms ); - - public IASTParameterDeclaration createParameterDeclaration( boolean isConst, boolean isVolatile, IASTTypeSpecifier getTypeSpecifier, List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOp, char[] parameterName, IASTInitializerClause initializerClause, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn ) ; - - public IASTTemplateDeclaration createTemplateDeclaration( IASTScope scope, List templateParameters, boolean exported, int startingOffset, int startingLine, char[] fn ) throws ASTSemanticException; - - public IASTTemplateParameter createTemplateParameter( IASTTemplateParameter.ParamKind kind, char[] identifier, IASTTypeId defaultValue, IASTParameterDeclaration parameter, List parms, IASTCodeScope parameterScope, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn ) throws ASTSemanticException; - - public IASTTemplateInstantiation createTemplateInstantiation(IASTScope scope, int startingOffset, int startingLine, char[] fn); - - public IASTTemplateSpecialization createTemplateSpecialization(IASTScope scope, int startingOffset, int startingLine, char[] fn); - - public IASTTypedefDeclaration createTypedef( IASTScope scope, char[] name, IASTAbstractDeclaration mapping, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, char[] fn ) throws ASTSemanticException; - - public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration( IASTScope scope, IASTTypeSpecifier typeSpecifier, IASTTemplate template, int startingOffset, int startingLine, int endingOffset, int endingLine, boolean isFriend, char[] fn ); - - public boolean queryIsTypeName( IASTScope scope, ITokenDuple nameInQuestion ) ; - - static final char[] DOUBLE_COLON = new char[] { ':', ':' }; - static final char[] TELTA = new char[] { '~' }; - /** - * @param scope - * @return - */ - public IASTCodeScope createNewCodeBlock(IASTScope scope); - - public IASTTypeId createTypeId( IASTScope scope, IASTSimpleTypeSpecifier.Type kind, boolean isConst, boolean isVolatile, boolean isShort, - boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, ITokenDuple name, List pointerOps, List arrayMods, char[] completeSignature ) throws ASTSemanticException; - /** - * @param astClassSpecifier - */ - public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier); - - public IASTNode lookupSymbolInContext( IASTScope scope, ITokenDuple duple, IASTNode reference ) throws ASTNotImplementedException; - - /** - * @param log - */ - public void setLogger(IParserLogService log); - - /** - * @param scope - * @param duple - * @return - */ - public IASTScope getDeclaratorScope(IASTScope scope, ITokenDuple duple); - - /** - * @param scope TODO - * @param expression - * @return - */ - public IASTNode expressionToMostPreciseASTNode(IASTScope scope, IASTExpression expression); - - /** - * @param node - * @return - */ - public boolean validateIndirectMemberOperation(IASTNode node); - - /** - * @param node - * @return - */ - public boolean validateDirectMemberOperation(IASTNode node); - - public void constructExpressions( boolean flag ); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTField.java deleted file mode 100644 index 7fe207cbddb..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTField.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - - -/** - * @author jcamelon - * - */ -public interface IASTField extends IASTVariable, IASTMember { - - - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFieldReference.java deleted file mode 100644 index 4cc7b9e976f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFieldReference.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTFieldReference extends IASTReference -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFunction.java deleted file mode 100644 index 24a3dc26cb4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFunction.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - -/** - * @author jcamelon - * - */ -public interface IASTFunction extends IASTCodeScope, IASTOffsetableNamedElement, IASTTemplatedDeclaration, IASTDeclaration, IASTQualifiedNameElement { - - public boolean isInline(); - public boolean isFriend(); - public boolean isStatic(); - - public boolean takesVarArgs(); - - public String getName(); - - public IASTAbstractDeclaration getReturnType(); - public Iterator getParameters(); - public IASTExceptionSpecification getExceptionSpec(); - /** - * @param b - */ - public void setHasFunctionBody(boolean b); - public boolean hasFunctionBody(); - - public void setHasFunctionTryBlock( boolean b ); - public boolean hasFunctionTryBlock(); - - public boolean previouslyDeclared(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFunctionReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFunctionReference.java deleted file mode 100644 index 715f1626dd8..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTFunctionReference.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTFunctionReference extends IASTReference -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInclusion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInclusion.java deleted file mode 100644 index 97ca4d6bcd0..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInclusion.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - - -/** - * @author jcamelon - * - */ -public interface IASTInclusion extends IASTOffsetableNamedElement, ISourceElementCallbackDelegate { - - public String getName(); - - public String getFullFileName(); - - public boolean isLocal(); - - public boolean isImplicit(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java deleted file mode 100644 index 608bd439c4e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTInitializerClause.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.Enum; -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ITokenDuple; - -/** - * @author jcamelon - */ -public interface IASTInitializerClause extends ISourceElementCallbackDelegate{ - - public class Kind extends Enum - { - public static final Kind ASSIGNMENT_EXPRESSION = new Kind( 1 ); - public static final Kind INITIALIZER_LIST = new Kind( 2 ); - public static final Kind EMPTY = new Kind( 3 ); - public static final Kind DESIGNATED_INITIALIZER_LIST = new Kind( 4 ); - public static final Kind DESIGNATED_ASSIGNMENT_EXPRESSION = new Kind( 5 ); - - /** - * @param enumValue - */ - protected Kind(int enumValue) { - super(enumValue); - } - } - - public Kind getKind(); - public Iterator getInitializers(); - public IASTExpression getAssigmentExpression(); - public Iterator getDesignators(); - - public void setOwnerVariableDeclaration( IASTVariable declaration ); - public IASTVariable getOwnerVariableDeclaration(); - /** - * @param finalDuple - * @return - */ - public IASTExpression findExpressionForDuple(ITokenDuple finalDuple) throws ASTNotImplementedException; - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTLinkageSpecification.java deleted file mode 100644 index 6394f03b4e7..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTLinkageSpecification.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - - -/** - * @author jcamelon - * - */ -public interface IASTLinkageSpecification extends IASTScope, IASTDeclaration, IASTOffsetableElement { - - public String getLinkageString(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMacro.java deleted file mode 100644 index e8128b87c3c..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMacro.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTMacro extends IASTOffsetableNamedElement, ISourceElementCallbackDelegate{ - - /** - * @return - */ - boolean isImplicit(); - - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMember.java deleted file mode 100644 index d3a59da5717..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMember.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTMember extends IASTDeclaration, IASTQualifiedNameElement -{ - public ASTAccessVisibility getVisiblity(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMethod.java deleted file mode 100644 index 1b12d916807..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMethod.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - - -/** - * @author jcamelon - * - */ -public interface IASTMethod extends IASTFunction, IASTMember { - - public boolean isVirtual(); - public boolean isExplicit(); - - public boolean isConstructor(); - public boolean isDestructor(); - - public boolean isConst(); - public boolean isVolatile(); - public boolean isPureVirtual(); - - public Iterator getConstructorChainInitializers(); - - public IASTClassSpecifier getOwnerClassSpecifier(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMethodReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMethodReference.java deleted file mode 100644 index 45871d66aa2..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTMethodReference.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTMethodReference extends IASTReference -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceAlias.java deleted file mode 100644 index e1da46a5178..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceAlias.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTNamespaceAlias - extends ISourceElementCallbackDelegate, IASTDeclaration, IASTOffsetableNamedElement -{ - public String getAlias(); - public IASTNamespaceDefinition getNamespace() throws ASTNotImplementedException; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceDefinition.java deleted file mode 100644 index a18629044cf..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceDefinition.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - - -/** - * @author jcamelon - * - */ -public interface IASTNamespaceDefinition extends IASTOffsetableNamedElement, IASTScope, IASTDeclaration, IASTQualifiedNameElement { - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceReference.java deleted file mode 100644 index a45da41758b..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNamespaceReference.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTNamespaceReference extends IASTReference -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java deleted file mode 100644 index e66cf72da35..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTNode.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.Enum; - -/** - * @author jcamelon - * - */ -public interface IASTNode { - - public static class LookupKind extends Enum { - - public static final LookupKind ALL = new LookupKind( 0 ); // includes everything - public static final LookupKind STRUCTURES = new LookupKind( 1 ); // includes STRUCTS + UNIONS + CLASSES - public static final LookupKind STRUCTS = new LookupKind( 2 ); - public static final LookupKind UNIONS = new LookupKind( 3 ); - public static final LookupKind CLASSES = new LookupKind( 4 ); - public static final LookupKind FUNCTIONS = new LookupKind( 5 ); - public static final LookupKind VARIABLES = new LookupKind( 6 ); - public static final LookupKind LOCAL_VARIABLES = new LookupKind( 7 ); - public static final LookupKind MEMBERS = new LookupKind( 8 ); - public static final LookupKind METHODS = new LookupKind( 9 ); - public static final LookupKind FIELDS = new LookupKind( 10 ); - public static final LookupKind CONSTRUCTORS = new LookupKind (11); - public static final LookupKind NAMESPACES = new LookupKind( 12 ); - public static final LookupKind ENUMERATIONS = new LookupKind( 13 ); - public static final LookupKind ENUMERATORS = new LookupKind( 14 ); - public static final LookupKind THIS = new LookupKind(15); - public static final LookupKind TYPEDEFS = new LookupKind(16); - public static final LookupKind TYPES = new LookupKind(17); // includes STRUCTURES + ENUMERATIONS + TYPEDEFS - - /** - * @param enumValue - */ - protected LookupKind(int enumValue) { - super(enumValue); - } - } - - public static class LookupError extends Error - { - } - - public static interface ILookupResult - { - public String getPrefix(); - public Iterator getNodes(); - public int getResultsSize(); - public int getIndexOfNextParameter(); - } - - /** - * @param prefix - * @param kind - * @param context - * @param functionParameters - * @return - * @throws LookupError - */ - public ILookupResult lookup( String prefix, LookupKind[] kind, IASTNode context, IASTExpression functionParameters) throws LookupError, ASTNotImplementedException; -} - diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableElement.java deleted file mode 100644 index 691287bfbce..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableElement.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTOffsetableElement { - - public void setStartingOffsetAndLineNumber( int offset, int lineNumber ); - public void setEndingOffsetAndLineNumber( int offset, int lineNumber ); - - public int getStartingOffset(); - public int getEndingOffset(); - - public int getStartingLine(); - public int getEndingLine(); - - public char [] getFilename(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java deleted file mode 100644 index 58d2ecdb8f4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTOffsetableNamedElement.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - - -/** - * @author jcamelon - * - */ -public interface IASTOffsetableNamedElement extends IASTOffsetableElement { - - public String getName(); - public char[] getNameCharArray(); - public int getNameOffset(); - public void setNameOffset( int o ); - public int getNameEndOffset(); - public void setNameEndOffsetAndLineNumber( int offset, int lineNumber ); - public int getNameLineNumber(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTParameterDeclaration.java deleted file mode 100644 index 4d05f17de14..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTParameterDeclaration.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTParameterDeclaration extends IASTAbstractDeclaration, IASTOffsetableNamedElement -{ - public IASTInitializerClause getDefaultValue(); - - /** - * @return - */ - public IASTFunction getOwnerFunctionDeclaration() throws ASTNotImplementedException; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTParameterReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTParameterReference.java deleted file mode 100644 index 11e88a5748a..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTParameterReference.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTParameterReference extends IASTReference -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerOperatorOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerOperatorOwner.java deleted file mode 100644 index 7e85b5f89e3..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTPointerOperatorOwner.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTPointerOperatorOwner -{ - public ASTPointerOperator getPointerOperator(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTQualifiedNameElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTQualifiedNameElement.java deleted file mode 100644 index 4387a0a261b..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTQualifiedNameElement.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTQualifiedNameElement -{ - public String[] getFullyQualifiedName(); - public char[][] getFullyQualifiedNameCharArrays(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTReference.java deleted file mode 100644 index 677b09196b7..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTReference.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTReference extends ISourceElementCallbackDelegate -{ - - public int getOffset(); - public String getName(); - public char[] getNameCharArray(); - public ISourceElementCallbackDelegate getReferencedElement(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScope.java deleted file mode 100644 index d86dc576053..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScope.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - -/** - * @author jcamelon - * - */ -public interface IASTScope extends IASTNode { - - public Iterator getDeclarations() throws ASTNotImplementedException; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedElement.java deleted file mode 100644 index ac93d3a6e2b..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedElement.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTScopedElement extends IASTNode -{ - IASTScope getOwnerScope(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedTypeSpecifier.java deleted file mode 100644 index 8b569e8f889..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTScopedTypeSpecifier.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTScopedTypeSpecifier extends IASTTypeSpecifier, IASTScopedElement, IASTQualifiedNameElement -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTSimpleTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTSimpleTypeSpecifier.java deleted file mode 100644 index 335b82aac5e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTSimpleTypeSpecifier.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.Enum; - -/** - * @author jcamelon - * - */ -public interface IASTSimpleTypeSpecifier extends IASTTypeSpecifier -{ - public static class Type extends Enum - { - public static final Type UNSPECIFIED = new Type( 1 ); - public static final Type CHAR = new Type( 1 ); - public static final Type WCHAR_T = new Type( 2 ); - public static final Type BOOL = new Type( 3 ); - public static final Type INT = new Type( 4 ); - public static final Type FLOAT = new Type( 5 ); - public static final Type DOUBLE = new Type( 6 ); - public static final Type VOID = new Type( 7 ); - public static final Type CLASS_OR_TYPENAME = new Type( 8 ); - public static final Type _BOOL = new Type( 10 ); - - protected static final int LAST_TYPE = 10; - /** - * @param enumValue - */ - protected Type(int enumValue) - { - super(enumValue); - } - - - } - - public Type getType(); - public String getTypename(); - public boolean isLong(); - public boolean isShort(); - public boolean isSigned(); - public boolean isUnsigned(); - public boolean isTypename(); - public boolean isComplex(); - public boolean isImaginary(); - - public IASTTypeSpecifier getTypeSpecifier() throws ASTNotImplementedException; - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplate.java deleted file mode 100644 index 233d193ecc1..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplate.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTTemplate -{ - public IASTDeclaration getOwnedDeclaration(); - public void setOwnedDeclaration( IASTDeclaration declaration ); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateDeclaration.java deleted file mode 100644 index 42b44781757..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateDeclaration.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - - -/** - * @author jcamelon - * - */ -public interface IASTTemplateDeclaration extends IASTDeclaration, IASTTemplate, IASTTemplateParameterList, IASTScope, IASTOffsetableElement { - - public boolean isExported(); - - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateInstantiation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateInstantiation.java deleted file mode 100644 index 23d8bf3dccc..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateInstantiation.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTTemplateInstantiation extends IASTTemplate, IASTDeclaration, IASTScope, IASTOffsetableElement { - - public IASTTemplateDeclaration getInstantiatedTemplate(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameter.java deleted file mode 100644 index 2e2d5854648..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameter.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import org.eclipse.cdt.core.parser.Enum; -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTTemplateParameter extends IASTTemplateParameterList, IASTTypeSpecifier, ISourceElementCallbackDelegate { - - public class ParamKind extends Enum - { - public static final ParamKind CLASS = new ParamKind( 1 ); - public static final ParamKind TYPENAME = new ParamKind( 2 ); - public static final ParamKind TEMPLATE_LIST = new ParamKind( 3 ); - public static final ParamKind PARAMETER = new ParamKind( 4 ); - - /** - * @param enumValue - */ - protected ParamKind(int enumValue) - { - super(enumValue); - } - - } - - public ParamKind getTemplateParameterKind(); - public String getIdentifier(); - public String getDefaultValueIdExpression(); - public IASTParameterDeclaration getParameterDeclaration(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameterList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameterList.java deleted file mode 100644 index 764c3462f61..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameterList.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - -/** - * @author jcamelon - * - */ -public interface IASTTemplateParameterList -{ - public Iterator getTemplateParameters(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameterReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameterReference.java deleted file mode 100644 index 1de87a22130..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateParameterReference.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Mar 8, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public interface IASTTemplateParameterReference extends IASTReference { -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateSpecialization.java deleted file mode 100644 index 285f9e9c636..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplateSpecialization.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTTemplateSpecialization extends IASTTemplateDeclaration { - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplatedDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplatedDeclaration.java deleted file mode 100644 index 087ab4efb7d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTemplatedDeclaration.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTTemplatedDeclaration { - - public IASTTemplate getOwnerTemplateDeclaration(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeId.java deleted file mode 100644 index e2c97cc81bd..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeId.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; - -/** - * @author jcamelon - * - */ -public interface IASTTypeId extends ISourceElementCallbackDelegate -{ - public IASTSimpleTypeSpecifier.Type getKind(); - public String getTypeOrClassName(); - public char[] getTypeOrClassNameCharArray(); - public Iterator getPointerOperators(); - public Iterator getArrayModifiers(); - - public boolean isConst(); - public boolean isVolatile(); - public boolean isLong(); - public boolean isShort(); - public boolean isSigned(); - public boolean isUnsigned(); - public boolean isTypename(); - - - public String getFullSignature(); - public char[] getFullSignatureCharArray(); - /** - * @param manager - */ - public void freeReferences(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeSpecifier.java deleted file mode 100644 index 695b0d3ed6e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeSpecifier.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTTypeSpecifier extends IASTNode { - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeSpecifierOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeSpecifierOwner.java deleted file mode 100644 index c9243074869..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypeSpecifierOwner.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTTypeSpecifierOwner -{ - public IASTTypeSpecifier getTypeSpecifier(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedefDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedefDeclaration.java deleted file mode 100644 index c4d60506a62..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedefDeclaration.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - - -/** - * @author jcamelon - * - */ -public interface IASTTypedefDeclaration extends IASTDeclaration, IASTOffsetableNamedElement, IASTQualifiedNameElement, IASTTypeSpecifier { - - public String getName(); - public IASTAbstractDeclaration getAbstractDeclarator(); - - public IASTTypeSpecifier getFinalTypeSpecifier() throws ASTNotImplementedException; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedefReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedefReference.java deleted file mode 100644 index ec8f7195e8d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTTypedefReference.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTTypedefReference extends IASTReference -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDeclaration.java deleted file mode 100644 index b70291444ff..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDeclaration.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -import java.util.Iterator; - -/** - * @author jcamelon - * - */ -public interface IASTUsingDeclaration extends IASTDeclaration, IASTOffsetableNamedElement { - - public boolean isTypename(); - public String usingTypeName(); - public char[] usingTypeNameCharArray(); - public Iterator getUsingTypes() throws ASTNotImplementedException; - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java deleted file mode 100644 index aef0c0ff62d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTUsingDirective.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTUsingDirective extends IASTDeclaration, IASTOffsetableNamedElement { - - public String getNamespaceName(); - public IASTNamespaceDefinition getNamespaceDefinition() throws ASTNotImplementedException; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTVariable.java deleted file mode 100644 index 70027725a30..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTVariable.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - - -/** - * @author jcamelon - * - */ -public interface IASTVariable extends IASTDeclaration, IASTOffsetableNamedElement, IASTQualifiedNameElement { - - public boolean isAuto(); - public boolean isRegister(); - public boolean isStatic(); - public boolean isExtern(); - public boolean isMutable(); - - public IASTAbstractDeclaration getAbstractDeclaration(); - public String getName(); - public IASTInitializerClause getInitializerClause(); - - public boolean isBitfield(); - public IASTExpression getBitfieldExpression(); - public IASTExpression getConstructorExpression(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTVariableReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTVariableReference.java deleted file mode 100644 index 6c3edbb6aa0..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTVariableReference.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.ast; - -/** - * @author jcamelon - * - */ -public interface IASTVariableReference extends IASTReference -{ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCDesignator.java deleted file mode 100644 index ee509eaae83..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCDesignator.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.core.parser.ast.gcc; - -import org.eclipse.cdt.core.parser.ast.IASTDesignator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; - -/** - * @author jcamelon - * - */ -public interface IASTGCCDesignator extends IASTDesignator { - - public static class DesignatorKind extends IASTDesignator.DesignatorKind - { - public static final DesignatorKind SUBSCRIPT_RANGE = new DesignatorKind(LAST_KIND + 1 ); - - /** - * @param enumValue - */ - protected DesignatorKind(int enumValue) { - super(enumValue); - } - } - - public static final String SECOND_EXRESSION = "SUBSCRIPT2 EXPRESSION"; //$NON-NLS-1$ - public IASTExpression arraySubscriptExpression2(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCExpression.java deleted file mode 100644 index 2d0b49fd1d8..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCExpression.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.core.parser.ast.gcc; - -import org.eclipse.cdt.core.parser.ast.IASTExpression; - -/** - * @author jcamelon - * - */ -public interface IASTGCCExpression extends IASTExpression { - - public static class Kind extends IASTExpression.Kind - { - public static final Kind UNARY_ALIGNOF_UNARYEXPRESSION = new Kind( LAST_KIND + 1 ); - public static final Kind UNARY_ALIGNOF_TYPEID = new Kind( LAST_KIND + 2 ); - public static final Kind UNARY_TYPEOF_UNARYEXPRESSION = new Kind( LAST_KIND + 3 ); - public static final Kind UNARY_TYPEOF_TYPEID = new Kind( LAST_KIND + 4 ); - public static final Kind RELATIONAL_MAX = new Kind( LAST_KIND + 5 ); - public static final Kind RELATIONAL_MIN = new Kind( LAST_KIND + 6 ); - public static final Kind STATEMENT_EXPRESSION = new Kind( LAST_KIND + 7 ); - - protected Kind( int kind ) - { - super( kind ); - } - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCSimpleTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCSimpleTypeSpecifier.java deleted file mode 100644 index 4ac7c5c8c53..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/gcc/IASTGCCSimpleTypeSpecifier.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.core.parser.ast.gcc; - -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; - -/** - * @author jcamelon - * - */ -public interface IASTGCCSimpleTypeSpecifier extends IASTSimpleTypeSpecifier { - - public static class Type extends IASTSimpleTypeSpecifier.Type - { - public static final Type TYPEOF = new Type( LAST_TYPE + 1 ); - - /** - * @param enumValue - */ - protected Type(int enumValue) { - super(enumValue); - } - - } - - public static final String TYPEOF_EXRESSION = "TYPEOF EXPRESSION"; //$NON-NLS-1$ - public IASTExpression getTypeOfExpression(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/ExtensionDialect.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/ExtensionDialect.java deleted file mode 100644 index fff9a4eeb1d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/ExtensionDialect.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.extension; - -import org.eclipse.cdt.core.parser.Enum; - -/** - * @author jcamelon - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class ExtensionDialect extends Enum { - - public static final ExtensionDialect GCC = new ExtensionDialect( 1 ); - /** - * @param enumValue - */ - public ExtensionDialect(int enumValue) { - super(enumValue); - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IASTFactoryExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IASTFactoryExtension.java deleted file mode 100644 index 495edbca085..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IASTFactoryExtension.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.core.parser.extension; - -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTDesignator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTFactory; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; -import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; - -/** - * @author jcamelon - * - */ -public interface IASTFactoryExtension { - - public boolean overrideCreateExpressionMethod(); - public IASTExpression createExpression( - IASTScope scope, - IASTExpression.Kind kind, - IASTExpression lhs, - IASTExpression rhs, - IASTExpression thirdExpression, - IASTTypeId typeId, - ITokenDuple idExpression, - char[] literal, - IASTNewExpressionDescriptor newDescriptor, - List references); - - public boolean canHandleExpressionKind( IASTExpression.Kind kind ); - /** - * @param kind - * @param lhs - * @param rhs - * @param typeId - * @return TODO - */ - public ITypeInfo getExpressionResultType(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTTypeId typeId); - - public boolean overrideCreateSimpleTypeSpecifierMethod(Type type); - - public IASTSimpleTypeSpecifier createSimpleTypeSpecifier( - ParserSymbolTable pst, - IASTScope scope, - IASTSimpleTypeSpecifier.Type kind, - ITokenDuple typeName, - boolean isShort, - boolean isLong, - boolean isSigned, - boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map extensionParms ); - - public boolean overrideCreateDesignatorMethod( IASTDesignator.DesignatorKind kind ); - public IASTDesignator createDesignator( IASTDesignator.DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier, Map extensionParms ); - - public void initialize( IASTFactory factory, IASTCompilationUnit compilationUnit ); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IParserExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IParserExtension.java deleted file mode 100644 index 9d8204fd7c6..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IParserExtension.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.extension; - -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.KeywordSetKey; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.IASTDesignator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; -import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; -import org.eclipse.cdt.internal.core.parser.DeclarationWrapper; -import org.eclipse.cdt.internal.core.parser.IParserData; -import org.eclipse.cdt.internal.core.parser.Parser; - - -/** - * @author jcamelon - */ -public interface IParserExtension { - - public boolean isValidCVModifier( ParserLanguage language, int tokenType ); - public ASTPointerOperator getPointerOperator( ParserLanguage language, int tokenType ); - - public boolean isValidUnaryExpressionStart( int tokenType ); - public IASTExpression parseUnaryExpression( IASTScope scope, IParserData data, CompletionKind kind, KeywordSetKey key ); - - public boolean isValidRelationalExpressionStart( ParserLanguage language, int tokenType ); - public IASTExpression parseRelationalExpression( IASTScope scope, IParserData data, CompletionKind kind, KeywordSetKey key, IASTExpression lhsExpression ); - /** - * @param i - * @return - */ - public boolean canHandleDeclSpecifierSequence(int tokenType ); - public interface IDeclSpecifierExtensionResult - { - public IToken getFirstToken(); - public IToken getLastToken(); - public Parser.Flags getFlags(); - } - - /** - * @param parser - * @param flags - * @param sdw - * @param key TODO - * @return TODO - */ - public IDeclSpecifierExtensionResult parseDeclSpecifierSequence(IParserData parser, Parser.Flags flags, DeclarationWrapper sdw, CompletionKind kind, KeywordSetKey key ); - /** - * @param i - * @return - */ - public boolean canHandleCDesignatorInitializer(int tokenType); - /** - * @param parserData - * @param scope TODO - * @return - */ - public IASTDesignator parseDesignator(IParserData parserData, IASTScope scope); - /** - * @return - */ - public boolean supportsStatementsInExpressions(); - /** - * @return - */ - public Kind getExpressionKindForStatement(); - - public boolean supportsExtendedTemplateInstantiationSyntax(); - - public boolean isValidModifierForInstantiation( IToken la ); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IParserExtensionFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IParserExtensionFactory.java deleted file mode 100644 index 18fbb30c715..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/extension/IParserExtensionFactory.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser.extension; - -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserMode; - - -/** - * @author jcamelon - */ -public interface IParserExtensionFactory { - - public IParserExtension createParserExtension() throws ParserFactoryError; - public IASTFactoryExtension createASTExtension(ParserMode mode); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayPool.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayPool.java deleted file mode 100644 index 4dd6e5296ab..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayPool.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on May 28, 2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.cdt.core.parser.util; - -/** - * @author dschaefe - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ -public class CharArrayPool extends CharTable{ - - public CharArrayPool(int tableSize) { - super(tableSize); - } - - // Removes the current entry - private final void remove() { - int hash = hash(keyTable[currEntry], 0, keyTable[currEntry].length); - int i = hashTable[hash] - 1; - if (i == currEntry) - // make my next the hash entry - hashTable[hash] = nextTable[currEntry]; - else { - // remove me from the next list - int last; - do { - last = i; - i = nextTable[i] - 1; - } while (i != currEntry); - - nextTable[last] = nextTable[currEntry]; - } - - keyTable[currEntry] = null; - nextTable[currEntry] = 0; - } - - private final void addHashed(char[] str, int hash) { - // First remove the existing string if there is one - if (++currEntry == keyTable.length) - currEntry = 0; - - if (keyTable[currEntry] != null) - remove(); - - keyTable[currEntry] = str; - - // Now add it to the hash table, insert into next entries as necessary - if (hashTable[hash] != 0) - nextTable[currEntry] = hashTable[hash]; - hashTable[hash] = currEntry + 1; - } - - public final char[] add(char[] source, int start, int length) { - // do we have it already? - int hash = hash(source, start, length); - int result = lookup(source, start, length, hash); - - if( result >= 0) - return keyTable[result]; - - char [] res = new char[length]; - System.arraycopy(source, 0, res, 0, length); - addHashed(res, hash); - - return res; - } - - public final char[] add(char[] source) { - return add(source, 0, source.length); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java index 1ca22d324fe..5aae6261acd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java @@ -84,7 +84,8 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { private static final char[] __BUILTIN_CLZLL = "__builtin_clzll".toCharArray(); //$NON-NLS-1$ private static final char[] __BUILTIN_CTZLL = "__builtin_ctzll".toCharArray(); //$NON-NLS-1$ private static final char[] __BUILTIN_POPCOUNTLL = "__builtin_popcountll".toCharArray(); //$NON-NLS-1$ - private static final char[] __BUILTIN_PARITYLL = "__builtin_parityll".toCharArray(); //$NON-NLS-1$ + private static final char[] __BUILTIN_PARITYLL = "__builtin_parityll".toCharArray(); //$NON-NLS-1$ + private static final char[] __BUILTIN_CHOOSE_EXPR = "__builtin_choose_expr".toCharArray(); //$NON-NLS-1$ private static final char[] __BUILTIN_TYPES_COMPATIBLE_P = "__builtin_types_compatible_p".toCharArray(); //$NON-NLS-1$ private static final char[] __BUILTIN_POWI = "__builtin_powi".toCharArray(); //$NON-NLS-1$ private static final char[] __BUILTIN_POWIF = "__builtin_powif".toCharArray(); //$NON-NLS-1$ @@ -306,6 +307,7 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { __builtin_unsigned_long(); __builtin_unsigned_long_long(); __builtin_types_compatible_p(); + __builtin_choose_expr(); __builtin_powi(); __builtin_exit(); __builtin_conj(); @@ -810,7 +812,26 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { } bindings = (IBinding[])ArrayUtil.append(IBinding.class, bindings, temp); } - + + private void __builtin_choose_expr() { + // type __builtin_choose_expr (const_exp, exp1, exp2) + IBinding temp = null; + if (lang == ParserLanguage.C) { + IFunctionType functionType = null; + IType[] parms = new IType[3]; + parms[0] = c_unspecified; + parms[1] = c_unspecified; + parms[2] = c_unspecified; + functionType = new CFunctionType(c_unspecified, parms); + IParameter[] theParms = new IParameter[3]; + theParms[0] = new CBuiltinParameter(parms[0]); + theParms[1] = theParms[0]; + theParms[2] = theParms[0]; + temp = new CImplicitFunction(__BUILTIN_CHOOSE_EXPR, scope, functionType, theParms, true); + bindings = (IBinding[])ArrayUtil.append(IBinding.class, bindings, temp); + } + } + private void __builtin_types_compatible_p() { // int __builtin_types_compatible_p( type1, type2 ) implemented via ( ... ) IBinding temp = null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index 0757ca67e6c..0cb2863975f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -39,11 +39,11 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.ASTComment; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -321,7 +321,7 @@ public class CASTTranslationUnit extends CASTNode implements * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) */ public int visit(IASTEnumerator enumerator) { - return processNode((IASTNode) enumerator); + return processNode(enumerator); } /* diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index a94babef588..cb2ef0e6d33 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -618,7 +618,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } } translationUnit.setComments((IASTComment[]) ArrayUtil.trim(IASTComment.class, comments)); - // compilationUnit.exitScope( requestor ); } /** @@ -826,7 +825,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return unaryOperatorCastExpression(IASTUnaryExpression.op_minus); case IToken.tNOT: return unaryOperatorCastExpression(IASTUnaryExpression.op_not); - case IToken.tCOMPL: + case IToken.tBITCOMPLEMENT: return unaryOperatorCastExpression(IASTUnaryExpression.op_tilde); case IToken.tINCR: return unaryOperatorCastExpression(IASTUnaryExpression.op_prefixIncr); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index f7f1dc11c0f..f7900d59cc6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -43,6 +43,7 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; @@ -57,7 +58,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.parser.ASTComment; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; @@ -345,7 +345,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements } public int visit(IASTEnumerator enumerator) { - return processNode((IASTNode)enumerator); + return processNode(enumerator); } public int visit(IASTExpression expression) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/BacktrackException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/BacktrackException.java deleted file mode 100644 index 4bc46492c3b..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/BacktrackException.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; - -import org.eclipse.cdt.core.parser.IProblem; - -/** - * @author jcamelon - * - */ -public class BacktrackException extends Exception -{ - private static final char [] EMPTY_CHARARRAY = "".toCharArray(); //$NON-NLS-1$ - private IProblem problem; - private int startOffset; - private int endOffset; - private int lineNumber; - private char[] filename; - - /** - * @param p - */ - public void initialize(IProblem p) { - reset(); - problem = p; - } - - /** - * - */ - private void reset() { - problem = null; - startOffset = 0; - endOffset = 0; - filename = EMPTY_CHARARRAY; - } - /** - * @return Returns the problem. - */ - public final IProblem getProblem() { - return problem; - } - - /** - * @param startingOffset - * @param endingOffset - * @param f TODO - */ - public void initialize(int startingOffset, int endingOffset, int line, char[] f) { - reset(); - startOffset = startingOffset; - endOffset = endingOffset; - lineNumber = line; - this.filename = f; - } - /** - * @return Returns the offset. - */ - public final int getStartingOffset() { - return startOffset; - } - /** - * @return Returns the endOffset. - */ - public final int getEndOffset() { - return endOffset; - } - - /** - * @return - */ - public int getLineNumber() { - return lineNumber; - } - - /** - * @return - */ - public char[] getFilename() { - return filename; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java deleted file mode 100644 index a06cc1023d0..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java +++ /dev/null @@ -1,794 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.ASTSemanticException; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTFactory; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTemplate; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; -import org.eclipse.cdt.internal.core.parser.token.TokenFactory; -/** - * @author jcamelon - * - */ -public class DeclarationWrapper implements IDeclaratorOwner -{ - private int flag = 0; - protected void setBit(boolean b, int mask){ - if( b ){ - flag = flag | mask; - } else { - flag = flag & ~mask; - } - } - - protected boolean checkBit(int mask){ - return (flag & mask) != 0; - } - - private static final int DEFAULT_LIST_SIZE = 4; - - protected static final int IS_IMAGINARY = 0x00000010; - protected static final int IS_COMPLEX = 0x00000020; - protected static final int IS_RESTRICT = 0x00000040; - protected static final int IS_SIGNED = 0x00000080; - protected static final int IS_SHORT = 0x00000100; - protected static final int IS_UNSIGNED = 0x00000200; - protected static final int IS_LONG = 0x00000400; - protected static final int IS_TYPENAMED = 0x00000800; - protected static final int IS_VOLATILE = 0x00001000; - protected static final int IS_VIRTUAL = 0x00002000; - protected static final int IS_TYPEDEF = 0x00004000; - protected static final int IS_STATIC = 0x00008000; - protected static final int IS_REGISTER = 0x00010000; - protected static final int IS_EXTERN = 0x00020000; - protected static final int IS_EXPLICIT = 0x00040000; - protected static final int IS_CONST = 0x00080000; - protected static final int IS_AUTO = 0x00100000; - protected static final int IS_GLOBAL = 0x00200000; - protected static final int IS_MUTABLE = 0x00400000; - protected static final int IS_FRIEND = 0x00800000; - protected static final int IS_INLINE = 0x01000000; - - - private int startingOffset = 0; - private int startingLine; - private int endOffset; - - private ITokenDuple name; - private Type simpleType = IASTSimpleTypeSpecifier.Type.UNSPECIFIED; - private final IASTTemplate templateDeclaration; - private final IASTScope scope; - private IASTTypeSpecifier typeSpecifier; - - private List declarators = Collections.EMPTY_LIST; - /** - * @param b - */ - public void setAuto(boolean b) - { - setBit( b, IS_AUTO ); - } - /** - * @return - */ - public IASTScope getScope() - { - return scope; - } - - /** - * @param scope - * @param filename TODO - */ - public DeclarationWrapper( - IASTScope scope, - int startingOffset, - int startingLine, IASTTemplate templateDeclaration, char[] filename) - { - this.scope = scope; - this.startingOffset = startingOffset; - this.startingLine = startingLine; - this.templateDeclaration = templateDeclaration; - this.fn = filename; - } - /** - * @param b - */ - public void setTypenamed(boolean b) - { - setBit( b, IS_TYPENAMED ); - } - /** - * @param b - */ - public void setMutable(boolean b) - { - setBit( b, IS_MUTABLE); - } - /** - * @param b - */ - public void setFriend(boolean b) - { - setBit( b, IS_FRIEND ); - } - /** - * @param b - */ - public void setInline(boolean b) - { - setBit( b, IS_INLINE ); - } - /** - * @param b - */ - public void setRegister(boolean b) - { - setBit( b, IS_REGISTER ); - } - /** - * @param b - */ - public void setStatic(boolean b) - { - setBit( b, IS_STATIC ); - } - /** - * @param b - */ - public void setTypedef(boolean b) - { - setBit( b, IS_TYPEDEF ); - } - /** - * @param b - */ - public void setVirtual(boolean b) - { - setBit( b, IS_VIRTUAL ); - } - /** - * @param b - */ - public void setVolatile(boolean b) - { - setBit( b, IS_VOLATILE ); - } - /** - * @param b - */ - public void setExtern(boolean b) - { - setBit( b, IS_EXTERN ); - } - /** - * @param b - */ - public void setExplicit(boolean b) - { - setBit( b, IS_EXPLICIT ); - } - /** - * @param b - */ - public void setConst(boolean b) - { - setBit( b, IS_CONST ); - } - /** - * @return - */ - public boolean isAuto() - { - return checkBit( IS_AUTO ); - } - /** - * @return - */ - public boolean isConst() - { - return checkBit( IS_CONST ); - } - /** - * @return - */ - public boolean isExplicit() - { - return checkBit( IS_EXPLICIT ); - } - /** - * @return - */ - public boolean isExtern() - { - return checkBit( IS_EXTERN ); - } - /** - * @return - */ - public boolean isFriend() - { - return checkBit( IS_FRIEND ); - } - /** - * @return - */ - public boolean isInline() - { - return checkBit( IS_INLINE ); - } - /** - * @return - */ - public boolean isMutable() - { - return checkBit( IS_MUTABLE ); - } - /** - * @return - */ - public boolean isRegister() - { - return checkBit( IS_REGISTER ); - } - /** - * @return - */ - public int getStartingOffset() - { - return startingOffset; - } - - public int getStartingLine() - { - return startingLine; - } - /** - * @return - */ - public boolean isStatic() - { - return checkBit( IS_STATIC ); - } - /** - * @return - */ - public boolean isTypedef() - { - return checkBit( IS_TYPEDEF ); - } - /** - * @return - */ - public boolean isTypeNamed() - { - return checkBit( IS_TYPENAMED ); - } - /** - * @return - */ - public boolean isVirtual() - { - return checkBit( IS_VIRTUAL ); - } - /** - * @return - */ - public boolean isVolatile() - { - return checkBit( IS_VOLATILE ); - } - public void addDeclarator(Declarator d) - { - if( declarators == Collections.EMPTY_LIST ) - declarators = new ArrayList(DEFAULT_LIST_SIZE); - declarators.add(d); - } - public Iterator getDeclarators() - { - return declarators.iterator(); - } - private List getDeclaratorsList(){ - return declarators; - } - /** - * @return - */ - public IASTTypeSpecifier getTypeSpecifier() - { - return typeSpecifier; - } - /** - * @param specifier - */ - public void setTypeSpecifier(IASTTypeSpecifier specifier) - { - typeSpecifier = specifier; - } - private IASTFactory astFactory = null; - private int endLine; - - private final char[] fn; - /** - * @param requestor - */ - public List createASTNodes(IASTFactory astFactoryToWorkWith) throws ASTSemanticException, BacktrackException - { - this.astFactory = astFactoryToWorkWith; - if( declarators.isEmpty() ) return Collections.EMPTY_LIST; - List l = new ArrayList(declarators.size()); - for( int i = 0; i < declarators.size(); ++i ) - l.add(createASTNode((Declarator)declarators.get(i))); - return l; - } - /** - * @param declarator - */ - private IASTDeclaration createASTNode(Declarator declarator) throws ASTSemanticException, BacktrackException - { - boolean isWithinClass = false;//(getScope() instanceof IASTClassSpecifier); //TODO fix this for COMPLETE_PARSE - if( getScope() instanceof IASTClassSpecifier ){ - isWithinClass = true; - } else if ( getScope() instanceof IASTTemplateDeclaration ){ - isWithinClass = (((IASTTemplateDeclaration)getScope()).getOwnerScope() instanceof IASTClassSpecifier); - } - - boolean isFunction = declarator.isFunction(); - boolean hasInnerDeclarator = ( declarator.getOwnedDeclarator() != null ); - - if( hasInnerDeclarator ) - return createIndirectDeclaration( declarator ); - - if (isTypedef()) - return createTypedef(declarator, false); - - if (isWithinClass ) - { - if( isFunction) - return createMethodASTNode(declarator, false); - else - if( declarator.hasFunctionBody() ) - throw new ASTSemanticException( (IProblem)null ); - return createFieldASTNode(declarator, false ); - } - if (isFunction) - return createFunctionASTNode(declarator, false); - else - if( declarator.hasFunctionBody() ) - throw new ASTSemanticException( (IProblem)null ); - return createVariableASTNode(declarator, false); - - } - /** - * @param declarator - * @return - */ - private IASTDeclaration createIndirectDeclaration(Declarator declarator) throws BacktrackException, ASTSemanticException - { - if( declarator.getOwnedDeclarator().getOwnedDeclarator() == null ) - { - - Declarator d = declarator.getOwnedDeclarator(); - List ptrOps = d.getPointerOperators(); - boolean isWithinClass = scope instanceof IASTClassSpecifier; - boolean isFunction = (declarator.getParameters().size() != 0); - if( ptrOps.size() == 0 ) - { - - if (isTypedef()) - return createTypedef(declarator, true); - - if (isWithinClass ) - { - if( isFunction) - return createMethodASTNode(declarator, true); - return createFieldASTNode(declarator, true ); - } - if (isFunction) - return createFunctionASTNode(declarator, true); - return createVariableASTNode(declarator, true); - } - - List convertedParms = createParameterList( declarator.getParameters() ); - IASTAbstractDeclaration abs = null; - abs = - astFactory.createAbstractDeclaration( - isConst(), - isVolatile(), - getTypeSpecifier(), - declarator.getPointerOperators(), - declarator.getArrayModifiers(), - convertedParms, - (ASTPointerOperator)ptrOps.get( 0 )); - - ITokenDuple nameDuple = ( d.getPointerOperatorNameDuple() != null ) ? TokenFactory.createTokenDuple( d.getPointerOperatorNameDuple(), d.getNameDuple() ) : d.getNameDuple(); - - if( isTypedef() ) - return astFactory.createTypedef(scope, nameDuple.toCharArray(), abs, - getStartingOffset(), getStartingLine(), d - .getNameStartOffset(), d.getNameEndOffset(), d - .getNameLine(), fn); - - if( isWithinClass ) - return astFactory.createField( scope, nameDuple, isAuto(), d.getInitializerClause(), d.getBitFieldExpression(), abs, isMutable(), isExtern(), isRegister(), isStatic(), getStartingOffset(), getStartingLine(), d.getNameStartOffset(), d.getNameEndOffset(), d.getNameLine(), d.getConstructorExpression(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode(), fn ); - - return astFactory.createVariable( scope, nameDuple, isAuto(), d.getInitializerClause(), d.getBitFieldExpression(), abs, isMutable(), isExtern(), isRegister(), isStatic(), getStartingOffset(), getStartingLine(), d.getNameStartOffset(), d.getNameEndOffset(), d.getNameLine(), d.getConstructorExpression(), fn ); - - } - throw new BacktrackException(); - - } - - /** - * @param declarator - * @return - */ - private IASTTypedefDeclaration createTypedef(Declarator declarator, boolean nested ) throws ASTSemanticException - { - return astFactory.createTypedef(scope, nested ? declarator - .getOwnedDeclarator().getName() : declarator.getName(), - astFactory.createAbstractDeclaration(isConst(), isVolatile(), - getTypeSpecifier(), declarator.getPointerOperators(), - declarator.getArrayModifiers(), null, null), - startingOffset, getStartingLine(), declarator - .getNameStartOffset(), declarator.getNameEndOffset(), - declarator.getNameLine(), fn); - } - /** - * @param declarator - * @return - */ - private IASTMethod createMethodASTNode(Declarator declarator, boolean nested) throws ASTSemanticException - { - IASTScope classifierScope = getScope(); - if( classifierScope instanceof IASTTemplateDeclaration ){ - classifierScope = ((IASTTemplateDeclaration)classifierScope).getOwnerScope(); - } - return astFactory.createMethod(scope, nested ? declarator - .getOwnedDeclarator().getNameDuple() : declarator - .getNameDuple(), - createParameterList(declarator.getParameters()), astFactory - .createAbstractDeclaration(isConst(), isVolatile(), - getTypeSpecifier(), declarator - .getPointerOperators(), declarator - .getArrayModifiers(), null, null), - declarator.getExceptionSpecification(), isInline(), isFriend(), - isStatic(), startingOffset, getStartingLine(), declarator - .getNameStartOffset(), declarator.getNameEndOffset(), - declarator.getNameLine(), templateDeclaration, declarator - .isConst(), declarator.isVolatile(), isVirtual(), isExplicit(), - declarator.isPureVirtual(), ((IASTClassSpecifier) classifierScope) - .getCurrentVisibilityMode(), declarator - .getConstructorMemberInitializers(), declarator - .hasFunctionBody(), declarator.hasFunctionTryBlock(), - declarator.isVarArgs()); - } - /** - * @param declarator - * @return - */ - private IASTFunction createFunctionASTNode(Declarator declarator, boolean nested) throws ASTSemanticException - { - return astFactory.createFunction(scope, nested ? declarator - .getOwnedDeclarator().getNameDuple() : declarator - .getNameDuple(), - createParameterList(declarator.getParameters()), astFactory - .createAbstractDeclaration(isConst(), isVolatile(), - getTypeSpecifier(), declarator - .getPointerOperators(), declarator - .getArrayModifiers(), null, null), - declarator.getExceptionSpecification(), isInline(), isFriend(), - isStatic(), startingOffset, getStartingLine(), declarator - .getNameStartOffset(), declarator.getNameEndOffset(), - declarator.getNameLine(), templateDeclaration, declarator - .isConst(), declarator.isVolatile(), isVirtual(), isExplicit(), - declarator.isPureVirtual(), declarator - .getConstructorMemberInitializers(), declarator - .hasFunctionBody(), declarator.hasFunctionTryBlock(), - declarator.isVarArgs()); - } - /** - * @param declarator - * @return - */ - private IASTField createFieldASTNode(Declarator declarator, boolean nested) throws ASTSemanticException - { - return astFactory.createField( - scope, - nested ? declarator.getOwnedDeclarator().getNameDuple() : declarator.getNameDuple(), - isAuto(), - declarator.getInitializerClause(), - declarator.getBitFieldExpression(), - astFactory.createAbstractDeclaration( - isConst(), - isVolatile(), - getTypeSpecifier(), - declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), - isMutable(), - isExtern(), - isRegister(), - isStatic(), - startingOffset, - getStartingLine(), - declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), declarator.getConstructorExpression(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode(), fn); - } - - private List createParameterList(List currentParameters) throws ASTSemanticException - { - if( currentParameters.isEmpty() ) return Collections.EMPTY_LIST; - List result = new ArrayList(currentParameters.size()); - for( int i = 0; i < currentParameters.size(); ++i ) - { - DeclarationWrapper wrapper = (DeclarationWrapper)currentParameters.get(i); - List decls = wrapper.getDeclaratorsList(); - for( int j = 0; j < decls.size(); j++ ) - { - Declarator declarator = (Declarator)decls.get(j); - - result.add( - astFactory.createParameterDeclaration( - wrapper.isConst(), - wrapper.isVolatile(), - wrapper.getTypeSpecifier(), - declarator.getPointerOperators(), - declarator.getArrayModifiers(), - null, null, declarator.getName(), declarator.getInitializerClause(), wrapper.getStartingOffset(), getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), wrapper.getEndOffset(), getEndLine(), wrapper.fn )); - } - } - return result; - } - /** - * @param declarator - * @return - */ - private IASTVariable createVariableASTNode(Declarator declarator, boolean nested ) throws ASTSemanticException - { - return astFactory.createVariable( - scope, - nested ? declarator.getOwnedDeclarator().getNameDuple() : declarator.getNameDuple(), - isAuto(), - declarator.getInitializerClause(), - declarator.getBitFieldExpression(), - astFactory.createAbstractDeclaration( - isConst(), - isVolatile(), - getTypeSpecifier(), - declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), - isMutable(), - isExtern(), - isRegister(), - isStatic(), - getStartingOffset(), - getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), declarator.getConstructorExpression(), fn); - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IDeclaratorOwner#getDeclarationWrapper() - */ - public DeclarationWrapper getDeclarationWrapper() - { - return this; - } - /** - * @return - */ - public boolean isUnsigned() - { - return checkBit( IS_UNSIGNED ); - } - /** - * @return - */ - public boolean isSigned() - { - return checkBit( IS_SIGNED ); - } - /** - * @return - */ - public boolean isShort() - { - return checkBit( IS_SHORT ); - } - /** - * @return - */ - public boolean isLong() - { - return checkBit( IS_LONG ); - } - /** - * @param b - */ - public void setLong(boolean b) - { - setBit( b, IS_LONG ); - } - /** - * @param b - */ - public void setShort(boolean b) - { - setBit( b, IS_SHORT ); - } - /** - * @param b - */ - public void setSigned(boolean b) - { - setBit( b, IS_SIGNED ); - } - /** - * @param b - */ - public void setUnsigned(boolean b) - { - setBit( b, IS_UNSIGNED ); - } - /** - * @return - */ - public Type getSimpleType() - { - return simpleType; - } - /** - * @param type - */ - public void setSimpleType(Type type) - { - simpleType = type; - } - /** - * @param duple - */ - public void setTypeName(ITokenDuple duple) - { - name = duple; - } - /** - * @return - */ - public final ITokenDuple getName() - { - return name; - } - - /** - * @return - */ - public final IASTTemplate getOwnerTemplate() - { - return templateDeclaration; - } - /** - * @param i - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endOffset = offset; - endLine = lineNumber; - } - /** - * @return - */ - public int getEndOffset() - { - return endOffset; - } - - public int getEndLine() - { - return endLine; - } - /** - * @param b - */ - public void setRestrict(boolean b) - { - setBit( b, IS_RESTRICT ); - } - - - /** - * @return - */ - public boolean isRestrict() - { - return checkBit( IS_RESTRICT ); - } - /** - * @param b - */ - public void setImaginary(boolean b) - { - setBit( b, IS_IMAGINARY ); - } - - /** - * @return - */ - public boolean isComplex() - { - return checkBit( IS_COMPLEX ); - } - - /** - * @return - */ - public boolean isImaginary() - { - return checkBit( IS_IMAGINARY ); - } - - /** - * @param b - */ - public void setComplex(boolean b) - { - setBit( b, IS_COMPLEX ); - } - /** - * @param b - */ - public void setGloballyQualified(boolean b) { - setBit( b, IS_GLOBAL ); - } - - public boolean isGloballyQualified(){ - return checkBit( IS_GLOBAL ); - } - - private Map extensionParameters = Collections.EMPTY_MAP; - /** - * @param key - * @param typeOfExpression - */ - public void setExtensionParameter(String key, Object value) { - if( extensionParameters == Collections.EMPTY_MAP ) - extensionParameters = new Hashtable( 4 ); - extensionParameters.put( key, value ); - } - - public Map getExtensionParameters() - { - return extensionParameters; - } - /** - * @return - */ - public boolean consumedRawType() { - return( getSimpleType() != IASTSimpleTypeSpecifier.Type.UNSPECIFIED ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java deleted file mode 100644 index 04f7aeb990d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declarator.java +++ /dev/null @@ -1,439 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.core.parser.ast.IASTConstructorMemberInitializer; -import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; - -/** - * @author jcamelon - * - */ -public class Declarator implements IParameterCollection, IDeclaratorOwner, IDeclarator -{ - private static final int DEFAULT_ARRAYLIST_SIZE = 4; - private static final char[] EMPTY_STRING = new char[0]; //$NON-NLS-1$ - - private final IDeclaratorOwner owner; - private ITokenDuple pointerOperatorNameDuple = null; - private ITokenDuple namedDuple = null; - private IASTExpression constructorExpression = null; - private Declarator ownedDeclarator = null; - private IASTInitializerClause initializerClause = null; - private IASTExceptionSpecification exceptionSpecification = null; - private IASTExpression bitFieldExpression = null; - - private int flag = 0; - protected void setBit(boolean b, int mask){ - if( b ){ - flag = flag | mask; - } else { - flag = flag & ~mask; - } - } - - protected boolean checkBit(int mask){ - return (flag & mask) != 0; - } - - protected static final int IS_FUNCTION = 0x000020; - protected static final int HAS_TRY_BLOCK = 0x000040; - protected static final int HAS_FUNCTION_BODY = 0x000080; - protected static final int IS_PURE_VIRTUAL = 0x000100; - protected static final int IS_VAR_ARGS = 0x000200; - protected static final int IS_VOLATILE = 0x000400; - protected static final int IS_CONST = 0x000800; - - private List ptrOps = Collections.EMPTY_LIST; - private List parameters = Collections.EMPTY_LIST; - private List arrayModifiers = Collections.EMPTY_LIST; - private List constructorMemberInitializers = Collections.EMPTY_LIST; - - - - public Declarator( IDeclaratorOwner owner ) - { - this.owner = owner; - } - - /** - * @return - */ - public char[] getName() - { - if( namedDuple == null ) return EMPTY_STRING; - return namedDuple.toCharArray(); - } - - /** - * @return - */ - public int getNameEndOffset() - { - if( namedDuple == null ) return -1; - return namedDuple.getEndOffset(); - } - - public int getNameLine() - { - if( namedDuple == null ) return -1; - return namedDuple.getLineNumber(); - } - - /** - * @return - */ - public int getNameStartOffset() - { - if( namedDuple == null ) return -1; - return namedDuple.getStartOffset(); - } - - /** - * @return - */ - public IDeclaratorOwner getOwner() - { - return owner; - } - - - /** - * @return - */ - public List getPointerOperators() - { - return ptrOps; - } - - public void addPointerOperator( ASTPointerOperator ptrOp ) - { - if( ptrOps == Collections.EMPTY_LIST ) - ptrOps = new ArrayList( DEFAULT_ARRAYLIST_SIZE ); - - ptrOps.add( ptrOp ); - } - /** - * @return - */ - public List getParameters() - { - return parameters; - } - - public void addParameter( DeclarationWrapper param ) - { - if( parameters == Collections.EMPTY_LIST ) - parameters = new ArrayList( DEFAULT_ARRAYLIST_SIZE ); - - parameters.add( param ); - } - /** - * @return - */ - public IASTInitializerClause getInitializerClause() - { - return initializerClause; - } - - /** - * @param expression - */ - public void setInitializerClause(IASTInitializerClause expression) - { - initializerClause = expression; - } - - /** - * @return - */ - public Declarator getOwnedDeclarator() - { - return ownedDeclarator; - } - - /** - * @param declarator - */ - public void setOwnedDeclarator(Declarator declarator) - { - ownedDeclarator = declarator; - } - - public void setName( ITokenDuple duple ) - { - namedDuple = duple; - } - - /** - * @return - */ - public IASTExceptionSpecification getExceptionSpecification() - { - return exceptionSpecification; - } - - /** - * @return - */ - public boolean isConst() - { - return checkBit(IS_CONST); - } - - /** - * @return - */ - public boolean isVolatile() - { - return checkBit( IS_VOLATILE); - } - - /** - * @param specification - */ - public void setExceptionSpecification(IASTExceptionSpecification specification) - { - exceptionSpecification = specification; - } - - /** - * @param b - */ - public void setConst(boolean b) - { - setBit(b, IS_CONST ); - } - - /** - * @param b - */ - public void setVolatile(boolean b) - { - setBit( b, IS_VOLATILE ); - } - - /** - * @param b - */ - public void setPureVirtual(boolean b) - { - setBit( b, IS_PURE_VIRTUAL ); - } - - /** - * @return - */ - public boolean isPureVirtual() - { - return checkBit( IS_PURE_VIRTUAL ); - } - - /** - * @param arrayMod - */ - public void addArrayModifier(IASTArrayModifier arrayMod) - { - if( arrayModifiers == Collections.EMPTY_LIST ) - arrayModifiers = new ArrayList( DEFAULT_ARRAYLIST_SIZE ); - arrayModifiers.add( arrayMod ); - } - - /** - * @return - */ - public List getArrayModifiers() - { - return arrayModifiers; - } - - /** - * @return - */ - public IASTExpression getBitFieldExpression() - { - return bitFieldExpression; - } - - /** - * @param expression - */ - public void setBitFieldExpression(IASTExpression expression) - { - bitFieldExpression = expression; - } - - /** - * @param astExpression - */ - public void setConstructorExpression(IASTExpression astExpression) - { - constructorExpression = astExpression; - } - - /** - * @return - */ - public IASTExpression getConstructorExpression() - { - return constructorExpression; - } - - /** - * @param initializer - */ - public void addConstructorMemberInitializer(IASTConstructorMemberInitializer initializer) - { - if( constructorMemberInitializers == Collections.EMPTY_LIST ) - constructorMemberInitializers = new ArrayList( DEFAULT_ARRAYLIST_SIZE ); - constructorMemberInitializers.add( initializer ); - } - - /** - * @return - */ - public List getConstructorMemberInitializers() - { - return constructorMemberInitializers; - } - - - /** - * @return - */ - public boolean isFunction() - { - return checkBit( IS_FUNCTION ); - } - - /** - * @param b - */ - public void setIsFunction(boolean b) - { - setBit( b, IS_FUNCTION ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IDeclaratorOwner#getDeclarators() - */ - public Iterator getDeclarators() - { - if( ownedDeclarator == null ) - return EmptyIterator.EMPTY_ITERATOR; - - List l = new ArrayList(1); - l.add( ownedDeclarator ); - return l.iterator(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IDeclaratorOwner#getDeclarationWrapper() - */ - public DeclarationWrapper getDeclarationWrapper() - { - Declarator d = this; - while( d.getOwner() instanceof Declarator ) - d = (Declarator)d.getOwner(); - return (DeclarationWrapper)d.getOwner(); - } - - - /** - * @return - */ - public ITokenDuple getNameDuple() - { - return namedDuple; - } - - /** - * @param nameDuple - */ - public void setPointerOperatorName(ITokenDuple nameDuple) - { - pointerOperatorNameDuple = nameDuple; - } - - /** - * @return - */ - public ITokenDuple getPointerOperatorNameDuple() - { - return pointerOperatorNameDuple; - } - - /** - * @return - */ - public boolean hasFunctionBody() - { - return checkBit( HAS_FUNCTION_BODY ); - } - - /** - * @param b - */ - public void setHasFunctionBody(boolean b) - { - setBit( b, HAS_FUNCTION_BODY ); - } - - /** - * @param b - */ - public void setFunctionTryBlock(boolean b) - { - setBit( b, HAS_TRY_BLOCK ); - } - - /** - * @return - */ - public boolean hasFunctionTryBlock() - { - return checkBit( HAS_TRY_BLOCK ); - } - - /** - * @param b - */ - public void setIsVarArgs(boolean b) { - setBit( b, IS_VAR_ARGS ); - } - - /** - * @return Returns the varArgs. - */ - public boolean isVarArgs() { - return checkBit( IS_VAR_ARGS ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IDeclarator#getScope() - */ - public IASTScope getScope() { - return getDeclarationWrapper().getScope(); - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/EmptyIterator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/EmptyIterator.java similarity index 91% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/EmptyIterator.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/EmptyIterator.java index 2f5bde7e6e2..7600a8d2e79 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/EmptyIterator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/EmptyIterator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. + * Copyright (c) 2002, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,7 +8,7 @@ * Contributors: * IBM Rational Software - Initial API and implementation *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast; +package org.eclipse.cdt.internal.core.parser; import java.util.Iterator; import java.util.NoSuchElementException; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/GCCParserExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/GCCParserExtension.java deleted file mode 100644 index e85d7cee8a8..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/GCCParserExtension.java +++ /dev/null @@ -1,491 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser; - -import java.util.Hashtable; -import java.util.Map; - -import org.eclipse.cdt.core.parser.EndOfFileException; -import org.eclipse.cdt.core.parser.Enum; -import org.eclipse.cdt.core.parser.IGCCToken; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.KeywordSetKey; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.ASTSemanticException; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; -import org.eclipse.cdt.core.parser.ast.IASTDesignator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; -import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCDesignator; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.extension.IParserExtension; -import org.eclipse.cdt.internal.core.parser.Parser.Flags; - - -/** - * @author jcamelon - * - */ -public class GCCParserExtension implements IParserExtension { - - private static final char[] EMPTY_STRING = "".toCharArray();//$NON-NLS-1$ - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#isValidCVModifier(org.eclipse.cdt.core.parser.ParserLanguage, int) - */ - public boolean isValidCVModifier(ParserLanguage language, int tokenType) { - if( tokenType == IToken.t_restrict && language == ParserLanguage.CPP ) - return true; - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#getPointerOperator(org.eclipse.cdt.core.parser.ParserLanguage, int) - */ - public ASTPointerOperator getPointerOperator(ParserLanguage language, int tokenType) { - if( tokenType == IToken.t_restrict && language == ParserLanguage.CPP ) - return ASTPointerOperator.RESTRICT_POINTER; - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#isValidUnaryExpressionStart(int) - */ - public boolean isValidUnaryExpressionStart(int tokenType) { - switch( tokenType ) - { - case IGCCToken.t___alignof__: - case IGCCToken.t_typeof: - return true; - default: - return false; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#parseUnaryExpression(org.eclipse.cdt.internal.core.parser.IParserData) - */ - public IASTExpression parseUnaryExpression(IASTScope scope, IParserData data, IASTCompletionNode.CompletionKind kind, KeywordSetKey key) { - try { - switch( data.LT(1)) - { - case IGCCToken.t___alignof__: - return performUnaryExpression( data, scope, kind, key, UnaryExpressionKind.ALIGNOF ); - case IGCCToken.t_typeof: - return performUnaryExpression( data, scope, kind, key, UnaryExpressionKind.TYPEOF ); - default: - break; - } - } catch (EndOfFileException e) { - //TODO - } - return null; - } - - - protected static class UnaryExpressionKind extends Enum - { - public static final UnaryExpressionKind ALIGNOF = new UnaryExpressionKind( 1 ); - public static final UnaryExpressionKind TYPEOF = new UnaryExpressionKind( 2 ); - /** - * @param enumValue - */ - protected UnaryExpressionKind(int enumValue) { - super(enumValue); - } - - } - - /** - * @param data - * @param scope - * @param kind - * @param key TODO - * @param type TODO - * @return - */ - protected IASTExpression performUnaryExpression(IParserData data, IASTScope scope, CompletionKind kind, KeywordSetKey key, UnaryExpressionKind type) { - IToken startingPoint = null; - try - { - if( type == UnaryExpressionKind.ALIGNOF ) - startingPoint = data.consume(IGCCToken.t___alignof__); - else if( type == UnaryExpressionKind.TYPEOF ) - startingPoint = data.consume(IGCCToken.t_typeof ); - } catch( BacktrackException b ) - { - return null; - } catch (EndOfFileException e) { - return null; - } - - try - { - IToken mark = data.mark(); - IASTTypeId d = null; - IASTExpression unaryExpression = null; - if (data.LT(1) == IToken.tLPAREN) - { - try - { - data.consume(IToken.tLPAREN); - d = data.typeId(scope, false, CompletionKind.TYPE_REFERENCE); - data.consume(IToken.tRPAREN); - } - catch (BacktrackException bt) - { - data.backup(mark); - d = null; - unaryExpression = data.unaryExpression(scope,kind, key); - } - } - else - { - unaryExpression = data.unaryExpression(scope,kind, key); - } - if (d != null & unaryExpression == null) - try - { - IASTExpression.Kind expKind = null; - if( type == UnaryExpressionKind.ALIGNOF ) - expKind = IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID; - else if( type == UnaryExpressionKind.TYPEOF ) - expKind = IASTGCCExpression.Kind.UNARY_TYPEOF_TYPEID; - return data.getAstFactory().createExpression( - scope, - expKind, - null, - null, - null, - d, - null, EMPTY_STRING, null, null); - } - catch (ASTSemanticException e) - { - data.backup( startingPoint ); - return null; - } catch (Exception e) - { - data.logException( "unaryExpression_1::createExpression()", e ); //$NON-NLS-1$ - data.backup( startingPoint ); - return null; - } - else if (unaryExpression != null && d == null) - try - { - IASTExpression.Kind expKind = null; - if( type == UnaryExpressionKind.ALIGNOF ) - expKind = IASTGCCExpression.Kind.UNARY_ALIGNOF_UNARYEXPRESSION; - else if( type == UnaryExpressionKind.TYPEOF ) - expKind = IASTGCCExpression.Kind.UNARY_TYPEOF_UNARYEXPRESSION; - - return data.getAstFactory().createExpression( - scope, - expKind, - unaryExpression, - null, - null, - null, - null, EMPTY_STRING, null, null); - } - catch (ASTSemanticException e1) - { - data.backup( startingPoint ); - return null; - } catch (Exception e) - { - data.logException( "unaryExpression_1::createExpression()", e ); //$NON-NLS-1$ - data.backup( startingPoint ); - return null; - } - return null; - } - catch( BacktrackException bt ) - { - data.backup( startingPoint ); - return null; - } - catch( EndOfFileException eof ) - { - data.backup( startingPoint ); - return null; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#canHandleDeclSpecifierSequence(int) - */ - public boolean canHandleDeclSpecifierSequence(int tokenType) { - switch( tokenType ) - { - case IGCCToken.t_typeof: - return true; - default: - return false; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#handleDeclSpecifierSequence(org.eclipse.cdt.internal.core.parser.IParserData, org.eclipse.cdt.core.model.Flags, org.eclipse.cdt.internal.core.parser.DeclarationWrapper) - */ - public IDeclSpecifierExtensionResult parseDeclSpecifierSequence(IParserData data, Parser.Flags flags, DeclarationWrapper sdw, CompletionKind kind, KeywordSetKey key) { - IToken startingPoint = null; - try - { - startingPoint = data.mark(); - } catch( EndOfFileException eof ) - { - return null; - } - - try - { - switch( data.LT(1)) - { - case IGCCToken.t_typeof: - IASTExpression typeOfExpression = performUnaryExpression( data, sdw.getScope(), kind, key, UnaryExpressionKind.TYPEOF ); - if( typeOfExpression != null ) - { - sdw.setSimpleType( IASTGCCSimpleTypeSpecifier.Type.TYPEOF ); - flags.setEncounteredRawType(true); - Hashtable params = new Hashtable(); - params.put( IASTGCCSimpleTypeSpecifier.TYPEOF_EXRESSION, typeOfExpression ); - sdw.setExtensionParameter( IASTGCCSimpleTypeSpecifier.TYPEOF_EXRESSION, typeOfExpression ); - return new GCCDeclSpecifierExtensionResult( startingPoint, data.getLastToken(), flags, params ); - } - data.backup( startingPoint ); - return null; - default: - data.backup( startingPoint ); - return null; - } - } - catch( EndOfFileException eof ) - { - data.backup( startingPoint ); - } - return null; - } - - public class GCCDeclSpecifierExtensionResult implements IDeclSpecifierExtensionResult - { - private final IToken first; - private final IToken last; - private final Flags flags; - - /** - * @param startingPoint - * @param token - * @param flags - */ - public GCCDeclSpecifierExtensionResult(IToken startingPoint, IToken token, Flags flags, Hashtable params) { - first = startingPoint; - last = token; - this.flags = flags; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension.IDeclSpecifierExtensionResult#getFirstToken() - */ - public IToken getFirstToken() { - return first; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension.IDeclSpecifierExtensionResult#getLastToken() - */ - public IToken getLastToken() { - return last; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension.IDeclSpecifierExtensionResult#getFlags() - */ - public Flags getFlags() { - return flags; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#isValidRelationalExpressionStart(int) - */ - public boolean isValidRelationalExpressionStart(ParserLanguage language, int tokenType) { - switch( tokenType ) - { - case IGCCToken.tMAX: - case IGCCToken.tMIN: - return true; - default: - return false; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#parseRelationalExpression(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.internal.core.parser.IParserData, org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind) - */ - public IASTExpression parseRelationalExpression(IASTScope scope, IParserData data, CompletionKind kind, KeywordSetKey key, IASTExpression lhsExpression) { - if( data.getParserLanguage() == ParserLanguage.C ) return null; - IToken mark = null; - try { - mark = data.mark(); - } catch (EndOfFileException e) { - return null; - } - IASTGCCExpression.Kind expressionKind = null; - try - { - switch( data.LT(1) ) - { - case IGCCToken.tMAX: - data.consume( IGCCToken.tMAX ); - expressionKind = IASTGCCExpression.Kind.RELATIONAL_MAX; - break; - case IGCCToken.tMIN: - data.consume( IGCCToken.tMIN ); - expressionKind = IASTGCCExpression.Kind.RELATIONAL_MIN; - break; - default: - data.backup( mark ); - return null; - } - - IToken next = data.LA(1); - IASTExpression secondExpression = data.shiftExpression(scope,kind, key); - if (next == data.LA(1)) - { - // we did not consume anything - // this is most likely an error - data.backup(mark); - return null; - } - - try { - IASTExpression resultExpression = data.getAstFactory().createExpression( - scope, expressionKind, lhsExpression, secondExpression, null, null, null, EMPTY_STRING, null, null ); - return resultExpression; - } catch (ASTSemanticException e1) { - data.backup( mark ); - return null; - } - - } catch( EndOfFileException eof ) - { - data.backup( mark ); - return null; - } catch( BacktrackException bt ) - { - data.backup( mark ); - return null; - } - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#canHandleCDesignatorInitializer(int) - */ - public boolean canHandleCDesignatorInitializer(int tokenType) { - switch( tokenType ) - { - case IToken.tIDENTIFIER: - case IToken.tLBRACKET: - return true; - default: - return false; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#parseDesignator(org.eclipse.cdt.internal.core.parser.IParserData) - */ - public IASTDesignator parseDesignator(IParserData parserData, IASTScope scope) { - IToken startingPoint = null; - try { - startingPoint = parserData.mark(); - } catch (EndOfFileException e) { - return null; - } - - try - { - if( parserData.LT(1) == IToken.tIDENTIFIER ) - { - IToken identifier = parserData.identifier(); - parserData.consume( IToken.tCOLON ); - return parserData.getAstFactory().createDesignator( IASTDesignator.DesignatorKind.FIELD, null, identifier, null ); - } - if( parserData.LT(1) == IToken.tLBRACKET ) - { - parserData.consume( IToken.tLBRACKET ); - IASTExpression constantExpression1 = parserData.expression( scope, CompletionKind.SINGLE_NAME_REFERENCE, KeywordSetKey.EXPRESSION ); - parserData.consume( IToken.tELLIPSIS ); - IASTExpression constantExpression2 = parserData.expression( scope, CompletionKind.SINGLE_NAME_REFERENCE, KeywordSetKey.EXPRESSION ); - parserData.consume(IToken.tRBRACKET ); - Map extensionParms = new Hashtable(); - extensionParms.put( IASTGCCDesignator.SECOND_EXRESSION, constantExpression2 ); - return parserData.getAstFactory().createDesignator( IASTGCCDesignator.DesignatorKind.SUBSCRIPT_RANGE, constantExpression1, null, extensionParms ); - } - } - catch( EndOfFileException eof ) - { - //nothing - } - catch( BacktrackException bt ) - { - //nothing - } - parserData.backup( startingPoint ); - return null; - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#supportsStatementsInExpressions() - */ - public boolean supportsStatementsInExpressions() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#getExpressionKindForStatement() - */ - public Kind getExpressionKindForStatement() { - return IASTGCCExpression.Kind.STATEMENT_EXPRESSION; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#supportsExtendedTemplateInstantiationSyntax() - */ - public boolean supportsExtendedTemplateInstantiationSyntax() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtension#isValidModifierForInstantiation(org.eclipse.cdt.core.parser.IToken) - */ - public boolean isValidModifierForInstantiation(IToken la) { - if( la == null ) return false; - switch( la.getType() ) - { - case IToken.t_static: - case IToken.t_inline: - case IToken.t_extern: - return true; - default: - return false; - } - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IDeclarator.java deleted file mode 100644 index 8f59e33efe5..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IDeclarator.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; -import java.util.List; - -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.core.parser.ast.IASTScope; -/** - * @author jcamelon - * - */ -public interface IDeclarator -{ - public IASTScope getScope(); - /** - * @return - */ - public abstract List getPointerOperators(); - public abstract void addPointerOperator(ASTPointerOperator ptrOp); - /** - * @param arrayMod - */ - public abstract void addArrayModifier(IASTArrayModifier arrayMod); - /** - * @return - */ - public abstract List getArrayModifiers(); - - /** - * @param nameDuple - */ - public void setPointerOperatorName(ITokenDuple nameDuple); - - public ITokenDuple getPointerOperatorNameDuple(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IDeclaratorOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IDeclaratorOwner.java deleted file mode 100644 index 1412efefb25..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IDeclaratorOwner.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; - -import java.util.Iterator; - -/** - * @author jcamelon - * - */ -public interface IDeclaratorOwner -{ - public Iterator getDeclarators(); - public DeclarationWrapper getDeclarationWrapper(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParameterCollection.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParameterCollection.java deleted file mode 100644 index fca45db6173..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParameterCollection.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; - -import java.util.List; - -/** - * @author jcamelon - * - */ -public interface IParameterCollection -{ - public List getParameters(); - public void addParameter( DeclarationWrapper param ); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserData.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserData.java deleted file mode 100644 index 0e9d168c78e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserData.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; -import org.eclipse.cdt.core.parser.EndOfFileException; -import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.KeywordSetKey; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTFactory; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; -/** - * @author jcamelon - * - */ -public interface IParserData { - - public IASTExpression expression(IASTScope scope, CompletionKind kind, - KeywordSetKey key) throws BacktrackException, EndOfFileException; - - /** - * @return Returns the astFactory. - */ - public abstract IASTFactory getAstFactory(); - /** - * @return Returns the log. - */ - public abstract IParserLogService getLog(); - /** - * Look Ahead in the token list to see what is coming. - * - * @param i How far ahead do you wish to peek? - * @return the token you wish to observe - * @throws EndOfFileException if looking ahead encounters EOF, throw EndOfFile - */ - public abstract IToken LA(int i) throws EndOfFileException; - /** - * Look ahead in the token list and return the token type. - * - * @param i How far ahead do you wish to peek? - * @return The type of that token - * @throws EndOfFileException if looking ahead encounters EOF, throw EndOfFile - */ - public abstract int LT(int i) throws EndOfFileException; - /** - * Consume the next token available, regardless of the type. - * - * @return The token that was consumed and removed from our buffer. - * @throws EndOfFileException If there is no token to consume. - */ - public abstract IToken consume() throws EndOfFileException; - /** - * Consume the next token available only if the type is as specified. - * - * @param type The type of token that you are expecting. - * @return the token that was consumed and removed from our buffer. - * @throws BacktrackException If LT(1) != type - */ - public abstract IToken consume(int type) throws EndOfFileException, - BacktrackException; - /** - * Mark our place in the buffer so that we could return to it should we have to. - * - * @return The current token. - * @throws EndOfFileException If there are no more tokens. - */ - public abstract IToken mark() throws EndOfFileException; - /** - * Rollback to a previous point, reseting the queue of tokens. - * - * @param mark The point that we wish to restore to. - * - */ - public abstract void backup(IToken mark); - /** - * @param string - * @param e - */ - public abstract void logException(String string, Exception e); - /** - * @param scope - * @param b - * @param kind - * @return - */ - public IASTTypeId typeId(IASTScope scope, boolean b, CompletionKind kind) throws EndOfFileException, BacktrackException; - /** - * @param scope - * @param kind - * @param key TODO - * @return - */ - public IASTExpression unaryExpression(IASTScope scope, CompletionKind kind, KeywordSetKey key) throws EndOfFileException, BacktrackException; - /** - * @return - */ - public IToken getLastToken(); - /** - * @return - */ - public abstract ParserLanguage getParserLanguage(); - /** - * @param scope - * @param kind - * @param key TODO - * @return - */ - public IASTExpression shiftExpression(IASTScope scope, CompletionKind kind, KeywordSetKey key) throws BacktrackException, EndOfFileException; - - public IToken identifier() throws EndOfFileException, BacktrackException; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParameterCollection.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParameterCollection.java deleted file mode 100644 index b5810ab62fb..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParameterCollection.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author jcamelon - * - */ -public class ParameterCollection implements IParameterCollection -{ - private List list = new ArrayList(); - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParameterCollection#getParameters() - */ - public List getParameters() - { - return list; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParameterCollection#addParameter(org.eclipse.cdt.internal.core.parser.DeclarationWrapper) - */ - public void addParameter(DeclarationWrapper param) - { - list.add( param ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java deleted file mode 100644 index 52dc6c85d3e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ /dev/null @@ -1,6957 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -import org.eclipse.cdt.core.parser.EndOfFileException; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.IScanner; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.KeywordSetKey; -import org.eclipse.cdt.core.parser.OffsetLimitReachedException; -import org.eclipse.cdt.core.parser.ParseError; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.ASTSemanticException; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTDesignator; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTFactory; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; -import org.eclipse.cdt.core.parser.ast.IASTReference; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTemplate; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; -import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; -import org.eclipse.cdt.core.parser.extension.IParserExtension; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.internal.core.parser.ast.ASTCompletionNode; -import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory; -import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner; -import org.eclipse.cdt.internal.core.parser.token.KeywordSets; -import org.eclipse.cdt.internal.core.parser.token.OffsetDuple; -import org.eclipse.cdt.internal.core.parser.token.TokenFactory; -import org.eclipse.cdt.internal.core.parser.util.TraceUtil; - -/** - * This is our first implementation of the IParser interface, serving as a - * parser for ANSI C and C++. - * - * From time to time we will make reference to the ANSI ISO specifications. - * - * @author jcamelon - */ -public class Parser implements IParserData, IParser -{ - protected final ParserMode mode; - protected static final char[] EMPTY_STRING = "".toCharArray(); //$NON-NLS-1$ - private static int FIRST_ERROR_UNSET = -1; - protected boolean parsePassed = true; - protected int firstErrorOffset = FIRST_ERROR_UNSET; - protected int firstErrorLine = FIRST_ERROR_UNSET; - private BacktrackException backtrack = new BacktrackException(); - private int backtrackCount = 0; - private char[] parserStartFilename = null; - - protected final void throwBacktrack( IProblem problem ) throws BacktrackException { - ++backtrackCount; - backtrack.initialize( problem ); - throw backtrack; - } - - protected final void throwBacktrack( int startingOffset, int endingOffset, int lineNumber, char[] f ) throws BacktrackException { - ++backtrackCount; - backtrack.initialize( startingOffset, ( endingOffset == 0 ) ? startingOffset + 1 : endingOffset, lineNumber, f ); - throw backtrack; - } - - protected final IParserExtension extension; - - //TODO this stuff needs to be encapsulated by IParserData - protected final IParserLogService log; - protected ParserLanguage language = ParserLanguage.CPP; - protected IASTFactory astFactory = null; - protected IScanner scanner; - protected IToken currToken; - protected IToken lastToken; - private boolean limitReached = false; - private ScopeStack templateIdScopes = new ScopeStack(); - private TypeId typeIdInstance = new TypeId(); - - private static class ScopeStack { - private int [] stack; - private int index = -1; - - public ScopeStack(){ - stack = new int [8]; - } - - private void grow(){ - int [] newStack = new int[ stack.length << 1 ]; - System.arraycopy( stack, 0, newStack, 0, stack.length ); - stack = newStack; - } - - final public void push( int i ){ - if( ++index == stack.length ) - grow(); - stack[index] = i; - } - final public int pop(){ - if( index >= 0 ) - return stack[index--]; - return -1; - } - final public int peek(){ - if( index >= 0 ) - return stack[index]; - return -1; - } - final public int size(){ - return index + 1; - } - } - /** - * @return Returns the astFactory. - */ - public IASTFactory getAstFactory() { - return astFactory; - } - /** - * @return Returns the log. - */ - public IParserLogService getLog() { - return log; - } - - /** - * Look Ahead in the token list to see what is coming. - * - * @param i How far ahead do you wish to peek? - * @return the token you wish to observe - * @throws EndOfFileException if looking ahead encounters EOF, throw EndOfFile - */ - public IToken LA(int i) throws EndOfFileException { - - if (isCancelled) { - throw new ParseError(ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED); - } - - if (i < 1) // can't go backwards - return null; - if (currToken == null) - currToken = fetchToken(); - IToken retToken = currToken; - for (; i > 1; --i) { - retToken = retToken.getNext(); - if (retToken == null) - retToken = fetchToken(); - } - return retToken; - } - - /** - * Look ahead in the token list and return the token type. - * - * @param i How far ahead do you wish to peek? - * @return The type of that token - * @throws EndOfFileException if looking ahead encounters EOF, throw EndOfFile - */ - public int LT(int i) throws EndOfFileException { - return LA(i).getType(); - } - - /** - * Consume the next token available, regardless of the type. - * - * @return The token that was consumed and removed from our buffer. - * @throws EndOfFileException If there is no token to consume. - */ - public IToken consume() throws EndOfFileException { - - if (currToken == null) - currToken = fetchToken(); - if (currToken != null) - lastToken = currToken; - currToken = currToken.getNext(); - handleNewToken(lastToken); - return lastToken; - } - - /** - * Consume the next token available only if the type is as specified. - * - * @param type The type of token that you are expecting. - * @return the token that was consumed and removed from our buffer. - * @throws BacktrackException If LT(1) != type - */ - public IToken consume(int type) throws EndOfFileException, - BacktrackException { - if (LT(1) == type) - return consume(); - IToken la = LA(1); - throwBacktrack(la.getOffset(), la.getEndOffset(), la.getLineNumber(), la.getFilename()); - return null; - } - - /** - * Mark our place in the buffer so that we could return to it should we have to. - * - * @return The current token. - * @throws EndOfFileException If there are no more tokens. - */ - public IToken mark() throws EndOfFileException { - if (currToken == null) - currToken = fetchToken(); - return currToken; - } - - /** - * Rollback to a previous point, reseting the queue of tokens. - * - * @param mark The point that we wish to restore to. - * - */ - public void backup(IToken mark) { - currToken = mark; - lastToken = null; // this is not entirely right ... - } - - /** - * This is the single entry point for setting parsePassed to - * false, and also making note what token offset we failed upon. - * - * @throws EndOfFileException - */ - protected void failParse() { - try { - if (firstErrorOffset == FIRST_ERROR_UNSET){ - firstErrorOffset = LA(1).getOffset(); - firstErrorLine = LA(1).getLineNumber(); - } - } catch (EndOfFileException eof) { - // do nothing - } finally { - parsePassed = false; - } - } - - /** - * Consumes template parameters. - * - * @param previousLast Previous "last" token (returned if nothing was consumed) - * @return Last consumed token, or previousLast if nothing was consumed - * @throws BacktrackException request a backtrack - */ - protected IToken consumeTemplateParameters(IToken previousLast) - throws EndOfFileException, BacktrackException { - if (language != ParserLanguage.CPP) - return previousLast; - int startingOffset = previousLast == null ? lastToken.getOffset() : previousLast.getOffset(); - IToken last = previousLast; - if (LT(1) == IToken.tLT) { - last = consume(IToken.tLT); - // until we get all the names sorted out - ScopeStack scopes = new ScopeStack(); - scopes.push(IToken.tLT); - - while (scopes.size() > 0) { - int top; - last = consume(); - - switch (last.getType()) { - case IToken.tGT : - if (scopes.peek() == IToken.tLT) { - scopes.pop(); - } - break; - case IToken.tRBRACKET : - do { - top = scopes.pop(); - } while (scopes.size() > 0 - && (top == IToken.tGT || top == IToken.tLT)); - if (top != IToken.tLBRACKET) - throwBacktrack(startingOffset, last.getEndOffset(), last.getLineNumber(), last.getFilename()); - - break; - case IToken.tRPAREN : - do { - top = scopes.pop(); - } while (scopes.size() > 0 - && (top == IToken.tGT || top == IToken.tLT)); - if (top != IToken.tLPAREN) - throwBacktrack(startingOffset, last.getEndOffset(), last.getLineNumber(), last.getFilename()); - - break; - case IToken.tLT : - case IToken.tLBRACKET : - case IToken.tLPAREN : - scopes.push(last.getType()); - break; - } - } - } - return last; - } - - protected List templateArgumentList(IASTScope scope, - IASTCompletionNode.CompletionKind kind) throws EndOfFileException, - BacktrackException { - IToken start = LA(1); - int startingOffset = start.getOffset(); - int startingLineNumber = start.getOffset(); - char [] fn = start.getFilename(); - start = null; - IASTExpression expression = null; - List list = new ArrayList(); - - boolean completedArg = false; - boolean failed = false; - - templateIdScopes.push( IToken.tLT ); - - while (LT(1) != IToken.tGT) { - completedArg = false; - - IToken mark = mark(); - - try { - IASTTypeId typeId = typeId(scope, false, kind); - - expression = astFactory.createExpression(scope, - IASTExpression.Kind.POSTFIX_TYPEID_TYPEID, null, null, - null, typeId, null, EMPTY_STRING, null, (ITokenDuple)start); - list.add(expression); - completedArg = true; - } catch (BacktrackException e) { - backup(mark); - } catch (ASTSemanticException e) { - backup(mark); - } - - if (!completedArg) { - try { - IToken la = LA(1); - int so = la.getOffset(); - int ln= la.getLineNumber(); - expression = assignmentExpression(scope, - CompletionKind.VARIABLE_TYPE, - KeywordSetKey.EXPRESSION); - - if (expression.getExpressionKind() == IASTExpression.Kind.PRIMARY_EMPTY) { - throwBacktrack(so, ( lastToken != null ) ? lastToken.getEndOffset() : 0, ln, fn ); - } - list.add(expression); - completedArg = true; - } catch (BacktrackException e) { - backup(mark); - } - } - if (!completedArg) { - try { - ITokenDuple nameDuple = name(scope, null, - KeywordSetKey.EMPTY); - expression = astFactory.createExpression(scope, - IASTExpression.Kind.ID_EXPRESSION, null, null, - null, null, nameDuple, EMPTY_STRING, null, (ITokenDuple)start); - list.add(expression); - continue; - } catch (ASTSemanticException e) { - failed = true; - break; - } catch (BacktrackException e) { - failed = true; - break; - } catch (Exception e) { - logException("templateArgumentList::createExpression()", e); //$NON-NLS-1$ - failed = true; - break; - } - } - - if (LT(1) == IToken.tCOMMA) { - consume(); - } else if (LT(1) != IToken.tGT) { - failed = true; - break; - } - } - - templateIdScopes.pop(); - - if (failed) { - if (expression != null) - expression.freeReferences(); - throwBacktrack(startingOffset, 0, startingLineNumber, fn ); - } - - return list; - } - - /** - * Parse a template-id, according to the ANSI C++ spec. - * - * template-id: template-name < template-argument-list opt > - * template-name : identifier - * - * @return the last token that we consumed in a successful parse - * - * @throws BacktrackException request a backtrack - */ - protected IToken templateId(IASTScope scope, CompletionKind kind) - throws EndOfFileException, BacktrackException { - ITokenDuple duple = name(scope, kind, KeywordSetKey.EMPTY); - //IToken last = consumeTemplateParameters(duple.getLastToken()); - return duple.getLastToken();//last; - } - - /** - * Parse a name. - * - * name - * : ("::")? name2 ("::" name2)* - * - * name2 - * : IDENTIFER - * : template-id - * - * @param key TODO - * @throws BacktrackException request a backtrack - */ - protected ITokenDuple name(IASTScope scope, - IASTCompletionNode.CompletionKind kind, KeywordSetKey key) - throws BacktrackException, EndOfFileException { - - TemplateParameterManager argumentList = TemplateParameterManager - .getInstance(); - - try { - IToken first = LA(1); - IToken last = null; - IToken mark = mark(); - - boolean hasTemplateId = false; - boolean startsWithColonColon = false; - - if (LT(1) == IToken.tCOLONCOLON) { - argumentList.addSegment(null); - last = consume(IToken.tCOLONCOLON); - setCompletionValues(scope, kind, KeywordSetKey.EMPTY, - getCompliationUnit()); - startsWithColonColon = true; - } - - if (LT(1) == IToken.tCOMPL) - consume(); - - switch (LT(1)) { - case IToken.tIDENTIFIER : - IToken prev = last; - last = consume(IToken.tIDENTIFIER); - if (startsWithColonColon) - setCompletionValues(scope, kind, getCompliationUnit()); - else if (prev != null) - setCompletionValues(scope, kind, first, prev, - argumentList.getTemplateArgumentsList(), KeywordSetKey.EMPTY); - else - setCompletionValuesNoContext(scope, kind, key); - - last = consumeTemplateArguments(scope, last, argumentList, kind); - if (last.getType() == IToken.tGT) - hasTemplateId = true; - break; - - default : - IToken l = LA(1); - backup(mark); - throwBacktrack(first.getOffset(), l.getEndOffset(), first.getLineNumber(), l.getFilename()); - } - - while (LT(1) == IToken.tCOLONCOLON) { - IToken prev = last; - last = consume(IToken.tCOLONCOLON); - setCompletionValues(scope, kind, first, prev, - argumentList.getTemplateArgumentsList(), KeywordSetKey.EMPTY); - - if (queryLookaheadCapability() && LT(1) == IToken.t_template) - consume(); - - if (queryLookaheadCapability() && LT(1) == IToken.tCOMPL) - consume(); - - switch (LT(1)) { - case IToken.t_operator : - IToken l = LA(1); - backup(mark); - throwBacktrack(first.getOffset(), l.getEndOffset(), first.getLineNumber(), l.getFilename()); - case IToken.tIDENTIFIER : - prev = last; - last = consume(); - setCompletionValues(scope, kind, first, prev, - argumentList.getTemplateArgumentsList(), KeywordSetKey.EMPTY); - last = consumeTemplateArguments(scope, last, - argumentList, kind); - if (last.getType() == IToken.tGT) - hasTemplateId = true; - } - } - - ITokenDuple tokenDuple = TokenFactory.createTokenDuple(first, last, - (hasTemplateId - ? argumentList.getTemplateArgumentsList() - : null)); - setGreaterNameContext(tokenDuple); - return tokenDuple; - } finally { - TemplateParameterManager.returnInstance(argumentList); - } - - } - - /** - * @param scope - * @param last - * @param argumentList - * @return - * @throws EndOfFileException - * @throws BacktrackException - */ - protected IToken consumeTemplateArguments(IASTScope scope, IToken last, - TemplateParameterManager argumentList, - IASTCompletionNode.CompletionKind completionKind) - throws EndOfFileException, BacktrackException { - if (language != ParserLanguage.CPP) - return last; - if (LT(1) == IToken.tLT) { - IToken secondMark = mark(); - consume(IToken.tLT); - try { - List list = templateArgumentList(scope, completionKind); - argumentList.addSegment(list); - last = consume(IToken.tGT); - } catch (BacktrackException bt) { - argumentList.addSegment(null); - backup(secondMark); - } - } else { - argumentList.addSegment(null); - } - return last; - } - - /** - * Parse a const-volatile qualifier. - * - * cvQualifier - * : "const" | "volatile" - * - * TODO: fix this - * @param ptrOp Pointer Operator that const-volatile applies to. - * @return Returns the same object sent in. - * @throws BacktrackException - */ - protected IToken cvQualifier(IDeclarator declarator) - throws EndOfFileException, BacktrackException { - IToken result = null; - int startingOffset = LA(1).getOffset(); - switch (LT(1)) { - case IToken.t_const : - result = consume(IToken.t_const); - declarator.addPointerOperator(ASTPointerOperator.CONST_POINTER); - break; - case IToken.t_volatile : - result = consume(IToken.t_volatile); - declarator - .addPointerOperator(ASTPointerOperator.VOLATILE_POINTER); - break; - case IToken.t_restrict : - if (language == ParserLanguage.C) { - result = consume(IToken.t_restrict); - declarator - .addPointerOperator(ASTPointerOperator.RESTRICT_POINTER); - break; - } - if (extension.isValidCVModifier(language, IToken.t_restrict)) { - result = consume(IToken.t_restrict); - declarator.addPointerOperator(extension.getPointerOperator( - language, IToken.t_restrict)); - break; - } - IToken la = LA(1); - throwBacktrack(startingOffset, la.getEndOffset(), la.getLineNumber(), la.getFilename()); - - default : - if (extension.isValidCVModifier(language, LT(1))) { - result = consume(); - declarator.addPointerOperator(extension.getPointerOperator( - language, result.getType())); - } - } - return result; - } - - protected IToken consumeArrayModifiers(IDeclarator d, IASTScope scope) - throws EndOfFileException, BacktrackException { - int startingOffset = LA(1).getOffset(); - IToken last = null; - while (LT(1) == IToken.tLBRACKET) { - consume(IToken.tLBRACKET); // eat the '[' - - IASTExpression exp = null; - if (LT(1) != IToken.tRBRACKET) { - exp = constantExpression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EXPRESSION); - } - last = consume(IToken.tRBRACKET); - IASTArrayModifier arrayMod = null; - try { - arrayMod = astFactory.createArrayModifier(exp); - } catch (Exception e) { - logException("consumeArrayModifiers::createArrayModifier()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, last.getEndOffset(), last.getLineNumber(), last.getFilename()); - } - d.addArrayModifier(arrayMod); - } - return last; - } - - protected void operatorId(Declarator d, IToken originalToken, - TemplateParameterManager templateArgs, - IASTCompletionNode.CompletionKind completionKind) - throws BacktrackException, EndOfFileException { - // we know this is an operator - IToken operatorToken = consume(IToken.t_operator); - IToken toSend = null; - if (LA(1).isOperator() || LT(1) == IToken.tLPAREN - || LT(1) == IToken.tLBRACKET) { - if ((LT(1) == IToken.t_new || LT(1) == IToken.t_delete) - && LT(2) == IToken.tLBRACKET && LT(3) == IToken.tRBRACKET) { - consume(); - consume(IToken.tLBRACKET); - toSend = consume(IToken.tRBRACKET); - // vector new and delete operators - } else if (LT(1) == IToken.tLPAREN && LT(2) == IToken.tRPAREN) { - // operator () - consume(IToken.tLPAREN); - toSend = consume(IToken.tRPAREN); - } else if (LT(1) == IToken.tLBRACKET && LT(2) == IToken.tRBRACKET) { - consume(IToken.tLBRACKET); - toSend = consume(IToken.tRBRACKET); - } else if (LA(1).isOperator()) - toSend = consume(); - else - throwBacktrack(operatorToken.getOffset(), toSend != null ? toSend.getEndOffset() : 0, operatorToken.getLineNumber(), operatorToken.getFilename() ); - } else { - // must be a conversion function - typeId(d.getDeclarationWrapper().getScope(), true, - CompletionKind.TYPE_REFERENCE); - toSend = lastToken; - } - - boolean hasTemplateId = (templateArgs != null); - boolean grabbedNewInstance = false; - if (templateArgs == null) { - templateArgs = TemplateParameterManager.getInstance(); - grabbedNewInstance = true; - } - - try { - toSend = consumeTemplateArguments(d.getDeclarationWrapper() - .getScope(), toSend, templateArgs, completionKind); - if (toSend.getType() == IToken.tGT) { - hasTemplateId = true; - } - - ITokenDuple duple = TokenFactory.createTokenDuple( - originalToken == null ? operatorToken : originalToken, - toSend, (hasTemplateId ? templateArgs - .getTemplateArgumentsList() : null)); - - d.setName(duple); - } finally { - if (grabbedNewInstance) - TemplateParameterManager.returnInstance(templateArgs); - } - } - - /** - * Parse a Pointer Operator. - * - * ptrOperator - * : "*" (cvQualifier)* - * | "&" - * | ::? nestedNameSpecifier "*" (cvQualifier)* - * - * @param owner Declarator that this pointer operator corresponds to. - * @throws BacktrackException request a backtrack - */ - protected IToken consumePointerOperators(IDeclarator d) - throws EndOfFileException, BacktrackException { - IToken result = null; - for (;;) { - if (LT(1) == IToken.tAMPER) { - result = consume(IToken.tAMPER); - d.addPointerOperator(ASTPointerOperator.REFERENCE); - return result; - - } - IToken mark = mark(); - - ITokenDuple nameDuple = null; - if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON) { - try { - nameDuple = name(d.getScope(), - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EMPTY); - } catch (BacktrackException bt) { - backup(mark); - return null; - } - } - if (LT(1) == IToken.tSTAR) { - result = consume(IToken.tSTAR); - - d.setPointerOperatorName(nameDuple); - - IToken successful = null; - for (;;) { - IToken newSuccess = cvQualifier(d); - if (newSuccess != null) - successful = newSuccess; - else - break; - - } - - if (successful == null) { - d.addPointerOperator(ASTPointerOperator.POINTER); - } - continue; - } - if (nameDuple != null) - nameDuple.freeReferences(); - backup(mark); - return result; - } - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression constantExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws BacktrackException, - EndOfFileException { - return conditionalExpression(scope, kind, key); - } - - public IASTExpression expression(IASTScope scope, CompletionKind kind, - KeywordSetKey key) throws BacktrackException, EndOfFileException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int ln = la.getLineNumber(); - char [] fn = la.getFilename(); - - //moved to primary expression -// IASTExpression resultExpression = null; -// if( la.getType() == IToken.tLPAREN && LT(2) == IToken.tLBRACE && extension.supportsStatementsInExpressions() ) -// { -// resultExpression = compoundStatementExpression(scope, la, resultExpression); -// } -// -// if( resultExpression != null ) -// return resultExpression; - - IASTExpression assignmentExpression = assignmentExpression(scope, kind, - key); - while (LT(1) == IToken.tCOMMA) { - consume(IToken.tCOMMA); - setParameterListExpression(assignmentExpression); - IASTExpression secondExpression = assignmentExpression(scope, kind, - key); - setParameterListExpression(null); - int endOffset = lastToken != null ? lastToken.getEndOffset() : 0 ; - try { - assignmentExpression = astFactory.createExpression(scope, - IASTExpression.Kind.EXPRESSIONLIST, - assignmentExpression, secondExpression, null, null, - null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("expression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, ln, fn); - } - } - return assignmentExpression; - } - - /** - * @param scope - * @param la - * @param resultExpression - * @return - * @throws EndOfFileException - * @throws BacktrackException - */ - private IASTExpression compoundStatementExpression(IASTScope scope, IToken la, IASTExpression resultExpression) throws EndOfFileException, BacktrackException { - int startingOffset = la.getOffset(); - int ln = la.getLineNumber(); - char [] fn = la.getFilename(); - consume( IToken.tLPAREN ); - try - { - if( mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE ) - skipOverCompoundStatement(); - else if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - { - if( scanner.isOnTopContext() ) - compoundStatement(scope, true); - else - skipOverCompoundStatement(); - } - else if( mode == ParserMode.COMPLETE_PARSE ) - compoundStatement(scope, true); - - consume( IToken.tRPAREN ); - try - { - resultExpression = astFactory.createExpression( scope, extension.getExpressionKindForStatement(), null, null, null, null, null,EMPTY_STRING, null, (ITokenDuple)la ); - } - catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("expression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, lastToken != null ? lastToken.getEndOffset() : 0 , ln, fn); - } - } - catch( BacktrackException bte ) - { - backup( la ); - } - return resultExpression; - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression assignmentExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws EndOfFileException, - BacktrackException { - setCompletionValues(scope, kind, key); - if (LT(1) == IToken.t_throw) { - return throwExpression(scope, key); - } - - IASTExpression conditionalExpression = conditionalExpression(scope, - kind, key); - // if the condition not taken, try assignment operators - if (conditionalExpression != null - && conditionalExpression.getExpressionKind() == IASTExpression.Kind.CONDITIONALEXPRESSION) - return conditionalExpression; - switch (LT(1)) { - case IToken.tASSIGN : - return assignmentOperatorExpression(scope, - IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL, - conditionalExpression, kind, key); - case IToken.tSTARASSIGN : - return assignmentOperatorExpression(scope, - IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT, - conditionalExpression, kind, key); - case IToken.tDIVASSIGN : - return assignmentOperatorExpression(scope, - IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV, - conditionalExpression, kind, key); - case IToken.tMODASSIGN : - return assignmentOperatorExpression(scope, - IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD, - conditionalExpression, kind, key); - case IToken.tPLUSASSIGN : - return assignmentOperatorExpression(scope, - IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS, - conditionalExpression, kind, key); - case IToken.tMINUSASSIGN : - return assignmentOperatorExpression(scope, - IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS, - conditionalExpression, kind, key); - case IToken.tSHIFTRASSIGN : - return assignmentOperatorExpression(scope, - IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT, - conditionalExpression, kind, key); - case IToken.tSHIFTLASSIGN : - return assignmentOperatorExpression(scope, - IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT, - conditionalExpression, kind, key); - case IToken.tAMPERASSIGN : - return assignmentOperatorExpression(scope, - IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND, - conditionalExpression, kind, key); - case IToken.tXORASSIGN : - return assignmentOperatorExpression(scope, - IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR, - conditionalExpression, kind, key); - case IToken.tBITORASSIGN : - return assignmentOperatorExpression(scope, - IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR, - conditionalExpression, kind, key); - } - return conditionalExpression; - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression throwExpression(IASTScope scope, KeywordSetKey key) - throws EndOfFileException, BacktrackException { - IToken throwToken = consume(IToken.t_throw); - setCompletionValues(scope, CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EXPRESSION); - IASTExpression throwExpression = null; - try { - throwExpression = expression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, key); - } catch (BacktrackException b) { - } - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.THROWEXPRESSION, throwExpression, null, - null, null, null, EMPTY_STRING, null, (ITokenDuple)throwToken); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("throwExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(throwToken.getOffset(), endOffset, throwToken.getLineNumber(), throwToken.getFilename() ); - - } - return null; - } - - /** - * @param expression - * @return - * @throws BacktrackException - */ - protected IASTExpression conditionalExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws BacktrackException, - EndOfFileException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int ln = la.getLineNumber(); - char [] fn = la.getFilename(); - - IASTExpression firstExpression = logicalOrExpression(scope, kind, key); - if (LT(1) == IToken.tQUESTION) { - consume(IToken.tQUESTION); - IASTExpression secondExpression = expression(scope, kind, key); - consume(IToken.tCOLON); - IASTExpression thirdExpression = assignmentExpression(scope, kind, - key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.CONDITIONALEXPRESSION, - firstExpression, secondExpression, thirdExpression, - null, null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("conditionalExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, ln, fn); - } - } - return firstExpression; - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression logicalOrExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws BacktrackException, - EndOfFileException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - IASTExpression firstExpression = logicalAndExpression(scope, kind, key); - while (LT(1) == IToken.tOR) { - consume(IToken.tOR); - IASTExpression secondExpression = logicalAndExpression(scope, kind, - key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - firstExpression = astFactory.createExpression(scope, - IASTExpression.Kind.LOGICALOREXPRESSION, - firstExpression, secondExpression, null, null, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("logicalOrExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - } - return firstExpression; - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression logicalAndExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws BacktrackException, - EndOfFileException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - IASTExpression firstExpression = inclusiveOrExpression(scope, kind, key); - while (LT(1) == IToken.tAND) { - consume(IToken.tAND); - IASTExpression secondExpression = inclusiveOrExpression(scope, - kind, key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - firstExpression = astFactory.createExpression(scope, - IASTExpression.Kind.LOGICALANDEXPRESSION, - firstExpression, secondExpression, null, null, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("logicalAndExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - } - return firstExpression; - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression inclusiveOrExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws BacktrackException, - EndOfFileException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - - IASTExpression firstExpression = exclusiveOrExpression(scope, kind, key); - while (LT(1) == IToken.tBITOR) { - consume(); - IASTExpression secondExpression = exclusiveOrExpression(scope, - kind, key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - firstExpression = astFactory.createExpression(scope, - IASTExpression.Kind.INCLUSIVEOREXPRESSION, - firstExpression, secondExpression, null, null, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("inclusiveOrExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - } - return firstExpression; - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression exclusiveOrExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws BacktrackException, - EndOfFileException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - - IASTExpression firstExpression = andExpression(scope, kind, key); - while (LT(1) == IToken.tXOR) { - consume(); - - IASTExpression secondExpression = andExpression(scope, kind, key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - firstExpression = astFactory.createExpression(scope, - IASTExpression.Kind.EXCLUSIVEOREXPRESSION, - firstExpression, secondExpression, null, null, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("exclusiveORExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - } - return firstExpression; - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression andExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws EndOfFileException, - BacktrackException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - - IASTExpression firstExpression = equalityExpression(scope, kind, key); - while (LT(1) == IToken.tAMPER) { - consume(); - IASTExpression secondExpression = equalityExpression(scope, kind, - key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - firstExpression = astFactory.createExpression(scope, - IASTExpression.Kind.ANDEXPRESSION, firstExpression, - secondExpression, null, null, null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("andExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - } - return firstExpression; - } - - /** - * @param methodName - * @param e - */ - public void logException(String methodName, Exception e) { - if (!(e instanceof EndOfFileException) && e != null && log.isTracing()) { - StringBuffer buffer = new StringBuffer(); - buffer.append("Parser: Unexpected exception in "); //$NON-NLS-1$ - buffer.append(methodName); - buffer.append(":"); //$NON-NLS-1$ - buffer.append(e.getClass().getName()); - buffer.append("::"); //$NON-NLS-1$ - buffer.append(e.getMessage()); - buffer.append(". w/"); //$NON-NLS-1$ - buffer.append(scanner.toString()); - log.traceLog(buffer.toString()); -// log.errorLog(buffer.toString()); - } - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression equalityExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws EndOfFileException, - BacktrackException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - - IASTExpression firstExpression = relationalExpression(scope, kind, key); - for (;;) { - switch (LT(1)) { - case IToken.tEQUAL : - case IToken.tNOTEQUAL : - IToken t = consume(); - IASTExpression secondExpression = relationalExpression( - scope, kind, key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - firstExpression = astFactory.createExpression(scope, (t - .getType() == IToken.tEQUAL) - ? IASTExpression.Kind.EQUALITY_EQUALS - : IASTExpression.Kind.EQUALITY_NOTEQUALS, - firstExpression, secondExpression, null, null, - null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException( - "equalityExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - default : - return firstExpression; - } - } - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression relationalExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws BacktrackException, - EndOfFileException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - - IASTExpression firstExpression = shiftExpression(scope, kind, key); - for (;;) { - switch (LT(1)) { - case IToken.tGT : - if (templateIdScopes.size() > 0 && templateIdScopes.peek() == IToken.tLT) { - return firstExpression; - } - case IToken.tLT : - case IToken.tLTEQUAL : - case IToken.tGTEQUAL : - IToken mark = mark(); - int t = consume().getType(); - IASTExpression secondExpression = shiftExpression(scope, - kind, key); - if (LA(1) == mark.getNext()) { - // we did not consume anything - // this is most likely an error - backup(mark); - return firstExpression; - } - IASTExpression.Kind expressionKind = null; - switch (t) { - case IToken.tGT : - expressionKind = IASTExpression.Kind.RELATIONAL_GREATERTHAN; - break; - case IToken.tLT : - expressionKind = IASTExpression.Kind.RELATIONAL_LESSTHAN; - break; - case IToken.tLTEQUAL : - expressionKind = IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO; - break; - case IToken.tGTEQUAL : - expressionKind = IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO; - break; - } - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - firstExpression = astFactory.createExpression(scope, - expressionKind, firstExpression, - secondExpression, null, null, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException( - "relationalExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - default : - if (extension.isValidRelationalExpressionStart(language, - LT(1))) { - IASTExpression extensionExpression = extension - .parseRelationalExpression(scope, this, kind, - key, firstExpression); - if (extensionExpression != null) - return extensionExpression; - } - return firstExpression; - } - } - } - - /** - * @param expression - * @throws BacktrackException - */ - public IASTExpression shiftExpression(IASTScope scope, CompletionKind kind, - KeywordSetKey key) throws BacktrackException, EndOfFileException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - IASTExpression firstExpression = additiveExpression(scope, kind, key); - for (;;) { - switch (LT(1)) { - case IToken.tSHIFTL : - case IToken.tSHIFTR : - IToken t = consume(); - IASTExpression secondExpression = additiveExpression(scope, - kind, key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - firstExpression = astFactory.createExpression(scope, - ((t.getType() == IToken.tSHIFTL) - ? IASTExpression.Kind.SHIFT_LEFT - : IASTExpression.Kind.SHIFT_RIGHT), - firstExpression, secondExpression, null, null, - null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("shiftExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - default : - return firstExpression; - } - } - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression additiveExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws BacktrackException, - EndOfFileException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - IASTExpression firstExpression = multiplicativeExpression(scope, kind, - key); - for (;;) { - switch (LT(1)) { - case IToken.tPLUS : - case IToken.tMINUS : - IToken t = consume(); - IASTExpression secondExpression = multiplicativeExpression( - scope, kind, key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - firstExpression = astFactory.createExpression(scope, - ((t.getType() == IToken.tPLUS) - ? IASTExpression.Kind.ADDITIVE_PLUS - : IASTExpression.Kind.ADDITIVE_MINUS), - firstExpression, secondExpression, null, null, - null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException( - "additiveExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - default : - return firstExpression; - } - } - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression multiplicativeExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws BacktrackException, - EndOfFileException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - IASTExpression firstExpression = pmExpression(scope, kind, key); - for (;;) { - switch (LT(1)) { - case IToken.tSTAR : - case IToken.tDIV : - case IToken.tMOD : - IToken t = consume(); - IASTExpression secondExpression = pmExpression(scope, kind, - key); - IASTExpression.Kind expressionKind = null; - switch (t.getType()) { - case IToken.tSTAR : - expressionKind = IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY; - break; - case IToken.tDIV : - expressionKind = IASTExpression.Kind.MULTIPLICATIVE_DIVIDE; - break; - case IToken.tMOD : - expressionKind = IASTExpression.Kind.MULTIPLICATIVE_MODULUS; - break; - } - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - firstExpression = astFactory.createExpression(scope, - expressionKind, firstExpression, - secondExpression, null, null, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - firstExpression.freeReferences(); - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException( - "multiplicativeExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - default : - return firstExpression; - } - } - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression pmExpression(IASTScope scope, CompletionKind kind, - KeywordSetKey key) throws EndOfFileException, BacktrackException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - - IASTExpression firstExpression = castExpression(scope, kind, key); - for (;;) { - switch (LT(1)) { - case IToken.tDOTSTAR : - case IToken.tARROWSTAR : - IToken t = consume(); - IASTExpression secondExpression = castExpression(scope, - kind, key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - firstExpression = astFactory.createExpression(scope, - ((t.getType() == IToken.tDOTSTAR) - ? IASTExpression.Kind.PM_DOTSTAR - : IASTExpression.Kind.PM_ARROWSTAR), - firstExpression, secondExpression, null, null, - null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("pmExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - default : - return firstExpression; - } - } - } - - /** - * castExpression - * : unaryExpression - * | "(" typeId ")" castExpression - */ - protected IASTExpression castExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws EndOfFileException, - BacktrackException { - // TO DO: we need proper symbol checkint to ensure type name - if (LT(1) == IToken.tLPAREN) { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - IToken mark = mark(); - consume(); - if (templateIdScopes.size() > 0) { - templateIdScopes.push( IToken.tLPAREN ); - } - boolean popped = false; - IASTTypeId typeId = null; - // If this isn't a type name, then we shouldn't be here - try { - try { - typeId = typeId(scope, false, getCastExpressionKind(kind)); - consume(IToken.tRPAREN); - } catch (BacktrackException bte) { - backup(mark); - if (typeId != null) - typeId.freeReferences(); - throw bte; - } - - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - popped = true; - } - IASTExpression castExpression = castExpression(scope, kind, key); - if( castExpression != null && castExpression.getExpressionKind() == IASTExpression.Kind.PRIMARY_EMPTY ) - { - backup( mark ); - if (typeId != null) - typeId.freeReferences(); - return unaryExpression(scope, kind, key); - } - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - mark = null; // clean up mark so that we can garbage collect - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.CASTEXPRESSION, castExpression, - null, null, typeId, null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("castExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - } catch (BacktrackException b) { - if (templateIdScopes.size() > 0 && !popped) { - templateIdScopes.pop(); - } - } - } - return unaryExpression(scope, kind, key); - - } - - /** - * @param kind - * @return - */ - private CompletionKind getCastExpressionKind(CompletionKind kind) { - return ((kind == CompletionKind.SINGLE_NAME_REFERENCE || kind == CompletionKind.FUNCTION_REFERENCE) - ? kind - : CompletionKind.TYPE_REFERENCE); - } - - /** - * @param completionKind TODO - * @throws BacktrackException - */ - public IASTTypeId typeId(IASTScope scope, boolean skipArrayModifiers, - CompletionKind completionKind) throws EndOfFileException, - BacktrackException { - IToken mark = mark(); - ITokenDuple name = null; - boolean isConst = false, isVolatile = false; - boolean isSigned = false, isUnsigned = false; - boolean isShort = false, isLong = false; - boolean isTypename = false; - - IASTSimpleTypeSpecifier.Type kind = null; - do { - try { - name = name(scope, completionKind, - KeywordSetKey.DECL_SPECIFIER_SEQUENCE); - kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; - break; - } catch (BacktrackException b) { - // do nothing - } - - boolean encounteredType = false; - simpleMods : for (;;) { - switch (LT(1)) { - case IToken.t_signed : - consume(); - isSigned = true; - break; - - case IToken.t_unsigned : - consume(); - isUnsigned = true; - break; - - case IToken.t_short : - consume(); - isShort = true; - break; - - case IToken.t_long : - consume(); - isLong = true; - break; - - case IToken.t_const : - consume(); - isConst = true; - break; - - case IToken.t_volatile : - consume(); - isVolatile = true; - break; - - case IToken.tIDENTIFIER : - if (encounteredType) - break simpleMods; - encounteredType = true; - name = name(scope, completionKind, KeywordSetKey.EMPTY); - kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; - break; - - case IToken.t_int : - if (encounteredType) - break simpleMods; - encounteredType = true; - kind = IASTSimpleTypeSpecifier.Type.INT; - consume(); - break; - - case IToken.t_char : - if (encounteredType) - break simpleMods; - encounteredType = true; - kind = IASTSimpleTypeSpecifier.Type.CHAR; - consume(); - break; - - case IToken.t_bool : - if (encounteredType) - break simpleMods; - encounteredType = true; - kind = IASTSimpleTypeSpecifier.Type.BOOL; - consume(); - break; - - case IToken.t_double : - if (encounteredType) - break simpleMods; - encounteredType = true; - kind = IASTSimpleTypeSpecifier.Type.DOUBLE; - consume(); - break; - - case IToken.t_float : - if (encounteredType) - break simpleMods; - encounteredType = true; - kind = IASTSimpleTypeSpecifier.Type.FLOAT; - consume(); - break; - - case IToken.t_wchar_t : - if (encounteredType) - break simpleMods; - encounteredType = true; - kind = IASTSimpleTypeSpecifier.Type.WCHAR_T; - consume(); - break; - - case IToken.t_void : - if (encounteredType) - break simpleMods; - encounteredType = true; - kind = IASTSimpleTypeSpecifier.Type.VOID; - consume(); - break; - - case IToken.t__Bool : - if (encounteredType) - break simpleMods; - encounteredType = true; - kind = IASTSimpleTypeSpecifier.Type._BOOL; - consume(); - break; - - default : - break simpleMods; - } - } - - if (kind != null) - break; - - if (isShort || isLong || isUnsigned || isSigned) { - kind = IASTSimpleTypeSpecifier.Type.INT; - break; - } - - if (LT(1) == IToken.t_typename || LT(1) == IToken.t_struct - || LT(1) == IToken.t_class || LT(1) == IToken.t_enum - || LT(1) == IToken.t_union) { - consume(); - try { - name = name(scope, completionKind, KeywordSetKey.EMPTY); - kind = IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; - } catch (BacktrackException b) { - backup(mark); - throwBacktrack(b); - } - } - - } while (false); - - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - if (kind == null) - throwBacktrack(mark.getOffset(), endOffset, mark.getLineNumber(), mark.getFilename()); - - TypeId id = getTypeIdInstance(scope); - IToken last = lastToken; - IToken temp = last; - - //template parameters are consumed as part of name - //lastToken = consumeTemplateParameters( last ); - //if( lastToken == null ) lastToken = last; - - temp = consumePointerOperators(id); - if (temp != null) - last = temp; - - if (!skipArrayModifiers) { - temp = consumeArrayModifiers(id, scope); - if (temp != null) - last = temp; - } - - endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - char[] signature = EMPTY_STRING; - if (last != null) - { - if( lastToken == null ) - lastToken = last; - signature = TokenFactory.createCharArrayRepresentation(mark, last); - } - return astFactory.createTypeId(scope, kind, isConst, isVolatile, - isShort, isLong, isSigned, isUnsigned, isTypename, name, id - .getPointerOperators(), id.getArrayModifiers(), - signature); - } catch (ASTSemanticException e) { - backup(mark); - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("typeId::createTypeId()", e); //$NON-NLS-1$ - throwBacktrack(mark.getOffset(), endOffset, mark.getLineNumber(), mark.getFilename()); - } - return null; - } - - /** - * @param scope - * @return - */ - private TypeId getTypeIdInstance(IASTScope scope) { - typeIdInstance.reset(scope); - return typeIdInstance; - } - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression deleteExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws EndOfFileException, - BacktrackException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - if (LT(1) == IToken.tCOLONCOLON) { - // global scope - consume(IToken.tCOLONCOLON); - } - - consume(IToken.t_delete); - - boolean vectored = false; - if (LT(1) == IToken.tLBRACKET) { - // array delete - consume(); - consume(IToken.tRBRACKET); - vectored = true; - } - IASTExpression castExpression = castExpression(scope, kind, key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - return astFactory.createExpression(scope, (vectored - ? IASTExpression.Kind.DELETE_VECTORCASTEXPRESSION - : IASTExpression.Kind.DELETE_CASTEXPRESSION), - castExpression, null, null, null, null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("deleteExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - return null; - } - - /** - * Pazse a new-expression. - * - * @param expression - * @throws BacktrackException - * - * - * newexpression: ::? new newplacement? newtypeid newinitializer? - * ::? new newplacement? ( typeid ) newinitializer? - * newplacement: ( expressionlist ) - * newtypeid: typespecifierseq newdeclarator? - * newdeclarator: ptroperator newdeclarator? | directnewdeclarator - * directnewdeclarator: [ expression ] - * directnewdeclarator [ constantexpression ] - * newinitializer: ( expressionlist? ) - */ - protected IASTExpression newExpression(IASTScope scope, KeywordSetKey key) - throws BacktrackException, EndOfFileException { - setCompletionValues(scope, CompletionKind.NEW_TYPE_REFERENCE, - KeywordSetKey.EMPTY); - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - if (LT(1) == IToken.tCOLONCOLON) { - // global scope - consume(IToken.tCOLONCOLON); - } - consume(IToken.t_new); - boolean typeIdInParen = false; - boolean placementParseFailure = true; - IToken beforeSecondParen = null; - IToken backtrackMarker = null; - IASTTypeId typeId = null; - ArrayList newPlacementExpressions = new ArrayList(); - ArrayList newTypeIdExpressions = new ArrayList(); - ArrayList newInitializerExpressions = new ArrayList(); - - if (LT(1) == IToken.tLPAREN) { - consume(IToken.tLPAREN); - if (templateIdScopes.size() > 0) { - templateIdScopes.push(IToken.tLPAREN); - } - try { - // Try to consume placement list - // Note: since expressionList and expression are the same... - backtrackMarker = mark(); - newPlacementExpressions.add(expression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, key)); - consume(IToken.tRPAREN); - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - } //pop 1st Parent - placementParseFailure = false; - if (LT(1) == IToken.tLPAREN) { - beforeSecondParen = mark(); - consume(IToken.tLPAREN); - if (templateIdScopes.size() > 0) { - templateIdScopes.push(IToken.tLPAREN); - } //push 2nd Paren - typeIdInParen = true; - } - } catch (BacktrackException e) { - backup(backtrackMarker); - } - if (placementParseFailure) { - // CASE: new (typeid-not-looking-as-placement) ... - // the first expression in () is not a placement - // - then it has to be typeId - typeId = typeId(scope, true, CompletionKind.NEW_TYPE_REFERENCE); - consume(IToken.tRPAREN); - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - } //pop 1st Paren - } else { - if (!typeIdInParen) { - if (LT(1) == IToken.tLBRACKET) { - // CASE: new (typeid-looking-as-placement) [expr]... - // the first expression in () has been parsed as a placement; - // however, we assume that it was in fact typeId, and this - // new statement creates an array. - // Do nothing, fallback to array/initializer processing - } else { - // CASE: new (placement) typeid ... - // the first expression in () is parsed as a placement, - // and the next expression doesn't start with '(' or '[' - // - then it has to be typeId - try { - backtrackMarker = mark(); - typeId = typeId(scope, true, - CompletionKind.NEW_TYPE_REFERENCE); - } catch (BacktrackException e) { - // Hmmm, so it wasn't typeId after all... Then it is - // CASE: new (typeid-looking-as-placement) - backup(backtrackMarker); - // TODO fix this - return null; - } - } - } else { - // Tricky cases: first expression in () is parsed as a placement, - // and the next expression starts with '('. - // The problem is, the first expression might as well be a typeid - try { - typeId = typeId(scope, true, - CompletionKind.NEW_TYPE_REFERENCE); - consume(IToken.tRPAREN); - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - } //popping the 2nd Paren - - if (LT(1) == IToken.tLPAREN - || LT(1) == IToken.tLBRACKET) { - // CASE: new (placement)(typeid)(initializer) - // CASE: new (placement)(typeid)[] ... - // Great, so far all our assumptions have been correct - // Do nothing, fallback to array/initializer processing - } else { - // CASE: new (placement)(typeid) - // CASE: new (typeid-looking-as-placement)(initializer-looking-as-typeid) - // Worst-case scenario - this cannot be resolved w/o more semantic information. - // Luckily, we don't need to know what was that - we only know that - // new-expression ends here. - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - setCompletionValues(scope, - CompletionKind.NO_SUCH_KIND, - KeywordSetKey.EMPTY); - return astFactory.createExpression(scope, - IASTExpression.Kind.NEW_TYPEID, null, - null, null, typeId, null, EMPTY_STRING, - astFactory.createNewDescriptor( - newPlacementExpressions, - newTypeIdExpressions, - newInitializerExpressions), (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException( - "newExpression_1::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - } - } catch (BacktrackException e) { - // CASE: new (typeid-looking-as-placement)(initializer-not-looking-as-typeid) - // Fallback to initializer processing - backup(beforeSecondParen); - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - }//pop that 2nd paren - } - } - } - } else { - // CASE: new typeid ... - // new parameters do not start with '(' - // i.e it has to be a plain typeId - typeId = typeId(scope, true, CompletionKind.NEW_TYPE_REFERENCE); - } - while (LT(1) == IToken.tLBRACKET) { - // array new - consume(); - - if (templateIdScopes.size() > 0) { - templateIdScopes.push(IToken.tLBRACKET); - } - - newTypeIdExpressions.add(assignmentExpression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, key)); - consume(IToken.tRBRACKET); - - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - } - } - // newinitializer - if (LT(1) == IToken.tLPAREN) { - consume(IToken.tLPAREN); - setCurrentFunctionName(((typeId != null) ? typeId - .getFullSignatureCharArray() : EMPTY_STRING)); - setCompletionValues(scope, CompletionKind.CONSTRUCTOR_REFERENCE); - if (templateIdScopes.size() > 0) { - templateIdScopes.push(IToken.tLPAREN); - } - - //we want to know the difference between no newInitializer and an empty new Initializer - //if the next token is the RPAREN, then we have an Empty expression in our list. - newInitializerExpressions.add(expression(scope, - CompletionKind.CONSTRUCTOR_REFERENCE, key)); - - setCurrentFunctionName(EMPTY_STRING); - consume(IToken.tRPAREN); - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - } - } - setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, - KeywordSetKey.EMPTY); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.NEW_TYPEID, null, null, null, typeId, - null, EMPTY_STRING, astFactory.createNewDescriptor( - newPlacementExpressions, newTypeIdExpressions, - newInitializerExpressions), (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - return null; - } catch (Exception e) { - logException("newExpression_2::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - return null; - } - - /** - * @param expression - * @throws BacktrackException - */ - public IASTExpression unaryExpression(IASTScope scope, CompletionKind kind, - KeywordSetKey key) throws EndOfFileException, BacktrackException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - switch (LT(1)) { - case IToken.tSTAR : - consume(); - return unaryOperatorCastExpression(scope, - IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION, kind, - key); - case IToken.tAMPER : - consume(); - return unaryOperatorCastExpression(scope, - IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION, kind, - key); - case IToken.tPLUS : - consume(); - return unaryOperatorCastExpression(scope, - IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION, kind, - key); - case IToken.tMINUS : - consume(); - return unaryOperatorCastExpression(scope, - IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION, kind, - key); - case IToken.tNOT : - consume(); - return unaryOperatorCastExpression(scope, - IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION, kind, key); - case IToken.tCOMPL : - consume(); - return unaryOperatorCastExpression(scope, - IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION, kind, - key); - case IToken.tINCR : - consume(); - return unaryOperatorCastExpression(scope, - IASTExpression.Kind.UNARY_INCREMENT, kind, key); - case IToken.tDECR : - consume(); - return unaryOperatorCastExpression(scope, - IASTExpression.Kind.UNARY_DECREMENT, kind, key); - case IToken.t_sizeof : - consume(IToken.t_sizeof); - IToken mark = LA(1); - IASTTypeId d = null; - IASTExpression unaryExpression = null; - if (LT(1) == IToken.tLPAREN) { - try { - consume(IToken.tLPAREN); - d = typeId(scope, false, - CompletionKind.SINGLE_NAME_REFERENCE); - consume(IToken.tRPAREN); - } catch (BacktrackException bt) { - backup(mark); - unaryExpression = unaryExpression(scope, kind, key); - } - } else { - unaryExpression = unaryExpression(scope, kind, key); - } - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - if (unaryExpression == null) - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.UNARY_SIZEOF_TYPEID, null, - null, null, d, null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("unaryExpression_1::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.UNARY_SIZEOF_UNARYEXPRESSION, - unaryExpression, null, null, null, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e1) { - throwBacktrack(e1.getProblem()); - } catch (Exception e) { - logException("unaryExpression_1::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - case IToken.t_new : - return newExpression(scope, key); - case IToken.t_delete : - return deleteExpression(scope, kind, key); - case IToken.tCOLONCOLON : - if (queryLookaheadCapability(2)) { - switch (LT(2)) { - case IToken.t_new : - return newExpression(scope, key); - case IToken.t_delete : - return deleteExpression(scope, kind, key); - default : - return postfixExpression(scope, kind, key); - } - } - default : - if (extension.isValidUnaryExpressionStart(LT(1))) { - IASTExpression extensionExpression = extension - .parseUnaryExpression(scope, this, kind, key); - if (extensionExpression != null) - return extensionExpression; - } - return postfixExpression(scope, kind, key); - } - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression postfixExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws EndOfFileException, - BacktrackException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - IASTExpression firstExpression = null; - boolean isTemplate = false; - - setCompletionValues(scope, kind, key); - switch (LT(1)) { - case IToken.t_typename : - consume(IToken.t_typename); - - boolean templateTokenConsumed = false; - if (LT(1) == IToken.t_template) { - consume(IToken.t_template); - templateTokenConsumed = true; - } - ITokenDuple nestedName = name(scope, - CompletionKind.TYPE_REFERENCE, KeywordSetKey.EMPTY); - - consume(IToken.tLPAREN); - if (templateIdScopes.size() > 0) { - templateIdScopes.push(IToken.tLPAREN); - } - IASTExpression expressionList = expression(scope, - CompletionKind.TYPE_REFERENCE, key); - int endOffset = consume(IToken.tRPAREN).getEndOffset(); - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - } - - try { - firstExpression = astFactory - .createExpression( - scope, - (templateTokenConsumed - ? IASTExpression.Kind.POSTFIX_TYPENAME_TEMPLATEID - : IASTExpression.Kind.POSTFIX_TYPENAME_IDENTIFIER), - expressionList, null, null, null, - nestedName, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException ase) { - throwBacktrack(ase.getProblem()); - } catch (Exception e) { - logException("postfixExpression_1::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - // simple-type-specifier ( assignment-expression , .. ) - case IToken.t_char : - firstExpression = simpleTypeConstructorExpression(scope, - IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR, key); - break; - case IToken.t_wchar_t : - firstExpression = simpleTypeConstructorExpression(scope, - IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART, key); - break; - case IToken.t_bool : - firstExpression = simpleTypeConstructorExpression(scope, - IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL, key); - break; - case IToken.t_short : - firstExpression = simpleTypeConstructorExpression(scope, - IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT, key); - break; - case IToken.t_int : - firstExpression = simpleTypeConstructorExpression(scope, - IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT, key); - break; - case IToken.t_long : - firstExpression = simpleTypeConstructorExpression(scope, - IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG, key); - break; - case IToken.t_signed : - firstExpression = simpleTypeConstructorExpression(scope, - IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED, key); - break; - case IToken.t_unsigned : - firstExpression = simpleTypeConstructorExpression(scope, - IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED, key); - break; - case IToken.t_float : - firstExpression = simpleTypeConstructorExpression(scope, - IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT, key); - break; - case IToken.t_double : - firstExpression = simpleTypeConstructorExpression(scope, - IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE, key); - break; - case IToken.t_dynamic_cast : - firstExpression = specialCastExpression(scope, - IASTExpression.Kind.POSTFIX_DYNAMIC_CAST, key); - break; - case IToken.t_static_cast : - firstExpression = specialCastExpression(scope, - IASTExpression.Kind.POSTFIX_STATIC_CAST, key); - break; - case IToken.t_reinterpret_cast : - firstExpression = specialCastExpression(scope, - IASTExpression.Kind.POSTFIX_REINTERPRET_CAST, key); - break; - case IToken.t_const_cast : - firstExpression = specialCastExpression(scope, - IASTExpression.Kind.POSTFIX_CONST_CAST, key); - break; - case IToken.t_typeid : - consume(); - consume(IToken.tLPAREN); - if (templateIdScopes.size() > 0) { - templateIdScopes.push(IToken.tLPAREN); - } - boolean isTypeId = true; - IASTExpression lhs = null; - IASTTypeId typeId = null; - try { - typeId = typeId(scope, false, CompletionKind.TYPE_REFERENCE); - } catch (BacktrackException b) { - isTypeId = false; - lhs = expression(scope, CompletionKind.TYPE_REFERENCE, key); - } - endOffset = consume(IToken.tRPAREN).getEndOffset(); - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - } - try { - firstExpression = astFactory - .createExpression( - scope, - (isTypeId - ? IASTExpression.Kind.POSTFIX_TYPEID_TYPEID - : IASTExpression.Kind.POSTFIX_TYPEID_EXPRESSION), - lhs, null, null, typeId, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e6) { - throwBacktrack(e6.getProblem()); - } catch (Exception e) { - logException("postfixExpression_2::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - default : - firstExpression = primaryExpression(scope, kind, key); - } - IASTExpression secondExpression = null; - for (;;) { - switch (LT(1)) { - case IToken.tLBRACKET : - // array access - consume(IToken.tLBRACKET); - if (templateIdScopes.size() > 0) { - templateIdScopes.push(IToken.tLBRACKET); - } - secondExpression = expression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, key); - int endOffset = consume(IToken.tRBRACKET).getEndOffset(); - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - } - try { - firstExpression = astFactory.createExpression(scope, - IASTExpression.Kind.POSTFIX_SUBSCRIPT, - firstExpression, secondExpression, null, null, - null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e2) { - throwBacktrack(e2.getProblem()); - } catch (Exception e) { - logException( - "postfixExpression_3::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - case IToken.tLPAREN : - // function call - consume(IToken.tLPAREN); - IASTNode cntext = null; - if (firstExpression != null) { - if (firstExpression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION) - setCurrentFunctionName(firstExpression - .getIdExpressionCharArray()); - else if (firstExpression.getRHSExpression() != null - && firstExpression.getRHSExpression() - .getIdExpressionCharArray() != null) { - setCurrentFunctionName(firstExpression - .getRHSExpression().getIdExpressionCharArray()); - cntext = astFactory - .expressionToMostPreciseASTNode(scope, - firstExpression.getLHSExpression()); - } - } - - if (templateIdScopes.size() > 0) { - templateIdScopes.push(IToken.tLPAREN); - } - setCompletionValues(scope, - CompletionKind.FUNCTION_REFERENCE, cntext); - secondExpression = expression(scope, - CompletionKind.FUNCTION_REFERENCE, key); - setCurrentFunctionName(EMPTY_STRING); - endOffset = consume(IToken.tRPAREN).getEndOffset(); - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - } - try { - firstExpression = astFactory.createExpression(scope, - IASTExpression.Kind.POSTFIX_FUNCTIONCALL, - firstExpression, secondExpression, null, null, - null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e3) { - throwBacktrack(e3.getProblem()); - } catch (Exception e) { - logException( - "postfixExpression_4::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - case IToken.tINCR : - endOffset = consume(IToken.tINCR).getEndOffset(); - try { - firstExpression = astFactory.createExpression(scope, - IASTExpression.Kind.POSTFIX_INCREMENT, - firstExpression, null, null, null, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e1) { - throwBacktrack(e1.getProblem()); - } catch (Exception e) { - logException( - "postfixExpression_5::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - case IToken.tDECR : - endOffset = consume().getEndOffset(); - try { - firstExpression = astFactory.createExpression(scope, - IASTExpression.Kind.POSTFIX_DECREMENT, - firstExpression, null, null, null, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e4) { - throwBacktrack(e4.getProblem()); - } catch (Exception e) { - logException( - "postfixExpression_6::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - case IToken.tDOT : - // member access - consume(IToken.tDOT); - - if (queryLookaheadCapability()) - if (LT(1) == IToken.t_template) { - consume(IToken.t_template); - isTemplate = true; - } - - Kind memberCompletionKind = (isTemplate - ? IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS - : IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION); - - setCompletionValues(scope, CompletionKind.MEMBER_REFERENCE, - KeywordSetKey.EMPTY, firstExpression, - memberCompletionKind); - secondExpression = primaryExpression(scope, - CompletionKind.MEMBER_REFERENCE, key); - endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - if (secondExpression != null - && secondExpression.getExpressionKind() == Kind.ID_EXPRESSION - && CharArrayUtils.indexOf( '~', secondExpression.getIdExpressionCharArray() ) != -1) - memberCompletionKind = Kind.POSTFIX_DOT_DESTRUCTOR; - - try { - firstExpression = astFactory.createExpression(scope, - memberCompletionKind, firstExpression, - secondExpression, null, null, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e5) { - throwBacktrack(e5.getProblem()); - } catch (Exception e) { - logException( - "postfixExpression_7::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - case IToken.tARROW : - // member access - consume(IToken.tARROW); - - if (queryLookaheadCapability()) - if (LT(1) == IToken.t_template) { - consume(IToken.t_template); - isTemplate = true; - } - - Kind arrowCompletionKind = (isTemplate - ? IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP - : IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION); - - setCompletionValues(scope, CompletionKind.MEMBER_REFERENCE, - KeywordSetKey.EMPTY, firstExpression, - arrowCompletionKind); - secondExpression = primaryExpression(scope, - CompletionKind.MEMBER_REFERENCE, key); - endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - if (secondExpression != null - && secondExpression.getExpressionKind() == Kind.ID_EXPRESSION - && CharArrayUtils.indexOf( '~', secondExpression.getIdExpressionCharArray() ) != -1) - arrowCompletionKind = Kind.POSTFIX_ARROW_DESTRUCTOR; - try { - firstExpression = astFactory.createExpression(scope, - arrowCompletionKind, firstExpression, - secondExpression, null, null, null, - EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException( - "postfixExpression_8::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - break; - default : - return firstExpression; - } - } - } - - /** - * @return - * @throws EndOfFileException - */ - protected boolean queryLookaheadCapability(int count) - throws EndOfFileException { - //make sure we can look ahead one before doing this - boolean result = true; - try { - LA(count); - } catch (EndOfFileException olre) { - result = false; - } - return result; - } - - protected boolean queryLookaheadCapability() throws EndOfFileException { - return queryLookaheadCapability(1); - } - - protected void checkEndOfFile() throws EndOfFileException { - if( mode != ParserMode.SELECTION_PARSE ) - LA(1); - } - - protected IASTExpression simpleTypeConstructorExpression(IASTScope scope, - Kind type, KeywordSetKey key) throws EndOfFileException, - BacktrackException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - char[] typeName = consume().getCharImage(); - consume(IToken.tLPAREN); - setCurrentFunctionName(typeName); - IASTExpression inside = expression(scope, - CompletionKind.CONSTRUCTOR_REFERENCE, key); - setCurrentFunctionName(EMPTY_STRING); - int endOffset = consume(IToken.tRPAREN).getEndOffset(); - try { - return astFactory.createExpression(scope, type, inside, null, null, - null, null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException( - "simpleTypeConstructorExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - return null; - } - - /** - * @param expression - * @throws BacktrackException - */ - protected IASTExpression primaryExpression(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws EndOfFileException, - BacktrackException { - IToken t = null; - switch (LT(1)) { - // TO DO: we need more literals... - case IToken.tINTEGER : - t = consume(); - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.PRIMARY_INTEGER_LITERAL, null, - null, null, null, null, t.getCharImage(), null, (ITokenDuple)t); - } catch (ASTSemanticException e1) { - throwBacktrack(e1.getProblem()); - } catch (Exception e) { - logException("primaryExpression_1::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(t.getOffset(), t.getEndOffset(), t.getLineNumber(), t.getFilename()); - } - case IToken.tFLOATINGPT : - t = consume(); - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.PRIMARY_FLOAT_LITERAL, null, - null, null, null, null, t.getCharImage(), null, (ITokenDuple)t); - } catch (ASTSemanticException e2) { - throwBacktrack(e2.getProblem()); - } catch (Exception e) { - logException("primaryExpression_2::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(t.getOffset(), t.getEndOffset(), t.getLineNumber(), t.getFilename()); - } - case IToken.tSTRING : - case IToken.tLSTRING : - t = consume(); - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.PRIMARY_STRING_LITERAL, null, - null, null, null, null, t.getCharImage(), null, (ITokenDuple)t); - } catch (ASTSemanticException e5) { - throwBacktrack(e5.getProblem()); - } catch (Exception e) { - logException("primaryExpression_3::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(t.getOffset(), t.getEndOffset(), t.getLineNumber(), t.getFilename()); - } - - case IToken.t_false : - case IToken.t_true : - t = consume(); - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL, null, - null, null, null, null, t.getCharImage(), null, (ITokenDuple)t); - } catch (ASTSemanticException e3) { - throwBacktrack(e3.getProblem()); - } catch (Exception e) { - logException("primaryExpression_4::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(t.getOffset(), t.getEndOffset(), t.getLineNumber(), t.getFilename() ); - } - - case IToken.tCHAR : - case IToken.tLCHAR : - - t = consume(); - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.PRIMARY_CHAR_LITERAL, null, - null, null, null, null, t.getCharImage(), null, (ITokenDuple)t); - } catch (ASTSemanticException e4) { - throwBacktrack(e4.getProblem()); - } catch (Exception e) { - logException("primaryExpression_5::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(t.getOffset(), t.getEndOffset(), t.getLineNumber(), t.getFilename()); - } - - case IToken.t_this : - t = consume(IToken.t_this); - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.PRIMARY_THIS, null, null, null, - null, null, EMPTY_STRING, null, (ITokenDuple)t); - } catch (ASTSemanticException e7) { - throwBacktrack(e7.getProblem()); - } catch (Exception e) { - logException("primaryExpression_6::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(t.getOffset(), t.getEndOffset(), t.getLineNumber(), t.getFilename()); - } - case IToken.tLPAREN : - if( LT(2) == IToken.tLBRACE && extension.supportsStatementsInExpressions() ) - { - IASTExpression resultExpression = compoundStatementExpression(scope, LA(1), null); - if( resultExpression != null ) - return resultExpression; - } - t = consume(); - if (templateIdScopes.size() > 0) { - templateIdScopes.push(IToken.tLPAREN); - } - IASTExpression lhs = expression(scope, kind, key); - int endOffset = consume(IToken.tRPAREN).getEndOffset(); - if (templateIdScopes.size() > 0) { - templateIdScopes.pop(); - } - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION, - lhs, null, null, null, null, EMPTY_STRING, null, (ITokenDuple)t); - } catch (ASTSemanticException e6) { - throwBacktrack(e6.getProblem()); - } catch (Exception e) { - logException("primaryExpression_7::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(t.getOffset(), endOffset, t.getLineNumber(), t.getFilename() ); - } - case IToken.tIDENTIFIER : - case IToken.tCOLONCOLON : - case IToken.t_operator : - case IToken.tCOMPL : - ITokenDuple duple = null; - int startingOffset = LA(1).getOffset(); - int line = LA(1).getLineNumber(); - try { - duple = name(scope, kind, key); - } catch (BacktrackException bt) { - IToken mark = mark(); - Declarator d = new Declarator(new DeclarationWrapper(scope, - mark.getOffset(), mark.getLineNumber(), null, mark.getFilename())); - - if (LT(1) == IToken.tCOLONCOLON - || LT(1) == IToken.tIDENTIFIER) { - IToken start = consume(); - IToken end = null; - if (start.getType() == IToken.tIDENTIFIER) - end = consumeTemplateParameters(end); - while (LT(1) == IToken.tCOLONCOLON - || LT(1) == IToken.tIDENTIFIER) { - end = consume(); - if (end.getType() == IToken.tIDENTIFIER) - end = consumeTemplateParameters(end); - } - if (LT(1) == IToken.t_operator) - operatorId(d, start, null, kind); - else { - backup(mark); - throwBacktrack(startingOffset, end.getEndOffset(), end.getLineNumber(), t.getFilename()); - } - } else if (LT(1) == IToken.t_operator) - operatorId(d, null, null, kind); - - duple = d.getNameDuple(); - } - - endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - return astFactory.createExpression(scope, - IASTExpression.Kind.ID_EXPRESSION, null, null, - null, null, duple, EMPTY_STRING, null, duple); - } catch (ASTSemanticException e8) { - throwBacktrack(e8.getProblem()); - } catch (Exception e) { - logException("primaryExpression_8::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, duple.getFilename()); - } - default : - IToken la= LA(1); - startingOffset = la.getOffset(); - line = la.getLineNumber(); - char [] fn = la.getFilename(); - if (!queryLookaheadCapability(2)) { - if (LA(1).canBeAPrefix()) { - consume(); - checkEndOfFile(); - } - } - IASTExpression empty = null; - try { - empty = astFactory.createExpression(scope, - IASTExpression.Kind.PRIMARY_EMPTY, null, null, - null, null, null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e9) { - throwBacktrack( e9.getProblem() ); - return null; - } catch (Exception e) { - logException("primaryExpression_9::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, 0, line, fn); - } - return empty; - } - - } - - /** - * Fetches a token from the scanner. - * - * @return the next token from the scanner - * @throws EndOfFileException thrown when the scanner.nextToken() yields no tokens - */ - protected IToken fetchToken() throws EndOfFileException { - if (limitReached) - throw new EndOfFileException(); - - try { - IToken value = scanner.nextToken(); - return value; - } catch (OffsetLimitReachedException olre) { - limitReached = true; - handleOffsetLimitException(olre); - return null; - } - } - - protected IASTExpression assignmentOperatorExpression(IASTScope scope, - IASTExpression.Kind kind, IASTExpression lhs, - CompletionKind completionKind, KeywordSetKey key) - throws EndOfFileException, BacktrackException { - IToken t = consume(); - IASTExpression assignmentExpression = assignmentExpression(scope, - completionKind, key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - return astFactory.createExpression(scope, kind, lhs, - assignmentExpression, null, null, null, EMPTY_STRING, null, (ITokenDuple)t); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("assignmentOperatorExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(t.getOffset(), endOffset, t.getLineNumber(), t.getFilename()); - } - return null; - } - - - protected IASTExpression unaryOperatorCastExpression(IASTScope scope, - IASTExpression.Kind kind, CompletionKind completionKind, - KeywordSetKey key) throws EndOfFileException, BacktrackException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - IASTExpression castExpression = castExpression(scope, completionKind, - key); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - try { - return astFactory.createExpression(scope, kind, castExpression, - null, null, null, null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("unaryOperatorCastExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - return null; - } - - protected IASTExpression specialCastExpression(IASTScope scope, - IASTExpression.Kind kind, KeywordSetKey key) - throws EndOfFileException, BacktrackException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - - consume(); - consume(IToken.tLT); - IASTTypeId duple = typeId(scope, false, CompletionKind.TYPE_REFERENCE); - consume(IToken.tGT); - consume(IToken.tLPAREN); - IASTExpression lhs = expression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, key); - int endOffset = consume(IToken.tRPAREN).getEndOffset(); - try { - return astFactory.createExpression(scope, kind, lhs, null, null, - duple, null, EMPTY_STRING, null, (ITokenDuple)la); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - logException("specialCastExpression::createExpression()", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn ); - } - return null; - } - - - protected boolean isCancelled = false; - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserData#getLastToken() - */ - public IToken getLastToken() { - return lastToken; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IParserData#getParserLanguage() - */ - public final ParserLanguage getParserLanguage() { - return language; - } - /** - * Parse an identifier. - * - * @throws BacktrackException request a backtrack - */ - public IToken identifier() throws EndOfFileException, BacktrackException { - IToken first = consume(IToken.tIDENTIFIER); // throws backtrack if its not that - if( first instanceof ITokenDuple ) setGreaterNameContext((ITokenDuple) first); - return first; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - return scanner.toString(); //$NON-NLS-1$ - } - - /** - * @return Returns the backtrackCount. - */ - public final int getBacktrackCount() { - return backtrackCount; - } - - /** - * @param bt - */ - protected void throwBacktrack(BacktrackException bt) throws BacktrackException { - throw bt; - } - - /** - * @throws EndOfFileException - */ - protected void errorHandling() throws EndOfFileException { - int depth = ( LT(1) == IToken.tLBRACE ) ? 1 : 0; - int type = consume().getType(); - if( type == IToken.tSEMI ) return; - while (!((LT(1) == IToken.tSEMI && depth == 0) - || (LT(1) == IToken.tRBRACE && depth == 1))) - { - switch (LT(1)) - { - case IToken.tLBRACE : - ++depth; - break; - case IToken.tRBRACE : - --depth; - break; - } - if( depth < 0 ) - return; - - consume(); - } - // eat the SEMI/RBRACE as well - consume(); - } - - private static final int DEFAULT_DESIGNATOR_LIST_SIZE = 4; - protected ISourceElementRequestor requestor = null; - private IProblemFactory problemFactory = new ParserProblemFactory(); - /** - * This is the standard cosntructor that we expect the Parser to be - * instantiated with. - * @param mode TODO - * - */ - public Parser( - IScanner scanner, - ParserMode mode, - ISourceElementRequestor callback, - ParserLanguage language, IParserLogService log, IParserExtension extension ) - { - this.parserStartFilename = scanner.getMainFilename(); - this.scanner = scanner; - this.language = language; - this.log = log; - this.extension = extension; - this.mode = mode; - setupASTFactory(scanner, language); - requestor = callback; - if( this.mode == ParserMode.QUICK_PARSE ) - constructInitializersInDeclarations = false; - } - - - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#failParse() - */ - protected void failParse( BacktrackException bt ) { - if( bt.getProblem() == null ) - { - IProblem problem = problemFactory.createProblem( - IProblem.SYNTAX_ERROR, - bt.getStartingOffset(), - bt.getEndOffset(), - bt.getLineNumber(), - bt.getFilename(), - EMPTY_STRING, - false, - true ); - requestor.acceptProblem( problem ); - } - else - { - requestor.acceptProblem( bt.getProblem() ); - } - failParse(); - } - - protected void failParse( IProblem problem ){ - if( problem != null ){ - requestor.acceptProblem( problem ); - } - failParse(); - } - - // counter that keeps track of the number of times Parser.parse() is called - private static int parseCount = 0; - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.IParser#parse() - */ - public boolean parse() - { - long startTime = System.currentTimeMillis(); - translationUnit(); - // For the debuglog to take place, you have to call - // Util.setDebugging(true); - // Or set debug to true in the core plugin preference - log.traceLog( - "Parse " //$NON-NLS-1$ - + (++parseCount) - + ": " //$NON-NLS-1$ - + (System.currentTimeMillis() - startTime) - + "ms" //$NON-NLS-1$ - + (parsePassed ? "" : " - parse failure") ); //$NON-NLS-1$ //$NON-NLS-2$ - return parsePassed; - } - - - /** - * This is the top-level entry point into the ANSI C++ grammar. - * - * translationUnit : (declaration)* - */ - protected void translationUnit() - { - try - { - compilationUnit = astFactory.createCompilationUnit(); - } - catch (Exception e2) - { - logException( "translationUnit::createCompilationUnit()", e2 ); //$NON-NLS-1$ - return; - } - - compilationUnit.enterScope( requestor ); - try { - setCompletionValues(compilationUnit, CompletionKind.VARIABLE_TYPE, KeywordSetKey.DECLARATION ); - } catch (EndOfFileException e1) { - compilationUnit.exitScope( requestor ); - return; - } - -// int lastBacktrack = -1; - - while (true) - { - try - { - int checkOffset = LA(1).hashCode(); - declaration(compilationUnit, null, null, KeywordSetKey.DECLARATION); - if (LA(1).hashCode() == checkOffset) - failParseWithErrorHandling(); - } - catch (EndOfFileException e) - { - // Good - break; - } - catch (BacktrackException b) - { - try - { - // Mark as failure and try to reach a recovery point - failParse(b); - errorHandling(); -// if (lastBacktrack != -1 && lastBacktrack == LA(1).hashCode()) -// { -// // we haven't progressed from the last backtrack -// // try and find tne next definition -// failParseWithErrorHandling(); -// } -// else -// { -// // start again from here -// lastBacktrack = LA(1).hashCode(); -// } - } - catch (EndOfFileException e) - { - break; - } - } - catch( OutOfMemoryError oome ) - { - logThrowable( "translationUnit", oome ); //$NON-NLS-1$ - throw oome; - } - catch( Exception e ) - { - logException( "translationUnit", e ); //$NON-NLS-1$ - try { - failParseWithErrorHandling(); - } catch (EndOfFileException e3) { - } - } - catch( ParseError perr ) - { - throw perr; - } - catch (Throwable e) - { - logThrowable( "translationUnit", e ); //$NON-NLS-1$ - try { - failParseWithErrorHandling(); - } catch (EndOfFileException e3) { - } - } - } - compilationUnit.exitScope( requestor ); - } - /** - * @param string - * @param e - */ - private void logThrowable(String methodName, Throwable e) { - if( e != null && log.isTracing()) - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "Parser: Unexpected throwable in "); //$NON-NLS-1$ - buffer.append( methodName ); - buffer.append( ":"); //$NON-NLS-1$ - buffer.append( e.getClass().getName() ); - buffer.append( "::"); //$NON-NLS-1$ - buffer.append( e.getMessage() ); - buffer.append( ". w/"); //$NON-NLS-1$ - buffer.append( scanner.toString() ); - log.traceLog( buffer.toString() ); -// log.errorLog( buffer.toString() ); - } - } - - - - /** - * This function is called whenever we encounter and error that we cannot - * backtrack out of and we still wish to try and continue on with the parse - * to do a best-effort parse for our client. - * - * @throws EndOfFileException - * We can potentially hit EndOfFile here as we are skipping - * ahead. - */ - protected void failParseWithErrorHandling() throws EndOfFileException - { - failParse(); - errorHandling(); - } - /** - * The merger of using-declaration and using-directive in ANSI C++ grammar. - * - * using-declaration: using typename? ::? nested-name-specifier - * unqualified-id ; using :: unqualified-id ; using-directive: using - * namespace ::? nested-name-specifier? namespace-name ; - * - * @param container - * Callback object representing the scope these definitions fall - * into. - * @return TODO - * @throws BacktrackException - * request for a backtrack - */ - protected IASTDeclaration usingClause(IASTScope scope) - throws EndOfFileException, BacktrackException - { - IToken firstToken = consume(IToken.t_using); - setCompletionValues(scope, CompletionKind.TYPE_REFERENCE, KeywordSetKey.POST_USING ); - - if (LT(1) == IToken.t_namespace) - { - // using-directive - consume(IToken.t_namespace); - - setCompletionValues(scope, CompletionKind.NAMESPACE_REFERENCE, KeywordSetKey.EMPTY ); - // optional :: and nested classes handled in name - ITokenDuple duple = null; - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON) - duple = name(scope, CompletionKind.NAMESPACE_REFERENCE, KeywordSetKey.EMPTY); - else - throwBacktrack(firstToken.getOffset(), endOffset, firstToken.getLineNumber(), firstToken.getFilename()); - if (LT(1) == IToken.tSEMI) - { - IToken last = consume(IToken.tSEMI); - IASTUsingDirective astUD = null; - - try - { - astUD = astFactory.createUsingDirective(scope, duple, firstToken.getOffset(), firstToken.getLineNumber(), last.getEndOffset(), last.getLineNumber()); - } - catch( ASTSemanticException ase ) - { - backup( last ); - throwBacktrack( ase.getProblem() ); - } - catch (Exception e1) - { - logException( "usingClause:createUsingDirective", e1 ); //$NON-NLS-1$ - throwBacktrack(firstToken.getOffset(), last.getEndOffset(), firstToken.getLineNumber(), last.getFilename()); - } - astUD.acceptElement(requestor ); - return astUD; - } - endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - throwBacktrack(firstToken.getOffset(), endOffset, firstToken.getLineNumber(), firstToken.getFilename()); - } - boolean typeName = false; - setCompletionValues(scope, CompletionKind.TYPE_REFERENCE, KeywordSetKey.POST_USING ); - - if (LT(1) == IToken.t_typename) - { - typeName = true; - consume(IToken.t_typename); - } - - setCompletionValues(scope, CompletionKind.TYPE_REFERENCE, KeywordSetKey.NAMESPACE_ONLY ); - ITokenDuple name = null; - if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON) - { - // optional :: and nested classes handled in name - name = name(scope, CompletionKind.TYPE_REFERENCE, KeywordSetKey.POST_USING); - } - else - { - throwBacktrack(firstToken.getOffset(), ( lastToken != null ) ? lastToken.getEndOffset() : 0, firstToken.getLineNumber(), firstToken.getFilename()); - } - if (LT(1) == IToken.tSEMI) - { - IToken last = consume(IToken.tSEMI); - IASTUsingDeclaration declaration = null; - try - { - declaration = - astFactory.createUsingDeclaration( - scope, - typeName, - name, - firstToken.getOffset(), - firstToken.getLineNumber(), last.getEndOffset(), last.getLineNumber()); - } - catch (Exception e1) - { - logException( "usingClause:createUsingDeclaration", e1 ); //$NON-NLS-1$ - if( e1 instanceof ASTSemanticException && ((ASTSemanticException)e1).getProblem() != null ) - throwBacktrack(((ASTSemanticException)e1).getProblem()); - else - throwBacktrack(firstToken.getOffset(), last.getEndOffset(), firstToken.getLineNumber(), firstToken.getFilename()); - } - declaration.acceptElement( requestor ); - setCompletionValues(scope, getCompletionKindForDeclaration(scope, null), KeywordSetKey.DECLARATION ); - return declaration; - } - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - throwBacktrack(firstToken.getOffset(), endOffset, firstToken.getLineNumber(), firstToken.getFilename()); - return null; - } - /** - * Implements Linkage specification in the ANSI C++ grammar. - * - * linkageSpecification : extern "string literal" declaration | extern - * "string literal" { declaration-seq } - * - * @param container - * Callback object representing the scope these definitions fall - * into. - * @return TODO - * @throws BacktrackException - * request for a backtrack - */ - protected IASTDeclaration linkageSpecification(IASTScope scope) - throws EndOfFileException, BacktrackException - { - IToken firstToken = consume(IToken.t_extern); - if (LT(1) != IToken.tSTRING) - throwBacktrack(firstToken.getOffset(), firstToken.getEndOffset(), firstToken.getLineNumber(), firstToken.getFilename()); - IToken spec = consume(IToken.tSTRING); - - if (LT(1) == IToken.tLBRACE) - { - IToken lbrace = consume(IToken.tLBRACE); - IASTLinkageSpecification linkage = null; - try - { - linkage = - astFactory.createLinkageSpecification( - scope, - spec.getCharImage(), - firstToken.getOffset(), firstToken.getLineNumber(), firstToken.getFilename()); - } - catch (Exception e) - { - logException( "linkageSpecification_1:createLinkageSpecification", e ); //$NON-NLS-1$ - throwBacktrack(firstToken.getOffset(), lbrace.getEndOffset(), lbrace.getLineNumber(), lbrace.getFilename()); - } - - linkage.enterScope( requestor ); - try - { - linkageDeclarationLoop : while (LT(1) != IToken.tRBRACE) - { - int checkToken = LA(1).hashCode(); - switch (LT(1)) - { - case IToken.tRBRACE : - consume(IToken.tRBRACE); - break linkageDeclarationLoop; - default : - try - { - declaration(linkage, null, null, KeywordSetKey.DECLARATION); - } - catch (BacktrackException bt) - { - failParse(bt); - if (checkToken == LA(1).hashCode()) - failParseWithErrorHandling(); - } - } - if (checkToken == LA(1).hashCode()) - failParseWithErrorHandling(); - } - // consume the } - IToken lastTokenConsumed = consume(); - linkage.setEndingOffsetAndLineNumber(lastTokenConsumed.getEndOffset(), lastTokenConsumed.getLineNumber()); - } - finally - { - linkage.exitScope( requestor ); - } - return linkage; - } - // single declaration - - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0; - IASTLinkageSpecification linkage; - try - { - linkage = - astFactory.createLinkageSpecification( - scope, - spec.getCharImage(), - firstToken.getOffset(), firstToken.getLineNumber(), firstToken.getFilename()); - } - catch (Exception e) - { - logException( "linkageSpecification_2:createLinkageSpecification", e ); //$NON-NLS-1$ - throwBacktrack(firstToken.getOffset(), endOffset, firstToken.getLineNumber(), firstToken.getFilename()); - return null; - } - linkage.enterScope( requestor ); - try - { - declaration(linkage, null, null, KeywordSetKey.DECLARATION); - } - finally - { - linkage.exitScope( requestor ); - } - return linkage; - - } - /** - * - * Represents the emalgamation of template declarations, template - * instantiations and specializations in the ANSI C++ grammar. - * - * template-declaration: export? template < template-parameter-list > - * declaration explicit-instantiation: template declaration - * explicit-specialization: template <>declaration - * - * @param container - * Callback object representing the scope these definitions fall - * into. - * @return TODO - * @throws BacktrackException - * request for a backtrack - */ - protected IASTDeclaration templateDeclaration(IASTScope scope) - throws EndOfFileException, BacktrackException - { - IToken mark = mark(); - IToken firstToken = null; - boolean exported = false; - if (LT(1) == IToken.t_export) - { - exported = true; - firstToken = consume(IToken.t_export); - consume(IToken.t_template); - } - else - { - if( extension.supportsExtendedTemplateInstantiationSyntax() && extension.isValidModifierForInstantiation(LA(1))) - { - firstToken = consume(); // consume the modifier - consume( IToken.t_template ); - } - else - firstToken = consume(IToken.t_template); - } - if (LT(1) != IToken.tLT) - { - // explicit-instantiation - IASTTemplateInstantiation templateInstantiation; - try - { - templateInstantiation = - astFactory.createTemplateInstantiation( - scope, - firstToken.getOffset(), firstToken.getLineNumber(), firstToken.getFilename()); - } - catch (Exception e) - { - logException( "templateDeclaration:createTemplateInstantiation", e ); //$NON-NLS-1$ - backup( mark ); - throwBacktrack(firstToken.getOffset(), firstToken.getEndOffset(), firstToken.getLineNumber(), firstToken.getFilename()); - return null; - } - templateInstantiation.enterScope( requestor ); - try - { - declaration(templateInstantiation, templateInstantiation, null, KeywordSetKey.DECLARATION); - templateInstantiation.setEndingOffsetAndLineNumber(lastToken.getEndOffset(), lastToken.getLineNumber()); - } finally - { - templateInstantiation.exitScope( requestor ); - } - - return templateInstantiation; - } - consume(IToken.tLT); - if (LT(1) == IToken.tGT) - { - IToken gt = consume(IToken.tGT); - // explicit-specialization - - IASTTemplateSpecialization templateSpecialization; - try - { - templateSpecialization = - astFactory.createTemplateSpecialization( - scope, - firstToken.getOffset(), firstToken.getLineNumber(), firstToken.getFilename()); - } - catch (Exception e) - { - logException( "templateDeclaration:createTemplateSpecialization", e ); //$NON-NLS-1$ - backup( mark ); - throwBacktrack(firstToken.getOffset(), gt.getEndOffset(), gt.getLineNumber(), gt.getFilename()); - return null; - } - templateSpecialization.enterScope(requestor); - try - { - declaration(templateSpecialization, templateSpecialization, null, KeywordSetKey.DECLARATION); - templateSpecialization.setEndingOffsetAndLineNumber( - lastToken.getEndOffset(), lastToken.getLineNumber()); - } - finally - { - templateSpecialization.exitScope(requestor); - } - return templateSpecialization; - } - - - try - { - List parms = templateParameterList(scope); - IToken gt = consume(IToken.tGT); - IASTTemplateDeclaration templateDecl; - try - { - templateDecl = - astFactory.createTemplateDeclaration( - scope, - parms, - exported, - firstToken.getOffset(), firstToken.getLineNumber(), firstToken.getFilename()); - } - catch (Exception e) - { - logException( "templateDeclaration:createTemplateDeclaration", e ); //$NON-NLS-1$ - throwBacktrack(firstToken.getOffset(), gt.getEndOffset(), gt.getLineNumber(), gt.getFilename()); - return null; - } - templateDecl.enterScope( requestor ); - try{ - declaration(templateDecl, templateDecl, null, KeywordSetKey.DECLARATION ); - templateDecl.setEndingOffsetAndLineNumber( lastToken.getEndOffset(), lastToken.getLineNumber() ); - } finally - { - templateDecl.exitScope( requestor ); - } - return templateDecl; - } - catch (BacktrackException bt) - { - backup( mark ); - throw bt; - } - } - /** - * - * - * - * template-parameter-list: template-parameter template-parameter-list , - * template-parameter template-parameter: type-parameter - * parameter-declaration type-parameter: class identifier? class identifier? = - * type-id typename identifier? typename identifier? = type-id template < - * template-parameter-list > class identifier? template < - * template-parameter-list > class identifier? = id-expression template-id: - * template-name < template-argument-list?> template-name: identifier - * template-argument-list: template-argument template-argument-list , - * template-argument template-argument: assignment-expression type-id - * id-expression - * - * @param templateDeclaration - * Callback's templateDeclaration which serves as a scope to this - * list. - * @throws BacktrackException - * request for a backtrack - */ - protected List templateParameterList(IASTScope scope) - throws BacktrackException, EndOfFileException - { - // if we have gotten this far then we have a true template-declaration - // iterate through the template parameter list - List returnValue = new ArrayList(); - - IASTScope parameterScope = astFactory.createNewCodeBlock( scope ); - if( parameterScope == null ) - parameterScope = scope; - - IToken la = LA(1); - int startingOffset = la.getOffset(); - int lnum = la.getLineNumber(); - char [] fn = la.getFilename(); - - for (;;) - { - if (LT(1) == IToken.tGT) - return returnValue; - if (LT(1) == IToken.t_class || LT(1) == IToken.t_typename) - { - IASTTemplateParameter.ParamKind kind = (consume().getType() == IToken.t_class) - ? IASTTemplateParameter.ParamKind.CLASS - : IASTTemplateParameter.ParamKind.TYPENAME; - IToken startingToken = lastToken; - IToken id = null; - IASTTypeId typeId = null; - try - { - if (LT(1) == IToken.tIDENTIFIER) // optional identifier - { - id = identifier(); - - if (LT(1) == IToken.tASSIGN) // optional = type-id - { - consume(IToken.tASSIGN); - typeId = typeId(parameterScope, false, CompletionKind.TYPE_REFERENCE); // type-id - } - } - - } - catch (BacktrackException bt) - { - throw bt; - } - try - { - int nameStart = (id != null) ? id.getOffset() : 0; - int nameEnd = (id != null) ? id.getEndOffset() : 0; - int nameLine = (id != null) ? id.getLineNumber() : 0; - returnValue.add( - astFactory.createTemplateParameter( - kind, - ( id == null )? EMPTY_STRING : id.getCharImage(), //$NON-NLS-1$ - typeId, - null, - null, - ( parameterScope instanceof IASTCodeScope ) ? (IASTCodeScope) parameterScope : null, - startingToken.getOffset(), startingToken.getLineNumber(), - nameStart, nameEnd, nameLine, - (lastToken != null ) ? lastToken.getEndOffset() : nameEnd, - (lastToken != null ) ? lastToken.getLineNumber() : nameLine, startingToken.getFilename() )); - } - catch( ASTSemanticException ase ) - { - throwBacktrack(ase.getProblem()); - } - catch (Exception e) - { - logException( "templateParameterList_1:createTemplateParameter", e ); //$NON-NLS-1$ - throwBacktrack(startingOffset, ( lastToken != null ) ? lastToken.getEndOffset() : 0, lnum, fn); - } - - } - else if (LT(1) == IToken.t_template) - { - consume(IToken.t_template); - IToken startingToken = lastToken; - consume(IToken.tLT); - - List subResult = templateParameterList(parameterScope); - consume(IToken.tGT); - consume(IToken.t_class); - IToken optionalId = null; - IASTTypeId optionalTypeId = null; - if (LT(1) == IToken.tIDENTIFIER) // optional identifier - { - optionalId = identifier(); - - if (LT(1) == IToken.tASSIGN) // optional = type-id - { - consume(IToken.tASSIGN); - optionalTypeId = typeId(parameterScope, false, CompletionKind.TYPE_REFERENCE); - - } - } - - try - { - returnValue.add( - astFactory.createTemplateParameter( - IASTTemplateParameter.ParamKind.TEMPLATE_LIST, - ( optionalId == null )? EMPTY_STRING : optionalId.getCharImage(), //$NON-NLS-1$ - optionalTypeId, - null, - subResult, - ( parameterScope instanceof IASTCodeScope ) ? (IASTCodeScope) parameterScope : null, - startingToken.getOffset(), startingToken.getLineNumber(), - (optionalId != null) ? optionalId.getOffset() : 0, - (optionalId != null) ? optionalId.getEndOffset() : 0, - (optionalId != null) ? optionalId.getLineNumber() : 0, - lastToken.getEndOffset(), lastToken.getLineNumber(), lastToken.getFilename() )); - } - catch( ASTSemanticException ase ) - { - throwBacktrack(ase.getProblem()); - } - catch (Exception e) - { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException( "templateParameterList_2:createTemplateParameter", e ); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, lnum, fn); - } - } - else if (LT(1) == IToken.tCOMMA) - { - consume(IToken.tCOMMA); - continue; - } - else - { - ParameterCollection c = new ParameterCollection(); - parameterDeclaration(c, parameterScope); - DeclarationWrapper wrapper = (DeclarationWrapper)c.getParameters().get(0); - Declarator declarator = (Declarator)wrapper.getDeclarators().next(); - try - { - returnValue.add( - astFactory.createTemplateParameter( - IASTTemplateParameter.ParamKind.PARAMETER, - null, - null, - astFactory.createParameterDeclaration( - wrapper.isConst(), - wrapper.isVolatile(), - wrapper.getTypeSpecifier(), - declarator.getPointerOperators(), - declarator.getArrayModifiers(), - null, null, - declarator.getName(), - declarator.getInitializerClause(), - wrapper.getStartingOffset(), wrapper.getStartingLine(), - declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), - wrapper.getEndOffset(), wrapper.getEndLine(), fn ), - null, - ( parameterScope instanceof IASTCodeScope ) ? (IASTCodeScope) parameterScope : null, - wrapper.getStartingOffset(), wrapper.getStartingLine(), - declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), - wrapper.getEndOffset(), wrapper.getEndLine(), fn )); - } - catch( ASTSemanticException ase ) - { - throwBacktrack(ase.getProblem()); - } - catch (Exception e) - { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException( "templateParameterList:createParameterDeclaration", e ); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, lnum, fn); - } - } - } - } - /** - * The most abstract construct within a translationUnit : a declaration. - * - * declaration : {"asm"} asmDefinition | {"namespace"} namespaceDefinition | - * {"using"} usingDeclaration | {"export"|"template"} templateDeclaration | - * {"extern"} linkageSpecification | simpleDeclaration - * - * Notes: - folded in blockDeclaration - merged alternatives that required - * same LA - functionDefinition into simpleDeclaration - - * namespaceAliasDefinition into namespaceDefinition - usingDirective into - * usingDeclaration - explicitInstantiation and explicitSpecialization into - * templateDeclaration - * - * @param overideKey - * TODO - * @param container - * IParserCallback object which serves as the owner scope for - * this declaration. - * - * @throws BacktrackException - * request a backtrack - */ - protected void declaration( - IASTScope scope, - IASTTemplate ownerTemplate, CompletionKind overideKind, KeywordSetKey overideKey) - throws EndOfFileException, BacktrackException - { - - IASTCompletionNode.CompletionKind kind = getCompletionKindForDeclaration(scope, overideKind); - setCompletionValues(scope, kind, overideKey); - IASTDeclaration resultDeclaration = null; - switch (LT(1)) - { - case IToken.t_asm : - IToken first = consume(IToken.t_asm); - setCompletionValues( scope, CompletionKind.NO_SUCH_KIND, KeywordSetKey.EMPTY ); - consume(IToken.tLPAREN); - char[] assembly = consume(IToken.tSTRING).getCharImage(); - consume(IToken.tRPAREN); - IToken last = consume(IToken.tSEMI); - - try - { - resultDeclaration = - astFactory.createASMDefinition( - scope, - assembly, - first.getOffset(), - first.getLineNumber(), last.getEndOffset(), last.getLineNumber(), last.getFilename()); - } - catch (Exception e) - { - logException( "declaration:createASMDefinition", e ); //$NON-NLS-1$ - throwBacktrack(first.getOffset(), last.getEndOffset(), first.getLineNumber(), first.getFilename()); - } - // if we made it this far, then we have all we need - // do the callback - resultDeclaration.acceptElement(requestor); - setCompletionValues(scope, kind, KeywordSetKey.DECLARATION ); - break; - case IToken.t_namespace : - resultDeclaration = namespaceDefinition(scope); - break; - case IToken.t_using : - resultDeclaration = usingClause(scope); - break; - case IToken.t_export : - case IToken.t_template : - resultDeclaration = templateDeclaration(scope); - break; - case IToken.t_extern : - if (LT(2) == IToken.tSTRING) - { - resultDeclaration = linkageSpecification(scope); - break; - } - default : - if( extension.supportsExtendedTemplateInstantiationSyntax() && extension.isValidModifierForInstantiation(LA(1)) && LT(2) == IToken.t_template ) - resultDeclaration = templateDeclaration(scope); - else - resultDeclaration = simpleDeclarationStrategyUnion(scope, ownerTemplate, overideKind, overideKey); - } - setCompletionValues(scope, kind, KeywordSetKey.DECLARATION ); - endDeclaration( resultDeclaration ); - } - - - protected IASTDeclaration simpleDeclarationStrategyUnion( - IASTScope scope, - IASTTemplate ownerTemplate, CompletionKind overrideKind, KeywordSetKey overrideKey) - throws EndOfFileException, BacktrackException - { - simpleDeclarationMark = mark(); - IProblem firstFailure = null; - IProblem secondFailure = null; - try - { - return simpleDeclaration( - SimpleDeclarationStrategy.TRY_CONSTRUCTOR, - scope, - ownerTemplate, overrideKind, false, overrideKey); - // try it first with the original strategy - } - catch (BacktrackException bt) - { - if( simpleDeclarationMark == null ) - throwBacktrack( bt ); - firstFailure = bt.getProblem(); - // did not work - backup(simpleDeclarationMark); - - try - { - return simpleDeclaration( - SimpleDeclarationStrategy.TRY_FUNCTION, - scope, - ownerTemplate, overrideKind, false, overrideKey); - } - catch( BacktrackException bt2 ) - { - if( simpleDeclarationMark == null ) - { - if( firstFailure != null && (bt2.getProblem() == null )) - throwBacktrack(firstFailure); - else - throwBacktrack(bt2); - } - - secondFailure = bt2.getProblem(); - backup( simpleDeclarationMark ); - - try - { - return simpleDeclaration( - SimpleDeclarationStrategy.TRY_VARIABLE, - scope, - ownerTemplate, overrideKind, false, overrideKey); - } - catch( BacktrackException b3 ) - { - backup( simpleDeclarationMark ); //TODO - necessary? - - if( firstFailure != null ) - throwBacktrack( firstFailure ); - else if( secondFailure != null ) - throwBacktrack( secondFailure ); - else - throwBacktrack( b3 ); - return null; - } - } - - } - } - /** - * Serves as the namespace declaration portion of the ANSI C++ grammar. - * - * namespace-definition: namespace identifier { namespace-body } | namespace { - * namespace-body } namespace-body: declaration-seq? - * - * @param container - * IParserCallback object which serves as the owner scope for - * this declaration. - * @return TODO - * @throws BacktrackException - * request a backtrack - * - */ - protected IASTDeclaration namespaceDefinition(IASTScope scope) - throws BacktrackException, EndOfFileException - { - IToken first = consume(IToken.t_namespace); - - IASTCompletionNode.CompletionKind kind = getCompletionKindForDeclaration(scope, null); - - setCompletionValues(scope,CompletionKind.NAMESPACE_REFERENCE, KeywordSetKey.EMPTY ); - IToken identifier = null; - // optional name - if (LT(1) == IToken.tIDENTIFIER) - identifier = identifier(); - - if (LT(1) == IToken.tLBRACE) - { - IToken lbrace = consume(); - IASTNamespaceDefinition namespaceDefinition = null; - try - { - namespaceDefinition = - astFactory.createNamespaceDefinition( - scope, - (identifier == null ? EMPTY_STRING: identifier.getCharImage()), //$NON-NLS-1$ - first.getOffset(), - first.getLineNumber(), - (identifier == null ? first.getOffset() : identifier.getOffset()), - (identifier == null ? first.getEndOffset() : identifier.getEndOffset() ), - (identifier == null ? first.getLineNumber() : identifier.getLineNumber() ), first.getFilename()); - } - catch (Exception e1) - { - - logException( "namespaceDefinition:createNamespaceDefinition", e1 ); //$NON-NLS-1$ - throwBacktrack(first.getOffset(), lbrace.getEndOffset(), first.getLineNumber(), first.getFilename()); - return null; - } - namespaceDefinition.enterScope( requestor ); - try - { - setCompletionValues(scope,CompletionKind.VARIABLE_TYPE, KeywordSetKey.DECLARATION ); - endDeclaration( namespaceDefinition ); - namespaceDeclarationLoop : while (LT(1) != IToken.tRBRACE) - { - int checkToken = LA(1).hashCode(); - switch (LT(1)) - { - case IToken.tRBRACE : - //consume(Token.tRBRACE); - break namespaceDeclarationLoop; - default : - try - { - declaration(namespaceDefinition, null, null, KeywordSetKey.DECLARATION); - } - catch (BacktrackException bt) - { - failParse(bt); - if (checkToken == LA(1).hashCode()) - failParseWithErrorHandling(); - } - } - if (checkToken == LA(1).hashCode()) - failParseWithErrorHandling(); - } - setCompletionValues(scope, CompletionKind.NO_SUCH_KIND,KeywordSetKey.EMPTY ); - // consume the } - IToken last = consume(IToken.tRBRACE); - - namespaceDefinition.setEndingOffsetAndLineNumber( - last.getOffset() + last.getLength(), last.getLineNumber()); - setCompletionValues(scope, kind, KeywordSetKey.DECLARATION ); - } - finally - { - namespaceDefinition.exitScope( requestor ); - } - return namespaceDefinition; - } - else if( LT(1) == IToken.tASSIGN ) - { - setCompletionValues(scope, CompletionKind.NO_SUCH_KIND,KeywordSetKey.EMPTY); - IToken assign = consume( IToken.tASSIGN ); - - if( identifier == null ) - { - throwBacktrack(first.getOffset(), assign.getEndOffset(), first.getLineNumber(), first.getFilename()); - return null; - } - - ITokenDuple duple = name(scope, CompletionKind.NAMESPACE_REFERENCE, KeywordSetKey.EMPTY); - IToken semi = consume( IToken.tSEMI ); - setCompletionValues(scope, kind, KeywordSetKey.DECLARATION ); - IASTNamespaceAlias alias = null; - try - { - alias = astFactory.createNamespaceAlias( - scope, identifier.getCharImage(), duple, first.getOffset(), - first.getLineNumber(), identifier.getOffset(), identifier.getEndOffset(), identifier.getLineNumber(), duple.getLastToken().getEndOffset(), duple.getLastToken().getLineNumber() ); - } - catch (Exception e1) - { - logException( "namespaceDefinition:createNamespaceAlias", e1 ); //$NON-NLS-1$ - throwBacktrack(first.getOffset(), semi.getEndOffset(), first.getLineNumber(), first.getFilename()); - return null; - } - return alias; - } - else - { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - throwBacktrack(first.getOffset(), endOffset, first.getLineNumber(), first.getFilename()); - return null; - } - } - /** - * Serves as the catch-all for all complicated declarations, including - * function-definitions. - * - * simpleDeclaration : (declSpecifier)* (initDeclarator ("," - * initDeclarator)*)? (";" | { functionBody } - * - * Notes: - append functionDefinition stuff to end of this rule - * - * To do: - work in functionTryBlock - * - * @param container - * IParserCallback object which serves as the owner scope for - * this declaration. - * @param tryConstructor - * true == take strategy1 (constructor ) : false == take strategy - * 2 ( pointer to function) - * @return TODO - * @throws BacktrackException - * request a backtrack - */ - protected IASTDeclaration simpleDeclaration( - SimpleDeclarationStrategy strategy, - IASTScope scope, - IASTTemplate ownerTemplate, CompletionKind overideKind, boolean fromCatchHandler, KeywordSetKey overrideKey) - throws BacktrackException, EndOfFileException - { - IToken firstToken = LA(1); - int firstOffset = firstToken.getOffset(); - int firstLine = firstToken.getLineNumber(); - char [] fn = firstToken.getFilename(); - if( firstToken.getType() == IToken.tLBRACE ) throwBacktrack(firstToken.getOffset(), firstToken.getEndOffset(), firstToken.getLineNumber(), firstToken.getFilename()); - DeclarationWrapper sdw = - new DeclarationWrapper(scope, firstToken.getOffset(), firstToken.getLineNumber(), ownerTemplate, fn); - firstToken = null; // necessary for scalability - - CompletionKind completionKindForDeclaration = getCompletionKindForDeclaration(scope, overideKind); - setCompletionValues( scope, completionKindForDeclaration, KeywordSetKey.DECL_SPECIFIER_SEQUENCE ); - declSpecifierSeq(sdw, false, strategy == SimpleDeclarationStrategy.TRY_CONSTRUCTOR, completionKindForDeclaration, overrideKey ); - IASTSimpleTypeSpecifier simpleTypeSpecifier = null; - if (sdw.getTypeSpecifier() == null && sdw.getSimpleType() != IASTSimpleTypeSpecifier.Type.UNSPECIFIED ) - try - { - simpleTypeSpecifier = astFactory.createSimpleTypeSpecifier( - scope, - sdw.getSimpleType(), - sdw.getName(), - sdw.isShort(), - sdw.isLong(), - sdw.isSigned(), - sdw.isUnsigned(), - sdw.isTypeNamed(), - sdw.isComplex(), - sdw.isImaginary(), - sdw.isGloballyQualified(), sdw.getExtensionParameters()); - sdw.setTypeSpecifier( - simpleTypeSpecifier); - sdw.setTypeName( null ); - } - catch (Exception e1) - { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException( "simpleDeclaration:createSimpleTypeSpecifier", e1 ); //$NON-NLS-1$ - if( e1 instanceof ASTSemanticException && ((ASTSemanticException)e1).getProblem() != null ) - throwBacktrack(((ASTSemanticException)e1).getProblem()); - else - throwBacktrack(firstOffset, endOffset, firstLine, fn); - } - - try { - Declarator declarator = null; - if (LT(1) != IToken.tSEMI) - { - declarator = initDeclarator(sdw, strategy, completionKindForDeclaration, constructInitializersInDeclarations); - - while (LT(1) == IToken.tCOMMA) - { - consume(); - initDeclarator(sdw, strategy, completionKindForDeclaration, constructInitializersInDeclarations ); - } - } - - boolean hasFunctionBody = false; - boolean hasFunctionTryBlock = false; - boolean consumedSemi = false; - - switch (LT(1)) - { - case IToken.tSEMI : - consume(IToken.tSEMI); - consumedSemi = true; - break; - case IToken.t_try : - consume( IToken.t_try ); - if( LT(1) == IToken.tCOLON ) - ctorInitializer( declarator ); - hasFunctionTryBlock = true; - declarator.setFunctionTryBlock( true ); - break; - case IToken.tCOLON : - ctorInitializer(declarator); - break; - case IToken.tLBRACE: - break; - case IToken.tRPAREN: - if( ! fromCatchHandler ) - throwBacktrack(firstOffset, LA(1).getEndOffset(), LA(1).getLineNumber(), fn); - break; - default: - throwBacktrack(firstOffset, LA(1).getEndOffset(), LA(1).getLineNumber(), fn); - } - - if( ! consumedSemi ) - { - if( LT(1) == IToken.tLBRACE ) - { - declarator.setHasFunctionBody(true); - hasFunctionBody = true; - } - - if( hasFunctionTryBlock && ! hasFunctionBody ) - throwBacktrack(firstOffset, LA(1).getEndOffset(), LA(1).getLineNumber(), fn); - } - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - List l = null; - try - { - l = sdw.createASTNodes(astFactory); - } - catch (ASTSemanticException e) - { - if( e.getProblem() == null ) - { - IProblem p = problemFactory.createProblem( IProblem.SYNTAX_ERROR, - sdw.getStartingOffset(), - lastToken != null ? lastToken.getEndOffset() : 0, - sdw.getStartingLine(), - fn, - EMPTY_STRING, false, true ); - throwBacktrack( p ); - } else { - throwBacktrack(e.getProblem()); - } - } - catch( Exception e ) - { - logException( "simpleDecl", e ); //$NON-NLS-1$ - throwBacktrack(firstOffset, endOffset, firstLine, fn); - } - - if (hasFunctionBody && l.size() != 1) - { - throwBacktrack(firstOffset, endOffset, firstLine, fn); //TODO Should be an IProblem - } - if (!l.isEmpty()) // no need to do this unless we have a declarator - { - if (!hasFunctionBody || fromCatchHandler) - { - IASTDeclaration declaration = null; - for( int i = 0; i < l.size(); ++i ) - { - declaration = (IASTDeclaration)l.get(i); - ((IASTOffsetableElement)declaration).setEndingOffsetAndLineNumber( - lastToken.getEndOffset(), lastToken.getLineNumber()); - declaration.acceptElement( requestor ); - } - return declaration; - } - IASTDeclaration declaration = (IASTDeclaration)l.get(0); - endDeclaration( declaration ); - declaration.enterScope( requestor ); - try - { - if ( !( declaration instanceof IASTScope ) ) - throwBacktrack(firstOffset, endOffset, firstLine, fn); - - handleFunctionBody((IASTScope)declaration ); - ((IASTOffsetableElement)declaration).setEndingOffsetAndLineNumber( - lastToken.getEndOffset(), lastToken.getLineNumber()); - } - finally - { - declaration.exitScope( requestor ); - } - - if( hasFunctionTryBlock ) - catchHandlerSequence( scope ); - - return declaration; - - } - - try - { - if( sdw.getTypeSpecifier() != null ) - { - IASTAbstractTypeSpecifierDeclaration declaration = astFactory.createTypeSpecDeclaration( - sdw.getScope(), - sdw.getTypeSpecifier(), - ownerTemplate, - sdw.getStartingOffset(), - sdw.getStartingLine(), lastToken.getEndOffset(), lastToken.getLineNumber(), - sdw.isFriend(), lastToken.getFilename()); - declaration.acceptElement(requestor); - return declaration; - } - } - catch (Exception e1) - { - logException( "simpleDeclaration:createTypeSpecDeclaration", e1 ); //$NON-NLS-1$ - throwBacktrack(firstOffset, endOffset, firstLine, fn); - } - - return null; - } catch( BacktrackException be ) - { - throwBacktrack(be); - return null; - } - catch( EndOfFileException eof ) - { - throw eof; - } - } - - - protected void handleFunctionBody(IASTScope scope) throws BacktrackException, EndOfFileException - { - if( mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE ) - skipOverCompoundStatement(); - else if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - { - if( scanner.isOnTopContext() ) - functionBody(scope); - else - skipOverCompoundStatement(); - } - else if( mode == ParserMode.COMPLETE_PARSE ) - functionBody(scope); - - - } - - protected void skipOverCompoundStatement() throws BacktrackException, EndOfFileException - { - // speed up the parser by skiping the body - // simply look for matching brace and return - consume(IToken.tLBRACE); - int depth = 1; - while (depth > 0) - { - switch (consume().getType()) - { - case IToken.tRBRACE : - --depth; - break; - case IToken.tLBRACE : - ++depth; - break; - } - } - } - /** - * This method parses a constructor chain ctorinitializer: : - * meminitializerlist meminitializerlist: meminitializer | meminitializer , - * meminitializerlist meminitializer: meminitializerid | ( expressionlist? ) - * meminitializerid: ::? nestednamespecifier? classname identifier - * - * @param declarator - * IParserCallback object that represents the declarator - * (constructor) that owns this initializer - * @throws BacktrackException - * request a backtrack - */ - protected void ctorInitializer(Declarator d ) - throws EndOfFileException, BacktrackException - { - int startingOffset = consume(IToken.tCOLON).getOffset(); - IASTScope scope = d.getDeclarationWrapper().getScope(); - scope = astFactory.getDeclaratorScope(scope, d.getNameDuple()); - for (;;) - { - if (LT(1) == IToken.tLBRACE) - break; - - - ITokenDuple duple = name(scope, CompletionKind.SINGLE_NAME_REFERENCE, KeywordSetKey.EMPTY ); - - consume(IToken.tLPAREN); - IASTExpression expressionList = null; - - if( LT(1) != IToken.tRPAREN ) - expressionList = expression(scope, CompletionKind.SINGLE_NAME_REFERENCE, KeywordSetKey.EXPRESSION); - - IToken rparen = consume(IToken.tRPAREN); - - try - { - d.addConstructorMemberInitializer( - astFactory.createConstructorMemberInitializer(scope, duple, expressionList) ); - } - catch (Exception e1) - { - logException( "ctorInitializer:addConstructorMemberInitializer", e1 ); //$NON-NLS-1$ - throwBacktrack(startingOffset, rparen.getEndOffset(), rparen.getLineNumber(), rparen.getFilename()); - } - if (LT(1) == IToken.tLBRACE) - break; - consume(IToken.tCOMMA); - } - - } - - protected boolean constructInitializersInParameters = true; - protected boolean constructInitializersInDeclarations = true; - /** - * This routine parses a parameter declaration - * - * @param containerObject - * The IParserCallback object representing the - * parameterDeclarationClause owning the parm. - * @throws BacktrackException - * request a backtrack - */ - protected void parameterDeclaration( - IParameterCollection collection, IASTScope scope) - throws BacktrackException, EndOfFileException - { - IToken current = LA(1); - - DeclarationWrapper sdw = - new DeclarationWrapper(scope, current.getOffset(), current.getLineNumber(), null, current.getFilename()); - declSpecifierSeq(sdw, true, false, CompletionKind.ARGUMENT_TYPE, KeywordSetKey.DECL_SPECIFIER_SEQUENCE ); - if (sdw.getTypeSpecifier() == null - && sdw.getSimpleType() - != IASTSimpleTypeSpecifier.Type.UNSPECIFIED) - try - { - sdw.setTypeSpecifier( - astFactory.createSimpleTypeSpecifier( - scope, - sdw.getSimpleType(), - sdw.getName(), - sdw.isShort(), - sdw.isLong(), - sdw.isSigned(), - sdw.isUnsigned(), - sdw.isTypeNamed(), - sdw.isComplex(), - sdw.isImaginary(), - sdw.isGloballyQualified(), null)); - } - catch (ASTSemanticException e) - { - throwBacktrack(e.getProblem()); - } - catch (Exception e) - { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException( "parameterDeclaration:createSimpleTypeSpecifier", e ); //$NON-NLS-1$ - throwBacktrack(current.getOffset(), endOffset, current.getLineNumber(), current.getFilename()); - } - - setCompletionValues(scope,CompletionKind.SINGLE_NAME_REFERENCE,KeywordSetKey.EMPTY ); - if (LT(1) != IToken.tSEMI) - initDeclarator(sdw, SimpleDeclarationStrategy.TRY_FUNCTION, CompletionKind.VARIABLE_TYPE, constructInitializersInParameters ); - - if( lastToken != null ) - sdw.setEndingOffsetAndLineNumber( lastToken.getEndOffset(), lastToken.getLineNumber() ); - - if (current == LA(1)) - { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - throwBacktrack(current.getOffset(), endOffset, current.getLineNumber(), current.getFilename()); - } - collection.addParameter(sdw); - } - /** - * This class represents the state and strategy for parsing - * declarationSpecifierSequences - */ - public static class Flags - { - private boolean encounteredTypename = false; - // have we encountered a typeName yet? - private boolean encounteredRawType = false; - // have we encountered a raw type yet? - private final boolean parm; - // is this for a simpleDeclaration or parameterDeclaration? - private final boolean constructor; - // are we attempting the constructor strategy? - public Flags(boolean parm, boolean c) - { - this.parm = parm; - constructor = c; - } - /** - * @return true if we have encountered a simple type up to this point, - * false otherwise - */ - public boolean haveEncounteredRawType() - { - return encounteredRawType; - } - /** - * @return true if we have encountered a typename up to this point, - * false otherwise - */ - public boolean haveEncounteredTypename() - { - return encounteredTypename; - } - /** - * @param b - - * set to true if we encounter a raw type (int, short, etc.) - */ - public void setEncounteredRawType(boolean b) - { - encounteredRawType = b; - } - /** - * @param b - - * set to true if we encounter a typename - */ - public void setEncounteredTypename(boolean b) - { - encounteredTypename = b; - } - /** - * @return true if we are parsing for a ParameterDeclaration - */ - public boolean isForParameterDeclaration() - { - return parm; - } - /** - * @return whether or not we are attempting the constructor strategy or - * not - */ - public boolean isForConstructor() - { - return constructor; - } - } - /** - * @param flags - * input flags that are used to make our decision - * @return whether or not this looks like a constructor (true or false) - * @throws EndOfFileException - * we could encounter EOF while looking ahead - */ - private boolean lookAheadForConstructorOrConversion(Flags flags, - DeclarationWrapper sdw, CompletionKind kind) - throws EndOfFileException { - if (flags.isForParameterDeclaration()) - return false; - if (queryLookaheadCapability(2) && LT(2) == IToken.tLPAREN - && flags.isForConstructor()) - return true; - - IToken mark = mark(); - Declarator d = new Declarator(sdw); - try { - try { - consumeTemplatedOperatorName(d, kind); - } catch (BacktrackException e) { - backup(mark); - return false; - } catch (EndOfFileException eof) { - backup(mark); - return false; - } - - ITokenDuple duple = d.getNameDuple(); - if (duple == null) { - backup(mark); - return false; - } - - int lastColon = duple.findLastTokenType(IToken.tCOLON); - if (lastColon == -1) { - int lt1 = LT(1); - backup(mark); - return flags.isForConstructor() && (lt1 == IToken.tLPAREN); - } - - IToken className = null; - int index = lastColon - 1; - if (duple.getToken(index).getType() == IToken.tGT) { - int depth = -1; - while (depth == -1) { - if (duple.getToken(--index).getType() == IToken.tLT) - ++depth; - } - className = duple.getToken(index); - } - - boolean result = CharArrayUtils.equals( className.getCharImage(), duple.getLastToken().getCharImage() ); - backup(mark); - return result; - } finally { - if (d.getNameDuple() != null - && d.getNameDuple().getTemplateIdArgLists() != null) { - List[] arrayOfLists = d.getNameDuple().getTemplateIdArgLists(); - for (int i = 0; i < arrayOfLists.length; ++i) { - if (arrayOfLists[i] == null) - continue; - for (int j = 0; j < arrayOfLists[i].size(); ++j) { - IASTExpression e = (IASTExpression) arrayOfLists[i] - .get(j); - e.freeReferences(); - - } - } - } - } - } - /** - * @param flags - * input flags that are used to make our decision - * @return whether or not this looks like a a declarator follows - * @throws EndOfFileException - * we could encounter EOF while looking ahead - */ - private boolean lookAheadForDeclarator(Flags flags) - throws EndOfFileException { - return flags.haveEncounteredTypename() - && ((LT(2) != IToken.tIDENTIFIER || (LT(3) != IToken.tLPAREN && LT(3) != IToken.tASSIGN)) && !LA( - 2).isPointer()); - } - /** - * This function parses a declaration specifier sequence, as according to - * the ANSI C++ spec. - * - * declSpecifier : "auto" | "register" | "static" | "extern" | "mutable" | - * "inline" | "virtual" | "explicit" | "char" | "wchar_t" | "bool" | "short" | - * "int" | "long" | "signed" | "unsigned" | "float" | "double" | "void" | - * "const" | "volatile" | "friend" | "typedef" | ("typename")? name | - * {"class"|"struct"|"union"} classSpecifier | {"enum"} enumSpecifier - * - * Notes: - folded in storageClassSpecifier, typeSpecifier, - * functionSpecifier - folded elaboratedTypeSpecifier into classSpecifier - * and enumSpecifier - find template names in name - * - * @param decl - * IParserCallback object representing the declaration that owns - * this specifier sequence - * @param parm - * Is this for a parameter declaration (true) or simple - * declaration (false) - * @param tryConstructor - * true for constructor, false for pointer to function strategy - * @throws BacktrackException - * request a backtrack - */ - protected void declSpecifierSeq(DeclarationWrapper sdw, boolean parm, - boolean tryConstructor, CompletionKind kind, KeywordSetKey key) - throws BacktrackException, EndOfFileException { - Flags flags = new Flags(parm, tryConstructor); - IToken typeNameBegin = null; - IToken typeNameEnd = null; - declSpecifiers : for (;;) { - switch (LT(1)) { - case IToken.t_inline : - consume(); - sdw.setInline(true); - break; - case IToken.t_auto : - consume(); - sdw.setAuto(true); - break; - case IToken.t_register : - sdw.setRegister(true); - consume(); - break; - case IToken.t_static : - sdw.setStatic(true); - consume(); - break; - case IToken.t_extern : - sdw.setExtern(true); - consume(); - break; - case IToken.t_mutable : - sdw.setMutable(true); - consume(); - break; - case IToken.t_virtual : - sdw.setVirtual(true); - consume(); - break; - case IToken.t_explicit : - sdw.setExplicit(true); - consume(); - break; - case IToken.t_typedef : - sdw.setTypedef(true); - consume(); - break; - case IToken.t_friend : - sdw.setFriend(true); - consume(); - break; - case IToken.t_const : - sdw.setConst(true); - consume(); - break; - case IToken.t_volatile : - sdw.setVolatile(true); - consume(); - break; - case IToken.t_signed : - sdw.setSigned(true); - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT); - break; - case IToken.t_unsigned : - sdw.setUnsigned(true); - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT); - break; - case IToken.t_short : - sdw.setShort(true); - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT); - break; - case IToken.t_long : - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT); - sdw.setLong(true); - break; - case IToken.t__Complex : - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - consume(IToken.t__Complex); - sdw.setComplex(true); - break; - case IToken.t__Imaginary : - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - consume(IToken.t__Imaginary); - sdw.setImaginary(true); - break; - case IToken.t_char : - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.CHAR); - break; - case IToken.t_wchar_t : - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.WCHAR_T); - break; - case IToken.t_bool : - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.BOOL); - break; - case IToken.t__Bool : - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type._BOOL); - break; - case IToken.t_int : - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.INT); - break; - case IToken.t_float : - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.FLOAT); - break; - case IToken.t_double : - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.DOUBLE); - break; - case IToken.t_void : - if (typeNameBegin == null) - typeNameBegin = LA(1); - typeNameEnd = LA(1); - flags.setEncounteredRawType(true); - consume(); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.VOID); - break; - case IToken.t_typename : - sdw.setTypenamed(true); - consume(IToken.t_typename); - ITokenDuple duple = name(sdw.getScope(), CompletionKind.TYPE_REFERENCE, - KeywordSetKey.EMPTY); - sdw.setTypeName(duple); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME); - flags.setEncounteredTypename(true); - break; - case IToken.tCOLONCOLON : - sdw.setGloballyQualified(true); - consume(IToken.tCOLONCOLON); - break; - case IToken.tIDENTIFIER : - // TODO - Kludgy way to handle constructors/destructors - if (flags.haveEncounteredRawType()) { - setTypeName(sdw, typeNameBegin, typeNameEnd); - return; - } - if (parm && flags.haveEncounteredTypename()) { - setTypeName(sdw, typeNameBegin, typeNameEnd); - return; - } - if (lookAheadForConstructorOrConversion(flags, sdw, kind)) { - setTypeName(sdw, typeNameBegin, typeNameEnd); - return; - } - if (lookAheadForDeclarator(flags)) { - setTypeName(sdw, typeNameBegin, typeNameEnd); - return; - } - setCompletionValues(sdw.getScope(), kind, key); - ITokenDuple d = name(sdw.getScope(), kind, key); - sdw.setTypeName(d); - sdw.setSimpleType(IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME); - flags.setEncounteredTypename(true); - break; - case IToken.t_class : - case IToken.t_struct : - case IToken.t_union : - try { - classSpecifier(sdw); - flags.setEncounteredTypename(true); - break; - } catch (BacktrackException bt) { - elaboratedTypeSpecifier(sdw); - flags.setEncounteredTypename(true); - break; - } - case IToken.t_enum : - try { - enumSpecifier(sdw); - flags.setEncounteredTypename(true); - break; - } catch (BacktrackException bt) { - // this is an elaborated class specifier - elaboratedTypeSpecifier(sdw); - flags.setEncounteredTypename(true); - break; - } - default : - if (extension.canHandleDeclSpecifierSequence(LT(1))) { - IParserExtension.IDeclSpecifierExtensionResult declSpecExtResult = extension - .parseDeclSpecifierSequence(this, flags, sdw, - kind, key); - if (declSpecExtResult != null) { - flags = declSpecExtResult.getFlags(); - if (typeNameBegin == null) - typeNameBegin = declSpecExtResult - .getFirstToken(); - typeNameEnd = declSpecExtResult.getLastToken(); - break; - } - break declSpecifiers; - } - break declSpecifiers; - } - } - setTypeName(sdw, typeNameBegin, typeNameEnd); - return; - } - - /** - * @param sdw - * @param typeNameBegin - * @param typeNameEnd - */ - private void setTypeName(DeclarationWrapper sdw, IToken typeNameBegin, - IToken typeNameEnd) { - if (typeNameBegin != null) - sdw.setTypeName(TokenFactory.createTokenDuple(typeNameBegin, - typeNameEnd)); - } - - /** - * Parse an elaborated type specifier. - * - * @param decl - * Declaration which owns the elaborated type - * @throws BacktrackException - * request a backtrack - */ - protected void elaboratedTypeSpecifier(DeclarationWrapper sdw) - throws BacktrackException, EndOfFileException { - // this is an elaborated class specifier - IToken t = consume(); - ASTClassKind eck = null; - CompletionKind completionKind = null; - - switch (t.getType()) { - case IToken.t_class : - eck = ASTClassKind.CLASS; - completionKind = CompletionKind.CLASS_REFERENCE; - break; - case IToken.t_struct : - eck = ASTClassKind.STRUCT; - completionKind = CompletionKind.STRUCT_REFERENCE; - break; - case IToken.t_union : - eck = ASTClassKind.UNION; - completionKind = CompletionKind.UNION_REFERENCE; - break; - case IToken.t_enum : - eck = ASTClassKind.ENUM; - completionKind = CompletionKind.ENUM_REFERENCE; - break; - default : - backup(t); - throwBacktrack(t.getOffset(), t.getEndOffset(), t.getLineNumber(), t.getFilename()); - } - - ITokenDuple d = name(sdw.getScope(), completionKind, - KeywordSetKey.EMPTY); - IASTTypeSpecifier elaboratedTypeSpec = null; - final boolean isForewardDecl = (LT(1) == IToken.tSEMI); - - try { - elaboratedTypeSpec = astFactory.createElaboratedTypeSpecifier(sdw - .getScope(), eck, d, t.getOffset(), t.getLineNumber(), d - .getLastToken().getEndOffset(), d.getLastToken() - .getLineNumber(), isForewardDecl, sdw.isFriend()); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException( - "elaboratedTypeSpecifier:createElaboratedTypeSpecifier", e); //$NON-NLS-1$ - throwBacktrack(t.getOffset(), endOffset, t.getLineNumber(), t.getFilename()); - } - sdw.setTypeSpecifier(elaboratedTypeSpec); - - if (isForewardDecl) - { - ((IASTElaboratedTypeSpecifier) elaboratedTypeSpec).acceptElement( - requestor); - } - } - /** - * Parses the initDeclarator construct of the ANSI C++ spec. - * - * initDeclarator : declarator ("=" initializerClause | "(" expressionList - * ")")? - * - * @param constructInitializers - * TODO - * @param owner - * IParserCallback object that represents the owner declaration - * object. - * @return declarator that this parsing produced. - * @throws BacktrackException - * request a backtrack - */ - protected Declarator initDeclarator(DeclarationWrapper sdw, - SimpleDeclarationStrategy strategy, CompletionKind kind, - boolean constructInitializers) throws EndOfFileException, - BacktrackException { - Declarator d = declarator(sdw, sdw.getScope(), strategy, kind); - - try { - astFactory.constructExpressions(constructInitializers); - if (language == ParserLanguage.CPP) - optionalCPPInitializer(d, constructInitializers); - else if (language == ParserLanguage.C) - optionalCInitializer(d, constructInitializers); - sdw.addDeclarator(d); - return d; - } finally { - astFactory.constructExpressions(true); - } - } - - protected void optionalCPPInitializer(Declarator d, - boolean constructInitializers) throws EndOfFileException, - BacktrackException { - // handle initializer - final IASTScope scope = d.getDeclarationWrapper().getScope(); - setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, - KeywordSetKey.EMPTY); - if (LT(1) == IToken.tASSIGN) { - consume(IToken.tASSIGN); - setCompletionValues(scope, CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EMPTY); - throwAwayMarksForInitializerClause(d); - try - { - IASTInitializerClause clause = initializerClause(scope, - constructInitializers); - d.setInitializerClause(clause); - } - catch( EndOfFileException eof ) - { - failParse(); - throw eof; - } - setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, - KeywordSetKey.EMPTY); - } else if (LT(1) == IToken.tLPAREN) { - // initializer in constructor - consume(IToken.tLPAREN); // EAT IT! - setCompletionValues(scope, CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EMPTY); - IASTExpression astExpression = null; - astExpression = expression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EXPRESSION); - setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, - KeywordSetKey.EMPTY); - consume(IToken.tRPAREN); - d.setConstructorExpression(astExpression); - } - } - - /** - * @param d - */ - protected void throwAwayMarksForInitializerClause(Declarator d) { - simpleDeclarationMark = null; - if (d.getNameDuple() != null) - d.getNameDuple().getLastToken().setNext(null); - if (d.getPointerOperatorNameDuple() != null) - d.getPointerOperatorNameDuple().getLastToken().setNext(null); - } - - protected void optionalCInitializer(Declarator d, - boolean constructInitializers) throws EndOfFileException, - BacktrackException { - final IASTScope scope = d.getDeclarationWrapper().getScope(); - setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, - KeywordSetKey.EMPTY); - if (LT(1) == IToken.tASSIGN) { - consume(IToken.tASSIGN); - throwAwayMarksForInitializerClause(d); - setCompletionValues(scope, CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EMPTY); - d.setInitializerClause(cInitializerClause(scope, - Collections.EMPTY_LIST, constructInitializers)); - setCompletionValues(scope, CompletionKind.NO_SUCH_KIND, - KeywordSetKey.EMPTY); - } - } - /** - * @param scope - * @return - */ - protected IASTInitializerClause cInitializerClause(IASTScope scope, - List designators, boolean constructInitializers) - throws EndOfFileException, BacktrackException { - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - la = null; - if (LT(1) == IToken.tLBRACE) { - consume(IToken.tLBRACE); - List initializerList = new ArrayList(); - for (;;) { - int checkHashcode = LA(1).hashCode(); - // required at least one initializer list - // get designator list - List newDesignators = designatorList(scope); - if (newDesignators.size() != 0) - if (LT(1) == IToken.tASSIGN) - consume(IToken.tASSIGN); - IASTInitializerClause initializer = cInitializerClause(scope, - newDesignators, constructInitializers); - initializerList.add(initializer); - // can end with just a '}' - if (LT(1) == IToken.tRBRACE) - break; - // can end with ", }" - if (LT(1) == IToken.tCOMMA) - consume(IToken.tCOMMA); - if (LT(1) == IToken.tRBRACE) - break; - if (checkHashcode == LA(1).hashCode()) { - IToken l2 = LA(1); - throwBacktrack(startingOffset, l2.getEndOffset(), l2.getLineNumber(), l2.getFilename()); - return null; - } - - // otherwise, its another initializer in the list - } - // consume the closing brace - consume(IToken.tRBRACE); - return createInitializerClause(scope, ((designators.size() == 0) - ? IASTInitializerClause.Kind.INITIALIZER_LIST - : IASTInitializerClause.Kind.DESIGNATED_INITIALIZER_LIST), - null, initializerList, designators, constructInitializers); - } - // if we get this far, it means that we have not yet succeeded - // try this now instead - // assignmentExpression - try { - IASTExpression assignmentExpression = assignmentExpression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EXPRESSION); - try { - return createInitializerClause( - scope, - ((designators.size() == 0) - ? IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION - : IASTInitializerClause.Kind.DESIGNATED_ASSIGNMENT_EXPRESSION), - assignmentExpression, null, designators, - constructInitializers); - } catch (Exception e) { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException("cInitializerClause:createInitializerClause", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - } catch (BacktrackException b) { - // do nothing - } - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - throwBacktrack(startingOffset, endOffset, line, fn); - return null; - } - /** - * - */ - protected IASTInitializerClause initializerClause(IASTScope scope, - boolean constructInitializers) throws EndOfFileException, - BacktrackException { - if (LT(1) == IToken.tLBRACE) { - IToken t = consume(IToken.tLBRACE); - IToken last = null; - if (LT(1) == (IToken.tRBRACE)) { - last = consume(IToken.tRBRACE); - try { - return createInitializerClause(scope, - IASTInitializerClause.Kind.EMPTY, null, null, - Collections.EMPTY_LIST, constructInitializers); - } catch (Exception e) { - logException( - "initializerClause_1:createInitializerClause", e); //$NON-NLS-1$ - throwBacktrack(t.getOffset(), last.getEndOffset(), t.getLineNumber(), last.getFilename()); - return null; - } - } - - // otherwise it is a list of initializer clauses - List initializerClauses = null; - int startingOffset = LA(1).getOffset(); - for (;;) { - IASTInitializerClause clause = initializerClause(scope, - constructInitializers); - if (clause != null) { - if (initializerClauses == null) - initializerClauses = new ArrayList(); - initializerClauses.add(clause); - } - if (LT(1) == IToken.tRBRACE) - break; - consume(IToken.tCOMMA); - } - last = consume(IToken.tRBRACE); - try { - return createInitializerClause(scope, - IASTInitializerClause.Kind.INITIALIZER_LIST, null, - initializerClauses == null - ? Collections.EMPTY_LIST - : initializerClauses, Collections.EMPTY_LIST, - constructInitializers); - } catch (Exception e) { - logException("initializerClause_2:createInitializerClause", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, last.getEndOffset(), last.getLineNumber(), last.getFilename()); - return null; - } - } - - // if we get this far, it means that we did not - // try this now instead - // assignmentExpression - IToken la = LA(1); - char [] fn = la.getFilename(); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - la = null; - - IASTExpression assignmentExpression = assignmentExpression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EXPRESSION); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - try { - return createInitializerClause(scope, - IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION, - assignmentExpression, null, Collections.EMPTY_LIST, - constructInitializers); - } catch (Exception e) { - logException("initializerClause_3:createInitializerClause", e); //$NON-NLS-1$ - } - throwBacktrack(startingOffset, endOffset, line, fn); - return null; - } - - protected IASTInitializerClause createInitializerClause(IASTScope scope, - IASTInitializerClause.Kind kind, IASTExpression expression, - List initializerClauses, List designators, - boolean constructInitializer) { - if (!constructInitializer) - return null; - return astFactory.createInitializerClause(scope, kind, expression, - initializerClauses, designators); - } - - protected List designatorList(IASTScope scope) throws EndOfFileException, - BacktrackException { - List designatorList = Collections.EMPTY_LIST; - // designated initializers for C - - if (LT(1) == IToken.tDOT || LT(1) == IToken.tLBRACKET) { - - while (LT(1) == IToken.tDOT || LT(1) == IToken.tLBRACKET) { - IToken id = null; - IASTExpression constantExpression = null; - IASTDesignator.DesignatorKind kind = null; - - if (LT(1) == IToken.tDOT) { - consume(IToken.tDOT); - id = identifier(); - kind = IASTDesignator.DesignatorKind.FIELD; - } else if (LT(1) == IToken.tLBRACKET) { - IToken mark = consume(IToken.tLBRACKET); - constantExpression = expression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EXPRESSION); - if (LT(1) != IToken.tRBRACKET) { - backup(mark); - if (extension.canHandleCDesignatorInitializer(LT(1))) { - IASTDesignator d = extension.parseDesignator(this, - scope); - if (d != null) { - if (designatorList == Collections.EMPTY_LIST) - designatorList = new ArrayList( - DEFAULT_DESIGNATOR_LIST_SIZE); - designatorList.add(d); - } - break; - } - } - consume(IToken.tRBRACKET); - kind = IASTDesignator.DesignatorKind.SUBSCRIPT; - } - - IASTDesignator d = astFactory.createDesignator(kind, - constantExpression, id, null); - if (designatorList == Collections.EMPTY_LIST) - designatorList = new ArrayList(DEFAULT_DESIGNATOR_LIST_SIZE); - designatorList.add(d); - - } - } else { - if (extension.canHandleCDesignatorInitializer(LT(1))) { - IASTDesignator d = extension.parseDesignator(this, scope); - if (d != null) { - if (designatorList == Collections.EMPTY_LIST) - designatorList = new ArrayList( - DEFAULT_DESIGNATOR_LIST_SIZE); - designatorList.add(d); - } - } - } - return designatorList; - } - /** - * Parse a declarator, as according to the ANSI C++ specification. - * - * declarator : (ptrOperator)* directDeclarator - * - * directDeclarator : declaratorId | directDeclarator "(" - * parameterDeclarationClause ")" (cvQualifier)* (exceptionSpecification)* | - * directDeclarator "[" (constantExpression)? "]" | "(" declarator")" | - * directDeclarator "(" parameterDeclarationClause ")" - * (oldKRParameterDeclaration)* - * - * declaratorId : name - * - * @param container - * IParserCallback object that represents the owner declaration. - * @return declarator that this parsing produced. - * @throws BacktrackException - * request a backtrack - */ - protected Declarator declarator(IDeclaratorOwner owner, IASTScope scope, - SimpleDeclarationStrategy strategy, CompletionKind kind) - throws EndOfFileException, BacktrackException { - Declarator d = null; - DeclarationWrapper sdw = owner.getDeclarationWrapper(); - IToken la = LA(1); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - la = null; - overallLoop : do { - d = new Declarator(owner); - - consumePointerOperators(d); - - if (LT(1) == IToken.tLPAREN) { - consume(); - declarator(d, scope, strategy, kind); - consume(IToken.tRPAREN); - } else - consumeTemplatedOperatorName(d, kind); - - for (;;) { - switch (LT(1)) { - case IToken.tLPAREN : - - boolean failed = false; - IASTScope parameterScope = astFactory - .getDeclaratorScope(scope, d.getNameDuple()); - // temporary fix for initializer/function declaration - // ambiguity - if (queryLookaheadCapability(2) - && !LA(2).looksLikeExpression() - && strategy != SimpleDeclarationStrategy.TRY_VARIABLE) { - if (LT(2) == IToken.tIDENTIFIER) { - IToken newMark = mark(); - consume(IToken.tLPAREN); - ITokenDuple queryName = null; - try { - try { - queryName = name(parameterScope, - CompletionKind.TYPE_REFERENCE, - KeywordSetKey.EMPTY); - if (!astFactory.queryIsTypeName( - parameterScope, queryName)) - failed = true; - } catch (Exception e) { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException( - "declarator:queryIsTypeName", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, newMark.getFilename()); - } - } catch (BacktrackException b) { - failed = true; - } - - if (queryName != null) - queryName.freeReferences(); - backup(newMark); - } - } - if ((queryLookaheadCapability(2) - && !LA(2).looksLikeExpression() - && strategy != SimpleDeclarationStrategy.TRY_VARIABLE && !failed) - || !queryLookaheadCapability(3)) { - // parameterDeclarationClause - d.setIsFunction(true); - // TODO need to create a temporary scope object here - consume(IToken.tLPAREN); - setCompletionValues(scope, - CompletionKind.ARGUMENT_TYPE, - KeywordSetKey.DECL_SPECIFIER_SEQUENCE); - boolean seenParameter = false; - parameterDeclarationLoop : for (;;) { - switch (LT(1)) { - case IToken.tRPAREN : - consume(); - setCompletionValues(parameterScope, - CompletionKind.NO_SUCH_KIND, - KeywordSetKey.FUNCTION_MODIFIER); - break parameterDeclarationLoop; - case IToken.tELLIPSIS : - consume(); - d.setIsVarArgs(true); - break; - case IToken.tCOMMA : - consume(); - setCompletionValues( - parameterScope, - CompletionKind.ARGUMENT_TYPE, - KeywordSetKey.DECL_SPECIFIER_SEQUENCE); - seenParameter = false; - break; - default : - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - if (seenParameter) - throwBacktrack(startingOffset, endOffset, line, fn); - parameterDeclaration(d, parameterScope); - seenParameter = true; - } - } - } - - if (LT(1) == IToken.tCOLON || LT(1) == IToken.t_try) - break overallLoop; - - IToken beforeCVModifier = mark(); - IToken[] cvModifiers = new IToken[2]; - int numCVModifiers = 0; - IToken afterCVModifier = beforeCVModifier; - // const-volatile - // 2 options: either this is a marker for the method, - // or it might be the beginning of old K&R style - // parameter declaration, see - // void getenv(name) const char * name; {} - // This will be determined further below - while ((LT(1) == IToken.t_const || LT(1) == IToken.t_volatile) - && numCVModifiers < 2) { - cvModifiers[numCVModifiers++] = consume(); - afterCVModifier = mark(); - } - //check for throws clause here - List exceptionSpecIds = null; - if (LT(1) == IToken.t_throw) { - exceptionSpecIds = new ArrayList(); - consume(); // throw - consume(IToken.tLPAREN); // ( - boolean done = false; - IASTTypeId exceptionTypeId = null; - while (!done) { - switch (LT(1)) { - case IToken.tRPAREN : - consume(); - done = true; - break; - case IToken.tCOMMA : - consume(); - break; - default : - try { - exceptionTypeId = typeId( - scope, - false, - CompletionKind.EXCEPTION_REFERENCE); - exceptionSpecIds - .add(exceptionTypeId); - exceptionTypeId - .acceptElement( - requestor); - } catch (BacktrackException e) { - failParse(e); - consume(); - // eat this token anyway - continue; - } - break; - } - } - if (exceptionSpecIds != null) - try { - d.setExceptionSpecification(astFactory - .createExceptionSpecification(d - .getDeclarationWrapper() - .getScope(), - exceptionSpecIds)); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException( - "declarator:createExceptionSpecification", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - } - // check for optional pure virtual - if (LT(1) == IToken.tASSIGN && LT(2) == IToken.tINTEGER ) - { - char[] image = LA(2).getCharImage(); - if( image.length == 1 && image[0] == '0' ){ - consume(IToken.tASSIGN); - consume(IToken.tINTEGER); - d.setPureVirtual(true); - } - } - if (afterCVModifier != LA(1) || LT(1) == IToken.tSEMI) { - // There were C++-specific clauses after - // const/volatile modifier - // Then it is a marker for the method - if (numCVModifiers > 0) { - for (int i = 0; i < numCVModifiers; i++) { - if (cvModifiers[i].getType() == IToken.t_const) - d.setConst(true); - if (cvModifiers[i].getType() == IToken.t_volatile) - d.setVolatile(true); - } - } - afterCVModifier = mark(); - // In this case (method) we can't expect K&R - // parameter declarations, - // but we'll check anyway, for errorhandling - } - break; - case IToken.tLBRACKET : - consumeArrayModifiers(d, sdw.getScope()); - continue; - case IToken.tCOLON : - consume(IToken.tCOLON); - IASTExpression exp = constantExpression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EXPRESSION); - d.setBitFieldExpression(exp); - default : - break; - } - break; - } - if (LA(1).getType() != IToken.tIDENTIFIER) - break; - - } while (true); - if (d.getOwner() instanceof IDeclarator) - ((Declarator) d.getOwner()).setOwnedDeclarator(d); - return d; - } - - protected void consumeTemplatedOperatorName(Declarator d, - CompletionKind kind) throws EndOfFileException, BacktrackException { - TemplateParameterManager argumentList = TemplateParameterManager - .getInstance(); - try { - if (LT(1) == IToken.t_operator) - operatorId(d, null, null, kind); - else { - try { - ITokenDuple duple = name(d.getDeclarationWrapper() - .getScope(), kind, KeywordSetKey.EMPTY); - d.setName(duple); - - } catch (BacktrackException bt) { - Declarator d1 = d; - Declarator d11 = d1; - IToken start = null; - - boolean hasTemplateId = false; - - IToken mark = mark(); - if (LT(1) == IToken.tCOLONCOLON - || LT(1) == IToken.tIDENTIFIER) { - start = consume(); - IToken end = null; - - if (start.getType() == IToken.tIDENTIFIER) { - end = consumeTemplateArguments(d - .getDeclarationWrapper().getScope(), end, - argumentList, kind); - if (end != null && end.getType() == IToken.tGT) - hasTemplateId = true; - } - - while (LT(1) == IToken.tCOLONCOLON - || LT(1) == IToken.tIDENTIFIER) { - end = consume(); - if (end.getType() == IToken.tIDENTIFIER) { - end = consumeTemplateArguments(d - .getDeclarationWrapper().getScope(), - end, argumentList, kind); - if (end.getType() == IToken.tGT) - hasTemplateId = true; - } - } - if (LT(1) == IToken.t_operator) - operatorId(d11, start, (hasTemplateId - ? argumentList - : null), kind); - else { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - backup(mark); - throwBacktrack(mark.getOffset(), endOffset, mark.getLineNumber(), mark.getFilename()); - } - } - } - } - } finally { - TemplateParameterManager.returnInstance(argumentList); - } - } - /** - * Parse an enumeration specifier, as according to the ANSI specs in C & - * C++. - * - * enumSpecifier: "enum" (name)? "{" (enumerator-list) "}" enumerator-list: - * enumerator-definition enumerator-list , enumerator-definition - * enumerator-definition: enumerator enumerator = constant-expression - * enumerator: identifier - * - * @param owner - * IParserCallback object that represents the declaration that - * owns this type specifier. - * @throws BacktrackException - * request a backtrack - */ - protected void enumSpecifier(DeclarationWrapper sdw) - throws BacktrackException, EndOfFileException { - IToken mark = mark(); - IToken identifier = null; - consume(IToken.t_enum); - setCompletionValues(sdw.getScope(), CompletionKind.ENUM_REFERENCE); - if (LT(1) == IToken.tIDENTIFIER) { - identifier = identifier(); - setCompletionValues(sdw.getScope(), CompletionKind.ENUM_REFERENCE); - } - if (LT(1) == IToken.tLBRACE) { - IASTEnumerationSpecifier enumeration = null; - try { - enumeration = astFactory.createEnumerationSpecifier(sdw - .getScope(), ((identifier == null) - ? EMPTY_STRING : identifier.getCharImage()), //$NON-NLS-1$ - mark.getOffset(), mark.getLineNumber(), - ((identifier == null) ? mark.getOffset() : identifier - .getOffset()), ((identifier == null) ? mark - .getEndOffset() : identifier.getEndOffset()), - ((identifier == null) - ? mark.getLineNumber() - : identifier.getLineNumber()), mark.getFilename()); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException("enumSpecifier:createEnumerationSpecifier", e); //$NON-NLS-1$ - throwBacktrack(mark.getOffset(), endOffset, mark.getLineNumber(), mark.getFilename()); - } - handleEnumeration( enumeration ); - consume(IToken.tLBRACE); - while (LT(1) != IToken.tRBRACE) { - IToken enumeratorIdentifier = null; - if (LT(1) == IToken.tIDENTIFIER) { - enumeratorIdentifier = identifier(); - } else { - IToken la = LA(1); - throwBacktrack(la.getOffset(), la.getEndOffset(), la.getLineNumber(), la.getFilename()); - } - IASTExpression initialValue = null; - if (LT(1) == IToken.tASSIGN) { - consume(IToken.tASSIGN); - initialValue = constantExpression(sdw.getScope(), - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EXPRESSION); - } - IASTEnumerator enumerator = null; - if (LT(1) == IToken.tRBRACE) { - try { - enumerator = astFactory.addEnumerator(enumeration, - enumeratorIdentifier.getCharImage(), - enumeratorIdentifier.getOffset(), - enumeratorIdentifier.getLineNumber(), - enumeratorIdentifier.getOffset(), - enumeratorIdentifier.getEndOffset(), - enumeratorIdentifier.getLineNumber(), lastToken - .getEndOffset(), lastToken - .getLineNumber(), initialValue, lastToken.getFilename()); - endEnumerator(enumerator); - } catch (ASTSemanticException e1) { - throwBacktrack(e1.getProblem()); - } catch (Exception e) { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException("enumSpecifier:addEnumerator", e); //$NON-NLS-1$ - throwBacktrack(mark.getOffset(), endOffset, mark.getLineNumber(), mark.getFilename()); - } - break; - } - if (LT(1) != IToken.tCOMMA) { - enumeration - .freeReferences(); - if (enumerator != null) - enumerator.freeReferences(); - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - throwBacktrack(mark.getOffset(), endOffset, mark.getLineNumber(), mark.getFilename()); - } - try { - enumerator = astFactory.addEnumerator(enumeration, - enumeratorIdentifier.getCharImage(), - enumeratorIdentifier.getOffset(), - enumeratorIdentifier.getLineNumber(), - enumeratorIdentifier.getOffset(), - enumeratorIdentifier.getEndOffset(), - enumeratorIdentifier.getLineNumber(), lastToken - .getEndOffset(), lastToken.getLineNumber(), - initialValue, lastToken.getFilename()); - endEnumerator(enumerator); - } catch (ASTSemanticException e1) { - throwBacktrack(e1.getProblem()); - } catch (Exception e) { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException("enumSpecifier:addEnumerator", e); //$NON-NLS-1$ - throwBacktrack(mark.getOffset(), endOffset, mark.getLineNumber(), mark.getFilename()); - } - consume(IToken.tCOMMA); - } - IToken t = consume(IToken.tRBRACE); - enumeration.setEndingOffsetAndLineNumber(t.getEndOffset(), t - .getLineNumber()); - enumeration.acceptElement(requestor); - sdw.setTypeSpecifier(enumeration); - } else { - // enumSpecifierAbort - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - backup(mark); - throwBacktrack(mark.getOffset(), endOffset, mark.getLineNumber(), mark.getFilename()); - } - } - /** - * Parse a class/struct/union definition. - * - * classSpecifier : classKey name (baseClause)? "{" (memberSpecification)* - * "}" - * - * @param owner - * IParserCallback object that represents the declaration that - * owns this classSpecifier - * @throws BacktrackException - * request a backtrack - */ - protected void classSpecifier(DeclarationWrapper sdw) - throws BacktrackException, EndOfFileException { - ClassNameType nameType = ClassNameType.IDENTIFIER; - ASTClassKind classKind = null; - CompletionKind completionKind = null; - ASTAccessVisibility access = ASTAccessVisibility.PUBLIC; - IToken classKey = null; - IToken mark = mark(); - - // class key - switch (LT(1)) { - case IToken.t_class : - classKey = consume(); - classKind = ASTClassKind.CLASS; - access = ASTAccessVisibility.PRIVATE; - completionKind = CompletionKind.CLASS_REFERENCE; - break; - case IToken.t_struct : - classKey = consume(); - classKind = ASTClassKind.STRUCT; - completionKind = CompletionKind.STRUCT_REFERENCE; - break; - case IToken.t_union : - classKey = consume(); - classKind = ASTClassKind.UNION; - completionKind = CompletionKind.UNION_REFERENCE; - break; - default : - throwBacktrack(mark.getOffset(), mark.getEndOffset(), mark.getLineNumber(), mark.getFilename()); - } - - ITokenDuple duple = null; - - setCompletionValues(sdw.getScope(), completionKind, KeywordSetKey.EMPTY); - // class name - if (LT(1) == IToken.tIDENTIFIER) { - // Bug 66496 - // special magic to handle macros that resolve to dllimport/dllexport in quick parse - if (mode == ParserMode.QUICK_PARSE && LT(2) == IToken.tIDENTIFIER) - consume(); - - duple = name(sdw.getScope(), completionKind, KeywordSetKey.EMPTY); - } - if (duple != null && !duple.isIdentifier()) - nameType = ClassNameType.TEMPLATE; - if (LT(1) != IToken.tCOLON && LT(1) != IToken.tLBRACE) { - IToken errorPoint = LA(1); - backup(mark); - throwBacktrack(errorPoint.getOffset(), errorPoint.getEndOffset(), errorPoint.getLineNumber(), errorPoint.getFilename()); - } - IASTClassSpecifier astClassSpecifier = null; - - try { - astClassSpecifier = astFactory.createClassSpecifier(sdw.getScope(), - duple, classKind, nameType, access, classKey.getOffset(), - classKey.getLineNumber(), duple == null ? classKey - .getOffset() : duple.getFirstToken().getOffset(), - duple == null ? classKey.getEndOffset() : duple - .getFirstToken().getEndOffset(), duple == null - ? classKey.getLineNumber() - : duple.getFirstToken().getLineNumber(), classKey.getFilename()); - } catch (ASTSemanticException e) { - throwBacktrack(e.getProblem()); - } catch (Exception e) { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException("classSpecifier:createClassSpecifier", e); //$NON-NLS-1$ - throwBacktrack(mark.getOffset(), endOffset, mark.getLineNumber(), mark.getFilename()); - } - sdw.setTypeSpecifier(astClassSpecifier); - // base clause - if (LT(1) == IToken.tCOLON) { - baseSpecifier(astClassSpecifier); - } - - if (LT(1) == IToken.tLBRACE) { - consume(IToken.tLBRACE); - setCompletionValues(astClassSpecifier, CompletionKind.FIELD_TYPE, - KeywordSetKey.MEMBER); - astClassSpecifier.enterScope(requestor); - - try - { - handleClassSpecifier(astClassSpecifier); - memberDeclarationLoop : while (LT(1) != IToken.tRBRACE) - { - int checkToken = LA(1).hashCode(); - switch (LT(1)) { - case IToken.t_public : - consume(); - consume(IToken.tCOLON); - astClassSpecifier - .setCurrentVisibility(ASTAccessVisibility.PUBLIC); - break; - case IToken.t_protected : - consume(); - consume(IToken.tCOLON); - astClassSpecifier - .setCurrentVisibility(ASTAccessVisibility.PROTECTED); - break; - - case IToken.t_private : - consume(); - consume(IToken.tCOLON); - astClassSpecifier - .setCurrentVisibility(ASTAccessVisibility.PRIVATE); - break; - case IToken.tRBRACE : - consume(IToken.tRBRACE); - break memberDeclarationLoop; - default : - try { - declaration(astClassSpecifier, null, null, - KeywordSetKey.MEMBER); - } catch (BacktrackException bt) { - if (checkToken == LA(1).hashCode()) - failParseWithErrorHandling(); - } - } - if (checkToken == LA(1).hashCode()) - failParseWithErrorHandling(); - } - // consume the } - IToken lt = consume(IToken.tRBRACE); - astClassSpecifier.setEndingOffsetAndLineNumber(lt.getEndOffset(), - lt.getLineNumber()); - try { - astFactory.signalEndOfClassSpecifier(astClassSpecifier); - } catch (Exception e1) { - logException("classSpecifier:signalEndOfClassSpecifier", e1); //$NON-NLS-1$ - throwBacktrack(lt.getOffset(), lt.getEndOffset(), lt.getLineNumber(), lt.getFilename()); - } - - } - finally - { - astClassSpecifier.exitScope(requestor); - } - - - - } - } - /** - * Parse the subclass-baseclauses for a class specification. - * - * baseclause: : basespecifierlist - * basespecifierlist: basespecifier - * basespecifierlist, basespecifier - * basespecifier: ::? nestednamespecifier? classname - * virtual accessspecifier? ::? nestednamespecifier? classname - * accessspecifier virtual? ::? nestednamespecifier? classname - * accessspecifier: private | protected | public - * @param classSpecOwner - * @throws BacktrackException - */ - protected void baseSpecifier( - IASTClassSpecifier astClassSpec) - throws EndOfFileException, BacktrackException - { - IToken la = LA(1); - char [] fn = la.getFilename(); - int startingOffset = la.getOffset(); - int line = la.getLineNumber(); - la = null; - consume(IToken.tCOLON); - - setCompletionValues(astClassSpec.getOwnerScope(), CompletionKind.CLASS_REFERENCE, KeywordSetKey.BASE_SPECIFIER ); - boolean isVirtual = false; - ASTAccessVisibility visibility = ASTAccessVisibility.PUBLIC; - ITokenDuple nameDuple = null; - - ArrayList bases = null; - - baseSpecifierLoop : for (;;) - { - switch (LT(1)) - { - case IToken.t_virtual : - consume(IToken.t_virtual); - setCompletionValues(astClassSpec.getOwnerScope(), CompletionKind.CLASS_REFERENCE, KeywordSetKey.EMPTY ); - isVirtual = true; - break; - case IToken.t_public : - consume(); - setCompletionValues(astClassSpec.getOwnerScope(), CompletionKind.CLASS_REFERENCE, KeywordSetKey.EMPTY ); - break; - case IToken.t_protected : - consume(); - visibility = ASTAccessVisibility.PROTECTED; - setCompletionValues(astClassSpec.getOwnerScope(), CompletionKind.CLASS_REFERENCE, KeywordSetKey.EMPTY ); - break; - case IToken.t_private : - visibility = ASTAccessVisibility.PRIVATE; - consume(); - setCompletionValues(astClassSpec.getOwnerScope(), CompletionKind.CLASS_REFERENCE, KeywordSetKey.EMPTY ); - break; - case IToken.tCOLONCOLON : - case IToken.tIDENTIFIER : - //to get templates right we need to use the class as the scope - nameDuple = name(astClassSpec, CompletionKind.CLASS_REFERENCE, KeywordSetKey.BASE_SPECIFIER ); - break; - case IToken.tCOMMA : - //because we are using the class as the scope to get the name, we need to postpone adding the base - //specifiers until after we have all the nameDuples - if( bases == null ){ - bases = new ArrayList(4); - } - bases.add( new Object[] { isVirtual ? Boolean.TRUE : Boolean.FALSE, visibility, nameDuple } ); - - isVirtual = false; - visibility = ASTAccessVisibility.PUBLIC; - nameDuple = null; - consume(); - setCompletionValues(astClassSpec.getOwnerScope(), CompletionKind.CLASS_REFERENCE, KeywordSetKey.BASE_SPECIFIER ); - continue baseSpecifierLoop; - default : - break baseSpecifierLoop; - } - } - - try - { - if( bases != null ){ - int size = bases.size(); - for( int i = 0; i < size; i++ ){ - Object [] data = (Object[]) bases.get( i ); - try { - astFactory.addBaseSpecifier( astClassSpec, - ((Boolean)data[0]).booleanValue(), - (ASTAccessVisibility) data[1], - (ITokenDuple)data[2] ); - } catch (ASTSemanticException e1) { - failParse( e1.getProblem() ); - } - } - } - - astFactory.addBaseSpecifier( - astClassSpec, - isVirtual, - visibility, - nameDuple ); - } - catch (ASTSemanticException e) - { - failParse( e.getProblem() ); - } catch (Exception e) - { - int endOffset = ( lastToken != null ) ? lastToken.getEndOffset() : 0 ; - logException( "baseSpecifier_2::addBaseSpecifier", e ); //$NON-NLS-1$ - throwBacktrack( startingOffset, endOffset, line, fn ); - } - } - - /** - * Parses a function body. - * - * @throws BacktrackException - * request a backtrack - */ - protected void functionBody(IASTScope scope) throws EndOfFileException, - BacktrackException { - compoundStatement(scope, false); - } - /** - * Parses a statement. - * - * @throws BacktrackException - * request a backtrack - */ - protected void statement(IASTCodeScope scope) throws EndOfFileException, - BacktrackException { - - setCompletionValues(scope, CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.STATEMENT); - - switch (LT(1)) { - case IToken.t_case : - consume(IToken.t_case); - IASTExpression constant_expression = constantExpression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EXPRESSION); - constant_expression.acceptElement(requestor); - endExpression(constant_expression); - consume(IToken.tCOLON); - statement(scope); - cleanupLastToken(); - return; - case IToken.t_default : - consume(IToken.t_default); - consume(IToken.tCOLON); - statement(scope); - cleanupLastToken(); - return; - case IToken.tLBRACE : - compoundStatement(scope, true); - cleanupLastToken(); - return; - case IToken.t_if : - if_loop: while( true ){ - consume(IToken.t_if); - consume(IToken.tLPAREN); - IToken start = LA(1); - boolean passedCondition = true; - try { - condition(scope); - consume(IToken.tRPAREN); - } catch (BacktrackException b) { - //if the problem has no offset info, make a new one that does - if( b.getProblem() != null && b.getProblem().getSourceLineNumber() == -1 ){ - IProblem p = b.getProblem(); - IProblem p2 = problemFactory.createProblem( p.getID(), start.getOffset(), - lastToken != null ? lastToken.getEndOffset() : start.getEndOffset(), - start.getLineNumber(), p.getOriginatingFileName(), - p.getArguments() != null ? p.getArguments().toCharArray() : null, - p.isWarning(), p.isError() ); - b.initialize( p2 ); - } - failParse(b); - failParseWithErrorHandling(); - passedCondition = false; - } - - if( passedCondition ){ - if (LT(1) != IToken.tLBRACE) - singleStatementScope(scope); - else - statement(scope); - } - - if (LT(1) == IToken.t_else) { - consume(IToken.t_else); - if (LT(1) == IToken.t_if) { - //an else if, don't recurse, just loop and do another if - cleanupLastToken(); - continue if_loop; - } else if (LT(1) != IToken.tLBRACE) - singleStatementScope(scope); - else - statement(scope); - } - break if_loop; - } - cleanupLastToken(); - return; - case IToken.t_switch : - consume(); - consume(IToken.tLPAREN); - condition(scope); - consume(IToken.tRPAREN); - statement(scope); - cleanupLastToken(); - return; - case IToken.t_while : - consume(IToken.t_while); - consume(IToken.tLPAREN); - condition(scope); - consume(IToken.tRPAREN); - if (LT(1) != IToken.tLBRACE) - singleStatementScope(scope); - else - statement(scope); - cleanupLastToken(); - return; - case IToken.t_do : - consume(IToken.t_do); - if (LT(1) != IToken.tLBRACE) - singleStatementScope(scope); - else - statement(scope); - consume(IToken.t_while); - consume(IToken.tLPAREN); - condition(scope); - consume(IToken.tRPAREN); - cleanupLastToken(); - return; - case IToken.t_for : - consume(); - consume(IToken.tLPAREN); - forInitStatement(scope); - if (LT(1) != IToken.tSEMI) - condition(scope); - consume(IToken.tSEMI); - if (LT(1) != IToken.tRPAREN) { - IASTExpression finalExpression = expression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.DECLARATION); - finalExpression.acceptElement(requestor); - endExpression(finalExpression); - } - consume(IToken.tRPAREN); - statement(scope); - cleanupLastToken(); - return; - case IToken.t_break : - consume(); - consume(IToken.tSEMI); - cleanupLastToken(); - return; - case IToken.t_continue : - consume(); - consume(IToken.tSEMI); - cleanupLastToken(); - return; - case IToken.t_return : - consume(); - if (LT(1) != IToken.tSEMI) { - IASTExpression retVal = expression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.EXPRESSION); - retVal.acceptElement(requestor); - endExpression(retVal); - } - consume(IToken.tSEMI); - cleanupLastToken(); - return; - case IToken.t_goto : - consume(); - consume(IToken.tIDENTIFIER); - consume(IToken.tSEMI); - cleanupLastToken(); - return; - case IToken.t_try : - consume(); - compoundStatement(scope, true); - catchHandlerSequence(scope); - cleanupLastToken(); - return; - case IToken.tSEMI : - consume(); - cleanupLastToken(); - return; - default : - // can be many things: - // label - - if (queryLookaheadCapability(2) && LT(1) == IToken.tIDENTIFIER - && LT(2) == IToken.tCOLON) { - consume(IToken.tIDENTIFIER); - consume(IToken.tCOLON); - statement(scope); - cleanupLastToken(); - return; - } - // expressionStatement - // Note: the function style cast ambiguity is handled in - // expression - // Since it only happens when we are in a statement - IToken mark = mark(); - IASTExpression expressionStatement = null; - try { - expressionStatement = expression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.STATEMENT); - consume(IToken.tSEMI); - expressionStatement.acceptElement(requestor); - endExpression(expressionStatement); - return; - } catch (BacktrackException b) { - backup(mark); - if (expressionStatement != null) - expressionStatement.freeReferences(); - } - - // declarationStatement - declaration(scope, null, null, KeywordSetKey.STATEMENT); - } - - } - protected void catchHandlerSequence(IASTScope scope) - throws EndOfFileException, BacktrackException { - if( LT(1) != IToken.t_catch ) - { - IToken la = LA(1); - throwBacktrack(la.getOffset(), la.getEndOffset(), la.getLineNumber(), la.getFilename()); // error, need at least one of these - } - while (LT(1) == IToken.t_catch) - { - consume(IToken.t_catch); - setCompletionValues(scope,CompletionKind.NO_SUCH_KIND,KeywordSetKey.EMPTY ); - consume(IToken.tLPAREN); - setCompletionValues(scope,CompletionKind.EXCEPTION_REFERENCE,KeywordSetKey.DECL_SPECIFIER_SEQUENCE); - try - { - if( LT(1) == IToken.tELLIPSIS ) - consume( IToken.tELLIPSIS ); - else - simpleDeclaration( SimpleDeclarationStrategy.TRY_VARIABLE, scope, null, CompletionKind.EXCEPTION_REFERENCE, true, KeywordSetKey.DECLARATION); - consume(IToken.tRPAREN); - - catchBlockCompoundStatement(scope); - } - catch( BacktrackException bte ) - { - failParse( bte ); - failParseWithErrorHandling(); - } - } - } - - protected void catchBlockCompoundStatement(IASTScope scope) - throws BacktrackException, EndOfFileException - { - if( mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE ) - skipOverCompoundStatement(); - else if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - { - if( scanner.isOnTopContext() ) - compoundStatement(scope, true); - else - skipOverCompoundStatement(); - } - else if( mode == ParserMode.COMPLETE_PARSE ) - compoundStatement(scope, true); - } - - protected void singleStatementScope(IASTScope scope) - throws EndOfFileException, BacktrackException { - IASTCodeScope newScope; - try { - newScope = astFactory.createNewCodeBlock(scope); - } catch (Exception e) { - logException("singleStatementScope:createNewCodeBlock", e); //$NON-NLS-1$ - IToken la = LA(1); - throwBacktrack(la.getOffset(), la.getEndOffset(), la.getLineNumber(), la.getFilename()); - return; - } - newScope.enterScope(requestor); - try { - statement(newScope); - } finally { - newScope.exitScope(requestor); - } - } - - /** - * @throws BacktrackException - */ - protected void condition(IASTScope scope) throws BacktrackException, - EndOfFileException { - IASTExpression someExpression = expression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, KeywordSetKey.EXPRESSION); - someExpression.acceptElement(requestor); - - endExpression(someExpression); - } - - /** - * @throws BacktrackException - */ - protected void forInitStatement(IASTScope scope) throws BacktrackException, - EndOfFileException { - IToken mark = mark(); - try { - IASTExpression e = expression(scope, - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.DECLARATION); - consume(IToken.tSEMI); - e.acceptElement(requestor); - - } catch (BacktrackException bt) { - backup(mark); - try { - simpleDeclarationStrategyUnion(scope, null, null, null); - } catch (BacktrackException b) { - failParse(b); - throwBacktrack(b); - } - } - - } - /** - * @throws BacktrackException - */ - protected void compoundStatement(IASTScope scope, boolean createNewScope) - throws EndOfFileException, BacktrackException { - IToken la = LA(1); - int line = la.getLineNumber(); - char [] fn = la.getFilename(); - int startingOffset = consume(IToken.tLBRACE).getOffset(); - - IASTCodeScope newScope = null; - if (createNewScope) { - try { - newScope = astFactory.createNewCodeBlock(scope); - } catch (Exception e) { - int endOffset = ( lastToken == null ) ? 0 : lastToken.getEndOffset(); - logException("compoundStatement:createNewCodeBlock", e); //$NON-NLS-1$ - throwBacktrack(startingOffset, endOffset, line, fn); - } - newScope.enterScope(requestor); - } - - try - { - setCompletionValues((createNewScope ? newScope : scope), - CompletionKind.SINGLE_NAME_REFERENCE, KeywordSetKey.STATEMENT); - - while (LT(1) != IToken.tRBRACE) { - int checkToken = LA(1).hashCode(); - try { - statement((IASTCodeScope) (createNewScope ? newScope : scope)); - } catch (BacktrackException b) { - failParse(b); - if (LA(1).hashCode() == checkToken) - failParseWithErrorHandling(); - } - setCompletionValues(((createNewScope ? newScope : scope)), - CompletionKind.SINGLE_NAME_REFERENCE, - KeywordSetKey.STATEMENT); - } - - consume(IToken.tRBRACE); - } - finally - { - if (createNewScope) - newScope.exitScope(requestor); - } - } - - protected IASTCompilationUnit compilationUnit; - protected IToken simpleDeclarationMark; - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.IParser#getLanguage() - */ - public ParserLanguage getLanguage() { - return language; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.IParser#setLanguage(Language) - */ - public void setLanguage(ParserLanguage l) { - language = l; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.IParser#getLastErrorOffset() - */ - public int getLastErrorOffset() { - return firstErrorOffset; - } - public int getLastErrorLine() { - return firstErrorLine; - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.IParser#parse(int, int) - */ - public ISelectionParseResult parse(int startingOffset, int endingOffset) - throws ParseError { - if( mode != ParserMode.SELECTION_PARSE ) - throw new ParseError(ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED); - offsetRange = new OffsetDuple( startingOffset, endingOffset ); - translationUnit(); - return reconcileTokenDuple(); - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.IParser#parse(int) - */ - public IASTCompletionNode parse(int offset) throws ParseError { - if( mode != ParserMode.COMPLETION_PARSE ) - throw new ParseError(ParseError.ParseErrorKind.METHOD_NOT_IMPLEMENTED); - scanner.setOffsetBoundary(offset); - //long startTime = System.currentTimeMillis(); - translationUnit(); - //long stopTime = System.currentTimeMillis(); - //System.out.println("Completion Parse time: " + (stopTime - startTime) + "ms"); - return new ASTCompletionNode( getCompletionKind(), getCompletionScope(), getCompletionContext(), getCompletionPrefix(), reconcileKeywords( getKeywordSet(), getCompletionPrefix() ), String.valueOf(getCompletionFunctionName()), getParameterListExpression() ); - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setupASTFactory(org.eclipse.cdt.core.parser.IScanner, - * org.eclipse.cdt.core.parser.ParserLanguage) - */ - protected void setupASTFactory(IScanner scanner, ParserLanguage language) { - astFactory = ParserFactory.createASTFactory( mode, language); - scanner.setASTFactory(astFactory); - astFactory.setLogger(log); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#getCompliationUnit() - */ - protected IASTNode getCompliationUnit() { - return compilationUnit; - } - - protected void endDeclaration(IASTDeclaration declaration) - throws EndOfFileException { - if( mode != ParserMode.SELECTION_PARSE || ! tokenDupleCompleted() ) - cleanupLastToken(); - else - { - contextNode = declaration; - throw new EndOfFileException(); - } - } - - /** - * - */ - protected void cleanupLastToken() { - if (lastToken != null) - lastToken.setNext(null); - simpleDeclarationMark = null; - } - - /** - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IParser#cancel() - */ - public synchronized void cancel() { - isCancelled = true; - scanner.cancel(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#validateCaches() - */ - public boolean validateCaches() { - if( astFactory instanceof CompleteParseASTFactory) - return ((CompleteParseASTFactory)astFactory).validateCaches(); - return true; - } - - protected IASTScope contextualScope; - protected CompletionKind cKind; - protected IASTNode context; - protected IToken finalToken; - protected Set keywordSet; - protected char[] functionOrConstructorName = EMPTY_STRING; - protected char[] currentFunctionName = EMPTY_STRING; - protected IASTExpression parameterListExpression; - - /** - * @return - */ - protected IASTScope getCompletionScope() { - return contextualScope; - } - - - - /** - * @return - */ - protected IASTCompletionNode.CompletionKind getCompletionKind() { - return cKind; - } - - /** - * @return - */ - protected String getCompletionPrefix() { - return ( finalToken == null ? String.valueOf(EMPTY_STRING) : finalToken.getImage() ); - } - - /** - * @return - */ - protected IASTNode getCompletionContext() { - return context; - } - - protected void setCompletionContext(IASTNode node) { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - this.context = node; - } - - protected void setCompletionKind(IASTCompletionNode.CompletionKind kind) { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - this.cKind = kind; - } - - /** - * @param compilationUnit - * @param kind2 - * @param set - * @param object - * @param string - */ - protected void setCompletionValues(CompletionKind kind, Set keywordSet, String prefix) { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - { - setCompletionScope(compilationUnit); - this.keywordSet = keywordSet; - setCompletionKind(kind); - setCompletionContext(null); - setCompletionFunctionName( ); - setCompletionToken( TokenFactory.createStandAloneToken( IToken.tIDENTIFIER, prefix ) ); - } - } - - /** - */ - protected void setCompletionFunctionName() { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - functionOrConstructorName = currentFunctionName; - } - - - - protected void setCompletionKeywords(KeywordSetKey key) { - this.keywordSet = KeywordSets.getKeywords( key, language ); - } - - protected void setCompletionToken(IToken token) { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - finalToken = token; - } - - protected void setCompletionValues(IASTScope scope, CompletionKind kind, KeywordSetKey key, IASTNode node, String prefix) throws EndOfFileException { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - { - setCompletionToken( TokenFactory.createStandAloneToken( IToken.tIDENTIFIER, prefix ) ); - setCompletionValues(scope, kind, key, node ); - } - } - - protected void setCompletionValues(IASTScope scope, CompletionKind kind, KeywordSetKey key) throws EndOfFileException { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - setCompletionValues(scope, kind, key, null ); - } - - - - protected void setCompletionValues(IASTScope scope, CompletionKind kind, KeywordSetKey key, IASTNode node) throws EndOfFileException { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - { - setCompletionScope(scope); - setCompletionKeywords(key); - setCompletionKind(kind); - setCompletionContext(node); - setCompletionFunctionName( ); - checkEndOfFile(); - } - } - - - protected void setCompletionValues( IASTScope scope, CompletionKind kind, IToken first, IToken last, List arguments, KeywordSetKey key ) throws EndOfFileException{ - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - { - setCompletionScope( scope ); - setCompletionKind( kind ); - setCompletionKeywords(key); - ITokenDuple duple = TokenFactory.createTokenDuple( first, last, arguments ); - try { - setCompletionContext( astFactory.lookupSymbolInContext( scope, duple, null ) ); - } catch (ASTNotImplementedException e) { - } - setCompletionFunctionName(); - } - } - - protected void setCompletionValues(IASTScope scope, CompletionKind kind, KeywordSetKey key, IASTExpression firstExpression, Kind expressionKind) throws EndOfFileException { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - { - IASTNode node = astFactory.expressionToMostPreciseASTNode( scope, firstExpression ); - if( kind == CompletionKind.MEMBER_REFERENCE ) - { - if( ! validMemberOperation( node, expressionKind )) - node =null; - } - setCompletionValues(scope,kind,key, node ); - } - } - - /** - * @param node - * @param expressionKind - * @return - */ - private boolean validMemberOperation(IASTNode node, Kind expressionKind) { - if( expressionKind == Kind.POSTFIX_ARROW_IDEXPRESSION || expressionKind == Kind.POSTFIX_ARROW_TEMPL_IDEXP ) - return astFactory.validateIndirectMemberOperation( node ); - else if( expressionKind == Kind.POSTFIX_DOT_IDEXPRESSION || expressionKind == Kind.POSTFIX_DOT_TEMPL_IDEXPRESS ) - return astFactory.validateDirectMemberOperation( node ); - return false; - } - - protected void setCompletionScope(IASTScope scope) { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - this.contextualScope = scope; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setCompletionValues(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind) - */ - protected void setCompletionValues(IASTScope scope, CompletionKind kind) throws EndOfFileException { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - { - setCompletionScope(scope); - setCompletionKind(kind); - setCompletionFunctionName( ); - checkEndOfFile(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setCompletionValues(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind, org.eclipse.cdt.core.parser.ast.IASTNode) - */ - protected void setCompletionValues(IASTScope scope, CompletionKind kind, - IASTNode context) throws EndOfFileException { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - { - setCompletionScope(scope); - setCompletionKind(kind); - setCompletionContext(context); - setCompletionFunctionName( ); - checkEndOfFile(); - } - } - - /** - * @return - */ - protected char[] getCompletionFunctionName() { - return functionOrConstructorName; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setCurrentFunctionName(java.lang.String) - */ - protected void setCurrentFunctionName(char[] functionName) { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - currentFunctionName = functionName; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setCompletionValuesNoContext(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind, org.eclipse.cdt.internal.core.parser.token.KeywordSets.Key) - */ - protected void setCompletionValuesNoContext(IASTScope scope, - CompletionKind kind, KeywordSetKey key) throws EndOfFileException { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - { - setCompletionScope(scope); - setCompletionKeywords(key); - setCompletionKind(kind); - checkEndOfFile(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setParameterListExpression(org.eclipse.cdt.core.parser.ast.IASTExpression) - */ - protected void setParameterListExpression( - IASTExpression assignmentExpression) { - if( mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE ) - parameterListExpression = assignmentExpression; - } - /** - * @return Returns the parameterListExpression. - */ - public final IASTExpression getParameterListExpression() { - return parameterListExpression; - } - - private OffsetDuple offsetRange; - private IToken firstTokenOfDuple = null, lastTokenOfDuple = null; - private IASTScope ourScope = null; - private IASTCompletionNode.CompletionKind ourKind = null; - private IASTNode ourContext = null; - private ITokenDuple greaterContextDuple = null; - private boolean pastPointOfSelection = false; - private IASTNode contextNode = null; - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.Parser#handleNewToken(org.eclipse.cdt.core.parser.IToken) - */ - protected void handleNewToken(IToken value) { - if( mode != ParserMode.SELECTION_PARSE ) return; - if( value != null && CharArrayUtils.equals(value.getFilename(), parserStartFilename)) - { - TraceUtil.outputTrace(log, "IToken provided w/offsets ", null, value.getOffset(), " & ", value.getEndOffset() ); //$NON-NLS-1$ //$NON-NLS-2$ - boolean change = false; - if( value.getOffset() == offsetRange.getFloorOffset() ) - { - TraceUtil.outputTrace(log, "Offset Floor Hit w/token \"", null, value.getCharImage(), "\"", null ); //$NON-NLS-1$ //$NON-NLS-2$ - firstTokenOfDuple = value; - change = true; - } - if( value.getEndOffset() == offsetRange.getCeilingOffset() ) - { - TraceUtil.outputTrace(log, "Offset Ceiling Hit w/token \"", null, value.getCharImage(), "\"", null ); //$NON-NLS-1$ //$NON-NLS-2$ - change = true; - lastTokenOfDuple = value; - } - if( change && tokenDupleCompleted() ) - { - if ( ourScope == null ) - ourScope = getCompletionScope(); - if( ourContext == null ) - ourContext = getCompletionContext(); - if( ourKind == null ) - ourKind = getCompletionKind(); - } - } - } - - - - - /** - * @return - */ - protected boolean tokenDupleCompleted() { - return lastTokenOfDuple != null && lastTokenOfDuple.getEndOffset() >= offsetRange.getCeilingOffset(); - } - - - /** - * - */ - protected ISelectionParseResult reconcileTokenDuple() throws ParseError { - if( firstTokenOfDuple == null || lastTokenOfDuple == null ) - throw new ParseError( ParseError.ParseErrorKind.OFFSET_RANGE_NOT_NAME ); - - if( getCompletionKind() == IASTCompletionNode.CompletionKind.UNREACHABLE_CODE ) - throw new ParseError( ParseError.ParseErrorKind.OFFSETDUPLE_UNREACHABLE ); - - ITokenDuple duple = TokenFactory.createTokenDuple( firstTokenOfDuple, lastTokenOfDuple ); - - if( ! duple.syntaxOfName() ) - throw new ParseError( ParseError.ParseErrorKind.OFFSET_RANGE_NOT_NAME ); - - return provideSelectionNode(duple); - } - - /** - * @param duple - * @return - */ - protected ISelectionParseResult provideSelectionNode(ITokenDuple duple) { - - ITokenDuple finalDuple = null; - // reconcile the name to look up first - if( ! duple.equals( greaterContextDuple )) - { - // 3 cases - // duple is prefix of greaterContextDuple - // or duple is suffix of greaterContextDuple - // duple is a sub-duple of greaterContextDuple - if( greaterContextDuple == null || duple.getFirstToken().equals( greaterContextDuple.getFirstToken() )) - finalDuple = duple; // => do not use greaterContextDuple - else if( duple.getLastSegment().getFirstToken().equals( greaterContextDuple.getLastSegment().getFirstToken() )) - finalDuple = greaterContextDuple; // => use greaterContextDuple - else - throw new ParseError( ParseError.ParseErrorKind.OFFSET_RANGE_NOT_NAME ); - } - else - finalDuple = greaterContextDuple; - - IASTNode node = lookupNode(finalDuple); - if( node == null ) return null; - if( !(node instanceof IASTOffsetableNamedElement )) return null; - return new SelectionParseResult( (IASTOffsetableNamedElement) node, new String( ((IASTOffsetableElement)node).getFilename() )); - } - - - - - /** - * @param finalDuple - * @return - */ - protected IASTNode lookupNode(ITokenDuple finalDuple) { - if( contextNode == null ) return null; - if( contextNode instanceof IASTDeclaration ) - { - if( contextNode instanceof IASTOffsetableNamedElement && !(contextNode instanceof IASTUsingDirective) && !(contextNode instanceof IASTUsingDeclaration)) - { - if( contextNode instanceof IASTFunction ) { - Iterator i = ((IASTFunction)contextNode).getParameters(); - while (i.hasNext()) { - IASTParameterDeclaration parm = (IASTParameterDeclaration)i.next(); - if (parm.getName().equals(finalDuple.toString()) && parm.getNameOffset() == finalDuple.getStartOffset() && parm.getStartingLine() == finalDuple.getLineNumber() && parm instanceof IASTNode) { - return (IASTNode) parm; - } - } - } - - if (contextNode instanceof IASTMethod) { - Iterator parms = ((IASTMethod)contextNode).getParameters(); - while (parms.hasNext()) { - Object parm = parms.next(); - if (parm instanceof IASTParameterDeclaration && ((IASTParameterDeclaration)parm).getName().equals(finalDuple.toString()) && ((IASTParameterDeclaration)parm).getNameOffset() == finalDuple.getStartOffset()) { - return (IASTNode)parm; - } - } - } - - if( ((IASTOffsetableNamedElement)contextNode).getName().equals( finalDuple.toString() ) && ((IASTOffsetableNamedElement)contextNode).getNameOffset() == finalDuple.getStartOffset()) // 75731 needs to include offset for equality as well... - return contextNode; - } - if( contextNode instanceof IASTQualifiedNameElement ) - { - String [] elementQualifiedName = ((IASTQualifiedNameElement)contextNode).getFullyQualifiedName(); - if( Arrays.equals( elementQualifiedName, finalDuple.toQualifiedName() ) ){ - IASTNode declNode = null; - if( contextNode instanceof ISymbolOwner ){ - ISymbolOwner owner = (ISymbolOwner) contextNode; - if( owner.getSymbol() != null && owner.getSymbol().getASTExtension() != null ){ - declNode = owner.getSymbol().getASTExtension().getPrimaryDeclaration(); - } - } - return (declNode != null) ? declNode : contextNode; - } - } - try { - if( ourKind == IASTCompletionNode.CompletionKind.NEW_TYPE_REFERENCE ) - { - if( contextNode instanceof IASTVariable ) - { - IASTInitializerClause initializer = ((IASTVariable)contextNode).getInitializerClause(); - if( initializer != null ) - { - IASTExpression ownerExpression = initializer.findExpressionForDuple( finalDuple ); - return astFactory.lookupSymbolInContext( ourScope, finalDuple, ownerExpression ); - } - } - } - - return astFactory.lookupSymbolInContext( ourScope, finalDuple, null ); - } catch (ASTNotImplementedException e) { - return null; - } - } - else if( contextNode instanceof IASTExpression ) - { - try { - return astFactory.lookupSymbolInContext( ourScope, finalDuple, contextNode ); - } catch (ASTNotImplementedException e) { - return null; - } - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ExpressionParser#setGreaterNameContext(org.eclipse.cdt.core.parser.ITokenDuple) - */ - protected void setGreaterNameContext(ITokenDuple tokenDuple) { - if( mode != ParserMode.SELECTION_PARSE ) return; - if( pastPointOfSelection ) return; - if( greaterContextDuple == null && lastTokenOfDuple != null && firstTokenOfDuple != null && CharArrayUtils.equals(tokenDuple.getFilename(), parserStartFilename)) - { - if( tokenDuple.getStartOffset() > lastTokenOfDuple.getEndOffset() ) - { - pastPointOfSelection = true; - return; - } - int tokensFound = 0; - - for( IToken token = tokenDuple.getFirstToken(); token != null; token = token.getNext() ) - { - if( token == firstTokenOfDuple ) ++tokensFound; - if( token == lastTokenOfDuple ) ++tokensFound; - if( token == tokenDuple.getLastToken() ) - break; - } - if( tokensFound == 2 ) - { - greaterContextDuple = tokenDuple; - pastPointOfSelection = true; - } - - } - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.Parser#endExpressionStatement(org.eclipse.cdt.core.parser.ast.IASTExpression) - */ - protected void endExpression(IASTExpression expression) - throws EndOfFileException { - if( mode != ParserMode.SELECTION_PARSE || ! tokenDupleCompleted() ) - cleanupLastToken(); - else - { - contextNode = expression; - throw new EndOfFileException(); - } - - } - - - public static class SelectionParseResult implements ISelectionParseResult - { - - public SelectionParseResult( IASTOffsetableNamedElement node, String fileName ) - { - this.node = node; - this.fileName = fileName; - } - - private final String fileName; - private final IASTOffsetableNamedElement node; - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IParser.ISelectionParseResult#getNode() - */ - public IASTOffsetableNamedElement getOffsetableNamedElement() { - return node; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IParser.ISelectionParseResult#getFilename() - */ - public String getFilename() { - return fileName; - } - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.Parser#endEnumerator(org.eclipse.cdt.core.parser.ast.IASTEnumerator) - */ - protected void endEnumerator(IASTEnumerator enumerator) throws EndOfFileException { - if( mode != ParserMode.SELECTION_PARSE || ! tokenDupleCompleted() ) - cleanupLastToken(); - else - { - contextNode = enumerator; - throw new EndOfFileException(); - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.Parser#endClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - protected void handleClassSpecifier(IASTClassSpecifier classSpecifier) - throws EndOfFileException { - if( mode != ParserMode.SELECTION_PARSE || ! tokenDupleCompleted() ) - cleanupLastToken(); - else - { - contextNode = classSpecifier; - throw new EndOfFileException(); - } - } - - protected void handleEnumeration(IASTEnumerationSpecifier enumeration) throws EndOfFileException { - if( mode != ParserMode.SELECTION_PARSE || ! tokenDupleCompleted() ) - cleanupLastToken(); - else - { - contextNode = enumeration; - throw new EndOfFileException(); - } - } - - /** - * @param set - * @param string - * @return - */ - private Set reconcileKeywords(Set keywords, String prefix) { - if( keywords == null ) return null; - if( prefix.equals( "")) return keywords; //$NON-NLS-1$ - Set resultSet = new TreeSet(); - Iterator i = keywords.iterator(); - while( i.hasNext() ) - { - String value = (String) i.next(); - if( value.startsWith( prefix ) ) - resultSet.add( value ); - else if( value.compareTo( prefix ) > 0 ) - break; - } - return resultSet; - } - - - /** - * @return - */ - protected Set getKeywordSet() { - return keywordSet; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.Parser#handleOffsetLimitException() - */ - protected void handleOffsetLimitException(OffsetLimitReachedException exception) throws EndOfFileException { - if( mode != ParserMode.COMPLETION_PARSE ) - throw new EndOfFileException(); - - if( exception.getCompletionNode() == null ) - { - setCompletionToken( exception.getFinalToken() ); - if( (finalToken!= null )&& (!finalToken.canBeAPrefix() )) - setCompletionToken(null); - } - else - { - ASTCompletionNode node = (ASTCompletionNode) exception.getCompletionNode(); - setCompletionValues( node.getCompletionKind(), node.getKeywordSet(), node.getCompletionPrefix() ); - } - - throw exception; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.Parser#getCompletionKindForDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope) - */ - protected CompletionKind getCompletionKindForDeclaration(IASTScope scope, CompletionKind overide) { - if( mode != ParserMode.COMPLETION_PARSE ) return null; - IASTCompletionNode.CompletionKind kind = null; - if( overide != null ) - kind = overide; - else if( scope instanceof IASTClassSpecifier ) - kind = CompletionKind.FIELD_TYPE; - else if (scope instanceof IASTCodeScope) - kind = CompletionKind.SINGLE_NAME_REFERENCE; - else - kind = CompletionKind.VARIABLE_TYPE; - return kind; - } - - - protected IToken getCompletionToken() - { - if( mode != ParserMode.COMPLETION_PARSE ) - return null; - return finalToken; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTReferenceStore#processReferences() - */ - public static void processReferences(List references, ISourceElementRequestor requestor ) - { - if( references == null || references.isEmpty() ) - return; - - for( int i = 0; i < references.size(); ++i ) - { - IASTReference reference = ((IASTReference)references.get(i)); - reference.acceptElement(requestor ); - } - - references.clear(); - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserExtensionFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserExtensionFactory.java deleted file mode 100644 index 8b01f5eb798..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserExtensionFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; - -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.extension.ExtensionDialect; -import org.eclipse.cdt.core.parser.extension.IASTFactoryExtension; -import org.eclipse.cdt.core.parser.extension.IParserExtension; -import org.eclipse.cdt.core.parser.extension.IParserExtensionFactory; -import org.eclipse.cdt.internal.core.parser.ast.GCCASTExtension; - -/** - * @author jcamelon - */ -public class ParserExtensionFactory implements IParserExtensionFactory { - - private final ExtensionDialect dialect; - - /** - * @param dialect - */ - public ParserExtensionFactory(ExtensionDialect dialect) { - this.dialect = dialect; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtensionFactory#createParserExtension() - */ - public IParserExtension createParserExtension() throws ParserFactoryError - { - if( dialect == ExtensionDialect.GCC ) - return new GCCParserExtension(); - throw new ParserFactoryError( ParserFactoryError.Kind.BAD_DIALECT ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IParserExtensionFactory#createASTExtension(org.eclipse.cdt.core.parser.ParserMode) - */ - public IASTFactoryExtension createASTExtension(ParserMode mode) { - if( dialect == ExtensionDialect.GCC ) - return GCCASTExtension.createExtension( mode ); - throw new ParserFactoryError( ParserFactoryError.Kind.BAD_DIALECT ); - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserProblemFactory.java deleted file mode 100644 index 0384d8f2c29..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserProblemFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; - -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.internal.core.parser.problem.BaseProblemFactory; -import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; - -/** - * @author jcamelon - * - */ -public class ParserProblemFactory extends BaseProblemFactory - implements - IProblemFactory { - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IProblemFactory#createProblem(int, int, int, int, char[], java.lang.String, boolean, boolean) - */ - public IProblem createProblem( - int id, - int start, - int end, - int line, - char[] file, - char[] arg, - boolean warn, - boolean error) - { - if( checkBitmask( id, IProblem.INTERNAL_RELATED ) ) - return createInternalProblem( id, start, end, line, file, arg, warn, error ); - - if ( checkBitmask( id, IProblem.SYNTAX_RELATED ) || - checkBitmask( id, IProblem.SEMANTICS_RELATED) ) - return super.createProblem( - id, - start, - end, - line, - file, - arg, - warn, - error); - - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.problem.IProblemFactory#getRequiredAttributesForId(int) - */ - public String getRequiredAttributesForId(int id) { - return ""; //$NON-NLS-1$ - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java deleted file mode 100644 index a3ecdf4ada5..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/QuickParseCallback.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.IQuickParseCallback; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement; - - -public class QuickParseCallback extends NullSourceElementRequestor implements IQuickParseCallback -{ - protected IASTCompilationUnit compUnit = null; - protected List inclusions = new ArrayList(); - protected List macros = new ArrayList(); - protected boolean hasNoProblems = true; - - public Iterator getInclusions() - { - return inclusions.iterator(); - } - - public Iterator getMacros() - { - return macros.iterator(); - } - - public Iterator getDeclarations(){ - try{ - return compUnit.getDeclarations(); - } - catch (ASTNotImplementedException ne ) - { - return null; - } - } - - public void exitMethodBody( IASTMethod method ) - { - method.setHasFunctionBody( true ); - } - - - public void exitFunctionBody( IASTFunction function ) - { - function.setHasFunctionBody( true ); - } - - - - public void exitCompilationUnit( IASTCompilationUnit compilationUnit ) - { - this.compUnit = compilationUnit; - } - - public void exitInclusion( IASTInclusion inclusion ) - { - inclusions.add( inclusion ); - } - - public void acceptMacro( IASTMacro macro ) - { - macros.add( macro ); - } - - /** - * @return - */ - public IASTCompilationUnit getCompilationUnit() - { - return compUnit; - } - - public class OffsetableIterator implements Iterator - { - private Iterator declarationIter; - private final Iterator inclusionIter; - private final Iterator macroIter; - - private IASTOffsetableElement currentMacro = null, currentInclusion= null, currentDeclaration= null; - - public OffsetableIterator() - { - declarationIter = getDeclarations(); - inclusionIter = getInclusions(); - macroIter = getMacros(); - updateInclusionIterator(); - updateMacroIterator(); - updateDeclarationIterator(); - } - - private Object updateDeclarationIterator() - { - Object offsetable = currentDeclaration; - if(declarationIter != null) - currentDeclaration = ( declarationIter.hasNext() ) ? (IASTOffsetableElement)declarationIter.next() : null; - return offsetable; - } - - private Object updateMacroIterator() - { - Object offsetable = currentMacro; - currentMacro = ( macroIter.hasNext() ) ? (IASTOffsetableElement)macroIter.next() : null; - return offsetable; - } - - private Object updateInclusionIterator() - { - Object offsetable = currentInclusion; - currentInclusion = ( inclusionIter.hasNext() ) ? (IASTOffsetableElement)inclusionIter.next() : null; - return offsetable; - } - /* (non-Javadoc) - * @see java.util.Iterator#hasNext() - */ - public boolean hasNext() { - return (( currentMacro == null && currentInclusion == null && currentDeclaration == null ) ? - false : true); - } - - /* (non-Javadoc) - * @see java.util.Iterator#next() - */ - public Object next() { - // case 1: all are null - if( ! hasNext() ) - throw new NoSuchElementException(); - - // case 2: two of three are null - if( currentMacro == null && currentInclusion == null ) - return updateDeclarationIterator(); - if( currentDeclaration == null && currentInclusion == null ) - return updateMacroIterator(); - if( currentMacro == null && currentDeclaration == null ) - return updateInclusionIterator(); - - // case 3: 1 is null - if( currentMacro == null ) - { - if( currentDeclaration.getStartingOffset() < currentInclusion.getStartingOffset() ) - return updateDeclarationIterator(); - return updateInclusionIterator(); - } - - if( currentInclusion == null ) - { - if( currentDeclaration.getStartingOffset() < currentMacro.getStartingOffset() ) - return updateDeclarationIterator(); - return updateMacroIterator(); - } - - if( currentDeclaration == null ) - { - if( currentInclusion.getStartingOffset() < currentMacro.getStartingOffset() ) - return updateInclusionIterator(); - return updateMacroIterator(); - } - - // case 4: none are null - if( currentInclusion.getStartingOffset() < currentMacro.getStartingOffset() && - currentInclusion.getStartingOffset() < currentDeclaration.getStartingOffset() ) - return updateInclusionIterator(); - - if( currentMacro.getStartingOffset() < currentInclusion.getStartingOffset() && - currentMacro.getStartingOffset() < currentDeclaration.getStartingOffset() ) - return updateMacroIterator(); - // only remaining case - return updateDeclarationIterator(); - } - - /* (non-Javadoc) - * @see java.util.Iterator#remove() - */ - public void remove() { - throw new UnsupportedOperationException( ParserMessages.getString("QuickParseCallback.exception.constIterator")); //$NON-NLS-1$ - } - } - - public Iterator iterateOffsetableElements() - { - return new OffsetableIterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem) - */ - public boolean acceptProblem(IProblem problem) { - setHasNoProblems(false); - return super.acceptProblem(problem); - } - /** - * @return Returns the hasProblems. - */ - public boolean hasNoProblems() { - return hasNoProblems; - } - /** - * @param hasProblems The hasProblems to set. - */ - public void setHasNoProblems(boolean hasProblems) { - this.hasNoProblems = hasProblems; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/StructuralParseCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/StructuralParseCallback.java deleted file mode 100644 index b24178b8252..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/StructuralParseCallback.java +++ /dev/null @@ -1,267 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; -import java.util.LinkedList; - -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTLinkageSpecification; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTScope; - -/** - * @author hamer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class StructuralParseCallback extends QuickParseCallback{ - - protected LinkedList scopeStack = new LinkedList(); - protected IASTScope currentScope = null; - protected int inclusionLevel = 0; - - - private void addElement (IASTDeclaration element){ - if(inclusionLevel == 0){ - if( currentScope instanceof ASTScope ) - ((ASTScope)currentScope).addDeclaration(element); - else if( currentScope instanceof ASTLinkageSpecification ) - ((ASTLinkageSpecification)currentScope).addDeclaration( element ); - } - } - - private void enterScope(IASTNode node){ - if(node instanceof IASTScope){ - if(node instanceof ASTScope){ - ((ASTScope)node).initDeclarations(); - } - pushScope((IASTScope)node); - } - } - - private void exitScope(IASTNode node){ - if(node instanceof IASTScope){ - popScope(); - } - } - - private void pushScope( IASTScope scope ){ - scopeStack.addFirst( currentScope ); - currentScope = scope; - } - - private IASTScope popScope(){ - IASTScope oldScope = currentScope; - currentScope = (scopeStack.size() > 0 ) ? (IASTScope) scopeStack.removeFirst() : null; - return oldScope; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMacro(org.eclipse.cdt.core.parser.ast.IASTMacro) - */ - public void acceptMacro(IASTMacro macro) { - if(inclusionLevel == 0) - macros.add(macro); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptVariable(org.eclipse.cdt.core.parser.ast.IASTVariable) - */ - public void acceptVariable(IASTVariable variable) { - addElement(variable); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptFunctionDeclaration(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void acceptFunctionDeclaration(IASTFunction function) { - if(function.getOwnerTemplateDeclaration() == null) - addElement(function); - else if(function.getOwnerTemplateDeclaration() instanceof IASTTemplateDeclaration) - addElement((IASTTemplateDeclaration)function.getOwnerTemplateDeclaration()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptTypedefDeclaration(org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration) - */ - public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef) { - addElement(typedef); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptUsingDirective(org.eclipse.cdt.core.parser.ast.IASTUsingDirective) - */ - public void acceptUsingDirective(IASTUsingDirective usageDirective) { - addElement(usageDirective); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier) - */ - public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration) { - enterScope(enumeration); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier) - */ - public void acceptElaboratedForewardDeclaration(IASTElaboratedTypeSpecifier elaboratedType) { - enterScope(elaboratedType); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptAbstractTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration) - */ - public void acceptAbstractTypeSpecDeclaration(IASTAbstractTypeSpecifierDeclaration abstractDeclaration) { - if(abstractDeclaration.getOwnerTemplateDeclaration() == null) - addElement(abstractDeclaration); - else if(abstractDeclaration.getOwnerTemplateDeclaration() instanceof IASTTemplateDeclaration) - addElement((IASTTemplateDeclaration)abstractDeclaration.getOwnerTemplateDeclaration()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void enterInclusion(IASTInclusion inclusion) { - if(inclusionLevel == 0) - inclusions.add(inclusion); - inclusionLevel++; - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { - addElement(namespaceDefinition); - enterScope(namespaceDefinition); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - public void enterClassSpecifier(IASTClassSpecifier classSpecification) { - enterScope(classSpecification); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void enterLinkageSpecification(IASTLinkageSpecification linkageSpec) { - addElement(linkageSpec); - enterScope(linkageSpec); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void enterCompilationUnit(IASTCompilationUnit compilationUnit) { - enterScope(compilationUnit); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptMethodDeclaration(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void acceptMethodDeclaration(IASTMethod method) { - if(method.getOwnerTemplateDeclaration() == null) - addElement(method); - else if(method.getOwnerTemplateDeclaration() instanceof IASTTemplateDeclaration) - addElement((IASTTemplateDeclaration)method.getOwnerTemplateDeclaration()); - } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptField(org.eclipse.cdt.core.parser.ast.IASTField) - */ - public void acceptField(IASTField field) { - addElement(field); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitCompilationUnit(org.eclipse.cdt.core.parser.ast.IASTCompilationUnit) - */ - public void exitCompilationUnit(IASTCompilationUnit compilationUnit) { - exitScope(compilationUnit); - this.compUnit = compilationUnit; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitInclusion(org.eclipse.cdt.core.parser.ast.IASTInclusion) - */ - public void exitInclusion( IASTInclusion inclusion ) - { - inclusionLevel--; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IQuickParseCallback#getCompilationUnit() - */ - public IASTCompilationUnit getCompilationUnit() { - return compUnit; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - public void exitClassSpecifier(IASTClassSpecifier classSpecification) { - exitScope(classSpecification); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification) - */ - public void exitLinkageSpecification(IASTLinkageSpecification linkageSpec) { - exitScope(linkageSpec); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#exitNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition) - */ - public void exitNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { - exitScope(namespaceDefinition); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterFunctionBody(org.eclipse.cdt.core.parser.ast.IASTFunction) - */ - public void enterFunctionBody(IASTFunction function) { - if(function.getOwnerTemplateDeclaration() == null) - addElement(function); - else if(function.getOwnerTemplateDeclaration() instanceof IASTTemplateDeclaration) - addElement((IASTTemplateDeclaration)function.getOwnerTemplateDeclaration()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#enterMethodBody(org.eclipse.cdt.core.parser.ast.IASTMethod) - */ - public void enterMethodBody(IASTMethod method) { - if(method.getOwnerTemplateDeclaration() == null) - addElement(method); - else if(method.getOwnerTemplateDeclaration() instanceof IASTTemplateDeclaration) - addElement((IASTTemplateDeclaration)method.getOwnerTemplateDeclaration()); - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TypeId.java deleted file mode 100644 index 740b20d0adf..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TypeId.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.core.parser.ast.IASTScope; - -/** - * @author jcamelon - * - */ -public class TypeId implements IDeclarator -{ - private static final int DEFAULT_ARRAYLIST_SIZE = 4; - private ITokenDuple name; - private List arrayModifiers; - private List pointerOperators; - private IASTScope scope; - - /** - * @param scope2 - */ - public void reset(IASTScope s) { - this.scope = s; - arrayModifiers = Collections.EMPTY_LIST; - pointerOperators = Collections.EMPTY_LIST; - name = null; - } - /** - * - */ - public TypeId() - { - reset( null ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IDeclarator#getPointerOperators() - */ - public List getPointerOperators() - { - return pointerOperators; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IDeclarator#addPointerOperator(org.eclipse.cdt.core.parser.ast.ASTPointerOperator) - */ - public void addPointerOperator(ASTPointerOperator ptrOp) - { - if( pointerOperators == Collections.EMPTY_LIST ) - pointerOperators = new ArrayList( DEFAULT_ARRAYLIST_SIZE ); - pointerOperators.add( ptrOp ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IDeclarator#addArrayModifier(org.eclipse.cdt.core.parser.ast.IASTArrayModifier) - */ - public void addArrayModifier(IASTArrayModifier arrayMod) - { - if( arrayModifiers == Collections.EMPTY_LIST ) - arrayModifiers = new ArrayList( DEFAULT_ARRAYLIST_SIZE ); - arrayModifiers.add( arrayMod ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IDeclarator#getArrayModifiers() - */ - public List getArrayModifiers() - { - return arrayModifiers; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IDeclarator#setPointerOperatorName(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public void setPointerOperatorName(ITokenDuple nameDuple) - { - name = nameDuple; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IDeclarator#getPointerOperatorNameDuple() - */ - public ITokenDuple getPointerOperatorNameDuple() - { - return name; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.IDeclarator#getScope() - */ - public IASTScope getScope() { - return scope; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTAbstractDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTAbstractDeclaration.java deleted file mode 100644 index 714838d152d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTAbstractDeclaration.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast; - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; - -/** - * @author jcamelon - * - */ -public class ASTAbstractDeclaration implements IASTAbstractDeclaration -{ - private final boolean isVolatile; - private final List parms; - private final boolean isConst; - private final IASTTypeSpecifier typeSpecifier; - private final List pointerOperators; - private final List arrayModifiers; - private final ASTPointerOperator pointerOperator; - /** - * @param isConst - * @param typeSpecifier - * @param pointerOperators - * @param arrayModifiers - */ - public ASTAbstractDeclaration(boolean isConst, boolean isVolatile, IASTTypeSpecifier typeSpecifier, List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOp ) - { - this.isConst = isConst; - this.typeSpecifier = typeSpecifier; - this.pointerOperators = pointerOperators; - this.arrayModifiers = arrayModifiers; - this.parms = parameters; - this.pointerOperator = pointerOp; - this.isVolatile = isVolatile; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#isConst() - */ - public boolean isConst() - { - return isConst; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getTypeSpecifier() - */ - public IASTTypeSpecifier getTypeSpecifier() - { - return typeSpecifier; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getPointerOperators() - */ - public Iterator getPointerOperators() - { - if( pointerOperators == null ) return EmptyIterator.EMPTY_ITERATOR; - return pointerOperators.iterator(); - } - public List getPointerOperatorsList(){ - if( pointerOperators == null ) return Collections.EMPTY_LIST; - return pointerOperators; - } - - public int getNumPointerOperators(){ - if( pointerOperators == null ) - return 0; - return pointerOperators.size(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getArrayModifiers() - */ - public Iterator getArrayModifiers() - { - if( arrayModifiers == null ) return EmptyIterator.EMPTY_ITERATOR; - return arrayModifiers.iterator(); - } - - public List getArrayModifiersList(){ - if( arrayModifiers == null ) return Collections.EMPTY_LIST; - return arrayModifiers; - } - - public int getNumArrayModifiers(){ - if( arrayModifiers == null ) - return 0; - return arrayModifiers.size(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getParameters() - */ - public Iterator getParameters() - { - if( parms == null ) return EmptyIterator.EMPTY_ITERATOR; - return parms.iterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getPointerToFunctionOperator() - */ - public ASTPointerOperator getPointerToFunctionOperator() - { - return pointerOperator; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#isVolatile() - */ - public boolean isVolatile() - { - return isVolatile; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - List arrayMods = getArrayModifiersList(); - int size = arrayMods.size(); - for( int i = 0; i< size; i++ ) - ((IASTArrayModifier)arrayMods.get(i)).acceptElement(requestor); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTArrayModifier.java deleted file mode 100644 index 0904cdb505f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTArrayModifier.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.core.parser.ast.IASTExpression; - -/** - * @author jcamelon - * - */ -public class ASTArrayModifier implements IASTArrayModifier -{ - private final IASTExpression expression; - /** - * @param exp - */ - public ASTArrayModifier(IASTExpression exp) - { - expression = exp; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.IASTArrayModifier#getExpression() - */ - public IASTExpression getExpression() - { - return expression; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - if( expression != null ) - expression.acceptElement( requestor ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTCompletionNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTCompletionNode.java deleted file mode 100644 index 21873b05cb3..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTCompletionNode.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast; - -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTScope; - -/** - * @author jcamelon - */ -public class ASTCompletionNode implements IASTCompletionNode { - - private final String prefix; - private final IASTNode context; - private final IASTScope scope; - private final CompletionKind kind; - private final Set keywordSet; - private final String functionName; - private final IASTExpression parameterListExpression; - - public ASTCompletionNode( CompletionKind kind, IASTScope scope, IASTNode context, String prefix, Set keywords, String functionName, IASTExpression expression ) - { - this.kind = kind; - this.context = context; - this.scope = scope; - this.prefix = prefix; - this.keywordSet = keywords; - this.functionName = functionName; - this.parameterListExpression = expression; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionKind() - */ - public CompletionKind getCompletionKind() { - return kind; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionScope() - */ - public IASTScope getCompletionScope() { - return scope; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionContext() - */ - public IASTNode getCompletionContext() { - return context; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getCompletionPrefix() - */ - public String getCompletionPrefix() { - return prefix; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getKeywords() - */ - public Iterator getKeywords() { - if( keywordSet == null ) - return EmptyIterator.EMPTY_ITERATOR; - return keywordSet.iterator(); - } - - public Set getKeywordSet() - { - return keywordSet; - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getFunctionName() - */ - public String getFunctionName() { - return functionName; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCompletionNode#getFunctionParameters() - */ - public IASTExpression getFunctionParameters() { - return parameterListExpression; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTDesignator.java deleted file mode 100644 index 28d33fd5cbe..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTDesignator.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTDesignator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; - -/** - * @author jcamelon - * - */ -public class ASTDesignator implements IASTDesignator -{ - /** - * @param kind - * @param constantExpression - * @param string - */ - public ASTDesignator(DesignatorKind kind, IASTExpression constantExpression, char[] fieldName, int fieldOffset ) - { - this.fieldName = fieldName; - this.constantExpression = constantExpression; - this.kind = kind; - this.fieldOffset = fieldOffset; - } - - private int fieldOffset; - private final char[] fieldName; - private final IASTExpression constantExpression; - private final DesignatorKind kind; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTDesignator#getKind() - */ - public DesignatorKind getKind() - { - return kind; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTDesignator#arraySubscriptExpression() - */ - public IASTExpression arraySubscriptExpression() - { - return constantExpression; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTDesignator#fieldName() - */ - public String fieldName() - { - return String.valueOf(fieldName); - } - public char[] fieldNameCharArray(){ - return fieldName; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - if( constantExpression != null ) - constantExpression.acceptElement(requestor); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor ) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor ) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTDesignator#fieldOffset() - */ - public int fieldOffset() - { - return fieldOffset; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java deleted file mode 100644 index 1df894f0845..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTInclusion.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; - -/** - * @author jcamelon - * - */ -public class ASTInclusion implements IASTInclusion { - - public ASTInclusion( char[] name, char[] fileName, boolean local, int startingOffset, int startLine, int nameOffset, int nameEndOffset, int nameLine, int endOffset, int endLine, char [] fn, boolean i ) - { - this.name = name; - this.fileName = fileName; - this.local = local; - setStartingOffsetAndLineNumber(startingOffset, startLine); - setNameOffset(nameOffset); - setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); - setEndingOffsetAndLineNumber(endOffset, endLine); - this.filename = fn; - this.isImplicit = i; - } - - private int nameEndOffset; - private final char[] name, fileName; - private final boolean local; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInclusion#getName() - */ - public String getName() { - return String.valueOf(name); - } - public char[] getNameCharArray(){ - return name; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInclusion#getFullFileName() - */ - public String getFullFileName() { - return String.valueOf(fileName); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInclusion#isLocal() - */ - public boolean isLocal() { - return local; - } - - - private int startingOffset = 0, nameOffset = 0, endingOffset = 0; - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementStartingOffset() - */ - public int getStartingOffset() { - return startingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementEndingOffset() - */ - public int getEndingOffset() { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementNameOffset() - */ - public int getNameOffset() { - return nameOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.IOffsetableElementRW#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) { - startingOffset = offset; - startingLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.IOffsetableElementRW#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) { - endingOffset = offset; - endingLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.IOffsetableElementRW#setNameOffset(int) - */ - public void setNameOffset(int o) { - nameOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterInclusion(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitInclusion(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - private int startingLineNumber, endingLineNumber, nameLineNumber; - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLineNumber; - } - - private int fileIndex; - private final char[] filename; - private final boolean isImplicit; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFileIndex() - */ - public int getFileIndex() { - return fileIndex; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setFileIndex() - */ - public void setFileIndex(int index) { - fileIndex = index; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInclusion#isImplicit() - */ - public boolean isImplicit() { - return isImplicit; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java deleted file mode 100644 index 6959431b63f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTMacro.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast; - - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTMacro; - -/** - * @author jcamelon - * - */ -public class ASTMacro implements IASTMacro { - - private int nameEndOffset = 0; - private final char[] name; - private final char[] fn; - - public ASTMacro( char[] name, int start, int startLine, int nameBeg, int nameEnd, int nameLine, int end, int endLine, char[] fn, boolean implicit ) - { - this.name =name; - setStartingOffsetAndLineNumber(start, startLine); - setNameOffset(nameBeg); - setNameEndOffsetAndLineNumber(nameEnd, nameLine); - setEndingOffsetAndLineNumber(end, endLine); - this.fn = fn; - this.isImplicit = implicit; - } - - private int startingOffset = 0, endingOffset = 0, nameOffset = 0; - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMacro#getName() - */ - public String getName() { - return String.valueOf(name); - } - public char[] getNameCharArray(){ - return name; - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IOffsetableElementRW#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IOffsetableElementRW#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IOffsetableElementRW#setNameOffset(int) - */ - public void setNameOffset(int o) { - nameOffset = o; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementStartingOffset() - */ - public int getStartingOffset() { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementEndingOffset() - */ - public int getEndingOffset() { - return endingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IOffsetableElement#getElementNameOffset() - */ - public int getNameOffset() { - return nameOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptMacro( this ); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - private int startingLineNumber, endingLineNumber, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLineNumber; - } - - - private int fileIndex; - private final boolean isImplicit; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFileIndex() - */ - public int getFileIndex() { - return fileIndex; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setFileIndex() - */ - public void setFileIndex(int index) { - fileIndex = index; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMacro#isImplicit() - */ - public boolean isImplicit() { - return isImplicit; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTQualifiedNamedElement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTQualifiedNamedElement.java deleted file mode 100644 index a2fdf10f95f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/ASTQualifiedNamedElement.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast; - -import java.util.ArrayList; - -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTScopedElement; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; - -/** - * @author jcamelon - * - */ -public class ASTQualifiedNamedElement implements IASTQualifiedNameElement -{ - /** - * @param scope - */ - public ASTQualifiedNamedElement(IASTScope scope, char[] name ) - { - ArrayList names = new ArrayList(4); - IASTScope parent = scope; - - names.add( name ); // push on our own name - while (parent != null) - { - if (parent instanceof IASTNamespaceDefinition - || parent instanceof IASTClassSpecifier ) - { - names.add( ((IASTOffsetableNamedElement)parent).getNameCharArray() ); - if( parent instanceof IASTScopedElement ) - parent = ((IASTScopedElement)parent).getOwnerScope(); - } - else if( parent instanceof IASTTemplateDeclaration ) - { - if( parent instanceof IASTScopedElement ) - parent = ((IASTScopedElement)parent).getOwnerScope(); - continue; - } - else - break; - } - if (names.size() != 0) - { - qualifiedNames = new char[names.size()][]; - int counter = 0; - for( int i = names.size() - 1; i >= 0; i-- ) - qualifiedNames[counter++] = (char[])names.get(i); - } - else - qualifiedNames = null; - - } - - public String[] getFullyQualifiedName() - { - String[] result = new String[qualifiedNames.length ]; - for( int i = 0; i < qualifiedNames.length; i++ ){ - result[i] = String.valueOf(qualifiedNames[i]); - } - return result; - } - - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedNames; - } - - private final char[][] qualifiedNames; - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java deleted file mode 100644 index e4d2510cb6e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/BaseASTFactory.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast; - -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.core.parser.ast.IASTDesignator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTDesignator.DesignatorKind; -import org.eclipse.cdt.core.parser.extension.IASTFactoryExtension; - - -/** - * @author jcamelon - * - */ -public class BaseASTFactory { - - public BaseASTFactory( IASTFactoryExtension extension ) - { - this.extension = extension; - } - - protected IParserLogService logService; - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.IASTFactory#createMacro(java.lang.String, int, int, int) - */ - public IASTMacro createMacro(char[] name, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn, boolean isImplicit) { - IASTMacro m = new ASTMacro( name, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, endingOffset, endingLine, fn, isImplicit ); - return m; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.IASTFactory#createInclusion(java.lang.String, java.lang.String, boolean) - */ - public IASTInclusion createInclusion(char[] name, char[] fileName, boolean local, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] fn, boolean isImplicit) { - IASTInclusion inclusion = new ASTInclusion( name, fileName, local, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, endingOffset, endingLine, fn, isImplicit ); - return inclusion; - } - - public IASTAbstractDeclaration createAbstractDeclaration(boolean isConst, boolean isVolatile, IASTTypeSpecifier typeSpecifier, List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOperator) - { - return new ASTAbstractDeclaration( isConst, isVolatile, typeSpecifier, pointerOperators, arrayModifiers, parameters, pointerOperator ); - } - - public IASTArrayModifier createArrayModifier(IASTExpression exp) - { - return new ASTArrayModifier( exp ); - } - - public IASTDesignator createDesignator(DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier, Map extensionParms) - { - if( extension.overrideCreateDesignatorMethod( kind )) - return extension.createDesignator( kind, constantExpression, fieldIdentifier, extensionParms ); - return new ASTDesignator( kind, constantExpression, - fieldIdentifier == null ? new char[0] : fieldIdentifier.getCharImage(), //$NON-NLS-1$ - fieldIdentifier == null ? -1 : fieldIdentifier.getOffset() ); - } - - public void setLogger(IParserLogService log) { - logService = log; - } - - protected final IASTFactoryExtension extension; - protected static final char[] EMPTY_STRING = new char[0]; - - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java deleted file mode 100644 index 3cfa103becc..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast; - -import java.util.Collections; -import java.util.Map; - -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.IASTDesignator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTDesignator.DesignatorKind; -import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCDesignator; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.extension.IASTFactoryExtension; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTypeId; -import org.eclipse.cdt.internal.core.parser.ast.complete.gcc.ASTGCCSimpleTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.ast.complete.gcc.GCCASTCompleteExtension; -import org.eclipse.cdt.internal.core.parser.ast.gcc.ASTGCCDesignator; -import org.eclipse.cdt.internal.core.parser.ast.quick.GCCASTExpressionExtension; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; -import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider; - -/** - * @author jcamelon - * - */ -public abstract class GCCASTExtension implements IASTFactoryExtension { - protected final ParserMode mode; - protected static final char[] EMPTY_STRING = "".toCharArray(); //$NON-NLS-1$ - /** - * @param mode - */ - public GCCASTExtension(ParserMode mode) { - this.mode = mode; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#canHandleExpressionKind(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind) - */ - public boolean canHandleExpressionKind(Kind kind) { - if( kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID || - kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_UNARYEXPRESSION || - kind == IASTGCCExpression.Kind.UNARY_TYPEOF_UNARYEXPRESSION || - kind == IASTGCCExpression.Kind.UNARY_TYPEOF_TYPEID || - kind == IASTGCCExpression.Kind.RELATIONAL_MAX || - kind == IASTGCCExpression.Kind.RELATIONAL_MIN || - kind == IASTGCCExpression.Kind.STATEMENT_EXPRESSION ) - return true; - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#getExpressionResultType(org.eclipse.cdt.internal.core.parser.pst.TypeInfo, org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTTypeId, org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public ITypeInfo getExpressionResultType(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTTypeId typeId) { - ITypeInfo info = null; - if( kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID || - kind == IASTGCCExpression.Kind.UNARY_ALIGNOF_UNARYEXPRESSION ) - { - info = TypeInfoProvider.newTypeInfo( ITypeInfo.t_int ); - info.setBit(true, ITypeInfo.isUnsigned); - } - else if( kind == IASTGCCExpression.Kind.RELATIONAL_MAX || - kind == IASTGCCExpression.Kind.RELATIONAL_MIN ) - { - if( lhs instanceof ASTExpression ) - info = TypeInfoProvider.newTypeInfo( ((ASTExpression)lhs).getResultType().getResult() ); - } - else if( kind == IASTGCCExpression.Kind.UNARY_TYPEOF_TYPEID ) - { - if( typeId instanceof ASTTypeId ) - info = TypeInfoProvider.newTypeInfo( ((ASTTypeId)typeId).getTypeSymbol().getTypeInfo() ); - } - else if ( kind == IASTGCCExpression.Kind.UNARY_TYPEOF_UNARYEXPRESSION ) - { - if( lhs instanceof ASTExpression ){ - if( ((ASTExpression) lhs).getResultType() != null ) - info = TypeInfoProvider.newTypeInfo( ((ASTExpression)lhs).getResultType().getResult() ); - else { - info = TypeInfoProvider.newTypeInfo( ITypeInfo.t_void ); - } - } - } - - if( info != null ) - return info; - return TypeInfoProvider.newTypeInfo(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#overrideCreateSimpleTypeSpecifierMethod() - */ - public boolean overrideCreateSimpleTypeSpecifierMethod(Type type) { - if( type == IASTGCCSimpleTypeSpecifier.Type.TYPEOF ) - return true; - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTScope, org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type, org.eclipse.cdt.core.parser.ITokenDuple, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean) - */ - public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(ParserSymbolTable pst, IASTScope scope, Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary, boolean isGlobal, Map extensionParms) { - if( kind == IASTGCCSimpleTypeSpecifier.Type.TYPEOF ) - { - ASTExpression typeOfExpression = (ASTExpression) extensionParms.get( IASTGCCSimpleTypeSpecifier.TYPEOF_EXRESSION ); - ISymbol s = pst.newSymbol( EMPTY_STRING ); - s.setTypeInfo( typeOfExpression.getResultType().getResult() ); - return new ASTGCCSimpleTypeSpecifier( s, isTypename, ( typeName == null ? EMPTY_STRING : typeName.toCharArray()), Collections.EMPTY_LIST, typeOfExpression ); - } - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#overrideCreateDesignatorMethod(org.eclipse.cdt.core.parser.ast.IASTDesignator.DesignatorKind) - */ - public boolean overrideCreateDesignatorMethod(DesignatorKind kind) { - if( kind == IASTGCCDesignator.DesignatorKind.SUBSCRIPT_RANGE ) - return true; - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#createDesignator(org.eclipse.cdt.core.parser.ast.IASTDesignator.DesignatorKind, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.IToken, java.util.Map) - */ - public IASTDesignator createDesignator(DesignatorKind kind, IASTExpression constantExpression, IToken fieldIdentifier, Map extensionParms) { - IASTExpression secondExpression = (IASTExpression) extensionParms.get( IASTGCCDesignator.SECOND_EXRESSION ); - return new ASTGCCDesignator( kind, constantExpression, EMPTY_STRING, -1, secondExpression ); - } - - /** - * @param mode2 - * @return - */ - public static IASTFactoryExtension createExtension(ParserMode parseMode) { - if( parseMode == ParserMode.QUICK_PARSE ) - return new GCCASTExpressionExtension( parseMode ); - - return new GCCASTCompleteExtension( parseMode ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/SymbolIterator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/SymbolIterator.java deleted file mode 100644 index 172afd4add6..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/SymbolIterator.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on Feb 25, 2004 - */ -package org.eclipse.cdt.internal.core.parser.ast; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol; - -/** - * @author aniefer - */ -public class SymbolIterator implements Iterator { - - Iterator interalIterator; - - IExtensibleSymbol next = null; - - private static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$ - - public SymbolIterator( Iterator iter ){ - interalIterator = iter; - } - - /* (non-Javadoc) - * @see java.util.Iterator#hasNext() - */ - public boolean hasNext(){ - if( next != null ) - return true; - - while( interalIterator.hasNext() ){ - IExtensibleSymbol symbol = (IExtensibleSymbol) interalIterator.next(); - - if( symbol.getASTExtension() != null ){ - if( symbol.getASTExtension().getPrimaryDeclaration() instanceof IASTOffsetableElement && - CharArrayUtils.equals(((IASTOffsetableElement)symbol.getASTExtension().getPrimaryDeclaration()).getFilename(), EMPTY_CHAR_ARRAY ) ) - continue; - - next = symbol; - return true; - } - } - return false; - } - - /* (non-Javadoc) - * @see java.util.Iterator#next() - */ - public Object next(){ - IExtensibleSymbol temp = next; - if( next != null ){ - next = null; - return temp.getASTExtension().getPrimaryDeclaration(); - } - while( interalIterator.hasNext() ){ - temp = (IExtensibleSymbol) interalIterator.next(); - - if( temp.getASTExtension() != null ){ - if( temp.getASTExtension().getPrimaryDeclaration() instanceof IASTOffsetableElement && - CharArrayUtils.equals(((IASTOffsetableElement)temp.getASTExtension().getPrimaryDeclaration()).getFilename(), EMPTY_CHAR_ARRAY ) ) - continue; - - return temp.getASTExtension().getPrimaryDeclaration(); - } - - } - - throw new NoSuchElementException(); - } - - /* (non-Javadoc) - * @see java.util.Iterator#remove() - */ - public void remove(){ - throw new UnsupportedOperationException(); - } -} - diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTASMDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTASMDefinition.java deleted file mode 100644 index 43ecdac8747..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTASMDefinition.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; - -/** - * @author jcamelon - * - */ -public class ASTASMDefinition extends ASTAnonymousDeclaration implements IASTASMDefinition -{ - private final char[] assembly; - /** - * @param filename - * - */ - public ASTASMDefinition( IContainerSymbol scope, char[] assembly, int first, int firstLine, int last , int lastLine, char[] filename ) - { - super( scope ); - this.assembly = assembly; - setStartingOffsetAndLineNumber(first, firstLine); - setEndingOffsetAndLineNumber(last, lastLine); - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTASMDefinition#getBody() - */ - public String getBody() - { - return String.valueOf( assembly ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptASMDefinition(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - private final char[] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAbstractTypeSpecifierDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAbstractTypeSpecifierDeclaration.java deleted file mode 100644 index 21a9d334ac7..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAbstractTypeSpecifierDeclaration.java +++ /dev/null @@ -1,218 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.ast.IASTTemplate; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; - - -/** - * @author jcamelon - * - */ -public class ASTAbstractTypeSpecifierDeclaration - extends ASTAnonymousDeclaration - implements IASTAbstractTypeSpecifierDeclaration -{ - private final IASTTypeSpecifier typeSpec; - private final IASTTemplate ownerTemplate; - private final boolean isFriendDeclaration; - - /** - * @param ownerScope - * @param filename - */ - public ASTAbstractTypeSpecifierDeclaration(IContainerSymbol ownerScope, IASTTypeSpecifier typeSpecifier, IASTTemplate ownerTemplate, int startingOffset, int startingLine, int endingOffset, int endingLine, boolean isFriend, char[] filename ) - { - super(ownerScope); - this.typeSpec = typeSpecifier; - this.ownerTemplate = ownerTemplate; - this.isFriendDeclaration = isFriend; - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setEndingOffsetAndLineNumber(endingOffset, endingLine); - fn = filename; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - if( isFriendDeclaration() ) - requestor.acceptFriendDeclaration( this ); - else - requestor.acceptAbstractTypeSpecDeclaration(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeSpecifierOwner#getTypeSpecifier() - */ - public IASTTypeSpecifier getTypeSpecifier() - { - return typeSpec; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplatedDeclaration#getOwnerTemplateDeclaration() - */ - public IASTTemplate getOwnerTemplateDeclaration() - { - return ownerTemplate; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration#isFriendDeclaration() - */ - public boolean isFriendDeclaration() { - return isFriendDeclaration; - } - - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - private final char[] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() { - if (typeSpec instanceof IASTOffsetableNamedElement) - return ((IASTOffsetableNamedElement)typeSpec).getName(); - - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - if (typeSpec instanceof IASTOffsetableNamedElement) - return ((IASTOffsetableNamedElement)typeSpec).getNameCharArray(); - - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() { - if (typeSpec instanceof IASTOffsetableNamedElement) - return ((IASTOffsetableNamedElement)typeSpec).getNameOffset(); - - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() { - if (typeSpec instanceof IASTOffsetableNamedElement) - return ((IASTOffsetableNamedElement)typeSpec).getNameEndOffset(); - - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffsetAndLineNumber(int, int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - if (typeSpec instanceof IASTOffsetableNamedElement) - return ((IASTOffsetableNamedElement)typeSpec).getNameLineNumber(); - - return 0; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAnonymousDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAnonymousDeclaration.java deleted file mode 100644 index e0cd6992c49..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTAnonymousDeclaration.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; - -/** - * @author jcamelon - * - */ -public abstract class ASTAnonymousDeclaration extends ASTNode implements IASTDeclaration -{ - private final IContainerSymbol ownerScope; - /** - * - */ - public ASTAnonymousDeclaration( IContainerSymbol ownerScope ) - { - this.ownerScope = ownerScope; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() - */ - public IASTScope getOwnerScope() - { - return (IASTScope)ownerScope.getASTExtension().getPrimaryDeclaration(); - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBaseSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBaseSpecifier.java deleted file mode 100644 index b9264dc77be..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBaseSpecifier.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTBaseSpecifier implements IASTBaseSpecifier -{ - private List references; - private final boolean isVirtual; - private final ISymbol symbol; - private final ASTAccessVisibility visibility; - private final int offset; - /** - * @param symbol - * @param b - * @param visibility - */ - public ASTBaseSpecifier(ISymbol symbol, boolean b, ASTAccessVisibility visibility, int nameOffset, List references) - { - isVirtual = b; - this.visibility = visibility; - this.symbol = symbol; - this.offset = nameOffset; - this.references = references; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier#getAccess() - */ - public ASTAccessVisibility getAccess() - { - return visibility; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier#isVirtual() - */ - public boolean isVirtual() - { - return isVirtual; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier#getParentClassName() - */ - public String getParentClassName() - { - return String.valueOf(symbol.getName()); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier#getParentClassSpecifier() - */ - public IASTTypeSpecifier getParentClassSpecifier() - { - return (IASTTypeSpecifier)symbol.getASTExtension().getPrimaryDeclaration(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier#getNameOffset() - */ - public int getNameOffset() - { - return offset; - } - - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - Parser.processReferences( references, requestor ); - references = null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBinaryExpression.java deleted file mode 100644 index a304072c4ab..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTBinaryExpression.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; - -/** - * @author jcamelon - * - */ -public class ASTBinaryExpression extends ASTUnaryExpression { - private final IASTExpression rhs; - - /** - * @param kind - * @param references - * @param lhs - */ - public ASTBinaryExpression(Kind kind, List references, IASTExpression lhs, IASTExpression rhs) { - super(kind, references, lhs); - this.rhs = rhs; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getRHSExpression() - */ - public IASTExpression getRHSExpression() { - return rhs; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#findOwnerExpressionForIDExpression(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) { - if( isIDExpressionForDuple( rhs, duple ) ) - return this; - ASTExpression result = recursiveFindExpressionForDuple(rhs, duple); - if( result != null ) - return result; - return super.findOwnerExpressionForIDExpression(duple); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences() - */ - public void purgeReferences() throws ASTNotImplementedException { - super.purgeReferences(); - rhs.purgeReferences(); - purgeSubExpression( (ASTExpression) rhs ); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences() - */ - public void reconcileReferences() throws ASTNotImplementedException { - super.reconcileReferences(); - rhs.reconcileReferences(); - reconcileSubExpression((ASTExpression) rhs ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks() - */ - protected void processCallbacks( ISourceElementRequestor requestor ) { - super.processCallbacks(requestor ); - rhs.acceptElement( requestor ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - super.freeReferences(); - rhs.freeReferences(); - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassReference.java deleted file mode 100644 index f6cfe77b35e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassReference.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTClassReference; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; - - -public class ASTClassReference extends ASTReference - implements - IASTClassReference { - private IASTTypeSpecifier reference; - /** - * @param i - * @param specifier - */ - public ASTClassReference(int i, IASTTypeSpecifier specifier) { - super(i); - reference = specifier; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTReference#initialize(int) - */ - public void initialize(int o, ISourceElementCallbackDelegate specifier) { - super.initialize(o); - reference = (IASTTypeSpecifier) specifier; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTReference#reset() - */ - public void reset() { - super.resetOffset(); - reference = null; - } - /** - * - */ - public ASTClassReference() { - super(0); - reference = null; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() - */ - public ISourceElementCallbackDelegate getReferencedElement() { - return (ISourceElementCallbackDelegate) reference; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - try { - requestor.acceptClassReference(this); - } catch (Exception e) { - /* do nothing */ - } - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTClassReference#isResolved() - */ - public boolean isResolved() { - return (reference instanceof IASTClassSpecifier); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassSpecifier.java deleted file mode 100644 index 7e181c8cbda..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTClassSpecifier.java +++ /dev/null @@ -1,385 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTReference; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; -import org.eclipse.cdt.internal.core.parser.ast.SymbolIterator; -import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol; - -/** - * @author jcamelon - * - */ -public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier -{ - private List declarations = null; - public class BaseIterator implements Iterator - { - - private final Iterator parents; - /** - * @param symbol - */ - public BaseIterator(IDerivableContainerSymbol symbol) - { - if( symbol.getParents() != null ) - parents = symbol.getParents().iterator(); - else - parents = null; - } - /* (non-Javadoc) - * @see java.util.Iterator#hasNext() - */ - public boolean hasNext() - { - if( parents == null ) - return false; - return parents.hasNext(); - } - /* (non-Javadoc) - * @see java.util.Iterator#next() - */ - public Object next() - { - if( ! hasNext() ) - throw new NoSuchElementException(); - - IParentSymbol pw = (IParentSymbol)parents.next(); - - return new ASTBaseSpecifier( pw.getParent(), pw.isVirtual(), pw.getAccess(), pw.getOffset(), pw.getReferences() ); - - } - /* (non-Javadoc) - * @see java.util.Iterator#remove() - */ - public void remove() - { - throw new UnsupportedOperationException(); - } - } - - - - private final ClassNameType classNameType; - private final ASTClassKind classKind; - private ASTAccessVisibility currentVisibility; - private final ASTQualifiedNamedElement qualifiedName; - private List references; - - /** - * @param symbol - */ - public ASTClassSpecifier(ISymbol symbol, ASTClassKind kind, ClassNameType type, ASTAccessVisibility access, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, List references, char [] filename ) - { - super(symbol); - classKind = kind; - classNameType = type; - currentVisibility = access; - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setNameOffset(nameOffset); - setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); - qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() ); - this.references = references; - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getClassNameType() - */ - public ClassNameType getClassNameType() - { - return classNameType; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getClassKind() - */ - public ASTClassKind getClassKind() - { - return classKind; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getBaseClauses() - */ - public Iterator getBaseClauses() - { - return new BaseIterator( (IDerivableContainerSymbol)getSymbol() ); - } - - private List getBaseClausesList(){ - List clauses = ((IDerivableContainerSymbol)getSymbol()).getParents(); - return (clauses != null) ? clauses : Collections.EMPTY_LIST; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getCurrentVisibilityMode() - */ - public ASTAccessVisibility getCurrentVisibilityMode() - { - return currentVisibility; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#setCurrentVisibility(org.eclipse.cdt.core.parser.ast.ASTAccessVisibility) - */ - public void setCurrentVisibility(ASTAccessVisibility visibility) - { - currentVisibility = visibility; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() - { - return String.valueOf(symbol.getName()); - } - public char[] getNameCharArray(){ - return symbol.getName(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - Parser.processReferences( references, requestor ); - references = null; - try - { - requestor.enterClassSpecifier(this); - } - catch (Exception e) - { - /* do nothing */ - } - List bases = getBaseClausesList(); - int size = bases.size(); - for( int i = 0; i < size; i++ ) - { - IParentSymbol pw = (IParentSymbol)bases.get(i); - IASTBaseSpecifier baseSpec = new ASTBaseSpecifier( pw.getParent(), pw.isVirtual(), pw.getAccess(), pw.getOffset(), pw.getReferences() ); - baseSpec.acceptElement(requestor); - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - Parser.processReferences( this.resolvedCrossReferences, requestor ); - try - { - requestor.exitClassSpecifier(this); - } - catch (Exception e) - { - /* do nothing */ - } - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedName.getFullyQualifiedName(); - } - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedName.getFullyQualifiedNameCharArrays(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() - */ - public IASTScope getOwnerScope() - { - return (IASTScope)symbol.getContainingSymbol().getASTExtension().getPrimaryDeclaration(); - } - - - public Iterator getDeclarations() - { - //If a callback (ie StructuralParseCallback) populates the declarations list - //then return that iterator, otherwise use the ASTScope implementation which - //gets one from the symbol table. - if( declarations != null ){ - return declarations.iterator(); - } - return super.getDeclarations(); - } - - public void addDeclaration(IASTDeclaration declaration) - { - declarations.add(declaration); - } - - public void initDeclarations() - { - declarations = new ArrayList(0); - } - - private List unresolvedCrossReferences = Collections.EMPTY_LIST; - private boolean processingUnresolvedReferences = false; - public void addUnresolvedReference( UnresolvedReferenceDuple duple) - { - //avoid a ConcurrentModificationException by not adding more references when we are - //in the middle of processing them - if( !processingUnresolvedReferences ){ - if( unresolvedCrossReferences == Collections.EMPTY_LIST ) - unresolvedCrossReferences = new ArrayList(); - unresolvedCrossReferences.add( duple ); - } - } - - public List getUnresolvedReferences() - { - return unresolvedCrossReferences; - } - - public void setProcessingUnresolvedReferences( boolean processing ){ - processingUnresolvedReferences = processing; - } - - private List resolvedCrossReferences = Collections.EMPTY_LIST; - /** - * @param references2 - */ - public void setExtraReferences(List references ) { - if( references != null && !references.isEmpty()) - { - for( int i = 0; i < references.size(); ++i ) - { - IASTReference r = (IASTReference)references.get(i); - if( resolvedCrossReferences == Collections.EMPTY_LIST ) - resolvedCrossReferences = new ArrayList( references.size() ); - resolvedCrossReferences.add( r ); - } - } - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTClassSpecifier#getFriends() - */ - public Iterator getFriends() { - IDerivableContainerSymbol s = (IDerivableContainerSymbol) getSymbol(); - return new SymbolIterator( s.getFriends().iterator() ); - } - - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - private final char[] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCodeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCodeScope.java deleted file mode 100644 index b5c06c54916..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCodeScope.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Sep 2, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; - -/** - * @author jcamelon - * - */ -public class ASTCodeScope extends ASTScope implements IASTCodeScope { - - private List declarations = null; - private final IASTCodeScope ownerCodeScope; - - /** - * @param newScope - */ - public ASTCodeScope(IContainerSymbol newScope) { - super( newScope ); - ownerCodeScope = ( newScope.getContainingSymbol().getASTExtension().getPrimaryDeclaration() instanceof IASTCodeScope ) ? - (IASTCodeScope) newScope.getContainingSymbol().getASTExtension().getPrimaryDeclaration() : null; - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) { - try - { - requestor.enterCodeBlock( this ); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) { - try - { - requestor.exitCodeBlock( this ); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCodeScope#getOwnerCodeScope() - */ - public IASTCodeScope getOwnerCodeScope() - { - return ownerCodeScope; - } - - public Iterator getDeclarations() - { - if(declarations != null) - return declarations.iterator(); - return super.getDeclarations(); - } - - public void addDeclaration(IASTDeclaration declaration) - { - declarations.add(declaration); - } - public void initDeclarations() - { - declarations = new ArrayList(0); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCodeScope#getContainingFunction() - */ - public IASTFunction getContainingFunction() { - IASTCodeScope i = getOwnerCodeScope(); - while( (i != null ) && !( i instanceof IASTFunction )) - i = i.getOwnerCodeScope(); - return (IASTFunction) i; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCompilationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCompilationUnit.java deleted file mode 100644 index f0a3f1a1381..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTCompilationUnit.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTCompilationUnit - extends ASTScope - implements IASTCompilationUnit -{ - private List declarations = null; - /** - * @param symbol - */ - public ASTCompilationUnit(ISymbol symbol) - { - super(symbol); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterCompilationUnit( this ); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitCompilationUnit( this ); - } - catch (Exception e) - { - /* do nothing */ - } - } - - public Iterator getDeclarations() - { - //If a callback (ie StructuralParseCallback) populates the declarations list - //then return that iterator, otherwise use the ASTScope implementation which - //gets one from the symbol table. - if( declarations != null ) - return declarations.iterator(); - - return super.getDeclarations(); - } - - public void addDeclaration(IASTDeclaration declaration) - { - declarations.add(declaration); - } - public void initDeclarations() - { - declarations = new ArrayList(0); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConditionalExpression.java deleted file mode 100644 index c25b44040c4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConditionalExpression.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; - -/** - * @author jcamelon - * - */ -public class ASTConditionalExpression extends ASTBinaryExpression { - private final IASTExpression thirdExpression; - - /** - * @param kind - * @param references - * @param lhs - * @param rhs - */ - public ASTConditionalExpression(Kind kind, List references, - IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression) { - super(kind, references, lhs, rhs); - this.thirdExpression = thirdExpression; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getThirdExpression() - */ - public IASTExpression getThirdExpression() { - return thirdExpression; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#findOwnerExpressionForIDExpression(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) { - if( isIDExpressionForDuple( thirdExpression, duple ) ) - return this; - ASTExpression result = recursiveFindExpressionForDuple(thirdExpression, duple); - if( result != null ) - return result; - return super.findOwnerExpressionForIDExpression(duple); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences() - */ - public void purgeReferences() throws ASTNotImplementedException { - super.purgeReferences(); - thirdExpression.purgeReferences(); - purgeSubExpression( (ASTExpression) thirdExpression ); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences() - */ - public void reconcileReferences() throws ASTNotImplementedException { - super.reconcileReferences(); - thirdExpression.reconcileReferences(); - reconcileSubExpression((ASTExpression) thirdExpression); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks() - */ - protected void processCallbacks( ISourceElementRequestor requestor ) { - super.processCallbacks(requestor ); - thirdExpression.acceptElement( requestor ); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - super.freeReferences(); - thirdExpression.freeReferences(); - } - public String toString(){ - return ASTUtil.getExpressionString( this ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConstructorMemberInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConstructorMemberInitializer.java deleted file mode 100644 index f70162cbecb..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTConstructorMemberInitializer.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTConstructorMemberInitializer; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.internal.core.parser.Parser; - -/** - * @author jcamelon - * - */ -public class ASTConstructorMemberInitializer - implements IASTConstructorMemberInitializer -{ - private final int nameOffset; - private final boolean requireNameResolution; - private final char[] name; - private final IASTExpression expression; - private List references; - /** - * - */ - public ASTConstructorMemberInitializer( IASTExpression expression, char[] name, int nameOffset, List references, boolean requireNameResolution ) - { - this.expression = expression; - this.name = name; - this.nameOffset = nameOffset; - this.references = references; - this.requireNameResolution = requireNameResolution; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTConstructorMemberInitializer#getExpressionList() - */ - public IASTExpression getExpressionList() - { - return expression; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTConstructorMemberInitializer#getName() - */ - public String getName() - { - return String.valueOf( name ); - } - public char[] getNameCharArray(){ - return name; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - Parser.processReferences( references, requestor ); - references = null; - if( expression != null ) - expression.freeReferences(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - /** - * @return - */ - public boolean requiresNameResolution() - { - return requireNameResolution; - } - - /** - * @return - */ - public List getReferences() - { - return references; - } - /** - * @return - */ - public int getNameOffset() - { - return nameOffset; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTElaboratedTypeSpecifier.java deleted file mode 100644 index a3b6fc57eb4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTElaboratedTypeSpecifier.java +++ /dev/null @@ -1,231 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTElaboratedTypeSpecifier extends ASTSymbol implements IASTElaboratedTypeSpecifier -{ - private List references; - private final boolean isForwardDeclaration; - private final ASTClassKind kind; - private final ASTQualifiedNamedElement qualifiedName; - - /** - * @param checkSymbol - * @param kind - * @param startingOffset - * @param endOffset - * @param filename - */ - public ASTElaboratedTypeSpecifier(ISymbol checkSymbol, ASTClassKind kind, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endOffset, int endingLine, List references, boolean isDecl, char[] filename ) - { - super( checkSymbol ); - this.kind = kind; - setStartingOffsetAndLineNumber( startingOffset, startingLine ); - setNameOffset( nameOffset ); - setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); - setEndingOffsetAndLineNumber( endOffset, endingLine ); - qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), checkSymbol.getName() ); - isForwardDeclaration = isDecl; - this.references = references; - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier#getName() - */ - public String getName() - { - return String.valueOf(getSymbol().getName()); - } - public char[] getNameCharArray(){ - return getSymbol().getName(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier#getClassKind() - */ - public ASTClassKind getClassKind() - { - return kind; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier#isResolved() - */ - public boolean isResolved() - { - return ! getSymbol().isForwardDeclaration(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - if( isForwardDeclaration ) - try - { - requestor.acceptElaboratedForewardDeclaration(this); - } - catch (Exception e) - { - /* do nothing */ - } - Parser.processReferences( references, requestor ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedName.getFullyQualifiedName(); - } - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedName.getFullyQualifiedNameCharArrays(); - } - public List getReferences() - { - return references; - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) { - if( obj == this ) return true; - if( obj == null ) return false; - if( ! (obj instanceof IASTElaboratedTypeSpecifier )) return false; - IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) obj; - if( elab.getClassKind() != getClassKind() ) return false; - if( !elab.getName().equals( getName() ) ) return false; - return true; - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - String coded =getName().toString(); - return coded.hashCode(); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEmptyExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEmptyExpression.java deleted file mode 100644 index ffafc5d21e1..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEmptyExpression.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ast.ASTUtil; - -/** - * @author jcamelon - * - */ -public class ASTEmptyExpression extends ASTExpression { - /** - * @param kind - * @param references - */ - public ASTEmptyExpression(Kind kind, List references) { - super( kind, references ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffsetAndLineNumber(int, int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffsetAndLineNumber(int, int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - // TODO Auto-generated method stub - return null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationReference.java deleted file mode 100644 index 8c63b14b762..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationReference.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; - - -public class ASTEnumerationReference extends ASTReference - implements - IASTEnumerationReference { - private IASTEnumerationSpecifier referencedElement; - /** - * @param offset - * @param specifier - */ - public ASTEnumerationReference(int offset, - IASTEnumerationSpecifier specifier) { - super(offset); - referencedElement = specifier; - } - - /** - * - */ - public ASTEnumerationReference() { - super( 0 ); - referencedElement = null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() - */ - public ISourceElementCallbackDelegate getReferencedElement() { - return referencedElement; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - try { - requestor.acceptEnumerationReference(this); - } catch (Exception e) { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#initialize(int, org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate) - */ - public void initialize(int o, ISourceElementCallbackDelegate re) { - initialize(o); - this.referencedElement = (IASTEnumerationSpecifier) re; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#reset() - */ - public void reset() { - super.resetOffset(); - this.referencedElement = null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationSpecifier.java deleted file mode 100644 index bc2d0f6af1c..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationSpecifier.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTEnumerationSpecifier - extends ASTSymbol - implements IASTEnumerationSpecifier -{ - private final ASTQualifiedNamedElement qualifiedName; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param symbol - * @param filename - */ - public ASTEnumerationSpecifier(ISymbol symbol, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, char[] filename ) - { - super(symbol); - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setNameOffset( nameOffset ); - setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); - qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() ); - fn = filename; - } - - - private List enumerators = Collections.EMPTY_LIST; - private static final int ENUMERATOR_LIST_SIZE = 4; - public void addEnumerator(IASTEnumerator enumerator) - { - if( enumerators == Collections.EMPTY_LIST ) - enumerators = new ArrayList( ENUMERATOR_LIST_SIZE ); - enumerators.add(enumerator); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier#getEnumerators() - */ - public Iterator getEnumerators() - { - return enumerators.iterator(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptEnumerationSpecifier(this); - } - catch (Exception e) - { - /* do nothing */ - } - if( enumerators.isEmpty() ) return; - for( int i = 0; i < enumerators.size(); ++i ) - { - IASTEnumerator enumerator = (IASTEnumerator) enumerators.get(i); - if( enumerator.getInitialValue() != null ) - enumerator.getInitialValue().acceptElement(requestor ); - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() - { - return String.valueOf(getSymbol().getName()); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray(){ - return getSymbol().getName(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedName.getFullyQualifiedName(); - } - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedName.getFullyQualifiedNameCharArrays(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - if( enumerators.isEmpty() ) return; - for( int i = 0; i < enumerators.size(); ++i ) - ((IASTEnumerator) enumerators.get(i)).freeReferences(); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerator.java deleted file mode 100644 index 4ad61fe5c4e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerator.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTEnumerator extends ASTSymbol implements IASTEnumerator -{ - - private final IASTExpression initialValue; - private final IASTEnumerationSpecifier owner; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param enumeratorSymbol - * @param startingOffset - * @param endingOffset - * @param initialValue - * @param filename - */ - public ASTEnumerator(ISymbol enumeratorSymbol, IASTEnumerationSpecifier owner, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, IASTExpression initialValue, char[] filename) - { - super( enumeratorSymbol ); - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setNameOffset( nameOffset ); - setNameEndOffsetAndLineNumber( nameEndOffset, nameLine ); - setEndingOffsetAndLineNumber( endingOffset, endingLine ); - this.initialValue = initialValue; - this.owner = owner; - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTEnumerator#getOwnerEnumerationSpecifier() - */ - public IASTEnumerationSpecifier getOwnerEnumerationSpecifier() - { - return owner; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTEnumerator#getInitialValue() - */ - public IASTExpression getInitialValue() - { - return initialValue; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() - { - return String.valueOf(symbol.getName()); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTEnumerator#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - if( initialValue != null ) - initialValue.freeReferences(); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameEndOffset; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return getStartingLine(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() - { - return getStartingOffset(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return symbol.getName(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumeratorReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumeratorReference.java deleted file mode 100644 index 40d11efc458..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumeratorReference.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTEnumeratorReference; - - -public class ASTEnumeratorReference extends ASTReference - implements - IASTEnumeratorReference { - - private IASTEnumerator enumerator; - /** - * @param offset - * @param enumerator - */ - public ASTEnumeratorReference(int offset, IASTEnumerator enumerator) { - super(offset); - this.enumerator = enumerator; - } - - /** - * - */ - public ASTEnumeratorReference() { - super( 0 ); - enumerator = null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() - */ - public ISourceElementCallbackDelegate getReferencedElement() { - return enumerator; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - try { - requestor.acceptEnumeratorReference(this); - } catch (Exception e) { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#initialize(int, org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate) - */ - public void initialize(int o, ISourceElementCallbackDelegate referencedElement) { - super.initialize(o); - this.enumerator = (IASTEnumerator) referencedElement; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#reset() - */ - public void reset() { - super.resetOffset(); - this.enumerator = null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExceptionSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExceptionSpecification.java deleted file mode 100644 index 710c30599fe..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExceptionSpecification.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; - -/** - * @author jcamelon - * - */ -public class ASTExceptionSpecification implements IASTExceptionSpecification -{ - private final List typeIds; - /** - * @param newTypeIds - */ - public ASTExceptionSpecification(List newTypeIds) - { - this.typeIds = newTypeIds; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification#getTypeIds() - */ - public Iterator getTypeIds() - { - if( typeIds == null ) return EmptyIterator.EMPTY_ITERATOR; - return typeIds.iterator(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java deleted file mode 100644 index 1dbe819d99d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTExpression.java +++ /dev/null @@ -1,302 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTReference; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider; - -/** - * @author jcamelon - * - */ -public abstract class ASTExpression extends ASTNode implements IASTExpression -{ - private final Kind kind; - private List references; - private ExpressionResult resultType; - - /** - * - */ - public ASTExpression( Kind kind, List references ) - { - this.kind = kind; - this.references = references; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getExpressionKind() - */ - public Kind getExpressionKind() - { - return kind; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression() - */ - public long evaluateExpression() throws ASTExpressionEvaluationException - { - throw new ASTExpressionEvaluationException(); - } - - public List getReferences() - { - return references; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - reconcileReferences(); - } - catch (ASTNotImplementedException e) - { - // will not get thrown - } - Parser.processReferences( references, requestor ); - references = null; - - processCallbacks(requestor); - - try - { - purgeReferences(); - } - catch (ASTNotImplementedException e) - { - // will not get thrown - } - } - - /** - * @param requestor TODO - * @param manager TODO - * - */ - protected void processCallbacks(ISourceElementRequestor requestor ) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - /** - * @return - */ - public ExpressionResult getResultType() { - return resultType; - } - - /** - * @param i - */ - public void setResultType(ExpressionResult i) { - resultType = i; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences() - */ - public void reconcileReferences() throws ASTNotImplementedException - { - } - - protected void reconcileSubExpression(ASTExpression subExpression ) - { - if( subExpression != null && subExpression.getReferences() != null ) - { - List refs = subExpression.getReferences(); - int size = refs.size(); - for( int i = 0; i < refs.size(); i++ ) - { - IASTReference aReference = (IASTReference)refs.get(i); - if( aReference != null && references.contains( aReference ) ) - { - refs.remove(i--); - size--; - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences() - */ - public void purgeReferences() throws ASTNotImplementedException - { - } - - protected void purgeSubExpression(ASTExpression subExpression) - { - if( subExpression != null && subExpression.getReferences() != null ) - { - subExpression.getReferences().clear(); - } - } - - - protected String getStringPrefix() - { - StringBuffer buffer = new StringBuffer(); - buffer.append( "ASTExpression w/Kind=" ); //$NON-NLS-1$ - buffer.append( kind.getKindName() ); - return buffer.toString(); - } - - - public IContainerSymbol getLookupQualificationSymbol() throws LookupError { - ExpressionResult result = getResultType(); - ITypeInfo type = (result != null ) ? result.getResult() : null; - IContainerSymbol containerSymbol = null; - - if( type != null && type.getTypeSymbol() != null ){ - TypeInfoProvider provider = type.getTypeSymbol().getSymbolTable().getTypeInfoProvider(); - type = type.getFinalType( provider ); - if( type.isType( ITypeInfo.t_type ) && - type.getTypeSymbol() != null && type.getTypeSymbol() instanceof IContainerSymbol ) - { - containerSymbol = (IContainerSymbol) type.getTypeSymbol(); - } - provider.returnTypeInfo( type ); - } - - return containerSymbol; - } - - public boolean shouldFilterLookupResult( ISymbol symbol ){ - ExpressionResult result = getResultType(); - ITypeInfo type = ( result != null ) ? result.getResult() : null; - if( type != null ){ - boolean answer = false; - TypeInfoProvider provider = symbol.getSymbolTable().getTypeInfoProvider(); - type = type.getFinalType( provider ); - if( type.checkBit( ITypeInfo.isConst ) && !symbol.getTypeInfo().checkBit( ITypeInfo.isConst ) ) - answer = true; - - if( type.checkBit( ITypeInfo.isVolatile ) && !symbol.getTypeInfo().checkBit( ITypeInfo.isVolatile ) ) - answer = true; - - provider.returnTypeInfo( type ); - return answer; - } - - return false; - } - - /** - * @param duple - * @return - */ - public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) { - return null; - } - - /** - * @param duple - * @return - */ - protected ASTExpression recursiveFindExpressionForDuple(IASTExpression expression, ITokenDuple duple) { - if( expression == null ) return null; - return ((ASTExpression)expression).findOwnerExpressionForIDExpression(duple); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#isIDExpressionForDuple(org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ITokenDuple) - */ - protected boolean isIDExpressionForDuple(IASTExpression expression, - ITokenDuple duple) { - if( expression == null ) return false; - if( expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION && - expression instanceof ASTIdExpression ) - { - ITokenDuple expressionDuple = ((ASTIdExpression)expression).getIdExpressionTokenDuple(); - // check equality - if( expressionDuple.equals( duple ) ) - return true; - // check subduple - if( expressionDuple.contains( duple ) ) - return true; - } - return false; - } - - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ - private static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$ - - public IASTExpression getLHSExpression() { - return null; - } - - public IASTExpression getRHSExpression() { - return null; - } - - public IASTExpression getThirdExpression() { - return null; - } - - public String getLiteralString() { - return EMPTY_STRING; - } - - public String getIdExpression() { - return EMPTY_STRING; - } - - public char[] getIdExpressionCharArray(){ - return EMPTY_CHAR_ARRAY; - } - - public IASTTypeId getTypeId() { - return null; - } - - public IASTNewExpressionDescriptor getNewExpressionDescriptor() { - return null; - } - - /** - * @param finalDuple - * @return - */ - public IASTExpression findNewDescriptor(ITokenDuple finalDuple) { - return null; - } - - public void freeReferences( ) - { - if( references == null || references.isEmpty() ) return; - references.clear(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java deleted file mode 100644 index 82af0073cfe..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTField.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTField extends ASTVariable implements IASTField -{ - private final ASTAccessVisibility visibility; - /** - * @param newSymbol - * @param abstractDeclaration - * @param initializerClause - * @param bitfieldExpression - * @param startingOffset - * @param nameOffset - * @param references - * @param visibility - * @param filename - */ - public ASTField(ISymbol newSymbol, IASTAbstractDeclaration abstractDeclaration, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, List references, boolean previouslyDeclared, IASTExpression constructorExpression, ASTAccessVisibility visibility, char [] filename) - { - super( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, startingLine, nameOffset, nameEndOffset, nameLine, references, constructorExpression, previouslyDeclared, filename ); - this.visibility = visibility; - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMember#getVisiblity() - */ - public ASTAccessVisibility getVisiblity() - { - return visibility; - } - - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptField(this); - } - catch (Exception e) - { - /* do nothing */ - } - Parser.processReferences(references, requestor); - references = null; - - if( getInitializerClause() != null ) - getInitializerClause().acceptElement(requestor); - if( getAbstractDeclaration() != null ) - getAbstractDeclaration().acceptElement(requestor); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFieldReference.java deleted file mode 100644 index 6fc1ffe093c..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFieldReference.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFieldReference; -import org.eclipse.cdt.core.parser.ast.IASTReference; - - -public class ASTFieldReference extends ASTReference - implements - IASTReference, - IASTFieldReference { - private IASTField referencedElement; - /** - * @param offset - * @param field - */ - public ASTFieldReference(int offset, IASTField field) { - super(offset); - referencedElement = field; - } - /** - * - */ - public ASTFieldReference() { - super(0); - referencedElement = null; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() - */ - public ISourceElementCallbackDelegate getReferencedElement() { - return referencedElement; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - try { - requestor.acceptFieldReference(this); - } catch (Exception e) { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#initialize(int, org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate) - */ - public void initialize(int o, ISourceElementCallbackDelegate re) { - initialize(o); - this.referencedElement = (IASTField) re; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#reset() - */ - public void reset() { - resetOffset(); - this.referencedElement = null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java deleted file mode 100644 index e550769bf1e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunction.java +++ /dev/null @@ -1,401 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplate; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; -import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; - -/** - * @author jcamelon - * - */ -public class ASTFunction extends ASTScope implements IASTFunction -{ - private final boolean previouslyDeclared; - private boolean hasFunctionBody = false; - private final boolean isFriendDeclaration; - private final IASTTemplate ownerTemplate; - private final IASTAbstractDeclaration returnType; - private final IASTExceptionSpecification exception; - private final ASTQualifiedNamedElement qualifiedName; - private final List parameters; - protected List references; - private List declarations = null; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param symbol - * @param parameters - * @param returnType - * @param exception - * @param startOffset - * @param nameOffset - * @param ownerTemplate - * @param references - * @param filename - */ - public ASTFunction(IParameterizedSymbol symbol, int nameEndOffset, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, int startOffset, int startingLine, int nameOffset, int nameLine, IASTTemplate ownerTemplate, List references, boolean previouslyDeclared, boolean hasFunctionTryBlock, boolean isFriend, char[] filename ) - { - super( symbol ); - this.parameters = parameters; - this.returnType = returnType; - this.exception = exception; - setStartingOffsetAndLineNumber(startOffset, startingLine); - setNameOffset(nameOffset); - setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); - this.ownerTemplate = ownerTemplate; - this.references = references; - qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), symbol.getName() ); - this.previouslyDeclared =previouslyDeclared; - this.hasFunctionTryBlock = hasFunctionTryBlock; - this.isFriendDeclaration = isFriend; - fn = filename; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isInline() - */ - public boolean isInline() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isInline ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isFriend() - */ - public boolean isFriend() - { - return isFriendDeclaration; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isStatic() - */ - public boolean isStatic() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isStatic ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() - { - return String.valueOf(symbol.getName()); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getReturnType() - */ - public IASTAbstractDeclaration getReturnType() - { - return returnType; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getParameters() - */ - public Iterator getParameters() - { - return parameters.iterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getExceptionSpec() - */ - public IASTExceptionSpecification getExceptionSpec() - { - return exception; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#setHasFunctionBody(boolean) - */ - public void setHasFunctionBody(boolean b) - { - hasFunctionBody = b; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#hasFunctionBody() - */ - public boolean hasFunctionBody() - { - return hasFunctionBody; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplatedDeclaration#getOwnerTemplateDeclaration() - */ - public IASTTemplate getOwnerTemplateDeclaration() - { - return ownerTemplate; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedName.getFullyQualifiedName(); - } - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedName.getFullyQualifiedNameCharArrays(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - if( isFriend() ) - requestor.acceptFriendDeclaration(this); - else - requestor.acceptFunctionDeclaration(this); - } - catch (Exception e) - { - /* do nothing */ - } - functionCallbacks(requestor); - } - - protected void functionCallbacks(ISourceElementRequestor requestor ) - { - Parser.processReferences(references, requestor); - references = null; - processParameterInitializersAndArrayMods(requestor); - if( getReturnType() != null ) - getReturnType().acceptElement(requestor); - } - /** - * @param requestor - * @param manager - */ - protected void processParameterInitializersAndArrayMods(ISourceElementRequestor requestor ) - { - int size = parameters.size(); - for( int i = 0; i < size; i++ ) - { - IASTParameterDeclaration parm = (IASTParameterDeclaration)parameters.get(i); - if( parm.getDefaultValue() != null ) - parm.getDefaultValue().acceptElement(requestor); - Iterator arrays = parm.getArrayModifiers(); - while( arrays.hasNext() ) - { - ((IASTArrayModifier)arrays.next()).acceptElement(requestor); - } - } - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterFunctionBody( this ); - } - catch (Exception e) - { - /* do nothing */ - } - functionCallbacks( requestor ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitFunctionBody( this ); - } - catch (Exception e) - { - /* do nothing */ - } - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCodeScope#getOwnerCodeScope() - */ - public IASTCodeScope getOwnerCodeScope() - { - return ( getSymbol().getContainingSymbol().getASTExtension().getPrimaryDeclaration() ) instanceof IASTCodeScope ? - (IASTCodeScope) getSymbol().getContainingSymbol().getASTExtension().getPrimaryDeclaration() : null; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#previouslyDeclared() - */ - public boolean previouslyDeclared() - { - return previouslyDeclared; - } - - private boolean hasFunctionTryBlock = false; - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#setHasFunctionTryBlock(boolean) - */ - public void setHasFunctionTryBlock(boolean b) - { - hasFunctionTryBlock = b; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#hasFunctionTryBlock() - */ - public boolean hasFunctionTryBlock() - { - return hasFunctionTryBlock; - } - - public Iterator getDeclarations() - { - if(declarations != null) - return declarations.iterator(); - return super.getDeclarations(); - } - - public void addDeclaration(IASTDeclaration declaration) - { - declarations.add(declaration); - } - public void initDeclarations() - { - declarations = new ArrayList(0); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#takesVarArgs() - */ - public boolean takesVarArgs() { - return ((IParameterizedSymbol)getSymbol()).hasVariableArgs(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCodeScope#getContainingFunction() - */ - public IASTFunction getContainingFunction() { - return this; - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return symbol.getName(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunctionReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunctionReference.java deleted file mode 100644 index e397559755b..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTFunctionReference.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTFunctionReference; -import org.eclipse.cdt.core.parser.ast.IASTReference; - - -public class ASTFunctionReference extends ASTReference - implements - IASTReference, - IASTFunctionReference { - private IASTFunction declaration; - /** - * @param offset - */ - public ASTFunctionReference(int offset, - IASTFunction referencedDeclaration) { - super(offset); - this.declaration = referencedDeclaration; - } - /** - * - */ - public ASTFunctionReference() { - super(0); - declaration = null; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() - */ - public ISourceElementCallbackDelegate getReferencedElement() { - return declaration; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - try { - requestor.acceptFunctionReference(this); - } catch (Exception e) { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#initialize(int, org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate) - */ - public void initialize(int o, ISourceElementCallbackDelegate referencedElement) { - super.initialize(o); - this.declaration = (IASTFunction) referencedElement; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#reset() - */ - public void reset() { - resetOffset(); - this.declaration = null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTIdExpression.java deleted file mode 100644 index dfc91c1211c..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTIdExpression.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTUtil; - -/** - * @author jcamelon - * - */ -public class ASTIdExpression extends ASTExpression { - - private ITokenDuple idExpression; - private char[] idExpressionValue; - /** - * @param kind - * @param references - */ - public ASTIdExpression(Kind kind, List references, ITokenDuple idExpression) { - super(kind, references); - this.idExpression = idExpression; - idExpressionValue = idExpression.toCharArray(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getIdExpression() - */ - public String getIdExpression() { - return String.valueOf( idExpressionValue ); - } - - public char[] getIdExpressionCharArray(){ - return idExpressionValue; - } - - public ITokenDuple getIdExpressionTokenDuple() - { - return idExpression; - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffsetAndLineNumber(int, int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffsetAndLineNumber(int, int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() { - // TODO Auto-generated method stub - return idExpression.getStartOffset(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() { - // TODO Auto-generated method stub - return idExpression.getEndOffset(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - // TODO Auto-generated method stub - return idExpression.getLineNumber(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - // TODO Auto-generated method stub - return idExpression.getLineNumber(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - // TODO Auto-generated method stub - return idExpression.getFilename(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTInitializerClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTInitializerClause.java deleted file mode 100644 index a3dfdd8e851..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTInitializerClause.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; - -/** - * @author jcamelon - * - */ -public class ASTInitializerClause implements IASTInitializerClause -{ - private List references = new ArrayList(); - private IASTVariable ownerDeclaration = null; - private final IASTInitializerClause.Kind kind; - private final IASTExpression assignmentExpression; - private final List initializerClauses; - private final List designators; - - /** - * @param kind - * @param assignmentExpression - * @param initializerClauses - * @param designators - */ - public ASTInitializerClause(Kind kind, IASTExpression assignmentExpression, List initializerClauses, List designators) - { - this.kind = kind; - this.assignmentExpression = assignmentExpression; - this.initializerClauses = initializerClauses; - this.designators = designators; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getKind() - */ - public Kind getKind() { - return kind; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializerList() - */ - public Iterator getInitializers() { - if( initializerClauses == null ) - return EmptyIterator.EMPTY_ITERATOR; - return initializerClauses.iterator(); - } - - public List getInitializersList(){ - return ( initializerClauses != null ) ? initializerClauses : Collections.EMPTY_LIST; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression() - */ - public IASTExpression getAssigmentExpression() { - return assignmentExpression; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - List initializers = getInitializersList(); - int size = initializers.size(); - for( int i = 0; i < size; i++ ) - ((IASTInitializerClause)initializers.get(i)).acceptElement(requestor); - - if( assignmentExpression != null ) - assignmentExpression.acceptElement( requestor ); - - Parser.processReferences(references, requestor); - references = null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getDesignators() - */ - public Iterator getDesignators() - { - return designators.iterator(); - } - - public List getDesignatorList(){ - return designators; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#setOwnerDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void setOwnerVariableDeclaration(IASTVariable declaration) - { - ownerDeclaration = declaration; - Iterator subInitializers = getInitializers(); - while( subInitializers.hasNext() ) - ((IASTInitializerClause)subInitializers.next()).setOwnerVariableDeclaration(declaration); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getOwnerDeclaration() - */ - public IASTVariable getOwnerVariableDeclaration() - { - return ownerDeclaration; - } - - public List getReferences() - { - return references; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#findExpressionForDuple(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public IASTExpression findExpressionForDuple(ITokenDuple finalDuple) throws ASTNotImplementedException { - if( kind == IASTInitializerClause.Kind.EMPTY ) return null; - if( kind == IASTInitializerClause.Kind.ASSIGNMENT_EXPRESSION || - kind == Kind.DESIGNATED_ASSIGNMENT_EXPRESSION ) - return ((ASTExpression)assignmentExpression).findNewDescriptor( finalDuple ); - Iterator i = getInitializers(); - while( i.hasNext() ) - { - IASTInitializerClause clause = (IASTInitializerClause) i.next(); - IASTExpression e = clause.findExpressionForDuple(finalDuple); - if( e != null ) return e; - } - return null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLinkageSpecification.java deleted file mode 100644 index 0434d4d7640..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLinkageSpecification.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; - -/** - * @author jcamelon - * - */ -public class ASTLinkageSpecification extends ASTAnonymousDeclaration implements IASTLinkageSpecification -{ - private List declarations = new ArrayList(); - private final char[] linkageString; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param filename - * - */ - public ASTLinkageSpecification( IContainerSymbol scope, char[] linkageString, int startingOffset, int startingLine, char[] filename ) - { - super( scope ); - this.linkageString = linkageString; - setStartingOffsetAndLineNumber(startingOffset, startingLine); - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification#getLinkageString() - */ - public String getLinkageString() - { - return String.valueOf(linkageString); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() - */ - public Iterator getDeclarations() throws ASTNotImplementedException - { - return declarations.iterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterLinkageSpecification(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitLinkageSpecification(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - public void addDeclaration(IASTDeclaration declaration) - { - declarations.add(declaration); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - -} - diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLiteralExpression.java deleted file mode 100644 index 0283045fb42..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTLiteralExpression.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ast.ASTUtil; - -/** - * @author jcamelon - * - */ -public class ASTLiteralExpression extends ASTExpression { - - private final char[] literal; - - /** - * @param kind - * @param references - */ - public ASTLiteralExpression(Kind kind, List references, char[] literal) { - super(kind, references); - this.literal = literal; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLiteralString() - */ - public String getLiteralString() { - return String.valueOf( literal ); - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffsetAndLineNumber(int, int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffsetAndLineNumber(int, int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - // TODO Auto-generated method stub - return null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java deleted file mode 100644 index 6eb728c9c50..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethod.java +++ /dev/null @@ -1,252 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTConstructorMemberInitializer; -import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTTemplate; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableError; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; -import org.eclipse.cdt.internal.core.parser.pst.TypeFilter; - -/** - * @author jcamelon - * - */ -public class ASTMethod extends ASTFunction implements IASTMethod -{ - private final List constructorChain; - private final boolean isConstructor; - private final boolean isPureVirtual; - private final ASTAccessVisibility visibility; - private final boolean isDestructor; - /** - * @param symbol - * @param parameters - * @param returnType - * @param exception - * @param startOffset - * @param nameOffset - * @param ownerTemplate - * @param references - * @param filename - */ - public ASTMethod(IParameterizedSymbol symbol, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, int startOffset, int startLine, int nameOffset, int nameEndOffset, int nameLine, IASTTemplate ownerTemplate, - List references, boolean previouslyDeclared, boolean isConstructor, boolean isDestructor, boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean hasFunctionTryBlock, boolean isFriend, char [] filename ) - { - super( - symbol, - nameEndOffset, - parameters, - returnType, - exception, - startOffset, - startLine, - nameOffset, - nameLine, ownerTemplate, references, previouslyDeclared, hasFunctionTryBlock, isFriend, filename ); - this.visibility = visibility; - this.isConstructor = isConstructor; - this.isDestructor = isDestructor; - this.isPureVirtual = isPureVirtual; - this.constructorChain = constructorChain; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isVirtual() - */ - public boolean isVirtual() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isVirtual ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isExplicit() - */ - public boolean isExplicit() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isExplicit); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isConstructor() - */ - public boolean isConstructor() - { - return isConstructor; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isDestructor() - */ - public boolean isDestructor() - { - return isDestructor; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isConst() - */ - public boolean isConst() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isConst); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isVolatile() - */ - public boolean isVolatile() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isVolatile ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isPureVirtual() - */ - public boolean isPureVirtual() - { - return isPureVirtual; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMember#getVisiblity() - */ - public ASTAccessVisibility getVisiblity() - { - return visibility; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - if( isFriend() ) - requestor.acceptFriendDeclaration( this ); - else - requestor.acceptMethodDeclaration(this); - } - catch (Exception e) - { - /* do nothing */ - } - methodCallbacks(requestor ); - } - protected void methodCallbacks(ISourceElementRequestor requestor) - { - functionCallbacks(requestor); - processConstructorChain(requestor); - } - - protected void processConstructorChain(ISourceElementRequestor requestor ) - { - if( constructorChain != null ) - { - List initializers = getConstructorChainInitializersList(); - for( int i = 0; i < initializers.size(); i++ ) - { - IASTConstructorMemberInitializer c = (IASTConstructorMemberInitializer)initializers.get(i); - c.acceptElement(requestor); - } - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterMethodBody(this); - } - catch (Exception e) - { - /* do nothing */ - } - methodCallbacks( requestor ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitMethodBody( this ); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#getConstructorChainInitializers() - */ - public Iterator getConstructorChainInitializers() - { - if( constructorChain == null ) - return EmptyIterator.EMPTY_ITERATOR; - return constructorChain.iterator(); - } - public List getConstructorChainInitializersList(){ - if( constructorChain == null) - return Collections.EMPTY_LIST; - return constructorChain; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#getOwnerClassSpecifier() - */ - public IASTClassSpecifier getOwnerClassSpecifier() { - if( getOwnerScope() instanceof IASTTemplateDeclaration ) - return (IASTClassSpecifier) ((IASTTemplateDeclaration)getOwnerScope()).getOwnerScope(); - - return (IASTClassSpecifier) getOwnerScope(); - } - - /** - * @param prefix - * @param thisContainer - * @param qualification - * @param filter - * @param lookInThis - * @param lookupResults - * @return - * @throws LookupError - */ - protected List performPrefixLookup(char[] prefix, IContainerSymbol thisContainer, IContainerSymbol qualification, TypeFilter filter, List paramList) throws LookupError { - if( filter.isLookingInThis() ){ - try{ - ISymbol thisPointer = thisContainer.lookup( ParserSymbolTable.THIS ); - ISymbol thisClass = ( thisPointer != null ) ? thisPointer.getTypeSymbol() : null; - if( thisClass != null && thisClass instanceof IContainerSymbol ){ - return ((IContainerSymbol) thisClass).prefixLookup( filter, prefix, true, paramList ); - } - } catch (ParserSymbolTableException e) { - throw new LookupError(); - } catch (ParserSymbolTableError e ){ - throw new LookupError(); - } - } else { - return super.performPrefixLookup( prefix, thisContainer, qualification, filter, paramList ); - } - - return null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethodReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethodReference.java deleted file mode 100644 index 13f0763fee9..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTMethodReference.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTMethodReference; - - -public class ASTMethodReference extends ASTReference - implements - IASTMethodReference { - private IASTMethod method; - /** - * @param offset - */ - public ASTMethodReference(int offset, IASTMethod method) { - super(offset); - this.method = method; - } - /** - * - */ - public ASTMethodReference() { - super(0); - this.method = null; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() - */ - public ISourceElementCallbackDelegate getReferencedElement() { - return method; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - try { - requestor.acceptMethodReference(this); - } catch (Exception e) { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#initialize(int, org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate) - */ - public void initialize(int o, ISourceElementCallbackDelegate referencedElement) { - super.initialize(o); - this.method = (IASTMethod) referencedElement; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#reset() - */ - public void reset() { - resetOffset(); - this.method= null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceAlias.java deleted file mode 100644 index c6287016dff..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceAlias.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTNamespaceAlias extends ASTSymbol implements IASTNamespaceAlias -{ - - private final char[] alias; - private final IASTNamespaceDefinition namespace; - private List references; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param scope - * @param symbol - * @param startingOffset - * @param nameOffset - * @param endOffset - * @param filename - */ - public ASTNamespaceAlias(ISymbol s, char[] alias, IASTNamespaceDefinition namespaceDefinition, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endOffset, int endingLine, List references, char[] filename) - { - super( s ); - this.alias = alias; - this.namespace = namespaceDefinition; - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setEndingOffsetAndLineNumber(endOffset, endingLine); - setNameOffset(nameOffset); - setNameEndOffsetAndLineNumber(nameEndOffset, nameEndOffset); - this.references = references; - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias#getAlias() - */ - public String getAlias() - { - return String.valueOf(alias); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias#getNamespace() - */ - public IASTNamespaceDefinition getNamespace() - { - return namespace; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - Parser.processReferences(references, requestor); - references = null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() - { - return String.valueOf(getSymbol().getName()); - } - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return getSymbol().getName(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceDefinition.java deleted file mode 100644 index ebc8d410f41..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceDefinition.java +++ /dev/null @@ -1,223 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTNamespaceDefinition - extends ASTScope - implements IASTNamespaceDefinition -{ - private final ASTQualifiedNamedElement qualifiedName; - private List declarations = null; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param namespaceSymbol - * @param startingOffset - * @param nameOffset - * @param filename - */ - public ASTNamespaceDefinition(ISymbol namespaceSymbol, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, char[] filename ) - { - super( namespaceSymbol ); - setStartingOffsetAndLineNumber( startingOffset, startingLine ); - setNameOffset( nameOffset ); - setNameEndOffsetAndLineNumber( nameEndOffset, nameLine ); - qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), namespaceSymbol.getName() ); - fn= filename; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() - { - return String.valueOf(symbol.getName()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterNamespaceDefinition( this ); - } - catch (Exception e) - { - /* do nothing */ - } - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitNamespaceDefinition( this ); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedName.getFullyQualifiedName(); - } - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedName.getFullyQualifiedNameCharArrays(); - } - - public Iterator getDeclarations() - { - //If a callback (ie StructuralParseCallback) populates the declarations list - //then return that iterator, otherwise use the ASTScope implementation which - //gets one from the symbol table. - if( declarations != null ) - return declarations.iterator(); - - return super.getDeclarations(); - } - public void addDeclaration(IASTDeclaration declaration) - { - declarations.add(declaration); - } - - public void initDeclarations() - { - declarations = new ArrayList(0); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return symbol.getName(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceReference.java deleted file mode 100644 index 8412994bc9f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNamespaceReference.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceReference; - - -public class ASTNamespaceReference extends ASTReference - implements - IASTNamespaceReference { - private IASTNamespaceDefinition reference; - - /** - * @param offset - * @param definition - */ - public ASTNamespaceReference(int offset, - IASTNamespaceDefinition definition) { - super(offset); - reference = definition; - } - - /** - * - */ - public ASTNamespaceReference() { - super(0); - reference = null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() - */ - public ISourceElementCallbackDelegate getReferencedElement() { - return reference; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - try { - requestor.acceptNamespaceReference(this); - } catch (Exception e) { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#initialize(int, org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate) - */ - public void initialize(int o, ISourceElementCallbackDelegate referencedElement) { - super.initialize(o); - this.reference = (IASTNamespaceDefinition) referencedElement; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#reset() - */ - public void reset() { - resetOffset(); - this.reference = null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewDescriptor.java deleted file mode 100644 index ad661280493..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewDescriptor.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Rational Software - initial implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; - -/** - * @author hamer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class ASTNewDescriptor implements IASTNewExpressionDescriptor { - - private List newPlacementExpressions; - private List newTypeIdExpressions; - private List newInitializerExpressions; - - public ASTNewDescriptor(List newPlacementExpressions, List newTypeIdExpressions, List newInitializerExpressions) { - this.newPlacementExpressions = newPlacementExpressions; - this.newTypeIdExpressions = newTypeIdExpressions; - this.newInitializerExpressions = newInitializerExpressions; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor#getExpressions() - */ - public Iterator getNewPlacementExpressions() { - return newPlacementExpressions.iterator(); - } - public Iterator getNewTypeIdExpressions() { - return newTypeIdExpressions.iterator(); - } - public Iterator getNewInitializerExpressions() { - return newInitializerExpressions.iterator(); - } - - public List getNewInitializerExpressionsList(){ - return newInitializerExpressions; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - accept( requestor, getNewPlacementExpressions() ); - accept( requestor, getNewTypeIdExpressions() ); - accept( requestor, getNewInitializerExpressions() ); - } - - - /** - * @param requestor - * @param iterator - * @param manager - */ - protected void accept(ISourceElementRequestor requestor, Iterator iterator) - { - while( iterator.hasNext() ) - ((IASTExpression)iterator.next()).acceptElement(requestor); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - free( newPlacementExpressions ); - free( newTypeIdExpressions ); - free( newInitializerExpressions ); - } - - - /** - * @param list - * @param manager - */ - private void free(List list ) { - if( list == null || list.isEmpty() ) return; - for( int i = 0; i < list.size(); ++i) - ((IASTExpression)list.get(i)).freeReferences(); - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java deleted file mode 100644 index 1807660fad5..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNewExpression.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; - -/** - * @author jcamelon - * - */ -public class ASTNewExpression extends ASTExpression { - - private final IASTTypeId typeId; - private final IASTNewExpressionDescriptor newDescriptor; - - /** - * @param kind - * @param references - * @param newDescriptor - * @param typeId - */ - public ASTNewExpression(Kind kind, List references, IASTNewExpressionDescriptor newDescriptor, IASTTypeId typeId) { - super( kind, references ); - this.newDescriptor = newDescriptor; - this.typeId = typeId; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId() - */ - public IASTTypeId getTypeId() { - return typeId; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor() - */ - public IASTNewExpressionDescriptor getNewExpressionDescriptor() { - return newDescriptor; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - protected void processCallbacks(ISourceElementRequestor requestor ) { - super.processCallbacks(requestor ); - typeId.acceptElement(requestor); - newDescriptor.acceptElement(requestor); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#findNewDescriptor(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public IASTExpression findNewDescriptor(ITokenDuple finalDuple) { - if( ((ASTTypeId)typeId).getTokenDuple().contains( finalDuple )) - return this; - return null; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - super.freeReferences(); - typeId.freeReferences( ); - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } - - public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) { - ASTTypeId ti = (ASTTypeId) getTypeId(); - ITokenDuple typeDuple = ti.getTokenDuple(); - - if( typeDuple.equals( duple ) ) - return this; - // check subduple - if( typeDuple.contains( duple ) ) - return this; - - //else, check the parameters - ASTExpression ownerExpression = null; - ASTNewDescriptor nd = (ASTNewDescriptor)getNewExpressionDescriptor(); - List newInitializerExpressions = nd.getNewInitializerExpressionsList(); - int size = newInitializerExpressions.size(); - for( int i = 0; i < size; i++ ) - { - ASTExpression expressionList = (ASTExpression) newInitializerExpressions.get(i); - ownerExpression = expressionList.findOwnerExpressionForIDExpression( duple ); - if( ownerExpression != null ){ - break; - } - } - - return ownerExpression; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffsetAndLineNumber(int, int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffsetAndLineNumber(int, int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - // TODO Auto-generated method stub - return null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java deleted file mode 100644 index c53833c0db3..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.internal.core.parser.ast.SymbolIterator; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableError; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; -import org.eclipse.cdt.internal.core.parser.pst.TypeFilter; - -/** - * @author aniefer - */ -public class ASTNode implements IASTNode { - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind, org.eclipse.cdt.core.parser.ast.IASTNode) - */ - public ILookupResult lookup(String prefix, LookupKind[] kind, IASTNode context, IASTExpression functionParameters) throws LookupError, ASTNotImplementedException { - - if( ! ( this instanceof ISymbolOwner ) ){ - return null; - } - - IExtensibleSymbol symbol = ((ISymbolOwner)this).getSymbol(); - if( symbol == null || !(symbol instanceof IContainerSymbol) ){ - throw new LookupError(); - } - IContainerSymbol thisContainer = (IContainerSymbol) symbol; - IContainerSymbol qualification = ( context != null ) ? ((ASTNode)context).getLookupQualificationSymbol() : null; - - // trying to dereference a context of unknown type - if (context != null && qualification == null) - return null; - - List parameters = createLookupParameterList( functionParameters ); - - int paramIndex = ( parameters != null ) ? parameters.size() : 0; - - if( thisContainer.getSymbolTable().getParserMode() != ParserMode.COMPLETION_PARSE ){ - throw new ASTNotImplementedException(); - } - - TypeFilter filter = new TypeFilter(); - if( kind != null ){ - for( int i = 0; i < kind.length; i++ ){ - filter.addAcceptedType( kind[i] ); - if( kind[i] == LookupKind.THIS ){ - filter.setLookingInThis( true ); - if( kind.length == 1 ){ - filter.addAcceptedType( LookupKind.ALL ); - } - } else { - filter.addAcceptedType( kind[i] ); - } - } - } else { - filter.addAcceptedType( LookupKind.ALL ); - } - - List lookupResults = performPrefixLookup(prefix.toCharArray(), thisContainer, qualification, filter, parameters); - - if(lookupResults == null) - return null; - - //filter out things that are not visible and things that don't have AST nodes attached - ListIterator iter = lookupResults.listIterator(); - while( iter.hasNext() ){ - ISymbol s = (ISymbol) iter.next(); - if( !thisContainer.isVisible( s, qualification ) || - s.getASTExtension() == null || - s.getASTExtension().getPrimaryDeclaration() == null ) - { - iter.remove(); - continue; - } - - if( context != null && ((ASTNode)context).shouldFilterLookupResult( s ) ) - iter.remove(); - - } - - SymbolIterator iterator = new SymbolIterator( lookupResults.iterator() ); - - return new Result( prefix, iterator, lookupResults.size(), paramIndex ); - } - - /** - * @param prefix - * @param thisContainer - * @param qualification - * @param filter - * @param paramList TODO - * @param lookInThis - * @param lookupResults - * @return - * @throws LookupError - */ - protected List performPrefixLookup(char[] prefix, IContainerSymbol thisContainer, IContainerSymbol qualification, TypeFilter filter, List paramList) throws LookupError { - List results = null; - try { - if( qualification != null ){ - results = qualification.prefixLookup( filter, prefix, true, paramList ); - } else { - results = thisContainer.prefixLookup( filter, prefix, false, paramList ); - } - } catch (ParserSymbolTableException e) { - throw new LookupError(); - } catch (ParserSymbolTableError e ){ - throw new LookupError(); - } - return results; - } - - /** - * @param context - * @param qualification - * @return - * @throws LookupError - */ - public IContainerSymbol getLookupQualificationSymbol() throws LookupError { - throw new LookupError(); - } - - public boolean shouldFilterLookupResult( ISymbol symbol ){ - return false; - } - - public List createLookupParameterList( IASTExpression parameterExpression ){ - if( parameterExpression == null ) - return null; - - List params = new ArrayList(); - ASTExpression exp = (ASTExpression) parameterExpression; - while( exp != null ){ - params.add( exp.getResultType().getResult() ); - exp = (ASTExpression) exp.getRHSExpression(); - } - return params; - } - - private class Result implements ILookupResult{ - private String prefix; - private Iterator iterator; - private int resultsNumber; - private int parameterIndex; - - public Result( String pref, Iterator iter, int resultsSize, int paramIndex ){ - prefix = pref; - iterator = iter; - resultsNumber = resultsSize; - parameterIndex = paramIndex; - } - - public String getPrefix() { return prefix; } - public Iterator getNodes() { return iterator; } - public int getResultsSize() { return resultsNumber; } - public int getIndexOfNextParameter() { return parameterIndex; } - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTParameterDeclaration.java deleted file mode 100644 index 61652e11544..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTParameterDeclaration.java +++ /dev/null @@ -1,251 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.ast.ASTAbstractDeclaration; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTParameterDeclaration extends ASTSymbol implements IASTParameterDeclaration -{ - private final ASTAbstractDeclaration abstractDeclaration; - private final char[] parameterName; - private final IASTInitializerClause initializerClause; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param isConst - * @param typeSpecifier - * @param pointerOperators - * @param arrayModifiers - * @param parameterName - * @param initializerClause - * @param filename - */ - public ASTParameterDeclaration(ISymbol symbol, boolean isConst, boolean isVolatile, IASTTypeSpecifier typeSpecifier, List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOp, char[] parameterName, IASTInitializerClause initializerClause, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] filename ) - { - super( symbol ); - abstractDeclaration = new ASTAbstractDeclaration( isConst, isVolatile, typeSpecifier, pointerOperators, arrayModifiers, parameters, pointerOp ); - this.parameterName = parameterName; - this.initializerClause = initializerClause; - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setEndingOffsetAndLineNumber(endingOffset, endingLine); - setNameOffset(nameOffset); - setNameEndOffsetAndLineNumber( nameEndOffset, nameLine ); - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration#getName() - */ - public String getName() - { - return String.valueOf(parameterName); - } - public char[] getNameCharArray(){ - return parameterName; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration#getDefaultValue() - */ - public IASTInitializerClause getDefaultValue() - { - return initializerClause; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#isConst() - */ - public boolean isConst() - { - return abstractDeclaration.isConst(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#isVolatile() - */ - public boolean isVolatile() - { - return abstractDeclaration.isVolatile(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getPointerOperators() - */ - public Iterator getPointerOperators() - { - return abstractDeclaration.getPointerOperators(); - } - public List getPointerOperatorsList(){ - return abstractDeclaration.getPointerOperatorsList(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getArrayModifiers() - */ - public Iterator getArrayModifiers() - { - return abstractDeclaration.getArrayModifiers(); - } - public List getArrayModifiersList(){ - return abstractDeclaration.getArrayModifiersList(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getParameters() - */ - public Iterator getParameters() - { - return abstractDeclaration.getParameters(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration#getPointerToFunctionOperator() - */ - public ASTPointerOperator getPointerToFunctionOperator() - { - return abstractDeclaration.getPointerToFunctionOperator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeSpecifierOwner#getTypeSpecifier() - */ - public IASTTypeSpecifier getTypeSpecifier() - { - return abstractDeclaration.getTypeSpecifier(); - } - - public IASTAbstractDeclaration getAbstractDeclaration(){ - return abstractDeclaration; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration#getOwnerFunctionDeclaration() - */ - public IASTFunction getOwnerFunctionDeclaration() throws ASTNotImplementedException { - return (IASTFunction) getSymbol().getContainingSymbol().getASTExtension().getPrimaryDeclaration(); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTParameterReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTParameterReference.java deleted file mode 100644 index 66ff5e60ac1..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTParameterReference.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTParameterReference; - - -public class ASTParameterReference extends ASTReference - implements - IASTParameterReference { - private IASTParameterDeclaration parm; - - /** - * @param offset - * @param declaration - */ - public ASTParameterReference(int offset, - IASTParameterDeclaration declaration) { - super(offset); - parm = declaration; - } - - /** - * - */ - public ASTParameterReference() { - super(0); - parm = null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() - */ - public ISourceElementCallbackDelegate getReferencedElement() { - return parm; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - try { - requestor.acceptParameterReference(this); - } catch (Exception e) { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#initialize(int, org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate) - */ - public void initialize(int o, ISourceElementCallbackDelegate referencedElement) { - initialize(o); - this.parm = (IASTParameterDeclaration) referencedElement; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#reset() - */ - public void reset() { - resetOffset(); - this.parm = null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTProblemFactory.java deleted file mode 100644 index 8f4215230ef..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTProblemFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Rational Software - initial implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.internal.core.parser.problem.BaseProblemFactory; -import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; - -/** - * @author jcamelon - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class ASTProblemFactory extends BaseProblemFactory implements IProblemFactory -{ - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.problem.IProblemFactory#createProblem(int, int, int, int, char[], java.util.Map, boolean, boolean) - */ - public IProblem createProblem(int id, int start, int end, int line, - char[] file, char[] arg, boolean warn, boolean error) { - - if( checkBitmask( id, IProblem.INTERNAL_RELATED ) ) - return createInternalProblem( id, start, end, line, file, arg, warn, error ); - - if ( checkBitmask( id, IProblem.SEMANTICS_RELATED ) ) - return super.createProblem( - id, - start, - end, - line, - file, - arg, - warn, - error); - - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.problem.IProblemFactory#getRequiredAttributesForId(int) - */ - public String getRequiredAttributesForId(int id) { - switch (id) - { - case IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED : - case IProblem.SEMANTIC_NAME_NOT_FOUND: - case IProblem.SEMANTIC_AMBIGUOUS_LOOKUP: - return IProblem.A_SYMBOL_NAME; - case IProblem.SEMANTIC_INVALID_TYPE: - return IProblem.A_TYPE_NAME; - case IProblem.SEMANTIC_INVALID_USING: - return IProblem.A_NAMESPACE_NAME; - case IProblem.SEMANTIC_NAME_NOT_PROVIDED: - return null; - } - return null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTReference.java deleted file mode 100644 index e907cccf08c..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTReference.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.ast.IASTReference; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; - - -public abstract class ASTReference implements IASTReference { - protected int offset; - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ - private static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$ - - public abstract void reset(); - - protected void resetOffset() { - offset = 0; - } - - /** - * @param offset2 - * @param re - */ - public abstract void initialize(int o, ISourceElementCallbackDelegate re ); - - - protected void initialize(int o) { - this.offset = o; - } - - /** - * - */ - public ASTReference(int offset) { - this.offset = offset; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getOffset() - */ - public int getOffset() { - return offset; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getName() - */ - public String getName() { - if (getReferencedElement() instanceof IASTOffsetableNamedElement) - return ((IASTOffsetableNamedElement) getReferencedElement()) - .getName(); - return EMPTY_STRING; - } - public char[] getNameCharArray() { - if (getReferencedElement() instanceof IASTOffsetableNamedElement) - return ((IASTOffsetableNamedElement) getReferencedElement()) - .getNameCharArray(); - return EMPTY_CHAR_ARRAY; - } - public boolean equals(Object obj) { - if (obj == null) - return false; - if (!(obj instanceof IASTReference)) - return false; - - if ( CharArrayUtils.equals( ((IASTReference) obj).getNameCharArray(), getNameCharArray() ) - && ((IASTReference) obj).getOffset() == getOffset()) - return true; - return false; - } - - public void enterScope(ISourceElementRequestor requestor) { - } - - public void exitScope(ISourceElementRequestor requestor) { - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTScope.java deleted file mode 100644 index c70fa87bca7..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTScope.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.internal.core.parser.ast.SymbolIterator; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public abstract class ASTScope extends ASTSymbol implements IASTScope -{ - /** - * @param symbol - */ - public ASTScope(ISymbol symbol) - { - super(symbol); - } - - public IContainerSymbol getContainerSymbol() - { - return (IContainerSymbol)symbol; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() - */ - public Iterator getDeclarations() - { - if( getContainerSymbol() != null ){ - return new SymbolIterator( getContainerSymbol().getContentsIterator() ); - } - return null; - } - - public void addDeclaration(IASTDeclaration declaration) - { - } - - public void initDeclarations() - { - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSimpleTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSimpleTypeSpecifier.java deleted file mode 100644 index 27ea8db92fa..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSimpleTypeSpecifier.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; - -/** - * @author jcamelon - * - */ -public class ASTSimpleTypeSpecifier extends ASTNode implements IASTSimpleTypeSpecifier -{ - private final List refs; - private ISymbol symbol; - private final boolean isTypename; - private final char[] name; - - /** - * @param s - * @param b - * @param string - */ - public ASTSimpleTypeSpecifier(ISymbol s, boolean b, char[] string, List references ) - { - this.symbol = s; - this.isTypename = b; - this.name = string; - this.refs = references; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getType() - */ - public Type getType() - { - if( symbol.getType() == ITypeInfo.t_int ) - return IASTSimpleTypeSpecifier.Type.INT; - if( symbol.getType() == ITypeInfo.t_double ) - return IASTSimpleTypeSpecifier.Type.DOUBLE; - if( symbol.getType() == ITypeInfo.t_float ) - return IASTSimpleTypeSpecifier.Type.FLOAT; - if( symbol.getType() == ITypeInfo.t_bool ) - return IASTSimpleTypeSpecifier.Type.BOOL; - if( symbol.getType() == ITypeInfo.t_type ) - return IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; - if( symbol.getType() == ITypeInfo.t_char ) - return IASTSimpleTypeSpecifier.Type.CHAR; - if( symbol.getType() == ITypeInfo.t_void ) - return IASTSimpleTypeSpecifier.Type.VOID; - if( symbol.getType() == ITypeInfo.t_wchar_t) - return IASTSimpleTypeSpecifier.Type.WCHAR_T; - if( symbol.getType() == ITypeInfo.t__Bool ) - return IASTSimpleTypeSpecifier.Type._BOOL; - - return IASTSimpleTypeSpecifier.Type.UNSPECIFIED; - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getTypename() - */ - public String getTypename() - { - return String.valueOf(name); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isLong() - */ - public boolean isLong() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isLong ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isShort() - */ - public boolean isShort() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isShort ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isSigned() - */ - public boolean isSigned() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isSigned); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isUnsigned() - */ - public boolean isUnsigned() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isUnsigned ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isTypename() - */ - public boolean isTypename() - { - return isTypename; - } - /** - * @return - */ - public ISymbol getSymbol() - { - return symbol; - } - - public List getReferences() - { - return (refs == null ) ? Collections.EMPTY_LIST : refs; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getTypeSpecifier() - */ - public IASTTypeSpecifier getTypeSpecifier() - { - return (IASTTypeSpecifier)getSymbol().getTypeSymbol().getASTExtension().getPrimaryDeclaration(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isComplex() - */ - public boolean isComplex() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isComplex ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isImaginary() - */ - public boolean isImaginary() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isImaginary ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#releaseReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void releaseReferences() { - if( refs == null || refs.isEmpty() ) return; - refs.clear(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java deleted file mode 100644 index 0396abbfe32..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbol.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableError; -import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider; - -/** - * @author jcamelon - * - */ -public abstract class ASTSymbol extends ASTSymbolOwner implements ISymbolOwner, IASTDeclaration -{ - - public ASTSymbol( ISymbol symbol ) - { - super(symbol); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() - */ - public IASTScope getOwnerScope() - { - if( symbol.getContainingSymbol() != null ) - return (IASTScope)symbol.getContainingSymbol().getASTExtension().getPrimaryDeclaration(); - return null; - } - - public IContainerSymbol getLookupQualificationSymbol() throws LookupError { - ISymbol sym = getSymbol(); - IContainerSymbol result = null; - TypeInfoProvider provider = sym.getSymbolTable().getTypeInfoProvider(); - ITypeInfo info = null; - - try{ - info = sym.getTypeInfo().getFinalType( provider ); - } catch( ParserSymbolTableError e ){ - throw new LookupError(); - } - - if( info.isType( ITypeInfo.t_type ) && info.getTypeSymbol() != null && info.getTypeSymbol() instanceof IContainerSymbol ) - result = (IContainerSymbol) info.getTypeSymbol(); - else if( sym instanceof IContainerSymbol ) - result = (IContainerSymbol) sym; - - provider.returnTypeInfo( info ); - return result; - } - - public boolean shouldFilterLookupResult( ISymbol sym ){ - boolean result = false; - TypeInfoProvider provider = sym.getSymbolTable().getTypeInfoProvider(); - ITypeInfo info = null; - try{ - info = getSymbol().getTypeInfo().getFinalType( provider ); - } catch( ParserSymbolTableError e ){ - return true; - } - - if( info.checkBit( ITypeInfo.isConst ) && !sym.getTypeInfo().checkBit( ITypeInfo.isConst ) ) - result = true; - - if( info.checkBit( ITypeInfo.isVolatile ) && !sym.getTypeInfo().checkBit( ITypeInfo.isVolatile ) ) - result = true; - - provider.returnTypeInfo( info ); - return result; - - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbolOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbolOwner.java deleted file mode 100644 index eaae9ccb2b6..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTSymbolOwner.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner; - -/** - * @author jcamelon - * - */ -public class ASTSymbolOwner extends ASTNode implements ISymbolOwner -{ - protected ISymbol symbol; - /** - * - */ - public ASTSymbolOwner( ISymbol symbol ) - { - this.symbol = symbol; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner#getSymbol() - */ - public ISymbol getSymbol() - { - return symbol; - } - - public void setSymbol( ISymbol symbol ) - { - this.symbol = symbol; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateDeclaration.java deleted file mode 100644 index 9f1cc206a5e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateDeclaration.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension; -import org.eclipse.cdt.internal.core.parser.pst.ITemplateFactory; -import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol; -import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension; - -/** - * @author jcamelon - * - */ -public class ASTTemplateDeclaration extends ASTSymbol implements IASTTemplateDeclaration -{ - final private List templateParameters; - private ISymbol owned = null; - private IASTScope ownerScope; - private ITemplateFactory factory; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - - private ITemplateSymbol getTemplateSymbol(){ - return (ITemplateSymbol) (( getSymbol() instanceof ITemplateSymbol ) ? getSymbol() : null); - } - /** - * @param filename - * - */ - public ASTTemplateDeclaration( ITemplateSymbol template, IASTScope scope, List parameters, char[] filename ) - { - super( template ); - - IContainerSymbol container = null; - if( scope instanceof ASTTemplateDeclaration ) - container = ((ASTTemplateDeclaration)scope).getContainerSymbol(); - else - container = ((ASTScope)scope).getContainerSymbol(); - - if( container instanceof ITemplateFactory ){ - factory = (ITemplateFactory) container; - } else { - factory = template.getSymbolTable().newTemplateFactory(); - factory.setContainingSymbol( container ); - factory.setASTExtension( new StandardSymbolExtension(factory, this ) ); - } - - factory.pushTemplate( template ); - - templateParameters = ( parameters != null ) ? parameters : Collections.EMPTY_LIST; - ownerScope = scope; - fn = filename; - } - - public IASTScope getOwnerScope(){ - return ownerScope; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration#isExported() - */ - public boolean isExported() - { - // TODO Auto-generated method stub - return false; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplate#getOwnedDeclaration() - */ - public IASTDeclaration getOwnedDeclaration() - { - if( owned != null && owned.getASTExtension() != null ){ - ISymbolASTExtension extension = owned.getASTExtension(); - Iterator i = extension.getAllDefinitions(); - ASTSymbol s = null; - while( i.hasNext() ){ - s = (ASTSymbol) i.next(); - } - - return s; - } - - IContainerSymbol ownedSymbol = getTemplateSymbol().getTemplatedSymbol(); - if( ownedSymbol != null && ownedSymbol.getASTExtension() != null ){ - ASTNode node = ownedSymbol.getASTExtension().getPrimaryDeclaration(); - return ( node instanceof IASTDeclaration ) ? (IASTDeclaration)node : null; - } - return null; - } - - public void setOwnedDeclaration(ISymbol symbol) { - owned = symbol; - } - - public void releaseFactory(){ - factory = null; - } - - public IContainerSymbol getContainerSymbol() - { - return factory != null ? (IContainerSymbol) factory : getTemplateSymbol(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameterList#getTemplateParameters() - */ - public Iterator getTemplateParameters() - { - return templateParameters.iterator(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterTemplateDeclaration(this); - } - catch (Exception e) - { - /* do nothing */ - } - if( templateParameters == null || templateParameters.isEmpty()) return; - for( int i = 0; i < templateParameters.size(); ++i ) - ((IASTTemplateParameter)templateParameters.get(i)).acceptElement(requestor ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitTemplateDeclaration(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplate#setOwnedDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void setOwnedDeclaration(IASTDeclaration declaration) { - // TODO Auto-generated method stub - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() - */ - public Iterator getDeclarations() throws ASTNotImplementedException { - // TODO Auto-generated method stub - return null; - } - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateInstantiation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateInstantiation.java deleted file mode 100644 index 948cb24d6c3..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateInstantiation.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITemplateFactory; -import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol; -import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension; - -/** - * @author jcamelon - * - */ -public class ASTTemplateInstantiation extends ASTSymbol implements IASTTemplateInstantiation -{ - private ITemplateFactory factory; - private IASTScope ownerScope; - private IASTTemplateDeclaration instantiatedTemplate; - private ISymbol instance; - - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - - public ASTTemplateInstantiation( IASTScope scope, char[] filename ){ - super( null ); - IContainerSymbol container = ((ASTScope)scope).getContainerSymbol(); - - factory = container.getSymbolTable().newTemplateFactory(); - factory.setContainingSymbol( container ); - - factory.setASTExtension( new StandardSymbolExtension( factory, this ) ); - - factory.pushTemplate( null ); - ownerScope = scope; - fn = filename; - } - - public IASTTemplateDeclaration getInstantiatedTemplate(){ - return instantiatedTemplate; - } - - public void releaseFactory(){ - factory = null; - } - - public void setInstanceSymbol( ISymbol sym ){ - instance = sym; - ITemplateSymbol template = (ITemplateSymbol) instance.getInstantiatedSymbol().getContainingSymbol(); - instantiatedTemplate = (IASTTemplateDeclaration) template.getASTExtension().getPrimaryDeclaration(); - setSymbol( instance.getInstantiatedSymbol().getContainingSymbol() ); - } - - public ISymbol getInstanceSymbol(){ - return instance; - } - - public IContainerSymbol getContainerSymbol() - { - return factory != null ? (IContainerSymbol) factory : ((ASTTemplateDeclaration)getInstantiatedTemplate()).getContainerSymbol(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplate#getOwnedDeclaration() - */ - public IASTDeclaration getOwnedDeclaration() - { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplate#setOwnedDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void setOwnedDeclaration(IASTDeclaration declaration) - { - // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() - */ - public IASTScope getOwnerScope() - { - return ownerScope; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - // TODO Auto-generated method stub - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterTemplateInstantiation(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitTemplateExplicitInstantiation(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() - */ - public Iterator getDeclarations() throws ASTNotImplementedException { - // TODO Auto-generated method stub - return null; - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateParameter.java deleted file mode 100644 index 01cb9584ac1..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateParameter.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Mar 3, 2004 - */ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class ASTTemplateParameter extends ASTSymbol implements IASTTemplateParameter, IASTOffsetableNamedElement { - -// private ParamKind kind; -// private String identifier; - //private ISymbol symbol; - private IASTTypeId defaultValue; - private ASTParameterDeclaration parameter; - private List parms; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - - /** - * @param filename - * @param symbol - * @param defaultValue2 - * @param parameter2 - * @param parms2 - */ - public ASTTemplateParameter(ISymbol sym, IASTTypeId defVal, IASTParameterDeclaration param, List parms, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] filename ) { - super( sym ); - symbol = sym; - defaultValue = defVal; - parameter = (ASTParameterDeclaration) param; - this.parms = parms; - - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setEndingOffsetAndLineNumber(endingOffset, endingLine); - setNameOffset(nameOffset); - setNameEndOffsetAndLineNumber( nameEndOffset, nameLine ); - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getTemplateParameterKind() - */ - public ParamKind getTemplateParameterKind() { - ITypeInfo.eType type = symbol.getTypeInfo().getTemplateParameterType(); - if( type == ITypeInfo.t_typeName ) - //TODO: difference between class & typename? - return ParamKind.TYPENAME; - else if( type == ITypeInfo.t_template ) - return ParamKind.TEMPLATE_LIST; - else - return ParamKind.PARAMETER; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getIdentifier() - */ - public String getIdentifier() { - return String.valueOf(symbol.getName()); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getDefaultValueIdExpression() - */ - public String getDefaultValueIdExpression() { - return ( defaultValue != null ) ? defaultValue.toString() : ""; //$NON-NLS-1$ - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getParameterDeclaration() - */ - public IASTParameterDeclaration getParameterDeclaration() { - return parameter; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameterList#getTemplateParameters() - */ - public Iterator getTemplateParameters() { - return parms.iterator(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - if( defaultValue != null ) - defaultValue.acceptElement( requestor ); - if( parameter != null ) - parameter.acceptElement( requestor ); - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) { - // TODO Auto-generated method stub - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) { - // TODO Auto-generated method stub - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() { - return String.valueOf(symbol.getName()); - } - public char[] getNameCharArray(){ - return symbol.getName(); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateParameterReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateParameterReference.java deleted file mode 100644 index bd4669b9086..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateParameterReference.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameterReference; - - -public class ASTTemplateParameterReference extends ASTReference - implements - IASTTemplateParameterReference { - private IASTTemplateParameter parameter; - /** - * @param offset - */ - public ASTTemplateParameterReference(int offset, - IASTTemplateParameter param) { - super(offset); - parameter = param; - } - - /** - * - */ - public ASTTemplateParameterReference() { - super(0); - parameter = null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() - */ - public ISourceElementCallbackDelegate getReferencedElement() { - return parameter; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - try { - requestor.acceptTemplateParameterReference(this); - } catch (Exception e) { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#initialize(int, org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate) - */ - public void initialize(int o, ISourceElementCallbackDelegate referencedElement) { - super.initialize(o); - parameter = (IASTTemplateParameter) referencedElement; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#reset() - */ - public void reset() { - resetOffset(); - this.parameter = null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateSpecialization.java deleted file mode 100644 index 5f145dee0d6..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateSpecialization.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol; - -/** - * @author jcamelon - * - */ -public class ASTTemplateSpecialization extends ASTTemplateDeclaration implements IASTTemplateSpecialization -{ - /** - * @param filename - * - */ - public ASTTemplateSpecialization( ITemplateSymbol template, IASTScope scope, char []filename ) - { - super(template, scope, null, filename); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeId.java deleted file mode 100644 index bb46fa693dc..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeId.java +++ /dev/null @@ -1,252 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.IASTArrayModifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTTypeId implements IASTTypeId -{ - private final boolean isTypename; - private final boolean isUnsigned; - private final boolean isSigned; - private final boolean isShort; - private final boolean isLong; - private final boolean isVolatile; - private final boolean isConst; - private final char[] signature; - private ITokenDuple tokenDuple; - private final List arrayModifiers; - private final char[] typeName; - private final List pointerOps; - private final Type kind; - private List references = null; - private ISymbol symbol; - - /** - * - */ - public ASTTypeId( Type kind, ITokenDuple duple, List pointerOps, List arrayMods, char[] signature, - boolean isConst, boolean isVolatile, boolean isUnsigned, boolean isSigned, boolean isShort, boolean isLong, boolean isTypeName ) - { - typeName = ( duple == null ) ? "".toCharArray() : duple.toCharArray() ; //$NON-NLS-1$ - this.tokenDuple = duple; - this.kind = kind; - this.pointerOps = pointerOps; - this.arrayModifiers = arrayMods; - this.signature = signature; - this.isConst = isConst; - this.isVolatile = isVolatile; - this.isUnsigned = isUnsigned; - this.isSigned = isSigned; - this.isShort = isShort; - this.isLong = isLong; - this.isTypename = isTypeName; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getKind() - */ - public Type getKind() - { - return kind; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getType() - */ - public String getTypeOrClassName() - { - return String.valueOf(typeName); - } - public char[] getTypeOrClassNameCharArray(){ - return typeName; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getPointerOperators() - */ - public Iterator getPointerOperators() - { - return pointerOps.iterator(); - } - public List getPointerOperatorsList(){ - return pointerOps; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getArrayModifiers() - */ - public Iterator getArrayModifiers() - { - return arrayModifiers.iterator(); - } - public List getArrayModifiersList(){ - return arrayModifiers; - } - - public List getReferences() - { - return (references == null ) ? Collections.EMPTY_LIST : references; - } - - public ITokenDuple getTokenDuple() - { - return tokenDuple; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getFullSignature() - */ - public String getFullSignature() - { - return String.valueOf(signature); - } - - public char[] getFullSignatureCharArray(){ - return signature; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#createTypeSymbol(org.eclipse.cdt.core.parser.ast.IASTFactory) - */ - public ISymbol getTypeSymbol() - { - return symbol; - } - - public void setTypeSymbol( ISymbol symbol ) - { - this.symbol = symbol; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isConst() - */ - public boolean isConst() - { - return isConst; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isVolatile() - */ - public boolean isVolatile() - { - return isVolatile; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isLong() - */ - public boolean isLong() - { - return isLong; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isShort() - */ - public boolean isShort() - { - return isShort; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isSigned() - */ - public boolean isSigned() - { - return isSigned; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isUnsigned() - */ - public boolean isUnsigned() - { - return isUnsigned; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isTypename() - */ - public boolean isTypename() - { - return isTypename; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - Parser.processReferences(references, requestor); - references = null; - if( tokenDuple != null ) - tokenDuple.acceptElement( requestor ); - - List arrayMods = getArrayModifiersList(); - int size = arrayMods.size(); - for( int i = 0; i < size; i++ ) - { - ((IASTArrayModifier)arrayMods.get(i)).acceptElement(requestor); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - /** - * @param list - */ - public void addReferences(List list ) - { - if( references == null ) - references = new ArrayList( list.size() ); - for( int i = 0; i < list.size(); ++i ) - references.add( list.get(i) ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - if( tokenDuple != null ) - tokenDuple.freeReferences( ); - - if( references == null || references.isEmpty() ) return; - references.clear(); - } - - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeIdExpression.java deleted file mode 100644 index 85577d8066a..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypeIdExpression.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; - -/** - * @author jcamelon - * - */ -public class ASTTypeIdExpression extends ASTExpression { - private final IASTTypeId typeId; - /** - * @param kind - * @param references - * @param typeId - */ - public ASTTypeIdExpression(Kind kind, List references, IASTTypeId typeId) { - super( kind, references ); - this.typeId = typeId; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId() - */ - public IASTTypeId getTypeId() { - return typeId; - } - - protected void processCallbacks(ISourceElementRequestor requestor ) { - super.processCallbacks(requestor ); - typeId.acceptElement(requestor); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - super.freeReferences(); - typeId.freeReferences(); - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#findOwnerExpressionForIDExpression(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) { - if( typeId instanceof ASTTypeId && ((ASTTypeId)typeId).getTokenDuple() == duple ) - return this; - return super.findOwnerExpressionForIDExpression(duple); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffsetAndLineNumber(int, int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffsetAndLineNumber(int, int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - // TODO Auto-generated method stub - return null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypedef.java deleted file mode 100644 index faa8c106a0e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypedef.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTTypedef extends ASTSymbol implements IASTTypedefDeclaration -{ - - private final IASTAbstractDeclaration mapping; - private final ASTQualifiedNamedElement qualifiedName; - private List references; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param newSymbol - * @param mapping - * @param startingOffset - * @param nameOffset - * @param references - * @param filename - */ - public ASTTypedef(ISymbol newSymbol, IASTAbstractDeclaration mapping, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, List references, char[] filename) - { - super( newSymbol ); - this.mapping = mapping; - this.references = references; - this.qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), newSymbol.getName()); - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setNameOffset(nameOffset); - setNameEndOffsetAndLineNumber( nameEndOffset, nameLine ); - fn = filename; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration#getName() - */ - public String getName() - { - return String.valueOf(getSymbol().getName()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration#getAbstractDeclarator() - */ - public IASTAbstractDeclaration getAbstractDeclarator() - { - return mapping; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptTypedefDeclaration(this); - } - catch (Exception e) - { - /* do nothing */ - } - Parser.processReferences(references, requestor); - references = null; - getAbstractDeclarator().acceptElement( requestor ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedName.getFullyQualifiedName(); - } - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedName.getFullyQualifiedNameCharArrays(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration#getFinalTypeSpecifier() - */ - public IASTTypeSpecifier getFinalTypeSpecifier() throws ASTNotImplementedException { - IASTTypeSpecifier currentTypeSpec = mapping.getTypeSpecifier(); - while( currentTypeSpec instanceof IASTSimpleTypeSpecifier || - currentTypeSpec instanceof IASTTypedefDeclaration ) - { - if( currentTypeSpec instanceof IASTSimpleTypeSpecifier ) - { - IASTSimpleTypeSpecifier simpleTypeSpec = (IASTSimpleTypeSpecifier) currentTypeSpec; - if( simpleTypeSpec.getType() == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME ) - currentTypeSpec = simpleTypeSpec.getTypeSpecifier(); - else - break; - } - else if( currentTypeSpec instanceof IASTTypedefDeclaration ) - { - currentTypeSpec = ((IASTTypedefDeclaration)currentTypeSpec).getAbstractDeclarator().getTypeSpecifier(); - } - } - return currentTypeSpec; - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return getSymbol().getName(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypedefReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypedefReference.java deleted file mode 100644 index 4110fc9e0a4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTypedefReference.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypedefReference; - - -public class ASTTypedefReference extends ASTReference - implements - IASTTypedefReference { - private IASTTypedefDeclaration referencedItem; - /** - * @param offset - */ - public ASTTypedefReference(int offset, - IASTTypedefDeclaration referencedItem) { - super(offset); - this.referencedItem = referencedItem; - } - /** - * - */ - public ASTTypedefReference() { - super( 0 ); - this.referencedItem = null; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() - */ - public ISourceElementCallbackDelegate getReferencedElement() { - return referencedItem; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - try { - requestor.acceptTypedefReference(this); - } catch (Exception e) { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#initialize(int, org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate) - */ - public void initialize(int o, ISourceElementCallbackDelegate referencedElement) { - super.initialize(o); - referencedItem = (IASTTypedefDeclaration) referencedElement; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#reset() - */ - public void reset() { - super.resetOffset(); - referencedItem = null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryExpression.java deleted file mode 100644 index c9cf116dcd7..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryExpression.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; - -/** - * @author jcamelon - * - */ -public class ASTUnaryExpression extends ASTExpression { - - private final IASTExpression lhs; - /** - * @param kind - * @param references - */ - public ASTUnaryExpression(Kind kind, List references, IASTExpression lhs ) { - super(kind, references); - this.lhs = lhs; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLHSExpression() - */ - public IASTExpression getLHSExpression() { - return lhs; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#findOwnerExpressionForIDExpression(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) { - if( isIDExpressionForDuple( lhs, duple ) ) - return this; - ASTExpression result = recursiveFindExpressionForDuple(lhs, duple); - return result; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences() - */ - public void reconcileReferences() throws ASTNotImplementedException { - lhs.reconcileReferences(); - reconcileSubExpression((ASTExpression) lhs); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences() - */ - public void purgeReferences() throws ASTNotImplementedException { - lhs.purgeReferences(); - purgeSubExpression( (ASTExpression) lhs ); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks() - */ - protected void processCallbacks( ISourceElementRequestor requestor ) { - super.processCallbacks(requestor ); - lhs.acceptElement( requestor ); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - super.freeReferences(); - lhs.freeReferences(); - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffsetAndLineNumber(int, int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffsetAndLineNumber(int, int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() { - // TODO Auto-generated method stub - return lhs.getStartingOffset(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() { - // TODO Auto-generated method stub - return lhs.getEndingOffset(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - // TODO Auto-generated method stub - return lhs.getStartingLine(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - // TODO Auto-generated method stub - return lhs.getEndingLine(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - // TODO Auto-generated method stub - return lhs.getFilename(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryIdExpression.java deleted file mode 100644 index dc37063ad0f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryIdExpression.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -/* - * Created on Jun 7, 2004 - */ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; - -/** - * @author aniefer - */ -public class ASTUnaryIdExpression extends ASTIdExpression { - private final IASTExpression lhs; - - /** - * @param kind - * @param references - * @param idExpression - */ - public ASTUnaryIdExpression(Kind kind, List references, IASTExpression lhs, ITokenDuple idExpression) { - super(kind, references, idExpression); - this.lhs = lhs; - } - - public IASTExpression getLHSExpression(){ - return lhs; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#findOwnerExpressionForIDExpression(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) { - if( isIDExpressionForDuple( lhs, duple ) ) - return this; - ASTExpression result = recursiveFindExpressionForDuple(lhs, duple); - return result; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences() - */ - public void reconcileReferences() throws ASTNotImplementedException { - lhs.reconcileReferences(); - reconcileSubExpression((ASTExpression) lhs); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences() - */ - public void purgeReferences() throws ASTNotImplementedException { - lhs.purgeReferences(); - purgeSubExpression( (ASTExpression) lhs ); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks() - */ - protected void processCallbacks( ISourceElementRequestor requestor ) { - super.processCallbacks(requestor); - lhs.acceptElement( requestor ); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - super.freeReferences(); - lhs.freeReferences(); - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryTypeIdExpression.java deleted file mode 100644 index 0ab83498392..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUnaryTypeIdExpression.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; - -/** - * @author jcamelon - * - */ -public class ASTUnaryTypeIdExpression extends ASTUnaryExpression { - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - super.freeReferences(); - typeId.freeReferences(); - } - private final IASTTypeId typeId; - - /** - * @param kind - * @param references - * @param lhs - */ - public ASTUnaryTypeIdExpression(Kind kind, List references, IASTExpression lhs, IASTTypeId typeId) { - super(kind, references, lhs); - this.typeId = typeId; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId() - */ - public IASTTypeId getTypeId() { - return typeId; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTExpression#processCallbacks() - */ - protected void processCallbacks( ISourceElementRequestor requestor ) { - super.processCallbacks(requestor ); - typeId.acceptElement( requestor ); - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ASTUnaryExpression#findOwnerExpressionForIDExpression(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public ASTExpression findOwnerExpressionForIDExpression(ITokenDuple duple) { - if( typeId instanceof ASTTypeId && ((ASTTypeId)typeId).getTokenDuple() == duple ) - return this; - - return super.findOwnerExpressionForIDExpression(duple); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDeclaration.java deleted file mode 100644 index 8925cd2a6d9..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDeclaration.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ast.SymbolIterator; - -/** - * @author jcamelon - * - */ -public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration -{ - private final IASTScope ownerScope; - private final boolean isTypeName; - private final List declarations = new ArrayList(); - private List references; - private char[] name; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param filename - * @param nStart - * @param nEnd - * @param nLine - * - */ - public ASTUsingDeclaration( IASTScope ownerScope, char[] name, List declarations, boolean isTypeName, int startingOffset, int startingLine, int endingOffset, int endingLine, List references, char[] filename, int nStart, int nEnd, int nLine ) - { - this.ownerScope = ownerScope; - this.isTypeName = isTypeName; - this.name = name; - this.declarations.addAll( declarations ); - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setEndingOffsetAndLineNumber(endingOffset, endingLine); - this.references = references; - fn = filename; - setNameOffset(nStart); - setNameEndOffsetAndLineNumber( nEnd, nLine ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#isTypename() - */ - public boolean isTypename() - { - return isTypeName; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#usingTypeName() - */ - public String usingTypeName() - { - return String.valueOf(name); - } - public char[] usingTypeNameCharArray(){ - return name; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() - */ - public IASTScope getOwnerScope() - { - return ownerScope; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptUsingDeclaration( this ); - } - catch (Exception e) - { - /* do nothing */ - } - Parser.processReferences(references, requestor); - references = null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#getUsingType() - */ - public Iterator getUsingTypes() - { - return new SymbolIterator( declarations.iterator() ); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - private int nameEndOffset; - private int nameStartOffset; - private int nameLine; - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() { - return new String( name ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return name; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() { - return nameStartOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() { - return nameEndOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffsetAndLineNumber(int, int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) { - nameLine = lineNumber; - nameEndOffset = offset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLine; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDirective.java deleted file mode 100644 index a507c4490bd..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDirective.java +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IUsingDirectiveSymbol; - -/** - * @author jcamelon - * - */ -public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUsingDirective -{ - private final IUsingDirectiveSymbol using; - private List references; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param namespaceDefinition - * @param startingOffset - * @param endingOffset - * @param filename - * @param nStart - * @param nEnd - * @param nLine - */ - //public ASTUsingDirective(IContainerSymbol ownerSymbol, IASTNamespaceDefinition namespaceDefinition, int startingOffset, int endingOffset, List references ) - public ASTUsingDirective(IContainerSymbol ownerSymbol, IUsingDirectiveSymbol usingDirective, int startingOffset, int startingLine, int endingOffset, int endingLine, List references, char[] filename, int nStart, int nEnd, int nLine ) - { - super( ownerSymbol ); - //namespace = namespaceDefinition; - using = usingDirective; - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setEndingOffsetAndLineNumber(endingOffset, endingLine); - this.references = references; - fn = filename; - setNameOffset( nStart ); - setNameEndOffsetAndLineNumber( nEnd, nLine ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTUsingDirective#getNamespaceName() - */ - public String getNamespaceName() - { - IASTNamespaceDefinition namespace = getNamespaceDefinition(); - String [] fqn = namespace.getFullyQualifiedName(); - StringBuffer buffer = new StringBuffer(); - for( int i = 0; i < fqn.length; ++i ) - { - buffer.append( fqn[ i ] ); - if( i + 1 != fqn.length ) - buffer.append( "::"); //$NON-NLS-1$ - } - return buffer.toString(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptUsingDirective( this ); - } - catch (Exception e) - { - /* do nothing */ - } - Parser.processReferences(references, requestor); - references = null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTUsingDirective#getNamespaceDefinition() - */ - public IASTNamespaceDefinition getNamespaceDefinition() - { - IContainerSymbol namespaceSymbol = using.getNamespace(); - - return (IASTNamespaceDefinition)namespaceSymbol.getASTExtension().getPrimaryDeclaration(); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - private int nameEndOffset; - private int nameStartOffset; - private int nameLine; - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() { - return getNamespaceName(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return getName().toCharArray(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() { - return nameStartOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() { - return nameEndOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffsetAndLineNumber(int, int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) { - nameLine = lineNumber; - nameEndOffset = offset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLine; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java deleted file mode 100644 index 6ff9371ce60..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariable.java +++ /dev/null @@ -1,289 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.Parser; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; - -/** - * @author jcamelon - * - */ -public class ASTVariable extends ASTSymbol implements IASTVariable -{ - private final IASTExpression constructorExpression; - private final ASTQualifiedNamedElement qualifiedName; - private final IASTExpression bitfieldExpression; - private final IASTInitializerClause initializerClause; - private final IASTAbstractDeclaration abstractDeclaration; - protected List references; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param newSymbol - * @param abstractDeclaration - * @param initializerClause - * @param bitfieldExpression - * @param startingOffset - * @param nameOffset - * @param references - * @param filename - */ - public ASTVariable(ISymbol newSymbol, IASTAbstractDeclaration abstractDeclaration, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, List references, IASTExpression constructorExpression, boolean previouslyDeclared, char[] filename ) - { - super( newSymbol ); - this.abstractDeclaration = abstractDeclaration; - this.initializerClause = initializerClause; - this.bitfieldExpression = bitfieldExpression; - this.constructorExpression = constructorExpression; - setStartingOffsetAndLineNumber( startingOffset, startingLine ); - setNameOffset( nameOffset ); - setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); - this.references = references; - qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), newSymbol.getName() ); - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isAuto() - */ - public boolean isAuto() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isAuto ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isRegister() - */ - public boolean isRegister() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isRegister); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isStatic() - */ - public boolean isStatic() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isStatic); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isExtern() - */ - public boolean isExtern() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isExtern ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isMutable() - */ - public boolean isMutable() - { - return symbol.getTypeInfo().checkBit( ITypeInfo.isMutable); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#getAbstractDeclaration() - */ - public IASTAbstractDeclaration getAbstractDeclaration() - { - return abstractDeclaration; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() - { - return String.valueOf(getSymbol().getName()); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#getInitializerClause() - */ - public IASTInitializerClause getInitializerClause() - { - return initializerClause; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isBitfield() - */ - public boolean isBitfield() - { - return ( bitfieldExpression != null ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#getBitfieldExpression() - */ - public IASTExpression getBitfieldExpression() - { - return bitfieldExpression; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedName.getFullyQualifiedName(); - } - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedName.getFullyQualifiedNameCharArrays(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() - */ - public IASTScope getOwnerScope() - { - return (IASTScope)getSymbol().getContainingSymbol().getASTExtension().getPrimaryDeclaration(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptVariable(this); - } - catch (Exception e) - { - /* do nothing */ - } - Parser.processReferences(references, requestor); - references = null; - if( initializerClause != null ) - initializerClause.acceptElement(requestor); - if( constructorExpression != null ) - constructorExpression.acceptElement(requestor); - if( getAbstractDeclaration() != null ) - getAbstractDeclaration().acceptElement(requestor); - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#getConstructorExpression() - */ - public IASTExpression getConstructorExpression() - { - return constructorExpression; - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public final int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public final int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public final void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public final int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public final void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return getSymbol().getName(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariableReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariableReference.java deleted file mode 100644 index a0bcd51caf2..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTVariableReference.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTReference; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTVariableReference; - - -public class ASTVariableReference extends ASTReference - implements - IASTReference, - IASTVariableReference { - - private IASTVariable referencedElement; - /** - * @param offset - * @param variable - */ - public ASTVariableReference(int offset, IASTVariable variable) { - super(offset); - referencedElement = variable; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#initialize(int) - */ - public void initialize(int o, ISourceElementCallbackDelegate var ) { - super.initialize(o); - referencedElement = (IASTVariable) var; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache.ASTReference#reset() - */ - public void reset() { - super.resetOffset(); - referencedElement = null; - } - /** - * - */ - public ASTVariableReference() { - super(0); - referencedElement = null; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTReference#getReferencedElement() - */ - public ISourceElementCallbackDelegate getReferencedElement() { - return referencedElement; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - try { - requestor.acceptVariableReference(this); - } catch (Exception e) { - /* do nothing */ - } - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java deleted file mode 100644 index 4aa4c12a059..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ /dev/null @@ -1,4142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.parser.Enum; -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.ASTSemanticException; -import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTConstructorMemberInitializer; -import org.eclipse.cdt.core.parser.ast.IASTDesignator; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTFactory; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTReference; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTemplate; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType; -import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; -import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind; -import org.eclipse.cdt.core.parser.extension.IASTFactoryExtension; -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.internal.core.parser.ast.ASTAbstractDeclaration; -import org.eclipse.cdt.internal.core.parser.ast.ASTDesignator; -import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory; -import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; -import org.eclipse.cdt.internal.core.parser.pst.ExtensibleSymbolExtension; -import org.eclipse.cdt.internal.core.parser.pst.ForewardDeclaredSymbolExtension; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IDeferredTemplateInstance; -import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner; -import org.eclipse.cdt.internal.core.parser.pst.ITemplateFactory; -import org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.pst.IUsingDeclarationSymbol; -import org.eclipse.cdt.internal.core.parser.pst.IUsingDirectiveSymbol; -import org.eclipse.cdt.internal.core.parser.pst.NamespaceSymbolExtension; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableError; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; -import org.eclipse.cdt.internal.core.parser.pst.StandardSymbolExtension; -import org.eclipse.cdt.internal.core.parser.pst.TemplateSymbolExtension; -import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider; -import org.eclipse.cdt.internal.core.parser.pst.UndefinedTemplateSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension.ExtensionException; -import org.eclipse.cdt.internal.core.parser.token.TokenFactory; -import org.eclipse.cdt.internal.core.parser.util.TraceUtil; - -/** - * @author jcamelon - * - * The CompleteParseASTFactory class creates a complete AST for a given parsed - * code. - * - */ -public class CompleteParseASTFactory extends BaseASTFactory implements - IASTFactory { - protected static final char[] THIS = new char[] { - 't', 'h', 'i', 's' }; - private final static ITypeInfo.OperatorExpression SUBSCRIPT; - private final static IProblemFactory problemFactory = new ASTProblemFactory(); - private final ParserMode mode; - - private static final int BUILTIN_TYPE_SIZE = 64; - private final CharArrayObjectMap typeIdCache = new CharArrayObjectMap( - BUILTIN_TYPE_SIZE); - private final CharArrayObjectMap simpleTypeSpecCache = new CharArrayObjectMap( - BUILTIN_TYPE_SIZE); - private static final int DEFAULT_QUALIFIEDNAME_REFERENCE_SIZE = 4; - private char[] filename; - private int problemStartOffset = -1; - private int problemEndOffset = -1; - private int problemLineNumber = -1; - - static { - SUBSCRIPT = ITypeInfo.OperatorExpression.subscript; - } - - static private class LookupType extends Enum { - public static final LookupType QUALIFIED = new LookupType(1); - public static final LookupType UNQUALIFIED = new LookupType(2); - public static final LookupType FORDEFINITION = new LookupType(3); - public static final LookupType FORFRIENDSHIP = new LookupType(4); - public static final LookupType FORPARENTSCOPE = new LookupType(5); - - private LookupType(int constant) { - super(constant); - } - } - - public CompleteParseASTFactory(ParserLanguage language, ParserMode mode, - IASTFactoryExtension extension) { - super(extension); - pst = new ParserSymbolTable(language, mode); - this.mode = mode; - filename = EMPTY_STRING; - } - - /* - * Adds a reference to a reference list Overrides an existing reference if it - * has the same name and offset - */ - protected void addReference(List references, IASTReference reference) { - if (reference == null) - return; - if (references == null) - return; - - int size = references.size(); - for (int i = 0; i < size; i++) { - IASTReference ref = (IASTReference) references.get(i); - if (ref != null) { - if ((CharArrayUtils.equals(ref.getNameCharArray(), reference - .getNameCharArray())) - && (ref.getOffset() == reference.getOffset())) { - references.remove(i--); - size--; - break; - } - } - } - references.add(reference); - } - - protected void addTemplateIdReferences(List references, List templateArgs) { - if (templateArgs == null) - return; - - int numArgs = templateArgs.size(); - for (int i = 0; i < numArgs; i++) { - ASTExpression exp = (ASTExpression) templateArgs.get(i); - List refs = null; - if (exp.getExpressionKind() == IASTExpression.Kind.POSTFIX_TYPEID_TYPEID) - refs = ((ASTTypeId) exp.getTypeId()).getReferences(); - else - refs = exp.getReferences(); - int numRefs = refs.size(); - for (int j = 0; j < numRefs; j++) { - IASTReference r = (IASTReference) refs.get(j); - addReference(references, r); - } - } - } - - /* - * Test if the provided list is a valid parameter list Parameters are list of - * TypeInfos - */ - protected boolean validParameterList(List parameters) { - int size = parameters.size(); - for (int i = 0; i < size; i++) { - ITypeInfo info = (ITypeInfo) parameters.get(i); - if (info != null) { - if ((info.getType() == ITypeInfo.t_type) - && (info.getTypeSymbol() == null)) - return false; - } else - return false; - } - return true; - } - - private ISymbol lookupElement(IContainerSymbol startingScope, char[] name, - ITypeInfo.eType type, List parameters, LookupType lookupType) - throws ASTSemanticException { - return lookupElement(startingScope, name, type, parameters, null, - lookupType); - } - - private ISymbol lookupElement(IContainerSymbol startingScope, char[] name, - ITypeInfo.eType type, List parameters, List arguments, - LookupType lookupType) throws ASTSemanticException { - ISymbol result = null; - if (startingScope == null) - return null; - try { - if ((type == ITypeInfo.t_function) - || (type == ITypeInfo.t_constructor)) { - // looking for a function - if (validParameterList(parameters)) - if (type == ITypeInfo.t_constructor) { - IDerivableContainerSymbol startingDerivableScope = (IDerivableContainerSymbol) startingScope; - result = startingDerivableScope.lookupConstructor(parameters); - } else { - if (arguments != null) - result = startingScope.lookupFunctionTemplateId(name, - parameters, arguments, - (lookupType == LookupType.FORDEFINITION)); - else if (lookupType == LookupType.QUALIFIED) - result = startingScope.qualifiedFunctionLookup(name, - parameters); - else if (lookupType == LookupType.UNQUALIFIED - || lookupType == LookupType.FORPARENTSCOPE) - result = startingScope.unqualifiedFunctionLookup(name, - parameters); - else if (lookupType == LookupType.FORDEFINITION) - result = startingScope.lookupMethodForDefinition(name, - parameters); - else if (lookupType == LookupType.FORFRIENDSHIP) { - result = ((IDerivableContainerSymbol) startingScope) - .lookupFunctionForFriendship(name, parameters); - } - } - else - result = null; - } else { - // looking for something else - if (arguments != null) - result = startingScope.lookupTemplateId(name, arguments); - else if (lookupType == LookupType.QUALIFIED) - result = startingScope.qualifiedLookup(name, type); - else if (lookupType == LookupType.UNQUALIFIED - || lookupType == LookupType.FORPARENTSCOPE) - result = startingScope.elaboratedLookup(type, name); - else if (lookupType == LookupType.FORDEFINITION) - result = startingScope.lookupMemberForDefinition(name); - else if (lookupType == LookupType.FORFRIENDSHIP) - result = ((IDerivableContainerSymbol) startingScope) - .lookupForFriendship(name); - } - } catch (ParserSymbolTableException e) { - if (e.reason != ParserSymbolTableException.r_UnableToResolveFunction) - handleProblem(e.createProblemID(), name); - } catch (ParserSymbolTableError e) { - handleProblem(IProblem.INTERNAL_RELATED, name); - } - return result; - } - - protected ISymbol lookupQualifiedName(IContainerSymbol startingScope, - char[] name, List references, boolean throwOnError, LookupType lookup) - throws ASTSemanticException { - return lookupQualifiedName(startingScope, name, ITypeInfo.t_any, null, 0, - references, throwOnError, lookup); - } - - protected ISymbol lookupQualifiedName(IContainerSymbol startingScope, - char[] name, ITypeInfo.eType type, List parameters, int offset, - List references, boolean throwOnError, LookupType lookup) - throws ASTSemanticException { - ISymbol result = null; - if (name == null && throwOnError) - handleProblem(IProblem.SEMANTIC_NAME_NOT_PROVIDED, null); - else if (name == null) - return null; - - try { - result = lookupElement(startingScope, name, type, parameters, lookup); - if (result != null) - addReference(references, createReference(result, name, offset)); - else if (throwOnError) - handleProblem(IProblem.SEMANTIC_NAME_NOT_FOUND, name); - } catch (ASTSemanticException e) { - if (throwOnError) - throw new ASTSemanticException(e); - - return null; - } - return result; - } - - protected ISymbol lookupQualifiedName(IContainerSymbol startingScope, - ITokenDuple name, List references, boolean throwOnError) - throws ASTSemanticException { - return lookupQualifiedName(startingScope, name, references, throwOnError, - LookupType.UNQUALIFIED); - } - - protected ISymbol lookupQualifiedName(IContainerSymbol startingScope, - ITokenDuple name, List references, boolean throwOnError, - LookupType lookup) throws ASTSemanticException { - return lookupQualifiedName(startingScope, name, ITypeInfo.t_any, null, - references, throwOnError, lookup); - } - - protected ISymbol lookupQualifiedName(IContainerSymbol startingScope, - ITokenDuple name, ITypeInfo.eType type, List parameters, - List references, boolean throwOnError) throws ASTSemanticException { - return lookupQualifiedName(startingScope, name, type, parameters, - references, throwOnError, LookupType.UNQUALIFIED); - } - - protected ISymbol lookupQualifiedName(IContainerSymbol startingScope, - ITokenDuple name, ITypeInfo.eType type, List parameters, - List references, boolean throwOnError, LookupType lookup) - throws ASTSemanticException { - setProblemInfo(name); - ISymbol result = null; - if (name == null && throwOnError) - handleProblem(IProblem.SEMANTIC_NAME_NOT_PROVIDED, null); - else if (name == null) - return null; - - List[] templateArgLists = name.getTemplateIdArgLists(); - List args = null; - int idx = 0; - char[] image = null; - switch (name.getSegmentCount()) { - case 0: - if (throwOnError) - handleProblem(IProblem.SEMANTIC_NAME_NOT_PROVIDED, null); - else - return null; - case 1: - image = name.extractNameFromTemplateId(); - args = (templateArgLists != null) ? getTemplateArgList(templateArgLists[0]) - : null; - try { - result = lookupElement(startingScope, image, type, parameters, - args, lookup); - } catch (ASTSemanticException e) { - if (e.getProblem() == null - || e.getProblem().getSourceLineNumber() == -1) { - handleProblem(e.getProblem().getID(), image, name - .getStartOffset(), name.getEndOffset(), name - .getLineNumber(), e.getProblem().isError()); - } else { - throw e; - } - } - - if (result != null) { - if (lookup == LookupType.FORPARENTSCOPE - && startingScope instanceof ITemplateFactory) { - if (args != null) - ((ITemplateFactory) startingScope).pushTemplateId(result, - args); - else - ((ITemplateFactory) startingScope).pushSymbol(result); - } - if (references != null) - addReference(references, createReference(result, image, name - .getStartOffset())); - if (args != null && references != null) { - addTemplateIdReferences(references, templateArgLists[0]); - name.freeReferences(); - } - } else { - if (startingScope.getASTExtension() != null - && startingScope.getASTExtension().getPrimaryDeclaration() instanceof IASTCodeScope) { - if (((IASTCodeScope) startingScope.getASTExtension() - .getPrimaryDeclaration()).getContainingFunction() instanceof IASTMethod) { - IASTClassSpecifier classSpecifier = ((IASTMethod) ((IASTCodeScope) startingScope - .getASTExtension().getPrimaryDeclaration()) - .getContainingFunction()).getOwnerClassSpecifier(); - if (classSpecifier != null) - ((ASTClassSpecifier) classSpecifier) - .addUnresolvedReference(new UnresolvedReferenceDuple( - startingScope, name)); - break; - } - } - if (throwOnError) - handleProblem(IProblem.SEMANTIC_NAME_NOT_FOUND, image, name - .getStartOffset(), name.getEndOffset(), name - .getLineNumber(), true); - return null; - } - break; - default: - IToken t = null; - IToken last = name.getLastToken(); - result = startingScope; - if (name.getFirstToken().getType() == IToken.tCOLONCOLON) - result = pst.getCompilationUnit(); - - for (;;) { - if (t == last) - break; - t = (t != null) ? t.getNext() : name.getFirstToken(); - if (t.getType() == IToken.tCOLONCOLON) { - idx++; - continue; - } else if (t.getType() == IToken.t_template) { - continue; - } - if (t.isPointer()) - break; - - image = t.getCharImage(); - int offset = t.getOffset(); - - if (templateArgLists != null && templateArgLists[idx] != null) { - if (t != last && t.getNext().getType() == IToken.tLT) - t = TokenFactory.consumeTemplateIdArguments(t.getNext(), - last); - } - - try { - while (!(result instanceof IContainerSymbol)) { - if (result.getTypeInfo().checkBit(ITypeInfo.isTypedef)) { - result = result.getTypeSymbol(); - } else if (result instanceof IDeferredTemplateInstance) { - result = ((IDeferredTemplateInstance) result) - .getTemplate().getTemplatedSymbol(); - } else { - if (throwOnError) - handleProblem(IProblem.SEMANTIC_NAME_NOT_PROVIDED, - image, t.getOffset(), t.getEndOffset(), t - .getLineNumber(), true); - else - return null; - } - } - args = (templateArgLists != null) ? getTemplateArgList(templateArgLists[idx]) - : null; - if (t == last) - result = lookupElement((IContainerSymbol) result, image, - type, parameters, args, - (lookup == LookupType.FORDEFINITION) ? lookup - : LookupType.QUALIFIED); - else if (templateArgLists != null - && templateArgLists[idx] != null) - result = ((IContainerSymbol) result).lookupTemplateId( - image, args); - else - result = ((IContainerSymbol) result) - .lookupNestedNameSpecifier(image); - - if (result != null) { - if (lookup == LookupType.FORPARENTSCOPE - && startingScope instanceof ITemplateFactory) { - if (templateArgLists != null - && templateArgLists[idx] != null) - ((ITemplateFactory) startingScope).pushTemplateId( - result, args); - else - ((ITemplateFactory) startingScope) - .pushSymbol(result); - } - if (references != null) - addReference(references, createReference(result, image, - offset)); - if (references != null && templateArgLists != null - && templateArgLists[idx] != null) { - addTemplateIdReferences(references, - templateArgLists[idx]); - name.freeReferences(); - } - } else - break; - } catch (ParserSymbolTableException pste) { - if (throwOnError) - handleProblem(pste.createProblemID(), image); - return null; - } catch (ParserSymbolTableError e) { - if (throwOnError) - handleProblem(IProblem.INTERNAL_RELATED, image); - return null; - } - } - } - return result; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createUsingDirective(org.eclipse.cdt.core.parser.ast.IASTScope, - * org.eclipse.cdt.core.parser.ITokenDuple, int, int) - */ - public IASTUsingDirective createUsingDirective(IASTScope scope, - ITokenDuple duple, int startingOffset, int startingLine, - int endingOffset, int endingLine) throws ASTSemanticException { - setProblemInfo(duple); - List references = new ArrayList(); - ISymbol symbol = lookupQualifiedName(scopeToSymbol(scope), duple, - references, true); - - IUsingDirectiveSymbol usingDirective = null; - if (symbol != null) - try { - usingDirective = ((ASTScope) scope).getContainerSymbol() - .addUsingDirective((IContainerSymbol) symbol); - } catch (ParserSymbolTableException pste) { - handleProblem(pste.createProblemID(), duple.toCharArray(), - startingOffset, endingOffset, startingLine, true); - } - - ASTUsingDirective using = new ASTUsingDirective(scopeToSymbol(scope), - usingDirective, startingOffset, startingLine, endingOffset, - endingLine, references, filename, duple.getStartOffset(), duple - .getEndOffset(), duple.getLineNumber()); - attachSymbolExtension(usingDirective, using); - - return using; - } - - protected IContainerSymbol getScopeToSearchUpon(IASTScope currentScope, - IToken firstToken) { - if (firstToken.getType() == IToken.tCOLONCOLON) { - return pst.getCompilationUnit(); - } - return scopeToSymbol(currentScope); - } - - protected IContainerSymbol scopeToSymbol(IASTScope currentScope) { - if (currentScope instanceof ASTScope) - return ((ASTScope) currentScope).getContainerSymbol(); - else if (currentScope instanceof ASTTemplateDeclaration) - return ((ASTTemplateDeclaration) currentScope).getContainerSymbol(); - else if (currentScope instanceof ASTTemplateInstantiation) - return ((ASTTemplateInstantiation) currentScope).getContainerSymbol(); - else - return scopeToSymbol(((ASTAnonymousDeclaration) currentScope) - .getOwnerScope()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createUsingDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope, - * boolean, org.eclipse.cdt.core.parser.ITokenDuple, int, int) - */ - public IASTUsingDeclaration createUsingDeclaration(IASTScope scope, - boolean isTypeName, ITokenDuple name, int startingOffset, - int startingLine, int endingOffset, int endingLine) - throws ASTSemanticException { - setProblemInfo(name); - List references = new ArrayList(); - - IUsingDeclarationSymbol endResult = null; - - if (name.getSegmentCount() > 1) { - ITokenDuple duple = name.getLeadingSegments(); - IContainerSymbol containerSymbol = null; - if (duple == null) { - //null leading segment means globally qualified - containerSymbol = scopeToSymbol(scope).getSymbolTable() - .getCompilationUnit(); - } else { - ISymbol symbol = lookupQualifiedName(scopeToSymbol(scope), duple, - references, true); - - if (symbol instanceof IContainerSymbol) - containerSymbol = (IContainerSymbol) symbol; - else if (symbol instanceof IDeferredTemplateInstance) - containerSymbol = ((IDeferredTemplateInstance) symbol) - .getTemplate().getTemplatedSymbol(); - } - try { - endResult = scopeToSymbol(scope).addUsingDeclaration( - name.getLastToken().getCharImage(), containerSymbol); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), name.getLastToken() - .getCharImage(), startingOffset, endingOffset, startingLine, - true); - } - } else - try { - endResult = scopeToSymbol(scope).addUsingDeclaration( - name.getLastToken().getCharImage()); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), name.getLastToken() - .getCharImage(), startingOffset, endingOffset, startingLine, - true); - } - - if (endResult != null) { - List refs = endResult.getReferencedSymbols(); - int numRefs = refs.size(); - for (int i = 0; i < numRefs; i++) - addReference(references, createReference((ISymbol) refs.get(i), - name.getLastToken().getCharImage(), name.getLastToken() - .getOffset())); - - } - ASTUsingDeclaration using = new ASTUsingDeclaration(scope, name - .getLastToken().getCharImage(), endResult.getReferencedSymbols(), - isTypeName, startingOffset, startingLine, endingOffset, endingLine, - references, filename, name.getStartOffset(), name.getEndOffset(), - name.getLineNumber()); - attachSymbolExtension(endResult, using); - - return using; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createASMDefinition(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.lang.String, int, int) - */ - public IASTASMDefinition createASMDefinition(IASTScope scope, - char[] assembly, int startingOffset, int startingLine, - int endingOffset, int endingLine, char[] fn) { - return new ASTASMDefinition(scopeToSymbol(scope), assembly, - startingOffset, startingLine, endingOffset, endingLine, fn); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNamespaceDefinition(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.lang.String, int, int) - */ - public IASTNamespaceDefinition createNamespaceDefinition(IASTScope scope, - char[] identifier, int startingOffset, int startingLine, - int nameOffset, int nameEndOffset, int nameLineNumber, char[] fn) - throws ASTSemanticException { - //TODO - set filename - IContainerSymbol pstScope = scopeToSymbol(scope); - ISymbol namespaceSymbol = null; - - if (!identifier.equals(EMPTY_STRING)) { - try { - namespaceSymbol = pstScope.qualifiedLookup(identifier); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), identifier, nameOffset, - nameEndOffset, nameLineNumber, true); - } - } - - if (namespaceSymbol != null) { - if (namespaceSymbol.getType() != ITypeInfo.t_namespace) - handleProblem(IProblem.SEMANTIC_INVALID_OVERLOAD, identifier, - nameOffset, nameEndOffset, nameLineNumber, true); - } else { - namespaceSymbol = pst.newContainerSymbol(identifier, - ITypeInfo.t_namespace); - if (identifier.equals(EMPTY_STRING)) - namespaceSymbol.setContainingSymbol(pstScope); - else { - - try { - pstScope.addSymbol(namespaceSymbol); - } catch (ParserSymbolTableException e1) { - // assert false : e1; - } - } - } - - ASTNamespaceDefinition namespaceDef = new ASTNamespaceDefinition( - namespaceSymbol, startingOffset, startingLine, nameOffset, - nameEndOffset, nameLineNumber, fn); - attachSymbolExtension(namespaceSymbol, namespaceDef, true); - return namespaceDef; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createCompilationUnit() - */ - public IASTCompilationUnit createCompilationUnit() { - ISymbol symbol = pst.getCompilationUnit(); - ASTCompilationUnit compilationUnit = new ASTCompilationUnit(symbol); - attachSymbolExtension(symbol, compilationUnit, true); - extension.initialize(this, compilationUnit); - return compilationUnit; - } - - protected void attachSymbolExtension(IExtensibleSymbol symbol, - ASTNode astNode) { - ISymbolASTExtension symbolExtension = new ExtensibleSymbolExtension( - symbol, astNode); - symbol.setASTExtension(symbolExtension); - } - - protected void attachSymbolExtension(ISymbol symbol, ASTSymbol astSymbol, - boolean asDefinition) { - ISymbolASTExtension symbolExtension = symbol.getASTExtension(); - if (symbolExtension == null) { - if (astSymbol instanceof IASTNamespaceDefinition) - symbolExtension = new NamespaceSymbolExtension(symbol, astSymbol); - else if (astSymbol instanceof IASTFunction - || astSymbol instanceof IASTMethod - || astSymbol instanceof IASTEnumerationSpecifier - || astSymbol instanceof IASTClassSpecifier - || astSymbol instanceof IASTElaboratedTypeSpecifier) { - symbolExtension = new ForewardDeclaredSymbolExtension(symbol, - astSymbol); - } else if (astSymbol instanceof IASTTemplateDeclaration) { - symbolExtension = new TemplateSymbolExtension(symbol, astSymbol); - } else { - symbolExtension = new StandardSymbolExtension(symbol, astSymbol); - } - symbol.setASTExtension(symbolExtension); - } else { - if (asDefinition) - try { - symbolExtension.addDefinition(astSymbol); - } catch (ExtensionException e) { - // assert false : ExtensionException.class; - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createLinkageSpecification(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.lang.String, int) - */ - public IASTLinkageSpecification createLinkageSpecification(IASTScope scope, - char[] spec, int startingOffset, int startingLine, char[] fn) { - return new ASTLinkageSpecification(scopeToSymbol(scope), spec, - startingOffset, startingLine, fn); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.lang.String, org.eclipse.cdt.core.parser.ast.ASTClassKind, - * org.eclipse.cdt.core.parser.ast.IASTClassSpecifier.ClassNameType, - * org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, - * org.eclipse.cdt.core.parser.ast.IASTTemplate, int, int) - */ - public IASTClassSpecifier createClassSpecifier(IASTScope scope, - ITokenDuple name, ASTClassKind kind, ClassNameType type, - ASTAccessVisibility access, int startingOffset, int startingLine, - int nameOffset, int nameEndOffset, int nameLine, char[] fn) - throws ASTSemanticException { - setFilename(fn); - IContainerSymbol currentScopeSymbol = scopeToSymbol(scope); - ITypeInfo.eType pstType = classKindToTypeInfo(kind); - List references = new ArrayList(); - - char[] newSymbolName = EMPTY_STRING; - List templateIdArgList = null; - boolean isTemplateId = false; - - if (name != null) { - IToken nameToken = null; - if (name.getSegmentCount() != 1) // qualified name - { - ITokenDuple containerSymbolName = name.getLeadingSegments(); - ISymbol temp = lookupQualifiedName(currentScopeSymbol, - containerSymbolName, references, true); - if (temp instanceof IDeferredTemplateInstance) - currentScopeSymbol = ((IDeferredTemplateInstance) temp) - .getTemplate().getTemplatedSymbol(); - else - currentScopeSymbol = (IContainerSymbol) temp; - if (currentScopeSymbol == null) - handleProblem(IProblem.SEMANTIC_NAME_NOT_FOUND, - containerSymbolName.toCharArray(), containerSymbolName - .getFirstToken().getOffset(), containerSymbolName - .getLastToken().getEndOffset(), containerSymbolName - .getLastToken().getLineNumber(), true); - - nameToken = name.getLastSegment().getFirstToken(); - } else { - nameToken = name.getFirstToken(); - } - //template-id - List[] array = name.getTemplateIdArgLists(); - if (array != null) { - templateIdArgList = array[array.length - 1]; - isTemplateId = (templateIdArgList != null); - } - - newSymbolName = nameToken.getCharImage(); - } - ISymbol classSymbol = null; - if (!CharArrayUtils.equals(newSymbolName, EMPTY_STRING) && !isTemplateId) { - try { - classSymbol = currentScopeSymbol.lookupMemberForDefinition( - newSymbolName, pstType); - } catch (ParserSymbolTableException e) { - handleProblem(IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED, name - .toCharArray(), nameOffset, nameEndOffset, nameLine, true); - } - - if (classSymbol != null && !classSymbol.isForwardDeclaration()) - handleProblem(IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED, - newSymbolName, nameOffset, nameEndOffset, nameLine, true); - - if (classSymbol != null && classSymbol.getType() != pstType) { - boolean isError = true; - if (classSymbol.isType(ITypeInfo.t_class, ITypeInfo.t_union)) { - if ((pstType == ITypeInfo.t_class - || pstType == ITypeInfo.t_struct || pstType == ITypeInfo.t_union)) - isError = false; - - } - handleProblem(IProblem.SEMANTIC_INVALID_OVERLOAD, newSymbolName, - nameOffset, nameEndOffset, nameLine, isError); - } - } - - IDerivableContainerSymbol newSymbol = pst.newDerivableContainerSymbol( - newSymbolName, pstType); - - if (classSymbol != null) - classSymbol.setForwardSymbol(newSymbol); - - List args = null; - if (isTemplateId) { - args = getTemplateArgList(templateIdArgList); - } - try { - if (!isTemplateId) - currentScopeSymbol.addSymbol(newSymbol); - else - currentScopeSymbol.addTemplateId(newSymbol, args); - } catch (ParserSymbolTableException e2) { - if (e2.reason == ParserSymbolTableException.r_InvalidOverload) - handleProblem(e2.createProblemID(), newSymbolName, nameOffset, - nameEndOffset, nameLine, false); // to fix 65569 for this - // patch - else - handleProblem(e2.createProblemID(), newSymbolName, nameOffset, - nameEndOffset, nameLine, true); - } - - if (name != null && name.getTemplateIdArgLists() != null) { - for (int i = 0; i < name.getTemplateIdArgLists().length; ++i) - addTemplateIdReferences(references, name.getTemplateIdArgLists()[i]); - name.freeReferences(); - } - ASTClassSpecifier classSpecifier = new ASTClassSpecifier(newSymbol, kind, - type, access, startingOffset, startingLine, nameOffset, - nameEndOffset, nameLine, references, filename); - attachSymbolExtension(newSymbol, classSpecifier, true); - - return classSpecifier; - } - - private List getTemplateArgList(List args) { - if (args == null) - return null; - - int size = args.size(); - List list = new ArrayList(size); - - ASTExpression exp; - for (int i = 0; i < size; i++) { - exp = (ASTExpression) args.get(i); - - ITypeInfo info = exp.getResultType().getResult(); - - list.add(info); - } - - return list; - } - - protected void handleProblem(int id, char[] attribute) - throws ASTSemanticException { - handleProblem(null, id, attribute, problemStartOffset, problemEndOffset, - problemLineNumber, true); - } - - protected void handleProblem(IASTScope scope, int id, char[] attribute) - throws ASTSemanticException { - handleProblem(scope, id, attribute, problemStartOffset, problemEndOffset, - problemLineNumber, true); - } - - protected void handleProblem(int id, char[] attribute, int startOffset, - int endOffset, int lineNumber, boolean isError) - throws ASTSemanticException { - handleProblem(null, id, attribute, startOffset, endOffset, lineNumber, - isError); - } - - /** - * @param id - * @param attribute - * @param startOffset - * @param endOffset - * @param lineNumber - * @param isError - * TODO - * @param filename - * @throws ASTSemanticException - */ - protected void handleProblem(IASTScope scope, int id, char[] attribute, - int startOffset, int endOffset, int lineNumber, boolean isError) - throws ASTSemanticException { - IProblem p = problemFactory.createProblem(id, startOffset, endOffset, - lineNumber, filename, attribute, !isError, isError); - - TraceUtil.outputTrace(logService, - "CompleteParseASTFactory - IProblem : ", p); //$NON-NLS-1$ - - if (shouldThrowException(scope, id, !isError)) - throw new ASTSemanticException(p); - } - - protected boolean shouldThrowException(IASTScope scope, int id, - boolean isWarning) { - if (isWarning) - return false; - if (scope != null) { - IContainerSymbol symbol = scopeToSymbol(scope); - if (symbol.isTemplateMember()) { - if (id == IProblem.SEMANTIC_INVALID_CONVERSION_TYPE - || id == IProblem.SEMANTIC_INVALID_TYPE) { - return false; - } - } - } - return true; - } - - protected ITypeInfo.eType classKindToTypeInfo(ASTClassKind kind) { - ITypeInfo.eType pstType = null; - - if (kind == ASTClassKind.CLASS) - pstType = ITypeInfo.t_class; - else if (kind == ASTClassKind.STRUCT) - pstType = ITypeInfo.t_struct; - else if (kind == ASTClassKind.UNION) - pstType = ITypeInfo.t_union; - else if (kind == ASTClassKind.ENUM) - pstType = ITypeInfo.t_enumeration; - // else - // assert false : kind ; - return pstType; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#addBaseSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier, - * boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, - * java.lang.String) - */ - public void addBaseSpecifier(IASTClassSpecifier astClassSpec, - boolean isVirtual, ASTAccessVisibility visibility, - ITokenDuple parentClassName) throws ASTSemanticException { - setProblemInfo(parentClassName); - IDerivableContainerSymbol classSymbol = (IDerivableContainerSymbol) scopeToSymbol(astClassSpec); - List references = new ArrayList(); - - if (parentClassName == null || parentClassName.getFirstToken() == null) - handleProblem(IProblem.SEMANTIC_NAME_NOT_PROVIDED, null); - - //Its possible that the parent is not an IContainerSymbol if its a - // template parameter or some kinds of template instances - ISymbol symbol = lookupQualifiedName(classSymbol, parentClassName, - references, true); - - if (symbol == null) - handleProblem(IProblem.SEMANTIC_NAME_NOT_FOUND, parentClassName - .toCharArray(), parentClassName.getStartOffset(), - parentClassName.getEndOffset(), parentClassName.getLineNumber(), - true); - if (symbol instanceof ITemplateSymbol - && !(symbol instanceof UndefinedTemplateSymbol)) - handleProblem(IProblem.SEMANTIC_INVALID_TEMPLATE_ARGUMENT, - parentClassName.toCharArray(), parentClassName.getStartOffset(), - parentClassName.getEndOffset(), parentClassName.getLineNumber(), - true); - - List[] templateArgumentLists = parentClassName.getTemplateIdArgLists(); - if (templateArgumentLists != null) { - for (int i = 0; i < templateArgumentLists.length; ++i) - addTemplateIdReferences(references, templateArgumentLists[i]); - } - parentClassName.freeReferences(); - classSymbol.addParent(symbol, isVirtual, visibility, parentClassName - .getFirstToken().getOffset(), references); - - } - - /** - * @param symbol - * @param referenceElementName - * @return - */ - protected IASTReference createReference(ISymbol symbol, - char[] referenceElementName, int offset) throws ASTSemanticException { - if (mode != ParserMode.COMPLETE_PARSE) - return null; - //referenced symbol doesn't have an attached AST node, could happen say - // for the copy constructor added - //by the symbol table. - if (symbol.getASTExtension() == null) - return null; - - Iterator i = symbol.getASTExtension().getAllDefinitions(); - ASTSymbol declaration = i.hasNext() ? (ASTSymbol) i.next() : null; - ASTSymbol definition = i.hasNext() ? (ASTSymbol) i.next() : null; - - // assert (symbol != null ) : "createReference cannot be called on null - // symbol "; - if (symbol.getTypeInfo().checkBit(ITypeInfo.isTypedef) - || symbol.getASTExtension().getPrimaryDeclaration() instanceof IASTTypedefDeclaration) - return new ASTTypedefReference(offset, - (IASTTypedefDeclaration) declaration); - else if (symbol.getType() == ITypeInfo.t_namespace) { - if (declaration instanceof IASTNamespaceDefinition) - return new ASTNamespaceReference(offset, - (IASTNamespaceDefinition) declaration); - else if (declaration instanceof IASTNamespaceAlias) { - IASTNamespaceDefinition namespace = null; - try { - namespace = ((IASTNamespaceAlias) declaration).getNamespace(); - } catch (ASTNotImplementedException e) { - return null; - } - return new ASTNamespaceReference(offset, namespace); - } else - return null; - } else if (symbol.getType() == ITypeInfo.t_class - || symbol.getType() == ITypeInfo.t_struct - || symbol.getType() == ITypeInfo.t_union) - return new ASTClassReference(offset, (IASTTypeSpecifier) symbol - .getASTExtension().getPrimaryDeclaration()); - else if (symbol.getType() == ITypeInfo.t_enumeration) - return new ASTEnumerationReference(offset, - (IASTEnumerationSpecifier) symbol.getASTExtension() - .getPrimaryDeclaration()); - else if (symbol.getType() == ITypeInfo.t_enumerator) - return new ASTEnumeratorReference(offset, (IASTEnumerator) declaration); - else if ((symbol.getType() == ITypeInfo.t_function) - || (symbol.getType() == ITypeInfo.t_constructor)) { - ASTNode referenced = (definition != null) ? definition : declaration; - if (referenced instanceof IASTMethod) - - return new ASTMethodReference(offset, (IASTMethod) referenced); - return new ASTFunctionReference(offset, (IASTFunction) referenced); - } else if ((symbol.getType() == ITypeInfo.t_type) - || (symbol.getType() == ITypeInfo.t_bool) - || (symbol.getType() == ITypeInfo.t_char) - || (symbol.getType() == ITypeInfo.t_wchar_t) - || (symbol.getType() == ITypeInfo.t_int) - || (symbol.getType() == ITypeInfo.t_float) - || (symbol.getType() == ITypeInfo.t_double) - || (symbol.getType() == ITypeInfo.t_void) - || (symbol.getType() == ITypeInfo.t__Bool) - || (symbol.getType() == ITypeInfo.t_templateParameter)) - - { - if (symbol.getContainingSymbol().getType() == ITypeInfo.t_class - || symbol.getContainingSymbol().getType() == ITypeInfo.t_struct - || symbol.getContainingSymbol().getType() == ITypeInfo.t_union) { - return new ASTFieldReference(offset, - (IASTField) (definition != null ? definition : declaration)); - } else if ((symbol.getContainingSymbol().getType() == ITypeInfo.t_function || symbol - .getContainingSymbol().getType() == ITypeInfo.t_constructor) - && symbol.getContainingSymbol() instanceof IParameterizedSymbol - && ((IParameterizedSymbol) symbol.getContainingSymbol()) - .getParameterList() != null - && ((IParameterizedSymbol) symbol.getContainingSymbol()) - .getParameterList().contains(symbol)) { - return new ASTParameterReference(offset, - (IASTParameterDeclaration) declaration); - } else { - ASTNode s = (definition != null) ? definition : declaration; - if (s instanceof IASTVariable) - return new ASTVariableReference(offset, (IASTVariable) s); - else if (s instanceof IASTParameterDeclaration) - return new ASTParameterReference(offset, - (IASTParameterDeclaration) s); - else if (s instanceof IASTTemplateParameter) - return new ASTTemplateParameterReference(offset, - (IASTTemplateParameter) s); - } - } - // assert false : "Unreachable code : createReference()"; - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createEnumerationSpecifier(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.lang.String, int, int) - */ - public IASTEnumerationSpecifier createEnumerationSpecifier(IASTScope scope, - char[] name, int startingOffset, int startingLine, int nameOffset, - int nameEndOffset, int nameLine, char[] fn) - throws ASTSemanticException { - setFilename(fn); - IContainerSymbol containerSymbol = scopeToSymbol(scope); - ITypeInfo.eType pstType = ITypeInfo.t_enumeration; - - IDerivableContainerSymbol classSymbol = pst.newDerivableContainerSymbol( - name, pstType); - try { - containerSymbol.addSymbol(classSymbol); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), name); - } - - ASTEnumerationSpecifier enumSpecifier = new ASTEnumerationSpecifier( - classSymbol, startingOffset, startingLine, nameOffset, - nameEndOffset, nameLine, fn); - - attachSymbolExtension(classSymbol, enumSpecifier, true); - return enumSpecifier; - } - - /** - * @param fn - */ - private void setFilename(char[] fn) { - filename = fn; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#addEnumerator(org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier, - * java.lang.String, int, int, - * org.eclipse.cdt.core.parser.ast.IASTExpression) - */ - public IASTEnumerator addEnumerator(IASTEnumerationSpecifier enumeration, - char[] name, int startingOffset, int startingLine, int nameOffset, - int nameEndOffset, int nameLine, int endingOffset, int endLine, - IASTExpression initialValue, char[] fn) throws ASTSemanticException { - setFilename(fn); - IContainerSymbol enumerationSymbol = (IContainerSymbol) ((ISymbolOwner) enumeration) - .getSymbol(); - - ISymbol enumeratorSymbol = pst.newSymbol(name, ITypeInfo.t_enumerator); - try { - enumerationSymbol.addSymbol(enumeratorSymbol); - } catch (ParserSymbolTableException e1) { - if (e1.reason == ParserSymbolTableException.r_InvalidOverload) - handleProblem(IProblem.SEMANTIC_INVALID_OVERLOAD, name, - startingOffset, endingOffset, startingLine, true); - // assert false : e1; - } - ASTEnumerator enumerator = new ASTEnumerator(enumeratorSymbol, - enumeration, startingOffset, startingLine, nameOffset, - nameEndOffset, nameLine, endingOffset, endLine, initialValue, fn); - ((ASTEnumerationSpecifier) enumeration).addEnumerator(enumerator); - attachSymbolExtension(enumeratorSymbol, enumerator, true); - return enumerator; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExpression(org.eclipse.cdt.core.parser.ast.IASTExpression.Kind, - * org.eclipse.cdt.core.parser.ast.IASTExpression, - * org.eclipse.cdt.core.parser.ast.IASTExpression, - * org.eclipse.cdt.core.parser.ast.IASTExpression, java.lang.String, - * java.lang.String, java.lang.String, - * org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor) - */ - public IASTExpression createExpression(IASTScope scope, Kind kind, - IASTExpression lhs, IASTExpression rhs, - IASTExpression thirdExpression, IASTTypeId typeId, - ITokenDuple idExpression, char[] literal, - IASTNewExpressionDescriptor newDescriptor, ITokenDuple extra) - throws ASTSemanticException { - setProblemInfo(extra); - if (idExpression != null && logService.isTracing()) { - TraceUtil.outputTrace(logService, - "Entering createExpression with Kind=", //$NON-NLS-1$ - null, kind.getKindName(), " idexpression=", //$NON-NLS-1$ - idExpression.toString()); - } else if (literal != null && literal.length > 0 - && logService.isTracing()) { - TraceUtil.outputTrace(logService, - "Entering createExpression with Kind=", //$NON-NLS-1$ - null, kind.getKindName(), " literal=", //$NON-NLS-1$ - String.valueOf(literal)); - } - - List references = new ArrayList(); - ISymbol symbol = getExpressionSymbol(scope, kind, lhs, rhs, idExpression, - references); - - // Try to figure out the result that this expression evaluates to - ExpressionResult expressionResult = getExpressionResultType(scope, kind, - lhs, rhs, thirdExpression, typeId, literal, symbol, extra); - - if (newDescriptor != null) { - createConstructorReference(newDescriptor, typeId, references); - } - - if (symbol == null) - purgeBadReferences(kind, rhs); - - // expression results could be empty, but should not be null - // assert expressionResult != null : expressionResult; //throw new - // ASTSemanticException(); - - // create the ASTExpression - ASTExpression expression = null; - if (extension.overrideCreateExpressionMethod()) - expression = (ASTExpression) extension.createExpression(scope, kind, - lhs, rhs, thirdExpression, typeId, idExpression, literal, - newDescriptor, references); - else - expression = ExpressionFactory.createExpression(kind, lhs, rhs, - thirdExpression, typeId, idExpression, literal, newDescriptor, - references); - // Assign the result to the created expression - expression.setResultType(expressionResult); - - return expression; - } - - private void createConstructorReference( - IASTNewExpressionDescriptor descriptor, IASTTypeId typeId, - List references) { - ISymbol symbol = null; - - symbol = ((ASTTypeId) typeId).getTypeSymbol(); - - if (symbol.isType(ITypeInfo.t_type)) - symbol = symbol.getTypeSymbol(); - - if (symbol == null || !(symbol instanceof IDerivableContainerSymbol)) - return; - - List initializers = ((ASTNewDescriptor) descriptor) - .getNewInitializerExpressionsList(); - - ASTExpression exp = (initializers.size() > 0) ? (ASTExpression) initializers - .get(0) - : null; - - ITokenDuple duple = ((ASTTypeId) typeId).getTokenDuple().getLastSegment(); - - if (createConstructorReference(symbol, exp, duple, references)) { - //if we have a constructor reference, get rid of the class reference. - List refs = ((ASTTypeId) typeId).getReferences(); - int size = refs.size(); - for (int i = 0; i < size; i++) { - ASTReference ref = (ASTReference) refs.get(i); - if (CharArrayUtils.equals(ref.getNameCharArray(), duple - .toCharArray()) - && ref.getOffset() == duple.getStartOffset()) { - refs.remove(i--); - size--; - } - } - } - } - - private boolean createConstructorReference(ISymbol classSymbol, - ASTExpression expressionList, ITokenDuple duple, List references) { - if (classSymbol != null - && classSymbol.getTypeInfo().checkBit(ITypeInfo.isTypedef)) { - TypeInfoProvider provider = pst.getTypeInfoProvider(); - ITypeInfo info = classSymbol.getTypeInfo().getFinalType(provider); - classSymbol = info.getTypeSymbol(); - provider.returnTypeInfo(info); - } - if (classSymbol == null - || !(classSymbol instanceof IDerivableContainerSymbol)) { - return false; - } - - List parameters = new ArrayList(); - while (expressionList != null) { - parameters.add(expressionList.getResultType().getResult()); - if (expressionList.getExpressionKind() == IASTExpression.Kind.EXPRESSIONLIST) - expressionList = (ASTExpression) expressionList.getRHSExpression(); - else - expressionList = null; - } - - IParameterizedSymbol constructor = null; - try { - constructor = ((IDerivableContainerSymbol) classSymbol) - .lookupConstructor(parameters); - } catch (ParserSymbolTableException e1) { - return false; - } - - if (constructor != null) { - IASTReference reference = null; - try { - reference = createReference(constructor, duple.toCharArray(), duple - .getStartOffset()); - } catch (ASTSemanticException e2) { - return false; - } - if (reference != null) { - addReference(references, reference); - return true; - } - } - return false; - } - - /** - * @param kind - * @param rhs - */ - private void purgeBadReferences(Kind kind, IASTExpression rhs) { - if (rhs == null) - return; - if (kind == Kind.POSTFIX_ARROW_IDEXPRESSION - || kind == Kind.POSTFIX_ARROW_TEMPL_IDEXP - || kind == Kind.POSTFIX_DOT_IDEXPRESSION - || kind == Kind.POSTFIX_DOT_TEMPL_IDEXPRESS) { - ASTExpression astExpression = (ASTExpression) rhs; - char[] idExpression = astExpression.getIdExpressionCharArray(); - if (idExpression.length > 0) //$NON-NLS-1$ - { - List refs = astExpression.getReferences(); - int size = refs.size(); - for (int i = 0; i < size; i++) { - IASTReference r = (IASTReference) refs.get(i); - if (CharArrayUtils.equals(r.getNameCharArray(), idExpression)) { - refs.remove(i--); - size--; - } - } - } - } - - } - - /* - * Try and dereference the symbol in the expression - */ - private ISymbol getExpressionSymbol(IASTScope scope, Kind kind, - IASTExpression lhs, IASTExpression rhs, ITokenDuple idExpression, - List references) throws ASTSemanticException { - ISymbol symbol = null; - IContainerSymbol startingScope = scopeToSymbol(scope); - - //If the expression has an id, look up id and add it to references - if (idExpression != null) - symbol = lookupQualifiedName(startingScope, idExpression, references, - false); - - // If the expression is lookup symbol if it is in the scope of a type - // after a "." or an "->" - IContainerSymbol searchScope = getSearchScope(kind, lhs, startingScope); - if (searchScope != null && !searchScope.equals(startingScope)) - symbol = lookupQualifiedName(searchScope, ((ASTIdExpression) rhs) - .getIdExpressionTokenDuple(), references, false, - LookupType.QUALIFIED); - - // get symbol if it is the "this" pointer - // go up the scope until you hit a class - if (kind == IASTExpression.Kind.PRIMARY_THIS) { - try { - symbol = startingScope.lookup(THIS); //$NON-NLS-1$ - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), THIS); //$NON-NLS-1$ - } - } - // lookup symbol if it is a function call - if (kind == IASTExpression.Kind.POSTFIX_FUNCTIONCALL) { - ITokenDuple functionId = getFunctionId(lhs); - IContainerSymbol functionScope = getSearchScope(lhs - .getExpressionKind(), lhs.getLHSExpression(), startingScope); - - if (functionScope == null) - return null; - - ExpressionResult expResult = ((ASTExpression) rhs).getResultType(); - List parameters = null; - if (expResult instanceof ExpressionResultList) { - ExpressionResultList expResultList = (ExpressionResultList) expResult; - parameters = expResultList.getResultList(); - - } else { - parameters = new ArrayList(1); - parameters.add(expResult.getResult()); - } - if (functionScope.equals(startingScope)) - symbol = lookupQualifiedName(functionScope, functionId, - ITypeInfo.t_function, parameters, references, false); - else - symbol = lookupQualifiedName(functionScope, functionId, - ITypeInfo.t_function, parameters, references, false, - LookupType.QUALIFIED); - } - - return symbol; - } - - /* - * Returns the function ID token - */ - private ITokenDuple getFunctionId(IASTExpression expression) { - if (expression.getExpressionKind().isPostfixMemberReference() - && expression.getRHSExpression() instanceof ASTIdExpression) - return ((ASTIdExpression) expression.getRHSExpression()) - .getIdExpressionTokenDuple(); - else if (expression instanceof ASTIdExpression) - return ((ASTIdExpression) expression).getIdExpressionTokenDuple(); - return null; - } - - private IContainerSymbol getSearchScope(Kind kind, IASTExpression lhs, - IContainerSymbol startingScope) throws ASTSemanticException { - if (kind.isPostfixMemberReference()) { - ITypeInfo lhsInfo = ((ASTExpression) lhs).getResultType().getResult(); - if (lhsInfo != null) { - TypeInfoProvider provider = pst.getTypeInfoProvider(); - ITypeInfo info = null; - try { - info = lhsInfo.getFinalType(provider); - } catch (ParserSymbolTableError e) { - return null; - } - ISymbol containingScope = info.getTypeSymbol(); - provider.returnTypeInfo(info); - // assert containingScope != null : "Malformed Expression"; - if (containingScope instanceof IDeferredTemplateInstance) - return ((IDeferredTemplateInstance) containingScope) - .getTemplate().getTemplatedSymbol(); - return (containingScope instanceof IContainerSymbol) ? (IContainerSymbol) containingScope - : null; - } - // assert lhsInfo != null : "Malformed Expression"; - return null; - } - return startingScope; - } - - /* - * Conditional Expression conversion - */ - protected ITypeInfo conditionalExpressionConversions(ITypeInfo second, - ITypeInfo third) { - ITypeInfo info = null; - if (second.equals(third)) { - info = second; - return info; - } - if ((second.getType() == ITypeInfo.t_void) - && (third.getType() != ITypeInfo.t_void)) { - info = third; - return info; - } - if ((second.getType() != ITypeInfo.t_void) - && (third.getType() == ITypeInfo.t_void)) { - info = second; - return info; - } - if ((second.getType() == ITypeInfo.t_void) - && (third.getType() == ITypeInfo.t_void)) { - info = second; - return info; - } - try { - info = pst.getConditionalOperand(second, third); - return info; - } catch (ParserSymbolTableException e) { - // empty info - return info; - } - } - - /* - * Apply the usual arithmetic conversions to find out the result of an - * expression that has a lhs and a rhs as indicated in the specs (section - * 5.Expressions, page 64) - */ - protected ITypeInfo usualArithmeticConversions(IASTScope scope, - ASTExpression lhsExp, ASTExpression rhsExp, Kind kind) - throws ASTSemanticException { - setFilename(lhsExp.getFilename()); - - ITypeInfo lhs = lhsExp.getResultType().getResult(); - ITypeInfo rhs = rhsExp.getResultType().getResult(); - - if (lhs == null) - return null; - if (rhs == null) - return null; - boolean isLhsPointer = false; - boolean isRhsPointer = false; - // if you have a variable of type basic type, then we need to go to the - // basic type first - while ((lhs.getType() == ITypeInfo.t_type) - && (lhs.getTypeSymbol() != null)) { - if (!isLhsPointer) - isLhsPointer = lhs.hasPtrOperators(); - lhs = lhs.getTypeSymbol().getTypeInfo(); - } - while ((rhs.getType() == ITypeInfo.t_type) - && (rhs.getTypeSymbol() != null)) { - if (!isRhsPointer) - isRhsPointer = rhs.hasPtrOperators(); - rhs = rhs.getTypeSymbol().getTypeInfo(); - } - - boolean checkInvalidConversion = true; - IASTExpression expLeftTest = lhsExp.getLHSExpression(); - IASTExpression expRightTest = rhsExp.getLHSExpression(); - while (expLeftTest != null - && !(expLeftTest instanceof ASTEmptyExpression)) { - expLeftTest = expLeftTest.getLHSExpression(); - } - - while (expRightTest != null - && !(expRightTest instanceof ASTEmptyExpression)) { - expRightTest = expRightTest.getLHSExpression(); - } - - if ((expLeftTest != null && expLeftTest instanceof ASTEmptyExpression) - || (expRightTest != null && expRightTest instanceof ASTEmptyExpression)) - checkInvalidConversion = false; - - if (checkInvalidConversion) { - // invalid arithmetic detection TODO add support for 4.5 Integral - // Promotions/4.7 Integral Conversions if necessary - // 5.6 Multiplicative Operators: The operands of * and / shall have - // arithmetic or enumeration type; the operands of % shall have - // integral or enumeration type. - if (kind == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY - || kind == IASTExpression.Kind.MULTIPLICATIVE_DIVIDE) { - if (!lhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator)) - handleProblem(scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, - null, lhsExp.getStartingOffset(), - lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true); - if (!rhs.isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator)) - handleProblem(scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, - null, rhsExp.getStartingOffset(), - rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true); - } else if (kind == IASTExpression.Kind.MULTIPLICATIVE_MODULUS) { - if (!(isIntegralType(lhs, isLhsPointer) || lhs.isType( - ITypeInfo.t__Bool, ITypeInfo.t_enumerator))) - handleProblem(scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, - null, lhsExp.getStartingOffset(), - lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true); - if (!(isIntegralType(rhs, isRhsPointer) || rhs.isType( - ITypeInfo.t__Bool, ITypeInfo.t_enumerator))) - handleProblem(scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, - null, rhsExp.getStartingOffset(), - rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true); - - // 5.7 Additive Operators: - // For addition, either both operands shall have arithmetic or - // enumeration type, or one operand shall be a - // pointer to a completely defined object type and the other shall - // have integral or enumeration type. - // For subtraction, one of the following shall hold: - // - both operands have arithmetic or enumeration type; or - // - both operands are pointers to cvqualified or cvunqualified - // versions of the same completely defined object type; or - // - the left operand is a pointer to a completely defined object - // type and the right operand has integral or - // enumeration type. - } else if (kind == IASTExpression.Kind.ADDITIVE_PLUS) { - if (!((isLhsPointer && (isIntegralType(rhs, isRhsPointer) || rhs - .isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator))) || (isRhsPointer && (isIntegralType( - lhs, isRhsPointer) || lhs.isType(ITypeInfo.t__Bool, - ITypeInfo.t_enumerator))))) { - if (!(isIntegralType(lhs, isLhsPointer) || lhs.isType( - ITypeInfo.t__Bool, ITypeInfo.t_enumerator))) - handleProblem(scope, - IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp - .getStartingOffset(), lhsExp.getEndingOffset(), - lhsExp.getStartingLine(), true); - if (!(isIntegralType(rhs, isRhsPointer) || rhs.isType( - ITypeInfo.t__Bool, ITypeInfo.t_enumerator))) - handleProblem(scope, - IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp - .getStartingOffset(), rhsExp.getEndingOffset(), - rhsExp.getStartingLine(), true); - } - } else if (kind == IASTExpression.Kind.ADDITIVE_MINUS) { - if (!(isLhsPointer && (isIntegralType(rhs, isRhsPointer) || rhs - .isType(ITypeInfo.t__Bool, ITypeInfo.t_enumerator)))) { - if (!(isIntegralType(lhs, isLhsPointer) || lhs.isType( - ITypeInfo.t__Bool, ITypeInfo.t_enumerator))) - handleProblem(scope, - IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, lhsExp - .getStartingOffset(), lhsExp.getEndingOffset(), - lhsExp.getStartingLine(), true); - if (!(isIntegralType(rhs, isRhsPointer) || rhs.isType( - ITypeInfo.t__Bool, ITypeInfo.t_enumerator))) - handleProblem(scope, - IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, null, rhsExp - .getStartingOffset(), rhsExp.getEndingOffset(), - rhsExp.getStartingLine(), true); - } - - // 5.11, 5.12, 5.13: The operator applies only to integral or - // enumeration operands. - } else if (kind == IASTExpression.Kind.ANDEXPRESSION - || kind == IASTExpression.Kind.EXCLUSIVEOREXPRESSION - || kind == IASTExpression.Kind.INCLUSIVEOREXPRESSION) { - if (!(isIntegralType(lhs, isLhsPointer) || lhs.isType( - ITypeInfo.t__Bool, ITypeInfo.t_enumerator))) - handleProblem(scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, - null, lhsExp.getStartingOffset(), - lhsExp.getEndingOffset(), lhsExp.getStartingLine(), true); - if (!(isIntegralType(rhs, isRhsPointer) || rhs.isType( - ITypeInfo.t__Bool, ITypeInfo.t_enumerator))) - handleProblem(scope, IProblem.SEMANTIC_INVALID_CONVERSION_TYPE, - null, rhsExp.getStartingOffset(), - rhsExp.getEndingOffset(), rhsExp.getStartingLine(), true); - } - } - - ITypeInfo info = TypeInfoProvider.newTypeInfo(); - if ((lhs.checkBit(ITypeInfo.isLong) && lhs.getType() == ITypeInfo.t_double) - || (rhs.checkBit(ITypeInfo.isLong) && rhs.getType() == ITypeInfo.t_double)) { - info.setType(ITypeInfo.t_double); - info.setBit(true, ITypeInfo.isLong); - return info; - } else if ((lhs.getType() == ITypeInfo.t_double) - || (rhs.getType() == ITypeInfo.t_double)) { - info.setType(ITypeInfo.t_double); - return info; - } else if ((lhs.getType() == ITypeInfo.t_float) - || (rhs.getType() == ITypeInfo.t_float)) { - info.setType(ITypeInfo.t_float); - return info; - } else { - // perform intergral promotions (Specs section 4.5) - info.setType(ITypeInfo.t_int); - } - - if ((lhs.checkBit(ITypeInfo.isUnsigned) && lhs.checkBit(ITypeInfo.isLong)) - || (rhs.checkBit(ITypeInfo.isUnsigned) && rhs - .checkBit(ITypeInfo.isLong))) { - info.setBit(true, ITypeInfo.isUnsigned); - info.setBit(true, ITypeInfo.isLong); - return info; - } else if ((lhs.checkBit(ITypeInfo.isUnsigned) && rhs - .checkBit(ITypeInfo.isLong)) - || (rhs.checkBit(ITypeInfo.isUnsigned) && lhs - .checkBit(ITypeInfo.isLong))) { - info.setBit(true, ITypeInfo.isUnsigned); - info.setBit(true, ITypeInfo.isLong); - return info; - } else if ((lhs.checkBit(ITypeInfo.isLong)) - || (rhs.checkBit(ITypeInfo.isLong))) { - info.setBit(true, ITypeInfo.isLong); - return info; - } else if ((lhs.checkBit(ITypeInfo.isUnsigned)) - || (rhs.checkBit(ITypeInfo.isUnsigned))) { - info.setBit(true, ITypeInfo.isUnsigned); - return info; - } else { - // it should be both = int - return info; - } - } - - private ITypeInfo modifyTypeInfo(ASTExpression exp, Kind kind) { - // assert exp != null : exp; - ITypeInfo info = exp.getResultType().getResult(); - - //short added to a type - if (kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT) { - info.setBit(true, ITypeInfo.isShort); - } - // long added to a type - if (kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG) { - info.setBit(true, ITypeInfo.isLong); - } - // signed added to a type - if (kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED) { - info.setBit(true, ITypeInfo.isUnsigned); - } - // unsigned added to a type - if (kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED) { - info.setBit(true, ITypeInfo.isUnsigned); - } - - return info; - } - - private void constructBasicType(TypeInfoProvider provider, Kind kind) { - // types that resolve to void - if ((kind == IASTExpression.Kind.PRIMARY_EMPTY) - || (kind == IASTExpression.Kind.THROWEXPRESSION) - || (kind == IASTExpression.Kind.POSTFIX_DOT_DESTRUCTOR) - || (kind == IASTExpression.Kind.POSTFIX_ARROW_DESTRUCTOR) - || (kind == IASTExpression.Kind.DELETE_CASTEXPRESSION) - || (kind == IASTExpression.Kind.DELETE_VECTORCASTEXPRESSION)) { - provider.setType(ITypeInfo.t_void); - return; - } - // types that resolve to int - if ((kind == IASTExpression.Kind.PRIMARY_INTEGER_LITERAL) - || (kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT)) { - provider.setType(ITypeInfo.t_int); - return; - } - - // size of is always unsigned int - if ((kind == IASTExpression.Kind.UNARY_SIZEOF_TYPEID) - || (kind == IASTExpression.Kind.UNARY_SIZEOF_UNARYEXPRESSION)) { - provider.setType(ITypeInfo.t_int); - provider.setTypeBits(ITypeInfo.isUnsigned); - return; - } - - // types that resolve to char - if ((kind == IASTExpression.Kind.PRIMARY_CHAR_LITERAL) - || (kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR) - || (kind == IASTExpression.Kind.PRIMARY_STRING_LITERAL)) { - provider.setType(ITypeInfo.t_char); - return; - } - // types that resolve to float - if ((kind == IASTExpression.Kind.PRIMARY_FLOAT_LITERAL) - || (kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT)) { - provider.setType(ITypeInfo.t_float); - return; - } - //types that resolve to double - if (kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE) { - provider.setType(ITypeInfo.t_double); - return; - } - //types that resolve to wchar - if (kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART) { - provider.setType(ITypeInfo.t_wchar_t); - return; - } - // types that resolve to bool - if ((kind == IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL) - || (kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL) - || (kind == IASTExpression.Kind.RELATIONAL_GREATERTHAN) - || (kind == IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO) - || (kind == IASTExpression.Kind.RELATIONAL_LESSTHAN) - || (kind == IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO) - || (kind == IASTExpression.Kind.EQUALITY_EQUALS) - || (kind == IASTExpression.Kind.EQUALITY_NOTEQUALS) - || (kind == IASTExpression.Kind.LOGICALANDEXPRESSION) - || (kind == IASTExpression.Kind.LOGICALOREXPRESSION)) { - provider.setType(ITypeInfo.t_bool); - return; - } - } - - protected ExpressionResult getExpressionResultType(IASTScope scope, - Kind kind, IASTExpression lhs, IASTExpression rhs, - IASTExpression thirdExpression, IASTTypeId typeId, char[] literal, - ISymbol symbol, ITokenDuple extra) throws ASTSemanticException { - setProblemInfo(extra); - ITypeInfo info = null; - ExpressionResult result = null; - - if (extension.canHandleExpressionKind(kind)) { - info = extension.getExpressionResultType(kind, lhs, rhs, typeId); - return new ExpressionResult(info); - } - - //basic types - if (kind.isBasicType()) { - TypeInfoProvider provider = pst.getTypeInfoProvider(); - provider.beginTypeConstruction(); - - if (literal != null && !literal.equals(EMPTY_STRING) - && kind.isLiteral()) { - provider.setDefaultObj(literal); - } - - constructBasicType(provider, kind); - - info = provider.completeConstruction(); - - //types that need a pointer - - if (kind == IASTExpression.Kind.PRIMARY_STRING_LITERAL - || (literal.length > 3 && (kind == IASTExpression.Kind.PRIMARY_CHAR_LITERAL || kind == IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR))) { - info.addPtrOperator(new ITypeInfo.PtrOp(ITypeInfo.PtrOp.t_pointer)); - } - - return new ExpressionResult(info); - } - - // modifications to existing types - if (kind.isPostfixSimpleType()) { - info = modifyTypeInfo((ASTExpression) lhs, kind); - return new ExpressionResult(info); - } - - // Id expressions resolve to t_type, symbol already looked up - if (kind == IASTExpression.Kind.ID_EXPRESSION) { - info = TypeInfoProvider.newTypeInfo(ITypeInfo.t_type); - info.setTypeSymbol(symbol); - result = new ExpressionResult(info); - if (symbol == null) - result.setFailedToDereference(true); - return result; - } - - // an ampersand implies a pointer operation of type reference - if (kind == IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION) { - ASTExpression left = (ASTExpression) lhs; - if (left == null) - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - - info = left.getResultType().getResult(); - if (info != null) { - info = info.getFinalType(null); - info - .applyOperatorExpression(ITypeInfo.OperatorExpression.addressof); - } else - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - - result = new ExpressionResult(info); - return result; - } - - // a star implies a pointer operation of type pointer - if (kind == IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION) { - ASTExpression left = (ASTExpression) lhs; - if (left == null) - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - info = left.getResultType().getResult(); - if (info != null) { - info = info.getFinalType(null); - info - .applyOperatorExpression(ITypeInfo.OperatorExpression.indirection); - } else - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - - result = new ExpressionResult(info); - return result; - } - // subscript - if (kind == IASTExpression.Kind.POSTFIX_SUBSCRIPT) { - ASTExpression left = (ASTExpression) lhs; - if (left == null) - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - info = left.getResultType().getResult(); - if ((info != null)) { - info = info.getFinalType(null); - info - .applyOperatorExpression(ITypeInfo.OperatorExpression.subscript); - } else { - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - } - result = new ExpressionResult(info); - return result; - } - // the dot and the arrow resolves to the type of the member - if ((kind == IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION) - || (kind == IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION) - || (kind == IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS) - || (kind == IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP)) { - if (symbol != null) { - info = TypeInfoProvider.newTypeInfo(symbol.getTypeInfo()); - } - result = new ExpressionResult(info); - return result; - } - // the dot* and the arrow* are the same as dot/arrow + unary star - if ((kind == IASTExpression.Kind.PM_DOTSTAR) - || (kind == IASTExpression.Kind.PM_ARROWSTAR)) { - ASTExpression right = (ASTExpression) rhs; - if (right == null) - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - info = right.getResultType().getResult(); - if ((info != null) && (symbol != null)) { - info.setTypeSymbol(symbol); - info = info.getFinalType(null); - info - .applyOperatorExpression(ITypeInfo.OperatorExpression.indirection); - - } else - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - - result = new ExpressionResult(info); - return result; - } - // this - if (kind == IASTExpression.Kind.PRIMARY_THIS) { - if (symbol != null) { - info = TypeInfoProvider.newTypeInfo(ITypeInfo.t_type); - info.setTypeSymbol(symbol); - } else - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - - result = new ExpressionResult(info); - return result; - } - - // conditional - if (kind == IASTExpression.Kind.CONDITIONALEXPRESSION) { - ASTExpression right = (ASTExpression) rhs; - ASTExpression third = (ASTExpression) thirdExpression; - if ((right != null) && (third != null)) { - ITypeInfo rightType = right.getResultType().getResult(); - ITypeInfo thirdType = third.getResultType().getResult(); - if ((rightType != null) && (thirdType != null)) { - info = conditionalExpressionConversions(rightType, thirdType); - } else - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, - null); - - } else - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - - result = new ExpressionResult(info); - return result; - } - // new - if ((kind == IASTExpression.Kind.NEW_TYPEID) - || (kind == IASTExpression.Kind.NEW_NEWTYPEID)) { - info = ((ASTTypeId) typeId).getTypeSymbol().getTypeInfo(); - info.addPtrOperator(new ITypeInfo.PtrOp(ITypeInfo.PtrOp.t_pointer)); - result = new ExpressionResult(info); - return result; - } - // types that use the usual arithmetic conversions - if ((kind == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY) - || (kind == IASTExpression.Kind.MULTIPLICATIVE_DIVIDE) - || (kind == IASTExpression.Kind.MULTIPLICATIVE_MODULUS) - || (kind == IASTExpression.Kind.ADDITIVE_PLUS) - || (kind == IASTExpression.Kind.ADDITIVE_MINUS) - || (kind == IASTExpression.Kind.ANDEXPRESSION) - || (kind == IASTExpression.Kind.EXCLUSIVEOREXPRESSION) - || (kind == IASTExpression.Kind.INCLUSIVEOREXPRESSION)) { - ASTExpression left = (ASTExpression) lhs; - ASTExpression right = (ASTExpression) rhs; - if ((left != null) && (right != null)) { - info = usualArithmeticConversions(scope, left, right, kind); - } else - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - - result = new ExpressionResult(info); - return result; - } - - // types that resolve to LHS types - if ((kind == IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION) - || (kind == IASTExpression.Kind.POSTFIX_INCREMENT) - || (kind == IASTExpression.Kind.POSTFIX_DECREMENT) - || (kind == IASTExpression.Kind.POSTFIX_TYPEID_EXPRESSION) - || (kind == IASTExpression.Kind.UNARY_INCREMENT) - || (kind == IASTExpression.Kind.UNARY_DECREMENT) - || (kind == IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION) - || (kind == IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION) - || (kind == IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION) - || (kind == IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION) - || (kind == IASTExpression.Kind.SHIFT_LEFT) - || (kind == IASTExpression.Kind.SHIFT_RIGHT) - || (kind == IASTExpression.Kind.ASSIGNMENTEXPRESSION_NORMAL) - || (kind == IASTExpression.Kind.ASSIGNMENTEXPRESSION_PLUS) - || (kind == IASTExpression.Kind.ASSIGNMENTEXPRESSION_MINUS) - || (kind == IASTExpression.Kind.ASSIGNMENTEXPRESSION_MULT) - || (kind == IASTExpression.Kind.ASSIGNMENTEXPRESSION_DIV) - || (kind == IASTExpression.Kind.ASSIGNMENTEXPRESSION_MOD) - || (kind == IASTExpression.Kind.ASSIGNMENTEXPRESSION_LSHIFT) - || (kind == IASTExpression.Kind.ASSIGNMENTEXPRESSION_RSHIFT) - || (kind == IASTExpression.Kind.ASSIGNMENTEXPRESSION_AND) - || (kind == IASTExpression.Kind.ASSIGNMENTEXPRESSION_OR) - || (kind == IASTExpression.Kind.ASSIGNMENTEXPRESSION_XOR)) { - ASTExpression left = (ASTExpression) lhs; - if (left != null && left.getResultType() != null) { - info = left.getResultType().getResult(); - } else - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - - result = new ExpressionResult(info); - return result; - } - // the cast changes the types to the type looked up in typeId = symbol - if ((kind == IASTExpression.Kind.CASTEXPRESSION) - || (kind == IASTExpression.Kind.POSTFIX_DYNAMIC_CAST) - || (kind == IASTExpression.Kind.POSTFIX_STATIC_CAST) - || (kind == IASTExpression.Kind.POSTFIX_REINTERPRET_CAST) - || (kind == IASTExpression.Kind.POSTFIX_CONST_CAST)) { - - info = TypeInfoProvider.newTypeInfo(((ASTTypeId) typeId) - .getTypeSymbol().getTypeInfo()); - result = new ExpressionResult(info); - return result; - } - // a list collects all types of left and right hand sides - if (kind == IASTExpression.Kind.EXPRESSIONLIST) { - result = new ExpressionResultList(); - if (lhs != null) { - ExpressionResult resultType = ((ASTExpression) lhs).getResultType(); - if (resultType instanceof ExpressionResultList) - ((ExpressionResultList) result) - .setResult((ExpressionResultList) resultType); - else - result.setResult(resultType.getResult()); - } - if (rhs != null) { - ITypeInfo rightType = ((ASTExpression) rhs).getResultType() - .getResult(); - result.setResult(rightType); - } - return result; - } - // a function call type is the return type of the function - if (kind == IASTExpression.Kind.POSTFIX_FUNCTIONCALL) { - if (symbol != null) { - IParameterizedSymbol psymbol = (IParameterizedSymbol) symbol; - ISymbol returnTypeSymbol = psymbol.getReturnType(); - if (returnTypeSymbol != null) { - info = TypeInfoProvider.newTypeInfo(returnTypeSymbol - .getTypeInfo()); - //info.setTypeSymbol(returnTypeSymbol); - } else { - // this is call to a constructor - } - } else { - info = TypeInfoProvider.newTypeInfo(); - } - result = new ExpressionResult(info); - if (symbol == null) - result.setFailedToDereference(true); - return result; - } - // typeid - if (kind == IASTExpression.Kind.POSTFIX_TYPEID_TYPEID) { - info = ((ASTTypeId) typeId).getTypeSymbol().getTypeInfo(); - result = new ExpressionResult(info); - return result; - } - // typename - if ((kind == IASTExpression.Kind.POSTFIX_TYPENAME_IDENTIFIER) - || (kind == IASTExpression.Kind.POSTFIX_TYPENAME_TEMPLATEID)) { - if (symbol != null) { - info = TypeInfoProvider.newTypeInfo(ITypeInfo.t_type); - info.setTypeSymbol(symbol); - } else - handleProblem(scope, IProblem.SEMANTIC_MALFORMED_EXPRESSION, null); - - result = new ExpressionResult(info); - return result; - } - // assert false : this; - return null; - } - - protected void getExpressionReferences(IASTExpression expression, - List references) { - if (expression != null) { - List eRefs = ((ASTExpression) expression).getReferences(); - if (eRefs != null && !eRefs.isEmpty()) { - for (int i = 0; i < eRefs.size(); ++i) { - IASTReference r = (IASTReference) eRefs.get(i); - references.add(r); - } - } - if (expression.getLHSExpression() != null) - getExpressionReferences(expression.getLHSExpression(), references); - if (expression.getRHSExpression() != null) - getExpressionReferences(expression.getRHSExpression(), references); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewDescriptor() - */ - public IASTNewExpressionDescriptor createNewDescriptor( - List newPlacementExpressions, List newTypeIdExpressions, - List newInitializerExpressions) { - return new ASTNewDescriptor(newPlacementExpressions, - newTypeIdExpressions, newInitializerExpressions); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createExceptionSpecification(java.util.List) - */ - public IASTExceptionSpecification createExceptionSpecification( - IASTScope scope, List typeIds) throws ASTSemanticException { - List newTypeIds = new ArrayList(); - if (typeIds != null) { - int size = typeIds.size(); - for (int i = 0; i < size; i++) - newTypeIds.add(typeIds.get(i)); - - } - return new ASTExceptionSpecification(newTypeIds); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createConstructorMemberInitializer(org.eclipse.cdt.core.parser.ITokenDuple, - * org.eclipse.cdt.core.parser.ast.IASTExpression) - */ - public IASTConstructorMemberInitializer createConstructorMemberInitializer( - IASTScope scope, ITokenDuple duple, IASTExpression expressionList) { - setProblemInfo(duple); - List references = new ArrayList(); - - IContainerSymbol scopeSymbol = scopeToSymbol(scope); - - boolean requireReferenceResolution = false; - ISymbol symbol = null; - if (duple != null) { - try { - symbol = lookupQualifiedName(scopeSymbol, duple, references, true); - } catch (ASTSemanticException ase) { - //use the class specifier's unresolved reference mechanism to - // resolve these references. - //TODO: resolve unresolved references in the expressionList using - // resolveLeftoverConstructorInitializerMembers - if (scope instanceof ASTClassSpecifier) { - ASTClassSpecifier classSpecifier = (ASTClassSpecifier) scope; - classSpecifier - .addUnresolvedReference(new UnresolvedReferenceDuple( - scopeSymbol, duple)); - } - } - } - - if (symbol != null) { - createConstructorReference(symbol, (ASTExpression) expressionList, - duple, references); - } - - getExpressionReferences(expressionList, references); - return new ASTConstructorMemberInitializer(expressionList, - duple == null ? EMPTY_STRING : duple.toCharArray(), - duple == null ? 0 : duple.getFirstToken().getOffset(), references, - requireReferenceResolution); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createSimpleTypeSpecifier(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type, - * org.eclipse.cdt.core.parser.ITokenDuple, boolean, boolean, boolean, - * boolean, boolean) - */ - public IASTSimpleTypeSpecifier createSimpleTypeSpecifier(IASTScope scope, - Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, - boolean isSigned, boolean isUnsigned, boolean isTypename, - boolean isComplex, boolean isImaginary, boolean isGlobal, - Map extensionParms) throws ASTSemanticException { - setProblemInfo(typeName); - if (extension.overrideCreateSimpleTypeSpecifierMethod(kind)) - return extension.createSimpleTypeSpecifier(pst, scope, kind, typeName, - isShort, isLong, isSigned, isUnsigned, isTypename, isComplex, - isImaginary, isGlobal, extensionParms); - char[] typeNameAsString = typeName.toCharArray(); - if (kind != Type.CLASS_OR_TYPENAME) { - IASTSimpleTypeSpecifier query = (IASTSimpleTypeSpecifier) simpleTypeSpecCache - .get(typeNameAsString); - if (query != null) - return query; - } - - ITypeInfo.eType type = null; - - if (kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME) - type = ITypeInfo.t_type; - else if (kind == IASTSimpleTypeSpecifier.Type.BOOL) - type = ITypeInfo.t_bool; - else if (kind == IASTSimpleTypeSpecifier.Type.CHAR) - type = ITypeInfo.t_char; - else if (kind == IASTSimpleTypeSpecifier.Type.DOUBLE) - type = ITypeInfo.t_double; - else if (kind == IASTSimpleTypeSpecifier.Type.FLOAT) - type = ITypeInfo.t_float; - else if (kind == IASTSimpleTypeSpecifier.Type.INT) - type = ITypeInfo.t_int; - else if (kind == IASTSimpleTypeSpecifier.Type.VOID) - type = ITypeInfo.t_void; - else if (kind == IASTSimpleTypeSpecifier.Type.WCHAR_T) - type = ITypeInfo.t_wchar_t; - else if (kind == IASTSimpleTypeSpecifier.Type._BOOL) - type = ITypeInfo.t__Bool; - - List references = (kind == Type.CLASS_OR_TYPENAME) ? new ArrayList( - DEFAULT_QUALIFIEDNAME_REFERENCE_SIZE) : null; - ISymbol s = pst.newSymbol(EMPTY_STRING, type); - if (kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME) { - // lookup the duple - IToken last = typeName.getLastToken(); - IToken current = null; - ISymbol typeSymbol = getScopeToSearchUpon(scope, typeName - .getFirstToken()); - - if (isGlobal) - typeSymbol = typeSymbol.getSymbolTable().getCompilationUnit(); - - List[] argLists = typeName.getTemplateIdArgLists(); - int idx = 0; - - for (;;) { - if (current == last) - break; - current = (current != null) ? current.getNext() : typeName - .getFirstToken(); - - if (current.getType() == IToken.tCOLONCOLON) { - idx++; - continue; - } - if (current.getType() == IToken.t_template) { - continue; - } - - char[] image = current.getCharImage(); - int offset = current.getOffset(); - - if (argLists != null && argLists[idx] != null) { - if (current != last && current.getNext().getType() == IToken.tLT) - current = TokenFactory.consumeTemplateIdArguments(current - .getNext(), last); - } - - while (!(typeSymbol instanceof IContainerSymbol)) { - if (typeSymbol.getTypeInfo().checkBit(ITypeInfo.isTypedef)) { - typeSymbol = typeSymbol.getTypeSymbol(); - } else if (typeSymbol instanceof IDeferredTemplateInstance) { - typeSymbol = ((IDeferredTemplateInstance) typeSymbol) - .getTemplate().getTemplatedSymbol(); - } else { - handleProblem(IProblem.SEMANTIC_INVALID_TYPE, image, current - .getOffset(), current.getEndOffset(), current - .getLineNumber(), true); - } - } - try { - if (argLists != null && argLists[idx] != null) - typeSymbol = ((IContainerSymbol) typeSymbol) - .lookupTemplateId(image, - getTemplateArgList(argLists[idx])); - else if (current != last) - typeSymbol = ((IContainerSymbol) typeSymbol) - .lookupNestedNameSpecifier(image); - else if (typeName.getSegmentCount() == 1) // a single segment - typeSymbol = ((IContainerSymbol) typeSymbol).lookup(image); - else - typeSymbol = ((IContainerSymbol) typeSymbol) - .qualifiedLookup(image); - - if (typeSymbol != null) { - addReference(references, createReference(typeSymbol, image, - offset)); - if (argLists != null && argLists[idx] != null) { - addTemplateIdReferences(references, argLists[idx]); - typeName.freeReferences(); - } - } else - handleProblem(IProblem.SEMANTIC_NAME_NOT_FOUND, image, - current.getOffset(), current.getEndOffset(), current - .getLineNumber(), true); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), image, typeName - .getStartOffset(), typeName.getEndOffset(), typeName - .getLineNumber(), true); - } - } - s.setTypeSymbol(typeSymbol); - } - - s.getTypeInfo().setBit(isLong, ITypeInfo.isLong); - s.getTypeInfo().setBit(isShort, ITypeInfo.isShort); - s.getTypeInfo().setBit(isUnsigned, ITypeInfo.isUnsigned); - s.getTypeInfo().setBit(isComplex, ITypeInfo.isComplex); - s.getTypeInfo().setBit(isImaginary, ITypeInfo.isImaginary); - s.getTypeInfo().setBit(isSigned, ITypeInfo.isSigned); - - IASTSimpleTypeSpecifier result = new ASTSimpleTypeSpecifier(s, false, - typeNameAsString, references); - if (kind != Type.CLASS_OR_TYPENAME) - simpleTypeSpecCache.put(typeNameAsString, result); - return result; - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createFunction(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.lang.String, java.util.List, - * org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, - * org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, - * boolean, boolean, int, int, - * org.eclipse.cdt.core.parser.ast.IASTTemplate) - */ - public IASTFunction createFunction(IASTScope scope, ITokenDuple name, - List parameters, IASTAbstractDeclaration returnType, - IASTExceptionSpecification exception, boolean isInline, - boolean isFriend, boolean isStatic, int startOffset, int startLine, - int nameOffset, int nameEndOffset, int nameLine, - IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, - boolean isVirtual, boolean isExplicit, boolean isPureVirtual, - List constructorChain, boolean isFunctionDefinition, - boolean hasFunctionTryBlock, boolean hasVariableArguments) - throws ASTSemanticException { - setProblemInfo(name); - List references = new ArrayList(); - IContainerSymbol ownerScope = scopeToSymbol(scope); - - // check if this is a method in a body file - if (name.getSegmentCount() > 1) { - ISymbol symbol = lookupQualifiedName(ownerScope, name - .getLeadingSegments(), references, false, - LookupType.FORPARENTSCOPE); - - IContainerSymbol parentScope = null; - - if (symbol instanceof IContainerSymbol) - parentScope = (IContainerSymbol) symbol; - else if (symbol instanceof IDeferredTemplateInstance) - parentScope = ((IDeferredTemplateInstance) symbol).getTemplate() - .getTemplatedSymbol(); - - if ((parentScope != null) - && ((parentScope.getType() == ITypeInfo.t_class) - || (parentScope.getType() == ITypeInfo.t_struct) || (parentScope - .getType() == ITypeInfo.t_union))) { - if (parentScope.getASTExtension().getPrimaryDeclaration() instanceof IASTElaboratedTypeSpecifier) { - //we are trying to define a member of a class for which we only - // have a forward declaration - handleProblem(scope, IProblem.SEMANTICS_RELATED, name - .toCharArray(), startOffset, nameEndOffset, startLine, - true); - } - IASTScope methodParentScope = (IASTScope) parentScope - .getASTExtension().getPrimaryDeclaration(); - ITokenDuple newName = name.getLastSegment(); - return createMethod(methodParentScope, newName, parameters, - returnType, exception, isInline, isFriend, isStatic, - startOffset, startLine, newName.getFirstToken().getOffset(), - nameEndOffset, nameLine, ownerTemplate, isConst, isVolatile, - isVirtual, isExplicit, isPureVirtual, - ASTAccessVisibility.PRIVATE, constructorChain, references, - isFunctionDefinition, hasFunctionTryBlock, - hasVariableArguments); - } - } - - IParameterizedSymbol symbol = pst.newParameterizedSymbol(name - .extractNameFromTemplateId(), ITypeInfo.t_function); - setFunctionTypeInfoBits(isInline, isFriend, isStatic, symbol); - - symbol.setHasVariableArgs(hasVariableArguments); - - symbol.prepareForParameters(parameters.size()); - setParameter(symbol, returnType, false, references); - setParameters(symbol, references, parameters); - - symbol.setIsForwardDeclaration(!isFunctionDefinition); - boolean previouslyDeclared = false; - - int size = parameters.size(); - List functionParameters = new ArrayList(size); - // the lookup requires a list of type infos - // instead of a list of IASTParameterDeclaration - for (int i = 0; i < size; i++) { - ASTParameterDeclaration param = (ASTParameterDeclaration) parameters - .get(i); - if (param.getSymbol() == null) - handleProblem(IProblem.SEMANTICS_RELATED, param.getNameCharArray(), - param.getNameOffset(), param.getEndingOffset(), param - .getStartingLine(), true); - functionParameters.add(param.getSymbol().getTypeInfo()); - } - - IParameterizedSymbol functionDeclaration = null; - - functionDeclaration = (IParameterizedSymbol) lookupQualifiedName( - ownerScope, name.extractNameFromTemplateId(), ITypeInfo.t_function, - functionParameters, 0, null, false, LookupType.FORDEFINITION); - - if (functionDeclaration != null && symbol.isType(ITypeInfo.t_function)) { - previouslyDeclared = true; - - if (isFunctionDefinition) { - functionDeclaration.setForwardSymbol(symbol); - } - } - - if (previouslyDeclared == false || isFunctionDefinition) { - try { - ownerScope.addSymbol(symbol); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), name.toCharArray(), nameOffset, - nameEndOffset, nameLine, true); - } - } else { - symbol = functionDeclaration; - } - - ASTFunction function = new ASTFunction(symbol, nameEndOffset, parameters, - returnType, exception, startOffset, startLine, nameOffset, - nameLine, ownerTemplate, references, previouslyDeclared, - hasFunctionTryBlock, isFriend, filename); - - attachSymbolExtension(symbol, function, isFunctionDefinition); - - function.setHasFunctionBody(isFunctionDefinition); - - return function; - } - - protected void setFunctionTypeInfoBits(boolean isInline, boolean isFriend, - boolean isStatic, IParameterizedSymbol symbol) { - symbol.getTypeInfo().setBit(isInline, ITypeInfo.isInline); - symbol.getTypeInfo().setBit(isFriend, ITypeInfo.isFriend); - symbol.getTypeInfo().setBit(isStatic, ITypeInfo.isStatic); - } - - /** - * @param symbol - * @param iterator - */ - protected void setParameters(IParameterizedSymbol symbol, List references, - List params) throws ASTSemanticException { - int size = params.size(); - for (int i = 0; i < size; i++) { - setParameter(symbol, (IASTParameterDeclaration) params.get(i), true, - references); - } - } - - protected ITypeInfo getParameterTypeInfo(IASTAbstractDeclaration absDecl) - throws ASTSemanticException { - TypeInfoProvider provider = pst.getTypeInfoProvider(); - provider.beginTypeConstruction(); - if (absDecl.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier) { - IASTSimpleTypeSpecifier simpleType = ((IASTSimpleTypeSpecifier) absDecl - .getTypeSpecifier()); - IASTSimpleTypeSpecifier.Type kind = simpleType.getType(); - if (kind == IASTSimpleTypeSpecifier.Type.BOOL) - provider.setType(ITypeInfo.t_bool); - else if (kind == IASTSimpleTypeSpecifier.Type.CHAR) - provider.setType(ITypeInfo.t_char); - else if (kind == IASTSimpleTypeSpecifier.Type.DOUBLE) - provider.setType(ITypeInfo.t_double); - else if (kind == IASTSimpleTypeSpecifier.Type.FLOAT) - provider.setType(ITypeInfo.t_float); - else if (kind == IASTSimpleTypeSpecifier.Type.INT) - provider.setType(ITypeInfo.t_int); - else if (kind == IASTSimpleTypeSpecifier.Type.VOID) - provider.setType(ITypeInfo.t_void); - else if (kind == IASTSimpleTypeSpecifier.Type.WCHAR_T) - provider.setType(ITypeInfo.t_wchar_t); - else if (kind == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME) - provider.setType(ITypeInfo.t_type); - else if (kind == IASTSimpleTypeSpecifier.Type._BOOL) { - provider.setType(ITypeInfo.t__Bool); - } - // else - // assert false : "Unexpected IASTSimpleTypeSpecifier.Type"; - - setTypeBitFlags(provider, simpleType); - - } else if (absDecl.getTypeSpecifier() instanceof IASTClassSpecifier) { - provider.setType(ITypeInfo.t_type); - provider - .setTypeSymbol(((ASTClassSpecifier) absDecl.getTypeSpecifier()) - .getSymbol()); - } else if (absDecl.getTypeSpecifier() instanceof IASTEnumerationSpecifier) { - provider.setType(ITypeInfo.t_type); - provider.setTypeSymbol(((ASTEnumerationSpecifier) absDecl - .getTypeSpecifier()).getSymbol()); - } else if (absDecl.getTypeSpecifier() instanceof IASTElaboratedTypeSpecifier) { - provider.setType(ITypeInfo.t_type); - provider.setTypeSymbol(((ASTElaboratedTypeSpecifier) absDecl - .getTypeSpecifier()).getSymbol()); - } - // else - // assert false : this; - - return provider.completeConstruction(); - } - - /** - * @param type - * @param simpleType - */ - private void setTypeBitFlags(TypeInfoProvider provider, - IASTSimpleTypeSpecifier simpleType) { - provider.setBit(simpleType.isLong(), ITypeInfo.isLong); - provider.setBit(simpleType.isShort(), ITypeInfo.isShort); - provider.setBit(simpleType.isUnsigned(), ITypeInfo.isUnsigned); - provider.setBit(simpleType.isComplex(), ITypeInfo.isComplex); - provider.setBit(simpleType.isImaginary(), ITypeInfo.isImaginary); - provider.setBit(simpleType.isSigned(), ITypeInfo.isSigned); - } - - /** - * @param symbol - * @param returnType - */ - protected void setParameter(IParameterizedSymbol symbol, - IASTAbstractDeclaration absDecl, boolean isParameter, List references) - throws ASTSemanticException { - if (absDecl.getTypeSpecifier() == null) - return; - - // now determined by another function - ITypeInfo info = getParameterTypeInfo(absDecl); - ITypeInfo.eType type = info.getType(); - - ISymbol xrefSymbol = info.getTypeSymbol(); - List newReferences = null; - int infoBits = 0; - if (absDecl.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier) { - if (((IASTSimpleTypeSpecifier) absDecl.getTypeSpecifier()).getType() == IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME) { - xrefSymbol = ((ASTSimpleTypeSpecifier) absDecl.getTypeSpecifier()) - .getSymbol(); - newReferences = ((ASTSimpleTypeSpecifier) absDecl - .getTypeSpecifier()).getReferences(); - } - - infoBits = ((ASTSimpleTypeSpecifier) absDecl.getTypeSpecifier()) - .getSymbol().getTypeInfo().getTypeBits(); - } else if (absDecl.getTypeSpecifier() instanceof ASTElaboratedTypeSpecifier) { - ASTElaboratedTypeSpecifier elab = (ASTElaboratedTypeSpecifier) absDecl - .getTypeSpecifier(); - xrefSymbol = elab.getSymbol(); - List elabReferences = elab.getReferences(); - newReferences = new ArrayList(elabReferences.size()); - for (int i = 0; i < elabReferences.size(); ++i) { - IASTReference r = (IASTReference) elabReferences.get(i); - newReferences.add(r); - } - if (xrefSymbol != null) - addReference(newReferences, createReference(xrefSymbol, elab - .getNameCharArray(), elab.getNameOffset())); - } - - char[] paramName = EMPTY_STRING; - if (absDecl instanceof IASTParameterDeclaration) { - paramName = ((ASTParameterDeclaration) absDecl).getNameCharArray(); - } - - ISymbol paramSymbol = pst.newSymbol(paramName, type); - if (xrefSymbol != null) { - if (absDecl.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier) - paramSymbol.setTypeSymbol(xrefSymbol.getTypeSymbol()); - else - paramSymbol.setTypeSymbol(xrefSymbol); - } - - paramSymbol.getTypeInfo().setTypeBits(infoBits); - paramSymbol.getTypeInfo().setBit(absDecl.isConst(), ITypeInfo.isConst); - paramSymbol.getTypeInfo().setBit(absDecl.isVolatile(), - ITypeInfo.isVolatile); - - List ptrs = null, arrayMods = null; - if (absDecl instanceof ASTParameterDeclaration) { - ptrs = ((ASTParameterDeclaration) absDecl).getPointerOperatorsList(); - arrayMods = ((ASTParameterDeclaration) absDecl) - .getArrayModifiersList(); - } else { - ptrs = ((ASTAbstractDeclaration) absDecl).getPointerOperatorsList(); - arrayMods = ((ASTAbstractDeclaration) absDecl).getArrayModifiersList(); - } - setPointerOperators(paramSymbol, ptrs, arrayMods); - - if (isParameter) - symbol.addParameter(paramSymbol); - else - symbol.setReturnType(paramSymbol); - - if (newReferences != null && !newReferences.isEmpty()) - references.addAll(newReferences); - - if (absDecl instanceof ASTParameterDeclaration) { - ASTParameterDeclaration parm = (ASTParameterDeclaration) absDecl; - parm.setSymbol(paramSymbol); - attachSymbolExtension(paramSymbol, parm, true); - } - } - - /** - * @param paramSymbol - * @param iterator - */ - protected void setPointerOperators(ISymbol symbol, List pointerOps, - List arrayMods) throws ASTSemanticException { - int ptrOpsSize = pointerOps.size(); - for (int i = 0; i < ptrOpsSize; i++) { - ASTPointerOperator pointerOperator = (ASTPointerOperator) pointerOps - .get(i); - if (pointerOperator == ASTPointerOperator.REFERENCE) - symbol.addPtrOperator(new ITypeInfo.PtrOp( - ITypeInfo.PtrOp.t_reference)); - else if (pointerOperator == ASTPointerOperator.POINTER) - symbol - .addPtrOperator(new ITypeInfo.PtrOp(ITypeInfo.PtrOp.t_pointer)); - else if (pointerOperator == ASTPointerOperator.CONST_POINTER) - symbol.addPtrOperator(new ITypeInfo.PtrOp( - ITypeInfo.PtrOp.t_pointer, true, false)); - else if (pointerOperator == ASTPointerOperator.VOLATILE_POINTER) - symbol.addPtrOperator(new ITypeInfo.PtrOp( - ITypeInfo.PtrOp.t_pointer, false, true)); - else if (pointerOperator == ASTPointerOperator.RESTRICT_POINTER) - symbol - .addPtrOperator(new ITypeInfo.PtrOp(ITypeInfo.PtrOp.t_pointer)); - // else - // assert false : pointerOperator; - } - int arrayModsSize = arrayMods.size(); - for (int i = 0; i < arrayModsSize; i++) { - symbol.addPtrOperator(new ITypeInfo.PtrOp(ITypeInfo.PtrOp.t_array)); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createMethod(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.lang.String, java.util.List, - * org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, - * org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, - * boolean, boolean, int, int, - * org.eclipse.cdt.core.parser.ast.IASTTemplate, boolean, boolean, - * boolean, boolean, boolean, boolean, boolean, - * org.eclipse.cdt.core.parser.ast.ASTAccessVisibility) - */ - - public IASTMethod createMethod(IASTScope scope, ITokenDuple name, - List parameters, IASTAbstractDeclaration returnType, - IASTExceptionSpecification exception, boolean isInline, - boolean isFriend, boolean isStatic, int startOffset, int startLine, - int nameOffset, int nameEndOffset, int nameLine, - IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, - boolean isVirtual, boolean isExplicit, boolean isPureVirtual, - ASTAccessVisibility visibility, List constructorChain, - boolean isFunctionDefinition, boolean hasFunctionTryBlock, - boolean hasVariableArguments) throws ASTSemanticException { - return createMethod(scope, name, parameters, returnType, exception, - isInline, isFriend, isStatic, startOffset, startLine, nameOffset, - nameEndOffset, nameLine, ownerTemplate, isConst, isVolatile, - isVirtual, isExplicit, isPureVirtual, visibility, constructorChain, - null, isFunctionDefinition, hasFunctionTryBlock, - hasVariableArguments); - } - - public IASTMethod createMethod(IASTScope scope, ITokenDuple nameDuple, - List parameters, IASTAbstractDeclaration returnType, - IASTExceptionSpecification exception, boolean isInline, - boolean isFriend, boolean isStatic, int startOffset, int startingLine, - int nameOffset, int nameEndOffset, int nameLine, - IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, - boolean isVirtual, boolean isExplicit, boolean isPureVirtual, - ASTAccessVisibility visibility, List constructorChain, - List references, boolean isFunctionDefinition, - boolean hasFunctionTryBlock, boolean hasVariableArguments) - throws ASTSemanticException { - setProblemInfo(nameDuple); - boolean isConstructor = false; - boolean isDestructor = false; - - IContainerSymbol ownerScope = scopeToSymbol(ownerTemplate != null ? (IASTScope) ownerTemplate - : scope); - - IParameterizedSymbol symbol = null; - - if (references == null) { - references = new ArrayList(); - if (nameDuple.length() > 2) // destructor - { - ITokenDuple leadingSegments = nameDuple.getLeadingSegments(); - ISymbol test = lookupQualifiedName(ownerScope, leadingSegments, - references, false); - if (test == ownerScope) - nameDuple = nameDuple.getLastSegment(); - } - } - char[] methodName = null; - List templateIdArgList = null; - //template-id? - if (nameDuple.getTemplateIdArgLists() != null) { - templateIdArgList = nameDuple.getTemplateIdArgLists()[0]; - methodName = nameDuple.extractNameFromTemplateId(); - } else { - methodName = nameDuple.toCharArray(); - } - - symbol = pst.newParameterizedSymbol(methodName, ITypeInfo.t_function); - setFunctionTypeInfoBits(isInline, isFriend, isStatic, symbol); - setMethodTypeInfoBits(symbol, isConst, isVolatile, isVirtual, isExplicit); - symbol.setHasVariableArgs(hasVariableArguments); - - symbol.prepareForParameters(parameters.size()); - if (returnType.getTypeSpecifier() != null) - setParameter(symbol, returnType, false, references); - setParameters(symbol, references, parameters); - - IASTClassSpecifier classifier = null; - if (scope instanceof IASTTemplateDeclaration) { - classifier = (IASTClassSpecifier) ((IASTTemplateDeclaration) scope) - .getOwnerScope(); - } else { - classifier = (IASTClassSpecifier) scope; - } - char[] parentName = ((ASTClassSpecifier) classifier).getNameCharArray(); - - // check constructor / destructor if no return type - if (returnType.getTypeSpecifier() == null) { - if (CharArrayUtils.indexOf(DOUBLE_COLON, parentName) != -1) { - parentName = CharArrayUtils.lastSegment(parentName, DOUBLE_COLON); - } - if (CharArrayUtils.equals(parentName, methodName)) { - isConstructor = true; - } else if (methodName[0] == '~' - && CharArrayUtils.equals(methodName, 1, methodName.length - 1, - parentName)) { //$NON-NLS-1$ - isDestructor = true; - } - } - - symbol.setIsForwardDeclaration(!isFunctionDefinition); - boolean previouslyDeclared = false; - - IParameterizedSymbol functionDeclaration = null; - - if (isFunctionDefinition || isFriend) { - int size = parameters.size(); - List functionParameters = new ArrayList(size); - // the lookup requires a list of type infos - // instead of a list of IASTParameterDeclaration - for (int i = 0; i < size; i++) { - ASTParameterDeclaration param = (ASTParameterDeclaration) parameters - .get(i); - if (param.getSymbol() == null) - handleProblem(IProblem.SEMANTICS_RELATED, param - .getNameCharArray(), param.getNameOffset(), param - .getEndingOffset(), param.getNameLineNumber(), true); - functionParameters.add(param.getSymbol().getTypeInfo()); - } - - functionDeclaration = (IParameterizedSymbol) lookupQualifiedName( - ownerScope, nameDuple, isConstructor ? ITypeInfo.t_constructor - : ITypeInfo.t_function, functionParameters, null, false, - isFriend ? LookupType.FORFRIENDSHIP : LookupType.FORDEFINITION); - - previouslyDeclared = (functionDeclaration != null) - && functionDeclaration - .isType(isConstructor ? ITypeInfo.t_constructor - : ITypeInfo.t_function); - - if (isFriend) { - if (functionDeclaration != null - && functionDeclaration - .isType(isConstructor ? ITypeInfo.t_constructor - : ITypeInfo.t_function)) { - symbol.setForwardSymbol(functionDeclaration); - // friend declaration, has no real visibility, set private - visibility = ASTAccessVisibility.PRIVATE; - } else if (ownerScope.getContainingSymbol().isType( - ITypeInfo.t_constructor) - || ownerScope.getContainingSymbol().isType( - ITypeInfo.t_function) - || ownerScope.getContainingSymbol().isType(ITypeInfo.t_block)) { - //only needs to be previously declared if we are in a local - // class - handleProblem(IProblem.SEMANTIC_ILLFORMED_FRIEND, nameDuple - .toCharArray(), nameDuple.getStartOffset(), nameDuple - .getEndOffset(), nameDuple.getLineNumber(), true); - } - - } else if (functionDeclaration != null - && functionDeclaration - .isType(isConstructor ? ITypeInfo.t_constructor - : ITypeInfo.t_function)) { - functionDeclaration.setForwardSymbol(symbol); - // set the definition visibility = declaration visibility - visibility = ((IASTMethod) (functionDeclaration.getASTExtension() - .getPrimaryDeclaration())).getVisiblity(); - } - } - - try { - if (isFriend) { - if (functionDeclaration != null) - ((IDerivableContainerSymbol) ownerScope) - .addFriend(functionDeclaration); - else - ((IDerivableContainerSymbol) ownerScope).addFriend(symbol); - } else if (!isConstructor) { - if (templateIdArgList == null) - ownerScope.addSymbol(symbol); - else - ownerScope.addTemplateId(symbol, - getTemplateArgList(templateIdArgList)); - } else { - symbol.setType(ITypeInfo.t_constructor); - ((IDerivableContainerSymbol) ownerScope).addConstructor(symbol); - } - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), nameDuple.toCharArray(), nameDuple - .getStartOffset(), nameDuple.getEndOffset(), nameDuple - .getLineNumber(), true); - } - - resolveLeftoverConstructorInitializerMembers(symbol, constructorChain); - - ASTMethod method = new ASTMethod(symbol, parameters, returnType, - exception, startOffset, startingLine, nameOffset, nameEndOffset, - nameLine, ownerTemplate, references, previouslyDeclared, - isConstructor, isDestructor, isPureVirtual, visibility, - constructorChain, hasFunctionTryBlock, isFriend, filename); - if (functionDeclaration != null && isFunctionDefinition) - attachSymbolExtension(symbol, (ASTSymbol) functionDeclaration - .getASTExtension().getPrimaryDeclaration(), false); - attachSymbolExtension(symbol, method, isFunctionDefinition); - return method; - } - - /** - * @param symbol - * @param constructorChain - */ - protected void resolveLeftoverConstructorInitializerMembers( - IParameterizedSymbol symbol, List constructorChain) - throws ASTSemanticException { - if (constructorChain != null) { - int size = constructorChain.size(); - for (int i = 0; i < size; i++) { - IASTConstructorMemberInitializer initializer = (IASTConstructorMemberInitializer) constructorChain - .get(i); - if (initializer.getNameCharArray().length > 0 - && initializer instanceof ASTConstructorMemberInitializer - && ((ASTConstructorMemberInitializer) initializer) - .requiresNameResolution()) { - ASTConstructorMemberInitializer realInitializer = ((ASTConstructorMemberInitializer) initializer); - IDerivableContainerSymbol container = (IDerivableContainerSymbol) symbol - .getContainingSymbol(); - lookupQualifiedName(container, realInitializer - .getNameCharArray(), ITypeInfo.t_any, null, - realInitializer.getNameOffset(), realInitializer - .getReferences(), false, LookupType.QUALIFIED); - // TODO try and resolve parameter references now in the - // expression list - } - } - } - } - - /** - * @param symbol - * @param isConst - * @param isVolatile - * @param isConstructor - * @param isDestructor - * @param isVirtual - * @param isExplicit - * @param isPureVirtual - */ - protected void setMethodTypeInfoBits(IParameterizedSymbol symbol, - boolean isConst, boolean isVolatile, boolean isVirtual, - boolean isExplicit) { - symbol.getTypeInfo().setBit(isConst, ITypeInfo.isConst); - symbol.getTypeInfo().setBit(isVolatile, ITypeInfo.isVolatile); - symbol.getTypeInfo().setBit(isVirtual, ITypeInfo.isVirtual); - symbol.getTypeInfo().setBit(isExplicit, ITypeInfo.isExplicit); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createVariable(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.lang.String, boolean, - * org.eclipse.cdt.core.parser.ast.IASTInitializerClause, - * org.eclipse.cdt.core.parser.ast.IASTExpression, - * org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, boolean, - * boolean, boolean, boolean, int, int) - */ - public IASTVariable createVariable(IASTScope scope, ITokenDuple name, - boolean isAuto, IASTInitializerClause initializerClause, - IASTExpression bitfieldExpression, - IASTAbstractDeclaration abstractDeclaration, boolean isMutable, - boolean isExtern, boolean isRegister, boolean isStatic, - int startingOffset, int startingLine, int nameOffset, - int nameEndOffset, int nameLine, IASTExpression constructorExpression, - char[] fn) throws ASTSemanticException { - setFilename(fn); - List references = new ArrayList(); - IContainerSymbol ownerScope = scopeToSymbol(scope); - - if (name == null) - handleProblem(IProblem.SEMANTIC_NAME_NOT_PROVIDED, null, - startingOffset, startingOffset + 1, startingLine, true); - - if (name.getSegmentCount() > 1) { - ISymbol symbol = lookupQualifiedName(ownerScope, name - .getLeadingSegments(), references, false, - LookupType.FORPARENTSCOPE); - IContainerSymbol parentScope = null; - - if (symbol instanceof IContainerSymbol) - parentScope = (IContainerSymbol) symbol; - else if (symbol instanceof IDeferredTemplateInstance) - parentScope = ((IDeferredTemplateInstance) symbol).getTemplate() - .getTemplatedSymbol(); - - if ((parentScope != null) - && ((parentScope.getType() == ITypeInfo.t_class) - || (parentScope.getType() == ITypeInfo.t_struct) || (parentScope - .getType() == ITypeInfo.t_union))) { - IASTScope fieldParentScope = (IASTScope) parentScope - .getASTExtension().getPrimaryDeclaration(); - - ITokenDuple newName = name.getLastSegment(); - - return createField(fieldParentScope, newName, isAuto, - initializerClause, bitfieldExpression, abstractDeclaration, - isMutable, isExtern, isRegister, isStatic, startingOffset, - startingLine, newName.getStartOffset(), nameEndOffset, - nameLine, constructorExpression, ASTAccessVisibility.PRIVATE, - references, fn); - } - } - - ISymbol newSymbol = cloneSimpleTypeSymbol(name.getFirstToken() - .getCharImage(), abstractDeclaration, references); - if (newSymbol == null) - handleProblem(IProblem.SEMANTICS_RELATED, name.toCharArray()); - - setVariableTypeInfoBits(isAuto, abstractDeclaration, isMutable, isExtern, - isRegister, isStatic, newSymbol); - - int numPtrOps = ((ASTAbstractDeclaration) abstractDeclaration) - .getNumArrayModifiers() - + ((ASTAbstractDeclaration) abstractDeclaration) - .getNumPointerOperators(); - newSymbol.preparePtrOperatros(numPtrOps); - setPointerOperators(newSymbol, - ((ASTAbstractDeclaration) abstractDeclaration) - .getPointerOperatorsList(), - ((ASTAbstractDeclaration) abstractDeclaration) - .getArrayModifiersList()); - - newSymbol.setIsForwardDeclaration(isStatic || isExtern); - boolean previouslyDeclared = false; - if (!isStatic) { - ISymbol variableDeclaration = lookupQualifiedName(ownerScope, name - .toCharArray(), null, false, LookupType.UNQUALIFIED); - - if (variableDeclaration != null - && newSymbol.getType() == variableDeclaration.getType()) { - TypeInfoProvider provider = pst.getTypeInfoProvider(); - - ITypeInfo newInfo = newSymbol.getTypeInfo().getFinalType(provider); - ITypeInfo varInfo = variableDeclaration.getTypeInfo().getFinalType( - provider); - - if (newInfo.equals(varInfo)) { - variableDeclaration.setForwardSymbol(newSymbol); - previouslyDeclared = true; - } - provider.returnTypeInfo(newInfo); - provider.returnTypeInfo(varInfo); - } - } - try { - ownerScope.addSymbol(newSymbol); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), - name.getFirstToken().getCharImage(), name.getFirstToken() - .getOffset(), name.getFirstToken().getEndOffset(), name - .getFirstToken().getLineNumber(), true); - } - - ASTVariable variable = new ASTVariable(newSymbol, abstractDeclaration, - initializerClause, bitfieldExpression, startingOffset, - startingLine, nameOffset, nameEndOffset, nameLine, references, - constructorExpression, previouslyDeclared, filename); - if (variable.getInitializerClause() != null) { - variable.getInitializerClause().setOwnerVariableDeclaration(variable); - addDesignatorReferences((ASTInitializerClause) variable - .getInitializerClause()); - } - - attachSymbolExtension(newSymbol, variable, !isStatic); - return variable; - } - - /** - * @param clause - */ - protected void addDesignatorReferences(ASTInitializerClause clause) { - if (clause.getKind() == IASTInitializerClause.Kind.DESIGNATED_INITIALIZER_LIST - || clause.getKind() == IASTInitializerClause.Kind.DESIGNATED_ASSIGNMENT_EXPRESSION) { - ISymbol variableSymbol = ((ASTVariable) clause - .getOwnerVariableDeclaration()).getSymbol(); - ISymbol currentSymbol = variableSymbol.getTypeSymbol(); - if (currentSymbol == null) - return; - - ITypeInfo currentTypeInfo = TypeInfoProvider.newTypeInfo(currentSymbol - .getTypeInfo()); - List designators = clause.getDesignatorList(); - int size = designators.size(); - for (int i = 0; i < size; i++) { - ASTDesignator designator = (ASTDesignator) designators.get(i); - if (designator.getKind() == IASTDesignator.DesignatorKind.FIELD) { - ISymbol lookup = null; - if (!(currentSymbol instanceof IContainerSymbol)) - break; - - try { - lookup = ((IContainerSymbol) currentSymbol).lookup(designator - .fieldNameCharArray()); - } catch (ParserSymbolTableException e) { - break; - } - - if (lookup == null - || lookup.getContainingSymbol() != currentSymbol) - break; - - try { - if (lookup != null) - addReference(clause.getReferences(), createReference( - lookup, designator.fieldNameCharArray(), designator - .fieldOffset())); - } catch (ASTSemanticException e1) { - // error - } - - // we have found the correct field - currentTypeInfo = TypeInfoProvider.newTypeInfo(lookup - .getTypeInfo()); - if (lookup.getTypeInfo() == null) - break; - currentSymbol = lookup.getTypeSymbol(); - - } else if (designator.getKind() == IASTDesignator.DesignatorKind.SUBSCRIPT) - currentTypeInfo.applyOperatorExpression(SUBSCRIPT); - } - - } - - if (clause.getKind() == IASTInitializerClause.Kind.DESIGNATED_INITIALIZER_LIST - || clause.getKind() == IASTInitializerClause.Kind.INITIALIZER_LIST) { - List subInitializers = clause.getInitializersList(); - int size = subInitializers.size(); - for (int i = 0; i < size; i++) - addDesignatorReferences((ASTInitializerClause) subInitializers - .get(i)); - } - } - - protected void setVariableTypeInfoBits(boolean isAuto, - IASTAbstractDeclaration abstractDeclaration, boolean isMutable, - boolean isExtern, boolean isRegister, boolean isStatic, - ISymbol newSymbol) { - newSymbol.getTypeInfo().setBit(isMutable, ITypeInfo.isMutable); - newSymbol.getTypeInfo().setBit(isAuto, ITypeInfo.isAuto); - newSymbol.getTypeInfo().setBit(isExtern, ITypeInfo.isExtern); - newSymbol.getTypeInfo().setBit(isRegister, ITypeInfo.isRegister); - newSymbol.getTypeInfo().setBit(isStatic, ITypeInfo.isStatic); - newSymbol.getTypeInfo().setBit(abstractDeclaration.isConst(), - ITypeInfo.isConst); - newSymbol.getTypeInfo().setBit(abstractDeclaration.isVolatile(), - ITypeInfo.isVolatile); - } - - protected ISymbol cloneSimpleTypeSymbol(char[] name, - IASTAbstractDeclaration abstractDeclaration, List references) - throws ASTSemanticException { - // assert abstractDeclaration.getTypeSpecifier() != null : this; - ISymbol newSymbol = null; - ISymbol symbolToBeCloned = null; - if (abstractDeclaration.getTypeSpecifier() instanceof ASTSimpleTypeSpecifier) { - symbolToBeCloned = ((ASTSimpleTypeSpecifier) abstractDeclaration - .getTypeSpecifier()).getSymbol(); - if (references != null) { - List absRefs = ((ASTSimpleTypeSpecifier) abstractDeclaration - .getTypeSpecifier()).getReferences(); - for (int i = 0; i < absRefs.size(); ++i) { - IASTReference r = (IASTReference) absRefs.get(i); - references.add(r); - } - } - } else if (abstractDeclaration.getTypeSpecifier() instanceof ASTClassSpecifier) { - symbolToBeCloned = pst.newSymbol(name, ITypeInfo.t_type); - symbolToBeCloned - .setTypeSymbol(((ASTClassSpecifier) abstractDeclaration - .getTypeSpecifier()).getSymbol()); - } else if (abstractDeclaration.getTypeSpecifier() instanceof ASTElaboratedTypeSpecifier) { - ASTElaboratedTypeSpecifier elab = ((ASTElaboratedTypeSpecifier) abstractDeclaration - .getTypeSpecifier()); - symbolToBeCloned = pst.newSymbol(name, ITypeInfo.t_type); - symbolToBeCloned.setTypeSymbol(elab.getSymbol()); - if (elab.getSymbol() != null && references != null) - addReference(references, createReference(elab.getSymbol(), elab - .getNameCharArray(), elab.getNameOffset())); - } else if (abstractDeclaration.getTypeSpecifier() instanceof ASTEnumerationSpecifier) { - symbolToBeCloned = pst.newSymbol(name, ITypeInfo.t_type); - symbolToBeCloned - .setTypeSymbol(((ASTEnumerationSpecifier) abstractDeclaration - .getTypeSpecifier()).getSymbol()); - } - if (symbolToBeCloned != null) { - newSymbol = (ISymbol) symbolToBeCloned.clone(); - newSymbol.setName(name); - } - - return newSymbol; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createField(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.lang.String, boolean, - * org.eclipse.cdt.core.parser.ast.IASTInitializerClause, - * org.eclipse.cdt.core.parser.ast.IASTExpression, - * org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, boolean, - * boolean, boolean, boolean, int, int, - * org.eclipse.cdt.core.parser.ast.ASTAccessVisibility) - */ - public IASTField createField(IASTScope scope, ITokenDuple name, - boolean isAuto, IASTInitializerClause initializerClause, - IASTExpression bitfieldExpression, - IASTAbstractDeclaration abstractDeclaration, boolean isMutable, - boolean isExtern, boolean isRegister, boolean isStatic, - int startingOffset, int startingLine, int nameOffset, - int nameEndOffset, int nameLine, IASTExpression constructorExpression, - ASTAccessVisibility visibility, char[] fn) throws ASTSemanticException { - return createField(scope, name, isAuto, initializerClause, - bitfieldExpression, abstractDeclaration, isMutable, isExtern, - isRegister, isStatic, startingOffset, startingLine, nameOffset, - nameEndOffset, nameLine, constructorExpression, visibility, null, - fn); - } - - public IASTField createField(IASTScope scope, ITokenDuple name, - boolean isAuto, IASTInitializerClause initializerClause, - IASTExpression bitfieldExpression, - IASTAbstractDeclaration abstractDeclaration, boolean isMutable, - boolean isExtern, boolean isRegister, boolean isStatic, - int startingOffset, int startingLine, int nameOffset, - int nameEndOffset, int nameLine, IASTExpression constructorExpression, - ASTAccessVisibility visibility, List references, char[] fn) - throws ASTSemanticException { - setFilename(fn); - IContainerSymbol ownerScope = scopeToSymbol(scope); - - char[] image = (name != null) ? name.toCharArray() : EMPTY_STRING; - - if (references == null) - references = new ArrayList(); - ISymbol newSymbol = cloneSimpleTypeSymbol(image, abstractDeclaration, - references); - if (newSymbol == null) - handleProblem(IProblem.SEMANTICS_RELATED, image); - - setVariableTypeInfoBits(isAuto, abstractDeclaration, isMutable, isExtern, - isRegister, isStatic, newSymbol); - setPointerOperators(newSymbol, - ((ASTAbstractDeclaration) abstractDeclaration) - .getPointerOperatorsList(), - ((ASTAbstractDeclaration) abstractDeclaration) - .getArrayModifiersList()); - - newSymbol.setIsForwardDeclaration(isStatic); - boolean previouslyDeclared = false; - if (!isStatic && !image.equals(EMPTY_STRING)) { - ISymbol fieldDeclaration = lookupQualifiedName(ownerScope, image, - null, false, LookupType.FORDEFINITION); - - if (fieldDeclaration != null - && newSymbol.getType() == fieldDeclaration.getType()) { - TypeInfoProvider provider = pst.getTypeInfoProvider(); - - ITypeInfo newInfo = newSymbol.getTypeInfo().getFinalType(provider); - ITypeInfo fieldInfo = fieldDeclaration.getTypeInfo().getFinalType( - provider); - - if (newInfo.equals(fieldInfo)) { - previouslyDeclared = true; - fieldDeclaration.setForwardSymbol(newSymbol); - // set the definition visibility = declaration visibility - visibility = ((IASTField) fieldDeclaration.getASTExtension() - .getPrimaryDeclaration()).getVisiblity(); - } - provider.returnTypeInfo(newInfo); - provider.returnTypeInfo(fieldInfo); - } - } - - try { - ownerScope.addSymbol(newSymbol); - } catch (ParserSymbolTableException e) { - if (name == null) - handleProblem(e.createProblemID(), image); - else - handleProblem(e.createProblemID(), image, name.getStartOffset(), - name.getEndOffset(), name.getLineNumber(), true); - } - - ASTField field = new ASTField(newSymbol, abstractDeclaration, - initializerClause, bitfieldExpression, startingOffset, - startingLine, nameOffset, nameEndOffset, nameLine, references, - previouslyDeclared, constructorExpression, visibility, filename); - attachSymbolExtension(newSymbol, field, !isStatic); - return field; - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.util.List, boolean, int) - */ - public IASTTemplateDeclaration createTemplateDeclaration(IASTScope scope, - List templateParameters, boolean exported, int startingOffset, - int startingLine, char[] fn) throws ASTSemanticException { - setFilename(fn); - ITemplateSymbol template = pst - .newTemplateSymbol(ParserSymbolTable.EMPTY_NAME_ARRAY); - - // the lookup requires a list of type infos - // instead of a list of IASTParameterDeclaration - int size = templateParameters.size(); - for (int i = 0; i < size; i++) { - ASTTemplateParameter param = (ASTTemplateParameter) templateParameters - .get(i); - try { - template.addTemplateParameter(param.getSymbol()); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), param.getNameCharArray(), - startingOffset, -1, startingLine, true); - } - } - - ASTTemplateDeclaration ast = new ASTTemplateDeclaration(template, scope, - templateParameters, filename); - ast.setStartingOffsetAndLineNumber(startingOffset, startingLine); - attachSymbolExtension(template, ast, false); - - return ast; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateParameter(org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind, - * java.lang.String, java.lang.String, - * org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration, - * java.util.List) - */ - public IASTTemplateParameter createTemplateParameter(ParamKind kind, - char[] identifier, IASTTypeId defaultValue, - IASTParameterDeclaration parameter, List parms, - IASTCodeScope parameterScope, int startingOffset, int startingLine, - int nameOffset, int nameEndOffset, int nameLine, int endingOffset, - int endingLine, char[] fn) throws ASTSemanticException { - //TODO filename - ISymbol symbol = null; - - TypeInfoProvider provider = pst.getTypeInfoProvider(); - provider.beginTypeConstruction(); - - if (defaultValue != null) { - provider.setDefaultObj(((ASTTypeId) defaultValue).getTypeSymbol() - .getTypeInfo()); - } - if (kind == ParamKind.TEMPLATE_LIST) { - ITemplateSymbol template = pst.newTemplateSymbol(identifier); - provider.setType(ITypeInfo.t_templateParameter); - provider.setTemplateParameterType(ITypeInfo.t_template); - template.setTypeInfo(provider.completeConstruction()); - int size = parms.size(); - for (int i = 0; i < size; i++) { - ASTTemplateParameter param = (ASTTemplateParameter) parms.get(i); - try { - template.addTemplateParameter(param.getSymbol()); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), param.getNameCharArray(), - param.getStartingOffset(), param.getEndingOffset(), param - .getStartingLine(), true); //$NON-NLS-1$ - } - } - symbol = template; - } else { - - if (kind == ParamKind.CLASS || kind == ParamKind.TYPENAME) { - // to allow for template parameter qualified typedefs - // i.e. typedef typename T::some_type some_type; - // symbol = pst.newSymbol( identifier ); - symbol = pst.newUndefinedTemplateSymbol(identifier); - provider.setType(ITypeInfo.t_templateParameter); - provider.setTemplateParameterType(ITypeInfo.t_typeName); - symbol.setTypeInfo(provider.completeConstruction()); - } else /* ParamKind.PARAMETER */{ - symbol = cloneSimpleTypeSymbol( - ((ASTParameterDeclaration) parameter).getNameCharArray(), - parameter, null); - provider.setTemplateParameterType(symbol.getType()); - provider.setType(ITypeInfo.t_templateParameter); - provider.setTypeSymbol(symbol.getTypeSymbol()); - ITypeInfo info = provider.completeConstruction(); - info.addPtrOperator(symbol.getPtrOperators()); - info.setTypeBits(symbol.getTypeInfo().getTypeBits()); - symbol.setTypeInfo(info); - } - } - - IContainerSymbol codeScope = ((ASTCodeScope) parameterScope) - .getContainerSymbol(); - try { - codeScope.addSymbol(symbol); - } catch (ParserSymbolTableException e) { - } - - ASTTemplateParameter ast = new ASTTemplateParameter(symbol, defaultValue, - parameter, parms, startingOffset, startingLine, nameOffset, - nameEndOffset, nameLine, endingOffset, endingLine, fn); - - attachSymbolExtension(symbol, ast, false); - - return ast; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateInstantiation(org.eclipse.cdt.core.parser.ast.IASTScope, - * int) - */ - public IASTTemplateInstantiation createTemplateInstantiation( - IASTScope scope, int startingOffset, int startingLine, char[] fn) { - ASTTemplateInstantiation inst = new ASTTemplateInstantiation(scope, fn); - inst.setStartingOffsetAndLineNumber(startingOffset, startingLine); - return inst; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTemplateSpecialization(org.eclipse.cdt.core.parser.ast.IASTScope, - * int) - */ - public IASTTemplateSpecialization createTemplateSpecialization( - IASTScope scope, int startingOffset, int startingLine, char[] fn) { - ITemplateSymbol template = pst - .newTemplateSymbol(ParserSymbolTable.EMPTY_NAME_ARRAY); - - ASTTemplateSpecialization ast = new ASTTemplateSpecialization(template, - scope, fn); - ast.setStartingOffsetAndLineNumber(startingOffset, startingLine); - attachSymbolExtension(template, ast, false); - - return ast; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypedef(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.lang.String, - * org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, int, int) - */ - public IASTTypedefDeclaration createTypedef(IASTScope scope, char[] name, - IASTAbstractDeclaration mapping, int startingOffset, int startingLine, - int nameOffset, int nameEndOffset, int nameLine, char[] fn) - throws ASTSemanticException { - IContainerSymbol containerSymbol = scopeToSymbol(scope); - ISymbol typeSymbol = cloneSimpleTypeSymbol(name, mapping, null); - - if (typeSymbol == null) - handleProblem(scope, IProblem.SEMANTICS_RELATED, name, nameOffset, - nameEndOffset, nameLine, true); - - setPointerOperators(typeSymbol, ((ASTAbstractDeclaration) mapping) - .getPointerOperatorsList(), ((ASTAbstractDeclaration) mapping) - .getArrayModifiersList()); - - if (typeSymbol.getType() != ITypeInfo.t_type) { - ISymbol newSymbol = pst.newSymbol(name, ITypeInfo.t_type); - newSymbol.getTypeInfo().setBit(true, ITypeInfo.isTypedef); - newSymbol.setTypeSymbol(typeSymbol); - typeSymbol = newSymbol; - } else { - typeSymbol.getTypeInfo().setBit(true, ITypeInfo.isTypedef); - } - - List references = new ArrayList(); - if (mapping.getTypeSpecifier() instanceof ASTSimpleTypeSpecifier) { - List mappingReferences = ((ASTSimpleTypeSpecifier) mapping - .getTypeSpecifier()).getReferences(); - if (mappingReferences != null && !mappingReferences.isEmpty()) { - for (int i = 0; i < mappingReferences.size(); ++i) { - IASTReference r = (IASTReference) mappingReferences.get(i); - references.add(r); - } - } - } - - try { - containerSymbol.addSymbol(typeSymbol); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), name, nameOffset, nameEndOffset, - nameLine, true); - } - ASTTypedef d = new ASTTypedef(typeSymbol, mapping, startingOffset, - startingLine, nameOffset, nameEndOffset, nameLine, references, - filename); - attachSymbolExtension(typeSymbol, d, true); - return d; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypeSpecDeclaration(org.eclipse.cdt.core.parser.ast.IASTScope, - * org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier, - * org.eclipse.cdt.core.parser.ast.IASTTemplate, int, int) - */ - public IASTAbstractTypeSpecifierDeclaration createTypeSpecDeclaration( - IASTScope scope, IASTTypeSpecifier typeSpecifier, - IASTTemplate template, int startingOffset, int startingLine, - int endingOffset, int endingLine, boolean isFriend, char[] fn) { - return new ASTAbstractTypeSpecifierDeclaration(scopeToSymbol(scope), - typeSpecifier, template, startingOffset, startingLine, - endingOffset, endingLine, isFriend, fn); - } - - public IASTElaboratedTypeSpecifier createElaboratedTypeSpecifier( - IASTScope scope, ASTClassKind kind, ITokenDuple name, - int startingOffset, int startingLine, int endOffset, int endingLine, - boolean isForewardDecl, boolean isFriend) throws ASTSemanticException { - setProblemInfo(name); - IContainerSymbol currentScopeSymbol = scopeToSymbol(scope); - IContainerSymbol originalScope = currentScopeSymbol; - - ITypeInfo.eType pstType = classKindToTypeInfo(kind); - List references = new ArrayList(); - IToken nameToken = name.getFirstToken(); - char[] newSymbolName = EMPTY_STRING; - List templateIdArgList = null; - boolean isTemplateId = false; - if (name.getSegmentCount() != 1) // qualified name - { - ITokenDuple containerSymbolName = name.getLeadingSegments(); - if (containerSymbolName == null) { - //null means globally qualified - currentScopeSymbol = currentScopeSymbol.getSymbolTable() - .getCompilationUnit(); - } else { - currentScopeSymbol = (IContainerSymbol) lookupQualifiedName( - currentScopeSymbol, containerSymbolName, references, true); - } - if (currentScopeSymbol == null) - handleProblem(IProblem.SEMANTIC_NAME_NOT_FOUND, containerSymbolName - .toCharArray(), containerSymbolName.getFirstToken() - .getOffset(), containerSymbolName.getLastToken() - .getEndOffset(), containerSymbolName.getLastToken() - .getLineNumber(), true); - nameToken = name.getLastSegment().getFirstToken(); - } - //template-id - List[] array = name.getTemplateIdArgLists(); - if (array != null) { - isTemplateId = true; - templateIdArgList = array[array.length - 1]; - } - newSymbolName = nameToken.getCharImage(); - ISymbol checkSymbol = null; - if (!isTemplateId) { - try { - if (isFriend && isForewardDecl - && currentScopeSymbol instanceof IDerivableContainerSymbol) { - checkSymbol = ((IDerivableContainerSymbol) currentScopeSymbol) - .lookupForFriendship(newSymbolName); - } else { - if (!isForewardDecl) - checkSymbol = currentScopeSymbol.elaboratedLookup(pstType, - newSymbolName); // for using - goes outside scope with - // filter - else - checkSymbol = currentScopeSymbol.lookupMemberForDefinition( - newSymbolName, pstType); // for declaring - stays inside - // scope with filter - } - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), nameToken.getCharImage(), - nameToken.getOffset(), nameToken.getEndOffset(), nameToken - .getLineNumber(), true); - } - } - List args = null; - if (isTemplateId) { - args = getTemplateArgList(templateIdArgList); - } - if (scope instanceof IASTTemplateInstantiation) { - if (isTemplateId) { - checkSymbol = pst.newDerivableContainerSymbol(newSymbolName, - pstType); - try { - currentScopeSymbol.addTemplateId(checkSymbol, args); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), nameToken.getCharImage(), - nameToken.getOffset(), nameToken.getEndOffset(), nameToken - .getLineNumber(), true); - } - } else { - handleProblem(IProblem.SEMANTIC_INVALID_TEMPLATE, nameToken - .getCharImage()); - } - checkSymbol = ((ASTTemplateInstantiation) scope).getInstanceSymbol(); - } else if (checkSymbol == null) { - checkSymbol = pst.newDerivableContainerSymbol(newSymbolName, pstType); - checkSymbol.setIsForwardDeclaration(true); - try { - if (isFriend && isForewardDecl) { - ((IDerivableContainerSymbol) originalScope) - .addFriend(checkSymbol); - } else { - if (!isTemplateId) - currentScopeSymbol.addSymbol(checkSymbol); - else - currentScopeSymbol.addTemplateId(checkSymbol, args); - } - } catch (ParserSymbolTableException e1) { - handleProblem(e1.createProblemID(), nameToken.getCharImage(), - nameToken.getOffset(), nameToken.getEndOffset(), nameToken - .getLineNumber(), true); - } - ASTElaboratedTypeSpecifier elab = new ASTElaboratedTypeSpecifier( - checkSymbol, kind, startingOffset, startingLine, name - .getFirstToken().getOffset(), name.getLastToken() - .getEndOffset(), name.getLastToken().getLineNumber(), - endOffset, endingLine, references, isForewardDecl, filename); - attachSymbolExtension(checkSymbol, elab, !isForewardDecl); - return elab; - } else if (isFriend && isForewardDecl) { - ((IDerivableContainerSymbol) originalScope).addFriend(checkSymbol); - } - if (checkSymbol != null) { - if (scope instanceof IASTTemplateInstantiation) { - addReference(references, createReference(checkSymbol, - newSymbolName, nameToken.getOffset())); - } - if (checkSymbol instanceof ITemplateSymbol) { - checkSymbol = ((ITemplateSymbol) checkSymbol).getTemplatedSymbol(); - } - if (checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTClassSpecifier - || checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTEnumerationSpecifier - || checkSymbol.getASTExtension().getPrimaryDeclaration() instanceof IASTElaboratedTypeSpecifier) { - ASTElaboratedTypeSpecifier elab = new ASTElaboratedTypeSpecifier( - checkSymbol, kind, startingOffset, startingLine, name - .getFirstToken().getOffset(), name.getLastToken() - .getEndOffset(), name.getLastToken().getLineNumber(), - endOffset, endingLine, references, isForewardDecl, filename); - attachSymbolExtension(checkSymbol, elab, !isForewardDecl); - return elab; - } - } else { - handleProblem(IProblem.SEMANTIC_NAME_NOT_FOUND, newSymbolName, - nameToken.getOffset(), nameToken.getEndOffset(), nameToken - .getLineNumber(), true); - } - - // assert false : this; - return null; - } - - protected ParserSymbolTable pst; - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNamespaceAlias(org.eclipse.cdt.core.parser.ast.IASTScope, - * java.lang.String, org.eclipse.cdt.core.parser.ITokenDuple, int, int, - * int) - */ - public IASTNamespaceAlias createNamespaceAlias(IASTScope scope, - char[] identifier, ITokenDuple alias, int startingOffset, - int startingLine, int nameOffset, int nameEndOffset, int nameLine, - int endOffset, int endingLine) throws ASTSemanticException { - setProblemInfo(alias); - IContainerSymbol startingSymbol = scopeToSymbol(scope); - List references = new ArrayList(); - - ISymbol namespaceSymbol = lookupQualifiedName(startingSymbol, alias, - references, true); - - if (namespaceSymbol.getType() != ITypeInfo.t_namespace) - handleProblem(IProblem.SEMANTIC_INVALID_OVERLOAD, alias.toCharArray(), - startingOffset, endOffset, startingLine, true); - - ISymbol newSymbol = pst.newContainerSymbol(identifier, - ITypeInfo.t_namespace); - newSymbol.setForwardSymbol(namespaceSymbol); - - try { - startingSymbol.addSymbol(newSymbol); - } catch (ParserSymbolTableException e) { - handleProblem(e.createProblemID(), identifier, startingOffset, - endOffset, startingLine, true); - } - - ASTNamespaceAlias astAlias = new ASTNamespaceAlias(newSymbol, alias - .toCharArray(), (IASTNamespaceDefinition) namespaceSymbol - .getASTExtension().getPrimaryDeclaration(), startingOffset, - startingLine, nameOffset, nameEndOffset, nameLine, endOffset, - endingLine, references, filename); - attachSymbolExtension(newSymbol, astAlias, true); - return astAlias; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createNewCodeBlock(org.eclipse.cdt.core.parser.ast.IASTScope) - */ - public IASTCodeScope createNewCodeBlock(IASTScope scope) { - IContainerSymbol symbol = scopeToSymbol(scope); - - IContainerSymbol newScope = pst.newContainerSymbol(EMPTY_STRING, - ITypeInfo.t_block); - newScope.setContainingSymbol(symbol); - newScope.setIsTemplateMember(symbol.isTemplateMember()); - - ASTCodeScope codeScope = new ASTCodeScope(newScope); - attachSymbolExtension(newScope, codeScope, true); - return codeScope; - } - - public IASTScope getDeclaratorScope(IASTScope scope, ITokenDuple duple) { - if (duple != null && duple.getSegmentCount() > 1) { - - IContainerSymbol ownerScope = scopeToSymbol(scope); - ISymbol symbol; - - try { - symbol = lookupQualifiedName(ownerScope, - duple.getLeadingSegments(), null, false, - LookupType.FORDEFINITION); - } catch (ASTSemanticException e) { - return scope; - } - - IContainerSymbol parentScope = null; - - if (symbol instanceof IContainerSymbol) - parentScope = (IContainerSymbol) symbol; - else if (symbol instanceof IDeferredTemplateInstance) - parentScope = ((IDeferredTemplateInstance) symbol).getTemplate() - .getTemplatedSymbol(); - - if (parentScope != null && parentScope.getASTExtension() != null) { - if (scope instanceof IASTTemplateDeclaration - || scope instanceof IASTTemplateSpecialization) { - symbol = scopeToSymbol(scope); - if (symbol instanceof ITemplateFactory) { - symbol.setContainingSymbol(parentScope); - } - return scope; - } - return (IASTScope) parentScope.getASTExtension() - .getPrimaryDeclaration(); - } - } - - return scope; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#queryIsTypeName(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public boolean queryIsTypeName(IASTScope scope, ITokenDuple nameInQuestion) { - ISymbol lookupSymbol = null; - try { - lookupSymbol = lookupQualifiedName(scopeToSymbol(scope), - nameInQuestion, null, false); - } catch (ASTSemanticException e) { - // won't get thrown - } - if (lookupSymbol == null) - return false; - if (lookupSymbol.isType(ITypeInfo.t_type, ITypeInfo.t_enumeration) - || (lookupSymbol.isType(ITypeInfo.t_templateParameter) && lookupSymbol - .getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName) - || (lookupSymbol.getASTExtension() != null && lookupSymbol - .getASTExtension().getPrimaryDeclaration() instanceof IASTTypedefDeclaration)) { - return true; - } - return false; - } - - public IASTParameterDeclaration createParameterDeclaration(boolean isConst, - boolean isVolatile, IASTTypeSpecifier typeSpecifier, - List pointerOperators, List arrayModifiers, List parameters, - ASTPointerOperator pointerOp, char[] parameterName, - IASTInitializerClause initializerClause, int startingOffset, - int startingLine, int nameOffset, int nameEndOffset, int nameLine, - int endingOffset, int endingLine, char[] fn) { - setFilename(fn); - return new ASTParameterDeclaration(null, isConst, isVolatile, - typeSpecifier, pointerOperators, arrayModifiers, parameters, - pointerOp, parameterName, initializerClause, startingOffset, - startingLine, nameOffset, nameEndOffset, nameLine, endingOffset, - endingLine, filename); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createTypeId(org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type, - * org.eclipse.cdt.core.parser.ITokenDuple, java.util.List, - * java.util.List) - */ - public IASTTypeId createTypeId(IASTScope scope, Type kind, boolean isConst, - boolean isVolatile, boolean isShort, boolean isLong, boolean isSigned, - boolean isUnsigned, boolean isTypename, ITokenDuple name, - List pointerOps, List arrayMods, char[] completeSignature) - throws ASTSemanticException { - if (kind != Type.CLASS_OR_TYPENAME) { - IASTTypeId check = (IASTTypeId) typeIdCache.get(completeSignature); - if (check != null) - return check; - } - ASTTypeId result = new ASTTypeId(kind, name, pointerOps, arrayMods, - completeSignature, isConst, isVolatile, isUnsigned, isSigned, - isShort, isLong, isTypename); - result.setTypeSymbol(createSymbolForTypeId(scope, result)); - if (kind != Type.CLASS_OR_TYPENAME) - typeIdCache.put(completeSignature, result); - return result; - } - - /** - * @param id - * @return - */ - public static ITypeInfo.eType getTypeKind(IASTTypeId id) { - IASTSimpleTypeSpecifier.Type type = id.getKind(); - if (type == IASTSimpleTypeSpecifier.Type.BOOL) - return ITypeInfo.t_bool; - else if (type == IASTSimpleTypeSpecifier.Type._BOOL) - return ITypeInfo.t__Bool; - else if (type == IASTSimpleTypeSpecifier.Type.CHAR) - return ITypeInfo.t_char; - else if (type == IASTSimpleTypeSpecifier.Type.WCHAR_T) - return ITypeInfo.t_wchar_t; - else if (type == IASTSimpleTypeSpecifier.Type.DOUBLE) - return ITypeInfo.t_double; - else if (type == IASTSimpleTypeSpecifier.Type.FLOAT) - return ITypeInfo.t_float; - else if (type == IASTSimpleTypeSpecifier.Type.INT) - return ITypeInfo.t_int; - else if (type == IASTSimpleTypeSpecifier.Type.VOID) - return ITypeInfo.t_void; - else if (id.isShort() || id.isLong() || id.isUnsigned() || id.isSigned()) - return ITypeInfo.t_int; - else - return ITypeInfo.t_type; - } - - protected ISymbol createSymbolForTypeId(IASTScope scope, IASTTypeId id) - throws ASTSemanticException { - if (id == null) - return null; - - ASTTypeId typeId = (ASTTypeId) id; - ISymbol result = pst.newSymbol(EMPTY_STRING, CompleteParseASTFactory - .getTypeKind(id)); - - result.getTypeInfo().setBit(id.isConst(), ITypeInfo.isConst); - result.getTypeInfo().setBit(id.isVolatile(), ITypeInfo.isVolatile); - - result.getTypeInfo().setBit(id.isShort(), ITypeInfo.isShort); - result.getTypeInfo().setBit(id.isLong(), ITypeInfo.isLong); - result.getTypeInfo().setBit(id.isUnsigned(), ITypeInfo.isUnsigned); - result.getTypeInfo().setBit(id.isSigned(), ITypeInfo.isSigned); - - List refs = new ArrayList(); - if (result.getType() == ITypeInfo.t_type) { - ISymbol typeSymbol = lookupQualifiedName(scopeToSymbol(scope), typeId - .getTokenDuple(), refs, true); - if (typeSymbol == null /* || typeSymbol.getType() == TypeInfo.t_type */) { - freeReferences(refs); - handleProblem(scope, IProblem.SEMANTIC_INVALID_TYPE, typeId - .getTypeOrClassNameCharArray()); - } - result.setTypeSymbol(typeSymbol); - typeId.addReferences(refs); - } - - setPointerOperators(result, ((ASTTypeId) id).getPointerOperatorsList(), - ((ASTTypeId) id).getArrayModifiersList()); - return result; - } - - /** - * @param refs - */ - private void freeReferences(List refs) { - if (refs == null || refs.isEmpty()) - return; - refs.clear(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#signalEndOfClassSpecifier(org.eclipse.cdt.core.parser.ast.IASTClassSpecifier) - */ - public void signalEndOfClassSpecifier(IASTClassSpecifier astClassSpecifier) { - ASTClassSpecifier astImplementation = (ASTClassSpecifier) astClassSpecifier; - try { - ((IDerivableContainerSymbol) (astImplementation).getSymbol()) - .addCopyConstructor(); - } catch (ParserSymbolTableException e) { - // do nothing, this is best effort - } - - astImplementation.setProcessingUnresolvedReferences(true); - List unresolved = astImplementation.getUnresolvedReferences(); - List references = new ArrayList(); - int size = unresolved.size(); - for (int i = 0; i < size; i++) { - UnresolvedReferenceDuple duple = (UnresolvedReferenceDuple) unresolved - .get(i); - - try { - lookupQualifiedName(duple.getScope(), duple.getName(), references, - false); - } catch (ASTSemanticException ase) { - } - } - - astImplementation.setProcessingUnresolvedReferences(false); - - if (!references.isEmpty()) - astImplementation.setExtraReferences(references); - - } - - public IASTInitializerClause createInitializerClause(IASTScope scope, - IASTInitializerClause.Kind kind, IASTExpression assignmentExpression, - List initializerClauses, List designators) { - return new ASTInitializerClause(kind, assignmentExpression, - initializerClauses, designators); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#lookupSymbolInContext(org.eclipse.cdt.core.parser.ast.IASTScope, - * org.eclipse.cdt.core.parser.ITokenDuple) - */ - public IASTNode lookupSymbolInContext(IASTScope scope, ITokenDuple duple, - IASTNode reference) throws ASTNotImplementedException { - ISymbol s = null; - if (reference == null) { - try { - s = lookupQualifiedName(scopeToSymbol(scope), duple, null, false); - } catch (ASTSemanticException e) { - } - } else { - if (reference instanceof ASTExpression) { - ASTExpression expression = (ASTExpression) reference; - final char[] dupleAsCharArray = duple.toCharArray(); - if (expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION - && CharArrayUtils.equals(expression - .getIdExpressionCharArray(), dupleAsCharArray)) { - try { - s = lookupQualifiedName(scopeToSymbol(scope), duple, null, - false); - } catch (ASTSemanticException e1) { - } - } else if (expression.getExpressionKind() == IASTExpression.Kind.NEW_NEWTYPEID - || expression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID) { - s = lookupSymbolInNewExpression(scope, duple, expression); - } else if (expression.getExpressionKind() == Kind.POSTFIX_FUNCTIONCALL - && CharArrayUtils.equals(expression.getLHSExpression() - .getIdExpressionCharArray(), dupleAsCharArray)) { - try { - ISymbol symbol = getExpressionSymbol(scope, expression - .getExpressionKind(), expression.getLHSExpression(), - expression.getRHSExpression(), null, null); - if (symbol == null) - return null; - return symbol.getASTExtension().getPrimaryDeclaration(); - } catch (ASTSemanticException e) { - return null; - } - - } else { - ASTExpression ownerExpression = expression - .findOwnerExpressionForIDExpression(duple); - if (ownerExpression == null) - return null; - if (ownerExpression.getExpressionKind() - .isPostfixMemberReference()) { - try { - s = lookupQualifiedName(getSearchScope(ownerExpression - .getExpressionKind(), ownerExpression - .getLHSExpression(), scopeToSymbol(scope)), duple, - null, false); - } catch (ASTSemanticException e) { - return null; - } - } else if (ownerExpression.getExpressionKind() == IASTExpression.Kind.NEW_NEWTYPEID - || ownerExpression.getExpressionKind() == IASTExpression.Kind.NEW_TYPEID) { - s = lookupSymbolInNewExpression(scope, duple, ownerExpression); - } else { - try { - s = lookupQualifiedName(scopeToSymbol(scope), duple, null, - false); - } catch (ASTSemanticException e1) { //we'll return null - } - } - } - } - } - if (s != null && s.getASTExtension() != null) - return s.getASTExtension().getPrimaryDeclaration(); - return null; - } - - public ISymbol lookupSymbolInNewExpression(IASTScope scope, - ITokenDuple duple, ASTExpression expression) { - IContainerSymbol classSymbol = null; - try { - classSymbol = (IContainerSymbol) lookupQualifiedName( - scopeToSymbol(scope), duple, null, false); - } catch (ASTSemanticException e) { - return null; - } - if (classSymbol != null - && classSymbol.getTypeInfo().checkBit(ITypeInfo.isTypedef)) { - ITypeInfo info = classSymbol.getTypeInfo().getFinalType( - pst.getTypeInfoProvider()); - classSymbol = (IContainerSymbol) info.getTypeSymbol(); - pst.getTypeInfoProvider().returnTypeInfo(info); - } - if (classSymbol == null - || !(classSymbol instanceof IDerivableContainerSymbol)) { - return null; - } - - List parameters = new ArrayList(); - ASTNewDescriptor newDescriptor = (ASTNewDescriptor) expression - .getNewExpressionDescriptor(); - List newInitializerExpressions = newDescriptor - .getNewInitializerExpressionsList(); - int size = newInitializerExpressions.size(); - for (int i = 0; i < size; i++) { - ASTExpression expressionList = (ASTExpression) newInitializerExpressions - .get(i); - while (expressionList != null) { - parameters.add(expressionList.getResultType().getResult()); - if (expressionList.getExpressionKind() == IASTExpression.Kind.EXPRESSIONLIST) - expressionList = (ASTExpression) expressionList - .getRHSExpression(); - else - expressionList = null; - } - } - - try { - return ((IDerivableContainerSymbol) classSymbol) - .lookupConstructor(parameters); - } catch (ParserSymbolTableException e1) { - //fall out and return null - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#getNodeForThisExpression(org.eclipse.cdt.core.parser.ast.IASTExpression) - */ - public IASTNode expressionToMostPreciseASTNode(IASTScope scope, - IASTExpression expression) { - if (expression == null) - return null; - if (expression.getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION) { - if (expression instanceof ASTExpression) { - try { - return lookupSymbolInContext( - scope, - ((ASTIdExpression) expression).getIdExpressionTokenDuple(), - null); - } catch (ASTNotImplementedException e) { - // assert false : e; - } - } - } - - return expression; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#validateIndirectMemberOperation(org.eclipse.cdt.core.parser.ast.IASTNode) - */ - public boolean validateIndirectMemberOperation(IASTNode node) { - List pointerOps = null; - TypeInfoProvider provider = pst.getTypeInfoProvider(); - ITypeInfo typeInfo = null; - if ((node instanceof ISymbolOwner)) { - ISymbol symbol = ((ISymbolOwner) node).getSymbol(); - typeInfo = symbol.getTypeInfo().getFinalType(provider); - pointerOps = typeInfo.getPtrOperators(); - provider.returnTypeInfo(typeInfo); - } else if (node instanceof ASTExpression) { - ITypeInfo info = ((ASTExpression) node).getResultType().getResult(); - if (info != null) { - typeInfo = info.getFinalType(provider); - pointerOps = typeInfo.getPtrOperators(); - provider.returnTypeInfo(typeInfo); - } - } else - return false; - - if (pointerOps == null || pointerOps.isEmpty()) - return false; - ITypeInfo.PtrOp lastOperator = (ITypeInfo.PtrOp) pointerOps - .get(pointerOps.size() - 1); - if (lastOperator.getType() == ITypeInfo.PtrOp.t_array - || lastOperator.getType() == ITypeInfo.PtrOp.t_pointer) - return true; - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#validateDirectMemberOperation(org.eclipse.cdt.core.parser.ast.IASTNode) - */ - public boolean validateDirectMemberOperation(IASTNode node) { - List pointerOps = null; - if ((node instanceof ISymbolOwner)) { - ISymbol symbol = ((ISymbolOwner) node).getSymbol(); - TypeInfoProvider provider = pst.getTypeInfoProvider(); - ITypeInfo info = symbol.getTypeInfo().getFinalType(provider); - pointerOps = info.getPtrOperators(); - provider.returnTypeInfo(info); - } else if (node instanceof ASTExpression) { - ITypeInfo info = ((ASTExpression) node).getResultType().getResult(); - if (info != null) { - TypeInfoProvider provider = pst.getTypeInfoProvider(); - info = info.getFinalType(provider); - pointerOps = info.getPtrOperators(); - provider.returnTypeInfo(info); - } - } else - return false; - - if (pointerOps == null || pointerOps.isEmpty()) - return true; - ITypeInfo.PtrOp lastOperator = (ITypeInfo.PtrOp) pointerOps - .get(pointerOps.size() - 1); - if (lastOperator.getType() == ITypeInfo.PtrOp.t_reference) - return true; - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.ast.IASTFactory#constructExpressions(boolean) - */ - public void constructExpressions(boolean flag) { - //ignore - } - - /** - * @return - */ - public boolean validateCaches() { - return (pst.getTypeInfoProvider().numAllocated() == 0); - } - - private void setProblemInfo(ITokenDuple extra) { - if (extra != null) { - this.problemStartOffset = extra.getStartOffset(); - this.problemEndOffset = extra.getEndOffset(); - this.problemLineNumber = extra.getLineNumber(); - this.filename = extra.getFilename(); - } else { - this.problemStartOffset = -1; - this.problemEndOffset = -1; - this.problemLineNumber = -1; - this.filename = EMPTY_STRING; - } - } - - // used to check if an ITypeInfo is an "integral type" based on 3.9.1-7 - private boolean isIntegralType(ITypeInfo info, boolean isPointer) { - if (isPointer) - return true; - if (info.getType() == ITypeInfo.t_bool - || info.getType() == ITypeInfo.t_char - || info.getType() == ITypeInfo.t_wchar_t - || info.getType() == ITypeInfo.t_int) - return true; - - return false; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionFactory.java deleted file mode 100644 index 49845f504c5..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; -import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; - -/** - * @author jcamelon - * - */ -public class ExpressionFactory { - - public static ASTExpression createExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, char[] literal, IASTNewExpressionDescriptor newDescriptor, List references ) - { - if( literal.length != 0 && idExpression == null ) //$NON-NLS-1$ - return new ASTLiteralExpression( kind, references, literal ); - - if( idExpression != null && lhs == null ) - return new ASTIdExpression( kind, references, idExpression ); - - if( thirdExpression != null ) - return new ASTConditionalExpression( kind, references, lhs, rhs, thirdExpression ); - - if( newDescriptor != null ) - return new ASTNewExpression( kind, references, newDescriptor, typeId ); - - if( lhs != null && rhs != null ) - return new ASTBinaryExpression( kind, references, lhs, rhs ); - - if( lhs != null && typeId != null ) - return new ASTUnaryTypeIdExpression( kind, references, lhs, typeId ); - - if( lhs != null && idExpression != null ) - return new ASTUnaryIdExpression( kind, references, lhs, idExpression ); - - if( lhs != null ) - return new ASTUnaryExpression( kind, references, lhs ); - - if( typeId != null ) - return new ASTTypeIdExpression( kind, references, typeId ); - - return new ASTEmptyExpression( kind, references ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionResult.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionResult.java deleted file mode 100644 index 88ffa19d6b8..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionResult.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.pst.TypeInfoProvider; - -/** - * @author hamer - * - */ -public class ExpressionResult { - - - private ITypeInfo result; - private boolean failedToDereference = false; - - ExpressionResult(){ - result = TypeInfoProvider.newTypeInfo(); - } - ExpressionResult(ITypeInfo result){ - this.result = result; - } -/** - * @return - */ -public ITypeInfo getResult() { - return result; -} - -/** - * @param info - */ -public void setResult(ITypeInfo info) { - result = info; -} - -/** - * @return - */ -public boolean isFailedToDereference() { - return failedToDereference; -} - -/** - * @param b - */ -public void setFailedToDereference(boolean b) { - failedToDereference = b; -} - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionResultList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionResultList.java deleted file mode 100644 index 5dccd414e82..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ExpressionResultList.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; - -/** - * @author hamer - * - */ -public class ExpressionResultList extends ExpressionResult { - private List resultList = new ArrayList(); - ExpressionResultList(){ - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ExpressionResult#getResult() - */ - public ITypeInfo getResult() { - // TODO Auto-generated method stub - return (ITypeInfo)resultList.get(0); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.complete.ExpressionResult#setResult(org.eclipse.cdt.internal.core.parser.pst.TypeInfo) - */ - public void setResult(ITypeInfo info) { - // TODO Auto-generated method stub - resultList.add(info); - } - - public void setResult( ExpressionResultList result ){ - List list = result.getResultList(); - int size = list.size(); - for( int i = 0; i < size; i++ ){ - resultList.add( list.get( i ) ); - } - } - - /** - * @return - */ - public List getResultList() { - return resultList; - } - - /** - * @param list - */ - public void setResultList(List list) { - resultList = list; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/UnresolvedReferenceDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/UnresolvedReferenceDuple.java deleted file mode 100644 index 8c9e49bc530..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/UnresolvedReferenceDuple.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.complete; - -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; - -/** - * @author jcamelon - */ -public class UnresolvedReferenceDuple { - - public UnresolvedReferenceDuple( IContainerSymbol scope, ITokenDuple name ){ - this.scope = scope; - this.name = name; - } - - private final IContainerSymbol scope; - private final ITokenDuple name; - - public IContainerSymbol getScope() - { - return scope; - } - - public ITokenDuple getName() - { - return name; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/ASTGCCSimpleTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/ASTGCCSimpleTypeSpecifier.java deleted file mode 100644 index 571a55f8170..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/ASTGCCSimpleTypeSpecifier.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.complete.gcc; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCSimpleTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSimpleTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTGCCSimpleTypeSpecifier extends ASTSimpleTypeSpecifier implements IASTGCCSimpleTypeSpecifier { - - private final IASTExpression expression; - - /** - * @param s - * @param b - * @param string - * @param references - */ - public ASTGCCSimpleTypeSpecifier(ISymbol s, boolean b, char[] string, List references, IASTExpression typeOfExpression ) { - super(s, b, string, references); - expression = typeOfExpression; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getType() - */ - public IASTSimpleTypeSpecifier.Type getType() { - if( expression != null ) return IASTGCCSimpleTypeSpecifier.Type.TYPEOF; - return super.getType(); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.gcc.IASTGCCSimpleTypeSpecifier#getTypeOfExpression() - */ - public IASTExpression getTypeOfExpression() { - return expression; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/GCCASTCompleteExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/GCCASTCompleteExtension.java deleted file mode 100644 index 67374256057..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/GCCASTCompleteExtension.java +++ /dev/null @@ -1,707 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -/* - * Created on Jun 8, 2004 - */ -package org.eclipse.cdt.internal.core.parser.ast.complete.gcc; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.cdt.core.parser.GCCKeywords; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.ASTSemanticException; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTFactory; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; -import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression; -import org.eclipse.cdt.internal.core.parser.BacktrackException; -import org.eclipse.cdt.internal.core.parser.DeclarationWrapper; -import org.eclipse.cdt.internal.core.parser.Declarator; -import org.eclipse.cdt.internal.core.parser.ast.GCCASTExtension; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTBinaryExpression; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTEmptyExpression; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSimpleTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTypeIdExpression; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTUnaryExpression; -import org.eclipse.cdt.internal.core.parser.ast.complete.ExpressionFactory; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo; -import org.eclipse.cdt.internal.core.parser.token.ImagedToken; -import org.eclipse.cdt.internal.core.parser.token.SimpleToken; -import org.eclipse.cdt.internal.core.parser.token.TokenFactory; - -/** - * @author aniefer - */ -public class GCCASTCompleteExtension extends GCCASTExtension { - - private static final char [] __BUILTIN_VA_LIST = "__builtin_va_list".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_EXPECT = "__builtin_expect".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_PREFETCH = "__builtin_prefetch".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_HUGE_VAL = "__builtin_huge_val".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_HUGE_VALF = "__builtin_huge_valf".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_HUGE_VALL = "__builtin_huge_vall".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_INF = "__builtin_inf".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_INFF = "__builtin_inff".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_INFL = "__builtin_infl".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_NAN = "__builtin_nan".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_NANF = "__builtin_nanf".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_NANL = "__builtin_nanl".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_NANS = "__builtin_nans".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_NANSF = "__builtin_nansf".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_NANSL = "__builtin_nansl".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_FFS = "__builtin_ffs".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_CLZ = "__builtin_clz".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_CTZ = "__builtin_ctz".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_POPCOUNT = "__builtin_popcount".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_PARITY = "__builtin_parity".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_FFSL = "__builtin_ffsl".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_CLZL = "__builtin_clzl".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_CTZL = "__builtin_ctzl".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_POPCOUNTL = "__builtin_popcountl".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_PARITYL = "__builtin_parityl".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_FFSLL = "__builtin_ffsll".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_CLZLL = "__builtin_clzll".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_CTZLL = "__builtin_ctzll".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_POPCOUNTLL = "__builtin_popcountll".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_PARITYLL = "__builtin_parityll".toCharArray(); //$NON-NLS-1$ - private static final char [] __BUILTIN_TYPES_COMPATIBLE_P = "__builtin_types_compatible_p".toCharArray(); //$NON-NLS-1$ - - /** - * @param mode - */ - public GCCASTCompleteExtension(ParserMode mode) { - super(mode); - } - - public boolean overrideCreateExpressionMethod() { - if( mode == ParserMode.STRUCTURAL_PARSE || mode == ParserMode.COMPLETE_PARSE ) - return true; - return false; - } - - protected IASTExpression createExpression(IASTExpression.Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, ITokenDuple idExpression, char[] literal, IASTNewExpressionDescriptor newDescriptor, List references) { - if( lhs != null && rhs != null && - (kind == IASTGCCExpression.Kind.RELATIONAL_MAX || - kind == IASTGCCExpression.Kind.RELATIONAL_MIN ) ) - { - return new ASTBinaryExpression( kind, references, lhs, rhs ){ - public String toString(){ - IASTExpression.Kind k = getExpressionKind(); - StringBuffer buffer = new StringBuffer(); - buffer.append( ASTUtil.getExpressionString( getLHSExpression() ) ); - if( k == IASTGCCExpression.Kind.RELATIONAL_MAX ) - buffer.append( " >? " ); //$NON-NLS-1$ - else - buffer.append( " Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; - - - -/** - * @author jcamelon - */ -public class ASTExpression implements IASTExpression { - - private final Kind kind; - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ - - /** - * @param kind - * @param id - */ - public ASTExpression(Kind kind ) { - this.kind = kind; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getExpressionKind() - */ - public Kind getExpressionKind() { - return kind; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLHSExpression() - */ - public IASTExpression getLHSExpression() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getRHSExpression() - */ - public IASTExpression getRHSExpression() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLiteralString() - */ - public String getLiteralString() { - return EMPTY_STRING; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId() - */ - public IASTTypeId getTypeId() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor() - */ - public IASTNewExpressionDescriptor getNewExpressionDescriptor() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getThirdExpression() - */ - public IASTExpression getThirdExpression() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#evaluateExpression() - */ - public long evaluateExpression() throws ASTExpressionEvaluationException { - // primary expressions - if( getExpressionKind() == IASTExpression.Kind.PRIMARY_INTEGER_LITERAL ) - { - try - { - if( getLiteralString().startsWith( "0x") || getLiteralString().startsWith( "0x") ) //$NON-NLS-1$ //$NON-NLS-2$ - { - return Integer.parseInt( getLiteralString().substring(2), 16 ); - } - if( getLiteralString().startsWith( "0") && getLiteralString().length() > 1 ) //$NON-NLS-1$ - return Integer.parseInt( getLiteralString().substring(1), 8 ); - return Integer.parseInt( getLiteralString() ); - } - catch( NumberFormatException nfe ) - { - throw new ASTExpressionEvaluationException(); - } - } - - if( getExpressionKind() == IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION ) - return getLHSExpression().evaluateExpression(); - // unary not - if( getExpressionKind() == IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION ) - return ( ( getLHSExpression().evaluateExpression() == 0 ) ? 1 : 0 ); - - // multiplicative expressions - if( getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY ) - return ( getLHSExpression().evaluateExpression() * getRHSExpression().evaluateExpression()) ; - if( getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_DIVIDE ) - return ( getLHSExpression().evaluateExpression() / getRHSExpression().evaluateExpression()) ; - if( getExpressionKind() == IASTExpression.Kind.MULTIPLICATIVE_MODULUS ) - return ( getLHSExpression().evaluateExpression() % getRHSExpression().evaluateExpression()) ; - // additives - if( getExpressionKind() == IASTExpression.Kind.ADDITIVE_PLUS ) - return ( getLHSExpression().evaluateExpression() + getRHSExpression().evaluateExpression()) ; - if( getExpressionKind() == IASTExpression.Kind.ADDITIVE_MINUS ) - return ( getLHSExpression().evaluateExpression() - getRHSExpression().evaluateExpression()) ; - // shift expression - if( getExpressionKind() == IASTExpression.Kind.SHIFT_LEFT ) - return ( getLHSExpression().evaluateExpression() << getRHSExpression().evaluateExpression()) ; - if( getExpressionKind() == IASTExpression.Kind.SHIFT_RIGHT ) - return ( getLHSExpression().evaluateExpression() >> getRHSExpression().evaluateExpression()) ; - // relational - if( getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHAN ) - return ( getLHSExpression().evaluateExpression() < getRHSExpression().evaluateExpression() ? 1 : 0 ) ; - if( getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHAN ) - return ( getLHSExpression().evaluateExpression() > getRHSExpression().evaluateExpression() ? 1 : 0 ) ; - if( getExpressionKind() == IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO ) - return ( getLHSExpression().evaluateExpression() <= getRHSExpression().evaluateExpression() ? 1 : 0 ) ; - if( getExpressionKind() == IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO ) - return ( getLHSExpression().evaluateExpression() >= getRHSExpression().evaluateExpression() ? 1 : 0 ) ; - // equality - if( getExpressionKind() == IASTExpression.Kind.EQUALITY_EQUALS ) - return ( getLHSExpression().evaluateExpression() == getRHSExpression().evaluateExpression() ? 1 : 0 ) ; - if( getExpressionKind() == IASTExpression.Kind.EQUALITY_NOTEQUALS ) - return ( getLHSExpression().evaluateExpression() != getRHSExpression().evaluateExpression() ? 1 : 0 ) ; - // and - if( getExpressionKind() == IASTExpression.Kind.ANDEXPRESSION ) - return ( getLHSExpression().evaluateExpression() & getRHSExpression().evaluateExpression() ) ; - // xor - if( getExpressionKind() == IASTExpression.Kind.EXCLUSIVEOREXPRESSION ) - return ( getLHSExpression().evaluateExpression() ^ getRHSExpression().evaluateExpression() ) ; - // or - if( getExpressionKind() == IASTExpression.Kind.INCLUSIVEOREXPRESSION ) - return ( getLHSExpression().evaluateExpression() | getRHSExpression().evaluateExpression() ) ; - // logical and - if( getExpressionKind() == IASTExpression.Kind.LOGICALANDEXPRESSION ) - return( ( getLHSExpression().evaluateExpression() != 0 ) && ( getRHSExpression().evaluateExpression() != 0 ) ) ? 1 : 0 ; - // logical or - if( getExpressionKind() == IASTExpression.Kind.LOGICALOREXPRESSION ) - return( ( getLHSExpression().evaluateExpression() != 0 ) || ( getRHSExpression().evaluateExpression() != 0 ) ) ? 1 : 0 ; - - if( getExpressionKind() == IASTExpression.Kind.CONDITIONALEXPRESSION ) - { - return ( getLHSExpression().evaluateExpression() != 0 ) ? getRHSExpression().evaluateExpression() : getThirdExpression().evaluateExpression(); - } - - throw new ASTExpressionEvaluationException(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getIdExpression() - */ - public String getIdExpression() - { - return null; - } - public char[] getIdExpressionCharArray(){ - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#reconcileReferences() - */ - public void reconcileReferences() throws ASTNotImplementedException - { - throw new ASTNotImplementedException(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#purgeReferences() - */ - public void purgeReferences() throws ASTNotImplementedException - { - throw new ASTNotImplementedException(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind[], org.eclipse.cdt.core.parser.ast.IASTNode) - */ - public ILookupResult lookup(String prefix, LookupKind[] k, IASTNode context, IASTExpression functionParameters) throws LookupError, ASTNotImplementedException { - // Not provided in this mode - throw new ASTNotImplementedException(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#freeReferences() - */ - public void freeReferences() { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffsetAndLineNumber(int, int) - */ - public void setStartingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffsetAndLineNumber(int, int) - */ - public void setEndingOffsetAndLineNumber(int offset, int lineNumber) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public int getStartingOffset() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public int getEndingOffset() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public int getStartingLine() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public int getEndingLine() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - // TODO Auto-generated method stub - return null; - } - - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpressionInitializerClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpressionInitializerClause.java deleted file mode 100644 index 3d0e4fb61fe..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTExpressionInitializerClause.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; - -/** - * @author jcamelon - */ -public class ASTExpressionInitializerClause extends ASTInitializerClause - implements - IASTInitializerClause { - - private final IASTExpression expression; - - /** - * @param kind - * @param assignmentExpression - */ - public ASTExpressionInitializerClause(Kind kind, IASTExpression assignmentExpression) { - super( kind ); - this.expression = assignmentExpression; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression() - */ - public IASTExpression getAssigmentExpression() { - return expression; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTField.java deleted file mode 100644 index 34f36e4fc45..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTField.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTScope; - -/** - * @author jcamelon - * - */ -public class ASTField extends ASTVariable implements IASTField -{ - private final ASTAccessVisibility visibility; - - /** - * @param scope - * @param name - * @param isAuto - * @param initializerClause - * @param bitfieldExpression - * @param abstractDeclaration - * @param isMutable - * @param isExtern - * @param isRegister - * @param isStatic - */ - public ASTField(IASTScope scope, char[] name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression, ASTAccessVisibility visibility, char [] filename) - { - super( - scope, - name, - isAuto, - initializerClause, - bitfieldExpression, - abstractDeclaration, - isMutable, - isExtern, - isRegister, - isStatic, startingOffset, startLine, nameOffset, nameEndOffset, nameLine, constructorExpression, filename ); - this.visibility = visibility; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMember#getVisiblity() - */ - public ASTAccessVisibility getVisiblity() - { - return visibility; - } - - public void acceptElement( ISourceElementRequestor requestor ) - { - try - { - requestor.acceptField( this ); - } - catch (Exception e) - { - /* do nothing */ - } - } - - public void enterScope( ISourceElementRequestor requestor ) - { - } - - public void exitScope( ISourceElementRequestor requestor ) - { - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java deleted file mode 100644 index e5ec4bb707e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTFunction.java +++ /dev/null @@ -1,347 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTCodeScope; -import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplate; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; - -/** - * @author jcamelon - * - */ -public class ASTFunction extends ASTDeclaration implements IASTFunction -{ - /** - * @param scope - * @param filename - */ - public ASTFunction(IASTScope scope, char[] name, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, - boolean isFriend, boolean isStatic, int startOffset, int startLine, int nameOffset, int nameEndOffset, IASTTemplate ownerTemplate, boolean hasFunctionTryBlock, boolean hasVarArgs, int nameLine, char[] filename ) - { - super(ownerTemplate != null ? null : scope ); - this.name = name; - this.parms = parameters; - this.returnType = returnType; - this.exceptionSpec = exception; - this.isInline = isInline; - this.isFriend = isFriend; - this.isStatic = isStatic; - this.ownerTemplateDeclaration = ownerTemplate; - if( ownerTemplate != null ) - ownerTemplate.setOwnedDeclaration( this ); - setStartingOffsetAndLineNumber( startOffset, startLine ); - setNameOffset( nameOffset ); - qualifiedName = new ASTQualifiedNamedElement( scope, name ); - setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); - this.hasFunctionTryBlock = hasFunctionTryBlock; - this.varArgs = hasVarArgs; - fn = filename; - } - - private boolean previouslyDeclared; - private boolean hasFunctionBody = false; - private final IASTQualifiedNameElement qualifiedName; - private final IASTTemplate ownerTemplateDeclaration; - private List declarations = new ArrayList(); - private final IASTExceptionSpecification exceptionSpec; - private final char[] name; - private final List parms; - private final IASTAbstractDeclaration returnType; - private final boolean isInline, isFriend, isStatic; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isInline() - */ - public boolean isInline() - { - return isInline; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isFriend() - */ - public boolean isFriend() - { - return isFriend; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#isStatic() - */ - public boolean isStatic() - { - return isStatic; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() - { - return String.valueOf(name); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getReturnType() - */ - public IASTAbstractDeclaration getReturnType() - { - return returnType; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getParameters() - */ - public Iterator getParameters() - { - return parms.iterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#getExceptionSpec() - */ - public IASTExceptionSpecification getExceptionSpec() - { - return exceptionSpec; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplatedDeclaration#getOwnerTemplateDeclaration() - */ - public IASTTemplate getOwnerTemplateDeclaration() - { - return ownerTemplateDeclaration; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() - */ - public Iterator getDeclarations() - { - return declarations.iterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedName.getFullyQualifiedName(); - } - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedName.getFullyQualifiedNameCharArrays(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - if( isFriend() ) - requestor.acceptFriendDeclaration(this); - else - requestor.acceptFunctionDeclaration(this); - - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enter(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterFunctionBody( this ); - } - catch (Exception e) - { - /* do nothing */ - } - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exit(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitFunctionBody( this ); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#setHasFunctionBody(boolean) - */ - public void setHasFunctionBody(boolean b) { - hasFunctionBody = true; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#hasFunctionBody() - */ - public boolean hasFunctionBody() { - return hasFunctionBody; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCodeScope#getOwnerCodeScope() - */ - public IASTCodeScope getOwnerCodeScope() - { - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#previouslyDeclared() - */ - public boolean previouslyDeclared() - { - return previouslyDeclared; - } - private boolean hasFunctionTryBlock = false; - private final boolean varArgs; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#setHasFunctionTryBlock(boolean) - */ - public void setHasFunctionTryBlock(boolean b) - { - hasFunctionTryBlock = b; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#hasFunctionTryBlock() - */ - public boolean hasFunctionTryBlock() - { - return hasFunctionTryBlock; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTFunction#takesVarArgs() - */ - public boolean takesVarArgs() { - return varArgs; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTCodeScope#getContainingFunction() - */ - public IASTFunction getContainingFunction() { - return this; - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public final int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public final int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public final void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public final int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public final void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return name; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTIdExpression.java deleted file mode 100644 index 5b8ad760a7c..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTIdExpression.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; - -/** - * @author jcamelon - * - */ -public class ASTIdExpression extends ASTExpression implements IASTExpression { - - private final char[] idExpression; - - - /** - * @param kind - * @param idExpression - */ - public ASTIdExpression(Kind kind, char[] idExpression) { - super(kind); - this.idExpression = idExpression; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getIdExpression() - */ - public String getIdExpression() { - return String.valueOf(idExpression); - } - - public char[] getIdExpressionCharArray(){ - return idExpression; - } - public String toString(){ - return ASTUtil.getExpressionString( this ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerClause.java deleted file mode 100644 index ed83d607000..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerClause.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; - -/** - * @author jcamelon - */ -public class ASTInitializerClause implements IASTInitializerClause { - - private final IASTInitializerClause.Kind kind; - private IASTVariable ownerDeclaration = null; - /** - * @param kind - * @param assignmentExpression - * @param initializerClauses - */ - public ASTInitializerClause(Kind kind ) { - this.kind = kind; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getKind() - */ - public Kind getKind() { - return kind; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializerList() - */ - public Iterator getInitializers() { - return EmptyIterator.EMPTY_ITERATOR; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getAssigmentExpression() - */ - public IASTExpression getAssigmentExpression() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getDesignators() - */ - public Iterator getDesignators() - { - return EmptyIterator.EMPTY_ITERATOR; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#setOwnerDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void setOwnerVariableDeclaration(IASTVariable declaration) - { - ownerDeclaration = declaration; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getOwnerDeclaration() - */ - public IASTVariable getOwnerVariableDeclaration() - { - return ownerDeclaration; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#findExpressionForDuple(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public IASTExpression findExpressionForDuple(ITokenDuple finalDuple) throws ASTNotImplementedException { - throw new ASTNotImplementedException(); - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerListInitializerClause.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerListInitializerClause.java deleted file mode 100644 index aa5fbbfba1f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTInitializerListInitializerClause.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; - -/** - * @author jcamelon - */ -public class ASTInitializerListInitializerClause extends ASTInitializerClause - implements - IASTInitializerClause { - - private final List initializerClauses; - - /** - * @param kind - * @param initializerClauses - */ - public ASTInitializerListInitializerClause(Kind kind, List initializerClauses) { - super( kind ); - this.initializerClauses = initializerClauses; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTInitializerClause#getInitializers() - */ - public Iterator getInitializers() { - if( initializerClauses == null ) - return EmptyIterator.EMPTY_ITERATOR; - return initializerClauses.iterator(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java deleted file mode 100644 index 95a00918ade..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLinkageSpecification.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTScope; - -/** - * @author jcamelon - * - */ -public class ASTLinkageSpecification - extends ASTDeclaration - implements IASTDeclaration, IASTLinkageSpecification, IASTQScope { - - private final char[] linkage; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - public ASTLinkageSpecification( IASTScope scope, char[] linkage, int startingOffset, int startingLine, char[] filename ) - { - super( scope ); - this.linkage = linkage; - setStartingOffsetAndLineNumber(startingOffset, startingLine); - fn = filename; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification#getLinkageString() - */ - public String getLinkageString() { - return String.valueOf(linkage); - } - - private List declarations = new ArrayList(); - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() - */ - public Iterator getDeclarations() { - return declarations.iterator(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.quick.IASTQScope#addDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void addDeclaration(IASTDeclaration declaration) { - declarations.add( declaration ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enter(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterLinkageSpecification(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exit(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitLinkageSpecification(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLiteralExpression.java deleted file mode 100644 index 737478f6f7a..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTLiteralExpression.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ast.ASTUtil; - - -/** - * @author jcamelon - * - */ -public class ASTLiteralExpression extends ASTExpression { - - private final char[] literal; - - /** - * @param kind - * @param literal - */ - public ASTLiteralExpression(Kind kind, char[] literal) { - super( kind ); - this.literal =literal; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLiteralString() - */ - public String getLiteralString() { - return String.valueOf( literal ); - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTMethod.java deleted file mode 100644 index 041a055599f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTMethod.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplate; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; -/** - * @author jcamelon - * - */ -public class ASTMethod extends ASTFunction implements IASTMethod -{ - private final List constructorChainElements; - private final boolean isConst; - private final boolean isDestructor; - private final boolean isConstructor; - private final boolean isExplicit; - private final boolean isPureVirtual; - private final boolean isVirtual; - private final boolean isVolatile; - private final ASTAccessVisibility visibility; - private final IASTQualifiedNameElement qualifiedName; - /** - * @param scope - * @param name - * @param parameters - * @param returnType - * @param exception - * @param isInline - * @param isFriend - * @param isStatic - * @param startOffset - * @param nameOffset - * @param ownerTemplate - * @param filename - */ - public ASTMethod( - IASTScope scope, - char[] name, - List parameters, - IASTAbstractDeclaration returnType, - IASTExceptionSpecification exception, - boolean isInline, - boolean isFriend, - boolean isStatic, - int startOffset, - int startLine, - int nameOffset, - int nameEndOffset, - int nameLine, - IASTTemplate ownerTemplate, - boolean isConst, - boolean isVolatile, - boolean isConstructor, - boolean isDestructor, - boolean isVirtual, boolean isExplicit, boolean isPureVirtual, - ASTAccessVisibility visibility, List constructorChainElements, boolean hasFunctionTryBlock, boolean hasVarArgs, char []filename ) - { - super( - scope, - name, - parameters, - returnType, - exception, - isInline, - isFriend, - isStatic, - startOffset, - startLine, - nameOffset, - nameEndOffset, ownerTemplate, hasFunctionTryBlock, hasVarArgs, nameLine, filename); - this.isVirtual = isVirtual; - this.isPureVirtual = isPureVirtual; - this.isConstructor = isConstructor; - this.isDestructor = isDestructor; - this.isExplicit = isExplicit; - this.isConst = isConst; - this.isVolatile = isVolatile; - this.visibility = visibility; - this.constructorChainElements = constructorChainElements; - qualifiedName = new ASTQualifiedNamedElement( scope, name ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isVirtual() - */ - public boolean isVirtual() - { - return isVirtual; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isExplicit() - */ - public boolean isExplicit() - { - // TODO Auto-generated method stub - return isExplicit; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isConstructor() - */ - public boolean isConstructor() - { - return isConstructor; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isDestructor() - */ - public boolean isDestructor() - { - return isDestructor; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isConst() - */ - public boolean isConst() - { - return isConst; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isVolatile() - */ - public boolean isVolatile() - { - return isVolatile; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#isPureVirtual() - */ - public boolean isPureVirtual() - { - return isPureVirtual; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMember#getVisiblity() - */ - public ASTAccessVisibility getVisiblity() - { - return visibility; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedName.getFullyQualifiedName(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMember#getOwnerClassSpecifier() - */ - - - public void acceptElement( ISourceElementRequestor requestor ) - { - try - { - if( isFriend() ) - requestor.acceptFriendDeclaration(this); - else - requestor.acceptMethodDeclaration( this ); - } - catch (Exception e) - { - /* do nothing */ - } - } - - public void enterScope( ISourceElementRequestor requestor ) - { - try - { - requestor.enterMethodBody(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - public void exitScope( ISourceElementRequestor requestor ) - { - try - { - requestor.exitMethodBody(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#getConstructorChainInitializers() - */ - public Iterator getConstructorChainInitializers() - { - if( constructorChainElements == null ) - return EmptyIterator.EMPTY_ITERATOR; - return constructorChainElements.iterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTMethod#getOwnerClassSpecifier() - */ - public IASTClassSpecifier getOwnerClassSpecifier() { - return (IASTClassSpecifier) getOwnerScope(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceAlias.java deleted file mode 100644 index 1632d18451a..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceAlias.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTScope; - -/** - * @author jcamelon - * - */ -public class ASTNamespaceAlias extends ASTDeclaration implements IASTNamespaceAlias -{ - - private final char[] alias; - private final char[] identifier; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param scope - * @param identifier - * @param string - * @param startingOffset - * @param nameOffset - * @param endOffset - * @param filename - */ - public ASTNamespaceAlias(IASTScope scope, char[] identifier, char[] string, int startingOffset, int nameOffset, int nameEndOffset, int endOffset, int startingLine, int nameLine, int endingLine, char[] filename) - { - super( scope ); - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setNameOffset(nameOffset); - setNameEndOffsetAndLineNumber( nameEndOffset, nameLine ); - setEndingOffsetAndLineNumber(endOffset, endingLine); - this.identifier = identifier; - this.alias = string; - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias#getAlias() - */ - public String getAlias() - { - return String.valueOf(alias); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNamespaceAlias#getNamespace() - */ - public IASTNamespaceDefinition getNamespace() throws ASTNotImplementedException - { - throw new ASTNotImplementedException(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() - { - return String.valueOf(identifier); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public final int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public final int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public final void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public final int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public final void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return identifier; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java deleted file mode 100644 index 7011b453952..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNamespaceDefinition.java +++ /dev/null @@ -1,203 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; - -/** - * @author jcamelon - * - */ -public class ASTNamespaceDefinition extends ASTDeclaration implements IASTNamespaceDefinition, IASTQScope { - - private final char[] name; - private final ASTQualifiedNamedElement qualifiedNameElement; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - public ASTNamespaceDefinition( IASTScope scope, char[] name, int startOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, char[] filename ) - { - super( scope ); - qualifiedNameElement = new ASTQualifiedNamedElement( scope, name ); - this.name = name; - setStartingOffsetAndLineNumber(startOffset, startingLine); - setNameOffset(nameOffset); - setNameEndOffsetAndLineNumber(nameEndOffset, nameEndOffset); - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() { - return String.valueOf(name); - } - - private List declarations = new ArrayList(); - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() - */ - public Iterator getDeclarations() { - return declarations.iterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.ast.quick.IASTQScope#addDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void addDeclaration(IASTDeclaration declaration) { - declarations.add( declaration ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedNameElement.getFullyQualifiedName(); - } - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedNameElement.getFullyQualifiedNameCharArrays(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enter(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterNamespaceDefinition(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exit(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitNamespaceDefinition(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public final int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public final int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public final void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public final int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public final void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return name; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java deleted file mode 100644 index 15944123f80..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewDescriptor.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; - -/** - * @author jcamelon - */ -public class ASTNewDescriptor implements IASTNewExpressionDescriptor { - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor#getNewInitializerExpressions() - */ - public Iterator getNewInitializerExpressions() { - return EmptyIterator.EMPTY_ITERATOR; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor#getNewPlacementExpressions() - */ - public Iterator getNewPlacementExpressions() { - return EmptyIterator.EMPTY_ITERATOR; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor#getTypeIdExpressions() - */ - public Iterator getNewTypeIdExpressions() { - return EmptyIterator.EMPTY_ITERATOR; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewExpression.java deleted file mode 100644 index 4a10d629051..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNewExpression.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; - -/** - * @author jcamelon - * - */ -public class ASTNewExpression extends ASTExpression implements IASTExpression { - - private final IASTNewExpressionDescriptor newDescriptor; - private final IASTTypeId typeId; - - /** - * @param kind - * @param newDescriptor - * @param typeId - */ - public ASTNewExpression(Kind kind, IASTNewExpressionDescriptor newDescriptor, IASTTypeId typeId) { - super(kind); - this.newDescriptor = newDescriptor; - this.typeId = typeId; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getNewExpressionDescriptor() - */ - public IASTNewExpressionDescriptor getNewExpressionDescriptor() { - return newDescriptor; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId() - */ - public IASTTypeId getTypeId() { - return typeId; - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNode.java deleted file mode 100644 index 50e2137584f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTNode.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on 17/12/2003 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTNode; - -/** - * @author hamer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class ASTNode implements IASTNode { - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind[], org.eclipse.cdt.core.parser.ast.IASTNode) - */ - public ILookupResult lookup( - String prefix, - LookupKind[] kind, - IASTNode context, IASTExpression functionParameters) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTParameterDeclaration.java deleted file mode 100644 index 3583c271c8a..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTParameterDeclaration.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.ast.ASTAbstractDeclaration; - -/** - * @author jcamelon - * - */ -public class ASTParameterDeclaration extends ASTAbstractDeclaration implements IASTParameterDeclaration -{ - private final char[] parameterName; - private final IASTInitializerClause initializerClause; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param isConst - * @param typeSpecifier - * @param pointerOperators - * @param arrayModifiers - * @param parameterName - * @param initializerClause - * @param filename - */ - public ASTParameterDeclaration(boolean isConst, boolean isVolatile, IASTTypeSpecifier typeSpecifier, List pointerOperators, List arrayModifiers, List parameters, ASTPointerOperator pointerOp, char[] parameterName, IASTInitializerClause initializerClause, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] filename ) - { - super( isConst, isVolatile, typeSpecifier, pointerOperators, arrayModifiers, parameters, pointerOp ); - this.parameterName = parameterName; - this.initializerClause = initializerClause; - setStartingOffsetAndLineNumber( startingOffset, startingLine ); - setEndingOffsetAndLineNumber( endingOffset, endingLine ); - setNameOffset( nameOffset ); - setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration#getName() - */ - public String getName() - { - return String.valueOf(parameterName); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration#getDefaultValue() - */ - public IASTInitializerClause getDefaultValue() - { - return initializerClause; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration#getOwnerFunctionDeclaration() - */ - public IASTFunction getOwnerFunctionDeclaration() throws ASTNotImplementedException { - throw new ASTNotImplementedException(); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public final int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public final int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public final void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public final int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public final void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return parameterName; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTScopedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTScopedTypeSpecifier.java deleted file mode 100644 index d72b87c0cae..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTScopedTypeSpecifier.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTScopedTypeSpecifier; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; - -/** - * @author jcamelon - * - */ -public class ASTScopedTypeSpecifier extends ASTQualifiedNamedElement implements IASTScopedTypeSpecifier -{ - private final IASTScope scope; - - public ASTScopedTypeSpecifier( IASTScope scope, char[] name ) - { - super( scope, name ); - this.scope = scope; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScopedElement#getOwnerScope() - */ - public IASTScope getOwnerScope() - { - return scope; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind[], org.eclipse.cdt.core.parser.ast.IASTNode) - */ - public ILookupResult lookup( - String prefix, - LookupKind[] kind, - IASTNode context, IASTExpression functionParameters) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTSimpleTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTSimpleTypeSpecifier.java deleted file mode 100644 index 5e49d749006..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTSimpleTypeSpecifier.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.Hashtable; -import java.util.Map; - -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; - -/** - * @author jcamelon - * - */ -public class ASTSimpleTypeSpecifier extends ASTNode implements IASTSimpleTypeSpecifier -{ - private final boolean imaginary; - private final boolean complex; - private final boolean isTypename; - private final Type kind; - private final String typeName; - private final boolean isLong, isShort, isSigned, isUnsigned; - - private static final Map nameMap; - static - { - nameMap = new Hashtable(); - nameMap.put( Type.BOOL, "bool"); //$NON-NLS-1$ - nameMap.put( Type.CHAR, "char"); //$NON-NLS-1$ - nameMap.put( Type.DOUBLE, "double"); //$NON-NLS-1$ - nameMap.put( Type.FLOAT, "float"); //$NON-NLS-1$ - nameMap.put( Type.INT, "int"); //$NON-NLS-1$ - nameMap.put( Type.VOID, "void" ); //$NON-NLS-1$ - nameMap.put( Type.WCHAR_T, "wchar_t" ); //$NON-NLS-1$ - nameMap.put( Type._BOOL, "_Bool"); //$NON-NLS-1$ - } - /** - * @param kind - * @param typeName - */ - public ASTSimpleTypeSpecifier(Type kind, ITokenDuple typeName, boolean isShort, boolean isLong, boolean isSigned, boolean isUnsigned, boolean isTypename, boolean isComplex, boolean isImaginary ) - { - this.kind = kind; - this.isLong = isLong; - this.isShort = isShort; - this.isSigned = isSigned; - this.isUnsigned = isUnsigned; - this.isTypename = isTypename; - this.complex = isComplex; - this.imaginary = isImaginary; - - this.typeName = typeName.toString(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getType() - */ - public Type getType() - { - return kind; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getTypename() - */ - public String getTypename() - { - return typeName; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isLong() - */ - public boolean isLong() - { - return isLong; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isShort() - */ - public boolean isShort() - { - return isShort; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isSigned() - */ - public boolean isSigned() - { - return isSigned; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isUnsigned() - */ - public boolean isUnsigned() - { - return isUnsigned; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isTypename() - */ - public boolean isTypename() - { - return isTypename; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#getTypeSpecifier() - */ - public IASTTypeSpecifier getTypeSpecifier() throws ASTNotImplementedException - { - throw new ASTNotImplementedException(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isComplex() - */ - public boolean isComplex() - { - return complex; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#isImaginary() - */ - public boolean isImaginary() - { - return imaginary; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier#releaseReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void releaseReferences() { - // DO NOTHING - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateDeclaration.java deleted file mode 100644 index 89e0a960862..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateDeclaration.java +++ /dev/null @@ -1,174 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; - -/** - * @author jcamelon - * - */ -public class ASTTemplateDeclaration extends ASTDeclaration implements IASTTemplateDeclaration -{ - private IASTDeclaration ownedDeclaration; - private List templateParameters; - private final boolean isExported; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param templateParameters - * @param filename - */ - public ASTTemplateDeclaration(IASTScope scope, List templateParameters, int startingOffset, int startingLine, boolean isExported, char[] filename) - { - super( scope ); - this.templateParameters = templateParameters; - setStartingOffsetAndLineNumber(startingOffset, startingLine); - this.isExported = isExported; - fn = filename; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration#getTemplateParameters() - */ - public Iterator getTemplateParameters() - { - return ( templateParameters != null ) ? templateParameters.iterator() : EmptyIterator.EMPTY_ITERATOR; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration#getOwnedDeclaration() - */ - public IASTDeclaration getOwnedDeclaration() - { - return ownedDeclaration; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplate#setOwnedDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void setOwnedDeclaration(IASTDeclaration declaration) - { - ownedDeclaration = declaration; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration#isExported() - */ - public boolean isExported() - { - return isExported; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enter(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterTemplateDeclaration(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exit(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitTemplateDeclaration(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() - */ - public Iterator getDeclarations() throws ASTNotImplementedException { - List decls = new ArrayList(1); - decls.add( getOwnedDeclaration() ); - return decls.iterator(); - } - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateInstantiation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateInstantiation.java deleted file mode 100644 index 199ee1270d1..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateInstantiation.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation; - -/** - * @author jcamelon - * - */ -public class ASTTemplateInstantiation extends ASTDeclaration implements IASTTemplateInstantiation -{ - private IASTDeclaration declaration; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - - /** - * @param scope - * @param filename - */ - public ASTTemplateInstantiation(IASTScope scope, int startingOffset, int startingLine, char[] filename) - { - super( scope ); - setStartingOffsetAndLineNumber(startingOffset, startingLine); - fn = filename; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplate#getOwnedDeclaration() - */ - public IASTDeclaration getOwnedDeclaration() - { - return declaration; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplate#setOwnedDeclaration(org.eclipse.cdt.core.parser.ast.IASTDeclaration) - */ - public void setOwnedDeclaration(IASTDeclaration declaration) - { - this.declaration = declaration; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enter(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterTemplateInstantiation(this); - } - catch (Exception e) - { - /* do nothing */ - } - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exit(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitTemplateExplicitInstantiation(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation#getInstantiatedTemplate() - */ - public IASTTemplateDeclaration getInstantiatedTemplate() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTScope#getDeclarations() - */ - public Iterator getDeclarations() throws ASTNotImplementedException { - // TODO Auto-generated method stub - return null; - } - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateParameter.java deleted file mode 100644 index 51e532157be..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateParameter.java +++ /dev/null @@ -1,219 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement; -import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter; - -/** - * @author jcamelon - * - */ -public class ASTTemplateParameter implements IASTTemplateParameter, IASTOffsetableNamedElement -{ - private final List templateParms; - private final IASTParameterDeclaration parameter; - private final ParamKind kind; - private final char[] identifier; - private final char[] defaultValue; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param kind - * @param identifier - * @param defaultValue - * @param parameter - * @param filename - */ - public ASTTemplateParameter(ParamKind kind, char[] identifier, char[] defaultValue, IASTParameterDeclaration parameter, List templateParms, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, int endingOffset, int endingLine, char[] filename ) - { - this.kind = kind; - this.identifier = identifier; - this.defaultValue = defaultValue; - this.parameter = parameter; - this.templateParms = templateParms; - setStartingOffsetAndLineNumber( startingOffset, startingLine ); - setEndingOffsetAndLineNumber( endingOffset, endingLine ); - setNameOffset( nameOffset ); - setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); - fn = filename; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getTemplateParameterKind() - */ - public ParamKind getTemplateParameterKind() - { - return kind; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getIdentifier() - */ - public String getIdentifier() - { - return String.valueOf(identifier); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getDefaultValueIdExpression() - */ - public String getDefaultValueIdExpression() - { - return String.valueOf(defaultValue); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameterList#getTemplateParameters() - */ - public Iterator getTemplateParameters() - { - return templateParms.iterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTemplateParameter#getParameterDeclaration() - */ - public IASTParameterDeclaration getParameterDeclaration() - { - return parameter; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind[], org.eclipse.cdt.core.parser.ast.IASTNode) - */ - public ILookupResult lookup(String prefix, LookupKind[] lookupKind, IASTNode context, IASTExpression functionParameters) throws LookupError, ASTNotImplementedException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() { - return String.valueOf(identifier); - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public final int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public final int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public final void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public final int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public final void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return identifier; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateSpecialization.java deleted file mode 100644 index ddd7b871ea5..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTemplateSpecialization.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization; - -/** - * @author jcamelon - * - */ -public class ASTTemplateSpecialization extends ASTTemplateDeclaration implements IASTTemplateSpecialization -{ - /** - * @param scope - */ - public ASTTemplateSpecialization(IASTScope scope, int startingOffset, int startingLine, char [] filename ) - { - super(scope, null, startingOffset, startingLine, false, filename ); - setStartingOffsetAndLineNumber(startingOffset, startingLine); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enter(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - try - { - requestor.enterTemplateSpecialization(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exit(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - try - { - requestor.exitTemplateSpecialization(this); - } - catch (Exception e) - { - /* do nothing */ - } - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypeId.java deleted file mode 100644 index 034fbc14d56..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypeId.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; -import org.eclipse.cdt.internal.core.parser.pst.ISymbol; - -/** - * @author jcamelon - * - */ -public class ASTTypeId implements IASTTypeId -{ - private final boolean isVolatile; - private final boolean isUnsigned; - private final boolean isTypeName; - private final boolean isSigned; - private final boolean isShort; - private final boolean isLong; - private final boolean isConst; - private final Type kind; - private final char[] name; - private final List pointerOps; - private final List arrayMods; - private final char[] completeSignature; - /** - * @param kind - * @param string - * @param pointerOps - * @param arrayMods - */ - public ASTTypeId(Type kind, char[] string, List pointerOps, List arrayMods, boolean isConst, boolean isVolatile, - boolean isUnsigned, boolean isSigned, boolean isShort, boolean isLong, boolean isTypeName, char[] completeSignature) - { - this.kind = kind; - this.name = string; - this.pointerOps = pointerOps; - this.arrayMods = arrayMods; - this.isVolatile =isVolatile; - this.isUnsigned =isUnsigned; - this.isTypeName =isTypeName; - this.isSigned =isSigned; - this.isShort =isShort; - this.isLong =isLong; - this.isConst =isConst; - this.completeSignature = completeSignature; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getKind() - */ - public Type getKind() - { - return kind; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getType() - */ - public String getTypeOrClassName() - { - return String.valueOf(name); - } - public char[] getTypeOrClassNameCharArray(){ - return name; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getPointerOperators() - */ - public Iterator getPointerOperators() - { - return pointerOps.iterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getArrayModifiers() - */ - public Iterator getArrayModifiers() - { - return arrayMods.iterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#getFullSignature() - */ - public String getFullSignature() - { - return String.valueOf(completeSignature); - } - public char[] getFullSignatureCharArray(){ - return completeSignature; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#createTypeSymbol(org.eclipse.cdt.core.parser.ast.IASTFactory) - */ - public ISymbol getTypeSymbol() throws ASTNotImplementedException - { - throw new ASTNotImplementedException(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isConst() - */ - public boolean isConst() - { - return isConst; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isVolatile() - */ - public boolean isVolatile() - { - return isVolatile; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isLong() - */ - public boolean isLong() - { - return isLong; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isShort() - */ - public boolean isShort() - { - return isShort; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isSigned() - */ - public boolean isSigned() - { - return isSigned; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isUnsigned() - */ - public boolean isUnsigned() - { - return isUnsigned; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#isTypename() - */ - public boolean isTypename() - { - return isTypeName; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enterScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exitScope(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypeId#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - // do nothing - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypeIdExpression.java deleted file mode 100644 index 2a6bf6b0709..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypeIdExpression.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; - -/** - * @author jcamelon - * - */ -public class ASTTypeIdExpression extends ASTExpression - implements - IASTExpression { - - private final IASTTypeId typeId; - - /** - * @param kind - * @param typeId - */ - public ASTTypeIdExpression(Kind kind, IASTTypeId typeId) { - super( kind ); - this.typeId = typeId; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId() - */ - public IASTTypeId getTypeId() { - return typeId; - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedefDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedefDeclaration.java deleted file mode 100644 index 874c5544ecb..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTTypedefDeclaration.java +++ /dev/null @@ -1,203 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; - -/** - * @author jcamelon - * - */ -public class ASTTypedefDeclaration extends ASTDeclaration implements IASTTypedefDeclaration -{ - protected static final ASTNotImplementedException NOT_IMPLEMENTED = new ASTNotImplementedException(); - private final char[] name; - private final IASTAbstractDeclaration mapping; - private final ASTQualifiedNamedElement qualifiedName; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param scope - * @param name - * @param mapping - * @param filename - */ - public ASTTypedefDeclaration(IASTScope scope, char[] name, IASTAbstractDeclaration mapping, int startingOffset, int startingLine, int nameOffset, int nameEndOffset, int nameLine, char[] filename ) - { - super( scope ); - this.name = name; - this.mapping = mapping; - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setNameOffset(nameOffset); - setNameEndOffsetAndLineNumber(nameEndOffset, nameLine); - qualifiedName = new ASTQualifiedNamedElement( scope, name ); - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypedef#getName() - */ - public String getName() - { - return String.valueOf(name); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypedef#getAbstractDeclarator() - */ - public IASTAbstractDeclaration getAbstractDeclarator() - { - return mapping; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedName.getFullyQualifiedName(); - } - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedName.getFullyQualifiedNameCharArrays(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptTypedefDeclaration(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enter(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exit(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration#getFinalTypeSpecifier() - */ - public IASTTypeSpecifier getFinalTypeSpecifier() throws ASTNotImplementedException { - throw NOT_IMPLEMENTED; - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public final int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public final int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public final void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public final int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public final void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return name; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryExpression.java deleted file mode 100644 index a1c2327be53..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryExpression.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; - -/** - * @author jcamelon - * - */ -public class ASTUnaryExpression extends ASTExpression implements IASTExpression { - - private final IASTExpression lhs; - - /** - * @param kind - * @param lhs - */ - public ASTUnaryExpression(Kind kind, IASTExpression lhs) { - super(kind); - this.lhs = lhs; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getLHSExpression() - */ - public IASTExpression getLHSExpression() { - return lhs; - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryIdExpression.java deleted file mode 100644 index 55df70de76f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryIdExpression.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -/* - * Created on Jun 7, 2004 - */ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; - -/** - * @author aniefer - */ -public class ASTUnaryIdExpression extends ASTIdExpression { - private final IASTExpression lhs; - /** - * @param kind - * @param idExpression - */ - public ASTUnaryIdExpression(Kind kind, IASTExpression lhs, char[] idExpression) { - super(kind, idExpression); - this.lhs = lhs; - } - - public IASTExpression getLHSExpression(){ - return lhs; - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryTypeIdExpression.java deleted file mode 100644 index 92f8e7732cf..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUnaryTypeIdExpression.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; - -/** - * @author jcamelon - * - */ -public class ASTUnaryTypeIdExpression extends ASTUnaryExpression - implements - IASTExpression { - - private final IASTTypeId typeId; - - /** - * @param kind - * @param lhs - * @param typeId - */ - public ASTUnaryTypeIdExpression(Kind kind, IASTExpression lhs, IASTTypeId typeId) { - super( kind, lhs ); - this.typeId = typeId; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTExpression#getTypeId() - */ - public IASTTypeId getTypeId() { - return typeId; - } - - public String toString(){ - return ASTUtil.getExpressionString( this ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java deleted file mode 100644 index 0daee6c3174..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDeclaration.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; - -/** - * @author jcamelon - * - */ -public class ASTUsingDeclaration - extends ASTDeclaration - implements IASTUsingDeclaration { - - private final boolean isTypename; - private final char [] mappingName; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - - public ASTUsingDeclaration( IASTScope scope, boolean isTypeName, char[] mappingName, int startingOffset, int startingLine, int endingOffset, int endingLine, char[] filename, int nStart, int nEnd, int nLine ) - { - super( scope ); - isTypename = isTypeName; - this.mappingName = mappingName; - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setEndingOffsetAndLineNumber(endingOffset, endingLine); - fn = filename; - setNameOffset( nStart ); - setNameEndOffsetAndLineNumber( nEnd, nLine ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#isTypename() - */ - public boolean isTypename() { - return isTypename; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#usingTypeName() - */ - public String usingTypeName() { - return String.valueOf(mappingName); - } - public char[] usingTypeNameCharArray(){ - return mappingName; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptUsingDeclaration(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enter(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exit(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration#getUsingType() - */ - public Iterator getUsingTypes() throws ASTNotImplementedException - { - throw new ASTNotImplementedException(); - } - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - private int nameStartOffset; - private int nameEndOffset; - private int nameLine; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() { - return new String( mappingName ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return mappingName; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() { - return nameStartOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() { - return nameEndOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffsetAndLineNumber(int, int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) { - nameEndOffset = offset; - nameLine = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLine; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java deleted file mode 100644 index 0c1c8c7f17a..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTUsingDirective.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; - -/** - * @author jcamelon - * - */ -public class ASTUsingDirective - extends ASTDeclaration - implements IASTUsingDirective { - - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - public ASTUsingDirective( IASTScope scope, String name, int startingOffset, int startingLine, int endingOffset, int endingLine, char[] filename, int nStart, int nEnd, int nLine ) - { - super( scope ); - this.namespaceName = name; - setStartingOffsetAndLineNumber(startingOffset, startingLine); - setEndingOffsetAndLineNumber(endingOffset, endingLine); - fn = filename; - setNameOffset( nStart ); - setNameEndOffsetAndLineNumber( nEnd, nLine ); - } - private final String namespaceName; - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTUsingDirective#getNamespaceName() - */ - public String getNamespaceName() { - return namespaceName; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptUsingDirective(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enter(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exit(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTUsingDirective#getNamespaceDefinition() - */ - public IASTNamespaceDefinition getNamespaceDefinition() throws ASTNotImplementedException - { - throw new ASTNotImplementedException(); - } - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset; - private int nameStartOffset; - private int nameEndOffset; - private int nameLine; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getName() - */ - public String getName() { - return namespaceName; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return namespaceName.toCharArray(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public int getNameOffset() { - return nameStartOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public void setNameOffset(int o) { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public int getNameEndOffset() { - return nameEndOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffsetAndLineNumber(int, int) - */ - public void setNameEndOffsetAndLineNumber(int offset, int lineNumber) { - nameEndOffset = offset; - nameLine = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public int getNameLineNumber() { - return nameLine; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java deleted file mode 100644 index 42e47f3ee6e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ASTVariable.java +++ /dev/null @@ -1,276 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; - -/** - * @author jcamelon - * - */ -public class ASTVariable extends ASTDeclaration implements IASTVariable -{ - private IASTExpression constructorExpression; - private final boolean isAuto; - private final IASTInitializerClause initializerClause; - private final IASTExpression bitfieldExpression; - private final IASTAbstractDeclaration abstractDeclaration; - private final boolean isMutable; - private final boolean isExtern; - private final boolean isRegister; - private final boolean isStatic; - private final char[] name; - private final ASTQualifiedNamedElement qualifiedName; - private final char [] fn; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getFilename() - */ - public char[] getFilename() { - return fn; - } - - /** - * @param scope - * @param filename - */ - public ASTVariable(IASTScope scope, char[] name, boolean isAuto, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, - IASTAbstractDeclaration abstractDeclaration, boolean isMutable, boolean isExtern, boolean isRegister, boolean isStatic, int startingOffset, int startLine, int nameOffset, int nameEndOffset, int nameLine, IASTExpression constructorExpression, char[] filename ) - { - super(scope); - this.isAuto = isAuto; - this.initializerClause = initializerClause; - this.bitfieldExpression = bitfieldExpression; - this.abstractDeclaration = abstractDeclaration; - this.isMutable= isMutable; - this.isExtern = isExtern; - this.isRegister = isRegister; - this.isStatic = isStatic; - this.name = name; - this.constructorExpression = constructorExpression; - qualifiedName = new ASTQualifiedNamedElement( scope, name ); - setStartingOffsetAndLineNumber(startingOffset, startLine); - setNameOffset(nameOffset); - setNameEndOffsetAndLineNumber( nameEndOffset, nameLine ); - if( initializerClause != null ) - initializerClause.setOwnerVariableDeclaration(this); - fn = filename; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isAuto() - */ - public boolean isAuto() - { - return isAuto; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isRegister() - */ - public boolean isRegister() - { - return isRegister; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isStatic() - */ - public boolean isStatic() - { - return isStatic; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isExtern() - */ - public boolean isExtern() - { - return isExtern; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isMutable() - */ - public boolean isMutable() - { - return isMutable; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#getAbstractDeclaration() - */ - public IASTAbstractDeclaration getAbstractDeclaration() - { - return abstractDeclaration; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#getName() - */ - public String getName() - { - return String.valueOf(name); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#getInitializerClause() - */ - public IASTInitializerClause getInitializerClause() - { - return initializerClause; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#isBitfield() - */ - public boolean isBitfield() - { - return ( bitfieldExpression != null ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#getBitfieldExpression() - */ - public IASTExpression getBitfieldExpression() - { - return bitfieldExpression; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement#getFullyQualifiedName() - */ - public String[] getFullyQualifiedName() - { - return qualifiedName.getFullyQualifiedName(); - } - public char[][] getFullyQualifiedNameCharArrays(){ - return qualifiedName.getFullyQualifiedNameCharArrays(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#accept(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) - { - try - { - requestor.acceptVariable(this); - } - catch (Exception e) - { - /* do nothing */ - } - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#enter(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void enterScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate#exit(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void exitScope(ISourceElementRequestor requestor) - { - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTVariable#getConstructorExpression() - */ - public IASTExpression getConstructorExpression() - { - return constructorExpression; - } - - private int startingLineNumber, startingOffset, endingLineNumber, endingOffset, nameStartOffset, nameEndOffset, nameLineNumber; - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine() - */ - public final int getStartingLine() { - return startingLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingLine() - */ - public final int getEndingLine() { - return endingLineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameLineNumber() - */ - public final int getNameLineNumber() { - return nameLineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setStartingOffset(int) - */ - public final void setStartingOffsetAndLineNumber(int offset, int lineNumber) - { - startingOffset = offset; - startingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#setEndingOffset(int) - */ - public final void setEndingOffsetAndLineNumber(int offset, int lineNumber) - { - endingOffset = offset; - endingLineNumber = lineNumber; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingOffset() - */ - public final int getStartingOffset() - { - return startingOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getEndingOffset() - */ - public final int getEndingOffset() - { - return endingOffset; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameOffset() - */ - public final int getNameOffset() - { - return nameStartOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameOffset(int) - */ - public final void setNameOffset(int o) - { - nameStartOffset = o; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameEndOffset() - */ - public final int getNameEndOffset() - { - return nameEndOffset; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#setNameEndOffset(int) - */ - public final void setNameEndOffsetAndLineNumber(int offset, int lineNumber) - { - nameEndOffset = offset; - nameLineNumber = lineNumber; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement#getNameCharArray() - */ - public char[] getNameCharArray() { - return name; - } -} - diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ExpressionFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ExpressionFactory.java deleted file mode 100644 index d4aae5bafef..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/ExpressionFactory.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; -import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; - -/** - * @author jcamelon - * - */ -public class ExpressionFactory { - /** - * - */ - public ExpressionFactory() { - super(); - } - - /** - * @param kind - * @param lhs - * @param rhs - * @param thirdExpression - * @param typeId - * @param string - * @param literal - * @param newDescriptor - * @return - */ - public static IASTExpression createExpression(Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, char[] idExpression, char[] literal, IASTNewExpressionDescriptor newDescriptor) { - if( literal.length != 0 && idExpression.length == 0 ) //$NON-NLS-1$ - return new ASTLiteralExpression( kind, literal ); - - if( idExpression.length != 0 && lhs == null ) - return new ASTIdExpression( kind, idExpression ); - - if( thirdExpression != null ) - return new ASTConditionalExpression( kind, lhs, rhs, thirdExpression ); - - if( newDescriptor != null ) - return new ASTNewExpression( kind, newDescriptor, typeId ); - - if( lhs != null && rhs != null ) - return new ASTBinaryExpression( kind, lhs, rhs ); - - if( lhs != null && typeId != null ) - return new ASTUnaryTypeIdExpression( kind, lhs, typeId ); - - if( lhs != null && idExpression.length != 0 ) - return new ASTUnaryIdExpression( kind, lhs, idExpression ); - - if( lhs != null ) - return new ASTUnaryExpression( kind, lhs ); - - if( typeId != null ) - return new ASTTypeIdExpression( kind, typeId ); - - return new ASTEmptyExpression( kind ); - - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/GCCASTExpressionExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/GCCASTExpressionExtension.java deleted file mode 100644 index 76ff70ee0a0..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/quick/GCCASTExpressionExtension.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -/* - * Created on Jun 8, 2004 - */ -package org.eclipse.cdt.internal.core.parser.ast.quick; - -import java.util.List; - -import org.eclipse.cdt.core.parser.GCCKeywords; -import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.ASTExpressionEvaluationException; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTFactory; -import org.eclipse.cdt.core.parser.ast.IASTScope; -import org.eclipse.cdt.core.parser.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; -import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression; -import org.eclipse.cdt.internal.core.parser.ast.GCCASTExtension; - -/** - * @author aniefer - */ -public class GCCASTExpressionExtension extends GCCASTExtension { - /** - * @param mode - */ - public GCCASTExpressionExtension(ParserMode mode) { - super(mode); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.extension.IASTFactoryExtension#overrideExpressionFactory() - */ - public boolean overrideCreateExpressionMethod() { - return false; - } - /** - * @param kind - * @param lhs - * @param rhs - * @param thirdExpression - * @param typeId - * @param string - * @param literal - * @param newDescriptor - * @return - */ - private static IASTExpression createExpression(IASTExpression.Kind kind, IASTExpression lhs, IASTExpression rhs, IASTExpression thirdExpression, IASTTypeId typeId, char[] idExpression, char[] literal, IASTNewExpressionDescriptor newDescriptor) { - if( idExpression.length != 0 && literal.length == 0 ) - return new ASTIdExpression( kind, idExpression ) - { - public long evaluateExpression() throws ASTExpressionEvaluationException { - if( getExpressionKind() == IASTExpression.Kind.ID_EXPRESSION ) - return 0; - return super.evaluateExpression(); - } - }; - else if( lhs != null && rhs != null && - (kind == IASTGCCExpression.Kind.RELATIONAL_MAX || - kind == IASTGCCExpression.Kind.RELATIONAL_MIN ) ) - { - return new ASTBinaryExpression( kind, lhs, rhs ){ - public String toString(){ - IASTExpression.Kind k = getExpressionKind(); - StringBuffer buffer = new StringBuffer(); - buffer.append( ASTUtil.getExpressionString( getLHSExpression() ) ); - if( k == IASTGCCExpression.Kind.RELATIONAL_MAX ) - buffer.append( " >? " ); //$NON-NLS-1$ - else - buffer.append( " size; i++ ){ - op1 = (ITypeInfo.PtrOp)symbol.getTypeInfo().getPtrOperators().get(i); - op2 = (ITypeInfo.PtrOp)getTypeInfo().getPtrOperators().get(i); - - if( op1.compareCVTo( op2 ) != 0 ){ - return -1; - } - } - } - - return 0; - } - - public List getPtrOperators(){ - return getTypeInfo().getPtrOperators(); - } - public void addPtrOperator( ITypeInfo.PtrOp ptrOp ){ - getTypeInfo().addPtrOperator( ptrOp ); - } - public void preparePtrOperatros(int numPtrOps) { - getTypeInfo().preparePtrOperators( numPtrOps ); - } - - - public int getDepth(){ - return _depth; - } - - public boolean isTemplateMember(){ - return _isTemplateMember; - } - public void setIsTemplateMember( boolean isMember ){ - _isTemplateMember = isMember; - } - public boolean isTemplateInstance(){ - return ( _isTemplateInstance && _symbolDef != null ); - } - public ISymbol getInstantiatedSymbol(){ - return _symbolDef; - } - public void setInstantiatedSymbol( ISymbol symbol ){ - _isTemplateInstance = true; - _symbolDef = symbol; - } - - public boolean getIsInvisible(){ - return _isInvisible; - } - public void setIsInvisible( boolean invisible ){ - _isInvisible = invisible ; - } - - private char[] _name; //our name - private ITypeInfo _typeInfo; //our type info - private int _depth; //how far down the scope stack we are - - private boolean _isInvisible = false; //used by friend declarations (11.4-9) - private boolean _isTemplateMember = false; - private boolean _isForwardDeclaration = false; - private boolean _isTemplateInstance = false; - private ISymbol _symbolDef = null; //used for forward declarations and template instantiations - - - /* (non-Javadoc) - * @see java.lang.Object#clone() - */ - public Object clone() { - - BasicSymbol s = (BasicSymbol) super.clone(); - s._typeInfo = TypeInfoProvider.newTypeInfo( s._typeInfo ); - return s; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/BasicTypeInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/BasicTypeInfo.java deleted file mode 100644 index 566897e8b41..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/BasicTypeInfo.java +++ /dev/null @@ -1,312 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Jul 5, 2004 - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.ListIterator; - - -/** - * @author aniefer - */ -public class BasicTypeInfo implements ITypeInfo { - - public void setBit( boolean b, int mask ) { - if( b ){ - _typeBits = _typeBits | mask; - } else { - _typeBits = _typeBits & ~mask; - } - } - - public boolean checkBit( int mask ) { - return (_typeBits & mask) != 0; - } - - public void setType( ITypeInfo.eType t ) { - _type = t; - } - - public ITypeInfo.eType getType() { - return _type; - } - - public boolean isType( ITypeInfo.eType type ) { - return isType( type, t_undef ); - } - - public int getTypeBits() { - return _typeBits; - } - - public void setTypeBits( int typeInfo ) { - _typeBits = typeInfo; - } - - /** - * - * @param infoProvider - TypeInfoProvider to use if pooling the TypeInfo created, if null, - * pooling is not used. If pooling is used, TypeInfoProvider.returnTypeInfo - * must be called when the TypeInfo is no longer needed - * @return - */ - public ITypeInfo getFinalType( TypeInfoProvider infoProvider ) { - return ParserSymbolTable.getFlatTypeInfo( this, infoProvider ); - } - - /** - * - * @param type - * @param upperType - * @return boolean - * - * type checking, check that this declaration's type is between type and - * upperType (inclusive). upperType of 0 means no range and our type must - * be type. - */ - public boolean isType( ITypeInfo.eType type, ITypeInfo.eType upperType ) { - //type of -1 means we don't care - if( type == t_any ) - return true; - - //upperType of 0 means no range - if( upperType == t_undef ){ - return ( getType() == type ); - } - return ( getType().compareTo( type ) >= 0 && getType().compareTo( upperType ) <= 0 ); - } - - - - public boolean hasPtrOperators() { - return _ptrOperators.size() > 0; - } - - public List getPtrOperators() { - return _ptrOperators; - } - - public boolean hasSamePtrs( ITypeInfo type ) { - int size = getPtrOperators().size(); - int size2 = type.getPtrOperators().size(); - ITypeInfo.PtrOp ptr1 = null, ptr2 = null; - - if( size == size2 ){ - if( size > 0 ){ - for( int i = 0; i < size; i++ ){ - ptr1 = (ITypeInfo.PtrOp)getPtrOperators().get(i); - ptr2 = (ITypeInfo.PtrOp)type.getPtrOperators().get(i); - if( ptr1.getType() != ptr2.getType() ){ - return false; - } - } - } - return true; - } - return false; - } - - public void applyOperatorExpression( ITypeInfo.OperatorExpression op ) { - if( op == null ) - return; - - if( op == ITypeInfo.OperatorExpression.indirection || - op == ITypeInfo.OperatorExpression.subscript ) - { - //indirection operator, can only be applied to a pointer - //subscript should be applied to something that is "pointer to T", the result is a lvalue of type "T" - if( hasPtrOperators() ){ - ListIterator iterator = getPtrOperators().listIterator( getPtrOperators().size() ); - ITypeInfo.PtrOp last = (ITypeInfo.PtrOp)iterator.previous(); - if( last.getType() == ITypeInfo.PtrOp.t_pointer || - last.getType() == ITypeInfo.PtrOp.t_array ) - { - iterator.remove(); - } - } - } else if( op == ITypeInfo.OperatorExpression.addressof ){ - //Address-of unary operator, results in pointer to T - //TODO or pointer to member - ITypeInfo.PtrOp newOp = new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ); - addPtrOperator( newOp ); - } - } - - public void addPtrOperator( ITypeInfo.PtrOp ptr ) { - if( ptr != null ){ - if( _ptrOperators == Collections.EMPTY_LIST ){ - _ptrOperators = new ArrayList(4); - } - - _ptrOperators.add( ptr ); - } - } - - public void addPtrOperator( List ptrs ) { - if( ptrs == null || ptrs.size() == 0 ) - return; - - if( _ptrOperators == Collections.EMPTY_LIST ){ - _ptrOperators = new ArrayList( ptrs.size() ); - } - - int size = ptrs.size(); - for( int i = 0; i < size; i++ ){ - _ptrOperators.add( ptrs.get( i ) ); - } - } - - public void preparePtrOperators( int numPtrOps ) { - if( _ptrOperators == Collections.EMPTY_LIST ) - _ptrOperators = new ArrayList( numPtrOps ); - else - ((ArrayList) _ptrOperators).ensureCapacity( numPtrOps ); - } - - - /** - * canHold - * @param type - * @return boolean - * return true if our type can hold all the values of the passed in - * type. - * TODO, for now return true if our type is "larger" (based on ordering of - * the type values) - */ - public boolean canHold( ITypeInfo type ) { - if( getType().compareTo( type.getType()) > 0 ){ - return true; - } - int mask = isShort | isLong | isLongLong; - return ( getTypeBits() & mask ) >= ( type.getTypeBits() & mask ); - } - - public boolean equals( Object t ) { - if( t == null || !(t instanceof ITypeInfo) ){ - return false; - } - - ITypeInfo type = (ITypeInfo)t; - - int bits1 = _typeBits & ~isTypedef & ~isForward & ~isStatic & ~isExtern; - int bits2 = type.getTypeBits() & ~isTypedef & ~isForward & ~isStatic & ~isExtern; - boolean result = ( bits1 == bits2 ); - - result &= ( _type == type.getType() ); - -// Object def1 = getDefault(); -// Object def2 = type.getDefault(); -// result &= ( (def1 == null && def2 == null) || -// (def1 != null && def2 != null && def1.equals( def2 )) ); -// - if( !result ) - return false; - - int size1 = _ptrOperators.size(); - int size2 = type.getPtrOperators().size(); - if( size1 == size2 ){ - if( size1 != 0 ){ - ITypeInfo.PtrOp op1 = null, op2 = null; - for( int i = 0; i < size1; i++ ){ - op1 = (ITypeInfo.PtrOp)_ptrOperators.get(i); - op2 = (ITypeInfo.PtrOp)type.getPtrOperators().get(i); - - if( !op1.equals(op2) ){ - return false; - } - } - } - } else { - return false; - } - - return result; - } - - private static final char _image[][] = { ParserSymbolTable.EMPTY_NAME_ARRAY, //$NON-NLS-1$ t_undef - ParserSymbolTable.EMPTY_NAME_ARRAY, //t_type - "namespace".toCharArray(), //$NON-NLS-1$ t_namespace - "class".toCharArray(), //$NON-NLS-1$ t_class - "struct".toCharArray(), //$NON-NLS-1$ t_struct - "union".toCharArray(), //$NON-NLS-1$ t_union - "enum".toCharArray(), //$NON-NLS-1$ t_enumeration - ParserSymbolTable.EMPTY_NAME_ARRAY, //t_constructor - ParserSymbolTable.EMPTY_NAME_ARRAY, //t_function - "_Bool".toCharArray(), //$NON-NLS-1$ t__Bool - "bool".toCharArray(), //$NON-NLS-1$ t_bool - "char".toCharArray(), //$NON-NLS-1$ t_char - "wchar_t".toCharArray(), //$NON-NLS-1$ t_wchar_t - "int".toCharArray(), //$NON-NLS-1$ t_int - "float".toCharArray(), //$NON-NLS-1$ t_float - "double".toCharArray(), //$NON-NLS-1$ t_double - "void".toCharArray(), //$NON-NLS-1$ t_void - ParserSymbolTable.EMPTY_NAME_ARRAY, //t_enumerator - ParserSymbolTable.EMPTY_NAME_ARRAY, //t_block - "template".toCharArray(), //$NON-NLS-1$ t_template - ParserSymbolTable.EMPTY_NAME_ARRAY, //t_asm - ParserSymbolTable.EMPTY_NAME_ARRAY, //t_linkage - ParserSymbolTable.EMPTY_NAME_ARRAY, //t_templateParameter - "typename".toCharArray() //$NON-NLS-1$ t_typeName - }; - - public char[] toCharArray() { - if( isType( t_type ) && getTypeSymbol() != null ){ - return getTypeSymbol().getName(); - } - return _image[ getType().toInt() ]; - } - - public void clear() { - _typeBits = 0; - _type = t_undef; - _ptrOperators = Collections.EMPTY_LIST; - } - - public void copy( ITypeInfo t ) { - if( t == null ) - return; - _typeBits = t.getTypeBits(); - _type = t.getType(); - - if( t.getPtrOperators() != Collections.EMPTY_LIST ) - _ptrOperators = (ArrayList)((ArrayList)t.getPtrOperators()).clone(); - else - _ptrOperators = Collections.EMPTY_LIST; - } - - public boolean getHasDefault(){ - return _hasDefault; - } - public void setHasDefault( boolean def ){ - _hasDefault = def; - } - - /** - * The following functions are implemented in derived classes - */ - public ITypeInfo.eType getTemplateParameterType() { return ITypeInfo.t_undef; } - public void setTemplateParameterType( ITypeInfo.eType type ) { throw new UnsupportedOperationException(); } - public ISymbol getTypeSymbol() { return null; } - public void setTypeSymbol( ISymbol type ) { if( type != null ) throw new UnsupportedOperationException(); } - public void setDefault( Object t ) { if( t != null ) throw new UnsupportedOperationException(); } - public Object getDefault() { return null; } - - protected int _typeBits = 0; - protected ITypeInfo.eType _type = t_undef; - protected List _ptrOperators = Collections.EMPTY_LIST; - protected boolean _hasDefault = false; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java deleted file mode 100644 index e4dd22bd2dc..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java +++ /dev/null @@ -1,1213 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on Nov 4, 2003 - */ - -package org.eclipse.cdt.internal.core.parser.pst; - -import java.text.Collator; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.IASTMember; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.core.parser.util.CharArraySet; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.core.parser.util.ObjectSet; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class ContainerSymbol extends BasicSymbol implements IContainerSymbol { - - protected ContainerSymbol( ParserSymbolTable table, char[] name ){ - super( table, name ); - } - - protected ContainerSymbol( ParserSymbolTable table, char[] name, ITypeInfo.eType typeInfo ){ - super( table, name, typeInfo ); - } - - public Object clone(){ - ContainerSymbol copy = (ContainerSymbol)super.clone(); - - copy._usingDirectives = (_usingDirectives != Collections.EMPTY_LIST) ? (List) ((ArrayList)_usingDirectives).clone() : _usingDirectives; - copy._containedSymbols = (CharArrayObjectMap) ( ( _containedSymbols != CharArrayObjectMap.EMPTY_MAP )? _containedSymbols.clone() : _containedSymbols ); - copy._contents = (_contents != Collections.EMPTY_LIST) ? (List) ((ArrayList)_contents).clone() : _contents; - - return copy; - } - - public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{ - if( !isTemplateMember() || template == null ){ - return null; - } - - ContainerSymbol newContainer = (ContainerSymbol) super.instantiate( template, argMap ); - - Iterator iter = getContentsIterator(); - - newContainer.getContainedSymbols().clear(); - if( !newContainer._contents.isEmpty() ){ - newContainer._contents.clear(); - - IExtensibleSymbol containedSymbol = null; - ISymbol newSymbol = null; - - while( iter.hasNext() ){ - containedSymbol = (IExtensibleSymbol) iter.next(); - - if( containedSymbol instanceof IUsingDirectiveSymbol ){ - newContainer._contents.add( containedSymbol ); - } else { - ISymbol symbol = (ISymbol) containedSymbol; - if( symbol.isForwardDeclaration() && symbol.getForwardSymbol() != null ){ - continue; - } - - if( !template.getExplicitSpecializations().isEmpty() ){ - List params = template.getParameterList(); - int size = template.getParameterList().size(); - List argList = new ArrayList( size ); - boolean hasAllParams = true; - for( int i = 0; i < size; i++ ){ - Object obj = argMap.get( params.get( i ) ); - if( obj == null ){ - hasAllParams = false; - break; - } - argList.add( obj ); - } - if( hasAllParams){ - ISymbol temp = TemplateEngine.checkForTemplateExplicitSpecialization( template, symbol, argList ); - if( temp != null ) - containedSymbol = temp; - } - } - - ObjectMap instanceMap = argMap; - if( !template.getDefinitionParameterMap().isEmpty() && - template.getDefinitionParameterMap().containsKey( containedSymbol ) ) - { - ObjectMap defMap = (ObjectMap) template.getDefinitionParameterMap().get( containedSymbol ); - instanceMap = new ObjectMap(defMap.size()); - for( int i = 0; i < defMap.size(); i++ ){ - ISymbol p = (ISymbol) defMap.keyAt(i); - instanceMap.put( p, argMap.get( defMap.get( p ) ) ); - } - } - - newSymbol = ((ISymbol)containedSymbol).instantiate( template, instanceMap ); - newSymbol.setContainingSymbol( newContainer ); - newContainer._contents.add( newSymbol ); - - if( newSymbol instanceof IParameterizedSymbol && newSymbol.isType( ITypeInfo.t_constructor ) ){ - collectInstantiatedConstructor( (IParameterizedSymbol) containedSymbol ); - } else { - if( newContainer.getContainedSymbols().containsKey( newSymbol.getName() ) ){ - Object obj = newContainer.getContainedSymbols().get( newSymbol.getName() ); - if( obj instanceof List ){ - ((List) obj).add( newSymbol ); - } else { - List list = new ArrayList(4); - list.add( obj ); - list.add( newSymbol ); - newContainer.putInContainedSymbols( newSymbol.getName(), list ); - } - } else { - newContainer.putInContainedSymbols( newSymbol.getName(), newSymbol ); - } - } - } - } - } - - return newContainer; - } - - protected void collectInstantiatedConstructor( IParameterizedSymbol constructor ){ - throw new ParserSymbolTableError(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addSymbol(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void addSymbol( ISymbol obj ) throws ParserSymbolTableException{ - IContainerSymbol containing = this; - - //handle enumerators - if( obj.getType() == ITypeInfo.t_enumerator ){ - //a using declaration of an enumerator will not be contained in a - //enumeration. - if( containing.getType() == ITypeInfo.t_enumeration ){ - //Following the closing brace of an enum-specifier, each enumerator has the type of its - //enumeration - obj.setTypeSymbol( containing ); - //Each enumerator is declared in the scope that immediately contains the enum-specifier - containing = containing.getContainingSymbol(); - } - } - - if( obj.isType( ITypeInfo.t_template ) ){ - if( ! TemplateEngine.canAddTemplate( containing, (ITemplateSymbol) obj ) ) { - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - } - } - - //in C, structs, unions, enums don't nest - if( getSymbolTable().getLanguage() == ParserLanguage.C ){ - if( obj.isType( ITypeInfo.t_struct, ITypeInfo.t_enumeration ) ){ - containing = getScopeForCTag( containing ); - } - } - - //14.6.1-4 A Template parameter shall not be redeclared within its scope. - if( isTemplateMember() || isType( ITypeInfo.t_template ) ){ - if( TemplateEngine.alreadyHasTemplateParameter( this, obj.getName() ) ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_RedeclaredTemplateParam ); - } - } - - boolean unnamed = CharArrayUtils.equals( obj.getName(), ParserSymbolTable.EMPTY_NAME_ARRAY ); - - Object origObj = null; - - obj.setContainingSymbol( containing ); - - //does this name exist already? - origObj = containing.getContainedSymbols().get( obj.getName() ); - - if( origObj != null ) - { - ISymbol origDecl = null; - ArrayList origList = null; - - if( origObj instanceof ISymbol ){ - origDecl = (ISymbol)origObj; - } else if( origObj.getClass() == ArrayList.class ){ - origList = (ArrayList)origObj; - } else { - throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError ); - } - - boolean validOverride = ( !unnamed ? ( (origList == null) ? ParserSymbolTable.isValidOverload( origDecl, obj ) - : ParserSymbolTable.isValidOverload( origList, obj ) ) - : true ); - - if( unnamed || validOverride ) - { - if( origList == null ){ - origList = new ArrayList(4); - origList.add( origDecl ); - origList.add( obj ); - - ((ContainerSymbol)containing).putInContainedSymbols( obj.getName(), origList ); - } else { - origList.add( obj ); - //origList is already in _containedDeclarations - } - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidOverload ); - } - } else { - ((ContainerSymbol)containing).putInContainedSymbols( obj.getName(), obj ); - } - - obj.setIsTemplateMember( isTemplateMember() || getType() == ITypeInfo.t_template ); - - addToContents( obj ); - -// Command command = new AddSymbolCommand( obj, containing ); -// getSymbolTable().pushCommand( command ); - } - -// public boolean removeSymbol( ISymbol symbol ){ -// boolean removed = false; -// -// StringObjectMap contained = getContainedSymbols(); -// -// if( symbol != null && contained.containsKey( symbol.getName() ) ){ -// Object obj = contained.get( symbol.getName() ); -// if( obj instanceof ISymbol ){ -// if( obj == symbol ){ -// contained.remove( symbol.getName() ); -// removed = true; -// } -// } else if ( obj instanceof List ){ -// List list = (List) obj; -// if( list.remove( symbol ) ){ -// if( list.size() == 1 ){ -// contained.put( symbol.getName(), list.get( 0 ) ); -// } -// removed = true; -// } -// } -// } -// -// if( removed ){ -// ListIterator iter = getContents().listIterator( getContents().size() ); -// while( iter.hasPrevious() ){ -// if( iter.previous() == symbol ){ -// iter.remove(); -// break; -// } -// } -// } -// -// return removed; -// } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#hasUsingDirectives() - */ - public boolean hasUsingDirectives(){ - return !_usingDirectives.isEmpty(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getUsingDirectives() - */ - public List getUsingDirectives(){ - return _usingDirectives; - } - - protected void addToUsingDirectives( IExtensibleSymbol symbol ){ - if( _usingDirectives == Collections.EMPTY_LIST ) - _usingDirectives = new ArrayList(4); - _usingDirectives.add( symbol ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDirective(org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) - */ - public IUsingDirectiveSymbol addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException{ - if( namespace.getType() != ITypeInfo.t_namespace ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing ); - } - //7.3.4 A using-directive shall not appear in class scope - if( isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing ); - } - - //handle namespace aliasing - ISymbol alias = namespace.getForwardSymbol(); - if( alias != null && alias.isType( ITypeInfo.t_namespace ) ){ - namespace = (IContainerSymbol) alias; - } - - IUsingDirectiveSymbol usingDirective = new UsingDirectiveSymbol( getSymbolTable(), namespace ); - - addToUsingDirectives( usingDirective ); - addToContents( usingDirective ); - -// Command command = new AddUsingDirectiveCommand( this, usingDirective ); -// getSymbolTable().pushCommand( command ); - - return usingDirective; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDeclaration(java.lang.String) - */ - /** - * addUsingDeclaration - * @param obj - * @throws ParserSymbolTableException - * - * 7.3.3-9 The entity declared by a using-declaration shall be known in the - * context using it according to its definition at the point of the using- - * declaration. Definitions added to the namespace after the using- - * declaration are not considered when a use of the name is made. - * - * 7.3.3-4 A using-declaration used as a member-declaration shall refer to a - * member of a base class of the class being defined, shall refer to a - * member of an anonymous union that is a member of a base class of the - * class being defined, or shall refer to an enumerator for an enumeration - * type that is a member of a base class of the class being defined. - */ - public IUsingDeclarationSymbol addUsingDeclaration( char[] name ) throws ParserSymbolTableException { - return addUsingDeclaration( name, null ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDeclaration(java.lang.String, org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) - */ - public IUsingDeclarationSymbol addUsingDeclaration( char[] name, IContainerSymbol declContext ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name ); - - if( declContext != null ){ - data.qualified = true; - ParserSymbolTable.lookup( data, declContext ); - } else { - ParserSymbolTable.lookup( data, this ); - } - - //figure out which declaration we are talking about, if it is a set of functions, - //then they will be in data.foundItems (since we provided no parameter info); - ISymbol symbol = null; - ISymbol clone = null; - int objListSize = 0; - List objList = null; - - try{ - symbol = getSymbolTable().resolveAmbiguities( data ); - } catch ( ParserSymbolTableException e ) { - if( e.reason != ParserSymbolTableException.r_UnableToResolveFunction ){ - throw e; - } - } - - if( symbol == null && (data.foundItems == null || data.foundItems.isEmpty()) ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing ); - } - - if( symbol == null ){ - Object object = data.foundItems.get( data.name ); - objList = ( object instanceof List ) ? (List) object : null; - objListSize = ( objList != null ) ? objList.size() : 0; - symbol = ( objListSize > 0 ) ? (ISymbol)objList.get(0) : null; - } - - List usingDecs = new ArrayList( ( objListSize > 0 ) ? objListSize : 1 ); - List usingRefs = new ArrayList( ( objListSize > 0 ) ? objListSize : 1 ); - - UsingDeclarationSymbol usingDeclaration = new UsingDeclarationSymbol( getSymbolTable(), usingRefs, usingDecs ); - boolean addedUsingToContained = false; - int idx = 1; - while( symbol != null ){ - if( ParserSymbolTable.okToAddUsingDeclaration( symbol, this ) ){ - if( ! addedUsingToContained ){ - addToContents( usingDeclaration ); - addedUsingToContained = true; - } - clone = (ISymbol) symbol.clone(); //7.3.3-9 - - clone.setForwardSymbol(symbol); - clone.setIsForwardDeclaration(true); - - addSymbol( clone ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing ); - } - - usingDecs.add( clone ); - usingRefs.add( symbol ); - - if( objList != null && idx < objListSize ){ - symbol = (ISymbol) objList.get( idx++ ); - } else { - symbol = null; - } - } - - return usingDeclaration; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getContainedSymbols() - */ - public CharArrayObjectMap getContainedSymbols(){ - return _containedSymbols; - } - - protected void putInContainedSymbols( char[] key, Object obj ){ - if( _containedSymbols == CharArrayObjectMap.EMPTY_MAP ){ - _containedSymbols = new CharArrayObjectMap( 4 ); - } - _containedSymbols.put( key, obj ); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#elaboratedLookup(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType, java.lang.String) - */ - public ISymbol elaboratedLookup( final ITypeInfo.eType type, char[] name ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name ){ - public TypeFilter getFilter() { - if( t == ITypeInfo.t_any ) return ANY_FILTER; - if( filter == null ) filter = new TypeFilter( t ); - return filter; - } - private TypeFilter filter = null; - private final ITypeInfo.eType t = type; - }; - - ParserSymbolTable.lookup( data, this ); - - ISymbol found = getSymbolTable().resolveAmbiguities( data ); - - if( isTemplateMember() && found instanceof ITemplateSymbol ) { - boolean areWithinTemplate = false; - IContainerSymbol container = getContainingSymbol(); - while( container != null ){ - if( container == found ){ - areWithinTemplate = true; - break; - } - container = container.getContainingSymbol(); - } - if( areWithinTemplate ) - return TemplateEngine.instantiateWithinTemplateScope( this, (ITemplateSymbol) found ); - } - - return found; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookup(java.lang.String) - */ - public ISymbol lookup( char[] name ) throws ParserSymbolTableException { - LookupData data = new LookupData( name ); - - ParserSymbolTable.lookup( data, this ); - - ISymbol found = getSymbolTable().resolveAmbiguities( data ); - - if( isTemplateMember() && found instanceof ITemplateSymbol ) { - return TemplateEngine.instantiateWithinTemplateScope( this, (ITemplateSymbol) found ); - } - - return found; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupMemberForDefinition(java.lang.String) - */ - /** - * LookupMemberForDefinition - * @param name - * @return Declaration - * @throws ParserSymbolTableException - * - * In a definition for a namespace member in which the declarator-id is a - * qualified-id, given that the qualified-id for the namespace member has - * the form "nested-name-specifier unqualified-id", the unqualified-id shall - * name a member of the namespace designated by the nested-name-specifier. - * - * ie: - * you have this: - * namespace A{ - * namespace B{ - * void f1(int); - * } - * using namespace B; - * } - * - * if you then do this - * void A::f1(int) { ... } //ill-formed, f1 is not a member of A - * but, you can do this (Assuming f1 has been defined elsewhere) - * A::f1( 1 ); //ok, finds B::f1 - * - * ie, We need a seperate lookup function for looking up the member names - * for a definition. - */ - public ISymbol lookupMemberForDefinition( char[] name, final ITypeInfo.eType type ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name ){ - public TypeFilter getFilter() { - if( t == ITypeInfo.t_any ) return ANY_FILTER; - if( filter == null ) filter = new TypeFilter( t ); - return filter; - } - private TypeFilter filter = null; - private final ITypeInfo.eType t = type; - }; - - data.qualified = true; - - IContainerSymbol container = this; - - //handle namespace aliases - if( container.isType( ITypeInfo.t_namespace ) ){ - ISymbol symbol = container.getForwardSymbol(); - if( symbol != null && symbol.isType( ITypeInfo.t_namespace ) ){ - container = (IContainerSymbol) symbol; - } - } - - data.foundItems = ParserSymbolTable.lookupInContained( data, container ); - if( data.foundItems != null ) - return getSymbolTable().resolveAmbiguities( data ); - return null; - } - - public ISymbol lookupMemberForDefinition( char[] name ) throws ParserSymbolTableException { - return lookupMemberForDefinition(name, ITypeInfo.t_any); - } - - public IParameterizedSymbol lookupMethodForDefinition( char[] name, final List parameters ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name ){ - public List getParameters() { return params; } - final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters; - }; - data.qualified = true; - data.exactFunctionsOnly = true; - - IContainerSymbol container = this; - - //handle namespace aliases - if( container.isType( ITypeInfo.t_namespace ) ){ - ISymbol symbol = container.getForwardSymbol(); - if( symbol != null && symbol.isType( ITypeInfo.t_namespace ) ){ - container = (IContainerSymbol) symbol; - } - } - - data.foundItems = ParserSymbolTable.lookupInContained( data, container ); - - if( data.foundItems != null ){ - ISymbol symbol = getSymbolTable().resolveAmbiguities( data ); - return (IParameterizedSymbol) (( symbol instanceof IParameterizedSymbol ) ? symbol : null); - } - - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupNestedNameSpecifier(java.lang.String) - */ - /** - * Method LookupNestedNameSpecifier. - * @param name - * @return Declaration - * The name of a class or namespace member can be referred to after the :: - * scope resolution operator applied to a nested-name-specifier that - * nominates its class or namespace. During the lookup for a name preceding - * the ::, object, function and enumerator names are ignored. If the name - * is not a class-name or namespace-name, the program is ill-formed - */ - public ISymbol lookupNestedNameSpecifier( char[] name ) throws ParserSymbolTableException { - return lookupNestedNameSpecifier( name, this ); - } - - private ISymbol lookupNestedNameSpecifier(char[] name, IContainerSymbol inSymbol ) throws ParserSymbolTableException{ - ISymbol foundSymbol = null; - - final TypeFilter filter = new TypeFilter( ITypeInfo.t_namespace ); - filter.addAcceptedType( ITypeInfo.t_class ); - filter.addAcceptedType( ITypeInfo.t_struct ); - filter.addAcceptedType( ITypeInfo.t_union ); - filter.addAcceptedType( ITypeInfo.t_templateParameter ); - filter.addAcceptedType( IASTNode.LookupKind.TYPEDEFS ); - - LookupData data = new LookupData( name ){ - public TypeFilter getFilter() { return typeFilter; } - final private TypeFilter typeFilter = filter; - }; - - ParserSymbolTable.lookup( data, inSymbol ); - - if( data.foundItems != null ){ - foundSymbol = getSymbolTable().resolveAmbiguities( data ); - } - - return foundSymbol; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#qualifiedLookup(java.lang.String) - */ - public ISymbol qualifiedLookup( char[] name ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name ); - data.qualified = true; - ParserSymbolTable.lookup( data, this ); - - return getSymbolTable().resolveAmbiguities( data ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#qualifiedLookup(java.lang.String, org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType) - */ - public ISymbol qualifiedLookup( char[] name, final ITypeInfo.eType t ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name ){ - public TypeFilter getFilter() { - if( t == ITypeInfo.t_any ) return ANY_FILTER; - - if( filter == null ) - filter = new TypeFilter( t ); - return filter; - - } - private TypeFilter filter = null; - }; - data.qualified = true; - ParserSymbolTable.lookup( data, this ); - - return getSymbolTable().resolveAmbiguities( data ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#unqualifiedFunctionLookup(java.lang.String, java.util.List) - */ - /** - * UnqualifiedFunctionLookup - * @param name - * @param parameters - * @return Declaration - * @throws ParserSymbolTableException - * - * 3.4.2-1 When an unqualified name is used as the post-fix expression in a - * function call, other namespaces not consdiered during the usual - * unqualified lookup may be searched. - * - * 3.4.2-2 For each argument type T in the function call, there is a set of - * zero or more associated namespaces and a set of zero or more associated - * classes to be considered. - * - * If the ordinary unqualified lookup of the name find the declaration of a - * class member function, the associated namespaces and classes are not - * considered. Otherwise, the set of declarations found by the lookup of - * the function name is the union of the set of declarations found using - * ordinary unqualified lookup and the set of declarations found in the - * namespaces and classes associated with the argument types. - */ - public IParameterizedSymbol unqualifiedFunctionLookup( char[] name, final List parameters ) throws ParserSymbolTableException{ - //figure out the set of associated scopes first, so we can remove those that are searched - //during the normal lookup to avoid doing them twice - ObjectSet associated = ObjectSet.EMPTY_SET; - - //collect associated namespaces & classes. - int size = ( parameters == null ) ? 0 : parameters.size(); - - ITypeInfo param = null; - ISymbol paramType = null; - for( int i = 0; i < size; i++ ){ - param = (ITypeInfo) parameters.get(i); - ITypeInfo info = ParserSymbolTable.getFlatTypeInfo( param, getSymbolTable().getTypeInfoProvider() ); - paramType = info.getTypeSymbol(); - getSymbolTable().getTypeInfoProvider().returnTypeInfo( info ); - - if( paramType == null ){ - continue; - } - - if( associated == ObjectSet.EMPTY_SET ) - associated = new ObjectSet( 2 ); - ParserSymbolTable.getAssociatedScopes( paramType, associated ); - - //if T is a pointer to a data member of class X, its associated namespaces and classes - //are those associated with the member type together with those associated with X - if( param.hasPtrOperators() && param.getPtrOperators().size() == 1 ){ - ITypeInfo.PtrOp op = (ITypeInfo.PtrOp)param.getPtrOperators().get(0); - if( op.getType() == ITypeInfo.PtrOp.t_pointer && - paramType.getContainingSymbol().isType( ITypeInfo.t_class, ITypeInfo.t_union ) ) - { - ParserSymbolTable.getAssociatedScopes( paramType.getContainingSymbol(), associated ); - } - } - } - final ObjectSet associatedData = associated; - LookupData data = new LookupData( name ){ - public ObjectSet getAssociated() { return assoc; } - public List getParameters() { return params; } - public TypeFilter getFilter() { return FUNCTION_FILTER; } - - final private ObjectSet assoc = associatedData; - final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters; - }; - - ParserSymbolTable.lookup( data, this ); - - ISymbol found = getSymbolTable().resolveAmbiguities( data ); - - //if we haven't found anything, or what we found is not a class member, consider the - //associated scopes - if( found == null || found.getContainingSymbol().getType() != ITypeInfo.t_class ){ -// if( found != null ){ -// data.foundItems.add( found ); -// } - - IContainerSymbol associatedScope; - //dump the hash to an array and iterate over the array because we - //could be removing items from the collection as we go and we don't - //want to get ConcurrentModificationExceptions - Object [] scopes = associated.keyArray(); - - size = associated.size(); - - for( int i = 0; i < size; i++ ){ - associatedScope = (IContainerSymbol) scopes[ i ]; - if( associated.containsKey( associatedScope ) ){ - data.qualified = true; - data.ignoreUsingDirectives = true; - data.usingDirectivesOnly = false; - ParserSymbolTable.lookup( data, associatedScope ); - } - } - - found = getSymbolTable().resolveAmbiguities( data ); - } - - if( found instanceof IParameterizedSymbol ) - return (IParameterizedSymbol) found; - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#memberFunctionLookup(java.lang.String, java.util.List) - */ - /** - * MemberFunctionLookup - * @param name - * @param parameters - * @return Declaration - * @throws ParserSymbolTableException - * - * Member lookup really proceeds as an unqualified lookup, but doesn't - * include argument dependant scopes - */ - public IParameterizedSymbol memberFunctionLookup( char[] name, final List parameters ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name ){ - public List getParameters() { return params; } - final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters; - public TypeFilter getFilter() { return FUNCTION_FILTER; } - }; - ParserSymbolTable.lookup( data, this ); - return (IParameterizedSymbol) getSymbolTable().resolveAmbiguities( data ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#qualifiedFunctionLookup(java.lang.String, java.util.List) - */ - public IParameterizedSymbol qualifiedFunctionLookup( char[] name, final List parameters ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name ){ - public List getParameters() { return params; } - final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters; - public TypeFilter getFilter() { return FUNCTION_FILTER; } - }; - data.qualified = true; - - ParserSymbolTable.lookup( data, this ); - - return (IParameterizedSymbol) getSymbolTable().resolveAmbiguities( data ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#templateLookup(java.lang.String, java.util.List) - */ - public ISymbol lookupTemplateId( char[] name, List arguments ) throws ParserSymbolTableException - { - LookupData data = new LookupData( name ); - - ParserSymbolTable.lookup( data, this ); - ISymbol found = getSymbolTable().resolveAmbiguities( data ); - if( found != null ){ - if( (found.isType( ITypeInfo.t_templateParameter ) && found.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template) || - found.isType( ITypeInfo.t_template ) ) - { - found = ((ITemplateSymbol) found).instantiate( arguments ); - } else if( found.getContainingSymbol().isType( ITypeInfo.t_template ) ){ - found = ((ITemplateSymbol) found.getContainingSymbol()).instantiate( arguments ); - } - } - - return found; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupFunctionTemplateId(java.lang.String, java.util.List, java.util.List) - */ - public ISymbol lookupFunctionTemplateId(char[] name, final List parameters, final List arguments, boolean forDefinition) throws ParserSymbolTableException { - LookupData data = new LookupData( name ){ - public List getParameters() { return params; } - public List getTemplateParameters() { return templateParams; } - public TypeFilter getFilter() { return FUNCTION_FILTER; } - final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters; - final private List templateParams = arguments; - }; - data.exactFunctionsOnly = forDefinition; - - ParserSymbolTable.lookup( data, this ); - ISymbol found = getSymbolTable().resolveAmbiguities( data ); - - return found; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupTemplateIdForDefinition(java.lang.String, java.util.List) - */ - public IContainerSymbol lookupTemplateIdForDefinition(char[] name, List arguments){ - // TODO Auto-generated method stub - return null; - } - - public List prefixLookup( final TypeFilter filter, char[] prefix, boolean qualified, final List paramList ) throws ParserSymbolTableException{ - LookupData data = new LookupData( prefix ){ - public List getParameters() { return params; } - public boolean isPrefixLookup(){ return true; } - public CharArraySet getAmbiguities(){ return ambiguities; } - public TypeFilter getFilter() { return typeFilter; } - - public void addAmbiguity( char[] n ){ - if( ambiguities == CharArraySet.EMPTY_SET ){ - ambiguities = new CharArraySet(2); - } - ambiguities.put( n ); - } - - final private List params = paramList; - private CharArraySet ambiguities = CharArraySet.EMPTY_SET; - final private TypeFilter typeFilter = filter; - }; - - data.qualified = qualified; - - ParserSymbolTable.lookup( data, this ); - - List constructors = null; - if( filter != null && filter.willAccept( ITypeInfo.t_constructor ) && (this instanceof IDerivableContainerSymbol) ){ - if( CharArrayUtils.equals( getName(), 0, prefix.length, prefix, true ) ){ - List temp = ((IDerivableContainerSymbol)this).getConstructors(); - int size = temp.size(); - constructors = new ArrayList( size ); - for( int i = 0; i < size; i++ ) - constructors.add( temp.get( i ) ); - } - } - - if( data.foundItems == null || data.foundItems.isEmpty() ){ - if( constructors != null ){ - if( paramList != null ){ - getSymbolTable().resolveFunction( data, constructors ); - return constructors; - } - return constructors; - } - return null; - } - - List list = new ArrayList(); - - Object obj = null; - char[] key = null; - List tempList = null; - int size = data.foundItems.size(); - for( int i = 0; i < size; i++ ){ - key = data.foundItems.keyAt( i ); - - //skip ambiguous symbols - if( data.getAmbiguities() != null && data.getAmbiguities().containsKey( key ) ) - continue; - - obj = data.foundItems.get( key ); - - if( obj instanceof List ){ - //a list must be all functions? - if( paramList != null ) - getSymbolTable().resolveFunction( data, (List) obj ); - list.addAll( (List) obj ); - } else{ - if( paramList != null && ((ISymbol)obj).isType( ITypeInfo.t_function ) ) - { - if( tempList == null ) - tempList = new ArrayList(1); - else - tempList.clear(); - tempList.add( obj ); - getSymbolTable().resolveFunction( data, tempList ); - list.addAll( tempList ); - } else { - list.add( obj ); - } - } - } - - if( constructors != null ) - list.addAll( constructors ); - - return list; - - } - - public boolean isVisible( ISymbol symbol, IContainerSymbol qualifyingSymbol ){ - ISymbolASTExtension extension = symbol.getASTExtension(); - if(extension == null) - return true; - IASTNode node = extension.getPrimaryDeclaration(); - if(node == null) - return true; - - if( node instanceof IASTMember ){ - ASTAccessVisibility visibility; - - visibility = ParserSymbolTable.getVisibility( symbol, qualifyingSymbol ); - if( visibility == null ) - return false; - - if( visibility == ASTAccessVisibility.PUBLIC ){ - return true; - } - - IContainerSymbol container = getContainingSymbol(); - IContainerSymbol symbolContainer = symbol.getContainingSymbol(); - - if( !symbolContainer.isType( ITypeInfo.t_class, ITypeInfo.t_union ) || - symbolContainer.equals( container ) ) - { - return true; - } - - //if this is a friend of the symbolContainer, then we are good - if( isFriendOf( ( qualifyingSymbol != null ) ? qualifyingSymbol : symbolContainer ) ){ - return true; - } - - if( visibility == ASTAccessVisibility.PROTECTED ) - { - try { - return ( ParserSymbolTable.hasBaseClass( container, symbolContainer ) >= 0 ); - } catch (ParserSymbolTableException e) { - return false; - } - } - return false; - } - return true; - } - - protected boolean isFriendOf( IContainerSymbol symbol ){ - if( symbol instanceof IDerivableContainerSymbol ){ - IContainerSymbol container = this.getContainingSymbol(); - - while( container != null && container.isType( ITypeInfo.t_block ) ){ - container = container.getContainingSymbol(); - } - if( container != null && !container.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){ - container = null; - } - - IDerivableContainerSymbol derivable = (IDerivableContainerSymbol) symbol; - - List friends = derivable.getFriends(); - int size = friends.size(); - for( int i = 0; i < size; i++ ){ - ISymbol friend = (ISymbol) friends.get(i); - ISymbol forwardSymbol = friend.getForwardSymbol(); - if( friend == this || forwardSymbol == this || - friend == container || ( container != null && forwardSymbol == container ) ) - { - return true; - } - } - } - return false; - } - - private IContainerSymbol getScopeForCTag( IContainerSymbol container ){ - while( !container.isType( ITypeInfo.t_namespace ) && - !container.isType( ITypeInfo.t_function ) && - !container.isType( ITypeInfo.t_block ) ) - { - container = container.getContainingSymbol(); - } - return container; - } - - protected void addToContents( IExtensibleSymbol symbol ){ - if( _contents == Collections.EMPTY_LIST ){ - if( isType( ITypeInfo.t_namespace ) ) - _contents = new ArrayList( 64 ); - else if( isType( ITypeInfo.t_class ) || isType( ITypeInfo.t_struct ) ) - _contents = new ArrayList( 32 ); - else if( isType( ITypeInfo.t_function ) ) - _contents = new ArrayList( 16 ); - else - _contents = new ArrayList( 8 ); - } - _contents.add( symbol ); - } - - protected List getContents(){ - return _contents; - } - - public Iterator getContentsIterator(){ - return new ContentsIterator( getContents() ); - } - - protected class ContentsIterator implements Iterator { - final List internalList; - private int idx = 0; - ObjectSet alreadyReturned = new ObjectSet( 2 ); - - public ContentsIterator( List contents ){ - internalList = contents; - } - - IExtensibleSymbol next = null; - public boolean hasNext() { - if( next != null ){ - return true; - } - if( internalList.size() <= idx ) - return false; - for( ; idx < internalList.size(); ){ - IExtensibleSymbol extensible = (IExtensibleSymbol) internalList.get(idx++); - if( !alreadyReturned.containsKey( extensible ) ){ - if( extensible instanceof ISymbol ){ - ISymbol symbol = (ISymbol) extensible; - ISymbol forward = symbol.getForwardSymbol(); - if( symbol.isForwardDeclaration() && forward != null && - forward.getContainingSymbol() == ContainerSymbol.this ) - { - alreadyReturned.put( forward ); - next = forward; - return true; - } - } else if( extensible instanceof IUsingDeclarationSymbol ){ - IUsingDeclarationSymbol using = (IUsingDeclarationSymbol) extensible; - alreadyReturned.addAll( using.getDeclaredSymbols() ); - } - next = extensible; - return true; - } - } - return false; - } - - public Object next() { - IExtensibleSymbol extensible = next; - if( next != null ){ - next = null; - return extensible; - } - - for( ; idx < internalList.size(); ){ - extensible = (IExtensibleSymbol) internalList.get(idx++); - if( !alreadyReturned.containsKey( extensible ) ){ - if( extensible instanceof ISymbol ){ - ISymbol symbol = (ISymbol) extensible; - if( symbol.isForwardDeclaration() && symbol.getForwardSymbol() != null && - symbol.getForwardSymbol().getContainingSymbol() == ContainerSymbol.this ) - { - alreadyReturned.put( symbol.getForwardSymbol() ); - return symbol.getForwardSymbol(); - } - } else if( extensible instanceof IUsingDeclarationSymbol ){ - IUsingDeclarationSymbol using = (IUsingDeclarationSymbol) extensible; - alreadyReturned.addAll( using.getDeclaredSymbols() ); - } - return extensible; - } - } - throw new NoSuchElementException(); - } - - public void remove() { - throw new UnsupportedOperationException(); - } - } -// static private class AddSymbolCommand extends Command{ -// AddSymbolCommand( ISymbol newDecl, IContainerSymbol context ){ -// _symbol = newDecl; -// _context = context; -// } -// -// public void undoIt(){ -// Object obj = _context.getContainedSymbols().get( _symbol.getName() ); -// -// if( obj instanceof ArrayList ){ -// ArrayList list = (ArrayList)obj; -// ListIterator iter = list.listIterator(); -// int size = list.size(); -// ISymbol item = null; -// for( int i = 0; i < size; i++ ){ -// item = (ISymbol)iter.next(); -// if( item == _symbol ){ -// iter.remove(); -// break; -// } -// } -// if( list.size() == 1 ){ -// _context.getContainedSymbols().put( _symbol.getName(), list.get(0) ); -// } -// } else if( obj instanceof BasicSymbol ){ -// _context.getContainedSymbols().remove( _symbol.getName() ); -// } -// -// //this is an inefficient way of doing this, we can modify the interfaces if the undo starts -// //being used often. -// ContentsIterator iter = (ContentsIterator) _context.getContentsIterator(); -// while( iter.hasNext() ){ -// IExtensibleSymbol ext = (IExtensibleSymbol) iter.next(); -// if( ext == _symbol ){ -// iter.removeSymbol(); -// break; -// } -// } -// } -// -// private final ISymbol _symbol; -// private final IContainerSymbol _context; -// } - -// static private class AddUsingDirectiveCommand extends Command{ -// public AddUsingDirectiveCommand( IContainerSymbol container, IUsingDirectiveSymbol directive ){ -// _decl = container; -// _directive = directive; -// } -// public void undoIt(){ -// _decl.getUsingDirectives().remove( _directive ); -// -// //this is an inefficient way of doing this, we can modify the interfaces if the undo starts -// //being used often. -// ContentsIterator iter = (ContentsIterator) _decl.getContentsIterator(); -// while( iter.hasNext() ){ -// IExtensibleSymbol ext = (IExtensibleSymbol) iter.next(); -// if( ext == _directive ){ -// iter.removeSymbol(); -// break; -// } -// } -// } -// private final IContainerSymbol _decl; -// private final IUsingDirectiveSymbol _directive; -// } - - static public final SymbolTableComparator comparator = new SymbolTableComparator(); - static protected class SymbolTableComparator implements Comparator{ - static final private Collator collator = Collator.getInstance(); - static { collator.setStrength( Collator.PRIMARY ); } - public int compare( Object o1, Object o2 ){ - String s1 = String.valueOf( (char[])o1 ); - String s2 = String.valueOf( (char[])o2 ); - int result = collator.compare( s1, s2 ); - if( result == 0 ){ - collator.setStrength( Collator.IDENTICAL ); - result = collator.compare( s1, s2 ); - collator.setStrength( Collator.PRIMARY ); - } - return result; - } - - public boolean equals( Object obj ){ - return ( obj instanceof SymbolTableComparator ); - } - } - - private List _contents = Collections.EMPTY_LIST; //ordered list of all contents of this symbol - private List _usingDirectives = Collections.EMPTY_LIST; //collection of nominated namespaces - private CharArrayObjectMap _containedSymbols = CharArrayObjectMap.EMPTY_MAP; //declarations contained by us. - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addTemplateId(org.eclipse.cdt.internal.core.parser.pst.ISymbol, java.util.List) - */ - public void addTemplateId(ISymbol symbol, List args) throws ParserSymbolTableException { - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java deleted file mode 100644 index ff34309ab1e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DeferredTemplateInstance.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.core.parser.util.ObjectMap; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class DeferredTemplateInstance extends BasicSymbol implements IDeferredTemplateInstance { - - public DeferredTemplateInstance( ParserSymbolTable table, ITemplateSymbol template, List args ){ - super(table, ParserSymbolTable.EMPTY_NAME_ARRAY ); - _template = template; - _arguments = new ArrayList( args ); - - setContainingSymbol( template ); - if( template.getTemplatedSymbol() != null ) - setASTExtension( template.getTemplatedSymbol().getASTExtension() ); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDeferredTemplateInstance#getTemplate() - */ - public ITemplateSymbol getTemplate() { - return _template; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDeferredTemplateInstance#getArgumentMap() - */ - public List getArguments() { - return _arguments; - } - - public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{ - List args = getArguments(); - List newArgs = new ArrayList( args.size() ); - int size = args.size(); - for( int i = 0; i < size; i++ ){ - ITypeInfo arg = (ITypeInfo) args.get(i); - newArgs.add( TemplateEngine.instantiateTypeInfo( arg, template, argMap ) ); - } - - ITemplateSymbol deferredTemplate = getTemplate(); - if( deferredTemplate.isType( ITypeInfo.t_templateParameter ) && argMap.containsKey( deferredTemplate ) ){ - ITypeInfo i = (ITypeInfo) argMap.get( deferredTemplate ); - deferredTemplate = (ITemplateSymbol) i.getTypeSymbol(); - } - - // process any accumulated deferred instances, we may need them - if (template instanceof TemplateSymbol) - ((TemplateSymbol)template).processDeferredInstantiations(); - - ISymbol instance = deferredTemplate.instantiate( newArgs ); - -// if( !( instance instanceof IDeferredTemplateInstance ) ) -// return instance.instantiate( template, argMap ); -// else - return instance; - } - - public boolean isType( ITypeInfo.eType type, ITypeInfo.eType upperType ){ - ISymbol symbol = _template.getTemplatedSymbol(); - if( symbol != null ) - return symbol.isType( type, upperType ); - return super.isType( type, upperType ); - - } - - public ITypeInfo.eType getType(){ - ISymbol symbol = _template.getTemplatedSymbol(); - if( symbol != null ) - return symbol.getType(); - return super.getType(); - } - - public ITypeInfo getTypeInfo(){ - ISymbol symbol = _template.getTemplatedSymbol(); - if( symbol != null ) - return symbol.getTypeInfo(); - return super.getTypeInfo(); - } - - public boolean isType( ITypeInfo.eType type ){ - return _template.getTemplatedSymbol().isType( type ); - } - - public ISymbolASTExtension getASTExtension(){ - if( super.getASTExtension() != null ) - return super.getASTExtension(); - else if( _template.getTemplatedSymbol() != null ) - return _template.getTemplatedSymbol().getASTExtension(); - else - return _template.getASTExtension(); - } - - private ITemplateSymbol _template; - private List _arguments; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java deleted file mode 100644 index c1f828ba5ca..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java +++ /dev/null @@ -1,523 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on Nov 6, 2003 - */ - -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class DerivableContainerSymbol extends ContainerSymbol implements IDerivableContainerSymbol { - - protected DerivableContainerSymbol( ParserSymbolTable table, char[] name ){ - super( table, name ); - } - - protected DerivableContainerSymbol( ParserSymbolTable table, char[] name, ITypeInfo.eType typeInfo ){ - super( table, name, typeInfo ); - } - - - public Object clone(){ - DerivableContainerSymbol copy = (DerivableContainerSymbol)super.clone(); - - copy._parentScopes = ( _parentScopes != Collections.EMPTY_LIST ) ? (List)((ArrayList)_parentScopes).clone() : _parentScopes; - copy._constructors = ( _constructors != Collections.EMPTY_LIST ) ? (List)((ArrayList) _constructors).clone() : _constructors; - copy._friends = ( _friends != Collections.EMPTY_LIST ) ? (List)((ArrayList) _friends).clone() : _friends; - - return copy; - } - - public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{ - if( !isTemplateMember() ){ - return null; - } - - DerivableContainerSymbol newSymbol = (DerivableContainerSymbol) super.instantiate( template, argMap ); - - List parents = getParents(); - int size = parents.size(); - newSymbol.getParents().clear(); - ParentWrapper wrapper = null; - for( int i = 0; i < size; i++ ){ - wrapper = (ParentWrapper) parents.get(i); - ISymbol parent = wrapper.getParent(); - if( parent == null ) - continue; - - if( parent instanceof IDeferredTemplateInstance ){ - template.registerDeferredInstatiation( newSymbol, parent, ITemplateSymbol.DeferredKind.PARENT, argMap ); - } else if( parent.isType( ITypeInfo.t_templateParameter ) && argMap.containsKey( parent ) ){ - ITypeInfo info = (ITypeInfo) argMap.get( parent ); - parent = info.getTypeSymbol(); - } - newSymbol.addParent( parent, wrapper.isVirtual(), wrapper.getAccess(), wrapper.getOffset(), wrapper.getReferences() ); - } - - //TODO: friends - - return newSymbol; - } - - public void instantiateDeferredParent( ISymbol parent, ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{ - List parents = getParents(); - int size = parents.size(); - ParentWrapper w = null; - for( int i = 0; i < size; i++ ){ - w = (ParentWrapper) parents.get(i); - if( w.getParent() == parent ){ - w.setParent( parent.instantiate( template, argMap ) ); - } - } - } - - /** - * @param symbol - * @param symbol2 - * @param map - */ - public void discardDeferredParent(IDeferredTemplateInstance parent, ITemplateSymbol template, ObjectMap map) { - List parents = getParents(); - int size = parents.size(); - ParentWrapper w = null; - ISymbol originalParent = parent.getTemplate().getTemplatedSymbol(); - for( int i = 0; i < size; i++ ){ - w = (ParentWrapper) parents.get(i); - ISymbol instance = w.getParent(); - if( instance.getInstantiatedSymbol() == originalParent ){ - parents.remove( i ); - template.removeInstantiation( (IContainerSymbol) instance ); - break; - } - } - } - - protected void collectInstantiatedConstructor( IParameterizedSymbol constructor ){ - if( constructor.isType( ITypeInfo.t_constructor ) ) - addToConstructors( constructor ); - } - - public void addSymbol(ISymbol symbol) throws ParserSymbolTableException { - super.addSymbol( symbol ); - - //take care of the this pointer - if( symbol instanceof IParameterizedSymbol ){ - addThis( (IParameterizedSymbol) symbol ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addParent(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void addParent( ISymbol parent ){ - addParent( parent, false, ASTAccessVisibility.PUBLIC, -1, null ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addParent(org.eclipse.cdt.internal.core.parser.pst.ISymbol, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, int, java.util.List) - */ - public void addParent( ISymbol parent, boolean virtual, ASTAccessVisibility visibility, int offset, List references ){ - if( _parentScopes == Collections.EMPTY_LIST ){ - _parentScopes = new ArrayList(4); - } - - ParentWrapper wrapper = new ParentWrapper( parent, virtual, visibility, offset, references ); - _parentScopes.add( wrapper ); - -// Command command = new AddParentCommand( this, wrapper ); -// getSymbolTable().pushCommand( command ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#getParents() - */ - public List getParents(){ - return _parentScopes; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#hasParents() - */ - public boolean hasParents(){ - return !_parentScopes.isEmpty(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addConstructor(org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol) - */ - public void addConstructor(IParameterizedSymbol constructor) throws ParserSymbolTableException { - if( !constructor.isType( ITypeInfo.t_constructor ) ) - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); - - List constructors = getConstructors(); - - if( constructors.size() == 0 || ParserSymbolTable.isValidOverload( constructors, constructor ) ){ - addToConstructors( constructor ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidOverload ); - } - - constructor.setContainingSymbol( this ); - constructor.setIsTemplateMember( isTemplateMember() || getType() == ITypeInfo.t_template ); - - addThis( constructor ); - - addToContents( constructor ); - -// Command command = new AddConstructorCommand( constructor, this ); -// getSymbolTable().pushCommand( command ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addCopyConstructor() - */ - public void addCopyConstructor() throws ParserSymbolTableException{ - List parameters = new ArrayList(1); - - ISymbol paramType = this; - if( getContainingSymbol() instanceof ITemplateSymbol ){ - paramType = TemplateEngine.instantiateWithinTemplateScope( this, (ITemplateSymbol) getContainingSymbol() ); - } - - ITypeInfo param = getSymbolTable().getTypeInfoProvider().getTypeInfo( ITypeInfo.t_type ); - param.setType( ITypeInfo.t_type ); - param.setBit( true, ITypeInfo.isConst ); - param.setTypeSymbol( paramType ); - param.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, false, false ) ); - parameters.add( param ); - - IParameterizedSymbol constructor = null; - try{ - constructor = lookupConstructor( parameters ); - } catch ( ParserSymbolTableException e ){ - /* nothing */ - } finally { - getSymbolTable().getTypeInfoProvider().returnTypeInfo( param ); - } - - if( constructor == null ){ - constructor = getSymbolTable().newParameterizedSymbol( getName(), ITypeInfo.t_constructor ); - constructor.addParameter( this, ITypeInfo.isConst, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_reference, false, false ), false ); - - addConstructor( constructor ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#lookupConstructor(java.util.List) - */ - public IParameterizedSymbol lookupConstructor( final List parameters ) throws ParserSymbolTableException - { - LookupData data = new LookupData( ParserSymbolTable.EMPTY_NAME_ARRAY ){ - public List getParameters() { return params; } - public TypeFilter getFilter() { return CONSTRUCTOR_FILTER; } - final private List params = parameters; - }; - - List constructors = null; - if( !getConstructors().isEmpty() ){ - constructors = new ArrayList( getConstructors() ); - } - if( constructors != null ) - return getSymbolTable().resolveFunction( data, constructors ); - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#getConstructors() - */ - public List getConstructors(){ - return _constructors; - } - - private void addToConstructors( IParameterizedSymbol constructor ){ - if( _constructors == Collections.EMPTY_LIST ) - _constructors = new ArrayList(4); - _constructors.add( constructor ); - } - /** - * - * @param obj - * @throws ParserSymbolTableException - * 9.3.2-1 In the body of a nonstatic member function... the type of this of - * a class X is X*. If the member function is declared const, the type of - * this is const X*, if the member function is declared volatile, the type - * of this is volatile X*.... - */ - private boolean addThis( IParameterizedSymbol obj ){ - if( getSymbolTable().getLanguage() != ParserLanguage.CPP ){ - return false; - } - - if( obj instanceof ITemplateSymbol ){ - ISymbol templated = ((ITemplateSymbol)obj).getTemplatedSymbol(); - if( templated instanceof IParameterizedSymbol ){ - obj = (IParameterizedSymbol) templated; - } else { - return false; - } - } - - IContainerSymbol containing = obj.getContainingSymbol(); - if( containing instanceof ITemplateSymbol ){ - containing = containing.getContainingSymbol(); - } - - ITypeInfo type = obj.getTypeInfo(); - if( ( !type.isType( ITypeInfo.t_function ) && !type.isType( ITypeInfo.t_constructor) ) || - type.checkBit( ITypeInfo.isStatic ) ){ - return false; - } - - if( containing.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){ - //check to see if there is already a this object, since using declarations - //of function will have them from the original declaration - boolean foundThis = false; - - LookupData data = new LookupData( ParserSymbolTable.THIS ); - try { - CharArrayObjectMap map = ParserSymbolTable.lookupInContained( data, obj ); - foundThis = ( map != null ) ? map.containsKey( data.name ) : false; - } catch (ParserSymbolTableException e) { - return false; - } - - //if we didn't find "this" then foundItems will still be null, no need to actually - //check its contents - if( !foundThis ){ - ISymbol thisObj = getSymbolTable().newSymbol( ParserSymbolTable.THIS, ITypeInfo.t_type ); - thisObj.setTypeSymbol( obj.getContainingSymbol() ); - ITypeInfo.PtrOp ptr = new ITypeInfo.PtrOp(); - ptr.setType( ITypeInfo.PtrOp.t_pointer ); - thisObj.getTypeInfo().setBit( obj.getTypeInfo().checkBit( ITypeInfo.isConst ), ITypeInfo.isConst ); - thisObj.getTypeInfo().setBit( obj.getTypeInfo().checkBit( ITypeInfo.isVolatile ), ITypeInfo.isVolatile ); - - thisObj.addPtrOperator(ptr); - - try{ - obj.addSymbol( thisObj ); - } catch ( ParserSymbolTableException e ) { - //shouldn't happen because we checked that "this" didn't exist already - return false; - } - - } - } - return true; - } - - - /** - * - * @param name - * @return Declaration - * @throws ParserSymbolTableException - * - * 7.3.1.2-3 If a friend declaration in a non-local class first declares a - * class or function, the friend class or function is a member of the - * innermost enclosing namespace. - */ - public void addFriend( ISymbol friend ){ - //is this symbol already in the table? - IContainerSymbol containing = friend.getContainingSymbol(); - if( containing == null ){ - //its not, it goes in the innermost enclosing namespace - IContainerSymbol enclosing = getContainingSymbol(); - - boolean local = enclosing.isType( ITypeInfo.t_constructor ) || - enclosing.isType( ITypeInfo.t_function ) || - enclosing.isType( ITypeInfo.t_block ); - - while( enclosing != null && !enclosing.isType( ITypeInfo.t_namespace ) ){ - enclosing = enclosing.getContainingSymbol(); - } - - friend.setIsInvisible( local ); - friend.setIsForwardDeclaration( true ); - try { - enclosing.addSymbol( friend ); - } catch (ParserSymbolTableException e) { - /* nothing */ - } - } - - addToFriends( friend ); - } - - /** - * LookupForFriendship - * @param name - * @return Declaration - * 7.3.1.2-3 When looking for a prior declaration of a class or a function - * declared as a friend, scopes outside the innermost enclosing namespace - * scope are not considered. - * 11.4-9 If a friend declaration appears in a local class and the name - * specified is an unqualified name, a prior declaration is looked up - * without considering scopes that are outside the innermost enclosing non- - * class scope. - */ - public ISymbol lookupForFriendship( char[] name ) throws ParserSymbolTableException{ - IContainerSymbol enclosing = getContainingSymbol(); - if( enclosing != null && enclosing.isType( ITypeInfo.t_namespace, ITypeInfo.t_union ) ){ - while( enclosing != null && ( enclosing.getType() != ITypeInfo.t_namespace) ) - { - enclosing = enclosing.getContainingSymbol(); - } - } - - final ISymbol finalEnc = enclosing; - LookupData data = new LookupData( name ){ - public ISymbol getStopAt() { return stopAt; } - final private ISymbol stopAt = finalEnc; - }; - - ParserSymbolTable.lookup( data, this ); - return getSymbolTable().resolveAmbiguities( data ); - } - - public IParameterizedSymbol lookupFunctionForFriendship( char[] name, final List parameters ) throws ParserSymbolTableException{ - - - IContainerSymbol enclosing = getContainingSymbol(); - if( enclosing != null && enclosing.isType( ITypeInfo.t_namespace, ITypeInfo.t_union ) ){ - while( enclosing != null && ( enclosing.getType() != ITypeInfo.t_namespace) ) - { - enclosing = enclosing.getContainingSymbol(); - } - } - final ISymbol finalEnc = enclosing; - LookupData data = new LookupData( name ){ - public List getParameters() { return params; } - public ISymbol getStopAt() { return stopAt; } - final private List params = parameters; - final ISymbol stopAt = finalEnc; - }; - - ParserSymbolTable.lookup( data, this ); - return (IParameterizedSymbol) getSymbolTable().resolveAmbiguities( data ); - } - - - public List getFriends(){ - return _friends; - } - private void addToFriends( ISymbol friend ){ - if( _friends == Collections.EMPTY_LIST ){ - _friends = new ArrayList(4); - } - _friends.add( friend ); - } - -// static private class AddParentCommand extends Command{ -// public AddParentCommand( IDerivableContainerSymbol container, ParentWrapper wrapper ){ -// _decl = container; -// _wrapper = wrapper; -// } -// -// public void undoIt(){ -// List parents = _decl.getParents(); -// parents.remove( _wrapper ); -// } -// -// private IDerivableContainerSymbol _decl; -// private ParentWrapper _wrapper; -// } -// -// static private class AddConstructorCommand extends Command{ -// AddConstructorCommand( IParameterizedSymbol newConstr, IDerivableContainerSymbol context ){ -// _constructor = newConstr; -// _context = context; -// } -// public void undoIt(){ -// List constructors = _context.getConstructors(); -// Iterator iter = constructors.listIterator(); -// -// int size = constructors.size(); -// IParameterizedSymbol item = null; -// for( int i = 0; i < size; i++ ){ -// item = (IParameterizedSymbol)iter.next(); -// if( item == _constructor ){ -// iter.remove(); -// break; -// } -// } -// -// ContentsIterator contents = (ContentsIterator) _context.getContentsIterator(); -// while( iter.hasNext() ){ -// IExtensibleSymbol ext = (IExtensibleSymbol) iter.next(); -// if( ext == _constructor ){ -// contents.removeSymbol(); -// break; -// } -// } -// } -// -// private final IParameterizedSymbol _constructor; -// private final IDerivableContainerSymbol _context; -// } - - public class ParentWrapper implements IDerivableContainerSymbol.IParentSymbol - { - public ParentWrapper( ISymbol p, boolean v, ASTAccessVisibility s, int offset, List r ){ - parent = p; - isVirtual = v; - access = s; - this.offset = offset; - this.references = r; - } - - public Object clone(){ - try{ - return super.clone(); - } catch ( CloneNotSupportedException e ){ - //should not happen - return null; - } - } - - public void setParent( ISymbol parent ){ this.parent = parent; } - - public ISymbol getParent() { return parent; } - public boolean isVirtual() { return isVirtual; } - - public void setVirtual( boolean virtual ){ isVirtual = virtual; } - - public ASTAccessVisibility getAccess() { return access; } - - public int getOffset() { return offset; } - public List getReferences() { return references; } - - private boolean isVirtual = false; - protected ISymbol parent = null; - private final ASTAccessVisibility access; - private final int offset; - private final List references; - } - - private List _constructors = Collections.EMPTY_LIST; //constructor list - private List _parentScopes = Collections.EMPTY_LIST; //inherited scopes (is base classes) - private List _friends = Collections.EMPTY_LIST; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbol.java deleted file mode 100644 index 50f8376e0e6..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbol.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.pst; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class ExtensibleSymbol implements Cloneable, IExtensibleSymbol { - public ExtensibleSymbol( ParserSymbolTable table ){ - _table = table; - } - - public ExtensibleSymbol( ParserSymbolTable table, ISymbolASTExtension obj ){ - _table = table; - _object = obj; - } - - - public Object clone(){ - ExtensibleSymbol copy = null; - try{ - copy = (ExtensibleSymbol)super.clone(); - } catch ( CloneNotSupportedException e ){ - //should not happen - return null; - } - - return copy; - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol#getSymbolTable() - */ - public ParserSymbolTable getSymbolTable(){ - return _table; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol#getASTExtension() - */ - public ISymbolASTExtension getASTExtension() { - return _object; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol#setASTExtension(org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension) - */ - public void setASTExtension( ISymbolASTExtension obj ) { - _object = obj; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol#getContainingSymbol() - */ - public IContainerSymbol getContainingSymbol() { - return _containingScope; - } - - public void setContainingSymbol( IContainerSymbol scope ){ - _containingScope = scope; - } - - private final ParserSymbolTable _table; - private ISymbolASTExtension _object; //the object associated with us - private IContainerSymbol _containingScope; //the scope that contains us -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbolExtension.java deleted file mode 100644 index 051db17998e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbolExtension.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on Apr 21, 2004 - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTNode; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; - -/** - * @author aniefer - */ -public class ExtensibleSymbolExtension implements ISymbolASTExtension { - protected final IExtensibleSymbol extensibleSymbol; - protected final ASTNode primaryDeclaration; - - public ExtensibleSymbolExtension( IExtensibleSymbol symbol, IASTNode node ){ - primaryDeclaration = (ASTNode) node; - extensibleSymbol = symbol; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getPrimaryDeclaration() - */ - public ASTNode getPrimaryDeclaration() { - return primaryDeclaration; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getAllDefinitions() - */ - public Iterator getAllDefinitions() { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#addDefinition(org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol) - */ - public void addDefinition(ASTSymbol definition) throws ExtensionException { - // TODO Auto-generated method stub - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner#getSymbol() - */ - public ISymbol getSymbol() { - if( extensibleSymbol instanceof ISymbol ) - return (ISymbol) extensibleSymbol; - return null; - } - - public IExtensibleSymbol getExtensibleSymbol(){ - return extensibleSymbol; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ForewardDeclaredSymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ForewardDeclaredSymbolExtension.java deleted file mode 100644 index aaf59d0da34..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ForewardDeclaredSymbolExtension.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; - -/** - * @author jcamelon - * - */ -public class ForewardDeclaredSymbolExtension extends AbstractSymbolExtension -{ - /** - * @author jcamelon - * - */ - private class DualIterator implements Iterator - { - private int state = 0; - /** - * - */ - public DualIterator() - { - super(); - } - - /* (non-Javadoc) - * @see java.util.Iterator#hasNext() - */ - public boolean hasNext() - { - if( state == 0 ) return true; - if( state == 1 && definitionSymbol != null ) return true; - return false; - } - - /* (non-Javadoc) - * @see java.util.Iterator#next() - */ - public Object next() - { - switch( state ) - { - case 0: - state = 1; - return primaryDeclaration; - case 1: - if( definitionSymbol != null ) - { - state = 2; - return definitionSymbol; - } - break; - } - throw new NoSuchElementException(); - - } - - /* (non-Javadoc) - * @see java.util.Iterator#remove() - */ - public void remove() - { - throw new UnsupportedOperationException(); - } - } - - protected ASTSymbol definitionSymbol = null; - /** - * @param symbol - * @param primaryDeclaration - */ - public ForewardDeclaredSymbolExtension( - ISymbol symbol, - ASTSymbol primaryDeclaration) - { - super(symbol, primaryDeclaration); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getAllDefinitions() - */ - public Iterator getAllDefinitions() - { - return new DualIterator(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#addDefinition(org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol) - */ - public void addDefinition(ASTSymbol definition) throws ExtensionException - { - if( definitionSymbol != null ) - throw new ExtensionException(); - definitionSymbol = definition; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java deleted file mode 100644 index 34bab58572d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on May 9, 2003 - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public interface IContainerSymbol extends ISymbol { - - /** - * Add a symbol to this container - * @param symbol - * @throws ParserSymbolTableException - * Reason : r_BadTemplate if (14-2) the symbol is a template declaration is outside a namespace or class scope - * or if (14.5.2-3) the symbol is a member function template and is virtual - * r_RedeclaredTemplateParam if (14.6.1-4) a template parameter is redeclared in its scope - * r_InvalidOverload if there already exists a symbol with the same name and the new symbol does not - * hide the first symbol (3.3.7) or is not a valid function overload (3.4-1) - */ - public void addSymbol( ISymbol symbol ) throws ParserSymbolTableException; - - public void addTemplateId( ISymbol symbol, List args ) throws ParserSymbolTableException; - -// public boolean removeSymbol( ISymbol symbol ); - - public boolean hasUsingDirectives(); - public List getUsingDirectives(); - - /** - * Add a using directive to this symbol - * @param namespace - * @return - * @throws ParserSymbolTableException - * Reason: r_InvalidUsing if (7.3.4) the using directive appears in class scope - * or if the symbol being added is not a namespace - */ - public IUsingDirectiveSymbol addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException; - - /** - * Add a using declaration to this symbol - * @param name - * @return - * @throws ParserSymbolTableException - * Reason: r_InvalidUsing if (7.3.3-5) the name is a template-id - * or if (7.3.3-4) this using declaration is a member declaration and the name is not a - * member of a base class, or an anonymous union that is a member of a base class, or - * an enumerator for an enumeration which is a member of a base class - * or if the name specified can not be found - * r_Ambiguous if more than one symbol with the given name is found and we can't resolve which one to use - * r_BadTypeInfo if during lookup of the name, we come across a class inheriting from a symbol which is not an - * IDerivableContainerSymbol - * r_CircularInheritance if during lookup of the name, we come across a class with a circular inheritance tree - */ - public IUsingDeclarationSymbol addUsingDeclaration( char[] name ) throws ParserSymbolTableException; - public IUsingDeclarationSymbol addUsingDeclaration( char[] name, IContainerSymbol declContext ) throws ParserSymbolTableException; - - public CharArrayObjectMap getContainedSymbols(); - - /** - * Lookup symbols matching the given prefix - * @param filter - * @param prefix - * @param qualified - * @param paramList TODO - * @return - * @throws ParserSymbolTableException - * Reason: r_BadTypeInfo if during lookup, we come across a class inheriting from a symbol which is not an - * IDerivableContainerSymbol - * r_CircularInheritance if during lookup, we come across a class with a circular inheritance tree - */ - public List prefixLookup( TypeFilter filter, char[] prefix, boolean qualified, List paramList ) throws ParserSymbolTableException; - - /** - * Lookups - * @throws ParserSymbolTableException - * Reason: r_Ambiguous if more than one symbol with the given name is found and we can't resolve which one to use - * r_UnableToResolveFunction if an overloaded function is found and no parameter information has been provided - * r_BadTypeInfo if during lookup of the name, we come across a class inheriting from a symbol which is not an - * IDerivableContainerSymbol - * r_CircularInheritance if during lookup of the name, we come across a class with a circular inheritance tree - */ - public ISymbol elaboratedLookup( ITypeInfo.eType type, char[] name ) throws ParserSymbolTableException; - public ISymbol lookup( char[] name ) throws ParserSymbolTableException; - public ISymbol lookupMemberForDefinition( char[] name, ITypeInfo.eType type ) throws ParserSymbolTableException; - public ISymbol lookupMemberForDefinition( char[] name ) throws ParserSymbolTableException; - public IParameterizedSymbol lookupMethodForDefinition( char[] name, List parameters ) throws ParserSymbolTableException; - public ISymbol lookupNestedNameSpecifier( char[] name ) throws ParserSymbolTableException; - public ISymbol qualifiedLookup( char[] name ) throws ParserSymbolTableException; - public ISymbol qualifiedLookup( char[] name, ITypeInfo.eType t ) throws ParserSymbolTableException; - public IParameterizedSymbol unqualifiedFunctionLookup( char[] name, List parameters ) throws ParserSymbolTableException; - public IParameterizedSymbol memberFunctionLookup( char[] name, List parameters ) throws ParserSymbolTableException; - public IParameterizedSymbol qualifiedFunctionLookup( char[] name, List parameters ) throws ParserSymbolTableException; - - /** - * - * @param name - * @param arguments - * @return - * @throws ParserSymbolTableException - * In addition to the above lookup reasons, the following also can happen in lookupTemplate - * r_Ambiguous if (14.5.4.1) more than one specialization can be used and none is more specializaed than all the others - * r_BadTemplateArgument if (14.3.1, 14.3.2) a template argument is invalid - */ - public ISymbol lookupTemplateId( char[] name, List arguments ) throws ParserSymbolTableException; - public ISymbol lookupFunctionTemplateId( char[] name, List parameters, List arguments, boolean forDefinition ) throws ParserSymbolTableException; - - public IContainerSymbol lookupTemplateIdForDefinition( char[] name, List arguments ) throws ParserSymbolTableException; - - /** - * - * @param name - * @param templateParameters - * @param templateArguments - * @return - * @throws ParserSymbolTableException - * In addition to the Exception thrown in lookup functions, and lookupTemplate, lookupTemplateForMemberDefinition can also throw: - * r_BadTemplateParameter if (14.5.1-3) the parameters provided can't be matched up to a template declaration - * r_BadTemplate if the parameter and argument list can't be resolved to either the template or a specialization - */ -// public ITemplateFactory lookupTemplateForMemberDefinition( String name, List templateParameters, -// List templateArguments ) throws ParserSymbolTableException; - - public boolean isVisible( ISymbol symbol, IContainerSymbol qualifyingSymbol ); - - public Iterator getContentsIterator(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IDeferredTemplateInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IDeferredTemplateInstance.java deleted file mode 100644 index acb021c3d6b..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IDeferredTemplateInstance.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.List; - -/** - * @author aniefer - */ - -public interface IDeferredTemplateInstance extends ISymbol { - - public ITemplateSymbol getTemplate(); - - public List getArguments(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IDerivableContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IDerivableContainerSymbol.java deleted file mode 100644 index de685d55d13..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IDerivableContainerSymbol.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on May 9, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.List; - -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public interface IDerivableContainerSymbol extends IContainerSymbol { - - public void addParent( ISymbol parent ); - public void addParent( ISymbol parent, boolean virtual, ASTAccessVisibility visibility, int offset, List references ); - public List getParents(); - public boolean hasParents(); - - /** - * - * @param constructor - * @throws ParserSymbolTableException - * Reason: - * r_BadTypeInfo if the symbol being added is not of type TypeInfo.t_constructor - * r_InvalidOverload if the constructor being added is not a valid overload of existing constructors - */ - public void addConstructor( IParameterizedSymbol constructor ) throws ParserSymbolTableException; - public void addCopyConstructor() throws ParserSymbolTableException; - - /** - * - * @param parameters - * @return - * @throws ParserSymbolTableException - * Reason: - * r_Ambiguous if more than one constructor can be used with the given parameters - */ - public IParameterizedSymbol lookupConstructor( List parameters ) throws ParserSymbolTableException; - - public List getConstructors(); - - public void addFriend( ISymbol friend ); - - /** - * Lookups - * @throws ParserSymbolTableException - * Reason: r_Ambiguous if more than one symbol with the given name is found and we can't resolve which one to use - * r_UnableToResolveFunction if an overloaded function is found and no parameter information has been provided - * r_BadTypeInfo if during lookup of the name, we come across a class inheriting from a symbol which is not an - * IDerivableContainerSymbol - * r_CircularInheritance if during lookup of the name, we come across a class with a circular inheritance tree - */ - public ISymbol lookupForFriendship( char[] name ) throws ParserSymbolTableException; - public IParameterizedSymbol lookupFunctionForFriendship( char[] name, List parameters ) throws ParserSymbolTableException; - - public List getFriends(); - - public interface IParentSymbol extends Cloneable { - public Object clone(); - public void setParent( ISymbol parent ); - public ISymbol getParent(); - public boolean isVirtual(); - public void setVirtual( boolean virtual ); - - public ASTAccessVisibility getAccess(); - public int getOffset(); - public List getReferences(); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IExtensibleSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IExtensibleSymbol.java deleted file mode 100644 index 084ecd7d99b..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IExtensibleSymbol.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.pst; - -/** - * @author aniefer - */ -public interface IExtensibleSymbol { - /** - * get the instance of ParserSymbolTable with wich this symbol is associated - * @return ParserSymbolTable - */ - public ParserSymbolTable getSymbolTable(); - - /** - * get the ISymbolASTExtension attached to this symbol - * @return ISymbolASTExtension - */ - public ISymbolASTExtension getASTExtension(); - - /** - * attach an ISymbolASTExtension to this symbol - * @param obj - */ - public void setASTExtension( ISymbolASTExtension obj ); - - public IContainerSymbol getContainingSymbol(); - - public void setContainingSymbol( IContainerSymbol scope ); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IParameterizedSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IParameterizedSymbol.java deleted file mode 100644 index 201d18f839b..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IParameterizedSymbol.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on May 9, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.List; - -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public interface IParameterizedSymbol extends IContainerSymbol { - - public void addParameter( ISymbol param ); - public void addParameter( ITypeInfo.eType type, int info, ITypeInfo.PtrOp ptrOp, boolean hasDefault ); - public void addParameter( ISymbol typeSymbol, int info, ITypeInfo.PtrOp ptrOp, boolean hasDefault ); - - public CharArrayObjectMap getParameterMap(); - public List getParameterList(); - //public void setParameterList( List list ); - - public boolean hasSameParameters(IParameterizedSymbol newDecl); - - public void setReturnType( ISymbol type ); - public ISymbol getReturnType(); - - public void setHasVariableArgs( boolean var ); - public boolean hasVariableArgs( ); - - public void prepareForParameters(int i); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISpecializedSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISpecializedSymbol.java deleted file mode 100644 index 726f720b2c0..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISpecializedSymbol.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on May 9, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.List; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public interface ISpecializedSymbol extends ITemplateSymbol { - - public void addArgument( ITypeInfo arg ); - - public List getArgumentList(); - - public ITemplateSymbol getPrimaryTemplate(); - public void setPrimaryTemplate( ITemplateSymbol templateSymbol ); - - /** - * @param size - */ - public void prepareArguments(int size); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java deleted file mode 100644 index 9e82b036d0e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.List; - -import org.eclipse.cdt.core.parser.util.ObjectMap; - -/** - * @author jcamelon - * - */ -public interface ISymbol extends Cloneable, IExtensibleSymbol { - - public Object clone(); - - /** - * - * @param args - * @return - * @throws ParserSymbolTableException - * Exceptions can be thrown when a IDeferredTemplateInstance must be instantiated - * Reason: - * r_BadTemplateArgument if an argument does not match the corresponding parameter type - * r_Ambiguous if more than one specialization can be used but none is more specialized than all the others - */ - public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException; - - public void setName(char[] name); - public char[] getName(); - - public IContainerSymbol getContainingSymbol(); - public void setContainingSymbol( IContainerSymbol containing ); - - public boolean isType( ITypeInfo.eType type ); - public boolean isType( ITypeInfo.eType type, ITypeInfo.eType upperType ); - public ITypeInfo.eType getType(); - public void setType(ITypeInfo.eType t); - public ITypeInfo getTypeInfo(); - public void setTypeInfo( ITypeInfo info ); - public ISymbol getTypeSymbol(); - public void setTypeSymbol( ISymbol type ); - - public boolean isForwardDeclaration(); - public void setIsForwardDeclaration( boolean forward ); - public void setForwardSymbol( ISymbol forward ); - public ISymbol getForwardSymbol(); - - public int compareCVQualifiersTo( ISymbol symbol ); - public List getPtrOperators(); - public void addPtrOperator( ITypeInfo.PtrOp ptrOp ); - - public boolean isTemplateInstance(); - public ISymbol getInstantiatedSymbol(); - public void setInstantiatedSymbol( ISymbol symbol ); - public boolean isTemplateMember(); - public void setIsTemplateMember( boolean isMember ); - - public int getDepth(); - public boolean getIsInvisible(); - public void setIsInvisible( boolean invisible ); - - public void preparePtrOperatros(int numPtrOps); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java deleted file mode 100644 index 1d6567011ca..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - - -import java.util.Iterator; - -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTNode; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; - -/** - * @author jcamelon - * - */ -public interface ISymbolASTExtension extends ISymbolOwner -{ - public class ExtensionException extends Exception - { - } - - - public ASTNode getPrimaryDeclaration(); - public IExtensibleSymbol getExtensibleSymbol(); - public Iterator getAllDefinitions(); - public void addDefinition( ASTSymbol definition ) throws ExtensionException; - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolOwner.java deleted file mode 100644 index 26700094111..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolOwner.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -/** - * @author jcamelon - * - */ -public interface ISymbolOwner -{ - public ISymbol getSymbol(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITemplateFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITemplateFactory.java deleted file mode 100644 index c47b29ff6fc..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITemplateFactory.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.List; - -/** - * @author aniefer - **/ - -public interface ITemplateFactory extends IDerivableContainerSymbol { - public void pushTemplate( ITemplateSymbol template ); - public void pushSymbol( ISymbol symbol ); - public void pushTemplateId( ISymbol symbol, List args ); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITemplateSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITemplateSymbol.java deleted file mode 100644 index 25f3b5187ca..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITemplateSymbol.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.List; - -import org.eclipse.cdt.core.parser.util.ObjectMap; - -/** - * @author aniefer - */ - -public interface ITemplateSymbol extends IParameterizedSymbol { - - /** - * - * @param param - * @throws ParserSymbolTableException - * Reason: - * r_BadTemplateParameter if the Parameter does not have type TypeInfo.t_templateParameter - * or if the parameter has the same name as the template - * or if the parameter is a non-type parameter and does not have a valid type (14.1-4, 14.1-7) - */ - public void addTemplateParameter( ISymbol param ) throws ParserSymbolTableException; - - public boolean hasSpecializations(); - public void addSpecialization( ISpecializedSymbol spec ); - public List getSpecializations(); - - public IContainerSymbol getTemplatedSymbol(); - - public ObjectMap getDefinitionParameterMap(); - - public IContainerSymbol findInstantiation( List arguments ); - public List findArgumentsFor( IContainerSymbol instance ); - - public void addInstantiation( IContainerSymbol instance, List args ); - public void removeInstantiation( IContainerSymbol symbol ); - - public void addExplicitSpecialization( ISymbol symbol, List args ) throws ParserSymbolTableException; - - /** - * - * @param args - * @return - * @throws ParserSymbolTableException - * Reason: - * r_BadTemplateArgument if an argument does not match the corresponding parameter type - * r_Ambiguous if more than one specialization can be used but none is more specialized than all the others - */ - public ISymbol instantiate( List args ) throws ParserSymbolTableException; - - public IDeferredTemplateInstance deferredInstance( List args ); - - public ObjectMap getExplicitSpecializations(); - - /** - * @param symbol - * @param type - * @param kind - */ - public void registerDeferredInstatiation( Object obj0, Object obj1, DeferredKind kind, ObjectMap argMap ); - public int getNumberDeferredInstantiations(); - - public static class DeferredKind{ - private DeferredKind( int v ){ - _val = v; - } - protected int _val; - - public static final DeferredKind RETURN_TYPE = new DeferredKind( 1 ); - public static final DeferredKind PARENT = new DeferredKind( 2 ); - public static final DeferredKind TYPE_SYMBOL = new DeferredKind( 3 ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITypeInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITypeInfo.java deleted file mode 100644 index f44eb8817b4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ITypeInfo.java +++ /dev/null @@ -1,254 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Jul 5, 2004 - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.List; - -import org.eclipse.cdt.core.parser.Enum; - -/** - * @author aniefer - */ -public interface ITypeInfo { - public static class OperatorExpression extends Enum{ - - //5.3.1-1 : The unary * operator, the expression to which it is applied shall be - //a pointer to an object type or a pointer to a function type and the result - //is an lvalue refering to the object or function to which the expression points - public static final OperatorExpression indirection = new OperatorExpression( 1 ); - - //5.3.1-2 : The result of the unary & operator is a pointer to its operand - public static final OperatorExpression addressof = new OperatorExpression( 0 ); - - //5.2.1 A postfix expression followed by an expression in square brackets is a postfix - //expression. one of the expressions shall have the type "pointer to T" and the other - //shall have a enumeration or integral type. The result is an lvalue of type "T" - public static final OperatorExpression subscript = new OperatorExpression( 2 ); - - protected OperatorExpression(int enumValue) { - super(enumValue); - } - } - - public static class PtrOp { - public PtrOp( eType type ){ - this.type = type; - } - public PtrOp( eType type, boolean isConst, boolean isVolatile ){ - this.type = type; - this.isConstPtr = isConst; - this.isVolatilePtr = isVolatile; - } - public PtrOp( ISymbol memberOf, boolean isConst, boolean isVolatile ){ - this.type = PtrOp.t_memberPointer; - this.isConstPtr = isConst; - this.isVolatilePtr = isVolatile; - this.memberOf = memberOf; - } - - public PtrOp(){ - super(); - } - - public static final eType t_undef_ptr = new eType( 0 ); - public static final eType t_pointer = new eType( 1 ); - public static final eType t_reference = new eType( 2 ); - public static final eType t_array = new eType( 3 ); - public static final eType t_memberPointer = new eType( 4 ); - - public eType getType() { return type; } - public void setType( eType type ) { this.type = type; } - - public boolean isConst() { return isConstPtr; } - public boolean isVolatile() { return isVolatilePtr; } - public void setConst( boolean isConst ) { this.isConstPtr = isConst; } - public void setVolatile(boolean isVolatile) { this.isVolatilePtr = isVolatile; } - - public ISymbol getMemberOf() { return memberOf; } - public void setMemberOf( ISymbol member ) { this.memberOf = member; } - - public int compareCVTo( ITypeInfo.PtrOp ptr ){ - int cv1 = ( isConst() ? 1 : 0 ) + ( isVolatile() ? 1 : 0 ); - int cv2 = ( ptr.isConst() ? 1 : 0 ) + ( ptr.isVolatile() ? 1 : 0 ); - - return cv1 - cv2; - } - public boolean equals( Object o ){ - if( o == null || !(o instanceof ITypeInfo.PtrOp) ){ - return false; - } - ITypeInfo.PtrOp op = (ITypeInfo.PtrOp)o; - - return ( isConst() == op.isConst() && - isVolatile() == op.isVolatile() && - getType() == op.getType() ); - } - - private eType type = PtrOp.t_undef_ptr; - private boolean isConstPtr = false; - private boolean isVolatilePtr = false; - private ISymbol memberOf = null; - } - - public static class eType extends Enum implements Comparable{ - protected eType( int v ){ - super( v ); - } - - public int compareTo( Object o ){ - ITypeInfo.eType t = (ITypeInfo.eType) o; - return getEnumValue() - t.getEnumValue(); - } - public int toInt() { - return getEnumValue(); - } - } - - public static final int isAuto = 1 << 0; - public static final int isRegister = 1 << 1; - public static final int isStatic = 1 << 2; - public static final int isExtern = 1 << 3; - public static final int isMutable = 1 << 4; - public static final int isInline = 1 << 5; - public static final int isVirtual = 1 << 6; - public static final int isExplicit = 1 << 7; - public static final int isTypedef = 1 << 8; - public static final int isFriend = 1 << 9; - public static final int isConst = 1 << 10; - public static final int isVolatile = 1 << 11; - public static final int isUnsigned = 1 << 12; - public static final int isShort = 1 << 13; - public static final int isLong = 1 << 14; - public static final int isForward = 1 << 15; - public static final int isComplex = 1 << 16; - public static final int isImaginary = 1 << 17; - public static final int isLongLong = 1 << 18; - public static final int isSigned = 1 << 19; - - // Types - // Note that these should be considered ordered and if you change - // the order, you should consider the ParserSymbolTable uses - public static final ITypeInfo.eType t_any = new ITypeInfo.eType( -1 ); //don't care - public static final ITypeInfo.eType t_undef = new ITypeInfo.eType( 0 ); //not specified - public static final ITypeInfo.eType t_type = new ITypeInfo.eType( 1 ); //Type Specifier - public static final ITypeInfo.eType t_namespace = new ITypeInfo.eType( 2 ); - public static final ITypeInfo.eType t_class = new ITypeInfo.eType( 3 ); - public static final ITypeInfo.eType t_struct = new ITypeInfo.eType( 4 ); - public static final ITypeInfo.eType t_union = new ITypeInfo.eType( 5 ); - public static final ITypeInfo.eType t_enumeration = new ITypeInfo.eType( 6 ); - public static final ITypeInfo.eType t_constructor = new ITypeInfo.eType( 7 ); - public static final ITypeInfo.eType t_function = new ITypeInfo.eType( 8 ); - public static final ITypeInfo.eType t__Bool = new ITypeInfo.eType( 9 ); - public static final ITypeInfo.eType t_bool = new ITypeInfo.eType( 10 ); - public static final ITypeInfo.eType t_char = new ITypeInfo.eType( 11 ); - public static final ITypeInfo.eType t_wchar_t = new ITypeInfo.eType( 12 ); - public static final ITypeInfo.eType t_int = new ITypeInfo.eType( 13 ); - public static final ITypeInfo.eType t_float = new ITypeInfo.eType( 14 ); - public static final ITypeInfo.eType t_double = new ITypeInfo.eType( 15 ); - public static final ITypeInfo.eType t_void = new ITypeInfo.eType( 16 ); - public static final ITypeInfo.eType t_enumerator = new ITypeInfo.eType( 17 ); - public static final ITypeInfo.eType t_block = new ITypeInfo.eType( 18 ); - public static final ITypeInfo.eType t_template = new ITypeInfo.eType( 19 ); - public static final ITypeInfo.eType t_asm = new ITypeInfo.eType( 20 ); - public static final ITypeInfo.eType t_linkage = new ITypeInfo.eType( 21 ); - public static final ITypeInfo.eType t_templateParameter = new ITypeInfo.eType( 22 ); - - public static final ITypeInfo.eType t_typeName = new ITypeInfo.eType( 23 ); - - public abstract void setBit( boolean b, int mask ); - - public abstract boolean checkBit( int mask ); - - public abstract void setType( ITypeInfo.eType t ); - - public abstract ITypeInfo.eType getType(); - - public abstract boolean isType( ITypeInfo.eType type ); - - public abstract int getTypeBits(); - - public abstract void setTypeBits( int typeInfo ); - - public abstract ITypeInfo.eType getTemplateParameterType(); - - public abstract void setTemplateParameterType( ITypeInfo.eType type ); - - /** - * - * @param infoProvider - TypeInfoProvider to use if pooling the TypeInfo created, if null, - * pooling is not used. If pooling is used, TypeInfoProvider.returnTypeInfo - * must be called when the TypeInfo is no longer needed - * @return - */ - public abstract ITypeInfo getFinalType( TypeInfoProvider infoProvider ); - - /** - * - * @param type - * @param upperType - * @return boolean - * - * type checking, check that this declaration's type is between type and - * upperType (inclusive). upperType of 0 means no range and our type must - * be type. - */ - public abstract boolean isType( ITypeInfo.eType type, - ITypeInfo.eType upperType ); - - public abstract ISymbol getTypeSymbol(); - - public abstract void setTypeSymbol( ISymbol type ); - - public abstract boolean hasPtrOperators(); - - public abstract List getPtrOperators(); - - public abstract boolean hasSamePtrs( ITypeInfo type ); - - public abstract void applyOperatorExpression( ITypeInfo.OperatorExpression op ); - - public abstract void addPtrOperator( ITypeInfo.PtrOp ptr ); - - public abstract void addPtrOperator( List ptrs ); - - public abstract void preparePtrOperators( int numPtrOps ); - - public abstract boolean getHasDefault(); - - public abstract void setHasDefault( boolean def ); - - public abstract void setDefault( Object t ); - - public abstract Object getDefault(); - - /** - * canHold - * @param type - * @return boolean - * return true if our type can hold all the values of the passed in - * type. - * TODO, for now return true if our type is "larger" (based on ordering of - * the type values) - */ - public abstract boolean canHold( ITypeInfo type ); - - public abstract boolean equals( Object t ); - - public abstract char[] toCharArray(); - - public abstract void clear(); - - public abstract void copy( ITypeInfo t ); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDeclarationSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDeclarationSymbol.java deleted file mode 100644 index 4ab2e401029..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDeclarationSymbol.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Feb 18, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.List; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public interface IUsingDeclarationSymbol extends IExtensibleSymbol { - - List getReferencedSymbols(); - - List getDeclaredSymbols(); - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDirectiveSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDirectiveSymbol.java deleted file mode 100644 index c1b956edc06..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDirectiveSymbol.java +++ /dev/null @@ -1,16 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - - -public interface IUsingDirectiveSymbol extends IExtensibleSymbol{ - public IContainerSymbol getNamespace(); -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/NamespaceSymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/NamespaceSymbolExtension.java deleted file mode 100644 index 62f90515d74..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/NamespaceSymbolExtension.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; - -/** - * @author jcamelon - * - */ -public class NamespaceSymbolExtension extends AbstractSymbolExtension -{ - /** - * @author jcamelon - * - */ - private class LocalIterator implements Iterator - { - private boolean donePrimary = false; - private Iterator secondaries = otherDefinitions.iterator(); - /** - * - */ - public LocalIterator() - { - super(); - } - /* (non-Javadoc) - * @see java.util.Iterator#hasNext() - */ - public boolean hasNext() - { - if( ! donePrimary ) return true; - return secondaries.hasNext(); - } - /* (non-Javadoc) - * @see java.util.Iterator#next() - */ - public Object next() - { - if( ! hasNext() ) - throw new NoSuchElementException(); - - if( ! donePrimary ) - { - donePrimary = true; - return primaryDeclaration; - } - - return secondaries.next(); - } - /* (non-Javadoc) - * @see java.util.Iterator#remove() - */ - public void remove() - { - throw new UnsupportedOperationException(); - } - } - protected List otherDefinitions = new ArrayList(); - /** - * @param symbol - * @param primaryDeclaration - */ - public NamespaceSymbolExtension( - ISymbol symbol, - ASTSymbol primaryDeclaration) - { - super(symbol, primaryDeclaration); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getAllDefinitions() - */ - public Iterator getAllDefinitions() - { - return new LocalIterator(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#addDefinition(org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol) - */ - public void addDefinition(ASTSymbol definition) - { - otherDefinitions.add( definition ); - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java deleted file mode 100644 index f6d644e9efb..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParameterizedSymbol.java +++ /dev/null @@ -1,317 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on Nov 6, 2003 - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.core.parser.util.ObjectMap; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class ParameterizedSymbol extends ContainerSymbol implements IParameterizedSymbol { - - protected ParameterizedSymbol( ParserSymbolTable table, char[] name ){ - super( table, name ); - } - - protected ParameterizedSymbol( ParserSymbolTable table, char[] name, ITypeInfo.eType typeInfo ){ - super( table, name, typeInfo ); - } - - public Object clone(){ - ParameterizedSymbol copy = (ParameterizedSymbol)super.clone(); - - copy._parameterList = ( _parameterList != Collections.EMPTY_LIST ) ? (List) ((ArrayList)_parameterList).clone() : _parameterList; - copy._parameterMap = ( _parameterMap != CharArrayObjectMap.EMPTY_MAP ) ? (CharArrayObjectMap) _parameterMap.clone() : _parameterMap; - - return copy; - } - - public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{ - if( !isTemplateMember() ){ - return null; - } - - ParameterizedSymbol newParameterized = (ParameterizedSymbol) super.instantiate( template, argMap ); - - if( _returnType != null ){ - if( _returnType.isType( ITypeInfo.t_templateParameter ) ){ - if( argMap.containsKey( _returnType ) ){ - newParameterized.setReturnType( getSymbolTable().newSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY ) ); - newParameterized.getReturnType().setTypeInfo( (ITypeInfo) argMap.get( _returnType ) ); - newParameterized.getReturnType().setInstantiatedSymbol( _returnType ); - } - } else { - if( _returnType instanceof IDeferredTemplateInstance ) - template.registerDeferredInstatiation( newParameterized, _returnType, ITemplateSymbol.DeferredKind.RETURN_TYPE, argMap ); - else - newParameterized.setReturnType( _returnType.instantiate( template, argMap ) ); - } - } - - //handle template parameter lists in TemplateSymbol, only do function parameter lists here. - if( !isType( ITypeInfo.t_template ) ){ - List params = getParameterList(); - int size = params.size(); - - newParameterized.getParameterList().clear(); - newParameterized.getParameterMap().clear(); - - ISymbol param = null, newParam = null; - - for( int i = 0; i < size; i++ ){ - param = (ISymbol) params.get(i); - newParam = param.instantiate( template, argMap ); - - newParameterized.addParameter( newParam ); - } - } - - return newParameterized; - } - - public void instantiateDeferredReturnType( ISymbol returnType, ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{ - setReturnType( returnType.instantiate( template, argMap ) ); - } - - /** - * @param symbol - * @param symbol2 - * @param map - */ - public void discardDeferredReturnType(ISymbol oldReturnType, ITemplateSymbol template, ObjectMap map) { - ISymbol returnType = getReturnType(); - setReturnType( null ); - template.removeInstantiation( (IContainerSymbol) returnType ); - } - - public void prepareForParameters( int numParams ){ - if( _parameterList == Collections.EMPTY_LIST ){ - _parameterList = new ArrayList( numParams ); - } else { - ((ArrayList)_parameterList).ensureCapacity( numParams ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addParameter(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void addParameter( ISymbol param ){ - if( _parameterList == Collections.EMPTY_LIST) - _parameterList = new ArrayList(8); - - _parameterList.add( param ); - - char[] name = param.getName(); - if( name != null && !name.equals(ParserSymbolTable.EMPTY_NAME_ARRAY) ) - { - if( _parameterMap == CharArrayObjectMap.EMPTY_MAP ){ - _parameterMap = new CharArrayObjectMap( 2 ); - } - - if( !_parameterMap.containsKey( name ) ) - _parameterMap.put( name, param ); - } - - param.setContainingSymbol( this ); - param.setIsTemplateMember( isTemplateMember() || getType() == ITypeInfo.t_template ); - -// Command command = new AddParameterCommand( this, param ); -// getSymbolTable().pushCommand( command ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addParameter(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType, int, org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp, boolean) - */ - public void addParameter( ITypeInfo.eType type, int info, ITypeInfo.PtrOp ptrOp, boolean hasDefault ){ - BasicSymbol param = new BasicSymbol(getSymbolTable(), ParserSymbolTable.EMPTY_NAME_ARRAY); - - ITypeInfo t = TypeInfoProvider.newTypeInfo( type, info, ptrOp, hasDefault ); - param.setTypeInfo( t ); - - addParameter( param ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addParameter(org.eclipse.cdt.internal.core.parser.pst.ISymbol, org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp, boolean) - */ - public void addParameter( ISymbol typeSymbol, int info, ITypeInfo.PtrOp ptrOp, boolean hasDefault ){ - BasicSymbol param = new BasicSymbol(getSymbolTable(), ParserSymbolTable.EMPTY_NAME_ARRAY); - - ITypeInfo nfo = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, info, typeSymbol, ptrOp, hasDefault ); - param.setTypeInfo( nfo ); - - addParameter( param ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#getParameterMap() - */ - public CharArrayObjectMap getParameterMap(){ - return _parameterMap; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#getParameterList() - */ - public List getParameterList(){ - return _parameterList; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#setParameterList(java.util.List) - */ -// public void setParameterList( List list ){ -// _parameterList = new LinkedList( list ); -// } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#hasSameParameters(org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol) - */ - public boolean hasSameParameters( IParameterizedSymbol function ){ - if( function.getType() != getType() ){ - return false; - } - - int size = ( getParameterList() == null ) ? 0 : getParameterList().size(); - int fsize = ( function.getParameterList() == null ) ? 0 : function.getParameterList().size(); - if( fsize != size ){ - return false; - } - if( fsize == 0 ) - return true; - - List params = getParameterList(); - List functionParams = function.getParameterList(); - - ITypeInfo info = null; - ITypeInfo fInfo = null; - - TypeInfoProvider provider = getSymbolTable().getTypeInfoProvider(); - - for( int i = 0; i < size; i++ ){ - ISymbol p = (ISymbol) params.get(i); - ISymbol pf = (ISymbol) functionParams.get(i); - - info = p.getTypeInfo(); - fInfo = pf.getTypeInfo(); - - //parameters that differ only in the use of equivalent typedef types are equivalent. - info = ParserSymbolTable.getFlatTypeInfo( info, provider ); - fInfo = ParserSymbolTable.getFlatTypeInfo( fInfo, provider ); - - for( ITypeInfo nfo = info; nfo != null; nfo = fInfo ){ - //an array declaration is adjusted to become a pointer declaration - //only the second and subsequent array dimensions are significant in parameter types - List ptrs = nfo.getPtrOperators(); - if( ptrs.size() > 0 ){ - ITypeInfo.PtrOp op = (ITypeInfo.PtrOp) ptrs.get(0); - if( op.getType() == ITypeInfo.PtrOp.t_array ){ - ptrs.set( 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, op.isConst(), op.isVolatile() ) ); - } - } - - //a function type is adjusted to become a pointer to function type - if( nfo.isType( ITypeInfo.t_type ) && nfo.getTypeSymbol() != null && - nfo.getTypeSymbol().isType( ITypeInfo.t_function ) ) - { - if( nfo.getPtrOperators().size() == 0 ){ - nfo.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - } - } - - //const and volatile type-specifiers are ignored (only the outermost level) - if( nfo.getPtrOperators().size() == 0 ){ - nfo.setBit( false, ITypeInfo.isConst ); - nfo.setBit( false, ITypeInfo.isVolatile ); - } else { - ITypeInfo.PtrOp op = (ITypeInfo.PtrOp) nfo.getPtrOperators().get( nfo.getPtrOperators().size() - 1 ); - op.setConst( false ); - op.setVolatile( false ); - } - - if( nfo == fInfo ) - break; - } - - boolean equals = info.equals( fInfo ); - - provider.returnTypeInfo( info ); - provider.returnTypeInfo( fInfo ); - - if( ! equals ) - return false; - } - - - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#setReturnType(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void setReturnType( ISymbol type ){ - _returnType = type; - _returnType.setContainingSymbol( this ); - _returnType.setIsTemplateMember( isTemplateMember() || getType() == ITypeInfo.t_template ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#getReturnType() - */ - public ISymbol getReturnType(){ - return _returnType; - } - - public void setHasVariableArgs( boolean var ){ - _hasVarArgs = var; - } - - public boolean hasVariableArgs( ){ - return _hasVarArgs; - } - -// static private class AddParameterCommand extends Command{ -// public AddParameterCommand( IParameterizedSymbol container, ISymbol parameter ){ -// _decl = container; -// _param = parameter; -// } -// -// public void undoIt(){ -// _decl.getParameterList().remove( _param ); -// -// String name = _param.getName(); -// if( name != null && !name.equals( ParserSymbolTable.EMPTY_NAME) ) -// { -// _decl.getParameterMap().remove( name ); -// } -// } -// -// private IParameterizedSymbol _decl; -// private ISymbol _param; -// } - - - private List _parameterList = Collections.EMPTY_LIST; //have my cake - private CharArrayObjectMap _parameterMap = CharArrayObjectMap.EMPTY_MAP; //and eat it too - private ISymbol _returnType; - private boolean _hasVarArgs = false; //whether or not this function has variable arguments -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java deleted file mode 100644 index 43004b28a61..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java +++ /dev/null @@ -1,2509 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.ast.IASTMember; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.core.parser.util.CharArraySet; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.core.parser.util.ObjectSet; -import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol; - -/** - * @author aniefer - */ - -public class ParserSymbolTable { - - public static final int TYPE_LOOP_THRESHOLD = 50; - public static final int TEMPLATE_LOOP_THRESHOLD = 10; - public static final char[] EMPTY_NAME_ARRAY = new char[0]; //$NON-NLS-1$ - public static final char[] THIS = new char[] {'t','h','i','s'}; //$NON-NLS-1$ - public static final char[] OPERATOR_ = new char[] {'o','p','e','r','a','t','o','r',' '}; //$NON-NLS-1$ - - /** - * Constructor for ParserSymbolTable. - */ - public ParserSymbolTable( ParserLanguage language, ParserMode mode ) { - super(); - _compilationUnit = newContainerSymbol( EMPTY_NAME_ARRAY, ITypeInfo.t_namespace ); - _language = language; - _mode = mode; - _typeInfoProvider = new TypeInfoProvider(); - } - - public IContainerSymbol getCompilationUnit(){ - return _compilationUnit; - } - - public IContainerSymbol newContainerSymbol( char[] name ){ - if( name == null ) name = EMPTY_NAME_ARRAY; - return new ContainerSymbol( this, name ); - } - public IContainerSymbol newContainerSymbol( char[] name, ITypeInfo.eType type ){ - if( name == null ) name = EMPTY_NAME_ARRAY; - return new ContainerSymbol( this, name, type ); - } - - public ISymbol newSymbol( char[] name ){ - if( name == null ) name = EMPTY_NAME_ARRAY; - return new BasicSymbol( this, name ); - } - public ISymbol newSymbol( char[] name, ITypeInfo.eType type ){ - if( name == null ) name = EMPTY_NAME_ARRAY; - return new BasicSymbol( this, name, type ); - } - public IDerivableContainerSymbol newDerivableContainerSymbol( char[] name ){ - return new DerivableContainerSymbol( this, name != null ? name : EMPTY_NAME_ARRAY ); - } - public IDerivableContainerSymbol newDerivableContainerSymbol( char[] name, ITypeInfo.eType type ){ - return new DerivableContainerSymbol( this, name != null ? name : EMPTY_NAME_ARRAY, type ); - } - public IParameterizedSymbol newParameterizedSymbol( char[] name ){ - if( name == null ) name = EMPTY_NAME_ARRAY; - return new ParameterizedSymbol( this, name ); - } - public IParameterizedSymbol newParameterizedSymbol( char[] name, ITypeInfo.eType type ){ - if( name == null ) name = EMPTY_NAME_ARRAY; - return new ParameterizedSymbol( this, name, type ); - } - public ITemplateSymbol newTemplateSymbol( char[] name ){ - if( name == null ) name = EMPTY_NAME_ARRAY; - return new TemplateSymbol( this, name ); - } - - public ISpecializedSymbol newSpecializedSymbol( char[] name ){ - if( name == null ) name = EMPTY_NAME_ARRAY; - return new SpecializedSymbol( this, name ); - } - - public ITemplateFactory newTemplateFactory(){ - return new TemplateFactory( this ); - } - - public ISymbol newUndefinedTemplateSymbol(char[] name) { - if( name == null ) name = EMPTY_NAME_ARRAY; - return new UndefinedTemplateSymbol( this, name ); - } - - public ISymbol newUndefinedTemplateSymbol(char[] name, ITypeInfo.eType type ){ - if( name == null ) name = EMPTY_NAME_ARRAY; - return new UndefinedTemplateSymbol( this, name, type ); - } - - /** - * Lookup the name from LookupData starting in the inDeclaration - * @param data - * @param inDeclaration - * @return Declaration - * @throws ParserSymbolTableException - */ - static protected void lookup( LookupData data, IContainerSymbol inSymbol ) throws ParserSymbolTableException - { - //handle namespace aliases - if( inSymbol.isType( ITypeInfo.t_namespace ) ){ - ISymbol symbol = inSymbol.getForwardSymbol(); - if( symbol != null && symbol.isType( ITypeInfo.t_namespace ) ){ - inSymbol = (IContainerSymbol) symbol; - } - } - - ArrayList transitives = null; //list of transitive using directives - - //if this name define in this scope? - CharArrayObjectMap map = null; - if( !data.usingDirectivesOnly ){ - map = lookupInContained( data, inSymbol ); - if( data.foundItems == null || data.foundItems.isEmpty() ){ - data.foundItems = map; - } else { - mergeScopedResults( data.foundItems, map ); - } - } - - if( inSymbol.getSymbolTable().getLanguage() == ParserLanguage.CPP && - !data.ignoreUsingDirectives ) - { - //check nominated namespaces - //the transitives list is populated in LookupInNominated, and then - //processed in ProcessDirectives - - data.visited.clear(); //each namesapce is searched at most once, so keep track - - transitives = lookupInNominated( data, inSymbol, transitives ); - - //if we are doing a qualified lookup, only process using directives if - //we haven't found the name yet (and if we aren't ignoring them). - if( !data.qualified || data.foundItems == null || data.foundItems.isEmpty() ){ - processDirectives( inSymbol, data, transitives ); - - if( inSymbol.hasUsingDirectives() ){ - processDirectives( inSymbol, data, inSymbol.getUsingDirectives() ); - } - - while( data.usingDirectives != null && data.usingDirectives.get( inSymbol ) != null ){ - if( transitives != null ) - transitives.clear(); - - transitives = lookupInNominated( data, inSymbol, transitives ); - - if( !data.qualified || data.foundItems == null ){ - processDirectives( inSymbol, data, transitives ); - } - } - } - } - - if( !data.isPrefixLookup() && ( ( data.foundItems != null && !data.foundItems.isEmpty()) || data.getStopAt() == inSymbol ) ){ - return; - } - - if( !data.usingDirectivesOnly && inSymbol instanceof IDerivableContainerSymbol ){ - //if we still havn't found it, check any parents we have - data.visited.clear(); //each virtual base class is searched at most once - map = lookupInParents( data, inSymbol ); - - if( data.foundItems == null || data.foundItems.isEmpty() ){ - data.foundItems = map; - } else { - mergeScopedResults( data.foundItems, map ); - } - } - - //if still not found, check our containing scope. - if( ( data.foundItems == null || data.foundItems.isEmpty() || data.isPrefixLookup() ) - && inSymbol.getContainingSymbol() != null ) - { - if( data.qualified ){ - if( data.usingDirectives != null && !data.usingDirectives.isEmpty() ){ - data.usingDirectivesOnly = true; - lookup( data, inSymbol.getContainingSymbol() ); - - } - } else { - lookup( data, inSymbol.getContainingSymbol() ); - } - - } - - return; - } - - /** - * function LookupInNominated - * @param data - * @param transitiveDirectives - * @return List - * - * for qualified: - * 3.4.3.2-2 "let S be the set of all declarations of m in X - * and in the transitive closure of all namespaces nominated by using- - * directives in X and its used namespaces, except that using-directives are - * ignored in any namespace, including X, directly containing one or more - * declarations of m." - * - * for unqualified: - * 7.3.4-2 The using-directive is transitive: if a scope contains a using - * directive that nominates a second namespace that itself contains using- - * directives, the effect is as if the using-directives from the second - * namespace also appeared in the first. - */ - static private ArrayList lookupInNominated( LookupData data, IContainerSymbol symbol, ArrayList transitiveDirectives ) throws ParserSymbolTableException{ - //if the data.usingDirectives is empty, there is nothing to do. - if( data.usingDirectives == null ){ - return transitiveDirectives; - } - - //local variables - ArrayList directives = null; //using directives association with declaration - IContainerSymbol temp = null; - - boolean foundSomething = false; - int size = 0; - - directives = (ArrayList) data.usingDirectives.remove( symbol ); - - if( directives == null ){ - return transitiveDirectives; - } - - size = directives.size(); - for( int i = 0; i < size; i++ ){ - temp = (IContainerSymbol) directives.get(i); - - //namespaces are searched at most once - if( !data.visited.containsKey( temp ) ){ - if( data.visited == ObjectSet.EMPTY_SET ) - data.visited = new ObjectSet( 2 ); - data.visited.put( temp ); - - CharArrayObjectMap map = lookupInContained( data, temp ); - foundSomething = ( map != null && !map.isEmpty() ); - if( foundSomething ){ - if( data.foundItems == null ) - data.foundItems = map; - else - mergeResults( data, data.foundItems, map ); - } - - //only consider the transitive using directives if we are an unqualified - //lookup, or we didn't find the name in decl - if( (!data.qualified || !foundSomething || data.isPrefixLookup() ) && temp.hasUsingDirectives() ){ - //name wasn't found, add transitive using directives for later consideration - if( transitiveDirectives == null ) - transitiveDirectives = new ArrayList(4); - transitiveDirectives.addAll( temp.getUsingDirectives() ); - } - } - } - - return transitiveDirectives; - } - - /** - * @param map - * @param map2 - */ - private static void mergeResults( LookupData data, CharArrayObjectMap resultMap, CharArrayObjectMap map ) throws ParserSymbolTableException { - if( resultMap == null || map == null || map.isEmpty() ){ - return; - } - - char[] key = null; - int size = map.size(); - for( int i = 0; i < size; i++ ){ - key = map.keyAt( i ); - if( resultMap.containsKey( key ) ){ - List list = new ArrayList(); - Object obj = resultMap.get( key ); - - if ( obj instanceof List ) list.addAll( (List) obj ); - else list.add( obj ); - - obj = map.get( key ); - - if( obj instanceof List ) list.addAll( (List) obj ); - else list.add( obj ); - - resultMap.put( key, collectSymbol( data, list ) ); - } else { - resultMap.put( key, map.get( key ) ); - } - } - } - - /** - * function LookupInContained - * @param data - * @return List - * - * Look for data.name in our collection _containedDeclarations - */ - protected static CharArrayObjectMap lookupInContained( LookupData data, IContainerSymbol lookIn ) throws ParserSymbolTableException{ - CharArrayObjectMap found = null; - - Object obj = null; - - if( data.getAssociated() != null ){ - //we are looking in lookIn, remove it from the associated scopes list - data.getAssociated().remove( lookIn ); - } - - CharArrayObjectMap declarations = lookIn.getContainedSymbols(); - - int numKeys = -1; - int idx = 0; - if( data.isPrefixLookup() && declarations != CharArrayObjectMap.EMPTY_MAP ){ - numKeys = declarations.size(); - } - - char[] name = ( numKeys > 0 ) ? (char[]) declarations.keyAt( idx++ ) : data.name; - - while( name != null ) { - if( nameMatches( data, name ) ){ - obj = ( declarations.size() > 0 ) ? declarations.get( name ) : null; - if( obj != null ){ - obj = collectSymbol( data, obj ); - - if( obj != null ){ - if( found == null ){ - found = new CharArrayObjectMap( 2 ); - } - found.put( name, obj ); - } - } - } - if( idx < numKeys ) - name = declarations.keyAt( idx++ ); - else - name = null; - } - if( found != null && data.isPrefixLookup() ) - found.sort( ContainerSymbol.comparator ); - - if( found != null && !data.isPrefixLookup() ){ - return found; - } - - if( lookIn instanceof IParameterizedSymbol ){ - found = lookupInParameters(data, lookIn, found); - } - - if( lookIn.isTemplateMember() && data.templateMember == null ){ - IContainerSymbol containing = lookIn.getContainingSymbol(); - IContainerSymbol outer = (containing != null ) ? containing.getContainingSymbol() : null; - if( ( containing instanceof IDerivableContainerSymbol && outer instanceof ITemplateSymbol) || - ( lookIn instanceof IParameterizedSymbol && containing instanceof ITemplateSymbol ) || - ( lookIn instanceof IDerivableContainerSymbol && containing instanceof ITemplateSymbol ) ) - { - data.templateMember = lookIn; - } - } - - return found; - - } - /** - * @param data - * @param lookIn - * @param found - * @throws ParserSymbolTableException - */ - private static CharArrayObjectMap lookupInParameters(LookupData data, IContainerSymbol lookIn, CharArrayObjectMap found) throws ParserSymbolTableException { - Object obj; - char[] name; - - if( lookIn instanceof ITemplateSymbol && !((ITemplateSymbol)lookIn).getDefinitionParameterMap().isEmpty() ){ - ITemplateSymbol template = (ITemplateSymbol) lookIn; - if( data.templateMember != null && template.getDefinitionParameterMap().containsKey( data.templateMember ) ){ - ObjectMap map = (ObjectMap) template.getDefinitionParameterMap().get( data.templateMember ); - for( int i = 0; i < map.size(); i++ ){ - ISymbol symbol = (ISymbol) map.keyAt(i); - if( nameMatches( data, symbol.getName() ) ){ - obj = collectSymbol( data, symbol ); - if( obj != null ){ - if( found == null ){ - found = new CharArrayObjectMap(2); - } - found.put( symbol.getName(), obj ); - } - } - } - if( found != null && data.isPrefixLookup() ) - found.sort( ContainerSymbol.comparator ); - - return found; - } - - } - CharArrayObjectMap parameters = ((IParameterizedSymbol)lookIn).getParameterMap(); - if( parameters != CharArrayObjectMap.EMPTY_MAP ){ - int numKeys = -1; - int idx = 0; - - if( data.isPrefixLookup() && parameters != CharArrayObjectMap.EMPTY_MAP ){ - numKeys = parameters.size(); - } - name = ( numKeys > 0 ) ? (char[]) parameters.keyAt( idx++ ) : data.name; - while( name != null ){ - if( nameMatches( data, name ) ){ - obj = parameters.get( name ); - obj = collectSymbol( data, obj ); - if( obj != null ){ - if( found == null ){ - found = new CharArrayObjectMap( 2 ); - } - found.put( name, obj ); - } - } - - if( idx < numKeys ) - name = parameters.keyAt( idx++ ); - else - name = null; - } - } - if( found != null && data.isPrefixLookup() ) - found.sort( ContainerSymbol.comparator ); - - return found; - } - - private static boolean nameMatches( LookupData data, char[] name ){ - if( data.isPrefixLookup() ){ - return CharArrayUtils.equals( name, 0, data.name.length, data.name, true); - } - return CharArrayUtils.equals( name, data.name ); - } - private static boolean checkType( LookupData data, ISymbol symbol ) { - if( data.getFilter() == null ){ - return true; - } - - TypeInfoProvider provider = symbol.getSymbolTable().getTypeInfoProvider(); - ITypeInfo typeInfo = ParserSymbolTable.getFlatTypeInfo( symbol.getTypeInfo(), provider ); - boolean accept = data.getFilter().shouldAccept( symbol, typeInfo ) || data.getFilter().shouldAccept( symbol ); - provider.returnTypeInfo( typeInfo ); - - return accept; - } - - private static Object collectSymbol(LookupData data, Object object ) throws ParserSymbolTableException { - if( object == null ){ - return null; - } - - ISymbol foundSymbol = null; - - List objList = ( object instanceof List ) ? (List)object : null; - int objListSize = ( objList != null ) ? objList.size() : 0; - ISymbol symbol = ( objList != null ) ? (ISymbol) objList.get( 0 ) : (ISymbol) object; - - ObjectSet functionSet = ObjectSet.EMPTY_SET; - ObjectSet templateFunctionSet = ObjectSet.EMPTY_SET; - - ISymbol obj = null; - IContainerSymbol cls = null; - int idx = 1; - while( symbol != null ){ - if( symbol instanceof ITemplateSymbol ){ - ISymbol temp = ((ITemplateSymbol)symbol).getTemplatedSymbol(); - symbol = ( temp != null ) ? temp : symbol; - } - - if( ( data.returnInvisibleSymbols || !symbol.getIsInvisible() ) && checkType( data, symbol ) ){ - foundSymbol = symbol; - - if( foundSymbol.isType( ITypeInfo.t_function ) ){ - if( foundSymbol.isForwardDeclaration() && foundSymbol.getForwardSymbol() != null && - !foundSymbol.isTemplateInstance() && foundSymbol.getForwardSymbol().getContainingSymbol() != null) - { - foundSymbol = foundSymbol.getForwardSymbol(); - } - if( foundSymbol.getContainingSymbol().isType( ITypeInfo.t_template ) ){ - if( templateFunctionSet == ObjectSet.EMPTY_SET ) - templateFunctionSet = new ObjectSet( 2 ); - templateFunctionSet.put( foundSymbol ); - } else { - if( functionSet == ObjectSet.EMPTY_SET ) - functionSet = new ObjectSet( 2 ); - functionSet.put( foundSymbol ); - } - - } else { - //if this is a class-name, other stuff hides it - if( foundSymbol.isType( ITypeInfo.t_class, ITypeInfo.t_enumeration ) ){ - if( cls == null ){ - cls = (IContainerSymbol) foundSymbol; - } else { - if( cls.isForwardDeclaration() && cls.getForwardSymbol() == foundSymbol ){ - //cls is a forward declaration of decl, we want decl. - cls = (IContainerSymbol) foundSymbol; - } else if( foundSymbol.isForwardDeclaration() && foundSymbol.getForwardSymbol() == cls ){ - //decl is a forward declaration of cls, we already have what we want (cls) - } else { - if( data.isPrefixLookup() ){ - data.addAmbiguity( foundSymbol.getName() ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); - } - } - } - } else { - //an object, can only have one of these - if( obj == null ){ - obj = foundSymbol; - } else { - if( obj.isForwardDeclaration() && obj.getForwardSymbol() == foundSymbol ) - obj = foundSymbol; - else if( foundSymbol.isForwardDeclaration() && foundSymbol.getForwardSymbol() == obj ){ - //we already have what we want. - } - else if( foundSymbol.getTypeInfo().checkBit(ITypeInfo.isTypedef ) && - obj.getTypeInfo().checkBit( ITypeInfo.isTypedef ) && - foundSymbol.getTypeInfo().getFinalType( null ).equals(obj.getTypeInfo().getFinalType( null ) )) - { - //two typedef's with matching name, if they are typedefed to the same thing, - //then its all good and we already have the one we want. (7.1.3-2) - } - else if( data.isPrefixLookup() ){ - data.addAmbiguity( foundSymbol.getName() ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); - } - } - } - } - } - - if( objList != null && idx < objListSize ){ - symbol = (ISymbol) objList.get( idx++ ); - } else { - symbol = null; - } - } - - int numFunctions = functionSet.size(); - int numTemplateFunctions = templateFunctionSet.size(); - - boolean ambiguous = false; - - if( cls != null ){ - //the class is only hidden by other stuff if they are from the same scope - if( obj != null && cls.getContainingSymbol() != obj.getContainingSymbol()){ - ambiguous = true; - } - - IParameterizedSymbol fn = null; - if( numTemplateFunctions > 0 ){ - for( int i = 0; i < numTemplateFunctions; i++ ){ - fn = (IParameterizedSymbol) templateFunctionSet.keyAt( i ); - if( cls.getContainingSymbol()!= fn.getContainingSymbol()){ - ambiguous = true; - break; - } - } - } - if( numFunctions > 0 ){ - for( int i = 0; i < numFunctions; i++ ){ - fn = (IParameterizedSymbol) functionSet.keyAt( i ); - if( cls.getContainingSymbol()!= fn.getContainingSymbol()){ - ambiguous = true; - break; - } - } - } - } - - if( numTemplateFunctions > 0 ){ - if( data.getParameters() != null && ( !data.exactFunctionsOnly || data.getTemplateParameters() != null ) ){ - List fns = TemplateEngine.selectTemplateFunctions( templateFunctionSet, data.getParameters(), data.getTemplateParameters() ); - if( fns != null ){ - if( functionSet == ObjectSet.EMPTY_SET ) - functionSet = new ObjectSet( fns.size() ); - functionSet.addAll( fns ); - } - numFunctions = functionSet.size(); - } else { - if( functionSet == ObjectSet.EMPTY_SET ) - functionSet = new ObjectSet( templateFunctionSet.size() ); - functionSet.addAll( templateFunctionSet ); - numFunctions += numTemplateFunctions; - } - } - - if( obj != null && !ambiguous ){ - if( numFunctions > 0 ){ - ambiguous = true; - } else { - return obj; - } - } else if( numFunctions > 0 ) { - return functionSet.toList(); - } - - if( ambiguous ){ - if( data.isPrefixLookup() ){ - data.addAmbiguity( foundSymbol.getName() ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); - } - } - - return cls; - } - /** - * - * @param data - * @param lookIn - * @return Declaration - * @throws ParserSymbolTableException - */ - private static CharArrayObjectMap lookupInParents( LookupData data, ISymbol lookIn ) throws ParserSymbolTableException{ - IDerivableContainerSymbol container = null; - - if( lookIn instanceof IDerivableContainerSymbol ){ - container = (IDerivableContainerSymbol) lookIn; - } else{ - throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError ); - } - - List scopes = container.getParents(); - - CharArrayObjectMap temp = null; - CharArrayObjectMap symbol = null; - CharArrayObjectMap inherited = null; - - IDerivableContainerSymbol.IParentSymbol wrapper = null; - - if( scopes == null ) - return null; - - //use data to detect circular inheritance - if( data.inheritanceChain == null ) - data.inheritanceChain = new ObjectSet( 2 ); - - data.inheritanceChain.put( container ); - - int size = scopes.size(); - for( int i = 0; i < size; i++ ) - { - wrapper = (IDerivableContainerSymbol.IParentSymbol) scopes.get(i); - ISymbol parent = wrapper.getParent(); - - //skip if parent is template parameter - if( parent == null || parent.isType( ITypeInfo.t_templateParameter ) ) - continue; - - if( !wrapper.isVirtual() || !data.visited.containsKey( parent ) ){ - if( wrapper.isVirtual() ){ - if( data.visited == ObjectSet.EMPTY_SET ) - data.visited = new ObjectSet(2); - data.visited.put( parent ); - } - - if( parent instanceof IDeferredTemplateInstance ){ - parent = ((IDeferredTemplateInstance)parent).getTemplate().getTemplatedSymbol(); - } else if( parent instanceof ITemplateSymbol ){ - parent = ((ITemplateSymbol)parent).getTemplatedSymbol(); - } - - //if the inheritanceChain already contains the parent, then that - //is circular inheritance - if( ! data.inheritanceChain.containsKey( parent ) ){ - //is this name define in this scope? - if( parent instanceof IDerivableContainerSymbol ){ - temp = lookupInContained( data, (IDerivableContainerSymbol) parent ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); - } - - if( (temp == null || temp.isEmpty()) || data.isPrefixLookup() ){ - inherited = lookupInParents( data, parent ); - if( temp == null ) - temp = inherited; - else - mergeScopedResults( temp, inherited ); - } - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_CircularInheritance ); - } - } - - if( temp != null && !temp.isEmpty() ){ - if( symbol == null || symbol.isEmpty() ){ - symbol = temp; - } else if ( temp != null && !temp.isEmpty() ) { - char[] key = null; - int tempSize = temp.size(); - for( int ii = 0; ii < tempSize; ii++ ){ - key = temp.keyAt( ii ); - - if( symbol.containsKey( key ) ){ - Object obj = symbol.get( key ); - List objList = ( obj instanceof List ) ? (List)obj : null; - int objListSize = ( objList != null ) ? objList.size() : 0, idx = 1; - ISymbol sym = (ISymbol) (( objList != null && objListSize > 0 ) ? objList.get(0) : obj); - while( sym != null ){ - if( !checkAmbiguity( sym, temp.get( key ) ) ){ - if( data.isPrefixLookup() ){ - data.addAmbiguity( sym.getName() ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); - } - } - - if( objList != null && idx < objListSize ){ - sym = (ISymbol) objList.get( idx++ ); - } else { - sym = null; - } - } - } else { - symbol.put( key, temp.get( key ) ); - } - } - } - } else { - temp = null; //reset temp for next iteration - } - } - - data.inheritanceChain.remove( container ); - - return symbol; - } - - private static boolean checkAmbiguity( Object obj1, Object obj2 ){ - //it is not ambiguous if they are the same thing and it is static or an enumerator - if( obj1 == obj2 ){ - List objList = ( obj1 instanceof List ) ? (List) obj1 : null; - int objListSize = ( objList != null ) ? objList.size() : 0; - ISymbol symbol = ( objList != null ) ? (ISymbol) objList.get(0) : ( ISymbol )obj1; - int idx = 1; - while( symbol != null ) { - ITypeInfo type = ((ISymbol)obj1).getTypeInfo(); - if( !type.checkBit( ITypeInfo.isStatic ) && !type.isType( ITypeInfo.t_enumerator ) ){ - return false; - } - - if( objList != null && idx < objListSize ){ - symbol = (ISymbol) objList.get( idx++ ); - } else { - symbol = null; - } - } - return true; - } - return false; - } - - /** - * Symbols in map are added to the resultMap if a symbol with that name does not already exist there - * @param resultMap - * @param map - * @throws ParserSymbolTableException - */ - private static void mergeScopedResults( CharArrayObjectMap resultMap, CharArrayObjectMap map ){ - if( resultMap == null || map == null || map.isEmpty() ){ - return; - } - - char[] key = null; - int size = map.size(); - for( int i = 0; i < size; i++ ){ - key = map.keyAt( i ); - if( !resultMap.containsKey( key ) ){ - resultMap.put( key, map.get( key ) ); - } - } - } - - /** - * function isValidOverload - * @param origDecl - * @param newDecl - * @return boolean - * - * 3.3.7 "A class name or enumeration name can be hidden by the name of an - * object, function or enumerator declared in the same scope" - * - * 3.4-1 "Name lookup may associate more than one declaration with a name if - * it finds the name to be a function name" - */ - protected static boolean isValidOverload( ISymbol origSymbol, ISymbol newSymbol ){ - ITypeInfo.eType origType = origSymbol.getType(); - ITypeInfo.eType newType = newSymbol.getType(); - - if( origType == ITypeInfo.t_template ){ - ITemplateSymbol template = (ITemplateSymbol) origSymbol; - origSymbol = template.getTemplatedSymbol(); - if( origSymbol == null ) - return true; - origType = origSymbol.getType(); - } - - if( newType == ITypeInfo.t_template ){ - ITemplateSymbol template = (ITemplateSymbol) newSymbol; - newSymbol = template.getTemplatedSymbol(); - if( newSymbol == null ) - return true; - newType = newSymbol.getType(); - } - - // handle reverse-forward 'using' decls - if( newSymbol.isForwardDeclaration() ){ - if( newSymbol.getForwardSymbol() == origSymbol ) - return true; - } - - //handle forward decls - if( origSymbol.isForwardDeclaration() ){ - if( origSymbol.getForwardSymbol() == newSymbol ) - return true; - - //friend class declarations - if( origSymbol.getIsInvisible() && origSymbol.isType( newSymbol.getType() ) ){ - origSymbol.setForwardSymbol( newSymbol ); - return true; - } - } - - if( (origType.compareTo(ITypeInfo.t_class) >= 0 && origType.compareTo(ITypeInfo.t_enumeration) <= 0) && //class name or enumeration ... - ( newType == ITypeInfo.t_type || (newType.compareTo( ITypeInfo.t_function ) >= 0 /*&& newType <= TypeInfo.typeMask*/) ) ){ - - return true; - // 3.3.7-2 (in any order) same as above but with origType and newType reversed - } else if( (newType.compareTo(ITypeInfo.t_class) >= 0 && newType.compareTo(ITypeInfo.t_enumeration) <= 0) && //class name or enumeration ... - ( origType == ITypeInfo.t_type || (origType.compareTo( ITypeInfo.t_function ) >= 0 /*&& newType <= TypeInfo.typeMask*/) ) ){ - - return true; - } - //if the origtype is not a class-name or enumeration name, then the only other - //allowable thing is if they are both functions. - if( origSymbol instanceof IParameterizedSymbol && newSymbol instanceof IParameterizedSymbol ) - return isValidFunctionOverload( (IParameterizedSymbol) origSymbol, (IParameterizedSymbol) newSymbol ); - - if( origSymbol.getTypeInfo().checkBit( ITypeInfo.isTypedef ) && newSymbol.getTypeInfo().checkBit( ITypeInfo.isTypedef ) ){ - TypeInfoProvider provider = origSymbol.getSymbolTable().getTypeInfoProvider(); - ITypeInfo origFlat = origSymbol.getTypeInfo().getFinalType( provider ); - ITypeInfo newFlat = origSymbol.getTypeInfo().getFinalType( provider ); - boolean equals = origFlat.equals( newFlat ); - provider.returnTypeInfo( origFlat ); - provider.returnTypeInfo( newFlat ); - return equals; - } - return false; - } - - protected static boolean isValidOverload( List origList, ISymbol newSymbol ){ - if( origList.size() == 1 ){ - return isValidOverload( (ISymbol)origList.get(0), newSymbol ); - } else if ( origList.size() > 1 ){ - if( newSymbol.isType( ITypeInfo.t_template ) && newSymbol instanceof ITemplateSymbol ){ - newSymbol = ((ITemplateSymbol) newSymbol).getTemplatedSymbol(); - } - - //the first thing can be a class-name or enumeration name, but the rest - //must be functions. So make sure the newDecl is a function before even - //considering the list - if( newSymbol.getType() != ITypeInfo.t_function && newSymbol.getType() != ITypeInfo.t_constructor ){ - return false; - } - - //Iterator iter = origList.iterator(); - ISymbol symbol = (ISymbol) origList.get(0); - int numSymbols = origList.size(); - if( symbol.isType( ITypeInfo.t_template ) && symbol instanceof ITemplateSymbol ){ - symbol = ((ITemplateSymbol) symbol).getTemplatedSymbol(); - } - - boolean valid = isValidOverload( symbol, newSymbol ); - int idx = 1; - while( valid && idx < numSymbols ){ - symbol = (ISymbol) origList.get(idx++); - if( symbol.isType( ITypeInfo.t_template ) ){ - ITemplateSymbol template = (ITemplateSymbol) symbol; - symbol = template.getTemplatedSymbol(); - } - valid = ( symbol instanceof IParameterizedSymbol) && isValidFunctionOverload( (IParameterizedSymbol)symbol, (IParameterizedSymbol)newSymbol ); - } - - return valid; - } - - //empty list, return true - return true; - } - - private static boolean isValidFunctionOverload( IParameterizedSymbol origSymbol, IParameterizedSymbol newSymbol ){ - if( ( !origSymbol.isType( ITypeInfo.t_function ) && !origSymbol.isType( ITypeInfo.t_constructor ) ) || - ( ! newSymbol.isType( ITypeInfo.t_function ) && ! newSymbol.isType( ITypeInfo.t_constructor ) ) ){ - return false; - } - - //handle forward decls - if( origSymbol.isForwardDeclaration() && - origSymbol.getForwardSymbol() == newSymbol ) - { - return true; - } - if( origSymbol.hasSameParameters( newSymbol ) ){ - //functions with the same name and same parameter types cannot be overloaded if any of them - //is static - if( origSymbol.getTypeInfo().checkBit( ITypeInfo.isStatic ) || newSymbol.getTypeInfo().checkBit( ITypeInfo.isStatic ) ){ - return false; - } - - //if none of them are static, then the function can be overloaded if they differ in the type - //of their implicit object parameter. - if( (origSymbol.getTypeInfo().getTypeBits()& ( ITypeInfo.isConst | ITypeInfo.isVolatile )) != - (newSymbol.getTypeInfo().getTypeBits() & ( ITypeInfo.isConst | ITypeInfo.isVolatile )) ) - { - return true; - } - - // fix 71317, see C++ spec 7.3.3-11, two using declarations may introduce functions with the same - //name and parameter types - if (newSymbol.isForwardDeclaration() && newSymbol.getForwardSymbol() != null - && newSymbol.getContainingSymbol() == origSymbol.getContainingSymbol() - && newSymbol.getForwardSymbol().getContainingSymbol() != newSymbol.getContainingSymbol() - && origSymbol.isForwardDeclaration() && origSymbol.getForwardSymbol() != null - && origSymbol.getForwardSymbol().getContainingSymbol() != origSymbol.getContainingSymbol()) { - return true; - } - - return false; - } - - return true; - } - - /** - * - * @param data - * @return Declaration - * @throws ParserSymbolTableException - * - * Resolve the foundItems set down to one declaration and return that - * declaration. - * If we successfully resolve, then the data.foundItems list will be - * cleared. If however, we were not able to completely resolve the set, - * then the data.foundItems set will be left with those items that - * survived the partial resolution and we will return null. (currently, - * this case applies to when we have overloaded functions and no parameter - * information) - * - * NOTE: data.parameters == null means there is no parameter information at - * all, when looking for functions with no parameters, an empty list must be - * provided in data.parameters. - */ - protected ISymbol resolveAmbiguities( LookupData data ) throws ParserSymbolTableException{ - ISymbol resolvedSymbol = null; - - if( data.foundItems == null || data.foundItems.isEmpty() || data.isPrefixLookup() ){ - return null; - } - - Object object = data.foundItems.get( data.name ); - - ArrayList functionList = null; - - if( object instanceof List ){ - //if we got this far with a list, they must all be functions - functionList = new ArrayList( ((List)object).size() ); - functionList.addAll( (List) object ); - } else { - ISymbol symbol = (ISymbol) object; - if( symbol.isType( ITypeInfo.t_function ) ){ - functionList = new ArrayList(1); - functionList.add( symbol ); - } else { - if( symbol.isTemplateMember() && !symbol.isTemplateInstance() && - !symbol.isType( ITypeInfo.t_templateParameter ) && symbol.getContainingSymbol().isType( ITypeInfo.t_template )) - { - resolvedSymbol = symbol.getContainingSymbol(); - if( resolvedSymbol instanceof ISpecializedSymbol ){ - resolvedSymbol = ((ISpecializedSymbol)resolvedSymbol).getPrimaryTemplate(); - } - } else { - resolvedSymbol = symbol; - } - } - } - - if( resolvedSymbol == null ){ - if( data.getParameters() == null ){ - //we have no parameter information, if we only have one function, return - //that, otherwise we can't decide between them - if( functionList.size() == 1){ - resolvedSymbol = (ISymbol) functionList.get(0); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_UnableToResolveFunction ); - } - } else { - resolvedSymbol = resolveFunction( data, functionList ); - } - } - return resolvedSymbol; - } - - protected IParameterizedSymbol resolveFunction( LookupData data, List functions ) throws ParserSymbolTableException{ - if( functions == null ){ - return null; - } - - //reduce our set of candidate functions to only those who have the right number of parameters - reduceToViable( data, functions ); - - if( data.exactFunctionsOnly && data.getTemplateParameters() == null ){ - if( functions.size() == 1 ){ - return (IParameterizedSymbol) functions.get( 0 ); - } else if( functions.size() == 0 ){ - return null; - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); - } - } - - int numSourceParams = ( data.getParameters() == null ) ? 0 : data.getParameters().size(); - int numFns = functions.size(); - - if( numSourceParams == 0 ){ - //no parameters - //if there is only 1 viable function, return it, if more than one, its ambiguous - if( numFns == 0 ){ - return null; - } else if ( numFns == 1 ){ - return (IParameterizedSymbol)functions.get(0); - } else if ( numFns == 2 ){ - for (int i = 0; i < numFns; i++) { - IParameterizedSymbol fn = (IParameterizedSymbol) functions.get(i); - if( fn.isForwardDeclaration() && fn.getForwardSymbol() != null ){ - if( functions.contains( fn.getForwardSymbol() ) ){ - return (IParameterizedSymbol) fn.getForwardSymbol(); - } - } - } - } - - if( data.getParameters() == null ) - throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); - } - - IParameterizedSymbol bestFn = null; //the best function - IParameterizedSymbol currFn = null; //the function currently under consideration - Cost [] bestFnCost = null; //the cost of the best function - Cost [] currFnCost = null; //the cost for the current function - - ITypeInfo source = null; //parameter we are called with - ITypeInfo target = null; //function's parameter - ITypeInfo voidInfo = null; //used to compare f() and f(void) - - int comparison; - Cost cost = null; //the cost of converting source to target - Cost temp = null; //the cost of using a user defined conversion to convert source to target - - boolean hasWorse = false; //currFn has a worse parameter fit than bestFn - boolean hasBetter = false; //currFn has a better parameter fit than bestFn - boolean ambiguous = false; //ambiguity, 2 functions are equally good - boolean currHasAmbiguousParam = false; //currFn has an ambiguous parameter conversion (ok if not bestFn) - boolean bestHasAmbiguousParam = false; //bestFn has an ambiguous parameter conversion (not ok, ambiguous) - - List sourceParameters = null; //the parameters the function is being called with - List targetParameters = null; //the current function's parameters - - TypeInfoProvider infoProvider = getTypeInfoProvider(); - - if( numSourceParams == 0 ){ - //f() is the same as f( void ) - sourceParameters = new ArrayList(1); - voidInfo = infoProvider.getTypeInfo( ITypeInfo.t_void ); - voidInfo.setType( ITypeInfo.t_void ); - sourceParameters.add( voidInfo ); - numSourceParams = 1; - } else { - sourceParameters = data.getParameters(); - } - - try { - for( int fnIdx = 0; fnIdx < numFns; fnIdx++ ){ - currFn = (IParameterizedSymbol) functions.get( fnIdx ); - - if( bestFn != null ){ - if( bestFn.isForwardDeclaration() && bestFn.getForwardSymbol() == currFn ){ - bestFn = currFn; - continue; - } else if( currFn.isForwardDeclaration() && currFn.getForwardSymbol() == bestFn ){ - continue; - } - } - - - if( currFn.getParameterList().isEmpty() && !currFn.hasVariableArgs() ){ - //the only way we get here and have no parameters, is if we are looking - //for a function that takes void parameters ie f( void ) - targetParameters = new ArrayList(1); - targetParameters.add( currFn.getSymbolTable().newSymbol( EMPTY_NAME_ARRAY, ITypeInfo.t_void ) ); //$NON-NLS-1$ - } else { - targetParameters = currFn.getParameterList(); - } - - int numTargetParams = targetParameters.size(); - if( currFnCost == null ){ - currFnCost = new Cost [ numSourceParams ]; - } - - comparison = 0; - boolean varArgs = false; - - for( int j = 0; j < numSourceParams; j++ ){ - source = (ITypeInfo) sourceParameters.get(j); - - if( j < numTargetParams ) - target = ((ISymbol)targetParameters.get(j)).getTypeInfo(); - else - varArgs = true; - - if( varArgs ){ - cost = new Cost( infoProvider, source, null ); - cost.rank = Cost.ELLIPSIS_CONVERSION; - } else if ( target.getHasDefault() && source.isType( ITypeInfo.t_void ) && !source.hasPtrOperators() ){ - //source is just void, ie no parameter, if target had a default, then use that - cost = new Cost( infoProvider, source, target ); - cost.rank = Cost.IDENTITY_RANK; - } else if( source.equals( target ) ){ - cost = new Cost( infoProvider, source, target ); - cost.rank = Cost.IDENTITY_RANK; //exact match, no cost - } else { - try{ - cost = checkStandardConversionSequence( source, target ); - - //12.3-4 At most one user-defined conversion is implicitly applied to - //a single value. (also prevents infinite loop) - if( cost.rank == Cost.NO_MATCH_RANK && !data.forUserDefinedConversion ){ - temp = checkUserDefinedConversionSequence( source, target ); - if( temp != null ){ - cost.release( infoProvider ); - cost = temp; - } - } - } catch( ParserSymbolTableException e ) { - if( cost != null ) { cost.release( infoProvider ); cost = null; } - if( temp != null ) { temp.release( infoProvider ); temp = null; } - throw e; - } catch( ParserSymbolTableError e ) { - if( cost != null ) { cost.release( infoProvider ); cost = null; } - if( temp != null ) { temp.release( infoProvider ); temp = null; } - throw e; - } - } - - currFnCost[ j ] = cost; - } - - - hasWorse = false; - hasBetter = false; - //In order for this function to be better than the previous best, it must - //have at least one parameter match that is better that the corresponding - //match for the other function, and none that are worse. - for( int j = 0; j < numSourceParams; j++ ){ - if( currFnCost[ j ].rank < 0 ){ - hasWorse = true; - hasBetter = false; - - if( data.isPrefixLookup() ){ - //for prefix lookup, just remove from the function list those functions - //that don't fit the parameters - functions.remove( fnIdx-- ); - numFns--; - } - break; - } - - //an ambiguity in the user defined conversion sequence is only a problem - //if this function turns out to be the best. - currHasAmbiguousParam = ( currFnCost[ j ].userDefined == 1 ); - - if( bestFnCost != null ){ - comparison = currFnCost[ j ].compare( bestFnCost[ j ] ); - hasWorse |= ( comparison < 0 ); - hasBetter |= ( comparison > 0 ); - } else { - hasBetter = true; - } - } - - //during a prefix lookup, we don't need to rank the functions - if( data.isPrefixLookup() ){ - releaseCosts( currFnCost, infoProvider ); - continue; - } - - //If function has a parameter match that is better than the current best, - //and another that is worse (or everything was just as good, neither better nor worse). - //then this is an ambiguity (unless we find something better than both later) - ambiguous |= ( hasWorse && hasBetter ) || ( !hasWorse && !hasBetter ); - - if( !hasWorse ){ - if( !hasBetter ){ - //if they are both template functions, we can order them that way - boolean bestIsTemplate = bestFn.getContainingSymbol() instanceof ITemplateSymbol; - boolean currIsTemplate = currFn.getContainingSymbol() instanceof ITemplateSymbol; - if( bestIsTemplate && currIsTemplate ) - { - try{ - ITemplateSymbol t1 = (ITemplateSymbol) bestFn.getInstantiatedSymbol().getContainingSymbol(); - ITemplateSymbol t2 = (ITemplateSymbol) currFn.getInstantiatedSymbol().getContainingSymbol(); - int order = TemplateEngine.orderTemplateFunctions( t1, t2 ); - if ( order < 0 ){ - hasBetter = true; - } else if( order > 0 ){ - ambiguous = false; - } - } catch( ParserSymbolTableException e ) { - if( currFnCost != null ) releaseCosts( currFnCost, infoProvider ); - if( bestFnCost != null ) releaseCosts( bestFnCost, infoProvider ); - throw e; - } catch( ParserSymbolTableError e ) { - if( currFnCost != null ) releaseCosts( currFnCost, infoProvider ); - if( bestFnCost != null ) releaseCosts( bestFnCost, infoProvider ); - throw e; - } - } - //we prefer normal functions over template functions, unless we specified template arguments - else if( bestIsTemplate && !currIsTemplate ){ - if( data.getTemplateParameters() == null ) - hasBetter = true; - else - ambiguous = false; - } else if( !bestIsTemplate && currIsTemplate ){ - if( data.getTemplateParameters() == null ) - ambiguous = false; - else - hasBetter = true; - } - } - if( hasBetter ){ - //the new best function. - ambiguous = false; - releaseCosts( bestFnCost, infoProvider ); - bestFnCost = currFnCost; - bestHasAmbiguousParam = currHasAmbiguousParam; - currFnCost = null; - bestFn = currFn; - } else { - releaseCosts( currFnCost, infoProvider ); - } - } else { - releaseCosts( currFnCost, infoProvider ); - } - } - } finally { - if( currFnCost != null ){ - releaseCosts( currFnCost, infoProvider ); - currFnCost = null; - } - if( bestFnCost != null ){ - releaseCosts( bestFnCost, infoProvider ); - bestFnCost = null; - } - if( voidInfo != null ) - infoProvider.returnTypeInfo( voidInfo ); - } - - if( ambiguous || bestHasAmbiguousParam ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); - } - - return bestFn; - } - static private void releaseCosts( Cost [] costs, TypeInfoProvider provider ){ - if( costs != null && provider != null) { - for( int i = 0; i < costs.length; i++ ){ - if( costs[i] != null ) - costs[i].release( provider ); - } - } - } - - static private boolean functionHasParameters( IParameterizedSymbol function, List params ){ - if( params == null ){ - return function.getParameterList().isEmpty(); - } - //create a new function that has params as its parameters, then use IParameterizedSymbol.hasSameParameters - IParameterizedSymbol tempFn = function.getSymbolTable().newParameterizedSymbol( EMPTY_NAME_ARRAY, ITypeInfo.t_function ); - - int size = params.size(); - for( int i = 0; i < size; i++ ){ - ISymbol param = function.getSymbolTable().newSymbol( EMPTY_NAME_ARRAY ); - param.setTypeInfo( (ITypeInfo) params.get(i) ); - tempFn.addParameter( param ); - } - - return function.hasSameParameters( tempFn ); - } - - static private void reduceToViable( LookupData data, List functions ){ - int numParameters = ( data.getParameters() == null ) ? 0 : data.getParameters().size(); - int num; - - if( data.isPrefixLookup() ) - { - if( numParameters >= 1 ) - numParameters++; - } - - //Trim the list down to the set of viable functions - IParameterizedSymbol function; - Object obj = null; - int size = functions.size(); - for( int i = 0; i < size; i++ ){ - obj = functions.get(i); - //sanity check - if( obj instanceof IParameterizedSymbol ){ - function = (IParameterizedSymbol) obj; - if( !function.isType( ITypeInfo.t_function) && !function.isType( ITypeInfo.t_constructor ) ){ - functions.remove( i-- ); - size--; - continue; - } - } else { - functions.remove( i-- ); - size--; - continue; - } - - num = ( function.getParameterList() == null ) ? 0 : function.getParameterList().size(); - - //if there are m arguments in the list, all candidate functions having m parameters - //are viable - if( num == numParameters ){ - if( data.exactFunctionsOnly && !functionHasParameters( function, data.getParameters() ) ){ - functions.remove( i-- ); - size--; - } - continue; - } - //check for void - else if( numParameters == 0 && num == 1 ){ - ISymbol param = (ISymbol)function.getParameterList().get(0); - if( param.isType( ITypeInfo.t_void ) ) - continue; - } - else if( numParameters == 1 && num == 0 ){ - ITypeInfo paramType = (ITypeInfo) data.getParameters().get(0); - if( paramType.isType( ITypeInfo.t_void ) ) - continue; - } - - //A candidate function having fewer than m parameters is viable only if it has an - //ellipsis in its parameter list. - if( num < numParameters ){ - if( function.hasVariableArgs() ) { - continue; - } - //not enough parameters, remove it - functions.remove( i-- ); - size--; - } - //a candidate function having more than m parameters is viable only if the (m+1)-st - //parameter has a default argument - else { - if( data.isPrefixLookup() ){ - //during prefix lookup, having more parameters than what is provided is ok - continue; - } - List params = function.getParameterList(); - ITypeInfo param; - for( int j = num - 1; j > ( numParameters - num); j-- ){ - param = ((ISymbol)params.get(j)).getTypeInfo(); - if( !param.getHasDefault() ){ - functions.remove( i-- ); - size--; - break; - } - } - } - } - } - - /** - * function ProcessDirectives - * @param Declaration decl - * @param LookupData data - * @param LinkedList directives - * - * Go through the directives and for each nominated namespace find the - * closest enclosing declaration for that namespace and decl, then add the - * nominated namespace to the lookup data for consideration when we reach - * the enclosing declaration. - */ - static private void processDirectives( IContainerSymbol symbol, LookupData data, List directives ){ - IContainerSymbol enclosing = null; - IContainerSymbol temp = null; - - if( directives == null ) - return; - - int size = directives.size(); - for( int i = 0; i < size; i++ ){ - temp = ((IUsingDirectiveSymbol) directives.get(i)).getNamespace(); - - //namespaces are searched at most once - if( !data.visited.containsKey( temp ) ){ - enclosing = getClosestEnclosingDeclaration( symbol, temp ); - - //the data.usingDirectives is a map from enclosing declaration to - //a list of namespaces to consider when we reach that enclosing - //declaration - ArrayList list = (data.usingDirectives == null ) - ? null - : (ArrayList) data.usingDirectives.get( enclosing ); - if ( list == null ){ - list = new ArrayList(4); - list.add( temp ); - if( data.usingDirectives == null ){ - data.usingDirectives = new ObjectMap(2); - } - data.usingDirectives.put( enclosing, list ); - } else { - list.add( temp ); - } - } - } - } - - /** - * function getClosestEnclosingDeclaration - * @param decl1 - * @param decl2 - * @return Declaration - * - * 7.3.4-1 "During unqualified lookup, the names appear as if they were - * declared in the nearest enclosing namespace which contains both the - * using-directive and the nominated namespace" - * - * TBD: Consider rewriting this iteratively instead of recursively, for - * performance - */ - static private IContainerSymbol getClosestEnclosingDeclaration( ISymbol symbol1, ISymbol symbol2 ){ - if( symbol1 == symbol2 ){ - return ( symbol1 instanceof IContainerSymbol ) ? (IContainerSymbol) symbol1 : symbol1.getContainingSymbol(); - } - - if( symbol1.getDepth() == symbol2.getDepth() ){ - return getClosestEnclosingDeclaration( symbol1.getContainingSymbol(), symbol2.getContainingSymbol() ); - } else if( symbol1.getDepth() > symbol2.getDepth() ) { - return getClosestEnclosingDeclaration( symbol1.getContainingSymbol(), symbol2 ); - } else { - return getClosestEnclosingDeclaration( symbol1, symbol2.getContainingSymbol() ); - } - } - - /** - * - * @param obj - * @param base - * @return int - * figure out if base is a base class of obj, and return the "distance" to - * the base class. - * ie: - * A -> B -> C - * the distance from A to B is 1 and from A to C is 2. This distance is used - * to rank standard pointer conversions. - * - * TBD: Consider rewriting iteratively for performance. - */ - static protected int hasBaseClass( ISymbol obj, ISymbol base ) throws ParserSymbolTableException { - return hasBaseClass( obj, base, false ); - } - - static private int hasBaseClass( ISymbol obj, ISymbol base, boolean throwIfNotVisible ) throws ParserSymbolTableException{ - if( obj == base ){ - return 0; - } - IDerivableContainerSymbol symbol = null; - - if( obj instanceof IDerivableContainerSymbol ){ - symbol = (IDerivableContainerSymbol) obj; - } else { - return -1; - } - - if( symbol.hasParents() ){ - ISymbol temp = null; - IDerivableContainerSymbol parent = null; - IDerivableContainerSymbol.IParentSymbol wrapper; - - List parents = symbol.getParents(); - int size = parents.size(); - - for( int i = 0; i < size; i++ ){ - wrapper = (IDerivableContainerSymbol.IParentSymbol) parents.get(i); - temp = wrapper.getParent(); - boolean isVisible = ( wrapper.getAccess() == ASTAccessVisibility.PUBLIC ); - if ( temp instanceof IDerivableContainerSymbol ){ - parent = (IDerivableContainerSymbol)temp; - } else { - continue; - } - if( parent == base ){ - if( throwIfNotVisible && !isVisible ) - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadVisibility ); - return 1; - } - int n = hasBaseClass( parent, base, throwIfNotVisible ); - if( n > 0 ) - return n + 1; - } - } - - return -1; - } - - static protected void getAssociatedScopes( ISymbol symbol, ObjectSet associated ){ - if( symbol == null ){ - return; - } - //if T is a class type, its associated classes are the class itself, - //and its direct and indirect base classes. its associated Namespaces are the - //namespaces in which its associated classes are defined - //if( symbol.getType() == TypeInfo.t_class ){ - if( symbol instanceof IDerivableContainerSymbol ){ - associated.put( symbol ); - associated.put( symbol.getContainingSymbol() ); - getBaseClassesAndContainingNamespaces( (IDerivableContainerSymbol) symbol, associated ); - } - //if T is a union or enumeration type, its associated namespace is the namespace in - //which it is defined. if it is a class member, its associated class is the member's - //class - else if( symbol.getType() == ITypeInfo.t_union || symbol.getType() == ITypeInfo.t_enumeration ){ - associated.put( symbol.getContainingSymbol() ); - } - } - - static private void getBaseClassesAndContainingNamespaces( IDerivableContainerSymbol obj, ObjectSet classes ){ - if( obj.getParents() != null ){ - if( classes == null ){ - return; - } - - List parents = obj.getParents(); - int size = parents.size(); - IDerivableContainerSymbol.IParentSymbol wrapper; - ISymbol base; - - for( int i = 0; i < size; i++ ){ - wrapper = (IDerivableContainerSymbol.IParentSymbol) parents.get(i); - base = wrapper.getParent(); - //TODO: what about IDeferredTemplateInstance parents? - if( base instanceof IDerivableContainerSymbol ){ - classes.put( base ); - if( base.getContainingSymbol().getType() == ITypeInfo.t_namespace ){ - classes.put( base.getContainingSymbol()); - } - - getBaseClassesAndContainingNamespaces( (IDerivableContainerSymbol) base, classes ); - } - - } - } - } - - static protected boolean okToAddUsingDeclaration( ISymbol obj, IContainerSymbol context ){ - boolean okToAdd = false; - - //7.3.3-5 A using-declaration shall not name a template-id - if( obj.isTemplateInstance() && obj.getInstantiatedSymbol().getContainingSymbol().isType( ITypeInfo.t_template ) ){ - okToAdd = false; - } - //7.3.3-4 - else if( context.isType( ITypeInfo.t_class, ITypeInfo.t_struct ) ){ - IContainerSymbol container = obj.getContainingSymbol(); - - try{ - //a member of a base class - if( obj.getContainingSymbol().getType() == context.getType() ){ - okToAdd = ( hasBaseClass( context, container ) > 0 ); - } - else if ( obj.getContainingSymbol().getType() == ITypeInfo.t_union ) { - // TODO : must be an _anonymous_ union - container = container.getContainingSymbol(); - okToAdd = ( container instanceof IDerivableContainerSymbol ) - ? ( hasBaseClass( context, container ) > 0 ) - : false; - } - //an enumerator for an enumeration - else if ( obj.getType() == ITypeInfo.t_enumerator ){ - container = container.getContainingSymbol(); - okToAdd = ( container instanceof IDerivableContainerSymbol ) - ? ( hasBaseClass( context, container ) > 0 ) - : false; - } - } catch ( ParserSymbolTableException e ) { - //not going to happen since we didn't ask for the visibility exception from hasBaseClass - } - } else { - okToAdd = true; - } - - return okToAdd; - } - - static private Cost lvalue_to_rvalue( TypeInfoProvider provider, ITypeInfo source, ITypeInfo target ){ - - //lvalues will have type t_type - if( source.isType( ITypeInfo.t_type ) ){ - source = getFlatTypeInfo( source, null ); - } - - if( target.isType( ITypeInfo.t_type ) ){ - target = getFlatTypeInfo( target, null ); - } - - Cost cost = new Cost( provider, source, target ); - - //if either source or target is null here, then there was a problem - //with the parameters and we can't match them. - if( cost.getSource() == null || cost.getTarget() == null ){ - return cost; - } - - ITypeInfo.PtrOp op = null; - - if( cost.getSource().hasPtrOperators() ){ - List sourcePtrs = cost.getSource().getPtrOperators(); - ITypeInfo.PtrOp ptr = (ITypeInfo.PtrOp)sourcePtrs.get( 0 ); - if( ptr.getType() == ITypeInfo.PtrOp.t_reference ){ - sourcePtrs.remove( 0 ); - } - int size = sourcePtrs.size(); - for( int i = 0; i < size; i++ ){ - op = (ITypeInfo.PtrOp) sourcePtrs.get( 0 ); - if( op.getType() == ITypeInfo.PtrOp.t_array ){ - op.setType( ITypeInfo.PtrOp.t_pointer ); - } - } - } - - if( cost.getTarget().hasPtrOperators() ){ - List targetPtrs = cost.getTarget().getPtrOperators(); - //ListIterator iterator = targetPtrs.listIterator(); - ITypeInfo.PtrOp ptr = (ITypeInfo.PtrOp)targetPtrs.get(0); - - if( ptr.getType() == ITypeInfo.PtrOp.t_reference ){ - targetPtrs.remove(0); - cost.targetHadReference = true; - } - int size = targetPtrs.size(); - for( int i = 0; i < size; i++ ){ - op = (ITypeInfo.PtrOp) targetPtrs.get(0); - if( op.getType() == ITypeInfo.PtrOp.t_array ){ - op.setType( ITypeInfo.PtrOp.t_pointer ); - } - } - } - - return cost; - } - - /** - * qualificationConversion - * @param cost - * - * see spec section 4.4 regarding qualification conversions - */ - static private void qualificationConversion( Cost cost ){ - List sourcePtrs = cost.getSource().getPtrOperators(); - List targetPtrs = cost.getTarget().getPtrOperators(); - int size = sourcePtrs.size(); - int size2 = targetPtrs.size(); - - ITypeInfo.PtrOp op1 = null, op2 = null; - boolean canConvert = true; - - if( size != size2 ){ - canConvert = false; - } else if( size > 0 ){ - op1 = (ITypeInfo.PtrOp) sourcePtrs.get(0); - op2 = (ITypeInfo.PtrOp) targetPtrs.get(0); - - boolean constInEveryCV2k = true; - - for( int j= 1; j < size; j++ ){ - op1 = (ITypeInfo.PtrOp) sourcePtrs.get(j); - op2 = (ITypeInfo.PtrOp) targetPtrs.get(j); - - //pointer types must be similar - if( op1.getType() != op2.getType() ){ - canConvert = false; - break; - } - //if const is in cv1,j then const is in cv2,j. Similary for volatile - if( ( op1.isConst() && !op2.isConst() ) || - ( op1.isVolatile() && !op2.isVolatile() ) ) - { - canConvert = false; - break; - } - - //if cv1,j and cv2,j are different then const is in every cv2,k for 0 0 ) ? Cost.PROMOTION_RANK : Cost.NO_MATCH_RANK; - } - - /** - * - * @param source - * @param target - * @return int - * - */ - static private void conversion( Cost cost ){ - ITypeInfo src = cost.getSource(); - ITypeInfo trg = cost.getTarget(); - - int temp = -1; - - cost.conversion = 0; - cost.detail = 0; - - if( !src.hasSamePtrs( trg ) ){ - return; - } - if( src.hasPtrOperators() && src.getPtrOperators().size() == 1 ){ - ITypeInfo.PtrOp ptr = (ITypeInfo.PtrOp)src.getPtrOperators().get(0); - ISymbol srcDecl = src.isType( ITypeInfo.t_type ) ? src.getTypeSymbol() : null; - ISymbol trgDecl = trg.isType( ITypeInfo.t_type ) ? trg.getTypeSymbol() : null; - if( ptr.getType() == ITypeInfo.PtrOp.t_pointer ){ - if( srcDecl == null || (trgDecl == null && !trg.isType( ITypeInfo.t_void )) ){ - return; - } - - //4.10-2 an rvalue of type "pointer to cv T", where T is an object type can be - //converted to an rvalue of type "pointer to cv void" - if( trg.isType( ITypeInfo.t_void ) ){ - cost.rank = Cost.CONVERSION_RANK; - cost.conversion = 1; - cost.detail = 2; - return; - } - - cost.detail = 1; - - //4.10-3 An rvalue of type "pointer to cv D", where D is a class type can be converted - // to an rvalue of type "pointer to cv B", where B is a base class of D. - if( (srcDecl instanceof IDerivableContainerSymbol) && trgDecl.isType( srcDecl.getType() ) ){ - try { - temp = hasBaseClass( srcDecl, trgDecl ); - } catch (ParserSymbolTableException e) { - //not going to happen since we didn't ask for the visibility exception - } - cost.rank = ( temp > -1 ) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK; - cost.conversion = ( temp > -1 ) ? temp : 0; - cost.detail = 1; - return; - } - } else if( ptr.getType() == ITypeInfo.PtrOp.t_memberPointer ){ - //4.11-2 An rvalue of type "pointer to member of B of type cv T", where B is a class type, - //can be converted to an rvalue of type "pointer to member of D of type cv T" where D is a - //derived class of B - if( srcDecl == null || trgDecl == null ){ - return; - } - - ITypeInfo.PtrOp srcPtr = trg.hasPtrOperators() ? (ITypeInfo.PtrOp)trg.getPtrOperators().get(0) : null; - if( trgDecl.isType( srcDecl.getType() ) && srcPtr != null && srcPtr.getType() == ITypeInfo.PtrOp.t_memberPointer ){ - try { - temp = hasBaseClass( ptr.getMemberOf(), srcPtr.getMemberOf() ); - } catch (ParserSymbolTableException e) { - //not going to happen since we didn't ask for the visibility exception - } - cost.rank = ( temp > -1 ) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK; - cost.detail = 1; - cost.conversion = ( temp > -1 ) ? temp : 0; - return; - } - } - } else if( !src.hasPtrOperators() ) { - //4.7 An rvalue of an integer type can be converted to an rvalue of another integer type. - //An rvalue of an enumeration type can be converted to an rvalue of an integer type. - if( src.isType( ITypeInfo.t__Bool, ITypeInfo.t_int ) || src.isType( ITypeInfo.t_float, ITypeInfo.t_double ) || - src.isType( ITypeInfo.t_enumeration ) || ( src.isType( ITypeInfo.t_type ) && src.getTypeSymbol() != null - && src.getTypeSymbol().isType( ITypeInfo.t_enumeration ) ) ) - { - if( trg.isType( ITypeInfo.t__Bool, ITypeInfo.t_int ) || - trg.isType( ITypeInfo.t_float, ITypeInfo.t_double ) ) - { - cost.rank = Cost.CONVERSION_RANK; - cost.conversion = 1; - } - } - } - } - - static private void derivedToBaseConversion( Cost cost ) throws ParserSymbolTableException{ - ITypeInfo src = cost.getSource(); - ITypeInfo trg = cost.getTarget(); - - ISymbol srcDecl = src.isType( ITypeInfo.t_type ) ? src.getTypeSymbol() : null; - ISymbol trgDecl = trg.isType( ITypeInfo.t_type ) ? trg.getTypeSymbol() : null; - - if( !src.hasSamePtrs( trg ) || srcDecl == null || trgDecl == null || !cost.targetHadReference ){ - return; - } - - int temp = hasBaseClass( srcDecl, trgDecl, true ); - - if( temp > -1 ){ - cost.rank = Cost.DERIVED_TO_BASE_CONVERSION; - cost.conversion = temp; - } - } - - protected Cost checkStandardConversionSequence( ITypeInfo source, ITypeInfo target ) throws ParserSymbolTableException{ - Cost cost = lvalue_to_rvalue( getTypeInfoProvider(), source, target ); - - if( cost.getSource() == null || cost.getTarget() == null ){ - return cost; - } - - if( cost.getSource().equals( cost.getTarget() ) ){ - cost.rank = Cost.IDENTITY_RANK; - return cost; - } - - qualificationConversion( cost ); - - //if we can't convert the qualifications, then we can't do anything - if( cost.qualification == 0 ){ - return cost; - } - - //was the qualification conversion enough? - if( cost.getSource().isType( ITypeInfo.t_type ) && cost.getTarget().isType( ITypeInfo.t_type ) ){ - if( cost.getTarget().hasSamePtrs( cost.getSource() ) ){ - ISymbol srcSymbol = cost.getSource().getTypeSymbol(); - ISymbol trgSymbol = cost.getTarget().getTypeSymbol(); - if( srcSymbol != null && trgSymbol != null ){ - if( srcSymbol.equals( trgSymbol ) ) - { - return cost; - } - } - } - } else if( cost.getSource().getType() == cost.getTarget().getType() && - (cost.getSource().getTypeBits() & ~ITypeInfo.isConst & ~ITypeInfo.isVolatile) == (cost.getTarget().getTypeBits() & ~ITypeInfo.isConst & ~ITypeInfo.isVolatile) ) - { - return cost; - } - promotion( cost ); - if( cost.promotion > 0 || cost.rank > -1 ){ - return cost; - } - - conversion( cost ); - - if( cost.rank > -1 ) - return cost; - - try{ - derivedToBaseConversion( cost ); - } catch ( ParserSymbolTableException e ){ - cost.release( getTypeInfoProvider() ); - throw e; - } - - return cost; - } - - private Cost checkUserDefinedConversionSequence( ITypeInfo source, ITypeInfo target ) throws ParserSymbolTableException { - Cost cost = null; - Cost constructorCost = null; - Cost conversionCost = null; - - ISymbol targetDecl = null; - ISymbol sourceDecl = null; - IParameterizedSymbol constructor = null; - IParameterizedSymbol conversion = null; - - //constructors - if( target.getType() == ITypeInfo.t_type ){ - targetDecl = target.getTypeSymbol(); - if( targetDecl == null ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); - } - if( targetDecl.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){ - LookupData data = new LookupData( EMPTY_NAME_ARRAY ){ - public List getParameters() { return parameters; } - public TypeFilter getFilter() { return CONSTRUCTOR_FILTER; } - private List parameters = new ArrayList( 1 ); - }; - data.forUserDefinedConversion = true; - data.getParameters().add( source ); - - if( targetDecl instanceof IDeferredTemplateInstance ){ - targetDecl = ((IDeferredTemplateInstance)targetDecl).getTemplate().getTemplatedSymbol(); - } - IDerivableContainerSymbol container = (IDerivableContainerSymbol) targetDecl; - - if( !container.getConstructors().isEmpty() ){ - ArrayList constructors = new ArrayList( container.getConstructors() ); - constructor = resolveFunction( data, constructors ); - } - if( constructor != null && constructor.getTypeInfo().checkBit( ITypeInfo.isExplicit ) ){ - constructor = null; - } - - } - } - - TypeInfoProvider provider = getTypeInfoProvider(); - //conversion operators - if( source.getType() == ITypeInfo.t_type ){ - source = getFlatTypeInfo( source, provider ); - sourceDecl = ( source != null ) ? source.getTypeSymbol() : null; - provider.returnTypeInfo( source ); - - if( sourceDecl != null && (sourceDecl instanceof IContainerSymbol) ){ - char[] name = target.toCharArray(); - - if( !CharArrayUtils.equals( name, EMPTY_NAME_ARRAY) ){ - - LookupData data = new LookupData( CharArrayUtils.concat( OPERATOR_, name )){ //$NON-NLS-1$ - public List getParameters() { return Collections.EMPTY_LIST; } - public TypeFilter getFilter() { return FUNCTION_FILTER; } - }; - data.forUserDefinedConversion = true; - data.foundItems = lookupInContained( data, (IContainerSymbol) sourceDecl ); - conversion = (data.foundItems != null ) ? (IParameterizedSymbol)resolveAmbiguities( data ) : null; - } - } - } - - try { - if( constructor != null ){ - ITypeInfo info = provider.getTypeInfo( ITypeInfo.t_type ); - info.setTypeSymbol( constructor.getContainingSymbol() ); - constructorCost = checkStandardConversionSequence( info, target ); - provider.returnTypeInfo( info ); - } - if( conversion != null ){ - ITypeInfo info = provider.getTypeInfo( target.getType() ); - info.setTypeSymbol( target.getTypeSymbol() ); - conversionCost = checkStandardConversionSequence( info, target ); - provider.returnTypeInfo( info ); - } - - //if both are valid, then the conversion is ambiguous - if( constructorCost != null && constructorCost.rank != Cost.NO_MATCH_RANK && - conversionCost != null && conversionCost.rank != Cost.NO_MATCH_RANK ) - { - cost = constructorCost; - cost.userDefined = Cost.AMBIGUOUS_USERDEFINED_CONVERSION; - cost.rank = Cost.USERDEFINED_CONVERSION_RANK; - } else { - if( constructorCost != null && constructorCost.rank != Cost.NO_MATCH_RANK ){ - cost = constructorCost; - cost.userDefined = constructor.hashCode(); - cost.rank = Cost.USERDEFINED_CONVERSION_RANK; - } else if( conversionCost != null && conversionCost.rank != Cost.NO_MATCH_RANK ){ - cost = conversionCost; - cost.userDefined = conversion.hashCode(); - cost.rank = Cost.USERDEFINED_CONVERSION_RANK; - } - } - } finally { - if( constructorCost != null && constructorCost != cost ) - constructorCost.release( provider ); - if( conversionCost != null && conversionCost != cost ) - conversionCost.release( provider ); - } - return cost; - } - - /** - * Determine the type of a conditional operator based on the second and third operands - * @param secondOp - * @param thirdOp - * @return - * Spec 5.16 - * Determine if the second operand can be converted to match the third operand, and vice versa. - * - If both can be converted, or one can be converted but the conversion is ambiguous, the program - * is illformed (throw ParserSymbolTableException) - * - If neither can be converted, further checking must be done (return null) - * - If exactly one conversion is possible, that conversion is applied ( return the other TypeInfo ) - */ - public ITypeInfo getConditionalOperand( ITypeInfo secondOp, ITypeInfo thirdOp ) throws ParserSymbolTableException{ - Cost thirdCost = null, secondCost = null; - ITypeInfo temp = null; - TypeInfoProvider provider = getTypeInfoProvider(); - try{ - //can secondOp convert to thirdOp ? - temp = getFlatTypeInfo( thirdOp, provider ); - secondCost = checkStandardConversionSequence( secondOp, temp ); - - if( secondCost.rank == Cost.NO_MATCH_RANK ){ - secondCost.release( provider ); - secondCost = checkUserDefinedConversionSequence( secondOp, temp ); - } - getTypeInfoProvider().returnTypeInfo( temp ); - temp = getFlatTypeInfo( secondOp, provider ); - - thirdCost = checkStandardConversionSequence( thirdOp, temp ); - if( thirdCost.rank == Cost.NO_MATCH_RANK ){ - thirdCost.release( provider ); - thirdCost = checkUserDefinedConversionSequence( thirdOp, temp ); - } - } finally { - if( thirdCost != null ) thirdCost.release( provider ); - if( secondCost != null ) secondCost.release( provider ); - if( temp != null ) provider.returnTypeInfo( temp ); - } - - boolean canConvertSecond = ( secondCost != null && secondCost.rank != Cost.NO_MATCH_RANK ); - boolean canConvertThird = ( thirdCost != null && thirdCost.rank != Cost.NO_MATCH_RANK ); - - if( !canConvertSecond && !canConvertThird ){ - //neither can be converted - return null; - } else if ( canConvertSecond && canConvertThird ){ - //both can be converted -> illformed - throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); - } else { - if( canConvertSecond ){ - if( secondCost.userDefined == Cost.AMBIGUOUS_USERDEFINED_CONVERSION ){ - //conversion is ambiguous -> ill-formed - throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); - } - return thirdOp; - } - if( thirdCost.userDefined == Cost.AMBIGUOUS_USERDEFINED_CONVERSION ) - //conversion is ambiguous -> ill-formed - throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); - - return secondOp; - } - } - - /** - * - * @param infoProvider - if using the pool, an instance of the symbol table must be provided - * @param decl - * @return TypeInfo - * The top level TypeInfo represents modifications to the object and the - * remaining TypeInfo's represent the object. - */ - static protected ITypeInfo getFlatTypeInfo( ITypeInfo topInfo, TypeInfoProvider infoProvider ){ - ITypeInfo returnInfo = null; - ITypeInfo info = null; - - if( topInfo.getType() == ITypeInfo.t_type && topInfo.getTypeSymbol() != null ){ - if( infoProvider != null ) returnInfo = infoProvider.getTypeInfo( ITypeInfo.t_type ); - else returnInfo = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type ); - - returnInfo.setTypeBits( topInfo.getTypeBits() ); - ISymbol typeSymbol = topInfo.getTypeSymbol(); - - info = typeSymbol.getTypeInfo(); - int j = 0; - while( (info.getTypeSymbol() != null && ( info.isType( ITypeInfo.t_type ) || info.isType( ITypeInfo.t_enumerator ) ) ) || - (typeSymbol != null && typeSymbol.isForwardDeclaration() && typeSymbol.getForwardSymbol() != null ) ){ - - typeSymbol = (info.isType( ITypeInfo.t_type) || info.isType(ITypeInfo.t_enumerator)) - ? info.getTypeSymbol() - : typeSymbol.getForwardSymbol(); - - returnInfo.addPtrOperator( info.getPtrOperators() ); - returnInfo.setTypeBits( ( returnInfo.getTypeBits() | info.getTypeBits() ) & ~ITypeInfo.isTypedef & ~ITypeInfo.isForward ); - info = typeSymbol.getTypeInfo(); - if( ++j > TYPE_LOOP_THRESHOLD ){ - if( infoProvider != null ) - infoProvider.returnTypeInfo( returnInfo ); - throw new ParserSymbolTableError(); - } - } - - if( info.isType( ITypeInfo.t_class, ITypeInfo.t_enumeration ) || info.isType( ITypeInfo.t_function ) || - ( info.isType( ITypeInfo.t_undef ) && typeSymbol instanceof UndefinedTemplateSymbol ) ) { - returnInfo.setType( ITypeInfo.t_type ); - returnInfo.setTypeSymbol( typeSymbol ); - } else { - returnInfo.setTypeBits( ( returnInfo.getTypeBits() | info.getTypeBits() ) & ~ITypeInfo.isTypedef & ~ITypeInfo.isForward ); - returnInfo.setType( info.getType() ); - returnInfo.setTypeSymbol( null ); - returnInfo.addPtrOperator( info.getPtrOperators() ); - } - if( returnInfo.isType( ITypeInfo.t_templateParameter ) ){ - returnInfo.setTypeSymbol( typeSymbol ); - } - - if( topInfo.hasPtrOperators() ){ - returnInfo.addPtrOperator( topInfo.getPtrOperators() ); - } - } else { - if( infoProvider != null ){ - returnInfo = infoProvider.getTypeInfo( topInfo.getType() ); - returnInfo.copy( topInfo ); - } else - returnInfo = TypeInfoProvider.newTypeInfo( topInfo ); - } - - return returnInfo; - } - - private IContainerSymbol _compilationUnit; - private ParserLanguage _language; - private TypeInfoProvider _typeInfoProvider; - private ParserMode _mode; - - public void setLanguage( ParserLanguage language ){ - _language = language; - } - - public ParserLanguage getLanguage(){ - return _language; - } - - public ParserMode getParserMode(){ - return _mode; - } - - public TypeInfoProvider getTypeInfoProvider(){ - return _typeInfoProvider; - } - -// protected void pushCommand( Command command ){ -// undoList.addFirst( command ); -// } - -// public Mark setMark(){ -// Mark mark = new Mark(); -// undoList.addFirst( mark ); -// markSet.add( mark ); -// return mark; -// } - -// public boolean rollBack( Mark toMark ){ -// if( markSet.contains( toMark ) ){ -// markSet.remove( toMark ); -// Command command = ( Command )undoList.removeFirst(); -// while( command != toMark ){ -// command.undoIt(); -// command = ( Command ) undoList.removeFirst(); -// } -// -// return true; -// } -// -// return false; -// } - -// public boolean commit( Mark toMark ){ -// if( markSet.contains( toMark ) ){ -// markSet.remove( toMark ); -// Command command = ( Command )undoList.removeLast(); -// while( command != toMark ){ -// command = (Command) undoList.removeLast(); -// } -// return true; -// } -// -// return false; -// } - -// static abstract protected class Command{ -// abstract public void undoIt(); -// } -// -// static public class Mark extends Command{ -// public void undoIt(){ } -// } - - - - static protected class LookupData - { - protected static final TypeFilter ANY_FILTER = new TypeFilter( ITypeInfo.t_any ); - protected static final TypeFilter CONSTRUCTOR_FILTER = new TypeFilter( ITypeInfo.t_constructor ); - protected static final TypeFilter FUNCTION_FILTER = new TypeFilter( ITypeInfo.t_function ); - - public char[] name; - public ObjectMap usingDirectives; - public ObjectSet visited = ObjectSet.EMPTY_SET; //used to ensure we don't visit things more than once - public ObjectSet inheritanceChain; //used to detect circular inheritance - public ISymbol templateMember; //to assit with template member defs - - public boolean qualified = false; - public boolean ignoreUsingDirectives = false; - public boolean usingDirectivesOnly = false; - public boolean forUserDefinedConversion = false; - public boolean exactFunctionsOnly = false; - public boolean returnInvisibleSymbols = false; - - public CharArrayObjectMap foundItems = null; - - public LookupData( char[] n ){ - name = n; - } - - //the following function are optionally overloaded by anonymous classes deriving from - //this LookupData - public boolean isPrefixLookup(){ return false;} //prefix lookup - public CharArraySet getAmbiguities() { return null; } - public void addAmbiguity(char[] n ) { /*nothing*/ } - public List getParameters() { return null; } //parameter info for resolving functions - public ObjectSet getAssociated() { return null; } //associated namespaces for argument dependant lookup - public ISymbol getStopAt() { return null; } //stop looking along the stack once we hit this declaration - public List getTemplateParameters() { return null; } //template parameters - public TypeFilter getFilter() { return ANY_FILTER; } - } - - - static protected class Cost - { - - public Cost( TypeInfoProvider provider, ITypeInfo s, ITypeInfo t ){ - if( s != null ){ - source = provider.getTypeInfo( s.getType() ); - source.copy( s ); - } - if( t != null ){ - target = provider.getTypeInfo( t.getType() ); - target.copy( t ); - } - } - - private ITypeInfo source; - private ITypeInfo target; - - public boolean targetHadReference = false; - - public int lvalue; - public int promotion; - public int conversion; - public int qualification; - public int userDefined; - public int rank = -1; - public int detail; - - //Some constants to help clarify things - public static final int AMBIGUOUS_USERDEFINED_CONVERSION = 1; - - public static final int NO_MATCH_RANK = -1; - public static final int IDENTITY_RANK = 0; - public static final int LVALUE_OR_QUALIFICATION_RANK = 0; - public static final int PROMOTION_RANK = 1; - public static final int CONVERSION_RANK = 2; - public static final int DERIVED_TO_BASE_CONVERSION = 3; - public static final int USERDEFINED_CONVERSION_RANK = 4; - public static final int ELLIPSIS_CONVERSION = 5; - - public void release( TypeInfoProvider provider ){ - provider.returnTypeInfo( getSource() ); - provider.returnTypeInfo( getTarget() ); - } - - public int compare( Cost cost ){ - int result = 0; - - if( rank != cost.rank ){ - return cost.rank - rank; - } - - if( userDefined != 0 || cost.userDefined != 0 ){ - if( userDefined == 0 || cost.userDefined == 0 ){ - return cost.userDefined - userDefined; - } - if( (userDefined == AMBIGUOUS_USERDEFINED_CONVERSION || cost.userDefined == AMBIGUOUS_USERDEFINED_CONVERSION) || - (userDefined != cost.userDefined ) ) - return 0; - - // else they are the same constructor/conversion operator and are ranked - //on the standard conversion sequence - - } - - if( promotion > 0 || cost.promotion > 0 ){ - result = cost.promotion - promotion; - } - if( conversion > 0 || cost.conversion > 0 ){ - if( detail == cost.detail ){ - result = cost.conversion - conversion; - } else { - result = cost.detail - detail; - } - } - - if( result == 0 ){ - if( cost.qualification != qualification ){ - return cost.qualification - qualification; - } else if( (cost.qualification == qualification) && qualification == 0 ){ - return 0; - } else { - int size = cost.getTarget().hasPtrOperators() ? cost.getTarget().getPtrOperators().size() : 0; - int size2 = getTarget().hasPtrOperators() ? getTarget().getPtrOperators().size() : 0; - - ListIterator iter1 = cost.getTarget().getPtrOperators().listIterator( size ); - ListIterator iter2 = getTarget().getPtrOperators().listIterator( size2 ); - - ITypeInfo.PtrOp op1 = null, op2 = null; - - int subOrSuper = 0; - for( int i = ( size < size2 ) ? size : size2; i > 0; i-- ){ - op1 = (ITypeInfo.PtrOp)iter1.previous(); - op2 = (ITypeInfo.PtrOp)iter2.previous(); - - if( subOrSuper == 0) - subOrSuper = op1.compareCVTo( op2 ); - else if( ( subOrSuper > 0 && ( op1.compareCVTo( op2 ) < 0 )) || - ( subOrSuper < 0 && ( op1.compareCVTo( op2 ) > 0 )) ) - { - result = -1; - break; - } - } - if( result == -1 ){ - result = 0; - } else { - if( size == size2 ){ - result = subOrSuper; - } else { - result = size - size2; - } - } - } - } - - return result; - } - - /** - * @return Returns the source. - */ - public ITypeInfo getSource() { - return source; - } - - /** - * @return Returns the target. - */ - public ITypeInfo getTarget() { - return target; - } - } - - /** - * The visibility of the symbol is modified by the visibility of the base classes - * @param symbol - * @param qualifyingSymbol - * @return - */ - public static ASTAccessVisibility getVisibility(ISymbol symbol, IContainerSymbol qualifyingSymbol){ - - IContainerSymbol container = symbol.getContainingSymbol(); - if( qualifyingSymbol == null || container.equals( qualifyingSymbol ) ){ - ISymbolASTExtension extension = symbol.getASTExtension(); - IASTNode node = extension != null ? extension.getPrimaryDeclaration() : null; - if( node != null && node instanceof IASTMember ){ - return ((IASTMember)node).getVisiblity(); - } - throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError ); - } - - if( ! (qualifyingSymbol instanceof IDerivableContainerSymbol) ){ - return ASTAccessVisibility.PUBLIC; - } - - List parents = ((IDerivableContainerSymbol) qualifyingSymbol).getParents(); - int numParents = parents.size(); - IParentSymbol parent = null; - ASTAccessVisibility symbolAccess = null; - ASTAccessVisibility parentAccess = null; - - for( int i = 0; i < numParents; i++ ){ - parent = (IParentSymbol) parents.get(i); - - if( container == parent.getParent() ){ - parentAccess = parent.getAccess(); - symbolAccess = ((IASTMember)symbol.getASTExtension().getPrimaryDeclaration()).getVisiblity(); - - return ( parentAccess.isGreaterThan( symbolAccess ) )? parentAccess : symbolAccess; - } - } - - //if static or an enumerator, the symbol could be visible through more than one path through the heirarchy, - //so we need to check all paths - boolean checkAllPaths = ( symbol.isType( ITypeInfo.t_enumerator ) || symbol.getTypeInfo().checkBit( ITypeInfo.isStatic ) ); - ASTAccessVisibility resultingAccess = null; - for( int i = 0; i < numParents; i++ ){ - parent = (IParentSymbol) parents.get(i); - parentAccess = parent.getAccess(); - - ISymbol tmp = parent.getParent(); - if( tmp instanceof IDeferredTemplateInstance ) - tmp = ((IDeferredTemplateInstance)tmp).getTemplate().getTemplatedSymbol(); - else if( tmp instanceof ITemplateSymbol ){ - tmp = ((ITemplateSymbol)tmp).getTemplatedSymbol(); - } - - if( !( tmp instanceof IContainerSymbol ) ) - return null; - - symbolAccess = getVisibility( symbol, (IContainerSymbol) tmp ); - - if( symbolAccess != null ){ - symbolAccess = ( parentAccess.isGreaterThan( symbolAccess ) ) ? parentAccess : symbolAccess; - if( checkAllPaths ){ - if( resultingAccess != null ) - resultingAccess = resultingAccess.isGreaterThan( symbolAccess ) ? symbolAccess : resultingAccess; - else - resultingAccess = symbolAccess; - } else { - return symbolAccess; - } - } - } - return resultingAccess; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableError.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableError.java deleted file mode 100644 index 36548662c27..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableError.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -/** - * @author aniefer - */ -public class ParserSymbolTableError extends Error { - /** - * Constructor for ParserSymbolTableError. - */ - public ParserSymbolTableError() { - super(); - } - - /** - * Constructor for ParserSymbolTableError. - * @param int r: reason - */ - public ParserSymbolTableError( int r ) { - reason = r; - } - - public static final int r_InternalError = -1; - public static final int r_OperationNotSupported = 0; - public int reason = -1; - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableException.java deleted file mode 100644 index 5a430e3a229..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTableException.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Rational Software - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.pst; - -import org.eclipse.cdt.core.parser.IProblem; - -/** - * @author aniefer - */ -public class ParserSymbolTableException extends Exception { - - /** - * Constructor for ParserSymbolTableException. - */ - public ParserSymbolTableException() { - super(); - } - - /** - * Constructor for ParserSymbolTableException. - * @param int r: reason - */ - public ParserSymbolTableException( int r ) { - reason = r; - } - - public static final int r_InternalError = -1; - public static final int r_Ambiguous = 0; - public static final int r_BadTypeInfo = 1; - public static final int r_CircularInheritance = 2; - public static final int r_InvalidOverload = 3; - public static final int r_BadTemplate = 4; - public static final int r_InvalidUsing = 5; - public static final int r_BadVisibility = 6; - public static final int r_UnableToResolveFunction = 7; - public static final int r_BadTemplateArgument = 8; - public static final int r_BadTemplateParameter = 9; - public static final int r_RedeclaredTemplateParam = 10; - public static final int r_RecursiveTemplate = 11; - public int reason = -1; - - /** - * @return - */ - public int createProblemID() { - switch( reason ) - { - case r_Ambiguous: - return IProblem.SEMANTIC_AMBIGUOUS_LOOKUP; - case r_BadTypeInfo: - return IProblem.SEMANTIC_INVALID_TYPE; - case r_CircularInheritance: - return IProblem.SEMANTIC_CIRCULAR_INHERITANCE; - case r_InvalidOverload: - return IProblem.SEMANTIC_INVALID_OVERLOAD; - case r_BadTemplate: - return IProblem.SEMANTIC_INVALID_TEMPLATE; - case r_InvalidUsing: - return IProblem.SEMANTIC_INVALID_USING; - case r_BadVisibility: - return IProblem.SEMANTIC_BAD_VISIBILITY; - case r_UnableToResolveFunction: - return IProblem.SEMANTIC_UNABLE_TO_RESOLVE_FUNCTION; - case r_BadTemplateArgument: - return IProblem.SEMANTIC_INVALID_TEMPLATE_ARGUMENT; - case r_BadTemplateParameter: - return IProblem.SEMANTIC_INVALID_TEMPLATE_PARAMETER; - case r_RedeclaredTemplateParam: - return IProblem.SEMANTIC_REDECLARED_TEMPLATE_PARAMETER; - case r_RecursiveTemplate: - return IProblem.SEMANTIC_RECURSIVE_TEMPLATE_INSTANTIATION; - default: -// assert false : this; - return -1; - } - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/SpecializedSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/SpecializedSymbol.java deleted file mode 100644 index 4b0bd5768ef..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/SpecializedSymbol.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on Nov 6, 2003 - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.cdt.core.parser.util.ObjectMap; - -/** - * @author aniefe - */ - -public class SpecializedSymbol extends TemplateSymbol implements ISpecializedSymbol { - protected SpecializedSymbol( ParserSymbolTable table, char[] name ){ - super( table, name ); - } - - public Object clone(){ - SpecializedSymbol copy = (SpecializedSymbol)super.clone(); - - copy._argumentList = ( _argumentList != Collections.EMPTY_LIST ) ? (List)((ArrayList) _argumentList).clone() : _argumentList; - - return copy; - } - - - public ITemplateSymbol getPrimaryTemplate(){ - return _primaryTemplate; - } - - public void setPrimaryTemplate( ITemplateSymbol templateSymbol ){ - _primaryTemplate = templateSymbol; - } - - public ISymbol instantiate( List arguments ) throws ParserSymbolTableException{ - List specArgs = getArgumentList(); - if( specArgs.size() != arguments.size() ){ - return null; - } - - List actualArgs = new ArrayList( specArgs.size() ); - ObjectMap argMap = new ObjectMap( specArgs.size() ); - - ISymbol templatedSymbol = getTemplatedSymbol(); - while( templatedSymbol.isTemplateInstance() ){ - templatedSymbol = templatedSymbol.getInstantiatedSymbol(); - } - - int numSpecArgs = specArgs.size(); - for( int i = 0; i < numSpecArgs; i++ ){ - ITypeInfo info = (ITypeInfo) specArgs.get(i); - ITypeInfo mappedInfo = (ITypeInfo) arguments.get(i); - - //If the argument is a template parameter, we can't instantiate yet, defer for later - if( mappedInfo.isType( ITypeInfo.t_type ) && mappedInfo.getTypeSymbol().isType( ITypeInfo.t_templateParameter ) ){ - return deferredInstance( arguments ); - } - - actualArgs.add( mappedInfo ); - if( info.isType( ITypeInfo.t_type ) && info.getTypeSymbol().isType( ITypeInfo.t_templateParameter )){ - ISymbol param = info.getTypeSymbol(); - - param = TemplateEngine.translateParameterForDefinition ( templatedSymbol, param, getDefinitionParameterMap() ); - - if( !argMap.containsKey( param ) ){ - argMap.put( param, mappedInfo ); - } - } - } - - //sanity check - if( getParameterList().size() != argMap.size() ) - return null; - - List params = getParameterList(); - int numParams = params.size(); - for( int i = 0; i < numParams; i++ ){ - if( !argMap.containsKey( params.get(i) ) ) - return null; - } - - IContainerSymbol instance = findInstantiation( actualArgs ); - if( instance != null ){ - return instance; - } - IContainerSymbol symbol = null; - - if( getContainedSymbols().size() == 1 ){ - symbol = (IContainerSymbol)getContainedSymbols().getAt( 0 ); - } - - instance = (IContainerSymbol) symbol.instantiate( this, argMap ); - addInstantiation( instance, actualArgs ); - try{ - processDeferredInstantiations(); - } catch( ParserSymbolTableException e ){ - if( e.reason == ParserSymbolTableException.r_RecursiveTemplate ){ - //clean up some. - removeInstantiation( instance ); - } - throw e; - } - return instance; - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#getArgumentList() - */ - public List getArgumentList(){ - return _argumentList; - } - - public void prepareArguments( int size ){ - if( _argumentList == Collections.EMPTY_LIST ) - _argumentList = new ArrayList( size ); - else - ((ArrayList)_argumentList).ensureCapacity( size ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addArgument(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void addArgument(ITypeInfo arg) { - if( _argumentList == Collections.EMPTY_LIST ) - _argumentList = new ArrayList(4); - - _argumentList.add( arg ); - - //arg.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template ); - -// Command command = new AddArgumentCommand( this, arg ); -// getSymbolTable().pushCommand( command ); - } - -// static private class AddArgumentCommand extends Command{ -// public AddArgumentCommand( ISpecializedSymbol container, TypeInfo arg ){ -// _decl = container; -// _arg = arg; -// } -// public void undoIt(){ -// _decl.getArgumentList().remove( _arg ); -// } -// -// private ISpecializedSymbol _decl; -// private TypeInfo _arg; -// } - - private List _argumentList = Collections.EMPTY_LIST; //template specialization arguments - private ITemplateSymbol _primaryTemplate; //our primary template -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/StandardSymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/StandardSymbolExtension.java deleted file mode 100644 index 81c388d4bf5..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/StandardSymbolExtension.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; - -/** - * @author jcamelon - * - */ -public class StandardSymbolExtension extends AbstractSymbolExtension -{ - - /** - * @author jcamelon - * - */ - private class SimpleIterator implements Iterator - { - boolean hasNext = true; - /** - * - */ - public SimpleIterator() - { - } - - /* (non-Javadoc) - * @see java.util.Iterator#hasNext() - */ - public boolean hasNext() - { - return hasNext; - } - - /* (non-Javadoc) - * @see java.util.Iterator#next() - */ - public Object next() - { - if( hasNext ) - { - hasNext = false; - return primaryDeclaration; - } - - throw new NoSuchElementException(); - } - - /* (non-Javadoc) - * @see java.util.Iterator#remove() - */ - public void remove() - { - throw new UnsupportedOperationException(); - } - } - /** - * @param symbol - * @param primaryDeclaration - */ - public StandardSymbolExtension(ISymbol symbol, ASTSymbol primaryDeclaration) - { - super(symbol, primaryDeclaration); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getAllDefinitions() - */ - public Iterator getAllDefinitions() - { - return this.new SimpleIterator(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#addDefinition(org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol) - */ - public void addDefinition(ASTSymbol definition) throws ExtensionException - { - throw new ExtensionException(); - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java deleted file mode 100644 index ed69b229635..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateEngine.java +++ /dev/null @@ -1,1372 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.core.parser.util.ObjectSet; -import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol.IParentSymbol; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.Cost; - -/** - * @author aniefer - */ -public final class TemplateEngine { - - static protected ITypeInfo instantiateTypeInfo( ITypeInfo info, ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{ - if( argMap == null ) - return info; - ISymbol typeSymbol = info.getTypeSymbol(); - if( info.isType( ITypeInfo.t_type ) ) { - if ( info.getTypeSymbol() == null ) { - return info; - } - if( typeSymbol instanceof IDeferredTemplateInstance ){ - IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) info.getTypeSymbol(); - ITypeInfo newInfo = TypeInfoProvider.newTypeInfo( info ); - //newInfo.setTypeSymbol( deferred.instantiate( template, argMap ) ); - template.registerDeferredInstatiation( newInfo, deferred, ITemplateSymbol.DeferredKind.TYPE_SYMBOL, argMap ); - newInfo.setTypeSymbol( deferred ); - return newInfo; - } else if ( typeSymbol instanceof UndefinedTemplateSymbol && - ( typeSymbol.isType( ITypeInfo.t_template ) || - typeSymbol.isType( ITypeInfo.t_undef ) ) ) { - ITemplateSymbol deferred = (ITemplateSymbol) info.getTypeSymbol(); - ITypeInfo newInfo = TypeInfoProvider.newTypeInfo( info ); - template.registerDeferredInstatiation( newInfo, deferred, ITemplateSymbol.DeferredKind.TYPE_SYMBOL, argMap ); - newInfo.setTypeSymbol( deferred ); - return newInfo; - } else if( typeSymbol.isType( ITypeInfo.t_templateParameter ) && - argMap.containsKey( info.getTypeSymbol() ) ) - { - ITypeInfo targetInfo = TypeInfoProvider.newTypeInfo( (ITypeInfo) argMap.get( info.getTypeSymbol() ) ); - if( info.hasPtrOperators() ){ - targetInfo.addPtrOperator( info.getPtrOperators() ); - } - - if( info.checkBit( ITypeInfo.isConst ) ) - targetInfo.setBit( true, ITypeInfo.isConst ); - - if( info.checkBit( ITypeInfo.isVolatile ) ) - targetInfo.setBit( true, ITypeInfo.isVolatile ); - - return targetInfo; - } else if( typeSymbol.isType( ITypeInfo.t_function ) ){ - ITypeInfo newInfo = TypeInfoProvider.newTypeInfo( info ); - newInfo.setTypeSymbol( info.getTypeSymbol().instantiate( template, argMap ) ); - return newInfo; - } - } - return info; - - } - - static protected void instantiateDeferredTypeInfo( ITypeInfo info, ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException { - info.setTypeSymbol( info.getTypeSymbol().instantiate( template, argMap ) ); - } - - /** - * @param info - * @param symbol - * @param map - */ - public static void discardDeferredTypeInfo(ITypeInfo info, ITemplateSymbol template, ObjectMap map) { - ISymbol instance = info.getTypeSymbol(); - if( !(instance instanceof IDeferredTemplateInstance ) ) - template.removeInstantiation( (IContainerSymbol) instance ); - info.setTypeSymbol( null ); - } - - static protected ITemplateSymbol matchTemplatePartialSpecialization( ITemplateSymbol template, List args ) throws ParserSymbolTableException{ - if( template == null ){ - return null; - } - - List specs = template.getSpecializations(); - int size = ( specs != null ) ? specs.size() : 0; - if( size == 0 ){ - return template; - } - - ISpecializedSymbol bestMatch = null; - boolean bestMatchIsBest = true; - ISpecializedSymbol spec = null; - List specArgs = null; - for( int i = 0; i < size; i++ ){ - spec = (ISpecializedSymbol) specs.get(i); - specArgs = spec.getArgumentList(); - if( specArgs == null || specArgs.size() != args.size() ){ - continue; - } - - int specArgsSize = specArgs.size(); - ObjectMap map = new ObjectMap(specArgsSize); - ITypeInfo info1 = null, info2 = null; - - boolean match = true; - for( int j = 0; j < specArgsSize; j++ ){ - info1 = (ITypeInfo) specArgs.get(j); - info2 = (ITypeInfo) args.get(j); - - ISymbol sym1 = template.getSymbolTable().newSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY ); - sym1.setTypeInfo( info1 ); - - if( !deduceTemplateArgument( map, sym1, info2 ) ){ - match = false; - break; - } - } - if( match ){ - int compare = orderSpecializations( bestMatch, spec ); - if( compare == 0 ){ - bestMatchIsBest = false; - } else if( compare < 0 ) { - bestMatch = spec; - bestMatchIsBest = true; - } - } - } - - //14.5.4.1 If none of the specializations is more specialized than all the other matchnig - //specializations, then the use of the class template is ambiguous and the program is ill-formed. - if( !bestMatchIsBest ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); - } - - return bestMatch; - } - - static protected boolean matchTemplateParameterAndArgument( ISymbol param, ITypeInfo arg ){ - if( !isValidArgument(param, arg) ){ - return false; - } - - if( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName ){ - return true; - } else if( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ){ - - ISymbol symbol = arg.getTypeSymbol(); - if( !arg.isType( ITypeInfo.t_type ) || symbol == null || !symbol.isType( ITypeInfo.t_template ) ){ - return false; - } - - IParameterizedSymbol p = (IParameterizedSymbol) param; - IParameterizedSymbol a = (IParameterizedSymbol) symbol; - - List pList = p.getParameterList(); - List aList = a.getParameterList(); - int size = pList.size(); - if( aList.size() != size){ - return false; - } - - for( int i = 0; i < size; i++){ - ISymbol pParam = (ISymbol) pList.get(i); - ISymbol aParam = (ISymbol) aList.get(i); - - if( pParam.getType() != aParam.getType() || - pParam.getTypeInfo().getTemplateParameterType() != aParam.getTypeInfo().getTemplateParameterType() ) - { - return false; - } - } - - return true; - } else { - Cost cost = null; - TypeInfoProvider provider = param.getSymbolTable().getTypeInfoProvider(); - try{ - ITypeInfo info = provider.getTypeInfo( param.getTypeInfo().getTemplateParameterType() ); - try { - info.copy( param.getTypeInfo() ); - info.setType( info.getTemplateParameterType() ); - cost = param.getSymbolTable().checkStandardConversionSequence( arg, info ); - provider.returnTypeInfo( info ); - } catch (ParserSymbolTableException e) { - //nothing - } finally { - provider.returnTypeInfo( info ); - } - - if( cost == null || cost.rank != Cost.NO_MATCH_RANK ){ - return false; - } - } finally{ - if( cost != null ) - cost.release( provider ); - } - } - return true; - } - - static private boolean isValidArgument(ISymbol param, ITypeInfo arg) { - if( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName ){ - //14.3.1, local type, type with no name - if( arg.isType( ITypeInfo.t_type ) && arg.getTypeSymbol() != null ){ - ISymbol symbol = arg.getTypeSymbol(); - if( CharArrayUtils.equals( symbol.getName(), ParserSymbolTable.EMPTY_NAME_ARRAY ) ){ - return false; - } else if( hasNoLinkage( arg ) ){ - return false; - } - } - } else if ( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ){ - //TODO - } else { - List ptrs = param.getPtrOperators(); - ITypeInfo.PtrOp op = ( ptrs.size() > 0 ) ? (ITypeInfo.PtrOp) ptrs.get(0) : null; - - //if the parameter has reference type - if( op != null && op.getType() == ITypeInfo.PtrOp.t_reference ){ - if( arg.isType( ITypeInfo.t_type ) && arg.getTypeSymbol() != null ){ - if( CharArrayUtils.equals( arg.getTypeSymbol().getName(), ParserSymbolTable.EMPTY_NAME_ARRAY )){ - return false; - } - } - return hasExternalLinkage( arg ); - } - - List argPtrs = arg.getPtrOperators(); - ITypeInfo.PtrOp argOp = (argPtrs.size() > 0 ) ? (ITypeInfo.PtrOp)argPtrs.get(0) : null; - - //address of an object with external linkage exluding nonstatic class members - //name of an object with external linkage excluding nonstatic class members - if( (argOp != null && argOp.getType() == ITypeInfo.PtrOp.t_pointer ) || - ( arg.isType( ITypeInfo.t_type ) ) ) - { - ISymbol symbol = arg.getTypeSymbol(); - if ( symbol != null && symbol.getContainingSymbol().isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){ - if( !symbol.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){ - if( !symbol.getTypeInfo().checkBit( ITypeInfo.isStatic ) ){ - return false; - } - } - } - - return hasExternalLinkage( arg ); - } - - //integral or enumeration type - if( op == null && ( arg.isType( ITypeInfo.t_bool, ITypeInfo.t_int ) || - arg.isType( ITypeInfo.t_enumerator ) ) ) - { - return true; - } - - //name of a non-type template parameter - if( arg.isType( ITypeInfo.t_templateParameter ) && - arg.getTemplateParameterType() != ITypeInfo.t_typeName && - arg.getTemplateParameterType() != ITypeInfo.t_template ) - { - return true; - } - return false; - } - return true; - } - - static protected boolean hasExternalLinkage( ITypeInfo type ){ - if( ! type.isType( ITypeInfo.t_type ) ) - return false; - - return !hasNoLinkage( type ); - } - - static protected boolean hasInternalLinkage( ITypeInfo type ){ - return !hasNoLinkage( type ); - } - - static protected boolean hasNoLinkage( ITypeInfo type ){ - if( type.isType( ITypeInfo.t_type ) ){ - ISymbol symbol = type.getTypeSymbol(); - if( symbol.getContainingSymbol() == null ){ - return true; //a temporary - } - - return symbol.getContainingSymbol().isType( ITypeInfo.t_function ); - } - - return false; - } - - /** - * 14.8.2.1-2 If P is a cv-qualified type, the top level cv-qualifiers of P's type are ignored for type - * deduction. If P is a reference type, the type referred to by P is used for Type deduction. - * @param pSymbol - * @return - */ - static private ITypeInfo getParameterTypeForDeduction( ISymbol pSymbol ){ - ITypeInfo p = TypeInfoProvider.newTypeInfo( pSymbol.getTypeInfo () ); - List pPtrs = p.getPtrOperators(); - if( pPtrs.size() > 0 ){ - ITypeInfo.PtrOp pOp = (ITypeInfo.PtrOp) pPtrs.get( 0 ); - if( pOp.getType() == ITypeInfo.PtrOp.t_reference || pOp.getType() == ITypeInfo.PtrOp.t_undef_ptr ){ - pPtrs.remove( 0 ); - } else { - ITypeInfo.PtrOp newOp = new ITypeInfo.PtrOp( pOp.getType(), false, false ); - pPtrs.set( 0, newOp ); - } - } else { - p.setBit( false, ITypeInfo.isConst ); - p.setBit( false, ITypeInfo.isVolatile ); - } - - - return p; - } - - /** - * 14.8.2.1-2 - * if P is not a reference type - * - If A is an array type, the pointer type produced by the array-to-pointer conversion is used instead - * - If A is a function type, the pointer type produced by the function-to-pointer conversion is used instead - * - If A is a cv-qualified type, the top level cv-qualifiers are ignored for type deduction - * @param aInfo - * @return - */ - static private ITypeInfo getArgumentTypeForDeduction( ITypeInfo aInfo, boolean pIsAReferenceType ) throws ParserSymbolTableException{ - - ITypeInfo a = ParserSymbolTable.getFlatTypeInfo( aInfo, null ); - - if( !pIsAReferenceType ){ - ISymbol aSymbol = a.getTypeSymbol(); - - if( a.getType() == ITypeInfo.t_type ){ - if( aSymbol == null ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument ); - } else if( aSymbol.isType( ITypeInfo.t_function ) && a.getPtrOperators().size() == 0 ){ - a.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - } - } - List aPtrs = a.getPtrOperators(); - if( aPtrs.size() > 0 ){ - ITypeInfo.PtrOp pOp = (ITypeInfo.PtrOp) aPtrs.get( 0 ); - - if( pOp.getType() == ITypeInfo.PtrOp.t_array ){ - aPtrs.set( 0, new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer, false, false ) ); - } else { - aPtrs.set( 0, new ITypeInfo.PtrOp( pOp.getType(), false, false ) ); - } - } else { - a.setBit( false, ITypeInfo.isConst ); - a.setBit( false, ITypeInfo.isVolatile ); - } - } - - return a; - } - - static private List getSourceList( ISymbol symbol ){ - ITemplateSymbol template = null; - - if( symbol instanceof IDeferredTemplateInstance ){ - IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) symbol; - return deferred.getArguments(); - } - ISymbol instantiated = symbol.getInstantiatedSymbol(); - template = (ITemplateSymbol) instantiated.getContainingSymbol(); - - - if( template instanceof ISpecializedSymbol ){ - return ((ISpecializedSymbol)template).getArgumentList(); - } - return template.getParameterList(); - } - - static private List getTargetList( ISymbol symbol ){ - if( symbol instanceof IDeferredTemplateInstance ){ - IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) symbol; - return deferred.getArguments(); - } - ISymbol instantiated = symbol.getInstantiatedSymbol(); - if( instantiated != null ){ - ITemplateSymbol template = (ITemplateSymbol) instantiated.getContainingSymbol(); - return template.findArgumentsFor( (IContainerSymbol) symbol ); - } - return null; - } - - /** - * @param aSymbol - * @param p - * @param derivable - * @return - */ - private static ISymbol findMatchingBaseClass( ISymbol p, IDerivableContainerSymbol a ) { - ISymbol aSymbol = null; - ITemplateSymbol pTemplate = null; - ITemplateSymbol parentTemplate = null; - - if( p instanceof IDeferredTemplateInstance ){ - pTemplate = ((IDeferredTemplateInstance)p).getTemplate(); - } else { - pTemplate = (ITemplateSymbol) p.getInstantiatedSymbol().getContainingSymbol(); - } - if( pTemplate instanceof ISpecializedSymbol ){ - pTemplate = ((ISpecializedSymbol)pTemplate).getPrimaryTemplate(); - } - List parents = a.getParents(); - int size = parents.size(); - for( int i = 0; i < size; i++ ){ - IParentSymbol wrapper = (IParentSymbol) parents.get(i); - ISymbol parent = wrapper.getParent(); - if( parent instanceof IDeferredTemplateInstance ){ - IDeferredTemplateInstance parentInstance = (IDeferredTemplateInstance) parent; - parentTemplate = parentInstance.getTemplate(); - if( parentTemplate instanceof ISpecializedSymbol ){ - parentTemplate = ((ISpecializedSymbol)parentTemplate).getPrimaryTemplate(); - } - if( pTemplate == parentTemplate ){ - aSymbol = parent; - break; - } - //In general, we don't have enough information to proceed further down this branch - } else { - parentTemplate = (ITemplateSymbol) parent.getInstantiatedSymbol().getContainingSymbol(); - if( parentTemplate instanceof ISpecializedSymbol ){ - parentTemplate = ((ISpecializedSymbol)parentTemplate).getPrimaryTemplate(); - } - if( pTemplate == parentTemplate ){ - aSymbol = parent; - break; - } - aSymbol = findMatchingBaseClass( p, (IDerivableContainerSymbol) parent ); - } - if( aSymbol != null ) - return aSymbol; - } - - return aSymbol; - } - - static private boolean deduceTemplateArgument( ObjectMap map, ISymbol pSymbol, ITypeInfo a ) throws ParserSymbolTableException{ - ISymbol symbol; - - boolean pIsAReferenceType = false; - - List ptrOps = pSymbol.getPtrOperators(); - if( ptrOps.size() > 0 && ((ITypeInfo.PtrOp)ptrOps.get(0)).getType() == ITypeInfo.PtrOp.t_reference ){ - pIsAReferenceType = true; - } - - ITypeInfo p = getParameterTypeForDeduction( pSymbol ); - - a = getArgumentTypeForDeduction( a, pIsAReferenceType ); - - if( p.isType( ITypeInfo.t_type ) ){ - symbol = p.getTypeSymbol(); - ISymbol aSymbol = a.getTypeSymbol(); - if( symbol == null || ( a.isType( ITypeInfo.t_type) && aSymbol == null ) || a.isType( ITypeInfo.t_undef )) - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); - if( symbol instanceof IDeferredTemplateInstance || symbol.isTemplateInstance() ){ - if( aSymbol == null ) - return false; - return deduceFromTemplateTemplateArguments(map, symbol, aSymbol); - } - if( symbol.isType( ITypeInfo.t_templateParameter ) ){ - if( symbol.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName ){ - //a = getFlatTypeInfo( a ); - List aPtrs = a.getPtrOperators(); - List pPtrs = p.getPtrOperators(); - - if( pPtrs != null && pPtrs.size() > 0){ - if( aPtrs == null ){ - return false; - } - - int pSize = pPtrs.size(); - int aSize = aPtrs.size(); - if( pSize != aSize ) - return false; - - ITypeInfo.PtrOp pOp = null; - ITypeInfo.PtrOp aOp = null; - - int aIdx = 0; - for( int i = 0; i < pSize; i++ ){ - pOp = (ITypeInfo.PtrOp) pPtrs.get(i); - aOp = (ITypeInfo.PtrOp) aPtrs.get(aIdx++); - if( pOp.getType() == aOp.getType() ){ - if( !pOp.equals( aOp ) ) - return false; - aPtrs.remove( --aIdx ); - } else { - return false; - } - } - } - //cvlist T - if( p.checkBit( ITypeInfo.isConst ) ){ - if( !a.checkBit( ITypeInfo.isConst ) ) - return false; - a.setBit( false, ITypeInfo.isConst); - } - if( p.checkBit( ITypeInfo.isVolatile ) ){ - if( !a.checkBit( ITypeInfo.isVolatile ) ) - return false; - a.setBit( false, ITypeInfo.isVolatile); - } - - //T - return deduceArgument( map, symbol, a ); - - } else if ( symbol.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ){ - //TODO - } else { - //non-type parameter - if( symbol.getTypeInfo().getTemplateParameterType() == a.getType() ){ - return deduceArgument( map, symbol, a ); - } - return false; - } - } - //T (*) ( ), T ( T::* ) ( T ), & variations - else if( symbol.isType( ITypeInfo.t_function ) ){ - if( !(aSymbol instanceof IParameterizedSymbol)|| - !aSymbol.isType( ITypeInfo.t_function ) ) - { - return false; - } - - IParameterizedSymbol pFunction = (IParameterizedSymbol)symbol; - IParameterizedSymbol aFunction = (IParameterizedSymbol)aSymbol; - - if( !deduceTemplateArgument( map, pFunction.getReturnType(), aFunction.getReturnType().getTypeInfo() ) ){ - return false; - } - - List pPtrs = p.getPtrOperators(); - if( pPtrs.size() != 0 ){ - ITypeInfo.PtrOp op = (ITypeInfo.PtrOp) pPtrs.get(0); - if( op.getType() == ITypeInfo.PtrOp.t_memberPointer ){ - ITypeInfo info = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, aFunction.getContainingSymbol() ); - if( !deduceTemplateArgument( map, op.getMemberOf(), info ) ){ - return false; - } - } - } - - List pParams = pFunction.getParameterList(); - List aParams = aFunction.getParameterList(); - if( pParams.size() != aParams.size() ){ - return false; - } - int size = pParams.size(); - for( int i = 0; i < size; i++ ){ - ITypeInfo info = ((ISymbol)aParams.get( i )).getTypeInfo(); - if( !deduceTemplateArgument( map, (ISymbol)pParams.get(i), info ) ){ - return false; - } - } - return true; - } - - } - if( p.isType( ITypeInfo.t_templateParameter ) ){ - return deduceArgument( map, pSymbol, a ); - } - if( p.getType() == a.getType() ){ - if( p.getDefault() != null ){ - if( p.getDefault() instanceof char[] && a.getDefault() instanceof char[] ) - return CharArrayUtils.equals( (char[])p.getDefault(), (char[])a.getDefault() ); - return ( p.getDefault().equals( a.getDefault() ) ); - } - return true; - } - - return false; - } - - /** - * @param map - * @param pSymbol - * @param transformationMap - * @param symbol - * @param aSymbol - * @return - */ - private static boolean deduceFromTemplateTemplateArguments(ObjectMap map, ISymbol pSymbol, ISymbol aSymbol) { - //template-name or template-name, where template-name is a class template - ITemplateSymbol p = ( pSymbol instanceof IDeferredTemplateInstance ) ? - (ITemplateSymbol) ((IDeferredTemplateInstance) pSymbol ).getTemplate() : - (ITemplateSymbol) pSymbol.getInstantiatedSymbol().getContainingSymbol(); - - if( p instanceof ISpecializedSymbol ) - p = ((ISpecializedSymbol)p).getPrimaryTemplate(); - - ISymbol a = ( aSymbol.isTemplateInstance() ) ? aSymbol.getInstantiatedSymbol().getContainingSymbol() : - aSymbol.getContainingSymbol(); - - if( a instanceof ISpecializedSymbol ) - a = ((ISpecializedSymbol)a).getPrimaryTemplate(); - - if( p != a ){ - if( aSymbol instanceof IDerivableContainerSymbol ){ - aSymbol = findMatchingBaseClass( pSymbol, (IDerivableContainerSymbol) aSymbol ); - } else { - aSymbol = null; - } - if( aSymbol == null ) { - return false; - } - } - - List pList = getSourceList( pSymbol ); - List aList = getTargetList( aSymbol ); - - //TODO: default args? - if( pList == null || aList == null || pList.size() != aList.size()){ - return false; - } - - int size = pList.size(); - for( int i = 0; i < size; i++ ){ - Object obj = pList.get( i ); - ISymbol sym = null; - if( obj instanceof ISymbol ){ - sym = (ISymbol) obj; - } else { - sym = pSymbol.getSymbolTable().newSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY ); - sym.setTypeInfo( (ITypeInfo) obj ); - } - - ITypeInfo arg = transformTypeInfo( aList.get( i ), null ); - - try { - if( !deduceTemplateArgument( map, sym, arg ) ){ - return false; - } - } catch (ParserSymbolTableException e) { - return false; - } - } - return true; - } - - /** - * - * @param template - * @param argList - the arguments passed in the function call - * @return - * - * A type that is specified in terms of template parameters (P) is compared with an actual - * type (A), and an attempt is made to find template argument vaules that will make P, - * after substitution of the deduced values, compatible with A. - */ - static private ObjectMap deduceTemplateArgumentsUsingParameterList( ITemplateSymbol template, IParameterizedSymbol function ){ - - List aList = function.getParameterList(); - int size = aList.size(); - ArrayList args = new ArrayList( size ); - - for( int i = 0; i < size; i++ ){ - ISymbol symbol = (ISymbol) aList.get(i); - args.add( symbol.getTypeInfo() ); - } - - return deduceTemplateArguments( template, args ); - } - /** - * - * @param template - * @param args - * @return - * - * A type that is specified in terms of template parameters (P) is compared with an actual - * type (A), and an attempt is made to find template argument vaules that will make P, - * after substitution of the deduced values, compatible with A. - */ - static private ObjectMap deduceTemplateArguments( ITemplateSymbol template, List arguments ){ - if( template.getContainedSymbols() == CharArrayObjectMap.EMPTY_MAP || template.getContainedSymbols().size() != 1 ){ - return null; - } - - ISymbol templateSymbol = template.getTemplatedSymbol(); - if( !templateSymbol.isType( ITypeInfo.t_function ) ){ - return null; - } - - IParameterizedSymbol templateFunction = (IParameterizedSymbol) templateSymbol; - - List pList = templateFunction.getParameterList(); -// TODO: ellipses? - if( pList == null || arguments == null || pList.size() != arguments.size() ){ - return null; - } - - int size = pList.size(); - ObjectMap map = new ObjectMap(size); - for( int i = 0; i < size; i++ ){ - try { - if( !deduceTemplateArgument( map, (ISymbol) pList.get(i), (ITypeInfo) arguments.get(i) ) ){ - return null; - } - } catch (ParserSymbolTableException e) { - return null; - } - } - - return map; - } - - static private boolean deduceArgument( ObjectMap map, ISymbol p, ITypeInfo a ){ - - a = ParserSymbolTable.getFlatTypeInfo( a, null ); - - if( map.containsKey( p ) ){ - ITypeInfo current = (ITypeInfo)map.get( p ); - return current.equals( a ); - } - map.put( p, a ); - return true; - } - /** - * Compare spec1 to spec2. Return > 0 if spec1 is more specialized, < 0 if spec2 - * is more specialized, = 0 otherwise. - * @param spec1 - * @param spec2 - * @return - */ - static private int orderSpecializations( ISpecializedSymbol spec1, ISpecializedSymbol spec2 ) throws ParserSymbolTableException{ - if( spec1 == null ){ - return -1; - } - - ISymbol decl = spec1.getTemplatedSymbol(); - - //to order class template specializations, we need to transform them into function templates - ITemplateSymbol template1 = spec1; - ITemplateSymbol template2 = spec2; - - if( decl.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ) { - template1 = classTemplateSpecializationToFunctionTemplate( spec1 ); - template2 = classTemplateSpecializationToFunctionTemplate( spec2 ); - } - - return orderTemplateFunctions( template1, template2); - } - - /** - * Compare spec1 to spec2. Return > 0 if spec1 is more specialized, < 0 if spec2 - * is more specialized, = 0 otherwise. - * - * Both spec1 and spec2 are expected to be template functions - * - */ - static protected int orderTemplateFunctions( ITemplateSymbol spec1, ITemplateSymbol spec2 ) throws ParserSymbolTableException{ - //Using the transformed parameter list, perform argument deduction against the other - //function template - ObjectMap map = createMapForFunctionTemplateOrdering( spec1 ); - - IContainerSymbol templatedSymbol = spec1.getTemplatedSymbol(); - if( !( templatedSymbol instanceof IParameterizedSymbol ) ) - throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError ); - - IParameterizedSymbol function = (IParameterizedSymbol)templatedSymbol; - function = (IParameterizedSymbol) function.instantiate( spec1, map ); - ((TemplateSymbol)spec1).processDeferredInstantiations(); - - ObjectMap m1 = deduceTemplateArgumentsUsingParameterList( spec2, function); - - map = createMapForFunctionTemplateOrdering( spec2 ); - - templatedSymbol = spec2.getTemplatedSymbol(); - if( !( templatedSymbol instanceof IParameterizedSymbol ) ) - throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError ); - - function = (IParameterizedSymbol)templatedSymbol; - function = (IParameterizedSymbol) function.instantiate( spec2, map ); - ((TemplateSymbol)spec2).processDeferredInstantiations(); - - ObjectMap m2 = deduceTemplateArgumentsUsingParameterList( spec1, function ); - - //The transformed template is at least as specialized as the other iff the deduction - //succeeds and the deduced parameter types are an exact match - //A template is more specialized than another iff it is at least as specialized as the - //other template and that template is not at least as specialized as the first. - boolean d1 = ( m1 != null ); - boolean d2 = ( m2 != null ); - - if( d1 && d2 || !d1 && !d2 ) - return 0; - else if( d1 && !d2 ) - return 1; - else - return -1; - } - - /** - * transform a function template for use in partial ordering, as described in the - * spec 14.5.5.2-3 - * @param template - * @return - * -for each type template parameter, synthesize a unique type and substitute that for each - * occurence of that parameter in the function parameter list - * -for each non-type template parameter, synthesize a unique value of the appropriate type and - * susbstitute that for each occurence of that parameter in the function parameter list - * for each template template parameter, synthesize a unique class template and substitute that - * for each occurence of that parameter in the function parameter list - */ - - static private ObjectMap createMapForFunctionTemplateOrdering( ITemplateSymbol template ){ - ITypeInfo val = null; - List paramList = template.getParameterList(); - int size = paramList.size(); - ObjectMap map = new ObjectMap(size); - for( int i = 0; i < size; i++ ){ - ISymbol param = (ISymbol) paramList.get( i ); - //template type parameter - if( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName ){ - val = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, template.getSymbolTable().newSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY, ITypeInfo.t_class ) ); //$NON-NLS-1$ - } - //template parameter - else if ( param.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ) { - //TODO - } - //non type parameter - else { - val = TypeInfoProvider.newTypeInfo( param.getTypeInfo().getTemplateParameterType() ); - } - map.put( param, val ); - } - return map; - } - - - /** - * transform the class template to a function template as described in the spec - * 14.5.4.2-1 - * @param template - * @return IParameterizedSymbol - * the function template has the same template parameters as the partial specialization and - * has a single function parameter whose type is a class template specialization with the template - * arguments of the partial specialization - */ - static private ITemplateSymbol classTemplateSpecializationToFunctionTemplate( ISpecializedSymbol specialization ) throws ParserSymbolTableException{ - ISpecializedSymbol transformed = (ISpecializedSymbol) specialization.clone(); - transformed.getArgumentList().clear(); - transformed.getContainedSymbols().clear(); - //TODO clean up this - ((ContainerSymbol)transformed).getContents().clear(); - - IParameterizedSymbol function = specialization.getSymbolTable().newParameterizedSymbol( transformed.getName(), ITypeInfo.t_function ); - try{ - transformed.addSymbol( function ); - } catch ( ParserSymbolTableException e ){ - //we shouldn't get this because there aren't any other symbols in the template - } - ISymbol param = specialization.getSymbolTable().newSymbol( ParserSymbolTable.EMPTY_NAME_ARRAY, ITypeInfo.t_type ); //$NON-NLS-1$ - - param.setTypeSymbol( specialization.instantiate( specialization.getArgumentList() ) ); - - function.addParameter( param ); - - return transformed; - } - - static private ITypeInfo transformTypeInfo( Object obj, ObjectMap argumentMap ){ - ITypeInfo info = null; - if( obj instanceof ISymbol ){ - info = TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, (ISymbol) obj ); - } else { - info = (ITypeInfo) obj; - } - - if( argumentMap == null ) - return info; - - if( info.isType( ITypeInfo.t_type ) && - info.getTypeSymbol().isType( ITypeInfo.t_templateParameter ) && - argumentMap.containsKey( info.getTypeSymbol() ) ) - { - ITypeInfo newType = TypeInfoProvider.newTypeInfo( (ITypeInfo) argumentMap.get( info.getTypeSymbol() ) ); - if( info.hasPtrOperators() ) - newType.addPtrOperator( info.getPtrOperators() ); - - return newType; - } - - return info; - } - - static protected List selectTemplateFunctions( ObjectSet templates, List functionArguments, List templateArguments ) throws ParserSymbolTableException{ - if( templates == null || templates.size() == 0 ) - return null; - - List instances = null; - - //Iterator iter = templates.iterator(); - int size = templates.size(); - - outer: for( int idx = 0; idx < size; idx++ ){ - IParameterizedSymbol fn = (IParameterizedSymbol) templates.keyAt( idx ); - ITemplateSymbol template = (ITemplateSymbol) fn.getContainingSymbol(); - - ObjectMap map = deduceTemplateArguments( template, functionArguments ); - - if( map == null ) - continue; - - List templateParams = template.getParameterList(); - int numTemplateParams = templateParams.size(); - int numTemplateArgs = ( templateArguments != null ) ? templateArguments.size() : 0; - List instanceArgs = new ArrayList( templateParams.size() ); - for( int i = 0; i < numTemplateParams; i++ ){ - ISymbol param = (ISymbol) templateParams.get(i); - ITypeInfo arg = (ITypeInfo) ( i < numTemplateArgs ? templateArguments.get(i) : null); - ITypeInfo mapped = (ITypeInfo) map.get( param ); - - if( arg != null && mapped != null ) - if( arg.equals( mapped ) ) - instanceArgs.add( arg ); - else - continue outer; - else if( arg == null && mapped == null ) - continue outer; - else - instanceArgs.add( (arg != null) ? arg : mapped ); - } - - IContainerSymbol instance = (IContainerSymbol) template.instantiate( instanceArgs ); - - if( instance != null ){ - if( instances == null ) - instances = new ArrayList(4); - instances.add( instance ); - } - } - - return instances; - } - - /** - * @param look - * @param parameters - * @param arguments - * @throws ParserSymbolTableException - */ - static protected ITemplateSymbol selectTemplateOrSpecialization( ITemplateSymbol template, List parameters, List arguments ) throws ParserSymbolTableException { - if( template != null ){ - //primary definition or specialization? - boolean forPrimary = true; - - if( parameters.size() == 0 ){ - forPrimary = false; - } else if( arguments != null ){ - if( arguments.size() != parameters.size() ){ - forPrimary = false; - } else if( !parameters.isEmpty() ){ - int size = parameters.size(); - for( int i = 0; i < size; i++ ){ - if( parameters.get(i) != ((ITypeInfo) arguments.get(i)).getTypeSymbol() ){ - forPrimary = false; - break; - } - } - } - } - - ITemplateSymbol primary = template; - - if( forPrimary ){ - //make sure parameters match up with found template - if( checkTemplateParameterListsAreEquivalent( primary.getParameterList(), parameters ) ){ - return template; - } - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateParameter ); - } - - //specialization - if( parameters.isEmpty() ){ - return primary; - } - - //partial specialization - ISpecializedSymbol spec = findPartialSpecialization( template, parameters, arguments ); - - if( spec != null ) - return spec; - - //TODO - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - - } - return null; - } - - static private boolean checkTemplateParameterListsAreEquivalent( List p1, List p2 ){ - if( p1.size() != p2.size() ){ - return false; - } - - int size = p1.size(); - for( int i = 0; i < size; i++ ){ - ISymbol param1 = (ISymbol) p1.get( i ); - ISymbol param2 = (ISymbol) p2.get( i ); - if( param1.getTypeInfo().getTemplateParameterType() != param2.getTypeInfo().getTemplateParameterType() ){ - return false; - } - } - return true; - } - - static private boolean checkTemplateArgumentListsAreEquivalent( List p1, List p2, List a1, List a2 ){ - if( a1.size() != a2.size() || p1.size() != p2.size() ){ - return false; - } - - ObjectMap m [] = { new ObjectMap(p1.size()), new ObjectMap(p1.size()) }; - - for( List list = p1; list != null; list = p2 ){ - int size = list.size(); - int index = 0; - for( int i = 0; i < size; i++ ) { - m[ ( list == p2 )? 1 : 0 ].put( list.get( i ), new Integer( index++ ) ); - } - - if( list == p2 ){ - break; - } - } - - int a1Size = a1.size(); - for( int i = 0; i < a1Size; i++ ){ - ITypeInfo t1 = (ITypeInfo) a1.get( i ); - ITypeInfo t2 = (ITypeInfo) a2.get( i ); - - if( t1.equals( t2 ) ){ - continue; - } else if( t1.isType( ITypeInfo.t_type ) && t2.isType( ITypeInfo.t_type ) ) { - ISymbol s1 = t1.getTypeSymbol(), s2 = t2.getTypeSymbol(); - if( m[0].containsKey( s1 ) && m[1].containsKey( s2 ) && m[0].get( s1 ).equals( m[1].get( s2 ) ) ) - continue; - } - - return false; - } - return true; - } - - static private ISpecializedSymbol findPartialSpecialization( ITemplateSymbol template, List parameters, List arguments ){ - List specs = template.getSpecializations(); - int size = specs.size(); - ISpecializedSymbol spec = null; - for( int i = 0; i < size; i++ ){ - spec = (ISpecializedSymbol) specs.get(i); - - if( ! checkTemplateParameterListsAreEquivalent( spec.getParameterList(), parameters ) ){ - continue; - } - - if( checkTemplateArgumentListsAreEquivalent( spec.getParameterList(), parameters, - spec.getArgumentList(), arguments ) ) - { - return spec; - } - } - return null; - } - - static protected ISymbol translateParameterForDefinition ( ISymbol templatedSymbol, ISymbol param, ObjectMap defnMap ){ - if( defnMap == ObjectMap.EMPTY_MAP || templatedSymbol == null ){ - return param; - } - - ISymbol mappedParam = param; - while( mappedParam.isTemplateInstance() ){ - mappedParam = mappedParam.getInstantiatedSymbol(); - } - - if( defnMap.containsKey( templatedSymbol ) ){ - ObjectMap map = (ObjectMap) defnMap.get( templatedSymbol ); - - for( int i = 0; i < map.size(); i++){ - ISymbol key = (ISymbol) map.keyAt(i); - if( map.get( key ) == mappedParam ){ - return key; - } - } - } - - return param; - } - - /** - * 14.6.1-1 (2) Within the scope of a class template (class template specialization or partial specialization), when - * the name of the template is neither qualified nor followed by <. it is equivalent to the name of the template - * followed by the template-parameters (template-arguments) enclosed in <> - * - * @param symbol - * @return - * @throws ParserSymbolTableException - */ - static protected ISymbol instantiateWithinTemplateScope( IContainerSymbol container, ITemplateSymbol symbol ) throws ParserSymbolTableException - { - if( symbol.getTemplatedSymbol() == null || symbol.getTemplatedSymbol().isType( ITypeInfo.t_function ) ){ - return symbol; - } - - ISymbol instance = null; - ITemplateSymbol template = null; - IContainerSymbol containing = container.getContainingSymbol(); - boolean instantiate = false; - while( containing != null ){ - if( containing == symbol || - ( containing instanceof ISpecializedSymbol && ((ISpecializedSymbol)containing).getPrimaryTemplate() == symbol ) ) - { - instantiate = true; - template = (ITemplateSymbol) containing; - break; - } - containing = containing.getContainingSymbol(); - - if( containing != null && !containing.isTemplateMember() || !containing.isType( ITypeInfo.t_template ) ){ - break; - } - } - - if( instantiate ){ - if( template instanceof ISpecializedSymbol ){ - ISpecializedSymbol spec = (ISpecializedSymbol) template; - instance = spec.instantiate( spec.getArgumentList() ); - } else { - List params = template.getParameterList(); - int size = params.size(); - List args = new ArrayList( size ); - for( int i = 0; i < size; i++ ){ - args.add( TypeInfoProvider.newTypeInfo( ITypeInfo.t_type, 0, (ISymbol) params.get(i) ) ); - } - - instance = template.instantiate( args ); - } - } - - return ( instance != null ) ? instance : (ISymbol) symbol; - } - - static protected boolean alreadyHasTemplateParameter( IContainerSymbol container, char[] name ){ - while( container != null ){ - if( container instanceof ITemplateSymbol ){ - ITemplateSymbol template = (ITemplateSymbol) container; - if( template.getParameterMap().containsKey( name ) ){ - return true; - } - } - container = container.getContainingSymbol(); - } - return false; - } - - static protected boolean canAddTemplate( IContainerSymbol containing, ITemplateSymbol template ){ - //14-2 A template-declaration can appear only as a namespace scope or class scope declaration - if( !containing.isType( ITypeInfo.t_namespace ) && !containing.isType( ITypeInfo.t_class, ITypeInfo.t_union ) ){ - return false; - } - - //14.5.2-3 A member function template shall not be virtual - if( containing.isTemplateMember() && containing.getContainingSymbol().isType( ITypeInfo.t_template ) ){ - ISymbol symbol = template.getTemplatedSymbol(); - if( symbol != null && symbol.isType( ITypeInfo.t_function ) && symbol.getTypeInfo().checkBit( ITypeInfo.isVirtual ) ){ - return false; - } - } - - return true; - } - - static protected List verifyExplicitArguments( ITemplateSymbol template, List arguments, ISymbol symbol ) throws ParserSymbolTableException{ - List params = template.getParameterList(); - - int numParams = params.size(); - int numArgs = arguments.size(); - List actualArgs = new ArrayList( numParams ); - for( int i = 0; i < numParams; i++ ){ - ISymbol param = (ISymbol) params.get(i); - if( i < numArgs ){ - ITypeInfo arg = (ITypeInfo) arguments.get(i); - if( matchTemplateParameterAndArgument( param, arg ) ){ - actualArgs.add( arg ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument ); - } - } else { - //14.7.3-11 a trailing template-argument can be left unspecified in the template-id naming an explicit - //function template specialization provided it can be deduced from the function argument type - if( template.getTemplatedSymbol() instanceof IParameterizedSymbol && - symbol instanceof IParameterizedSymbol && CharArrayUtils.equals( template.getTemplatedSymbol().getName(), symbol.getName() ) ) - { - ObjectMap map = deduceTemplateArgumentsUsingParameterList( template, (IParameterizedSymbol) symbol ); - if( map != null && map.containsKey( param ) ){ - actualArgs.add( map.get( param ) ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument ); - } - } - } - } - return actualArgs; - } - - static protected ITemplateSymbol resolveTemplateFunctions( ObjectSet functions, List args, ISymbol symbol ) throws ParserSymbolTableException{ - ITemplateSymbol template = null; - - outer: for( int i = 0; i < functions.size(); i++ ){ - IParameterizedSymbol fn = (IParameterizedSymbol) functions.keyAt(i); - ITemplateSymbol tmpl = (ITemplateSymbol) fn.getContainingSymbol(); - - ObjectMap map = deduceTemplateArgumentsUsingParameterList( tmpl, (IParameterizedSymbol) symbol ); - - if( map == null ) - continue; - List params = tmpl.getParameterList(); - int numParams = params.size(); - int numArgs = args.size(); - for( int j = 0; j < numParams && j < numArgs; j++ ){ - ISymbol param = (ISymbol) params.get(j); - ITypeInfo arg = (ITypeInfo) args.get(j); - if( map.containsKey( param ) ) { - if( !map.get( param ).equals( arg )){ - continue outer; - } - } else if( !matchTemplateParameterAndArgument( param, arg )){ - continue outer; - } - } - //made it this far, its a match - if( template != null ){ - throw new ParserSymbolTableException(ParserSymbolTableException.r_Ambiguous ); - } - template = tmpl; - } - - return template; - } - - static protected List resolveTemplateFunctionArguments( List args, ITemplateSymbol template, IParameterizedSymbol fn ) - { - List resultList = new ArrayList(); - - List params = template.getParameterList(); - ObjectMap map = null; - - int numParams = params.size(); - int numArgs = ( args != null ) ? args.size() : 0; - for( int i = 0; i < numParams; i++ ){ - ISymbol param = (ISymbol) params.get(i); - ITypeInfo arg = null; - if( i < numArgs ){ - arg = (ITypeInfo) args.get(i); - } else { - if( map == null ){ - map = deduceTemplateArgumentsUsingParameterList( template, fn ); - if(map == null ) - return null; - } - if( map.containsKey( param ) ){ - arg = (ITypeInfo) map.get( param ); - } - } - - if( arg == null || !matchTemplateParameterAndArgument( param, arg ) ) - return null; - - resultList.add( arg ); - } - - return resultList; - } - - static protected ISymbol checkForTemplateExplicitSpecialization( ITemplateSymbol template, ISymbol symbol, List arguments ){ - if( !template.getExplicitSpecializations().isEmpty() ){ - //TODO: could optimize this if we had a TypeInfo.hashCode() - ObjectMap specs = template.getExplicitSpecializations(); - List args = null; - for( int i = 0; i < specs.size(); i++ ){ - args = (List) specs.keyAt(i); - - if( args.equals( arguments ) ){ - ObjectMap explicitMap = (ObjectMap) template.getExplicitSpecializations().get( args ); - if( explicitMap.containsKey( symbol ) ){ - return (ISymbol) explicitMap.get( symbol ); - } - } - } - } - - return null; - } - - static protected boolean templateParametersAreEquivalent( ISymbol p1, ISymbol p2 ){ - if( !p1.isType( ITypeInfo.t_templateParameter ) || !p2.isType( ITypeInfo.t_templateParameter ) || - p1.getTypeInfo().getTemplateParameterType() != p2.getTypeInfo().getTemplateParameterType() ) - { - return false; - } - - ITemplateSymbol t1 = getContainingTemplate( p1 ); - ITemplateSymbol t2 = getContainingTemplate( p2 ); - - if( t1 == null || t2 == null ) - return false; - - if( p1.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_typeName ) - { - List l1 = t1.getParameterList(), l2 = t2.getParameterList(); - return ( l1 != null && l2 != null && l1.indexOf( p1 ) == l2.indexOf( p2 ) ); - } else if( p1.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ){ - ITemplateSymbol pt1 = (ITemplateSymbol)p1.getTypeSymbol(); - ITemplateSymbol pt2 = (ITemplateSymbol)p2.getTypeSymbol(); - return checkTemplateParameterListsAreEquivalent( pt1.getParameterList(), pt2.getParameterList() ); - } else { - return p1.getTypeInfo().equals( p2.getTypeInfo() ); - } - } - - static protected ITemplateSymbol getContainingTemplate( ISymbol symbol ){ - if( ! symbol.isTemplateMember() ){ - return null; - } - - while( !( symbol.getContainingSymbol() instanceof ITemplateSymbol ) ){ - symbol = symbol.getContainingSymbol(); - } - return (ITemplateSymbol) symbol.getContainingSymbol(); - } - - /** - * @param instance - * @param instance2 - * @return - */ - protected static boolean deferedInstancesAreEquivalent(IDeferredTemplateInstance instance, IDeferredTemplateInstance instance2) { - if( instance.getTemplate() != instance2.getTemplate() ) - return false; - - List args = instance.getArguments(); - List args2 = instance2.getArguments(); - int size = args.size(); - if( size != args2.size() ) - return false; - - for( int i = 0; i < size; i++ ){ - ITypeInfo info1 = (ITypeInfo) args.get(i); - ITypeInfo info2 = (ITypeInfo) args2.get(i); - - if( ! info1.equals( info2 ) ) - return false; - } - return true; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateFactory.java deleted file mode 100644 index c3e7a0080c9..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateFactory.java +++ /dev/null @@ -1,895 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateDeclaration; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateInstantiation; -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTTemplateSpecialization; - -/** - * @author aniefer - */ -public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactory { - - private IContainerSymbol lastSymbol; - - private ArrayList templates = new ArrayList(4); - private ArrayList symbols = new ArrayList(4); - private ObjectMap argMap = new ObjectMap(2); - - protected TemplateFactory( ParserSymbolTable table ){ - super( table ); - } - - public void pushTemplate(ITemplateSymbol template ) { - templates.add( template ); - } - - public void pushSymbol(ISymbol symbol) { - symbols.add( symbol ); - } - - public void pushTemplateId(ISymbol symbol, List args) { - symbols.add( symbol ); - argMap.put( symbol, new ArrayList( args ) ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addTemplateId(org.eclipse.cdt.internal.core.parser.pst.ISymbol, java.util.List) - */ - public void addTemplateId(ISymbol symbol, List args) throws ParserSymbolTableException { - ISymbol previous = findPreviousSymbol( symbol, args ); - ITemplateSymbol origTemplate = (previous != null && previous.getContainingSymbol() instanceof ITemplateSymbol ) - ? (ITemplateSymbol) previous.getContainingSymbol() : null; - - if( origTemplate == null ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - } - - ITemplateSymbol template = (ITemplateSymbol) templates.get( templates.size() - 1 ); - - List params = ( template != null ) ? template.getParameterList() : null; - if( params == null ){ - //explicit instantiation - addExplicitInstantiation( origTemplate, args ); - } else if( params.size() == 0 ){ - //explicit specialization - addExplicitSpecialization( origTemplate, symbol, args ); - - } else { - //partial speciailization - ISpecializedSymbol spec = template.getSymbolTable().newSpecializedSymbol( symbol.getName() ); - int size = params.size(); - for( int i = 0; i < size; i++){ - spec.addTemplateParameter( (ISymbol) params.get( i ) ); - } - size = args.size(); - spec.prepareArguments( size ); - for( int i = 0; i < size; i++){ - spec.addArgument( (ITypeInfo) args.get(i) ); - } - - spec.addSymbol( symbol ); - origTemplate.addSpecialization( spec ); - - //replace the symbol attached to the AST node. - if( getASTExtension() != null ){ - TemplateSymbolExtension extension = (TemplateSymbolExtension) template.getASTExtension(); - extension.replaceSymbol( spec ); - ASTTemplateDeclaration templateDecl = (ASTTemplateDeclaration) getASTExtension().getPrimaryDeclaration(); - templateDecl.releaseFactory(); - templateDecl.setSymbol( spec ); - templateDecl.setOwnedDeclaration( symbol ); - } - } - - - } - - public void addSymbol(ISymbol symbol) throws ParserSymbolTableException { - lastSymbol = getLastSymbol(); - - ISymbol sym = null; - ISymbol container = null; - boolean templateParamState = false; - int size = symbols.size(); - int templatesSize = templates.size(), templatesIdx = 0; - for( int i = 0; i < size; i++ ){ - sym = (ISymbol) symbols.get( i ); - if( !sym.getContainingSymbol().isType( ITypeInfo.t_template ) ){ - symbols.remove( i-- ); - size--; - } else if( templatesIdx < templatesSize ) { - ITemplateSymbol template = (ITemplateSymbol) templates.get( templatesIdx++ ); - if( template.getParameterList().size() == 0 ){ - templateParamState = true; - container = sym; - } else if( templateParamState ) - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - } - } - - int numTemplates = templates.size(); - int numSymbols = symbols.size(); - - if( templateParamState ){ - List args = (List) argMap.get( container ); - addExplicitSpecialization( (ITemplateSymbol) container.getContainingSymbol(), symbol, args ); - return; - } - - if( numTemplates == numSymbols + 1 ){ - //basic template declaration or Definition - basicTemplateDeclaration( symbol ); - return; - } - - if( numTemplates == numSymbols ){ - //all of the templates were matched to a symbol, we are doing a member - memberDeclaration( symbol ); - return; - } - } - - private ISymbol findPreviousSymbol( ISymbol symbol, List args ) throws ParserSymbolTableException{ - ISymbol previous = null; - - List argList = null; - if( symbol instanceof IParameterizedSymbol ){ - List params = ((IParameterizedSymbol)symbol).getParameterList(); - int size = params.size(); - argList = new ArrayList( size ); - for( int i = 0; i < size; i++ ){ - ISymbol param = (ISymbol) params.get(i); - argList.add( param.getTypeInfo() ); - } - } - - if( symbol.isType( ITypeInfo.t_function ) ){ - if( args != null ) - previous = lookupFunctionTemplateId( symbol.getName(), argList, args, false ); - else - previous = lookupMethodForDefinition( symbol.getName(), argList ); - } else if ( symbol.isType( ITypeInfo.t_constructor ) ){ - previous = lookupConstructor( argList ); - } else { - previous = lookupMemberForDefinition( symbol.getName() ); - } - return previous; - } - - private void basicTemplateDeclaration( ISymbol symbol ) throws ParserSymbolTableException{ - ITemplateSymbol template = (ITemplateSymbol)templates.get( 0 ); - - if( template == null ) return; - if( template.getParameterList().size() == 0 ){ - //explicit specialization, deduce some arguments and use addTemplateId - ISymbol previous = findPreviousSymbol( symbol, new ArrayList() ); - if( previous == null || !(previous.getContainingSymbol() instanceof ITemplateSymbol) ) - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - - List args = null; - if( symbol instanceof IParameterizedSymbol ){ - args = TemplateEngine.resolveTemplateFunctionArguments( null, (ITemplateSymbol)previous.getContainingSymbol(), (IParameterizedSymbol) symbol ); - } - if( args != null ) - addTemplateId( symbol, args ); - else - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - - } else { - ISymbol previous = findPreviousSymbol( symbol, null ); - - if( previous == null ){ - //new template - template.setName( symbol.getName () ); - template.addSymbol( symbol ); - getContainingSymbol().addSymbol( template ); - if( getASTExtension() != null ){ - ASTTemplateDeclaration templateDecl = (ASTTemplateDeclaration) getASTExtension().getPrimaryDeclaration(); - templateDecl.releaseFactory(); - templateDecl.setOwnedDeclaration( symbol ); - } - } else { - //definition for something declared already - ITemplateSymbol originalTemplate = null; - ISymbol originalSymbol = null; - - if( previous instanceof ITemplateSymbol ){ - originalTemplate = (ITemplateSymbol) previous; - originalSymbol = originalTemplate.getTemplatedSymbol(); - } else { - if( previous.getContainingSymbol() instanceof ITemplateSymbol ){ - originalTemplate = (ITemplateSymbol) previous.getContainingSymbol(); - originalSymbol = previous; - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - } - } - - if( originalSymbol.isForwardDeclaration() ){ - - if( originalTemplate.getParameterList().size() != template.getParameterList().size() ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - } - - symbols.add( originalSymbol ); - doDefinitionParameterMaps( symbol ); - - originalTemplate.addSymbol( symbol ); - - if( getASTExtension() != null ){ - ASTTemplateDeclaration templateDecl = (ASTTemplateDeclaration) getASTExtension().getPrimaryDeclaration(); - templateDecl.releaseFactory(); - templateDecl.setOwnedDeclaration( symbol ); - } - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidOverload ); - } - } - } - } - - private void memberDeclaration( ISymbol symbol ) throws ParserSymbolTableException{ - ISymbol previous = findPreviousSymbol( symbol, null ); - if( previous == null ) { - //could happen in trying to define something for which we don't have a declaration - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - } - IContainerSymbol originalContainer = previous.getContainingSymbol(); - - if( previous.isForwardDeclaration() ){ - doDefinitionParameterMaps( symbol ); - - originalContainer.addSymbol( symbol ); - - if( getASTExtension() != null ){ - ASTTemplateDeclaration templateDecl = (ASTTemplateDeclaration) getASTExtension().getPrimaryDeclaration(); - templateDecl.releaseFactory(); - templateDecl.setOwnedDeclaration( symbol ); - } - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidOverload ); - } - } - - private void doDefinitionParameterMaps( ISymbol newSymbol ) throws ParserSymbolTableException { - if( templates.size() != symbols.size() ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - } - - int size = templates.size(); - for( int i = 0; i < size; i++ ){ - ITemplateSymbol template = (ITemplateSymbol) templates.get(i); - ISymbol origContainer = (ISymbol) symbols.get(i); - if ( origContainer instanceof IDeferredTemplateInstance ) - origContainer = ((IDeferredTemplateInstance) origContainer).getTemplate().getTemplatedSymbol(); - ITemplateSymbol origTemplate = (ITemplateSymbol)origContainer.getContainingSymbol(); - ObjectMap containerDefnMap = null; - List tList = template.getParameterList(); - if( origTemplate.getDefinitionParameterMap().containsKey( origContainer ) ){ - containerDefnMap = (ObjectMap) origTemplate.getDefinitionParameterMap().get( origContainer ); - } - List oList = origTemplate.getParameterList(); - int tListSize = tList.size(); - if( oList.size() < tListSize ) - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - ObjectMap defnMap = new ObjectMap(tListSize); - for( int j = 0; j < tListSize; j++ ) { - ISymbol param = (ISymbol) tList.get(j); - ISymbol origParam = (ISymbol) oList.get(j); - if( containerDefnMap != null ) { - ISymbol keyParam, valParam; - for( int k = 0; k < containerDefnMap.size(); ++k ) { - keyParam = (ISymbol) containerDefnMap.keyAt( k ); - valParam = (ISymbol) containerDefnMap.getAt( k ); - if ( valParam.equals(origParam) ) { - origParam = keyParam; - break; - } - } - } - defnMap.put( param, origParam ); - } - - ((TemplateSymbol)origTemplate).addToDefinitionParameterMap( newSymbol, defnMap ); - } - } - - private void addExplicitInstantiation( ITemplateSymbol origTemplate, List args ) throws ParserSymbolTableException { - ISymbol instance = origTemplate.instantiate( args ); - - if( getASTExtension() != null ){ - ASTTemplateInstantiation templateInstance = (ASTTemplateInstantiation) getASTExtension().getPrimaryDeclaration(); - templateInstance.releaseFactory(); - templateInstance.setInstanceSymbol( instance ); - } - } - private void addExplicitSpecialization( ITemplateSymbol template, ISymbol symbol, List arguments ) throws ParserSymbolTableException { - template.addExplicitSpecialization( symbol, arguments ); - - int size = symbols.size(); - for( int i = 0; i < size; i++ ){ - IContainerSymbol sym = (IContainerSymbol) symbols.get( 0 ); - ISymbol instantiated = sym.getInstantiatedSymbol(); - if( instantiated != null ){ - IContainerSymbol container = instantiated.getContainingSymbol(); - if( container.isType( ITypeInfo.t_template ) ){ - ((ITemplateSymbol) container ).removeInstantiation( sym ); - } - } - } - - if( getASTExtension() != null ){ - ASTTemplateSpecialization spec = (ASTTemplateSpecialization) getASTExtension().getPrimaryDeclaration(); - spec.setOwnedDeclaration( symbol ); - } - } - - private IContainerSymbol getLastSymbol() { - if( lastSymbol != null ) - return lastSymbol; - else if( !symbols.isEmpty() ) { - ISymbol symbol = (ISymbol) symbols.get( symbols.size() - 1 ); - if( symbol instanceof IDeferredTemplateInstance ) - return ((IDeferredTemplateInstance)symbol).getTemplate().getTemplatedSymbol(); - else if( symbol instanceof IContainerSymbol ) - return (IContainerSymbol) symbol; - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateFactory#lookupMemberForDefinition(java.lang.String) - */ - public ISymbol lookupMemberForDefinition(char[] name, ITypeInfo.eType type ) throws ParserSymbolTableException { - ISymbol look = null; - IContainerSymbol last = getLastSymbol(); - if( last != null && last.isType(type)){ - look = last.lookupMemberForDefinition( name ); - } else { - look = getContainingSymbol().lookupMemberForDefinition( name ); - } - if( look instanceof ITemplateSymbol ){ - return ((ITemplateSymbol)look).getTemplatedSymbol(); - } - return look; - } - - public ISymbol lookupMemberForDefinition(char[] name) throws ParserSymbolTableException { - return lookupMemberForDefinition(name, ITypeInfo.t_any); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#elaboratedLookup(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType, java.lang.String) - */ - public ISymbol elaboratedLookup(ITypeInfo.eType type, char[] name) throws ParserSymbolTableException { - int size = templates.size(); - for( int i = size - 1; i >= 0; i-- ){ - ITemplateSymbol template = (ITemplateSymbol) templates.get(i); - if( template == null )continue; - ISymbol look = template.lookupMemberForDefinition( name ); - if( look != null && look.isType( type ) ){ - return look; - } - } - - return getContainingSymbol().elaboratedLookup( type, name ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookup(java.lang.String) - */ - public ISymbol lookup(char[] name) throws ParserSymbolTableException { - int size = templates.size(); - for( int i = size - 1; i >= 0; i-- ){ - ITemplateSymbol template = (ITemplateSymbol) templates.get(i); - if( template != null ) - { - ISymbol look = template.lookupMemberForDefinition( name ); - if( look != null ){ - return look; - } - } - } - - return getContainingSymbol().lookup( name ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupMethodForDefinition(java.lang.String, java.util.List) - */ - public IParameterizedSymbol lookupMethodForDefinition(char[] name, List parameters) throws ParserSymbolTableException { - IContainerSymbol last = getLastSymbol(); - if( last != null ){ - IParameterizedSymbol found = last.lookupMethodForDefinition( name, parameters ); - if( found != null ){ - return found; - } - } - return getContainingSymbol().lookupMethodForDefinition( name, parameters ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupNestedNameSpecifier(java.lang.String) - */ - public ISymbol lookupNestedNameSpecifier(char[] name) throws ParserSymbolTableException { - return getContainingSymbol().lookupNestedNameSpecifier( name ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#qualifiedLookup(java.lang.String) - */ - public ISymbol qualifiedLookup(char[] name) throws ParserSymbolTableException { - return getContainingSymbol().qualifiedLookup( name ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#qualifiedLookup(java.lang.String, org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType) - */ - public ISymbol qualifiedLookup(char[] name, ITypeInfo.eType t) throws ParserSymbolTableException { - return getContainingSymbol().qualifiedLookup( name, t ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#unqualifiedFunctionLookup(java.lang.String, java.util.List) - */ - public IParameterizedSymbol unqualifiedFunctionLookup(char[] name, List parameters) throws ParserSymbolTableException { - return getContainingSymbol().unqualifiedFunctionLookup( name, parameters ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#memberFunctionLookup(java.lang.String, java.util.List) - */ - public IParameterizedSymbol memberFunctionLookup(char[] name, List parameters) throws ParserSymbolTableException { - return getContainingSymbol().memberFunctionLookup( name, parameters ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#qualifiedFunctionLookup(java.lang.String, java.util.List) - */ - public IParameterizedSymbol qualifiedFunctionLookup(char[] name, List parameters) throws ParserSymbolTableException { - return getContainingSymbol().qualifiedFunctionLookup( name, parameters ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupTemplate(java.lang.String, java.util.List) - */ - public ISymbol lookupTemplateId(char[] name, List arguments) throws ParserSymbolTableException { - ISymbol look = null; - IContainerSymbol last = getLastSymbol(); - if( last != null ){ - look = last.lookupTemplateId( name, arguments ); - } else { - look = getContainingSymbol().lookupTemplateId( name, arguments ); - } - return look; - } - - public IContainerSymbol lookupTemplateIdForDefinition(char[] name, List arguments) throws ParserSymbolTableException { - ISymbol look = null; - IContainerSymbol last = getLastSymbol(); - if( last != null ){ - look = last.lookupMemberForDefinition( name ); - } else { - look = getContainingSymbol().lookupMemberForDefinition( name ); - } - - if( look instanceof ITemplateSymbol ){ - ITemplateSymbol t = TemplateEngine.selectTemplateOrSpecialization( (ITemplateSymbol) look, getNextAvailableTemplate().getParameterList(), arguments ); - look = t.getTemplatedSymbol(); - } - return (IContainerSymbol) (( look instanceof IContainerSymbol) ? look : null); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupFunctionTemplateId(java.lang.String, java.util.List, java.util.List) - */ - public ISymbol lookupFunctionTemplateId(char[] name, List parameters, List arguments, boolean forDefinition) throws ParserSymbolTableException { - IContainerSymbol last = getLastSymbol(); - if( last != null ){ - IParameterizedSymbol found = (IParameterizedSymbol) last.lookupFunctionTemplateId( name, parameters, arguments, forDefinition ); - if( found != null ){ - return found; - } - } - return getContainingSymbol().lookupFunctionTemplateId( name, parameters, arguments, forDefinition ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#lookupConstructor(java.util.List) - */ - public IParameterizedSymbol lookupConstructor(List parameters) throws ParserSymbolTableException { - IContainerSymbol last = getLastSymbol(); - if( last != null && last instanceof IDerivableContainerSymbol ){ - IDerivableContainerSymbol derivable = (IDerivableContainerSymbol) last; - IParameterizedSymbol found = derivable.lookupConstructor( parameters ); - if( found != null ) - return found; - } - if( getContainingSymbol() instanceof IDerivableContainerSymbol ) - return ((IDerivableContainerSymbol) getContainingSymbol()).lookupConstructor( parameters ); - - return null; - } - - private ITemplateSymbol getNextAvailableTemplate() throws ParserSymbolTableException{ - int numSymbols = symbols.size(); - int numTemplates = templates.size(); - int templateIdx = 0; - for( int i = 0; i < numSymbols; i++ ){ - ISymbol symbol = (ISymbol) symbols.get(i); - if( symbol.getContainingSymbol().isType( ITypeInfo.t_template ) ){ - if( templateIdx < numTemplates ) - templateIdx++; - else - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - } - } - - if( templateIdx >= numTemplates ) - return null; - return (ITemplateSymbol) templates.get( templateIdx ); - } - - - //TODO: Do any of these other functions need to be implemented? - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#removeSymbol(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public boolean removeSymbol(ISymbol symbol) { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#hasUsingDirectives() - */ - public boolean hasUsingDirectives() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getUsingDirectives() - */ - public List getUsingDirectives() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDirective(org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) - */ - public IUsingDirectiveSymbol addUsingDirective(IContainerSymbol namespace) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDeclaration(java.lang.String) - */ - public IUsingDeclarationSymbol addUsingDeclaration(char[] name) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDeclaration(java.lang.String, org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) - */ - public IUsingDeclarationSymbol addUsingDeclaration(char[] name, IContainerSymbol declContext) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getContainedSymbols() - */ - public CharArrayObjectMap getContainedSymbols() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#prefixLookup(org.eclipse.cdt.internal.core.parser.pst.TypeFilter, java.lang.String, boolean) - */ - public List prefixLookup(TypeFilter filter, char[] prefix, boolean qualified, List paramList) { - return null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#isVisible(org.eclipse.cdt.internal.core.parser.pst.ISymbol, org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) - */ - public boolean isVisible(ISymbol symbol, IContainerSymbol qualifyingSymbol) { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getContentsIterator() - */ - public Iterator getContentsIterator() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#clone() - */ - public Object clone() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#instantiate(org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol, java.util.Map) - */ - public ISymbol instantiate(ITemplateSymbol template, ObjectMap argMapParm) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setName(java.lang.String) - */ - public void setName(char[] name) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getName() - */ - public char[] getName() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#isType(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType) - */ - public boolean isType(ITypeInfo.eType type) { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#isType(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType, org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType) - */ - public boolean isType(ITypeInfo.eType type, ITypeInfo.eType upperType) { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getType() - */ - public ITypeInfo.eType getType() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setType(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.eType) - */ - public void setType(ITypeInfo.eType t) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getTypeInfo() - */ - public ITypeInfo getTypeInfo() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setTypeInfo(org.eclipse.cdt.internal.core.parser.pst.TypeInfo) - */ - public void setTypeInfo(ITypeInfo info) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getTypeSymbol() - */ - public ISymbol getTypeSymbol() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setTypeSymbol(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void setTypeSymbol(ISymbol type) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#isForwardDeclaration() - */ - public boolean isForwardDeclaration() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setIsForwardDeclaration(boolean) - */ - public void setIsForwardDeclaration(boolean forward) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#compareCVQualifiersTo(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public int compareCVQualifiersTo(ISymbol symbol) { - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getPtrOperators() - */ - public List getPtrOperators() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#addPtrOperator(org.eclipse.cdt.internal.core.parser.pst.TypeInfo.PtrOp) - */ - public void addPtrOperator(ITypeInfo.PtrOp ptrOp) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#isTemplateInstance() - */ - public boolean isTemplateInstance() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getInstantiatedSymbol() - */ - public ISymbol getInstantiatedSymbol() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setInstantiatedSymbol(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void setInstantiatedSymbol(ISymbol symbol) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#isTemplateMember() - */ - public boolean isTemplateMember() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setIsTemplateMember(boolean) - */ - public void setIsTemplateMember(boolean isMember) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getDepth() - */ - public int getDepth() { - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getIsInvisible() - */ - public boolean getIsInvisible() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setIsInvisible(boolean) - */ - public void setIsInvisible(boolean invisible) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addParent(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void addParent(ISymbol parent) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addParent(org.eclipse.cdt.internal.core.parser.pst.ISymbol, boolean, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility, int, java.util.List) - */ - public void addParent(ISymbol parent, boolean virtual, ASTAccessVisibility visibility, int offset, List references) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#getParents() - */ - public List getParents() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#hasParents() - */ - public boolean hasParents() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addConstructor(org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol) - */ - public void addConstructor(IParameterizedSymbol constructor) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addCopyConstructor() - */ - public void addCopyConstructor() { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#getConstructors() - */ - public List getConstructors() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#addFriend(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void addFriend(ISymbol friend) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#lookupForFriendship(java.lang.String) - */ - public ISymbol lookupForFriendship(char[] name) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#lookupFunctionForFriendship(java.lang.String, java.util.List) - */ - public IParameterizedSymbol lookupFunctionForFriendship(char[] name, List parameters) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol#getFriends() - */ - public List getFriends() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#preparePtrOperatros(int) - */ - public void preparePtrOperatros(int numPtrOps) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#setForwardSymbol(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void setForwardSymbol(ISymbol forward) { - /* nothing */ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#getForwardSymbol() - */ - public ISymbol getForwardSymbol() { - return null; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateParameterTypeInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateParameterTypeInfo.java deleted file mode 100644 index 55ff05f122f..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateParameterTypeInfo.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Jul 5, 2004 - */ -package org.eclipse.cdt.internal.core.parser.pst; - -/** - * @author aniefer - */ -public class TemplateParameterTypeInfo extends TypeInfo { - - public ITypeInfo.eType getTemplateParameterType() { - return _templateParameterType; - } - public void setTemplateParameterType( ITypeInfo.eType type ) { - _templateParameterType = type; - } - public boolean equals( Object t ) { - if( !super.equals( t ) ){ - return false; - } - return _templateParameterType == ((ITypeInfo)t).getTemplateParameterType(); - } - - private ITypeInfo.eType _templateParameterType = t_typeName; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbol.java deleted file mode 100644 index 106bba4d58a..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbol.java +++ /dev/null @@ -1,508 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.ObjectMap; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymbol { - - protected TemplateSymbol ( ParserSymbolTable table, char[] name ){ - super( table, name, ITypeInfo.t_template ); - } - - public Object clone(){ - TemplateSymbol copy = (TemplateSymbol)super.clone(); - - copy._defnParameterMap = ( _defnParameterMap != ObjectMap.EMPTY_MAP ) ? (ObjectMap)_defnParameterMap.clone() : _defnParameterMap; - copy._instantiations = ( _instantiations != ObjectMap.EMPTY_MAP ) ? (ObjectMap)_instantiations.clone() : _instantiations; - - return copy; - } - - public IContainerSymbol getTemplatedSymbol(){ - Iterator iter = getContentsIterator(); - if( iter.hasNext() ){ - IContainerSymbol contained = (IContainerSymbol) iter.next(); - return contained; - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#instantiate(java.util.List) - */ - public ISymbol instantiate( List arguments ) throws ParserSymbolTableException{ - if( getType() != ITypeInfo.t_template && - ( getType() != ITypeInfo.t_templateParameter || - getTypeInfo().getTemplateParameterType() != ITypeInfo.t_template ) ) - { - return null; - } - - ITemplateSymbol template = TemplateEngine.matchTemplatePartialSpecialization( this, arguments ); - - if( template != null && template instanceof ISpecializedSymbol ){ - return template.instantiate( arguments ); - } - - if( template == null ){ - template = this; - } - - List paramList = template.getParameterList(); - int numParams = ( paramList != null ) ? paramList.size() : 0; - int numArgs = arguments.size(); - - if( numParams == 0 ){ - return null; - } - - ObjectMap map = new ObjectMap( numParams ); - ISymbol param = null; - ITypeInfo arg = null; - List actualArgs = new ArrayList( numParams ); - - ISymbol templatedSymbol = template.getTemplatedSymbol(); - while( templatedSymbol != null && templatedSymbol.isTemplateInstance() ){ - templatedSymbol = templatedSymbol.getInstantiatedSymbol(); - } - - for( int i = 0; i < numParams; i++ ){ - param = (ISymbol) paramList.get(i); - - param = TemplateEngine.translateParameterForDefinition ( templatedSymbol, param, getDefinitionParameterMap() ); - - if( i < numArgs ){ - arg = (ITypeInfo) arguments.get(i); - //If the argument is a template parameter, we can't instantiate yet, defer for later - if( arg.isType( ITypeInfo.t_type ) ){ - if( arg.getTypeSymbol() == null ) - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument ); - else if( arg.getTypeSymbol().isType( ITypeInfo.t_templateParameter ) || - arg.getTypeSymbol() instanceof IDeferredTemplateInstance ) - return deferredInstance( arguments ); - } - } else { - Object obj = param.getTypeInfo().getDefault(); - if( obj != null && obj instanceof ITypeInfo ){ - arg = (ITypeInfo) obj; - if( arg.isType( ITypeInfo.t_type ) && arg.getTypeSymbol().isType( ITypeInfo.t_templateParameter ) ){ - if( map.containsKey( arg.getTypeSymbol() ) ){ - arg = (ITypeInfo) map.get( arg.getTypeSymbol() ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument ); - } - } else if( arg.isType( ITypeInfo.t_type ) && arg.getTypeSymbol() instanceof IDeferredTemplateInstance ){ - IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) arg.getTypeSymbol(); - arg = TypeInfoProvider.newTypeInfo( arg ); - arg.setTypeSymbol( deferred.instantiate( this, map ) ); -// // IDeferredTemplateInstance deferred = (IDeferredTemplateInstance) info.getTypeSymbol(); -// ITypeInfo newInfo = TypeInfoProvider.newTypeInfo( arg ); -// //newInfo.setTypeSymbol( deferred.instantiate( template, argMap ) ); -// template.registerDeferredInstatiation( newInfo, deferred, ITemplateSymbol.DeferredKind.TYPE_SYMBOL, map ); -// newInfo.setTypeSymbol( deferred ); -// // process any accumulated deferred instances, we may need them -// processDeferredInstantiations(); - } - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument ); - } - } - - if( TemplateEngine.matchTemplateParameterAndArgument( param, arg ) ){ - map.put( param, arg ); - actualArgs.add( arg ); - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateArgument ); - } - } - - IContainerSymbol instance = findInstantiation( actualArgs ); - if( instance != null ){ - return instance; - } - if( template.isType( ITypeInfo.t_templateParameter ) ){ - //template template parameter. must defer instantiation - return deferredInstance( arguments ); - } - - IContainerSymbol symbol = template.getTemplatedSymbol(); - ISymbol temp = TemplateEngine.checkForTemplateExplicitSpecialization( template, symbol, actualArgs ); - symbol = (IContainerSymbol) ( temp != null ? temp : symbol); - - instance = (IContainerSymbol) symbol.instantiate( template, map ); - addInstantiation( instance, actualArgs ); - - try{ - processDeferredInstantiations(); - } catch( ParserSymbolTableException e ){ - if( e.reason == ParserSymbolTableException.r_RecursiveTemplate ){ - //clean up some. - removeInstantiation( instance ); - } - throw e; - } - - return instance; - } - - public ISymbol instantiate( ITemplateSymbol template, ObjectMap argMap ) throws ParserSymbolTableException{ - if( !isTemplateMember() ){ - return null; - } - - TemplateSymbol newTemplate = (TemplateSymbol) super.instantiate( template, argMap ); - - //we don't want to instantiate the template parameters, just the defaults if there are any - List parameters = newTemplate.getParameterList(); - int size = parameters.size(); - ISymbol param = null; - for( int i = 0; i < size; i++ ){ - param = (ISymbol) parameters.get(i); - Object obj = param.getTypeInfo().getDefault(); - if( obj instanceof ITypeInfo ){ - param.getTypeInfo().setDefault( TemplateEngine.instantiateTypeInfo( (ITypeInfo) obj, template, argMap ) ); - } - } - - return newTemplate; - } - - public void addParameter( ISymbol param ) { - throw new ParserSymbolTableError( ParserSymbolTableError.r_OperationNotSupported ); - } - - public void addTemplateParameter( ISymbol param ) throws ParserSymbolTableException { - if( isType( ITypeInfo.t_template ) || getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template ){ - if( !isAllowableTemplateParameter( param ) ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplateParameter ); - } - modifyTemplateParameter( param ); - } - - super.addParameter( param ); - } - - private boolean isAllowableTemplateParameter( ISymbol param ) { - if( !param.isType( ITypeInfo.t_templateParameter ) ) - return false; - - if( !CharArrayUtils.equals( getName(), ParserSymbolTable.EMPTY_NAME_ARRAY ) && - CharArrayUtils.equals( param.getName(), getName() ) ) - { - return false; - } - - if( param.getTypeInfo().getTemplateParameterType() != ITypeInfo.t_typeName && - param.getTypeInfo().getTemplateParameterType() != ITypeInfo.t_template ) - { - ITypeInfo info = param.getTypeInfo(); - //a non-type template parameter shall have one of the following: - //integral or enumeration type - //pointer to object or pointer to function - //reference to object or reference to function - //pointer to member - - //14.1-7 - //A non-type template-parameter shall not be declared to have floating point, class or void type - if( info.getPtrOperators().size() == 0 ) - if( info.getTemplateParameterType() == ITypeInfo.t_float || - info.getTemplateParameterType() == ITypeInfo.t_double || - info.getTemplateParameterType() == ITypeInfo.t_class || - info.getTemplateParameterType() == ITypeInfo.t_struct || - info.getTemplateParameterType() == ITypeInfo.t_union || - info.getTemplateParameterType() == ITypeInfo.t_enumeration || - info.getTemplateParameterType() == ITypeInfo.t_void ) - { - return false; - } - } - return true; - } - - private void modifyTemplateParameter( ISymbol param ){ - List ptrs = param.getPtrOperators(); - if( ptrs.size() > 0 ){ - ITypeInfo.PtrOp op = (ITypeInfo.PtrOp) ptrs.get( 0 ); - if( op.getType() == ITypeInfo.PtrOp.t_array ){ - op.setType( ITypeInfo.PtrOp.t_pointer ); - } - } else if ( param.isType( ITypeInfo.t_type ) && param.getTypeSymbol().isType( ITypeInfo.t_function ) ){ - param.addPtrOperator( new ITypeInfo.PtrOp( ITypeInfo.PtrOp.t_pointer ) ); - } - } - - - - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#hasSpecializations() - */ - public boolean hasSpecializations(){ - return !_specializations.isEmpty(); - } - - public void addExplicitSpecialization( ISymbol symbol, List args ) throws ParserSymbolTableException{ - - List actualArgs = TemplateEngine.verifyExplicitArguments( this, args, symbol ); - - if( _explicitSpecializations == ObjectMap.EMPTY_MAP ) - _explicitSpecializations = new ObjectMap(2); - - ObjectMap specs = null; - List key = null; - - for( int i = 0; i < _explicitSpecializations.size(); i++ ){ - List list = (List) _explicitSpecializations.keyAt( i ); - if( list.equals( args ) ){ - key = list; - break; - } - } - - if( key != null ){ - specs = (ObjectMap) _explicitSpecializations.get( key ); - } else { - specs = new ObjectMap(2); - _explicitSpecializations.put( new ArrayList( actualArgs ), specs ); - } - - ISymbol found = null; - try{ - if( symbol.isType( ITypeInfo.t_function ) || symbol.isType( ITypeInfo.t_constructor ) ){ - List params = ((IParameterizedSymbol) symbol).getParameterList(); - int size = params.size(); - List fnArgs = new ArrayList( size ); - for( int i = 0; i < size; i++){ - fnArgs.add( ((ISymbol)params.get(i)).getTypeInfo() ); - } - found = getTemplatedSymbol().lookupMethodForDefinition( symbol.getName(), fnArgs ); - } else { - found = getTemplatedSymbol().lookupMemberForDefinition( symbol.getName() ); - } - } catch (ParserSymbolTableException e) { - /* nothing */ - } - if( found == null && CharArrayUtils.equals( getTemplatedSymbol().getName(), symbol.getName() ) ){ - found = getTemplatedSymbol(); - - IContainerSymbol instance = findInstantiation( actualArgs ); - if( instance != null ){ - _instantiations.remove( findArgumentsFor( instance ) ); - } - } - - if( found != null ){ - //in defining the explicit specialization for a member function, the factory would have set - //the specialization as the definition of the original declaration, which it is not - if( found.isForwardDeclaration() && found.getForwardSymbol() == symbol ) - found.setForwardSymbol( null ); - - //TODO, once we can instantiate members as we need them instead of at the same time as the class - //then found should stay as the instance, for now though, we need the original (not 100% correct - //but the best we can do for now) - while( found.isTemplateInstance() ){ - found = found.getInstantiatedSymbol(); - } - } - - if( found != null ){ - symbol.setIsTemplateMember( true ); - symbol.setContainingSymbol( found.getContainingSymbol() ); - specs.put( found, symbol ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addSpecialization(org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol) - */ - public void addSpecialization( ISpecializedSymbol spec ){ - if( _specializations == Collections.EMPTY_LIST ) - _specializations = new ArrayList(4); - - _specializations.add( spec ); - - spec.setContainingSymbol( getContainingSymbol() ); - spec.setPrimaryTemplate( this ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#getSpecializations() - */ - public List getSpecializations() { - return _specializations; - } - - public void addInstantiation( IContainerSymbol instance, List args ){ - List key = new ArrayList( args ); - if( _instantiations == ObjectMap.EMPTY_MAP ){ - _instantiations = new ObjectMap(2); - } - _instantiations.put( key, instance ); - } - - public IContainerSymbol findInstantiation( List arguments ){ - if( _instantiations == ObjectMap.EMPTY_MAP ){ - return null; - } - - //TODO: we could optimize this by doing something other than a linear search. - int size = _instantiations.size(); - List args = null; - for( int i = 0; i < size; i++ ){ - args = (List) _instantiations.keyAt(i); - - if( args.equals( arguments ) ){ - return (IContainerSymbol) _instantiations.get( args ); - } - } - return null; - } - - public List findArgumentsFor( IContainerSymbol instance ){ - if( instance == null || !instance.isTemplateInstance() ) - return null; - -// ITemplateSymbol template = (ITemplateSymbol) instance.getInstantiatedSymbol().getContainingSymbol(); -// if( template != this ) -// return null; - - int size = _instantiations.size(); - for( int i = 0; i < size; i++){ - List args = (List) _instantiations.keyAt( i ); - if( _instantiations.get( args ) == instance ){ - return args; - } - } - - return null; - } - - public void removeInstantiation( IContainerSymbol symbol ){ - List args = findArgumentsFor( symbol ); - if( args != null ){ - _instantiations.remove( args ); - } - } - - public ObjectMap getDefinitionParameterMap(){ - return _defnParameterMap; - } - - protected void addToDefinitionParameterMap( ISymbol newSymbol, ObjectMap defnMap ){ - if( _defnParameterMap == ObjectMap.EMPTY_MAP ) - _defnParameterMap = new ObjectMap(2); - _defnParameterMap.put( newSymbol, defnMap ); - } - - public IDeferredTemplateInstance deferredInstance( List args ){ - return new DeferredTemplateInstance( getSymbolTable(), this, args ); - } - - public ObjectMap getExplicitSpecializations() { - return _explicitSpecializations; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#registerDeferredInstatiation(org.eclipse.cdt.internal.core.parser.pst.ParameterizedSymbol, org.eclipse.cdt.internal.core.parser.pst.ISymbol, org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol.DeferredKind) - */ - public void registerDeferredInstatiation( Object obj0, Object obj1, DeferredKind kind, ObjectMap argMap ) { - if( _deferredInstantiations == Collections.EMPTY_LIST ) - _deferredInstantiations = new ArrayList(8); - - _deferredInstantiations.add( new Object [] { obj0, obj1, kind, argMap } ); - } - - public int getNumberDeferredInstantiations(){ - return _deferredInstantiations.size(); - } - - protected void processDeferredInstantiations() throws ParserSymbolTableException{ - if( _deferredInstantiations == Collections.EMPTY_LIST ) - return; - - if( _processingDeferred ){ - return; - } - _processingDeferred = true; - int numDeferred = _deferredInstantiations.size(); - int numProcessed = 0; - int loopCount = 0; - while( numDeferred > numProcessed ){ - for( int i = numProcessed; i < numDeferred; i++ ){ - Object [] objs = (Object [])_deferredInstantiations.get(i); - - DeferredKind kind = (DeferredKind) objs[2]; - - if( kind == DeferredKind.PARENT ){ - DerivableContainerSymbol d = (DerivableContainerSymbol) objs[0]; - d.instantiateDeferredParent( (ISymbol) objs[ 1 ], this, (ObjectMap) objs[3] ); - } else if( kind == DeferredKind.RETURN_TYPE ){ - ParameterizedSymbol p = (ParameterizedSymbol) objs[0]; - p.instantiateDeferredReturnType( (ISymbol) objs[1], this, (ObjectMap) objs[3] ); - } else if( kind == DeferredKind.TYPE_SYMBOL ){ - TemplateEngine.instantiateDeferredTypeInfo( (ITypeInfo) objs[0], this, (ObjectMap) objs[3] ); - } - numProcessed++; - } - numDeferred = _deferredInstantiations.size(); - if( ++loopCount > ParserSymbolTable.TEMPLATE_LOOP_THRESHOLD ){ - discardDeferredInstantiations(); - _processingDeferred = false; - throw new ParserSymbolTableException( ParserSymbolTableException.r_RecursiveTemplate ); - } - } - _deferredInstantiations.clear(); - _processingDeferred = false; - } - - private void discardDeferredInstantiations(){ - int size = _deferredInstantiations.size(); - for( int i = 0; i < size; i++ ){ - Object [] objs = (Object []) _deferredInstantiations.get(i); - - DeferredKind kind = (DeferredKind) objs[2]; - - if( kind == DeferredKind.PARENT ){ - DerivableContainerSymbol d = (DerivableContainerSymbol) objs[0]; - d.discardDeferredParent( (IDeferredTemplateInstance) objs[1], this, (ObjectMap) objs[3] ); - } else if( kind == DeferredKind.RETURN_TYPE ){ - ParameterizedSymbol p = (ParameterizedSymbol) objs[0]; - p.discardDeferredReturnType( (ISymbol) objs[1], this, (ObjectMap) objs[3] ); - } else if( kind == DeferredKind.TYPE_SYMBOL ){ - TemplateEngine.discardDeferredTypeInfo( (ITypeInfo) objs[0], this, (ObjectMap) objs[3] ); - } - } - _deferredInstantiations.clear(); - } - - private List _specializations = Collections.EMPTY_LIST; //template specializations - private ObjectMap _explicitSpecializations = ObjectMap.EMPTY_MAP; //explicit specializations - private ObjectMap _defnParameterMap = ObjectMap.EMPTY_MAP; //members could be defined with different template parameter names - private ObjectMap _instantiations = ObjectMap.EMPTY_MAP; - private List _deferredInstantiations = Collections.EMPTY_LIST; //used to avoid recursive loop - private boolean _processingDeferred = false; - - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbolExtension.java deleted file mode 100644 index 3c2c4d1e3e4..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TemplateSymbolExtension.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Mar 15, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; - -/** - * @author aniefer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -public class TemplateSymbolExtension extends StandardSymbolExtension { - - protected ISymbol replacement = null; - - /** - * @param symbol - * @param primaryDeclaration - */ - public TemplateSymbolExtension(ISymbol symbol, ASTSymbol primaryDeclaration) { - super(symbol, primaryDeclaration); - } - - /** - * @param spec - */ - public void replaceSymbol(ISpecializedSymbol spec) { - replacement = spec; - spec.setASTExtension( this ); - } - - public ISymbol getSymbol(){ - return ( replacement == null ) ? super.getSymbol() : replacement; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java deleted file mode 100644 index 08a2a2b23cb..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.parser.pst; - -import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind; -import org.eclipse.cdt.core.parser.util.ObjectSet; - -/** - * @author aniefer - */ -public class TypeFilter { - - public TypeFilter(){ - //empty - } - - public TypeFilter( ITypeInfo.eType type ){ - acceptedTypes.put( type ); - } - - public TypeFilter( LookupKind kind ){ - acceptedKinds.put( kind ); - populatedAcceptedTypes( kind ); - } - - public void addAcceptedType( ITypeInfo.eType type ){ - acceptedTypes.put( type ); - } - - public void addAcceptedType( LookupKind kind ) { - populatedAcceptedTypes( kind ); - acceptedKinds.put( kind ); - } - - public boolean willAccept( ITypeInfo.eType type ){ - return( acceptedTypes.containsKey( ITypeInfo.t_any ) || - acceptedTypes.containsKey( type ) ); - } - - public boolean shouldAccept( ISymbol symbol ){ - return shouldAccept( symbol, symbol.getTypeInfo() ); - } - public boolean shouldAccept( ISymbol symbol, ITypeInfo typeInfo ){ - if( acceptedTypes.containsKey( ITypeInfo.t_any ) ){ - return true; - } - - if( acceptedKinds.isEmpty() ){ - return acceptedTypes.containsKey( typeInfo.getType() ); - } - - IContainerSymbol container = symbol.getContainingSymbol(); - - boolean symbolIsMember = container.isType( ITypeInfo.t_class, ITypeInfo.t_union ); - boolean symbolIsLocal = container.isType( ITypeInfo.t_constructor, ITypeInfo.t_function ) || - container.isType( ITypeInfo.t_block ); - - if( typeInfo.isType( ITypeInfo.t_function ) ) - { - if( ( acceptedKinds.containsKey( LookupKind.FUNCTIONS ) && !symbolIsMember ) || - ( acceptedKinds.containsKey( LookupKind.METHODS ) && symbolIsMember ) || - ( acceptedKinds.containsKey( LookupKind.MEMBERS ) && symbolIsMember ) ) - { - return true; - } - return false; - } - else if ( typeInfo.isType( ITypeInfo.t_type ) && typeInfo.checkBit( ITypeInfo.isTypedef ) ){ - if( acceptedKinds.containsKey( LookupKind.TYPEDEFS ) || - acceptedKinds.containsKey( LookupKind.TYPES ) ) - { - return true; - } - return false; - } - else if ( typeInfo.isType( ITypeInfo.t_type ) || typeInfo.isType( ITypeInfo.t__Bool, ITypeInfo.t_void ) ) - { - if( ( acceptedKinds.containsKey( LookupKind.VARIABLES ) && !symbolIsMember && !symbolIsLocal ) || - ( acceptedKinds.containsKey( LookupKind.LOCAL_VARIABLES ) && !symbolIsMember && symbolIsLocal ) || - ( acceptedKinds.containsKey( LookupKind.FIELDS ) && symbolIsMember ) || - ( acceptedKinds.containsKey( LookupKind.MEMBERS ) && symbolIsMember ) ) - { - return true; - } - return false; - } - else - { - return acceptedTypes.containsKey( typeInfo.getType() ); - } - } - - /** - * @param lookupKind - */ - private void populatedAcceptedTypes(LookupKind kind) { - if ( kind == LookupKind.ALL ) { acceptedTypes.put( ITypeInfo.t_any ); } - else if ( kind == LookupKind.STRUCTURES ) { acceptedTypes.put( ITypeInfo.t_class ); - acceptedTypes.put( ITypeInfo.t_struct ); - acceptedTypes.put( ITypeInfo.t_union ); } - else if ( kind == LookupKind.STRUCTS ) { acceptedTypes.put( ITypeInfo.t_struct ); } - else if ( kind == LookupKind.UNIONS ) { acceptedTypes.put( ITypeInfo.t_union ); } - else if ( kind == LookupKind.CLASSES ) { acceptedTypes.put( ITypeInfo.t_class ); } - else if ( kind == LookupKind.CONSTRUCTORS ){ acceptedTypes.put( ITypeInfo.t_constructor ); } - else if ( kind == LookupKind.NAMESPACES ) { acceptedTypes.put( ITypeInfo.t_namespace ); } - else if ( kind == LookupKind.ENUMERATIONS ){ acceptedTypes.put( ITypeInfo.t_enumeration ); } - else if ( kind == LookupKind.ENUMERATORS ) { acceptedTypes.put( ITypeInfo.t_enumerator ); } -// else if ( kind == LookupKind.TYPEDEFS ) { acceptedTypes.put( TypeInfo.t_type ); } - else if ( kind == LookupKind.TYPES ) { acceptedTypes.put( ITypeInfo.t_class ); - acceptedTypes.put( ITypeInfo.t_struct ); - acceptedTypes.put( ITypeInfo.t_union ); - acceptedTypes.put( ITypeInfo.t_enumeration ); } - - } - - public void setLookingInThis( boolean inThis ){ - lookingInThis = inThis; - } - public boolean isLookingInThis(){ - return lookingInThis; - } - - private ObjectSet acceptedTypes = new ObjectSet(2); - private ObjectSet acceptedKinds = new ObjectSet(2); - - private boolean lookingInThis = false; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java deleted file mode 100644 index 612cbdfbb7d..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfo.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - - -public class TypeInfo extends BasicTypeInfo implements ITypeInfo{ - public TypeInfo(){ - super(); - } - - public ISymbol getTypeSymbol() { - return _typeDeclaration; - } - - public void setTypeSymbol( ISymbol type ) { - _typeDeclaration = type; - } - - public boolean getHasDefault() { - return _hasDefaultValue; - } - - public void setHasDefault( boolean def ) { - _hasDefaultValue = def; - } - - public void clear() { - super.clear(); - _typeDeclaration = null; - _hasDefaultValue = false; - } - - public void copy( ITypeInfo t ) { - super.copy( t ); - _typeDeclaration = t.getTypeSymbol(); - _hasDefaultValue = t.getHasDefault(); - } - - public boolean equals( Object t ) { - if( !super.equals( t ) ){ - return false; - } - - ITypeInfo type = (ITypeInfo)t; - - boolean result = true; - ISymbol symbol = type.getTypeSymbol(); - if( _typeDeclaration != null && symbol != null ){ - if( _typeDeclaration.isType( t__Bool, t_void ) && - symbol.isType( t__Bool, t_void ) ) - { - //if typeDeclaration is a basic type, then only need the types the same - result &= ( _typeDeclaration.getType() == symbol.getType() ); - } else if( _typeDeclaration.isType( t_function ) && - symbol.isType( t_function ) ) - { - //function pointers... functions must have same parameter lists and return types - IParameterizedSymbol f1 = (IParameterizedSymbol) _typeDeclaration; - IParameterizedSymbol f2 = (IParameterizedSymbol) symbol; - - result &= f1.hasSameParameters( f2 ); - if( f1.getReturnType() != null && f2.getReturnType() != null ) - result &= f1.getReturnType().getTypeInfo().equals( f2.getReturnType().getTypeInfo() ); - else - result &= (f1.getReturnType() == f2.getReturnType()); - } else if( _typeDeclaration.isType( t_templateParameter ) && - symbol.isType( t_templateParameter ) ) - { - //template parameters - result &= TemplateEngine.templateParametersAreEquivalent( _typeDeclaration, symbol ); - } else if ( _typeDeclaration instanceof IDeferredTemplateInstance && - symbol instanceof IDeferredTemplateInstance ) - { - result &= TemplateEngine.deferedInstancesAreEquivalent( (IDeferredTemplateInstance) _typeDeclaration, (IDeferredTemplateInstance)symbol ); - }else { - //otherwise, its a user defined type, need the decls the same - result &= ( _typeDeclaration == symbol ); - } - } else { - result &= ( _typeDeclaration == symbol ); - } - return result; - } - - private ISymbol _typeDeclaration = null; - private boolean _hasDefaultValue = false; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfoProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfoProvider.java deleted file mode 100644 index bd34c8b79d2..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/TypeInfoProvider.java +++ /dev/null @@ -1,282 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Jul 5, 2004 - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo.PtrOp; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo.eType; - - -public class TypeInfoProvider -{ - private static final int BASIC = 0; - private static final int TYPE = 1; - private static final int TEMPLATE = 2; - private static final int POOL_SIZE = 16; - - private final ITypeInfo [][] pool; - private final boolean [][] free; - private final int [] firstFreeHint; - - protected TypeInfoProvider() - { - - pool = new ITypeInfo[POOL_SIZE][3]; - free = new boolean [POOL_SIZE][3]; - firstFreeHint = new int [] { 0, 0, 0 }; - - for( int i = 0; i < POOL_SIZE; i++ ) - { - pool[i] = new ITypeInfo[] { newInfo( ITypeInfo.t_void, true ), - newInfo( ITypeInfo.t_type, true ), - newInfo( ITypeInfo.t_templateParameter, true ) }; - free[i] = new boolean [] { true, true, true }; - } - } - - public ITypeInfo getTypeInfo( eType t ) - { - int idx = BASIC; - if( t == ITypeInfo.t_type || t == ITypeInfo.t_enumerator ) - idx = TYPE; - else if( t == ITypeInfo.t_templateParameter ) - idx = TEMPLATE; - - ITypeInfo returnType = null; - for( int i = firstFreeHint[idx]; i < POOL_SIZE; ++i ) - { - if( free[i][idx] ) - { - free[i][idx] = false; - firstFreeHint[idx] = i + 1; - returnType = pool[i][idx]; - break; - } - } - if( returnType == null ){ - //if there is nothing free, just give them a new one - if( t == ITypeInfo.t_type ){ - returnType = new TypeInfo(); - } else if( t == ITypeInfo.t_templateParameter ) { - returnType = new TemplateParameterTypeInfo(); - } else { - returnType = new BasicTypeInfo(); - } - } - - returnType.setType( t ); - return returnType; - } - - public void returnTypeInfo( ITypeInfo t ) - { - int idx = BASIC; - if( t instanceof TemplateParameterTypeInfo ) - idx = TEMPLATE; - else if ( t instanceof TypeInfo ) - idx = TYPE; - - for( int i = 0; i < POOL_SIZE; i++ ){ - if( pool[i][idx] == t ){ - t.clear(); - free[i][idx] = true; - if( i < firstFreeHint[idx] ){ - firstFreeHint[idx] = i; - } - return; - } - } - //else it was one allocated outside the pool - } - - public int numAllocated(){ - int num = 0; - for( int i = 0; i < POOL_SIZE; i++ ){ - num += ( free[i][0] ? 0 : 1 ) + - ( free[i][1] ? 0 : 1 ) + - ( free[i][2] ? 0 : 1 ); - } - return num; - } - - /** - * @param topInfo - * @return - */ - static final public ITypeInfo newTypeInfo( ITypeInfo topInfo ) { - ITypeInfo newInfo = newInfo( topInfo.getType(), topInfo.getDefault() != null ); - - newInfo.copy( topInfo ); - return newInfo; - } - - /** - * - * @param type - * @param bits - * @param typeSymbol - * @param ptrOp - * @param hasDefault - * @return - */ - static final public ITypeInfo newTypeInfo( eType type, int bits, ISymbol typeSymbol, PtrOp ptrOp, boolean hasDefault ) { - ITypeInfo newInfo = newTypeInfo( type, bits, ptrOp, hasDefault ); - newInfo.setTypeSymbol( typeSymbol ); - return newInfo; - } - - /** - * - * @param type - * @param bits - * @param typeSymbol - * @return - */ - static final public ITypeInfo newTypeInfo( eType type, int bits, ISymbol typeSymbol ) { - ITypeInfo newInfo = newTypeInfo( type ); - newInfo.setTypeBits( bits ); - newInfo.setTypeSymbol( typeSymbol ); - return newInfo; - } - - /** - * - * @param type - * @param bits - * @param ptrOp - * @param hasDefault - * @return - */ - static final public ITypeInfo newTypeInfo( eType type, int bits, PtrOp ptrOp, boolean hasDefault ) { - ITypeInfo newInfo = newTypeInfo( type ); - newInfo.setTypeBits( bits ); - newInfo.addPtrOperator( ptrOp ); - newInfo.setHasDefault( hasDefault ); - return newInfo; - } - - /** - * @param typeInfo - * @return - */ - static final public ITypeInfo newTypeInfo( eType type ) { - ITypeInfo newInfo = newInfo( type, false ); - newInfo.setType( type ); - return newInfo; - } - - /** - * - * @param type - * @param bits - * @param symbol - * @param op - * @param def - * @return - */ - public final static ITypeInfo newTypeInfo( eType type, int bits, ISymbol symbol, PtrOp op, Object def ) { - ITypeInfo newInfo = newInfo( type, def != null ); - - newInfo.setType( type ); - newInfo.setTypeBits( bits ); - newInfo.setDefault( def ); - newInfo.setTypeSymbol( symbol ); - newInfo.addPtrOperator( op ); - return newInfo; - } - /** - * @return - */ - public final static ITypeInfo newTypeInfo() { - return new BasicTypeInfo(); - } - - /** - * Functions for constructing a Type info a piece at a time. - */ - private eType type; - private ISymbol typeSymbol; - private int bits; - private Object defaultObj; - private boolean hasDef; - private eType templateParamType; - - public void setType( eType t ) { type = t; } - public void setTypeSymbol( ISymbol s ) { typeSymbol = s; } - public void setTypeBits( int b ) { bits = b; } - public void setHasDef( boolean b ) { hasDef = b; } - public void setDefaultObj( Object obj ) { defaultObj = obj; } - public void setTemplateParameterType( eType t ) { templateParamType = t; } - - public void setBit( boolean b, int mask ) { - if( b ) bits = bits | mask; - else bits = bits & ~mask; - } - - public void beginTypeConstruction(){ - type = ITypeInfo.t_undef; - typeSymbol = null; - bits = 0; - defaultObj = null; - templateParamType = null; - hasDef = false; - } - - public ITypeInfo completeConstruction(){ - ITypeInfo newInfo = newTypeInfo( type, bits, typeSymbol, null, defaultObj ); - newInfo.setHasDefault( hasDef ); - if( templateParamType != null ) - newInfo.setTemplateParameterType( templateParamType ); - - //clear the fields - beginTypeConstruction(); - return newInfo; - } - - private final static ITypeInfo newInfo( eType type, boolean def ){ - ITypeInfo newInfo = null; - if( type == ITypeInfo.t_type || type == ITypeInfo.t_enumerator ){ - if( def ) - newInfo = new TypeInfo(){ - public void copy( ITypeInfo t ) { super.copy( t ); _defObj = t.getDefault(); } - public void setDefault( Object t ) { _defObj = t; } - public Object getDefault() { return _defObj;} - private Object _defObj; - }; - else - newInfo = new TypeInfo(); - } else if( type == ITypeInfo.t_templateParameter ){ - if( def ) - newInfo = new TemplateParameterTypeInfo(){ - public void copy( ITypeInfo t ) { super.copy( t ); _defObj = t.getDefault(); } - public void setDefault( Object t ) { _defObj = t; } - public Object getDefault() { return _defObj;} - private Object _defObj; - }; - else - newInfo = new TemplateParameterTypeInfo(); - } else { - if( def ) - newInfo = new BasicTypeInfo(){ - public void copy( ITypeInfo t ) { super.copy( t ); _defObj = t.getDefault(); } - public void setDefault( Object t ) { _defObj = t; } - public Object getDefault() { return _defObj;} - private Object _defObj; - }; - else - newInfo = new BasicTypeInfo(); - } - return newInfo; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UndefinedTemplateSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UndefinedTemplateSymbol.java deleted file mode 100644 index 0b3f6d1fd6e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UndefinedTemplateSymbol.java +++ /dev/null @@ -1,756 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.core.parser.util.ObjectMap; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo.PtrOp; -import org.eclipse.cdt.internal.core.parser.pst.ITypeInfo.eType; -import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable.LookupData; - -/** - * A symbol type representing a template parameter as a scope - * example: - * template - * class A { - * typedef typename T::some_type some_type; - * }; - * - * Actual template argument is expected to have type 'some_type' but - * that cannot be confirmed until the templated class is instantiated. - * A symbol that represents T requires some behaviour of IContainerSymbol. - * 'some_type' symbol will be added to this container as an unknown type - * so that at the time of instantiation it can be replaced with real type symbol. - * - * @author vhirsl - */ -public class UndefinedTemplateSymbol extends BasicSymbol implements ITemplateSymbol { - - // ContainerSymbol - private List _contents = Collections.EMPTY_LIST; //ordered list of all contents of this symbol - private CharArrayObjectMap _containedSymbols = CharArrayObjectMap.EMPTY_MAP; //declarations contained by us. -// private List _usingDirectives = Collections.EMPTY_LIST; //collection of nominated namespaces - // TemplateSymbol - // these are actually arguments in case of - // typedef typename T::template B::some_type some_type; - // ^ ^^^^ - private List _argumentList = Collections.EMPTY_LIST; //list of template arguments - private ObjectMap _instantiations = ObjectMap.EMPTY_MAP; - - /** - * @param table - * @param name - */ - public UndefinedTemplateSymbol(ParserSymbolTable table, char[] name) { - super(table, name); - } - - /** - * @param table - * @param name - * @param typeInfo - */ - public UndefinedTemplateSymbol(ParserSymbolTable table, char[] name, eType typeInfo) { - super(table, name, typeInfo); - } - - public Object clone() { - UndefinedTemplateSymbol copy = (UndefinedTemplateSymbol) super.clone(); - - copy._containedSymbols = (CharArrayObjectMap) ( ( _containedSymbols != CharArrayObjectMap.EMPTY_MAP )? _containedSymbols.clone() : _containedSymbols ); - copy._contents = (_contents != Collections.EMPTY_LIST) ? (List) ((ArrayList)_contents).clone() : _contents; - - copy._instantiations = ( _instantiations != ObjectMap.EMPTY_MAP ) ? (ObjectMap)_instantiations.clone() : _instantiations; - copy._argumentList = ( _argumentList != Collections.EMPTY_LIST ) ? (List) ((ArrayList)_argumentList).clone() : _argumentList; - - return copy; - } - - /* - * IContainerSymbol -------------------------------------------------------- - */ - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addSymbol(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void addSymbol(ISymbol obj) throws ParserSymbolTableException { - IContainerSymbol containing = this; - - // We are expecting another UTS - if ( ! ( obj instanceof UndefinedTemplateSymbol) ) { - throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError ); - } - - obj.setContainingSymbol( containing ); - ((UndefinedTemplateSymbol)containing).putInContainedSymbols( obj.getName(), obj ); - obj.setIsTemplateMember( isTemplateMember() || getType() == ITypeInfo.t_template ); - - addToContents( obj ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addTemplateId(org.eclipse.cdt.internal.core.parser.pst.ISymbol, java.util.List) - */ - public void addTemplateId(ISymbol symbol, List args) throws ParserSymbolTableException { - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTemplate ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#hasUsingDirectives() - */ - public boolean hasUsingDirectives() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getUsingDirectives() - */ - public List getUsingDirectives() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDirective(org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) - */ - public IUsingDirectiveSymbol addUsingDirective(IContainerSymbol namespace) throws ParserSymbolTableException { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDeclaration(char[]) - */ - public IUsingDeclarationSymbol addUsingDeclaration(char[] name) - throws ParserSymbolTableException { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDeclaration(char[], org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) - */ - public IUsingDeclarationSymbol addUsingDeclaration(char[] name, - IContainerSymbol declContext) throws ParserSymbolTableException { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getContainedSymbols() - */ - public CharArrayObjectMap getContainedSymbols() { - return _containedSymbols; - } - - protected void putInContainedSymbols( char[] key, Object obj ){ - if( _containedSymbols == CharArrayObjectMap.EMPTY_MAP ){ - _containedSymbols = new CharArrayObjectMap( 4 ); - } - _containedSymbols.put( key, obj ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#prefixLookup(org.eclipse.cdt.internal.core.parser.pst.TypeFilter, char[], boolean, java.util.List) - */ - public List prefixLookup(TypeFilter filter, char[] prefix, boolean qualified, List paramList) throws ParserSymbolTableException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#elaboratedLookup(org.eclipse.cdt.internal.core.parser.pst.ITypeInfo.eType, char[]) - */ - public ISymbol elaboratedLookup(final eType type, char[] name) throws ParserSymbolTableException { - LookupData data = new LookupData( name ){ - public TypeFilter getFilter() { - if( t == ITypeInfo.t_any ) return ANY_FILTER; - if( filter == null ) filter = new TypeFilter( t ); - return filter; - } - private TypeFilter filter = null; - private final ITypeInfo.eType t = type; - }; - - ParserSymbolTable.lookup( data, this ); - - ISymbol found = getSymbolTable().resolveAmbiguities( data ); - - if( isTemplateMember() && found instanceof ITemplateSymbol ) { - boolean areWithinTemplate = false; - IContainerSymbol container = getContainingSymbol(); - while( container != null ){ - if( container == found ){ - areWithinTemplate = true; - break; - } - container = container.getContainingSymbol(); - } - if( areWithinTemplate ) - return TemplateEngine.instantiateWithinTemplateScope( this, (ITemplateSymbol) found ); - } - - return found; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookup(char[]) - */ - public ISymbol lookup(char[] name) throws ParserSymbolTableException { - LookupData data = new LookupData( name ); - - ParserSymbolTable.lookup( data, this ); - - ISymbol found = getSymbolTable().resolveAmbiguities( data ); - - if( isTemplateMember() && found instanceof ITemplateSymbol ) { - return TemplateEngine.instantiateWithinTemplateScope( this, (ITemplateSymbol) found ); - } - - if (found == null && getTypeInfo() instanceof TemplateParameterTypeInfo) { - // add a symbol as an expected type to a template parameter - found = getSymbolTable().newUndefinedTemplateSymbol(name, ITypeInfo.t_undef); - addSymbol(found); - } - - return found; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupMemberForDefinition(char[]) - */ - public ISymbol lookupMemberForDefinition(char[] name, ITypeInfo.eType type) throws ParserSymbolTableException { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupMemberForDefinition(char[]) - */ - public ISymbol lookupMemberForDefinition(char[] name) throws ParserSymbolTableException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupMethodForDefinition(char[], java.util.List) - */ - public IParameterizedSymbol lookupMethodForDefinition(char[] name, List parameters) throws ParserSymbolTableException { - // TODO Auto-generated method stub - return null; - } - - /** - * The name of a class or namespace member can be referred to after the :: - * scope resolution operator applied to a nested-name-specifier that - * nominates its class or namespace. During the lookup for a name preceding - * the ::, object, function and enumerator names are ignored. If the name - * is not a class-name or namespace-name, the program is ill-formed - */ - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupNestedNameSpecifier(char[]) - */ - public ISymbol lookupNestedNameSpecifier(char[] name) throws ParserSymbolTableException { - return lookupNestedNameSpecifier( name, this ); - } - - private ISymbol lookupNestedNameSpecifier(char[] name, IContainerSymbol inSymbol ) throws ParserSymbolTableException{ - ISymbol foundSymbol = null; - - final TypeFilter filter = new TypeFilter( ITypeInfo.t_namespace ); - filter.addAcceptedType( ITypeInfo.t_class ); - filter.addAcceptedType( ITypeInfo.t_struct ); - filter.addAcceptedType( ITypeInfo.t_union ); - filter.addAcceptedType( ITypeInfo.t_templateParameter ); - filter.addAcceptedType( IASTNode.LookupKind.TYPEDEFS ); - - LookupData data = new LookupData( name ){ - public TypeFilter getFilter() { return typeFilter; } - final private TypeFilter typeFilter = filter; - }; - data.qualified = true; - ParserSymbolTable.lookup( data, inSymbol ); - - if( data.foundItems != null ){ - foundSymbol = getSymbolTable().resolveAmbiguities( data ); - } - - // another undefined symbol i.e.: - // template class A { - // typedef typename T::R::some_type some_type; - // }; ^ - if (foundSymbol == null && getTypeInfo() instanceof TemplateParameterTypeInfo) { - // add a symbol as an expected type to a template parameter - foundSymbol = getSymbolTable().newUndefinedTemplateSymbol(name, ITypeInfo.t_undef); - addSymbol(foundSymbol); - } - - return foundSymbol; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#qualifiedLookup(char[]) - */ - public ISymbol qualifiedLookup(char[] name) throws ParserSymbolTableException { - LookupData data = new LookupData( name ); - data.qualified = true; - ParserSymbolTable.lookup( data, this ); - - ISymbol found = getSymbolTable().resolveAmbiguities( data ); - - if (found == null) { - // add a symbol as an expected type to a template parameter - found = getSymbolTable().newUndefinedTemplateSymbol(name, ITypeInfo.t_undef); - addSymbol(found); - } - return found; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#qualifiedLookup(char[], org.eclipse.cdt.internal.core.parser.pst.ITypeInfo.eType) - */ - public ISymbol qualifiedLookup(char[] name, final ITypeInfo.eType t) throws ParserSymbolTableException { - LookupData data = new LookupData( name ){ - public TypeFilter getFilter() { - if( t == ITypeInfo.t_any ) return ANY_FILTER; - - if( filter == null ) - filter = new TypeFilter( t ); - return filter; - - } - private TypeFilter filter = null; - }; - data.qualified = true; - ParserSymbolTable.lookup( data, this ); - - ISymbol found = getSymbolTable().resolveAmbiguities( data ); - - if (found == null) { - // add a symbol as an expected type to a template parameter - found = getSymbolTable().newUndefinedTemplateSymbol(name, ITypeInfo.t_undef); - addSymbol(found); - } - return found; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#unqualifiedFunctionLookup(char[], java.util.List) - */ - public IParameterizedSymbol unqualifiedFunctionLookup(char[] name, List parameters) throws ParserSymbolTableException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#memberFunctionLookup(char[], java.util.List) - */ - public IParameterizedSymbol memberFunctionLookup(char[] name, List parameters) throws ParserSymbolTableException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#qualifiedFunctionLookup(char[], java.util.List) - */ - public IParameterizedSymbol qualifiedFunctionLookup(char[] name, List parameters) throws ParserSymbolTableException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupTemplateId(char[], java.util.List) - */ - public ISymbol lookupTemplateId(char[] name, List arguments) throws ParserSymbolTableException { - LookupData data = new LookupData( name ); - - ParserSymbolTable.lookup( data, this ); - ISymbol found = getSymbolTable().resolveAmbiguities( data ); - if (found == null) { - // VMIR { - // another undefined symbol i.e.: - // template class A { - // typedef typename T::template R::some_type some_type; - // }; ^^^^ - // add a symbol as an expected type to a template parameter - found = getSymbolTable().newUndefinedTemplateSymbol(name, ITypeInfo.t_template); - addSymbol(found); - } - if( found != null ){ - if( (found.isType( ITypeInfo.t_templateParameter ) && found.getTypeInfo().getTemplateParameterType() == ITypeInfo.t_template) || - found.isType( ITypeInfo.t_template ) ) - { - found = ((ITemplateSymbol) found).instantiate( arguments ); - } else if( found.getContainingSymbol().isType( ITypeInfo.t_template ) ){ - found = ((ITemplateSymbol) found.getContainingSymbol()).instantiate( arguments ); - } - } - - return found; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupFunctionTemplateId(char[], java.util.List, java.util.List, boolean) - */ - public ISymbol lookupFunctionTemplateId(char[] name, final List parameters, final List arguments, boolean forDefinition) - throws ParserSymbolTableException { - LookupData data = new LookupData( name ){ - public List getParameters() { return params; } - public List getTemplateParameters() { return templateParams; } - public TypeFilter getFilter() { return FUNCTION_FILTER; } - final private List params = ( parameters == null ) ? Collections.EMPTY_LIST : parameters; - final private List templateParams = arguments; - }; - data.exactFunctionsOnly = forDefinition; - - ParserSymbolTable.lookup( data, this ); - ISymbol found = getSymbolTable().resolveAmbiguities( data ); - - return found; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#lookupTemplateIdForDefinition(char[], java.util.List) - */ - public IContainerSymbol lookupTemplateIdForDefinition(char[] name, List arguments) throws ParserSymbolTableException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#isVisible(org.eclipse.cdt.internal.core.parser.pst.ISymbol, org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) - */ - public boolean isVisible(ISymbol symbol, IContainerSymbol qualifyingSymbol) { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#getContentsIterator() - */ - public Iterator getContentsIterator() { - return getContents().iterator(); - } - - protected void addToContents( IExtensibleSymbol symbol ){ - if( _contents == Collections.EMPTY_LIST ){ - _contents = new ArrayList( 8 ); - } - _contents.add( symbol ); - } - - protected List getContents(){ - return _contents; - } - - - /* - * IParameterSymbol -------------------------------------------------------- - */ - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addParameter(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void addParameter(ISymbol param) { - throw new ParserSymbolTableError( ParserSymbolTableError.r_OperationNotSupported ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addParameter(org.eclipse.cdt.internal.core.parser.pst.ITypeInfo.eType, int, org.eclipse.cdt.internal.core.parser.pst.ITypeInfo.PtrOp, boolean) - */ - public void addParameter(eType type, int info, PtrOp ptrOp, boolean hasDefault) { - throw new ParserSymbolTableError( ParserSymbolTableError.r_OperationNotSupported ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#addParameter(org.eclipse.cdt.internal.core.parser.pst.ISymbol, int, org.eclipse.cdt.internal.core.parser.pst.ITypeInfo.PtrOp, boolean) - */ - public void addParameter(ISymbol typeSymbol, int info, PtrOp ptrOp, boolean hasDefault) { - throw new ParserSymbolTableError( ParserSymbolTableError.r_OperationNotSupported ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#getParameterMap() - */ - public CharArrayObjectMap getParameterMap() { - return CharArrayObjectMap.EMPTY_MAP; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#getParameterList() - */ - public List getParameterList() { - return Collections.EMPTY_LIST; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#hasSameParameters(org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol) - */ - public boolean hasSameParameters(IParameterizedSymbol newDecl) { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#setReturnType(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void setReturnType(ISymbol type) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#getReturnType() - */ - public ISymbol getReturnType() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#setHasVariableArgs(boolean) - */ - public void setHasVariableArgs(boolean var) { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#hasVariableArgs() - */ - public boolean hasVariableArgs() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol#prepareForParameters(int) - */ - public void prepareForParameters(int numParams) { - } - - - /* - * ITemplateSymbol -------------------------------------------------------- - */ - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#addTemplateParameter(org.eclipse.cdt.internal.core.parser.pst.ISymbol) - */ - public void addTemplateParameter(ISymbol param) throws ParserSymbolTableException { - throw new ParserSymbolTableError( ParserSymbolTableError.r_OperationNotSupported ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#hasSpecializations() - */ - public boolean hasSpecializations() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#addSpecialization(org.eclipse.cdt.internal.core.parser.pst.ISpecializedSymbol) - */ - public void addSpecialization(ISpecializedSymbol spec) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#getSpecializations() - */ - public List getSpecializations() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#getTemplatedSymbol() - */ - public IContainerSymbol getTemplatedSymbol() { - return this; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#getDefinitionParameterMap() - */ - public ObjectMap getDefinitionParameterMap() { - return ObjectMap.EMPTY_MAP; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#findInstantiation(java.util.List) - */ - public IContainerSymbol findInstantiation(List arguments) { - if( _instantiations == ObjectMap.EMPTY_MAP ){ - return null; - } - - //TODO: we could optimize this by doing something other than a linear search. - int size = _instantiations.size(); - List args = null; - for( int i = 0; i < size; i++ ){ - args = (List) _instantiations.keyAt(i); - - if( args.equals( arguments ) ){ - return (IContainerSymbol) _instantiations.get( args ); - } - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#findArgumentsFor(org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) - */ - public List findArgumentsFor(IContainerSymbol instance) { - if( instance == null || !instance.isTemplateInstance() ) - return null; - -// ITemplateSymbol template = (ITemplateSymbol) instance.getInstantiatedSymbol().getContainingSymbol(); -// if( template != this ) -// return null; - - int size = _instantiations.size(); - for( int i = 0; i < size; i++){ - List args = (List) _instantiations.keyAt( i ); - if( _instantiations.get( args ) == instance ){ - return args; - } - } - - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#addInstantiation(org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol, java.util.List) - */ - public void addInstantiation(IContainerSymbol instance, List args) { - List key = new ArrayList( args ); - if( _instantiations == ObjectMap.EMPTY_MAP ){ - _instantiations = new ObjectMap(2); - } - _instantiations.put( key, instance ); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#removeInstantiation(org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol) - */ - public void removeInstantiation(IContainerSymbol symbol) { - List args = findArgumentsFor( symbol ); - if( args != null ){ - _instantiations.remove( args ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#addExplicitSpecialization(org.eclipse.cdt.internal.core.parser.pst.ISymbol, java.util.List) - */ - public void addExplicitSpecialization(ISymbol symbol, List args) throws ParserSymbolTableException { - // TODO Auto-generated method stub - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#instantiate(java.util.List) - */ - public ISymbol instantiate(List arguments) throws ParserSymbolTableException { - if( getType() != ITypeInfo.t_template && - ( getType() != ITypeInfo.t_templateParameter || - getTypeInfo().getTemplateParameterType() != ITypeInfo.t_template ) ) - { - return null; - } - - UndefinedTemplateSymbol instance = (UndefinedTemplateSymbol) findInstantiation( arguments ); - if (instance == null) { - // clone and store the arguments - instance = (UndefinedTemplateSymbol) getSymbolTable().newUndefinedTemplateSymbol(getName(), getType()); - instance.setArgumentList(arguments); - instance.setInstantiatedSymbol(this); - - addInstantiation(instance, arguments); - } - return instance; - } - - /** - * @return Returns the _argumentList. - */ - public List getArgumentList() { - return _argumentList; - } - /** - * @param list The _argumentList to set. - */ - protected void setArgumentList(List list) { - _argumentList = new ArrayList(list); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ISymbol#instantiate(org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol, org.eclipse.cdt.core.parser.util.ObjectMap) - */ - public ISymbol instantiate(ITemplateSymbol template, ObjectMap argMap) throws ParserSymbolTableException { - if( !isTemplateMember() || template == null ) { - return null; - } - if (getContainingSymbol() instanceof UndefinedTemplateSymbol) { - // instantiate containing symbol - ISymbol containingSymbol = ((UndefinedTemplateSymbol) getContainingSymbol()).instantiate( template, argMap ); - // now lookup for the symbol in containing symbol's list of contained symbols - if (containingSymbol instanceof IContainerSymbol) { - ISymbol symbol; - if (isType(ITypeInfo.t_template)) { - symbol = ((IContainerSymbol) containingSymbol).lookupTemplateId(getName(), getArgumentList()); - } - else { - symbol = ((IContainerSymbol) containingSymbol).lookup(getName()); - } - if (symbol instanceof IDeferredTemplateInstance) { - symbol = ((IDeferredTemplateInstance) symbol).getTemplate(); - } - if (symbol instanceof ITemplateSymbol) { - symbol = ((ITemplateSymbol) symbol).getTemplatedSymbol(); - } - return symbol; - } - - throw new ParserSymbolTableException(ParserSymbolTableException.r_BadTemplateArgument); - - } - else if (isType(ITypeInfo.t_templateParameter) && argMap.containsKey(this)) { - return ((ITypeInfo)argMap.get(this)).getTypeSymbol(); - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#deferredInstance(java.util.List) - */ - public IDeferredTemplateInstance deferredInstance(List args) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#getExplicitSpecializations() - */ - public ObjectMap getExplicitSpecializations() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#getNumberDeferredInstantiations() - */ - public int getNumberDeferredInstantiations() { - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol#registerDeferredInstatiation(java.lang.Object, java.lang.Object, org.eclipse.cdt.internal.core.parser.pst.ITemplateSymbol.DeferredKind, org.eclipse.cdt.core.parser.util.ObjectMap) - */ - public void registerDeferredInstatiation(Object obj0, Object obj1, DeferredKind kind, ObjectMap argMap) { - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java deleted file mode 100644 index d1528eb4575..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corp. - Rational Software - initial implementation - *******************************************************************************/ -/* - * Created on Feb 18, 2004 - */ -package org.eclipse.cdt.internal.core.parser.pst; - -import java.util.List; - - -/** - * @author aniefer - */ -public class UsingDeclarationSymbol extends ExtensibleSymbol implements IUsingDeclarationSymbol { - - public UsingDeclarationSymbol( ParserSymbolTable table, List referenced, List declared ){ - super( table ); - referencedSymbol = referenced; - declaredSymbol = declared; - } - - public List getReferencedSymbols() { return referencedSymbol; } - public List getDeclaredSymbols() { return declaredSymbol; } - - private final List referencedSymbol; - private final List declaredSymbol; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDirectiveSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDirectiveSymbol.java deleted file mode 100644 index f97191dc5c2..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDirectiveSymbol.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.pst; - - -public class UsingDirectiveSymbol extends ExtensibleSymbol implements IUsingDirectiveSymbol{ - - public UsingDirectiveSymbol( ParserSymbolTable table, IContainerSymbol ns ){ - super( table ); - namespace = ns; - } - - public IContainerSymbol getNamespace(){ - return namespace; - } - - private final IContainerSymbol namespace; -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java index 9480f688d81..0251644373a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java @@ -39,7 +39,6 @@ import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.ParseError; import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ast.IASTFactory; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayUtils; @@ -82,11 +81,6 @@ public class CPreprocessor implements ILexerLog, IScanner { private static final ObjectStyleMacro __STDC_HOSTED__ = new ObjectStyleMacro("__STDC_HOSTED_".toCharArray(), ONE); //$NON-NLS-1$ private static final ObjectStyleMacro __STDC_VERSION__ = new ObjectStyleMacro("__STDC_VERSION_".toCharArray(), "199901L".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$ - private static final ILexerLog LEXERLOG_NULL= new ILexerLog() { - public void handleComment(boolean isBlockComment, int offset, int endOffset) {} - public void handleProblem(int problemID, char[] source, int offset, int endOffset) {} - }; - private interface IIncludeFileTester { Object checkFile(String path, String fileName); } @@ -368,9 +362,9 @@ public class CPreprocessor implements ILexerLog, IScanner { } public PreprocessorMacro addMacroDefinition(char[] key, char[] value) { - final Lexer lex= new Lexer(key, fLexOptions, LEXERLOG_NULL, null); + final Lexer lex= new Lexer(key, fLexOptions, ILexerLog.NULL, null); try { - PreprocessorMacro result= fMacroDefinitionParser.parseMacroDefinition(lex, LEXERLOG_NULL, value); + PreprocessorMacro result= fMacroDefinitionParser.parseMacroDefinition(lex, ILexerLog.NULL, value); fLocationMap.registerPredefinedMacro(result); fMacroDictionary.put(result.getNameCharArray(), result); return result; @@ -1410,19 +1404,10 @@ public class CPreprocessor implements ILexerLog, IScanner { } public void setScanComments(boolean val) { } - public char[] getMainFilename() { - throw new UnsupportedOperationException(); - } public IMacro addDefinition(char[] name, char[][] params, char[] expansion) { throw new UnsupportedOperationException(); } - public void setASTFactory(IASTFactory f) { - throw new UnsupportedOperationException(); - } public org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver getLocationResolver() { return fLocationMap; } - public void setOffsetBoundary(int offset) { - throw new UnsupportedOperationException(); - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java index 7d9917f36ca..349d46f5eda 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java @@ -93,29 +93,4 @@ public class Token implements IToken, Cloneable { return null; } } - - public char[] getFilename() { - // mstodo- parser removal - throw new UnsupportedOperationException(); - } - - public boolean looksLikeExpression() { - // mstodo- parser removal - throw new UnsupportedOperationException(); - } - - public boolean canBeAPrefix() { - // mstodo- parser removal - throw new UnsupportedOperationException(); - } - - public int getLineNumber() { - // mstodo- parser removal - throw new UnsupportedOperationException(); - } - - public boolean isPointer() { - // mstodo- parser removal - throw new UnsupportedOperationException(); - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java index 431d3e7c259..017f8257951 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java @@ -34,21 +34,17 @@ import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.KeywordSetKey; import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.ParseError; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayIntMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArraySet; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharTable; -import org.eclipse.cdt.internal.core.parser.ast.ASTCompletionNode; -import org.eclipse.cdt.internal.core.parser.token.KeywordSets; import org.eclipse.cdt.internal.core.parser.token.SimpleToken; /** @@ -603,9 +599,9 @@ abstract class BaseScanner implements IScanner { result = fetchToken(); } catch (OffsetLimitReachedException olre) { if (contentAssistMode) { - IASTCompletionNode node= olre.getCompletionNode(); - if (node != null) { - result= newToken(IToken.tCOMPLETION, node.getCompletionPrefix().toCharArray()); + String prefix= olre.getPrefix(); + if (prefix != null) { + result= newToken(IToken.tCOMPLETION, prefix.toCharArray()); } else { result= newToken(IToken.tCOMPLETION); } @@ -4170,12 +4166,7 @@ abstract class BaseScanner implements IScanner { */ protected void handleCompletionOnDefinition(String definition) throws EndOfFileException { - IASTCompletionNode node = new ASTCompletionNode( - IASTCompletionNode.CompletionKind.MACRO_REFERENCE, null, null, - definition, KeywordSets.getKeywords(KeywordSetKey.EMPTY, - language), EMPTY_STRING, null); - - throw new OffsetLimitReachedException(node); + throw new OffsetLimitReachedException(definition); } /** @@ -4184,7 +4175,6 @@ abstract class BaseScanner implements IScanner { protected void handleCompletionOnExpression(char[] buffer) throws EndOfFileException { - IASTCompletionNode.CompletionKind kind = IASTCompletionNode.CompletionKind.MACRO_REFERENCE; int lastSpace = CharArrayUtils.lastIndexOf(SPACE, buffer); int lastTab = CharArrayUtils.lastIndexOf(TAB, buffer); int max = lastSpace > lastTab ? lastSpace : lastTab; @@ -4199,41 +4189,20 @@ abstract class BaseScanner implements IScanner { continue; handleInvalidCompletion(); } - IASTCompletionNode node = new ASTCompletionNode( - kind, - null, - null, - new String(prefix), - KeywordSets - .getKeywords( - ((kind == IASTCompletionNode.CompletionKind.NO_SUCH_KIND) ? KeywordSetKey.EMPTY - : KeywordSetKey.MACRO), language), - EMPTY_STRING, null); - - throw new OffsetLimitReachedException(node); + throw new OffsetLimitReachedException(new String(prefix)); } protected void handleNoSuchCompletion() throws EndOfFileException { - throw new OffsetLimitReachedException(new ASTCompletionNode( - IASTCompletionNode.CompletionKind.NO_SUCH_KIND, null, null, - EMPTY_STRING, KeywordSets.getKeywords(KeywordSetKey.EMPTY, - language), EMPTY_STRING, null)); + throw new OffsetLimitReachedException(EMPTY_STRING); } protected void handleInvalidCompletion() throws EndOfFileException { - throw new OffsetLimitReachedException(new ASTCompletionNode( - IASTCompletionNode.CompletionKind.UNREACHABLE_CODE, null, null, - EMPTY_STRING, KeywordSets.getKeywords(KeywordSetKey.EMPTY, - language), EMPTY_STRING, null)); + throw new OffsetLimitReachedException(EMPTY_STRING); } protected void handleCompletionOnPreprocessorDirective(String prefix) throws EndOfFileException { - throw new OffsetLimitReachedException(new ASTCompletionNode( - IASTCompletionNode.CompletionKind.PREPROCESSOR_DIRECTIVE, null, - null, prefix, KeywordSets.getKeywords( - KeywordSetKey.PP_DIRECTIVE, language), EMPTY_STRING, - null)); + throw new OffsetLimitReachedException(prefix); } protected int getCurrentOffset() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java index 1470305fc3a..6daff852a6c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java @@ -23,15 +23,12 @@ import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IMacro; import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.IASTFactory; import org.eclipse.cdt.core.parser.util.CharArrayUtils; /** @@ -94,7 +91,7 @@ public class DOMScanner extends BaseScanner { IScannerExtensionConfiguration configuration, ICodeReaderFactory readerFactory) { super(reader, info, parserMode, language, log, configuration); - this.expressionEvaluator = new ExpressionEvaluator(null, null); + this.expressionEvaluator = new ExpressionEvaluator(null); this.codeReaderFactory = readerFactory; postConstructorSetup(reader, info); } @@ -138,15 +135,6 @@ public class DOMScanner extends BaseScanner { return null; } - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.IScanner#setASTFactory(org.eclipse.cdt.core.parser.ast.IASTFactory) - */ - public void setASTFactory(IASTFactory f) { - // do nothing - } - /* * (non-Javadoc) * @@ -898,21 +886,8 @@ public class DOMScanner extends BaseScanner { qualifiedName[0] = getImage(); return qualifiedName; } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#acceptElement(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void acceptElement(ISourceElementRequestor requestor) { - } - + + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ITokenDuple#getSegmentIterator() */ @@ -1194,9 +1169,9 @@ public class DOMScanner extends BaseScanner { return Keywords._IMAGINARY ; case IToken.t_restrict : return Keywords.RESTRICT ; - case IScanner.tPOUND: + case IToken.tPOUND: return "#"; //$NON-NLS-1$ - case IScanner.tPOUNDPOUND: + case IToken.tPOUNDPOUND: return "##"; //$NON-NLS-1$ case IToken.tEOC: return "EOC"; //$NON-NLS-1$ @@ -1424,8 +1399,8 @@ public class DOMScanner extends BaseScanner { case IToken.t__Complex : return Keywords.c_COMPLEX ; case IToken.t__Imaginary : return Keywords.c_IMAGINARY ; case IToken.t_restrict : return Keywords.cRESTRICT ; - case IScanner.tPOUND: return Keywords.cpPOUND; - case IScanner.tPOUNDPOUND: return Keywords.cpPOUNDPOUND; + case IToken.tPOUND: return Keywords.cpPOUND; + case IToken.tPOUNDPOUND: return Keywords.cpPOUNDPOUND; default : // we should never get here! diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java index 27086c46bd8..0b1a7ba5bc1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java @@ -35,8 +35,6 @@ public class ExpressionEvaluator { private int[] bufferLimit = new int[initSize]; - private ScannerCallbackManager callbackManager = null; - private ScannerProblemFactory problemFactory = null; private int lineNumber = 1; @@ -52,9 +50,7 @@ public class ExpressionEvaluator { super(); } - public ExpressionEvaluator(ScannerCallbackManager manager, - ScannerProblemFactory spf) { - this.callbackManager = manager; + public ExpressionEvaluator(ScannerProblemFactory spf) { this.problemFactory = spf; } @@ -1044,16 +1040,6 @@ public class ExpressionEvaluator { } private void handleProblem(int id, int startOffset) { - if (callbackManager != null && problemFactory != null) - callbackManager - .pushCallback(problemFactory - .createProblem( - id, - startOffset, - bufferPos[(bufferStackPos == -1 ? 0 - : bufferStackPos)], - lineNumber, - (fileName == null ? "".toCharArray() : fileName), emptyCharArray, false, true)); //$NON-NLS-1$ } private boolean isValidTokenSeparator(char c, char c2) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java deleted file mode 100644 index 08a87548eb5..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java +++ /dev/null @@ -1,360 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Anton Leherbauer (Wind River Systems) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.scanner2; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ast.IASTFactory; -import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; -import org.eclipse.cdt.internal.core.parser.token.ImagedExpansionToken; -import org.eclipse.cdt.internal.core.parser.token.ImagedToken; -import org.eclipse.cdt.internal.core.parser.token.SimpleExpansionToken; -import org.eclipse.cdt.internal.core.parser.token.SimpleToken; - -/** - * @author jcamelon - */ -public class Scanner2 extends BaseScanner { - - /** - * @param reader - * @param info - * @param requestor - * @param parserMode - * @param language - * @param log - * @param workingCopies - * @param configuration - */ - public Scanner2(CodeReader reader, IScannerInfo info, - ISourceElementRequestor requestor, ParserMode parserMode, - ParserLanguage language, IParserLogService log, List workingCopies, - IScannerExtensionConfiguration configuration) { - super(reader, info, parserMode, language, log, configuration); - this.requestor = requestor; - this.callbackManager = new ScannerCallbackManager(requestor); - this.expressionEvaluator = new ExpressionEvaluator(callbackManager, spf); - this.workingCopies = workingCopies; - postConstructorSetup(reader, info); - if (reader.filename != null) - fileCache.put(reader.filename, reader); - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getASTFactory() - */ - protected IASTFactory getASTFactory() { - if (astFactory == null) - astFactory = ParserFactory.createASTFactory(parserMode, language); - return astFactory; - } - - protected IASTFactory astFactory; - - // callbacks - protected ScannerCallbackManager callbackManager; - - protected ISourceElementRequestor requestor; - - protected List workingCopies; - - public final void setASTFactory(IASTFactory f) { - astFactory = f; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createInclusionConstruct(char[], - * char[], boolean, int, int, int, int, int, int, int, boolean) - */ - protected Object createInclusionConstruct(char[] fileName, - char[] filenamePath, boolean local, int startOffset, - int startingLineNumber, int nameOffset, int nameEndOffset, - int nameLine, int endOffset, int endLine, boolean isForced) { - return getASTFactory().createInclusion(fileName, filenamePath, local, - startOffset, startingLineNumber, nameOffset, nameEndOffset, - nameLine, endOffset, endLine, getCurrentFilename(), isForced); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processMacro(char[], - * int, int, int, int, int, int, int) - */ - protected void processMacro(char[] name, int startingOffset, - int startingLineNumber, int idstart, int idend, int nameLine, - int textEnd, int endingLine, - org.eclipse.cdt.core.parser.IMacro macro) { - callbackManager.pushCallback(getASTFactory().createMacro(name, - startingOffset, startingLineNumber, idstart, idend, nameLine, - textEnd, endingLine, getCurrentFilename(), !isInitialized)); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[], - * java.lang.Object) - */ - protected void pushContext(char[] buffer, Object data) { - super.pushContext(buffer, data); - if (data instanceof InclusionData) { - callbackManager.pushCallback(data); - if (log.isTracing()) { - StringBuffer b = new StringBuffer("Entering inclusion "); //$NON-NLS-1$ - b.append(((InclusionData) data).reader.filename); - log.traceLog(b.toString()); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#beforeSecondFetchToken() - */ - protected void beforeSecondFetchToken() { - if (callbackManager.hasCallbacks()) - callbackManager.popCallbacks(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object) - */ - protected void quickParsePushPopInclusion(Object inclusion) { - callbackManager.pushCallback(new InclusionData(null, inclusion, false)); - callbackManager.pushCallback(inclusion); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String) - */ - protected CodeReader createReaderDuple(String finalPath) { - return ScannerUtility.createReaderDuple(finalPath, requestor, - getWorkingCopies()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.parser.IScanner#getLocationResolver() - */ - public ILocationResolver getLocationResolver() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getWorkingCopies() - */ - protected Iterator getWorkingCopies() { - if (workingCopies == null) - return EmptyIterator.EMPTY_ITERATOR; - return workingCopies.iterator(); - } - - /** - * @return - */ - protected IToken newToken(int signal) { - if (bufferData[bufferStackPos] instanceof MacroData) { - int mostRelevant; - for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant) - if (bufferData[mostRelevant] instanceof InclusionData - || bufferData[mostRelevant] instanceof CodeReader) - break; - MacroData data = (MacroData) bufferData[mostRelevant + 1]; - return new SimpleExpansionToken(signal, data.getStartOffset(), - data.getLength(), - getCurrentFilename(), - getLineNumber(bufferPos[mostRelevant] + 1)); - } - return new SimpleToken(signal, bufferPos[bufferStackPos] + 1, - getCurrentFilename(), - getLineNumber(bufferPos[bufferStackPos] + 1)); - } - - protected IToken newToken(int signal, char[] buffer) { - if (bufferData[bufferStackPos] instanceof MacroData) { - int mostRelevant; - for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant) - if (bufferData[mostRelevant] instanceof InclusionData - || bufferData[mostRelevant] instanceof CodeReader) - break; - MacroData data = (MacroData) bufferData[mostRelevant + 1]; - return new ImagedExpansionToken(signal, buffer, data.getStartOffset(), - data.getLength(), - getCurrentFilename(), - getLineNumber(bufferPos[mostRelevant] + 1)); - } - IToken i = new ImagedToken(signal, buffer, - bufferPos[bufferStackPos] + 1, getCurrentFilename(), - getLineNumber(bufferPos[bufferStackPos] + 1)); - - return i; - } - - protected static final ScannerProblemFactory spf = new ScannerProblemFactory(); - - protected final CharArrayObjectMap fileCache = new CharArrayObjectMap(100); - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int, - * int, char[]) - */ - protected void handleProblem(int id, int offset, char[] arg) { - if (parserMode == ParserMode.COMPLETION_PARSE) - return; - IProblem p = spf.createProblem(id, offset, bufferPos[bufferStackPos], - getLineNumber(bufferPos[bufferStackPos]), getCurrentFilename(), - arg != null ? arg : EMPTY_CHAR_ARRAY, false, true); - callbackManager.pushCallback(p); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext() - */ - protected Object popContext() { - if (bufferData[bufferStackPos] instanceof InclusionData) { - if (log.isTracing()) { - StringBuffer buffer = new StringBuffer("Exiting inclusion "); //$NON-NLS-1$ - buffer - .append(((InclusionData) bufferData[bufferStackPos]).reader.filename); - log.traceLog(buffer.toString()); - } - callbackManager - .pushCallback(((InclusionData) bufferData[bufferStackPos]).inclusion); - } - return super.popContext(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processIfdef(int, - * int, boolean, boolean) - */ - protected void processIfdef(int startPos, int endPos, boolean positive, - boolean taken) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processIf(int, - * int, boolean) - */ - protected void processIf(int startPos, int endPos, boolean taken) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processElsif(int, - * int, boolean) - */ - protected void processElsif(int startPos, int endPos, boolean taken) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processElse(int, - * int, boolean) - */ - protected void processElse(int startPos, int endPos, boolean taken) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processUndef(int, - * int) - */ - protected void processUndef(int pos, int endPos, char[] symbol, int namePos, Object definition) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processError(int, - * int) - */ - protected void processError(int startPos, int endPos) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processEndif(int, - * int) - */ - protected void processEndif(int pos, int i) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processPragma(int, - * int) - */ - protected void processPragma(int startPos, int endPos) { - } - - protected CodeReader createReader(String path, String fileName){ - String finalPath = ScannerUtility.createReconciledPath(path, fileName); - char[] finalPathc = finalPath.toCharArray(); - CodeReader reader = (CodeReader) fileCache.get(finalPathc); - if (reader != null) - return reader; // found the file in the cache - - // create a new reader on this file (if the file does not exist we will - // get null) - reader = createReaderDuple(finalPath); - if (reader == null) - return null; // the file was not found - - if (reader.filename != null) - // put the full requested path in the cache -- it is more likely - // to match next time than the reader.filename - fileCache.put(finalPathc, reader); - return reader; - } - - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerCallbackManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerCallbackManager.java deleted file mode 100644 index 3f3f317f6f9..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerCallbackManager.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Oct 18, 2004 - */ -package org.eclipse.cdt.internal.core.parser.scanner2; - -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner.InclusionData; - -/** - * @author aniefer - */ -public class ScannerCallbackManager { - private static final int bufferInitialSize = 8; - - private Object[] callbackStack = new Object[bufferInitialSize]; - private int callbackPos = -1; - private ISourceElementRequestor requestor; - - public ScannerCallbackManager( ISourceElementRequestor requestor ){ - this.requestor = requestor; - } - - public void pushCallback( Object obj ){ - if( ++callbackPos == callbackStack.length ){ - Object[] temp = new Object[ callbackStack.length << 1 ]; - System.arraycopy( callbackStack, 0, temp, 0, callbackStack.length ); - callbackStack = temp; - } - callbackStack[ callbackPos ] = obj; - } - - public void popCallbacks(){ - Object obj = null; - for( int i = 0; i <= callbackPos; i++ ){ - obj = callbackStack[i]; - if( obj == null ) continue; - //on the stack, InclusionData means enter, IASTInclusion means exit - if( obj instanceof InclusionData && ((InclusionData)obj).inclusion != null ) - requestor.enterInclusion( (IASTInclusion) ((InclusionData)obj).inclusion ); - else if( obj instanceof IASTInclusion ) - requestor.exitInclusion( (IASTInclusion) obj ); - else if( obj instanceof IASTMacro ) - requestor.acceptMacro( (IASTMacro) obj ); - else if( obj instanceof IProblem ) - requestor.acceptProblem( (IProblem) obj ); - } - callbackPos = -1; - } - - public boolean hasCallbacks(){ - return callbackPos != -1; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java index 2166e679649..474a721a706 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,10 +11,6 @@ package org.eclipse.cdt.internal.core.parser.scanner2; import java.io.File; -import java.util.Iterator; - -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; /** * @author jcamelon @@ -128,50 +124,4 @@ public class ScannerUtility { boolean pathEmpty = (path == null || path.length() == 0); return (pathEmpty ? fileName : reconcilePath(path + File.separatorChar + fileName)); } - - public static CodeReader createReaderDuple( String path, ISourceElementRequestor requestor, Iterator workingCopies ) - { - return requestor.createReader( path, workingCopies ); - } - - public static class InclusionDirective - { - public InclusionDirective( String fileName, boolean useIncludePaths, int startOffset, int endOffset ) - { - this.fileName = fileName; - this.useIncludePaths = useIncludePaths; - this.startOffset = startOffset; - this.endOffset = endOffset; - } - - private final boolean useIncludePaths; - private final String fileName; - private final int startOffset; - private final int endOffset; - - boolean useIncludePaths() - { - return useIncludePaths; - } - - public String getFilename() - { - return fileName; - } - - int getStartOffset() - { - return startOffset; - } - - int getEndOffset() - { - return endOffset; - } - } - - public static class InclusionParseException extends Exception - { - } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java index 500a212b4ba..e7b69971433 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.parser.token; import java.util.Iterator; import java.util.List; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.util.CharArrayUtils; @@ -265,12 +264,6 @@ public abstract class AbstractToken implements IToken, ITokenDuple { if( index == 0 ) return this; return null; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#isIdentifier() - */ - public boolean isIdentifier() { - return ( getType() == IToken.tIDENTIFIER ); - } private class SingleIterator implements Iterator @@ -325,21 +318,8 @@ public abstract class AbstractToken implements IToken, ITokenDuple { qualifiedName[0] = getImage(); return qualifiedName; } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#acceptElement(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void acceptElement(ISourceElementRequestor requestor) { - } - + + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ITokenDuple#getSegmentIterator() */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java index 31f0bc2f655..5c23e0b4af9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. + * Copyright (c) 2002, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,7 +15,6 @@ import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.util.CharArrayUtils; @@ -293,11 +292,6 @@ public class BasicTokenDuple implements ITokenDuple { return String.valueOf(stringRepresentation); } - public boolean isIdentifier() - { - return ( (firstToken == lastToken ) && (firstToken.getType() == IToken.tIDENTIFIER )); - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ITokenDuple#length() */ @@ -365,12 +359,6 @@ public class BasicTokenDuple implements ITokenDuple { public int getEndOffset() { return getLastToken().getEndOffset(); } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#getLineNumber() - */ - public int getLineNumber() { - return getFirstToken().getLineNumber(); - } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ITokenDuple#getStartOffset() */ @@ -577,18 +565,6 @@ public class BasicTokenDuple implements ITokenDuple { return n; } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#acceptElement(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void acceptElement(ISourceElementRequestor requestor) { - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ITokenDuple#toCharArray() */ @@ -597,11 +573,4 @@ public class BasicTokenDuple implements ITokenDuple { stringRepresentation = createCharArrayRepresentation(firstToken, lastToken); return stringRepresentation; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#getFilename() - */ - public char[] getFilename() { - return firstToken.getFilename(); - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedExpansionToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedExpansionToken.java deleted file mode 100644 index 25a9a50c9f1..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedExpansionToken.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.token; - -import org.eclipse.cdt.core.parser.IToken; - -/** - * @author johnc - */ -public class ImagedExpansionToken extends ImagedToken implements IToken { - - /** - * @param t - * @param contextStack - * @param i - * @param l - */ - public ImagedExpansionToken(int t, char[] i, int macroOffset, int macroLength, char [] f, int l) { - super(t, i, macroOffset, f, l ); - setOffsetAndLength( macroOffset, macroLength ); - } - - protected void setOffsetAndLength(int macroOffset, int macroLength ) { - offset = macroOffset; - length = macroLength; - } - - - protected int length; - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.token.AbstractToken#getLength() - */ - public final int getLength() { - return length; - } - -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedToken.java deleted file mode 100644 index 708b18ec7d7..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/ImagedToken.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.token; - -import org.eclipse.cdt.core.parser.IToken; - - -/** - * @author johnc - */ -public class ImagedToken extends SimpleToken { - - protected char [] image = null; - - public ImagedToken( int t, char[] i, int endOffset, char [] f, int l ) { - super( t, 0, f, l ); - setImage(i); - setOffsetAndLength( endOffset ); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.token.AbstractToken#getImage() - */ - public final String getImage() { - if( image == null ) return null; - return new String( image ); - } - - public final char[] getCharImage() { - return image; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IToken#setImage(java.lang.String) - */ - public void setImage(String i) { - image = i.toCharArray(); - } - - public void setImage( char [] image ) - { - this.image = image; - } - - - public int getLength() { - if( getCharImage() == null ) - return 0; - int s_length = getCharImage().length; - switch( getType() ) - { - case IToken.tSTRING: - return s_length + 2; - case IToken.tLSTRING: - return s_length + 3; - default: - return s_length; - } - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/OffsetDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/OffsetDuple.java deleted file mode 100644 index 4356e5b9922..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/OffsetDuple.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.token; - -import org.eclipse.cdt.core.parser.IOffsetDuple; - -/** - * @author jcamelon - * - */ -public class OffsetDuple implements IOffsetDuple -{ - private final int lineFloor, lineCeiling; - /** - * @param floor - * @param ceiling - */ - public OffsetDuple(int floor, int ceiling) - { - lineFloor = floor; - lineCeiling = ceiling; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IOffsetDuple#getCeilingOffset() - */ - public int getCeilingOffset() - { - return lineCeiling; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.IOffsetDuple#getFloorOffset() - */ - public int getFloorOffset() - { - return lineFloor; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/OperatorTokenDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/OperatorTokenDuple.java index 196c8ee30ff..66debc44fc7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/OperatorTokenDuple.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/OperatorTokenDuple.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,7 +14,6 @@ import java.util.Iterator; import java.util.List; import org.eclipse.cdt.core.dom.ast.IASTTypeId; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; @@ -115,30 +114,12 @@ public class OperatorTokenDuple implements ITokenDuple { return token.toCharArray(); } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#getFilename() - */ - public char[] getFilename() { - return token.getFilename(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#isIdentifier() - */ - public boolean isIdentifier() { - return token.isIdentifier(); - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ITokenDuple#length() */ public int length() { return token.length(); } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#getSubrange(int, int) - */ - public ITokenDuple getSubrange(int startIndex, int endIndex) { - return token.getSubrange(startIndex, endIndex); - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ITokenDuple#getToken(int) */ public IToken getToken(int index) { @@ -151,12 +132,6 @@ public class OperatorTokenDuple implements ITokenDuple { return token.getSegments(); } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#findLastTokenType(int) - */ - public int findLastTokenType(int type) { - return token.findLastTokenType(type); - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ITokenDuple#getStartOffset() */ public int getStartOffset() { @@ -169,49 +144,12 @@ public class OperatorTokenDuple implements ITokenDuple { return token.getEndOffset(); } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#getLineNumber() - */ - public int getLineNumber() { - return token.getLineNumber(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#syntaxOfName() - */ - public boolean syntaxOfName() { - return token.syntaxOfName(); - } - /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ITokenDuple#extractNameFromTemplateId() */ public char[] extractNameFromTemplateId() { return token.extractNameFromTemplateId(); } /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#contains(org.eclipse.cdt.core.parser.ITokenDuple) - */ - public boolean contains(ITokenDuple duple) { - return token.contains(duple); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#toQualifiedName() - */ - public String[] toQualifiedName() { - return token.toQualifiedName(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#freeReferences() - */ - public void freeReferences() { - token.freeReferences(); - } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple# - * acceptElement(org.eclipse.cdt.core.parser.ISourceElementRequestor) - */ - public void acceptElement(ISourceElementRequestor requestor) { - token.acceptElement(requestor); - } - /* (non-Javadoc) * @see java.lang.Object#toString() */ public String toString() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleExpansionToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleExpansionToken.java deleted file mode 100644 index 2edc4e8a247..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleExpansionToken.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Sep 27, 2004 - */ -package org.eclipse.cdt.internal.core.parser.token; - -import org.eclipse.cdt.core.parser.IToken; - -/** - * @author aniefer - */ -public class SimpleExpansionToken extends SimpleToken implements IToken { - public SimpleExpansionToken(int t, int macroOffset, int macroLength, char [] f, int l) { - super(t, macroOffset + macroLength, f, l); - setOffsetAndLength( macroOffset, macroLength ); - } - - protected void setOffsetAndLength(int macroOffset, int macroLength ) { - offset = macroOffset; - length = macroLength; - } - - - protected int length; - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.token.AbstractToken#getLength() - */ - public final int getLength() { - return length; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java index f03cfdaa1b1..02764f59776 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. + * Copyright (c) 2001, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.token; -import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.Keywords; @@ -295,9 +294,9 @@ public class SimpleToken extends AbstractToken implements IToken { return Keywords._IMAGINARY ; case IToken.t_restrict : return Keywords.RESTRICT ; - case IScanner.tPOUND: + case IToken.tPOUND: return "#"; //$NON-NLS-1$ - case IScanner.tPOUNDPOUND: + case IToken.tPOUNDPOUND: return "##"; //$NON-NLS-1$ case IToken.tEOC: return "EOC"; //$NON-NLS-1$ @@ -451,8 +450,8 @@ public class SimpleToken extends AbstractToken implements IToken { case IToken.t__Complex : return Keywords.c_COMPLEX ; case IToken.t__Imaginary : return Keywords.c_IMAGINARY ; case IToken.t_restrict : return Keywords.cRESTRICT ; - case IScanner.tPOUND: return Keywords.cpPOUND; - case IScanner.tPOUNDPOUND: return Keywords.cpPOUNDPOUND; + case IToken.tPOUND: return Keywords.cpPOUND; + case IToken.tPOUNDPOUND: return Keywords.cpPOUNDPOUND; default : // we should never get here! diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TemplateTokenDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TemplateTokenDuple.java index 849a48bee76..bf20efc3bca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TemplateTokenDuple.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TemplateTokenDuple.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,10 +13,8 @@ package org.eclipse.cdt.internal.core.parser.token; import java.util.ArrayList; import java.util.List; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; -import org.eclipse.cdt.core.parser.ast.IASTExpression; /** * @author jcamelon @@ -97,42 +95,6 @@ public class TemplateTokenDuple extends BasicTokenDuple { return argLists; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#freeReferences(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void freeReferences() { - if( argLists == null ) return; - for( int i = 0; i < argLists.length; ++i ) - { - if( argLists[i] == null ) continue; - for( int j = 0; j < argLists[i].size(); ++ j ) - { - IASTExpression e = (IASTExpression) argLists[i].get(j); - if( e != null ) - e.freeReferences(); - - } - } - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ITokenDuple#acceptElement(org.eclipse.cdt.core.parser.ast.IReferenceManager) - */ - public void acceptElement(ISourceElementRequestor requestor) { - if( argLists == null ) return; - for( int i = 0; i < argLists.length; ++i ) - { - if( argLists[i] == null ) continue; - for( int j = 0; j < argLists[i].size(); ++ j ) - { - IASTExpression e = (IASTExpression) argLists[i].get(j); - e.acceptElement(requestor); - } - } - } - public ITokenDuple[] getSegments() { List r = new ArrayList(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TokenFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TokenFactory.java index 337c29f0fcd..649652f4cdb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TokenFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/TokenFactory.java @@ -15,7 +15,6 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; -import org.eclipse.cdt.core.parser.ISourceElementRequestor; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; @@ -35,15 +34,9 @@ public class TokenFactory { public String toString() { return fToken.toString(); } - public boolean contains(ITokenDuple duple) { - return fToken == duple.getFirstToken() && fToken == duple.getLastToken(); - } public char[] extractNameFromTemplateId(){ return fToken.getCharImage(); } - public int findLastTokenType(int t) { - return fToken.getType() == t ? 0 : -1; - } public IToken getFirstToken() { return fToken; } @@ -62,21 +55,13 @@ public class TokenFactory { public int getStartOffset() { return fToken.getOffset(); } - public ITokenDuple getSubrange(int startIndex, int endIndex) { - if( startIndex == 0 && endIndex == 0 ) return this; - return null; - } public List[] getTemplateIdArgLists() { return null; } public IToken getToken(int index) { if( index == 0 ) return fToken; return null; - } - public boolean isIdentifier() { - return ( fToken.getType() == IToken.tIDENTIFIER ); - } - + } public Iterator iterator() { return new Iterator() { private boolean hasNext = true; @@ -95,38 +80,17 @@ public class TokenFactory { public int length() { return 1; } - public boolean syntaxOfName() { - return isIdentifier(); - } - public String[] toQualifiedName() { - return new String[] {fToken.getImage()}; - } - public void freeReferences() { - } - public void acceptElement(ISourceElementRequestor requestor) { - } public ITokenDuple[] getSegments() { return new ITokenDuple[] {this}; } public int getEndOffset() { return fToken.getEndOffset(); } - public char[] getFilename() { - return fToken.getFilename(); - } - public int getLineNumber() { - return fToken.getLineNumber(); - } public char[] toCharArray() { return fToken.getCharImage(); } } - public static IToken createStandAloneToken( int type, String image ) - { - return new ImagedToken( type, image.toCharArray(), 0, EMPTY_CHAR_ARRAY, 0); - } - public static ITokenDuple createTokenDuple(IToken first, IToken last) { if (first == last) { if (first instanceof ITokenDuple) { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CConventions.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CConventions.java index e76f44a0532..f48365106c7 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CConventions.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CConventions.java @@ -13,17 +13,12 @@ package org.eclipse.cdt.core; import java.util.StringTokenizer; import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.EndOfFileException; -import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IToken; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.Util; import org.eclipse.cdt.internal.core.model.CModelStatus; +import org.eclipse.cdt.internal.core.parser.scanner.ILexerLog; +import org.eclipse.cdt.internal.core.parser.scanner.Lexer; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; @@ -323,30 +318,14 @@ public class CConventions { // create a scanner and get the type of the token // assuming that you are given a valid identifier IToken token = null; - IScanner scanner = ParserFactory.createScanner( - new CodeReader(name.toCharArray()), - new ScannerInfo(), - ParserMode.QUICK_PARSE, - ParserLanguage.CPP, - null, - null, - null - ); - + Lexer lexer= new Lexer(name.toCharArray(), new Lexer.LexerOptions(), ILexerLog.NULL, null); try { - token = scanner.nextToken(); + token = lexer.nextToken(); + if (token.getType() == IToken.tIDENTIFIER && lexer.nextToken().getType() == IToken.tEND_OF_INPUT) { + return true; + } } catch (Exception e) { } - - if ((token != null) && (token.getType() == IToken.tIDENTIFIER)) { - try { - scanner.nextToken(); - } catch (EndOfFileException e) { - return true; - } catch (Exception e) { - } - } - return false; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/CodeReaderCache.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/CodeReaderCache.java index 9a4f0410f1c..16e8f05381a 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/CodeReaderCache.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/CodeReaderCache.java @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.parser; import java.io.File; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; +import org.eclipse.cdt.internal.core.parser.EmptyIterator; import org.eclipse.cdt.internal.core.util.ILRUCacheable; import org.eclipse.cdt.internal.core.util.LRUCache; import org.eclipse.cdt.internal.core.util.OverflowingLRUCache; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserTimeOut.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserTimeOut.java deleted file mode 100644 index 2a1194e80b6..00000000000 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserTimeOut.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.core.parser; - - -/** - * @author bgheorgh - * - */ -public class ParserTimeOut implements Runnable { - - - protected Thread thread; - protected boolean enabled; - protected IParser cancellable; - private int timeout = 0; - private int threadPriority = Thread.MIN_PRIORITY + 1; - boolean debug = false; - private String threadName = null; - boolean readyToRun = true; - - public ParserTimeOut(){ - reset(); - } - - public ParserTimeOut(String threadName){ - this.threadName = threadName; - reset(); - } - - public void run() { - while (this.thread != null) { - try { - synchronized(this){ - if (enabled){ - readyToRun = false; - wait(timeout); - if (enabled){ - if(cancellable != null) - cancellable.cancel(); - enabled = false; - } - } - else{ - while(!enabled){ - readyToRun = true; - wait(); - } - } - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - public synchronized void startTimer(){ - enabled = true; - notify(); - } - - public synchronized void stopTimer(){ - enabled= false; - notify(); - } - - - - public void reset() { - enabled=false; - if (threadName!=null){ - thread = new Thread(this, threadName); - } - else{ - thread = new Thread(this, "Time Out Thread"); //$NON-NLS-1$ - } - thread.setDaemon(true); - thread.setPriority(threadPriority); - thread.start(); - } - /** - * @return Returns the threadPriority. - */ - public int getThreadPriority() { - return threadPriority; - } - /** - * @param threadPriority The threadPriority to set. - */ - public void setThreadPriority(int threadPriority) { - this.threadPriority = threadPriority; - } - - /** - * @param pm The pm to set. - */ - public void setParser(IParser c) { - this.cancellable = c; - } - /** - * @return Returns the timeout. - */ - public int getTimeout() { - return timeout; - } - /** - * @param timeout The timeout to set. - */ - public void setTimeout(int timeout) { - this.timeout = timeout; - } - - public boolean isReadyToRun(){ - return readyToRun; - } -} diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/PartialWorkingCopyCodeReaderFactory.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/PartialWorkingCopyCodeReaderFactory.java index 904e8bf4cea..b77ee6f7a39 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/PartialWorkingCopyCodeReaderFactory.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/PartialWorkingCopyCodeReaderFactory.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.core.model.IWorkingCopyProvider; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.ICodeReaderCache; import org.eclipse.cdt.core.parser.ParserUtil; -import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; +import org.eclipse.cdt.internal.core.parser.EmptyIterator; /** * @author jcamelon diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java index b642bc0cef7..6b590e5035d 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java @@ -86,6 +86,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; @@ -95,7 +96,6 @@ import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.ParserUtil; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; import org.eclipse.cdt.core.resources.FileStorage; import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup; import org.eclipse.cdt.ui.testplugin.CTestPlugin;