mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 04:15:35 +02:00
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 <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
a2a05a515a
commit
b5cf6c388c
103 changed files with 2090 additions and 374 deletions
|
@ -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<IASTAttributeSpecifier> specifiers = new ArrayList<IASTAttributeSpecifier>();
|
||||
|
||||
public List<IASTAttributeSpecifier> getAttributes() {
|
||||
return specifiers;
|
||||
}
|
||||
|
||||
public int visit(IASTAttributeSpecifier specifier) {
|
||||
specifiers.add(specifier);
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
private List<IASTAttributeSpecifier> getAttributeSpecifiers(IASTTranslationUnit tu) {
|
||||
AttributeNodeFinder attributeFinder = new AttributeNodeFinder();
|
||||
tu.accept(attributeFinder);
|
||||
List<IASTAttributeSpecifier> specifiers = attributeFinder.getAttributes();
|
||||
return specifiers;
|
||||
}
|
||||
|
||||
private IASTAttribute[] getAttributes() throws Exception {
|
||||
IASTTranslationUnit tu = parseAndCheckBindings();
|
||||
List<IASTAttributeSpecifier> specifiers = getAttributeSpecifiers(tu);
|
||||
assertEquals(1, specifiers.size());
|
||||
IASTAttributeSpecifier specifier = specifiers.get(0);
|
||||
return specifier.getAttributes();
|
||||
}
|
||||
|
||||
private void checkAttributeRelations(List<IASTAttributeSpecifier> specifiers, Class<? extends IASTAttributeOwner>... 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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);
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
* <code>IASTArrayModifier</code> and an <code>IASTExpression</code>.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 = {};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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?
|
||||
|
|
|
@ -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 {
|
||||
/**
|
||||
* <code>MEMBER_INITIALIZER</code> is the role of a member initializer in the function definition.
|
||||
*/
|
||||
|
|
|
@ -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 {
|
||||
/**
|
||||
* <code>OWNED_DECLARATION</code> is the role served by all the nested
|
||||
* declarations.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<IASTAttributeSpecifier> TYPE_FILTER =
|
||||
new InstanceOfPredicate<>(IGCCASTAttributeSpecifier.class);
|
||||
|
||||
@Override
|
||||
public IGCCASTAttributeSpecifier copy();
|
||||
|
||||
@Override
|
||||
public IGCCASTAttributeSpecifier copy(CopyStyle style);
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<IASTAttributeSpecifier> TYPE_FILTER =
|
||||
new InstanceOfPredicate<>(ICPPASTAttributeSpecifier.class);
|
||||
|
||||
@Override
|
||||
public ICPPASTAttributeSpecifier copy();
|
||||
|
||||
@Override
|
||||
public ICPPASTAttributeSpecifier copy(CopyStyle style);
|
||||
}
|
|
@ -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<T> implements IUnaryPredicate<T> {
|
||||
private Class<T> type;
|
||||
private Class<?> type;
|
||||
|
||||
public InstanceOfPredicate(Class<T> type) {
|
||||
public InstanceOfPredicate(Class<?> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean apply(T obj) {
|
||||
return type.isInstance(obj);
|
||||
|
|
|
@ -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 extends ASTAttributeOwner> 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;
|
||||
}
|
||||
}
|
|
@ -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<IASTAttributeSpecifier> 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<IASTAttribute> __attribute_decl_seq(boolean allowAttrib, boolean allowDeclspec)
|
||||
protected List<IASTAttributeSpecifier> __attribute_decl_seq(boolean allowAttrib, boolean allowDeclspec)
|
||||
throws BacktrackException, EndOfFileException {
|
||||
List<IASTAttribute> result = null;
|
||||
List<IASTAttributeSpecifier> 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<IASTAttributeSpecifier>();
|
||||
}
|
||||
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<IASTAttribute> __attribute__() throws BacktrackException, EndOfFileException {
|
||||
protected IASTAttributeSpecifier __attribute__() throws BacktrackException, EndOfFileException {
|
||||
if (LT(1) != IGCCToken.t__attribute__)
|
||||
return null;
|
||||
|
||||
List<IASTAttribute> 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<IASTAttribute>();
|
||||
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<IASTAttributeSpecifier> 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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<IASTAttribute> attributes =
|
||||
List<IASTAttributeSpecifier> 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<IASTPointerOperator> pointerOps,
|
||||
List<IASTAttribute> attributes, final IASTName declaratorName,
|
||||
List<IASTAttributeSpecifier> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 extends ASTAttributeSpecifier> 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);
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<IASTAttributeSpecifier> attributes)
|
||||
throws EndOfFileException, BacktrackException {
|
||||
final int offset= consume().getOffset();
|
||||
|
||||
List<IASTAttribute> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> attributeSpecifierSeq() throws EndOfFileException,
|
||||
BacktrackException {
|
||||
List<IASTAttributeSpecifier> specifiers = null;
|
||||
|
||||
while (LTcatchEOF(1) == IToken.tLBRACKET && LTcatchEOF(2) == IToken.tLBRACKET) {
|
||||
if (specifiers == null)
|
||||
specifiers = new ArrayList<IASTAttributeSpecifier>();
|
||||
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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<? extends IASTPointerOperator> consumePointerOperators() throws EndOfFileException, BacktrackException {
|
||||
List<IASTPointerOperator> result= null;
|
||||
for (;;) {
|
||||
IToken mark = mark();
|
||||
final int startOffset = mark.getOffset();
|
||||
|
||||
// __attribute__ in-between pointers
|
||||
__attribute_decl_seq(supportAttributeSpecifiers, false);
|
||||
List<IASTAttributeSpecifier> 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<IASTPointerOperator>(4);
|
||||
}
|
||||
|
||||
attributes = CollectionUtils.merge(attributes, attributeSpecifierSeq());
|
||||
addAttributeSpecifiers(attributes, pointer);
|
||||
|
||||
result.add(pointer);
|
||||
}
|
||||
}
|
||||
|
||||
private IASTDeclarator declarator(List<? extends IASTPointerOperator> pointerOps, boolean hasEllipsis,
|
||||
IASTName declaratorName, IASTDeclarator nestedDeclarator, int startingOffset, int endOffset,
|
||||
DtorStrategy strategy, DeclarationOptions option)
|
||||
DtorStrategy strategy, DeclarationOptions option, List<IASTAttributeSpecifier> attributes)
|
||||
throws EndOfFileException, BacktrackException {
|
||||
ICPPASTDeclarator result= null;
|
||||
List<IASTAttribute> 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<IASTAttribute> attributes = __attribute_decl_seq(supportAttributeSpecifiers, false);
|
||||
List<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> 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<IASTAttributeSpecifier> attributes = attributeSpecifierSeq();
|
||||
IASTDeclaration decl= simpleDeclaration(DeclarationOptions.RANGE_BASED_FOR, attributes);
|
||||
consume(IToken.tCOLON);
|
||||
IASTInitializerClause init= null;
|
||||
switch (LT(1)) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
* <code>Scribe</code> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<SpaceLocation> spaceLocations) {
|
||||
IASTAttributeSpecifier[] specifiers = attributeOwner.getAttributeSpecifiers();
|
||||
writeAttributes(specifiers, spaceLocations);
|
||||
}
|
||||
|
||||
protected void writeGCCAttributes(IASTAttributeOwner attributeOwner, EnumSet<SpaceLocation> spaceLocations) {
|
||||
IASTAttributeSpecifier[] specifiers = attributeOwner.getAttributeSpecifiers();
|
||||
IASTAttributeSpecifier[] gnuSpecifiers = ArrayUtil.filter(specifiers, IGCCASTAttributeSpecifier.TYPE_FILTER);
|
||||
writeAttributes(gnuSpecifiers, spaceLocations);
|
||||
}
|
||||
|
||||
protected void writeCPPAttributes(IASTAttributeOwner attributeOwner, EnumSet<SpaceLocation> spaceLocations) {
|
||||
IASTAttributeSpecifier[] specifiers = attributeOwner.getAttributeSpecifiers();
|
||||
IASTAttributeSpecifier[] cppSpecifiers = ArrayUtil.filter(specifiers, ICPPASTAttributeSpecifier.TYPE_FILTER);
|
||||
writeAttributes(cppSpecifiers, spaceLocations);
|
||||
}
|
||||
|
||||
private void writeAttributes(IASTAttributeSpecifier[] specifiers, EnumSet<SpaceLocation> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue