From 6a848875507bd3146b1be9b55df7c53d4505eba8 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Wed, 17 Nov 2004 20:52:23 +0000 Subject: [PATCH] Merging AST2 branch into HEAD. Definition of new DOM AST interface. Construction of new C Parser. Tests. --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 818 +++ .../tests/ast2/ScannerConfigFactory.java | 121 + .../tests/parser2/QuickParser2Tests.java | 1591 ++++++ .../cdt/core/dom/ast/ASTNodeProperty.java | 51 + .../cdt/core/dom/ast/IASTASMDeclaration.java | 20 + .../cdt/core/dom/ast/IASTArrayDeclarator.java | 28 + .../cdt/core/dom/ast/IASTArrayModifier.java | 21 + .../dom/ast/IASTArraySubscriptExpression.java | 24 + .../core/dom/ast/IASTBinaryExpression.java | 58 + .../cdt/core/dom/ast/IASTBreakStatement.java | 20 + .../cdt/core/dom/ast/IASTCaseStatement.java | 34 + .../dom/ast/IASTCompositeTypeSpecifier.java | 51 + .../core/dom/ast/IASTCompoundStatement.java | 33 + .../dom/ast/IASTConditionalExpression.java | 30 + .../core/dom/ast/IASTContinueStatement.java | 20 + .../cdt/core/dom/ast/IASTDeclSpecifier.java | 40 + .../cdt/core/dom/ast/IASTDeclaration.java | 20 + .../dom/ast/IASTDeclarationStatement.java | 31 + .../cdt/core/dom/ast/IASTDeclarator.java | 64 + .../core/dom/ast/IASTDefaultStatement.java | 23 + .../cdt/core/dom/ast/IASTDoStatement.java | 41 + .../dom/ast/IASTElaboratedTypeSpecifier.java | 28 + .../dom/ast/IASTEnumerationSpecifier.java | 42 + .../cdt/core/dom/ast/IASTExpression.java | 20 + .../cdt/core/dom/ast/IASTExpressionList.java | 24 + .../core/dom/ast/IASTExpressionStatement.java | 28 + .../cdt/core/dom/ast/IASTFieldDeclarator.java | 32 + .../cdt/core/dom/ast/IASTFieldReference.java | 49 + .../cdt/core/dom/ast/IASTFileLocation.java | 27 + .../cdt/core/dom/ast/IASTForStatement.java | 71 + .../dom/ast/IASTFunctionCallExpression.java | 25 + .../core/dom/ast/IASTFunctionDeclarator.java | 35 + .../core/dom/ast/IASTFunctionDefinition.java | 52 + .../cdt/core/dom/ast/IASTGotoStatement.java | 31 + .../cdt/core/dom/ast/IASTIdExpression.java | 29 + .../cdt/core/dom/ast/IASTIfStatement.java | 52 + .../cdt/core/dom/ast/IASTInitializer.java | 20 + .../dom/ast/IASTInitializerExpression.java | 29 + .../cdt/core/dom/ast/IASTInitializerList.java | 31 + .../cdt/core/dom/ast/IASTLabelStatement.java | 31 + .../core/dom/ast/IASTLiteralExpression.java | 30 + .../cdt/core/dom/ast/IASTMacroDefinition.java | 20 + .../cdt/core/dom/ast/IASTMacroExpansion.java | 33 + .../eclipse/cdt/core/dom/ast/IASTName.java | 31 + .../eclipse/cdt/core/dom/ast/IASTNode.java | 43 + .../cdt/core/dom/ast/IASTNodeLocation.java | 37 + .../dom/ast/IASTParameterDeclaration.java | 37 + .../eclipse/cdt/core/dom/ast/IASTPointer.java | 27 + .../cdt/core/dom/ast/IASTPointerOperator.java | 18 + .../cdt/core/dom/ast/IASTReturnStatement.java | 29 + .../core/dom/ast/IASTSimpleDeclSpecifier.java | 49 + .../core/dom/ast/IASTSimpleDeclaration.java | 45 + .../cdt/core/dom/ast/IASTStatement.java | 20 + .../cdt/core/dom/ast/IASTSwitchStatement.java | 43 + .../cdt/core/dom/ast/IASTTranslationUnit.java | 59 + .../eclipse/cdt/core/dom/ast/IASTTypeId.java | 24 + .../core/dom/ast/IASTTypeIdExpression.java | 27 + .../dom/ast/IASTTypedefNameSpecifier.java | 29 + .../cdt/core/dom/ast/IASTUnaryExpression.java | 39 + .../dom/ast/IASTUnaryTypeIdExpression.java | 32 + .../cdt/core/dom/ast/IASTWhileStatement.java | 41 + .../eclipse/cdt/core/dom/ast/IBinding.java | 32 + .../cdt/core/dom/ast/ICompositeType.java | 35 + .../org/eclipse/cdt/core/dom/ast/IField.java | 18 + .../eclipse/cdt/core/dom/ast/IFunction.java | 37 + .../org/eclipse/cdt/core/dom/ast/ILabel.java | 28 + .../eclipse/cdt/core/dom/ast/IParameter.java | 21 + .../org/eclipse/cdt/core/dom/ast/IScope.java | 37 + .../org/eclipse/cdt/core/dom/ast/IType.java | 19 + .../eclipse/cdt/core/dom/ast/ITypedef.java | 25 + .../eclipse/cdt/core/dom/ast/IVariable.java | 22 + .../cdt/core/dom/ast/c/IASTNullStatement.java | 19 + .../core/dom/ast/c/ICASTArrayDesignator.java | 25 + .../core/dom/ast/c/ICASTArrayModifier.java | 28 + .../ast/c/ICASTCompositeTypeSpecifier.java | 20 + .../core/dom/ast/c/ICASTDeclSpecifier.java | 25 + .../cdt/core/dom/ast/c/ICASTDesignator.java | 21 + .../ast/c/ICASTElaboratedTypeSpecifier.java | 20 + .../dom/ast/c/ICASTEnumerationSpecifier.java | 20 + .../core/dom/ast/c/ICASTFieldDesignator.java | 24 + .../cdt/core/dom/ast/c/ICASTPointer.java | 22 + .../dom/ast/c/ICASTSimpleDeclSpecifier.java | 28 + .../c/ICASTTypeIdInitializerExpression.java | 30 + .../dom/ast/c/ICASTTypedefNameSpecifier.java | 20 + .../cpp/ICPPASTConstructorInitializer.java | 32 + .../dom/ast/cpp/ICPPASTDeclSpecifier.java | 26 + .../ast/cpp/ICPPASTFunctionDeclarator.java | 27 + .../dom/ast/cpp/ICPPASTPointerToMember.java | 25 + .../dom/ast/cpp/ICPPASTReferenceOperator.java | 22 + .../ast/cpp/ICPPASTSimpleDeclSpecifier.java | 26 + .../cdt/core/dom/ast/cpp/ICPPBase.java | 45 + .../cdt/core/dom/ast/cpp/ICPPClassType.java | 73 + .../cdt/core/dom/ast/cpp/ICPPField.java | 20 + .../cdt/core/dom/ast/cpp/ICPPMember.java | 31 + .../cdt/core/dom/ast/cpp/ICPPMethod.java | 20 + .../dom/ast/cpp/ICPPTemplateDefinition.java | 45 + .../ast/cpp/ICPPTemplateNonTypeParameter.java | 28 + .../dom/ast/cpp/ICPPTemplateParameter.java | 18 + .../ast/cpp/ICPPTemplateTypeParameter.java | 27 + .../IGNUASTCompoundStatementExpression.java | 25 + .../dom/ast/gnu/IGNUASTTypeIdExpression.java | 23 + .../dom/ast/gnu/IGNUASTUnaryExpression.java | 22 + .../gnu/c/IGCCASTArrayRangeDesignator.java | 28 + .../ast/gnu/cpp/IGPPASTBinaryExpression.java | 19 + .../eclipse/cdt/core/parser/ITokenDuple.java | 4 + .../core/parser/GCCParserExtension.java | 2 + .../core/parser/token/BasicTokenDuple.java | 9 + .../core/parser/token/SimpleToken.java | 7 + .../core/parser/token/TemplateTokenDuple.java | 3 +- .../cdt/internal/core/parser2/ASTNode.java | 36 + .../parser2/AbstractGNUSourceCodeParser.java | 1176 +++++ .../core/parser2/CompilationUnit.java | 36 + .../core/parser2/DeclarationWrapper.java | 497 ++ .../cdt/internal/core/parser2/Declarator.java | 428 ++ .../internal/core/parser2/IDeclarator.java | 43 + .../core/parser2/IDeclaratorOwner.java | 23 + .../core/parser2/IParameterCollection.java | 21 + .../core/parser2/ISourceCodeParser.java | 24 + .../core/parser2/ParameterCollection.java | 34 + .../cdt/internal/core/parser2/TypeId.java | 99 + .../c/ANSICParserExtensionConfiguration.java | 46 + .../core/parser2/c/CASTASMDeclaration.java | 35 + .../core/parser2/c/CASTArrayDeclarator.java | 77 + .../core/parser2/c/CASTArrayDesignator.java | 37 + .../core/parser2/c/CASTArrayModifier.java | 36 + .../parser2/c/CASTArrayRangeDesignator.java | 51 + .../c/CASTArraySubscriptExpression.java | 52 + .../core/parser2/c/CASTBaseDeclSpecifier.java | 80 + .../core/parser2/c/CASTBinaryExpression.java | 67 + .../core/parser2/c/CASTBreakStatement.java | 19 + .../core/parser2/c/CASTCaseStatement.java | 36 + .../parser2/c/CASTCompositeTypeSpecifier.java | 107 + .../core/parser2/c/CASTCompoundStatement.java | 73 + .../c/CASTCompoundStatementExpression.java | 37 + .../parser2/c/CASTConditionalExpression.java | 67 + .../core/parser2/c/CASTContinueStatement.java | 20 + .../parser2/c/CASTDeclarationStatement.java | 37 + .../core/parser2/c/CASTDeclarator.java | 117 + .../core/parser2/c/CASTDefaultStatement.java | 20 + .../core/parser2/c/CASTDoStatement.java | 52 + .../c/CASTElaboratedTypeSpecifier.java | 52 + .../parser2/c/CASTEnumerationSpecifier.java | 88 + .../core/parser2/c/CASTEnumerator.java | 52 + .../core/parser2/c/CASTExpressionList.java | 73 + .../parser2/c/CASTExpressionStatement.java | 37 + .../core/parser2/c/CASTFieldDeclarator.java | 38 + .../core/parser2/c/CASTFieldDesignator.java | 37 + .../core/parser2/c/CASTFieldReference.java | 67 + .../core/parser2/c/CASTForStatement.java | 99 + .../parser2/c/CASTFunctionCallExpression.java | 52 + .../parser2/c/CASTFunctionDeclarator.java | 91 + .../parser2/c/CASTFunctionDefinition.java | 69 + .../core/parser2/c/CASTGotoStatement.java | 36 + .../core/parser2/c/CASTIdExpression.java | 36 + .../core/parser2/c/CASTIfStatement.java | 67 + .../parser2/c/CASTInitializerExpresion.java | 37 + .../core/parser2/c/CASTInitializerList.java | 76 + .../core/parser2/c/CASTLabelStatement.java | 36 + .../core/parser2/c/CASTLiteralExpression.java | 51 + .../parser2/c/CASTModifiedArrayModifier.java | 81 + .../cdt/internal/core/parser2/c/CASTName.java | 63 + .../cdt/internal/core/parser2/c/CASTNode.java | 66 + .../core/parser2/c/CASTNullStatement.java | 19 + .../parser2/c/CASTParameterDeclaration.java | 53 + .../internal/core/parser2/c/CASTPointer.java | 65 + .../core/parser2/c/CASTReturnStatement.java | 37 + .../parser2/c/CASTSimpleDeclSpecifier.java | 96 + .../core/parser2/c/CASTSimpleDeclaration.java | 90 + .../core/parser2/c/CASTSwitchStatement.java | 53 + .../core/parser2/c/CASTTranslationUnit.java | 103 + .../internal/core/parser2/c/CASTTypeId.java | 53 + .../core/parser2/c/CASTTypeIdExpression.java | 52 + .../c/CASTTypeIdInitializerExpression.java | 53 + .../parser2/c/CASTTypedefNameSpecifier.java | 36 + .../core/parser2/c/CASTUnaryExpression.java | 52 + .../parser2/c/CASTUnaryTypeIdExpression.java | 37 + .../core/parser2/c/CASTWhileStatement.java | 52 + .../cdt/internal/core/parser2/c/CField.java | 30 + .../internal/core/parser2/c/CFunction.java | 86 + .../core/parser2/c/CFunctionScope.java | 43 + .../internal/core/parser2/c/CParameter.java | 72 + .../internal/core/parser2/c/CStructure.java | 134 + .../cdt/internal/core/parser2/c/CTypeDef.java | 65 + .../internal/core/parser2/c/CVariable.java | 67 + .../cdt/internal/core/parser2/c/CVisitor.java | 588 +++ .../c/GCCParserExtensionConfiguration.java | 46 + .../core/parser2/c/GNUCSourceParser.java | 2385 +++++++++ .../c/ICParserExtensionConfiguration.java | 23 + .../ANSICPPParserExtensionConfiguration.java | 61 + .../GNUCPPParserExtensionConfiguration.java | 60 + .../core/parser2/cpp/GNUCPPSourceParser.java | 4633 +++++++++++++++++ .../cpp/ICPPParserExtensionConfiguration.java | 30 + .../core/parser2/cpp/IProblemRequestor.java | 26 + 193 files changed, 19677 insertions(+), 1 deletion(-) create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ScannerConfigFactory.java create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/QuickParser2Tests.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTNodeProperty.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTASMDeclaration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArrayDeclarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArrayModifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArraySubscriptExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBinaryExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBreakStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCaseStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCompositeTypeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCompoundStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTConditionalExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTContinueStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclaration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarationStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDefaultStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDoStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTElaboratedTypeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTEnumerationSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionList.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFieldDeclarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFieldReference.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFileLocation.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionCallExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDefinition.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTGotoStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTIdExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTIfStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializer.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerList.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLabelStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLiteralExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTMacroDefinition.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTMacroExpansion.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTName.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNodeLocation.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTParameterDeclaration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPointer.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPointerOperator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTReturnStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclaration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSwitchStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypedefNameSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryTypeIdExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTWhileStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IField.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ILabel.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IParameter.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/IASTNullStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTArrayDesignator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTArrayModifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTCompositeTypeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTDeclSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTDesignator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTElaboratedTypeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTEnumerationSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTFieldDesignator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTPointer.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTSimpleDeclSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTTypeIdInitializerExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTTypedefNameSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTConstructorInitializer.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTDeclSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTPointerToMember.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTReferenceOperator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTSimpleDeclSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPBase.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPField.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMember.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateDefinition.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateNonTypeParameter.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateParameter.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateTypeParameter.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTCompoundStatementExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTTypeIdExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTUnaryExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/IGCCASTArrayRangeDesignator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTBinaryExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/ASTNode.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/CompilationUnit.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/DeclarationWrapper.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/Declarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IDeclarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IDeclaratorOwner.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IParameterCollection.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/ISourceCodeParser.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/ParameterCollection.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/TypeId.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/ANSICParserExtensionConfiguration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTASMDeclaration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayDeclarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayDesignator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayModifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayRangeDesignator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArraySubscriptExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBaseDeclSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBinaryExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBreakStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCaseStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompositeTypeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompoundStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompoundStatementExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTConditionalExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTContinueStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDeclarationStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDeclarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDefaultStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDoStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTElaboratedTypeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTEnumerationSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTEnumerator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTExpressionList.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTExpressionStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldDeclarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldDesignator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldReference.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTForStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionCallExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionDeclarator.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionDefinition.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTGotoStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTIdExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTIfStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTInitializerExpresion.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTInitializerList.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTLabelStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTLiteralExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTModifiedArrayModifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTName.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNode.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNullStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTParameterDeclaration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTPointer.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTReturnStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSimpleDeclSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSimpleDeclaration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSwitchStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTranslationUnit.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeId.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeIdExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeIdInitializerExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypedefNameSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTUnaryExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTUnaryTypeIdExpression.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTWhileStatement.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CField.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CFunction.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CFunctionScope.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CParameter.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CStructure.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CTypeDef.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CVariable.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CVisitor.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GCCParserExtensionConfiguration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GNUCSourceParser.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/ICParserExtensionConfiguration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/ANSICPPParserExtensionConfiguration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPParserExtensionConfiguration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/ICPPParserExtensionConfiguration.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/IProblemRequestor.java 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 new file mode 100644 index 00000000000..ef6e38c401c --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -0,0 +1,818 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.parser.tests.ast2; + +import java.util.Collections; +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; +import org.eclipse.cdt.core.dom.ast.IASTFieldReference; +import org.eclipse.cdt.core.dom.ast.IASTForStatement; +import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; +import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTTypedefNameSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTUnaryTypeIdExpression; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IField; +import org.eclipse.cdt.core.dom.ast.IFunction; +import org.eclipse.cdt.core.dom.ast.IParameter; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTPointer; +import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; +import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.core.parser.IParserLogService; +import org.eclipse.cdt.core.parser.IScanner; +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.ParserLanguage; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.core.parser.ScannerInfo; +import org.eclipse.cdt.core.parser.tests.parser2.QuickParser2Tests.ProblemCollector; +import org.eclipse.cdt.internal.core.parser.ParserException; +import org.eclipse.cdt.internal.core.parser2.ISourceCodeParser; +import org.eclipse.cdt.internal.core.parser2.c.ANSICParserExtensionConfiguration; +import org.eclipse.cdt.internal.core.parser2.c.CVisitor; +import org.eclipse.cdt.internal.core.parser2.c.GNUCSourceParser; +import org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration; +import org.eclipse.cdt.internal.core.parser2.cpp.ANSICPPParserExtensionConfiguration; +import org.eclipse.cdt.internal.core.parser2.cpp.GNUCPPSourceParser; +import org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration; + +/** + * Test the new AST. + * + * @author Doug Schaefer + */ +public class AST2Tests extends TestCase { + + private static final ISourceElementRequestor NULL_REQUESTOR = new NullSourceElementRequestor(); + private static final IParserLogService NULL_LOG = new NullLogService(); + + /** + * @param string + * @param c + * @return + * @throws ParserException + */ + protected IASTTranslationUnit parse(String code, ParserLanguage lang) throws ParserException { + ProblemCollector collector = new ProblemCollector(); + IScanner scanner = ParserFactory.createScanner(new CodeReader(code + .toCharArray()), new ScannerInfo(), ParserMode.COMPLETE_PARSE, + lang, NULL_REQUESTOR, + NULL_LOG, Collections.EMPTY_LIST); + ISourceCodeParser parser2 = null; + if( lang == ParserLanguage.CPP ) + { + ICPPParserExtensionConfiguration config = null; + config = new ANSICPPParserExtensionConfiguration(); + parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, collector, + NULL_LOG, + config ); + } + else + { + ICParserExtensionConfiguration config = null; + config = new ANSICParserExtensionConfiguration(); + + parser2 = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, collector, + NULL_LOG, config ); + } + IASTTranslationUnit tu = parser2.parse(); + if( parser2.encounteredError() ) + throw new ParserException( "FAILURE"); //$NON-NLS-1$ + + assertTrue( collector.hasNoProblems() ); + + return tu; + } + + + public void testBasicFunction() throws ParserException { + StringBuffer buff = new StringBuffer(); + buff.append("int x;\n"); //$NON-NLS-1$ + buff.append("void f(int y) {\n"); //$NON-NLS-1$ + buff.append(" int z = x + y;\n"); //$NON-NLS-1$ + buff.append("}\n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C ); + IScope globalScope = tu.getScope(); + + List declarations = tu.getDeclarations(); + + // int x + IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) declarations + .get(0); + IASTSimpleDeclSpecifier declspec_x = (IASTSimpleDeclSpecifier) decl_x + .getDeclSpecifier(); + assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_x.getType()); + IASTDeclarator declor_x = (IASTDeclarator) decl_x.getDeclarators().get( + 0); + IASTName name_x = declor_x.getName(); + assertEquals("x", name_x.toString()); //$NON-NLS-1$ + + // function - void f() + IASTFunctionDefinition funcdef_f = (IASTFunctionDefinition) declarations + .get(1); + IASTSimpleDeclSpecifier declspec_f = (IASTSimpleDeclSpecifier) funcdef_f + .getDeclSpecifier(); + assertEquals(IASTSimpleDeclSpecifier.t_void, declspec_f.getType()); + IASTFunctionDeclarator declor_f = funcdef_f + .getDeclarator(); + IASTName name_f = declor_f.getName(); + assertEquals("f", name_f.toString()); //$NON-NLS-1$ + + // parameter - int y + IASTParameterDeclaration decl_y = (IASTParameterDeclaration) declor_f + .getParameters().get(0); + IASTSimpleDeclSpecifier declspec_y = (IASTSimpleDeclSpecifier) decl_y + .getDeclSpecifier(); + assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_y.getType()); + IASTDeclarator declor_y = decl_y.getDeclarator(); + IASTName name_y = declor_y.getName(); + assertEquals("y", name_y.toString()); //$NON-NLS-1$ + + // int z + IASTCompoundStatement body_f = (IASTCompoundStatement) funcdef_f + .getBody(); + IASTDeclarationStatement declstmt_z = (IASTDeclarationStatement) body_f + .getStatements().get(0); + IASTSimpleDeclaration decl_z = (IASTSimpleDeclaration) declstmt_z + .getDeclaration(); + IASTSimpleDeclSpecifier declspec_z = (IASTSimpleDeclSpecifier) decl_z + .getDeclSpecifier(); + assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_z.getType()); + IASTDeclarator declor_z = (IASTDeclarator) decl_z.getDeclarators().get( + 0); + IASTName name_z = declor_z.getName(); + assertEquals("z", name_z.toString()); //$NON-NLS-1$ + + // = x + y + IASTInitializerExpression initializer = (IASTInitializerExpression) declor_z.getInitializer(); + IASTBinaryExpression init_z = (IASTBinaryExpression) initializer.getExpression(); + assertEquals(IASTBinaryExpression.op_plus, init_z.getOperator()); + IASTIdExpression ref_x = (IASTIdExpression) init_z.getOperand1(); + IASTName name_ref_x = ref_x.getName(); + assertEquals("x", name_ref_x.toString()); //$NON-NLS-1$ + + IASTIdExpression ref_y = (IASTIdExpression) init_z.getOperand2(); + IASTName name_ref_y = ref_y.getName(); + assertEquals("y", name_ref_y.toString()); //$NON-NLS-1$ + + //BINDINGS + // resolve the binding to get the variable object + IVariable var_x = (IVariable) name_x.resolveBinding(); + assertEquals(globalScope, var_x.getScope()); + IFunction func_f = (IFunction) name_f.resolveBinding(); + assertEquals(globalScope, func_f.getScope()); + IParameter var_y = (IParameter) name_y.resolveBinding(); + assertEquals(func_f.getFunctionScope(), var_y.getScope()); + + IVariable var_z = (IVariable) name_z.resolveBinding(); + assertEquals(func_f.getFunctionScope(), var_z.getScope()); + + // make sure the variable referenced is the same one we declared above + assertEquals(var_x, name_ref_x.resolveBinding()); + assertEquals(var_y, name_ref_y.resolveBinding()); + + } + + public void testSimpleStruct() throws ParserException { + StringBuffer buff = new StringBuffer(); + buff.append("typedef struct {\n"); //$NON-NLS-1$ + buff.append(" int x;\n"); //$NON-NLS-1$ + buff.append("} S;\n"); //$NON-NLS-1$ + + buff.append("void f() {\n"); //$NON-NLS-1$ + buff.append(" S myS;\n"); //$NON-NLS-1$ + buff.append(" myS.x = 5;"); //$NON-NLS-1$ + buff.append("}"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C ); + IASTSimpleDeclaration decl = (IASTSimpleDeclaration)tu.getDeclarations().get(0); + IASTCompositeTypeSpecifier type = (IASTCompositeTypeSpecifier)decl.getDeclSpecifier(); + + // it's a typedef + assertEquals(IASTDeclSpecifier.sc_typedef, type.getStorageClass()); + // this an anonymous struct + IASTName name_struct = type.getName(); + assertNull("", name_struct.toString()); //$NON-NLS-1$ + // member - x + IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) type + .getMembers().get(0); + IASTSimpleDeclSpecifier spec_x = (IASTSimpleDeclSpecifier) decl_x + .getDeclSpecifier(); + // it's an int + assertEquals(IASTSimpleDeclSpecifier.t_int, spec_x.getType()); + IASTDeclarator tor_x = (IASTDeclarator) decl_x + .getDeclarators().get(0); + IASTName name_x = tor_x.getName(); + assertEquals("x", name_x.toString()); //$NON-NLS-1$ + + // declarator S + IASTDeclarator tor_S = (IASTDeclarator) decl.getDeclarators().get(0); + IASTName name_S = tor_S.getName(); + assertEquals("S", name_S.toString()); //$NON-NLS-1$ + + // function f + IASTFunctionDefinition def_f = (IASTFunctionDefinition) tu + .getDeclarations().get(1); + // f's body + IASTCompoundStatement body_f = (IASTCompoundStatement) def_f.getBody(); + // the declaration statement for myS + IASTDeclarationStatement declstmt_myS = (IASTDeclarationStatement)body_f.getStatements().get(0); + // the declaration for myS + IASTSimpleDeclaration decl_myS = (IASTSimpleDeclaration)declstmt_myS.getDeclaration(); + // the type specifier for myS + IASTTypedefNameSpecifier type_spec_myS = (IASTTypedefNameSpecifier)decl_myS.getDeclSpecifier(); + // the type name for myS + IASTName name_type_myS = type_spec_myS.getName(); + // the declarator for myS + IASTDeclarator tor_myS = (IASTDeclarator)decl_myS.getDeclarators().get(0); + // the name for myS + IASTName name_myS = tor_myS.getName(); + // the assignment expression statement + IASTExpressionStatement exprstmt = (IASTExpressionStatement)body_f.getStatements().get(1); + // the assignment expression + IASTBinaryExpression assexpr = (IASTBinaryExpression)exprstmt.getExpression(); + // the field reference to myS.x + IASTFieldReference fieldref = (IASTFieldReference)assexpr.getOperand1(); + // the reference to myS + IASTIdExpression ref_myS = (IASTIdExpression)fieldref.getFieldOwner(); + IASTLiteralExpression lit_5 = (IASTLiteralExpression)assexpr.getOperand2(); + assertEquals("5", lit_5.toString()); //$NON-NLS-1$ + + //Logical Bindings In Test + ICompositeType type_struct = (ICompositeType) name_struct.resolveBinding(); + ITypedef typedef_S = (ITypedef) name_S.resolveBinding(); + // make sure the typedef is hooked up correctly + assertEquals(type_struct, typedef_S.getType()); + // the typedef S for myS + ITypedef typedef_myS = (ITypedef)name_type_myS.resolveBinding(); + assertEquals(typedef_S, typedef_myS); + // get the real type for S which is our anonymous struct + ICompositeType type_myS = (ICompositeType)typedef_myS.getType(); + assertEquals( type_myS, type_struct ); + // the variable myS + IVariable var_myS = (IVariable)name_myS.resolveBinding(); + assertEquals(typedef_S, var_myS.getType()); + assertEquals(var_myS, ref_myS.getName().resolveBinding()); + IField field_x = (IField)name_x.resolveBinding(); + assertEquals(field_x, fieldref.getFieldName().resolveBinding()); + } + + public void testCExpressions() throws ParserException + { + validateSimpleUnaryExpressionC( "++x", IASTUnaryExpression.op_prefixIncr ); //$NON-NLS-1$ + validateSimpleUnaryExpressionC( "--x", IASTUnaryExpression.op_prefixDecr ); //$NON-NLS-1$ + validateSimpleUnaryExpressionC( "+x", IASTUnaryExpression.op_plus ); //$NON-NLS-1$ + validateSimpleUnaryExpressionC( "-x", IASTUnaryExpression.op_minus ); //$NON-NLS-1$ + validateSimpleUnaryExpressionC( "!x", IASTUnaryExpression.op_not ); //$NON-NLS-1$ + validateSimpleUnaryExpressionC( "~x", IASTUnaryExpression.op_tilde ); //$NON-NLS-1$ + validateSimpleUnaryExpressionC( "*x", IASTUnaryExpression.op_star ); //$NON-NLS-1$ + validateSimpleUnaryExpressionC( "&x", IASTUnaryExpression.op_amper ); //$NON-NLS-1$ + validateSimpleUnaryExpressionC( "sizeof x", IASTUnaryExpression.op_sizeof ); //$NON-NLS-1$ + validateSimpleTypeIdExpressionC( "sizeof( int )", IASTTypeIdExpression.op_sizeof ); //$NON-NLS-1$ + validateSimpleUnaryTypeIdExpression( "(int)x", IASTUnaryTypeIdExpression.op_cast ); //$NON-NLS-1$ + validateSimplePostfixInitializerExpressionC( "(int) { 5 }"); //$NON-NLS-1$ + validateSimplePostfixInitializerExpressionC( "(int) { 5, }"); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x=y", IASTBinaryExpression.op_assign ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x*=y", IASTBinaryExpression.op_multiplyAssign ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x/=y", IASTBinaryExpression.op_divideAssign ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x%=y", IASTBinaryExpression.op_moduloAssign ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x+=y", IASTBinaryExpression.op_plusAssign); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x-=y", IASTBinaryExpression.op_minusAssign ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x<<=y", IASTBinaryExpression.op_shiftLeftAssign); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x>>=y", IASTBinaryExpression.op_shiftRightAssign ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x&=y", IASTBinaryExpression.op_binaryAndAssign ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x^=y", IASTBinaryExpression.op_binaryXorAssign ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x|=y", IASTBinaryExpression.op_binaryOrAssign ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x-y", IASTBinaryExpression.op_minus ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x+y", IASTBinaryExpression.op_plus ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x/y", IASTBinaryExpression.op_divide ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x*y", IASTBinaryExpression.op_multiply); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x%y", IASTBinaryExpression.op_modulo ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x<>y", IASTBinaryExpression.op_shiftRight ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("xy", IASTBinaryExpression.op_greaterThan); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x<=y", IASTBinaryExpression.op_lessEqual ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x>=y", IASTBinaryExpression.op_greaterEqual ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x==y", IASTBinaryExpression.op_equals ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x!=y", IASTBinaryExpression.op_notequals ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x&y", IASTBinaryExpression.op_binaryAnd ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x^y", IASTBinaryExpression.op_binaryXor ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x|y", IASTBinaryExpression.op_binaryOr ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x&&y", IASTBinaryExpression.op_logicalAnd ); //$NON-NLS-1$ + validateSimpleBinaryExpressionC("x||y", IASTBinaryExpression.op_logicalOr ); //$NON-NLS-1$ + validateConditionalExpressionC( "x ? y : x" ); //$NON-NLS-1$ + } + + /** + * @param string + */ + protected void validateSimplePostfixInitializerExpressionC(String code ) throws ParserException { + ICASTTypeIdInitializerExpression e = (ICASTTypeIdInitializerExpression) getExpressionFromStatementInCode(code, ParserLanguage.C ); + assertNotNull( e ); + assertNotNull( e.getTypeId() ); + assertNotNull( e.getInitializer() ); + } + + + /** + * @param string + * @throws ParserException + */ + protected void validateSimpleUnaryTypeIdExpression(String code, int op ) throws ParserException { + IASTUnaryTypeIdExpression e = (IASTUnaryTypeIdExpression) getExpressionFromStatementInCode( code, ParserLanguage.C ); + assertNotNull( e ); + assertEquals( e.getOperator(), op ); + assertNotNull( e.getTypeId() ); + IASTIdExpression x = (IASTIdExpression) e.getOperand(); + assertEquals( x.getName().toString(), "x"); //$NON-NLS-1$ + } + + + /** + * @param code + * @param op + * @throws ParserException + */ + protected void validateSimpleTypeIdExpressionC(String code, int op ) throws ParserException { + IASTTypeIdExpression e = (IASTTypeIdExpression) getExpressionFromStatementInCode( code, ParserLanguage.C ); + assertNotNull( e ); + assertEquals( e.getOperator(), op ); + assertNotNull( e.getTypeId() ); + } + + + /** + * @param string + * @param op_prefixIncr + * @throws ParserException + */ + protected void validateSimpleUnaryExpressionC(String code , int operator ) throws ParserException { + IASTUnaryExpression e = (IASTUnaryExpression) getExpressionFromStatementInCode( code, ParserLanguage.C ); + assertNotNull( e ); + assertEquals( e.getOperator(), operator ); + IASTIdExpression x = (IASTIdExpression) e.getOperand(); + assertEquals( x.getName().toString(), "x"); //$NON-NLS-1$ + } + + + /** + * @param code + * @throws ParserException + */ + protected void validateConditionalExpressionC(String code ) throws ParserException { + IASTConditionalExpression e = (IASTConditionalExpression) getExpressionFromStatementInCode( code , ParserLanguage.C ); + assertNotNull( e ); + IASTIdExpression x = (IASTIdExpression) e.getLogicalConditionExpression(); + assertEquals( x.getName().toString(), "x" ); //$NON-NLS-1$ + IASTIdExpression y = (IASTIdExpression) e.getPositiveResultExpression(); + assertEquals( y.getName().toString(), "y"); //$NON-NLS-1$ + IASTIdExpression x2 = (IASTIdExpression) e.getNegativeResultExpression(); + assertEquals( x.getName().toString(), x2.getName().toString() ); + } + + + /** + * @param operand + * @throws ParserException + */ + protected void validateSimpleBinaryExpressionC( String code, int operand) throws ParserException { + IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode( code, ParserLanguage.C ); //$NON-NLS-1$ + assertNotNull( e ); + assertEquals( e.getOperator(), operand ); + IASTIdExpression x = (IASTIdExpression) e.getOperand1(); + assertEquals( x.getName().toString(), "x"); //$NON-NLS-1$ + IASTIdExpression y = (IASTIdExpression) e.getOperand2(); + assertEquals( y.getName().toString(), "y"); //$NON-NLS-1$ + } + + + protected IASTExpression getExpressionFromStatementInCode( String code, ParserLanguage language ) throws ParserException + { + StringBuffer buffer = new StringBuffer( "void f() { "); //$NON-NLS-1$ + buffer.append( "int x, y;\n"); //$NON-NLS-1$ + buffer.append( code ); + buffer.append( ";\n}"); //$NON-NLS-1$ + IASTTranslationUnit tu = parse( buffer.toString(), language ); + IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations().get(0); + IASTCompoundStatement cs = (IASTCompoundStatement) f.getBody(); + IASTExpressionStatement s = (IASTExpressionStatement) cs.getStatements().get( 1 ); + return s.getExpression(); + } + + + public void testMultipleDeclarators() throws Exception { + IASTTranslationUnit tu = parse( "int r, s;" , ParserLanguage.C ); //$NON-NLS-1$ + IASTSimpleDeclaration decl = (IASTSimpleDeclaration)tu.getDeclarations().get(0); + List declarators = decl.getDeclarators(); + assertEquals( 2, declarators.size() ); + + IASTDeclarator dtor1 = (IASTDeclarator) declarators.get(0); + IASTDeclarator dtor2 = (IASTDeclarator) declarators.get(1); + + IASTName name1 = dtor1.getName(); + IASTName name2 = dtor2.getName(); + + assertEquals( name1.resolveBinding().getName(), "r" ); //$NON-NLS-1$ + assertEquals( name2.resolveBinding().getName(), "s" ); //$NON-NLS-1$ + } + + public void testStructureTagScoping_1() throws Exception{ + StringBuffer buffer = new StringBuffer(); + buffer.append( "struct A; \n" ); //$NON-NLS-1$ + buffer.append( "void f(){ \n" ); //$NON-NLS-1$ + buffer.append( " struct A; \n" ); //$NON-NLS-1$ + buffer.append( " struct A * a; \n" ); //$NON-NLS-1$ + buffer.append( "} \n" ); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); + + //struct A; + IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations().get(0); + IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier(); + assertEquals( 0, decl1.getDeclarators().size() ); + IASTName nameA1 = compTypeSpec.getName(); + + //void f() { + IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations().get(1); + IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody(); + assertEquals( 2, compoundStatement.getStatements().size() ); + + // struct A; + IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements().get( 0 ); + IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration(); + compTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier(); + assertEquals( 0, decl2.getDeclarators().size() ); + IASTName nameA2 = compTypeSpec.getName(); + + // struct A * a; + declStatement = (IASTDeclarationStatement) compoundStatement.getStatements().get(1); + IASTSimpleDeclaration decl3 = (IASTSimpleDeclaration) declStatement.getDeclaration(); + compTypeSpec = (IASTElaboratedTypeSpecifier) decl3.getDeclSpecifier(); + IASTName nameA3 = compTypeSpec.getName(); + IASTDeclarator dtor = (IASTDeclarator) decl3.getDeclarators().get(0); + IASTName namea = dtor.getName(); + assertEquals( 1, dtor.getPointerOperators().size() ); + assertTrue( dtor.getPointerOperators().get(0) instanceof ICASTPointer ); + + //bindings + ICompositeType str1 = (ICompositeType) nameA1.resolveBinding(); + ICompositeType str2 = (ICompositeType) nameA2.resolveBinding(); + IVariable var = (IVariable) namea.resolveBinding(); + ICompositeType str3 = (ICompositeType) var.getType(); + ICompositeType str4 = (ICompositeType) nameA3.resolveBinding(); + assertNotNull( str1 ); + assertNotNull( str2 ); + assertNotSame( str1, str2 ); + assertSame( str2, str3 ); + assertSame( str3, str4 ); + } + + public void testStructureTagScoping_2() throws Exception{ + StringBuffer buffer = new StringBuffer(); + buffer.append( "struct A; \n" ); //$NON-NLS-1$ + buffer.append( "void f(){ \n" ); //$NON-NLS-1$ + buffer.append( " struct A * a; \n" ); //$NON-NLS-1$ + buffer.append( "} \r\n" ); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); + + //struct A; + IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration) tu.getDeclarations().get(0); + IASTElaboratedTypeSpecifier compTypeSpec = (IASTElaboratedTypeSpecifier) decl1.getDeclSpecifier(); + assertEquals( 0, decl1.getDeclarators().size() ); + IASTName nameA1 = compTypeSpec.getName(); + + //void f() { + IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations().get(1); + IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody(); + assertEquals( 1, compoundStatement.getStatements().size() ); + + // struct A * a; + IASTDeclarationStatement declStatement = (IASTDeclarationStatement) compoundStatement.getStatements().get(0); + IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration) declStatement.getDeclaration(); + compTypeSpec = (IASTElaboratedTypeSpecifier) decl2.getDeclSpecifier(); + IASTName nameA2 = compTypeSpec.getName(); + IASTDeclarator dtor = (IASTDeclarator) decl2.getDeclarators().get(0); + IASTName namea = dtor.getName(); + assertEquals( 1, dtor.getPointerOperators().size() ); + assertTrue( dtor.getPointerOperators().get(0) instanceof ICASTPointer ); + + //bindings + ICompositeType str1 = (ICompositeType) nameA1.resolveBinding(); + ICompositeType str2 = (ICompositeType) nameA2.resolveBinding(); + IVariable var = (IVariable) namea.resolveBinding(); + ICompositeType str3 = (ICompositeType) var.getType(); + assertNotNull( str1 ); + assertSame( str1, str2 ); + assertSame( str2, str3 ); + } + + public void testStructureDef() throws Exception{ + StringBuffer buffer = new StringBuffer(); + buffer.append( "struct A; \r\n"); //$NON-NLS-1$ + buffer.append( "struct A * a; \n"); //$NON-NLS-1$ + buffer.append( "struct A { int i; }; \n"); //$NON-NLS-1$ + buffer.append( "void f() { \n"); //$NON-NLS-1$ + buffer.append( " a->i; \n"); //$NON-NLS-1$ + buffer.append( "} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); + + //struct A; + IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations().get(0); + IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) decl.getDeclSpecifier(); + assertEquals( 0, decl.getDeclarators().size() ); + IASTName name_A1 = elabTypeSpec.getName(); + + //struct A * a; + decl = (IASTSimpleDeclaration) tu.getDeclarations().get(1); + elabTypeSpec = (IASTElaboratedTypeSpecifier) decl.getDeclSpecifier(); + IASTName name_A2 = elabTypeSpec.getName(); + IASTDeclarator dtor = (IASTDeclarator) decl.getDeclarators().get(0); + IASTName name_a = dtor.getName(); + assertEquals( 1, dtor.getPointerOperators().size() ); + assertTrue( dtor.getPointerOperators().get(0) instanceof ICASTPointer ); + + //struct A { + decl = (IASTSimpleDeclaration) tu.getDeclarations().get(2); + ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) decl.getDeclSpecifier(); + IASTName name_Adef = compTypeSpec.getName(); + + // int i; + decl = (IASTSimpleDeclaration) compTypeSpec.getMembers().get(0); + dtor = (IASTDeclarator) decl.getDeclarators().get(0); + IASTName name_i = dtor.getName(); + + //void f() { + IASTFunctionDefinition fndef = (IASTFunctionDefinition) tu.getDeclarations().get(3); + IASTCompoundStatement compoundStatement = (IASTCompoundStatement) fndef.getBody(); + assertEquals( 1, compoundStatement.getStatements().size() ); + + // a->i; + IASTExpressionStatement exprstmt = (IASTExpressionStatement)compoundStatement.getStatements().get(0); + IASTFieldReference fieldref = (IASTFieldReference)exprstmt.getExpression(); + IASTIdExpression id_a = (IASTIdExpression) fieldref.getFieldOwner(); + IASTName name_aref = id_a.getName(); + IASTName name_iref = fieldref.getFieldName(); + + //bindings + IVariable var_a1 = (IVariable) name_aref.resolveBinding(); + IVariable var_i1 = (IVariable) name_iref.resolveBinding(); + ICompositeType structA_1 = (ICompositeType) var_a1.getType(); + ICompositeType structA_2 = (ICompositeType) name_A1.resolveBinding(); + ICompositeType structA_3 = (ICompositeType) name_A2.resolveBinding(); + ICompositeType structA_4 = (ICompositeType) name_Adef.resolveBinding(); + + IVariable var_a2 = (IVariable) name_a.resolveBinding(); + IVariable var_i2 = (IVariable) name_i.resolveBinding(); + + assertSame( var_a1, var_a2 ); + assertSame( var_i1, var_i2 ); + assertSame( structA_1, structA_2 ); + assertSame( structA_2, structA_3 ); + assertSame( structA_3, structA_4 ); + } + + public void testFunctionParameters() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append( "void f( int a ); \n"); //$NON-NLS-1$ + buffer.append( "void f( int b ){ \n"); //$NON-NLS-1$ + buffer.append( " b; \n"); //$NON-NLS-1$ + buffer.append( "} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); + + //void f( + IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration) tu.getDeclarations().get(0); + IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) f_decl.getDeclarators().get(0); + IASTName f_name1 = dtor.getName(); + // int a ); + IASTParameterDeclaration param = (IASTParameterDeclaration) dtor.getParameters().get(0); + IASTDeclarator paramDtor = param.getDeclarator(); + IASTName name_param1 = paramDtor.getName(); + + //void f( + IASTFunctionDefinition f_defn = (IASTFunctionDefinition) tu.getDeclarations().get(1); + dtor = f_defn.getDeclarator(); + IASTName f_name2 = dtor.getName(); + // int b ); + param = (IASTParameterDeclaration) dtor.getParameters().get(0); + paramDtor = param.getDeclarator(); + IASTName name_param2 = paramDtor.getName(); + + // b; + IASTCompoundStatement compound = (IASTCompoundStatement) f_defn.getBody(); + IASTExpressionStatement expStatement = (IASTExpressionStatement) compound.getStatements().get(0); + IASTIdExpression idexp = (IASTIdExpression) expStatement.getExpression(); + IASTName name_param3 = idexp.getName(); + + //bindings + IParameter param_1 = (IParameter) name_param3.resolveBinding(); + IParameter param_2 = (IParameter) name_param2.resolveBinding(); + IParameter param_3 = (IParameter) name_param1.resolveBinding(); + IFunction f_1 = (IFunction) f_name1.resolveBinding(); + IFunction f_2 = (IFunction) f_name2.resolveBinding(); + + assertNotNull( param_1 ); + assertNotNull( f_1 ); + assertSame( param_1, param_2 ); + assertSame( param_2, param_3 ); + assertSame( f_1, f_2 ); + + CVisitor.clearBindings( tu ); + param_1 = (IParameter) name_param1.resolveBinding(); + param_2 = (IParameter) name_param3.resolveBinding(); + param_3 = (IParameter) name_param2.resolveBinding(); + f_1 = (IFunction) f_name2.resolveBinding(); + f_2 = (IFunction) f_name1.resolveBinding(); + assertNotNull( param_1 ); + assertNotNull( f_1 ); + assertSame( param_1, param_2 ); + assertSame( param_2, param_3 ); + assertSame( f_1, f_2 ); + } + + public void testSimpleFunction() throws Exception { + StringBuffer buffer = new StringBuffer( "void f( int a, int b ) { } \n" ); //$NON-NLS-1$ + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); + + IASTFunctionDefinition fDef = (IASTFunctionDefinition) tu.getDeclarations().get(0); + IASTFunctionDeclarator fDtor = fDef.getDeclarator(); + IASTName fName = fDtor.getName(); + + IASTParameterDeclaration a = (IASTParameterDeclaration) fDtor.getParameters().get( 0 ); + IASTName name_a = a.getDeclarator().getName(); + + IASTParameterDeclaration b = (IASTParameterDeclaration) fDtor.getParameters().get( 1 ); + IASTName name_b = b.getDeclarator().getName(); + + IFunction function = (IFunction) fName.resolveBinding(); + IParameter param_a = (IParameter) name_a.resolveBinding(); + IParameter param_b = (IParameter) name_b.resolveBinding(); + + assertEquals( "f", function.getName() ); //$NON-NLS-1$ + assertEquals( "a", param_a.getName() ); //$NON-NLS-1$ + assertEquals( "b", param_b.getName() ); //$NON-NLS-1$ + + List params = function.getParameters(); + assertEquals( 2, params.size() ); + assertSame( params.get(0), param_a ); + assertSame( params.get(1), param_b ); + } + + public void testSimpleFunctionCall() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append( "void f(); \n" ); //$NON-NLS-1$ + buffer.append( "void g() { \n" ); //$NON-NLS-1$ + buffer.append( " f(); \n" ); //$NON-NLS-1$ + buffer.append( "} \n" ); //$NON-NLS-1$ + buffer.append( "void f(){ } \n" ); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); + + //void f(); + IASTSimpleDeclaration fdecl = (IASTSimpleDeclaration) tu.getDeclarations().get(0); + IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) fdecl.getDeclarators().get(0); + IASTName name_f = fdtor.getName(); + + //void g() { + IASTFunctionDefinition gdef = (IASTFunctionDefinition) tu.getDeclarations().get(1); + + // f(); + IASTCompoundStatement compound = (IASTCompoundStatement) gdef.getBody(); + IASTExpressionStatement expStatement = (IASTExpressionStatement) compound.getStatements().get(0); + IASTFunctionCallExpression fcall = (IASTFunctionCallExpression) expStatement.getExpression(); + IASTIdExpression fcall_id = (IASTIdExpression) fcall.getFunctionNameExpression(); + IASTName name_fcall = fcall_id.getName(); + assertNull( fcall.getParameterExpression() ); + + //void f() {} + IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations().get(2); + fdtor = fdef.getDeclarator(); + IASTName name_fdef = fdtor.getName(); + + //bindings + IFunction function_1 = (IFunction) name_fcall.resolveBinding(); + IFunction function_2 = (IFunction) name_f.resolveBinding(); + IFunction function_3 = (IFunction) name_fdef.resolveBinding(); + + assertNotNull( function_1 ); + assertSame( function_1, function_2 ); + assertSame( function_2, function_3 ); + } + + public void testForLoop() throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append( "void f() { \n"); //$NON-NLS-1$ + buffer.append( " for( int i = 0; i < 5; i++ ) { \n"); //$NON-NLS-1$ + buffer.append( " i; \n"); //$NON-NLS-1$ + buffer.append( " } \n"); //$NON-NLS-1$ + buffer.append( "} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); + + //void f() { + IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations().get(0); + IASTCompoundStatement compound = (IASTCompoundStatement) fdef.getBody(); + + // for( + IASTForStatement for_stmt = (IASTForStatement) compound.getStatements().get(0); + // int i = 0; + assertNull( for_stmt.getInitExpression() ); + IASTSimpleDeclaration initDecl = (IASTSimpleDeclaration) for_stmt.getInitDeclaration(); + IASTDeclarator dtor = (IASTDeclarator) initDecl.getDeclarators().get(0); + IASTName name_i = dtor.getName(); + // i < 5; + IASTBinaryExpression exp = (IASTBinaryExpression) for_stmt.getCondition(); + IASTIdExpression id_i = (IASTIdExpression) exp.getOperand1(); + IASTName name_i2 = id_i.getName(); + IASTLiteralExpression lit_5 = (IASTLiteralExpression) exp.getOperand2(); + assertEquals( IASTLiteralExpression.lk_integer_constant, lit_5.getKind() ); + // i++ ) { + IASTUnaryExpression un = (IASTUnaryExpression) for_stmt.getIterationExpression(); + IASTIdExpression id_i2 = (IASTIdExpression) un.getOperand(); + IASTName name_i3 = id_i2.getName(); + assertEquals( IASTUnaryExpression.op_postFixIncr, un.getOperator() ); + + // i; + compound = (IASTCompoundStatement) for_stmt.getBody(); + IASTExpressionStatement exprSt = (IASTExpressionStatement) compound.getStatements().get(0); + IASTIdExpression id_i3 = (IASTIdExpression) exprSt.getExpression(); + IASTName name_i4 = id_i3.getName(); + + //bindings + IVariable var_1 = (IVariable) name_i4.resolveBinding(); + IVariable var_2 = (IVariable) name_i.resolveBinding(); + IVariable var_3 = (IVariable) name_i2.resolveBinding(); + IVariable var_4 = (IVariable) name_i3.resolveBinding(); + + assertSame( var_1, var_2 ); + assertSame( var_2, var_3 ); + assertSame( var_3, var_4 ); + } + + public void testExpressionFieldReference() throws Exception{ + StringBuffer buffer = new StringBuffer(); + buffer.append( "struct A { int x; }; \n"); //$NON-NLS-1$ + buffer.append( "void f(){ \n"); //$NON-NLS-1$ + buffer.append( " ((struct A *) 1)->x; \n"); //$NON-NLS-1$ + buffer.append( "} \n"); //$NON-NLS-1$ + + IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C ); + + IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) tu.getDeclarations().get(0); + IASTCompositeTypeSpecifier compType = (IASTCompositeTypeSpecifier) simpleDecl.getDeclSpecifier(); + IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) compType.getMembers().get(0); + IASTName name_x1 = ((IASTDeclarator) decl_x.getDeclarators().get(0)).getName(); + IASTFunctionDefinition fdef = (IASTFunctionDefinition) tu.getDeclarations().get(1); + IASTCompoundStatement body = (IASTCompoundStatement) fdef.getBody(); + IASTExpressionStatement expStatement = (IASTExpressionStatement) body.getStatements().get(0); + IASTFieldReference fieldRef = (IASTFieldReference) expStatement.getExpression(); + IASTName name_x2 = fieldRef.getFieldName(); + + IField x1 = (IField) name_x1.resolveBinding(); + IField x2 = (IField) name_x2.resolveBinding(); + + assertNotNull( x1 ); + assertSame( x1, x2 ); + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ScannerConfigFactory.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ScannerConfigFactory.java new file mode 100644 index 00000000000..e5f5e07bda5 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/ScannerConfigFactory.java @@ -0,0 +1,121 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.parser.tests.ast2; + +import java.util.Hashtable; +import java.util.Map; + +import org.eclipse.cdt.core.parser.IScannerInfo; +import org.eclipse.cdt.core.parser.ScannerInfo; + +/** + * @author Doug Schaefer + */ +public class ScannerConfigFactory { + + public static IScannerInfo getScannerInfo() { + String config = System.getProperty("speedTest.config"); + + if (config == null) + return mingwScannerInfo(); + + if (config.equals("msvc")) + return msvcScannerInfo(); + else if (config.equals("ydl")) + return ydlScannerInfo(); + else + return mingwScannerInfo(); + } + + private static IScannerInfo msvcScannerInfo() { + 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 static IScannerInfo mingwScannerInfo() { + // TODO It would be easier and more flexible if we used discovery for this + 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 static IScannerInfo ydlScannerInfo() { + // TODO It would be easier and more flexible if we used discovery for this + 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/parser2/QuickParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/QuickParser2Tests.java new file mode 100644 index 00000000000..b771b9d1c86 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/QuickParser2Tests.java @@ -0,0 +1,1591 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.parser.tests.parser2; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.core.parser.IProblem; +import org.eclipse.cdt.core.parser.IScanner; +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.ParserLanguage; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.core.parser.ScannerInfo; +import org.eclipse.cdt.internal.core.parser.ParserException; +import org.eclipse.cdt.internal.core.parser2.ISourceCodeParser; +import org.eclipse.cdt.internal.core.parser2.c.ANSICParserExtensionConfiguration; +import org.eclipse.cdt.internal.core.parser2.c.GCCParserExtensionConfiguration; +import org.eclipse.cdt.internal.core.parser2.c.GNUCSourceParser; +import org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration; +import org.eclipse.cdt.internal.core.parser2.cpp.ANSICPPParserExtensionConfiguration; +import org.eclipse.cdt.internal.core.parser2.cpp.GNUCPPParserExtensionConfiguration; +import org.eclipse.cdt.internal.core.parser2.cpp.GNUCPPSourceParser; +import org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration; +import org.eclipse.cdt.internal.core.parser2.cpp.IProblemRequestor; + +/** + * @author jcamelon + */ +public class QuickParser2Tests extends TestCase { + + /** + * @author jcamelon + */ + public static class ProblemCollector implements IProblemRequestor { + + List problems = new ArrayList(); + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.IProblemRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem) + */ + public boolean acceptProblem(IProblem problem) { + problems.add( problem ); + return true; + } + + /** + * @return + */ + public boolean hasNoProblems() { + return problems.isEmpty(); + } + + } + private static final NullLogService NULL_LOG = new NullLogService(); + private static final NullSourceElementRequestor NULL_REQUESTOR = new NullSourceElementRequestor(); + /** + * + */ + public QuickParser2Tests() { + super(); + } + + /** + * @param name + */ + public QuickParser2Tests(String name) { + super(name); + } + + /** + * 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 + parse("int x = 5;"); //$NON-NLS-1$ + } + + /** + * 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$ + parse(code.toString()); + } + + /** + * 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$ + parse(code.toString()); + } + + protected void parse( String code, boolean expectedToPass, ParserLanguage lang ) throws Exception + { + parse( code, expectedToPass, lang, false ); + } + protected void parse( String code, boolean expectedToPass ) throws Exception + { + parse( code, expectedToPass, ParserLanguage.CPP ); + } + /** + * @param code + */ + protected void parse(String code) throws Exception { + parse( code, true, ParserLanguage.CPP ); + } + + public void testNamespaceDefinition() throws Exception { + for (int i = 0; i < 2; ++i) { + if (i == 0) + parse("namespace KingJohn { int x; }"); //$NON-NLS-1$ + else + parse("namespace { int x; }"); //$NON-NLS-1$ + } + } + + public void testLinkageSpecification() throws Exception { + for (int i = 0; i < 2; ++i) { + if (i == 0) + parse("extern \"C\" { int x(void); }"); //$NON-NLS-1$ + else + parse("extern \"ADA\" int x(void);"); //$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$ + parse(code.toString()); + } + + public void testTypedef() throws Exception { + parse("typedef const struct A * const 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$ + parse(code.toString()); + } + + /** + * 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$ + parse(code.toString()); + } + + /** + * 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$ + parse(code.toString()); + } + + /** + * 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$ + parse(code.toString()); + } + + 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 { + parse( + "template<> class stream { /* ... */ };"); //$NON-NLS-1$ + } + + public void testTemplateInstantiation() throws Exception { + parse("template class Array;"); //$NON-NLS-1$ + } + + /** + * Test code: "class A { int floor( double input ), someInt; };" + */ + public void testMultipleDeclarators() throws Exception { + // Parse and get the translaton unit + parse( "class A { int floor( double input ), someInt; };"); //$NON-NLS-1$ + } + + public void testFunctionModifiers() throws Exception { + parse( "class A {virtual void foo( void ) const throw ( yay, nay, we::dont::care ) = 0;};"); //$NON-NLS-1$ + } + + public void testArrays() throws Exception { + parse("int x [5][];"); //$NON-NLS-1$ + } + + public void testElaboratedParms() throws Exception { + parse("int x( struct A myA ) { /* junk */ }"); //$NON-NLS-1$ + } + + 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$ + parse(code.toString()); + } + + public void testPointerOperators() throws Exception { + parse( + "int * x = 0, & y, * const * volatile * z;"); //$NON-NLS-1$ + } + + 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$ + parse(code.toString()); + } + + public void testASMDefinition() throws Exception { + parse("asm( \"mov ep1 ds2\");"); //$NON-NLS-1$ + } + + public void testConstructorChain() throws Exception { + parse( "TrafficLight_Actor::TrafficLight_Actor( RTController * rtg_rts, RTActorRef * rtg_ref ) : RTActor( rtg_rts, rtg_ref ), myId( 0 ) {}"); //$NON-NLS-1$ + } + + public void testBug36237() throws Exception { + parse("A::A():B( (char *)0 ){}"); //$NON-NLS-1$ + } + + public void testBug36532() throws Exception { + try { + parse("template A aTemplatedFunction( B bInstance );"); //$NON-NLS-1$ + } + + public void testTemplateDeclarationOfClass() throws Exception { + parse( "template class, template class AClass> class myarray { /* ... */ };"); //$NON-NLS-1$ + } + + 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$ + parse(code.toString()); + } + + public void testBug36288() throws Exception { + parse("int foo() {}\nlong foo2(){}"); //$NON-NLS-1$ + } + + public void testBug36250() throws Exception { + parse("int f( int = 0 );"); //$NON-NLS-1$ + } + + public void testBug36240() throws Exception { + parse("A & A::operator=( A ){}"); //$NON-NLS-1$ + } + + public void testBug36254() throws Exception { + parse("unsigned i;\nvoid f( unsigned p1 = 0 );"); //$NON-NLS-1$ + } + + 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$ + } + + 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()); + } + + public void testBug36771() throws Exception { + Writer code = new StringWriter(); + code.write("#include /**/ \"foo.h\"\n"); //$NON-NLS-1$ + + parse(code.toString()); + } + + 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()); + } + + public void testBug36708() throws Exception { + parse( + "enum { isPointer = PointerTraits::result };"); //$NON-NLS-1$ + } + + public void testBug36690() throws Exception { + parse( + "Functor(const Functor& rhs) : spImpl_(Impl::Clone(rhs.spImpl_.get())){}"); //$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(), 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$ + + parse(code.toString()); + } + + public void testBug36600() throws Exception { + parse( + "enum mad_flow (*input_func)(void *, struct mad_stream *);"); //$NON-NLS-1$ + } + + 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()); + } + + // 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 { + parse("void (A::*name)(void);"); //$NON-NLS-1$ + } + + public void testBug39550() throws Exception { + parse("double x = 0x1.fp1;"); //$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$ + } + + public void testBug39537() throws Exception { + parse("typedef foo<(U::id > 0)> foobar;"); //$NON-NLS-1$ + } + + public void testBug39546() throws Exception { + parse("signed char c = (signed char) 0xffffffff;"); //$NON-NLS-1$ + } + + public void testIndirectDeclarators() throws Exception { + parse("void (*x)( int );"); //$NON-NLS-1$ + } + + public void testBug39532() throws Exception { + parse("class N1::N2::B : public A {};"); //$NON-NLS-1$ + } + + public void testBug39540() throws Exception { + parse("class {} const null;"); //$NON-NLS-1$ + } + + 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, ParserLanguage.C); //$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$ + parse(code.toString()); + } + + public void testBug43644() throws Exception { + parse("void foo();{ int x; }", false); //$NON-NLS-1$ + } + + public void testBug43062() throws Exception { + parse( + "class X { operator short (); operator int unsigned(); 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 { + parse("int y = #;", false); //$NON-NLS-1$ + } + + public void testBug40759() throws Exception { + parse("#define X SomeName \n class X {};"); //$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$ + parse(writer.toString()); + } + + public void testBug39525() throws Exception { + parse("C &(C::*DD)(const C &x) = &C::operator=;"); //$NON-NLS-1$ + } + + public void testBug41935() throws Exception { + parse("namespace A { int x; } namespace B = A;"); //$NON-NLS-1$ + } + + 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) { + } + parse(code.toString()); + } + + 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$ + parse(writer.toString()); + } + + public void testBug39536A() throws Exception { + parse( + "template class X { X(); };"); //$NON-NLS-1$ + } + + 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, 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, ParserLanguage.C); //$NON-NLS-1$ + } + + public void testBug39551A() throws Exception { + parse( + "extern float _Complex conjf (float _Complex);", true, ParserLanguage.C); //$NON-NLS-1$ + } + + public void testBug39551B() throws Exception { + parse( + "_Imaginary double id = 99.99 * __I__;", true, ParserLanguage.C); //$NON-NLS-1$ + } + + public void testCBool() throws Exception { + parse( "_Bool x;", true, ParserLanguage.C); //$NON-NLS-1$ + } + + public void testBug39678() throws Exception { + parse("char *s = L\"a\" \"b\";"); //$NON-NLS-1$ + } + + public void testBug43110() throws Exception { + parse("void x( int y, ... );"); //$NON-NLS-1$ + } + + // 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$ + parse(writer.toString()); + } + + public void testBug44336() throws Exception { + parse("class A {}; typedef typename A foo;"); //$NON-NLS-1$ + } + + public void testBug39705() throws Exception { + parse("#ident \"@(#)filename.c 1.3 90/02/12\""); //$NON-NLS-1$ + } + + public void testBug45235() throws Exception { + parse("class A { friend class B; friend void f(); }; "); //$NON-NLS-1$ + } + + public void testBug59179() throws Exception { + parse("class __decl main{ int main; };", false); //$NON-NLS-1$ + } + + public void testBug57652() throws Exception { + parse( "struct file_operations driver_fops = { open: device_open, release: device_release };", true, ParserLanguage.C, true); //$NON-NLS-1$ + } + + /** + * @param string + * @param b + * @param c + * @param d + */ + protected void parse(String code, boolean expectedToPass, ParserLanguage lang, boolean gcc ) throws Exception { + + ProblemCollector collector = new ProblemCollector(); + IScanner scanner = ParserFactory.createScanner(new CodeReader(code + .toCharArray()), new ScannerInfo(), ParserMode.QUICK_PARSE, + lang, NULL_REQUESTOR, + NULL_LOG, Collections.EMPTY_LIST); + ISourceCodeParser parser2 = null; + if( lang == ParserLanguage.CPP ) + { + ICPPParserExtensionConfiguration config = null; + if( gcc ) + config = new GNUCPPParserExtensionConfiguration(); + else + config = new ANSICPPParserExtensionConfiguration(); + parser2 = new GNUCPPSourceParser(scanner, ParserMode.QUICK_PARSE, collector, + NULL_LOG, + config ); + } + else + { + ICParserExtensionConfiguration config = null; + if( gcc ) + config = new GCCParserExtensionConfiguration(); + else + config = new ANSICParserExtensionConfiguration(); + + parser2 = new GNUCSourceParser( scanner, ParserMode.QUICK_PARSE, collector, + NULL_LOG, config ); + } + IASTTranslationUnit tu = parser2.parse(); + if( parser2.encounteredError() && expectedToPass ) + throw new ParserException( "FAILURE"); //$NON-NLS-1$ + if( expectedToPass ) + assertTrue( collector.hasNoProblems() ); + } + + public void testBug60142() throws Exception { + parse("unsigned long var;"); //$NON-NLS-1$ + } + + public void testBug61431() throws Exception { + for (int i = 0; i < 2; ++i) { + ParserLanguage language = (i == 0) ? ParserLanguage.C + : ParserLanguage.CPP; + parse( + "int k[][] = { {0, {1}, {2,3}};", false, language); //$NON-NLS-1$ + } + } + + public void testBadIdentifier() throws Exception { + parse("class 0302 { private: int stinks; };", 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$ + parse(writer.toString()); + } + + 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$ + parse( + writer.toString(), true, ParserLanguage.C); + } + + public void testBug39694() throws Exception + { + parse("int ab$cd = 1;"); //$NON-NLS-1$ + } + + public void testBug39704A() throws Exception + { + parse("__declspec (dllimport) int foo;"); //$NON-NLS-1$ + } + public void testBug39704D() throws Exception + { + parse("__declspec(dllexport) int func1 (int a) {}"); //$NON-NLS-1$ + } + + public void testBug39695() throws Exception + { + parse("int a = __alignof__ (int);", true, ParserLanguage.CPP, true); //$NON-NLS-1$ + } + + public void testBug39684() throws Exception + { + parse("typeof(foo(1)) bar () { return foo(1); }", true, ParserLanguage.CPP, true); //$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$ + parse(code.toString(), true, ParserLanguage.CPP, true); + } + + public void testBug39698A() throws Exception + { + parse("int c = a ? b;", true, ParserLanguage.CPP, true); //$NON-NLS-1$ + } + + public void testBug39554() throws Exception + { + parse("_Pragma(\"foobar\")", true, ParserLanguage.C ); //$NON-NLS-1$ + } + + public void testBug39704B() throws Exception + { + parse("extern int (* import) (void) __attribute__((dllimport));", true, ParserLanguage.CPP, true); //$NON-NLS-1$ + } + public void testBug39704C() throws Exception + { + parse("int func2 (void) __attribute__((dllexport));", true, ParserLanguage.CPP, true); //$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(), true, ParserLanguage.C, true); + } + + 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; })) {}", true, ParserLanguage.CPP, true); //$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(), true, ParserLanguage.CPP, true ); + 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() , true, ParserLanguage.CPP, true); + 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$ + parse( writer.toString() , true, ParserLanguage.CPP, true); + } + + public void testBug39701A() throws Exception + { + parse("extern template int max (int, int);", true, ParserLanguage.CPP, true); //$NON-NLS-1$ + } + public void testBug39701B() throws Exception + { + parse("inline template class Foo;", true, ParserLanguage.CPP, true); //$NON-NLS-1$ + } + public void testBug39701C() throws Exception + { + parse("static template class Foo;", true, ParserLanguage.CPP, true); //$NON-NLS-1$ + } + + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTNodeProperty.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTNodeProperty.java new file mode 100644 index 00000000000..8da2987bf10 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTNodeProperty.java @@ -0,0 +1,51 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This interface represents a structural property in an IASTNode. + * This is used to determine the relationship between a child node and + * it's parent. This is especially important with rewrite since we need + * to understand how to properly replace the child in the source. + * + * @author Doug Schaefer + */ +public class ASTNodeProperty { + + private String name; + + /** + * @param n + */ + public ASTNodeProperty(String n) { + this.name = n; + } + + + /** + * Each property has a name to help distinguish it from other + * properties of a node. + * + * @return the name of the property + */ + public String getName() + { + return name; + } + + + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTASMDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTASMDeclaration.java new file mode 100644 index 00000000000..fc3add67aa4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTASMDeclaration.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + + +/** + * @author jcamelon + */ +public interface IASTASMDeclaration extends IASTDeclaration { + + public String getAssembly(); + public void setAssembly( String assembly ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArrayDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArrayDeclarator.java new file mode 100644 index 00000000000..c2951f9b9ce --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArrayDeclarator.java @@ -0,0 +1,28 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + + +/** + * This is the declarator for an array. + * + * @author Doug Schaefer + */ +public interface IASTArrayDeclarator extends IASTDeclarator { + + public static final ASTNodeProperty ARRAY_MODIFIER = new ASTNodeProperty( "Array Modifier"); //$NON-NLS-1$ + + public List getArrayModifiers(); + public void addArrayModifier( IASTArrayModifier arrayModifier ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArrayModifier.java new file mode 100644 index 00000000000..cb7c8246196 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArrayModifier.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTArrayModifier extends IASTNode { + + public static final ASTNodeProperty CONSTANT_EXPRESSION = new ASTNodeProperty( "Constant Expression"); //$NON-NLS-1$ + public IASTExpression getConstantExpression(); + public void setConstantExpression( IASTExpression expression ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArraySubscriptExpression.java new file mode 100644 index 00000000000..f352fc90a31 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTArraySubscriptExpression.java @@ -0,0 +1,24 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTArraySubscriptExpression extends IASTExpression { + + public static final ASTNodeProperty ARRAY = new ASTNodeProperty( "Array"); //$NON-NLS-1$ + public IASTExpression getArrayExpression(); + public void setArrayExpression( IASTExpression expression ); + public static final ASTNodeProperty SUBSCRIPT = new ASTNodeProperty( "Subscript"); //$NON-NLS-1$ + public IASTExpression getSubscriptExpression(); + public void setSubscriptExpression( IASTExpression expression ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBinaryExpression.java new file mode 100644 index 00000000000..6bcd4a40d30 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBinaryExpression.java @@ -0,0 +1,58 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author Doug Schaefer + */ +public interface IASTBinaryExpression extends IASTExpression { + + public static final ASTNodeProperty OPERAND_ONE = new ASTNodeProperty( "Operand 1"); //$NON-NLS-1$ + public static final ASTNodeProperty OPERAND_TWO = new ASTNodeProperty( "Operand 2"); //$NON-NLS-1$ + + public void setOperator( int op ); + public int getOperator(); + public static final int op_multiply = 1; + public static final int op_divide = 2; + public static final int op_modulo = 3; + public static final int op_plus = 4; + public static final int op_minus = 5; + public static final int op_shiftLeft = 6; + public static final int op_shiftRight = 7; + public static final int op_lessThan = 8; + public static final int op_greaterThan = 9; + public static final int op_lessEqual = 10; + public static final int op_greaterEqual = 11; + public static final int op_binaryAnd = 12; + public static final int op_binaryXor = 13; + public static final int op_binaryOr = 14; + public static final int op_logicalAnd = 15; + public static final int op_logicalOr = 16; + public static final int op_assign = 17; + public static final int op_multiplyAssign = 18; + public static final int op_divideAssign = 19; + public static final int op_moduloAssign = 20; + public static final int op_plusAssign = 21; + public static final int op_minusAssign = 22; + public static final int op_shiftLeftAssign = 23; + public static final int op_shiftRightAssign = 24; + public static final int op_binaryAndAssign = 25; + public static final int op_binaryXorAssign = 26; + public static final int op_binaryOrAssign = 27; + public static final int op_equals = 28; + public static final int op_notequals = 29; + public static final int op_last = op_notequals; + + public IASTExpression getOperand1(); + public void setOperand1( IASTExpression expression ); + public IASTExpression getOperand2(); + public void setOperand2( IASTExpression expression ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBreakStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBreakStatement.java new file mode 100644 index 00000000000..3f384a14b63 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTBreakStatement.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This is the break clause in a loop. + * + * @author Doug Schaefer + */ +public interface IASTBreakStatement extends IASTStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCaseStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCaseStatement.java new file mode 100644 index 00000000000..b32d3fbfb3a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCaseStatement.java @@ -0,0 +1,34 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This is a case in a switch statement. Note that in the grammar, + * a statement is part of the clause. For the AST, just go on to the + * next statement to find it. It's really only there to ensure that there + * is at least one statement following this clause. + * + * @author Doug Schaefer + */ +public interface IASTCaseStatement extends IASTStatement { + + public static final ASTNodeProperty EXPRESSION = new ASTNodeProperty("expression"); //$NON-NLS-1$ + + /** + * The expression that determines whether this case should be + * taken. + * @return + */ + public IASTExpression getExpression(); + + public void setExpression(IASTExpression expression); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCompositeTypeSpecifier.java new file mode 100644 index 00000000000..8895e6b0faa --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCompositeTypeSpecifier.java @@ -0,0 +1,51 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * @author Doug Schaefer + */ +public interface IASTCompositeTypeSpecifier extends IASTDeclSpecifier { + + public static final ASTNodeProperty TYPE_NAME = new ASTNodeProperty( "Type Name"); //$NON-NLS-1$ + public static final ASTNodeProperty MEMBER_DECLARATION = new ASTNodeProperty( "Member Declaration"); //$NON-NLS-1$ + /** + * Is this a struct or a union or some other type of composite type. + * + * @return key for this type + */ + public int getKey(); + public static final int k_struct = 1; + public static final int k_union = 2; + + + public void setKey( int key ); + /** + * Return the name for this composite type. If this is an anonymous + * type, this will return null. + * + * @return the name of the type or null + */ + public IASTName getName(); + + public void setName( IASTName name ); + + /** + * Returns a list of member declarations. + * + * @return List of IASTDeclaration + */ + public List getMembers(); + + public void addMemberDeclaration( IASTDeclaration declaration ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCompoundStatement.java new file mode 100644 index 00000000000..572d336108d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTCompoundStatement.java @@ -0,0 +1,33 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * This represents a block of statements. + * + * @author Doug Schaefer + */ +public interface IASTCompoundStatement extends IASTStatement { + + ASTNodeProperty NESTED_STATEMENT = new ASTNodeProperty( "Nested Statement" ); //$NON-NLS-1$ + + /** + * Gets the statements in this block. + * + * @return List of IASTStatement + */ + public List getStatements(); + + public void addStatement( IASTStatement statement ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTConditionalExpression.java new file mode 100644 index 00000000000..1686f9340ba --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTConditionalExpression.java @@ -0,0 +1,30 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTConditionalExpression extends IASTExpression { + + public static final ASTNodeProperty LOGICAL_CONDITION = new ASTNodeProperty( "Logical Condition"); //$NON-NLS-1$ + public static final ASTNodeProperty POSITIVE_RESULT = new ASTNodeProperty( "Positive Result" ); //$NON-NLS-1$ + public static final ASTNodeProperty NEGATIVE_RESULT = new ASTNodeProperty( "Negative Result" ); //$NON-NLS-1$ + + public IASTExpression getLogicalConditionExpression(); + public void setLogicalConditionExpression( IASTExpression expression ); + + public IASTExpression getPositiveResultExpression(); + public void setPositiveResultExpression(IASTExpression expression); + + public IASTExpression getNegativeResultExpression(); + public void setNegativeResultExpression(IASTExpression expression); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTContinueStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTContinueStatement.java new file mode 100644 index 00000000000..fb7ea99bd8b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTContinueStatement.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This is the continue clause in a loop. + * + * @author Doug Schaefer + */ +public interface IASTContinueStatement extends IASTStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclSpecifier.java new file mode 100644 index 00000000000..27b6c733d7b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclSpecifier.java @@ -0,0 +1,40 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author Doug Schaefer + */ +public interface IASTDeclSpecifier extends IASTNode { + + // Storage class + public int getStorageClass(); + public static final int sc_unspecified = 0; + public static final int sc_typedef = 1; + public static final int sc_extern = 2; + public static final int sc_static = 3; + public static final int sc_auto = 4; + public static final int sc_register = 5; + public static final int sc_last = sc_register; + + public void setStorageClass( int storageClass ); + + // Type qualifier + public boolean isConst(); + public void setConst( boolean value ); + public boolean isVolatile(); + public void setVolatile( boolean value ); + + // Function specifier + public boolean isInline(); + public void setInline( boolean value ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclaration.java new file mode 100644 index 00000000000..9aab0da3b16 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclaration.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This is the root class of all declarations. + * + * @author Doug Schaefer + */ +public interface IASTDeclaration extends IASTNode { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarationStatement.java new file mode 100644 index 00000000000..b792797cdda --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarationStatement.java @@ -0,0 +1,31 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * A declaration statement that introduces a declaration. + * + * @author Doug Schaefer + */ +public interface IASTDeclarationStatement extends IASTStatement { + + public static final ASTNodeProperty DECLARATION = new ASTNodeProperty( "Declaration"); //$NON-NLS-1$ + + /** + * Gets the declaration introduced by this statement. + * + * @return the declaration + */ + public IASTDeclaration getDeclaration(); + + public void setDeclaration( IASTDeclaration declaration ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java new file mode 100644 index 00000000000..b792479aca1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java @@ -0,0 +1,64 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * @author Doug Schaefer + */ +public interface IASTDeclarator extends IASTNode { + + ASTNodeProperty POINTER_OPERATOR = new ASTNodeProperty( "Pointer Operator"); //$NON-NLS-1$ + ASTNodeProperty INITIALIZER = new ASTNodeProperty( "Initializer"); //$NON-NLS-1$ + ASTNodeProperty NESTED_DECLARATOR = new ASTNodeProperty( "Nested Declarator"); //$NON-NLS-1$ + ASTNodeProperty DECLARATOR_NAME = new ASTNodeProperty( "Declarator Name"); //$NON-NLS-1$ + + /** + * This is the list of pointer operators applied to the type for + * the declarator. + * + * @return List of IASTPointerOperator + */ + public List getPointerOperators(); + + public void addPointerOperator( IASTPointerOperator operator ); + + /** + * If the declarator is nested in parenthesis, this returns the + * declarator as found in those parenethesis. + * + * @return the nested declarator or null + */ + public IASTDeclarator getNestedDeclarator(); + + public void setNestedDeclarator( IASTDeclarator nested ); + + /** + * This returns the name of the declarator. If this is an abstract + * declarator, this will return null. + * + * @return the name of the declarator or null + */ + public IASTName getName(); + + public void setName( IASTName name ); + + /** + * This is the optional initializer for this declarator. + * + * @return the initializer expression or null + */ + public IASTInitializer getInitializer(); + + public void setInitializer( IASTInitializer initializer ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDefaultStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDefaultStatement.java new file mode 100644 index 00000000000..4ad8f717956 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDefaultStatement.java @@ -0,0 +1,23 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This is the default clause in the switch statement. Note that in the grammar, + * a statement is part of the clause. For the AST, just go on to the + * next statement to find it. It's really only there to ensure that there + * is at least one statement following this clause. + * + * @author Doug Schaefer + */ +public interface IASTDefaultStatement extends IASTStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDoStatement.java new file mode 100644 index 00000000000..dc1164a1deb --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDoStatement.java @@ -0,0 +1,41 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * Ye ol' do statement. + * + * @author Doug Schaefer + */ +public interface IASTDoStatement extends IASTStatement { + + public static final ASTNodeProperty BODY = new ASTNodeProperty("body"); //$NON-NLS-1$ + public static final ASTNodeProperty CONDITION = new ASTNodeProperty("condition"); //$NON-NLS-1$ + + /** + * The body of the loop. + * + * @return + */ + public IASTStatement getBody(); + + public void setBody(IASTStatement body); + + /** + * The condition on the loop. + * + * @return the expression for the condition + */ + public IASTExpression getCondition(); + + public void setCondition(IASTExpression condition); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTElaboratedTypeSpecifier.java new file mode 100644 index 00000000000..983e9830694 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTElaboratedTypeSpecifier.java @@ -0,0 +1,28 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTElaboratedTypeSpecifier extends IASTDeclSpecifier { + + public static final int k_struct = 0; + public static final int k_union = 1; + public static final int k_enum = 2; + + public int getKind(); + public void setKind( int value ); + + public static final ASTNodeProperty TYPE_NAME = new ASTNodeProperty( "Type Name"); //$NON-NLS-1$ + public IASTName getName(); + public void setName( IASTName name ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTEnumerationSpecifier.java new file mode 100644 index 00000000000..ec08341081b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTEnumerationSpecifier.java @@ -0,0 +1,42 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * @author jcamelon + */ +public interface IASTEnumerationSpecifier extends IASTDeclSpecifier { + + /** + * @author jcamelon + */ + public interface IASTEnumerator extends IASTNode { + + public static final ASTNodeProperty ENUMERATOR_NAME = new ASTNodeProperty( "Enumerator Name"); //$NON-NLS-1$ + public void setName( IASTName name ); + public IASTName getName(); + + public static final ASTNodeProperty ENUMERATOR_VALUE = new ASTNodeProperty( "Enumerator Value"); //$NON-NLS-1$ + public void setValue( IASTExpression expression ); + public IASTExpression getValue(); + + } + + public static final ASTNodeProperty ENUMERATOR = new ASTNodeProperty( "Enumerator" ); //$NON-NLS-1$ + public void addEnumerator( IASTEnumerator enumerator ); + public List getEnumerators(); + + public static final ASTNodeProperty ENUMERATION_NAME = new ASTNodeProperty( "Enum Name"); //$NON-NLS-1$ + public void setName( IASTName name ); + public IASTName getName(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpression.java new file mode 100644 index 00000000000..6ee9d6b9028 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpression.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This is the root class of expressions. + * + * @author Doug Schaefer + */ +public interface IASTExpression extends IASTNode { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionList.java new file mode 100644 index 00000000000..4432a72087e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionList.java @@ -0,0 +1,24 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * @author jcamelon + */ +public interface IASTExpressionList extends IASTExpression { + + public static final ASTNodeProperty NESTED_EXPRESSION = new ASTNodeProperty( "Nested Expression"); //$NON-NLS-1$ + + public List getExpressions(); + + public void addExpression( IASTExpression expression ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionStatement.java new file mode 100644 index 00000000000..d3499cb8279 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionStatement.java @@ -0,0 +1,28 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + + +/** + * @author Doug Schaefer + */ +public interface IASTExpressionStatement extends IASTStatement { + + public static final ASTNodeProperty EXPFRESSION = new ASTNodeProperty( "Expression"); //$NON-NLS-1$ + /** + * Get the expression in this statement. + * + * @return the expression + */ + public IASTExpression getExpression(); + + public void setExpression( IASTExpression expression ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFieldDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFieldDeclarator.java new file mode 100644 index 00000000000..f46c45159d7 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFieldDeclarator.java @@ -0,0 +1,32 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This represents a field in a struct. This allows for the specification of + * size for a bit field. + * + * @author Doug Schaefer + */ +public interface IASTFieldDeclarator extends IASTDeclarator { + + ASTNodeProperty FIELD_SIZE = new ASTNodeProperty( "BitField Size"); //$NON-NLS-1$ + /** + * This returns the number of bits if this is a bit field. + * If it is not a bit field, it returns null. + * + * @return size of bit field or null. + */ + public IASTExpression getBitFieldSize(); + + public void setBitFieldSize( IASTExpression size ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFieldReference.java new file mode 100644 index 00000000000..110e5cfd343 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFieldReference.java @@ -0,0 +1,49 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author Doug Schaefer + */ +public interface IASTFieldReference extends IASTExpression { + + public static final ASTNodeProperty FIELD_OWNER = new ASTNodeProperty( "Field Owner"); //$NON-NLS-1$ + public static final ASTNodeProperty FIELD_NAME = new ASTNodeProperty( "Field Name"); //$NON-NLS-1$ + + /** + * This returns an expression for the object containing the field. + * + * @return the field owner + */ + public IASTExpression getFieldOwner(); + + public void setFieldOwner( IASTExpression expression ); + + /** + * This returns the name of the field being dereferenced. + * + * @return the name of the field + */ + public IASTName getFieldName(); + + public void setFieldName( IASTName name ); + + /** + * This returns true of this is the arrow operator and not the + * dot operator. + * + * @return is this a pointer dereference + */ + public boolean isPointerDereference(); + + public void setIsPointerDereference( boolean value ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFileLocation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFileLocation.java new file mode 100644 index 00000000000..6d90fdd334e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFileLocation.java @@ -0,0 +1,27 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * Represents a node location that is directly in the source file. + * + * @author Doug Schaefer + */ +public interface IASTFileLocation extends IASTNodeLocation { + + /** + * The name of the file. + * + * @return the name of the file + */ + public String getFileName(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java new file mode 100644 index 00000000000..cd5ded5df32 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTForStatement.java @@ -0,0 +1,71 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * The for statement. The initialization clause can be an expression or + * a declaration but not both. + * + * @author Doug Schaefer + */ +public interface IASTForStatement extends IASTStatement { + + public static final ASTNodeProperty INITEXPRESSION = new ASTNodeProperty("initExpression"); //$NON-NLS-1$ + public static final ASTNodeProperty INITDECLARATION = new ASTNodeProperty("initDeclaration"); //$NON-NLS-1$ + public static final ASTNodeProperty CONDITION = new ASTNodeProperty("condition"); //$NON-NLS-1$ + public static final ASTNodeProperty ITERATION = new ASTNodeProperty("iteration"); //$NON-NLS-1$ + public static final ASTNodeProperty BODY = new ASTNodeProperty("body"); //$NON-NLS-1$ + + /** + * The initial expression for the loop. Returns null if there is + * none. You can not have both an initial expression and an initial + * declaration. + * + * @return + */ + public IASTExpression getInitExpression(); + + public void setInit(IASTExpression expression); + + /** + * The initial declaration for the loop. Returns null if there is + * none. You can not have both an initial declaration and an initial + * declaration. + * + * @return + */ + public IASTDeclaration getInitDeclaration(); + + public void setInit(IASTDeclaration declaration); + + /** + * The condition for the loop. + * + * @return + */ + public IASTExpression getCondition(); + + public void setCondition(IASTExpression condition); + + /** + * The expression that is evaluated after the completion of an iteration + * of the loop. + * + * @return + */ + public IASTExpression getIterationExpression(); + + public void setIterationExpression(IASTExpression iterator); + + public IASTStatement getBody(); + public void setBody( IASTStatement statement ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionCallExpression.java new file mode 100644 index 00000000000..a9229a037f4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionCallExpression.java @@ -0,0 +1,25 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTFunctionCallExpression extends IASTExpression { + + public static final ASTNodeProperty FUNCTION_NAME = new ASTNodeProperty( "Function Name"); //$NON-NLS-1$ + public void setFunctionNameExpression( IASTExpression expression ); + public IASTExpression getFunctionNameExpression(); + + public static final ASTNodeProperty PARAMETERS = new ASTNodeProperty( "Parameters"); //$NON-NLS-1$ + public void setParameterExpression( IASTExpression expression ); + public IASTExpression getParameterExpression(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java new file mode 100644 index 00000000000..1a43f54041e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDeclarator.java @@ -0,0 +1,35 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * This is a declarator for a function. + * + * @author Doug Schaefer + */ +public interface IASTFunctionDeclarator extends IASTDeclarator { + + ASTNodeProperty FUNCTION_PARAMETER = new ASTNodeProperty( "Parameter"); //$NON-NLS-1$ + /** + * Gets the parameter declarations for the function + * + * @return List of IASTParameterDeclaration + */ + public List getParameters(); + + public void addParameterDeclaration( IASTParameterDeclaration parameter ); + + public boolean takesVarArgs(); + + public void setVarArgs( boolean value ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDefinition.java new file mode 100644 index 00000000000..4562921440c --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDefinition.java @@ -0,0 +1,52 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This is a function definition, i.e. it has a body. + * + * @author Doug Schaefer + */ +public interface IASTFunctionDefinition extends IASTDeclaration { + + ASTNodeProperty DECL_SPECIFIER = new ASTNodeProperty( "Decl Specifier"); //$NON-NLS-1$ + ASTNodeProperty DECLARATOR = new ASTNodeProperty( "Declarator"); //$NON-NLS-1$ + ASTNodeProperty FUNCTION_BODY = new ASTNodeProperty( "Function Body"); //$NON-NLS-1$ + + /** + * The decl specifier for the function. + * + * @return + */ + public IASTDeclSpecifier getDeclSpecifier(); + + public void setDeclSpecifier( IASTDeclSpecifier declSpec ); + + /** + * The declarator for the function. + * + * @return + */ + public IASTFunctionDeclarator getDeclarator(); + + public void setDeclarator( IASTFunctionDeclarator declarator ); + + /** + * This is the body of the function. This is usually a compound statement + * but C++ also has a function try block. + * + * @return + */ + public IASTStatement getBody(); + + public void setBody( IASTStatement statement ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTGotoStatement.java new file mode 100644 index 00000000000..d26587b6beb --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTGotoStatement.java @@ -0,0 +1,31 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * Represents a goto statement. + * + * @author Doug Schaefer + */ +public interface IASTGotoStatement extends IASTStatement { + + public static final ASTNodeProperty NAME = new ASTNodeProperty("name"); //$NON-NLS-1$ + + /** + * Returns the name of the label. The name resolves to a ILabel binding. + * + * @return + */ + public IASTName getName(); + + public void setName(IASTName name); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTIdExpression.java new file mode 100644 index 00000000000..15b9963a07a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTIdExpression.java @@ -0,0 +1,29 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This is a name used in an expression. + * + * @author Doug Schaefer + */ +public interface IASTIdExpression extends IASTExpression { + + public static final ASTNodeProperty ID_NAME = new ASTNodeProperty( "IdExpression Name"); //$NON-NLS-1$ + /** + * Returns the name used in the expression. + * + * @return the name + */ + public IASTName getName(); + + public void setName( IASTName name ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTIfStatement.java new file mode 100644 index 00000000000..2107b598698 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTIfStatement.java @@ -0,0 +1,52 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * The if statement including the optional else clause. + * + * @author Doug Schaefer + */ +public interface IASTIfStatement extends IASTStatement { + + public static final ASTNodeProperty CONDITION = new ASTNodeProperty("condition"); //$NON-NLS-1$ + public static final ASTNodeProperty THEN = new ASTNodeProperty("then"); //$NON-NLS-1$ + public static final ASTNodeProperty ELSE = new ASTNodeProperty("else"); //$NON-NLS-1$ + + /** + * The condition in the if statement. + * + * @return the condition expression + */ + public IASTExpression getCondition(); + + public void setCondition(IASTExpression condition); + + /** + * The statement that is executed if the condition is true. + * + * @return the then clause + */ + public IASTStatement getThenClause(); + + public void setThenClause(IASTStatement thenClause); + + /** + * The statement that is executed if the condition is false. This + * clause is optional and returns null if there is none. + * + * @return the else clause or null + */ + public IASTStatement getElseClause(); + + public void setElseClause(IASTStatement elseClause); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializer.java new file mode 100644 index 00000000000..6303b9a919d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializer.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This represents an initializer for a declarator. + * + * @author Doug Schaefer + */ +public interface IASTInitializer extends IASTNode { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerExpression.java new file mode 100644 index 00000000000..08077f12b36 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerExpression.java @@ -0,0 +1,29 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This is an initializer that is simply an expression. + * + * @author Doug Schaefer + */ +public interface IASTInitializerExpression extends IASTInitializer { + + public ASTNodeProperty INITIALIZER_EXPRESSION = new ASTNodeProperty( "Initializer Expression"); //$NON-NLS-1$ + /** + * Get the expression for the initializer. + * + * @return + */ + public IASTExpression getExpression(); + + public void setExpression( IASTExpression expression ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerList.java new file mode 100644 index 00000000000..6001125eb68 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerList.java @@ -0,0 +1,31 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * This is an an initializer that is a list of initializers. + * + * @author Doug Schaefer + */ +public interface IASTInitializerList extends IASTInitializer { + + public ASTNodeProperty NESTED_INITIALIZER = new ASTNodeProperty( "Nested Initializer" ); //$NON-NLS-1$ + /** + * Get the list of initializers. + * + * @return + */ + public List getInitializers(); + + public void addInitializer( IASTInitializer initializer ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLabelStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLabelStatement.java new file mode 100644 index 00000000000..68cb15a4228 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLabelStatement.java @@ -0,0 +1,31 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * Represents a label statement. + * + * @author Doug Schaefer + */ +public interface IASTLabelStatement extends IASTStatement { + + public static final ASTNodeProperty NAME = new ASTNodeProperty("name"); //$NON-NLS-1$ + + /** + * The name for the label. The name resolves to an ILabel binding. + * + * @return the name for the label + */ + public IASTName getName(); + + public void setName(IASTName name); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLiteralExpression.java new file mode 100644 index 00000000000..fad856ee818 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTLiteralExpression.java @@ -0,0 +1,30 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This expression represents a literal in the program. + * + * @author Doug Schaefer + */ +public interface IASTLiteralExpression extends IASTExpression { + + public static final int lk_integer_constant = 0; + public static final int lk_float_constant = 1; + public static final int lk_char_constant = 2; + public static final int lk_string_literal = 3; + + public int getKind(); + public void setKind( int value ); + + public void setValue( String value ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTMacroDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTMacroDefinition.java new file mode 100644 index 00000000000..b93b465b6df --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTMacroDefinition.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This represents the definition of a macro. + * + * @author Doug Schaefer + */ +public interface IASTMacroDefinition { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTMacroExpansion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTMacroExpansion.java new file mode 100644 index 00000000000..bab822bd09f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTMacroExpansion.java @@ -0,0 +1,33 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author Doug Schaefer + */ +public interface IASTMacroExpansion { + + /** + * The macro definition used for the expansion + * + * @return + */ + public IASTMacroDefinition getMacroDefinition(); + + /** + * The source location for for the macro expansion. This is the location + * in the original source that expansion occured and was replaced. + * + * @return + */ + public IASTNodeLocation getExpansionLocation(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTName.java new file mode 100644 index 00000000000..3c4ccf466a5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTName.java @@ -0,0 +1,31 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This class represents a name in the program that represents a semantic + * object in the program. + * + * The toString method produces a string representation of the name as + * appropriate for the language. + * + * @author Doug Schaefer + */ +public interface IASTName extends IASTNode { + + /** + * Return the semantic object this name is referring to. + * + * @return binding + */ + public IBinding resolveBinding(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java new file mode 100644 index 00000000000..d4c83b84c46 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java @@ -0,0 +1,43 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This is the root node in the physical AST. A physical node represents + * a chunk of text in the source program. + * + * @author Doug Schaefer + */ +public interface IASTNode { + + public IASTTranslationUnit getTranslationUnit(); + + /** + * Get the parent node of this node in the tree. + * + * @return the parent node of this node + */ + public IASTNode getParent(); + + public void setParent( IASTNode node ); + + /** + * In order to properly understand the relationship between this child + * node and it's parent, a node property object is used. + * + * @return + */ + public ASTNodeProperty getPropertyInParent(); + + public void setPropertyInParent( ASTNodeProperty property ); + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNodeLocation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNodeLocation.java new file mode 100644 index 00000000000..fd1ffe9eaf7 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNodeLocation.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * A NodeLocation represents the source location of a given node. Most + * often this is a file it may be other fancy things like macro + * expansions. + * + * @author Doug Schaefer + */ +public interface IASTNodeLocation { + + /** + * This is the offset into the actual source location that this node + * starts at. + * + * @return + */ + public int getNodeOffset(); + + /** + * This is the length of the node contained in this location. + * + * @return + */ + public int getNodeLength(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTParameterDeclaration.java new file mode 100644 index 00000000000..9211c71773b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTParameterDeclaration.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This class represents a parameter declaration + * + * @author Doug Schaefer + */ +public interface IASTParameterDeclaration extends IASTNode { + + ASTNodeProperty DECL_SPECIFIER = new ASTNodeProperty( "Decl Specifier"); //$NON-NLS-1$ + ASTNodeProperty DECLARATOR = new ASTNodeProperty( "Declarator"); //$NON-NLS-1$ + + public IASTDeclSpecifier getDeclSpecifier(); + + public IASTDeclarator getDeclarator(); + + /** + * @param declSpec + */ + public void setDeclSpecifier(IASTDeclSpecifier declSpec); + + /** + * @param declarator2 + */ + public void setDeclarator(IASTDeclarator declarator); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPointer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPointer.java new file mode 100644 index 00000000000..7e2e4202132 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPointer.java @@ -0,0 +1,27 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This represents the good ol' * pointer operator. + * + * @author Doug Schaefer + */ +public interface IASTPointer extends IASTPointerOperator { + + // Qualifiers applied to the pointer type + public boolean isConst(); + public boolean isVolatile(); + + public void setConst( boolean value ); + public void setVolatile( boolean value ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPointerOperator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPointerOperator.java new file mode 100644 index 00000000000..3fe0c5fdf6e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTPointerOperator.java @@ -0,0 +1,18 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author Doug Schaefer + */ +public interface IASTPointerOperator extends IASTNode { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTReturnStatement.java new file mode 100644 index 00000000000..6bf91a646cd --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTReturnStatement.java @@ -0,0 +1,29 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author Doug Schaefer + */ +public interface IASTReturnStatement extends IASTStatement { + + public static final ASTNodeProperty RETURNVALUE = new ASTNodeProperty("returnValue"); //$NON-NLS-1$ + + /** + * This is the optional return value for this function. + * + * @return the return expression or null. + */ + public IASTExpression getReturnValue(); + + public void setReturnValue(IASTExpression returnValue); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclSpecifier.java new file mode 100644 index 00000000000..4287f143c2d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclSpecifier.java @@ -0,0 +1,49 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This represents a decl specifier for a built-in type. + * + * @author Doug Schaefer + */ +public interface IASTSimpleDeclSpecifier extends IASTDeclSpecifier { + + /** + * This returns the built-in type for the declaration. The type is + * then refined by qualifiers for signed/unsigned and short/long. + * The type could also be unspecified which usually means int. + * + * @return + */ + public int getType(); + + public static final int t_unspecified = 0; + public static final int t_void = 1; + public static final int t_char = 2; + public static final int t_int = 3; + public static final int t_float = 4; + public static final int t_double = 5; + public static final int t_last = t_double; // used only in subclasses + + public void setType( int type ); + + public boolean isSigned(); + public boolean isUnsigned(); + public boolean isShort(); + public boolean isLong(); + + public void setSigned( boolean value ); + public void setUnsigned( boolean value ); + public void setLong( boolean value ); + public void setShort( boolean value ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclaration.java new file mode 100644 index 00000000000..7b64740e019 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclaration.java @@ -0,0 +1,45 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * This is a simple declaration which contains a sequence of declSpecifiers + * followed by a list of declarators. + * + * @author Doug Schaefer + */ +public interface IASTSimpleDeclaration extends IASTDeclaration, IASTNode { + + ASTNodeProperty DECL_SPECIFIER = new ASTNodeProperty( "Decl Specifier"); //$NON-NLS-1$ + ASTNodeProperty DECLARATOR = new ASTNodeProperty( "Declarator"); //$NON-NLS-1$ + + /** + * This returns the object representing the declSpecifiers for this + * declaration. + * + * @return the declSpecifier object + */ + public IASTDeclSpecifier getDeclSpecifier(); + + public void setDeclSpecifier( IASTDeclSpecifier declSpec ); + + /** + * This returns the list of declarators in this declaration. + * + * @return list of IASTDeclarator + */ + public List getDeclarators(); + + public void addDeclarator( IASTDeclarator declarator ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStatement.java new file mode 100644 index 00000000000..9087c301448 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStatement.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * This is the root interface for statements. + * + * @author Doug Schaefer + */ +public interface IASTStatement extends IASTNode { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSwitchStatement.java new file mode 100644 index 00000000000..7e6bebce78e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSwitchStatement.java @@ -0,0 +1,43 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * The switch statement. + * + * @author Doug Schaefer + */ +public interface IASTSwitchStatement extends IASTStatement { + + public static final ASTNodeProperty CONTROLLER = new ASTNodeProperty("controller"); //$NON-NLS-1$ + public static final ASTNodeProperty BODY = new ASTNodeProperty("body"); //$NON-NLS-1$ + + /** + * This returns the expression which determines which case to take. + * + * @return the controller expression + */ + public IASTExpression getController(); + + public void setController(IASTExpression controller); + + /** + * The body of the switch statement. + * + * TODO - finding the cases could be a logical thing + * + * @return + */ + public IASTStatement getBody(); + + public void setBody(IASTStatement body); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java new file mode 100644 index 00000000000..3d1bbdec030 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java @@ -0,0 +1,59 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * The translation unit represents a compilable unit of source. + * + * @author Doug Schaefer + */ +public interface IASTTranslationUnit extends IASTNode { + + ASTNodeProperty OWNED_DECLARATION = new ASTNodeProperty( "OWNED" ); //$NON-NLS-1$ + + /** + * A translation unit contains an ordered sequence of declarations. + * + * @return List of IASTDeclaration + */ + public List getDeclarations(); + + public void addDeclaration( IASTDeclaration declaration ); + + /** + * This returns the global scope for the translation unit. + * + * @return the global scope + */ + public IScope getScope(); + + /** + * Returns the list of declarations in this translation unit for the given + * binding. The list contains the IASTName nodes that declare the binding. + * + * @param binding + * @return List of IASTName nodes for the binding's declaration + */ + public List getDeclarations(IBinding binding); + + /** + * Returns the list of references in this translation unit to the given + * binding. This list contains the IASTName nodes that represent a use of + * the binding. + * + * @param binding + * @return List of IASTName nodes representing uses of the binding + */ + public List getReferences(IBinding binding); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java new file mode 100644 index 00000000000..75ed27244aa --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeId.java @@ -0,0 +1,24 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTTypeId extends IASTNode { + + public static final ASTNodeProperty DECL_SPECIFIER = new ASTNodeProperty( "Decl Specifier"); //$NON-NLS-1$ + public static final ASTNodeProperty ABSTRACT_DECLARATOR = new ASTNodeProperty( "Abstract Declarator"); //$NON-NLS-1$ + + public IASTDeclSpecifier getDeclSpecifier(); + public void setDeclSpecifier( IASTDeclSpecifier declSpec ); + public IASTDeclarator getAbstractDeclarator(); + public void setAbstractDeclarator( IASTDeclarator abstractDeclarator ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java new file mode 100644 index 00000000000..9162bbb7eca --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypeIdExpression.java @@ -0,0 +1,27 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTTypeIdExpression extends IASTExpression { + + public static final int op_sizeof = 0; + public static final int op_last = op_sizeof; + + public int getOperator(); + public void setOperator( int value ); + + public static final ASTNodeProperty TYPE_ID = new ASTNodeProperty( "Type Id"); //$NON-NLS-1$ + public void setTypeId( IASTTypeId typeId ); + public IASTTypeId getTypeId(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypedefNameSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypedefNameSpecifier.java new file mode 100644 index 00000000000..8209c98e6fd --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTypedefNameSpecifier.java @@ -0,0 +1,29 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * Represents the use of a typedef name in an decl specifier. + * + * @author Doug Schaefer + */ +public interface IASTTypedefNameSpecifier extends IASTDeclSpecifier { + + public static final ASTNodeProperty NAME = new ASTNodeProperty( "Name"); //$NON-NLS-1$ + + /** + * @return the typedef name. + */ + public IASTName getName(); + + public void setName( IASTName name ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java new file mode 100644 index 00000000000..f8a6958d3a9 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryExpression.java @@ -0,0 +1,39 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTUnaryExpression extends IASTExpression { + + public static final int op_prefixIncr = 0; + public static final int op_prefixDecr = 1; + public static final int op_plus = 2; + public static final int op_minus = 3; + public static final int op_star = 4; + public static final int op_amper = 5; + public static final int op_tilde = 6; + public static final int op_not = 7; + public static final int op_sizeof = 8; + public static final int op_postFixIncr = 9; + public static final int op_postFixDecr = 10; + public static final int op_last = op_postFixDecr; + + public int getOperator(); + public void setOperator( int value ); + + public static final ASTNodeProperty OPERAND = new ASTNodeProperty( "Operand" ); //$NON-NLS-1$ + + + public IASTExpression getOperand(); + public void setOperand( IASTExpression expression ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryTypeIdExpression.java new file mode 100644 index 00000000000..4d6e35f75f4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTUnaryTypeIdExpression.java @@ -0,0 +1,32 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author jcamelon + */ +public interface IASTUnaryTypeIdExpression extends IASTExpression { + + public static final int op_cast = 0; + public static final int op_last = op_cast; + + public int getOperator(); + public void setOperator( int value ); + + public static final ASTNodeProperty OPERAND = new ASTNodeProperty( "Operand" ); //$NON-NLS-1$ + public IASTExpression getOperand(); + public void setOperand( IASTExpression expression ); + + public static final ASTNodeProperty TYPE_ID = new ASTNodeProperty( "Type Id"); //$NON-NLS-1$ + + public void setTypeId( IASTTypeId typeId ); + public IASTTypeId getTypeId(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTWhileStatement.java new file mode 100644 index 00000000000..28fbf06edc4 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTWhileStatement.java @@ -0,0 +1,41 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * Ye ol' while statement. + * + * @author Doug Schaefer + */ +public interface IASTWhileStatement extends IASTStatement { + + public static final ASTNodeProperty CONDITION = new ASTNodeProperty("condition"); //$NON-NLS-1$ + public static final ASTNodeProperty BODY = new ASTNodeProperty("body"); //$NON-NLS-1$ + + /** + * The condition on the while loop + * + * @return expression for the condition + */ + public IASTExpression getCondition(); + + public void setCondition(IASTExpression condition); + + /** + * The body of the loop. + * + * @return the body + */ + public IASTStatement getBody(); + + public void setBody(IASTStatement body); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java new file mode 100644 index 00000000000..07f0de4a676 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IBinding.java @@ -0,0 +1,32 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author Doug Schaefer + */ +public interface IBinding { + + /** + * The name of the binding. + * + * @return name + */ + public String getName(); + + /** + * Every name has a scope. + * + * @return the scope of this name + */ + public IScope getScope(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java new file mode 100644 index 00000000000..07c99ea2066 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ICompositeType.java @@ -0,0 +1,35 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * @author Doug Schaefer + */ +public interface ICompositeType extends IType { + + /** + * Returns the fields for this type. + * + * @return List of IField + */ + public List getFields(); + + /** + * returns the field that matches name, + * or null if there is no such field. + * + * @param name + * @return + */ + public IField findField( String name ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IField.java new file mode 100644 index 00000000000..419e87a8e37 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IField.java @@ -0,0 +1,18 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author Doug Schaefer + */ +public interface IField extends IVariable { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java new file mode 100644 index 00000000000..b99562afe08 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * This represents a function in the program. A function is also a scope + * for other bindings. + * + * @author Doug Schaefer + */ +public interface IFunction extends IBinding { + + /** + * This gets the parameters to the function which are IVariables. + * + * @return List of IParameter + */ + public List getParameters(); + + /** + * Get the function scope + * + * @return + */ + public IScope getFunctionScope(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ILabel.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ILabel.java new file mode 100644 index 00000000000..592945e443d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ILabel.java @@ -0,0 +1,28 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * Represents the mapping between goto statements and the label statements + * the go to. + * + * @author Doug Schaefer + */ +public interface ILabel extends IBinding { + + /** + * Returns the label statement for this label. + * + * @return + */ + public IASTLabelStatement getLabelStatement(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IParameter.java new file mode 100644 index 00000000000..b1110713e13 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IParameter.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * Represents a parameter to a function. The scope of the parameter is + * the function that declared this parameter. + * + * @author Doug Schaefer + */ +public interface IParameter extends IVariable { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java new file mode 100644 index 00000000000..06127b8ec86 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import java.util.List; + +/** + * + * @author Doug Schaefer + */ +public interface IScope { + + /** + * Scopes are arranged hierarchically. Lookups will generally + * flow upward to find resolution. + * + * @return + */ + public IScope getParent(); + + /** + * This is the general lookup entry point. It returns the list of + * valid bindings for a given name. + * + * @param searchString + * @return List of IBinding + */ + public List find(String name); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java new file mode 100644 index 00000000000..dffcc25a0e5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IType.java @@ -0,0 +1,19 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author Doug Schaefer + */ +public interface IType extends IBinding { + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java new file mode 100644 index 00000000000..935870f7115 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ITypedef.java @@ -0,0 +1,25 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author Doug Schaefer + */ +public interface ITypedef extends IType { + + /** + * Returns the type that this thing is a typedef of + * + * @return + */ + public IType getType(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java new file mode 100644 index 00000000000..3e75216a8f5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IVariable.java @@ -0,0 +1,22 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * @author Doug Schaefer + */ +public interface IVariable extends IBinding { + + /** + * @return the type of the variable + */ + public IType getType(); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/IASTNullStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/IASTNullStatement.java new file mode 100644 index 00000000000..f791eacd01e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/IASTNullStatement.java @@ -0,0 +1,19 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * @author jcamelon + */ +public interface IASTNullStatement extends IASTStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTArrayDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTArrayDesignator.java new file mode 100644 index 00000000000..19e1c271905 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTArrayDesignator.java @@ -0,0 +1,25 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTExpression; + +/** + * @author jcamelon + */ +public interface ICASTArrayDesignator extends ICASTDesignator { + + public static final ASTNodeProperty SUBSCRIPT_EXPRESSION = new ASTNodeProperty( "Subscript Expression" ); //$NON-NLS-1$ + + public IASTExpression getSubscriptExpression(); + public void setSubscriptExpression( IASTExpression value ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTArrayModifier.java new file mode 100644 index 00000000000..e271aa15726 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTArrayModifier.java @@ -0,0 +1,28 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; + +/** + * @author jcamelon + */ +public interface ICASTArrayModifier extends IASTArrayModifier { + + public boolean isConst(); + public boolean isStatic(); + public boolean isRestrict(); + public boolean isVolatile(); + + public void setConst( boolean value ); + public void setVolatile( boolean value ); + public void setRestrict( boolean value ); + public void setStatic( boolean value ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTCompositeTypeSpecifier.java new file mode 100644 index 00000000000..c4fba768c06 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTCompositeTypeSpecifier.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; + +/** + * @author jcamelon + */ +public interface ICASTCompositeTypeSpecifier extends + IASTCompositeTypeSpecifier, ICASTDeclSpecifier { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTDeclSpecifier.java new file mode 100644 index 00000000000..c7929679271 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTDeclSpecifier.java @@ -0,0 +1,25 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; + +/** + * @author Doug Schaefer + */ +public interface ICASTDeclSpecifier extends IASTDeclSpecifier { + + // Extra type qualifier in C + public boolean isRestrict(); + + public void setRestrict( boolean value ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTDesignator.java new file mode 100644 index 00000000000..5c9e4775bc8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTDesignator.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.IASTNode; + +/** + * @author jcamelon + */ +public interface ICASTDesignator extends IASTNode { + + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTElaboratedTypeSpecifier.java new file mode 100644 index 00000000000..488d1f60bc8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTElaboratedTypeSpecifier.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; + +/** + * @author jcamelon + */ +public interface ICASTElaboratedTypeSpecifier extends + IASTElaboratedTypeSpecifier, ICASTDeclSpecifier { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTEnumerationSpecifier.java new file mode 100644 index 00000000000..72ce2c4ee9f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTEnumerationSpecifier.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; + +/** + * @author jcamelon + */ +public interface ICASTEnumerationSpecifier extends ICASTDeclSpecifier, + IASTEnumerationSpecifier { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTFieldDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTFieldDesignator.java new file mode 100644 index 00000000000..3cd50896e9a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTFieldDesignator.java @@ -0,0 +1,24 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTName; + +/** + * @author jcamelon + */ +public interface ICASTFieldDesignator extends ICASTDesignator { + + public static final ASTNodeProperty FIELD_NAME = new ASTNodeProperty( "Designator Field Name"); //$NON-NLS-1$ + + public IASTName getName(); + public void setName( IASTName name ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTPointer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTPointer.java new file mode 100644 index 00000000000..6c3885bbdac --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTPointer.java @@ -0,0 +1,22 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.IASTPointer; + +/** + * @author jcamelon + */ +public interface ICASTPointer extends IASTPointer { + + boolean isRestrict(); + void setRestrict( boolean value ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTSimpleDeclSpecifier.java new file mode 100644 index 00000000000..4266112b7e9 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTSimpleDeclSpecifier.java @@ -0,0 +1,28 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; + +/** + * This interface represents a built-in type in C. + * + * @author Doug Schaefer + */ +public interface ICASTSimpleDeclSpecifier extends IASTSimpleDeclSpecifier, ICASTDeclSpecifier { + + // Extra types in C + public static final int t_Bool = IASTSimpleDeclSpecifier.t_last + 1; + public static final int t_Complex = IASTSimpleDeclSpecifier.t_last + 2; + public static final int t_Imaginary = IASTSimpleDeclSpecifier.t_last + 3; + public static final int t_last = t_Imaginary; + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTTypeIdInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTTypeIdInitializerExpression.java new file mode 100644 index 00000000000..0ddcfc63387 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTTypeIdInitializerExpression.java @@ -0,0 +1,30 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; + +/** + * @author jcamelon + */ +public interface ICASTTypeIdInitializerExpression extends IASTExpression { + + public static final ASTNodeProperty TYPE_ID = new ASTNodeProperty( "TypeId"); //$NON-NLS-1$ + public static final ASTNodeProperty INITIALIZER = new ASTNodeProperty( "Initializer"); //$NON-NLS-1$ + + public IASTTypeId getTypeId(); + public void setTypeId( IASTTypeId typeId ); + public IASTInitializer getInitializer(); + public void setInitializer( IASTInitializer initializer ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTTypedefNameSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTTypedefNameSpecifier.java new file mode 100644 index 00000000000..b2944a0b54a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c/ICASTTypedefNameSpecifier.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.c; + +import org.eclipse.cdt.core.dom.ast.IASTTypedefNameSpecifier; + +/** + * @author jcamelon + */ +public interface ICASTTypedefNameSpecifier extends IASTTypedefNameSpecifier, + ICASTDeclSpecifier { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTConstructorInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTConstructorInitializer.java new file mode 100644 index 00000000000..f8061dae803 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTConstructorInitializer.java @@ -0,0 +1,32 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTInitializer; + +/** + * This is an initializer that is a call to the constructor for the + * declarator. + * + * @author Doug Schaefer + */ +public interface ICPPASTConstructorInitializer extends IASTInitializer { + + /** + * Get the arguments to the constructor. + * + * @return List of IASTExpression + */ + public List getExpressions(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTDeclSpecifier.java new file mode 100644 index 00000000000..44175d2cbb1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTDeclSpecifier.java @@ -0,0 +1,26 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; + +/** + * @author Doug Schaefer + */ +public interface ICPPASTDeclSpecifier extends IASTDeclSpecifier { + + // Extra storage class in C++ + public static final int sc_mutable = IASTDeclSpecifier.sc_last + 1; + + // A declaration in C++ can be a friend declaration + public boolean isFriend(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java new file mode 100644 index 00000000000..3a49550535b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java @@ -0,0 +1,27 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; + +/** + * C++ adds a few things to function declarators. + * + * @author Doug Schaefer + */ +public interface ICPPASTFunctionDeclarator extends IASTFunctionDeclarator { + + public boolean isConst(); + public boolean isVolatile(); + + // TODO add in exception specification + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTPointerToMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTPointerToMember.java new file mode 100644 index 00000000000..37b54fc1e65 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTPointerToMember.java @@ -0,0 +1,25 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; + +/** + * This is a pointer to member pointer operator for declarators. + * + * @author Doug Schaefer + */ +public interface ICPPASTPointerToMember extends IASTPointerOperator { + + // TODO fill this in with a qualified name for the class containing + // the member + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTReferenceOperator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTReferenceOperator.java new file mode 100644 index 00000000000..4bd83c2f59e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTReferenceOperator.java @@ -0,0 +1,22 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; + +/** + * This is C++'s reference operator, i.e. &, used in a declarator. + * + * @author Doug Schaefer + */ +public interface ICPPASTReferenceOperator extends IASTPointerOperator { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTSimpleDeclSpecifier.java new file mode 100644 index 00000000000..2bf696e7f26 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTSimpleDeclSpecifier.java @@ -0,0 +1,26 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; + +/** + * This interface represents a built-in type in C++. + * + * @author Doug Schaefer + */ +public interface ICPPASTSimpleDeclSpecifier extends IASTSimpleDeclSpecifier, ICPPASTDeclSpecifier { + // Extra types + public static final int t_bool = IASTSimpleDeclSpecifier.t_last + 1; + public static final int t_wchar_t = IASTSimpleDeclSpecifier.t_last + 2; + public static final int t_last = t_wchar_t; + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPBase.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPBase.java new file mode 100644 index 00000000000..be72e158874 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPBase.java @@ -0,0 +1,45 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +/** + * Represents the relationship between a class and one of its base classes. + * + * @author Doug Schaefer + */ +public interface ICPPBase { + + /** + * The base class. + * + * @return + */ + public ICPPClassType getBaseClass(); + + /** + * The visibility qualifier applied to the base class. + * + * @return + */ + public int getVisibility(); + + public static final int v_private = 1; + public static final int v_protected = 2; + public static final int v_public = 3; + + /** + * Whether this is a virtual base class. + * + * @return + */ + public boolean isVirtual(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java new file mode 100644 index 00000000000..0bfe2ab88ca --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPClassType.java @@ -0,0 +1,73 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.ICompositeType; + +/** + * Represents a C++ class. + * + * @author Doug Schaefer + */ +public interface ICPPClassType extends ICompositeType { + + /** + * Returns a list of base class relationships. The list is empty if + * there are none. + * + * @return List of ICPPBase + */ + public List getBases(); + + /** + * Get fields is restated here just to point out that this method returns + * a list of ICPPField objects representing all fields, declared or inherited. + */ + public List getFields(); + + /** + * Returns a list of ICPPField objects representing fields declared in this + * class. It does not include fields inherited from base classes. + * + * @return List of ICPPField + */ + public List getDeclaredFields(); + + /** + * Returns a list of ICPPMethod objects representing all methods defined for + * this class including those declared, inherited, or generated (e.g. default + * constructors and the like). + * + * @return List of ICPPMethod + */ + public List getMethods(); + + /** + * Returns a list of ICPPMethod objects representing all method explicitly + * declared by this class and inherited from base classes. It does not include + * automatically generated methods. + * + * @return List of ICPPMethod + */ + public List getAllDeclaredMethods(); + + /** + * Returns a list of ICPPMethod objects representing all methods explicitly + * declared by this class. It does not include inherited methods or automatically + * generated methods. + * + * @return List of ICPPMethod + */ + public List getDeclaredMethods(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPField.java new file mode 100644 index 00000000000..27109f0dd3a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPField.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IField; + +/** + * @author Doug Schaefer + */ +public interface ICPPField extends IField, ICPPMember { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMember.java new file mode 100644 index 00000000000..add301ff083 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMember.java @@ -0,0 +1,31 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +/** + * Represents a member of a class. Adds in the visibility attribute. + * + * @author Doug Schaefer + */ +public interface ICPPMember { + + /** + * The visibility. + * + * @return + */ + public int getVisibility(); + + public static final int v_private = 1; + public static final int v_protected = 2; + public static final int v_public = 3; + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java new file mode 100644 index 00000000000..e17d1a4bb19 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPMethod.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IFunction; + +/** + * @author Doug Schaefer + */ +public interface ICPPMethod extends IFunction, ICPPMember { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateDefinition.java new file mode 100644 index 00000000000..2bae751ec2e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateDefinition.java @@ -0,0 +1,45 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import java.util.List; + +/** + * @author Doug Schaefer + */ +public interface ICPPTemplateDefinition { + + /** + * Returns the list of template parameters. If this is a template + * specialization, the parameters will be substituted by the arguments + * determined in the specialization. + * + * @return List of ICPPTemplateParameter, IType, or IASTExpression. + * The type or expression are arguments in a specialization. + */ + public List getParameters(); + + /** + * Returns whether this is a template specialization. + * + * @return is this a template specialization + */ + public boolean isSpecialization(); + + /** + * If this is a template specialization, this returns the template + * definition this is specializing. It returns null if this template + * is not a specialization. + * + * @return + */ + public ICPPTemplateDefinition getSpecializes(); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateNonTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateNonTypeParameter.java new file mode 100644 index 00000000000..bbf3504b5f9 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateNonTypeParameter.java @@ -0,0 +1,28 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IVariable; + +/** + * @author Doug Schaefer + */ +public interface ICPPTemplateNonTypeParameter extends ICPPTemplateParameter, IVariable { + + /** + * The default value for this parameter. + * + * @return + */ + public IASTExpression getDefault(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateParameter.java new file mode 100644 index 00000000000..0d25bad65bf --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateParameter.java @@ -0,0 +1,18 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +/** + * @author Doug Schaefer + */ +public interface ICPPTemplateParameter { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateTypeParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateTypeParameter.java new file mode 100644 index 00000000000..3e5dcd9ee51 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPTemplateTypeParameter.java @@ -0,0 +1,27 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IType; + +/** + * @author Doug Schaefer + */ +public interface ICPPTemplateTypeParameter extends ICPPTemplateParameter, IType { + + /** + * The default type for this parameter. + * + * @return + */ + public IType getDefault(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTCompoundStatementExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTCompoundStatementExpression.java new file mode 100644 index 00000000000..9e4fe3058db --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTCompoundStatementExpression.java @@ -0,0 +1,25 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.gnu; + +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTExpression; + +/** + * @author jcamelon + */ +public interface IGNUASTCompoundStatementExpression extends IASTExpression { + + public static final ASTNodeProperty STATEMENT = new ASTNodeProperty( "Statement"); //$NON-NLS-1$ + public IASTCompoundStatement getCompoundStatement(); + public void setCompoundStatement( IASTCompoundStatement statement ); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTTypeIdExpression.java new file mode 100644 index 00000000000..8aff26afe4d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTTypeIdExpression.java @@ -0,0 +1,23 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.gnu; + +import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; + +/** + * @author jcamelon + */ +public interface IGNUASTTypeIdExpression extends IASTTypeIdExpression { + + public static final int op_typeof = IASTTypeIdExpression.op_last + 1; + public static final int op_alignof = IASTTypeIdExpression.op_last + 2; + public static final int op_last = op_alignof; + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTUnaryExpression.java new file mode 100644 index 00000000000..3b7704d32bc --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTUnaryExpression.java @@ -0,0 +1,22 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.gnu; + +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; + +/** + * @author jcamelon + */ +public interface IGNUASTUnaryExpression extends IASTUnaryExpression { + + public static final int op_typeof = IASTUnaryExpression.op_last + 1; + public static final int op_alignOf = IASTUnaryExpression.op_last + 2; + public static final int op_last = op_alignOf; +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/IGCCASTArrayRangeDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/IGCCASTArrayRangeDesignator.java new file mode 100644 index 00000000000..71e8973d04f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/IGCCASTArrayRangeDesignator.java @@ -0,0 +1,28 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.gnu.c; + +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; + +/** + * @author jcamelon + */ +public interface IGCCASTArrayRangeDesignator extends ICASTDesignator { + + public static final ASTNodeProperty SUBSCRIPT_FLOOR_EXPRESSION = new ASTNodeProperty( "Subscript Floor Expression"); //$NON-NLS-1$ + public static final ASTNodeProperty SUBSCRIPT_CEILING_EXPRESSION = new ASTNodeProperty( "Subscript Ceiling Expression"); //$NON-NLS-1$ + + public IASTExpression getRangeFloor(); + public void setRangeFloor( IASTExpression expression ); + public IASTExpression getRangeCeiling(); + public void setRangeCeiling( IASTExpression expression ); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTBinaryExpression.java new file mode 100644 index 00000000000..291433e0863 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTBinaryExpression.java @@ -0,0 +1,19 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.core.dom.ast.gnu.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; + +/** + * @author jcamelon + */ +public interface IGPPASTBinaryExpression extends IASTBinaryExpression { + +} 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 21804ed67de..ce2fadaaff6 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 @@ -68,4 +68,8 @@ public interface ITokenDuple { public void freeReferences( ); public void acceptElement( ISourceElementRequestor requestor ); + /** + * @return + */ + public abstract boolean isConversion(); } \ No newline at end of file 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 index 3db87a38bb7..471633ec9cc 100644 --- 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 @@ -440,9 +440,11 @@ public class GCCParserExtension implements IParserExtension { } catch( EndOfFileException eof ) { + //nothing } catch( BacktrackException bt ) { + //nothing } parserData.backup( startingPoint ); return null; 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 a36847a4725..e6d2e0a1e1f 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 @@ -565,5 +565,14 @@ public class BasicTokenDuple implements ITokenDuple { return firstToken.getFilename(); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ITokenDuple#isConversion() + */ + public boolean isConversion() { + int index = findLastTokenType( IToken.t_operator ); + if( index == -1 ) return false; + return true; + } + } 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 397f46e74b9..79de2765d6e 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 @@ -475,4 +475,11 @@ public class SimpleToken extends AbstractToken implements IToken { return getCharImage(); } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.ITokenDuple#isConversion() + */ + public boolean isConversion() { + return false; + } + } 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 6c39f3c12bf..412f0ff228d 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 @@ -109,7 +109,8 @@ public class TemplateTokenDuple extends BasicTokenDuple { for( int j = 0; j < argLists[i].size(); ++ j ) { IASTExpression e = (IASTExpression) argLists[i].get(j); - e.freeReferences(); + if( e != null ) + e.freeReferences(); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/ASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/ASTNode.java new file mode 100644 index 00000000000..57e901b587a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/ASTNode.java @@ -0,0 +1,36 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2; + +/** + * @author jcamelon + */ +public class ASTNode { + + private int length; + private int offset; + + public int getOffset() { + return offset; + } + + public int getLength() { + return length; + } + + public void setOffset(int offset) { + this.offset = offset; + } + + public void setLength(int length) { + this.length = length; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java new file mode 100644 index 00000000000..4f4a87e423b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java @@ -0,0 +1,1176 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionList; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; +import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression; +import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression; +import org.eclipse.cdt.core.parser.BacktrackException; +import org.eclipse.cdt.core.parser.EndOfFileException; +import org.eclipse.cdt.core.parser.IGCCToken; +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.IToken; +import org.eclipse.cdt.core.parser.OffsetLimitReachedException; +import org.eclipse.cdt.core.parser.ParseError; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.internal.core.parser.ParserProblemFactory; +import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; +import org.eclipse.cdt.internal.core.parser.token.TokenFactory; +import org.eclipse.cdt.internal.core.parser2.cpp.IProblemRequestor; + +/** + * @author jcamelon + */ +public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { + + protected final IParserLogService log; + + protected final IScanner scanner; + + protected final ParserMode mode; + + protected IProblemRequestor requestor = null; + + protected final boolean supportStatementsInExpressions; + + protected final boolean supportTypeOfUnaries; + + protected final boolean supportAlignOfUnaries; + + protected AbstractGNUSourceCodeParser(IScanner scanner, + IParserLogService logService, ParserMode parserMode, + IProblemRequestor callback, boolean supportStatementsInExpressions, + boolean supportTypeOfUnaries, boolean supportAlignOfUnaries) { + this.scanner = scanner; + this.log = logService; + this.mode = parserMode; + this.requestor = callback; + this.supportStatementsInExpressions = supportStatementsInExpressions; + this.supportTypeOfUnaries = supportTypeOfUnaries; + this.supportAlignOfUnaries = supportAlignOfUnaries; + } + + protected boolean parsePassed = true; + + protected BacktrackException backtrack = new BacktrackException(); + + protected int backtrackCount = 0; + + 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 IToken currToken; + + protected IToken lastToken; + + /** + * 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 + */ + protected 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 + */ + protected 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. + */ + protected IToken consume() throws EndOfFileException { + + if (currToken == null) + currToken = fetchToken(); + if (currToken != null) + lastToken = currToken; + currToken = currToken.getNext(); + 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 + */ + protected 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; + } + + /** + * 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 { + try { + IToken value = scanner.nextToken(); + return value; + } catch (OffsetLimitReachedException olre) { + handleOffsetLimitException(olre); + return null; + } + } + + protected boolean isCancelled = false; + + protected static final int DEFAULT_DESIGNATOR_LIST_SIZE = 4; + + protected IProblemFactory problemFactory = new ParserProblemFactory(); + + protected static int parseCount = 0; + + protected void handleOffsetLimitException( + OffsetLimitReachedException exception) throws EndOfFileException { + if (mode != ParserMode.COMPLETION_PARSE) + throw new EndOfFileException(); + throw exception; + } + + protected static final char[] EMPTY_STRING = "".toCharArray(); //$NON-NLS-1$ + + /** + * 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. + */ + protected 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. + * + */ + protected 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() { + parsePassed = false; + } + + /** + * /* (non-Javadoc) + * + * @see org.eclipse.cdt.core.parser.IParser#cancel() + */ + public synchronized void cancel() { + isCancelled = true; + scanner.cancel(); + } + + /** + * Parse an identifier. + * + * @throws BacktrackException + * request a backtrack + */ + protected IToken identifier() throws EndOfFileException, BacktrackException { + return consume(IToken.tIDENTIFIER); + } + + /** + * @return Returns the backtrackCount. + */ + public final int getBacktrackCount() { + return backtrackCount; + } + + /** + * @param bt + */ + protected void throwBacktrack(BacktrackException bt) + throws BacktrackException { + throw bt; + } + + protected void failParse(BacktrackException bt) { + if (requestor != null) { + 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 != null) { + requestor.acceptProblem(problem); + } + failParse(); + } + + /** + * @param string + * @param e + */ + protected 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() ); + } + } + + public String toString() { + return scanner.toString(); //$NON-NLS-1$ + } + + /** + * @param methodName + * @param e + */ + protected 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()); + } + } + + protected final void throwBacktrack(IProblem problem) + throws BacktrackException { + ++backtrackCount; + backtrack.initialize(problem); + throw backtrack; + } + + protected IToken simpleDeclarationMark; + + private static final int DEFAULT_COMPOUNDSTATEMENT_LIST_SIZE = 8; + + /** + * + */ + protected void cleanupLastToken() { + if (lastToken != null) + lastToken.setNext(null); + simpleDeclarationMark = null; + } + + public IASTTranslationUnit 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 getTranslationUnit(); + } + + 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; + } + } + } + + /** + * @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(); + } + + /** + * 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(); + } + + /** + * @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); + } + + /** + * @return TODO + * @throws BacktrackException + */ + protected IASTCompoundStatement compoundStatement() + throws EndOfFileException, BacktrackException { + int startingOffset = consume(IToken.tLBRACE).getOffset(); + + List statements = Collections.EMPTY_LIST; + while (LT(1) != IToken.tRBRACE) { + int checkToken = LA(1).hashCode(); + try { + IASTStatement s = statement(); + if (statements == Collections.EMPTY_LIST) + statements = new ArrayList( + DEFAULT_COMPOUNDSTATEMENT_LIST_SIZE); + statements.add(s); + } catch (BacktrackException b) { + failParse(b); + if (LA(1).hashCode() == checkToken) + failParseWithErrorHandling(); + } + } + consume(IToken.tRBRACE); + + IASTCompoundStatement result = createCompoundStatement(); + ((ASTNode)result).setOffset(startingOffset); + for (int i = 0; i < statements.size(); ++i) { + IASTStatement s = (IASTStatement) statements.get(i); + result.addStatement(s); + s.setParent(result); + s.setPropertyInParent(IASTCompoundStatement.NESTED_STATEMENT); + } + return result; + } + + /** + * @return + */ + protected abstract IASTCompoundStatement createCompoundStatement(); + + /** + * @param la + * @return @throws + * EndOfFileException + * @throws BacktrackException + */ + protected IASTExpression compoundStatementExpression(IToken la) + throws EndOfFileException, BacktrackException { + int startingOffset = la.getOffset(); + consume(IToken.tLPAREN); + IASTCompoundStatement compoundStatement = null; + if (mode == ParserMode.QUICK_PARSE + || mode == ParserMode.STRUCTURAL_PARSE) + skipOverCompoundStatement(); + else if (mode == ParserMode.COMPLETION_PARSE + || mode == ParserMode.SELECTION_PARSE) { + if (scanner.isOnTopContext()) + compoundStatement(); + else + skipOverCompoundStatement(); + } else if (mode == ParserMode.COMPLETE_PARSE) + compoundStatement = compoundStatement(); + + consume(IToken.tRPAREN); + IGNUASTCompoundStatementExpression resultExpression = createCompoundStatementExpression(); + ((ASTNode)resultExpression).setOffset( startingOffset ); + resultExpression.setCompoundStatement(compoundStatement); + compoundStatement.setParent(resultExpression); + compoundStatement + .setPropertyInParent(IGNUASTCompoundStatementExpression.STATEMENT); + + return resultExpression; + } + + /** + * @return + */ + protected abstract IGNUASTCompoundStatementExpression createCompoundStatementExpression(); + + protected IASTExpression expression() throws BacktrackException, + EndOfFileException { + IToken la = LA(1); + int startingOffset = la.getOffset(); + + if (la.getType() == IToken.tLPAREN && LT(2) == IToken.tLBRACE + && supportStatementsInExpressions) { + IASTExpression resultExpression = compoundStatementExpression(la); + if (resultExpression != null) + return resultExpression; + } + + + IASTExpression assignmentExpression = assignmentExpression(); + if( LT(1) != IToken.tCOMMA ) + return assignmentExpression; + + IASTExpressionList expressionList = createExpressionList(); + ((ASTNode)expressionList).setOffset( startingOffset ); + expressionList.addExpression( assignmentExpression ); + assignmentExpression.setParent( expressionList ); + assignmentExpression.setPropertyInParent( IASTExpressionList.NESTED_EXPRESSION ); + + while (LT(1) == IToken.tCOMMA) { + consume(IToken.tCOMMA); + IASTExpression secondExpression = assignmentExpression(); + expressionList.addExpression( secondExpression ); + secondExpression.setParent( expressionList ); + secondExpression.setPropertyInParent( IASTExpressionList.NESTED_EXPRESSION ); + } + return expressionList; + } + + /** + * @return + */ + protected abstract IASTExpressionList createExpressionList(); + + protected abstract IASTExpression assignmentExpression() + throws BacktrackException, EndOfFileException; + + protected abstract IASTExpression relationalExpression() + throws BacktrackException, EndOfFileException; + + protected abstract IASTExpression multiplicativeExpression() + throws BacktrackException, EndOfFileException; + + protected abstract IASTTypeId typeId(boolean skipArrayMods) + throws BacktrackException, EndOfFileException; + + protected abstract IASTExpression castExpression() + throws BacktrackException, EndOfFileException; + + protected abstract IASTExpression unaryExpression() + throws BacktrackException, EndOfFileException; + + protected abstract IASTExpression buildTypeIdExpression(int op_sizeof, IASTTypeId typeId, int startingOffset); + + protected abstract void translationUnit(); + + protected abstract IASTStatement statement() throws EndOfFileException, + BacktrackException; + + protected abstract IASTTranslationUnit getTranslationUnit(); + + protected IASTExpression assignmentOperatorExpression(int kind, + IASTExpression lhs) throws EndOfFileException, BacktrackException { + consume(); + IASTExpression rhs = assignmentExpression(); + return buildBinaryExpression(kind, lhs, rhs); + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression constantExpression() throws BacktrackException, + EndOfFileException { + return conditionalExpression(); + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression logicalOrExpression() throws BacktrackException, + EndOfFileException { + IASTExpression firstExpression = logicalAndExpression(); + while (LT(1) == IToken.tOR) { + consume(IToken.tOR); + IASTExpression secondExpression = logicalAndExpression(); + firstExpression = buildBinaryExpression( + IASTBinaryExpression.op_logicalOr, firstExpression, + secondExpression); + } + return firstExpression; + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression logicalAndExpression() throws BacktrackException, + EndOfFileException { + IASTExpression firstExpression = inclusiveOrExpression(); + while (LT(1) == IToken.tAND) { + consume(IToken.tAND); + IASTExpression secondExpression = inclusiveOrExpression(); + firstExpression = buildBinaryExpression( + IASTBinaryExpression.op_logicalAnd, firstExpression, + secondExpression); + } + return firstExpression; + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression inclusiveOrExpression() throws BacktrackException, + EndOfFileException { + IASTExpression firstExpression = exclusiveOrExpression(); + while (LT(1) == IToken.tBITOR) { + consume(IToken.tBITOR); + IASTExpression secondExpression = exclusiveOrExpression(); + firstExpression = buildBinaryExpression( + IASTBinaryExpression.op_binaryOr, firstExpression, + secondExpression); + } + return firstExpression; + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression exclusiveOrExpression() throws BacktrackException, + EndOfFileException { + IASTExpression firstExpression = andExpression(); + while (LT(1) == IToken.tXOR) { + consume(IToken.tXOR); + IASTExpression secondExpression = andExpression(); + firstExpression = buildBinaryExpression( + IASTBinaryExpression.op_binaryXor, firstExpression, + secondExpression); + } + return firstExpression; + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression andExpression() throws EndOfFileException, + BacktrackException { + + IASTExpression firstExpression = equalityExpression(); + while (LT(1) == IToken.tAMPER) { + consume(); + IASTExpression secondExpression = equalityExpression(); + firstExpression = buildBinaryExpression( + IASTBinaryExpression.op_binaryAnd, firstExpression, + secondExpression); + } + return firstExpression; + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression equalityExpression() throws EndOfFileException, + BacktrackException { + IASTExpression firstExpression = relationalExpression(); + for (;;) { + switch (LT(1)) { + case IToken.tEQUAL: + case IToken.tNOTEQUAL: + IToken t = consume(); + int operator = ((t.getType() == IToken.tEQUAL) ? IASTBinaryExpression.op_equals + : IASTBinaryExpression.op_notequals); + IASTExpression secondExpression = relationalExpression(); + firstExpression = buildBinaryExpression(operator, + firstExpression, secondExpression); + break; + default: + return firstExpression; + } + } + } + + protected IASTExpression buildBinaryExpression(int operator, + IASTExpression firstExpression, IASTExpression secondExpression) { + IASTBinaryExpression result = createBinaryExpression(); + result.setOperator(operator); + ((ASTNode)result).setOffset(((ASTNode)firstExpression).getOffset()); + result.setOperand1(firstExpression); + firstExpression.setParent(result); + firstExpression.setPropertyInParent(IASTBinaryExpression.OPERAND_ONE); + result.setOperand2(secondExpression); + secondExpression.setParent(result); + secondExpression.setPropertyInParent(IASTBinaryExpression.OPERAND_TWO); + return result; + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression shiftExpression() throws BacktrackException, + EndOfFileException { + IASTExpression firstExpression = additiveExpression(); + for (;;) { + switch (LT(1)) { + case IToken.tSHIFTL: + case IToken.tSHIFTR: + IToken t = consume(); + int operator = t.getType() == IToken.tSHIFTL ? IASTBinaryExpression.op_shiftLeft + : IASTBinaryExpression.op_shiftRight; + IASTExpression secondExpression = additiveExpression(); + firstExpression = buildBinaryExpression(operator, + firstExpression, secondExpression); + break; + default: + return firstExpression; + } + } + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression additiveExpression() throws BacktrackException, + EndOfFileException { + IASTExpression firstExpression = multiplicativeExpression(); + for (;;) { + switch (LT(1)) { + case IToken.tPLUS: + case IToken.tMINUS: + IToken t = consume(); + int operator = (t.getType() == IToken.tPLUS) ? IASTBinaryExpression.op_plus + : IASTBinaryExpression.op_minus; + IASTExpression secondExpression = multiplicativeExpression(); + firstExpression = buildBinaryExpression(operator, + firstExpression, secondExpression); + break; + default: + return firstExpression; + } + } + } + + /** + * @return + */ + protected abstract IASTBinaryExpression createBinaryExpression(); + + /** + * @param expression + * @return @throws + * BacktrackException + */ + protected IASTExpression conditionalExpression() throws BacktrackException, + EndOfFileException { + IASTExpression firstExpression = logicalOrExpression(); + if (LT(1) == IToken.tQUESTION) { + consume(IToken.tQUESTION); + IASTExpression secondExpression = expression(); + consume(IToken.tCOLON); + IASTExpression thirdExpression = assignmentExpression(); + IASTConditionalExpression result = createConditionalExpression(); + result.setLogicalConditionExpression(firstExpression); + firstExpression.setParent(result); + firstExpression + .setPropertyInParent(IASTConditionalExpression.LOGICAL_CONDITION); + result.setPositiveResultExpression(secondExpression); + secondExpression.setParent(result); + secondExpression + .setPropertyInParent(IASTConditionalExpression.POSITIVE_RESULT); + result.setNegativeResultExpression(thirdExpression); + thirdExpression.setParent(result); + thirdExpression + .setPropertyInParent(IASTConditionalExpression.NEGATIVE_RESULT); + return result; + } + return firstExpression; + } + + /** + * @return + */ + protected abstract IASTConditionalExpression createConditionalExpression(); + + protected IASTExpression unaryOperatorCastExpression(int operator) + throws EndOfFileException, BacktrackException { + int offset = consume().getOffset(); + IASTExpression castExpression = castExpression(); + return buildUnaryExpression(operator, castExpression, offset); + } + + /** + * @param operator + * @param operand + * @param offset + * TODO + * @return + */ + protected IASTExpression buildUnaryExpression(int operator, + IASTExpression operand, int offset) { + IASTUnaryExpression result = createUnaryExpression(); + ((ASTNode)result).setOffset(offset); + result.setOperator(operator); + result.setOperand(operand); + operand.setParent(result); + operand.setPropertyInParent(IASTUnaryExpression.OPERAND); + return result; + } + + /** + * @return + */ + protected abstract IASTUnaryExpression createUnaryExpression(); + + /** + * @return @throws + * BacktrackException + * @throws EndOfFileException + */ + protected IASTExpression unaryAlignofExpression() + throws EndOfFileException, BacktrackException { + int offset = consume(IGCCToken.t___alignof__).getOffset(); + IASTTypeId d = null; + IASTExpression unaryExpression = null; + + IToken m = mark(); + if (LT(1) == IToken.tLPAREN) { + try { + consume(IToken.tLPAREN); + d = typeId(false); + consume(IToken.tRPAREN); + } catch (BacktrackException bt) { + backup(m); + d = null; + unaryExpression = unaryExpression(); + } + } else { + unaryExpression = unaryExpression(); + } + if (d != null & unaryExpression == null) + return buildTypeIdExpression( IGNUASTTypeIdExpression.op_alignof, d, offset ); + else if (unaryExpression != null && d == null) + return buildUnaryExpression( IGNUASTUnaryExpression.op_alignOf, unaryExpression, offset ); + return null; + } + + protected IASTExpression unaryTypeofExpression() throws EndOfFileException, + BacktrackException { + int offset = consume(IGCCToken.t_typeof).getOffset(); + IASTTypeId d = null; + IASTExpression unaryExpression = null; + + IToken m = mark(); + if (LT(1) == IToken.tLPAREN) { + try { + consume(IToken.tLPAREN); + d = typeId(false); + consume(IToken.tRPAREN); + } catch (BacktrackException bt) { + backup(m); + d = null; + unaryExpression = unaryExpression(); + } + } else { + unaryExpression = unaryExpression(); + } + if (d != null & unaryExpression == null) + return buildTypeIdExpression( IGNUASTTypeIdExpression.op_typeof, d, offset ); + else if (unaryExpression != null && d == null) + return buildUnaryExpression( IGNUASTUnaryExpression.op_typeof, unaryExpression, offset ); + return null; + } + + protected IASTStatement handleFunctionBody() throws BacktrackException, + EndOfFileException { + if (mode == ParserMode.QUICK_PARSE + || mode == ParserMode.STRUCTURAL_PARSE) { + skipOverCompoundStatement(); + return null; + } else if (mode == ParserMode.COMPLETION_PARSE + || mode == ParserMode.SELECTION_PARSE) { + if (scanner.isOnTopContext()) + return functionBody(); + skipOverCompoundStatement(); + return null; + } else if (mode == ParserMode.COMPLETE_PARSE) + return functionBody(); + return null; + } + + /** + * Parses a function body. + * + * @return TODO + * + * @throws BacktrackException + * request a backtrack + */ + protected IASTStatement functionBody() throws EndOfFileException, + BacktrackException { + return compoundStatement(); + } + + /** + * @param sdw + * @param typeNameBegin + * @param typeNameEnd + */ + protected void setTypeName(DeclarationWrapper sdw, IToken typeNameBegin, + IToken typeNameEnd) { + if (typeNameBegin != null) + sdw.setTypeName(TokenFactory.createTokenDuple(typeNameBegin, + typeNameEnd)); + } + + /** + * @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 + */ + protected boolean lookAheadForDeclarator(Flags flags) + throws EndOfFileException { + return flags.haveEncounteredTypename() + && ((LT(2) != IToken.tIDENTIFIER || (LT(3) != IToken.tLPAREN && LT(3) != IToken.tASSIGN)) && !LA( + 2).isPointer()); + } + + 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; + } + + public Flags(boolean parm) { + this(parm, false); + } + + /** + * @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; + } + } + + /** + * 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 IASTEnumerationSpecifier enumSpecifier(DeclarationWrapper sdw) + throws BacktrackException, EndOfFileException { + IToken mark = mark(); + IASTName name = null; + int startOffset = consume(IToken.t_enum).getOffset(); + if (LT(1) == IToken.tIDENTIFIER) { + name = createName( identifier() ); + } + else + name = createName(); + if (LT(1) == IToken.tLBRACE) { + + IASTEnumerationSpecifier result = createEnumerationSpecifier(); + ((ASTNode)result).setOffset( startOffset ); + result.setName( name ); + name.setParent( result ); + name.setPropertyInParent( IASTEnumerationSpecifier.ENUMERATION_NAME ); + cleanupLastToken(); + consume(IToken.tLBRACE); + while (LT(1) != IToken.tRBRACE) { + IASTName enumeratorName = null; + if (LT(1) == IToken.tIDENTIFIER) { + enumeratorName = createName( 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(); + } + IASTEnumerationSpecifier.IASTEnumerator enumerator = null; + if (LT(1) == IToken.tRBRACE) { + enumerator = createEnumerator(); + enumerator.setName( enumeratorName ); + ((ASTNode)enumerator).setOffset( ((ASTNode)enumeratorName).getOffset() ); + enumeratorName.setParent( enumerator ); + enumeratorName.setPropertyInParent( IASTEnumerationSpecifier.IASTEnumerator.ENUMERATOR_NAME ); + if( initialValue != null ) + { + enumerator.setValue( initialValue ); + initialValue.setParent( enumerator ); + initialValue.setPropertyInParent( IASTEnumerationSpecifier.IASTEnumerator.ENUMERATOR_VALUE ); + } + result.addEnumerator( enumerator ); + enumerator.setParent( result ); + enumerator.setPropertyInParent( IASTEnumerationSpecifier.ENUMERATOR ); + cleanupLastToken(); + break; + } + if (LT(1) != IToken.tCOMMA) { + int endOffset = (lastToken != null) ? lastToken + .getEndOffset() : 0; + throwBacktrack(mark.getOffset(), endOffset, mark + .getLineNumber(), mark.getFilename()); + } + + enumerator = createEnumerator(); + enumerator.setName( enumeratorName ); + ((ASTNode)enumerator).setOffset( ((ASTNode)enumeratorName).getOffset() ); + enumeratorName.setParent( enumerator ); + enumeratorName.setPropertyInParent( IASTEnumerationSpecifier.IASTEnumerator.ENUMERATOR_NAME ); + if( initialValue != null ) + { + enumerator.setValue( initialValue ); + initialValue.setParent( enumerator ); + initialValue.setPropertyInParent( IASTEnumerationSpecifier.IASTEnumerator.ENUMERATOR_VALUE ); + } + result.addEnumerator( enumerator ); + enumerator.setParent( result ); + enumerator.setPropertyInParent( IASTEnumerationSpecifier.ENUMERATOR ); + cleanupLastToken(); + + consume(IToken.tCOMMA); + } + consume(IToken.tRBRACE); + return result; + } + // enumSpecifierAbort + int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0; + backup(mark); + throwBacktrack(mark.getOffset(), endOffset, mark.getLineNumber(), + mark.getFilename()); + return null; + } + + /** + * @return + */ + protected abstract IASTEnumerator createEnumerator(); + + /** + * @return + */ + protected abstract IASTEnumerationSpecifier createEnumerationSpecifier(); + + /** + * @param token + * @return + */ + protected abstract IASTName createName(IToken token); + /** + * @return + */ + protected abstract IASTName createName(); + + /** + * @throws BacktrackException + */ + protected IASTExpression condition() throws BacktrackException, EndOfFileException { + IASTExpression cond = expression(); + cleanupLastToken(); + return cond; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.core.parser2.ISourceCodeParser#encounteredError() + */ + public boolean encounteredError() { + return !parsePassed; + } + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/CompilationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/CompilationUnit.java new file mode 100644 index 00000000000..9a1283529bd --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/CompilationUnit.java @@ -0,0 +1,36 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2; + +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IScope; + +/** + * @author aniefer + */ +public class CompilationUnit implements IScope { + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IScope#getParent() + */ + public IScope getParent() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) + */ + public List find(String name) { + return null; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/DeclarationWrapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/DeclarationWrapper.java new file mode 100644 index 00000000000..9f8c4efdb24 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/DeclarationWrapper.java @@ -0,0 +1,497 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2; + +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.ITokenDuple; +import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier.Type; + +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; + + + public int startingOffset = 0; + public int startingLine; + public int endOffset; + + private ITokenDuple name; + private Type simpleType = IASTSimpleTypeSpecifier.Type.UNSPECIFIED; + private final Object templateDeclaration; + private final Object scope; + private Object typeSpecifier; + + private List declarators = Collections.EMPTY_LIST; + /** + * @param b + */ + public void setAuto(boolean b) + { + setBit( b, IS_AUTO ); + } + /** + * @return + */ + public Object getScope() + { + return scope; + } + + /** + * @param scope + * @param filename TODO + */ + public DeclarationWrapper( + Object scope, + int startingOffset, + int startingLine, Object 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 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(); + } + /** + * @return + */ + public Object getTypeSpecifier() + { + return typeSpecifier; + } + /** + * @param enumeration + */ + public void setTypeSpecifier(Object enumeration) + { + typeSpecifier = enumeration; + } + public int endLine; + + public final char[] 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 Object getOwnerTemplate() + { + return templateDeclaration; + } + /** + * @param i + */ + public void setEndingOffsetAndLineNumber(int offset, int lineNumber) + { + endOffset = offset; + endLine = lineNumber; + } + /** + * @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 ); + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/Declarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/Declarator.java new file mode 100644 index 00000000000..5360329c05a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/Declarator.java @@ -0,0 +1,428 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2; + +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.internal.core.parser.ast.EmptyIterator; + +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 Object constructorExpression = null; + private Declarator ownedDeclarator = null; + private Object initializerClause = null; + private Object exceptionSpecification = null; + private Object 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( Object 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 Object getInitializerClause() + { + return initializerClause; + } + + /** + * @param clause + */ + public void setInitializerClause(Object clause) + { + initializerClause = clause; + } + + /** + * @return + */ + public Declarator getOwnedDeclarator() + { + return ownedDeclarator; + } + + /** + * @param declarator + */ + public void setOwnedDeclarator(Declarator declarator) + { + ownedDeclarator = declarator; + } + + public void setName( ITokenDuple duple ) + { + namedDuple = duple; + } + + /** + * @return + */ + public Object getExceptionSpecification() + { + return exceptionSpecification; + } + + /** + * @return + */ + public boolean isConst() + { + return checkBit(IS_CONST); + } + + /** + * @return + */ + public boolean isVolatile() + { + return checkBit( IS_VOLATILE); + } + + /** + * @param specification + */ + public void setExceptionSpecification(Object 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(Object arrayMod) + { + if( arrayModifiers == Collections.EMPTY_LIST ) + arrayModifiers = new ArrayList( DEFAULT_ARRAYLIST_SIZE ); + arrayModifiers.add( arrayMod ); + } + + /** + * @return + */ + public List getArrayModifiers() + { + return arrayModifiers; + } + + /** + * @return + */ + public Object getBitFieldExpression() + { + return bitFieldExpression; + } + + /** + * @param exp + */ + public void setBitFieldExpression(Object exp) + { + bitFieldExpression = exp; + } + + /** + * @param astExpression + */ + public void setConstructorExpression(Object astExpression) + { + constructorExpression = astExpression; + } + + /** + * @return + */ + public Object getConstructorExpression() + { + return constructorExpression; + } + + /** + * @param initializer + */ + public void addConstructorMemberInitializer(Object 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 Object getScope() { + return getDeclarationWrapper().getScope(); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IDeclarator.java new file mode 100644 index 00000000000..2ac76010b2c --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IDeclarator.java @@ -0,0 +1,43 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2; + +import java.util.List; + +import org.eclipse.cdt.core.parser.ITokenDuple; + +/** + * @author jcamelon + */ +public interface IDeclarator +{ + public Object getScope(); + /** + * @return + */ + public abstract List getPointerOperators(); + public abstract void addPointerOperator(Object ptrOp); + /** + * @param arrayMod + */ + public abstract void addArrayModifier(Object arrayMod); + /** + * @return + */ + public abstract List getArrayModifiers(); + + /** + * @param nameDuple + */ + public void setPointerOperatorName(ITokenDuple nameDuple); + + public ITokenDuple getPointerOperatorNameDuple(); + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IDeclaratorOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IDeclaratorOwner.java new file mode 100644 index 00000000000..ee5225a3832 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IDeclaratorOwner.java @@ -0,0 +1,23 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2; + +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/parser2/IParameterCollection.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IParameterCollection.java new file mode 100644 index 00000000000..b8aa44f375f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/IParameterCollection.java @@ -0,0 +1,21 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2; + +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/parser2/ISourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/ISourceCodeParser.java new file mode 100644 index 00000000000..c8dfc9fd859 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/ISourceCodeParser.java @@ -0,0 +1,24 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2; + +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; + +/** + * @author jcamelon + */ +public interface ISourceCodeParser { + + public void cancel(); + + public IASTTranslationUnit parse(); + + public boolean encounteredError(); +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/ParameterCollection.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/ParameterCollection.java new file mode 100644 index 00000000000..9142ba62433 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/ParameterCollection.java @@ -0,0 +1,34 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2; + +import java.util.ArrayList; +import java.util.List; + + +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/parser2/TypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/TypeId.java new file mode 100644 index 00000000000..55e678a358d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/TypeId.java @@ -0,0 +1,99 @@ +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.internal.core.parser2; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.parser.ITokenDuple; + +/** + * @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 Object scope; + + /** + * @param scope2 + */ + public void reset(Object scope2) { + this.scope = scope2; + 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(Object 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(Object 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 Object getScope() { + return scope; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/ANSICParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/ANSICParserExtensionConfiguration.java new file mode 100644 index 00000000000..fe58f3450bd --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/ANSICParserExtensionConfiguration.java @@ -0,0 +1,46 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +/** + * @author jcamelon + */ +public class ANSICParserExtensionConfiguration implements + ICParserExtensionConfiguration { + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportStatementsInExpressions() + */ + public boolean supportStatementsInExpressions() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportGCCStyleDesignators() + */ + public boolean supportGCCStyleDesignators() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportTypeofUnaryExpressions() + */ + public boolean supportTypeofUnaryExpressions() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportAlignOfUnaryExpression() + */ + public boolean supportAlignOfUnaryExpression() { + return false; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTASMDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTASMDeclaration.java new file mode 100644 index 00000000000..09c819876e3 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTASMDeclaration.java @@ -0,0 +1,35 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; + +/** + * @author jcamelon + */ +public class CASTASMDeclaration extends CASTNode implements IASTASMDeclaration { + + char [] assembly = null; + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTASMDeclaration#getAssembly() + */ + public String getAssembly() { + if( assembly == null ) return ""; //$NON-NLS-1$ + return new String( assembly ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTASMDeclaration#setAssembly(java.lang.String) + */ + public void setAssembly(String assembly) { + this.assembly = assembly.toCharArray(); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayDeclarator.java new file mode 100644 index 00000000000..73d7b7064e7 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayDeclarator.java @@ -0,0 +1,77 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; + +/** + * @author jcamelon + */ +public class CASTArrayDeclarator extends CASTDeclarator implements + IASTArrayDeclarator { + + private int currentIndex = 0; + /** + * @param decls2 + */ + private void removeNullArrayModifiers() { + int nullCount = 0; + for( int i = 0; i < arrayMods.length; ++i ) + if( arrayMods[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTArrayModifier [] old = arrayMods; + int newSize = old.length - nullCount; + arrayMods = new IASTArrayModifier[ newSize ]; + for( int i = 0; i < newSize; ++i ) + arrayMods[i] = old[i]; + currentIndex = newSize; + } + + + private IASTArrayModifier [] arrayMods = null; + private static final int DEFAULT_ARRAYMODS_LIST_SIZE = 4; + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator#getArrayModifiers() + */ + public List getArrayModifiers() { + if( arrayMods == null ) return Collections.EMPTY_LIST; + removeNullArrayModifiers(); + return Arrays.asList( arrayMods ); + + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator#addArrayModifier(org.eclipse.cdt.core.dom.ast.IASTArrayModifier) + */ + public void addArrayModifier(IASTArrayModifier arrayModifier) { + if( arrayMods == null ) + { + arrayMods = new IASTArrayModifier[ DEFAULT_ARRAYMODS_LIST_SIZE ]; + currentIndex = 0; + } + if( arrayMods.length == currentIndex ) + { + IASTArrayModifier [] old = arrayMods; + arrayMods = new IASTArrayModifier[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + arrayMods[i] = old[i]; + } + arrayMods[ currentIndex++ ] = arrayModifier; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayDesignator.java new file mode 100644 index 00000000000..fcc5f1413ec --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayDesignator.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator; + +/** + * @author jcamelon + */ +public class CASTArrayDesignator extends CASTNode implements + ICASTArrayDesignator { + + private IASTExpression exp; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator#getSubscriptExpression() + */ + public IASTExpression getSubscriptExpression() { + return exp; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator#setSubscriptExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setSubscriptExpression(IASTExpression value) { + exp = value; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayModifier.java new file mode 100644 index 00000000000..d751896171e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayModifier.java @@ -0,0 +1,36 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; +import org.eclipse.cdt.core.dom.ast.IASTExpression; + +/** + * @author jcamelon + */ +public class CASTArrayModifier extends CASTNode implements IASTArrayModifier { + + private IASTExpression exp; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTArrayModifier#getConstantExpression() + */ + public IASTExpression getConstantExpression() { + return exp; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTArrayModifier#setConstantExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setConstantExpression(IASTExpression expression) { + this.exp = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayRangeDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayRangeDesignator.java new file mode 100644 index 00000000000..a168abd2871 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArrayRangeDesignator.java @@ -0,0 +1,51 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator; + +/** + * @author jcamelon + */ +public class CASTArrayRangeDesignator extends CASTNode implements + IGCCASTArrayRangeDesignator { + + private IASTExpression floor, ceiling; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.gcc.IGCCASTArrayRangeDesignator#getRangeFloor() + */ + public IASTExpression getRangeFloor() { + return this.floor; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.gcc.IGCCASTArrayRangeDesignator#setRangeFloor(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setRangeFloor(IASTExpression expression) { + floor =expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.gcc.IGCCASTArrayRangeDesignator#getRangeCeiling() + */ + public IASTExpression getRangeCeiling() { + return ceiling; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.gcc.IGCCASTArrayRangeDesignator#setRangeCeiling(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setRangeCeiling(IASTExpression expression) { + ceiling = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArraySubscriptExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArraySubscriptExpression.java new file mode 100644 index 00000000000..c0196b9f4a2 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTArraySubscriptExpression.java @@ -0,0 +1,52 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpression; + +/** + * @author jcamelon + */ +public class CASTArraySubscriptExpression extends CASTNode implements + IASTArraySubscriptExpression { + + private IASTExpression array; + private IASTExpression subscript; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression#getArrayExpression() + */ + public IASTExpression getArrayExpression() { + return array; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression#setArrayExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setArrayExpression(IASTExpression expression) { + array = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression#getSubscriptExpression() + */ + public IASTExpression getSubscriptExpression() { + return subscript; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression#setSubscriptExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setSubscriptExpression(IASTExpression expression) { + this.subscript = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBaseDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBaseDeclSpecifier.java new file mode 100644 index 00000000000..9974a592c8f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBaseDeclSpecifier.java @@ -0,0 +1,80 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier; + + +/** + * @author jcamelon + */ +public class CASTBaseDeclSpecifier extends CASTNode implements ICASTDeclSpecifier { + + protected int storageClass; + protected boolean isConst; + protected boolean isVolatile; + protected boolean isRestrict; + protected boolean isInline; + + public boolean isRestrict() { + return isRestrict; + } + + public int getStorageClass() { + return storageClass; + } + + public boolean isConst() { + return isConst; + } + + public boolean isVolatile() { + return isVolatile; + } + + public boolean isInline() { + return isInline; + } + + /** + * @param storageClass The storageClass to set. + */ + public void setStorageClass(int storageClass) { + this.storageClass = storageClass; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier#setConst(boolean) + */ + public void setConst(boolean value) { + this.isConst = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier#setVolatile(boolean) + */ + public void setVolatile(boolean value) { + this.isVolatile = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier#setRestrict(boolean) + */ + public void setRestrict(boolean value) { + this.isRestrict = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier#setInline(boolean) + */ + public void setInline(boolean value) { + this.isInline = value; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBinaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBinaryExpression.java new file mode 100644 index 00000000000..55233687a6b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBinaryExpression.java @@ -0,0 +1,67 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpression; + +/** + * @author jcamelon + */ +public class CASTBinaryExpression extends CASTNode implements + IASTBinaryExpression { + + private int op; + private IASTExpression operand1; + private IASTExpression operand2; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#getOperator() + */ + public int getOperator() { + return op; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#getOperand1() + */ + public IASTExpression getOperand1() { + return operand1; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#getOperand2() + */ + public IASTExpression getOperand2() { + return operand2; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#setOperator(int) + */ + public void setOperator(int op) { + this.op = op; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#setOperand1(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setOperand1(IASTExpression expression) { + operand1 = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTBinaryExpression#setOperand2(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setOperand2(IASTExpression expression) { + operand2 = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBreakStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBreakStatement.java new file mode 100644 index 00000000000..cfd0a221776 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTBreakStatement.java @@ -0,0 +1,19 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; + +/** + * @author jcamelon + */ +public class CASTBreakStatement extends CASTNode implements IASTBreakStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCaseStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCaseStatement.java new file mode 100644 index 00000000000..e040f787ba8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCaseStatement.java @@ -0,0 +1,36 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; +import org.eclipse.cdt.core.dom.ast.IASTExpression; + +/** + * @author jcamelon + */ +public class CASTCaseStatement extends CASTNode implements IASTCaseStatement { + + private IASTExpression expression; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCaseStatement#getExpression() + */ + public IASTExpression getExpression() { + return expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCaseStatement#setExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setExpression(IASTExpression expression) { + this.expression = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompositeTypeSpecifier.java new file mode 100644 index 00000000000..5456c1636b2 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompositeTypeSpecifier.java @@ -0,0 +1,107 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; + +/** + * @author jcamelon + */ +public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements + ICASTCompositeTypeSpecifier { + + private int key; + private IASTName name; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getKey() + */ + public int getKey() { + return key; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#setKey(int) + */ + public void setKey(int key) { + this.key = key; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getName() + */ + public IASTName getName() { + return name; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + + private int currentIndex = 0; + private IASTDeclaration [] declarations = null; + private static final int DEFAULT_DECLARATIONS_LIST_SIZE = 4; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#getMembers() + */ + public List getMembers() { + if( declarations == null ) return Collections.EMPTY_LIST; + removeNullDeclarations(); + return Arrays.asList( declarations ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier#addMemberDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) + */ + public void addMemberDeclaration(IASTDeclaration declaration) { + if( declarations == null ) + { + declarations = new IASTDeclaration[ DEFAULT_DECLARATIONS_LIST_SIZE ]; + currentIndex = 0; + } + if( declarations.length == currentIndex ) + { + IASTDeclaration [] old = declarations; + declarations = new IASTDeclaration[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + declarations[i] = old[i]; + } + declarations[ currentIndex++ ] = declaration; + } + + /** + * @param decls2 + */ + private void removeNullDeclarations() { + int nullCount = 0; + for( int i = 0; i < declarations.length; ++i ) + if( declarations[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTDeclaration [] old = declarations; + int newSize = old.length - nullCount; + declarations = new IASTDeclaration[ newSize ]; + for( int i = 0; i < newSize; ++i ) + declarations[i] = old[i]; + currentIndex = newSize; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompoundStatement.java new file mode 100644 index 00000000000..a324a2eb3c9 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompoundStatement.java @@ -0,0 +1,73 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * @author jcamelon + */ +public class CASTCompoundStatement extends CASTNode implements + IASTCompoundStatement { + + private int currentIndex = 0; + private void removeNullStatements() { + int nullCount = 0; + for( int i = 0; i < statements.length; ++i ) + if( statements[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTStatement [] old = statements; + int newSize = old.length - nullCount; + statements = new IASTStatement[ newSize ]; + for( int i = 0; i < newSize; ++i ) + statements[i] = old[i]; + currentIndex = newSize; + } + + + private IASTStatement [] statements = null; + private static final int DEFAULT_STATEMENT_LIST_SIZE = 8; + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#getStatements() + */ + public List getStatements() { + if( statements == null ) return Collections.EMPTY_LIST; + removeNullStatements(); + return Arrays.asList( statements ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTCompoundStatement#addStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void addStatement(IASTStatement statement) { + if( statements == null ) + { + statements = new IASTStatement[ DEFAULT_STATEMENT_LIST_SIZE ]; + currentIndex = 0; + } + if( statements.length == currentIndex ) + { + IASTStatement [] old = statements; + statements = new IASTStatement[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + statements[i] = old[i]; + } + statements[ currentIndex++ ] = statement; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompoundStatementExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompoundStatementExpression.java new file mode 100644 index 00000000000..4c0e71f088e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTCompoundStatementExpression.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; + +/** + * @author jcamelon + */ +public class CASTCompoundStatementExpression extends CASTNode implements + IGNUASTCompoundStatementExpression { + + private IASTCompoundStatement statement; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.gcc.IGCCASTCompoundStatementExpression#getCompoundStatement() + */ + public IASTCompoundStatement getCompoundStatement() { + return statement; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.gcc.IGCCASTCompoundStatementExpression#setCompoundStatement(org.eclipse.cdt.core.dom.ast.IASTCompoundStatement) + */ + public void setCompoundStatement(IASTCompoundStatement statement) { + this.statement = statement; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTConditionalExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTConditionalExpression.java new file mode 100644 index 00000000000..65d206f91ee --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTConditionalExpression.java @@ -0,0 +1,67 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpression; + +/** + * @author jcamelon + */ +public class CASTConditionalExpression extends CASTNode implements + IASTConditionalExpression { + + private IASTExpression condition; + private IASTExpression negative; + private IASTExpression postive; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#getLogicalConditionExpression() + */ + public IASTExpression getLogicalConditionExpression() { + return condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#setLogicalConditionExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setLogicalConditionExpression(IASTExpression expression) { + condition = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#getPositiveResultExpression() + */ + public IASTExpression getPositiveResultExpression() { + return postive; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#setPositiveResultExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setPositiveResultExpression(IASTExpression expression) { + this.postive = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#getNegativeResultExpression() + */ + public IASTExpression getNegativeResultExpression() { + return negative; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTConditionalExpression#setNegativeResultExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setNegativeResultExpression(IASTExpression expression) { + this.negative = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTContinueStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTContinueStatement.java new file mode 100644 index 00000000000..c50c145feaa --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTContinueStatement.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTContinueStatement; + +/** + * @author jcamelon + */ +public class CASTContinueStatement extends CASTNode implements + IASTContinueStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDeclarationStatement.java new file mode 100644 index 00000000000..7538cc258ab --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDeclarationStatement.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; + +/** + * @author jcamelon + */ +public class CASTDeclarationStatement extends CASTNode implements + IASTDeclarationStatement { + + private IASTDeclaration declaration; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement#getDeclaration() + */ + public IASTDeclaration getDeclaration() { + return declaration; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement#setDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) + */ + public void setDeclaration(IASTDeclaration declaration) { + this.declaration = declaration; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDeclarator.java new file mode 100644 index 00000000000..dcb85b37432 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDeclarator.java @@ -0,0 +1,117 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; + +/** + * @author jcamelon + */ +public class CASTDeclarator extends CASTNode implements IASTDeclarator { + + private IASTInitializer initializer; + private IASTName name; + private IASTDeclarator nestedDeclarator; + private IASTPointerOperator [] pointerOps = null; + private static final int DEFAULT_PTROPS_LIST_SIZE = 4; + private int currentIndex; + + private void removeNullPointers() { + int nullCount = 0; + for( int i = 0; i < pointerOps.length; ++i ) + if( pointerOps[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTPointerOperator [] old = pointerOps; + int newSize = old.length - nullCount; + pointerOps = new IASTPointerOperator[ newSize ]; + for( int i = 0; i < newSize; ++i ) + pointerOps[i] = old[i]; + currentIndex = newSize; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclarator#getPointerOperators() + */ + public List getPointerOperators() { + if( pointerOps == null ) return Collections.EMPTY_LIST; + removeNullPointers(); + return Arrays.asList( pointerOps ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclarator#getNestedDeclarator() + */ + public IASTDeclarator getNestedDeclarator() { + return nestedDeclarator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclarator#getName() + */ + public IASTName getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclarator#getInitializer() + */ + public IASTInitializer getInitializer() { + return initializer; + } + + /** + * @param initializer + */ + public void setInitializer(IASTInitializer initializer) { + this.initializer = initializer; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclarator#addPointerOperator(org.eclipse.cdt.core.dom.ast.IASTPointerOperator) + */ + public void addPointerOperator(IASTPointerOperator operator) { + if( pointerOps == null ) + { + pointerOps = new IASTPointerOperator[ DEFAULT_PTROPS_LIST_SIZE ]; + currentIndex = 0; + } + if( pointerOps.length == currentIndex ) + { + IASTPointerOperator [] old = pointerOps; + pointerOps = new IASTPointerOperator[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + pointerOps[i] = old[i]; + } + pointerOps[ currentIndex++ ] = operator; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclarator#setNestedDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) + */ + public void setNestedDeclarator(IASTDeclarator nested) { + this.nestedDeclarator = nested; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDeclarator#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDefaultStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDefaultStatement.java new file mode 100644 index 00000000000..688d8328b15 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDefaultStatement.java @@ -0,0 +1,20 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; + +/** + * @author jcamelon + */ +public class CASTDefaultStatement extends CASTNode implements + IASTDefaultStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDoStatement.java new file mode 100644 index 00000000000..41aec3575cd --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTDoStatement.java @@ -0,0 +1,52 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTDoStatement; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * @author jcamelon + */ +public class CASTDoStatement extends CASTNode implements IASTDoStatement { + + private IASTStatement body; + private IASTExpression condition; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDoStatement#getBody() + */ + public IASTStatement getBody() { + return body; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDoStatement#setBody(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setBody(IASTStatement body) { + this.body = body; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDoStatement#getCondition() + */ + public IASTExpression getCondition() { + return condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTDoStatement#setCondition(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setCondition(IASTExpression condition) { + this.condition = condition; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTElaboratedTypeSpecifier.java new file mode 100644 index 00000000000..0c8a92d460f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTElaboratedTypeSpecifier.java @@ -0,0 +1,52 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; + +/** + * @author jcamelon + */ +public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implements + ICASTElaboratedTypeSpecifier { + + private int kind; + private IASTName name; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier#getKind() + */ + public int getKind() { + return kind; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier#setKind(int) + */ + public void setKind(int value) { + this.kind = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier#getName() + */ + public IASTName getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTEnumerationSpecifier.java new file mode 100644 index 00000000000..578ec3ec8fb --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTEnumerationSpecifier.java @@ -0,0 +1,88 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; + +/** + * @author jcamelon + */ +public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier implements + ICASTEnumerationSpecifier { + + private IASTName name; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#addEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) + */ + public void addEnumerator(IASTEnumerator enumerator) { + if( enumerators == null ) + { + enumerators = new IASTEnumerator[ DEFAULT_ENUMERATOR_LIST_SIZE ]; + currentIndex = 0; + } + if( enumerators.length == currentIndex ) + { + IASTEnumerator [] old = enumerators; + enumerators = new IASTEnumerator[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + enumerators[i] = old[i]; + } + enumerators[ currentIndex++ ] = enumerator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#getEnumerators() + */ + public List getEnumerators() { + if( enumerators == null ) return Collections.EMPTY_LIST; + removeNullEnumerators(); + return Arrays.asList( enumerators ); + + } + + private void removeNullEnumerators() { + int nullCount = 0; + for( int i = 0; i < enumerators.length; ++i ) + if( enumerators[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTEnumerator [] old = enumerators; + int newSize = old.length - nullCount; + enumerators = new IASTEnumerator[ newSize ]; + for( int i = 0; i < newSize; ++i ) + enumerators[i] = old[i]; + currentIndex = newSize; + } + + private int currentIndex = 0; + private IASTEnumerator [] enumerators = null; + private static final int DEFAULT_ENUMERATOR_LIST_SIZE = 4; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier#getName() + */ + public IASTName getName() { + return name; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTEnumerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTEnumerator.java new file mode 100644 index 00000000000..32af622d179 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTEnumerator.java @@ -0,0 +1,52 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; + +/** + * @author jcamelon + */ +public class CASTEnumerator extends CASTNode implements IASTEnumerator { + + private IASTName name; + private IASTExpression value; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator#getName() + */ + public IASTName getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator#setValue(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setValue(IASTExpression expression) { + this.value = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator#getValue() + */ + public IASTExpression getValue() { + return value; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTExpressionList.java new file mode 100644 index 00000000000..6bae2e4839f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTExpressionList.java @@ -0,0 +1,73 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionList; + +/** + * @author jcamelon + */ +public class CASTExpressionList extends CASTNode implements IASTExpressionList { + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#getExpressions() + */ + public List getExpressions() { + if( expressions == null ) return Collections.EMPTY_LIST; + removeNullExpressions(); + return Arrays.asList( expressions ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTExpressionList#addExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void addExpression(IASTExpression expression) { + if( expressions == null ) + { + expressions = new IASTExpression[ DEFAULT_EXPRESSIONLIST_SIZE ]; + currentIndex = 0; + } + if( expressions.length == currentIndex ) + { + IASTExpression [] old = expressions; + expressions = new IASTExpression[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + expressions[i] = old[i]; + } + expressions[ currentIndex++ ] = expression; + } + + /** + * @param decls2 + */ + private void removeNullExpressions() { + int nullCount = 0; + for( int i = 0; i < expressions.length; ++i ) + if( expressions[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTExpression [] old = expressions; + int newSize = old.length - nullCount; + expressions = new IASTExpression[ newSize ]; + for( int i = 0; i < newSize; ++i ) + expressions[i] = old[i]; + currentIndex = newSize; + } + + private int currentIndex = 0; + private IASTExpression [] expressions = null; + private static final int DEFAULT_EXPRESSIONLIST_SIZE = 4; + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTExpressionStatement.java new file mode 100644 index 00000000000..a29b47c5712 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTExpressionStatement.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; + +/** + * @author jcamelon + */ +public class CASTExpressionStatement extends CASTNode implements + IASTExpressionStatement { + + private IASTExpression expression; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTExpressionStatement#getExpression() + */ + public IASTExpression getExpression() { + return expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTExpressionStatement#setExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setExpression(IASTExpression expression) { + this.expression = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldDeclarator.java new file mode 100644 index 00000000000..89c59f2eed2 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldDeclarator.java @@ -0,0 +1,38 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; + +/** + * @author jcamelon + */ +public class CASTFieldDeclarator extends CASTDeclarator implements + IASTFieldDeclarator { + + private IASTExpression bitFieldSize; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator#getBitFieldSize() + */ + public IASTExpression getBitFieldSize() { + return bitFieldSize; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator#setBitFieldSize(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setBitFieldSize(IASTExpression size) { + bitFieldSize = size; + } + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldDesignator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldDesignator.java new file mode 100644 index 00000000000..29f21317015 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldDesignator.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator; + +/** + * @author jcamelon + */ +public class CASTFieldDesignator extends CASTNode implements + ICASTFieldDesignator { + + private IASTName name; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator#getName() + */ + public IASTName getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldReference.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldReference.java new file mode 100644 index 00000000000..7e64ce3b9be --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFieldReference.java @@ -0,0 +1,67 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTFieldReference; +import org.eclipse.cdt.core.dom.ast.IASTName; + +/** + * @author jcamelon + */ +public class CASTFieldReference extends CASTNode implements IASTFieldReference { + + private IASTExpression owner; + private IASTName name; + private boolean ptr; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFieldReference#getFieldOwner() + */ + public IASTExpression getFieldOwner() { + return owner; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFieldReference#setFieldOwner(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setFieldOwner(IASTExpression expression) { + this.owner = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFieldReference#getFieldName() + */ + public IASTName getFieldName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFieldReference#setFieldName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setFieldName(IASTName name) { + this.name = name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFieldReference#isPointerDereference() + */ + public boolean isPointerDereference() { + return ptr; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFieldReference#setIsPointerDereference(boolean) + */ + public void setIsPointerDereference(boolean value) { + ptr = value; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTForStatement.java new file mode 100644 index 00000000000..9f451c9abfb --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTForStatement.java @@ -0,0 +1,99 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTForStatement; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * @author jcamelon + */ +public class CASTForStatement extends CASTNode implements IASTForStatement { + + private IASTExpression initialExpression; + private IASTDeclaration initDeclaration; + private IASTExpression condition; + private IASTExpression iterationExpression; + private IASTStatement body; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getInitExpression() + */ + public IASTExpression getInitExpression() { + return initialExpression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#setInit(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setInit(IASTExpression expression) { + this.initialExpression = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getInitDeclaration() + */ + public IASTDeclaration getInitDeclaration() { + return initDeclaration; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#setInit(org.eclipse.cdt.core.dom.ast.IASTDeclaration) + */ + public void setInit(IASTDeclaration declaration) { + this.initDeclaration = declaration; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getCondition() + */ + public IASTExpression getCondition() { + return condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#setCondition(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setCondition(IASTExpression condition) { + this.condition = condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getIterationExpression() + */ + public IASTExpression getIterationExpression() { + return iterationExpression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#setIterationExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setIterationExpression(IASTExpression iterator) { + this.iterationExpression = iterator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#getBody() + */ + public IASTStatement getBody() { + return body; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTForStatement#setBody(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setBody(IASTStatement statement) { + body = statement; + + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionCallExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionCallExpression.java new file mode 100644 index 00000000000..afa484c7a8a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionCallExpression.java @@ -0,0 +1,52 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; + +/** + * @author jcamelon + */ +public class CASTFunctionCallExpression extends CASTNode implements + IASTFunctionCallExpression { + + private IASTExpression functionName; + private IASTExpression parameter; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression#setFunctionNameExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setFunctionNameExpression(IASTExpression expression) { + this.functionName = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression#getFunctionNameExpression() + */ + public IASTExpression getFunctionNameExpression() { + return functionName; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression#setParameterExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setParameterExpression(IASTExpression expression) { + this.parameter = expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression#getParameterExpression() + */ + public IASTExpression getParameterExpression() { + return parameter; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionDeclarator.java new file mode 100644 index 00000000000..4cae1490506 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionDeclarator.java @@ -0,0 +1,91 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; + +/** + * @author jcamelon + */ +public class CASTFunctionDeclarator extends CASTDeclarator implements + IASTFunctionDeclarator { + + private IASTParameterDeclaration [] parameters = null; + private static final int DEFAULT_PARAMETERS_LIST_SIZE = 4; + + private int currentIndex = 0; + private boolean varArgs; + + /** + * @param decls2 + */ + private void removeNullParameters() { + int nullCount = 0; + for( int i = 0; i < parameters.length; ++i ) + if( parameters[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTParameterDeclaration [] old = parameters; + int newSize = old.length - nullCount; + parameters = new IASTParameterDeclaration[ newSize ]; + for( int i = 0; i < newSize; ++i ) + parameters[i] = old[i]; + currentIndex = newSize; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#getParameters() + */ + public List getParameters() { + if( parameters == null ) return Collections.EMPTY_LIST; + removeNullParameters(); + return Arrays.asList( parameters ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#addParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) + */ + public void addParameterDeclaration(IASTParameterDeclaration parameter) { + if( parameters == null ) + { + parameters = new IASTParameterDeclaration[ DEFAULT_PARAMETERS_LIST_SIZE ]; + currentIndex = 0; + } + if( parameters.length == currentIndex ) + { + IASTParameterDeclaration [] old = parameters; + parameters = new IASTParameterDeclaration[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + parameters[i] = old[i]; + } + parameters[ currentIndex++ ] = parameter; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#takesVarArgs() + */ + public boolean takesVarArgs() { + return varArgs; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator#setVarArgs(boolean) + */ + public void setVarArgs(boolean value) { + varArgs = value; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionDefinition.java new file mode 100644 index 00000000000..766d788f23c --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTFunctionDefinition.java @@ -0,0 +1,69 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * @author jcamelon + */ +public class CASTFunctionDefinition extends CASTNode implements + IASTFunctionDefinition { + + private IASTDeclSpecifier declSpecifier; + private IASTFunctionDeclarator declarator; + private IASTStatement bodyStatement; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#getDeclSpecifier() + */ + public IASTDeclSpecifier getDeclSpecifier() { + return declSpecifier; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#setDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) + */ + public void setDeclSpecifier(IASTDeclSpecifier declSpec) { + declSpecifier = declSpec; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#getDeclarator() + */ + public IASTFunctionDeclarator getDeclarator() { + return declarator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#setDeclarator(org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator) + */ + public void setDeclarator(IASTFunctionDeclarator declarator) { + this.declarator = declarator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#getBody() + */ + public IASTStatement getBody() { + return bodyStatement; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition#setBody(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setBody(IASTStatement statement) { + bodyStatement = statement; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTGotoStatement.java new file mode 100644 index 00000000000..00ec6cd3d61 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTGotoStatement.java @@ -0,0 +1,36 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; +import org.eclipse.cdt.core.dom.ast.IASTName; + +/** + * @author jcamelon + */ +public class CASTGotoStatement extends CASTNode implements IASTGotoStatement { + + private IASTName name; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTGotoStatement#getName() + */ + public IASTName getName() { + return this.name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTGotoStatement#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTIdExpression.java new file mode 100644 index 00000000000..b06e8b69df5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTIdExpression.java @@ -0,0 +1,36 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTName; + +/** + * @author jcamelon + */ +public class CASTIdExpression extends CASTNode implements IASTIdExpression { + + private IASTName name; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIdExpression#getName() + */ + public IASTName getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIdExpression#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTIfStatement.java new file mode 100644 index 00000000000..b63c9bc5847 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTIfStatement.java @@ -0,0 +1,67 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTIfStatement; +import org.eclipse.cdt.core.dom.ast.IASTStatement; + +/** + * @author jcamelon + */ +public class CASTIfStatement extends CASTNode implements IASTIfStatement { + + private IASTExpression condition; + private IASTStatement thenClause; + private IASTStatement elseClause; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#getCondition() + */ + public IASTExpression getCondition() { + return condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#setCondition(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setCondition(IASTExpression condition) { + this.condition = condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#getThenClause() + */ + public IASTStatement getThenClause() { + return thenClause; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#setThenClause(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setThenClause(IASTStatement thenClause) { + this.thenClause = thenClause; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#getElseClause() + */ + public IASTStatement getElseClause() { + return elseClause; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTIfStatement#setElseClause(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setElseClause(IASTStatement elseClause) { + this.elseClause = elseClause; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTInitializerExpresion.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTInitializerExpresion.java new file mode 100644 index 00000000000..c5125835b84 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTInitializerExpresion.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; + +/** + * @author jcamelon + */ +public class CASTInitializerExpresion extends CASTNode implements + IASTInitializerExpression { + + private IASTExpression expression; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTInitializerExpression#getExpression() + */ + public IASTExpression getExpression() { + return expression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTInitializerExpression#setExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setExpression(IASTExpression expression) { + this.expression = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTInitializerList.java new file mode 100644 index 00000000000..8bd425abe2e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTInitializerList.java @@ -0,0 +1,76 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.dom.ast.IASTInitializerList; + +/** + * @author jcamelon + */ +public class CASTInitializerList extends CASTNode implements + IASTInitializerList { + + + private int currentIndex = 0; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators() + */ + public List getInitializers() { + if( initializers == null ) return Collections.EMPTY_LIST; + removeNullInitializers(); + return Arrays.asList( initializers ); + } + + public void addInitializer( IASTInitializer d ) + { + if( initializers == null ) + { + initializers = new IASTInitializer[ DEFAULT_INITIALIZERS_LIST_SIZE ]; + currentIndex = 0; + } + if( initializers.length == currentIndex ) + { + IASTInitializer [] old = initializers; + initializers = new IASTInitializer[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + initializers[i] = old[i]; + } + initializers[ currentIndex++ ] = d; + + } + + /** + * @param decls2 + */ + private void removeNullInitializers() { + int nullCount = 0; + for( int i = 0; i < initializers.length; ++i ) + if( initializers[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTInitializer [] old = initializers; + int newSize = old.length - nullCount; + initializers = new IASTInitializer[ newSize ]; + for( int i = 0; i < newSize; ++i ) + initializers[i] = old[i]; + currentIndex = newSize; + } + + + private IASTInitializer [] initializers = null; + private static final int DEFAULT_INITIALIZERS_LIST_SIZE = 4; + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTLabelStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTLabelStatement.java new file mode 100644 index 00000000000..d42f3238ca8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTLabelStatement.java @@ -0,0 +1,36 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; +import org.eclipse.cdt.core.dom.ast.IASTName; + +/** + * @author jcamelon + */ +public class CASTLabelStatement extends CASTNode implements IASTLabelStatement { + + private IASTName name; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTLabelStatement#getName() + */ + public IASTName getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTLabelStatement#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTLiteralExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTLiteralExpression.java new file mode 100644 index 00000000000..3980c925fbe --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTLiteralExpression.java @@ -0,0 +1,51 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; + +/** + * @author jcamelon + */ +public class CASTLiteralExpression extends CASTNode implements + IASTLiteralExpression { + + private int kind; + private String value = ""; //$NON-NLS-1$ + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTLiteralExpression#getKind() + */ + public int getKind() { + return kind; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTLiteralExpression#setKind(int) + */ + public void setKind(int value) { + kind = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTLiteralExpression#setValue(java.lang.String) + */ + public void setValue(String value) { + this.value = value; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + return value; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTModifiedArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTModifiedArrayModifier.java new file mode 100644 index 00000000000..9530b079874 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTModifiedArrayModifier.java @@ -0,0 +1,81 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier; + +/** + * @author jcamelon + */ +public class CASTModifiedArrayModifier extends CASTArrayModifier implements + ICASTArrayModifier { + + private boolean isVolatile; + private boolean isRestrict; + private boolean isStatic; + private boolean isConst; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#isConst() + */ + public boolean isConst() { + return isConst; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#isStatic() + */ + public boolean isStatic() { + return isStatic; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#isRestrict() + */ + public boolean isRestrict() { + return isRestrict; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#isVolatile() + */ + public boolean isVolatile() { + return isVolatile; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#setConst(boolean) + */ + public void setConst(boolean value) { + this.isConst = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#setVolatile(boolean) + */ + public void setVolatile(boolean value) { + this.isVolatile = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#setRestrict(boolean) + */ + public void setRestrict(boolean value) { + this.isRestrict = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier#setStatic(boolean) + */ + public void setStatic(boolean value) { + this.isStatic = value; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTName.java new file mode 100644 index 00000000000..284508058e3 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTName.java @@ -0,0 +1,63 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IBinding; + +/** + * @author jcamelon + */ +public class CASTName extends CASTNode implements IASTName { + + private final char[] name; + private static final char[] EMPTY_CHAR_ARRAY = { }; + private IBinding binding = null; + + /** + * @param name + */ + public CASTName(char [] name ) { + this.name = name; + } + + /** + * + */ + public CASTName() { + name = EMPTY_CHAR_ARRAY; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding() + */ + public IBinding resolveBinding() { + if( binding == null ) + CVisitor.createBinding( this ); + + return binding; + } + + protected void setBinding( IBinding binding ){ + this.binding = binding; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + if( name == EMPTY_CHAR_ARRAY ) return null; + return new String( name ); + } + + public char[] toCharArray() { + return name; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNode.java new file mode 100644 index 00000000000..026222c8cd9 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNode.java @@ -0,0 +1,66 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.internal.core.parser2.ASTNode; + +/** + * @author jcamelon + */ +class CASTNode extends ASTNode implements IASTNode { + + + private IASTNode parent; + private ASTNodeProperty property; + + public IASTNode getParent() { + return parent; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#getPropertyInParent() + */ + public ASTNodeProperty getPropertyInParent() { + return property; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#setParent(org.eclipse.cdt.core.dom.ast.IASTNode) + */ + public void setParent(IASTNode parent) { + this.parent = parent; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#setPropertyInParent(org.eclipse.cdt.core.dom.ast.IASTNodeProperty) + */ + public void setPropertyInParent(ASTNodeProperty property) { + this.property = property; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#getTranslationUnit() + */ + public IASTTranslationUnit getTranslationUnit() { + if( this instanceof IASTTranslationUnit ) return (IASTTranslationUnit) this; + IASTNode node = getParent(); + while( ! (node instanceof IASTTranslationUnit )) + { + node = node.getParent(); + } + return (IASTTranslationUnit) node; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNullStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNullStatement.java new file mode 100644 index 00000000000..8b1cb281e1f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTNullStatement.java @@ -0,0 +1,19 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.c.IASTNullStatement; + +/** + * @author jcamelon + */ +public class CASTNullStatement extends CASTNode implements IASTNullStatement { + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTParameterDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTParameterDeclaration.java new file mode 100644 index 00000000000..e47d754a0de --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTParameterDeclaration.java @@ -0,0 +1,53 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; + +/** + * @author jcamelon + */ +public class CASTParameterDeclaration extends CASTNode implements + IASTParameterDeclaration { + + private IASTDeclSpecifier declSpec; + private IASTDeclarator declarator; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration#getDeclSpecifier() + */ + public IASTDeclSpecifier getDeclSpecifier() { + return declSpec; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration#getDeclarator() + */ + public IASTDeclarator getDeclarator() { + return declarator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration#setDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) + */ + public void setDeclSpecifier(IASTDeclSpecifier declSpec) { + this.declSpec = declSpec; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration#setDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) + */ + public void setDeclarator(IASTDeclarator declarator) { + this.declarator = declarator; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTPointer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTPointer.java new file mode 100644 index 00000000000..bac638790b6 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTPointer.java @@ -0,0 +1,65 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.c.ICASTPointer; + +/** + * @author jcamelon + */ +public class CASTPointer extends CASTNode implements ICASTPointer { + + private boolean isRestrict; + private boolean isVolatile; + private boolean isConst; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTPointer#isRestrict() + */ + public boolean isRestrict() { + return isRestrict; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTPointer#setRestrict(boolean) + */ + public void setRestrict(boolean value) { + isRestrict = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTPointer#isConst() + */ + public boolean isConst() { + return isConst; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTPointer#isVolatile() + */ + public boolean isVolatile() { + return isVolatile; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTPointer#setConst(boolean) + */ + public void setConst(boolean value) { + isConst = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTPointer#setVolatile(boolean) + */ + public void setVolatile(boolean value) { + isVolatile = value; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTReturnStatement.java new file mode 100644 index 00000000000..2a6688dbe55 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTReturnStatement.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; + +/** + * @author jcamelon + */ +public class CASTReturnStatement extends CASTNode implements + IASTReturnStatement { + + private IASTExpression retValue; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTReturnStatement#getReturnValue() + */ + public IASTExpression getReturnValue() { + return retValue; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTReturnStatement#setReturnValue(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setReturnValue(IASTExpression returnValue) { + retValue = returnValue; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSimpleDeclSpecifier.java new file mode 100644 index 00000000000..8b374aa2ca8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSimpleDeclSpecifier.java @@ -0,0 +1,96 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; + +/** + * @author jcamelon + */ +public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements ICASTSimpleDeclSpecifier { + + private int simpleType; + private boolean isSigned; + private boolean isUnsigned; + private boolean isShort; + private boolean isLong; + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier#getType() + */ + public int getType() { + return simpleType; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier#isSigned() + */ + public boolean isSigned() { + return isSigned; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier#isUnsigned() + */ + public boolean isUnsigned() { + return isUnsigned; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier#isShort() + */ + public boolean isShort() { + return isShort; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier#isLong() + */ + public boolean isLong() { + return isLong; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier#setType(int) + */ + public void setType(int type) { + simpleType = type; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier#setShort(boolean) + */ + public void setShort(boolean value) { + isShort = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier#setLong(boolean) + */ + public void setLong(boolean value) { + isLong = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier#setUnsigned(boolean) + */ + public void setUnsigned(boolean value) { + isUnsigned = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier#setSigned(boolean) + */ + public void setSigned(boolean value) { + isSigned = value; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSimpleDeclaration.java new file mode 100644 index 00000000000..3d6b340cbf1 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSimpleDeclaration.java @@ -0,0 +1,90 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; + +/** + * @author jcamelon + */ +public class CASTSimpleDeclaration extends CASTNode implements + IASTSimpleDeclaration { + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclSpecifier() + */ + public IASTDeclSpecifier getDeclSpecifier() { + return declSpecifier; + } + + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration#getDeclarators() + */ + public List getDeclarators() { + if( declarators == null ) return Collections.EMPTY_LIST; + removeNullDeclarators(); + return Arrays.asList( declarators ); + } + + public void addDeclarator( IASTDeclarator d ) + { + if( declarators == null ) + { + declarators = new IASTDeclarator[ DEFAULT_DECLARATORS_LIST_SIZE ]; + currentIndex = 0; + } + if( declarators.length == currentIndex ) + { + IASTDeclarator [] old = declarators; + declarators = new IASTDeclarator[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + declarators[i] = old[i]; + } + declarators[ currentIndex++ ] = d; + + } + + /** + * @param decls2 + */ + private void removeNullDeclarators() { + int nullCount = 0; + for( int i = 0; i < declarators.length; ++i ) + if( declarators[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTDeclarator [] old = declarators; + int newSize = old.length - nullCount; + declarators = new IASTDeclarator[ newSize ]; + for( int i = 0; i < newSize; ++i ) + declarators[i] = old[i]; + currentIndex = newSize; + } + + private int currentIndex = 0; + private IASTDeclarator [] declarators = null; + private static final int DEFAULT_DECLARATORS_LIST_SIZE = 4; + private IASTDeclSpecifier declSpecifier; + + /** + * @param declSpecifier The declSpecifier to set. + */ + public void setDeclSpecifier(IASTDeclSpecifier declSpecifier) { + this.declSpecifier = declSpecifier; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSwitchStatement.java new file mode 100644 index 00000000000..5c47d2502f3 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTSwitchStatement.java @@ -0,0 +1,53 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; + +/** + * @author jcamelon + */ +public class CASTSwitchStatement extends CASTNode implements + IASTSwitchStatement { + + private IASTExpression controller; + private IASTStatement body; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#getController() + */ + public IASTExpression getController() { + return controller; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#setController(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setController(IASTExpression controller) { + this.controller = controller; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#getBody() + */ + public IASTStatement getBody() { + return body; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTSwitchStatement#setBody(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setBody(IASTStatement body) { + this.body = body; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTranslationUnit.java new file mode 100644 index 00000000000..79a15161502 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTranslationUnit.java @@ -0,0 +1,103 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.internal.core.parser2.CompilationUnit; + +/** + * @author jcamelon + */ +public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit { + + + private IASTDeclaration [] decls = null; + private static final int DEFAULT_CHILDREN_LIST_SIZE = 8; + private int currentIndex = 0; + + //Binding + private CompilationUnit compilationUnit = null; + + public void addDeclaration( IASTDeclaration d ) + { + if( decls == null ) + { + decls = new IASTDeclaration[ DEFAULT_CHILDREN_LIST_SIZE ]; + currentIndex = 0; + } + if( decls.length == currentIndex ) + { + IASTDeclaration [] old = decls; + decls = new IASTDeclaration[ old.length * 2 ]; + for( int i = 0; i < old.length; ++i ) + decls[i] = old[i]; + } + decls[ currentIndex++ ] = d; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations() + */ + public List getDeclarations() { + if( decls == null ) return Collections.EMPTY_LIST; + removeNullDeclarations(); + return Arrays.asList( decls ); + } + + /** + * @param decls2 + */ + private void removeNullDeclarations() { + int nullCount = 0; + for( int i = 0; i < decls.length; ++i ) + if( decls[i] == null ) + ++nullCount; + if( nullCount == 0 ) return; + IASTDeclaration [] old = decls; + int newSize = old.length - nullCount; + decls = new IASTDeclaration[ newSize ]; + for( int i = 0; i < newSize; ++i ) + decls[i] = old[i]; + currentIndex = newSize; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope() + */ + public IScope getScope() { + if( compilationUnit == null ) + compilationUnit = new CompilationUnit(); + return compilationUnit; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding) + */ + public List getDeclarations(IBinding binding) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getReferences(org.eclipse.cdt.core.dom.ast.IBinding) + */ + public List getReferences(IBinding binding) { + // TODO Auto-generated method stub + return null; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeId.java new file mode 100644 index 00000000000..aee0057b393 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeId.java @@ -0,0 +1,53 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; + +/** + * @author jcamelon + */ +public class CASTTypeId extends CASTNode implements IASTTypeId { + + private IASTDeclSpecifier declSpecifier; + private IASTDeclarator declarator; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeId#getDeclSpecifier() + */ + public IASTDeclSpecifier getDeclSpecifier() { + return declSpecifier; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeId#setDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) + */ + public void setDeclSpecifier(IASTDeclSpecifier declSpec) { + this.declSpecifier = declSpec; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeId#getAbstractDeclarator() + */ + public IASTDeclarator getAbstractDeclarator() { + return declarator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeId#setAbstractDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) + */ + public void setAbstractDeclarator(IASTDeclarator abstractDeclarator) { + declarator = abstractDeclarator; + + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeIdExpression.java new file mode 100644 index 00000000000..56e8195353f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeIdExpression.java @@ -0,0 +1,52 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; + +/** + * @author jcamelon + */ +public class CASTTypeIdExpression extends CASTNode implements + IASTTypeIdExpression { + + private int op; + private IASTTypeId typeId; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression#getOperator() + */ + public int getOperator() { + return op; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression#setOperator(int) + */ + public void setOperator(int value) { + this.op = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression#setTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) + */ + public void setTypeId(IASTTypeId typeId) { + this.typeId = typeId; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression#getTypeId() + */ + public IASTTypeId getTypeId() { + return typeId; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeIdInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeIdInitializerExpression.java new file mode 100644 index 00000000000..28d28613cd8 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypeIdInitializerExpression.java @@ -0,0 +1,53 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; + +/** + * @author jcamelon + */ +public class CASTTypeIdInitializerExpression extends CASTNode implements + ICASTTypeIdInitializerExpression { + + private IASTTypeId t; + private IASTInitializer i; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression#getTypeId() + */ + public IASTTypeId getTypeId() { + return t; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression#setTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) + */ + public void setTypeId(IASTTypeId typeId) { + t = typeId; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression#getInitializer() + */ + public IASTInitializer getInitializer() { + return i; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression#setInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) + */ + public void setInitializer(IASTInitializer initializer) { + i = initializer; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypedefNameSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypedefNameSpecifier.java new file mode 100644 index 00000000000..831732b127a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTTypedefNameSpecifier.java @@ -0,0 +1,36 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; + +/** + * @author jcamelon + */ +public class CASTTypedefNameSpecifier extends CASTBaseDeclSpecifier implements + ICASTTypedefNameSpecifier { + + private IASTName name; + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypedefNameSpecifier#getName() + */ + public IASTName getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTypedefNameSpecifier#setName(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public void setName(IASTName name) { + this.name = name; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTUnaryExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTUnaryExpression.java new file mode 100644 index 00000000000..ff4bfba8ee5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTUnaryExpression.java @@ -0,0 +1,52 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; + +/** + * @author jcamelon + */ +public class CASTUnaryExpression extends CASTNode implements + IASTUnaryExpression { + + private int operator; + private IASTExpression operand; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryExpression#getOperator() + */ + public int getOperator() { + return operator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryExpression#setOperator(int) + */ + public void setOperator(int value) { + this.operator = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryExpression#getOperand() + */ + public IASTExpression getOperand() { + return operand; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryExpression#setOperand(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setOperand(IASTExpression expression) { + operand = expression; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTUnaryTypeIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTUnaryTypeIdExpression.java new file mode 100644 index 00000000000..5d96a773fcf --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTUnaryTypeIdExpression.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTUnaryTypeIdExpression; + +/** + * @author jcamelon + */ +public class CASTUnaryTypeIdExpression extends CASTUnaryExpression implements + IASTUnaryTypeIdExpression { + + private IASTTypeId typeId; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryTypeIdExpression#setTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) + */ + public void setTypeId(IASTTypeId typeId) { + this.typeId = typeId; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTUnaryTypeIdExpression#getTypeId() + */ + public IASTTypeId getTypeId() { + return typeId; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTWhileStatement.java new file mode 100644 index 00000000000..9a966cac050 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CASTWhileStatement.java @@ -0,0 +1,52 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; + +/** + * @author jcamelon + */ +public class CASTWhileStatement extends CASTNode implements IASTWhileStatement { + + private IASTExpression condition; + private IASTStatement body; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTWhileStatement#getCondition() + */ + public IASTExpression getCondition() { + return condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTWhileStatement#setCondition(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setCondition(IASTExpression condition) { + this.condition = condition; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTWhileStatement#getBody() + */ + public IASTStatement getBody() { + return body; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTWhileStatement#setBody(org.eclipse.cdt.core.dom.ast.IASTStatement) + */ + public void setBody(IASTStatement body) { + this.body = body; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CField.java new file mode 100644 index 00000000000..cac7b68b894 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CField.java @@ -0,0 +1,30 @@ + +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IField; + +/** + * Created on Nov 8, 2004 + * @author aniefer + */ +public class CField extends CVariable implements IField { + + /** + * @param name + */ + public CField(IASTName name) { + super(name); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CFunction.java new file mode 100644 index 00000000000..d65059cde53 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CFunction.java @@ -0,0 +1,86 @@ + +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IFunction; +import org.eclipse.cdt.core.dom.ast.IScope; + +/** + * Created on Nov 5, 2004 + * @author aniefer + */ +public class CFunction implements IFunction { + final private IASTFunctionDeclarator declarator; + final private IScope functionScope; + + public CFunction( IASTFunctionDeclarator declarator ){ + declarator = checkForDefinition( declarator ); + this.declarator = declarator; + this.functionScope = new CFunctionScope( this ); + } + + private IASTFunctionDeclarator checkForDefinition( IASTFunctionDeclarator declarator ){ + if( declarator.getParent() instanceof IASTFunctionDefinition ) + return declarator; + + IASTFunctionDeclarator decl = CVisitor.findDefinition( declarator ); + if( decl != null && decl != declarator ){ + declarator = decl; + ((CASTName)declarator.getName()).setBinding( this ); + } + return declarator; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IFunction#getParameters() + */ + public List getParameters() { + List params = declarator.getParameters(); + int size = params.size(); + List result = new ArrayList( size ); + if( size > 0 ){ + for( int i = 0; i < size; i++ ){ + IASTParameterDeclaration p = (IASTParameterDeclaration) params.get(i); + result.add( p.getDeclarator().getName().resolveBinding() ); + } + } + return result; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() + */ + public String getName() { + return declarator.getName().toString(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() + */ + public IScope getScope() { + return CVisitor.getContainingScope( (IASTDeclaration) declarator.getParent() ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IFunction#getFunctionScope() + */ + public IScope getFunctionScope() { + return functionScope; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CFunctionScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CFunctionScope.java new file mode 100644 index 00000000000..44e2076ec42 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CFunctionScope.java @@ -0,0 +1,43 @@ + +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IScope; + +/** + * Created on Nov 8, 2004 + * @author aniefer + */ +public class CFunctionScope implements IScope { + private final CFunction function; + + public CFunctionScope( CFunction function ){ + this.function = function; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IScope#getParent() + */ + public IScope getParent() { + return function.getScope(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String) + */ + public List find(String name) { + return null; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CParameter.java new file mode 100644 index 00000000000..f920292b325 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CParameter.java @@ -0,0 +1,72 @@ + +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IParameter; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; + +/** + * Created on Nov 5, 2004 + * @author aniefer + */ +public class CParameter implements IParameter { + final private IASTParameterDeclaration parameterDeclaration; + + public CParameter( IASTParameterDeclaration parameterDeclaration ){ + parameterDeclaration = checkForDefinition( parameterDeclaration ); + this.parameterDeclaration = parameterDeclaration; + } + + private IASTParameterDeclaration checkForDefinition( IASTParameterDeclaration paramDecl ){ + IASTFunctionDeclarator fnDtor = (IASTFunctionDeclarator) paramDecl.getParent(); + if( fnDtor.getParent() instanceof IASTFunctionDefinition ) + return paramDecl; + + IASTFunctionDeclarator fDef = CVisitor.findDefinition( fnDtor ); + if( fDef != null && fDef instanceof IASTFunctionDefinition ){ + int index = fnDtor.getParameters().indexOf( paramDecl ); + if( index >= 0 && index < fDef.getParameters().size() ) { + IASTParameterDeclaration pDef = (IASTParameterDeclaration) fDef.getParameters().get( index ); + ((CASTName)pDef.getDeclarator().getName()).setBinding( this ); + paramDecl = pDef; + } + } + return paramDecl; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IVariable#getType() + */ + public IType getType() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() + */ + public String getName() { + return parameterDeclaration.getDeclarator().getName().toString(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() + */ + public IScope getScope() { + return CVisitor.getContainingScope( parameterDeclaration ); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CStructure.java new file mode 100644 index 00000000000..54c5ea0df11 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CStructure.java @@ -0,0 +1,134 @@ + +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IField; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; + +/** + * Created on Nov 8, 2004 + * @author aniefer + */ +public class CStructure implements ICompositeType { + final private IASTDeclSpecifier declSpec; + + public CStructure( IASTDeclSpecifier declSpec ){ + declSpec = checkForDefinition( declSpec ); + this.declSpec = declSpec; + } + + private IASTDeclSpecifier checkForDefinition( IASTDeclSpecifier declSpec ){ + if( declSpec instanceof ICASTCompositeTypeSpecifier ) + return declSpec; + + IASTDeclSpecifier spec = CVisitor.findDefinition( (ICASTElaboratedTypeSpecifier) declSpec ); + if( spec != null && spec instanceof ICASTCompositeTypeSpecifier ){ + declSpec = spec; + ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) spec; + ((CASTName)compTypeSpec.getName()).setBinding( this ); + } + return declSpec; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() + */ + public String getName() { + if( declSpec instanceof ICASTCompositeTypeSpecifier ) + return ((ICASTCompositeTypeSpecifier)declSpec).getName().toString(); + else if( declSpec instanceof ICASTElaboratedTypeSpecifier ) + return ((ICASTElaboratedTypeSpecifier)declSpec).getName().toString(); + + return ""; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() + */ + public IScope getScope() { + return CVisitor.getContainingScope( declSpec ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.ICompositeType#getFields() + */ + public List getFields() { + if( !( declSpec instanceof ICASTCompositeTypeSpecifier ) ){ + //error + return null; + } + + ICASTCompositeTypeSpecifier compositeTypeSpec = (ICASTCompositeTypeSpecifier) declSpec; + List members = compositeTypeSpec.getMembers(); + int size = members.size(); + List fields = new ArrayList( size ); + if( size > 0 ){ + + for( int i = 0; i < size; i++ ){ + IASTNode node = (IASTNode) members.get(i); + if( node instanceof IASTSimpleDeclaration ){ + List declarators = ((IASTSimpleDeclaration)node).getDeclarators(); + for( int j = 0; j < declarators.size(); j++ ){ + IASTDeclarator declarator = (IASTDeclarator) declarators.get(i); + IBinding binding = declarator.getName().resolveBinding(); + if( binding != null ) + fields.add( binding ); + } + } + } + + } + return fields; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(org.eclipse.cdt.core.dom.ast.IASTName) + */ + public IField findField(String name) { + if( !( declSpec instanceof ICASTCompositeTypeSpecifier ) ){ + //error + return null; + } + + ICASTCompositeTypeSpecifier compositeTypeSpec = (ICASTCompositeTypeSpecifier) declSpec; + List members = compositeTypeSpec.getMembers(); + int size = members.size(); + if( size > 0 ){ + for( int i = 0; i < size; i++ ){ + IASTNode node = (IASTNode) members.get(i); + if( node instanceof IASTSimpleDeclaration ){ + List declarators = ((IASTSimpleDeclaration)node).getDeclarators(); + for( int j = 0; j < declarators.size(); j++ ){ + IASTDeclarator declarator = (IASTDeclarator) declarators.get(i); + if( name.equals( declarator.getName().toString() ) ){ + IBinding binding = declarator.getName().resolveBinding(); + if( binding instanceof IField ) + return (IField) binding; + } + } + } + } + } + return null; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CTypeDef.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CTypeDef.java new file mode 100644 index 00000000000..dffe5084710 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CTypeDef.java @@ -0,0 +1,65 @@ + +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; + +/** + * Created on Nov 8, 2004 + * @author aniefer + */ +public class CTypeDef implements ITypedef { + private final IASTName name; + + public CTypeDef( IASTName name ){ + this.name = name; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.ITypedef#getType() + */ + public IType getType() { + IASTDeclarator declarator = (IASTDeclarator) name.getParent(); + IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) declarator.getParent(); + + IASTDeclSpecifier declSpec = declaration.getDeclSpecifier(); + if( declSpec instanceof ICASTCompositeTypeSpecifier ){ + ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) declSpec; + return (IType) compTypeSpec.getName().resolveBinding(); + } + + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() + */ + public String getName() { + return name.toString(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() + */ + public IScope getScope() { + IASTDeclarator declarator = (IASTDeclarator) name.getParent(); + return CVisitor.getContainingScope( (IASTDeclaration) declarator.getParent() ); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CVariable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CVariable.java new file mode 100644 index 00000000000..0118b157181 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CVariable.java @@ -0,0 +1,67 @@ + +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2.c; + +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; + +/** + * Created on Nov 5, 2004 + * @author aniefer + */ +public class CVariable implements IVariable { + final IASTName name; + + public CVariable( IASTName name ){ + this.name = name; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IVariable#getType() + */ + public IType getType() { + IASTDeclarator declarator = (IASTDeclarator) name.getParent(); + IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) declarator.getParent(); + IASTDeclSpecifier declSpec = declaration.getDeclSpecifier(); + if( declSpec instanceof ICASTTypedefNameSpecifier ){ + ICASTTypedefNameSpecifier nameSpec = (ICASTTypedefNameSpecifier) declSpec; + return (IType) nameSpec.getName().resolveBinding(); + } else if( declSpec instanceof IASTElaboratedTypeSpecifier ){ + IASTElaboratedTypeSpecifier elabTypeSpec = (IASTElaboratedTypeSpecifier) declSpec; + return (IType) elabTypeSpec.getName().resolveBinding(); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() + */ + public String getName() { + return name.toString(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() + */ + public IScope getScope() { + IASTDeclarator declarator = (IASTDeclarator) name.getParent(); + return CVisitor.getContainingScope( (IASTDeclaration) declarator.getParent() ); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CVisitor.java new file mode 100644 index 00000000000..e9a7ca2ebc5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/CVisitor.java @@ -0,0 +1,588 @@ + +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTDoStatement; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionList; +import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; +import org.eclipse.cdt.core.dom.ast.IASTFieldReference; +import org.eclipse.cdt.core.dom.ast.IASTForStatement; +import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; +import org.eclipse.cdt.core.dom.ast.IASTIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTIfStatement; +import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTUnaryTypeIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.IFunction; +import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; +import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; +import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; + +/** + * Created on Nov 5, 2004 + * @author aniefer + */ +public class CVisitor { + + private static final int COMPLETE = 1; + private static final int CURRENT_SCOPE = 2; + + static protected void createBinding( CASTName name ){ + IBinding binding = null; + IASTNode parent = name.getParent(); + + if( parent instanceof CASTIdExpression ){ + binding = resolveBinding( parent ); + } else if( parent instanceof ICASTTypedefNameSpecifier ){ + binding = resolveBinding( parent ); + } else if( parent instanceof IASTFieldReference ){ + binding = findBinding( (IASTFieldReference) parent ); + } else if( parent instanceof CASTDeclarator ){ + binding = createBinding( (CASTDeclarator) parent, name ); + } else if( parent instanceof CASTCompositeTypeSpecifier ){ + binding = createBinding( (CASTCompositeTypeSpecifier) parent ); + } else if( parent instanceof ICASTElaboratedTypeSpecifier ){ + binding = createBinding( (ICASTElaboratedTypeSpecifier) parent ); + } + name.setBinding( binding ); + } + + private static IBinding createBinding( ICASTElaboratedTypeSpecifier elabTypeSpec ){ + IASTNode parent = elabTypeSpec.getParent(); + if( parent instanceof IASTSimpleDeclaration ){ + IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) parent; + if( declaration.getDeclarators().size() == 0 ){ + //forward declaration + IBinding binding = resolveBinding( elabTypeSpec, CURRENT_SCOPE ); + if( binding == null ) + binding = new CStructure( elabTypeSpec ); + return binding; + } + return resolveBinding( elabTypeSpec ); + } else if( parent instanceof IASTTypeId ){ + IASTNode blockItem = getContainingBlockItem( parent ); + return findBinding( blockItem, (CASTName) elabTypeSpec.getName(), COMPLETE ); + } + return null; + } + private static IBinding findBinding( IASTFieldReference fieldReference ){ + IASTExpression fieldOwner = fieldReference.getFieldOwner(); + ICompositeType compositeType = null; + if( fieldOwner instanceof IASTIdExpression ){ + IBinding binding = resolveBinding( fieldOwner ); + if( binding instanceof IVariable ){ + binding = ((IVariable)binding).getType(); + while( binding != null && binding instanceof ITypedef ) + binding = ((ITypedef)binding).getType(); + } + if( binding instanceof ICompositeType ) + compositeType = (ICompositeType) binding; + } else if( fieldOwner instanceof IASTUnaryTypeIdExpression ){ + IASTTypeId id = ((IASTUnaryTypeIdExpression)fieldOwner).getTypeId(); + IBinding binding = resolveBinding( id ); + if( binding != null && binding instanceof ICompositeType ){ + compositeType = (ICompositeType) binding; + } + } + + IBinding binding = null; + if( compositeType != null ){ + binding = compositeType.findField( fieldReference.getFieldName().toString() ); + } + return binding; + } + + /** + * @param parent + * @return + */ + private static IBinding createBinding(IASTDeclarator declarator, CASTName name) { + IBinding binding = null; + IASTNode parent = declarator.getParent(); + if( declarator instanceof IASTFunctionDeclarator ){ + binding = resolveBinding( parent, CURRENT_SCOPE ); + if( binding == null ) + binding = new CFunction( (IASTFunctionDeclarator) declarator ); + } else if( parent instanceof IASTSimpleDeclaration ){ + binding = createBinding( (IASTSimpleDeclaration) parent, name ); + } else if( parent instanceof IASTParameterDeclaration ){ + binding = createBinding( (IASTParameterDeclaration ) parent ); + } + + return binding; + } + + private static IBinding createBinding( ICASTCompositeTypeSpecifier compositeTypeSpec ){ + return new CStructure( compositeTypeSpec ); + } + + + /** + * @param parent + * @return + */ + private static IBinding createBinding(IASTSimpleDeclaration simpleDeclaration, IASTName name) { + IBinding binding = null; + if( simpleDeclaration.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ){ + binding = new CTypeDef( name ); + } else if( simpleDeclaration.getParent() instanceof ICASTCompositeTypeSpecifier ){ + binding = new CField( name ); + } else { + binding = new CVariable( name ); + } + + return binding; + } + + private static IBinding createBinding( IASTParameterDeclaration parameterDeclaration ){ + IBinding binding = resolveBinding( parameterDeclaration, CURRENT_SCOPE ); + if( binding == null ) + binding = new CParameter( parameterDeclaration ); + return binding; + } + + protected static IBinding resolveBinding( IASTNode node ){ + return resolveBinding( node, COMPLETE ); + } + protected static IBinding resolveBinding( IASTNode node, int scopeDepth ){ + if( node instanceof IASTFunctionDefinition ){ + IASTFunctionDefinition functionDef = (IASTFunctionDefinition) node; + IASTFunctionDeclarator functionDeclartor = functionDef.getDeclarator(); + IASTName name = functionDeclartor.getName(); + IASTNode blockItem = getContainingBlockItem( node ); + return findBinding( blockItem, (CASTName) name, scopeDepth ); + } else if( node instanceof IASTIdExpression ){ + IASTNode blockItem = getContainingBlockItem( node ); + return findBinding( blockItem, (CASTName) ((IASTIdExpression)node).getName(), scopeDepth ); + } else if( node instanceof ICASTTypedefNameSpecifier ){ + IASTNode blockItem = getContainingBlockItem( node ); + return findBinding( blockItem, (CASTName) ((ICASTTypedefNameSpecifier)node).getName(), scopeDepth ); + } else if( node instanceof ICASTElaboratedTypeSpecifier ){ + IASTNode blockItem = getContainingBlockItem( node ); + return findBinding( blockItem, (CASTName) ((ICASTElaboratedTypeSpecifier)node).getName(), scopeDepth ); + } else if( node instanceof ICASTCompositeTypeSpecifier ){ + IASTNode blockItem = getContainingBlockItem( node ); + return findBinding( blockItem, (CASTName) ((ICASTCompositeTypeSpecifier)node).getName(), scopeDepth ); + } else if( node instanceof IASTParameterDeclaration ){ + IASTParameterDeclaration param = (IASTParameterDeclaration) node; + IASTFunctionDeclarator fDtor = (IASTFunctionDeclarator) param.getParent(); + if( fDtor.getParent() instanceof IASTFunctionDefinition ){ + return null; + } + IASTFunctionDeclarator fdef = findDefinition( fDtor ); + if( fdef != null ){ + int index = fDtor.getParameters().indexOf( param ); + if( index >= 0 && index < fdef.getParameters().size() ){ + IASTParameterDeclaration pdef = (IASTParameterDeclaration) fdef.getParameters().get( index ); + return pdef.getDeclarator().getName().resolveBinding(); + } + } + } else if( node instanceof IASTTypeId ){ + IASTTypeId typeId = (IASTTypeId) node; + IASTDeclSpecifier declSpec = typeId.getDeclSpecifier(); + IASTName name = null; + if( declSpec instanceof ICASTElaboratedTypeSpecifier ){ + name = ((ICASTElaboratedTypeSpecifier)declSpec).getName(); + } else if( declSpec instanceof ICASTCompositeTypeSpecifier ){ + name = ((ICASTCompositeTypeSpecifier)declSpec).getName(); + } + if( name != null ){ + return name.resolveBinding(); + } + } + return null; + } + + /** + * @param declaration + * @return + */ + public static IScope getContainingScope(IASTDeclaration declaration) { + IASTNode parent = declaration.getParent(); + if( parent instanceof IASTTranslationUnit ){ + return ((IASTTranslationUnit)parent).getScope(); + } else if( parent instanceof IASTDeclarationStatement ){ + return getContainingScope( (IASTStatement) parent ); + } + + return null; + } + + public static IScope getContainingScope( IASTStatement statement ){ + IASTNode parent = statement.getParent(); + if( parent instanceof IASTCompoundStatement ){ + return getContainingScope( (IASTStatement)parent ); + } else if( parent instanceof IASTFunctionDefinition ){ + IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent ).getDeclarator(); + IFunction function = (IFunction) fnDeclarator.getName().resolveBinding(); + return function.getFunctionScope(); + } + + return null; + } + + public static IScope getContainingScope( IASTDeclSpecifier compTypeSpec ){ + return null; + } + + /** + * @param parameterDeclaration + * @return + */ + public static IScope getContainingScope(IASTParameterDeclaration parameterDeclaration) { + IASTNode parent = parameterDeclaration.getParent(); + if( parent instanceof IASTFunctionDeclarator ){ + IASTFunctionDeclarator functionDeclarator = (IASTFunctionDeclarator) parent; + IASTName fnName = functionDeclarator.getName(); + IFunction function = (IFunction) fnName.resolveBinding(); + return function.getFunctionScope(); + } + + return null; + } + + private static IASTNode getContainingBlockItem( IASTNode node ){ + IASTNode parent = node.getParent(); + if( parent instanceof IASTDeclaration ){ + IASTNode p = parent.getParent(); + if( p instanceof IASTDeclarationStatement ) + return p; + return parent; + } + //if parent is something that can contain a declaration + else if ( parent instanceof IASTCompoundStatement || + parent instanceof IASTTranslationUnit || + parent instanceof IASTForStatement ) + { + return node; + } + + return getContainingBlockItem( parent ); + } + + protected static IBinding findBinding( IASTNode blockItem, CASTName name, int scopeDepth ){ + IBinding binding = null; + while( blockItem != null ){ + + IASTNode parent = blockItem.getParent(); + List list = null; + if( parent instanceof IASTCompoundStatement ){ + IASTCompoundStatement compound = (IASTCompoundStatement) parent; + list = compound.getStatements(); + } else if ( parent instanceof IASTTranslationUnit ){ + IASTTranslationUnit translation = (IASTTranslationUnit) parent; + list = translation.getDeclarations(); + } + + if( list != null ){ + for( int i = 0; i < list.size(); i++ ){ + IASTNode node = (IASTNode) list.get(i); + if( node == blockItem ) + break; + if( node instanceof IASTDeclarationStatement ){ + IASTDeclarationStatement declStatement = (IASTDeclarationStatement) node; + binding = checkForBinding( declStatement.getDeclaration(), name ); + } else if( node instanceof IASTDeclaration ){ + binding = checkForBinding( (IASTDeclaration) node, name ); + } + if( binding != null ) + return binding; + } + } else { + //check the parent + if( parent instanceof IASTDeclaration ){ + binding = checkForBinding( (IASTDeclaration) parent, name ); + if( binding != null ) + return binding; + } else if( parent instanceof IASTStatement ){ + binding = checkForBinding( (IASTStatement) parent, name ); + if( binding != null ) + return binding; + } + } + if( scopeDepth == COMPLETE ) + blockItem = parent; + else + blockItem = null; + } + + return null; + } + + private static IBinding checkForBinding( IASTDeclaration declaration, CASTName name ){ + if( declaration instanceof IASTSimpleDeclaration ){ + IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration; + List declarators = simpleDeclaration.getDeclarators(); + int size = declarators.size(); + + for( int i = 0; i < size; i++ ){ + IASTDeclarator declarator = (IASTDeclarator) declarators.get(i); + CASTName declaratorName = (CASTName) declarator.getName(); + if( CharArrayUtils.equals( declaratorName.toCharArray(), name.toCharArray() ) ){ + return declaratorName.resolveBinding(); + } + } + + //decl spec + IASTDeclSpecifier declSpec = simpleDeclaration.getDeclSpecifier(); + if( declSpec instanceof ICASTElaboratedTypeSpecifier ){ + CASTName elabName = (CASTName) ((ICASTElaboratedTypeSpecifier)declSpec).getName(); + if( CharArrayUtils.equals( elabName.toCharArray(), name.toCharArray() ) ){ + return elabName.resolveBinding(); + } + } else if( declSpec instanceof ICASTCompositeTypeSpecifier ){ + CASTName compName = (CASTName) ((ICASTCompositeTypeSpecifier)declSpec).getName(); + if( CharArrayUtils.equals( compName.toCharArray(), name.toCharArray() ) ){ + return compName.resolveBinding(); + } + } + } else if( declaration instanceof IASTFunctionDefinition ){ + IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration; + IASTFunctionDeclarator declarator = functionDef.getDeclarator(); + + //check the function itself + CASTName declName = (CASTName) declarator.getName(); + if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){ + return declName.resolveBinding(); + } + //check the parameters + List parameters = declarator.getParameters(); + for( int i = 0; i < parameters.size(); i++ ){ + IASTParameterDeclaration parameterDeclaration = (IASTParameterDeclaration) parameters.get(i); + declName = (CASTName) parameterDeclaration.getDeclarator().getName(); + if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){ + return declName.resolveBinding(); + } + } + } + return null; + } + + private static IBinding checkForBinding( IASTStatement statement, CASTName name ){ + if( statement instanceof IASTDeclarationStatement ){ + return checkForBinding( ((IASTDeclarationStatement)statement).getDeclaration(), name ); + } else if( statement instanceof IASTForStatement ){ + IASTForStatement forStatement = (IASTForStatement) statement; + if( forStatement.getInitDeclaration() != null ){ + return checkForBinding( forStatement.getInitDeclaration(), name ); + } + } + return null; + } + + protected static IASTFunctionDeclarator findDefinition( IASTFunctionDeclarator declarator ){ + return (IASTFunctionDeclarator) findDefinition( declarator, declarator.getName().toString() ); + } + protected static IASTDeclSpecifier findDefinition( ICASTElaboratedTypeSpecifier declSpec ){ + String elabName = declSpec.getName().toString(); + return (IASTDeclSpecifier) findDefinition(declSpec, elabName); + } + + private static IASTNode findDefinition(IASTNode decl, String declName) { + IASTNode blockItem = getContainingBlockItem( decl ); + IASTNode parent = blockItem.getParent(); + List list = null; + if( parent instanceof IASTCompoundStatement ){ + IASTCompoundStatement compound = (IASTCompoundStatement) parent; + list = compound.getStatements(); + } else if ( parent instanceof IASTTranslationUnit ){ + IASTTranslationUnit translation = (IASTTranslationUnit) parent; + list = translation.getDeclarations(); + } + if( list != null ){ + for( int i = 0; i < list.size(); i++ ){ + IASTNode node = (IASTNode) list.get(i); + if( node == blockItem ) + continue; + if( node instanceof IASTDeclarationStatement ){ + node = ((IASTDeclarationStatement) node).getDeclaration(); + } + + if( node instanceof IASTFunctionDefinition && decl instanceof IASTFunctionDeclarator ){ + IASTFunctionDeclarator dtor = ((IASTFunctionDefinition) node).getDeclarator(); + IASTName name = dtor.getName(); + if( name.toString().equals( declName )){ + return dtor; + } + } else if( node instanceof IASTSimpleDeclaration && decl instanceof ICASTElaboratedTypeSpecifier){ + IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) node; + if( simpleDecl.getDeclSpecifier() instanceof ICASTCompositeTypeSpecifier ){ + ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) simpleDecl.getDeclSpecifier(); + IASTName name = compTypeSpec.getName(); + if( name.toString().equals( declName ) ){ + return compTypeSpec; + } + } + } + } + } + return null; + } + + public static void clearBindings( IASTTranslationUnit tu ){ + List decls = tu.getDeclarations(); + for( int i = 0; i < decls.size(); i++ ){ + clearBindings( (IASTDeclaration) decls.get(i) ); + } + } + private static void clearBindings( IASTDeclaration declaration ){ + if( declaration instanceof IASTSimpleDeclaration ){ + IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration) declaration; + clearBindings( simpleDecl.getDeclSpecifier() ); + List list = simpleDecl.getDeclarators(); + for( int i = 0; i < list.size(); i++ ){ + clearBindings( (IASTDeclarator) list.get(i) ); + } + } else if( declaration instanceof IASTFunctionDefinition ){ + IASTFunctionDefinition fnDef = (IASTFunctionDefinition) declaration; + clearBindings( fnDef.getDeclSpecifier() ); + clearBindings( fnDef.getDeclarator() ); + clearBindings( fnDef.getBody() ); + } + } + private static void clearBindings( IASTDeclarator declarator ){ + ((CASTName)declarator.getName()).setBinding( null ); + + if( declarator.getNestedDeclarator() != null ) + clearBindings( declarator.getNestedDeclarator() ); + + //TODO: if( declarator.getInitializer() != null ) + + if( declarator instanceof IASTFunctionDeclarator ){ + List list = ((IASTFunctionDeclarator)declarator).getParameters(); + for( int i = 0; i < list.size(); i++ ){ + IASTParameterDeclaration param = (IASTParameterDeclaration) list.get(i); + clearBindings( param.getDeclarator() ); + } + } + } + private static void clearBindings( IASTDeclSpecifier declSpec ){ + if( declSpec instanceof ICASTCompositeTypeSpecifier ){ + ICASTCompositeTypeSpecifier compTypeSpec = (ICASTCompositeTypeSpecifier) declSpec; + ((CASTName) compTypeSpec.getName()).setBinding( null ); + + List list = compTypeSpec.getMembers(); + for( int i = 0; i < list.size(); i++ ){ + clearBindings( (IASTDeclaration) list.get(i) ); + } + } + } + private static void clearBindings( IASTStatement statement ){ + if( statement instanceof IASTCompoundStatement ){ + List list = ((IASTCompoundStatement) statement).getStatements(); + for( int i = 0; i < list.size(); i++ ){ + clearBindings( (IASTStatement) list.get(i) ); + } + } else if( statement instanceof IASTDeclarationStatement ){ + clearBindings( ((IASTDeclarationStatement)statement).getDeclaration() ); + } else if( statement instanceof IASTExpressionStatement ){ + clearBindings( ((IASTExpressionStatement)statement).getExpression() ); + } else if( statement instanceof IASTCaseStatement ){ + clearBindings( ((IASTCaseStatement)statement).getExpression() ); + } else if( statement instanceof IASTDoStatement ){ + clearBindings( ((IASTDoStatement)statement).getBody() ); + } else if( statement instanceof IASTGotoStatement ){ + ((CASTName) ((IASTGotoStatement)statement).getName()).setBinding( null ); + } else if( statement instanceof IASTIfStatement ){ + clearBindings( ((IASTIfStatement) statement ).getCondition() ); + clearBindings( ((IASTIfStatement) statement ).getThenClause() ); + clearBindings( ((IASTIfStatement) statement ).getElseClause() ); + } else if( statement instanceof IASTLabelStatement ){ + ((CASTName) ((IASTLabelStatement)statement).getName()).setBinding( null ); + } else if( statement instanceof IASTReturnStatement ){ + clearBindings( ((IASTReturnStatement) statement ).getReturnValue() ); + } else if( statement instanceof IASTSwitchStatement ){ + clearBindings( ((IASTSwitchStatement) statement ).getController() ); + clearBindings( ((IASTSwitchStatement) statement ).getBody() ); + } else if( statement instanceof IASTWhileStatement ){ + clearBindings( ((IASTWhileStatement) statement ).getCondition() ); + clearBindings( ((IASTWhileStatement) statement ).getBody() ); + } + } + private static void clearBindings( IASTTypeId typeId ){ + clearBindings( typeId.getAbstractDeclarator() ); + clearBindings( typeId.getDeclSpecifier() ); + } + private static void clearBindings( IASTExpression expression ){ + if( expression instanceof IASTArraySubscriptExpression ){ + clearBindings( ((IASTArraySubscriptExpression)expression).getArrayExpression() ); + clearBindings( ((IASTArraySubscriptExpression)expression).getSubscriptExpression() ); + } else if( expression instanceof IASTBinaryExpression ){ + clearBindings( ((IASTBinaryExpression)expression).getOperand1() ); + clearBindings( ((IASTBinaryExpression)expression).getOperand2() ); + } else if( expression instanceof IASTConditionalExpression){ + clearBindings( ((IASTConditionalExpression)expression).getLogicalConditionExpression() ); + clearBindings( ((IASTConditionalExpression)expression).getNegativeResultExpression() ); + clearBindings( ((IASTConditionalExpression)expression).getPositiveResultExpression() ); + } else if( expression instanceof IASTExpressionList ){ + List list = ((IASTExpressionList)expression).getExpressions(); + for( int i = 0; i < list.size(); i++){ + clearBindings( (IASTExpression) list.get(i) ); + } + } else if( expression instanceof IASTFieldReference ){ + clearBindings( ((IASTFieldReference)expression).getFieldOwner() ); + ((CASTName) ((IASTFieldReference)expression).getFieldName()).setBinding( null ); + } else if( expression instanceof IASTFunctionCallExpression ){ + clearBindings( ((IASTFunctionCallExpression)expression).getFunctionNameExpression() ); + clearBindings( ((IASTFunctionCallExpression)expression).getParameterExpression() ); + } else if( expression instanceof IASTIdExpression ){ + ((CASTName) ((IASTIdExpression)expression).getName()).setBinding( null ); + } else if( expression instanceof IASTTypeIdExpression ){ + clearBindings( ((IASTTypeIdExpression)expression).getTypeId() ); + } else if( expression instanceof IASTUnaryExpression ){ + clearBindings( ((IASTUnaryExpression)expression).getOperand() ); + } else if( expression instanceof IASTUnaryTypeIdExpression ){ + clearBindings( ((IASTUnaryTypeIdExpression)expression).getOperand() ); + clearBindings( ((IASTUnaryTypeIdExpression)expression).getTypeId() ); + } else if( expression instanceof ICASTTypeIdInitializerExpression ){ + clearBindings( ((ICASTTypeIdInitializerExpression)expression).getTypeId() ); + //TODO: ((ICASTTypeIdInitializerExpression)expression).getInitializer(); + } else if( expression instanceof IGNUASTCompoundStatementExpression ){ + clearBindings( ((IGNUASTCompoundStatementExpression)expression).getCompoundStatement() ); + } + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GCCParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GCCParserExtensionConfiguration.java new file mode 100644 index 00000000000..7c7e004cab5 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GCCParserExtensionConfiguration.java @@ -0,0 +1,46 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +/** + * @author jcamelon + */ +public class GCCParserExtensionConfiguration implements + ICParserExtensionConfiguration { + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportStatementsInExpressions() + */ + public boolean supportStatementsInExpressions() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportGCCStyleDesignators() + */ + public boolean supportGCCStyleDesignators() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportTypeofUnaryExpressions() + */ + public boolean supportTypeofUnaryExpressions() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.c.ICParserExtensionConfiguration#supportAlignOfUnaryExpression() + */ + public boolean supportAlignOfUnaryExpression() { + return true; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GNUCSourceParser.java new file mode 100644 index 00000000000..52f6acf1b4b --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/GNUCSourceParser.java @@ -0,0 +1,2385 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; +import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression; +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; +import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; +import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; +import org.eclipse.cdt.core.dom.ast.IASTContinueStatement; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; +import org.eclipse.cdt.core.dom.ast.IASTDoStatement; +import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionList; +import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; +import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFieldReference; +import org.eclipse.cdt.core.dom.ast.IASTForStatement; +import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; +import org.eclipse.cdt.core.dom.ast.IASTIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTIfStatement; +import org.eclipse.cdt.core.dom.ast.IASTInitializer; +import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; +import org.eclipse.cdt.core.dom.ast.IASTInitializerList; +import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; +import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTTypedefNameSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTUnaryTypeIdExpression; +import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.core.dom.ast.c.IASTNullStatement; +import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator; +import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator; +import org.eclipse.cdt.core.dom.ast.c.ICASTPointer; +import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; +import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; +import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; +import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator; +import org.eclipse.cdt.core.parser.BacktrackException; +import org.eclipse.cdt.core.parser.EndOfFileException; +import org.eclipse.cdt.core.parser.IGCCToken; +import org.eclipse.cdt.core.parser.IParserLogService; +import org.eclipse.cdt.core.parser.IScanner; +import org.eclipse.cdt.core.parser.IToken; +import org.eclipse.cdt.core.parser.ITokenDuple; +import org.eclipse.cdt.core.parser.ParseError; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.internal.core.parser.token.TokenFactory; +import org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser; +import org.eclipse.cdt.internal.core.parser2.cpp.IProblemRequestor; + +/** + * @author jcamelon + */ +public class GNUCSourceParser extends AbstractGNUSourceCodeParser { + + + private final boolean supportGCCStyleDesignators; + + private static final int DEFAULT_DECLARATOR_LIST_SIZE = 4; + + /** + * @param scanner + * @param logService + * @param parserMode + * @param callback + */ + public GNUCSourceParser(IScanner scanner, ParserMode parserMode, + IProblemRequestor callback, IParserLogService logService, + ICParserExtensionConfiguration config) { + super(scanner, logService, parserMode, callback, config + .supportStatementsInExpressions(), config + .supportTypeofUnaryExpressions(), config + .supportAlignOfUnaryExpression()); + supportGCCStyleDesignators = config.supportGCCStyleDesignators(); + } + + /** + * @param d + */ + protected void throwAwayMarksForInitializerClause() { + simpleDeclarationMark = null; + } + + protected IASTInitializer optionalCInitializer() throws EndOfFileException, + BacktrackException { + if (LT(1) == IToken.tASSIGN) { + consume(IToken.tASSIGN); + throwAwayMarksForInitializerClause(); + return cInitializerClause(Collections.EMPTY_LIST); + } + return null; + } + + /** + * @param scope + * @return + */ + protected IASTInitializer cInitializerClause(List designators) + 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).getOffset(); + IASTInitializerList result = createInitializerList(); + ((CASTNode)result).setOffset( startingOffset ); + for (;;) { + int checkHashcode = LA(1).hashCode(); + // required at least one initializer list + // get designator list + List newDesignators = designatorList(); + if (newDesignators.size() != 0) + if (LT(1) == IToken.tASSIGN) + consume(IToken.tASSIGN); + IASTInitializer initializer = cInitializerClause(newDesignators); + result.addInitializer(initializer); + initializer.setParent( result ); + initializer.setPropertyInParent( IASTInitializerList.NESTED_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 result; + } + // if we get this far, it means that we have not yet succeeded + // try this now instead + // assignmentExpression + try { + IASTExpression assignmentExpression = assignmentExpression(); + IASTInitializerExpression result = createInitializerExpression(); + result.setExpression(assignmentExpression); + ((CASTNode)result).setOffset(((CASTNode)assignmentExpression).getOffset()); + assignmentExpression.setParent(result); + assignmentExpression + .setPropertyInParent(IASTInitializerExpression.INITIALIZER_EXPRESSION); + return result; + } catch (BacktrackException b) { + // do nothing + } + int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0; + throwBacktrack(startingOffset, endOffset, line, fn); + return null; + } + + /** + * @return + */ + protected IASTInitializerList createInitializerList() { + return new CASTInitializerList(); + } + + /** + * @return + */ + protected IASTInitializerExpression createInitializerExpression() { + return new CASTInitializerExpresion(); + } + + protected List designatorList() throws EndOfFileException, + BacktrackException { + //designated initializers for C + List designatorList = Collections.EMPTY_LIST; + + if (LT(1) == IToken.tDOT || LT(1) == IToken.tLBRACKET) { + while (LT(1) == IToken.tDOT || LT(1) == IToken.tLBRACKET) { + if (LT(1) == IToken.tDOT) { + int offset = consume(IToken.tDOT).getOffset(); + IToken id = identifier(); + ICASTFieldDesignator designator = createFieldDesignator(); + ((CASTNode)designator).setOffset( offset ); + IASTName n = createName( id ); + designator.setName( n ); + n.setParent( designator ); + n.setPropertyInParent( ICASTFieldDesignator.FIELD_NAME ); + if( designatorList == Collections.EMPTY_LIST ) + designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); + designatorList.add( designator ); + } else if (LT(1) == IToken.tLBRACKET) { + IToken mark = consume(IToken.tLBRACKET); + int offset = mark.getOffset(); + IASTExpression constantExpression = expression(); + if (LT(1) == IToken.tRBRACKET) { + consume(IToken.tRBRACKET); + ICASTArrayDesignator designator = createArrayDesignator(); + ((CASTNode)designator).setOffset( offset ); + designator.setSubscriptExpression( constantExpression ); + constantExpression.setParent( designator ); + constantExpression.setPropertyInParent( ICASTArrayDesignator.SUBSCRIPT_EXPRESSION ); + if( designatorList == Collections.EMPTY_LIST ) + designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); + designatorList.add( designator ); + continue; + } + backup(mark); + if (supportGCCStyleDesignators ) { + int startOffset = consume(IToken.tLBRACKET).getOffset(); + IASTExpression constantExpression1 = expression(); + consume(IToken.tELLIPSIS); + IASTExpression constantExpression2 = expression(); + consume(IToken.tRBRACKET); + IGCCASTArrayRangeDesignator designator = createArrayRangeDesignator(); + ((CASTNode)designator).setOffset( startOffset ); + designator.setRangeFloor( constantExpression1 ); + constantExpression1.setParent( designator ); + constantExpression1.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_FLOOR_EXPRESSION ); + designator.setRangeCeiling( constantExpression2 ); + constantExpression2.setParent( designator ); + constantExpression2.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION ); + if( designatorList == Collections.EMPTY_LIST ) + designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); + designatorList.add( designator ); + } + } else if ( supportGCCStyleDesignators && LT(1) == IToken.tIDENTIFIER ) + { + IToken identifier = identifier(); + consume(IToken.tCOLON); + ICASTFieldDesignator designator = createFieldDesignator(); + ((CASTNode)designator).setOffset( identifier.getOffset() ); + IASTName n = createName( identifier ); + designator.setName( n ); + n.setParent( designator ); + n.setPropertyInParent( ICASTFieldDesignator.FIELD_NAME ); + if( designatorList == Collections.EMPTY_LIST ) + designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); + designatorList.add( designator ); + } + } + } else { + if (supportGCCStyleDesignators + && (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tLBRACKET)) { + + if (LT(1) == IToken.tIDENTIFIER) { + IToken identifier = identifier(); + consume(IToken.tCOLON); + ICASTFieldDesignator designator = createFieldDesignator(); + ((CASTNode)designator).setOffset( identifier.getOffset() ); + IASTName n = createName( identifier ); + designator.setName( n ); + n.setParent( designator ); + n.setPropertyInParent( ICASTFieldDesignator.FIELD_NAME ); + if( designatorList == Collections.EMPTY_LIST ) + designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); + designatorList.add( designator ); + } else if (LT(1) == IToken.tLBRACKET) { + int startOffset = consume(IToken.tLBRACKET).getOffset(); + IASTExpression constantExpression1 = expression(); + consume(IToken.tELLIPSIS); + IASTExpression constantExpression2 = expression(); + consume(IToken.tRBRACKET); + IGCCASTArrayRangeDesignator designator = createArrayRangeDesignator(); + ((CASTNode)designator).setOffset( startOffset ); + designator.setRangeFloor( constantExpression1 ); + constantExpression1.setParent( designator ); + constantExpression1.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_FLOOR_EXPRESSION ); + designator.setRangeCeiling( constantExpression2 ); + constantExpression2.setParent( designator ); + constantExpression2.setPropertyInParent( IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION ); + if( designatorList == Collections.EMPTY_LIST ) + designatorList = new ArrayList( DEFAULT_DESIGNATOR_LIST_SIZE ); + designatorList.add( designator ); + } + } + } + return designatorList; + } + + /** + * @return + */ + protected IGCCASTArrayRangeDesignator createArrayRangeDesignator() { + return new CASTArrayRangeDesignator(); + } + + /** + * @return + */ + protected ICASTArrayDesignator createArrayDesignator() { + return new CASTArrayDesignator(); + } + + /** + * @return + */ + protected ICASTFieldDesignator createFieldDesignator() { + return new CASTFieldDesignator(); + } + + protected IASTDeclaration declaration() throws EndOfFileException, + BacktrackException { + switch (LT(1)) { + case IToken.t_asm: + IToken first = consume(IToken.t_asm); + consume(IToken.tLPAREN); + String assembly = consume(IToken.tSTRING).getImage(); + consume(IToken.tRPAREN); + consume(IToken.tSEMI); + cleanupLastToken(); + return buildASMDirective( first.getOffset(), assembly ); + default: + IASTDeclaration d = simpleDeclaration(); + cleanupLastToken(); + return d; + } + + } + + /** + * @param offset + * @param assembly + * @return + */ + protected IASTASMDeclaration buildASMDirective(int offset, String assembly) { + IASTASMDeclaration result = createASMDirective(); + ((CASTNode)result).setOffset( offset ); + result.setAssembly( assembly ); + return result; + } + + /** + * @return + */ + protected IASTASMDeclaration createASMDirective() { + return new CASTASMDeclaration(); + } + + /** + * @throws BacktrackException + * @throws EndOfFileException + */ + protected IASTDeclaration simpleDeclaration() throws BacktrackException, + EndOfFileException { + IToken firstToken = LA(1); + int firstOffset = firstToken.getOffset(); + char[] fn = firstToken.getFilename(); + if (firstToken.getType() == IToken.tLBRACE) + throwBacktrack(firstToken.getOffset(), firstToken.getEndOffset(), + firstToken.getLineNumber(), firstToken.getFilename()); + + firstToken = null; // necessary for scalability + + IASTDeclSpecifier declSpec = declSpecifierSeq(false); + + List declarators = Collections.EMPTY_LIST; + if (LT(1) != IToken.tSEMI) { + declarators = new ArrayList(DEFAULT_DECLARATOR_LIST_SIZE); + declarators.add(initDeclarator()); + + while (LT(1) == IToken.tCOMMA) { + consume(IToken.tCOMMA); + declarators.add(initDeclarator()); + } + } + + boolean hasFunctionBody = false; + boolean hasFunctionTryBlock = false; + boolean consumedSemi = false; + + switch (LT(1)) { + case IToken.tSEMI: + consume(IToken.tSEMI); + consumedSemi = true; + break; + case IToken.tLBRACE: + break; + default: + throwBacktrack(firstOffset, LA(1).getEndOffset(), LA(1) + .getLineNumber(), fn); + } + + if (!consumedSemi) { + if (LT(1) == IToken.tLBRACE) { + hasFunctionBody = true; + } + + if (hasFunctionTryBlock && !hasFunctionBody) + throwBacktrack(firstOffset, LA(1).getEndOffset(), LA(1) + .getLineNumber(), fn); + } + + if (hasFunctionBody) { + if (declarators.size() != 1) + throwBacktrack(firstOffset, LA(1).getEndOffset(), LA(1) + .getLineNumber(), fn); + + IASTDeclarator declarator = (IASTDeclarator) declarators.get(0); + if (!(declarator instanceof IASTFunctionDeclarator)) + throwBacktrack(firstOffset, LA(1).getEndOffset(), LA(1) + .getLineNumber(), fn); + + IASTFunctionDefinition funcDefinition = createFunctionDefinition(); + ((CASTNode)funcDefinition).setOffset(firstOffset); + funcDefinition.setDeclSpecifier(declSpec); + declSpec.setParent(funcDefinition); + declSpec.setPropertyInParent(IASTFunctionDefinition.DECL_SPECIFIER); + + funcDefinition.setDeclarator((IASTFunctionDeclarator) declarator); + declarator.setParent(funcDefinition); + declarator.setPropertyInParent(IASTFunctionDefinition.DECLARATOR); + + IASTStatement s = handleFunctionBody(); + if (s != null) { + funcDefinition.setBody(s); + s.setParent(funcDefinition); + s.setPropertyInParent(IASTFunctionDefinition.FUNCTION_BODY); + } + return funcDefinition; + } + + IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration(); + ((CASTNode)simpleDeclaration).setOffset(firstOffset); + simpleDeclaration.setDeclSpecifier(declSpec); + declSpec.setParent(simpleDeclaration); + declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER); + + for (int i = 0; i < declarators.size(); ++i) { + IASTDeclarator declarator = (IASTDeclarator) declarators.get(i); + simpleDeclaration.addDeclarator(declarator); + declarator.setParent(simpleDeclaration); + declarator.setPropertyInParent(IASTSimpleDeclaration.DECLARATOR); + } + return simpleDeclaration; + } + + /** + * @return + */ + protected IASTFunctionDefinition createFunctionDefinition() { + return new CASTFunctionDefinition(); + } + + /** + * @return + */ + protected CASTSimpleDeclaration createSimpleDeclaration() { + return new CASTSimpleDeclaration(); + } + + protected CASTTranslationUnit translationUnit; + + private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4; + + private static final int DEFAULT_PARAMETERS_LIST_SIZE = 4; + + protected CASTTranslationUnit createTranslationUnit() { + CASTTranslationUnit t = new CASTTranslationUnit(); + t.setOffset(0); + t.setParent(null); + t.setPropertyInParent(null); + return t; + } + + /** + * This is the top-level entry point into the ANSI C++ grammar. + * + * translationUnit : (declaration)* + */ + protected void translationUnit() { + try { + translationUnit = createTranslationUnit(); + } catch (Exception e2) { + logException("translationUnit::createCompilationUnit()", e2); //$NON-NLS-1$ + return; + } + + int lastBacktrack = -1; + while (true) { + try { + int checkOffset = LA(1).hashCode(); + IASTDeclaration d = declaration(); + d.setParent(translationUnit); + d.setPropertyInParent(IASTTranslationUnit.OWNED_DECLARATION); + translationUnit.addDeclaration(d); + 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) { + //nothing + } + } catch (ParseError perr) { + throw perr; + } catch (Throwable e) { + logThrowable("translationUnit", e); //$NON-NLS-1$ + try { + failParseWithErrorHandling(); + } catch (EndOfFileException e3) { + //break; + } + } + } + // compilationUnit.exitScope( requestor ); + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression assignmentExpression() throws EndOfFileException, + BacktrackException { + IASTExpression conditionalExpression = conditionalExpression(); + // if the condition not taken, try assignment operators + if (conditionalExpression != null && conditionalExpression instanceof IASTConditionalExpression ) //&& + return conditionalExpression; + switch (LT(1)) { + case IToken.tASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_assign, conditionalExpression); + case IToken.tSTARASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_multiplyAssign, conditionalExpression); + case IToken.tDIVASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_divideAssign, conditionalExpression); + case IToken.tMODASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_moduloAssign, conditionalExpression); + case IToken.tPLUSASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_plusAssign, conditionalExpression); + case IToken.tMINUSASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_minusAssign, conditionalExpression); + case IToken.tSHIFTRASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_shiftRightAssign, conditionalExpression); + case IToken.tSHIFTLASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_shiftLeftAssign, conditionalExpression); + case IToken.tAMPERASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_binaryAndAssign, conditionalExpression); + case IToken.tXORASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_binaryXorAssign, conditionalExpression); + case IToken.tBITORASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_binaryOrAssign, conditionalExpression); + } + return conditionalExpression; + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression relationalExpression() throws BacktrackException, + EndOfFileException { + + IASTExpression firstExpression = shiftExpression(); + for (;;) { + switch (LT(1)) { + case IToken.tGT: + case IToken.tLT: + case IToken.tLTEQUAL: + case IToken.tGTEQUAL: + int t = consume().getType(); + IASTExpression secondExpression = shiftExpression(); + int operator = 0; + switch (t) { + case IToken.tGT: + operator = IASTBinaryExpression.op_greaterThan; + break; + case IToken.tLT: + operator = IASTBinaryExpression.op_lessThan; + break; + case IToken.tLTEQUAL: + operator = IASTBinaryExpression.op_lessEqual; + break; + case IToken.tGTEQUAL: + operator = IASTBinaryExpression.op_greaterEqual; + break; + } + firstExpression = buildBinaryExpression( operator, firstExpression, secondExpression ); + break; + default: + return firstExpression; + } + } + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression multiplicativeExpression() + throws BacktrackException, EndOfFileException { + IASTExpression firstExpression = castExpression(); + for (;;) { + switch (LT(1)) { + case IToken.tSTAR: + case IToken.tDIV: + case IToken.tMOD: + IToken t = consume(); + IASTExpression secondExpression = castExpression(); + int operator = 0; + switch (t.getType()) { + case IToken.tSTAR: + operator = IASTBinaryExpression.op_multiply; + break; + case IToken.tDIV: + operator = IASTBinaryExpression.op_divide; + break; + case IToken.tMOD: + operator = IASTBinaryExpression.op_modulo; + break; + } + firstExpression = buildBinaryExpression( operator, firstExpression, secondExpression ); + break; + default: + return firstExpression; + } + } + } + + /** + * castExpression : unaryExpression | "(" typeId ")" castExpression + */ + protected IASTExpression castExpression() throws EndOfFileException, + BacktrackException { + // TO DO: we need proper symbol checkint to ensure type name + if (LT(1) == IToken.tLPAREN) { + IToken mark = mark(); + int startingOffset = mark.getOffset(); + consume(); + IASTTypeId typeId = null; + IASTExpression castExpression = null; + // If this isn't a type name, then we shouldn't be here + try { + try { + typeId = typeId(false); + consume(IToken.tRPAREN); + castExpression = castExpression(); + } catch (BacktrackException bte) { + backup(mark); + throwBacktrack(bte); + } + + + return buildTypeIdUnaryExpression( IASTUnaryTypeIdExpression.op_cast, typeId, castExpression, startingOffset ); + } catch (BacktrackException b) { + } + } + return unaryExpression(); + } + + /** + * @param op + * @param typeId + * @param subExpression + * @param startingOffset + * @return + */ + protected IASTExpression buildTypeIdUnaryExpression(int op, IASTTypeId typeId, IASTExpression subExpression, int startingOffset) { + IASTUnaryTypeIdExpression result = createUnaryTypeIdExpression(); + result.setOperator( op ); + ((CASTNode)result).setOffset( startingOffset ); + result.setTypeId(typeId); + typeId.setParent( result ); + typeId.setPropertyInParent( IASTUnaryTypeIdExpression.TYPE_ID ); + result.setOperand( subExpression ); + subExpression.setParent( result ); + subExpression.setPropertyInParent( IASTUnaryTypeIdExpression.OPERAND ); + return result; + } + + /** + * @return + */ + protected IASTUnaryTypeIdExpression createUnaryTypeIdExpression() { + return new CASTUnaryTypeIdExpression(); + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression unaryExpression() throws EndOfFileException, + BacktrackException { + int startingOffset = LA(1).getOffset(); + switch (LT(1)) { + case IToken.tSTAR: + return unaryOperatorCastExpression(IASTUnaryExpression.op_star ); + case IToken.tAMPER: + return unaryOperatorCastExpression(IASTUnaryExpression.op_amper); + case IToken.tPLUS: + return unaryOperatorCastExpression(IASTUnaryExpression.op_plus ); + case IToken.tMINUS: + return unaryOperatorCastExpression(IASTUnaryExpression.op_minus ); + case IToken.tNOT: + return unaryOperatorCastExpression(IASTUnaryExpression.op_not ); + case IToken.tCOMPL: + return unaryOperatorCastExpression(IASTUnaryExpression.op_tilde); + case IToken.tINCR: + return unaryOperatorCastExpression(IASTUnaryExpression.op_prefixIncr); + case IToken.tDECR: + return unaryOperatorCastExpression(IASTUnaryExpression.op_prefixDecr); + case IToken.t_sizeof: + startingOffset = consume(IToken.t_sizeof).getOffset(); + IToken mark = LA(1); + IASTExpression unaryExpression = null; + IASTTypeId typeId = null; + if (LT(1) == IToken.tLPAREN) { + try { + consume(IToken.tLPAREN); + typeId = typeId(false); + consume(IToken.tRPAREN); + } catch (BacktrackException bt) { + backup(mark); + typeId = null; + unaryExpression = unaryExpression(); + } + } else { + unaryExpression = unaryExpression(); + } + mark = null; + if (typeId == null && unaryExpression != null ) + return buildUnaryExpression( IASTUnaryExpression.op_sizeof, unaryExpression, startingOffset ); + return buildTypeIdExpression( IASTTypeIdExpression.op_sizeof, typeId, startingOffset ); + + default: + if (LT(1) == IGCCToken.t_typeof && supportTypeOfUnaries) { + IASTExpression unary = unaryTypeofExpression(); + if (unary != null) + return unary; + } + if (LT(1) == IGCCToken.t___alignof__ && supportAlignOfUnaries) { + IASTExpression align = unaryAlignofExpression(); + if (align != null) + return align; + } + return postfixExpression(); + } + } + + /** + * @param op_sizeof + * @param typeId + * @param startingOffset + * @return + */ + protected IASTExpression buildTypeIdExpression(int op_sizeof, IASTTypeId typeId, int startingOffset) { + IASTTypeIdExpression result = createTypeIdExpression(); + result.setOperator( op_sizeof ); + ((CASTNode)result).setOffset( startingOffset ); + result.setTypeId( typeId ); + typeId.setParent( result ); + typeId.setPropertyInParent( IASTTypeIdExpression.TYPE_ID ); + return result; + } + + /** + * @return + */ + protected IASTTypeIdExpression createTypeIdExpression() { + return new CASTTypeIdExpression(); + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression postfixExpression() throws EndOfFileException, + BacktrackException { + + IASTExpression firstExpression = null; + switch (LT(1)) { + case IToken.tLPAREN: + // ( type-name ) { initializer-list } + // ( type-name ) { initializer-list , } + IToken m = mark(); + try + { + int offset = consume(IToken.tLPAREN).getOffset(); + IASTTypeId t = typeId(false); + consume( IToken.tRPAREN ); + IASTInitializer i = cInitializerClause(Collections.EMPTY_LIST); + firstExpression = buildTypeIdInitializerExpression( t, i, offset ); + break; + } + catch( BacktrackException bt ) + { + backup( m ); + } + + default: + firstExpression = primaryExpression(); + } + + IASTExpression secondExpression = null; + for (;;) { + switch (LT(1)) { + case IToken.tLBRACKET: + // array access + consume(IToken.tLBRACKET); + secondExpression = expression(); + consume(IToken.tRBRACKET); + IASTArraySubscriptExpression s = createArraySubscriptExpression(); + ((CASTNode)s).setOffset( ((CASTNode)firstExpression).getOffset() ); + s.setArrayExpression( firstExpression ); + firstExpression.setParent( s ); + firstExpression.setPropertyInParent( IASTArraySubscriptExpression.ARRAY ); + s.setSubscriptExpression( secondExpression ); + secondExpression.setParent( s ); + secondExpression.setPropertyInParent( IASTArraySubscriptExpression.SUBSCRIPT ); + firstExpression = s; + break; + case IToken.tLPAREN: + // function call + consume(IToken.tLPAREN); + if( LT(1) != IToken.tRPAREN ) + secondExpression = expression(); + consume(IToken.tRPAREN); + IASTFunctionCallExpression f = createFunctionCallExpression(); + ((CASTNode)f).setOffset( ((CASTNode)firstExpression).getOffset() ); + f.setFunctionNameExpression( firstExpression ); + firstExpression.setParent( f ); + firstExpression.setPropertyInParent( IASTFunctionCallExpression.FUNCTION_NAME ); + + if( secondExpression != null ) + { + f.setParameterExpression( secondExpression ); + secondExpression.setParent( f ); + secondExpression.setPropertyInParent( IASTFunctionCallExpression.PARAMETERS ); + } + firstExpression = f; + break; + case IToken.tINCR: + int offset = consume(IToken.tINCR).getOffset(); + firstExpression = buildUnaryExpression( IASTUnaryExpression.op_postFixIncr, firstExpression, offset ); + break; + case IToken.tDECR: + offset = consume().getOffset(); + firstExpression = buildUnaryExpression( IASTUnaryExpression.op_postFixDecr, firstExpression, offset ); + break; + case IToken.tDOT: + // member access + consume(IToken.tDOT); + IASTName name = createName( identifier() ); + IASTFieldReference result = createFieldReference(); + ((CASTNode)result).setOffset( ((CASTNode)firstExpression).getOffset() ); + result.setFieldOwner( firstExpression ); + result.setIsPointerDereference(false); + firstExpression.setParent( result ); + firstExpression.setPropertyInParent( IASTFieldReference.FIELD_OWNER ); + result.setFieldName( name ); + name.setParent( result ); + name.setPropertyInParent( IASTFieldReference.FIELD_NAME ); + firstExpression = result; + break; + case IToken.tARROW: + // member access + consume(IToken.tARROW); + name = createName( identifier() ); + result = createFieldReference(); + ((CASTNode)result).setOffset( ((CASTNode)firstExpression).getOffset() ); + result.setFieldOwner( firstExpression ); + result.setIsPointerDereference(true); + firstExpression.setParent( result ); + firstExpression.setPropertyInParent( IASTFieldReference.FIELD_OWNER ); + result.setFieldName( name ); + name.setParent( result ); + name.setPropertyInParent( IASTFieldReference.FIELD_NAME ); + firstExpression = result; + break; + default: + return firstExpression; + } + } + } + + /** + * @return + */ + protected IASTFunctionCallExpression createFunctionCallExpression() { + return new CASTFunctionCallExpression(); + } + + /** + * @return + */ + protected IASTArraySubscriptExpression createArraySubscriptExpression() { + return new CASTArraySubscriptExpression(); + } + + /** + * @param t + * @param i + * @param offset + * @return + */ + protected ICASTTypeIdInitializerExpression buildTypeIdInitializerExpression(IASTTypeId t, IASTInitializer i, int offset) { + ICASTTypeIdInitializerExpression result = createTypeIdInitializerExpression(); + ((CASTNode)result).setOffset( offset ); + result.setTypeId( t ); + t.setParent( result ); + t.setPropertyInParent( ICASTTypeIdInitializerExpression.TYPE_ID ); + result.setInitializer( i ); + i.setParent( result ); + i.setPropertyInParent( ICASTTypeIdInitializerExpression.INITIALIZER ); + return result; + } + + /** + * @return + */ + protected ICASTTypeIdInitializerExpression createTypeIdInitializerExpression() { + return new CASTTypeIdInitializerExpression(); + } + + /** + * @return + */ + protected IASTFieldReference createFieldReference() { + return new CASTFieldReference(); + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression primaryExpression() throws EndOfFileException, + BacktrackException { + IToken t = null; + IASTLiteralExpression literalExpression = null; + switch (LT(1)) { + // TO DO: we need more literals... + case IToken.tINTEGER: + t = consume(); + literalExpression = createLiteralExpression(); + literalExpression.setKind( IASTLiteralExpression.lk_integer_constant); + literalExpression.setValue( t.getImage() ); + ((CASTNode)literalExpression).setOffset( t.getOffset() ); + return literalExpression; + case IToken.tFLOATINGPT: + t = consume(); + literalExpression = createLiteralExpression(); + literalExpression.setKind( IASTLiteralExpression.lk_float_constant ); + literalExpression.setValue( t.getImage() ); + ((CASTNode)literalExpression).setOffset( t.getOffset() ); + return literalExpression; + case IToken.tSTRING: + case IToken.tLSTRING: + t = consume(); + literalExpression = createLiteralExpression(); + literalExpression.setKind( IASTLiteralExpression.lk_string_literal ); + literalExpression.setValue( t.getImage() ); + ((CASTNode)literalExpression).setOffset( t.getOffset() ); + return literalExpression; + case IToken.tCHAR: + case IToken.tLCHAR: + t = consume(); + literalExpression = createLiteralExpression(); + literalExpression.setKind( IASTLiteralExpression.lk_char_constant ); + literalExpression.setValue( t.getImage() ); + ((CASTNode)literalExpression).setOffset( t.getOffset() ); + return literalExpression; + case IToken.tLPAREN: + t = consume(); + //TODO - do we need to return a wrapper? + IASTExpression lhs = expression(); + consume(IToken.tRPAREN); + return lhs; + case IToken.tIDENTIFIER: + + int startingOffset = LA(1).getOffset(); + int line = LA(1).getLineNumber(); + IToken t1 = identifier(); + IASTIdExpression idExpression = createIdExpression(); + IASTName name = createName(t1); + idExpression.setName(name); + name.setParent(idExpression); + name.setPropertyInParent(IASTIdExpression.ID_NAME); + return idExpression; + default: + IToken la = LA(1); + startingOffset = la.getOffset(); + line = la.getLineNumber(); + throwBacktrack( startingOffset, startingOffset, line, la.getFilename() ); + return null; + } + + } + + /** + * @return + */ + protected IASTLiteralExpression createLiteralExpression() { + return new CASTLiteralExpression(); + } + + /** + * @return + */ + protected IASTIdExpression createIdExpression() { + return new CASTIdExpression(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.core.parser2.GNUBaseParser#statement(java.lang.Object) + */ + protected IASTStatement statement() throws EndOfFileException, + BacktrackException { + + switch (LT(1)) { + // labeled statements + case IToken.t_case: + int startOffset = consume(IToken.t_case).getOffset(); + IASTExpression case_exp = constantExpression(); + consume(IToken.tCOLON); + cleanupLastToken(); + IASTCaseStatement cs = createCaseStatement(); + ((CASTNode)cs).setOffset( startOffset ); + cs.setExpression( case_exp ); + case_exp.setParent( cs ); + case_exp.setPropertyInParent( IASTCaseStatement.EXPRESSION ); + return cs; + case IToken.t_default: + startOffset = consume(IToken.t_default).getOffset(); + consume(IToken.tCOLON); + cleanupLastToken(); + IASTDefaultStatement df = createDefaultStatement(); + ((CASTNode)df).setOffset( startOffset ); + return df; + // compound statement + case IToken.tLBRACE: + IASTCompoundStatement compound = compoundStatement(); + cleanupLastToken(); + return compound; + // selection statement + case IToken.t_if: + startOffset = consume(IToken.t_if).getOffset(); + consume(IToken.tLPAREN); + IASTExpression if_condition = condition(); + consume(IToken.tRPAREN); + IASTStatement then_clause = statement(); + IASTStatement else_clause = null; + if (LT(1) == IToken.t_else) { + consume(IToken.t_else); + else_clause = statement(); + } + + IASTIfStatement if_stmt = createIfStatement(); + if_stmt.setCondition( if_condition ); + ((CASTNode)if_stmt).setOffset( startOffset ); + if_condition.setParent( if_stmt ); + if_condition.setPropertyInParent( IASTIfStatement.CONDITION ); + if_stmt.setThenClause( then_clause ); + then_clause.setParent( if_stmt ); + then_clause.setPropertyInParent( IASTIfStatement.THEN ); + if( else_clause != null ) + { + if_stmt.setElseClause( else_clause ); + else_clause.setParent( if_stmt ); + else_clause.setPropertyInParent( IASTIfStatement.ELSE ); + } + cleanupLastToken(); + return if_stmt; + case IToken.t_switch: + startOffset = consume( IToken.t_switch ).getOffset(); + consume(IToken.tLPAREN); + IASTExpression switch_condition = condition(); + consume(IToken.tRPAREN); + IASTStatement switch_body = statement(); + cleanupLastToken(); + IASTSwitchStatement switch_statement = createSwitchStatement(); + ((CASTNode)switch_statement).setOffset( startOffset ); + switch_statement.setController( switch_condition ); + switch_condition.setParent( switch_statement ); + switch_condition.setPropertyInParent( IASTSwitchStatement.CONTROLLER ); + switch_statement.setBody( switch_body ); + switch_body.setParent( switch_statement ); + switch_body.setPropertyInParent( IASTSwitchStatement.BODY ); + return switch_statement; + //iteration statements + case IToken.t_while: + startOffset = consume(IToken.t_while).getOffset(); + consume(IToken.tLPAREN); + IASTExpression while_condition = condition(); + consume(IToken.tRPAREN); + IASTStatement while_body = statement(); + cleanupLastToken(); + IASTWhileStatement while_statement = createWhileStatement(); + ((CASTNode)while_statement).setOffset( startOffset ); + while_statement.setCondition( while_condition ); + while_condition.setParent( while_statement ); + while_condition.setPropertyInParent( IASTWhileStatement.CONDITION ); + while_statement.setBody( while_body ); + while_condition.setParent( while_statement ); + while_condition.setPropertyInParent( IASTWhileStatement.BODY ); + return while_statement; + case IToken.t_do: + startOffset = consume(IToken.t_do).getOffset(); + IASTStatement do_body = statement(); + consume(IToken.t_while); + consume(IToken.tLPAREN); + IASTExpression do_condition = condition(); + consume(IToken.tRPAREN); + cleanupLastToken(); + IASTDoStatement do_statement = createDoStatement(); + ((CASTNode)do_statement).setOffset( startOffset ); + do_statement.setBody( do_body ); + do_body.setParent( do_statement ); + do_body.setPropertyInParent( IASTDoStatement.BODY ); + do_statement.setCondition( do_condition ); + do_condition.setParent( do_statement ); + do_condition.setPropertyInParent( IASTDoStatement.CONDITION ); + return do_statement; + case IToken.t_for: + startOffset = consume( IToken.t_for ).getOffset(); + consume(IToken.tLPAREN); + IASTNode init = forInitStatement(); + IASTExpression for_condition = null; + if (LT(1) != IToken.tSEMI) + for_condition = condition(); + consume(IToken.tSEMI); + IASTExpression iterationExpression = null; + if (LT(1) != IToken.tRPAREN) { + iterationExpression = expression(); + cleanupLastToken(); + } + consume(IToken.tRPAREN); + IASTStatement for_body = statement(); + cleanupLastToken(); + IASTForStatement for_statement = createForStatement(); + ((CASTNode)for_statement).setOffset( startOffset ); + if( init instanceof IASTDeclaration ) + { + for_statement.setInit((IASTDeclaration) init); + ((IASTDeclaration) init).setParent( for_statement ); + ((IASTDeclaration) init).setPropertyInParent( IASTForStatement.INITDECLARATION ); + } + else if( init instanceof IASTExpression ) + { + for_statement.setInit((IASTExpression) init); + ((IASTExpression) init).setParent( for_statement ); + ((IASTExpression) init).setPropertyInParent( IASTForStatement.INITEXPRESSION ); + } + if( for_condition != null ) + { + for_statement.setCondition( for_condition ); + for_condition.setParent( for_statement ); + for_condition.setPropertyInParent( IASTForStatement.CONDITION ); + } + if( iterationExpression != null ) + { + for_statement.setIterationExpression( iterationExpression ); + iterationExpression.setParent( for_statement ); + iterationExpression.setPropertyInParent( IASTForStatement.ITERATION ); + } + for_statement.setBody( for_body ); + for_body.setParent( for_statement ); + for_body.setPropertyInParent( IASTForStatement.BODY ); + return for_statement; + //jump statement + case IToken.t_break: + startOffset = consume(IToken.t_break).getOffset(); + consume(IToken.tSEMI); + cleanupLastToken(); + IASTBreakStatement break_statement = createBreakStatement(); + ((CASTNode)break_statement).setOffset( startOffset ); + return break_statement; + case IToken.t_continue: + startOffset = consume(IToken.t_continue).getOffset(); + consume(IToken.tSEMI); + cleanupLastToken(); + IASTContinueStatement continue_statement = createContinueStatement(); + ((CASTNode)continue_statement).setOffset( startOffset ); + return continue_statement; + case IToken.t_return: + startOffset = consume(IToken.t_return).getOffset(); + IASTExpression result = null; + if (LT(1) != IToken.tSEMI) { + result = expression(); + cleanupLastToken(); + } + consume(IToken.tSEMI); + cleanupLastToken(); + IASTReturnStatement return_statement = createReturnStatement(); + ((CASTNode)return_statement).setOffset( startOffset ); + if( result != null ) + { + return_statement.setReturnValue( result ); + result.setParent( return_statement ); + result.setPropertyInParent( IASTReturnStatement.RETURNVALUE ); + } + return return_statement; + case IToken.t_goto: + startOffset = consume(IToken.t_goto).getOffset(); + IToken identifier = consume(IToken.tIDENTIFIER); + consume(IToken.tSEMI); + cleanupLastToken(); + IASTName goto_label_name = createName( identifier ); + IASTGotoStatement goto_statement = createGoToStatement(); + ((CASTNode)goto_statement).setOffset( startOffset ); + goto_statement.setName( goto_label_name ); + goto_label_name.setParent( goto_statement ); + goto_label_name.setPropertyInParent( IASTGotoStatement.NAME ); + return goto_statement; + case IToken.tSEMI: + startOffset = consume(IToken.tSEMI ).getOffset(); + cleanupLastToken(); + IASTNullStatement null_statement = createNullStatement(); + ((CASTNode)null_statement).setOffset( startOffset ); + return null_statement; + default: + // can be many things: + // label + if (LT(1) == IToken.tIDENTIFIER && LT(2) == IToken.tCOLON) { + IToken labelName = consume(IToken.tIDENTIFIER); + consume(IToken.tCOLON); + IASTLabelStatement label_statement = createLabelStatement(); + ((CASTNode)label_statement).setOffset( labelName.getOffset() ); + IASTName name = createName( labelName ); + label_statement.setName( name ); + name.setParent( label_statement ); + name.setPropertyInParent( IASTLabelStatement.NAME ); + return label_statement; + } + // expressionStatement + // Note: the function style cast ambiguity is handled in + // expression + // Since it only happens when we are in a statement + IToken mark = mark(); + try { + IASTExpression expression = expression(); + consume(IToken.tSEMI); + IASTExpressionStatement expressionStatement = createExpressionStatement(); + expressionStatement.setExpression( expression ); + expression.setParent( expressionStatement ); + expression.setPropertyInParent( IASTExpressionStatement.EXPFRESSION ); + cleanupLastToken(); + return expressionStatement; + } catch (BacktrackException b) { + backup(mark); + } + + // declarationStatement + IASTDeclaration d = declaration(); + IASTDeclarationStatement ds = createDeclarationStatement(); + ds.setDeclaration(d); + d.setParent( ds ); + d.setPropertyInParent( IASTDeclarationStatement.DECLARATION ); + cleanupLastToken(); + return ds; + } + + } + + /** + * @return + */ + protected IASTLabelStatement createLabelStatement() { + return new CASTLabelStatement(); + } + + /** + * @return + */ + protected IASTGotoStatement createGoToStatement() { + return new CASTGotoStatement(); + } + + /** + * @return + */ + protected IASTReturnStatement createReturnStatement() { + return new CASTReturnStatement(); + } + + /** + * @return + */ + protected IASTForStatement createForStatement() { + return new CASTForStatement(); + } + + /** + * @return + */ + protected IASTContinueStatement createContinueStatement() { + return new CASTContinueStatement(); + } + + /** + * @return + */ + protected IASTDoStatement createDoStatement() { + return new CASTDoStatement(); + } + + /** + * @return + */ + protected IASTBreakStatement createBreakStatement() { + return new CASTBreakStatement(); + } + + /** + * @return + */ + protected IASTWhileStatement createWhileStatement() { + return new CASTWhileStatement(); + } + + /** + * @return + */ + protected IASTNullStatement createNullStatement() { + return new CASTNullStatement(); + } + + /** + * @return + */ + protected IASTSwitchStatement createSwitchStatement() { + return new CASTSwitchStatement(); + } + + /** + * @return + */ + protected IASTIfStatement createIfStatement() { + return new CASTIfStatement(); + } + + /** + * @return + */ + protected IASTDefaultStatement createDefaultStatement() { + return new CASTDefaultStatement(); + } + + /** + * @return + */ + protected IASTCaseStatement createCaseStatement() { + return new CASTCaseStatement(); + } + + /** + * @return + */ + protected IASTExpressionStatement createExpressionStatement() { + return new CASTExpressionStatement(); + } + + /** + * @return + */ + protected IASTDeclarationStatement createDeclarationStatement() { + return new CASTDeclarationStatement(); + } + + protected IASTTypeId typeId(boolean skipArrayModifiers) + throws EndOfFileException, BacktrackException { + IToken mark = mark(); + int startingOffset = mark.getOffset(); + char [] filename = mark.getFilename(); + int lineNumber = mark.getLineNumber(); + IASTDeclSpecifier declSpecifier = null; + IASTDeclarator declarator = null; + + try + { + declSpecifier = declSpecifierSeq(false); + declarator = declarator(); + } + catch( BacktrackException bt ) + { + int endingOffset = lastToken == null ? 0 : lastToken.getEndOffset(); + backup( mark ); + throwBacktrack( startingOffset, endingOffset, lineNumber, filename ); + } + if( declarator == null || declarator.getName().toString() != null ) //$NON-NLS-1$ + { + int endingOffset = lastToken == null ? 0 : lastToken.getEndOffset(); + backup( mark ); + throwBacktrack( startingOffset, endingOffset, lineNumber, filename ); + } + + IASTTypeId result = createTypeId(); + ((CASTNode)result).setOffset( startingOffset ); + + result.setDeclSpecifier( declSpecifier ); + declSpecifier.setParent( result ); + declSpecifier.setPropertyInParent( IASTTypeId.DECL_SPECIFIER ); + + result.setAbstractDeclarator( declarator ); + declarator.setParent( result ); + declarator.setPropertyInParent( IASTTypeId.ABSTRACT_DECLARATOR ); + + return result; + } + + /** + * @return + */ + protected IASTTypeId createTypeId() { + return new CASTTypeId(); + } + + /** + * Parse a Pointer Operator. + * + * ptrOperator : "*" (cvQualifier)* | "&" | ::? nestedNameSpecifier "*" + * (cvQualifier)* + * + * @param owner + * Declarator that this pointer operator corresponds to. + * @throws BacktrackException + * request a backtrack + */ + protected void consumePointerOperators(List pointerOps) + throws EndOfFileException, BacktrackException { + for (;;) { + IToken mark = mark(); + + ITokenDuple nameDuple = null; + boolean isConst = false, isVolatile = false, isRestrict = false; + if (LT(1) == IToken.tIDENTIFIER) { + IToken t = identifier(); + nameDuple = TokenFactory.createTokenDuple(t, t); + } + + if( LT(1) != IToken.tSTAR ) + { + backup( mark ); + break; + } + + consume(IToken.tSTAR); + int startOffset = mark.getOffset(); + for (;;) { + IToken t = LA(1); + switch (LT(1)) { + case IToken.t_const: + consume(IToken.t_const); + isConst = true; + break; + case IToken.t_volatile: + consume(IToken.t_volatile); + isVolatile = true; + break; + case IToken.t_restrict: + consume(IToken.t_restrict); + isRestrict = true; + break; + } + + if (t == LA(1)) + break; + } + + IASTPointerOperator po = null; + if (nameDuple != null) { + nameDuple.freeReferences(); + } else { + po = createPointer(); + ((CASTNode)po).setOffset( startOffset ); + ((ICASTPointer) po).setConst(isConst); + ((ICASTPointer) po).setVolatile(isVolatile); + ((ICASTPointer) po).setRestrict(isRestrict); + } + if (po != null) + pointerOps.add(po); + } + } + + /** + * @return + */ + protected ICASTPointer createPointer() { + return new CASTPointer(); + } + + protected IASTDeclSpecifier declSpecifierSeq(boolean parm) + throws BacktrackException, EndOfFileException { + Flags flags = new Flags(parm); + + int startingOffset = LA(1).getOffset(); + int storageClass = IASTDeclSpecifier.sc_unspecified; + boolean isInline = false; + boolean isConst = false, isRestrict = false, isVolatile = false; + boolean isShort = false, isLong = false, isUnsigned = false, isIdentifier = false, isSigned = false; + int simpleType = IASTSimpleDeclSpecifier.t_unspecified; + IToken identifier = null; + ICASTCompositeTypeSpecifier structSpec = null; + ICASTElaboratedTypeSpecifier elabSpec = null; + ICASTEnumerationSpecifier enumSpec = null; + + declSpecifiers: for (;;) { + switch (LT(1)) { + //Storage Class Specifiers + case IToken.t_auto: + consume(); + storageClass = IASTDeclSpecifier.sc_auto; + break; + case IToken.t_register: + storageClass = IASTDeclSpecifier.sc_register; + consume(); + break; + case IToken.t_static: + storageClass = IASTDeclSpecifier.sc_static; + consume(); + break; + case IToken.t_extern: + storageClass = IASTDeclSpecifier.sc_extern; + consume(); + break; + case IToken.t_typedef: + storageClass = IASTDeclSpecifier.sc_typedef; + consume(); + break; + + //Function Specifier + case IToken.t_inline: + isInline = true; + consume(); + break; + + //Type Qualifiers + case IToken.t_const: + isConst = true; + consume(); + break; + case IToken.t_volatile: + isVolatile = true; + consume(); + break; + case IToken.t_restrict: + isRestrict = true; + consume(); + break; + + //Type Specifiers + case IToken.t_void: + flags.setEncounteredRawType(true); + consume(); + simpleType = IASTSimpleDeclSpecifier.t_void; + break; + case IToken.t_char: + flags.setEncounteredRawType(true); + consume(); + simpleType = IASTSimpleDeclSpecifier.t_char; + break; + case IToken.t_short: + flags.setEncounteredRawType(true); + consume(); + isShort = true; + break; + case IToken.t_int: + flags.setEncounteredRawType(true); + consume(); + simpleType = IASTSimpleDeclSpecifier.t_int; + break; + case IToken.t_long: + flags.setEncounteredRawType(true); + consume(); + isLong = true; + break; + case IToken.t_float: + flags.setEncounteredRawType(true); + consume(); + simpleType = IASTSimpleDeclSpecifier.t_float; + break; + case IToken.t_double: + flags.setEncounteredRawType(true); + consume(); + simpleType = IASTSimpleDeclSpecifier.t_double; + break; + case IToken.t_signed: + flags.setEncounteredRawType(true); + consume(); + isSigned = true; + break; + case IToken.t_unsigned: + flags.setEncounteredRawType(true); + consume(); + isUnsigned = true; + break; + case IToken.t__Bool: + flags.setEncounteredRawType(true); + consume(); + simpleType = ICASTSimpleDeclSpecifier.t_Bool; + break; + case IToken.t__Complex: + consume(IToken.t__Complex); + simpleType = ICASTSimpleDeclSpecifier.t_Complex; + break; + case IToken.t__Imaginary: + consume(IToken.t__Imaginary); + simpleType = ICASTSimpleDeclSpecifier.t_Imaginary; + break; + + case IToken.tIDENTIFIER: + // TODO - Kludgy way to handle constructors/destructors + if (flags.haveEncounteredRawType()) { + break declSpecifiers; + } + if (parm && flags.haveEncounteredTypename()) { + break declSpecifiers; + } + if (lookAheadForDeclarator(flags)) { + break declSpecifiers; + } + + identifier = identifier(); + isIdentifier = true; + flags.setEncounteredTypename(true); + break; + case IToken.t_struct: + case IToken.t_union: + try { + structSpec = structOrUnionSpecifier( ); + flags.setEncounteredTypename(true); + break; + } catch (BacktrackException bt) { + elabSpec = elaboratedTypeSpecifier( ); + flags.setEncounteredTypename(true); + break; + } + case IToken.t_enum: + try { + enumSpec = (ICASTEnumerationSpecifier) enumSpecifier(null); + flags.setEncounteredTypename(true); + break; + } catch (BacktrackException bt) { + // this is an elaborated class specifier + elabSpec = elaboratedTypeSpecifier( ); + flags.setEncounteredTypename(true); + break; + } + default: + if (supportTypeOfUnaries && LT(1) == IGCCToken.t_typeof) { + Object expression = unaryTypeofExpression(); + if (expression != null) { + flags.setEncounteredTypename(true); + } + } + break declSpecifiers; + } + } + + if( structSpec != null ) + { + ((CASTNode)structSpec).setOffset( startingOffset ); + structSpec.setConst(isConst); + structSpec.setRestrict(isRestrict); + structSpec.setVolatile(isVolatile); + structSpec.setInline(isInline); + structSpec.setStorageClass(storageClass); + + return structSpec; + } + + if( enumSpec != null ) + { + ((CASTNode)enumSpec).setOffset( startingOffset ); + enumSpec.setConst(isConst); + enumSpec.setRestrict(isRestrict); + enumSpec.setVolatile(isVolatile); + enumSpec.setInline(isInline); + enumSpec.setStorageClass(storageClass); + return enumSpec; + + } + if( elabSpec != null ) + { + ((CASTNode)elabSpec).setOffset( startingOffset ); + elabSpec.setConst(isConst); + elabSpec.setRestrict(isRestrict); + elabSpec.setVolatile(isVolatile); + elabSpec.setInline(isInline); + elabSpec.setStorageClass(storageClass); + + return elabSpec; + } + if (isIdentifier) { + ICASTTypedefNameSpecifier declSpec = createNamedTypeSpecifier(); + declSpec.setConst(isConst); + declSpec.setRestrict(isRestrict); + declSpec.setVolatile(isVolatile); + declSpec.setInline(isInline); + declSpec.setStorageClass(storageClass); + + ((CASTNode)declSpec).setOffset(startingOffset); + IASTName name = createName( identifier ); + declSpec.setName( name ); + name.setParent( declSpec ); + name.setPropertyInParent( IASTTypedefNameSpecifier.NAME ); + return declSpec; + } + if (simpleType != IASTSimpleDeclSpecifier.t_unspecified || isLong + || isShort || isUnsigned || isSigned) { + ICASTSimpleDeclSpecifier declSpec = createSimpleTypeSpecifier(); + declSpec.setConst(isConst); + declSpec.setRestrict(isRestrict); + declSpec.setVolatile(isVolatile); + declSpec.setInline(isInline); + declSpec.setStorageClass(storageClass); + + declSpec.setType(simpleType); + declSpec.setLong(isLong); + declSpec.setUnsigned(isUnsigned); + declSpec.setSigned(isSigned); + declSpec.setShort(isShort); + + ((CASTNode)declSpec).setOffset(startingOffset); + return declSpec; + } + return null; + } + + /** + * @return + */ + protected ICASTSimpleDeclSpecifier createSimpleTypeSpecifier() { + return new CASTSimpleDeclSpecifier(); + } + + /** + * @return + */ + protected ICASTTypedefNameSpecifier createNamedTypeSpecifier() { + return new CASTTypedefNameSpecifier(); + } + + /** + * Parse a class/struct/union definition. + * + * classSpecifier : classKey name (baseClause)? "{" (memberSpecification)* + * "}" + * @param owner + * IParserCallback object that represents the declaration that + * owns this classSpecifier + * + * @return TODO + * @throws BacktrackException + * request a backtrack + */ + protected ICASTCompositeTypeSpecifier structOrUnionSpecifier( ) + throws BacktrackException, EndOfFileException { + + int classKind = 0; + IToken classKey = null; + IToken mark = mark(); + + // class key + switch (LT(1)) { + case IToken.t_struct: + classKey = consume(); + classKind = IASTCompositeTypeSpecifier.k_struct; + break; + case IToken.t_union: + classKey = consume(); + classKind = IASTCompositeTypeSpecifier.k_union; + break; + default: + throwBacktrack(mark.getOffset(), mark.getEndOffset(), mark + .getLineNumber(), mark.getFilename()); + } + + IToken nameToken = null; + // class name + if (LT(1) == IToken.tIDENTIFIER) { + nameToken = identifier(); + } + + if (LT(1) != IToken.tLBRACE) { + IToken errorPoint = LA(1); + backup(mark); + throwBacktrack(errorPoint.getOffset(), errorPoint.getEndOffset(), + errorPoint.getLineNumber(), errorPoint.getFilename()); + } + + consume(IToken.tLBRACE); + cleanupLastToken(); + + IASTName name = null; + if( nameToken != null ) + name = createName( nameToken ); + else + name = createName(); + + ICASTCompositeTypeSpecifier result = createCompositeTypeSpecifier(); + + result.setKey( classKind ); + ((CASTNode)result).setOffset( classKey.getOffset() ); + + result.setName( name ); + if( name != null ) + { + name.setParent( result ); + name.setPropertyInParent( IASTCompositeTypeSpecifier.TYPE_NAME ); + } + + memberDeclarationLoop: while (LT(1) != IToken.tRBRACE) { + int checkToken = LA(1).hashCode(); + switch (LT(1)) { + case IToken.tRBRACE: + consume(IToken.tRBRACE); + break memberDeclarationLoop; + default: + try { + IASTDeclaration d = declaration(); + d.setParent( result ); + d.setPropertyInParent( IASTCompositeTypeSpecifier.MEMBER_DECLARATION ); + result.addMemberDeclaration( d ); + } catch (BacktrackException bt) { + if (checkToken == LA(1).hashCode()) + failParseWithErrorHandling(); + } + } + if (checkToken == LA(1).hashCode()) + failParseWithErrorHandling(); + } + // consume the } + consume(IToken.tRBRACE); + return result; + } + + /** + * @return + */ + protected IASTName createName() { + return new CASTName(); + } + + /** + * @return + */ + protected ICASTCompositeTypeSpecifier createCompositeTypeSpecifier() { + return new CASTCompositeTypeSpecifier(); + } + + protected ICASTElaboratedTypeSpecifier elaboratedTypeSpecifier() + throws BacktrackException, EndOfFileException { + // this is an elaborated class specifier + IToken t = consume(); + int eck = 0; + + switch (t.getType()) { + case IToken.t_struct: + eck = IASTElaboratedTypeSpecifier.k_struct; + break; + case IToken.t_union: + eck = IASTElaboratedTypeSpecifier.k_union; + break; + case IToken.t_enum: + eck = IASTElaboratedTypeSpecifier.k_enum; + break; + default: + backup(t); + throwBacktrack(t.getOffset(), t.getEndOffset(), t.getLineNumber(), + t.getFilename()); + } + + IToken identifier = identifier(); + IASTName name = createName( identifier ); + ICASTElaboratedTypeSpecifier result = createElaboratedTypeSpecifier(); + result.setName( name ); + name.setParent( result ); + name.setPropertyInParent( IASTElaboratedTypeSpecifier.TYPE_NAME ); + result.setKind( eck ); + return result; + } + + /** + * @return + */ + protected ICASTElaboratedTypeSpecifier createElaboratedTypeSpecifier() { + return new CASTElaboratedTypeSpecifier(); + } + + protected IASTDeclarator initDeclarator() throws EndOfFileException, + BacktrackException { + IASTDeclarator d = declarator(); + + try { + // astFactory.constructExpressions(constructInitializers); + IASTInitializer i = optionalCInitializer(); + if (i != null) { + d.setInitializer(i); + i.setParent(d); + i.setPropertyInParent(IASTDeclarator.INITIALIZER); + } + return d; + } finally { + // astFactory.constructExpressions(true); + } + } + + protected IASTDeclarator declarator() throws EndOfFileException, + BacktrackException { + IASTDeclarator innerDecl = null; + IASTName declaratorName = null; + IToken la = LA(1); + int startingOffset = la.getOffset(); + int line = la.getLineNumber(); + char[] fn = la.getFilename(); + la = null; + List pointerOps = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE); + List parameters = Collections.EMPTY_LIST; + List arrayMods = Collections.EMPTY_LIST; + boolean encounteredVarArgs = false; + Object bitField = null; + boolean isFunction = false; + overallLoop: do { + + consumePointerOperators(pointerOps); + + if (LT(1) == IToken.tLPAREN) { + consume(); + innerDecl = declarator(); + consume(IToken.tRPAREN); + declaratorName = createName(); + } else if (LT(1) == IToken.tIDENTIFIER) { + declaratorName = createName(identifier()); + } + else + declaratorName = createName(); + + for (;;) { + switch (LT(1)) { + case IToken.tLPAREN: + boolean failed = false; + // temporary fix for initializer/function declaration + // ambiguity + if (!LA(2).looksLikeExpression()) { + if (LT(2) == IToken.tIDENTIFIER) { + IToken newMark = mark(); + consume(IToken.tLPAREN); + ITokenDuple queryName = null; + try { + try { + IToken i = identifier(); + queryName = TokenFactory.createTokenDuple( + i, i); + // look it up + 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 ((!LA(2).looksLikeExpression() && !failed)) { + // parameterDeclarationClause + // d.setIsFunction(true); + // TODO need to create a temporary scope object here + consume(IToken.tLPAREN); + isFunction = true; + boolean seenParameter = false; + parameterDeclarationLoop: for (;;) { + switch (LT(1)) { + case IToken.tRPAREN: + consume(); + break parameterDeclarationLoop; + case IToken.tELLIPSIS: + consume(); + encounteredVarArgs = true; + break; + case IToken.tCOMMA: + consume(); + seenParameter = false; + break; + default: + int endOffset = (lastToken != null) ? lastToken + .getEndOffset() : 0; + if (seenParameter) + throwBacktrack(startingOffset, endOffset, + line, fn); + IASTParameterDeclaration pd = parameterDeclaration(); + if (parameters == Collections.EMPTY_LIST) + parameters = new ArrayList( + DEFAULT_PARAMETERS_LIST_SIZE); + parameters.add(pd); + seenParameter = true; + } + } + } + break; + case IToken.tLBRACKET: + if( arrayMods == Collections.EMPTY_LIST ) + arrayMods = new ArrayList( DEFAULT_POINTEROPS_LIST_SIZE ); + consumeArrayModifiers( arrayMods ); + continue; + case IToken.tCOLON: + consume(IToken.tCOLON); + bitField = constantExpression(); + default: + break; + } + break; + } + if (LA(1).getType() != IToken.tIDENTIFIER) + break; + + } while (true); + + IASTDeclarator d = null; + if (isFunction) { + IASTFunctionDeclarator fc = createFunctionDeclarator(); + fc.setVarArgs(encounteredVarArgs); + for (int i = 0; i < parameters.size(); ++i) + { + IASTParameterDeclaration p = (IASTParameterDeclaration) parameters + .get(i); + p.setParent( fc ); + p.setPropertyInParent( IASTFunctionDeclarator.FUNCTION_PARAMETER ); + fc.addParameterDeclaration(p); + } + d = fc; + } else if( arrayMods != Collections.EMPTY_LIST ) + { + d = createArrayDeclarator(); + for( int i = 0; i < arrayMods.size(); ++i ) + { + IASTArrayModifier m = (IASTArrayModifier) arrayMods.get(i); + m.setParent( d ); + m.setPropertyInParent( IASTArrayDeclarator.ARRAY_MODIFIER ); + ((IASTArrayDeclarator)d).addArrayModifier( m ); + } + } + else if (bitField != null) { + IASTFieldDeclarator fl = createFieldDeclarator(); + fl.setBitFieldSize((IASTExpression) bitField); + d = fl; + } else + { + d = createDeclarator(); + } + for (int i = 0; i < pointerOps.size(); ++i) { + IASTPointerOperator po = (IASTPointerOperator) pointerOps.get(i); + d.addPointerOperator(po); + po.setParent(d); + po.setPropertyInParent(IASTDeclarator.POINTER_OPERATOR); + } + if (innerDecl != null) { + d.setNestedDeclarator(innerDecl); + innerDecl.setParent(d); + innerDecl.setPropertyInParent(IASTDeclarator.NESTED_DECLARATOR); + } + if (declaratorName != null) { + d.setName(declaratorName); + declaratorName.setParent(d); + declaratorName.setPropertyInParent(IASTDeclarator.DECLARATOR_NAME); + } + + return d; + } + + + protected IASTArrayDeclarator createArrayDeclarator() { + return new CASTArrayDeclarator(); + } + + /** + * @return + */ + protected IASTFieldDeclarator createFieldDeclarator() { + return new CASTFieldDeclarator(); + } + + /** + * @return + */ + protected IASTFunctionDeclarator createFunctionDeclarator() { + return new CASTFunctionDeclarator(); + } + + + + + /** + * @param t + * @return + */ + protected IASTName createName(IToken t) { + IASTName n = new CASTName(t.getCharImage()); + ((CASTNode)n).setOffset(t.getOffset()); + return n; + } + + /** + * @return + */ + protected IASTDeclarator createDeclarator() { + return new CASTDeclarator(); + } + + protected void consumeArrayModifiers(List arrayMods ) + throws EndOfFileException, BacktrackException { + + while (LT(1) == IToken.tLBRACKET) { + //eat the '[' + int startOffset = consume(IToken.tLBRACKET).getOffset(); + + int modifier = -1; + + outerLoop: do { + switch (LT(1)) { + case IToken.t_static: + case IToken.t_const: + case IToken.t_volatile: + case IToken.t_restrict: + modifier = consume().getType(); + continue; + default: + break outerLoop; + } + } while (true); + + IASTExpression exp = null; + + if (LT(1) != IToken.tRBRACKET) { + if (modifier != -1 ) + exp = assignmentExpression(); + else + exp = constantExpression(); + } + consume(IToken.tRBRACKET); + + IASTArrayModifier arrayMod = null; + if( modifier == -1 ) + arrayMod = createArrayModifier(); + else + { + ICASTArrayModifier temp = createCArrayModifier(); + switch( modifier ) + { + case IToken.t_static: + temp.setConst( true ); + break; + case IToken.t_const: + temp.setConst( true ); + break; + case IToken.t_volatile: + temp.setVolatile( true ); + break; + case IToken.t_restrict: + temp.setRestrict( true ); + break; + } + arrayMod = temp; + } + arrayMod.setConstantExpression( exp ); + ((CASTNode)arrayMod).setOffset( startOffset ); + exp.setParent( arrayMod ); + exp.setPropertyInParent( IASTArrayModifier.CONSTANT_EXPRESSION ); + arrayMods.add( arrayMod ); + } + } + + /** + * @return + */ + protected ICASTArrayModifier createCArrayModifier() { + return new CASTModifiedArrayModifier(); + } + + /** + * @return + */ + protected IASTArrayModifier createArrayModifier() { + return new CASTArrayModifier(); + } + + protected IASTParameterDeclaration parameterDeclaration() + throws BacktrackException, EndOfFileException { + IToken current = LA(1); + int startingOffset = current.getOffset(); + IASTDeclSpecifier declSpec = declSpecifierSeq(true); + + IASTDeclarator declarator = null; + if (LT(1) != IToken.tSEMI) + declarator = initDeclarator(); + + if (current == LA(1)) { + int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0; + throwBacktrack(current.getOffset(), endOffset, current + .getLineNumber(), current.getFilename()); + } + + IASTParameterDeclaration result = createParameterDeclaration(); + ((CASTNode)result).setOffset(startingOffset); + result.setDeclSpecifier(declSpec); + declSpec.setParent(result); + declSpec.setPropertyInParent(IASTParameterDeclaration.DECL_SPECIFIER); + result.setDeclarator(declarator); + declarator.setParent(result); + declarator.setPropertyInParent(IASTParameterDeclaration.DECLARATOR); + + return result; + } + + /** + * @return + */ + protected IASTParameterDeclaration createParameterDeclaration() { + return new CASTParameterDeclaration(); + } + + /** + * @throws BacktrackException + */ + protected IASTNode forInitStatement() throws BacktrackException, + EndOfFileException { + IToken mark = mark(); + try { + IASTExpression e = expression(); + consume(IToken.tSEMI); + return e; + } catch (BacktrackException bt) { + backup(mark); + try { + return simpleDeclaration(); + } catch (BacktrackException b) { + failParse(b); + throwBacktrack(b); + } + } + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#getTranslationUnit() + */ + protected IASTTranslationUnit getTranslationUnit() { + return translationUnit; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createCompoundStatement() + */ + protected IASTCompoundStatement createCompoundStatement() { + return new CASTCompoundStatement(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createBinaryExpression() + */ + protected IASTBinaryExpression createBinaryExpression() { + return new CASTBinaryExpression(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createConditionalExpression() + */ + protected IASTConditionalExpression createConditionalExpression() { + return new CASTConditionalExpression(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createUnaryExpression() + */ + protected IASTUnaryExpression createUnaryExpression() { + return new CASTUnaryExpression(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createCompoundStatementExpression() + */ + protected IGNUASTCompoundStatementExpression createCompoundStatementExpression() { + return new CASTCompoundStatementExpression(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createExpressionList() + */ + protected IASTExpressionList createExpressionList() { + return new CASTExpressionList(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createEnumerator() + */ + protected IASTEnumerator createEnumerator() { + return new CASTEnumerator(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createEnumerationSpecifier() + */ + protected IASTEnumerationSpecifier createEnumerationSpecifier() { + return new CASTEnumerationSpecifier(); + } + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/ICParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/ICParserExtensionConfiguration.java new file mode 100644 index 00000000000..f5f5a86e8dd --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/c/ICParserExtensionConfiguration.java @@ -0,0 +1,23 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.c; + +/** + * @author jcamelon + */ +public interface ICParserExtensionConfiguration { + + public boolean supportStatementsInExpressions(); + public boolean supportGCCStyleDesignators(); + public boolean supportTypeofUnaryExpressions(); + public boolean supportAlignOfUnaryExpression(); + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/ANSICPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/ANSICPPParserExtensionConfiguration.java new file mode 100644 index 00000000000..51d93ebae3a --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/ANSICPPParserExtensionConfiguration.java @@ -0,0 +1,61 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.cpp; + +/** + * @author jcamelon + */ +public class ANSICPPParserExtensionConfiguration implements + ICPPParserExtensionConfiguration { + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#allowRestrictPointerOperators() + */ + public boolean allowRestrictPointerOperators() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportTypeofUnaryExpressions() + */ + public boolean supportTypeofUnaryExpressions() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportAlignOfUnaryExpression() + */ + public boolean supportAlignOfUnaryExpression() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportExtendedTemplateSyntax() + */ + public boolean supportExtendedTemplateSyntax() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportMinAndMaxOperators() + */ + public boolean supportMinAndMaxOperators() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportStatementsInExpressions() + */ + public boolean supportStatementsInExpressions() { + return false; + } + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPParserExtensionConfiguration.java new file mode 100644 index 00000000000..6a09753a783 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPParserExtensionConfiguration.java @@ -0,0 +1,60 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ +package org.eclipse.cdt.internal.core.parser2.cpp; + +/** + * @author jcamelon + */ +public class GNUCPPParserExtensionConfiguration implements + ICPPParserExtensionConfiguration { + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#allowRestrictPointerOperators() + */ + public boolean allowRestrictPointerOperators() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportTypeofUnaryExpressions() + */ + public boolean supportTypeofUnaryExpressions() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportAlignOfUnaryExpression() + */ + public boolean supportAlignOfUnaryExpression() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportExtendedTemplateSyntax() + */ + public boolean supportExtendedTemplateSyntax() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportMinAndMaxOperators() + */ + public boolean supportMinAndMaxOperators() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.cpp.ICPPParserExtensionConfiguration#supportStatementsInExpressions() + */ + public boolean supportStatementsInExpressions() { + return true; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java new file mode 100644 index 00000000000..084e6cd3337 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java @@ -0,0 +1,4633 @@ +/********************************************************************** + * Copyright (c) 2002,2003, 2004 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Rational Software - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.internal.core.parser2.cpp; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpressionList; +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTTypeId; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; +import org.eclipse.cdt.core.parser.BacktrackException; +import org.eclipse.cdt.core.parser.EndOfFileException; +import org.eclipse.cdt.core.parser.IGCCToken; +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.IToken; +import org.eclipse.cdt.core.parser.ITokenDuple; +import org.eclipse.cdt.core.parser.ParseError; +import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.parser.SimpleDeclarationStrategy; +import org.eclipse.cdt.internal.core.parser.TemplateParameterManager; +import org.eclipse.cdt.internal.core.parser.token.TokenFactory; +import org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser; +import org.eclipse.cdt.internal.core.parser2.DeclarationWrapper; +import org.eclipse.cdt.internal.core.parser2.Declarator; +import org.eclipse.cdt.internal.core.parser2.IDeclarator; +import org.eclipse.cdt.internal.core.parser2.IDeclaratorOwner; +import org.eclipse.cdt.internal.core.parser2.IParameterCollection; +import org.eclipse.cdt.internal.core.parser2.ParameterCollection; +import org.eclipse.cdt.internal.core.parser2.c.CASTBinaryExpression; +import org.eclipse.cdt.internal.core.parser2.c.CASTCompoundStatement; +import org.eclipse.cdt.internal.core.parser2.c.CASTCompoundStatementExpression; +import org.eclipse.cdt.internal.core.parser2.c.CASTConditionalExpression; +import org.eclipse.cdt.internal.core.parser2.c.CASTEnumerationSpecifier; +import org.eclipse.cdt.internal.core.parser2.c.CASTEnumerator; +import org.eclipse.cdt.internal.core.parser2.c.CASTExpressionList; +import org.eclipse.cdt.internal.core.parser2.c.CASTName; +import org.eclipse.cdt.internal.core.parser2.c.CASTUnaryExpression; + +/** + * This is our implementation of the IParser interface, serving as a + * parser for GNU C and C++. + * + * From time to time we will make reference to the ANSI ISO specifications. + * + * @author jcamelon + */ +public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { + + private ScopeStack templateIdScopes = new ScopeStack(); + protected Object translationUnit; + 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; + } + } + + /** + * 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 { + 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() + throws EndOfFileException, BacktrackException { + IToken start = LA(1); + int startingOffset = start.getOffset(); + int startingLineNumber = start.getOffset(); + char[] fn = start.getFilename(); + start = null; + Object 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 { + Object typeId = typeId(false); + + expression = null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.POSTFIX_TYPEID_TYPEID, + * null, null, null, typeId, null, + * EMPTY_STRING, null); + */ + 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(); + + // if ( ( expression == null ) || + // 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(); + expression = null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.ID_EXPRESSION, + * null, null, null, null, nameDuple, + * EMPTY_STRING, null); + */ + 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(Object scope) throws EndOfFileException, + BacktrackException { + ITokenDuple duple = name(); + //IToken last = consumeTemplateParameters(duple.getLastToken()); + return duple.getLastToken();//last; + } + + /** + * Parse a name. + * + * name : ("::")? name2 ("::" name2)* + * + * name2 : IDENTIFER : template-id + * + * @throws BacktrackException + * request a backtrack + */ + protected ITokenDuple name() throws BacktrackException, + EndOfFileException { + + TemplateParameterManager argumentList = TemplateParameterManager + .getInstance(); + + try { + IToken first = LA(1); + IToken last = null; + IToken mark = mark(); + + boolean hasTemplateId = false; + + if (LT(1) == IToken.tCOLONCOLON) { + argumentList.addSegment(null); + last = consume(IToken.tCOLONCOLON); + } + + if (LT(1) == IToken.tCOMPL) + consume(); + + switch (LT(1)) { + case IToken.tIDENTIFIER: + last = consume(IToken.tIDENTIFIER); + last = consumeTemplateArguments(last, argumentList); + 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) { + last = consume(IToken.tCOLONCOLON); + + if (LT(1) == IToken.t_template) + consume(); + + if (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: + last = consume(); + last = consumeTemplateArguments(last, argumentList); + if (last.getType() == IToken.tGT) + hasTemplateId = true; + } + } + + ITokenDuple tokenDuple = TokenFactory.createTokenDuple(first, last, + (hasTemplateId ? argumentList.getTemplateArgumentsList() + : null)); + return tokenDuple; + } finally { + TemplateParameterManager.returnInstance(argumentList); + } + + } + + /** + * @param last + * @param argumentList + * @return @throws + * EndOfFileException + * @throws BacktrackException + */ + protected IToken consumeTemplateArguments(IToken last, TemplateParameterManager argumentList) throws EndOfFileException, + BacktrackException { +// if (language != ParserLanguage.CPP) +// return last; + if (LT(1) == IToken.tLT) { + IToken secondMark = mark(); + consume(IToken.tLT); + try { + List list = templateArgumentList(); + 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(null /*ASTPointerOperator.CONST_POINTER*/); + break; + case IToken.t_volatile: + result = consume(IToken.t_volatile); + declarator.addPointerOperator(null/*ASTPointerOperator.VOLATILE_POINTER*/); + break; + case IToken.t_restrict: + if (allowCPPRestrict) { + result = consume(IToken.t_restrict); + declarator + .addPointerOperator(null/*ASTPointerOperator.RESTRICT_POINTER*/); + break; + } + IToken la = LA(1); + throwBacktrack(startingOffset, la.getEndOffset(), la + .getLineNumber(), la.getFilename()); + + } + return result; + } + + protected void operatorId(Declarator d, IToken originalToken, + TemplateParameterManager templateArgs) 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(true); + toSend = lastToken; + } + + boolean hasTemplateId = (templateArgs != null); + boolean grabbedNewInstance = false; + if (templateArgs == null) { + templateArgs = TemplateParameterManager.getInstance(); + grabbedNewInstance = true; + } + + try { + toSend = consumeTemplateArguments(toSend, templateArgs); + 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(null /*ASTPointerOperator.REFERENCE*/); + return result; + + } + IToken mark = mark(); + + ITokenDuple nameDuple = null; + if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON) { + try { + nameDuple = name(); + } 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(null /*ASTPointerOperator.POINTER*/ ); + } + continue; + } + if (nameDuple != null) + nameDuple.freeReferences(); + backup(mark); + return result; + } + } + + + + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression assignmentExpression() + throws EndOfFileException, BacktrackException { + if (LT(1) == IToken.t_throw) { + return throwExpression(); + } + + IASTExpression conditionalExpression = conditionalExpression(); + // 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(IASTBinaryExpression.op_assign, + conditionalExpression); + case IToken.tSTARASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_multiplyAssign, + conditionalExpression); + case IToken.tDIVASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_divideAssign, + conditionalExpression); + case IToken.tMODASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_moduloAssign, + conditionalExpression); + case IToken.tPLUSASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_plusAssign, + conditionalExpression); + case IToken.tMINUSASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_minusAssign, + conditionalExpression); + case IToken.tSHIFTRASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_shiftRightAssign, + conditionalExpression); + case IToken.tSHIFTLASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_shiftLeftAssign, + conditionalExpression); + case IToken.tAMPERASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_binaryAndAssign, + conditionalExpression); + case IToken.tXORASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_binaryXorAssign, + conditionalExpression); + case IToken.tBITORASSIGN: + return assignmentOperatorExpression(IASTBinaryExpression.op_binaryOrAssign, + conditionalExpression); + } + return conditionalExpression; + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression throwExpression() throws EndOfFileException, + BacktrackException { + IToken throwToken = consume(IToken.t_throw); + IASTExpression throwExpression = null; + throwExpression = expression(); + + int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0; + try { + return null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.THROWEXPRESSION, + * throwExpression, null, null, null, null, + * EMPTY_STRING, null); + */ + } /* + * 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 + * @throws BacktrackException + */ + protected IASTExpression relationalExpression() + throws BacktrackException, EndOfFileException { + IToken la = LA(1); + int startingOffset = la.getOffset(); + int line = la.getLineNumber(); + char[] fn = la.getFilename(); + + IASTExpression firstExpression = shiftExpression(); + 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(); + Object secondExpression = shiftExpression(); + if (LA(1) == mark.getNext()) { + // we did not consume anything + // this is most likely an error + backup(mark); + return firstExpression; + } + Object expressionKind = null; + switch (t) { + case IToken.tGT: + expressionKind = null; //IASTExpression.Kind.RELATIONAL_GREATERTHAN; + break; + case IToken.tLT: + expressionKind = null; //IASTExpression.Kind.RELATIONAL_LESSTHAN; + break; + case IToken.tLTEQUAL: + expressionKind = null; //IASTExpression.Kind.RELATIONAL_LESSTHANEQUALTO; + break; + case IToken.tGTEQUAL: + expressionKind = null; //IASTExpression.Kind.RELATIONAL_GREATERTHANEQUALTO; + break; + } + int endOffset = (lastToken != null) ? lastToken.getEndOffset() + : 0; + try { + firstExpression = null; /* + * astFactory.createExpression(scope, + * expressionKind, firstExpression, + * secondExpression, null, null, + * null, EMPTY_STRING, null); } + * catch (ASTSemanticException e) { + * throwBacktrack(e.getProblem()); + */ + } catch (Exception e) { + logException("relationalExpression::createExpression()", e); //$NON-NLS-1$ + throwBacktrack(startingOffset, endOffset, line, fn); + } + break; + default: + if ( supportMinAndMaxOperators + && (LT(1) == IGCCToken.tMIN || LT(1) == IGCCToken.tMAX)) { + IToken m = mark(); + Object k = null; + switch (LT(1)) { + case IGCCToken.tMAX: + consume(); + k = null; //IASTGCCExpression.Kind.RELATIONAL_MAX; + break; + case IGCCToken.tMIN: + consume(); + k = null; //IASTGCCExpression.Kind.RELATIONAL_MIN; + default: + break; + } + IToken next = LA(1); + Object se = shiftExpression(); + if (next == LA(1)) { + backup(m); + return firstExpression; + } + IASTExpression resultExpression = null; + //try { + resultExpression = null; /* + * astFactory.createExpression( + * scope, k, firstExpression, se, + * null, null, null, EMPTY_STRING, + * null ); } catch + * (ASTSemanticException e1) { + * throwBacktrack( e1.getProblem() ); } + */ + return resultExpression; + } + return firstExpression; + } + } + } + + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression multiplicativeExpression() + throws BacktrackException, EndOfFileException { + IToken la = LA(1); + int startingOffset = la.getOffset(); + int line = la.getLineNumber(); + char[] fn = la.getFilename(); + IASTExpression firstExpression = pmExpression(); + for (;;) { + switch (LT(1)) { + case IToken.tSTAR: + case IToken.tDIV: + case IToken.tMOD: + IToken t = consume(); + IASTExpression secondExpression = pmExpression(); + Object expressionKind = null; + switch (t.getType()) { + case IToken.tSTAR: + expressionKind = null; //IASTExpression.Kind.MULTIPLICATIVE_MULTIPLY; + break; + case IToken.tDIV: + expressionKind = null; //IASTExpression.Kind.MULTIPLICATIVE_DIVIDE; + break; + case IToken.tMOD: + expressionKind = null; //IASTExpression.Kind.MULTIPLICATIVE_MODULUS; + break; + } + int endOffset = (lastToken != null) ? lastToken.getEndOffset() + : 0; + try { + firstExpression = null; /* + * astFactory.createExpression(scope, + * expressionKind, firstExpression, + * secondExpression, null, null, + * null, EMPTY_STRING, null); } + * 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() throws EndOfFileException, + BacktrackException { + IToken la = LA(1); + int startingOffset = la.getOffset(); + int line = la.getLineNumber(); + char[] fn = la.getFilename(); + + IASTExpression firstExpression = castExpression(); + for (;;) { + switch (LT(1)) { + case IToken.tDOTSTAR: + case IToken.tARROWSTAR: + IToken t = consume(); + Object secondExpression = castExpression(); + int endOffset = (lastToken != null) ? lastToken.getEndOffset() + : 0; + try { + firstExpression = null; /* + * astFactory.createExpression(scope, + * ((t.getType() == IToken.tDOTSTAR) ? + * IASTExpression.Kind.PM_DOTSTAR : + * IASTExpression.Kind.PM_ARROWSTAR), + * firstExpression, + * secondExpression, null, null, + * null, EMPTY_STRING, null); } + * 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() 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; + Object typeId = null; + // If this isn't a type name, then we shouldn't be here + try { + try { + typeId = typeId(false); + consume(IToken.tRPAREN); + } catch (BacktrackException bte) { + backup(mark); + // if (typeId != null) + // typeId.freeReferences(); + throwBacktrack(bte); + } + + if (templateIdScopes.size() > 0) { + templateIdScopes.pop(); + popped = true; + } + Object castExpression = castExpression(); + // if( castExpression != null && + // castExpression.getExpressionKind() == + // IASTExpression.Kind.PRIMARY_EMPTY ) + // { + // backup( mark ); + // if (typeId != null) + // typeId.freeReferences(); + // return unaryExpression(scope); + // } + int endOffset = (lastToken != null) ? lastToken.getEndOffset() + : 0; + mark = null; // clean up mark so that we can garbage collect + try { + return null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.CASTEXPRESSION, + * castExpression, null, null, typeId, null, + * EMPTY_STRING, null); } 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(); + + } + + /** + * @throws BacktrackException + */ + protected IASTTypeId typeId(boolean skipArrayModifiers) + 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; + + boolean encountered = false; + Object kind = null; + do { + try { + name = name(); + kind = null; //IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; + encountered = true; + 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(); + kind = null; //IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; + encountered = true; + break; + + case IToken.t_int: + if (encounteredType) + break simpleMods; + encounteredType = true; + kind = null; //IASTSimpleTypeSpecifier.Type.INT; + encountered = true; + consume(); + break; + + case IToken.t_char: + if (encounteredType) + break simpleMods; + encounteredType = true; + kind = null; //IASTSimpleTypeSpecifier.Type.CHAR; + encountered = true; + consume(); + break; + + case IToken.t_bool: + if (encounteredType) + break simpleMods; + encounteredType = true; + kind = null; //IASTSimpleTypeSpecifier.Type.BOOL; + encountered = true; + consume(); + break; + + case IToken.t_double: + if (encounteredType) + break simpleMods; + encounteredType = true; + kind = null; //IASTSimpleTypeSpecifier.Type.DOUBLE; + encountered = true; + consume(); + break; + + case IToken.t_float: + if (encounteredType) + break simpleMods; + encounteredType = true; + kind = null; //IASTSimpleTypeSpecifier.Type.FLOAT; + encountered = true; + consume(); + break; + + case IToken.t_wchar_t: + if (encounteredType) + break simpleMods; + encounteredType = true; + kind = null; //IASTSimpleTypeSpecifier.Type.WCHAR_T; + encountered = true; + consume(); + break; + + case IToken.t_void: + if (encounteredType) + break simpleMods; + encounteredType = true; + kind = null; //IASTSimpleTypeSpecifier.Type.VOID; + encountered = true; + consume(); + break; + + case IToken.t__Bool: + if (encounteredType) + break simpleMods; + encounteredType = true; + kind = null; //IASTSimpleTypeSpecifier.Type._BOOL; + encountered = true; + consume(); + break; + + default: + break simpleMods; + } + } + + if (encountered) + break; + + if (isShort || isLong || isUnsigned || isSigned) { + encountered = true; + kind = null; //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(); + kind = null; //IASTSimpleTypeSpecifier.Type.CLASS_OR_TYPENAME; + encountered = true; + } catch (BacktrackException b) { + backup(mark); + throwBacktrack(b); + } + } + + } while (false); + + int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0; + if (! encountered ) + throwBacktrack(mark.getOffset(), endOffset, mark.getLineNumber(), + mark.getFilename()); + +// TypeId id = getTypeIdInstance(); + IToken last = lastToken; + IToken temp = last; + + //template parameters are consumed as part of name + //lastToken = consumeTemplateParameters( last ); + //if( lastToken == null ) lastToken = last; + + temp = consumePointerOperators(null); + if (temp != null) + last = temp; + + if (!skipArrayModifiers) { + temp = consumeArrayModifiers(null); + 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 null; /* + * 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 expression + * @throws BacktrackException + */ + protected IASTExpression deleteExpression() 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; + } + Object castExpression = castExpression(); + int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0; + try { + return null; /* + * astFactory.createExpression(scope, (vectored ? + * IASTExpression.Kind.DELETE_VECTORCASTEXPRESSION : + * IASTExpression.Kind.DELETE_CASTEXPRESSION), + * castExpression, null, null, null, null, + * EMPTY_STRING, null); } 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() throws BacktrackException, + EndOfFileException { + 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; + Object 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()); + 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(true); + 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(true); + } 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(true); + 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 { + return null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.NEW_TYPEID, + * null, null, null, typeId, null, + * EMPTY_STRING, + * astFactory.createNewDescriptor( + * newPlacementExpressions, + * newTypeIdExpressions, + * newInitializerExpressions)); } + * 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(true); + } + while (LT(1) == IToken.tLBRACKET) { + // array new + consume(); + + if (templateIdScopes.size() > 0) { + templateIdScopes.push(IToken.tLBRACKET); + } + + newTypeIdExpressions.add(assignmentExpression()); + consume(IToken.tRBRACKET); + + if (templateIdScopes.size() > 0) { + templateIdScopes.pop(); + } + } + // newinitializer + if (LT(1) == IToken.tLPAREN) { + consume(IToken.tLPAREN); + 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()); + + consume(IToken.tRPAREN); + if (templateIdScopes.size() > 0) { + templateIdScopes.pop(); + } + } + int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0; + try { + return null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.NEW_TYPEID, null, null, null, + * typeId, null, EMPTY_STRING, + * astFactory.createNewDescriptor( + * newPlacementExpressions, newTypeIdExpressions, + * newInitializerExpressions)); } 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 + */ + protected IASTExpression unaryExpression() 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: + return unaryOperatorCastExpression(IASTUnaryExpression.op_star );//IASTExpression.Kind.UNARY_STAR_CASTEXPRESSION); + case IToken.tAMPER: + return unaryOperatorCastExpression(IASTUnaryExpression.op_amper);//IASTExpression.Kind.UNARY_AMPSND_CASTEXPRESSION); + case IToken.tPLUS: + return unaryOperatorCastExpression(IASTUnaryExpression.op_plus );//IASTExpression.Kind.UNARY_PLUS_CASTEXPRESSION); + case IToken.tMINUS: + return unaryOperatorCastExpression(IASTUnaryExpression.op_minus );//IASTExpression.Kind.UNARY_MINUS_CASTEXPRESSION); + case IToken.tNOT: + return unaryOperatorCastExpression(IASTUnaryExpression.op_not );//IASTExpression.Kind.UNARY_NOT_CASTEXPRESSION); + case IToken.tCOMPL: + return unaryOperatorCastExpression(IASTUnaryExpression.op_tilde);//IASTExpression.Kind.UNARY_TILDE_CASTEXPRESSION); + case IToken.tINCR: + return unaryOperatorCastExpression(IASTUnaryExpression.op_prefixIncr);//IASTExpression.Kind.UNARY_INCREMENT); + case IToken.tDECR: + return unaryOperatorCastExpression(IASTUnaryExpression.op_prefixDecr);//IASTExpression.Kind.UNARY_DECREMENT); + case IToken.t_sizeof: + consume(IToken.t_sizeof); + IToken mark = LA(1); + Object d = null; + Object unaryExpression = null; + if (LT(1) == IToken.tLPAREN) { + try { + consume(IToken.tLPAREN); + d = typeId(false); + consume(IToken.tRPAREN); + } catch (BacktrackException bt) { + backup(mark); + unaryExpression = unaryExpression(); + } + } else { + unaryExpression = unaryExpression(); + } + int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0; + if (unaryExpression == null) + try { + return null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.UNARY_SIZEOF_TYPEID, + * null, null, null, d, null, EMPTY_STRING, + * null); } catch (ASTSemanticException e) { + * throwBacktrack(e.getProblem()); + */ + } catch (Exception e) { + logException("unaryExpression_1::createExpression()", e); //$NON-NLS-1$ + throwBacktrack(startingOffset, endOffset, line, fn); + } + try { + return null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.UNARY_SIZEOF_UNARYEXPRESSION, + * unaryExpression, null, null, null, null, + * EMPTY_STRING, null); } 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(); + case IToken.t_delete: + return deleteExpression(); + case IToken.tCOLONCOLON: + switch (LT(2)) { + case IToken.t_new: + return newExpression(); + case IToken.t_delete: + return deleteExpression(); + default: + return postfixExpression(); + } + default: + if (LT(1) == IGCCToken.t_typeof && supportTypeOfUnaries) { + IASTExpression unary = unaryTypeofExpression(); + if (unary != null) + return unary; + } + if (LT(1) == IGCCToken.t___alignof__ && supportAlignOfUnaries) { + IASTExpression align = unaryAlignofExpression(); + if (align != null) + return align; + } + return postfixExpression(); + } + } + + /** + * @param expression + * @throws BacktrackException + */ + protected IASTExpression postfixExpression() 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; + + 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(); + + consume(IToken.tLPAREN); + if (templateIdScopes.size() > 0) { + templateIdScopes.push(IToken.tLPAREN); + } + Object expressionList = expression(); + int endOffset = consume(IToken.tRPAREN).getEndOffset(); + if (templateIdScopes.size() > 0) { + templateIdScopes.pop(); + } + + try { + firstExpression = null; /* + * astFactory .createExpression( scope, + * (templateTokenConsumed ? + * IASTExpression.Kind.POSTFIX_TYPENAME_TEMPLATEID : + * IASTExpression.Kind.POSTFIX_TYPENAME_IDENTIFIER), + * expressionList, null, null, null, + * nestedName, EMPTY_STRING, null); } + * 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(null );//IASTExpression.Kind.POSTFIX_SIMPLETYPE_CHAR); + break; + case IToken.t_wchar_t: + firstExpression = simpleTypeConstructorExpression(null );//IASTExpression.Kind.POSTFIX_SIMPLETYPE_WCHART); + break; + case IToken.t_bool: + firstExpression = simpleTypeConstructorExpression(null );//IASTExpression.Kind.POSTFIX_SIMPLETYPE_BOOL); + break; + case IToken.t_short: + firstExpression = simpleTypeConstructorExpression(null );//IASTExpression.Kind.POSTFIX_SIMPLETYPE_SHORT); + break; + case IToken.t_int: + firstExpression = simpleTypeConstructorExpression(null );//IASTExpression.Kind.POSTFIX_SIMPLETYPE_INT); + break; + case IToken.t_long: + firstExpression = simpleTypeConstructorExpression(null );//IASTExpression.Kind.POSTFIX_SIMPLETYPE_LONG); + break; + case IToken.t_signed: + firstExpression = simpleTypeConstructorExpression(null );//IASTExpression.Kind.POSTFIX_SIMPLETYPE_SIGNED); + break; + case IToken.t_unsigned: + firstExpression = simpleTypeConstructorExpression(null );//IASTExpression.Kind.POSTFIX_SIMPLETYPE_UNSIGNED); + break; + case IToken.t_float: + firstExpression = simpleTypeConstructorExpression(null );//IASTExpression.Kind.POSTFIX_SIMPLETYPE_FLOAT); + break; + case IToken.t_double: + firstExpression = simpleTypeConstructorExpression(null );//IASTExpression.Kind.POSTFIX_SIMPLETYPE_DOUBLE); + break; + case IToken.t_dynamic_cast: + firstExpression = specialCastExpression(null );//IASTExpression.Kind.POSTFIX_DYNAMIC_CAST); + break; + case IToken.t_static_cast: + firstExpression = specialCastExpression(null );//IASTExpression.Kind.POSTFIX_STATIC_CAST); + break; + case IToken.t_reinterpret_cast: + firstExpression = specialCastExpression(null );//IASTExpression.Kind.POSTFIX_REINTERPRET_CAST); + break; + case IToken.t_const_cast: + firstExpression = specialCastExpression(null );//IASTExpression.Kind.POSTFIX_CONST_CAST); + break; + case IToken.t_typeid: + consume(); + consume(IToken.tLPAREN); + if (templateIdScopes.size() > 0) { + templateIdScopes.push(IToken.tLPAREN); + } + boolean isTypeId = true; + Object lhs = null; + Object typeId = null; + try { + typeId = typeId(false); + } catch (BacktrackException b) { + isTypeId = false; + lhs = expression(); + } + endOffset = consume(IToken.tRPAREN).getEndOffset(); + if (templateIdScopes.size() > 0) { + templateIdScopes.pop(); + } + try { + firstExpression = null; /* + * astFactory .createExpression( scope, + * (isTypeId ? + * IASTExpression.Kind.POSTFIX_TYPEID_TYPEID : + * IASTExpression.Kind.POSTFIX_TYPEID_EXPRESSION), + * lhs, null, null, typeId, null, + * EMPTY_STRING, null); } 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(); + } + 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(); + int endOffset = consume(IToken.tRBRACKET).getEndOffset(); + if (templateIdScopes.size() > 0) { + templateIdScopes.pop(); + } + try { + firstExpression = null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.POSTFIX_SUBSCRIPT, + * firstExpression, + * secondExpression, null, null, + * null, EMPTY_STRING, null); } + * 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); + + if (templateIdScopes.size() > 0) { + templateIdScopes.push(IToken.tLPAREN); + } + secondExpression = expression(); + endOffset = consume(IToken.tRPAREN).getEndOffset(); + if (templateIdScopes.size() > 0) { + templateIdScopes.pop(); + } + try { + firstExpression = null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.POSTFIX_FUNCTIONCALL, + * firstExpression, + * secondExpression, null, null, + * null, EMPTY_STRING, null); } + * 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 = null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.POSTFIX_INCREMENT, + * firstExpression, null, null, + * null, null, EMPTY_STRING, null); } + * 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 = null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.POSTFIX_DECREMENT, + * firstExpression, null, null, + * null, null, EMPTY_STRING, null); } + * 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 (LT(1) == IToken.t_template) { + consume(IToken.t_template); + isTemplate = true; + } + + Object memberCompletionKind = null; /*(isTemplate ? IASTExpression.Kind.POSTFIX_DOT_TEMPL_IDEXPRESS + : IASTExpression.Kind.POSTFIX_DOT_IDEXPRESSION); */ + + secondExpression = primaryExpression(); + 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 = null; /* + * astFactory.createExpression(scope, + * memberCompletionKind, + * firstExpression, + * secondExpression, null, null, + * null, EMPTY_STRING, null); } + * 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 (LT(1) == IToken.t_template) { + consume(IToken.t_template); + isTemplate = true; + } + + Object arrowCompletionKind = /*(isTemplate ? IASTExpression.Kind.POSTFIX_ARROW_TEMPL_IDEXP + : IASTExpression.Kind.POSTFIX_ARROW_IDEXPRESSION); */ null; + + secondExpression = primaryExpression(); + 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 = null; /* + * astFactory.createExpression(scope, + * arrowCompletionKind, + * firstExpression, + * secondExpression, null, null, + * null, EMPTY_STRING, null); } + * 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; + } + } + } + + protected IASTExpression simpleTypeConstructorExpression(Object type) + throws EndOfFileException, BacktrackException { + IToken la = LA(1); + int startingOffset = la.getOffset(); + int line = la.getLineNumber(); + char[] fn = la.getFilename(); + la = null; + consume(); + consume(IToken.tLPAREN); + IASTExpression inside = expression(); + int endOffset = consume(IToken.tRPAREN).getEndOffset(); + try { + return null; /* + * astFactory.createExpression(scope, type, inside, + * null, null, null, null, EMPTY_STRING, null); } 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() throws EndOfFileException, + BacktrackException { + IToken t = null; + switch (LT(1)) { + // TO DO: we need more literals... + case IToken.tINTEGER: + t = consume(); + try { + return null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.PRIMARY_INTEGER_LITERAL, + * null, null, null, null, null, t.getCharImage(), + * null); } 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 null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.PRIMARY_FLOAT_LITERAL, null, + * null, null, null, null, t.getCharImage(), null); } + * 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 null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.PRIMARY_STRING_LITERAL, + * null, null, null, null, null, t.getCharImage(), + * null); } 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 null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.PRIMARY_BOOLEAN_LITERAL, + * null, null, null, null, null, t.getCharImage(), + * null); } 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 null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.PRIMARY_CHAR_LITERAL, null, + * null, null, null, null, t.getCharImage(), null); } + * 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 null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.PRIMARY_THIS, null, null, + * null, null, null, EMPTY_STRING, null); } 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: + t = consume(); + if (templateIdScopes.size() > 0) { + templateIdScopes.push(IToken.tLPAREN); + } + IASTExpression lhs = expression(); + int endOffset = consume(IToken.tRPAREN).getEndOffset(); + if (templateIdScopes.size() > 0) { + templateIdScopes.pop(); + } + try { + return null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.PRIMARY_BRACKETED_EXPRESSION, + * lhs, null, null, null, null, EMPTY_STRING, + * null); } 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(); + } 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(null /*d*/, start, null); + else { + backup(mark); + throwBacktrack(startingOffset, end.getEndOffset(), end + .getLineNumber(), t.getFilename()); + } + } else if (LT(1) == IToken.t_operator) + operatorId(/*d*/null, null, null); + + duple = null; /*d.getNameDuple();*/ + } + + endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0; + try { + return null; /* + * astFactory.createExpression(scope, + * IASTExpression.Kind.ID_EXPRESSION, null, null, + * null, null, duple, EMPTY_STRING, null); } 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(); + throwBacktrack(startingOffset, startingOffset, line, fn); + return null; + } + + } + + protected IASTExpression specialCastExpression(Object kind) throws EndOfFileException, + BacktrackException { + IToken la = LA(1); + int startingOffset = la.getOffset(); + int line = la.getLineNumber(); + char[] fn = la.getFilename(); + la = null; + + consume(); + consume(IToken.tLT); + Object typeID = typeId(false); + consume(IToken.tGT); + consume(IToken.tLPAREN); + Object lhs = expression(); + int endOffset = consume(IToken.tRPAREN).getEndOffset(); + try { + return null; /* + * astFactory.createExpression(scope, kind, lhs, null, + * null, duple, null, EMPTY_STRING, null); } catch + * (ASTSemanticException e) { + * throwBacktrack(e.getProblem()); + */ + } catch (Exception e) { + logException("specialCastExpression::createExpression()", e); //$NON-NLS-1$ + throwBacktrack(startingOffset, endOffset, line, fn); + } + return null; + } + + private final boolean allowCPPRestrict; + + + private final boolean supportExtendedTemplateSyntax; + private final boolean supportMinAndMaxOperators; + + /** + * This is the standard cosntructor that we expect the Parser to be + * instantiated with. + * @param mode + * TODO + * + */ + public GNUCPPSourceParser(IScanner scanner, ParserMode mode, + IProblemRequestor callback, IParserLogService log, + ICPPParserExtensionConfiguration config) { + super( scanner, log, mode, callback, config.supportStatementsInExpressions(), + config.supportTypeofUnaryExpressions(), config.supportAlignOfUnaryExpression() ); + allowCPPRestrict = config.allowRestrictPointerOperators(); + supportExtendedTemplateSyntax = config + .supportExtendedTemplateSyntax(); + supportMinAndMaxOperators = config.supportMinAndMaxOperators(); + } + + + /** + * 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 Object usingClause(Object scope) throws EndOfFileException, + BacktrackException { + IToken firstToken = consume(IToken.t_using); + + if (LT(1) == IToken.t_namespace) { + // using-directive + consume(IToken.t_namespace); + + // 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(); + else + throwBacktrack(firstToken.getOffset(), endOffset, firstToken + .getLineNumber(), firstToken.getFilename()); + if (LT(1) == IToken.tSEMI) { + IToken last = consume(IToken.tSEMI); + Object astUD = null; + + try { + astUD = null; /* + * 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; + + if (LT(1) == IToken.t_typename) { + typeName = true; + consume(IToken.t_typename); + } + + ITokenDuple name = null; + if (LT(1) == IToken.tIDENTIFIER || LT(1) == IToken.tCOLONCOLON) { + // optional :: and nested classes handled in name + name = name(); + } else { + throwBacktrack(firstToken.getOffset(), + (lastToken != null) ? lastToken.getEndOffset() : 0, + firstToken.getLineNumber(), firstToken.getFilename()); + } + if (LT(1) == IToken.tSEMI) { + IToken last = consume(IToken.tSEMI); + Object declaration = null; + try { + declaration = null; /* + * 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 ); + 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 Object linkageSpecification(Object 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); + Object linkage = null; + try { + linkage = null; /* + * 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); + } 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; + Object linkage; + try { + linkage = null; /* + * 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); + } 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 Object templateDeclaration(Object 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 (supportExtendedTemplateSyntax) { + switch (LT(1)) { + case IToken.t_static: + case IToken.t_extern: + case IToken.t_inline: + firstToken = consume(); + consume(IToken.t_template); + break; + default: + firstToken = consume(IToken.t_template); + break; + } + } else + firstToken = consume(IToken.t_template); + } + if (LT(1) != IToken.tLT) { + // explicit-instantiation + Object templateInstantiation; + try { + templateInstantiation = null; /* + * 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); + // 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 + + Object templateSpecialization; + try { + templateSpecialization = null; /* + * 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); + // templateSpecialization.setEndingOffsetAndLineNumber( + // lastToken.getEndOffset(), lastToken.getLineNumber()); + } finally { + // templateSpecialization.exitScope(requestor); + } + return templateSpecialization; + } + + try { + List parms = templateParameterList(scope); + IToken gt = consume(IToken.tGT); + Object templateDecl; + try { + templateDecl = null; /* + * 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); + // 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(Object 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(); + + Object parameterScope = null; /* 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) { + consume(); +// IASTTemplateParameter.ParamKind kind = (consume().getType() == IToken.t_class) ? IASTTemplateParameter.ParamKind.CLASS +// : IASTTemplateParameter.ParamKind.TYPENAME; + IToken startingToken = lastToken; + IToken id = null; + Object 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(false); // 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(null /* + * 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; + Object optionalTypeId = null; + if (LT(1) == IToken.tIDENTIFIER) // optional identifier + { + optionalId = identifier(); + + if (LT(1) == IToken.tASSIGN) // optional = type-id + { + consume(IToken.tASSIGN); + optionalTypeId = typeId(false); + + } + } + + try { + returnValue + .add(null /* + * 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(null + /* + * 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.startingOffset, wrapper.startingLine, + * declarator.getNameStartOffset(), + * declarator.getNameEndOffset(), declarator.getNameLine(), + * wrapper.endOffset, wrapper.endLine, fn ), null, ( + * parameterScope instanceof IASTCodeScope ) ? + * (IASTCodeScope) parameterScope : null, + * wrapper.startingOffset, wrapper.startingLine, + * declarator.getNameStartOffset(), + * declarator.getNameEndOffset(), declarator.getNameLine(), + * wrapper.endOffset, wrapper.endLine, 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 container + * IParserCallback object which serves as the owner scope for + * this declaration. + * + * @throws BacktrackException + * request a backtrack + */ + protected void declaration(Object scope, Object ownerTemplate) + throws EndOfFileException, BacktrackException { + switch (LT(1)) { + case IToken.t_asm: + IToken first = consume(IToken.t_asm); + consume(IToken.tLPAREN); + char[] assembly = consume(IToken.tSTRING).getCharImage(); + consume(IToken.tRPAREN); + IToken last = consume(IToken.tSEMI); + + try { + // 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); + break; + case IToken.t_namespace: + namespaceDefinition(scope); + break; + case IToken.t_using: + usingClause(scope); + break; + case IToken.t_export: + case IToken.t_template: + templateDeclaration(scope); + break; + case IToken.t_extern: + if (LT(2) == IToken.tSTRING) { + linkageSpecification(scope); + break; + } + default: + if (supportExtendedTemplateSyntax + && (LT(1) == IToken.t_static || LT(1) == IToken.t_inline || LT(1) == IToken.t_extern) + && LT(2) == IToken.t_template) + templateDeclaration(scope); + else + simpleDeclarationStrategyUnion(scope, ownerTemplate); + } + + cleanupLastToken(); + } + + protected Object simpleDeclarationStrategyUnion(Object scope, + Object ownerTemplate) throws EndOfFileException, BacktrackException { + simpleDeclarationMark = mark(); + IProblem firstFailure = null; + IProblem secondFailure = null; + try { + return simpleDeclaration(SimpleDeclarationStrategy.TRY_CONSTRUCTOR, + ownerTemplate, false); + // 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, ownerTemplate, + false); + } 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, ownerTemplate, + false); + } 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 Object namespaceDefinition(Object scope) + throws BacktrackException, EndOfFileException { + IToken first = consume(IToken.t_namespace); + + IToken identifier = null; + // optional name + if (LT(1) == IToken.tIDENTIFIER) + identifier = identifier(); + + if (LT(1) == IToken.tLBRACE) { + IToken lbrace = consume(); + Object namespaceDefinition = null; + try { + namespaceDefinition = null; /* + * 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 { + cleanupLastToken(); + 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); + } catch (BacktrackException bt) { + failParse(bt); + if (checkToken == LA(1).hashCode()) + failParseWithErrorHandling(); + } + } + if (checkToken == LA(1).hashCode()) + failParseWithErrorHandling(); + } + // consume the } + IToken last = consume(IToken.tRBRACE); + + // namespaceDefinition.setEndingOffsetAndLineNumber( + // last.getOffset() + last.getLength(), last.getLineNumber()); + } finally { + // namespaceDefinition.exitScope( requestor ); + } + return namespaceDefinition; + } else if (LT(1) == IToken.tASSIGN) { + IToken assign = consume(IToken.tASSIGN); + + if (identifier == null) { + throwBacktrack(first.getOffset(), assign.getEndOffset(), first + .getLineNumber(), first.getFilename()); + return null; + } + + ITokenDuple duple = name(); + IToken semi = consume(IToken.tSEMI); + + Object alias = null; + try { + alias = null; /* + * 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 Object simpleDeclaration(SimpleDeclarationStrategy strategy, + Object ownerTemplate, boolean fromCatchHandler) + 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(null, firstToken + .getOffset(), firstToken.getLineNumber(), ownerTemplate, fn); + firstToken = null; // necessary for scalability + + declSpecifierSeq(sdw, false, + strategy == SimpleDeclarationStrategy.TRY_CONSTRUCTOR); + Object simpleTypeSpecifier = null; + if (sdw.getTypeSpecifier() == null + && sdw.getSimpleType() != null ) //IASTSimpleTypeSpecifier.Type.UNSPECIFIED) + try { + simpleTypeSpecifier = null; /* + * 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); + } + + Declarator declarator = null; + if (LT(1) != IToken.tSEMI) { + declarator = initDeclarator(sdw, strategy ); + + while (LT(1) == IToken.tCOMMA) { + consume(); + initDeclarator(sdw, strategy ); + } + } + + 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; + + if( hasFunctionBody ) + handleFunctionBody( ); + + if (hasFunctionTryBlock) + catchHandlerSequence(); + +// try { +// l = sdw.createASTNodes(); +//// } catch (ASTSemanticException e) { +//// if (e.getProblem() == null) { +//// IProblem p = problemFactory.createProblem( +//// IProblem.SYNTAX_ERROR, sdw.startingOffset, +//// lastToken != null ? lastToken.getEndOffset() : 0, +//// sdw.startingLine, 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) { +// Object declaration = null; +// for (int i = 0; i < l.size(); ++i) { +// declaration = l.get(i); +// +//// ((IASTOffsetableElement) declaration) +//// .setEndingOffsetAndLineNumber(lastToken +//// .getEndOffset(), lastToken +//// .getLineNumber()); +// // declaration.acceptElement( requestor ); +// } +// return declaration; +// } +// Object declaration = l.get(0); +// cleanupLastToken(); +// // declaration.enterScope( requestor ); +// try { +// // if ( !( declaration instanceof IASTScope ) ) +// // throwBacktrack(firstOffset, endOffset, firstLine, fn); +// +// handleFunctionBody(declaration); +// +//// ((IASTOffsetableElement) declaration) +//// .setEndingOffsetAndLineNumber(lastToken +//// .getEndOffset(), lastToken +//// .getLineNumber()); +// } finally { +// // declaration.exitScope( requestor ); +// } +// +// if (hasFunctionTryBlock) +// catchHandlerSequence(scope); +// +// return declaration; +// +// } +// +// try { +// if (sdw.getTypeSpecifier() != null) { +// Object declaration = null; /* +// * astFactory.createTypeSpecDeclaration( +// * sdw.getScope(), +// * sdw.getTypeSpecifier(), +// * ownerTemplate, +// * sdw.startingOffset, +// * sdw.startingLine, +// * 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; + return null; + } + + /** + * 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(); + Object scope = d.getDeclarationWrapper().getScope(); + scope = null; /* astFactory.getDeclaratorScope(scope, d.getNameDuple()); */ + for (;;) { + if (LT(1) == IToken.tLBRACE) + break; + + ITokenDuple duple = name(); + + consume(IToken.tLPAREN); + Object expressionList = null; + + if (LT(1) != IToken.tRPAREN) + expressionList = expression(); + + IToken rparen = consume(IToken.tRPAREN); + + try { + d + .addConstructorMemberInitializer(null /* + * 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); + } + + } + + + /** + * 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, + Object scope) throws BacktrackException, EndOfFileException { + IToken current = LA(1); + + DeclarationWrapper sdw = new DeclarationWrapper(scope, current + .getOffset(), current.getLineNumber(), null, current + .getFilename()); + declSpecifierSeq(sdw, true, false); + if (sdw.getTypeSpecifier() == null + && sdw.getSimpleType() != null )//IASTSimpleTypeSpecifier.Type.UNSPECIFIED) + try { + sdw.setTypeSpecifier(null /* + * 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()); + } + + if (LT(1) != IToken.tSEMI) + initDeclarator(sdw, SimpleDeclarationStrategy.TRY_FUNCTION); + + 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); + } + + /** + * @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) throws EndOfFileException { + if (flags.isForParameterDeclaration()) + return false; + if (LT(2) == IToken.tLPAREN + && flags.isForConstructor()) + return true; + + IToken mark = mark(); + Declarator d = new Declarator(sdw); + try { + consumeTemplatedOperatorName(d); + } 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; + } + + ITokenDuple leadingSegments = duple.getLeadingSegments(); + if (leadingSegments == null) { + backup(mark); + return false; + } + ITokenDuple lastSegment = duple.getLastSegment(); + char[] className = lastSegment.extractNameFromTemplateId(); + if (className == null || CharArrayUtils.equals(className, EMPTY_STRING)) { + backup(mark); + return false; + } + + ITokenDuple secondlastSegment = leadingSegments.getLastSegment(); + if (secondlastSegment == null) { + backup(mark); + return false; + } + char[] otherName = secondlastSegment.extractNameFromTemplateId(); + if (otherName == null || CharArrayUtils.equals(otherName, EMPTY_STRING)) { + backup(mark); + return false; + } + + if( lastSegment.isConversion() ) + { + backup( mark ); + return true; + } + + if (CharArrayUtils.equals(className, otherName)) { + backup(mark); + return true; + } + + backup(mark); + return false; + } + + /** + * 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 parm + * Is this for a parameter declaration (true) or simple + * declaration (false) + * @param tryConstructor + * true for constructor, false for pointer to function strategy + * @param decl + * IParserCallback object representing the declaration that owns + * this specifier sequence + * + * @throws BacktrackException + * request a backtrack + */ + protected void declSpecifierSeq(DeclarationWrapper sdw, boolean parm, + boolean tryConstructor) 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(null);//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(null);//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(null);//IASTSimpleTypeSpecifier.Type.INT); + break; + case IToken.t_long: + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + flags.setEncounteredRawType(true); + consume(); + sdw.setSimpleType(null);//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(null);//IASTSimpleTypeSpecifier.Type.CHAR); + break; + case IToken.t_wchar_t: + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + flags.setEncounteredRawType(true); + consume(); + sdw.setSimpleType(null);//IASTSimpleTypeSpecifier.Type.WCHAR_T); + break; + case IToken.t_bool: + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + flags.setEncounteredRawType(true); + consume(); + sdw.setSimpleType(null);//IASTSimpleTypeSpecifier.Type.BOOL); + break; + case IToken.t__Bool: + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + flags.setEncounteredRawType(true); + consume(); + sdw.setSimpleType(null);//IASTSimpleTypeSpecifier.Type._BOOL); + break; + case IToken.t_int: + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + flags.setEncounteredRawType(true); + consume(); + sdw.setSimpleType(null);//IASTSimpleTypeSpecifier.Type.INT); + break; + case IToken.t_float: + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + flags.setEncounteredRawType(true); + consume(); + sdw.setSimpleType(null);//IASTSimpleTypeSpecifier.Type.FLOAT); + break; + case IToken.t_double: + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + flags.setEncounteredRawType(true); + consume(); + sdw.setSimpleType(null);//IASTSimpleTypeSpecifier.Type.DOUBLE); + break; + case IToken.t_void: + if (typeNameBegin == null) + typeNameBegin = LA(1); + typeNameEnd = LA(1); + flags.setEncounteredRawType(true); + consume(); + sdw.setSimpleType(null);//IASTSimpleTypeSpecifier.Type.VOID); + break; + case IToken.t_typename: + sdw.setTypenamed(true); + consume(IToken.t_typename); + ITokenDuple duple = name(); + sdw.setTypeName(duple); + sdw + .setSimpleType(null);//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)) { + setTypeName(sdw, typeNameBegin, typeNameEnd); + return; + } + if (lookAheadForDeclarator(flags)) { + setTypeName(sdw, typeNameBegin, typeNameEnd); + return; + } + + ITokenDuple d = name(); + sdw.setTypeName(d); + sdw + .setSimpleType(null);//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 (supportTypeOfUnaries && LT(1) == IGCCToken.t_typeof) { + IToken start = LA(1); + Object expression = unaryTypeofExpression(); + if (expression != null) { + flags.setEncounteredTypename(true); + if (typeNameBegin == null) + typeNameBegin = start; + typeNameEnd = lastToken; + } + } + break declSpecifiers; + } + } + setTypeName(sdw, typeNameBegin, typeNameEnd); + return; + } + + /** + * 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(); + Object eck = null; + + switch (t.getType()) { + case IToken.t_class: + eck = null; //ASTClassKind.CLASS; + break; + case IToken.t_struct: + eck = null; //ASTClassKind.STRUCT; + break; + case IToken.t_union: + eck = null; //ASTClassKind.UNION; + break; + case IToken.t_enum: + eck = null; //ASTClassKind.ENUM; + break; + default: + backup(t); + throwBacktrack(t.getOffset(), t.getEndOffset(), t.getLineNumber(), + t.getFilename()); + } + + ITokenDuple d = name(); + Object elaboratedTypeSpec = null; + final boolean isForewardDecl = (LT(1) == IToken.tSEMI); + + try { + elaboratedTypeSpec = null; /* + * 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 ) + throws EndOfFileException, BacktrackException { + Declarator d = declarator(sdw, sdw.getScope(), strategy); + + try { + // astFactory.constructExpressions(constructInitializers); + optionalCPPInitializer(d ); +// else if (language == ParserLanguage.C) +// optionalCInitializer(d ); + sdw.addDeclarator(d); + return d; + } finally { + // astFactory.constructExpressions(true); + } + } + + protected void optionalCPPInitializer(Declarator d) throws EndOfFileException, + BacktrackException { + // handle initializer + Object scope = d.getDeclarationWrapper().getScope(); + + if (LT(1) == IToken.tASSIGN) { + consume(IToken.tASSIGN); + throwAwayMarksForInitializerClause(d); + try { + Object clause = initializerClause(scope); + d.setInitializerClause(clause); + } catch (EndOfFileException eof) { + failParse(); + throw eof; + } + } else if (LT(1) == IToken.tLPAREN) { + // initializer in constructor + consume(IToken.tLPAREN); // EAT IT! + Object astExpression = null; + astExpression = expression(); + consume(IToken.tRPAREN); + d.setConstructorExpression(astExpression); + } + } + + /** + * + */ + protected Object initializerClause(Object scope ) 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 null; + } 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 (;;) { + Object clause = initializerClause(scope ); + 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 null; + } 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; + + Object assignmentExpression = assignmentExpression(); + int endOffset = (lastToken != null) ? lastToken.getEndOffset() : 0; + try { + return null; + } catch (Exception e) { + logException("initializerClause_3:createInitializerClause", e); //$NON-NLS-1$ + } + throwBacktrack(startingOffset, endOffset, line, fn); + return null; + } + + + /** + * 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, Object scope, + SimpleDeclarationStrategy strategy) 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); + consume(IToken.tRPAREN); + } else + consumeTemplatedOperatorName(d); + + for (;;) { + switch (LT(1)) { + case IToken.tLPAREN: + + boolean failed = false; + Object parameterScope = null; /*astFactory + .getDeclaratorScope(scope, d.getNameDuple()); */ + // temporary fix for initializer/function declaration + // ambiguity + if ( !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(); + 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 ((!LA(2).looksLikeExpression() + && strategy != SimpleDeclarationStrategy.TRY_VARIABLE && !failed) + ) { + // parameterDeclarationClause + d.setIsFunction(true); + // TODO need to create a temporary scope object here + consume(IToken.tLPAREN); + boolean seenParameter = false; + parameterDeclarationLoop: for (;;) { + switch (LT(1)) { + case IToken.tRPAREN: + consume(); + break parameterDeclarationLoop; + case IToken.tELLIPSIS: + consume(); + d.setIsVarArgs(true); + break; + case IToken.tCOMMA: + consume(); + 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; + Object exceptionTypeId = null; + while (!done) { + switch (LT(1)) { + case IToken.tRPAREN: + consume(); + done = true; + break; + case IToken.tCOMMA: + consume(); + break; + default: + try { + exceptionTypeId = typeId(false); + exceptionSpecIds.add(exceptionTypeId); + // exceptionTypeId + // .acceptElement( + // requestor); + } catch (BacktrackException e) { + failParse(e); + consume(); + // eat this token anyway + continue; + } + break; + } + } + if (exceptionSpecIds != null) + try { + d.setExceptionSpecification(null /*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); + continue; + case IToken.tCOLON: + consume(IToken.tCOLON); + Object exp = constantExpression(); + 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) + throws EndOfFileException, BacktrackException { + TemplateParameterManager argumentList = TemplateParameterManager + .getInstance(); + try { + if (LT(1) == IToken.t_operator) + operatorId(d, null, null); + else { + try { + ITokenDuple duple = name(); + 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(end, argumentList); + 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(end, + argumentList); + if (end.getType() == IToken.tGT) + hasTemplateId = true; + } + } + if (LT(1) == IToken.t_operator) + operatorId(d11, start, + (hasTemplateId ? argumentList : null)); + else { + int endOffset = (lastToken != null) ? lastToken + .getEndOffset() : 0; + backup(mark); + throwBacktrack(mark.getOffset(), endOffset, mark + .getLineNumber(), mark.getFilename()); + } + } + } + } + } finally { + TemplateParameterManager.returnInstance(argumentList); + } + } + + /** + * 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 { + Object nameType = null; //ClassNameType.IDENTIFIER; + Object classKind = null; + Object access = null; //ASTAccessVisibility.PUBLIC; + IToken classKey = null; + IToken mark = mark(); + + // class key + switch (LT(1)) { + case IToken.t_class: + classKey = consume(); + classKind = null; //ASTClassKind.CLASS; + access = null; //ASTAccessVisibility.PRIVATE; + break; + case IToken.t_struct: + classKey = consume(); + classKind = null; //ASTClassKind.STRUCT; + break; + case IToken.t_union: + classKey = consume(); + classKind = null; //ASTClassKind.UNION; + break; + default: + throwBacktrack(mark.getOffset(), mark.getEndOffset(), mark + .getLineNumber(), mark.getFilename()); + } + + ITokenDuple duple = null; + + // class name + if (LT(1) == IToken.tIDENTIFIER) + duple = name(); + if (duple != null && !duple.isIdentifier()) + nameType = null; //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()); + } + Object astClassSpecifier = null; + + try { + astClassSpecifier = null; /*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); + // astClassSpecifier.enterScope(requestor); + + try { + cleanupLastToken(); + 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); + } 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(Object 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); + + boolean isVirtual = false; + Object visibility = null; //ASTAccessVisibility.PUBLIC; + ITokenDuple nameDuple = null; + + ArrayList bases = null; + + baseSpecifierLoop: for (;;) { + switch (LT(1)) { + case IToken.t_virtual: + consume(IToken.t_virtual); + isVirtual = true; + break; + case IToken.t_public: + consume(); + break; + case IToken.t_protected: + consume(); + visibility = null; //ASTAccessVisibility.PROTECTED; + break; + case IToken.t_private: + visibility = null; //ASTAccessVisibility.PRIVATE; + consume(); + break; + case IToken.tCOLONCOLON: + case IToken.tIDENTIFIER: + //to get templates right we need to use the class as the scope + nameDuple = name(); + 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 = null; //ASTAccessVisibility.PUBLIC; + nameDuple = null; + consume(); + 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 statement. + * + * @throws BacktrackException + * request a backtrack + */ + protected IASTStatement statement() throws EndOfFileException, + BacktrackException { + + switch (LT(1)) { + case IToken.t_case: + consume(IToken.t_case); + constantExpression(); + cleanupLastToken(); + consume(IToken.tCOLON); + statement(); + cleanupLastToken(); + return null; + case IToken.t_default: + consume(IToken.t_default); + consume(IToken.tCOLON); + statement(); + cleanupLastToken(); + return null; + case IToken.tLBRACE: + compoundStatement(); + cleanupLastToken(); + return null; + case IToken.t_if: + consume(IToken.t_if); + consume(IToken.tLPAREN); + condition(); + consume(IToken.tRPAREN); + if (LT(1) != IToken.tLBRACE) + statement(); + else + statement(); + if (LT(1) == IToken.t_else) { + consume(IToken.t_else); + if (LT(1) == IToken.t_if) { + //an else if, return and get the rest of the else if as + // the next statement instead of recursing + cleanupLastToken(); + return null; + } else if (LT(1) != IToken.tLBRACE) + statement(); + else + statement(); + } + cleanupLastToken(); + return null; + case IToken.t_switch: + consume(); + consume(IToken.tLPAREN); + condition(); + consume(IToken.tRPAREN); + statement(); + cleanupLastToken(); + return null; + case IToken.t_while: + consume(IToken.t_while); + consume(IToken.tLPAREN); + condition(); + consume(IToken.tRPAREN); + if (LT(1) != IToken.tLBRACE) + statement(); + else + statement(); + cleanupLastToken(); + return null; + case IToken.t_do: + consume(IToken.t_do); + if (LT(1) != IToken.tLBRACE) + statement(); + else + statement(); + consume(IToken.t_while); + consume(IToken.tLPAREN); + condition(); + consume(IToken.tRPAREN); + cleanupLastToken(); + return null; + case IToken.t_for: + consume(); + consume(IToken.tLPAREN); + forInitStatement(); + if (LT(1) != IToken.tSEMI) + condition(); + consume(IToken.tSEMI); + if (LT(1) != IToken.tRPAREN) { + expression(); + cleanupLastToken(); + } + consume(IToken.tRPAREN); + statement(); + cleanupLastToken(); + return null; + case IToken.t_break: + consume(); + consume(IToken.tSEMI); + cleanupLastToken(); + return null; + case IToken.t_continue: + consume(); + consume(IToken.tSEMI); + cleanupLastToken(); + return null; + case IToken.t_return: + consume(); + if (LT(1) != IToken.tSEMI) { + expression(); + cleanupLastToken(); + } + consume(IToken.tSEMI); + cleanupLastToken(); + return null; + case IToken.t_goto: + consume(); + consume(IToken.tIDENTIFIER); + consume(IToken.tSEMI); + cleanupLastToken(); + return null; + case IToken.t_try: + consume(); + compoundStatement(); + catchHandlerSequence(); + cleanupLastToken(); + return null; + case IToken.tSEMI: + consume(); + cleanupLastToken(); + return null; + default: + // can be many things: + // label + + if (LT(1) == IToken.tIDENTIFIER + && LT(2) == IToken.tCOLON) { + consume(IToken.tIDENTIFIER); + consume(IToken.tCOLON); + statement(); + cleanupLastToken(); + return null; + } + // expressionStatement + // Note: the function style cast ambiguity is handled in + // expression + // Since it only happens when we are in a statement + IToken mark = mark(); + Object expressionStatement = null; + try { + expressionStatement = expression(); + consume(IToken.tSEMI); + cleanupLastToken(); + return null; + } catch (BacktrackException b) { + backup(mark); + // if (expressionStatement != null) + // expressionStatement.freeReferences(); + } + + // declarationStatement + declaration(null, null); + return null; + } + + } + + protected void catchHandlerSequence() + 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); + consume(IToken.tLPAREN); + try { + if (LT(1) == IToken.tELLIPSIS) + consume(IToken.tELLIPSIS); + else + simpleDeclaration(SimpleDeclarationStrategy.TRY_VARIABLE, + null, true); + consume(IToken.tRPAREN); + + catchBlockCompoundStatement(); + } catch (BacktrackException bte) { + failParse(bte); + failParseWithErrorHandling(); + } + } + } + + protected void catchBlockCompoundStatement() + 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(); + else + skipOverCompoundStatement(); + } else if (mode == ParserMode.COMPLETE_PARSE) + compoundStatement(); + } + + /** + * @throws BacktrackException + */ + protected void forInitStatement() throws BacktrackException, + EndOfFileException { + IToken mark = mark(); + try { + expression(); + consume(IToken.tSEMI); + // e.acceptElement(requestor); + + } catch (BacktrackException bt) { + backup(mark); + try { + simpleDeclarationStrategyUnion(null, null); + } catch (BacktrackException b) { + failParse(b); + throwBacktrack(b); + } + } + + } + + + /** + * This is the top-level entry point into the ANSI C++ grammar. + * + * translationUnit : (declaration)* + */ + protected void translationUnit() { + try { + translationUnit = null; /* astFactory.createCompilationUnit(); */ + } catch (Exception e2) { + logException("translationUnit::createCompilationUnit()", e2); //$NON-NLS-1$ + return; + } + + // compilationUnit.enterScope( requestor ); + + while (true) { + try { + int checkOffset = LA(1).hashCode(); + declaration(translationUnit, null); + 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) { + //nothing + } + } catch (ParseError perr) { + throw perr; + } catch (Throwable e) { + logThrowable("translationUnit", e); //$NON-NLS-1$ + try { + failParseWithErrorHandling(); + } catch (EndOfFileException e3) { + //break; + } + } + } + // compilationUnit.exitScope( requestor ); + } + + protected IToken consumeArrayModifiers(IDeclarator d) throws EndOfFileException, BacktrackException { + int startingOffset = LA(1).getOffset(); + IToken last = null; + while (LT(1) == IToken.tLBRACKET) { + consume(IToken.tLBRACKET); // eat the '[' + + Object exp = null; + if (LT(1) != IToken.tRBRACKET) { + exp = constantExpression(); + } + last = consume(IToken.tRBRACKET); + Object arrayMod = null; + try { + arrayMod = null; /* 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; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#getTranslationUnit() + */ + protected IASTTranslationUnit getTranslationUnit() { + return (IASTTranslationUnit) translationUnit; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createCompoundStatement() + */ + protected IASTCompoundStatement createCompoundStatement() { + return new CASTCompoundStatement(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createBinaryExpression() + */ + protected IASTBinaryExpression createBinaryExpression() { + return new CASTBinaryExpression(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createConditionalExpression() + */ + protected IASTConditionalExpression createConditionalExpression() { + return new CASTConditionalExpression(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createUnaryExpression() + */ + protected IASTUnaryExpression createUnaryExpression() { + return new CASTUnaryExpression(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createCompoundStatementExpression() + */ + protected IGNUASTCompoundStatementExpression createCompoundStatementExpression() { + return new CASTCompoundStatementExpression(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createExpressionList() + */ + protected IASTExpressionList createExpressionList() { + return new CASTExpressionList(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createName(org.eclipse.cdt.core.parser.IToken) + */ + protected IASTName createName(IToken token) { + return new CASTName( token.getCharImage() ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createName() + */ + protected IASTName createName() { + return new CASTName(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createEnumerator() + */ + protected IASTEnumerator createEnumerator() { + return new CASTEnumerator(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#createEnumerationSpecifier() + */ + protected IASTEnumerationSpecifier createEnumerationSpecifier() { + return new CASTEnumerationSpecifier(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser2.AbstractGNUSourceCodeParser#buildTypeIdExpression(int, org.eclipse.cdt.core.dom.ast.IASTTypeId, int) + */ + protected IASTExpression buildTypeIdExpression(int op_sizeof, IASTTypeId typeId, int startingOffset) { + // TODO Auto-generated method stub + return null; + } + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/ICPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/ICPPParserExtensionConfiguration.java new file mode 100644 index 00000000000..c548345fb32 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/ICPPParserExtensionConfiguration.java @@ -0,0 +1,30 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ + +/* + * Created on Oct 22, 2004 + * + */ +package org.eclipse.cdt.internal.core.parser2.cpp; + +/** + * @author jcamelon + */ +public interface ICPPParserExtensionConfiguration { + + public boolean allowRestrictPointerOperators(); + public boolean supportTypeofUnaryExpressions(); + public boolean supportAlignOfUnaryExpression(); + public boolean supportExtendedTemplateSyntax(); + public boolean supportMinAndMaxOperators(); + public boolean supportStatementsInExpressions(); + + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/IProblemRequestor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/IProblemRequestor.java new file mode 100644 index 00000000000..357fc2a5bb2 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/IProblemRequestor.java @@ -0,0 +1,26 @@ +/********************************************************************** + * Copyright (c) 2002-2004 IBM Canada and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation */ + +/* + * Created on Oct 22, 2004 + */ +package org.eclipse.cdt.internal.core.parser2.cpp; + +import org.eclipse.cdt.core.parser.IProblem; + +/** + * @author jcamelon + * + */ +public interface IProblemRequestor { + + public boolean acceptProblem( IProblem problem ); + +}