From b5cf6c388c57777492a5162110c320eaaaf445d4 Mon Sep 17 00:00:00 2001 From: Thomas Corbat Date: Thu, 30 Jan 2014 09:46:18 +0100 Subject: [PATCH] Bug 427539 - C++11 attribute implementation - Implemented C++11 attributes without breaking the current API for attributes in CDT. Added attribute specifiers according to the standard, which can be added to attribute owners and contain ICPPASTAttributes themselves. - Adapted current attribute implementation (Tokens and Offsets) to be writable by ASTWriter. - Added integration of GNU attributes into the AST for several missing cases. Change-Id: Ifb6a05989f0b4da0d504be24213df86c66428060 Reviewed-on: https://git.eclipse.org/r/22555 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../tests/ast2/AST2CPPAttributeTests.java | 494 ++++++++++++++++++ .../core/parser/tests/ast2/AST2CPPTests.java | 8 +- .../parser/tests/ast2/DOMParserTestSuite.java | 4 +- .../rewrite/astwriter/AstWriterTestSuite.java | 4 +- .../rewrite/ASTWriterAttributeTestSource.awts | 283 ++++++++++ .../eclipse/cdt/core/dom/ast/ASTVisitor.java | 10 + .../cdt/core/dom/ast/IASTArrayModifier.java | 4 +- .../cdt/core/dom/ast/IASTAttributeOwner.java | 26 +- .../core/dom/ast/IASTAttributeSpecifier.java | 42 ++ .../cdt/core/dom/ast/IASTPointerOperator.java | 4 +- .../cdt/core/dom/ast/INodeFactory.java | 9 +- .../dom/ast/cpp/ICPPASTAliasDeclaration.java | 5 +- .../core/dom/ast/cpp/ICPPASTAttribute.java | 39 ++ .../dom/ast/cpp/ICPPASTDeclSpecifier.java | 5 +- .../ast/cpp/ICPPASTFunctionDefinition.java | 5 +- .../ast/cpp/ICPPASTNamespaceDefinition.java | 6 +- .../cdt/core/dom/ast/cpp/ICPPNodeFactory.java | 12 + .../ast/gnu/IGCCASTAttributeSpecifier.java | 33 ++ .../core/dom/ast/gnu/cpp/IGPPASTPointer.java | 3 +- .../ast/gnu/cpp/IGPPASTPointerToMember.java | 3 +- .../parser/cpp/ICPPASTAttributeSpecifier.java | 33 ++ .../core/parser/util/InstanceOfPredicate.java | 9 +- .../core/dom/parser/ASTAttributeOwner.java | 80 ++- .../parser/AbstractGNUSourceCodeParser.java | 125 ++--- .../dom/parser/GCCASTAttributeSpecifier.java | 30 ++ .../dom/parser/c/CASTAmbiguousDeclarator.java | 15 +- .../c/CASTAmbiguousSimpleDeclaration.java | 14 +- .../dom/parser/c/CASTAmbiguousStatement.java | 14 +- .../core/dom/parser/c/CASTArrayModifier.java | 12 +- .../core/dom/parser/c/CASTBreakStatement.java | 4 +- .../dom/parser/c/CASTCompoundStatement.java | 4 +- .../dom/parser/c/CASTContinueStatement.java | 4 +- .../parser/c/CASTDeclarationStatement.java | 16 +- .../core/dom/parser/c/CASTDeclarator.java | 4 +- .../dom/parser/c/CASTDefaultStatement.java | 4 +- .../core/dom/parser/c/CASTDoStatement.java | 4 +- .../dom/parser/c/CASTExpressionStatement.java | 4 +- .../core/dom/parser/c/CASTForStatement.java | 4 +- .../core/dom/parser/c/CASTGotoStatement.java | 4 +- .../core/dom/parser/c/CASTIfStatement.java | 4 +- .../core/dom/parser/c/CASTLabelStatement.java | 4 +- .../core/dom/parser/c/CASTNullStatement.java | 4 +- .../core/dom/parser/c/CASTPointer.java | 15 +- .../dom/parser/c/CASTProblemStatement.java | 15 +- .../dom/parser/c/CASTReturnStatement.java | 4 +- .../dom/parser/c/CASTSimpleDeclaration.java | 4 +- .../dom/parser/c/CASTSwitchStatement.java | 4 +- .../core/dom/parser/c/CASTWhileStatement.java | 4 +- .../core/dom/parser/c/CNodeFactory.java | 10 +- .../core/dom/parser/c/GNUCSourceParser.java | 12 +- .../dom/parser/cpp/ASTAttributeSpecifier.java | 77 +++ .../parser/cpp/CPPASTAliasDeclaration.java | 7 +- .../parser/cpp/CPPASTAmbiguousDeclarator.java | 16 +- .../cpp/CPPASTAmbiguousSimpleDeclaration.java | 14 +- .../parser/cpp/CPPASTAmbiguousStatement.java | 14 +- .../dom/parser/cpp/CPPASTArrayModifier.java | 12 +- .../core/dom/parser/cpp/CPPASTAttribute.java | 26 +- .../parser/cpp/CPPASTAttributeSpecifier.java | 29 + .../parser/cpp/CPPASTBaseDeclSpecifier.java | 6 +- .../dom/parser/cpp/CPPASTBreakStatement.java | 4 +- .../dom/parser/cpp/CPPASTCaseStatement.java | 4 +- .../dom/parser/cpp/CPPASTCatchHandler.java | 4 +- .../cpp/CPPASTCompositeTypeSpecifier.java | 7 +- .../parser/cpp/CPPASTCompoundStatement.java | 4 +- .../parser/cpp/CPPASTContinueStatement.java | 4 +- .../cpp/CPPASTDeclarationStatement.java | 16 +- .../core/dom/parser/cpp/CPPASTDeclarator.java | 40 +- .../parser/cpp/CPPASTDefaultStatement.java | 4 +- .../dom/parser/cpp/CPPASTDoStatement.java | 4 +- .../cpp/CPPASTElaboratedTypeSpecifier.java | 7 +- .../cpp/CPPASTEnumerationSpecifier.java | 8 +- .../parser/cpp/CPPASTExpressionStatement.java | 4 +- .../dom/parser/cpp/CPPASTForStatement.java | 4 +- .../parser/cpp/CPPASTFunctionDefinition.java | 10 +- .../dom/parser/cpp/CPPASTGotoStatement.java | 4 +- .../dom/parser/cpp/CPPASTIfStatement.java | 4 +- .../dom/parser/cpp/CPPASTLabelStatement.java | 4 +- .../parser/cpp/CPPASTNamespaceDefinition.java | 12 +- .../dom/parser/cpp/CPPASTNullStatement.java | 4 +- .../core/dom/parser/cpp/CPPASTPointer.java | 13 +- .../parser/cpp/CPPASTProblemStatement.java | 15 +- .../cpp/CPPASTRangeBasedForStatement.java | 4 +- .../parser/cpp/CPPASTReferenceOperator.java | 21 +- .../dom/parser/cpp/CPPASTReturnStatement.java | 4 +- .../parser/cpp/CPPASTSimpleDeclSpecifier.java | 6 +- .../parser/cpp/CPPASTSimpleDeclaration.java | 4 +- .../dom/parser/cpp/CPPASTSwitchStatement.java | 4 +- .../parser/cpp/CPPASTTryBlockStatement.java | 4 +- .../parser/cpp/CPPASTUsingDeclaration.java | 4 +- .../dom/parser/cpp/CPPASTUsingDirective.java | 6 +- .../dom/parser/cpp/CPPASTWhileStatement.java | 4 +- .../core/dom/parser/cpp/CPPNodeFactory.java | 27 +- .../dom/parser/cpp/GNUCPPSourceParser.java | 279 +++++++--- .../rewrite/astwriter/ASTWriterVisitor.java | 19 +- .../rewrite/astwriter/AttributeWriter.java | 110 ++++ .../dom/rewrite/astwriter/DeclSpecWriter.java | 17 +- .../rewrite/astwriter/DeclarationWriter.java | 28 +- .../rewrite/astwriter/DeclaratorWriter.java | 11 +- .../rewrite/astwriter/ExpressionWriter.java | 4 +- .../dom/rewrite/astwriter/NodeWriter.java | 46 +- .../rewrite/astwriter/StatementWriter.java | 14 +- .../parser/upc/ast/UPCASTForallStatement.java | 2 +- .../ast/UPCASTSynchronizationStatement.java | 2 +- 103 files changed, 2090 insertions(+), 374 deletions(-) create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPAttributeTests.java create mode 100644 core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterAttributeTestSource.awts create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttributeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTAttribute.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGCCASTAttributeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ICPPASTAttributeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCASTAttributeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ASTAttributeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttributeSpecifier.java create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/AttributeWriter.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPAttributeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPAttributeTests.java new file mode 100644 index 00000000000..ce0adf4f27f --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPAttributeTests.java @@ -0,0 +1,494 @@ +/******************************************************************************* + * Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Corbat (IFS) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.core.parser.tests.ast2; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; +import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; +import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; +import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTLabelStatement; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTToken; +import org.eclipse.cdt.core.dom.ast.IASTTokenList; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAttribute; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTEnumerationSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement; +import org.eclipse.cdt.core.parser.IToken; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.ASTTokenList; + +public class AST2CPPAttributeTests extends AST2TestBase { + + public AST2CPPAttributeTests() { + } + + public AST2CPPAttributeTests(String name) { + super(name); + } + + public static TestSuite suite() { + return suite(AST2CPPAttributeTests.class); + } + + private IASTTranslationUnit parseAndCheckBindings() throws Exception { + String code = getAboveComment(); + return parseAndCheckBindings(code, ParserLanguage.CPP); + } + + private final class TokenPositionCheckVisitor extends ASTVisitor { + { + shouldVisitTokens = true; + } + int offset; + String[] tokenImages; + int index = 0; + + private TokenPositionCheckVisitor(int startOffset, String[] tokenImages) { + this.offset = startOffset; + this.tokenImages = tokenImages; + } + + @Override + public int visit(IASTToken token) { + if (token instanceof ASTTokenList) { + return ASTVisitor.PROCESS_CONTINUE; + } + IToken location; + if (token instanceof ASTNode) { + ASTNode node = (ASTNode) token; + assertEquals(offset, node.getOffset()); + assertEquals(tokenImages[index++], String.valueOf(token.getTokenCharImage())); + offset += node.getLength(); + } + return ASTVisitor.PROCESS_CONTINUE; + } + } + + private class AttributeNodeFinder extends ASTVisitor { + { + shouldVisitAttributes = true; + } + + private List specifiers = new ArrayList(); + + public List getAttributes() { + return specifiers; + } + + public int visit(IASTAttributeSpecifier specifier) { + specifiers.add(specifier); + return PROCESS_CONTINUE; + } + } + + private List getAttributeSpecifiers(IASTTranslationUnit tu) { + AttributeNodeFinder attributeFinder = new AttributeNodeFinder(); + tu.accept(attributeFinder); + List specifiers = attributeFinder.getAttributes(); + return specifiers; + } + + private IASTAttribute[] getAttributes() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + List specifiers = getAttributeSpecifiers(tu); + assertEquals(1, specifiers.size()); + IASTAttributeSpecifier specifier = specifiers.get(0); + return specifier.getAttributes(); + } + + private void checkAttributeRelations(List specifiers, Class... parentType) { + assertEquals(parentType.length, specifiers.size()); + for (int i = 0; i < specifiers.size(); i++) { + IASTAttributeSpecifier specifier = specifiers.get(i); + IASTNode attributeParent = specifier.getParent(); + IASTAttributeOwner owner = assertInstance(attributeParent, parentType[i]); + IASTAttributeSpecifier[] ownerAttributes = owner.getAttributeSpecifiers(); + assertSame(specifier, ownerAttributes[0]); + } + } + + // auto t = []() mutable throw(char const *) [[attr]] { throw "exception"; }; + public void testAttributedLambda() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTFunctionDeclarator.class); + } + + // int * arr = new int[1][[attr]]{2}; + public void testAttributedNewArrayExpression() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTArrayModifier.class); + } + + // int (* matrix) = new int[2][[attr1]][2][[attr2]]; + public void testAttributedMultidimensionalNewArrayExpression() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + List specifiers = getAttributeSpecifiers(tu); + checkAttributeRelations(specifiers, IASTArrayModifier.class, IASTArrayModifier.class); + IASTAttributeSpecifier arrayModifierAttribute1 = specifiers.get(0); + IASTNode arrayModifier1 = arrayModifierAttribute1.getParent(); + IASTAttributeSpecifier arrayModifierAttribute2 = specifiers.get(1); + IASTNode arrayModifier2 = arrayModifierAttribute2.getParent(); + assertNotSame(arrayModifier1, arrayModifier2); + } + + // void foo() { + // [[attr]] label:; + // } + public void testAttributeInLabeledStatement() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTLabelStatement.class); + } + + // void foo(int i) { + // switch(i) { + // [[case_attr]] case 42: + // [[default_attr]] default: + // ; + // } + // } + public void testAttributedSwitchLabels() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + List specifiers = getAttributeSpecifiers(tu); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTCaseStatement.class, IASTDefaultStatement.class); + } + + // void foo() { + // int i{0}; + // [[attr]] i++; + // } + public void testAttributedExpressionStatement() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTExpressionStatement.class); + } + + // void foo() { + // [[attr]] {} + // } + public void testAttributedCompoundStatement() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTCompoundStatement.class); + } + + // void foo() { + // [[attr]] if(false); + // } + public void testAttributedSelectionStatement() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTIfStatement.class); + } + + // void foo() { + // [[attr]] while(false); + // } + public void testAttributedIterationStatement() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTWhileStatement.class); + } + + // void foo() { + // [[attr]] return; + // } + public void testAttributedJumpStatement() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTReturnStatement.class); + } + + // void foo() { + // [[attr]] try{} catch(...) {} + // } + public void testAttributedTryBlockStatement() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTTryBlockStatement.class); + } + + // void foo() { + // if([[attr]]int i{0}); + // } + public void testAttributedConditionWithInitializer() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTSimpleDeclaration.class); + } + + // void foo() { + // int a[1]{0}; + // for([[attr]]auto i : a){} + // } + public void testAttributedForRangeDeclaration() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTSimpleDeclaration.class); + } + + // using number [[attr]] = int; + public void testAttributedAliasDeclaration() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTAliasDeclaration.class); + } + + // enum [[attr]] e {}; + public void testAttributedEnumDeclaration() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTEnumerationSpecifier.class); + } + + // namespace NS{} + // [[attr]] using namespace NS; + public void testAttributedUsingDirective() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTUsingDirective.class); + } + + // void foo() throw(char const *) [[noreturn]] -> void { + // throw "exception"; + // } + public void testAttributedFunction() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTFunctionDeclarator.class); + } + + // class [[attr]] C{}; + public void testAttributedClass() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTCompositeTypeSpecifier.class); + } + + // void f() { try { } catch ([[attr]] int& id) {} } + public void testAttributedExceptionDeclaration() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTSimpleDeclaration.class); + } + + // struct [[attr]] S; + public void testAttributedElaboratedTypeSpecifier() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTElaboratedTypeSpecifier.class); + } + + // static int [[int_attr]] v; + public void testAttributedDeclSpecifier() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTSimpleDeclSpecifier.class); + } + + // const volatile unsigned long int [[attr]] cvuli; + public void testAttributedTypeSpecifier() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTSimpleDeclSpecifier.class); + } + + // int * [[pointer_attribute]] * [[pointer_attribute]] ipp; + public void testAttributedPtrOperators() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + List specifiers = getAttributeSpecifiers(tu); + checkAttributeRelations(specifiers, IASTPointerOperator.class, IASTPointerOperator.class); + IASTAttributeSpecifier pointerAttribute1 = specifiers.get(0); + IASTNode pointer1 = pointerAttribute1.getParent(); + IASTAttributeSpecifier pointerAttribute2 = specifiers.get(1); + IASTNode pointer2 = pointerAttribute2.getParent(); + assertNotSame(pointer1, pointer2); + } + + // int & [[ref_attribute]] iRef; + public void testAttributedRefOperator() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTReferenceOperator.class); + } + + // int && [[rvalue_ref_attribute]] iRvalueRef; + public void testAttributedRvalueRefOperator() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTReferenceOperator.class); + } + + // void foo() [[function_attr]]; + public void testAttributedFunctionDeclaration() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTFunctionDeclarator.class); + } + + // int ipp [[declarator_attr]]; + public void testAttributedDeclarator() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTDeclarator.class); + } + + // int iArr[5] [[arr_attr]]; + public void testAttributedArrayDeclarator() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTArrayModifier.class); + } + + // [[attr]] int i; + public void testAttributedSimpleDeclaration() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTSimpleDeclaration.class); + } + + // [[attr]] void bar(){} + public void testAttributedFunctionDefinition() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTFunctionDefinition.class); + } + + // struct S { + // [[ctor_attr]] S() = delete; + // }; + public void testDeletedCtor() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTFunctionDefinition.class); + } + + // struct S { + // [[dtor_attr]] ~S() = default; + // }; + public void testDefaultedDtor() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTFunctionDefinition.class); + } + + // void bar() { + // [[attr]] int i; + // } + public void testAttributedSimpleDeclarationInStatement() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTSimpleDeclaration.class); + } + + // [[]] int i; + public void testEmptyAttributeSpecifier() throws Exception { + IASTAttribute[] attributes = getAttributes(); + assertEquals(IASTAttribute.EMPTY_ATTRIBUTE_ARRAY, attributes); + } + + // [[attr]] [[attr2]] [[attr3]] int i; + public void testMultipleSequentialAttributeSpecifiers() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(); + List specifiers = getAttributeSpecifiers(tu); + assertEquals(3, specifiers.size()); + IASTAttributeSpecifier simpleDeclarationAttribute1 = specifiers.get(0); + IASTNode parent1 = simpleDeclarationAttribute1.getParent(); + assertInstance(parent1, IASTSimpleDeclaration.class); + IASTAttributeSpecifier simpleDeclarationAttribute2 = specifiers.get(1); + IASTNode parent2 = simpleDeclarationAttribute2.getParent(); + assertInstance(parent2, IASTSimpleDeclaration.class); + IASTAttributeSpecifier simpleDeclarationAttribute3 = specifiers.get(2); + IASTNode parent3 = simpleDeclarationAttribute3.getParent(); + assertInstance(parent3, IASTSimpleDeclaration.class); + assertSame(parent1, parent2); + assertSame(parent1, parent3); + } + + // [[attr1, attr2]] int i; + public void testMultipleAttributes() throws Exception { + IASTAttribute[] attributes = getAttributes(); + assertEquals(2, attributes.length); + IASTAttribute attr1 = attributes[0]; + assertEquals("attr1", String.valueOf(attr1.getName())); + IASTAttribute attr2 = attributes[1]; + assertEquals("attr2", String.valueOf(attr2.getName())); + } + + // [[attribute ...]] int i; + public void testPackExpansionAttribute() throws Exception { + IASTAttribute[] attributes = getAttributes(); + assertEquals(1, attributes.length); + IASTAttribute attribute = attributes[0]; + assertInstance(attribute, ICPPASTAttribute.class); + assertTrue(((ICPPASTAttribute) attribute).hasPackExpansion()); + } + + // [[scope::attribute]] int i; + public void testScopedAttribute() throws Exception { + IASTAttribute[] attributes = getAttributes(); + assertEquals(1, attributes.length); + IASTAttribute scopedAttribute = attributes[0]; + assertInstance(scopedAttribute, ICPPASTAttribute.class); + assertEquals("scope", String.valueOf(((ICPPASTAttribute) scopedAttribute).getScope())); + assertEquals("attribute", String.valueOf(scopedAttribute.getName())); + } + + // [[attr()]] int i; + public void testAttributeWithEmptyArgument() throws Exception { + IASTAttribute[] attributes = getAttributes(); + assertEquals(1, attributes.length); + IASTAttribute attribute = attributes[0]; + IASTToken argument = attribute.getArgumentClause(); + IASTTokenList tokenList = assertInstance(argument, IASTTokenList.class); + assertEquals(IASTToken.EMPTY_TOKEN_ARRAY, tokenList.getTokens()); + } + + // [[attr(this(is){[my]}(argument[with]{some},parentheses))]] int i; + public void testAttributeWithBalancedArgument() throws Exception { + IASTAttribute[] attributes = getAttributes(); + assertEquals(1, attributes.length); + IASTAttribute attribute = attributes[0]; + IASTToken argumentClause = attribute.getArgumentClause(); + final int startOffset = 8; + final String[] tokenImages = new String[] { "this", "(", "is", ")", "{", "[", + "my", "]", "}", "(", "argument", "[", "with", "]", "{", "some", + "}", ",", "parentheses", ")"}; + argumentClause.accept(new TokenPositionCheckVisitor(startOffset, tokenImages)); + } + + // [[attr(class)]] int i; + public void testAttributeWithKeywordArgument() throws Exception { + IASTAttribute[] attributes = getAttributes(); + assertEquals(1, attributes.length); + IASTAttribute attribute = attributes[0]; + IASTToken argument = attribute.getArgumentClause(); + IASTTokenList tokenList = assertInstance(argument, IASTTokenList.class); + IASTToken[] argumentTokens = tokenList.getTokens(); + assertEquals(1, argumentTokens.length); + IASTToken classToken = argumentTokens[0]; + assertEquals("class", String.valueOf(classToken.getTokenCharImage())); + } + + // struct S __attribute__((__packed__)) {}; + public void testGCCAttributedStruct() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); + checkAttributeRelations(getAttributeSpecifiers(tu), ICPPASTCompositeTypeSpecifier.class); + } + + // int a __attribute__ ((aligned ((64)))); + public void testGCCAttributedVariableDeclarator_bug391572() throws Exception { + IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, true); + checkAttributeRelations(getAttributeSpecifiers(tu), IASTDeclarator.class); + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index cdc8b9357ab..89d105b5674 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -161,11 +161,7 @@ public class AST2CPPTests extends AST2TestBase { } protected IASTTranslationUnit parseAndCheckBindings(String code) throws Exception { - IASTTranslationUnit tu = parse(code, CPP); - NameCollector col = new NameCollector(); - tu.accept(col); - assertNoProblemBindings(col); - return tu; + return parseAndCheckBindings(code, CPP); } protected IASTTranslationUnit parseAndCheckBindings() throws Exception { @@ -5373,7 +5369,7 @@ public class AST2CPPTests extends AST2TestBase { // outer::foo x; // outer::inner::foo y; public void testAttributeInUsingDirective_351228() throws Exception { - parseAndCheckBindings(); + parseAndCheckBindings(getAboveComment(), CPP, true); } // class C { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java index 6b46417c965..845568d5f07 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMParserTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) * Emanuel Graf (IFS) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; @@ -57,6 +58,7 @@ public class DOMParserTestSuite extends TestCase { suite.addTest(ASTInactiveCodeTests.suite()); suite.addTest(AccessControlTests.suite()); suite.addTest(VariableReadWriteFlagsTest.suite()); + suite.addTest(AST2CPPAttributeTests.suite()); return suite; } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/AstWriterTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/AstWriterTestSuite.java index b95598ad1ca..d7ac3a5f090 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/AstWriterTestSuite.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/AstWriterTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2006, 2014 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,7 @@ * * Contributors: * Institute for Software - initial API and implementation + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.astwriter; @@ -48,6 +49,7 @@ public class AstWriterTestSuite { suite.addTest(SourceRewriteTester.suite("CommentTests", "resources/rewrite/ASTWriterCommentedTestSource.awts")); suite.addTest(SourceRewriteTester.suite("NewCommentTests", "resources/rewrite/ASTWriterCommentedTestSource2.awts")); + suite.addTest(SourceRewriteTester.suite("AttributeTests", "resources/rewrite/ASTWriterAttributeTestSource.awts")); suite.addTestSuite(ExpressionWriterTest.class); return suite; } diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterAttributeTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterAttributeTestSource.awts new file mode 100644 index 00000000000..ad49798b308 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterAttributeTestSource.awts @@ -0,0 +1,283 @@ +//!Attributed Lambda +//%CPP +auto t = []() mutable throw (char*) [[noreturn]] { + throw "exception"; +} +; + +//!Attributed Array New Initialization +//%CPP +int* arr = new int[1][[attr]]{2}; + +//!Attributed Multidimensional Array +//%CPP +int (*matrix) = new int[2][[attr1]][2][[attr2]]; + +//!Attributed Label +//%CPP +void foo() +{ + [[attr]] label: + ; +} + +//!Attributed Switch Labels +//%CPP +void foo(int i) +{ + switch (i){ + [[attr]] case 42: + [[attr]] default: + ; + } +} + +//!Attributed Expression Statement +//%CPP +void foo() +{ + int i{0}; + [[attr]] i++; +} + +//!Attributed Compound Statement +//%CPP +void foo() +{ + [[attr]] { + } +} + +//!Attributed Selection Statement +//%CPP +void foo() +{ + [[attr]] if (false); + +} + +//!Attributed Iteration Statement +//%CPP +void foo() +{ + [[attr]] while (false); + +} + +//!Attributed Jump Statement +//%CPP +void foo() +{ + [[attr]] return; +} + +//!Attributed Try Block Statement +//%CPP +void foo() +{ + [[attr]] try { + } + catch (...){ + } +} + +//!Attributed Condition with Initializer +//%CPP +void foo() +{ + if ([[attr]] int i{0}); + +} + +//!Attributed For Range Declaration +//%CPP +void foo() +{ + int a[1]{0}; + for ([[attr]] auto i: a){ + } +} + +//!Attributed Alias Declaration +//%CPP +using number [[attr]] = int; + +//!Attributed Enum Declaration +//%CPP +enum [[attr]] e{ }; + +//!Attributed Using Directive +//%CPP +namespace NS +{ + + +} + +[[attr]] using namespace NS; + +//!Attributed Function Declarator in Definition +//%CPP +void foo() throw (char*) [[noreturn]] -> void +{ + throw "exception"; +} + +//!Attributed Class +//%CPP +class [[attr]] C +{ +}; + +//!Attributed Exception Declaration +//%CPP +void f() +{ + try { + } + catch ([[attr]] int& id){ + } +} + +//!Attributed Elaborated Type Specifier +//%CPP +struct [[attr]] S; + +//!Attributed Decl Specifier +//%CPP +static int [[int_attr]] v; + +//!Attributed Type Specifier +//%CPP +const volatile unsigned long int [[attr]] cvuli; + +//!Attributed Ptr Operators +//%CPP +int*[[pointer_attribute]]*[[pointer_attribute]] ipp; + +//!Attributed Reference Operator +//%CPP +int&[[ref_attribute]] iRef; + +//!Attributed Rvalue Reference Operator +//%CPP +int&&[[rvalue_ref_attribute]] iRvalueRef; + +//!Attributed Function Declaration +//%CPP +void foo() [[function_attr]]; + +//!Attributed Declarator +//%CPP +int ipp [[declarator_attr]]; + +//!Attributed Array Declarator +//%CPP +int iArr[5][[arr_attr]]; + +//!Attributed Simple Declaration +//%CPP +[[attr]] int i; + +//!Attributed Function Definition +//%CPP +[[attr]] void bar() +{ +} + +//!Attributed Deleted Constructor +//%CPP +struct S +{ + [[ctor_attr]] S() = delete; +}; + +//!Attributed Simple Declaration in Statement +//%CPP +void bar() +{ + [[attr]] int i; +} + +//!Empty Attribute +//%CPP +[[]] int i; + +//!Multiple Sequential Attribute Specifiers +//%CPP +[[attr]][[attr2]][[attr3]] int i; + +//!Multiple Attributes +//%CPP +[[attr1, attr2]] int i; + +//!Pack Expansion Attribute +//%CPP +[[attribute ...]] int i; + +//!Multiple Pack Expansions Attribute +//%CPP +[[attribute1 ..., attribute2 ...]] int i; + +//!Scoped Attribute +//%CPP +[[scope::attribute]] int i; + +//!Attribute with Empty Argument +//%CPP +[[attr()]] int i; + +//!Attribute with Balanced Argument +//%CPP +[[attr(this(is){[my]}(argument[with]{some},parentheses))]] int i; + +//!Attribute with Keyword Argument +//%CPP +[[attr(class)]] int i; + +//!GCC Attribute Sequence +//%CPP GNU +void bar(void* a1, void* a2) __attribute__((nonnull(1,2))); + +//!GCC Attributed Using Directive +//%CPP GNU +namespace inner +{ + + +} + +using namespace inner __attribute__((__strong__)); + +//!GCC Attributed Namespace Declaration +//%CPP GNU +namespace NS __attribute__((__visibility__("default"))) +{ + + +} + +//!GCC Attributed Function Definition +//%CPP GNU +inline static int __attribute__((always_inline)) f(int x) +{ + return x; +} + +//!GCC Attributed Enum Declaration +//%CPP GNU +enum __attribute__((deprecated)) Obsolete{ o1, o2}; + +//!GCC Attributed Elaborated Type Specifier +//%CPP GNU +struct __attribute__((declspec)) S; + +//!GCC Attributed Pointer Declarator +//%CPP GNU +void (*__attribute__((__stdcall__))*foo3)(int); +char*__attribute__((aligned(8)))* f; + +//!GCC Attributed Declarator +//%CPP GNU +void __attribute__((noreturn)) foo(); +void (__attribute__((__stdcall__))*foo1)(int); \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java index 776710b54b5..6b503b72a15 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java @@ -250,6 +250,11 @@ public abstract class ASTVisitor { return PROCESS_CONTINUE; } + /** @since 5.7 */ + public int visit(IASTAttributeSpecifier specifier) { + return PROCESS_CONTINUE; + } + /** @since 5.4 */ public int visit(IASTToken token) { return PROCESS_CONTINUE; @@ -354,6 +359,11 @@ public abstract class ASTVisitor { return PROCESS_CONTINUE; } + /** @since 5.7 */ + public int leave(IASTAttributeSpecifier specifier) { + return PROCESS_CONTINUE; + } + /** @since 5.4 */ public int leave(IASTToken token) { return PROCESS_CONTINUE; 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 index 48c9f45fda9..52a7ab623ef 100644 --- 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,7 +17,7 @@ package org.eclipse.cdt.core.dom.ast; * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ -public interface IASTArrayModifier extends IASTNode { +public interface IASTArrayModifier extends IASTAttributeOwner { /** * Node property that describes the relationship between an * IASTArrayModifier and an IASTExpression. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttributeOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttributeOwner.java index 79af3022bcc..bde39560135 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttributeOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttributeOwner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 IBM Corporation and others. + * Copyright (c) 2012, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Sergey Prigogin (Google) - Initial API and implementation + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -17,16 +18,35 @@ package org.eclipse.cdt.core.dom.ast; * @noimplement This interface is not intended to be implemented by clients. */ public interface IASTAttributeOwner extends IASTNode { + /** @since 5.7 */ + public static final ASTNodeProperty ATTRIBUTE_SPECIFIER = + new ASTNodeProperty("IASTAttributeOwner.ATTRIBUTE_SPECIFIER"); //$NON-NLS-1$ + /** @deprecated Not used. */ + @Deprecated public static final ASTNodeProperty ATTRIBUTE = new ASTNodeProperty("IASTAttributeOwner.ATTRIBUTE"); //$NON-NLS-1$ /** - * Returns the array of attributes. + * Returns an array of all the node's attribute specifiers. + * @since 5.7 + */ + public IASTAttributeSpecifier[] getAttributeSpecifiers(); + + /** + * Adds an attribute specifier to the node. + * @since 5.7 + */ + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier); + + /** + * Returns the array of all attributes. */ public IASTAttribute[] getAttributes(); /** - * Adds an attribute to the node. + * @deprecated Ignored. Attributes should not be assigned to nodes directly, but have to be + * wrapped by attribute specifiers. */ + @Deprecated public void addAttribute(IASTAttribute attribute); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttributeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttributeSpecifier.java new file mode 100644 index 00000000000..623054051b6 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttributeSpecifier.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Corbat (IFS) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +/** + * Represents a C++11 (ISO/IEC 14882:2011 7.6.1) + * or a GCC attribute specifier (http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html). + * + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @since 5.7 + */ +public interface IASTAttributeSpecifier extends IASTNode { + public static final IASTAttributeSpecifier[] EMPTY_ATTRIBUTE_SPECIFIER_ARRAY = {}; + public static final ASTNodeProperty ATTRIBUTE = + new ASTNodeProperty("IASTAttributeSpecifier.ATTRIBUTE"); //$NON-NLS-1$ + + /** + * Returns the attributes of the specifier. + */ + public abstract IASTAttribute[] getAttributes(); + + /** + * Adds an attribute to the specifier. + */ + public abstract void addAttribute(IASTAttribute attribute); + + @Override + public IASTAttributeSpecifier copy(); + + @Override + public IASTAttributeSpecifier copy(CopyStyle style); +} \ No newline at end of file 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 index 343a115cb88..13057a3b5a5 100644 --- 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,7 +14,7 @@ package org.eclipse.cdt.core.dom.ast; * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ -public interface IASTPointerOperator extends IASTNode { +public interface IASTPointerOperator extends IASTAttributeOwner { /** * Constant/sentinel. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/INodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/INodeFactory.java index e0801398907..69c2573a957 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/INodeFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/INodeFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 IBM Corporation and others. + * Copyright (c) 2006, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,10 +9,12 @@ * Mike Kucera (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Thoams Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.core.dom.ast.gnu.IGCCASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.IToken; @@ -112,7 +114,10 @@ public interface INodeFactory { public IASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator, IASTStatement bodyStatement); - + + /** @since 5.7 */ + public IGCCASTAttributeSpecifier newGCCAttributeSpecifier(); + public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement); public IASTGotoStatement newGotoStatement(IASTName name); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTAliasDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTAliasDeclaration.java index f8ab21dfab8..e06ad59e6a4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTAliasDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTAliasDeclaration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2012, 2014 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -12,6 +12,7 @@ package org.eclipse.cdt.core.dom.ast.cpp; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNameOwner; @@ -24,7 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNameOwner; * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ -public interface ICPPASTAliasDeclaration extends IASTDeclaration, IASTNameOwner { +public interface ICPPASTAliasDeclaration extends IASTDeclaration, IASTNameOwner, IASTAttributeOwner { public static final ICPPASTAliasDeclaration[] EMPTY_ALIAS_DECLARATION_ARRAY = {}; /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTAttribute.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTAttribute.java new file mode 100644 index 00000000000..dadc2eb439e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTAttribute.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Corbat (IFS) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.ast.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTAttribute; +/** + * Represents a C++11 (ISO/IEC 14882:2011 7.6) attribute. + * + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @since 5.7 + */ +public interface ICPPASTAttribute extends IASTAttribute { + /** + * Returns the scope of the attribute, or {@code null} if the attribute doesn't have a scope. + */ + public char[] getScope(); + + /** + * + * Returns true if this attribute has a pack expansion. + */ + public boolean hasPackExpansion(); + + @Override + public ICPPASTAttribute copy(); + + @Override + public ICPPASTAttribute copy(CopyStyle style); +} 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 index 2814b6afa56..cb43c172d96 100644 --- 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; +import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; /** @@ -20,7 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ -public interface ICPPASTDeclSpecifier extends IASTDeclSpecifier { +public interface ICPPASTDeclSpecifier extends IASTDeclSpecifier, IASTAttributeOwner { // A declaration in C++ can be a friend declaration /** * Is this a friend declaration? diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDefinition.java index 1a8dd4c6ace..0c6cfa4f814 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDefinition.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,6 +11,7 @@ package org.eclipse.cdt.core.dom.ast.cpp; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; /** @@ -20,7 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ -public interface ICPPASTFunctionDefinition extends IASTFunctionDefinition { +public interface ICPPASTFunctionDefinition extends IASTFunctionDefinition, IASTAttributeOwner { /** * MEMBER_INITIALIZER is the role of a member initializer in the function definition. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTNamespaceDefinition.java index 59e0de8d438..1c0a67a7fb7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTNamespaceDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTNamespaceDefinition.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ package org.eclipse.cdt.core.dom.ast.cpp; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationListOwner; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -24,7 +25,8 @@ import org.eclipse.cdt.core.dom.ast.IScope; * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ -public interface ICPPASTNamespaceDefinition extends IASTDeclaration, IASTNameOwner, IASTDeclarationListOwner { +public interface ICPPASTNamespaceDefinition extends IASTDeclaration, IASTNameOwner, IASTDeclarationListOwner, + IASTAttributeOwner { /** * OWNED_DECLARATION is the role served by all the nested * declarations. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNodeFactory.java index 3ecbd8d9ccf..c6e9a72bb7d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNodeFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNodeFactory.java @@ -25,10 +25,12 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId; import org.eclipse.cdt.core.dom.ast.IASTReturnStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTToken; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.INodeFactory; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUnaryTypeTransformation.Operator; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPASTAttributeSpecifier; import org.eclipse.cdt.core.parser.IScanner; /** @@ -53,6 +55,16 @@ public interface ICPPNodeFactory extends INodeFactory { */ public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTInitializerClause subscript); + /** + * @since 5.7 + */ + public ICPPASTAttribute newAttribute(char[] name, char[] scope, IASTToken argumentClause, boolean packExpansion); + + /** + * @since 5.7 + */ + public ICPPASTAttributeSpecifier newAttributeSpecifier(); + public ICPPASTBaseSpecifier newBaseSpecifier(IASTName name, int visibility, boolean isVirtual); @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGCCASTAttributeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGCCASTAttributeSpecifier.java new file mode 100644 index 00000000000..bc4d51c5cae --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/IGCCASTAttributeSpecifier.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Corbat (IFS) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.ast.gnu; + +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; +import org.eclipse.cdt.core.parser.util.InstanceOfPredicate; + +/** + * Represents a GCC attribute specifier, introduced by __attribute__. + * + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @since 5.7 + */ +public interface IGCCASTAttributeSpecifier extends IASTAttributeSpecifier { + public static InstanceOfPredicate TYPE_FILTER = + new InstanceOfPredicate<>(IGCCASTAttributeSpecifier.class); + + @Override + public IGCCASTAttributeSpecifier copy(); + + @Override + public IGCCASTAttributeSpecifier copy(CopyStyle style); +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTPointer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTPointer.java index 0c8c914f42c..5a2f93ba43c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTPointer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTPointer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ package org.eclipse.cdt.core.dom.ast.gnu.cpp; import org.eclipse.cdt.core.dom.ast.IASTPointer; /** + * @noimplement This interface is not intended to be implemented by clients. * @deprecated Use {@link IASTPointer}, instead. */ @Deprecated diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTPointerToMember.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTPointerToMember.java index cc4feb7a0fc..2a8fb3c70e5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTPointerToMember.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTPointerToMember.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ package org.eclipse.cdt.core.dom.ast.gnu.cpp; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; /** + * @noimplement This interface is not intended to be implemented by clients. * @deprecated Use {@link ICPPASTPointerToMember}, instead. */ @Deprecated diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ICPPASTAttributeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ICPPASTAttributeSpecifier.java new file mode 100644 index 00000000000..2102c7c3dc2 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/ICPPASTAttributeSpecifier.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Corbat (IFS) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; +import org.eclipse.cdt.core.parser.util.InstanceOfPredicate; + +/** + * Represents a C++11 (ISO/IEC 14882:2011 7.6.1 [dcl.attr.grammar]) attribute specifier. + * + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + * @since 5.7 + */ +public interface ICPPASTAttributeSpecifier extends IASTAttributeSpecifier { + public static InstanceOfPredicate TYPE_FILTER = + new InstanceOfPredicate<>(ICPPASTAttributeSpecifier.class); + + @Override + public ICPPASTAttributeSpecifier copy(); + + @Override + public ICPPASTAttributeSpecifier copy(CopyStyle style); +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/InstanceOfPredicate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/InstanceOfPredicate.java index bc5f5c99147..318b4c93da9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/InstanceOfPredicate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/InstanceOfPredicate.java @@ -11,16 +11,17 @@ package org.eclipse.cdt.core.parser.util; /** - * Unary predicate returning {@code true} if the object is an instance of the given class. + * Unary predicate returning {@code true} if the object is an instance of the given class + * or interface. * @since 5.7 */ public class InstanceOfPredicate implements IUnaryPredicate { - private Class type; + private Class type; - public InstanceOfPredicate(Class type) { + public InstanceOfPredicate(Class type) { this.type = type; } - + @Override public boolean apply(T obj) { return type.isInstance(obj); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttributeOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttributeOwner.java index 20c60b24ece..cb35f7fcbcd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttributeOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttributeOwner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Google, Inc and others. + * Copyright (c) 2012, 2014 Google, Inc and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,50 +7,92 @@ * * Contributors: * Sergey Prigogin (Google) - initial API and implementation + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTAttribute; import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; +import org.eclipse.cdt.core.dom.ast.gnu.IGCCASTAttributeSpecifier; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPASTAttributeSpecifier; import org.eclipse.cdt.core.parser.util.ArrayUtil; /** * Classes that implement IASTAttributeOwner interface may extend this class. */ public abstract class ASTAttributeOwner extends ASTNode implements IASTAttributeOwner { - private IASTAttribute[] attributes = IASTAttribute.EMPTY_ATTRIBUTE_ARRAY; + private IASTAttributeSpecifier[] attributeSpecifiers = IASTAttributeSpecifier.EMPTY_ATTRIBUTE_SPECIFIER_ARRAY; @Override public IASTAttribute[] getAttributes() { - attributes = ArrayUtil.trim(attributes); - return attributes; + IASTAttribute[] attributes = IASTAttribute.EMPTY_ATTRIBUTE_ARRAY; + for (IASTAttributeSpecifier attributeSpecifier : getAttributeSpecifiers()) { + attributes = ArrayUtil.addAll(attributes, attributeSpecifier.getAttributes()); + } + return attributes; } @Override + @Deprecated public void addAttribute(IASTAttribute attribute) { - assertNotFrozen(); - if (attribute != null) { - attribute.setParent(this); - attribute.setPropertyInParent(ATTRIBUTE); - attributes = ArrayUtil.append(attributes, attribute); + } + + @Override + public IASTAttributeSpecifier[] getAttributeSpecifiers() { + attributeSpecifiers = ArrayUtil.trim(attributeSpecifiers); + return attributeSpecifiers; + } + + @Override + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier) { + assertNotFrozen(); + if (attributeSpecifier != null) { + attributeSpecifier.setParent(this); + attributeSpecifier.setPropertyInParent(ATTRIBUTE_SPECIFIER); + attributeSpecifiers = ArrayUtil.append(attributeSpecifiers, attributeSpecifier); } } protected T copy(T copy, CopyStyle style) { - for (IASTAttribute attribute : getAttributes()) { - copy.addAttribute(attribute.copy(style)); + for (IASTAttributeSpecifier attributeSpecifier : getAttributeSpecifiers()) { + copy.addAttributeSpecifier(attributeSpecifier.copy(style)); } return super.copy(copy, style); } - protected boolean acceptByAttributes(ASTVisitor action) { - for (IASTAttribute attribute : attributes) { - if (attribute == null) - break; - if (!attribute.accept(action)) - return false; - } - return true; + protected boolean acceptByAttributeSpecifiers(ASTVisitor action) { + return visitAttributes(action, attributeSpecifiers); + } + + private boolean visitAttributes(ASTVisitor action, IASTAttributeSpecifier[] attributeSpecifiers) { + for (IASTAttributeSpecifier attributeSpecifier : attributeSpecifiers) { + if (attributeSpecifier == null) + break; + if (!attributeSpecifier.accept(action)) + return false; + } + return true; + } + + protected boolean acceptByGCCAttributeSpecifiers(ASTVisitor action) { + for (IASTAttributeSpecifier attributeSpecifier : attributeSpecifiers) { + if (!(attributeSpecifier instanceof IGCCASTAttributeSpecifier)) + continue; + if (!attributeSpecifier.accept(action)) + return false; + } + return true; + } + + protected boolean acceptByCPPAttributeSpecifiers(ASTVisitor action) { + for (IASTAttributeSpecifier attributeSpecifier : attributeSpecifiers) { + if (!(attributeSpecifier instanceof ICPPASTAttributeSpecifier)) + continue; + if (!attributeSpecifier.accept(action)) + return false; + } + return true; } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 208d6f2a0df..2750988e60a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2013 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.ASTGenericVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; @@ -42,6 +43,7 @@ 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.IASTEnumerationSpecifier.IASTEnumerator; +import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; @@ -91,7 +93,6 @@ 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.core.parser.util.CharArrayUtils; -import org.eclipse.cdt.core.parser.util.CollectionUtils; import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver; /** @@ -1846,6 +1847,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * if both parses succeed then an ambiguity node is returned. */ protected IASTStatement parseDeclarationOrExpressionStatement() throws EndOfFileException, BacktrackException { + return parseDeclarationOrExpressionStatement(null); + } + + protected IASTStatement parseDeclarationOrExpressionStatement(List attributeSpecifiers) + throws EndOfFileException, BacktrackException { // First attempt to parse an expressionStatement // Note: the function style cast ambiguity is handled in expression // Since it only happens when we are in a statement @@ -1856,6 +1862,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { try { IASTExpression expression = expression(); expressionStatement = nodeFactory.newExpressionStatement(expression); + addAttributeSpecifiers(attributeSpecifiers, expressionStatement); setRange(expressionStatement, expression); afterExpression= LA(); @@ -1872,6 +1879,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { IASTDeclarationStatement ds = null; try { IASTDeclaration d = declaration(DeclarationOptions.LOCAL); + if (d instanceof IASTAttributeOwner) { + addAttributeSpecifiers(attributeSpecifiers, (IASTAttributeOwner) d); + } ds = nodeFactory.newDeclarationStatement(d); setRange(ds, d); } catch (BacktrackException b) { @@ -2325,13 +2335,16 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * @throws BacktrackException * @throws EndOfFileException */ - protected List __attribute_decl_seq(boolean allowAttrib, boolean allowDeclspec) + protected List __attribute_decl_seq(boolean allowAttrib, boolean allowDeclspec) throws BacktrackException, EndOfFileException { - List result = null; + List result = null; while (true) { final int lt = LTcatchEOF(1); if (allowAttrib && (lt == IGCCToken.t__attribute__)) { - result = CollectionUtils.merge(result, __attribute__()); + if (result == null) { + result = new ArrayList(); + } + result.add(__attribute__()); } else if (allowDeclspec && (lt == IGCCToken.t__declspec)) { __declspec(); } else { @@ -2348,11 +2361,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { * @throws BacktrackException * @throws EndOfFileException */ - protected List __attribute__() throws BacktrackException, EndOfFileException { + protected IASTAttributeSpecifier __attribute__() throws BacktrackException, EndOfFileException { if (LT(1) != IGCCToken.t__attribute__) return null; - List result = null; + IASTAttributeSpecifier result = nodeFactory.newGCCAttributeSpecifier(); consume(); if (LT(1) == IToken.tLPAREN) { consume(); @@ -2365,10 +2378,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { // Allow empty attribute if (lt1 != IToken.tCOMMA) { - IASTAttribute attribute = singleAttribute(); - if (result == null) - result = new ArrayList(); - result.add(attribute); + result.addAttribute(singleAttribute()); } // Require comma @@ -2383,22 +2393,34 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return result; } - private IASTAttribute singleAttribute() throws EndOfFileException, BacktrackException { + protected IASTAttribute singleAttribute() throws EndOfFileException, BacktrackException { // Get an identifier including keywords - IToken attributeName = identifierOrKeyword(); + IToken nameToken = identifierOrKeyword(); IASTToken argumentClause = null; + int endOffset = nameToken.getEndOffset(); + // Check for arguments if (LT(1) == IToken.tLPAREN) { - consume(); - argumentClause = balancedTokenSeq(IToken.tRPAREN); - consumeOrEOC(IToken.tRPAREN); + int argumentOffset = consume().getEndOffset(); + argumentClause = balancedTokenSeq(argumentOffset, IToken.tRPAREN); + endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset(); } - IASTAttribute result = nodeFactory.newAttribute(attributeName.getCharImage(), argumentClause); - setRange(result, attributeName.getOffset(), getEndOffset()); + char[] attributeName = nameToken.getCharImage(); + + IASTAttribute result = nodeFactory.newAttribute(attributeName, argumentClause); + setRange(result, nameToken.getOffset(), endOffset); return result; } - private IToken identifierOrKeyword() throws EndOfFileException, BacktrackException { + protected void addAttributeSpecifiers(List specifiers, IASTAttributeOwner owner) { + if (specifiers != null && owner != null) { + for (IASTAttributeSpecifier specifier : specifiers) { + owner.addAttributeSpecifier(specifier); + } + } + } + + protected IToken identifierOrKeyword() throws EndOfFileException, BacktrackException { IToken t = LA(1); char[] image= t.getCharImage(); if (image.length == 0) @@ -2410,11 +2432,20 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return t; } - private IASTToken balancedTokenSeq(int endType) throws EndOfFileException, BacktrackException { - IASTToken result = null; + /** + * Parses sequence of tokens until encountering a token of a given type + * @param offset the offset for the returned token node. + * @param endType the type of the token to stop before + * @return a token sequence, possibly empty but never {@code null} + */ + protected IASTTokenList balancedTokenSeq(int offset, int endType) + throws EndOfFileException, BacktrackException { + IASTTokenList result = nodeFactory.newTokenList(); IToken t; while ((t = LA(1)).getType() != endType) { - consume(); + t = consume(); + result.addToken(createASTToken(t)); + IASTToken token; switch (t.getType()) { case IToken.tLPAREN: @@ -2430,53 +2461,25 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { break; default: - token = nodeFactory.newToken(t.getType(), t.getCharImage()); - setRange(token, t.getOffset(), t.getEndOffset()); - break; + continue; } - result = addTokenToSequence(result, token); + result.addToken(token); + t = consume(); + token = createASTToken(t); + result.addToken(token); } + + setRange(result, offset, t.getEndOffset()); return result; } - /** - * Parses sequence of tokens until encountering a token of a given type - * @param offset the offset for the returned token node. - * @param endType the type of the token to stop before - * @return a token sequence, possibly empty but never {@code null} - */ - private IASTToken balancedTokenSeq(int offset, int endType) throws EndOfFileException, BacktrackException { - IASTToken token = balancedTokenSeq(endType); - if (token == null) - token = nodeFactory.newTokenList(); - int endOffset = consumeOrEOC(endType).getEndOffset(); - setRange(token, offset, endOffset); + private IASTToken createASTToken(IToken t) { + IASTToken token; + token = nodeFactory.newToken(t.getType(), t.getCharImage()); + setRange(token, t.getOffset(), t.getEndOffset()); return token; } - /** - * Adds a token to a token sequence. - * - * @param sequence the token sequence, may be {@code null} - * @param token the token to add - * @return the modified token sequence that is never {@code null} - */ - private IASTToken addTokenToSequence(IASTToken sequence, IASTToken token) { - if (sequence == null) { - sequence = token; - } else if (sequence instanceof IASTTokenList) { - ((IASTTokenList) sequence).addToken(token); - adjustLength(sequence, token); - } else { - IASTTokenList list = nodeFactory.newTokenList(); - list.addToken(sequence); - list.addToken(token); - setRange(list, token); - sequence = list; - } - return sequence; - } - protected void __declspec() throws BacktrackException, EndOfFileException { IToken token = LA(1); if (token.getType() == IGCCToken.t__declspec) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCASTAttributeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCASTAttributeSpecifier.java new file mode 100644 index 00000000000..9f46809900d --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCASTAttributeSpecifier.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Corbat (IFS) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser; + +import org.eclipse.cdt.core.dom.ast.gnu.IGCCASTAttributeSpecifier; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ASTAttributeSpecifier; + +/** + * Represents a GCC attribute specifier, containing attributes. + */ +public class GCCASTAttributeSpecifier extends ASTAttributeSpecifier implements IGCCASTAttributeSpecifier { + @Override + public GCCASTAttributeSpecifier copy(CopyStyle style) { + return copy(new GCCASTAttributeSpecifier(), style); + } + + @Override + public GCCASTAttributeSpecifier copy() { + return copy(CopyStyle.withoutLocations); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java index c38ae9ddceb..c7ba18c1b73 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 IBM Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2014 IBM Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,9 +8,11 @@ * Contributors: * Markus Schorn - Initial API and implementation * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTAttribute; import org.eclipse.cdt.core.dom.ast.IASTInitializer; @@ -103,6 +105,17 @@ public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmb Assert.isLegal(false); } + @Override + public IASTAttributeSpecifier[] getAttributeSpecifiers() { + return dtors[0].getAttributeSpecifiers(); + } + + @Override + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier) { + assertNotFrozen(); + Assert.isLegal(false); + } + @Override public int getRoleForName(IASTName name) { return dtors[0].getRoleForName(name); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java index b28b6814384..a896e7f1379 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 IBM Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2014 IBM Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,11 +8,13 @@ * Contributors: * Markus Schorn - Initial API and implementation * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -97,6 +99,16 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements fSimpleDecl.addAttribute(attribute); } + @Override + public IASTAttributeSpecifier[] getAttributeSpecifiers() { + return fSimpleDecl.getAttributeSpecifiers(); + } + + @Override + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier) { + fSimpleDecl.addAttributeSpecifier(attributeSpecifier); + } + @Override protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) { final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java index 37d7c020f35..d57cd471bfe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,11 +9,13 @@ * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -96,6 +98,16 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi throw new UnsupportedOperationException(); } + @Override + public IASTAttributeSpecifier[] getAttributeSpecifiers() { + return IASTAttributeSpecifier.EMPTY_ATTRIBUTE_SPECIFIER_ARRAY; + } + + @Override + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier) { + throw new UnsupportedOperationException(); + } + @Override public IASTNode[] getNodes() { return getStatements(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java index 941746838d3..dbf2b04249b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayModifier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * John Camelon (IBM Rational Software) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -15,13 +16,13 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier; -import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * c-specific modifier for array specifiers. */ -public class CASTArrayModifier extends ASTNode implements ICASTArrayModifier, IASTAmbiguityParent { +public class CASTArrayModifier extends ASTAttributeOwner implements ICASTArrayModifier, IASTAmbiguityParent { private IASTExpression exp; private boolean isVolatile; @@ -134,7 +135,10 @@ public class CASTArrayModifier extends ASTNode implements ICASTArrayModifier, IA } if (exp != null && !exp.accept(action)) return false; - + + if (!acceptByAttributeSpecifiers(action)) + return false; + if (action.shouldVisitArrayModifiers && action.leave(this) == ASTVisitor.PROCESS_ABORT) { return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java index 6027776583d..4c900f89e55 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -30,7 +30,7 @@ public class CASTBreakStatement extends ASTAttributeOwner implements IASTBreakSt } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (action.shouldVisitStatements) { switch (action.leave(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java index 32eab5b177c..ae737cecda8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -75,7 +75,7 @@ public class CASTCompoundStatement extends ASTAttributeOwner implements IASTComp } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; IASTStatement[] s = getStatements(); for (int i = 0; i < s.length; i++) { if (!s[i].accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java index d5c811627ef..98553100737 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -30,7 +30,7 @@ public class CASTContinueStatement extends ASTAttributeOwner implements IASTCont } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (action.shouldVisitStatements) { switch (action.leave(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java index 3b5c12d59fb..2e266e9b6a1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,11 +10,13 @@ * Yuan Zhang / Beth Tibbitts (IBM Research) * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -104,4 +106,16 @@ public class CASTDeclarationStatement extends ASTNode // Declaration statements don't have attributes. throw new UnsupportedOperationException(); } + + @Override + public IASTAttributeSpecifier[] getAttributeSpecifiers() { + // Declaration statements don't have attributes. + return IASTAttributeSpecifier.EMPTY_ATTRIBUTE_SPECIFIER_ARRAY; + } + + @Override + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier) { + // Declaration statements don't have attributes. + throw new UnsupportedOperationException(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java index 340c246e640..9966a15ab09 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -149,7 +149,7 @@ public class CASTDeclarator extends ASTAttributeOwner implements IASTDeclarator, return false; } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && nestedDeclarator == null) { if (getParent() instanceof IASTDeclarator) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java index 88e8cd71935..994a9735d13 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -30,7 +30,7 @@ public class CASTDefaultStatement extends ASTAttributeOwner implements IASTDefau } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (action.shouldVisitStatements) { switch (action.leave(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java index 832e4d0bde5..8138c8d5925 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -88,7 +88,7 @@ public class CASTDoStatement extends ASTAttributeOwner implements IASTDoStatemen } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (body != null && !body.accept(action)) return false; if (condition != null && !condition.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java index 446d6d12669..58e9c945b84 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -70,7 +70,7 @@ public class CASTExpressionStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (expression != null && !expression.accept(action)) return false; if (action.shouldVisitStatements) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java index 7480cdfab8b..dc030bb1882 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -139,7 +139,7 @@ public class CASTForStatement extends ASTAttributeOwner implements IASTForStatem } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (init != null && !init.accept(action)) return false; if (condition != null && !condition.accept(action)) return false; if (iterationExpression != null && !iterationExpression.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java index 9b6518bac43..af6fc7d5465 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -66,7 +66,7 @@ public class CASTGotoStatement extends ASTAttributeOwner implements IASTGotoStat } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (name != null && !name.accept(action)) return false; if (action.shouldVisitStatements) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java index e624f165733..2926821e2c6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -125,7 +125,7 @@ public class CASTIfStatement extends ASTAttributeOwner implements IASTIfStatemen } } - if (!((CASTIfStatement) stmt).acceptByAttributes(action)) return false; + if (!((CASTIfStatement) stmt).acceptByAttributeSpecifiers(action)) return false; IASTNode child = stmt.getConditionExpression(); if (child != null && !child.accept(action)) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java index 38331c586b3..1b4985686c8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTLabelStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -73,7 +73,7 @@ public class CASTLabelStatement extends ASTAttributeOwner implements IASTLabelSt } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (name != null && !name.accept(action)) return false; if (nestedStatement != null && !nestedStatement.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java index b568263c0c3..a4363d42811 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNullStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -30,7 +30,7 @@ public class CASTNullStatement extends ASTAttributeOwner implements IASTNullStat } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (action.shouldVisitStatements) { switch (action.leave(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTPointer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTPointer.java index 28d92423357..daa49c4c09e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTPointer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTPointer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,14 +8,15 @@ * Contributors: * John Camelon (IBM Rational Software) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTPointer; -import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; -public class CASTPointer extends ASTNode implements ICASTPointer { +public class CASTPointer extends ASTAttributeOwner implements ICASTPointer { private boolean isRestrict; private boolean isVolatile; @@ -75,9 +76,15 @@ public class CASTPointer extends ASTNode implements ICASTPointer { case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_SKIP : return true; } + } + + if (!acceptByAttributeSpecifiers(action)) + return false; + + if (action.shouldVisitPointerOperators) { if (action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; } - return true; + return true; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java index 413acfbdb11..1cd8b355099 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,11 +10,13 @@ * Yuan Zhang / Beth Tibbitts (IBM Research) * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; @@ -73,4 +75,15 @@ public class CASTProblemStatement extends CASTProblemOwner implements IASTProble assertNotFrozen(); // Ignore. } + + @Override + public IASTAttributeSpecifier[] getAttributeSpecifiers() { + return IASTAttributeSpecifier.EMPTY_ATTRIBUTE_SPECIFIER_ARRAY; + } + + @Override + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier) { + assertNotFrozen(); + // Ignore. + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java index 34f8e9bdaa4..54c85c01829 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -82,7 +82,7 @@ public class CASTReturnStatement extends ASTAttributeOwner implements IASTReturn } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (retValue != null && !retValue.accept(action)) return false; if (action.shouldVisitStatements) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java index ee22a7af765..e3236a328b0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -95,7 +95,7 @@ public class CASTSimpleDeclaration extends ASTAttributeOwner implements IASTSimp } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (declSpecifier != null && !declSpecifier.accept(action)) return false; IASTDeclarator[] dtors = getDeclarators(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java index 26c41ea69ad..b84f6418cf6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -89,7 +89,7 @@ public class CASTSwitchStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (controller != null && !controller.accept(action)) return false; if (body != null && !body.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java index a3417540b82..5165aa7d350 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -89,7 +89,7 @@ public class CASTWhileStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (condition != null && !condition.accept(action)) return false; if (body != null && !body.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java index 1f05eb9f02f..22786b1e921 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 IBM Corporation and others. + * Copyright (c) 2006, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Mike Kucera (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -78,12 +79,14 @@ 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.c.ICNodeFactory; +import org.eclipse.cdt.core.dom.ast.gnu.IGCCASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.internal.core.dom.parser.ASTToken; import org.eclipse.cdt.internal.core.dom.parser.ASTTokenList; +import org.eclipse.cdt.internal.core.dom.parser.GCCASTAttributeSpecifier; import org.eclipse.cdt.internal.core.dom.parser.NodeFactory; import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor; @@ -283,6 +286,11 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory { IASTFunctionDeclarator declarator, IASTStatement bodyStatement) { return new CASTFunctionDefinition(declSpecifier, declarator, bodyStatement); } + + @Override + public IGCCASTAttributeSpecifier newGCCAttributeSpecifier() { + return new GCCASTAttributeSpecifier(); + } @Override public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index 83c43052647..94ec7c33a2f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2013 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -24,7 +24,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException; 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.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; @@ -1351,7 +1351,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } // Accept __attribute__ or __declspec between pointer operators and declarator. - List attributes = + List attributes = __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); // Look for identifier or nested declarator @@ -1422,7 +1422,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } private IASTDeclarator declarator(final List pointerOps, - List attributes, final IASTName declaratorName, + List attributes, final IASTName declaratorName, final IASTDeclarator nestedDeclarator, final int startingOffset, int endOffset, final DeclarationOptions option) throws EndOfFileException, BacktrackException { IASTDeclarator result= null; @@ -1489,8 +1489,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } if (attributes != null) { - for (IASTAttribute attribute : attributes) { - result.addAttribute(attribute); + for (IASTAttributeSpecifier specifier : attributes) { + result.addAttributeSpecifier(specifier); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ASTAttributeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ASTAttributeSpecifier.java new file mode 100644 index 00000000000..d5d35044424 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ASTAttributeSpecifier.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Corbat (IFS) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; +import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTNode; + +/** + * Represents an attribute specifier, containing attributes. + */ +public abstract class ASTAttributeSpecifier extends ASTNode implements IASTAttributeSpecifier { + protected IASTAttribute[] attributes = IASTAttribute.EMPTY_ATTRIBUTE_ARRAY; + + public ASTAttributeSpecifier() { + super(); + } + + @Override + public void addAttribute(IASTAttribute attribute) { + assertNotFrozen(); + if (attribute != null) { + attribute.setParent(this); + attribute.setPropertyInParent(IASTAttributeSpecifier.ATTRIBUTE); + attributes = ArrayUtil.append(attributes, attribute); + } + } + + @Override + public IASTAttribute[] getAttributes() { + attributes = ArrayUtil.trim(attributes); + return attributes; + } + + @Override + public boolean accept(ASTVisitor action) { + if (action.shouldVisitAttributes) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: + return false; + case ASTVisitor.PROCESS_SKIP: + return true; + } + } + + for (IASTAttribute attribute : getAttributes()) { + if (!attribute.accept(action)) + return false; + } + + if (action.shouldVisitAttributes && action.leave(this) == ASTVisitor.PROCESS_ABORT) + return false; + + return true; + } + + protected T copy(T copy, CopyStyle style) { + copy.attributes = ArrayUtil.trim(attributes, true); + for (int i = 0; i < copy.attributes.length; i++) { + IASTAttribute attributeCopy = copy.attributes[i].copy(style); + attributeCopy.setParent(this); + copy.attributes[i] = attributeCopy; + } + return super.copy(copy, style); + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAliasDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAliasDeclaration.java index 17796ae47a1..bc401ecd847 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAliasDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAliasDeclaration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2012, 2014 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -15,9 +15,9 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId; -import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; -public class CPPASTAliasDeclaration extends ASTNode implements ICPPASTAliasDeclaration { +public class CPPASTAliasDeclaration extends ASTAttributeOwner implements ICPPASTAliasDeclaration { private IASTName aliasName; private ICPPASTTypeId mappingTypeId; @@ -87,6 +87,7 @@ public class CPPASTAliasDeclaration extends ASTNode implements ICPPASTAliasDecla } if (aliasName != null && !aliasName.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (mappingTypeId != null && !mappingTypeId.accept(action)) return false; if (action.shouldVisitDeclarations) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java index 67d41afa794..de29004aaa7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 IBM Wind River Systems, Inc. and others. + * Copyright (c) 2008, 2014 IBM Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,11 +8,13 @@ * Contributors: * Markus Schorn - Initial API and implementation * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -127,11 +129,23 @@ public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode } @Override + @Deprecated public void addAttribute(IASTAttribute attribute) { assertNotFrozen(); Assert.isLegal(false); } + @Override + public IASTAttributeSpecifier[] getAttributeSpecifiers() { + return dtors[0].getAttributeSpecifiers(); + } + + @Override + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier) { + assertNotFrozen(); + Assert.isLegal(false); + } + @Override public int getRoleForName(IASTName name) { return dtors[0].getRoleForName(name); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java index ec1823928cc..0fbd9ce152f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 IBM Wind River Systems, Inc. and others. + * Copyright (c) 2009, 2014 IBM Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,11 +8,13 @@ * Contributors: * Markus Schorn - Initial API and implementation * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -139,4 +141,14 @@ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implement public void addAttribute(IASTAttribute attribute) { fSimpleDecl.addAttribute(attribute); } + + @Override + public IASTAttributeSpecifier[] getAttributeSpecifiers() { + return fSimpleDecl.getAttributeSpecifiers(); + } + + @Override + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier) { + fSimpleDecl.addAttributeSpecifier(attributeSpecifier); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java index 6d898528ee8..63905bf0c9c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,11 +9,13 @@ * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -111,4 +113,14 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAm public void addAttribute(IASTAttribute attribute) { throw new UnsupportedOperationException(); } + + @Override + public IASTAttributeSpecifier[] getAttributeSpecifiers() { + return IASTAttributeSpecifier.EMPTY_ATTRIBUTE_SPECIFIER_ARRAY; + } + + @Override + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier) { + throw new UnsupportedOperationException(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java index 29c92c181ec..814794c8a30 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTArrayModifier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -15,13 +16,13 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ -public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, IASTAmbiguityParent { +public class CPPASTArrayModifier extends ASTAttributeOwner implements IASTArrayModifier, IASTAmbiguityParent { private IASTExpression exp; public CPPASTArrayModifier() { @@ -68,7 +69,10 @@ public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, I } if (exp != null && !exp.accept(action)) return false; - + + if (!acceptByAttributeSpecifiers(action)) + return false; + if (action.shouldVisitArrayModifiers && action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttribute.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttribute.java index a676534cb51..c914e217528 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttribute.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttribute.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Google, Inc and others. + * Copyright (c) 2012, 2014 Google, Inc and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,19 +7,25 @@ * * Contributors: * Sergey Prigogin (Google) - initial API and implementation + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.IASTToken; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAttribute; import org.eclipse.cdt.internal.core.dom.parser.ASTAttribute; /** * C++-specific attribute. */ -public class CPPASTAttribute extends ASTAttribute { - - public CPPASTAttribute(char[] name, IASTToken argumentsClause) { +public class CPPASTAttribute extends ASTAttribute implements ICPPASTAttribute { + private final char[] scope; + private final boolean packExpansion; + + public CPPASTAttribute(char[] name, char[] scope, IASTToken argumentsClause, boolean packExpansion) { super(name, argumentsClause); + this.scope = scope; + this.packExpansion = packExpansion; } @Override @@ -32,6 +38,16 @@ public class CPPASTAttribute extends ASTAttribute { IASTToken argumentClause = getArgumentClause(); if (argumentClause != null) argumentClause = argumentClause.copy(style); - return copy(new CPPASTAttribute(getName(), argumentClause), style); + return copy(new CPPASTAttribute(getName(), getScope(), argumentClause, hasPackExpansion()), style); + } + + @Override + public char[] getScope() { + return scope; + } + + @Override + public boolean hasPackExpansion() { + return packExpansion; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttributeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttributeSpecifier.java new file mode 100644 index 00000000000..46e72351721 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttributeSpecifier.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Corbat (IFS) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser.cpp; + +import org.eclipse.cdt.core.dom.parser.cpp.ICPPASTAttributeSpecifier; + +/** + * Represents a C++ attribute specifier, containing attributes. + */ +public class CPPASTAttributeSpecifier extends ASTAttributeSpecifier implements ICPPASTAttributeSpecifier { + @Override + public CPPASTAttributeSpecifier copy(CopyStyle style) { + return copy(new CPPASTAttributeSpecifier(), style); + } + + @Override + public CPPASTAttributeSpecifier copy() { + return copy(CopyStyle.withoutLocations); + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java index c4d6fd0fa7f..d5016748bbb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseDeclSpecifier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,13 +12,13 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; -import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; import org.eclipse.cdt.internal.core.model.ASTStringUtil; /** * Base for all c++ declaration specifiers */ -public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPASTDeclSpecifier { +public abstract class CPPASTBaseDeclSpecifier extends ASTAttributeOwner implements ICPPASTDeclSpecifier { private boolean friend; private boolean inline; private boolean isConst; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java index 30ec00b7303..c99060b0d10 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -29,7 +29,7 @@ public class CPPASTBreakStatement extends ASTAttributeOwner implements IASTBreak } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (action.shouldVisitStatements) { switch (action.leave(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java index caad657005e..f91bb853519 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -69,7 +69,7 @@ public class CPPASTCaseStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (expression != null && !expression.accept(action)) return false; if (action.shouldVisitStatements) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java index e1754748719..92d20c5cbb0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -104,7 +104,7 @@ public class CPPASTCatchHandler extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (declaration != null && !declaration.accept(action)) return false; if (body != null && !body.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java index f979a504796..e5f962e7171 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompositeTypeSpecifier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -178,7 +178,10 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier default: break; } } - + + if (!acceptByAttributeSpecifiers(action)) + return false; + if (fName != null && !fName.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java index ca5e636962e..6176191c3d8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -78,7 +78,7 @@ public class CPPASTCompoundStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; for (IASTStatement statement : statements) { if (statement == null) break; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java index 344a5849dd1..b12b367a79a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -29,7 +29,7 @@ public class CPPASTContinueStatement extends ASTAttributeOwner implements IASTCo } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (action.shouldVisitStatements) { switch (action.leave(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java index fe3fd1e6f7f..f5cf34d49f9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,11 +8,13 @@ * Contributors: * IBM - Initial API and implementation * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -102,4 +104,16 @@ public class CPPASTDeclarationStatement extends ASTNode // Declaration statements don't have attributes. throw new UnsupportedOperationException(); } + + @Override + public IASTAttributeSpecifier[] getAttributeSpecifiers() { + // Declaration statements don't have attributes. + return IASTAttributeSpecifier.EMPTY_ATTRIBUTE_SPECIFIER_ARRAY; + } + + @Override + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier) { + // Declaration statements don't have attributes. + throw new UnsupportedOperationException(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java index e6b84d80805..26d224a6c42 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,11 +9,11 @@ * John Camelon (IBM) - Initial API and implementation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTAttribute; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; @@ -34,6 +34,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; @@ -43,14 +44,13 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; /** * C++ specific declarator. */ -public class CPPASTDeclarator extends ASTNode implements ICPPASTDeclarator, IASTImplicitNameOwner, +public class CPPASTDeclarator extends ASTAttributeOwner implements ICPPASTDeclarator, IASTImplicitNameOwner, IASTAmbiguityParent { private IASTInitializer initializer; private IASTName name; private IASTImplicitName[] implicitNames; private IASTDeclarator nested; private IASTPointerOperator[] pointerOps; - private IASTAttribute[] attributes; private boolean isPackExpansion; public CPPASTDeclarator() { @@ -84,11 +84,8 @@ public class CPPASTDeclarator extends ASTNode implements ICPPASTDeclarator, IAST for (IASTPointerOperator pointer : getPointerOperators()) { copy.addPointerOperator(pointer.copy(style)); } - for (IASTAttribute attribute : getAttributes()) { - copy.addAttribute(attribute.copy(style)); - } return super.copy(copy, style); - } + } @Override public boolean declaresParameterPack() { @@ -102,23 +99,6 @@ public class CPPASTDeclarator extends ASTNode implements ICPPASTDeclarator, IAST return pointerOps; } - @Override - public IASTAttribute[] getAttributes() { - if (attributes == null) return IASTAttribute.EMPTY_ATTRIBUTE_ARRAY; - attributes = ArrayUtil.trim(IASTAttribute.class, attributes); - return attributes; - } - - @Override - public void addAttribute(IASTAttribute attribute) { - assertNotFrozen(); - if (attribute != null) { - attribute.setParent(this); - attribute.setPropertyInParent(ATTRIBUTE); - attributes = ArrayUtil.append(IASTAttribute.class, attributes, attribute); - } - } - @Override public IASTDeclarator getNestedDeclarator() { return nested; @@ -199,14 +179,8 @@ public class CPPASTDeclarator extends ASTNode implements ICPPASTDeclarator, IAST } } - if (attributes != null) { - for (IASTAttribute attribute : attributes) { - if (attribute == null) - break; - if (!attribute.accept(action)) - return false; - } - } + if (!acceptByAttributeSpecifiers(action)) + return false; if (nested == null && name != null) { IASTDeclarator outermost= ASTQueries.findOutermostDeclarator(this); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java index 878773c1727..577ab6bdd17 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -29,7 +29,7 @@ public class CPPASTDefaultStatement extends ASTAttributeOwner implements IASTDef } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (action.shouldVisitStatements) { switch (action.leave(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java index b3ef616f7fc..41a448ebbf5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -88,7 +88,7 @@ public class CPPASTDoStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (body != null && !body.accept(action)) return false; if (condition != null && !condition.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java index acd89eed3e6..1af08592879 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTElaboratedTypeSpecifier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -85,6 +86,10 @@ public class CPPASTElaboratedTypeSpecifier extends CPPASTBaseDeclSpecifier default: break; } } + + if (!acceptByAttributeSpecifiers(action)) + return false; + if (name != null) if (!name.accept(action)) return false; if (action.shouldVisitDeclSpecifiers) { switch (action.leave(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java index b5d58ffd789..1496b64957d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTEnumerationSpecifier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * John Camelon (IBM) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -122,7 +123,10 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier if (fBaseType != null && !fBaseType.accept(action)) { return false; } - + + if (!acceptByAttributeSpecifiers(action)) + return false; + for (IASTEnumerator e : getEnumerators()) { if (!e.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java index 8cd4822ac48..aadb3f23747 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -69,7 +69,7 @@ public class CPPASTExpressionStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (expression != null && !expression.accept(action)) return false; if (action.shouldVisitExpressions) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java index a6183238854..97157aff9ca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -135,7 +135,7 @@ public class CPPASTForStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (init != null && !init.accept(action)) return false; if (condition != null && !condition.accept(action)) return false; if (condDeclaration != null && !condDeclaration.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java index 3db8591e159..acafc5315b1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -22,7 +23,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; @@ -30,7 +31,7 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * Models a function definition without a try-block. If used for a constructor definition * it may contain member initializers. */ -public class CPPASTFunctionDefinition extends ASTNode +public class CPPASTFunctionDefinition extends ASTAttributeOwner implements ICPPASTFunctionDefinition, IASTAmbiguityParent { private IASTDeclSpecifier declSpecifier; private IASTFunctionDeclarator declarator; @@ -182,6 +183,9 @@ public class CPPASTFunctionDefinition extends ASTNode } } + if (!acceptByAttributeSpecifiers(action)) + return false; + if (declSpecifier != null && !declSpecifier.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java index 4d24c5ad678..6390c16088c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -65,7 +65,7 @@ public class CPPASTGotoStatement extends ASTAttributeOwner implements IASTGotoSt } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (name != null && !name.accept(action)) return false; if (action.shouldVisitStatements) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java index 13d5c7421ff..be2a9b84d69 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -133,7 +133,7 @@ public class CPPASTIfStatement extends ASTAttributeOwner implements ICPPASTIfSta } } - if (!((CPPASTIfStatement) stmt).acceptByAttributes(action)) return false; + if (!((CPPASTIfStatement) stmt).acceptByAttributeSpecifiers(action)) return false; IASTNode child = stmt.getConditionExpression(); if (child != null && !child.accept(action)) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java index f3b745d962a..44fa46242d3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -73,7 +73,7 @@ public class CPPASTLabelStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (name != null && !name.accept(action)) return false; if (nestedStatement != null && !nestedStatement.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java index 031fcab0da0..9351d974472 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceDefinition.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * John Camelon (IBM) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -19,14 +20,14 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * Definition of a namespace. */ -public class CPPASTNamespaceDefinition extends ASTNode +public class CPPASTNamespaceDefinition extends ASTAttributeOwner implements ICPPASTNamespaceDefinition, IASTAmbiguityParent { private IASTName fName; private IASTDeclaration[] fAllDeclarations; @@ -129,7 +130,10 @@ public class CPPASTNamespaceDefinition extends ASTNode if (fName != null && !fName.accept(action)) return false; - + + if (!acceptByGCCAttributeSpecifiers(action)) + return false; + IASTDeclaration [] decls = getDeclarations(action.includeInactiveNodes); for (IASTDeclaration decl : decls) { if (!decl.accept(action)) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java index 94c20e2aa85..609dc66b24c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -29,7 +29,7 @@ public class CPPASTNullStatement extends ASTAttributeOwner implements IASTNullSt } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (action.shouldVisitStatements) { switch (action.leave(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointer.java index 0171242a1eb..1cfe697c443 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTPointer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,17 +8,18 @@ * Contributors: * John Camelon (IBM) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTPointer; -import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; /** * A pointer operator of a declarator */ -public class CPPASTPointer extends ASTNode implements IASTPointer { +public class CPPASTPointer extends ASTAttributeOwner implements IASTPointer { private boolean isConst; private boolean isVolatile; private boolean isRestrict; @@ -80,6 +81,12 @@ public class CPPASTPointer extends ASTNode implements IASTPointer { case ASTVisitor.PROCESS_ABORT: return false; case ASTVisitor.PROCESS_SKIP: return true; } + } + + if (!acceptByAttributeSpecifiers(action)) + return false; + + if (action.shouldVisitPointerOperators) { if (action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java index 09cd642a0f1..0c88ae12322 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,11 +9,13 @@ * IBM - Initial API and implementation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; @@ -71,4 +73,15 @@ public class CPPASTProblemStatement extends CPPASTProblemOwner implements IASTPr assertNotFrozen(); // Ignore. } + + @Override + public IASTAttributeSpecifier[] getAttributeSpecifiers() { + return IASTAttributeSpecifier.EMPTY_ATTRIBUTE_SPECIFIER_ARRAY; + } + + @Override + public void addAttributeSpecifier(IASTAttributeSpecifier attributeSpecifier) { + assertNotFrozen(); + // Ignore. + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java index dec522ab979..4285849d705 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2010, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -183,7 +183,7 @@ public class CPPASTRangeBasedForStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (fDeclaration != null && !fDeclaration.accept(action)) return false; if (fInitClause != null && !fInitClause.accept(action)) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReferenceOperator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReferenceOperator.java index 89f16aaaee1..41a5a85abc8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReferenceOperator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReferenceOperator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,17 +8,18 @@ * Contributors: * John Camelon (IBM) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; -import org.eclipse.cdt.internal.core.dom.parser.ASTNode; +import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner; /** * Reference operator for declarators. */ -public class CPPASTReferenceOperator extends ASTNode implements ICPPASTReferenceOperator { +public class CPPASTReferenceOperator extends ASTAttributeOwner implements ICPPASTReferenceOperator { private final boolean fIsRValue; public CPPASTReferenceOperator(boolean isRValueReference) { @@ -45,12 +46,18 @@ public class CPPASTReferenceOperator extends ASTNode implements ICPPASTReference public boolean accept(ASTVisitor action) { if (action.shouldVisitPointerOperators) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: return false; - case ASTVisitor.PROCESS_SKIP: return true; - } + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + } + } + + if (!acceptByAttributeSpecifiers(action)) + return false; + + if (action.shouldVisitPointerOperators) { if (action.leave(this) == ASTVisitor.PROCESS_ABORT) return false; } - return true; + return true; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java index bd02b23e235..d6f69743a83 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -80,7 +80,7 @@ public class CPPASTReturnStatement extends ASTAttributeOwner implements IASTRetu } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (retValue != null && !retValue.accept(action)) return false; if (action.shouldVisitStatements) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java index f686db824f9..608e3dfd649 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclSpecifier.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * John Camelon (IBM) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -213,6 +214,9 @@ public class CPPASTSimpleDeclSpecifier extends CPPASTBaseDeclSpecifier if (fDeclTypeExpression != null && !fDeclTypeExpression.accept(action)) return false; + if (!acceptByAttributeSpecifiers(action)) + return false; + if (action.shouldVisitDeclSpecifiers) { switch (action.leave(this)) { case ASTVisitor.PROCESS_ABORT: return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java index c3beeb30a43..f7accec5e2a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -98,7 +98,7 @@ public class CPPASTSimpleDeclaration extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (declSpecifier != null && !declSpecifier.accept(action)) return false; IASTDeclarator[] dtors = getDeclarators(); for (int i = 0; i < dtors.length; i++) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java index bf739c2875b..8cbfa7d9c81 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -102,7 +102,7 @@ public class CPPASTSwitchStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (controllerExpression != null && !controllerExpression.accept(action)) return false; if (controllerDeclaration != null && !controllerDeclaration.accept(action)) return false; if (body != null && !body.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java index 3dc2620a117..52161253110 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -93,7 +93,7 @@ public class CPPASTTryBlockStatement extends ASTAttributeOwner implements ICPPAS } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (tryBody != null && !tryBody.accept(action)) return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java index ba189cbbd0f..766fecd6e46 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -86,7 +86,7 @@ public class CPPASTUsingDeclaration extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (name != null && !name.accept(action)) return false; if (action.shouldVisitDeclarations) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java index 07f2eb960df..e9e2af5e526 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * John Camelon (IBM) - Initial API and implementation * Bryan Wilkinson (QNX) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -71,8 +72,9 @@ public class CPPASTUsingDirective extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByCPPAttributeSpecifiers(action)) return false; if (name != null && !name.accept(action)) return false; + if (!acceptByGCCAttributeSpecifiers(action)) return false; if (action.shouldVisitDeclarations) { switch (action.leave(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java index 0150824163b..b36354efe4a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -116,7 +116,7 @@ public class CPPASTWhileStatement extends ASTAttributeOwner } } - if (!acceptByAttributes(action)) return false; + if (!acceptByAttributeSpecifiers(action)) return false; if (condition != null && !condition.accept(action)) return false; if (condition2 != null && !condition2.accept(action)) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java index 80279c3e1bd..297ff7ad0c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java @@ -8,12 +8,12 @@ * Contributors: * Mike Kucera (IBM) - initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; -import org.eclipse.cdt.core.dom.ast.IASTAttribute; import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; @@ -54,6 +54,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArraySubscriptExpression; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAttribute; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression; @@ -117,10 +118,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUnaryTypeTransformation; +import org.eclipse.cdt.core.dom.ast.gnu.IGCCASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPASTAttributeSpecifier; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.internal.core.dom.parser.ASTToken; import org.eclipse.cdt.internal.core.dom.parser.ASTTokenList; +import org.eclipse.cdt.internal.core.dom.parser.GCCASTAttributeSpecifier; import org.eclipse.cdt.internal.core.dom.parser.NodeFactory; import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor; @@ -161,8 +165,18 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { } @Override - public IASTAttribute newAttribute(char[] name, IASTToken argumentClause) { - return new CPPASTAttribute(name, argumentClause); + public ICPPASTAttribute newAttribute(char[] name, IASTToken argumentClause) { + return newAttribute(name, null, argumentClause, false); + } + + @Override + public ICPPASTAttribute newAttribute(char[] name, char[] scope, IASTToken argumentClause, boolean packExpansion) { + return new CPPASTAttribute(name, scope, argumentClause, packExpansion); + } + + @Override + public ICPPASTAttributeSpecifier newAttributeSpecifier() { + return new CPPASTAttributeSpecifier(); } @Override @@ -394,7 +408,12 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { IASTStatement bodyStatement) { return new CPPASTFunctionWithTryBlock(declSpecifier, declarator, bodyStatement); } - + + @Override + public IGCCASTAttributeSpecifier newGCCAttributeSpecifier() { + return new GCCASTAttributeSpecifier(); + } + @Override public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) { return new CPPASTCompoundStatementExpression(compoundStatement); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index b0176f41edd..261c5d36828 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2013 IBM Corporation and others. + * Copyright (c) 2002, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -27,7 +27,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException; 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.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTCastExpression; @@ -58,6 +58,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId; 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.IASTToken; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; @@ -68,6 +69,7 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAmbiguousTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArrayDeclarator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAttribute; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; @@ -130,6 +132,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUnaryTypeTransformation; import org.eclipse.cdt.core.dom.parser.IExtensionToken; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPASTAttributeSpecifier; import org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.parser.EndOfFileException; @@ -1939,10 +1942,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @throws BacktrackException * request for a backtrack */ - protected IASTDeclaration usingClause() throws EndOfFileException, BacktrackException { + protected IASTDeclaration usingClause(List attributes) + throws EndOfFileException, BacktrackException { final int offset= consume().getOffset(); - List attributes = null; if (LT(1) == IToken.t_namespace) { // using-directive int endOffset = consume().getEndOffset(); @@ -1957,7 +1960,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throwBacktrack(offset, endOffset - offset); } - attributes = __attribute__(); + attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(supportAttributeSpecifiers, false)); switch (LT(1)) { case IToken.tSEMI: @@ -1968,28 +1971,34 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throw backtrack; } ICPPASTUsingDirective astUD = nodeFactory.newUsingDirective(name); - if (attributes != null) { - for (IASTAttribute attribute : attributes) { - astUD.addAttribute(attribute); - } - } + + addAttributeSpecifiers(attributes, astUD); + ((ASTNode) astUD).setOffsetAndLength(offset, endOffset - offset); return astUD; } - if (LT(1) == IToken.tIDENTIFIER && LT(2) == IToken.tASSIGN){ - return aliasDeclaration(offset); - - } + if (LT(1) == IToken.tIDENTIFIER + && (LT(2) == IToken.tASSIGN || (LT(2) == IToken.tLBRACKET && LT(3) == IToken.tLBRACKET))) { + return aliasDeclaration(offset); + } ICPPASTUsingDeclaration result = usingDeclaration(offset); return result; } + /** + * alias-declaration + * using identifier attribute-specifier-seq? = type-id ; + * + * @throws EndOfFileException + */ private IASTDeclaration aliasDeclaration(final int offset) throws EndOfFileException, BacktrackException { IToken identifierToken = consume(); IASTName aliasName = buildName(-1, identifierToken); - + + List attributes = attributeSpecifierSeq(); + consume(); ICPPASTTypeId aliasedType = typeId(DeclarationOptions.TYPEID); @@ -2000,6 +2009,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { int endOffset = consume().getEndOffset(); ICPPASTAliasDeclaration aliasDeclaration = nodeFactory.newAliasDeclaration(aliasName, aliasedType); + addAttributeSpecifiers(attributes, aliasDeclaration); setRange(aliasDeclaration, offset, endOffset); return aliasDeclaration; } @@ -2303,19 +2313,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * functionDefinition into simpleDeclaration - namespaceAliasDefinition into * namespaceDefinition - usingDirective into usingDeclaration - * explicitInstantiation and explicitSpecialization into templateDeclaration + * - fetched attributes at the beginning to avoid arbitrary lookahead * * @throws BacktrackException * request a backtrack */ @Override protected IASTDeclaration declaration(DeclarationOptions option) throws EndOfFileException, BacktrackException { + List attributes = attributeSpecifierSeq(); switch (LT(1)) { case IToken.t_asm: return asmDeclaration(); case IToken.t_namespace: return namespaceDefinitionOrAlias(); case IToken.t_using: - return usingClause(); + return usingClause(attributes); case IToken.t_static_assert: return staticAssertDeclaration(); case IToken.t_export: @@ -2357,7 +2369,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } try { - return simpleDeclaration(option); + return simpleDeclaration(option, attributes); } catch (BacktrackException e) { if (option != DeclarationOptions.CPP_MEMBER || declarationMark == null) throw e; @@ -2402,12 +2414,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } // bug 195701, gcc 4.2 allows visibility attribute for namespaces. - __attribute_decl_seq(true, false); + List attributeSpecifiers = __attribute_decl_seq(true, false); if (LT(1) == IToken.tLBRACE) { ICPPASTNamespaceDefinition ns = nodeFactory.newNamespaceDefinition(name); ns.setIsInline(isInline); declarationListInBraces(ns, offset, DeclarationOptions.GLOBAL); + addAttributeSpecifiers(attributeSpecifiers, ns); return ns; } @@ -2429,6 +2442,68 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return null; } + protected List attributeSpecifierSeq() throws EndOfFileException, + BacktrackException { + List specifiers = null; + + while (LTcatchEOF(1) == IToken.tLBRACKET && LTcatchEOF(2) == IToken.tLBRACKET) { + if (specifiers == null) + specifiers = new ArrayList(); + int offset = consumeOrEOC(IToken.tLBRACKET).getOffset(); + consumeOrEOC(IToken.tLBRACKET); + ICPPASTAttributeSpecifier attributeSpecifier = nodeFactory.newAttributeSpecifier(); + while (LT(1) != IToken.tRBRACKET) { + if (LT(1) == IToken.tCOMMA) + consume(); + ICPPASTAttribute attribute = singleAttribute(); + attributeSpecifier.addAttribute(attribute); + + } + consumeOrEOC(IToken.tRBRACKET); + int endOffset = consumeOrEOC(IToken.tRBRACKET).getEndOffset(); + setRange(attributeSpecifier, offset, endOffset); + specifiers.add(attributeSpecifier); + } + return specifiers; + } + + @Override + protected ICPPASTAttribute singleAttribute() throws EndOfFileException, BacktrackException { + // Get an identifier including keywords + IToken nameToken = identifierOrKeyword(); + IToken scopeToken = null; + IASTToken argumentClause = null; + boolean packExpansion = false; + + // Check for scoped attribute + if (LT(1) == IToken.tCOLONCOLON) { + consume(); + scopeToken = nameToken; + nameToken = identifierOrKeyword(); + } + int endOffset = nameToken.getEndOffset(); + + // Check for arguments + if (LT(1) == IToken.tLPAREN) { + IToken t = consume(); + argumentClause = balancedTokenSeq(t.getEndOffset(), IToken.tRPAREN); + //endOffset = calculateEndOffset(argumentClause); + endOffset = consume(IToken.tRPAREN).getEndOffset(); + } + + // Check for pack expansion + if (LT(1) == IToken.tELLIPSIS) { + packExpansion = true; + endOffset = consumeOrEOC(IToken.tELLIPSIS).getEndOffset(); + } + char[] attributeName = nameToken.getCharImage(); + char[] scopeName = scopeToken != null ? scopeToken.getCharImage() : null; + ICPPASTAttribute result = nodeFactory.newAttribute(attributeName, scopeName, + argumentClause, packExpansion); + setRange(result, nameToken.getOffset(), endOffset); + return result; + } + @Override protected boolean isLegalWithoutDtor(IASTDeclSpecifier declSpec) { if (declSpec instanceof IASTElaboratedTypeSpecifier) { @@ -2443,7 +2518,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { /** * Parses a declaration with the given options. */ - protected IASTDeclaration simpleDeclaration(DeclarationOptions declOption) throws BacktrackException, EndOfFileException { + protected IASTDeclaration simpleDeclaration(DeclarationOptions declOption, List attributes) + throws BacktrackException, EndOfFileException { if (LT(1) == IToken.tLBRACE) throwBacktrack(LA(1)); @@ -2524,7 +2600,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { declSpec= altDeclSpec; dtor= altDtor; } - return functionDefinition(firstOffset, declSpec, dtor); + ICPPASTFunctionDefinition functionDefinition = functionDefinition(firstOffset, declSpec, dtor); + addAttributeSpecifiers(attributes, functionDefinition); + return functionDefinition; default: insertSemi= true; @@ -2575,10 +2653,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTProblem problem= createProblem(IProblem.MISSING_SEMICOLON, endOffset-1, 1); throwBacktrack(problem, simpleDeclaration); } + addAttributeSpecifiers(attributes, simpleDeclaration); return simpleDeclaration; } - private IASTDeclaration functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec, + private ICPPASTFunctionDefinition functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec, IASTDeclarator outerDtor) throws EndOfFileException, BacktrackException { final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(outerDtor); @@ -2759,6 +2838,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IToken returnToken= null; ICPPASTDeclSpecifier result= null; ICPPASTDeclSpecifier altResult= null; + List attributes = null; try { IASTName identifier= null; IASTExpression typeofExpression= null; @@ -2771,7 +2851,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final int offset = LA(1).getOffset(); int endOffset= offset; - declSpecifiers: for (;;) { + declSpecifiers: for (;;) { final int lt1= LTcatchEOF(1); switch (lt1) { case 0: // encountered eof @@ -3029,7 +3109,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { case IGCCToken.t__attribute__: // if __attribute__ is after the declSpec if (!supportAttributeSpecifiers) throwBacktrack(LA(1)); - __attribute_decl_seq(true, false); + attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(true, false)); break; case IGCCToken.t__declspec: // __declspec precedes the identifier if (identifier != null || !supportDeclspecSpecifiers) @@ -3108,6 +3188,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { throwBacktrack(LA(1)); } + attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq()); + if (result != null) { configureDeclSpec(result, storageClass, options); // cannot store restrict in the cpp-nodes. @@ -3122,6 +3204,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } else { result= buildSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset); } + addAttributeSpecifiers(attributes, result); } catch (BacktrackException e) { if (returnToken != null) { backup(returnToken); @@ -3189,6 +3272,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { boolean isScoped= false; IASTName name= null; ICPPASTDeclSpecifier baseType= null; + List attributes = null; try { int lt1= LT(1); @@ -3197,7 +3281,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { consume(); } // if __attribute__ or __declspec occurs after struct/union/class and before the identifier - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + attributes = __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq()); if (isScoped || LT(1) == IToken.tIDENTIFIER) { name= identifier(); @@ -3238,6 +3323,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { endOffset= enumBody(result); } assert endOffset != 0; + addAttributeSpecifiers(attributes, result); return setRange(result, offset, endOffset); } @@ -3272,10 +3358,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final int offset= consume().getOffset(); // if __attribute__ or __declspec occurs after struct/union/class and before the identifier - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + List attributes = __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq()); IASTName name = qualifiedName(); - return setRange(nodeFactory.newElaboratedTypeSpecifier(eck, name), offset, calculateEndOffset(name)); + ICPPASTElaboratedTypeSpecifier elaboratedTypeSpecifier = nodeFactory.newElaboratedTypeSpecifier(eck, name); + addAttributeSpecifiers(attributes, elaboratedTypeSpecifier); + return setRange(elaboratedTypeSpecifier, offset, calculateEndOffset(name)); } /** @@ -3750,7 +3839,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } // Accept __attribute__ or __declspec between pointer operators and declarator. - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + List attributes = __attribute_decl_seq(supportAttributeSpecifiers, + supportDeclspecSpecifiers); // Look for identifier or nested declarator boolean hasEllipsis= false; @@ -3770,7 +3860,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final IASTName declaratorName= !option.fRequireSimpleName ? qualifiedName() : identifier(); endOffset= calculateEndOffset(declaratorName); - return declarator(pointerOps, hasEllipsis, declaratorName, null, startingOffset, endOffset, strategy, option); + return declarator(pointerOps, hasEllipsis, declaratorName, null, startingOffset, + endOffset, strategy, option, attributes); } if (lt1 == IToken.tLPAREN) { @@ -3780,7 +3871,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (option.fAllowAbstract && option.fAllowFunctions) { final IToken mark= mark(); try { - cand1= declarator(pointerOps, hasEllipsis, nodeFactory.newName(), null, startingOffset, endOffset, strategy, option); + cand1= declarator(pointerOps, hasEllipsis, nodeFactory.newName(), null, + startingOffset, endOffset, strategy, option, attributes); if (option.fRequireAbstract || !option.fAllowNested || hasEllipsis) return cand1; @@ -3793,7 +3885,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // type-ids for new or operator-id: if (!option.fAllowNested || hasEllipsis) { if (option.fAllowAbstract) { - return declarator(pointerOps, hasEllipsis, nodeFactory.newName(), null, startingOffset, endOffset, strategy, option); + return declarator(pointerOps, hasEllipsis, nodeFactory.newName(), null, + startingOffset, endOffset, strategy, option, attributes); } throwBacktrack(LA(1)); } @@ -3806,7 +3899,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { final IASTDeclarator nested= declarator(DtorStrategy.PREFER_FUNCTION, option); endOffset= consume(IToken.tRPAREN).getEndOffset(); - final IASTDeclarator cand2= declarator(pointerOps, hasEllipsis, nodeFactory.newName(), nested, startingOffset, endOffset, strategy, option); + final IASTDeclarator cand2= declarator(pointerOps, hasEllipsis, nodeFactory.newName(), nested, + startingOffset, endOffset, strategy, option, attributes); if (cand1 == null || cand1End == null) return cand2; final IToken cand2End= LA(1); @@ -3833,12 +3927,16 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (!option.fAllowBitField || LT(1) != IToken.tCOLON) throwBacktrack(LA(1)); } - return declarator(pointerOps, hasEllipsis, nodeFactory.newName(), null, startingOffset, endOffset, strategy, option); + return declarator(pointerOps, hasEllipsis, nodeFactory.newName(), null, startingOffset, + endOffset, strategy, option, attributes); } /** - * Parse a Pointer Operator. ptrOperator : "*" (cvQualifier)* | "&" | ::? - * nestedNameSpecifier "*" (cvQualifier)* + * Parse a Pointer Operator. + * ptrOperator : "*" attribute-specifier-seq? (cvQualifier)* + * | "&" attribute-specifier-seq? + * | "&&" attribute-specifier-seq? + * | ::? nestedNameSpecifier "*" attribute-specifier-seq? (cvQualifier)* * * @throws BacktrackException * request a backtrack @@ -3846,8 +3944,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { private List consumePointerOperators() throws EndOfFileException, BacktrackException { List result= null; for (;;) { + IToken mark = mark(); + final int startOffset = mark.getOffset(); + // __attribute__ in-between pointers - __attribute_decl_seq(supportAttributeSpecifiers, false); + List attributes = __attribute_decl_seq(supportAttributeSpecifiers, false); final int lt1 = LT(1); if (lt1 == IToken.tAMPER || lt1 == IToken.tAND) { @@ -3859,6 +3960,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } ICPPASTReferenceOperator refOp = nodeFactory.newReferenceOperator(lt1 == IToken.tAND); setRange(refOp, offset, endToken.getEndOffset()); + + attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq()); + addAttributeSpecifiers(attributes, refOp); + if (result != null) { result.add(refOp); return result; @@ -3866,8 +3971,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return Collections.singletonList(refOp); } - IToken mark = mark(); - final int startOffset = mark.getOffset(); boolean isConst = false, isVolatile = false, isRestrict = false; IASTName name= null; int coloncolon= LT(1) == IToken.tCOLONCOLON ? 1 : 0; @@ -3936,16 +4039,19 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (result == null) { result= new ArrayList(4); } + + attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq()); + addAttributeSpecifiers(attributes, pointer); + result.add(pointer); } } private IASTDeclarator declarator(List pointerOps, boolean hasEllipsis, IASTName declaratorName, IASTDeclarator nestedDeclarator, int startingOffset, int endOffset, - DtorStrategy strategy, DeclarationOptions option) + DtorStrategy strategy, DeclarationOptions option, List attributes) throws EndOfFileException, BacktrackException { ICPPASTDeclarator result= null; - List attributes = null; loop: while(true) { final int lt1= LTcatchEOF(1); switch (lt1) { @@ -3957,6 +4063,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { break loop; case IToken.tLBRACKET: + if (LTcatchEOF(2) == IToken.tLBRACKET) { + attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq()); + break; + } result= arrayDeclarator(option); setDeclaratorID(result, hasEllipsis, declaratorName, nestedDeclarator); break loop; @@ -4009,11 +4119,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - if (attributes != null) { - for (IASTAttribute attribute : attributes) { - result.addAttribute(attribute); - } - } + addAttributeSpecifiers(attributes, result); ((ASTNode) result).setOffsetAndLength(startingOffset, endOffset - startingOffset); return result; @@ -4078,7 +4184,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } // Consume any number of __attribute__ tokens after the parameters - List attributes = __attribute_decl_seq(supportAttributeSpecifiers, false); + List attributes = __attribute_decl_seq(supportAttributeSpecifiers, false); // cv-qualifiers if (isLambdaDeclarator) { @@ -4160,6 +4266,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { fc.setNoexceptExpression((ICPPASTExpression) expression); } + attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq()); + addAttributeSpecifiers(attributes, fc); + if (attributes != null && !attributes.isEmpty()) { + endOffset = getEndOffset(); + } + if (LT(1) == IToken.tARROW) { consume(); IASTTypeId typeId= typeId(DeclarationOptions.TYPEID_TRAILING_RETURN_TYPE); @@ -4167,12 +4279,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { endOffset= calculateEndOffset(typeId); } - if (attributes != null) { - for (IASTAttribute attribute : attributes) { - fc.addAttribute(attribute); - } - } - return setRange(fc, startOffset, endOffset); } @@ -4211,7 +4317,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } /** - * Parse a class/struct/union definition. classSpecifier : classKey name + * Parse a class/struct/union definition. classSpecifier : classKey attribute-specifier-seq? name * (baseClause)? "{" (memberSpecification)* "}" * * @throws BacktrackException @@ -4242,7 +4348,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } // if __attribute__ or __declspec occurs after struct/union/class and before the identifier - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + List attributes = __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq()); // class name IASTName name = null; @@ -4253,9 +4360,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } // if __attribute__ or __declspec occurs after struct/union/class identifier and before the { or ; - __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers); + attributes = CollectionUtils.merge(attributes, __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers)); ICPPASTCompositeTypeSpecifier astClassSpecifier = nodeFactory.newCompositeTypeSpecifier(classKind, name); + addAttributeSpecifiers(attributes, astClassSpecifier); // class virt specifier if (LT(1) == IToken.tIDENTIFIER) { @@ -4435,6 +4543,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTDeclSpecifier declSpec; IASTDeclarator declarator; + List attributes = attributeSpecifierSeq(); try { Decl decl= declSpecifierSequence_initDeclarator(options, true); declSpec= decl.fDeclSpec1; @@ -4449,6 +4558,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (declarator != null) decl.addDeclarator(declarator); ((ASTNode) decl).setOffsetAndLength(startOffset, endOffset - startOffset); + addAttributeSpecifiers(attributes, decl); return decl; } @@ -4509,6 +4619,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } IASTArrayModifier arrayMod = nodeFactory.newArrayModifier(exp); ((ASTNode) arrayMod).setOffsetAndLength(o, l - o); + + List attributes = attributeSpecifierSeq(); + addAttributeSpecifiers(attributes, arrayMod); + collection.add(arrayMod); } return; @@ -4521,49 +4635,69 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { @Override protected IASTStatement statement() throws EndOfFileException, BacktrackException { + List attributes = attributeSpecifierSeq(); + + IASTStatement statement = null; switch (LT(1)) { // labeled statements case IToken.t_case: - return parseCaseStatement(); + statement = parseCaseStatement(); + break; case IToken.t_default: - return parseDefaultStatement(); + statement = parseDefaultStatement(); + break; // compound statement case IToken.tLBRACE: - return parseCompoundStatement(); + statement = parseCompoundStatement(); + break; // selection statement case IToken.t_if: - return parseIfStatement(); + statement = parseIfStatement(); + break; case IToken.t_switch: - return parseSwitchStatement(); + statement = parseSwitchStatement(); + break; // iteration statements case IToken.t_while: - return parseWhileStatement(); + statement = parseWhileStatement(); + break; case IToken.t_do: - return parseDoStatement(); + statement = parseDoStatement(); + break; case IToken.t_for: - return parseForStatement(); + statement = parseForStatement(); + break; // jump statement case IToken.t_break: - return parseBreakStatement(); + statement = parseBreakStatement(); + break; case IToken.t_continue: - return parseContinueStatement(); + statement = parseContinueStatement(); + break; case IToken.t_return: - return parseReturnStatement(); + statement = parseReturnStatement(); + break; case IToken.t_goto: - return parseGotoStatement(); + statement = parseGotoStatement(); + break; case IToken.tSEMI: - return parseNullStatement(); + statement = parseNullStatement(); + break; case IToken.t_try: - return parseTryStatement(); + statement = parseTryStatement(); + break; default: // can be many things: // label if (LT(1) == IToken.tIDENTIFIER && LT(2) == IToken.tCOLON) { - return parseLabelStatement(); + statement = parseLabelStatement(); + break; } - return parseDeclarationOrExpressionStatement(); + return parseDeclarationOrExpressionStatement(attributes); } + addAttributeSpecifiers(attributes, statement); + return statement; } protected IASTStatement parseTryStatement() throws EndOfFileException, BacktrackException { @@ -4836,12 +4970,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // Look for "for-range-declaration : for-range-initializer" // for-range-declaration: - // attribute-specifier? type-specifier-seq declarator + // attribute-specifier-seq? type-specifier-seq declarator // for-range-initializer: // expression // braced-init-list private ICPPASTRangeBasedForStatement startRangeBasedForLoop() throws EndOfFileException, BacktrackException { - IASTDeclaration decl= simpleDeclaration(DeclarationOptions.RANGE_BASED_FOR); + List attributes = attributeSpecifierSeq(); + IASTDeclaration decl= simpleDeclaration(DeclarationOptions.RANGE_BASED_FOR, attributes); consume(IToken.tCOLON); IASTInitializerClause init= null; switch (LT(1)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java index 320140af070..6ed9d47371f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -10,11 +10,15 @@ * Institute for Software - initial API and implementation * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; +import java.util.List; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; @@ -28,15 +32,13 @@ import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.internal.core.dom.rewrite.ASTLiteralNode; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; -import java.util.List; - /** * Visits all nodes, prints leading comments and handles macro expansions. The * source code generation is delegated to severals {@code NodeWriter}s. @@ -56,6 +58,7 @@ public class ASTWriterVisitor extends ASTVisitor { protected InitializerWriter initializerWriter; protected NameWriter nameWriter; protected TemplateParameterWriter tempParameterWriter; + protected AttributeWriter attributeWriter; protected MacroExpansionHandler macroHandler; private boolean insertLeadingBlankLine; private boolean suppressLeadingBlankLine; @@ -77,6 +80,7 @@ public class ASTWriterVisitor extends ASTVisitor { shouldVisitTemplateParameters = true; shouldVisitTranslationUnit = true; shouldVisitTypeIds = true; + shouldVisitAttributes= true; } /** @@ -104,6 +108,7 @@ public class ASTWriterVisitor extends ASTVisitor { // ppStmtWriter = new PreprocessorStatementWriter(scribe, this, commentMap); nameWriter = new NameWriter(scribe, this, commentMap); tempParameterWriter = new TemplateParameterWriter(scribe, this, commentMap); + attributeWriter = new AttributeWriter(scribe, this, commentMap); } @Override @@ -286,6 +291,12 @@ public class ASTWriterVisitor extends ASTVisitor { return ASTVisitor.PROCESS_SKIP; } + @Override + public int visit(IASTAttributeSpecifier specifier) { + attributeWriter.writeAttributeSpecifier(specifier); + return ASTVisitor.PROCESS_SKIP; + } + public void cleanCache() { scribe.cleanCache(); macroHandler.reset(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/AttributeWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/AttributeWriter.java new file mode 100644 index 00000000000..e94a4455c0e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/AttributeWriter.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Corbat (IFS) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; + +import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; +import org.eclipse.cdt.core.dom.ast.IASTToken; +import org.eclipse.cdt.core.dom.ast.IASTTokenList; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAttribute; +import org.eclipse.cdt.core.dom.ast.gnu.IGCCASTAttributeSpecifier; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPASTAttributeSpecifier; +import org.eclipse.cdt.core.parser.GCCKeywords; +import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTAttribute; +import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; + +/** + * Generates source code for attribute nodes. The actual string operations are delegated to the + * Scribe class. + * + * @see Scribe + * @see IASTAttribute + */ +public class AttributeWriter extends NodeWriter { + + public AttributeWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) { + super(scribe, visitor, commentMap); + } + + public void writeAttributeSpecifier(IASTAttributeSpecifier attribute) { + if (attribute instanceof ICPPASTAttributeSpecifier) { + writeAttributeSpecifier((ICPPASTAttributeSpecifier) attribute); + } else if (attribute instanceof IGCCASTAttributeSpecifier) { + writeGCCAttributeSpecifier((IGCCASTAttributeSpecifier) attribute); + } + } + + private void writeGCCAttributeSpecifier(IGCCASTAttributeSpecifier specifier) { + scribe.print(GCCKeywords.__ATTRIBUTE__); + scribe.print(OPENING_PARENTHESIS); + scribe.print(OPENING_PARENTHESIS); + IASTAttribute[] innerAttributes = specifier.getAttributes(); + for (int i = 0; i < innerAttributes.length; i++) { + IASTAttribute innerAttribute = innerAttributes[i]; + writeAttribute((CPPASTAttribute)innerAttribute); + if (i < innerAttributes.length - 1) { + scribe.print(','); + scribe.printSpace(); + } + } + scribe.print(CLOSING_PARENTHESIS); + scribe.print(CLOSING_PARENTHESIS); + } + + private void writeAttributeSpecifier(ICPPASTAttributeSpecifier specifier) { + scribe.print(OPENING_SQUARE_BRACKET); + scribe.print(OPENING_SQUARE_BRACKET); + IASTAttribute[] innerAttributes = specifier.getAttributes(); + for (int i = 0; i < innerAttributes.length; i++) { + IASTAttribute innerAttribute = innerAttributes[i]; + writeAttribute((ICPPASTAttribute)innerAttribute); + if (i < innerAttributes.length - 1) { + scribe.print(','); + scribe.printSpace(); + } + } + scribe.print(CLOSING_SQUARE_BRACKET); + scribe.print(CLOSING_SQUARE_BRACKET); + } + + private void writeAttribute(ICPPASTAttribute attribute) { + char[] scope = attribute.getScope(); + if (scope != null) { + scribe.print(scope); + scribe.print(COLON_COLON); + } + scribe.print(attribute.getName()); + + IASTToken argumentClause = attribute.getArgumentClause(); + if (argumentClause != null) { + scribe.print(OPENING_PARENTHESIS); + printTokens(argumentClause); + scribe.print(CLOSING_PARENTHESIS); + } + + if (attribute.hasPackExpansion()) { + scribe.printSpace(); + scribe.print(VAR_ARGS); + } + } + + protected void printTokens(IASTToken token) { + if (token instanceof IASTTokenList) { + for (IASTToken innerToken : ((IASTTokenList) token).getTokens()) { + printTokens(innerToken); + } + } else { + char[] tokenCharImage = token.getTokenCharImage(); + scribe.print(tokenCharImage); + } + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java index da523e529ca..e7482b2302d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclSpecWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; +import java.util.EnumSet; + +import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner; import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; @@ -153,6 +156,9 @@ public class DeclSpecWriter extends NodeWriter { private void writeElaboratedTypeSec(IASTElaboratedTypeSpecifier elabType) { scribe.printStringSpace(getElabTypeString(elabType.getKind())); + if (elabType instanceof IASTAttributeOwner) { + writeAttributes((IASTAttributeOwner) elabType, EnumSet.of(SpaceLocation.AFTER)); + } elabType.getName().accept(visitor); } @@ -207,6 +213,9 @@ public class DeclSpecWriter extends NodeWriter { private void writeEnumSpec(IASTEnumerationSpecifier enumSpec) { scribe.printStringSpace(Keywords.ENUM); + if (enumSpec instanceof IASTAttributeOwner) { + writeAttributes((IASTAttributeOwner) enumSpec, EnumSet.of(SpaceLocation.AFTER)); + } enumSpec.getName().accept(visitor); scribe.print('{'); scribe.printSpace(); @@ -233,6 +242,9 @@ public class DeclSpecWriter extends NodeWriter { private void writeCompositeTypeSpecifier(IASTCompositeTypeSpecifier compDeclSpec) { boolean hasTrailingComments = hasTrailingComments(compDeclSpec.getName()); scribe.printStringSpace(getCPPCompositeTypeString(compDeclSpec.getKey())); + if (compDeclSpec instanceof IASTAttributeOwner) { + writeAttributes((IASTAttributeOwner) compDeclSpec, EnumSet.of(SpaceLocation.AFTER)); + } compDeclSpec.getName().accept(visitor); if (compDeclSpec instanceof ICPPASTCompositeTypeSpecifier) { ICPPASTCompositeTypeSpecifier cppComp = (ICPPASTCompositeTypeSpecifier) compDeclSpec; @@ -356,6 +368,7 @@ public class DeclSpecWriter extends NodeWriter { private void writeCPPSimpleDeclSpec(ICPPASTSimpleDeclSpecifier simpDeclSpec) { printQualifiers(simpDeclSpec); scribe.print(getCPPSimpleDecSpecifier(simpDeclSpec)); + writeAttributes(simpDeclSpec, EnumSet.of(SpaceLocation.BEFORE)); if (simpDeclSpec.getType() == IASTSimpleDeclSpecifier.t_typeof) { scribe.printSpace(); visitNodeIfNotNull(simpDeclSpec.getDeclTypeExpression()); @@ -377,7 +390,7 @@ public class DeclSpecWriter extends NodeWriter { scribe.printStringSpace(Keywords.SHORT); } else if (simpDeclSpec.isLong()) { scribe.printStringSpace(Keywords.LONG); - } else if (simpDeclSpec.isLongLong()) { + } else if (simpDeclSpec.isLongLong()) { scribe.printStringSpace(Keywords.LONG); scribe.printStringSpace(Keywords.LONG); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java index 8776a2a3df9..bca52929c1c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -14,7 +14,10 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; +import java.util.EnumSet; + import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; @@ -23,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTAliasDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; @@ -116,6 +120,7 @@ public class DeclarationWriter extends NodeWriter { if (alias != null) { alias.accept(visitor); } + writeAttributes(aliasDeclaration, EnumSet.of(SpaceLocation.BEFORE)); scribe.print(EQUALS); ICPPASTTypeId aliasedType = aliasDeclaration.getMappingTypeId(); if (aliasedType != null) { @@ -146,9 +151,11 @@ public class DeclarationWriter extends NodeWriter { } private void writeUsingDirective(ICPPASTUsingDirective usingDirective) { + writeCPPAttributes(usingDirective, EnumSet.of(SpaceLocation.AFTER)); scribe.printStringSpace(Keywords.USING); scribe.printStringSpace(Keywords.NAMESPACE); usingDirective.getQualifiedName().accept(visitor); + writeGCCAttributes(usingDirective, EnumSet.of(SpaceLocation.BEFORE)); scribe.printSemicolon(); } @@ -192,6 +199,7 @@ public class DeclarationWriter extends NodeWriter { private void writeNamespaceDefinition(ICPPASTNamespaceDefinition namespaceDefinition) { scribe.printStringSpace(Keywords.NAMESPACE); namespaceDefinition.getName().accept(visitor); + writeGCCAttributes(namespaceDefinition, EnumSet.of(SpaceLocation.BEFORE)); if (!hasTrailingComments(namespaceDefinition.getName())) { scribe.newLine(); } @@ -275,6 +283,9 @@ public class DeclarationWriter extends NodeWriter { } private void writeFunctionDefinition(IASTFunctionDefinition funcDef) { + if (funcDef instanceof IASTAttributeOwner) { + writeAttributes((IASTAttributeOwner) funcDef, EnumSet.of(SpaceLocation.AFTER)); + } IASTDeclSpecifier declSpecifier = funcDef.getDeclSpecifier(); if (declSpecifier != null) declSpecifier.accept(visitor); @@ -297,10 +308,22 @@ public class DeclarationWriter extends NodeWriter { if (funcDef instanceof ICPPASTFunctionDefinition) { ICPPASTFunctionDefinition cppFuncDef= (ICPPASTFunctionDefinition) funcDef; writeCtorChainInitializer(cppFuncDef, cppFuncDef.getMemberInitializers()); + if (cppFuncDef.isDefaulted()) { + scribe.print(EQUALS); + scribe.print(Keywords.DEFAULT); + scribe.printSemicolon(); + } else if (cppFuncDef.isDeleted()) { + scribe.print(EQUALS); + scribe.print(Keywords.DELETE); + scribe.printSemicolon(); + } } scribe.newLine(); - funcDef.getBody().accept(visitor); + IASTStatement body = funcDef.getBody(); + if (body != null) { + body.accept(visitor); + } if (funcDef instanceof ICPPASTFunctionWithTryBlock) { ICPPASTFunctionWithTryBlock tryblock = (ICPPASTFunctionWithTryBlock) funcDef; @@ -330,6 +353,7 @@ public class DeclarationWriter extends NodeWriter { IASTDeclSpecifier declSpecifier = simpDec.getDeclSpecifier(); IASTDeclarator[] decls = simpDec.getDeclarators(); + writeAttributes(simpDec, EnumSet.of(SpaceLocation.AFTER)); declSpecifier.accept(visitor); boolean noSpace = false; if (declSpecifier instanceof IASTSimpleDeclSpecifier) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java index e89395bbdd5..585c332517f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -14,6 +14,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; +import java.util.EnumSet; + import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; @@ -65,7 +67,7 @@ public class DeclaratorWriter extends NodeWriter { } visitor.setSpaceNeededBeforeName(false); - writeTrailingComments(declarator, false); + writeTrailingComments(declarator, false); } protected void writeDefaultDeclarator(IASTDeclarator declarator) { @@ -74,6 +76,7 @@ public class DeclaratorWriter extends NodeWriter { IASTName name = declarator.getName(); name.accept(visitor); writeNestedDeclarator(declarator); + writeAttributes(declarator, EnumSet.of(SpaceLocation.BEFORE)); IASTInitializer init = getInitializer(declarator); if (init != null) { init.accept(visitor); @@ -82,7 +85,9 @@ public class DeclaratorWriter extends NodeWriter { protected void writePointerOperators(IASTDeclarator declarator, IASTPointerOperator[] pointOps) { for (IASTPointerOperator operator : pointOps) { + writeGCCAttributes(operator, EnumSet.noneOf(SpaceLocation.class)); writePointerOperator(operator); + writeCPPAttributes(operator, EnumSet.noneOf(SpaceLocation.class)); } } @@ -153,6 +158,7 @@ public class DeclaratorWriter extends NodeWriter { scribe.print(PURE_VIRTUAL); } writeExceptionSpecification(funcDec, funcDec.getExceptionSpecification(), funcDec.getNoexceptExpression()); + writeAttributes(funcDec, EnumSet.of(SpaceLocation.BEFORE)); if (funcDec.getTrailingReturnType() != null) { scribe.printSpace(); scribe.print(ARROW_OPERATOR); @@ -260,6 +266,7 @@ public class DeclaratorWriter extends NodeWriter { ex.accept(visitor); } scribe.print(']'); + writeAttributes(modifier, EnumSet.noneOf(SpaceLocation.class)); } private void writeFieldDeclarator(IASTFieldDeclarator fieldDecl) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java index 774aa8791e9..142998e2d2b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -110,8 +110,6 @@ public class ExpressionWriter extends NodeWriter{ private static final String MODULO_OP = " % "; //$NON-NLS-1$ private static final String DIVIDE_OP = " / "; //$NON-NLS-1$ private static final String MULTIPLY_OP = " * "; //$NON-NLS-1$ - private static final String OPENING_SQUARE_BRACKET = "["; //$NON-NLS-1$ - private static final String CLOSING_SQUARE_BRACKET = "]"; //$NON-NLS-1$ private static final String THIS = "this"; //$NON-NLS-1$ private static final String THROW = "throw "; //$NON-NLS-1$ private final MacroExpansionHandler macroHandler; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java index 6e654b9b711..c57b9f68fa5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,13 +9,20 @@ * Contributors: * Institute for Software - initial API and implementation * Sergey Prigogin (Google) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; +import java.util.EnumSet; import java.util.List; +import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner; +import org.eclipse.cdt.core.dom.ast.IASTAttributeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.gnu.IGCCASTAttributeSpecifier; +import org.eclipse.cdt.core.dom.parser.cpp.ICPPASTAttributeSpecifier; +import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; /** @@ -34,6 +41,11 @@ public class NodeWriter { protected static final String VAR_ARGS = "..."; //$NON-NLS-1$ protected static final String COLON_COLON = "::"; //$NON-NLS-1$ protected static final String COLON_SPACE = ": "; //$NON-NLS-1$ + protected static final String OPENING_SQUARE_BRACKET = "["; //$NON-NLS-1$ + protected static final String CLOSING_SQUARE_BRACKET = "]"; //$NON-NLS-1$ + protected static final String OPENING_PARENTHESIS = "("; //$NON-NLS-1$ + protected static final String CLOSING_PARENTHESIS = ")"; //$NON-NLS-1$ + protected enum SpaceLocation {BEFORE, AFTER} public NodeWriter(Scribe scribe, ASTWriterVisitor visitor, NodeCommentMap commentMap) { super(); @@ -107,4 +119,36 @@ public class NodeWriter { scribe.newLine(); } } + + protected void writeAttributes(IASTAttributeOwner attributeOwner, EnumSet spaceLocations) { + IASTAttributeSpecifier[] specifiers = attributeOwner.getAttributeSpecifiers(); + writeAttributes(specifiers, spaceLocations); + } + + protected void writeGCCAttributes(IASTAttributeOwner attributeOwner, EnumSet spaceLocations) { + IASTAttributeSpecifier[] specifiers = attributeOwner.getAttributeSpecifiers(); + IASTAttributeSpecifier[] gnuSpecifiers = ArrayUtil.filter(specifiers, IGCCASTAttributeSpecifier.TYPE_FILTER); + writeAttributes(gnuSpecifiers, spaceLocations); + } + + protected void writeCPPAttributes(IASTAttributeOwner attributeOwner, EnumSet spaceLocations) { + IASTAttributeSpecifier[] specifiers = attributeOwner.getAttributeSpecifiers(); + IASTAttributeSpecifier[] cppSpecifiers = ArrayUtil.filter(specifiers, ICPPASTAttributeSpecifier.TYPE_FILTER); + writeAttributes(cppSpecifiers, spaceLocations); + } + + private void writeAttributes(IASTAttributeSpecifier[] specifiers, EnumSet spaceLocations) { + if (specifiers.length == 0) + return; + + if (spaceLocations.contains(SpaceLocation.BEFORE)) { + scribe.printSpace(); + } + for (IASTAttributeSpecifier specifier : specifiers) { + specifier.accept(visitor); + } + if (spaceLocations.contains(SpaceLocation.AFTER)) { + scribe.printSpace(); + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java index 96995e9e4b3..cf89b05a539 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,9 +8,12 @@ * * Contributors: * Institute for Software - initial API and implementation + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; +import java.util.EnumSet; + import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; @@ -207,6 +210,7 @@ public class StatementWriter extends NodeWriter { } private void writeIfStatement(IASTIfStatement ifStatement) { + writeAttributes(ifStatement, EnumSet.of(SpaceLocation.AFTER)); scribe.print(IF); scribe.noNewLines(); if (ifStatement instanceof ICPPASTIfStatement) { @@ -249,6 +253,7 @@ public class StatementWriter extends NodeWriter { } private void writeLabelStatement(IASTLabelStatement labelStatement) { + writeAttributes(labelStatement, EnumSet.of(SpaceLocation.AFTER)); labelStatement.getName().accept(visitor); scribe.print(':'); scribe.newLine(); @@ -262,6 +267,7 @@ public class StatementWriter extends NodeWriter { } private void writeReturnStatement(IASTReturnStatement returnStatement) { + writeAttributes(returnStatement, EnumSet.of(SpaceLocation.AFTER)); scribe.noNewLines(); scribe.print(RETURN); IASTExpression returnValue = returnStatement.getReturnValue(); @@ -282,6 +288,7 @@ public class StatementWriter extends NodeWriter { } private void writeExpressionStatement(IASTExpressionStatement expStmt) { + writeAttributes(expStmt, EnumSet.of(SpaceLocation.AFTER)); expStmt.getExpression().accept(visitor); scribe.printSemicolon(); } @@ -301,6 +308,7 @@ public class StatementWriter extends NodeWriter { } private void writeTryBlockStatement(ICPPASTTryBlockStatement tryStatement) { + writeAttributes(tryStatement, EnumSet.of(SpaceLocation.AFTER)); scribe.print(TRY); tryStatement.getTryBody().accept(visitor); for (ICPPASTCatchHandler catchStatement : tryStatement.getCatchHandlers()) { @@ -309,6 +317,7 @@ public class StatementWriter extends NodeWriter { } private void writeWhileStatement(IASTWhileStatement whileStatment) { + writeAttributes(whileStatment, EnumSet.of(SpaceLocation.AFTER)); scribe.print(WHILE); scribe.noNewLines(); if (whileStatment instanceof ICPPASTWhileStatement) { @@ -333,6 +342,7 @@ public class StatementWriter extends NodeWriter { if (!switchIsNew) { scribe.decrementIndentationLevel(); } + writeAttributes(caseStatement, EnumSet.of(SpaceLocation.AFTER)); scribe.print(CASE); caseStatement.getExpression().accept(visitor); scribe.print(':'); @@ -369,12 +379,14 @@ public class StatementWriter extends NodeWriter { if (!switchIsNew) { scribe.decrementIndentationLevel(); } + writeAttributes(defaultStatement, EnumSet.of(SpaceLocation.AFTER)); scribe.print(DEFAULT); scribe.incrementIndentationLevel(); switchIsNew = false; } private void writeCompoundStatement(IASTCompoundStatement compoundStatement) { + writeAttributes(compoundStatement, EnumSet.of(SpaceLocation.AFTER)); scribe.printLBrace(); scribe.newLine(); for (IASTStatement statements : getNestedStatements(compoundStatement)) { diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTForallStatement.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTForallStatement.java index 5987c3a5ec4..aade68d1f15 100644 --- a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTForallStatement.java +++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTForallStatement.java @@ -80,7 +80,7 @@ public class UPCASTForallStatement extends CASTForStatement implements IUPCASTFo } } - if (!acceptByAttributes(visitor)) return false; + if (!acceptByAttributeSpecifiers(visitor)) return false; IASTStatement initializer = super.getInitializerStatement(); if (initializer != null && !initializer.accept(visitor)) return false; diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTSynchronizationStatement.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTSynchronizationStatement.java index b28385766a3..f119d4dff78 100644 --- a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTSynchronizationStatement.java +++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTSynchronizationStatement.java @@ -75,7 +75,7 @@ public class UPCASTSynchronizationStatement extends ASTAttributeOwner implements } } - if (!acceptByAttributes(visitor)) return false; + if (!acceptByAttributeSpecifiers(visitor)) return false; if (barrierExpression != null && !barrierExpression.accept(visitor)) return false; if (visitor.shouldVisitStatements) {