diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index 61ebef86f9a..cbbaeb85a02 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -191,11 +191,11 @@ public class AST2CPPTests extends AST2BaseTest {
}
private void assertDefinition(ICPPBinding b) {
- assertTrue(((IASTName)((ICPPInternalBinding) b).getDefinition()).isDefinition());
+ assertTrue(((IASTName) ((ICPPInternalBinding) b).getDefinition()).isDefinition());
}
private void assertDeclaration(ICPPBinding b) {
- assertTrue(((IASTName)((ICPPInternalBinding) b).getDeclarations()[0]).isDeclaration());
+ assertTrue(((IASTName) ((ICPPInternalBinding) b).getDeclarations()[0]).isDeclaration());
}
private ICPPMethod extractSingleMethod(IBinding[] bindings) {
@@ -4682,10 +4682,10 @@ public class AST2CPPTests extends AST2BaseTest {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP, true, true);
IASTDeclaration[] decls = tu.getDeclarations();
- assertTrue(((IASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[0]).getDeclSpecifier()).isComplex());
- assertEquals(((IASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[0]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_float);
- assertTrue(((IASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[1]).getDeclSpecifier()).isComplex());
- assertEquals(((IASTSimpleDeclSpecifier)((IASTSimpleDeclaration)decls[1]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_double);
+ assertTrue(((IASTSimpleDeclSpecifier) ((IASTSimpleDeclaration)decls[0]).getDeclSpecifier()).isComplex());
+ assertEquals(((IASTSimpleDeclSpecifier) ((IASTSimpleDeclaration)decls[0]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_float);
+ assertTrue(((IASTSimpleDeclSpecifier) ((IASTSimpleDeclaration)decls[1]).getDeclSpecifier()).isComplex());
+ assertEquals(((IASTSimpleDeclSpecifier) ((IASTSimpleDeclaration)decls[1]).getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_double);
}
// class _A {
@@ -5396,7 +5396,7 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPASTFunctionDeclarator fdecl2= (ICPPASTFunctionDeclarator) ((IASTSimpleDeclaration) nsdecls[2]).getDeclarators()[0];
IASTStatement[] stmts= ((IASTCompoundStatement) fdef.getBody()).getStatements();
- IASTName clname= ((IASTNamedTypeSpecifier) ((IASTSimpleDeclaration)((IASTDeclarationStatement) stmts[0]).getDeclaration()).getDeclSpecifier()).getName();
+ IASTName clname= ((IASTNamedTypeSpecifier) ((IASTSimpleDeclaration) ((IASTDeclarationStatement) stmts[0]).getDeclaration()).getDeclSpecifier()).getName();
IASTName fnname1= ((IASTIdExpression) ((IASTFunctionCallExpression) ((IASTExpressionStatement) stmts[1]).getExpression()).getFunctionNameExpression()).getName();
IASTName fnname2= ((IASTIdExpression) ((IASTFunctionCallExpression) ((IASTExpressionStatement) stmts[2]).getExpression()).getFunctionNameExpression()).getName();
@@ -5906,8 +5906,8 @@ public class AST2CPPTests extends AST2BaseTest {
IType t1= ((IPointerType)pt1.getType().getParameterTypes()[0]).getType();
IQualifierType t2= (IQualifierType) ((IPointerType) pt2.getType().getParameterTypes()[0]).getType();
- IQualifierType t3= (IQualifierType)((IPointerType) pt3.getType().getParameterTypes()[0]).getType();
- IQualifierType t4= (IQualifierType)((IPointerType) pt4.getType().getParameterTypes()[0]).getType();
+ IQualifierType t3= (IQualifierType) ((IPointerType) pt3.getType().getParameterTypes()[0]).getType();
+ IQualifierType t4= (IQualifierType) ((IPointerType) pt4.getType().getParameterTypes()[0]).getType();
assertTrue(!(t1 instanceof IQualifierType));
assertTrue(t2.isConst()); assertTrue(!t2.isVolatile());
@@ -9559,4 +9559,36 @@ public class AST2CPPTests extends AST2BaseTest {
p= getDeclaration(S, 2);
p= getDeclaration(S, 3);
}
+
+ // typedef int int8_t __attribute__ ((__mode__ (__QI__)));
+ // typedef int int16_t __attribute__ ((__mode__ (__HI__)));
+ // typedef int int32_t __attribute__ ((__mode__ (__SI__)));
+ // typedef int int64_t __attribute__ ((__mode__ (__DI__)));
+ // typedef int word_t __attribute__ ((__mode__ (__word__)));
+ // void f(int8_t*) {}
+ // void f(int16_t*) {}
+ // void f(int32_t*) {}
+ // void f(int64_t*) {}
+ // void f(word_t*) {}
+ // void test(signed char* i8, short* i16, int* i32, long long* i64, word_t* word) {
+ // f(i8);
+ // f(i16);
+ // f(i32);
+ // f(i64);
+ // f(word);
+ // }
+ public void testModeAttribute_330635() throws Exception {
+ BindingAssertionHelper bh= getAssertionHelper();
+ String[] calls = { "f(i8)", "f(i16)", "f(i32)", "f(i64)", "f(word)" };
+ ICPPFunction[] functions = new ICPPFunction[calls.length];
+ for (int i = 0; i < calls.length; i++) {
+ functions[i] = bh.assertNonProblem(calls[i], 1, ICPPFunction.class);
+ }
+ for (int i = 0; i < functions.length; i++) {
+ for (int j = i + 1; j < functions.length; j++) {
+ assertNotSame(calls[i] + " and " + calls[j] + " resolve to the same function",
+ functions[i], functions[j]);
+ }
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java
index 2fe1ab4ef25..776710b54b5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTVisitor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,6 +10,7 @@
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Markus Schorn (Wind River Systems)
* Mike Kucera (IBM) - implicit names
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
@@ -76,6 +77,16 @@ public abstract class ASTVisitor {
* @since 5.1
*/
public boolean shouldVisitPointerOperators = false;
+ /**
+ * Set this flag to visit attributes.
+ * @since 5.4
+ */
+ public boolean shouldVisitAttributes = false;
+ /**
+ * Set this flag to visit token nodes.
+ * @since 5.4
+ */
+ public boolean shouldVisitTokens = false;
/**
* Set this flag to visit expressions.
*/
@@ -168,7 +179,8 @@ public abstract class ASTVisitor {
* @param visitNodes whether visitor is setup to visit all nodes per default, except
* ambiguous nodes ({@link #shouldVisitAmbiguousNodes}),
* inactive nodes ({@link #includeInactiveNodes}),
- * and implicit names (@link {@link #shouldVisitImplicitNames}).
+ * implicit names ({@link #shouldVisitImplicitNames}),
+ * and tokens ({@link #shouldVisitTokens}).
* @since 5.1
*/
public ASTVisitor(boolean visitNodes) {
@@ -186,6 +198,7 @@ public abstract class ASTVisitor {
shouldVisitNamespaces= visitNodes;
shouldVisitParameterDeclarations= visitNodes;
shouldVisitPointerOperators= visitNodes;
+ shouldVisitAttributes= visitNodes;
shouldVisitProblems= visitNodes;
shouldVisitStatements= visitNodes;
shouldVisitTemplateParameters= visitNodes;
@@ -222,20 +235,26 @@ public abstract class ASTVisitor {
return PROCESS_CONTINUE;
}
- /**
- * @since 5.1
- */
+ /** @since 5.1 */
public int visit(IASTArrayModifier arrayModifier) {
return PROCESS_CONTINUE;
}
- /**
- * @since 5.1
- */
+ /** @since 5.1 */
public int visit(IASTPointerOperator ptrOperator) {
return PROCESS_CONTINUE;
}
+ /** @since 5.4 */
+ public int visit(IASTAttribute attribute) {
+ return PROCESS_CONTINUE;
+ }
+
+ /** @since 5.4 */
+ public int visit(IASTToken token) {
+ return PROCESS_CONTINUE;
+ }
+
public int visit(IASTExpression expression) {
return PROCESS_CONTINUE;
}
@@ -320,20 +339,26 @@ public abstract class ASTVisitor {
return PROCESS_CONTINUE;
}
- /**
- * @since 5.1
- */
+ /** @since 5.1 */
public int leave(IASTArrayModifier arrayModifier) {
return PROCESS_CONTINUE;
}
- /**
- * @since 5.1
- */
+ /** @since 5.1 */
public int leave(IASTPointerOperator ptrOperator) {
return PROCESS_CONTINUE;
}
+ /** @since 5.4 */
+ public int leave(IASTAttribute attribute) {
+ return PROCESS_CONTINUE;
+ }
+
+ /** @since 5.4 */
+ public int leave(IASTToken token) {
+ return PROCESS_CONTINUE;
+ }
+
public int leave(IASTExpression expression) {
return PROCESS_CONTINUE;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttribute.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttribute.java
new file mode 100644
index 00000000000..0b898fc5ec5
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttribute.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.ast;
+
+/**
+ * Represents a C++11 (ISO/IEC 14882:2011 7.6)
+ * or a GCC attribute (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.4
+ */
+public interface IASTAttribute extends IASTNode {
+ public static final IASTAttribute[] EMPTY_ATTRIBUTE_ARRAY = {};
+
+ /**
+ * ATTRIBUTE_ARGUMENT
represents the relationship between an
+ * IASTAttribute
and an IASTExpression
.
+ */
+ public static final ASTNodeProperty ARGUMENT_CLAUSE = new ASTNodeProperty(
+ "IASTAttribute.ARGUMENT_CLAUSE - IASTToken, argument clause for IASTAttribute"); //$NON-NLS-1$
+
+ /**
+ * Returns the name of the attribute.
+ */
+ public char[] getName();
+
+ /**
+ * Returns arguments of this attribute, or {@code null} if the attribute doesn't have arguments.
+ */
+ public IASTToken getArgumentClause();
+
+ /**
+ * Sets the argument clause.
+ */
+ public void setArgumentClause(IASTToken argumentClause);
+
+ @Override
+ public IASTAttribute copy();
+
+ @Override
+ public IASTAttribute copy(CopyStyle style);
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttributeOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttributeOwner.java
new file mode 100644
index 00000000000..79af3022bcc
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTAttributeOwner.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.ast;
+
+/**
+ * An AST node that may have attributes.
+ * @since 5.4
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface IASTAttributeOwner extends IASTNode {
+ public static final ASTNodeProperty ATTRIBUTE =
+ new ASTNodeProperty("IASTAttributeOwner.ATTRIBUTE"); //$NON-NLS-1$
+
+ /**
+ * Returns the array of attributes.
+ */
+ public IASTAttribute[] getAttributes();
+
+ /**
+ * Adds an attribute to the node.
+ */
+ public void addAttribute(IASTAttribute attribute);
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java
index 55a24fda2cd..ab4c9fc1d1e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java
@@ -16,7 +16,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 IASTDeclarator extends IASTNode, IASTNameOwner {
+public interface IASTDeclarator extends IASTNameOwner, IASTAttributeOwner {
/**
* Constant - empty declarator array
*/
@@ -51,8 +51,7 @@ public interface IASTDeclarator extends IASTNode, IASTNameOwner {
"IASTDeclarator.DECLARATOR_NAME - IASTName for IASTDeclarator"); //$NON-NLS-1$
/**
- * This is the list of pointer operators applied to the type for the
- * declarator.
+ * This is the list of pointer operators applied to the type for the declarator.
*
* @return array of IASTPointerOperator
*/
@@ -61,8 +60,7 @@ public interface IASTDeclarator extends IASTNode, IASTNameOwner {
/**
* Adds a pointer operator to the declarator.
*
- * @param operator
- * IASTPointerOperator
to be added.
+ * @param operator a IASTPointerOperator
to be added.
*/
public void addPointerOperator(IASTPointerOperator operator);
@@ -106,7 +104,7 @@ public interface IASTDeclarator extends IASTNode, IASTNameOwner {
* IASTInitializer
*/
public void setInitializer(IASTInitializer initializer);
-
+
/**
* @since 5.1
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclaration.java
index 668fce1f490..70a0a4394d8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTSimpleDeclaration.java
@@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Doug Schaefer (IBM) - Initial API and implementation
+ * Doug Schaefer (IBM) - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
@@ -17,8 +18,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 IASTSimpleDeclaration extends IASTDeclaration {
-
+public interface IASTSimpleDeclaration extends IASTDeclaration, IASTAttributeOwner {
/**
* DECL_SPECIFIER
represents the relationship between an
* IASTSimpleDeclaration
and it's nested
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStatement.java
index c56efacb418..48a6bc32eaf 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTStatement.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Doug Schaefer (IBM) - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
@@ -16,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 IASTStatement extends IASTNode {
+public interface IASTStatement extends IASTAttributeOwner {
public static final IASTStatement[] EMPTY_STATEMENT_ARRAY = {};
/**
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTToken.java
new file mode 100644
index 00000000000..2aaa7741c74
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTToken.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.ast;
+
+/**
+ * Represents an arbitrary code token.
+ *
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @since 5.4
+ */
+public interface IASTToken extends IASTNode {
+ public static final IASTToken[] EMPTY_TOKEN_ARRAY = {};
+
+ /**
+ * Returns the token type.
+ * @see org.eclipse.cdt.core.parser.IToken#getType()
+ */
+ public int getTokenType();
+
+ /**
+ * Returns the token text.
+ * @see org.eclipse.cdt.core.parser.IToken#getCharImage()
+ */
+ public char[] getTokenCharImage();
+
+ @Override
+ public IASTToken copy();
+
+ @Override
+ public IASTToken copy(CopyStyle style);
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTokenList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTokenList.java
new file mode 100644
index 00000000000..f562eb28506
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTokenList.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.ast;
+
+/**
+ * Represents a sequence of code tokens.
+ *
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @since 5.4
+ */
+public interface IASTTokenList extends IASTToken {
+ /**
+ * {@code NESTED_TOKEN} describes the relationship between
+ * {@code IASTTokenList} and the nested {@code IASTToken}s.
+ */
+ public static final ASTNodeProperty NESTED_TOKEN = new ASTNodeProperty(
+ "IASTTokenList.NESTED_TOKEN - Nested IASTToken for IASTTokenList"); //$NON-NLS-1$
+
+ /**
+ * Returns nested tokens.
+ */
+ public IASTToken[] getTokens();
+
+ /**
+ * Adds a nested token.
+ *
+ * @param token a token to be added to the list
+ */
+ public void addToken(IASTToken token);
+
+ /**
+ * If the list contains a single token, returns its type. Otherwise returns 0.
+ * @see org.eclipse.cdt.core.parser.IToken#getType()
+ */
+ @Override
+ public int getTokenType();
+
+ /**
+ * If the list contains a single token, returns its text. Otherwise returns {@code null}.
+ * @see org.eclipse.cdt.core.parser.IToken#getCharImage()
+ */
+ @Override
+ public char[] getTokenCharImage();
+
+ @Override
+ public IASTTokenList copy();
+
+ @Override
+ public IASTTokenList copy(CopyStyle style);
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/INodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/INodeFactory.java
index 014265d567e..e0801398907 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/INodeFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/INodeFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 IBM Corporation and others.
+ * Copyright (c) 2006, 2012 IBM Corporation and others.
* All rights reserved. This program and 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)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
@@ -47,6 +48,9 @@ public interface INodeFactory {
public IASTASMDeclaration newASMDeclaration(String assembly);
+ /** @since 5.4 */
+ public IASTAttribute newAttribute(char[] name, IASTToken argumentClause);
+
public IASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2);
public IASTBreakStatement newBreakStatement();
@@ -158,6 +162,12 @@ public interface INodeFactory {
public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body);
+ /** @since 5.4 */
+ public IASTToken newToken(int tokenType, char[] tokenImage);
+
+ /** @since 5.4 */
+ public IASTTokenList newTokenList();
+
/**
* @deprecated Replaced by {@link #newTranslationUnit(IScanner)}.
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTUsingDeclaration.java
index 146b3153ccd..4cd7d85d8c2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTUsingDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTUsingDeclaration.java
@@ -6,11 +6,13 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * John Camelon (IBM) - Initial API and implementation
+ * John Camelon (IBM) - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
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;
@@ -21,8 +23,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 ICPPASTUsingDeclaration extends IASTDeclaration, IASTNameOwner {
-
+public interface ICPPASTUsingDeclaration extends IASTDeclaration, IASTNameOwner, IASTAttributeOwner {
/**
* NAME
is the qualified name brought into scope.
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTUsingDirective.java
index 63898bbc283..6d96e99672f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTUsingDirective.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTUsingDirective.java
@@ -1,16 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * John Camelon (IBM) - Initial API and implementation
+ * John Camelon (IBM) - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
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;
@@ -21,10 +23,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 ICPPASTUsingDirective extends IASTDeclaration, IASTNameOwner {
- /**
- * Constant.
- */
+public interface ICPPASTUsingDirective extends IASTDeclaration, IASTNameOwner, IASTAttributeOwner {
public static final ICPPASTUsingDirective[] EMPTY_USINGDIRECTIVE_ARRAY = new ICPPASTUsingDirective[0];
/**
@@ -60,5 +59,4 @@ public interface ICPPASTUsingDirective extends IASTDeclaration, IASTNameOwner {
*/
@Override
public ICPPASTUsingDirective copy(CopyStyle style);
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNodeFactory.java
index d0ec04341c8..3348938c563 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNodeFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPNodeFactory.java
@@ -37,7 +37,6 @@ import org.eclipse.cdt.core.parser.IScanner;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICPPNodeFactory extends INodeFactory {
-
/**
* @since 5.2
*/
@@ -51,7 +50,7 @@ public interface ICPPNodeFactory extends INodeFactory {
* @since 5.2
*/
public ICPPASTArraySubscriptExpression newArraySubscriptExpression(IASTExpression arrayExpr, IASTInitializerClause subscript);
-
+
public ICPPASTBaseSpecifier newBaseSpecifier(IASTName name, int visibility, boolean isVirtual);
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java
index 80608777453..54bbb3db73d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayUtils.java
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.core.parser.util;
@@ -19,7 +20,9 @@ import java.util.Arrays;
* @author dschaefe
*/
public class CharArrayUtils {
- public static final char[] EMPTY = {};
+ /** @since 5.4 */
+ public static final char[] EMPTY_CHAR_ARRAY = {};
+ public static final char[] EMPTY = EMPTY_CHAR_ARRAY;
private CharArrayUtils() {}
@@ -54,6 +57,40 @@ public class CharArrayUtils {
return true;
}
+ /**
+ * Returns {@code true} if the contents of a character array are the same as contents
+ * of a string.
+ * @since 5.4
+ */
+ public static final boolean equals(char[] str1, String str2) {
+ int length = str1.length;
+ if (str2.length() != length)
+ return false;
+
+ for (int i = 0; i < length; i++) {
+ if (str1[i] != str2.charAt(i))
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns {@code true} if a prefix of the character array is the same as contents
+ * of a string.
+ * @since 5.4
+ */
+ public static final boolean startsWith(char[] str1, String str2) {
+ int len = str2.length();
+ if (str1.length < len)
+ return false;
+ for (int i = 0; i < len; i++) {
+ if (str1[i] != str2.charAt(i)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
/**
* Implements a lexicographical comparator for char arrays. Comparison is done
* on a per char basis, not a code-point basis.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CollectionUtils.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CollectionUtils.java
index 4ada6ff99f4..9f879d86beb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CollectionUtils.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CollectionUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 IBM Corporation and others.
+ * Copyright (c) 2006, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,9 +7,11 @@
*
* Contributors:
* Mike Kucera (IBM Corporation) - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.core.parser.util;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
@@ -110,4 +112,25 @@ public final class CollectionUtils {
}
return null;
}
+
+ /**
+ * Combines two collections into one.
+ * @param c1 The first collection. May be modified as a result of the call. May be {@code null}.
+ * @param c2 The second collection. May be {@code null}.
+ * @return A collection containing elements from both input collections,
+ * or {@code null} if both, {@code c1} and {@code c2} are {@code null}.
+ * @since 5.4
+ */
+ public static > U merge(U c1, U c2) {
+ if (c1 == null)
+ return c2;
+ if (c2 == null)
+ return c1;
+ if (c1.isEmpty())
+ return c2;
+ if (c2.isEmpty())
+ return c1;
+ c1.addAll(c2);
+ return c1;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttribute.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttribute.java
new file mode 100644
index 00000000000..d1093ea9347
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttribute.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+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.IASTToken;
+import org.eclipse.cdt.core.parser.util.CharArrayUtils;
+
+/**
+ * Base class for C and C++ attributes.
+ */
+public abstract class ASTAttribute extends ASTNode implements IASTAttribute {
+ private static final String[] NORETURN_ATTRIBUTES = new String[] { "__noreturn__", "noreturn" }; //$NON-NLS-1$//$NON-NLS-2$
+
+ private final char[] name;
+ private final IASTToken argumentClause;
+
+ public ASTAttribute(char[] name, IASTToken arguments) {
+ this.name = name;
+ this.argumentClause = arguments;
+ }
+
+ @Override
+ public char[] getName() {
+ return name;
+ }
+
+ @Override
+ public IASTToken getArgumentClause() {
+ return argumentClause;
+ }
+
+ @Override
+ public void setArgumentClause(IASTToken argumentClause) {
+ assertNotFrozen();
+ if (argumentClause != null) {
+ argumentClause.setParent(this);
+ argumentClause.setPropertyInParent(ARGUMENT_CLAUSE);
+ }
+ }
+
+ @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;
+ default: break;
+ }
+ }
+
+ if (argumentClause != null && !argumentClause.accept(action)) return false;
+
+ if (action.shouldVisitAttributes && action.leave(this) == ASTVisitor.PROCESS_ABORT)
+ return false;
+
+ return true;
+ }
+
+ /**
+ * Returns {@code true} if a declarator has an attribute with one of the given names.
+ * The {@code names} array is assumed to be small.
+ */
+ public static boolean hasAttribute(IASTAttributeOwner node, String[] names) {
+ IASTAttribute[] attributes = node.getAttributes();
+ for (IASTAttribute attribute : attributes) {
+ char[] name = attribute.getName();
+ for (int i = 0; i < names.length; i++) {
+ if (CharArrayUtils.equals(name, names[i]))
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns {@code true} if the node has a "noreturn" or "__noreturn__" attribute.
+ */
+ public static boolean hasNoreturnAttribute(IASTAttributeOwner node) {
+ return hasAttribute(node, NORETURN_ATTRIBUTES);
+ }
+
+ /**
+ * Returns character representation of the attribute argument, or {@code null} if the attribute
+ * has zero or more than one argument.
+ */
+ public static char[] getSimpleArgument(IASTAttribute attribute) {
+ IASTToken argumentClause = attribute.getArgumentClause();
+ if (argumentClause == null)
+ return null;
+ return argumentClause.getTokenCharImage();
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttributeOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttributeOwner.java
new file mode 100644
index 00000000000..20c60b24ece
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttributeOwner.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+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.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;
+
+ @Override
+ public IASTAttribute[] getAttributes() {
+ attributes = ArrayUtil.trim(attributes);
+ return attributes;
+ }
+
+ @Override
+ public void addAttribute(IASTAttribute attribute) {
+ assertNotFrozen();
+ if (attribute != null) {
+ attribute.setParent(this);
+ attribute.setPropertyInParent(ATTRIBUTE);
+ attributes = ArrayUtil.append(attributes, attribute);
+ }
+ }
+
+ protected T copy(T copy, CopyStyle style) {
+ for (IASTAttribute attribute : getAttributes()) {
+ copy.addAttribute(attribute.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;
+ }
+}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java
index fb53f0d45c8..f8e0f8a54a9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java
@@ -370,6 +370,14 @@ public abstract class ASTNode implements IASTNode {
return null;
}
+ protected T copy(T copy, CopyStyle style) {
+ copy.setOffsetAndLength(this);
+ if (style == CopyStyle.withLocations) {
+ copy.setCopyLocation(this);
+ }
+ return copy;
+ }
+
protected void setCopyLocation(IASTNode originalNode) {
locations = new IASTNodeLocation[] { new ASTCopyLocation(originalNode) };
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTToken.java
new file mode 100644
index 00000000000..781224bfea7
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTToken.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.parser;
+
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTToken;
+
+/**
+ * Represents a code token.
+ */
+public class ASTToken extends ASTNode implements IASTToken {
+ private final int tokenType;
+ private final char[] tokenImage;
+
+ public ASTToken(int tokenType, char[] tokenImage) {
+ this.tokenType = tokenType;
+ this.tokenImage = tokenImage;
+ }
+
+ @Override
+ public int getTokenType() {
+ return tokenType;
+ }
+
+ @Override
+ public char[] getTokenCharImage() {
+ return tokenImage;
+ }
+
+ @Override
+ public ASTToken copy() {
+ return copy(CopyStyle.withoutLocations);
+ }
+
+ @Override
+ public ASTToken copy(CopyStyle style) {
+ return copy(new ASTToken(tokenType, tokenImage), style);
+ }
+
+ @Override
+ public boolean accept(ASTVisitor action) {
+ if (action.shouldVisitTokens) {
+ switch (action.visit(this)) {
+ case ASTVisitor.PROCESS_ABORT: return false;
+ case ASTVisitor.PROCESS_SKIP: return true;
+ default: break;
+ }
+ }
+
+ if (action.shouldVisitTokens) {
+ switch (action.leave(this)) {
+ case ASTVisitor.PROCESS_ABORT: return false;
+ case ASTVisitor.PROCESS_SKIP: return true;
+ default: break;
+ }
+ }
+ return true;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTokenList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTokenList.java
new file mode 100644
index 00000000000..bd4fb91b903
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTTokenList.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.parser;
+
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTToken;
+import org.eclipse.cdt.core.dom.ast.IASTTokenList;
+import org.eclipse.cdt.core.parser.util.ArrayUtil;
+
+/**
+ * Represents a sequence of code tokens.
+ */
+public class ASTTokenList extends ASTNode implements IASTTokenList {
+ private IASTToken[] tokens = IASTToken.EMPTY_TOKEN_ARRAY;
+
+ public ASTTokenList() {
+ }
+
+ @Override
+ public ASTTokenList copy() {
+ return copy(CopyStyle.withoutLocations);
+ }
+
+ @Override
+ public ASTTokenList copy(CopyStyle style) {
+ ASTTokenList copy = new ASTTokenList();
+ for (IASTToken token : tokens) {
+ if (token == null)
+ break;
+ copy.addToken(token.copy(style));
+ }
+ return copy(copy, style);
+ }
+
+ @Override
+ public IASTToken[] getTokens() {
+ tokens = ArrayUtil.trim(tokens);
+ return tokens;
+ }
+
+ @Override
+ public void addToken(IASTToken token) {
+ tokens = ArrayUtil.append(tokens, token);
+ }
+
+ @Override
+ public int getTokenType() {
+ IASTToken[] tok = getTokens();
+ return tok != null && tok.length == 1 ? tok[0].getTokenType() : 0;
+ }
+
+ @Override
+ public char[] getTokenCharImage() {
+ IASTToken[] tok = getTokens();
+ return tok != null && tok.length == 1 ? tok[0].getTokenCharImage() : null;
+ }
+
+ @Override
+ public boolean accept(ASTVisitor action) {
+ if (action.shouldVisitTokens) {
+ switch (action.visit(this)) {
+ case ASTVisitor.PROCESS_ABORT: return false;
+ case ASTVisitor.PROCESS_SKIP: return true;
+ default: break;
+ }
+ }
+
+ for (IASTToken token : tokens) {
+ if (token == null)
+ break;
+ if (!token.accept(action)) return false;
+ }
+
+ if (action.shouldVisitTokens && action.leave(this) == ASTVisitor.PROCESS_ABORT)
+ return false;
+
+ return true;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
index 186a8ad1baf..b8f79726547 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,13 +10,18 @@
* Markus Schorn (Wind River Systems)
* Ed Swartz (Nokia)
* Mike Kucera (IBM) - bug #206952
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
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.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
@@ -60,6 +65,8 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
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.IASTTokenList;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
@@ -83,6 +90,7 @@ 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;
/**
@@ -484,8 +492,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
}
/**
- * Consume the next token available only if the type is as specified. In case we reached the end of
- * completion, no token is consumed and the eoc-token returned.
+ * Consume the next token available only if the type is as specified. In case we reached
+ * the end of completion, no token is consumed and the eoc-token returned.
*
* @param type
* The type of token that you are expecting.
@@ -2314,26 +2322,38 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
*
* @param allowAttrib if true accept any number of __attribute__
* @param allowDeclspec if true accept any number of __declspec
+ * @return the list of attributes, or {@code null} if there are none
* @throws BacktrackException
* @throws EndOfFileException
*/
- protected void __attribute_decl_seq(boolean allowAttrib, boolean allowDeclspec) throws BacktrackException, EndOfFileException {
+ protected List __attribute_decl_seq(boolean allowAttrib, boolean allowDeclspec)
+ throws BacktrackException, EndOfFileException {
+ List result = null;
while (true) {
final int lt = LTcatchEOF(1);
if (allowAttrib && (lt == IGCCToken.t__attribute__)) {
- __attribute__();
+ result = CollectionUtils.merge(result, __attribute__());
} else if (allowDeclspec && (lt == IGCCToken.t__declspec)) {
__declspec();
} else {
break;
}
}
+ return result;
}
- protected void __attribute__() throws BacktrackException, EndOfFileException {
+ /**
+ * Parses an __attribute__ clause.
+ * @return the list of attributes, or {@code null} if the __attribute__ clause contained
+ * no attributes
+ * @throws BacktrackException
+ * @throws EndOfFileException
+ */
+ protected List __attribute__() throws BacktrackException, EndOfFileException {
if (LT(1) != IGCCToken.t__attribute__)
- return;
-
+ return null;
+
+ List result = null;
consume();
if (LT(1) == IToken.tLPAREN) {
consume();
@@ -2346,7 +2366,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
// Allow empty attribute
if (lt1 != IToken.tCOMMA) {
- singleAttribute();
+ IASTAttribute attribute = singleAttribute();
+ if (result == null)
+ result = new ArrayList();
+ result.add(attribute);
}
// Require comma
@@ -2358,41 +2381,100 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
consumeOrEOC(IToken.tRPAREN);
consumeOrEOC(IToken.tRPAREN);
}
+ return result;
}
- private void singleAttribute() throws EndOfFileException, BacktrackException {
- // Check if we have an identifier including keywords
- if (!isIdentifier(LA(1)))
- throw backtrack;
- consume();
-
- // Check for parameters
+ private IASTAttribute singleAttribute() throws EndOfFileException, BacktrackException {
+ // Get an identifier including keywords
+ IToken attributeName = identifierOrKeyword();
+ IASTToken argumentClause = null;
+ // Check for arguments
if (LT(1) == IToken.tLPAREN) {
consume();
- for(;;) {
- final int lt2= LT(1);
- if (lt2 == IToken.tRPAREN || lt2 == IToken.tEOC)
- break;
-
- // Allow empty parameter
- if (lt2 != IToken.tCOMMA) {
- expression();
- }
- // Require comma
- if (LT(1) != IToken.tCOMMA)
- break;
- consume();
- }
+ argumentClause = balancedTokenSeq(IToken.tRPAREN);
consumeOrEOC(IToken.tRPAREN);
}
+ IASTAttribute result = nodeFactory.newAttribute(attributeName.getCharImage(), argumentClause);
+ setRange(result, attributeName.getOffset(), getEndOffset());
+ return result;
}
- private boolean isIdentifier(IToken t) {
+ private IToken identifierOrKeyword() throws EndOfFileException, BacktrackException {
+ IToken t = LA(1);
char[] image= t.getCharImage();
if (image.length == 0)
- return false;
+ throw backtrack;
char firstChar= image[0];
- return Character.isLetter(firstChar) || firstChar == '_';
+ if (!Character.isLetter(firstChar) && firstChar != '_')
+ throw backtrack;
+ consume();
+ return t;
+ }
+
+ private IASTToken balancedTokenSeq(int endType) throws EndOfFileException, BacktrackException {
+ IASTToken result = null;
+ IToken t;
+ while ((t = LA(1)).getType() != endType) {
+ consume();
+ IASTToken token;
+ switch (LT(1)) {
+ case IToken.tLPAREN:
+ token = balancedTokenSeq(t.getOffset(), IToken.tRPAREN);
+ break;
+
+ case IToken.tLBRACKET:
+ token = balancedTokenSeq(t.getOffset(), IToken.tRBRACKET);
+ break;
+
+ case IToken.tLBRACE:
+ token = balancedTokenSeq(t.getOffset(), IToken.tRBRACE);
+ break;
+
+ default:
+ token = nodeFactory.newToken(t.getType(), t.getCharImage());
+ setRange(token, t.getOffset(), t.getEndOffset());
+ break;
+ }
+ result = addTokenToSequence(result, token);
+ }
+ 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);
+ 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(token);
+ setRange(list, token);
+ sequence = list;
+ }
+ return sequence;
}
protected void __declspec() throws BacktrackException, EndOfFileException {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java
index 7052c5240b2..c38ae9ddceb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 IBM Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2012 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
@@ -7,10 +7,12 @@
*
* Contributors:
* Markus Schorn - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTAttribute;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -89,7 +91,18 @@ public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmb
public IASTPointerOperator[] getPointerOperators() {
return dtors[0].getPointerOperators();
}
-
+
+ @Override
+ public IASTAttribute[] getAttributes() {
+ return dtors[0].getAttributes();
+ }
+
+ @Override
+ public void addAttribute(IASTAttribute attribute) {
+ assertNotFrozen();
+ Assert.isLegal(false);
+ }
+
@Override
public int getRoleForName(IASTName name) {
return dtors[0].getRoleForName(name);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java
index 36ec177e64b..b28b6814384 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java
@@ -7,10 +7,12 @@
*
* Contributors:
* Markus Schorn - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
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.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName;
@@ -84,7 +86,17 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements
public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
fSimpleDecl.setDeclSpecifier(declSpec);
}
-
+
+ @Override
+ public IASTAttribute[] getAttributes() {
+ return fSimpleDecl.getAttributes();
+ }
+
+ @Override
+ public void addAttribute(IASTAttribute attribute) {
+ fSimpleDecl.addAttribute(attribute);
+ }
+
@Override
protected final IASTNode doResolveAmbiguity(ASTVisitor resolver) {
final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java
index 2726c54de93..37d7c020f35 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,10 +8,12 @@
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
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.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -30,7 +32,7 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi
private IASTDeclaration fDeclaration;
public CASTAmbiguousStatement(IASTStatement... statements) {
- for(IASTStatement s : statements)
+ for (IASTStatement s : statements)
addStatement(s);
}
@@ -43,7 +45,7 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi
((ICPPASTInternalScope) fScope).populateCache();
}
}
-
+
@Override
protected void beforeAlternative(IASTNode alternative) {
cleanupScope();
@@ -84,6 +86,16 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi
return stmts;
}
+ @Override
+ public IASTAttribute[] getAttributes() {
+ return IASTAttribute.EMPTY_ATTRIBUTE_ARRAY;
+ }
+
+ @Override
+ public void addAttribute(IASTAttribute attribute) {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public IASTNode[] getNodes() {
return getStatements();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java
index 4914bd8e863..056ea340be5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTArrayDeclarator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and 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 Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -22,7 +23,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
* @author jcamelon
*/
public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDeclarator {
- private IASTArrayModifier[] arrayMods = null;
+ private IASTArrayModifier[] arrayMods;
private int arrayModsPos = -1;
public CASTArrayDeclarator() {
@@ -44,23 +45,18 @@ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDecl
@Override
public CASTArrayDeclarator copy(CopyStyle style) {
CASTArrayDeclarator copy = new CASTArrayDeclarator();
- copyBaseDeclarator(copy, style);
- for (IASTArrayModifier modifier : getArrayModifiers())
+ for (IASTArrayModifier modifier : getArrayModifiers()) {
copy.addArrayModifier(modifier == null ? null : modifier.copy(style));
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
}
- return copy;
+ return copy(copy, style);
}
@Override
public IASTArrayModifier[] getArrayModifiers() {
if (arrayMods == null)
return IASTArrayModifier.EMPTY_ARRAY;
- arrayMods = ArrayUtil.trimAt(IASTArrayModifier.class,
- arrayMods, arrayModsPos);
+ arrayMods = ArrayUtil.trimAt(IASTArrayModifier.class, arrayMods, arrayModsPos);
return arrayMods;
-
}
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAttribute.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAttribute.java
new file mode 100644
index 00000000000..a4188ffb58a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAttribute.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.parser.c;
+
+import org.eclipse.cdt.core.dom.ast.IASTToken;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttribute;
+
+/**
+ * C-specific attribute.
+ */
+public class CASTAttribute extends ASTAttribute {
+
+ public CASTAttribute(char[] name, IASTToken argumentClause) {
+ super(name, argumentClause);
+ }
+
+ @Override
+ public CASTAttribute copy() {
+ return copy(CopyStyle.withoutLocations);
+ }
+
+ @Override
+ public CASTAttribute copy(CopyStyle style) {
+ IASTToken argumentClause = getArgumentClause();
+ if (argumentClause != null)
+ argumentClause = argumentClause.copy(style);
+ return copy(new CASTAttribute(getName(), argumentClause), style);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java
index 42c4d2e390c..6027776583d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTBreakStatement.java
@@ -8,17 +8,18 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
-public class CASTBreakStatement extends ASTNode implements IASTBreakStatement {
+public class CASTBreakStatement extends ASTAttributeOwner implements IASTBreakStatement {
@Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitStatements) {
@@ -29,6 +30,8 @@ public class CASTBreakStatement extends ASTNode implements IASTBreakStatement {
}
}
+ if (!acceptByAttributes(action)) return false;
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@@ -48,10 +51,6 @@ public class CASTBreakStatement extends ASTNode implements IASTBreakStatement {
@Override
public CASTBreakStatement copy(CopyStyle style) {
CASTBreakStatement copy = new CASTBreakStatement();
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java
index 3f87fbe771b..bcf910dbf2e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCaseStatement.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
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.IASTCaseStatement;
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 CASTCaseStatement extends ASTNode implements IASTCaseStatement, IASTAmbiguityParent {
+public class CASTCaseStatement extends ASTAttributeOwner implements IASTCaseStatement, IASTAmbiguityParent {
private IASTExpression expression;
public CASTCaseStatement() {
@@ -39,11 +40,7 @@ public class CASTCaseStatement extends ASTNode implements IASTCaseStatement, IAS
@Override
public CASTCaseStatement copy(CopyStyle style) {
CASTCaseStatement copy = new CASTCaseStatement(expression == null ? null : expression.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java
index 6fdf72c13b5..32eab5b177c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTCompoundStatement.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -18,13 +19,13 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
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.IASTAmbiguityParent;
/**
* @author jcamelon
*/
-public class CASTCompoundStatement extends ASTNode implements IASTCompoundStatement, IASTAmbiguityParent {
+public class CASTCompoundStatement extends ASTAttributeOwner implements IASTCompoundStatement, IASTAmbiguityParent {
private IASTStatement[] statements;
private IScope scope;
@@ -38,11 +39,7 @@ public class CASTCompoundStatement extends ASTNode implements IASTCompoundStatem
CASTCompoundStatement copy = new CASTCompoundStatement();
for (IASTStatement statement : getStatements())
copy.addStatement(statement == null ? null : statement.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -77,10 +74,13 @@ public class CASTCompoundStatement extends ASTNode implements IASTCompoundStatem
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
IASTStatement[] s = getStatements();
for (int i = 0; i < s.length; i++) {
if (!s[i].accept(action)) return false;
}
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java
index 86a42fa09d3..d5c811627ef 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTContinueStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and 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:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
-public class CASTContinueStatement extends ASTNode implements IASTContinueStatement {
+public class CASTContinueStatement extends ASTAttributeOwner implements IASTContinueStatement {
@Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitStatements) {
@@ -28,6 +29,9 @@ public class CASTContinueStatement extends ASTNode implements IASTContinueStatem
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@@ -46,10 +50,6 @@ public class CASTContinueStatement extends ASTNode implements IASTContinueStatem
@Override
public CASTContinueStatement copy(CopyStyle style) {
CASTContinueStatement copy = new CASTContinueStatement();
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java
index 59f7e8c4517..3b5c12d59fb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarationStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and 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 @@
* John Camelon (IBM Rational Software) - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
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.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -22,7 +24,8 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
* A declaration statement.
*/
-public class CASTDeclarationStatement extends ASTNode implements IASTDeclarationStatement, IASTAmbiguityParent {
+public class CASTDeclarationStatement extends ASTNode
+ implements IASTDeclarationStatement, IASTAmbiguityParent {
private IASTDeclaration declaration;
public CASTDeclarationStatement() {
@@ -41,11 +44,7 @@ public class CASTDeclarationStatement extends ASTNode implements IASTDeclaration
public CASTDeclarationStatement copy(CopyStyle style) {
CASTDeclarationStatement copy = new CASTDeclarationStatement();
copy.setDeclaration(declaration == null ? null : declaration.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -72,7 +71,9 @@ public class CASTDeclarationStatement extends ASTNode implements IASTDeclaration
default: break;
}
}
+
if (declaration != null && !declaration.accept(action)) return false;
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@@ -91,4 +92,16 @@ public class CASTDeclarationStatement extends ASTNode implements IASTDeclaration
declaration = (IASTDeclaration) other;
}
}
+
+ @Override
+ public IASTAttribute[] getAttributes() {
+ // Declaration statements don't have attributes.
+ return IASTAttribute.EMPTY_ATTRIBUTE_ARRAY;
+ }
+
+ @Override
+ public void addAttribute(IASTAttribute attribute) {
+ // Declaration statements don't have attributes.
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java
index 2b6e8bf4943..340c246e640 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java
@@ -1,14 +1,15 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Rational Software - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Yuan Zhang / Beth Tibbitts (IBM Research)
+ * IBM Rational Software - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -26,17 +27,17 @@ import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
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.IASTAmbiguityParent;
/**
* @author jcamelon
*/
-public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbiguityParent {
+public class CASTDeclarator extends ASTAttributeOwner implements IASTDeclarator, IASTAmbiguityParent {
private IASTInitializer initializer;
private IASTName name;
private IASTDeclarator nestedDeclarator;
- private IASTPointerOperator[] pointerOps = null;
+ private IASTPointerOperator[] pointerOps;
private int pointerOpsPos= -1;
public CASTDeclarator() {
@@ -58,24 +59,19 @@ public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbig
@Override
public CASTDeclarator copy(CopyStyle style) {
- CASTDeclarator copy = new CASTDeclarator();
- copyBaseDeclarator(copy, style);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(new CASTDeclarator(), style);
}
- protected void copyBaseDeclarator(CASTDeclarator copy, CopyStyle style) {
+ protected T copy(T copy, CopyStyle style) {
copy.setName(name == null ? null : name.copy(style));
copy.setInitializer(initializer == null ? null : initializer.copy(style));
copy.setNestedDeclarator(nestedDeclarator == null ? null : nestedDeclarator.copy(style));
- for(IASTPointerOperator pointer : getPointerOperators())
+ for (IASTPointerOperator pointer : getPointerOperators()) {
copy.addPointerOperator(pointer == null ? null : pointer.copy(style));
- copy.setOffsetAndLength(this);
+ }
+ return super.copy(copy, style);
}
-
-
+
@Override
public IASTPointerOperator[] getPointerOperators() {
if (pointerOps == null) return IASTPointerOperator.EMPTY_ARRAY;
@@ -141,10 +137,10 @@ public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbig
@Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitDeclarators) {
- switch(action.visit(this)) {
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
+ switch (action.visit(this)) {
+ case ASTVisitor.PROCESS_ABORT: return false;
+ case ASTVisitor.PROCESS_SKIP: return true;
+ default: break;
}
}
@@ -153,6 +149,8 @@ public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbig
return false;
}
+ if (!acceptByAttributes(action)) return false;
+
if (getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && nestedDeclarator == null) {
if (getParent() instanceof IASTDeclarator) {
IASTDeclarator outermostDeclarator = (IASTDeclarator) getParent();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java
index 81e22a8f58c..88e8cd71935 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDefaultStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and 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:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
-public class CASTDefaultStatement extends ASTNode implements IASTDefaultStatement {
+public class CASTDefaultStatement extends ASTAttributeOwner implements IASTDefaultStatement {
@Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitStatements) {
@@ -28,6 +29,9 @@ public class CASTDefaultStatement extends ASTNode implements IASTDefaultStatemen
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@@ -46,10 +50,6 @@ public class CASTDefaultStatement extends ASTNode implements IASTDefaultStatemen
@Override
public CASTDefaultStatement copy(CopyStyle style) {
CASTDefaultStatement copy = new CASTDefaultStatement();
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java
index 1e776c358eb..832e4d0bde5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDoStatement.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -16,13 +17,13 @@ import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
-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 CASTDoStatement extends ASTNode implements IASTDoStatement, IASTAmbiguityParent {
+public class CASTDoStatement extends ASTAttributeOwner implements IASTDoStatement, IASTAmbiguityParent {
private IASTStatement body;
private IASTExpression condition;
@@ -44,11 +45,7 @@ public class CASTDoStatement extends ASTNode implements IASTDoStatement, IASTAmb
CASTDoStatement copy = new CASTDoStatement();
copy.setBody(body == null ? null : body.copy(style));
copy.setCondition(condition == null ? null : condition.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -91,6 +88,7 @@ public class CASTDoStatement extends ASTNode implements IASTDoStatement, IASTAmb
}
}
+ if (!acceptByAttributes(action)) return false;
if (body != null && !body.accept(action)) return false;
if (condition != null && !condition.accept(action)) return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java
index 5092f4e35b1..446d6d12669 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTExpressionStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and 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 Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -15,14 +16,14 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
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 CASTExpressionStatement extends ASTNode implements
- IASTExpressionStatement, IASTAmbiguityParent {
+public class CASTExpressionStatement extends ASTAttributeOwner
+ implements IASTExpressionStatement, IASTAmbiguityParent {
private IASTExpression expression;
public CASTExpressionStatement() {
@@ -41,11 +42,7 @@ public class CASTExpressionStatement extends ASTNode implements
public CASTExpressionStatement copy(CopyStyle style) {
CASTExpressionStatement copy = new CASTExpressionStatement();
copy.setExpression(expression == null ? null : expression.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -73,6 +70,7 @@ public class CASTExpressionStatement extends ASTNode implements
}
}
+ if (!acceptByAttributes(action)) return false;
if (expression != null && !expression.accept(action)) return false;
if (action.shouldVisitStatements) {
@@ -82,7 +80,6 @@ public class CASTExpressionStatement extends ASTNode implements
default: break;
}
}
-
return true;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java
index 4624d5cb1d9..7e0d39c4817 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFieldDeclarator.java
@@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Rational Software - Initial API and implementation
- * Markus Schorn (Wind River Systems)
+ * IBM Rational Software - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -39,12 +40,8 @@ public class CASTFieldDeclarator extends CASTDeclarator implements IASTFieldDecl
@Override
public CASTFieldDeclarator copy(CopyStyle style) {
CASTFieldDeclarator copy = new CASTFieldDeclarator();
- copyBaseDeclarator(copy, style);
copy.setBitFieldSize(bitFieldSize == null ? null : bitFieldSize.copy(style));
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -52,7 +49,6 @@ public class CASTFieldDeclarator extends CASTDeclarator implements IASTFieldDecl
return bitFieldSize;
}
-
@Override
public void setBitFieldSize(IASTExpression size) {
assertNotFrozen();
@@ -81,6 +77,4 @@ public class CASTFieldDeclarator extends CASTDeclarator implements IASTFieldDecl
super.replace(child, other);
}
}
-
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java
index 24284ad71ed..7480cdfab8b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTForStatement.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -18,13 +19,13 @@ import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
-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 CASTForStatement extends ASTNode implements IASTForStatement, IASTAmbiguityParent {
+public class CASTForStatement extends ASTAttributeOwner implements IASTForStatement, IASTAmbiguityParent {
private IScope scope;
private IASTExpression condition;
private IASTExpression iterationExpression;
@@ -50,20 +51,16 @@ public class CASTForStatement extends ASTNode implements IASTForStatement, IASTA
@Override
public CASTForStatement copy(CopyStyle style) {
CASTForStatement copy = new CASTForStatement();
- copyForStatement(copy, style);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
- protected void copyForStatement(CASTForStatement copy, CopyStyle style) {
+ protected T copy(T copy, CopyStyle style) {
copy.setInitializerStatement(init == null ? null : init.copy(style));
copy.setConditionExpression(condition == null ? null : condition.copy(style));
copy.setIterationExpression(iterationExpression == null ?
null : iterationExpression.copy(style));
copy.setBody(body == null ? null : body.copy(style));
- copy.setOffsetAndLength(this);
+ return super.copy(copy, style);
}
@Override
@@ -141,6 +138,8 @@ public class CASTForStatement extends ASTNode implements IASTForStatement, IASTA
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
if (init != null && !init.accept(action)) return false;
if (condition != null && !condition.accept(action)) return false;
if (iterationExpression != null && !iterationExpression.accept(action)) return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java
index 2bf3dfffe82..94814477650 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDeclarator.java
@@ -8,6 +8,7 @@
* Contributors:
* John Camelon (IBM Rational Software) - Initial API and implementation
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -47,17 +48,11 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda
@Override
public CASTFunctionDeclarator copy(CopyStyle style) {
CASTFunctionDeclarator copy = new CASTFunctionDeclarator();
- copyBaseDeclarator(copy, style);
copy.varArgs = varArgs;
-
for (IASTParameterDeclaration param : getParameters()) {
copy.addParameterDeclaration(param == null ? null : param.copy(style));
}
-
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java
index 639e422ba0a..9b6518bac43 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTGotoStatement.java
@@ -8,18 +8,19 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
-public class CASTGotoStatement extends ASTNode implements IASTGotoStatement {
+public class CASTGotoStatement extends ASTAttributeOwner implements IASTGotoStatement {
private IASTName name;
public CASTGotoStatement() {
@@ -37,11 +38,7 @@ public class CASTGotoStatement extends ASTNode implements IASTGotoStatement {
@Override
public CASTGotoStatement copy(CopyStyle style) {
CASTGotoStatement copy = new CASTGotoStatement(name == null ? null : name.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -69,6 +66,7 @@ public class CASTGotoStatement extends ASTNode implements IASTGotoStatement {
}
}
+ if (!acceptByAttributes(action)) return false;
if (name != null && !name.accept(action)) return false;
if (action.shouldVisitStatements) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java
index 8848fadfc97..e624f165733 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIfStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and 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 Rational Software) - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -17,13 +18,13 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
-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;
/**
* If statements for C.
*/
-public class CASTIfStatement extends ASTNode implements IASTIfStatement, IASTAmbiguityParent {
+public class CASTIfStatement extends ASTAttributeOwner implements IASTIfStatement, IASTAmbiguityParent {
private IASTExpression condition;
private IASTStatement thenClause;
private IASTStatement elseClause;
@@ -52,11 +53,7 @@ public class CASTIfStatement extends ASTNode implements IASTIfStatement, IASTAmb
copy.setConditionExpression(condition == null ? null : condition.copy(style));
copy.setThenClause(thenClause == null ? null : thenClause.copy(style));
copy.setElseClause(elseClause == null ? null : elseClause.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -117,16 +114,19 @@ public class CASTIfStatement extends ASTNode implements IASTIfStatement, IASTAmb
public boolean accept(ASTVisitor action) {
N stack= null;
IASTIfStatement stmt= this;
- loop: for(;;) {
+ loop: for (;;) {
if (action.shouldVisitStatements) {
switch (action.visit(stmt)) {
- case ASTVisitor.PROCESS_ABORT: return false;
+ case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP:
stmt= null;
break loop;
default: break;
}
}
+
+ if (!((CASTIfStatement) stmt).acceptByAttributes(action)) return false;
+
IASTNode child = stmt.getConditionExpression();
if (child != null && !child.accept(action))
return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java
index 429d70fd358..b57e480e79a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTKnRFunctionDeclarator.java
@@ -6,9 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
- * Anton Leherbauer (Wind River Systems)
- * Markus Schorn (Wind River Systems)
+ * IBM - Initial API and implementation
+ * Anton Leherbauer (Wind River Systems)
+ * Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -25,10 +26,8 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
* @author dsteffle
*/
public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKnRFunctionDeclarator {
-
IASTName[] parameterNames = IASTName.EMPTY_NAME_ARRAY;
IASTDeclaration[] parameterDeclarations = IASTDeclaration.EMPTY_DECLARATION_ARRAY;
-
public CASTKnRFunctionDeclarator() {
}
@@ -46,7 +45,6 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn
@Override
public CASTKnRFunctionDeclarator copy(CopyStyle style) {
CASTKnRFunctionDeclarator copy = new CASTKnRFunctionDeclarator();
- copyBaseDeclarator(copy, style);
copy.parameterNames = new IASTName[parameterNames.length];
for (int i = 0; i < parameterNames.length; i++) {
@@ -65,10 +63,7 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn
copy.parameterDeclarations[i].setPropertyInParent(FUNCTION_PARAMETER);
}
}
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -85,13 +80,11 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn
}
}
-
@Override
public IASTName[] getParameterNames() {
return parameterNames;
}
-
@Override
public void setParameterDeclarations(IASTDeclaration[] decls) {
assertNotFrozen();
@@ -106,7 +99,6 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn
}
}
-
@Override
public IASTDeclaration[] getParameterDeclarations() {
return parameterDeclarations;
@@ -131,17 +123,19 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn
@Override
public IASTDeclarator getDeclaratorForParameterName(IASTName name) {
- boolean found=false;
- for(int i=0; i T copy(T copy, CopyStyle style) {
copy.setProblem(problem == null ? null : problem.copy(style));
- copy.setOffsetAndLength(this);
+ return super.copy(copy, style);
}
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java
index 1a793d172b8..413acfbdb11 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java
@@ -9,10 +9,12 @@
* IBM - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
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.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
@@ -36,11 +38,7 @@ public class CASTProblemStatement extends CASTProblemOwner implements IASTProble
@Override
public CASTProblemStatement copy(CopyStyle style) {
CASTProblemStatement copy = new CASTProblemStatement();
- copyBaseProblem(copy, style);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -64,4 +62,15 @@ public class CASTProblemStatement extends CASTProblemOwner implements IASTProble
}
return true;
}
+
+ @Override
+ public IASTAttribute[] getAttributes() {
+ return IASTAttribute.EMPTY_ATTRIBUTE_ARRAY;
+ }
+
+ @Override
+ public void addAttribute(IASTAttribute attribute) {
+ assertNotFrozen();
+ // Ignore.
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java
index a87dc806eea..34f8e9bdaa4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTReturnStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and 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 Rational Software) - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -17,10 +18,10 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
-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;
-public class CASTReturnStatement extends ASTNode implements IASTReturnStatement, IASTAmbiguityParent {
+public class CASTReturnStatement extends ASTAttributeOwner implements IASTReturnStatement, IASTAmbiguityParent {
private IASTExpression retValue;
public CASTReturnStatement() {
@@ -39,11 +40,7 @@ public class CASTReturnStatement extends ASTNode implements IASTReturnStatement,
public CASTReturnStatement copy(CopyStyle style) {
CASTReturnStatement copy =
new CASTReturnStatement(retValue == null ? null : retValue.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -84,7 +81,10 @@ public class CASTReturnStatement extends ASTNode implements IASTReturnStatement,
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
if (retValue != null && !retValue.accept(action)) return false;
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java
index 3f2f375d1b6..ee22a7af765 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSimpleDeclaration.java
@@ -9,6 +9,7 @@
* John Camelon (IBM Rational Software) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -18,13 +19,13 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.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.IASTAmbiguityParent;
/**
* Models a simple declaration.
*/
-public class CASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclaration, IASTAmbiguityParent {
+public class CASTSimpleDeclaration extends ASTAttributeOwner implements IASTSimpleDeclaration, IASTAmbiguityParent {
private IASTDeclarator[] declarators;
private int declaratorsPos = -1;
private IASTDeclSpecifier declSpecifier;
@@ -45,15 +46,10 @@ public class CASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclarat
public CASTSimpleDeclaration copy(CopyStyle style) {
CASTSimpleDeclaration copy = new CASTSimpleDeclaration();
copy.setDeclSpecifier(declSpecifier == null ? null : declSpecifier.copy(style));
-
- for (IASTDeclarator declarator : getDeclarators())
+ for (IASTDeclarator declarator : getDeclarators()) {
copy.addDeclarator(declarator == null ? null : declarator.copy(style));
-
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
}
- return copy;
+ return copy(copy, style);
}
@Override
@@ -98,9 +94,10 @@ public class CASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclarat
default: break;
}
}
-
- if (declSpecifier != null && !declSpecifier.accept(action))
- return false;
+
+ if (!acceptByAttributes(action)) return false;
+ if (declSpecifier != null && !declSpecifier.accept(action)) return false;
+
IASTDeclarator[] dtors = getDeclarators();
for (int i = 0; i < dtors.length; i++) {
if (!dtors[i].accept(action))
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java
index 048766204ae..26c41ea69ad 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTSwitchStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and 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 Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -16,13 +17,13 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
-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 CASTSwitchStatement extends ASTNode
+public class CASTSwitchStatement extends ASTAttributeOwner
implements IASTSwitchStatement, IASTAmbiguityParent {
private IASTExpression controller;
private IASTStatement body;
@@ -45,11 +46,7 @@ public class CASTSwitchStatement extends ASTNode
CASTSwitchStatement copy = new CASTSwitchStatement();
copy.setControllerExpression(controller == null ? null : controller.copy(style));
copy.setBody(body == null ? null : body.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -92,6 +89,7 @@ public class CASTSwitchStatement extends ASTNode
}
}
+ if (!acceptByAttributes(action)) return false;
if (controller != null && !controller.accept(action)) return false;
if (body != null && !body.accept(action)) return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java
index c34ac0de762..a3417540b82 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTWhileStatement.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -16,13 +17,14 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
-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 CASTWhileStatement extends ASTNode implements IASTWhileStatement, IASTAmbiguityParent {
+public class CASTWhileStatement extends ASTAttributeOwner
+ implements IASTWhileStatement, IASTAmbiguityParent {
private IASTExpression condition;
private IASTStatement body;
@@ -44,11 +46,7 @@ public class CASTWhileStatement extends ASTNode implements IASTWhileStatement, I
CASTWhileStatement copy = new CASTWhileStatement();
copy.setCondition(condition == null ? null : condition.copy(style));
copy.setBody(body == null ? null : body.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -90,6 +88,8 @@ public class CASTWhileStatement extends ASTNode implements IASTWhileStatement, I
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
if (condition != null && !condition.accept(action)) return false;
if (body != null && !body.accept(action)) return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
index 9a08e1e2431..6cd767286e1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 IBM Corporation and others.
+ * Copyright (c) 2006, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,6 +14,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
+import org.eclipse.cdt.core.dom.ast.IASTAttribute;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
@@ -58,6 +59,8 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
+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.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
@@ -79,6 +82,8 @@ 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.NodeFactory;
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
@@ -88,7 +93,6 @@ import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
* implementations of the nodes.
*/
public class CNodeFactory extends NodeFactory implements ICNodeFactory {
-
private static final CNodeFactory DEFAULT_INSTANCE = new CNodeFactory();
public static CNodeFactory getDefault() {
@@ -125,6 +129,10 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
return new CASTASMDeclaration(assembly);
}
+ @Override
+ public IASTAttribute newAttribute(char[] name, IASTToken argumentClause) {
+ return new CASTAttribute(name, argumentClause);
+ }
@Override
public IASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2) {
return new CASTBinaryExpression(op, expr1, expr2);
@@ -392,7 +400,17 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body) {
return new CASTSwitchStatement(controller, body);
}
-
+
+ @Override
+ public IASTToken newToken(int tokenType, char[] tokenImage) {
+ return new ASTToken(tokenType, tokenImage);
+ }
+
+ @Override
+ public IASTTokenList newTokenList() {
+ return new ASTTokenList();
+ }
+
@Override
public IASTTranslationUnit newTranslationUnit() {
return newTranslationUnit(null);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java
index 2d6771192ac..404c63c8f4c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CParameter.java
@@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
+import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject;
@@ -88,7 +89,7 @@ public class CParameter extends PlatformObject implements IParameter {
IASTName name = getPrimaryDeclaration();
if (name != null)
return name.toCharArray();
- return CVisitor.EMPTY_CHAR_ARRAY;
+ return CharArrayUtils.EMPTY_CHAR_ARRAY;
}
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
index a9287c1947f..520b9143c09 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and 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 @@
* Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian)
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -22,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
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.IASTAttribute;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
@@ -91,6 +93,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArraySet;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.IContentAssistMatcher;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttribute;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
@@ -104,9 +107,6 @@ import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory;
* Collection of methods to find information in an AST.
*/
public class CVisitor extends ASTQueries {
- /**
- *
- */
private static final CBasicType UNSIGNED_LONG_INT = new CBasicType(Kind.eInt, IBasicType.IS_LONG | IBasicType.IS_UNSIGNED);
public static class CollectProblemsAction extends ASTVisitor {
@@ -443,9 +443,7 @@ public class CVisitor extends ASTQueries {
private static final String SIZE_T = "size_t"; //$NON-NLS-1$
private static final String PTRDIFF_T = "ptrdiff_t"; //$NON-NLS-1$
public static final String EMPTY_STRING = ""; //$NON-NLS-1$
- public static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$
-
- // definition lookup start location
+ // Definition lookup start location
protected static final int AT_BEGINNING = 1;
protected static final int AT_NEXT = 2;
@@ -1255,6 +1253,7 @@ public class CVisitor extends ASTQueries {
return createType(baseType, (IASTFunctionDeclarator) declarator);
IType type = baseType;
+ type = applyAttributes(type, declarator);
type = setupPointerChain(declarator.getPointerOperators(), type);
type = setupArrayChain(declarator, type);
@@ -1265,6 +1264,41 @@ public class CVisitor extends ASTQueries {
return type;
}
+ private static IType applyAttributes(IType type, IASTDeclarator declarator) {
+ if (type instanceof IBasicType) {
+ IBasicType basicType = (IBasicType) type;
+ if (basicType.getKind() == IBasicType.Kind.eInt) {
+ IASTAttribute[] attributes = declarator.getAttributes();
+ for (IASTAttribute attribute : attributes) {
+ char[] name = attribute.getName();
+ if (CharArrayUtils.equals(name, "__mode__") || CharArrayUtils.equals(name, "mode")) { //$NON-NLS-1$ //$NON-NLS-2$
+ char[] mode = ASTAttribute.getSimpleArgument(attribute);
+ if (CharArrayUtils.equals(mode, "__QI__") || CharArrayUtils.equals(mode, "QI")) { //$NON-NLS-1$ //$NON-NLS-2$
+ type = new CBasicType(IBasicType.Kind.eChar,
+ basicType.isUnsigned() ? IBasicType.IS_UNSIGNED : IBasicType.IS_SIGNED);
+ } else if (CharArrayUtils.equals(mode, "__HI__") || CharArrayUtils.equals(mode, "HI")) { //$NON-NLS-1$ //$NON-NLS-2$
+ type = new CBasicType(IBasicType.Kind.eInt,
+ IBasicType.IS_SHORT | getSignModifiers(basicType));
+ } else if (CharArrayUtils.equals(mode, "__SI__") || CharArrayUtils.equals(mode, "SI")) { //$NON-NLS-1$ //$NON-NLS-2$
+ type = new CBasicType(IBasicType.Kind.eInt, getSignModifiers(basicType));
+ } else if (CharArrayUtils.equals(mode, "__DI__") || CharArrayUtils.equals(mode, "DI")) { //$NON-NLS-1$ //$NON-NLS-2$
+ type = new CBasicType(IBasicType.Kind.eInt,
+ IBasicType.IS_LONG_LONG | getSignModifiers(basicType));
+ } else if (CharArrayUtils.equals(mode, "__word__") || CharArrayUtils.equals(mode, "word")) { //$NON-NLS-1$ //$NON-NLS-2$
+ type = new CBasicType(IBasicType.Kind.eInt,
+ IBasicType.IS_LONG | getSignModifiers(basicType));
+ }
+ }
+ }
+ }
+ }
+ return type;
+ }
+
+ private static int getSignModifiers(IBasicType type) {
+ return type.getModifiers() & (IBasicType.IS_SIGNED | IBasicType.IS_UNSIGNED);
+ }
+
public static IType createType(IType returnType, IASTFunctionDeclarator declarator) {
IType[] pTypes = getParmTypes(declarator);
returnType = setupPointerChain(declarator.getPointerOperators(), returnType);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
index d104fb63984..9238a9a1bfd 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,6 +10,7 @@
* Markus Schorn (Wind River Systems)
* Ed Swartz (Nokia)
* Mike Kucera (IBM) - bug #206952
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -22,6 +23,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.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
@@ -85,6 +87,7 @@ import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
+import org.eclipse.cdt.core.parser.util.CollectionUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
@@ -1272,7 +1275,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
return result;
}
-
protected IASTElaboratedTypeSpecifier elaboratedTypeSpecifier() throws BacktrackException, EndOfFileException {
// this is an elaborated class specifier
IToken t = consume();
@@ -1302,7 +1304,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
return result;
}
-
@Override
protected IASTDeclarator initDeclarator(IASTDeclSpecifier declspec, final DeclarationOptions option)
throws EndOfFileException, BacktrackException, FoundAggregateInitializer {
@@ -1337,7 +1338,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
// Accept __attribute__ or __declspec between pointer operators and declarator.
- __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
+ List attributes =
+ __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
// Look for identifier or nested declarator
final int lt1= LT(1);
@@ -1347,7 +1349,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
final IASTName declaratorName = identifier();
endOffset= calculateEndOffset(declaratorName);
- return declarator(pointerOps, declaratorName, null, startingOffset, endOffset, option);
+ return declarator(pointerOps, attributes, declaratorName, null, startingOffset,
+ endOffset, option);
}
if (lt1 == IToken.tLPAREN) {
@@ -1357,7 +1360,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (option.fAllowAbstract) {
final IToken mark= mark();
try {
- cand1= declarator(pointerOps, nodeFactory.newName(), null, startingOffset, endOffset, option);
+ cand1= declarator(pointerOps, attributes, nodeFactory.newName(), null,
+ startingOffset, endOffset, option);
if (option.fRequireAbstract)
return cand1;
@@ -1374,7 +1378,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
final IASTDeclarator nested= declarator(declSpec, option);
endOffset= consume(IToken.tRPAREN).getEndOffset();
- final IASTDeclarator cand2= declarator(pointerOps, null, nested, startingOffset, endOffset, option);
+ final IASTDeclarator cand2= declarator(pointerOps, attributes, null, nested,
+ startingOffset, endOffset, option);
if (cand1 == null || cand1End == null)
return cand2;
final IToken cand2End= LA(1);
@@ -1399,12 +1404,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (!option.fAllowAbstract) {
throwBacktrack(LA(1));
}
- return declarator(pointerOps, nodeFactory.newName(), null, startingOffset, endOffset, option);
+ return declarator(pointerOps, attributes, nodeFactory.newName(), null, startingOffset,
+ endOffset, option);
}
- private IASTDeclarator declarator(final List pointerOps,
- final IASTName declaratorName, final IASTDeclarator nestedDeclarator,
- final int startingOffset, int endOffset,
+ private IASTDeclarator declarator(final List pointerOps,
+ List attributes, final IASTName declaratorName,
+ final IASTDeclarator nestedDeclarator, final int startingOffset, int endOffset,
final DeclarationOptions option) throws EndOfFileException, BacktrackException {
IASTDeclarator result= null;
int lt1;
@@ -1433,19 +1439,23 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
case IGCCToken.t__attribute__: // if __attribute__ is after a declarator
if (!supportAttributeSpecifiers)
throwBacktrack(LA(1));
- __attribute_decl_seq(true, supportDeclspecSpecifiers);
+ attributes = CollectionUtils.merge(attributes,
+ __attribute_decl_seq(true, supportDeclspecSpecifiers));
break;
case IGCCToken.t__declspec:
if (!supportDeclspecSpecifiers)
throwBacktrack(LA(1));
- __attribute_decl_seq(supportAttributeSpecifiers, true);
+ attributes = CollectionUtils.merge(attributes,
+ __attribute_decl_seq(supportAttributeSpecifiers, true));
break;
default:
break loop;
}
}
- if (lt1 != 0)
- __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
+ if (lt1 != 0) {
+ attributes = CollectionUtils.merge(attributes,
+ __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers));
+ }
if (result == null) {
result= nodeFactory.newDeclarator(null);
@@ -1465,6 +1475,12 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
result.addPointerOperator(po);
}
+ if (attributes != null) {
+ for (IASTAttribute attribute : attributes) {
+ result.addAttribute(attribute);
+ }
+ }
+
((ASTNode) result).setOffsetAndLength(startingOffset, endOffset - startingOffset);
return result;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java
index 4ab8074fd29..67d41afa794 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 IBM Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2012 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
@@ -7,10 +7,12 @@
*
* Contributors:
* Markus Schorn - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
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.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName;
@@ -84,7 +86,7 @@ public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode
@Override
public IASTDeclarator[] getDeclarators() {
- dtors = ArrayUtil.trimAt(IASTDeclarator.class, dtors, dtorPos );
+ dtors = ArrayUtil.trimAt(IASTDeclarator.class, dtors, dtorPos);
return dtors;
}
@@ -113,17 +115,28 @@ public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode
return dtors[0].getPointerOperators();
}
- @Override
- public int getRoleForName(IASTName name) {
- return dtors[0].getRoleForName(name);
- }
-
@Override
public void addPointerOperator(IASTPointerOperator operator) {
assertNotFrozen();
Assert.isLegal(false);
}
+ @Override
+ public IASTAttribute[] getAttributes() {
+ return dtors[0].getAttributes();
+ }
+
+ @Override
+ public void addAttribute(IASTAttribute attribute) {
+ assertNotFrozen();
+ Assert.isLegal(false);
+ }
+
+ @Override
+ public int getRoleForName(IASTName name) {
+ return dtors[0].getRoleForName(name);
+ }
+
@Override
public void setInitializer(IASTInitializer initializer) {
// store the initializer until the ambiguity is resolved
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java
index 7f363cb0533..ec1823928cc 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousSimpleDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 IBM Wind River Systems, Inc. and others.
+ * Copyright (c) 2009, 2012 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
@@ -7,10 +7,12 @@
*
* Contributors:
* Markus Schorn - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
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.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName;
@@ -127,4 +129,14 @@ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implement
fSimpleDecl.accept(resolver);
return fSimpleDecl;
}
+
+ @Override
+ public IASTAttribute[] getAttributes() {
+ return fSimpleDecl.getAttributes();
+ }
+
+ @Override
+ public void addAttribute(IASTAttribute attribute) {
+ fSimpleDecl.addAttribute(attribute);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java
index cc6c607d1e9..53b624a78f9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,10 +8,12 @@
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
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.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -98,4 +100,14 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAm
public IASTNode[] getNodes() {
return getStatements();
}
+
+ @Override
+ public IASTAttribute[] getAttributes() {
+ return IASTAttribute.EMPTY_ATTRIBUTE_ARRAY;
+ }
+
+ @Override
+ public void addAttribute(IASTAttribute attribute) {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttribute.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttribute.java
new file mode 100644
index 00000000000..a676534cb51
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAttribute.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.parser.cpp;
+
+import org.eclipse.cdt.core.dom.ast.IASTToken;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttribute;
+
+/**
+ * C++-specific attribute.
+ */
+public class CPPASTAttribute extends ASTAttribute {
+
+ public CPPASTAttribute(char[] name, IASTToken argumentsClause) {
+ super(name, argumentsClause);
+ }
+
+ @Override
+ public CPPASTAttribute copy() {
+ return copy(CopyStyle.withoutLocations);
+ }
+
+ @Override
+ public CPPASTAttribute copy(CopyStyle style) {
+ IASTToken argumentClause = getArgumentClause();
+ if (argumentClause != null)
+ argumentClause = argumentClause.copy(style);
+ return copy(new CPPASTAttribute(getName(), argumentClause), style);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java
index 00f026ed1a5..30ec00b7303 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBreakStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,17 +7,18 @@
*
* Contributors:
* IBM - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
-public class CPPASTBreakStatement extends ASTNode implements IASTBreakStatement {
+public class CPPASTBreakStatement extends ASTAttributeOwner implements IASTBreakStatement {
@Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitStatements) {
@@ -27,6 +28,9 @@ public class CPPASTBreakStatement extends ASTNode implements IASTBreakStatement
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@@ -45,10 +49,6 @@ public class CPPASTBreakStatement extends ASTNode implements IASTBreakStatement
@Override
public CPPASTBreakStatement copy(CopyStyle style) {
CPPASTBreakStatement copy = new CPPASTBreakStatement();
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java
index 82e8d3b8bd0..caad657005e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCaseStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -14,13 +15,14 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
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 CPPASTCaseStatement extends ASTNode implements IASTCaseStatement, IASTAmbiguityParent {
+public class CPPASTCaseStatement extends ASTAttributeOwner
+ implements IASTCaseStatement, IASTAmbiguityParent {
private IASTExpression expression;
public CPPASTCaseStatement() {
@@ -39,11 +41,7 @@ public class CPPASTCaseStatement extends ASTNode implements IASTCaseStatement, I
public CPPASTCaseStatement copy(CopyStyle style) {
CPPASTCaseStatement copy =
new CPPASTCaseStatement(expression == null ? null : expression.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -71,6 +69,7 @@ public class CPPASTCaseStatement extends ASTNode implements IASTCaseStatement, I
}
}
+ if (!acceptByAttributes(action)) return false;
if (expression != null && !expression.accept(action)) return false;
if (action.shouldVisitStatements) {
@@ -91,5 +90,4 @@ public class CPPASTCaseStatement extends ASTNode implements IASTCaseStatement, I
expression = (IASTExpression) other;
}
}
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java
index 1cf869e278c..e1754748719 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCatchHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -17,13 +18,14 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
-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 CPPASTCatchHandler extends ASTNode implements ICPPASTCatchHandler, IASTAmbiguityParent {
+public class CPPASTCatchHandler extends ASTAttributeOwner
+ implements ICPPASTCatchHandler, IASTAmbiguityParent {
private boolean isCatchAll;
private IASTStatement body;
private IASTDeclaration declaration;
@@ -48,11 +50,7 @@ public class CPPASTCatchHandler extends ASTNode implements ICPPASTCatchHandler,
copy.setDeclaration(declaration == null ? null : declaration.copy(style));
copy.setCatchBody(body == null ? null : body.copy(style));
copy.setIsCatchAll(isCatchAll);
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -105,6 +103,8 @@ public class CPPASTCatchHandler extends ASTNode implements ICPPASTCatchHandler,
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
if (declaration != null && !declaration.accept(action)) return false;
if (body != null && !body.accept(action)) return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java
index 2f833ac037c..ca5e636962e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCompoundStatement.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -17,13 +18,13 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
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.IASTAmbiguityParent;
/**
* @author jcamelon
*/
-public class CPPASTCompoundStatement extends ASTNode
+public class CPPASTCompoundStatement extends ASTAttributeOwner
implements IASTCompoundStatement, IASTAmbiguityParent {
private IASTStatement[] statements = new IASTStatement[2];
private ICPPScope scope;
@@ -36,26 +37,24 @@ public class CPPASTCompoundStatement extends ASTNode
@Override
public CPPASTCompoundStatement copy(CopyStyle style) {
CPPASTCompoundStatement copy = new CPPASTCompoundStatement();
- for (IASTStatement statement : getStatements())
- copy.addStatement(statement == null ? null : statement.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
+ for (IASTStatement statement : getStatements()) {
+ if (statement == null)
+ break;
+ copy.addStatement(statement.copy(style));
}
- return copy;
+ return copy(copy, style);
}
@Override
public IASTStatement[] getStatements() {
- if (statements == null)
- return IASTStatement.EMPTY_STATEMENT_ARRAY;
- return ArrayUtil.trim(IASTStatement.class, statements);
+ statements = ArrayUtil.trim(statements);
+ return statements;
}
@Override
public void addStatement(IASTStatement statement) {
assertNotFrozen();
- statements = ArrayUtil.append(IASTStatement.class, statements, statement);
+ statements = ArrayUtil.append(statements, statement);
if (statement != null) {
statement.setParent(this);
statement.setPropertyInParent(NESTED_STATEMENT);
@@ -78,11 +77,15 @@ public class CPPASTCompoundStatement extends ASTNode
default: break;
}
}
- IASTStatement[] s = getStatements();
- for (int i = 0; i < s.length; i++) {
- if (!s[i].accept(action))
+
+ if (!acceptByAttributes(action)) return false;
+ for (IASTStatement statement : statements) {
+ if (statement == null)
+ break;
+ if (!statement.accept(action))
return false;
}
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@@ -95,7 +98,6 @@ public class CPPASTCompoundStatement extends ASTNode
@Override
public void replace(IASTNode child, IASTNode other) {
- if (statements == null) return;
for (int i = 0; i < statements.length; ++i) {
if (statements[i] == child) {
other.setParent(statements[i].getParent());
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java
index f2bf12eeb03..344a5849dd1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTContinueStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,17 +7,18 @@
*
* Contributors:
* IBM - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
-public class CPPASTContinueStatement extends ASTNode implements IASTContinueStatement {
+public class CPPASTContinueStatement extends ASTAttributeOwner implements IASTContinueStatement {
@Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitStatements) {
@@ -27,6 +28,9 @@ public class CPPASTContinueStatement extends ASTNode implements IASTContinueStat
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@@ -45,10 +49,6 @@ public class CPPASTContinueStatement extends ASTNode implements IASTContinueStat
@Override
public CPPASTContinueStatement copy(CopyStyle style) {
CPPASTContinueStatement copy = new CPPASTContinueStatement();
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java
index 85298da6dd9..fe3fd1e6f7f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarationStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,10 +7,12 @@
*
* Contributors:
* IBM - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
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.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -40,11 +42,7 @@ public class CPPASTDeclarationStatement extends ASTNode
public CPPASTDeclarationStatement copy(CopyStyle style) {
CPPASTDeclarationStatement copy = new CPPASTDeclarationStatement();
copy.setDeclaration(declaration == null ? null : declaration.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -71,7 +69,9 @@ public class CPPASTDeclarationStatement extends ASTNode
default: break;
}
}
+
if (declaration != null && !declaration.accept(action)) return false;
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@@ -90,4 +90,16 @@ public class CPPASTDeclarationStatement extends ASTNode
declaration = (IASTDeclaration) other;
}
}
+
+ @Override
+ public IASTAttribute[] getAttributes() {
+ // Declaration statements don't have attributes.
+ return IASTAttribute.EMPTY_ATTRIBUTE_ARRAY;
+ }
+
+ @Override
+ public void addAttribute(IASTAttribute attribute) {
+ // Declaration statements don't have attributes.
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java
index ffc5ed762b2..8b503ce3b30 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDeclarator.java
@@ -1,18 +1,19 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * John Camelon (IBM) - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Sergey Prigogin (Google)
+ * John Camelon (IBM) - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
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;
@@ -47,6 +48,7 @@ public class CPPASTDeclarator extends ASTNode implements ICPPASTDeclarator, IAST
private IASTImplicitName[] implicitNames;
private IASTDeclarator nested;
private IASTPointerOperator[] pointerOps;
+ private IASTAttribute[] attributes;
private boolean isPackExpansion;
public CPPASTDeclarator() {
@@ -81,8 +83,12 @@ public class CPPASTDeclarator extends ASTNode implements ICPPASTDeclarator, IAST
copy.setInitializer(initializer == null ? null : initializer.copy(style));
copy.setNestedDeclarator(nested == null ? null : nested.copy(style));
copy.isPackExpansion= isPackExpansion;
- for (IASTPointerOperator pointer : getPointerOperators())
- copy.addPointerOperator(pointer == null ? null : pointer.copy(style));
+ for (IASTPointerOperator pointer : getPointerOperators()) {
+ copy.addPointerOperator(pointer.copy(style));
+ }
+ for (IASTAttribute attribute : getAttributes()) {
+ copy.addAttribute(attribute.copy(style));
+ }
copy.setOffsetAndLength(this);
}
@@ -98,6 +104,23 @@ 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;
@@ -178,6 +201,15 @@ 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 (nested == null && name != null) {
IASTDeclarator outermost= ASTQueries.findOutermostDeclarator(this);
if (outermost.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java
index a9e33954eb1..878773c1727 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDefaultStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,18 +7,18 @@
*
* Contributors:
* IBM - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
-public class CPPASTDefaultStatement extends ASTNode implements IASTDefaultStatement {
-
+public class CPPASTDefaultStatement extends ASTAttributeOwner implements IASTDefaultStatement {
@Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitStatements) {
@@ -28,6 +28,9 @@ public class CPPASTDefaultStatement extends ASTNode implements IASTDefaultStatem
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@@ -46,10 +49,6 @@ public class CPPASTDefaultStatement extends ASTNode implements IASTDefaultStatem
@Override
public CPPASTDefaultStatement copy(CopyStyle style) {
CPPASTDefaultStatement copy = new CPPASTDefaultStatement();
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java
index 6002782353f..b3ef616f7fc 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTDoStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -15,13 +16,14 @@ import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
-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 CPPASTDoStatement extends ASTNode implements IASTDoStatement, IASTAmbiguityParent {
+public class CPPASTDoStatement extends ASTAttributeOwner
+ implements IASTDoStatement, IASTAmbiguityParent {
private IASTStatement body;
private IASTExpression condition;
@@ -43,11 +45,7 @@ public class CPPASTDoStatement extends ASTNode implements IASTDoStatement, IASTA
CPPASTDoStatement copy = new CPPASTDoStatement();
copy.setBody(body == null ? null : body.copy(style));
copy.setCondition(condition == null ? null : condition.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -90,6 +88,7 @@ public class CPPASTDoStatement extends ASTNode implements IASTDoStatement, IASTA
}
}
+ if (!acceptByAttributes(action)) return false;
if (body != null && !body.accept(action)) return false;
if (condition != null && !condition.accept(action)) return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java
index b17798e0346..8cd4822ac48 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTExpressionStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -14,14 +15,14 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
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 CPPASTExpressionStatement extends ASTNode implements
- IASTExpressionStatement, IASTAmbiguityParent {
+public class CPPASTExpressionStatement extends ASTAttributeOwner
+ implements IASTExpressionStatement, IASTAmbiguityParent {
private IASTExpression expression;
public CPPASTExpressionStatement() {
@@ -40,11 +41,7 @@ public class CPPASTExpressionStatement extends ASTNode implements
public CPPASTExpressionStatement copy(CopyStyle style) {
CPPASTExpressionStatement copy = new CPPASTExpressionStatement();
copy.setExpression(expression == null ? null : expression.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -71,7 +68,10 @@ public class CPPASTExpressionStatement extends ASTNode implements
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
if (expression != null && !expression.accept(action)) return false;
+
if (action.shouldVisitExpressions) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java
index ca4c3e7b2bf..a6183238854 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTForStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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
* Emanuel Graf IFS - Bug 198269
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -19,14 +20,15 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
-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;
/**
* For statement in C++
*/
-public class CPPASTForStatement extends ASTNode implements ICPPASTForStatement, IASTAmbiguityParent {
- private IScope scope = null;
+public class CPPASTForStatement extends ASTAttributeOwner
+ implements ICPPASTForStatement, IASTAmbiguityParent {
+ private IScope scope;
private IASTStatement init;
private IASTExpression condition;
@@ -67,11 +69,7 @@ public class CPPASTForStatement extends ASTNode implements ICPPASTForStatement,
copy.setIterationExpression(iterationExpression == null ?
null : iterationExpression.copy(style));
copy.setBody(body == null ? null : body.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -136,6 +134,8 @@ public class CPPASTForStatement extends ASTNode implements ICPPASTForStatement,
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
if (init != null && !init.accept(action)) return false;
if (condition != null && !condition.accept(action)) return false;
if (condDeclaration != null && !condDeclaration.accept(action)) return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java
index 62e88114664..4d24c5ad678 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTGotoStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,18 +7,19 @@
*
* Contributors:
* IBM - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
-public class CPPASTGotoStatement extends ASTNode implements IASTGotoStatement {
+public class CPPASTGotoStatement extends ASTAttributeOwner implements IASTGotoStatement {
private IASTName name;
public CPPASTGotoStatement() {
@@ -36,11 +37,7 @@ public class CPPASTGotoStatement extends ASTNode implements IASTGotoStatement {
@Override
public CPPASTGotoStatement copy(CopyStyle style) {
CPPASTGotoStatement copy = new CPPASTGotoStatement(name == null ? null : name.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -68,6 +65,7 @@ public class CPPASTGotoStatement extends ASTNode implements IASTGotoStatement {
}
}
+ if (!acceptByAttributes(action)) return false;
if (name != null && !name.accept(action)) return false;
if (action.shouldVisitStatements) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java
index 1611f398ce0..13d5c7421ff 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIfStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -19,13 +20,13 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
-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;
/**
* If statement in C++
*/
-public class CPPASTIfStatement extends ASTNode implements ICPPASTIfStatement, IASTAmbiguityParent {
+public class CPPASTIfStatement extends ASTAttributeOwner implements ICPPASTIfStatement, IASTAmbiguityParent {
private IASTExpression condition;
private IASTStatement thenClause;
private IASTStatement elseClause;
@@ -59,11 +60,7 @@ public class CPPASTIfStatement extends ASTNode implements ICPPASTIfStatement, IA
copy.setConditionExpression(condition == null ? null : condition.copy(style));
copy.setThenClause(thenClause == null ? null : thenClause.copy(style));
copy.setElseClause(elseClause == null ? null : elseClause.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -135,6 +132,9 @@ public class CPPASTIfStatement extends ASTNode implements ICPPASTIfStatement, IA
default: break;
}
}
+
+ if (!((CPPASTIfStatement) stmt).acceptByAttributes(action)) return false;
+
IASTNode child = stmt.getConditionExpression();
if (child != null && !child.accept(action))
return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java
index 43dacc1c1f8..f3b745d962a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTLabelStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -15,13 +16,13 @@ import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
-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 CPPASTLabelStatement extends ASTNode
+public class CPPASTLabelStatement extends ASTAttributeOwner
implements IASTLabelStatement, IASTAmbiguityParent {
private IASTName name;
private IASTStatement nestedStatement;
@@ -44,11 +45,7 @@ public class CPPASTLabelStatement extends ASTNode
CPPASTLabelStatement copy = new CPPASTLabelStatement();
copy.setName(name == null ? null : name.copy(style));
copy.setNestedStatement(nestedStatement == null ? null : nestedStatement.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -76,6 +73,7 @@ public class CPPASTLabelStatement extends ASTNode
}
}
+ if (!acceptByAttributes(action)) return false;
if (name != null && !name.accept(action)) return false;
if (nestedStatement != null && !nestedStatement.accept(action)) return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java
index c0799c22eae..94c20e2aa85 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNullStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,18 +7,18 @@
*
* Contributors:
* IBM - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
-public class CPPASTNullStatement extends ASTNode implements IASTNullStatement {
-
+public class CPPASTNullStatement extends ASTAttributeOwner implements IASTNullStatement {
@Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitStatements) {
@@ -28,6 +28,9 @@ public class CPPASTNullStatement extends ASTNode implements IASTNullStatement {
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
+
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@@ -46,10 +49,6 @@ public class CPPASTNullStatement extends ASTNode implements IASTNullStatement {
@Override
public CPPASTNullStatement copy(CopyStyle style) {
CPPASTNullStatement copy = new CPPASTNullStatement();
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java
index 2b8ae69a6e8..490da713166 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java
@@ -36,11 +36,7 @@ public class CPPASTProblemDeclaration extends CPPASTProblemOwner implements IAST
@Override
public CPPASTProblemDeclaration copy(CopyStyle style) {
CPPASTProblemDeclaration copy = new CPPASTProblemDeclaration();
- copyBaseProblem(copy, style);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java
index e2da6a8cc7a..21cab37cbf6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java
@@ -36,11 +36,7 @@ public class CPPASTProblemExpression extends CPPASTProblemOwner implements IASTP
@Override
public CPPASTProblemExpression copy(CopyStyle style) {
CPPASTProblemExpression copy = new CPPASTProblemExpression();
- copyBaseProblem(copy, style);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java
index 40e7eae4cdf..6844ef473e0 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -29,16 +30,16 @@ abstract class CPPASTProblemOwner extends ASTNode implements IASTProblemHolder {
setProblem(problem);
}
- protected void copyBaseProblem(CPPASTProblemOwner copy, CopyStyle style) {
+ protected T copy(T copy, CopyStyle style) {
copy.setProblem(problem == null ? null : problem.copy(style));
- copy.setOffsetAndLength(this);
+ return super.copy(copy, style);
}
@Override
public IASTProblem getProblem() {
return problem;
}
-
+
@Override
public void setProblem(IASTProblem p) {
assertNotFrozen();
@@ -48,8 +49,8 @@ abstract class CPPASTProblemOwner extends ASTNode implements IASTProblemHolder {
p.setPropertyInParent(PROBLEM);
}
}
-
- @Override
+
+ @Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitProblems) {
switch (action.visit(getProblem())) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java
index 55ffa3cc9ea..09cd642a0f1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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,10 +8,12 @@
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
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.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
@@ -36,11 +38,7 @@ public class CPPASTProblemStatement extends CPPASTProblemOwner implements IASTPr
@Override
public CPPASTProblemStatement copy(CopyStyle style) {
CPPASTProblemStatement copy = new CPPASTProblemStatement();
- copyBaseProblem(copy, style);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -62,4 +60,15 @@ public class CPPASTProblemStatement extends CPPASTProblemOwner implements IASTPr
}
return true;
}
+
+ @Override
+ public IASTAttribute[] getAttributes() {
+ return IASTAttribute.EMPTY_ATTRIBUTE_ARRAY;
+ }
+
+ @Override
+ public void addAttribute(IASTAttribute attribute) {
+ assertNotFrozen();
+ // Ignore.
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java
index 20901b448f1..4124bb9e1e5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java
@@ -37,11 +37,7 @@ public class CPPASTProblemTypeId extends CPPASTProblemOwner implements IASTProbl
@Override
public CPPASTProblemTypeId copy(CopyStyle style) {
CPPASTProblemTypeId copy = new CPPASTProblemTypeId();
- copyBaseProblem(copy, style);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java
index 7f41c1bde16..26c943b68c5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTRangeBasedForStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Wind River Systems, Inc. and others.
+ * Copyright (c) 2010, 2012 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - Initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -25,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
+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.IASTAmbiguityParent;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
@@ -34,7 +36,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
/**
* Range based for loop in c++.
*/
-public class CPPASTRangeBasedForStatement extends ASTNode implements ICPPASTRangeBasedForStatement, IASTAmbiguityParent {
+public class CPPASTRangeBasedForStatement extends ASTAttributeOwner
+ implements ICPPASTRangeBasedForStatement, IASTAmbiguityParent {
private IScope fScope;
private IASTDeclaration fDeclaration;
private IASTInitializerClause fInitClause;
@@ -55,11 +58,7 @@ public class CPPASTRangeBasedForStatement extends ASTNode implements ICPPASTRang
copy.setDeclaration(fDeclaration == null ? null : fDeclaration.copy(style));
copy.setInitializerClause(fInitClause == null ? null : fInitClause.copy(style));
copy.setBody(fBody == null ? null : fBody.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -183,6 +182,8 @@ public class CPPASTRangeBasedForStatement extends ASTNode implements ICPPASTRang
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
if (fDeclaration != null && !fDeclaration.accept(action))
return false;
if (fInitClause != null && !fInitClause.accept(action))
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java
index 2de2b71d577..bd02b23e235 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTReturnStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -16,10 +17,10 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
-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;
-public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatement, IASTAmbiguityParent {
+public class CPPASTReturnStatement extends ASTAttributeOwner implements IASTReturnStatement, IASTAmbiguityParent {
private IASTInitializerClause retValue;
public CPPASTReturnStatement() {
@@ -38,11 +39,7 @@ public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatemen
public CPPASTReturnStatement copy(CopyStyle style) {
CPPASTReturnStatement copy =
new CPPASTReturnStatement(retValue == null ? null : retValue.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -83,6 +80,7 @@ public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatemen
}
}
+ if (!acceptByAttributes(action)) return false;
if (retValue != null && !retValue.accept(action)) return false;
if (action.shouldVisitStatements) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java
index af786b347d4..c3beeb30a43 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -17,13 +18,17 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.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.IASTAmbiguityParent;
/**
* @author jcamelon
*/
-public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclaration, IASTAmbiguityParent {
+public class CPPASTSimpleDeclaration extends ASTAttributeOwner
+ implements IASTSimpleDeclaration, IASTAmbiguityParent {
+ private IASTDeclarator[] declarators;
+ private int declaratorsPos = -1;
+ private IASTDeclSpecifier declSpecifier;
public CPPASTSimpleDeclaration() {
}
@@ -44,11 +49,7 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
for (IASTDeclarator declarator : getDeclarators()) {
copy.addDeclarator(declarator == null ? null : declarator.copy(style));
}
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -73,10 +74,6 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
d.setPropertyInParent(DECLARATOR);
}
}
-
- private IASTDeclarator[] declarators;
- private int declaratorsPos = -1;
- private IASTDeclSpecifier declSpecifier;
/**
* @param declSpecifier The declSpecifier to set.
@@ -101,6 +98,7 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
}
}
+ if (!acceptByAttributes(action)) return false;
if (declSpecifier != null && !declSpecifier.accept(action)) return false;
IASTDeclarator[] dtors = getDeclarators();
for (int i = 0; i < dtors.length; i++) {
@@ -123,7 +121,7 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
IASTDeclarator[] declarators = getDeclarators();
for (int i = 0; i < declarators.length; i++) {
if (declarators[i] == child) {
- declarators[i] = (IASTDeclarator)other;
+ declarators[i] = (IASTDeclarator) other;
other.setParent(child.getParent());
other.setPropertyInParent(child.getPropertyInParent());
break;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java
index 50b537e066f..bf739c2875b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSwitchStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -18,13 +19,13 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSwitchStatement;
-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;
/**
* Switch statement in C++.
*/
-public class CPPASTSwitchStatement extends ASTNode
+public class CPPASTSwitchStatement extends ASTAttributeOwner
implements ICPPASTSwitchStatement, IASTAmbiguityParent {
private IScope scope;
private IASTExpression controllerExpression;
@@ -57,11 +58,7 @@ public class CPPASTSwitchStatement extends ASTNode
copy.setControllerExpression(controllerExpression == null ?
null : controllerExpression.copy(style));
copy.setBody(body == null ? null : body.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -105,6 +102,7 @@ public class CPPASTSwitchStatement extends ASTNode
}
}
+ if (!acceptByAttributes(action)) return false;
if (controllerExpression != null && !controllerExpression.accept(action)) return false;
if (controllerDeclaration != null && !controllerDeclaration.accept(action)) return false;
if (body != null && !body.accept(action)) return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java
index 354787dbcb7..3dc2620a117 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTryBlockStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -17,13 +18,13 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement;
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.IASTAmbiguityParent;
/**
* @author jcamelon
*/
-public class CPPASTTryBlockStatement extends ASTNode implements ICPPASTTryBlockStatement, IASTAmbiguityParent {
+public class CPPASTTryBlockStatement extends ASTAttributeOwner implements ICPPASTTryBlockStatement, IASTAmbiguityParent {
private ICPPASTCatchHandler[] catchHandlers;
private int catchHandlersPos= -1;
private IASTStatement tryBody;
@@ -46,11 +47,7 @@ public class CPPASTTryBlockStatement extends ASTNode implements ICPPASTTryBlockS
new CPPASTTryBlockStatement(tryBody == null ? null : tryBody.copy(style));
for (ICPPASTCatchHandler handler : getCatchHandlers())
copy.addCatchHandler(handler == null ? null : handler.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -95,6 +92,8 @@ public class CPPASTTryBlockStatement extends ASTNode implements ICPPASTTryBlockS
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
if (tryBody != null && !tryBody.accept(action))
return false;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java
index 33063c203f9..ba189cbbd0f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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)
* Markus Schorn (Wind River Systems)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -21,10 +22,10 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICPPASTCompletionContext;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
-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.cpp.semantics.CPPSemantics;
-public class CPPASTUsingDeclaration extends ASTNode
+public class CPPASTUsingDeclaration extends ASTAttributeOwner
implements ICPPASTUsingDeclaration, ICPPASTCompletionContext {
private boolean typeName;
private IASTName name;
@@ -46,11 +47,7 @@ public class CPPASTUsingDeclaration extends ASTNode
CPPASTUsingDeclaration copy =
new CPPASTUsingDeclaration(name == null ? null : name.copy(style));
copy.typeName = typeName;
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -89,6 +86,7 @@ public class CPPASTUsingDeclaration extends ASTNode
}
}
+ if (!acceptByAttributes(action)) return false;
if (name != null && !name.accept(action)) return false;
if (action.shouldVisitDeclarations) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java
index d4a60eb0b5e..07f2eb960df 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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
* Bryan Wilkinson (QNX)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -20,10 +21,10 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICPPASTCompletionContext;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
-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.cpp.semantics.CPPSemantics;
-public class CPPASTUsingDirective extends ASTNode
+public class CPPASTUsingDirective extends ASTAttributeOwner
implements ICPPASTUsingDirective, ICPPASTCompletionContext {
private IASTName name;
@@ -42,11 +43,7 @@ public class CPPASTUsingDirective extends ASTNode
@Override
public CPPASTUsingDirective copy(CopyStyle style) {
CPPASTUsingDirective copy = new CPPASTUsingDirective(name == null ? null : name.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -74,6 +71,7 @@ public class CPPASTUsingDirective extends ASTNode
}
}
+ if (!acceptByAttributes(action)) return false;
if (name != null && !name.accept(action)) return false;
if (action.shouldVisitDeclarations) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java
index 44c789f50ba..0150824163b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and 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)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -18,13 +19,13 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
-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;
/**
* While statement in C++.
*/
-public class CPPASTWhileStatement extends ASTNode
+public class CPPASTWhileStatement extends ASTAttributeOwner
implements ICPPASTWhileStatement, IASTAmbiguityParent {
private IASTExpression condition;
private IASTDeclaration condition2;
@@ -55,11 +56,7 @@ public class CPPASTWhileStatement extends ASTNode
copy.setConditionDeclaration(condition2 == null ? null : condition2.copy(style));
copy.setCondition(condition == null ? null : condition.copy(style));
copy.setBody(body == null ? null : body.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -118,6 +115,8 @@ public class CPPASTWhileStatement extends ASTNode
default: break;
}
}
+
+ if (!acceptByAttributes(action)) return false;
if (condition != null && !condition.accept(action))
return false;
if (condition2 != null && !condition2.accept(action))
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
index e7a8561d509..575873a4e67 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 IBM Corporation and others.
+ * Copyright (c) 2006, 2012 IBM Corporation and others.
* All rights reserved. This program and 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.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.Operator;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
@@ -46,6 +47,8 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTToken;
+import org.eclipse.cdt.core.dom.ast.IASTTokenList;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArrayDeclarator;
@@ -110,6 +113,8 @@ 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.gnu.IGNUASTCompoundStatementExpression;
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.NodeFactory;
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
@@ -149,6 +154,11 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
return new CPPASTASMDeclaration(assembly);
}
+ @Override
+ public IASTAttribute newAttribute(char[] name, IASTToken argumentClause) {
+ return new CPPASTAttribute(name, argumentClause);
+ }
+
@Override
public ICPPASTBaseSpecifier newBaseSpecifier(IASTName name, int visibility, boolean isVirtual) {
return new CPPASTBaseSpecifier(name, visibility, isVirtual);
@@ -643,6 +653,16 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
return new CPPASTTemplateSpecialization(declaration);
}
+ @Override
+ public IASTToken newToken(int tokenType, char[] tokenImage) {
+ return new ASTToken(tokenType, tokenImage);
+ }
+
+ @Override
+ public IASTTokenList newTokenList() {
+ return new ASTTokenList();
+ }
+
@Override
public ICPPASTTranslationUnit newTranslationUnit() {
return newTranslationUnit(null);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index 9459ab9e636..cf03470c049 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -12,6 +12,7 @@
* Ed Swartz (Nokia)
* Mike Kucera (IBM)
* Andrew Ferguson (Symbian)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -24,6 +25,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.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTBinaryTypeIdExpression.Operator;
@@ -131,6 +133,7 @@ import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
+import org.eclipse.cdt.core.parser.util.CollectionUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
@@ -1844,6 +1847,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
protected IASTDeclaration usingClause() throws EndOfFileException, BacktrackException {
final int offset= consume().getOffset();
+ List attributes = null;
if (LT(1) == IToken.t_namespace) {
// using-directive
int endOffset = consume().getEndOffset();
@@ -1858,7 +1862,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
throwBacktrack(offset, endOffset - offset);
}
- __attribute__();
+ attributes = __attribute__();
switch (LT(1)) {
case IToken.tSEMI:
@@ -1870,6 +1874,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
ICPPASTUsingDirective astUD = nodeFactory.newUsingDirective(name);
+ if (attributes != null) {
+ for (IASTAttribute attribute : attributes) {
+ astUD.addAttribute(attribute);
+ }
+ }
((ASTNode) astUD).setOffsetAndLength(offset, endOffset - offset);
return astUD;
}
@@ -3530,7 +3539,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
*/
protected IASTDeclarator declarator(DtorStrategy strategy, DeclarationOptions option)
throws EndOfFileException, BacktrackException {
-
final int startingOffset = LA(1).getOffset();
int endOffset = startingOffset;
@@ -3713,7 +3721,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
}
-
IASTPointer pointer;
if (name != null) {
pointer= nodeFactory.newPointerToMember(name);
@@ -3736,6 +3743,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
DtorStrategy strategy, DeclarationOptions option)
throws EndOfFileException, BacktrackException {
ICPPASTDeclarator result= null;
+ List attributes = null;
loop: while(true) {
final int lt1= LTcatchEOF(1);
switch (lt1) {
@@ -3762,18 +3770,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
case IGCCToken.t__attribute__: // if __attribute__ is after a declarator
if (!supportAttributeSpecifiers)
throwBacktrack(LA(1));
- __attribute_decl_seq(true, supportDeclspecSpecifiers);
+ attributes = CollectionUtils.merge(attributes,
+ __attribute_decl_seq(true, supportDeclspecSpecifiers));
break;
case IGCCToken.t__declspec:
if (!supportDeclspecSpecifiers)
throwBacktrack(LA(1));
- __attribute_decl_seq(supportAttributeSpecifiers, true);
+ attributes = CollectionUtils.merge(attributes,
+ __attribute_decl_seq(supportAttributeSpecifiers, true));
break;
default:
break loop;
}
}
- __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
+ attributes = CollectionUtils.merge(attributes,
+ __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers));
if (result == null) {
result= nodeFactory.newDeclarator(null);
@@ -3786,7 +3797,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
consume();
endOffset= asmExpression(null).getEndOffset();
- __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
+ attributes = CollectionUtils.merge(attributes,
+ __attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers));
}
if (pointerOps != null) {
@@ -3795,6 +3807,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
}
+ if (attributes != null) {
+ for (IASTAttribute attribute : attributes) {
+ result.addAttribute(attribute);
+ }
+ }
+
((ASTNode) result).setOffsetAndLength(startingOffset, endOffset - startingOffset);
return result;
}
@@ -3858,7 +3876,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
// Consume any number of __attribute__ tokens after the parameters
- __attribute_decl_seq(supportAttributeSpecifiers, false);
+ List attributes = __attribute_decl_seq(supportAttributeSpecifiers, false);
// cv-qualifiers
if (isLambdaDeclarator) {
@@ -3922,7 +3940,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
// more __attribute__ after throws
- __attribute_decl_seq(supportAttributeSpecifiers, false);
+ attributes = CollectionUtils.merge(attributes,
+ __attribute_decl_seq(supportAttributeSpecifiers, false));
}
if (LT(1) == IToken.tARROW) {
@@ -3932,6 +3951,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
endOffset= calculateEndOffset(typeId);
}
+ if (attributes != null) {
+ for (IASTAttribute attribute : attributes) {
+ fc.addAttribute(attribute);
+ }
+ }
+
return setRange(fc, startOffset, endOffset);
}
@@ -4006,10 +4031,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
// class name
IASTName name = null;
- if (LT(1) == IToken.tIDENTIFIER)
+ if (LT(1) == IToken.tIDENTIFIER) {
name = qualifiedName();
- else
+ } else {
name = nodeFactory.newName();
+ }
// if __attribute__ or __declspec occurs after struct/union/class identifier and before the { or ;
__attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
index 68aee31d1ff..33c65cbd8fa 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
@@ -33,6 +33,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.IASTAttribute;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
@@ -156,6 +157,7 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttribute;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
@@ -1779,6 +1781,7 @@ public class CPPVisitor extends ASTQueries {
if (name instanceof ICPPASTConversionName) {
returnType = createType(((ICPPASTConversionName) name).getTypeId());
} else {
+ returnType = applyAttributes(returnType, fnDtor);
returnType = getPointerTypes(returnType, fnDtor);
}
@@ -1843,9 +1846,44 @@ public class CPPVisitor extends ASTQueries {
return type;
}
+ private static IType applyAttributes(IType type, IASTDeclarator declarator) {
+ if (type instanceof IBasicType) {
+ IBasicType basicType = (IBasicType) type;
+ if (basicType.getKind() == IBasicType.Kind.eInt) {
+ IASTAttribute[] attributes = declarator.getAttributes();
+ for (IASTAttribute attribute : attributes) {
+ char[] name = attribute.getName();
+ if (CharArrayUtils.equals(name, "__mode__") || CharArrayUtils.equals(name, "mode")) { //$NON-NLS-1$ //$NON-NLS-2$
+ char[] mode = ASTAttribute.getSimpleArgument(attribute);
+ if (CharArrayUtils.equals(mode, "__QI__") || CharArrayUtils.equals(mode, "QI")) { //$NON-NLS-1$ //$NON-NLS-2$
+ type = new CPPBasicType(IBasicType.Kind.eChar,
+ basicType.isUnsigned() ? IBasicType.IS_UNSIGNED : IBasicType.IS_SIGNED);
+ } else if (CharArrayUtils.equals(mode, "__HI__") || CharArrayUtils.equals(mode, "HI")) { //$NON-NLS-1$ //$NON-NLS-2$
+ type = new CPPBasicType(IBasicType.Kind.eInt,
+ IBasicType.IS_SHORT | getSignModifiers(basicType));
+ } else if (CharArrayUtils.equals(mode, "__SI__") || CharArrayUtils.equals(mode, "SI")) { //$NON-NLS-1$ //$NON-NLS-2$
+ type = new CPPBasicType(IBasicType.Kind.eInt, getSignModifiers(basicType));
+ } else if (CharArrayUtils.equals(mode, "__DI__") || CharArrayUtils.equals(mode, "DI")) { //$NON-NLS-1$ //$NON-NLS-2$
+ type = new CPPBasicType(IBasicType.Kind.eInt,
+ IBasicType.IS_LONG_LONG | getSignModifiers(basicType));
+ } else if (CharArrayUtils.equals(mode, "__word__") || CharArrayUtils.equals(mode, "word")) { //$NON-NLS-1$ //$NON-NLS-2$
+ type = new CPPBasicType(IBasicType.Kind.eInt,
+ IBasicType.IS_LONG | getSignModifiers(basicType));
+ }
+ }
+ }
+ }
+ }
+ return type;
+ }
+
+ private static int getSignModifiers(IBasicType type) {
+ return type.getModifiers() & (IBasicType.IS_SIGNED | IBasicType.IS_UNSIGNED);
+ }
+
private static IType getArrayTypes(IType type, IASTArrayDeclarator declarator) {
IASTArrayModifier[] mods = declarator.getArrayModifiers();
- for (int i = mods.length -1; i >= 0; i--) {
+ for (int i = mods.length - 1; i >= 0; i--) {
IASTArrayModifier mod = mods[i];
type = new CPPArrayType(type, mod.getConstantExpression());
}
@@ -2084,6 +2122,7 @@ public class CPPVisitor extends ASTQueries {
return createType(baseType, (ICPPASTFunctionDeclarator) declarator);
IType type = baseType;
+ type = applyAttributes(type, declarator);
type = getPointerTypes(type, declarator);
if (declarator instanceof IASTArrayDeclarator)
type = getArrayTypes(type, (IASTArrayDeclarator) declarator);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java
index 72755f3508b..14e682f5d15 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/Token.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Markus Schorn - initial API and implementation
+ * Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner;
@@ -48,13 +48,14 @@ public class Token implements IToken, Cloneable {
@Override
final public int getLength() {
- return fEndOffset - fOffset;
+ return fEndOffset-fOffset;
}
@Override
final public IToken getNext() {
return fNextToken;
}
+
@Override
final public void setType(int kind) {
@@ -72,8 +73,8 @@ public class Token implements IToken, Cloneable {
}
public void shiftOffset(int shift) {
- fOffset += shift;
- fEndOffset += shift;
+ fOffset+= shift;
+ fEndOffset+= shift;
}
@Override
@@ -97,9 +98,9 @@ public class Token implements IToken, Cloneable {
}
@Override
- final public Object clone() {
+ final public Token clone() {
try {
- return super.clone();
+ return (Token) super.clone();
} catch (CloneNotSupportedException e) {
return null;
}
diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTForallStatement.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTForallStatement.java
index 9b85e452595..5987c3a5ec4 100644
--- a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTForallStatement.java
+++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTForallStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 IBM Corporation and others.
+ * Copyright (c) 2006, 2012 IBM Corporation and others.
* All rights reserved. This program and 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 Corporation - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.upc.ast;
@@ -39,11 +40,7 @@ public class UPCASTForallStatement extends CASTForStatement implements IUPCASTFo
public UPCASTForallStatement copy(CopyStyle style) {
UPCASTForallStatement copy = new UPCASTForallStatement();
copy.setAffinityExpression(affinity == null ? null : affinity.copy(style));
- copyForStatement(copy, style);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -83,6 +80,8 @@ public class UPCASTForallStatement extends CASTForStatement implements IUPCASTFo
}
}
+ if (!acceptByAttributes(visitor)) return false;
+
IASTStatement initializer = super.getInitializerStatement();
if (initializer != null && !initializer.accept(visitor)) return false;
diff --git a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTSynchronizationStatement.java b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTSynchronizationStatement.java
index 9058c8aa904..b28385766a3 100644
--- a/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTSynchronizationStatement.java
+++ b/upc/org.eclipse.cdt.core.parser.upc/src/org/eclipse/cdt/internal/core/dom/parser/upc/ast/UPCASTSynchronizationStatement.java
@@ -1,22 +1,23 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2006, 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
- * IBM Corporation - initial API and implementation
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.upc.ast;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.upc.ast.IUPCASTSynchronizationStatement;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
@SuppressWarnings("restriction")
-public class UPCASTSynchronizationStatement extends ASTNode implements IUPCASTSynchronizationStatement {
+public class UPCASTSynchronizationStatement extends ASTAttributeOwner implements IUPCASTSynchronizationStatement {
private int statmentKind;
private IASTExpression barrierExpression;
@@ -38,11 +39,7 @@ public class UPCASTSynchronizationStatement extends ASTNode implements IUPCASTSy
UPCASTSynchronizationStatement copy = new UPCASTSynchronizationStatement();
copy.statmentKind = statmentKind;
copy.setBarrierExpression(barrierExpression == null ? null : barrierExpression.copy(style));
- copy.setOffsetAndLength(this);
- if (style == CopyStyle.withLocations) {
- copy.setCopyLocation(this);
- }
- return copy;
+ return copy(copy, style);
}
@Override
@@ -78,6 +75,7 @@ public class UPCASTSynchronizationStatement extends ASTNode implements IUPCASTSy
}
}
+ if (!acceptByAttributes(visitor)) return false;
if (barrierExpression != null && !barrierExpression.accept(visitor)) return false;
if (visitor.shouldVisitStatements) {