diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java index 1a88534c671..ef510a5ecb5 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java @@ -58,7 +58,6 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; import org.w3c.dom.Element; @@ -359,7 +358,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } isExecuted = true; - Job job = new Job(ManagedMakeMessages.getResourceString("AbstractBuiltinSpecsDetector.DiscoverBuiltInSettingsJobNam")) { //$NON-NLS-1$ + Job job = new Job(ManagedMakeMessages.getResourceString("AbstractBuiltinSpecsDetector.DiscoverBuiltInSettingsJobName")) { //$NON-NLS-1$ @Override protected IStatus run(IProgressMonitor monitor) { IStatus status; diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java index 546b2fef333..f73999e63a0 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java @@ -53,7 +53,6 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; * of methods that are working with their value. * * @author Anton Gorenkov - * */ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker { public static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization"; //$NON-NLS-1$ @@ -65,7 +64,6 @@ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker { } class OnEachClass extends ASTVisitor { - // NOTE: Classes can be nested and even can be declared in constructors of the other classes private final Stack< Set > constructorsStack = new Stack< Set >(); private boolean skipConstructorsWithFCalls = skipConstructorsWithFCalls(); @@ -133,21 +131,21 @@ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker { } // Bug 368420 - Skip constructor if pattern is *this = toBeCopied; - if(expression instanceof IASTBinaryExpression) { + if (expression instanceof IASTBinaryExpression) { IASTBinaryExpression binaryExpression = (IASTBinaryExpression) expression; - if(referencesThis(binaryExpression.getOperand1()) && binaryExpression.getOperand1().isLValue()) { + if (referencesThis(binaryExpression.getOperand1()) && binaryExpression.getOperand1().isLValue()) { skipCurrentConstructor = true; } } - if (skipCurrentConstructor) { + if (skipCurrentConstructor && !constructorsStack.empty()) { constructorsStack.peek().clear(); } return PROCESS_CONTINUE; } - /** Checks whether expression references this (directly, by pointer or by reference) - * + /** + * Checks whether expression references this (directly, by pointer or by reference) */ public boolean referencesThis(IASTNode expr) { if (expr instanceof IASTLiteralExpression) { @@ -224,7 +222,6 @@ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker { return null; } - } @Override @@ -236,5 +233,4 @@ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker { public boolean skipConstructorsWithFCalls() { return (Boolean) getPreference(getProblemById(ER_ID, getFile()), PARAM_SKIP); } - } diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java index b22e9f26902..9c34d78659a 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java @@ -48,6 +48,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.parser.util.AttributeUtil; /** * Checker looking for unused function or variable declarations. @@ -58,6 +59,7 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker { public static final String ER_UNUSED_STATIC_FUNCTION_ID = "org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem"; //$NON-NLS-1$ public static final String PARAM_MACRO_ID = "macro"; //$NON-NLS-1$ public static final String PARAM_EXCEPT_ARG_LIST = "exceptions"; //$NON-NLS-1$ + private static final String[] ATTRIBUTE_UNUSED = new String[] { "__unused__", "unused" }; //$NON-NLS-1$//$NON-NLS-2$ private Map externFunctionDeclarations = new HashMap(); private Map staticFunctionDeclarations = new HashMap(); @@ -130,6 +132,8 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker { IASTDeclarator[] declarators = simpleDeclaration.getDeclarators(); for (IASTDeclarator decl : declarators) { + if (AttributeUtil.hasAttribute(decl, ATTRIBUTE_UNUSED)) + continue; IASTName astName = decl.getName(); if (astName != null) { IBinding binding = astName.resolveBinding(); @@ -191,14 +195,15 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker { // definitions IASTFunctionDefinition definition = (IASTFunctionDefinition) element; - IASTName astName = definition.getDeclarator().getName(); + IASTFunctionDeclarator declarator = definition.getDeclarator(); + IASTName astName = declarator.getName(); if (astName != null) { IBinding binding = astName.resolveBinding(); - if (definition.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_static) { - if (!(astName instanceof ICPPASTQualifiedName)) { - staticFunctionDefinitions.put(binding, definition.getDeclarator()); - } + if (definition.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_static && + !(astName instanceof ICPPASTQualifiedName) && + !AttributeUtil.hasAttribute(declarator, ATTRIBUTE_UNUSED)) { + staticFunctionDefinitions.put(binding, declarator); } // externFunctionDeclarators filter out diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java index 4cd1d7964fa..7bb967ed071 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Andrew Gvozdev and others. + * Copyright (c) 2011, 2012 Andrew Gvozdev and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -307,4 +307,14 @@ public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase { checkNoErrors(); } + // static int v1 __attribute__((unused)); + // int f1() __attribute__((__unused__)); + // extern int f2() __attribute__((unused)); + // static void f3() __attribute__((unused)); + // static void f4() __attribute__((unused)); + // static void f4() __attribute__((unused)) {} + public void testAttributeUnused() throws IOException { + loadCodeAndRun(getAboveComment()); + checkNoErrors(); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java index 8305b215918..9f68e1f51ee 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java @@ -107,12 +107,14 @@ public class AST2BaseTest extends BaseTestCase { map.put("__GNUC__", "4"); map.put("__GNUC_MINOR__", "5"); map.put("__SIZEOF_INT__", "4"); + map.put("__SIZEOF_LONG__", "8"); return map; } private static Map getStdMap() { Map map= new HashMap(); map.put("__SIZEOF_INT__", "4"); + map.put("__SIZEOF_LONG__", "8"); return map; } 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..26a291eb121 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,37 @@ 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 test(signed char* i8, short* i16, int* i32, 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 - 1; i++) { + for (int j = 0; j < i ; j++) { + assertNotSame(calls[i] + " and " + calls[j] + " resolve to the same function", + functions[i], functions[j]); + } + } + assertSame(calls[calls.length - 1] + " and " + calls[calls.length - 2] + " resolve to different functions", + functions[calls.length - 1], functions[calls.length - 2]); + } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java index fdc381a323a..d868d66ef6a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation. + * Copyright (c) 2006, 2012 IBM Corporation. * All rights reserved. This program and 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.pdom.tests; @@ -74,6 +75,12 @@ public class CFunctionTests extends PDOMTestBase { assertTrue(((IFunction) bindings[0]).takesVarArgs()); } + public void testNoReturnCFunction() throws Exception { + IBinding[] bindings = findQualifiedName(pdom, "noReturnCFunction"); + assertEquals(1, bindings.length); + assertTrue(((IFunction) bindings[0]).isNoReturn()); + } + public void testKnRStyleFunctionWithProblemParameters() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "KnRfunctionWithProblemParameters"); assertEquals(1, bindings.length); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java index b834b1b654f..b01af4b8144 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 IBM Corporation. + * Copyright (c) 2006, 2012 IBM Corporation. * All rights reserved. This program and 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 Corporation - initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; @@ -38,7 +39,6 @@ import org.eclipse.core.runtime.CoreException; */ public class CPPFunctionTests extends PDOMTestBase { protected ICProject project; - protected PDOM pdom; public static Test suite() { @@ -137,13 +137,19 @@ public class CPPFunctionTests extends PDOMTestBase { assertEquals(1, bindings.length); assertTrue(((ICPPFunction) bindings[0]).isInline()); } - + public void testVarArgsCPPFunction() throws Exception { IBinding[] bindings = findQualifiedName(pdom, "varArgsCPPFunction"); assertEquals(1, bindings.length); assertTrue(((ICPPFunction) bindings[0]).takesVarArgs()); } - + + public void testNoReturnCPPFunction() throws Exception { + IBinding[] bindings = findQualifiedName(pdom, "noReturnCPPFunction"); + assertEquals(1, bindings.length); + assertTrue(((ICPPFunction) bindings[0]).isNoReturn()); + } + public void testForwardDeclarationType() throws Exception { assertType(pdom, "forwardDeclaration", ICPPFunction.class); } diff --git a/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.c b/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.c index 8ee78772ddc..763cd95e91f 100644 --- a/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.c +++ b/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.c @@ -6,6 +6,7 @@ void varArgsCFunction(int p1, ...); const void constCFunction(); volatile void volatileCFunction(); void storageClassCFunction(register int p1, int p2); +void noReturnCFunction() __attribute__((noreturn)); void voidCFunction(); int intCFunction(); diff --git a/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.cpp b/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.cpp index bd5ef3c900e..3f9d5b91370 100644 --- a/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.cpp +++ b/core/org.eclipse.cdt.core.tests/resources/pdomtests/functionTests/modifiers.cpp @@ -4,6 +4,7 @@ static int staticCPPFunction(double p1); extern float externCPPFunction(int p1); inline void inlineCPPFunction(long p1); void varArgsCPPFunction(int p1, ...); +void noReturnCPPFunction() __attribute__((noreturn)); void voidCPPFunction(); int intCPPFunction(); 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/IASTDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclaration.java index 8e3ea11db58..1f7f2077629 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclaration.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Doug Schaefer (IBM) - Initial API and implementation + * Doug Schaefer (IBM) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; 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 9b4b64a3acb..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,10 +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 { - /** - * Constant. - */ +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/IFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java index ebafdabd6f9..92c7b3260d9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IFunction.java @@ -7,6 +7,7 @@ * * Contributors: * Doug Schaefer (IBM) - Initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -51,4 +52,11 @@ public interface IFunction extends IBinding { * Returns {@code true} if this function takes variable arguments. */ public boolean takesVarArgs(); + + /** + * Returns {@code true} if this function never returns. Based on 'noreturn' attribute in + * the function declaration. + * @since 5.4 + */ + public boolean isNoReturn(); } 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/ICPPASTNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTNamespaceAlias.java index 146c9d79512..b4524045610 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTNamespaceAlias.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTNamespaceAlias.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM) - Initial API and implementation + * John Camelon (IBM) - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; @@ -16,14 +16,13 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNameOwner; /** - * This interface represents a namespace alias in C++. e.g. namespace ABC { int - * x; } namspace DEF = ABC; + * This interface represents a namespace alias in C++, + * e.g. namespace ABC { int* x; } namespace DEF = ABC; * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ public interface ICPPASTNamespaceAlias extends IASTDeclaration, IASTNameOwner { - /** * ALIAS_NAME represents the new namespace name being * introduced. @@ -68,7 +67,6 @@ public interface ICPPASTNamespaceAlias extends IASTDeclaration, IASTNameOwner { */ public void setMappingName(IASTName qualifiedName); - /** * @since 5.1 */ @@ -80,5 +78,4 @@ public interface ICPPASTNamespaceAlias extends IASTDeclaration, IASTNameOwner { */ @Override public ICPPASTNamespaceAlias copy(CopyStyle style); - } 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/AttributeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/AttributeUtil.java new file mode 100644 index 00000000000..53c22374665 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/AttributeUtil.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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.parser.util; + +import org.eclipse.cdt.core.dom.ast.IASTAttribute; +import org.eclipse.cdt.core.dom.ast.IASTAttributeOwner; +import org.eclipse.cdt.core.dom.ast.IASTToken; + +/** + * Collection of static methods for dealing with attributes. + * @see org.eclipse.cdt.core.dom.ast.IASTAttribute + * @see org.eclipse.cdt.core.dom.ast.IASTAttributeOwner + * @since 5.4 + */ +public class AttributeUtil { + private static final String[] ATTRIBUTE_NORETURN = new String[] { "__noreturn__", "noreturn" }; //$NON-NLS-1$//$NON-NLS-2$ + + // Not instantiatable. + private AttributeUtil() {} + + /** + * 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, ATTRIBUTE_NORETURN); + } + + /** + * 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(); + return argumentClause == null ? null : argumentClause.getTokenCharImage(); + } +} 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..7cb00efe5c2 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTAttribute.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * 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.IASTToken; + +/** + * Base class for C and C++ attributes. + */ +public abstract class ASTAttribute extends ASTNode implements IASTAttribute { + 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; + } +} 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/IASTAmbiguityParent.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguityParent.java index c855899649b..e59ae75df37 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguityParent.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguityParent.java @@ -6,15 +6,13 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; import org.eclipse.cdt.core.dom.ast.IASTNode; - public interface IASTAmbiguityParent { - public void replace( IASTNode child, IASTNode other ); - + public void replace(IASTNode child, IASTNode other); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousStatement.java index 11432af3b92..eaeb54a3b1c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IASTAmbiguousStatement.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser; @@ -14,9 +14,9 @@ import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.IASTStatement; public interface IASTAmbiguousStatement extends IASTStatement { + public static final ASTNodeProperty STATEMENT = new ASTNodeProperty("IASTAmbiguousStatement.STATEMENT - Ambiguous statement."); //$NON-NLS-1$ - public static final ASTNodeProperty STATEMENT = new ASTNodeProperty( "IASTAmbiguousStatement.STATEMENT - Ambiguous statement." ); //$NON-NLS-1$ - public void addStatement( IASTStatement s ); - public IASTStatement [] getStatements(); - + public void addStatement(IASTStatement s); + + public IASTStatement[] getStatements(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java index 6d05a310554..6b903cccd04 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/SizeofCalculator.java @@ -50,22 +50,22 @@ public class SizeofCalculator { private static final SizeAndAlignment SIZE_1 = new SizeAndAlignment(1, 1); - private final SizeAndAlignment size_2; - private final SizeAndAlignment size_4; - private final SizeAndAlignment size_8; - private final SizeAndAlignment sizeof_pointer; - private final SizeAndAlignment sizeof_int; - private final SizeAndAlignment sizeof_long; - private final SizeAndAlignment sizeof_long_long; - private final SizeAndAlignment sizeof_short; - private final SizeAndAlignment sizeof_bool; - private final SizeAndAlignment sizeof_wchar_t; - private final SizeAndAlignment sizeof_float; - private final SizeAndAlignment sizeof_complex_float; - private final SizeAndAlignment sizeof_double; - private final SizeAndAlignment sizeof_complex_double; - private final SizeAndAlignment sizeof_long_double; - private final SizeAndAlignment sizeof_complex_long_double; + public final SizeAndAlignment size_2; + public final SizeAndAlignment size_4; + public final SizeAndAlignment size_8; + public final SizeAndAlignment sizeof_pointer; + public final SizeAndAlignment sizeof_int; + public final SizeAndAlignment sizeof_long; + public final SizeAndAlignment sizeof_long_long; + public final SizeAndAlignment sizeof_short; + public final SizeAndAlignment sizeof_bool; + public final SizeAndAlignment sizeof_wchar_t; + public final SizeAndAlignment sizeof_float; + public final SizeAndAlignment sizeof_complex_float; + public final SizeAndAlignment sizeof_double; + public final SizeAndAlignment sizeof_complex_double; + public final SizeAndAlignment sizeof_long_double; + public final SizeAndAlignment sizeof_complex_long_double; public SizeofCalculator(IASTTranslationUnit ast) { int maxAlignment = 32; 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 c62e6eede27..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 @@ -6,11 +6,13 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - Initial API and implementation + * 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; @@ -31,7 +33,6 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; * @since 5.0.1 */ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements IASTAmbiguousSimpleDeclaration { - private IASTSimpleDeclaration fSimpleDecl; private IASTDeclSpecifier fAltDeclSpec; private IASTDeclarator fAltDtor; @@ -85,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 1c85de5bb5b..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,17 +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: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * 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; @@ -24,14 +26,13 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPASTInternalScope; public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbiguousStatement { - - private IASTStatement [] stmts = new IASTStatement[2]; - private int stmtsPos=-1; + private IASTStatement[] stmts = new IASTStatement[2]; + private int stmtsPos= -1; private IScope fScope; private IASTDeclaration fDeclaration; public CASTAmbiguousStatement(IASTStatement... statements) { - for(IASTStatement s : statements) + for (IASTStatement s : statements) addStatement(s); } @@ -44,7 +45,7 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi ((ICPPASTInternalScope) fScope).populateCache(); } } - + @Override protected void beforeAlternative(IASTNode alternative) { cleanupScope(); @@ -73,7 +74,7 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi public void addStatement(IASTStatement s) { assertNotFrozen(); if (s != null) { - stmts = ArrayUtil.appendAt( IASTStatement.class, stmts, ++stmtsPos, s ); + stmts = ArrayUtil.appendAt(IASTStatement.class, stmts, ++stmtsPos, s); s.setParent(this); s.setPropertyInParent(STATEMENT); } @@ -81,16 +82,25 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi @Override public IASTStatement[] getStatements() { - stmts = ArrayUtil.trimAt( IASTStatement.class, stmts, stmtsPos ); + stmts = ArrayUtil.trimAt(IASTStatement.class, stmts, stmtsPos); 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(); } - @Override public IASTStatement copy() { throw new UnsupportedOperationException(); @@ -100,5 +110,4 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi public IASTStatement copy(CopyStyle style) { throw new UnsupportedOperationException(); } - } 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 3aefeac8f18..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 @@ -6,35 +6,37 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) + * 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 ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (!acceptByAttributes(action)) return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } @@ -49,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 c18db597193..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 @@ -6,8 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) + * 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,17 +16,15 @@ 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() { } @@ -41,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 @@ -64,20 +59,20 @@ public class CASTCaseStatement extends ASTNode implements IASTCaseStatement, IAS } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( expression != null ) if( !expression.accept( action ) ) return false; - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (expression != null) if (!expression.accept(action)) return false; + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } @@ -86,10 +81,9 @@ public class CASTCaseStatement extends ASTNode implements IASTCaseStatement, IAS @Override public void replace(IASTNode child, IASTNode other) { - if( child == expression ) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (child == expression) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); expression = (IASTExpression) other; } } 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 8b8277b434d..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,44 +1,47 @@ /******************************************************************************* - * 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 - * Yuan Zhang / Beth Tibbitts (IBM Research) + * 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 ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + + if (!acceptByAttributes(action)) return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } return true; } - + @Override public CASTDefaultStatement copy() { return copy(CopyStyle.withoutLocations); @@ -47,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 03014d200eb..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 @@ -6,8 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) + * 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,18 +17,16 @@ 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; - public CASTDoStatement() { } @@ -46,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 @@ -68,13 +63,11 @@ public class CASTDoStatement extends ASTNode implements IASTDoStatement, IASTAmb } } - @Override public IASTExpression getCondition() { return condition; } - @Override public void setCondition(IASTExpression condition) { assertNotFrozen(); @@ -86,21 +79,24 @@ public class CASTDoStatement extends ASTNode implements IASTDoStatement, IASTAmb } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( body != null ) if( !body.accept( action ) ) return false; - if( condition != null ) if( !condition.accept( action ) ) return false; - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + + if (!acceptByAttributes(action)) return false; + if (body != null && !body.accept(action)) return false; + if (condition != null && !condition.accept(action)) return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } return true; @@ -108,16 +104,14 @@ public class CASTDoStatement extends ASTNode implements IASTDoStatement, IASTAmb @Override public void replace(IASTNode child, IASTNode other) { - if( body == child ) - { - other.setPropertyInParent( body.getPropertyInParent() ); - other.setParent( body.getParent() ); + if (body == child) { + other.setPropertyInParent(body.getPropertyInParent()); + other.setParent(body.getParent()); body = (IASTStatement) other; } - if( child == condition ) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (child == condition) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); condition = (IASTExpression) other; } } 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 55e5daf039e..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,13 +1,14 @@ /******************************************************************************* - * 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 - * Yuan Zhang / Beth Tibbitts (IBM Research) + * 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,18 +16,16 @@ 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() { } @@ -43,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 @@ -69,29 +64,22 @@ public class CASTExpressionStatement extends ASTNode implements public boolean accept(ASTVisitor action) { if (action.shouldVisitStatements) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if (expression != null) - if (!expression.accept(action)) - return false; + + if (!acceptByAttributes(action)) return false; + if (expression != null && !expression.accept(action)) return false; if (action.shouldVisitStatements) { switch (action.leave(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - return true; } @@ -103,5 +91,4 @@ public class CASTExpressionStatement extends ASTNode implements expression = (IASTExpression) other; } } - } 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 0fb9f9aa28a..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 @@ -6,8 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) + * 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,19 +19,18 @@ 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 { - private IScope scope = null; - +public class CASTForStatement extends ASTAttributeOwner implements IASTForStatement, IASTAmbiguityParent { + private IScope scope; private IASTExpression condition; private IASTExpression iterationExpression; - private IASTStatement body, init; - + private IASTStatement body; + private IASTStatement init; public CASTForStatement() { } @@ -51,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.setIterationExpression(iterationExpression == null ? + null : iterationExpression.copy(style)); copy.setBody(body == null ? null : body.copy(style)); - copy.setOffsetAndLength(this); + return super.copy(copy, style); } @Override @@ -128,62 +124,58 @@ public class CASTForStatement extends ASTNode implements IASTForStatement, IASTA @Override public IScope getScope() { - if( scope == null ) - scope = new CScope( this, EScopeKind.eLocal); + if (scope == null) + scope = new CScope(this, EScopeKind.eLocal); return scope; } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( init != null ) if( !init.accept( action ) ) return false; - if( condition != null ) if( !condition.accept( action ) ) return false; - if( iterationExpression != null ) if( !iterationExpression.accept( action ) ) return false; - if( body != null ) if( !body.accept( action ) ) return false; - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - 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; + if (body != null && !body.accept(action)) return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - return true; } @Override public void replace(IASTNode child, IASTNode other) { - if( body == child ) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (body == child) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); body = (IASTStatement) other; } - if( child == init ) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (child == init) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); init = (IASTStatement) other; } - if( child == iterationExpression) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (child == iterationExpression) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); iterationExpression = (IASTExpression) other; } - if( child == condition) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (child == condition) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); condition = (IASTExpression) other; } - } } \ No newline at end of file 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 a9b0317631d..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 @@ -6,21 +6,21 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) + * 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() { @@ -38,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 @@ -51,31 +47,33 @@ public class CASTGotoStatement extends ASTNode implements IASTGotoStatement { } @Override - public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { - name.setParent(this); - name.setPropertyInParent(NAME); - } + public void setName(IASTName name) { + assertNotFrozen(); + this.name = name; + if (name != null) { + name.setParent(this); + name.setPropertyInParent(NAME); + } } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( name != null ) if( !name.accept( action ) ) return false; - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (!acceptByAttributes(action)) return false; + if (name != null && !name.accept(action)) return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } return true; @@ -83,7 +81,7 @@ public class CASTGotoStatement extends ASTNode implements IASTGotoStatement { @Override public int getRoleForName(IASTName n) { - if( n == name ) return r_reference; + if (n == name) return r_reference; return r_unclear; } } 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 5c07fd3cd93..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,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: - * John Camelon (IBM Rational Software) - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) - * Markus Schorn (Wind River Systems) + * 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,19 +18,16 @@ 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; - - public CASTIfStatement() { } @@ -39,7 +37,6 @@ public class CASTIfStatement extends ASTNode implements IASTIfStatement, IASTAmb setThenClause(thenClause); } - public CASTIfStatement(IASTExpression condition, IASTStatement thenClause, IASTStatement elseClause) { this(condition, thenClause); setElseClause(elseClause); @@ -56,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 @@ -121,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; @@ -165,22 +161,19 @@ public class CASTIfStatement extends ASTNode implements IASTIfStatement, IASTAmb @Override public void replace(IASTNode child, IASTNode other) { - if( thenClause == child ) - { - other.setParent( child.getParent() ); - other.setPropertyInParent( child.getPropertyInParent() ); + if (thenClause == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); thenClause = (IASTStatement) other; } - if( elseClause == child ) - { - other.setParent( child.getParent() ); - other.setPropertyInParent( child.getPropertyInParent() ); + if (elseClause == child) { + other.setParent(child.getParent()); + other.setPropertyInParent(child.getPropertyInParent()); elseClause = (IASTStatement) other; } - if( child == condition ) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (child == condition) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); condition = (IASTExpression) other; } } 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 @@ -51,17 +50,17 @@ abstract class CASTProblemOwner extends ASTNode implements IASTProblemHolder { } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitProblems ){ - switch( action.visit( getProblem() ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action){ + if (action.shouldVisitProblems) { + switch (action.visit(getProblem())) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } - switch( action.leave( getProblem() ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + switch (action.leave(getProblem())) { + 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/c/CASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java index 93183e88ae0..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 @@ -6,13 +6,15 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) - * Markus Schorn (Wind River Systems) + * 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,30 +38,39 @@ 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 - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } + super.accept(action); // visits the problem - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } 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 49ed5ec00fc..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,13 +1,14 @@ /******************************************************************************* - * 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 - * Yuan Zhang / Beth Tibbitts (IBM Research) + * 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,15 +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.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 implements - IASTSwitchStatement, IASTAmbiguityParent { - +public class CASTSwitchStatement extends ASTAttributeOwner + implements IASTSwitchStatement, IASTAmbiguityParent { private IASTExpression controller; private IASTStatement body; @@ -46,11 +46,7 @@ public class CASTSwitchStatement extends ASTNode implements 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 @@ -84,22 +80,24 @@ public class CASTSwitchStatement extends ASTNode implements } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( controller != null ) if( !controller.accept( action ) ) return false; - if( body != null ) if( !body.accept( action ) ) return false; - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (!acceptByAttributes(action)) return false; + if (controller != null && !controller.accept(action)) return false; + if (body != null && !body.accept(action)) return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } return true; @@ -107,16 +105,14 @@ public class CASTSwitchStatement extends ASTNode implements @Override public void replace(IASTNode child, IASTNode other) { - if( body == child ) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (body == child) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); body = (IASTStatement) other; } - if( child == controller ) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (child == controller) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); controller = (IASTExpression) other; } } 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/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 564ab70660f..16362419e82 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.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 @@ -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; @@ -32,8 +33,10 @@ import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IType; 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.AttributeUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.Linkage; +import org.eclipse.cdt.internal.core.dom.parser.ASTAttribute; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.core.runtime.PlatformObject; @@ -48,7 +51,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu private static final int RESOLUTION_IN_PROGRESS = 1 << 1; private int bits = 0; - protected IFunctionType type = null; + protected IFunctionType type; public CFunction(IASTDeclarator declarator) { storeDeclarator(declarator); @@ -469,12 +472,12 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu } @Override - public IASTNode[] getDeclarations() { + public IASTDeclarator[] getDeclarations() { return declarators; } @Override - public IASTNode getDefinition() { + public IASTFunctionDeclarator getDefinition() { return definition; } @@ -482,4 +485,25 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu public IBinding getOwner() { return null; } + + @Override + public boolean isNoReturn() { + IASTFunctionDeclarator dtor = getPreferredDtor(); + return dtor != null && AttributeUtil.hasNoreturnAttribute(dtor); + } + + protected IASTFunctionDeclarator getPreferredDtor() { + IASTFunctionDeclarator dtor = getDefinition(); + if (dtor != null) + return dtor; + + IASTDeclarator[] dtors = getDeclarations(); + if (dtors != null) { + for (IASTDeclarator declarator : dtors) { + if (declarator instanceof IASTFunctionDeclarator) + return (IASTFunctionDeclarator) declarator; + } + } + return null; + } } 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..e0ed54d939b 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; @@ -88,6 +90,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.parser.util.AttributeUtil; import org.eclipse.cdt.core.parser.util.CharArraySet; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.IContentAssistMatcher; @@ -98,15 +101,13 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; 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 +444,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 +1254,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 +1265,49 @@ 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 = AttributeUtil.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$ + SizeofCalculator sizeofs = new SizeofCalculator(declarator.getTranslationUnit()); + int modifier; + if (sizeofs.sizeof_long != null && sizeofs.sizeof_int != null && + sizeofs.sizeof_long.size == 2 * sizeofs.sizeof_int.size) { + modifier = IBasicType.IS_LONG; + } else { + modifier = IBasicType.IS_LONG_LONG; + } + type = new CBasicType(IBasicType.Kind.eInt, + modifier | 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 483a0652c50..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,16 +1,18 @@ /******************************************************************************* - * 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 * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - Initial API and implementation + * 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; @@ -33,7 +35,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; * }; */ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements IASTAmbiguousSimpleDeclaration { - private IASTSimpleDeclaration fSimpleDecl; private IASTDeclSpecifier fAltDeclSpec; private IASTDeclarator fAltDtor; @@ -55,7 +56,7 @@ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implement @Override public IASTNode[] getNodes() { - return new IASTNode[] {fSimpleDecl, fAltDeclSpec, fAltDtor}; + return new IASTNode[] { fSimpleDecl, fAltDeclSpec, fAltDtor }; } @Override @@ -97,7 +98,6 @@ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implement owner.replace(nodeToReplace, fSimpleDecl); IASTDeclarator dtor= fSimpleDecl.getDeclarators()[0]; dtor.accept(resolver); - // find nested names final NameCollector nameCollector= new NameCollector(); @@ -129,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 ab68e647d17..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,17 +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: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * 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; @@ -23,16 +25,14 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; -public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements - IASTAmbiguousStatement { - - private IASTStatement [] stmts = new IASTStatement[2]; - private int stmtsPos=-1; +public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbiguousStatement { + private IASTStatement[] stmts = new IASTStatement[2]; + private int stmtsPos= -1; private IScope fScope; private IASTDeclaration fDeclaration; public CPPASTAmbiguousStatement(IASTStatement... statements) { - for(IASTStatement s : statements) + for (IASTStatement s : statements) addStatement(s); } @@ -84,7 +84,7 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements public void addStatement(IASTStatement s) { assertNotFrozen(); if (s != null) { - stmts = ArrayUtil.appendAt( IASTStatement.class, stmts, ++stmtsPos, s ); + stmts = ArrayUtil.appendAt(IASTStatement.class, stmts, ++stmtsPos, s); s.setParent(this); s.setPropertyInParent(STATEMENT); } @@ -92,7 +92,7 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements @Override public IASTStatement[] getStatements() { - stmts = ArrayUtil.trimAt( IASTStatement.class, stmts, stmtsPos ); + stmts = ArrayUtil.trimAt(IASTStatement.class, stmts, stmtsPos); return stmts; } @@ -100,4 +100,14 @@ public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements 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 f4decd6ba3c..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,12 +1,13 @@ /******************************************************************************* - * 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: - * IBM - Initial API and implementation + * 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.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() { @@ -38,13 +39,9 @@ public class CPPASTCaseStatement extends ASTNode implements IASTCaseStatement, I @Override 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; + CPPASTCaseStatement copy = + new CPPASTCaseStatement(expression == null ? null : expression.copy(style)); + return copy(copy, style); } @Override @@ -63,18 +60,20 @@ public class CPPASTCaseStatement extends ASTNode implements IASTCaseStatement, I } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch(action.visit(this)) { case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_SKIP : return true; default : break; } } - if( expression != null ) if( !expression.accept( action ) ) return false; + + if (!acceptByAttributes(action)) return false; + if (expression != null && !expression.accept(action)) return false; - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ + if (action.shouldVisitStatements) { + switch(action.leave(this)) { case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_SKIP : return true; default : break; @@ -85,12 +84,10 @@ public class CPPASTCaseStatement extends ASTNode implements IASTCaseStatement, I @Override public void replace(IASTNode child, IASTNode other) { - if( child == expression ) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (child == expression) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); 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 b9942a34ce4..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,12 +1,13 @@ /******************************************************************************* - * 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: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -15,18 +16,17 @@ 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; - public CPPASTDoStatement() { } @@ -45,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 @@ -83,21 +79,24 @@ public class CPPASTDoStatement extends ASTNode implements IASTDoStatement, IASTA } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( body != null ) if( !body.accept( action ) ) return false; - if( condition != null ) if( !condition.accept( action ) ) return false; - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + + if (!acceptByAttributes(action)) return false; + if (body != null && !body.accept(action)) return false; + if (condition != null && !condition.accept(action)) return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } return true; @@ -105,16 +104,14 @@ public class CPPASTDoStatement extends ASTNode implements IASTDoStatement, IASTA @Override public void replace(IASTNode child, IASTNode other) { - if( body == child ) - { - other.setPropertyInParent( body.getPropertyInParent() ); - other.setParent( body.getParent() ); + if (body == child) { + other.setPropertyInParent(body.getPropertyInParent()); + other.setParent(body.getParent()); body = (IASTStatement) other; } - if( child == condition ) - { - other.setPropertyInParent( child.getPropertyInParent() ); - other.setParent( child.getParent() ); + if (child == condition) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); condition = (IASTExpression) other; } } 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 538a1070851..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,15 +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() { @@ -41,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 @@ -72,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 e5fdfdfb9b1..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,27 +1,26 @@ /******************************************************************************* - * 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: - * IBM - Initial API and implementation + * 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() { } @@ -38,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 @@ -51,28 +46,30 @@ public class CPPASTGotoStatement extends ASTNode implements IASTGotoStatement { } @Override - public void setName(IASTName name) { - assertNotFrozen(); - this.name = name; - if (name != null) { - name.setParent(this); - name.setPropertyInParent(NAME); - } + public void setName(IASTName name) { + assertNotFrozen(); + this.name = name; + if (name != null) { + name.setParent(this); + name.setPropertyInParent(NAME); + } } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_SKIP : return true; default : break; } } - if( name != null ) if( !name.accept( action ) ) return false; - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ + if (!acceptByAttributes(action)) return false; + if (name != null && !name.accept(action)) return false; + + if (action.shouldVisitStatements) { + switch (action.leave(this)) { case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_SKIP : return true; default : break; @@ -83,7 +80,7 @@ public class CPPASTGotoStatement extends ASTNode implements IASTGotoStatement { @Override public int getRoleForName(IASTName n) { - if( name == n ) return r_reference; + if (name == n) return r_reference; return r_unclear; } } 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 0ccfbb1d42e..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,13 +1,14 @@ /******************************************************************************* - * 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) + * 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; @@ -158,6 +158,7 @@ public class CPPASTIfStatement extends ASTNode implements ICPPASTIfStatement, IA break loop; } } + if (action.shouldVisitStatements) { if (stmt != null && action.leave(stmt) == ASTVisitor.PROCESS_ABORT) return false; @@ -207,8 +208,8 @@ public class CPPASTIfStatement extends ASTNode implements ICPPASTIfStatement, IA @Override public IScope getScope() { - if( scope == null ) - scope = new CPPBlockScope( this ); + if (scope == null) + scope = new CPPBlockScope(this); return scope; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java index c1da21d6927..c36952741e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTInitializerList.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * John Camelon (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -26,9 +26,8 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; * e.g.: int a[]= {1,2,3}; */ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializerList, IASTAmbiguityParent { - - private IASTInitializerClause [] initializers = null; - private int initializersPos=-1; + private IASTInitializerClause [] initializers; + private int initializersPos= -1; private int actualSize; private boolean fIsPackExpansion; @@ -40,8 +39,9 @@ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializer @Override public CPPASTInitializerList copy(CopyStyle style) { CPPASTInitializerList copy = new CPPASTInitializerList(); - for (IASTInitializerClause initializer : getClauses()) + for (IASTInitializerClause initializer : getClauses()) { copy.addClause(initializer == null ? null : initializer.copy(style)); + } copy.setOffsetAndLength(this); copy.actualSize = getSize(); copy.fIsPackExpansion = fIsPackExpansion; @@ -114,9 +114,9 @@ public class CPPASTInitializerList extends ASTNode implements ICPPASTInitializer public boolean accept( ASTVisitor action ){ if (action.shouldVisitInitializers) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } IASTInitializerClause[] list = getClauses(); 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 9d4af23a843..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,12 +1,13 @@ /******************************************************************************* - * 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: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -15,18 +16,16 @@ 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 implements - IASTLabelStatement, IASTAmbiguityParent { - +public class CPPASTLabelStatement extends ASTAttributeOwner + implements IASTLabelStatement, IASTAmbiguityParent { private IASTName name; private IASTStatement nestedStatement; - public CPPASTLabelStatement() { } @@ -46,11 +45,7 @@ public class CPPASTLabelStatement extends ASTNode implements 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 @@ -69,22 +64,24 @@ public class CPPASTLabelStatement extends ASTNode implements } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( name != null ) if( !name.accept( action ) ) return false; - if( nestedStatement != null ) if( !nestedStatement.accept( action ) ) return false; + + if (!acceptByAttributes(action)) return false; + if (name != null && !name.accept(action)) return false; + if (nestedStatement != null && !nestedStatement.accept(action)) return false; - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } return true; @@ -92,7 +89,7 @@ public class CPPASTLabelStatement extends ASTNode implements @Override public int getRoleForName(IASTName n) { - if( n == name ) return r_declaration; + if (n == name) return r_declaration; return r_unclear; } @@ -113,12 +110,10 @@ public class CPPASTLabelStatement extends ASTNode implements @Override public void replace(IASTNode child, IASTNode other) { - if( child == nestedStatement ) - { - other.setParent( this ); - other.setPropertyInParent( child.getPropertyInParent() ); + if (child == nestedStatement) { + other.setParent(this); + other.setPropertyInParent(child.getPropertyInParent()); setNestedStatement((IASTStatement) other); } - } } 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 8464ac526e6..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 @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -32,35 +32,30 @@ public class CPPASTProblemDeclaration extends CPPASTProblemOwner implements IAST public CPPASTProblemDeclaration copy() { return copy(CopyStyle.withoutLocations); } - + @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 - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitDeclarations ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } super.accept(action); // visits the problem - if( action.shouldVisitDeclarations ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (action.shouldVisitDeclarations) { + 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/cpp/CPPASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java index 556aeb2ea24..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 @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * John Camelon (IBM) - Initial API and implementation - * Markus Schorn (Wind River Systems) + * John Camelon (IBM) - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -36,28 +36,24 @@ 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 - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitExpressions ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitExpressions) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } super.accept(action); // visits the problem - if( action.shouldVisitExpressions ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (action.shouldVisitExpressions) { + 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/cpp/CPPASTProblemOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java index 34faea7268c..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,13 +1,14 @@ /******************************************************************************* - * 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: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -20,27 +21,25 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode; * @author jcamelon */ abstract class CPPASTProblemOwner extends ASTNode implements IASTProblemHolder { - private IASTProblem problem; - public CPPASTProblemOwner() { } public CPPASTProblemOwner(IASTProblem problem) { 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(); @@ -50,19 +49,19 @@ abstract class CPPASTProblemOwner extends ASTNode implements IASTProblemHolder { p.setPropertyInParent(PROBLEM); } } - - @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitProblems ){ - switch( action.visit( getProblem() ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + + @Override + public boolean accept(ASTVisitor action) { + if (action.shouldVisitProblems) { + switch (action.visit(getProblem())) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } - switch( action.leave( getProblem() ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + switch (action.leave(getProblem())) { + 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/cpp/CPPASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java index 5e763e00830..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,17 +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: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * 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; @@ -27,7 +29,7 @@ public class CPPASTProblemStatement extends CPPASTProblemOwner implements IASTPr public CPPASTProblemStatement(IASTProblem problem) { super(problem); } - + @Override public CPPASTProblemStatement copy() { return copy(CopyStyle.withoutLocations); @@ -36,30 +38,37 @@ 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 - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitStatements ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitStatements) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } super.accept(action); // visits the problem - if( action.shouldVisitStatements ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (action.shouldVisitStatements) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } 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 ce13cbcab98..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 @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId; * @author jcamelon */ public class CPPASTProblemTypeId extends CPPASTProblemOwner implements IASTProblemTypeId { + public CPPASTProblemTypeId() { } @@ -36,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 @@ -52,7 +49,7 @@ public class CPPASTProblemTypeId extends CPPASTProblemOwner implements IASTProbl default: break; } - // Visits the problem + // Visit the problem if (!super.accept(action)) return false; 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 0a4dc3aacd4..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,12 +1,13 @@ /******************************************************************************* - * 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 * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - Initial API and implementation + * 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 @@ -178,11 +177,13 @@ public class CPPASTRangeBasedForStatement extends ASTNode implements ICPPASTRang public boolean accept( ASTVisitor action ){ if (action.shouldVisitStatements) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + 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 192e9624a0f..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 @@ -77,16 +74,14 @@ public class CPPASTReturnStatement extends ASTNode implements IASTReturnStatemen public boolean accept(ASTVisitor action) { if (action.shouldVisitStatements) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT: - return false; - case ASTVisitor.PROCESS_SKIP: - return true; - default: - break; + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if (retValue != null && !retValue.accept(action)) - return false; + + if (!acceptByAttributes(action)) return false; + if (retValue != null && !retValue.accept(action)) return false; if (action.shouldVisitStatements) { switch (action.leave(this)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTSimpleDeclaration.java index 1a47bc44936..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() { } @@ -41,13 +46,10 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar public CPPASTSimpleDeclaration copy(CopyStyle style) { CPPASTSimpleDeclaration copy = new CPPASTSimpleDeclaration(); 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 @@ -72,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. @@ -100,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++) { @@ -122,12 +121,11 @@ 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 85f983f029b..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,13 +1,14 @@ /******************************************************************************* - * 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) + * 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 @@ -104,6 +101,8 @@ public class CPPASTSwitchStatement extends ASTNode default: break; } } + + 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 f90cf8b82c2..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,14 +1,15 @@ /******************************************************************************* - * Copyright (c) 2004, 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) 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 - * Bryan Wilkinson (QNX) - * Markus Schorn (Wind River Systems) + * Contributors: + * 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,13 +22,11 @@ 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; @@ -45,14 +44,10 @@ public class CPPASTUsingDeclaration extends ASTNode @Override public CPPASTUsingDeclaration copy(CopyStyle style) { - CPPASTUsingDeclaration copy = new CPPASTUsingDeclaration(name == null ? null - : name.copy(style)); + 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 @@ -85,19 +80,20 @@ public class CPPASTUsingDeclaration extends ASTNode public boolean accept(ASTVisitor action) { if (action.shouldVisitDeclarations) { switch (action.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if (name != null) if (!name.accept(action)) return false; + if (!acceptByAttributes(action)) return false; + if (name != null && !name.accept(action)) return false; if (action.shouldVisitDeclarations) { switch(action.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + 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/cpp/CPPASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java index cc6cbb3f92e..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,13 +1,14 @@ /******************************************************************************* - * 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 - * Bryan Wilkinson (QNX) + * John Camelon (IBM) - Initial API and implementation + * Bryan Wilkinson (QNX) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -20,13 +21,11 @@ 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 implements - ICPPASTUsingDirective, ICPPASTCompletionContext { - +public class CPPASTUsingDirective extends ASTAttributeOwner + implements ICPPASTUsingDirective, ICPPASTCompletionContext { private IASTName name; public CPPASTUsingDirective() { @@ -44,11 +43,7 @@ public class CPPASTUsingDirective extends ASTNode implements @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 @@ -64,35 +59,34 @@ public class CPPASTUsingDirective extends ASTNode implements qualifiedName.setParent(this); qualifiedName.setPropertyInParent(QUALIFIED_NAME); } - } @Override - public boolean accept( ASTVisitor action ){ - if( action.shouldVisitDeclarations ){ - switch( action.visit( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + public boolean accept(ASTVisitor action) { + if (action.shouldVisitDeclarations) { + switch (action.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } - if( name != null ) if( !name.accept( action ) ) return false; + if (!acceptByAttributes(action)) return false; + if (name != null && !name.accept(action)) return false; - if( action.shouldVisitDeclarations ){ - switch( action.leave( this ) ){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; - default : break; + if (action.shouldVisitDeclarations) { + switch (action.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; + default: break; } } return true; } - - @Override + @Override public int getRoleForName(IASTName n) { - if( n == name ) + if (n == name) return r_reference; return r_unclear; } 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/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 071bb01590b..d05977e2226 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.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 @@ -8,6 +8,7 @@ * Contributors: * Andrew Niefer (IBM Corporation) - initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -44,7 +45,9 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.parser.util.AttributeUtil; import org.eclipse.cdt.internal.core.dom.Linkage; +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; @@ -593,4 +596,10 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt ICPPParameter[] pars= getParameters(); return pars.length > 0 && pars[pars.length - 1].isParameterPack(); } + + @Override + public boolean isNoReturn() { + ICPPASTFunctionDeclarator dtor = getPreferredDtor(); + return dtor != null && AttributeUtil.hasNoreturnAttribute(dtor); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java index cf13fb67c95..74b9893f88a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 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 @@ * Andrew Niefer (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; @@ -210,6 +211,14 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP return false; } + @Override + public boolean isNoReturn() { + ICPPFunction f = (ICPPFunction) getSpecializedBinding(); + if (f != null) + return f.isNoReturn(); + return false; + } + @Override public IBinding resolveParameter(CPPParameter param) { int pos= param.getParameterPosition(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java index 24842f53ffe..101e4926023 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java @@ -8,6 +8,7 @@ * Contributors: * Andrew Niefer (IBM) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -35,6 +36,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; +import org.eclipse.cdt.core.parser.util.AttributeUtil; +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.ProblemFunctionType; @@ -338,6 +341,15 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition return false; } + @Override + public boolean isNoReturn() { + ICPPASTFunctionDeclarator fdecl= getFirstFunctionDtor(); + if (fdecl != null) { + return AttributeUtil.hasNoreturnAttribute(fdecl); + } + return false; + } + private IASTDeclarator getDeclaratorByName(IASTNode node) { // Skip qualified names and nested declarators. while (node != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java index 9e800ac6d99..5b4e4a4ef40 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNamespace.java @@ -69,8 +69,6 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI } } - private static final char[] EMPTY_CHAR_ARRAY = {}; - IASTName[] namespaceDefinitions; ICPPNamespaceScope scope; ICPPASTTranslationUnit tu; @@ -251,7 +249,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI */ @Override public char[] getNameCharArray() { - return tu != null ? EMPTY_CHAR_ARRAY : namespaceDefinitions[0].getSimpleID(); + return tu != null ? CharArrayUtils.EMPTY_CHAR_ARRAY : namespaceDefinitions[0].getSimpleID(); } /* (non-Javadoc) 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/CPPUnknownFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownFunction.java index d0e65667ad8..f6245270563 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownFunction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Wind River Systems, Inc. and others. + * Copyright (c) 2008, 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 @@ -107,6 +107,11 @@ public class CPPUnknownFunction extends CPPUnknownBinding implements ICPPFunctio return false; } + @Override + public boolean isNoReturn() { + return false; + } + @Override public int getRequiredArgumentCount() { return 0; 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/AutoTypeResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AutoTypeResolver.java index bcda5244bcd..1a4a168efef 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AutoTypeResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/AutoTypeResolver.java @@ -167,4 +167,9 @@ class AutoTypeResolver implements ICPPFunctionTemplate { public boolean isGloballyQualified() throws DOMException { throw new UnsupportedOperationException(UNEXPECTED_CALL); } + + @Override + public boolean isNoReturn() { + throw new UnsupportedOperationException(UNEXPECTED_CALL); + } } \ No newline at end of file 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..36a9f6d23cf 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; @@ -155,11 +156,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; 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.AttributeUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; 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; import org.eclipse.cdt.internal.core.dom.parser.ProblemType; +import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator; import org.eclipse.cdt.internal.core.dom.parser.Value; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFieldReference; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionCallExpression; @@ -1779,6 +1782,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 +1847,52 @@ 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 = AttributeUtil.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$ + SizeofCalculator sizeofs = new SizeofCalculator(declarator.getTranslationUnit()); + int modifier; + if (sizeofs.sizeof_long != null && sizeofs.sizeof_int != null && + sizeofs.sizeof_long.size == 2 * sizeofs.sizeof_int.size) { + modifier = IBasicType.IS_LONG; + } else { + modifier = IBasicType.IS_LONG_LONG; + } + type = new CPPBasicType(IBasicType.Kind.eInt, + modifier | 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 +2131,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/index/composite/c/CompositeCFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCFunction.java index b787d420395..195f786288d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCFunction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Symbian Software Systems and others. + * Copyright (c) 2007, 2012 Symbian Software Systems and others. * All rights reserved. This program and 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: * Andrew Ferguson (Symbian) - Initial implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.c; @@ -74,4 +75,9 @@ class CompositeCFunction extends CompositeCBinding implements IFunction { public boolean takesVarArgs() { return ((IFunction) rbinding).takesVarArgs(); } + + @Override + public boolean isNoReturn() { + return ((IFunction) rbinding).isNoReturn(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunction.java index 5149f44ffb5..2e5a3d68f34 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Symbian Software Systems and others. + * Copyright (c) 2007, 2012 Symbian Software Systems and others. * All rights reserved. This program and 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: * Andrew Ferguson (Symbian) - Initial implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite.cpp; @@ -90,7 +91,12 @@ class CompositeCPPFunction extends CompositeCPPBinding implements ICPPFunction { public boolean takesVarArgs() { return ((ICPPFunction) rbinding).takesVarArgs(); } - + + @Override + public boolean isNoReturn() { + return ((ICPPFunction) rbinding).isNoReturn(); + } + @Override public int getRequiredArgumentCount() { return ((ICPPFunction) rbinding).getRequiredArgumentCount(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java index 89a574118af..88d87b9cde1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java @@ -84,7 +84,6 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { private static final int ORIGIN_PREPROCESSOR_DIRECTIVE = OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE; private static final int ORIGIN_INACTIVE_CODE = OffsetLimitReachedException.ORIGIN_INACTIVE_CODE; - private static final char[] EMPTY_CHAR_ARRAY = new char[0]; private static final char[] ONE = "1".toCharArray(); //$NON-NLS-1$ @@ -392,7 +391,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { } private char[] nonNull(char[] array) { - return array == null ? EMPTY_CHAR_ARRAY : array; + return array == null ? CharArrayUtils.EMPTY_CHAR_ARRAY : array; } private void configureIncludeSearchPath(File directory, IScannerInfo info) { 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/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCAnnotation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCAnnotation.java index 7143e4bc806..0a86b7d0317 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCAnnotation.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCAnnotation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 IBM Corporation. + * Copyright (c) 2006, 2012 IBM Corporation. * All rights reserved. This program and 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 Corporation - initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.c; @@ -30,6 +31,7 @@ public class PDOMCAnnotation { public static final int REGISTER_OFFSET = 3; public static final int STATIC_OFFSET = 4; public static final int VARARGS_OFFSET = 5; + public static final int NO_RETURN = 6; // CV qualifiers public static final int CONST_OFFSET = 0; @@ -46,19 +48,20 @@ public class PDOMCAnnotation { byte modifiers = 0; if (binding instanceof IVariable) { IVariable variable = (IVariable) binding; - modifiers |= (variable.isAuto() ? 1 : 0) << PDOMCAnnotation.AUTO_OFFSET; - modifiers |= (variable.isExtern() ? 1 : 0) << PDOMCAnnotation.EXTERN_OFFSET; - modifiers |= (variable.isRegister() ? 1 : 0) << PDOMCAnnotation.REGISTER_OFFSET; - modifiers |= (variable.isStatic() ? 1 : 0) << PDOMCAnnotation.STATIC_OFFSET; + modifiers |= (variable.isAuto() ? 1 : 0) << AUTO_OFFSET; + modifiers |= (variable.isExtern() ? 1 : 0) << EXTERN_OFFSET; + modifiers |= (variable.isRegister() ? 1 : 0) << REGISTER_OFFSET; + modifiers |= (variable.isStatic() ? 1 : 0) << STATIC_OFFSET; } if (binding instanceof IFunction) { IFunction function = (IFunction) binding; - modifiers |= (function.isAuto() ? 1 : 0) << PDOMCAnnotation.AUTO_OFFSET; - modifiers |= (function.isExtern() ? 1 : 0) << PDOMCAnnotation.EXTERN_OFFSET; - modifiers |= (function.isRegister() ? 1 : 0) << PDOMCAnnotation.REGISTER_OFFSET; - modifiers |= (ASTInternal.isStatic(function, false) ? 1 : 0) << PDOMCAnnotation.STATIC_OFFSET; - modifiers |= (function.isInline() ? 1 : 0) << PDOMCAnnotation.INLINE_OFFSET; - modifiers |= (function.takesVarArgs() ? 1 : 0) << PDOMCAnnotation.VARARGS_OFFSET; + modifiers |= (function.isAuto() ? 1 : 0) << AUTO_OFFSET; + modifiers |= (function.isExtern() ? 1 : 0) << EXTERN_OFFSET; + modifiers |= (function.isRegister() ? 1 : 0) << REGISTER_OFFSET; + modifiers |= (ASTInternal.isStatic(function, false) ? 1 : 0) << STATIC_OFFSET; + modifiers |= (function.isInline() ? 1 : 0) << INLINE_OFFSET; + modifiers |= (function.takesVarArgs() ? 1 : 0) << VARARGS_OFFSET; + modifiers |= (function.isNoReturn() ? 1 : 0) << NO_RETURN; } return modifiers; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java index f2fc259eb97..a579fc6449f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCFunction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 QNX Software Systems and others. + * Copyright (c) 2006, 2012 QNX Software Systems and others. * All rights reserved. This program and 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 @@ * IBM Corporation * Andrew Ferguson (Symbian) * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.c; @@ -58,7 +59,7 @@ class PDOMCFunction extends PDOMBinding implements IFunction { */ @SuppressWarnings("hiding") public static final int RECORD_SIZE = ANNOTATIONS + 1; - + public PDOMCFunction(PDOMLinkage linkage, long record) { super(linkage, record); } @@ -195,7 +196,12 @@ class PDOMCFunction extends PDOMBinding implements IFunction { public boolean takesVarArgs() { return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.VARARGS_OFFSET); } - + + @Override + public boolean isNoReturn() { + return getBit(getByte(record + ANNOTATIONS), PDOMCAnnotation.NO_RETURN); + } + @Override public IScope getFunctionScope() { return null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java index 4d5c9f4a0cb..ab6d0333544 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 QNX Software Systems and others. + * Copyright (c) 2005, 2012 QNX Software Systems and others. * All rights reserved. This program and 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 @@ * Doug Schaefer (QNX) - Initial API and implementation * IBM Corporation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -347,6 +348,11 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl return getBit(getAnnotation(), PDOMCAnnotation.VARARGS_OFFSET); } + @Override + public boolean isNoReturn() { + return getBit(getAnnotation(), PDOMCAnnotation.NO_RETURN); + } + @Override public boolean hasParameterPack() { return getBit(getAnnotation(), ANNOT_PARAMETER_PACK); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java index 9097d5c6197..7a7becba71f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 QNX Software Systems and others. + * Copyright (c) 2007, 2012 QNX Software Systems and others. * All rights reserved. This program and 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: * Bryan Wilkinson (QNX) - Initial API and implementation * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -244,6 +245,11 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization implements ICP return getBit(readAnnotation(), PDOMCAnnotation.VARARGS_OFFSET); } + @Override + public boolean isNoReturn() { + return getBit(readAnnotation(), PDOMCAnnotation.NO_RETURN); + } + @Override public int getRequiredArgumentCount() { if (fRequiredArgCount == -1) { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index d7f3d834d6f..b1665f27f75 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 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 @@ -467,7 +467,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, continue; } try { - int pos = scribe.scanner.getCurrentPosition(); + int pos = getCurrentPosition(); IASTFileLocation declarationLocation = declaration.getFileLocation(); int declarationOffset = declarationLocation.getNodeOffset(); for (; m < macroExpansions.length; m++) { @@ -552,7 +552,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.alignment_for_arguments_in_method_invocation, Alignment.R_OUTERMOST, binding.getParameterList().length, - scribe.scanner.getCurrentPosition(), + getCurrentPosition(), continuationIndentation, false); scribe.enterAlignment(listAlignment); @@ -641,7 +641,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, try { return formatDeclaration(node); } finally { - endOfNode(node); + finishNode(node); } } @@ -705,7 +705,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, formatRaw(node); } } finally { - endOfNode(node); + finishNode(node); } return PROCESS_SKIP; } @@ -738,7 +738,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, formatRaw(node); } } finally { - endOfNode(node); + finishNode(node); } return PROCESS_SKIP; } @@ -765,7 +765,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, declarator.accept(this); } } finally { - endOfNode(node); + finishNode(node); } return PROCESS_SKIP; } @@ -827,7 +827,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, initializer.accept(this); } } finally { - endOfNode(node); + finishNode(node); } return PROCESS_SKIP; } @@ -870,7 +870,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, formatRaw(node); } } finally { - endOfNode(node); + finishNode(node); } return PROCESS_SKIP; } @@ -918,7 +918,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, formatRaw(node); } } finally { - endOfNode(node); + finishNode(node); } return PROCESS_SKIP; } @@ -928,8 +928,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, */ @Override public int visit(IASTStatement node) { - if (scribe.scanner.getCurrentPosition() <= node.getFileLocation().getNodeOffset() && - startsWithMacroExpansion(node)) { + if (getCurrentPosition() <= nodeOffset(node) && startsWithMacroExpansion(node)) { scribe.printCommentPreservingNewLines(); } if (!startNode(node)) { return PROCESS_SKIP; } @@ -986,7 +985,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } } } finally { - endOfNode(node); + finishNode(node); } return PROCESS_SKIP; } @@ -1016,7 +1015,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, declarator.accept(this); } } finally { - endOfNode(node); + finishNode(node); } return PROCESS_SKIP; } @@ -1041,7 +1040,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, value.accept(this); } } finally { - endOfNode(enumerator); + finishNode(enumerator); } return PROCESS_SKIP; } @@ -1073,7 +1072,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } specifier.getName().accept(this); } finally { - endOfNode(specifier); + finishNode(specifier); } return PROCESS_SKIP; } @@ -1105,7 +1104,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } formatClosingBrace(preferences.brace_position_for_namespace_declaration); } finally { - endOfNode(node); + finishNode(node); } return PROCESS_SKIP; } @@ -1219,7 +1218,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } catch (ASTProblemException e) { skipNode(node); } finally { - endOfNode(node); + finishNode(node); } return PROCESS_SKIP; } @@ -1290,7 +1289,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, // Format like a function call formatFunctionCallArguments(node.getArguments()); } finally { - endOfNode(node); + finishNode(node); } return PROCESS_SKIP; } @@ -1329,8 +1328,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (DefaultCodeFormatterConstants.END_OF_LINE.equals(preferences.brace_position_for_method_declaration) && !hasMemberInitializers(node) && !(node instanceof ICPPASTFunctionWithTryBlock)) { if (bodyStmt instanceof IASTCompoundStatement && !startsWithMacroExpansion(bodyStmt)) { - tailFormatter = new TrailingTokenFormatter(Token.tLBRACE, - bodyStmt.getFileLocation().getNodeOffset(), + tailFormatter = new TrailingTokenFormatter(Token.tLBRACE, nodeOffset(bodyStmt), preferences.insert_space_before_opening_brace_in_method_declaration, false); scribe.setTailFormatter(tailFormatter); } @@ -1376,7 +1374,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (bodyStmt instanceof IASTCompoundStatement) { if (startNode(bodyStmt)) { try { - if (scribe.scanner.getCurrentPosition() <= bodyStmt.getFileLocation().getNodeOffset()) { + if (getCurrentPosition() <= nodeOffset(bodyStmt)) { formatLeftCurlyBrace(line, preferences.brace_position_for_method_declaration); } formatBlock((IASTCompoundStatement) bodyStmt, @@ -1384,7 +1382,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.insert_space_before_opening_brace_in_method_declaration, preferences.indent_statements_compare_to_body); } finally { - endOfNode(bodyStmt); + finishNode(bodyStmt); } } } else { @@ -1468,7 +1466,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, Alignment.EXCEPTION_SPECIFICATION, preferences.alignment_for_throws_clause_in_method_declaration, exceptionSpecification.length, - scribe.scanner.getCurrentPosition()); + getCurrentPosition()); scribe.enterAlignment(alignment); boolean ok = false; @@ -1789,7 +1787,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } // Consider macro expansion - if (withinMacroExpansion(node, scribe.scanner.getCurrentPosition())) { + if (withinMacroExpansion(node, getCurrentPosition())) { scribe.printNextToken(peekNextToken()); continueNode(node); if (scribe.printComment()) scribe.space(); @@ -1842,7 +1840,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, final int headerIndent= scribe.numberOfIndentations; // Consider macro expansion - if (withinMacroExpansion(node, scribe.scanner.getCurrentPosition())) { + if (withinMacroExpansion(node, getCurrentPosition())) { scribe.printNextToken(peekNextToken()); continueNode(node); if (scribe.printComment()) @@ -1890,7 +1888,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (preferences.indent_access_specifier_compare_to_type_header) { scribe.indent(); } - if (scribe.scanner.getCurrentPosition() >= getNodeEndPosition(node)) { + if (getCurrentPosition() >= nodeEndOffset(node)) { return PROCESS_SKIP; } scribe.startNewLine(); @@ -1911,16 +1909,17 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, visit((ICPPASTVisibilityLabel) declaration); scribe.startNewLine(); } finally { - endOfNode(declaration); + finishNode(declaration); } } } else { if (startNode(declaration)) { try { - scribe.startNewLine(); + if (getCurrentPosition() <= nodeOffset(declaration)) + scribe.startNewLine(); formatDeclaration(declaration); } finally { - endOfNode(declaration); + finishNode(declaration); } } else { skipNode(declaration); @@ -2087,7 +2086,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, options.fMode, options.fTieBreakRule, elementsLength + (addEllipsis ? 1 : 0), - scribe.scanner.getCurrentPosition(), + getCurrentPosition(), continuationIndentation, false); scribe.enterAlignment(alignment); @@ -2230,7 +2229,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.alignment_for_conditional_expression_chain, Alignment.R_OUTERMOST, numConditions, - scribe.scanner.getCurrentPosition()); + getCurrentPosition()); scribe.enterAlignment(alignment); boolean ok = false; @@ -2270,7 +2269,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.alignment_for_conditional_expression, Alignment.R_OUTERMOST, negativeExpression instanceof IASTConditionalExpression ? 1 : 2, - scribe.scanner.getCurrentPosition()); + getCurrentPosition()); scribe.enterAlignment(alignment); boolean ok = false; @@ -2278,7 +2277,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, try { // In case of macros we may have already passed the expression position. if (positiveExpression != null && - scribe.scanner.getCurrentPosition() <= positiveExpression.getFileLocation().getNodeOffset()) { + getCurrentPosition() <= nodeOffset(positiveExpression)) { scribe.alignFragment(alignment, 0); } scribe.setTailFormatter(new TrailingTokenFormatter(Token.tCOLON, node, @@ -2292,7 +2291,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (!(negativeExpression instanceof IASTConditionalExpression)) { // In case of macros we may have already passed the expression position. - if (scribe.scanner.getCurrentPosition() <= negativeExpression.getFileLocation().getNodeOffset()) { + if (getCurrentPosition() <= nodeOffset(negativeExpression)) { scribe.alignFragment(alignment, 1); } scribe.setTailFormatter(tailFormatter); @@ -2448,7 +2447,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.alignment_for_assignment, Alignment.R_INNERMOST, 1, - scribe.scanner.getCurrentPosition()); + getCurrentPosition()); Runnable tailFormatter = scribe.getTailFormatter(); scribe.enterAlignment(alignment); @@ -2489,7 +2488,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, Alignment.DESIGNATED_INITIALIZER, preferences.alignment_for_assignment, 1, - scribe.scanner.getCurrentPosition()); + getCurrentPosition()); scribe.enterAlignment(expressionAlignment); boolean ok = false; @@ -2654,7 +2653,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.alignment_for_binary_expression, Alignment.R_OUTERMOST, operands.length, - scribe.scanner.getCurrentPosition()); + getCurrentPosition()); scribe.enterAlignment(alignment); boolean ok = false; @@ -2663,7 +2662,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, for (int i = 0; i < operands.length; i++) { final IASTExpression operand = operands[i]; // In case of macros we may have already passed the operator position. - if (i > 0 && scribe.scanner.getCurrentPosition() < operand.getFileLocation().getNodeOffset()) { + if (i > 0 && getCurrentPosition() < nodeOffset(operand)) { scribe.alignFragment(alignment, i); // Operator @@ -2689,7 +2688,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, scribe.setTailFormatter(tailFormatter); } operand.accept(this); - scribe.restartAtOffset(getNodeEndPosition(operand)); + scribe.restartAtOffset(nodeEndOffset(operand)); scribe.printTrailingComment(); } @@ -2710,7 +2709,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, op1.accept(this); // In case of macros we may have already passed the equal sign position. - if (scribe.scanner.getCurrentPosition() < node.getOperand2().getFileLocation().getNodeOffset()) { + if (getCurrentPosition() < nodeOffset(node.getOperand2())) { // Operator final int nextToken= peekNextToken(); // In case of C++ alternative operators, like 'and', 'not', etc. a space @@ -2727,7 +2726,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.alignment_for_assignment, Alignment.R_INNERMOST, 1, - scribe.scanner.getCurrentPosition()); + getCurrentPosition()); scribe.enterAlignment(expressionAlignment); boolean ok = false; @@ -2792,7 +2791,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.alignment_for_overloaded_left_shift_chain, Alignment.R_OUTERMOST, elements.size(), - scribe.scanner.getCurrentPosition(), + getCurrentPosition(), preferences.continuation_indentation, false); scribe.enterAlignment(alignment); @@ -2802,7 +2801,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, for (int i = 0; i < elements.size(); i++) { node= elements.get(i); // In case of macros we may have already passed the operator position. - if (scribe.scanner.getCurrentPosition() < node.getFileLocation().getNodeOffset()) { + if (getCurrentPosition() < nodeOffset(node)) { scribe.alignFragment(alignment, i); int token= peekNextToken(); if (token == Token.tSHIFTL) { @@ -2895,7 +2894,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.alignment_for_member_access, Alignment.R_OUTERMOST, 1, - scribe.scanner.getCurrentPosition()); + getCurrentPosition()); scribe.enterAlignment(alignment); boolean ok = false; @@ -3073,7 +3072,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, final IASTStatement action = node.getBody(); formatAction(line, action, preferences.brace_position_for_block); - if (scribe.scanner.getCurrentPosition() < getNodeEndPosition(node)) { + if (getCurrentPosition() < nodeEndOffset(node)) { if (peekNextToken() == Token.t_while) { if (preferences.insert_new_line_before_while_in_do_statement) { scribe.startNewLine(); @@ -3096,8 +3095,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } private int visit(IASTNullStatement node) { - if (!fInsideFor && - node.getFileLocation().getNodeOffset() == scribe.scanner.getCurrentPosition()) { + if (!fInsideFor && nodeOffset(node) == getCurrentPosition()) { scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon); scribe.printTrailingComment(); } @@ -3145,8 +3143,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } if (DefaultCodeFormatterConstants.END_OF_LINE.equals(preferences.brace_position_for_block) && body instanceof IASTCompoundStatement && !startsWithMacroExpansion(body)) { - tailFormatter = new TrailingTokenFormatter(Token.tLBRACE, - body.getFileLocation().getNodeOffset(), + tailFormatter = new TrailingTokenFormatter(Token.tLBRACE, nodeOffset(body), preferences.insert_space_before_opening_brace_in_block, false); } tailFormatter = new ClosingParensesisTailFormatter( @@ -3163,7 +3160,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, Alignment.M_COMPACT_SPLIT, Alignment.R_OUTERMOST, 2, - scribe.scanner.getCurrentPosition()); + getCurrentPosition()); scribe.enterAlignment(alignment); boolean ok = false; @@ -3216,7 +3213,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (body instanceof IASTCompoundStatement && !startsWithMacroExpansion(body)) { if (startNode(body)) { try { - if (scribe.scanner.getCurrentPosition() <= body.getFileLocation().getNodeOffset()) { + if (getCurrentPosition() <= nodeOffset(body)) { formatLeftCurlyBrace(line, preferences.brace_position_for_block); } formatBlock((IASTCompoundStatement) body, @@ -3224,7 +3221,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.insert_space_before_opening_brace_in_block, preferences.indent_statements_compare_to_block); } finally { - endOfNode(body); + finishNode(body); } } } else { @@ -3284,8 +3281,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, Runnable tailFormatter = null; if (DefaultCodeFormatterConstants.END_OF_LINE.equals(preferences.brace_position_for_block) && thenStatement instanceof IASTCompoundStatement && !startsWithMacroExpansion(thenStatement)) { - tailFormatter = new TrailingTokenFormatter(Token.tLBRACE, - thenStatement.getFileLocation().getNodeOffset(), + tailFormatter = new TrailingTokenFormatter(Token.tLBRACE, nodeOffset(thenStatement), preferences.insert_space_before_opening_brace_in_block, false); } tailFormatter = new ClosingParensesisTailFormatter( @@ -3316,7 +3312,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (isGuardClause(block, statements) && elseStatement == null && preferences.keep_guardian_clause_on_one_line) { // Specific formatting for guard clauses. A guard clause is a block // with a single return or throw statement. - if (scribe.scanner.getCurrentPosition() <= thenStatement.getFileLocation().getNodeOffset()) { + if (getCurrentPosition() <= nodeOffset(thenStatement)) { scribe.printNextToken(Token.tLBRACE, preferences.insert_space_before_opening_brace_in_block); scribe.space(); } @@ -3324,7 +3320,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, scribe.printNextToken(Token.tRBRACE, true); scribe.printTrailingComment(); } else { - if (scribe.scanner.getCurrentPosition() <= thenStatement.getFileLocation().getNodeOffset()) { + if (getCurrentPosition() <= nodeOffset(thenStatement)) { formatLeftCurlyBrace(line, preferences.brace_position_for_block); } thenStatement.accept(this); @@ -3342,7 +3338,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.alignment_for_compact_if, Alignment.R_OUTERMOST, 1, - scribe.scanner.getCurrentPosition(), + getCurrentPosition(), 1, false); scribe.enterAlignment(compactIfAlignment); @@ -3638,7 +3634,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, skipToNode(nextStatement); } } finally { - endOfNode(statement); + finishNode(statement); } if (preferences.indent_switchstatements_compare_to_cases) { scribe.indent(); @@ -3656,7 +3652,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, skipToNode(nextStatement); } } finally { - endOfNode(statement); + finishNode(statement); } } wasAStatement = true; @@ -3696,7 +3692,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, formatClosingBrace(brace_position); } } finally { - endOfNode(bodyStmt); + finishNode(bodyStmt); } return PROCESS_SKIP; } @@ -3769,7 +3765,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, IASTPreprocessorMacroExpansion macroExpansion = location.getExpansion(); IASTFileLocation macroLocation = macroExpansion.getFileLocation(); IASTFileLocation nodeLocation = node.getFileLocation(); - if (macroLocation.getNodeOffset() >= scribe.scanner.getCurrentPosition() && + if (macroLocation.getNodeOffset() >= getCurrentPosition() && !scribe.shouldSkip(macroLocation.getNodeOffset()) && (nodeLocation.getNodeOffset() + nodeLocation.getNodeLength() == macroLocation.getNodeOffset() + macroLocation.getNodeLength() || @@ -3783,7 +3779,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, int startOffset= expansionLocation.getNodeOffset(); int endOffset= startOffset + expansionLocation.getNodeLength(); scribe.skipRange(startOffset, endOffset); - if (locations.length == 1 && endOffset <= scribe.scanner.getCurrentPosition()) { + if (locations.length == 1 && endOffset <= getCurrentPosition()) { scribe.restartAtOffset(endOffset); continueNode(node.getParent()); return false; @@ -3800,7 +3796,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, * * @param node */ - private void endOfNode(IASTNode node) { + private void finishNode(IASTNode node) { if (node instanceof IASTProblemHolder) { return; } @@ -3832,7 +3828,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } int nodeOffset= fileLocation.getNodeOffset(); int nodeEndOffset= nodeOffset + fileLocation.getNodeLength(); - int currentOffset= scribe.scanner.getCurrentPosition(); + int currentOffset= getCurrentPosition(); if (currentOffset > nodeEndOffset) { return; } @@ -3856,7 +3852,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } private int getNextTokenOffset() { - localScanner.resetTo(scribe.scanner.getCurrentPosition(), scribe.scannerEndPosition); + localScanner.resetTo(getCurrentPosition(), scribe.scannerEndPosition); localScanner.getNextToken(); return localScanner.getCurrentTokenStartPosition(); } @@ -3865,7 +3861,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, final IASTNodeLocation fileLocation= node.getFileLocation(); if (fileLocation != null && fileLocation.getNodeLength() > 0) { final int endOffset= fileLocation.getNodeOffset() + fileLocation.getNodeLength(); - final int currentOffset= scribe.scanner.getCurrentPosition(); + final int currentOffset= getCurrentPosition(); final int restLength= endOffset - currentOffset; if (restLength > 0) { scribe.printRaw(currentOffset, restLength); @@ -3877,7 +3873,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, final IASTNodeLocation fileLocation= node.getFileLocation(); if (fileLocation != null) { final int startOffset= fileLocation.getNodeOffset(); - final int currentOffset= scribe.scanner.getCurrentPosition(); + final int currentOffset= getCurrentPosition(); final int restLength= startOffset - currentOffset; if (restLength > 0) { scribe.printRaw(currentOffset, restLength); @@ -3891,7 +3887,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, final int startOffset= fileLocation.getNodeOffset(); final int nextTokenOffset= getNextTokenOffset(); if (nextTokenOffset < startOffset) { - final int currentOffset= scribe.scanner.getCurrentPosition(); + final int currentOffset= getCurrentPosition(); final int restLength= startOffset - currentOffset; if (restLength > 0) { scribe.printRaw(currentOffset, restLength); @@ -3939,7 +3935,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.insert_space_before_opening_brace_in_block, preferences.indent_statements_compare_to_block); } finally { - endOfNode(stmt); + finishNode(stmt); } } } else if (stmt instanceof IASTNullStatement) { @@ -3953,7 +3949,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, // Don't insert a line break if we have already passed the start of the statement. // This is possible with macro expansions. boolean indented = false; - if (scribe.scanner.getCurrentPosition() <= stmt.getFileLocation().getNodeOffset()) { + if (getCurrentPosition() <= nodeOffset(stmt)) { scribe.printTrailingComment(); scribe.startNewLine(); scribe.indent(); @@ -4010,6 +4006,10 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, return true; } + private int getCurrentPosition() { + return scribe.scanner.getCurrentPosition(); + } + /** * Returns true if the given macro expansion is followed by a semicolon on the same * line. @@ -4051,10 +4051,14 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, * expansion. */ private static boolean doNodesHaveSameOffset(IASTNode node1, IASTNode node2) { - return node1.getFileLocation().getNodeOffset() == node2.getFileLocation().getNodeOffset(); + return nodeOffset(node1) == nodeOffset(node2); } - private static int getNodeEndPosition(IASTNode node) { + private static int nodeOffset(IASTNode node) { + return node.getFileLocation().getNodeOffset(); + } + + private static int nodeEndOffset(IASTNode node) { IASTFileLocation loc = node.getFileLocation(); return loc.getNodeOffset() + loc.getNodeLength(); } @@ -4072,7 +4076,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, scribe.startNewLine(); scribe.printComment(); } - } else if (scribe.scanner.getCurrentPosition() <= block.getFileLocation().getNodeOffset()) { + } else if (getCurrentPosition() <= nodeOffset(block)) { formatOpeningBrace(block_brace_position, insertSpaceBeforeOpeningBrace); } } @@ -4240,10 +4244,10 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } private int peekNextToken(boolean ignoreSkip) { - if (!ignoreSkip && scribe.shouldSkip(scribe.scanner.getCurrentPosition())) { + if (!ignoreSkip && scribe.shouldSkip(getCurrentPosition())) { return Token.tBADCHAR; } - localScanner.resetTo(scribe.scanner.getCurrentPosition(), scribe.scannerEndPosition); + localScanner.resetTo(getCurrentPosition(), scribe.scannerEndPosition); int token = localScanner.getNextToken(); while (token == Token.tBLOCKCOMMENT || token == Token.tLINECOMMENT) { token = localScanner.getNextToken(); @@ -4266,7 +4270,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, if (fileLocation == null) { return false; } - int blockStartPosition= block.getFileLocation().getNodeOffset(); + int blockStartPosition= nodeOffset(block); int blockLength= block.getFileLocation().getNodeLength(); if (commentStartsBlock(blockStartPosition, blockLength)) return false; final int statementsLength = statements.size(); diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java index 1cb1d0ffee2..aaf0db2d342 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/Scribe.java @@ -19,6 +19,7 @@ import java.util.List; import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; import org.eclipse.cdt.core.formatter.DefaultCodeFormatterOptions; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.formatter.align.Alignment; import org.eclipse.cdt.internal.formatter.align.AlignmentException; import org.eclipse.cdt.internal.formatter.scanner.Scanner; @@ -35,7 +36,6 @@ import org.eclipse.text.edits.TextEdit; */ public class Scribe { private static final String EMPTY_STRING= ""; //$NON-NLS-1$ - private static final char[] EMPTY_CHAR_ARRAY= {}; private static final String SPACE= " "; //$NON-NLS-1$ private static final int INITIAL_SIZE= 100; @@ -105,7 +105,7 @@ public class Scribe { int currentIndentation; int indentation; int lines; - char[] leadingSpaces = EMPTY_CHAR_ARRAY; + char[] leadingSpaces = CharArrayUtils.EMPTY_CHAR_ARRAY; } final LineComment lastLineComment = new LineComment(); @@ -1082,7 +1082,7 @@ public class Scribe { boolean hasComment= false; boolean hasLineComment= false; boolean hasWhitespace= false; - char[] whiteSpaces= EMPTY_CHAR_ARRAY; + char[] whiteSpaces= CharArrayUtils.EMPTY_CHAR_ARRAY; int lines= 0; while ((currentToken= scanner.nextToken()) != null) { if (skipOverInactive) { @@ -1243,7 +1243,7 @@ public class Scribe { lastLineComment.leadingSpaces = whiteSpaces; lastLineComment.lines = lines; } - whiteSpaces= EMPTY_CHAR_ARRAY; + whiteSpaces= CharArrayUtils.EMPTY_CHAR_ARRAY; hasWhitespace= false; printLineComment(); currentTokenStartPosition= scanner.getCurrentPosition(); @@ -1260,7 +1260,7 @@ public class Scribe { } else if (hasWhitespace) { space(); } - whiteSpaces= EMPTY_CHAR_ARRAY; + whiteSpaces= CharArrayUtils.EMPTY_CHAR_ARRAY; hasWhitespace= false; printBlockComment(false); currentTokenStartPosition= scanner.getCurrentPosition(); @@ -1280,7 +1280,7 @@ public class Scribe { // printNewLine(scanner.getCurrentTokenStartPosition()); } } - whiteSpaces= EMPTY_CHAR_ARRAY; + whiteSpaces= CharArrayUtils.EMPTY_CHAR_ARRAY; hasWhitespace= false; printPreprocessorDirective(); printNewLine(); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index dac004425f9..8b832972a30 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -1865,6 +1865,20 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //#define MACRO(a) a(const a&); void operator=(const a&) + // + //class Test{MACRO(Test);}; + + //#define MACRO(a) a(const a&); void operator=(const a&) + // + //class Test { + // MACRO(Test); + //}; + public void testMacroDeclaration() throws Exception { + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); + assertFormatterResult(); + } + //bool member __attribute__ ((__unused__)) = false; //bool member __attribute__ ((__unused__)) = false; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/ChangeBuildConfigActionBase.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/ChangeBuildConfigActionBase.java index 57c48e47a9c..b9f57b438b7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/ChangeBuildConfigActionBase.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/ChangeBuildConfigActionBase.java @@ -307,46 +307,53 @@ public class ChangeBuildConfigActionBase { action.setEnabled(enable); // Bug 375760 + // If focus is on a view that doesn't provide a resource/project context. Use the selection in a + // project/resource view. We support three views. If more than one is open, nevermind. If there's only + // one project in the workspace and it's a CDT one, use it unconditionally. // - // We shouldn't require that the projects view have focus. If the selection switched - // to something that doesn't provide us a project context, query any of the three projects/resources - // view to see if they have a selection. If so, try again using that selection. We give precedence to - // the CDT projects view, then to the project explorer, and finally to the resource navigator - // - // Also, if the view has no selection, see if the workspace has only one project. If so, we don't need - // to rely on the selection mechanism to tell us which project to operate on! + // Note that whatever project we get here is just a candidate; it's tested for suitability when we + // call ourselves recursively // if (badObject || fProjects.isEmpty()) { - IWorkbenchPage page = CUIPlugin.getActivePage(); - if (page != null) { - IViewReference viewRef = page.findViewReference("org.eclipse.cdt.ui.CView"); //$NON-NLS-1$ - if (viewRef == null) { - viewRef = page.findViewReference("org.eclipse.ui.navigator.ProjectExplorer"); //$NON-NLS-1$ - if (viewRef == null) { - viewRef = page.findViewReference("org.eclipse.ui.views.ResourceNavigator"); //$NON-NLS-1$ - } + // Check for lone CDT project in workspace + IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); + if (projects != null && projects.length == 1) { + IProject project = projects[0]; + if (CoreModel.getDefault().isNewStyleProject(project) && (getCfgs(project).length > 0)) { + onSelectionChanged(action, new ImaginarySelection(project)); + return; } - if (viewRef != null) { - IViewPart view = viewRef.getView(false); + } + + // Check the three supported views + IWorkbenchPage page = CUIPlugin.getActivePage(); + int viewCount = 0; + if (page != null) { + IViewReference theViewRef = null; + IViewReference viewRef = null; + + theViewRef = page.findViewReference("org.eclipse.cdt.ui.CView"); //$NON-NLS-1$ + viewCount += (theViewRef != null) ? 1 : 0; + + viewRef = page.findViewReference("org.eclipse.ui.navigator.ProjectExplorer"); //$NON-NLS-1$ + viewCount += (viewRef != null) ? 1 : 0; + theViewRef = (theViewRef == null) ? viewRef : theViewRef; + + viewRef = page.findViewReference("org.eclipse.ui.views.ResourceNavigator"); //$NON-NLS-1$ + viewCount += (viewRef != null) ? 1 : 0; + theViewRef = (theViewRef == null) ? viewRef : theViewRef; + + if (theViewRef != null && viewCount == 1) { + IViewPart view = theViewRef.getView(false); if (view != null) { ISelection cdtSelection = view.getSite().getSelectionProvider().getSelection(); if (cdtSelection != null) { - if (cdtSelection.isEmpty()) { - IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - if (projects != null && projects.length == 1) { - IProject project = projects[0]; - if (CoreModel.getDefault().isNewStyleProject(project) && (getCfgs(project).length > 0)) { - onSelectionChanged(action, new ImaginarySelection(project)); - } - } - } - else { - if (!cdtSelection.equals(selection)) { + if (!cdtSelection.isEmpty()) { + if (!cdtSelection.equals(selection)) { // avoids infinite recursion onSelectionChanged(action, cdtSelection); } } } - } } } diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/ExpressionManagerVMNode.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/ExpressionManagerVMNode.java index a5098e6059f..7061cbe5d13 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/ExpressionManagerVMNode.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/ExpressionManagerVMNode.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.dsf.debug.ui.viewmodel.expression; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -25,7 +26,6 @@ import org.eclipse.cdt.dsf.ui.viewmodel.VMDelta; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IExpressionManager; import org.eclipse.debug.core.model.IExpression; -import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementEditor; @@ -37,6 +37,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationCont import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ICellModifier; import org.eclipse.jface.viewers.TextCellEditor; @@ -124,7 +125,12 @@ public class ExpressionManagerVMNode extends AbstractVMNode // local state data, so we don't bother using a job to perform this // operation. for (int i = 0; i < updates.length; i++) { - updates[i].setHasChilren(fManager.getExpressions().length != 0); + boolean hasChildren = fManager.getExpressions().length != 0; + if (!hasChildren && updates[i].getPresentationContext().getColumns() != null) { + hasChildren = true; + } + + updates[i].setHasChilren(hasChildren); updates[i].done(); } } @@ -136,7 +142,14 @@ public class ExpressionManagerVMNode extends AbstractVMNode // We assume that the getExpressions() will just read local state data, // so we don't bother using a job to perform this operation. - update.setChildCount(fManager.getExpressions().length + 1); + int count = fManager.getExpressions().length; + + // Account for "Add New Expression" element + if (update.getPresentationContext().getColumns() != null) { + count += 1; + } + + update.setChildCount(count); update.done(); } } @@ -168,7 +181,12 @@ public class ExpressionManagerVMNode extends AbstractVMNode length = expressions.length; } final int highOffset= lowOffset + length; - for (int i = lowOffset; i < highOffset && i < expressions.length + 1; i++) { + // If columns are present, add the "Add New Expression" element. + int expressionsLength = expressions.length; + if (update.getPresentationContext().getColumns() != null) { + expressionsLength += 1; + } + for (int i = lowOffset; i < highOffset && i < expressionsLength; i++) { if (i < expressions.length) { multiRmCount++; final int childIndex = i; @@ -225,22 +243,26 @@ public class ExpressionManagerVMNode extends AbstractVMNode */ private void updateNewExpressionVMCLabel(ILabelUpdate update, NewExpressionVMC vmc) { String[] columnIds = update.getColumnIds() != null ? - update.getColumnIds() : new String[] { IDebugVMConstants.COLUMN_ID__NAME }; + update.getColumnIds() : new String[0]; for (int i = 0; i < columnIds.length; i++) { - if (IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(columnIds[i])) { + // Bug 373468: show "Add New Expression" label in name column if + // expression column is not shown. + if ( IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(columnIds[i]) || + (IDebugVMConstants.COLUMN_ID__NAME.equals(columnIds[i]) && + !Arrays.asList(columnIds).contains(IDebugVMConstants.COLUMN_ID__EXPRESSION)) ) + { update.setLabel(MessagesForExpressionVM.ExpressionManagerLayoutNode__newExpression_label, i); - // TODO: replace with an API image consant after bug 313828 is addressed. - update.setImageDescriptor(DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_LCL_MONITOR_EXPRESSION), i); + update.setImageDescriptor(DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_LCL_ADD), i); FontData fontData = JFaceResources.getFontDescriptor(IDebugUIConstants.PREF_VARIABLE_TEXT_FONT).getFontData()[0]; - fontData.setStyle(SWT.ITALIC); // Bugzilla 287598: Distinguish 'Add new expression' entry from actual expressions + // Bugzilla 287598: Distinguish 'Add new expression' entry from actual expressions + fontData.setStyle(SWT.ITALIC); update.setFontData(fontData, i); } else { update.setLabel("", i); //$NON-NLS-1$ } } - update.done(); } @@ -253,6 +275,12 @@ public class ExpressionManagerVMNode extends AbstractVMNode retVal |= IModelDelta.ADDED | IModelDelta.REMOVED | IModelDelta.INSERTED | IModelDelta.CONTENT ; } + if ( event instanceof PropertyChangeEvent && + IPresentationContext.PROPERTY_COLUMNS.equals(((PropertyChangeEvent)event).getProperty()) ) + { + retVal |= IModelDelta.CONTENT; + } + for (IExpression expression : fManager.getExpressions()) { retVal |= getExpressionVMProvider().getDeltaFlagsForExpression(expression, event); } @@ -264,7 +292,14 @@ public class ExpressionManagerVMNode extends AbstractVMNode public void buildDelta(final Object event, final VMDelta parentDelta, final int nodeOffset, final RequestMonitor requestMonitor) { if (event instanceof ExpressionsChangedEvent) { buildDeltaForExpressionsChangedEvent((ExpressionsChangedEvent)event, parentDelta, nodeOffset, requestMonitor); - } else { + } + else if ( event instanceof PropertyChangeEvent && + IPresentationContext.PROPERTY_COLUMNS.equals(((PropertyChangeEvent)event).getProperty()) ) + { + parentDelta.setFlags(parentDelta.getFlags() | IModelDelta.CONTENT); + requestMonitor.done(); + } + else { // For each expression, find its corresponding node and ask that // layout node for its delta flags for given event. If there are delta flags to be @@ -322,7 +357,10 @@ public class ExpressionManagerVMNode extends AbstractVMNode */ @Override public CellEditor getCellEditor(IPresentationContext context, String columnId, Object element, Composite parent) { - if (IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(columnId)) { + if (IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(columnId) || + (IDebugVMConstants.COLUMN_ID__NAME.equals(columnId) && + !Arrays.asList(context.getColumns()).contains(IDebugVMConstants.COLUMN_ID__EXPRESSION)) ) + { return new TextCellEditor(parent); } return null; diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/WatchExpressionCellModifier.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/WatchExpressionCellModifier.java index e027284a04c..71f792b4481 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/WatchExpressionCellModifier.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/WatchExpressionCellModifier.java @@ -55,13 +55,22 @@ public class WatchExpressionCellModifier implements ICellModifier { @Override public boolean canModify(Object element, String property) { - return IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(property) && - (getWatchExpression(element) != null || element instanceof NewExpressionVMC); + if (element instanceof NewExpressionVMC) { + return IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(property) || + IDebugVMConstants.COLUMN_ID__NAME.equals(property); + } else { + return IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(property) && + getWatchExpression(element) != null; + } } @Override public Object getValue(Object element, String property) { - if (!IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(property)) return ""; //$NON-NLS-1$ + if (!IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(property) && + !IDebugVMConstants.COLUMN_ID__NAME.equals(property)) + { + return ""; //$NON-NLS-1$ + } IWatchExpression expression = getWatchExpression(element); @@ -73,7 +82,11 @@ public class WatchExpressionCellModifier implements ICellModifier { @Override public void modify(Object element, String property, Object value) { - if (!IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(property)) return; + if (!IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(property) && + !IDebugVMConstants.COLUMN_ID__NAME.equals(property)) + { + return; + } if (!(value instanceof String)) return; String origStrValue = (String) value; diff --git a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java index d6f0d88bc71..662da9896a3 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Function.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 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.lrparser.c99.bindings; @@ -34,6 +35,7 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio private boolean isRegister; private boolean isStatic; private boolean isVarArgs; + private boolean isNoReturn; // the scope that the function is in (must be the global scope, no?) private IScope scope; @@ -117,6 +119,14 @@ public class C99Function extends PlatformObject implements IC99Binding, IFunctio this.isVarArgs = isVarArgs; } + public boolean isNoReturn() { + return isNoReturn; + } + + public void setNoReturn(boolean isNoReturn) { + this.isNoReturn = isNoReturn; + } + public ILinkage getLinkage() { return Linkage.C_LINKAGE; } 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 1fb52781b78..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,12 +1,13 @@ /******************************************************************************* - * 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 * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Corporation - initial API and implementation + * IBM Corporation - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.upc.ast; @@ -18,11 +19,9 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CASTForStatement; @SuppressWarnings("restriction") public class UPCASTForallStatement extends CASTForStatement implements IUPCASTForallStatement { - private IASTExpression affinity; private boolean affinityContinue; - public UPCASTForallStatement() { } @@ -40,15 +39,10 @@ public class UPCASTForallStatement extends CASTForStatement implements IUPCASTFo @Override public UPCASTForallStatement copy(CopyStyle style) { UPCASTForallStatement copy = new UPCASTForallStatement(); - copyForStatement(copy, style); copy.setAffinityExpression(affinity == null ? null : affinity.copy(style)); - if (style == CopyStyle.withLocations) { - copy.setCopyLocation(this); - } - return copy; + return copy(copy, style); } - @Override public boolean isAffinityContinue() { return affinityContinue; @@ -61,10 +55,10 @@ public class UPCASTForallStatement extends CASTForStatement implements IUPCASTFo @Override public void setAffinityExpression(IASTExpression affinity) { - if(affinity != null) + if (affinity != null) this.affinityContinue = false; this.affinity = affinity; - if(affinity != null) { + if (affinity != null) { affinity.setParent(this); affinity.setPropertyInParent(AFFINITY); } @@ -72,43 +66,42 @@ public class UPCASTForallStatement extends CASTForStatement implements IUPCASTFo @Override public void setAffinityContinue(boolean affinityContinue) { - if(affinityContinue) + if (affinityContinue) this.affinity = null; this.affinityContinue = affinityContinue; } - @Override public boolean accept(ASTVisitor visitor) { - if(visitor.shouldVisitStatements) { - switch(visitor.visit(this)){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; + if (visitor.shouldVisitStatements) { + switch (visitor.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; } } + if (!acceptByAttributes(visitor)) return false; + IASTStatement initializer = super.getInitializerStatement(); - if(initializer != null) if(!initializer.accept(visitor)) return false; + if (initializer != null && !initializer.accept(visitor)) return false; IASTExpression condition = super.getConditionExpression(); - if(condition != null) if(!condition.accept(visitor)) return false; + if (condition != null && !condition.accept(visitor)) return false; IASTExpression iteration = super.getIterationExpression(); - if(iteration != null) if(!iteration.accept(visitor)) return false; + if (iteration != null && !iteration.accept(visitor)) return false; - if(affinity != null) if(!affinity.accept(visitor)) return false; + if (affinity != null && !affinity.accept(visitor)) return false; IASTStatement body = super.getBody(); - if(body != null) if(!body.accept(visitor)) return false; + if (body != null && !body.accept(visitor)) return false; - if(visitor.shouldVisitStatements) { - switch(visitor.leave(this)){ - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; + if (visitor.shouldVisitStatements) { + switch (visitor.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; } } - return true; } - } 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 7af6f97da17..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,26 +1,25 @@ /******************************************************************************* - * 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: + * 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 = null; - + private IASTExpression barrierExpression; public UPCASTSynchronizationStatement() { } @@ -40,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 @@ -60,7 +55,7 @@ public class UPCASTSynchronizationStatement extends ASTNode implements IUPCASTSy @Override public void setBarrierExpression(IASTExpression expr) { this.barrierExpression = expr; - if(expr != null) { + if (expr != null) { expr.setParent(this); expr.setPropertyInParent(BARRIER_EXPRESSION); } @@ -71,30 +66,24 @@ public class UPCASTSynchronizationStatement extends ASTNode implements IUPCASTSy this.statmentKind = kind; } - @Override public boolean accept(ASTVisitor visitor) { - if(visitor.shouldVisitStatements) { - switch(visitor.visit(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; + if (visitor.shouldVisitStatements) { + switch (visitor.visit(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; } } - if(barrierExpression != null) { - boolean abort = !barrierExpression.accept(visitor); - if(abort) - return false; - } + if (!acceptByAttributes(visitor)) return false; + if (barrierExpression != null && !barrierExpression.accept(visitor)) return false; - if(visitor.shouldVisitStatements) { - switch(visitor.leave(this)) { - case ASTVisitor.PROCESS_ABORT : return false; - case ASTVisitor.PROCESS_SKIP : return true; + if (visitor.shouldVisitStatements) { + switch (visitor.leave(this)) { + case ASTVisitor.PROCESS_ABORT: return false; + case ASTVisitor.PROCESS_SKIP: return true; } } - return true; } - } \ No newline at end of file