1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Merge remote-tracking branch 'cdt/master' into sd90

This commit is contained in:
Andrew Gvozdev 2012-04-14 23:29:03 -04:00
commit 7a10d644c5
132 changed files with 2570 additions and 1385 deletions

View file

@ -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;

View file

@ -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<IField> > constructorsStack = new Stack< Set<IField> >();
private boolean skipConstructorsWithFCalls = skipConstructorsWithFCalls();
@ -140,14 +138,14 @@ public class ClassMembersInitializationChecker extends AbstractIndexAstChecker {
}
}
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);
}
}

View file

@ -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<IBinding, IASTDeclarator> externFunctionDeclarations = new HashMap<IBinding, IASTDeclarator>();
private Map<IBinding, IASTDeclarator> staticFunctionDeclarations = new HashMap<IBinding, IASTDeclarator>();
@ -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

View file

@ -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();
}
}

View file

@ -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<String, String> getStdMap() {
Map<String, String> map= new HashMap<String, String>();
map.put("__SIZEOF_INT__", "4");
map.put("__SIZEOF_LONG__", "8");
return map;
}

View file

@ -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]);
}
}

View file

@ -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);

View file

@ -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() {
@ -144,6 +144,12 @@ public class CPPFunctionTests extends PDOMTestBase {
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);
}

View file

@ -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();

View file

@ -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();

View file

@ -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;
}

View file

@ -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 = {};
/**
* <code>ATTRIBUTE_ARGUMENT</code> represents the relationship between an
* <code>IASTAttribute</code> and an <code>IASTExpression</code>.
*/
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);
}

View file

@ -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);
}

View file

@ -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
* <code>IASTPointerOperator</code> to be added.
* @param operator a <code>IASTPointerOperator</code> to be added.
*/
public void addPointerOperator(IASTPointerOperator operator);

View file

@ -7,6 +7,7 @@
*
* Contributors:
* 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 {
/**
* <code>DECL_SPECIFIER</code> represents the relationship between an
* <code>IASTSimpleDeclaration</code> and it's nested

View file

@ -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 = {};
/**

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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();
}

View file

@ -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)}.
*/

View file

@ -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 {
/**
* <code>ALIAS_NAME</code> 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);
}

View file

@ -7,10 +7,12 @@
*
* Contributors:
* 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 {
/**
* <code>NAME</code> is the qualified name brought into scope.
*/

View file

@ -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:
* 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);
}

View file

@ -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
*/

View file

@ -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();
}
}

View file

@ -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.

View file

@ -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 <T, U extends Collection<T>> 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;
}
}

View file

@ -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;
}
}

View file

@ -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 extends ASTAttributeOwner> 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;
}
}

View file

@ -370,6 +370,14 @@ public abstract class ASTNode implements IASTNode {
return null;
}
protected <T extends ASTNode> 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) };
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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<IASTAttribute> __attribute_decl_seq(boolean allowAttrib, boolean allowDeclspec)
throws BacktrackException, EndOfFileException {
List<IASTAttribute> 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<IASTAttribute> __attribute__() throws BacktrackException, EndOfFileException {
if (LT(1) != IGCCToken.t__attribute__)
return;
return null;
List<IASTAttribute> 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<IASTAttribute>();
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 {

View file

@ -12,9 +12,7 @@ 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);
}

View file

@ -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 void addStatement( IASTStatement s );
public IASTStatement [] getStatements();
public void addStatement(IASTStatement s);
public IASTStatement[] getStatements();
}

View file

@ -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;

View file

@ -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;
@ -90,6 +92,17 @@ public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmb
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);

View file

@ -7,10 +7,12 @@
*
* Contributors:
* Markus Schorn - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTAttribute;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName;
@ -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;
@ -86,6 +87,16 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements
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();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2011 IBM Corporation and others.
* Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,10 +8,12 @@
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTAttribute;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -24,7 +26,6 @@ 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 IScope fScope;
@ -85,12 +86,21 @@ public class CASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbi
return stmts;
}
@Override
public IASTAttribute[] getAttributes() {
return IASTAttribute.EMPTY_ATTRIBUTE_ARRAY;
}
@Override
public void addAttribute(IASTAttribute attribute) {
throw new UnsupportedOperationException();
}
@Override
public IASTNode[] getNodes() {
return getStatements();
}
@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();
}
}

View file

@ -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

View file

@ -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);
}
}

View file

@ -8,18 +8,18 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
public class CASTBreakStatement extends ASTNode implements IASTBreakStatement {
public class CASTBreakStatement extends ASTAttributeOwner implements IASTBreakStatement {
@Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitStatements) {
@ -30,6 +30,8 @@ public class CASTBreakStatement extends ASTNode implements IASTBreakStatement {
}
}
if (!acceptByAttributes(action)) return false;
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@ -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);
}
}

View file

@ -8,6 +8,7 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@ -15,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
@ -86,8 +81,7 @@ public class CASTCaseStatement extends ASTNode implements IASTCaseStatement, IAS
@Override
public void replace(IASTNode child, IASTNode other) {
if( child == expression )
{
if (child == expression) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
expression = (IASTExpression) other;

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -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 @@
* 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,23 +59,18 @@ 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 extends CASTDeclarator> 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() {
@ -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();

View file

@ -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,18 +8,18 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
public class CASTDefaultStatement extends ASTNode implements IASTDefaultStatement {
public class CASTDefaultStatement extends ASTAttributeOwner implements IASTDefaultStatement {
@Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitStatements) {
@ -29,6 +29,9 @@ public class CASTDefaultStatement extends ASTNode implements IASTDefaultStatemen
default: break;
}
}
if (!acceptByAttributes(action)) return false;
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@ -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);
}
}

View file

@ -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,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();
@ -94,8 +87,11 @@ public class CASTDoStatement extends ASTNode implements IASTDoStatement, IASTAmb
default: break;
}
}
if( body != null ) if( !body.accept( action ) ) return false;
if( condition != null ) if( !condition.accept( action ) ) return false;
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;
@ -108,14 +104,12 @@ public class CASTDoStatement extends ASTNode implements IASTDoStatement, IASTAmb
@Override
public void replace(IASTNode child, IASTNode other) {
if( body == child )
{
if (body == child) {
other.setPropertyInParent(body.getPropertyInParent());
other.setParent(body.getParent());
body = (IASTStatement) other;
}
if( child == condition )
{
if (child == condition) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
condition = (IASTExpression) other;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2011 IBM Corporation and others.
* Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@ -15,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;
}
}
}

View file

@ -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;
@ -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);
}
}
}

View file

@ -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,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 extends CASTForStatement> 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
@ -142,10 +138,12 @@ public class CASTForStatement extends ASTNode implements IASTForStatement, IASTA
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 (!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)) {
@ -154,36 +152,30 @@ public class CASTForStatement extends ASTNode implements IASTForStatement, IASTA
default: break;
}
}
return true;
}
@Override
public void replace(IASTNode child, IASTNode other) {
if( body == child )
{
if (body == child) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
body = (IASTStatement) other;
}
if( child == init )
{
if (child == init) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
init = (IASTStatement) other;
}
if( child == iterationExpression)
{
if (child == iterationExpression) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
iterationExpression = (IASTExpression) other;
}
if( child == condition)
{
if (child == condition) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
condition = (IASTExpression) other;
}
}
}

View file

@ -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

View file

@ -8,19 +8,19 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
public class CASTGotoStatement extends ASTNode implements IASTGotoStatement {
public class CASTGotoStatement extends ASTAttributeOwner implements IASTGotoStatement {
private IASTName name;
public CASTGotoStatement() {
@ -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
@ -69,7 +65,9 @@ public class CASTGotoStatement extends ASTNode implements IASTGotoStatement {
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.shouldVisitStatements) {
switch (action.leave(this)) {

View file

@ -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,20 +18,17 @@ 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
@ -131,6 +124,9 @@ public class CASTIfStatement extends ASTNode implements IASTIfStatement, IASTAmb
default: break;
}
}
if (!((CASTIfStatement) stmt).acceptByAttributes(action)) return false;
IASTNode child = stmt.getConditionExpression();
if (child != null && !child.accept(action))
return false;
@ -165,20 +161,17 @@ public class CASTIfStatement extends ASTNode implements IASTIfStatement, IASTAmb
@Override
public void replace(IASTNode child, IASTNode other) {
if( thenClause == child )
{
if (thenClause == child) {
other.setParent(child.getParent());
other.setPropertyInParent(child.getPropertyInParent());
thenClause = (IASTStatement) other;
}
if( elseClause == child )
{
if (elseClause == child) {
other.setParent(child.getParent());
other.setPropertyInParent(child.getPropertyInParent());
elseClause = (IASTStatement) other;
}
if( child == condition )
{
if (child == condition) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
condition = (IASTExpression) other;

View file

@ -9,6 +9,7 @@
* 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,11 +26,9 @@ 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;
@ -133,9 +125,11 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn
public IASTDeclarator getDeclaratorForParameterName(IASTName name) {
boolean found= false;
for (int i= 0; i < parameterNames.length; i++) {
if (parameterNames[i] == name) found = true;
if (parameterNames[i] == name)
found = true;
}
if(!found) return null;
if (!found)
return null;
for (int i= 0; i < parameterDeclarations.length; i++) {
if (parameterDeclarations[i] instanceof IASTSimpleDeclaration) {
@ -153,8 +147,10 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn
@Override
public int getRoleForName(IASTName name) {
IASTName [] n = getParameterNames();
for( int i = 0; i < n.length; ++i )
if( n[i] == name ) return r_unclear;
for (int i = 0; i < n.length; ++i) {
if (n[i] == name)
return r_unclear;
}
return super.getRoleForName(name);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others.
* Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@ -16,13 +17,13 @@ import org.eclipse.cdt.core.dom.ast.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 CASTLabelStatement extends ASTNode implements IASTLabelStatement, IASTAmbiguityParent {
public class CASTLabelStatement extends ASTAttributeOwner implements IASTLabelStatement, IASTAmbiguityParent {
private IASTName name;
private IASTStatement nestedStatement;
@ -44,11 +45,7 @@ public class CASTLabelStatement extends ASTNode implements IASTLabelStatement, I
CASTLabelStatement copy = new CASTLabelStatement();
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
@ -75,8 +72,11 @@ public class CASTLabelStatement extends ASTNode implements IASTLabelStatement, I
default: break;
}
}
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;

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
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.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTInternalNameOwner;
@ -33,7 +34,6 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalNameOwner;
public class CASTName extends ASTNode implements IASTName, IASTCompletionContext {
private final char[] name;
private static final char[] EMPTY_CHAR_ARRAY = {};
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private IBinding binding;
@ -43,7 +43,7 @@ public class CASTName extends ASTNode implements IASTName, IASTCompletionContext
}
public CASTName() {
name = EMPTY_CHAR_ARRAY;
name = CharArrayUtils.EMPTY_CHAR_ARRAY;
}
@Override
@ -107,7 +107,7 @@ public class CASTName extends ASTNode implements IASTName, IASTCompletionContext
@Override
public String toString() {
if (name == EMPTY_CHAR_ARRAY)
if (name == CharArrayUtils.EMPTY_CHAR_ARRAY)
return EMPTY_STRING;
return new String(name);
}

View file

@ -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,18 +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.IASTNullStatement;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
public class CASTNullStatement extends ASTNode implements IASTNullStatement {
public class CASTNullStatement extends ASTAttributeOwner implements IASTNullStatement {
@Override
public boolean accept(ASTVisitor action) {
if (action.shouldVisitStatements) {
@ -29,6 +29,9 @@ public class CASTNullStatement extends ASTNode implements IASTNullStatement {
default: break;
}
}
if (!acceptByAttributes(action)) return false;
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@ -47,10 +50,6 @@ public class CASTNullStatement extends ASTNode implements IASTNullStatement {
@Override
public CASTNullStatement copy(CopyStyle style) {
CASTNullStatement copy = new CASTNullStatement();
copy.setOffsetAndLength(this);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
}

View file

@ -19,8 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
/**
* @author jcamelon
*/
public class CASTProblemDeclaration extends CASTProblemOwner implements
IASTProblemDeclaration {
public class CASTProblemDeclaration extends CASTProblemOwner implements IASTProblemDeclaration {
public CASTProblemDeclaration() {
super();
@ -38,11 +37,7 @@ public class CASTProblemDeclaration extends CASTProblemOwner implements
@Override
public CASTProblemDeclaration copy(CopyStyle style) {
CASTProblemDeclaration copy = new CASTProblemDeclaration();
copyBaseProblem(copy, style);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override
@ -54,7 +49,9 @@ public class CASTProblemDeclaration extends CASTProblemOwner implements
default: break;
}
}
super.accept(action); // visits the problem
if (action.shouldVisitDeclarations) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;

View file

@ -37,11 +37,7 @@ public class CASTProblemExpression extends CASTProblemOwner implements IASTProbl
@Override
public CASTProblemExpression copy(CopyStyle style) {
CASTProblemExpression copy = new CASTProblemExpression();
copyBaseProblem(copy, style);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override
@ -53,7 +49,9 @@ public class CASTProblemExpression extends CASTProblemOwner implements IASTProbl
default: break;
}
}
super.accept(action); // visits the problem
if (action.shouldVisitExpressions) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;

View file

@ -20,7 +20,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
* @author jcamelon
*/
abstract class CASTProblemOwner extends ASTNode implements IASTProblemHolder {
private IASTProblem problem;
public CASTProblemOwner() {
@ -30,9 +29,9 @@ abstract class CASTProblemOwner extends ASTNode implements IASTProblemHolder {
setProblem(problem);
}
protected void copyBaseProblem(CASTProblemOwner copy, CopyStyle style) {
protected <T extends CASTProblemOwner> T copy(T copy, CopyStyle style) {
copy.setProblem(problem == null ? null : problem.copy(style));
copy.setOffsetAndLength(this);
return super.copy(copy, style);
}
@Override

View file

@ -9,10 +9,12 @@
* IBM - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTAttribute;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
@ -36,11 +38,7 @@ public class CASTProblemStatement extends CASTProblemOwner implements IASTProble
@Override
public CASTProblemStatement copy(CopyStyle style) {
CASTProblemStatement copy = new CASTProblemStatement();
copyBaseProblem(copy, style);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override
@ -52,7 +50,9 @@ public class CASTProblemStatement extends CASTProblemOwner implements IASTProble
default: break;
}
}
super.accept(action); // visits the problem
if (action.shouldVisitStatements) {
switch (action.leave(this)) {
case ASTVisitor.PROCESS_ABORT: return false;
@ -62,4 +62,15 @@ public class CASTProblemStatement extends CASTProblemOwner implements IASTProble
}
return true;
}
@Override
public IASTAttribute[] getAttributes() {
return IASTAttribute.EMPTY_ATTRIBUTE_ARRAY;
}
@Override
public void addAttribute(IASTAttribute attribute) {
assertNotFrozen();
// Ignore.
}
}

View file

@ -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;

View file

@ -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
@ -99,8 +95,9 @@ public class CASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclarat
}
}
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))

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2011 IBM Corporation and others.
* Copyright (c) 2005, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors:
* IBM Rational Software - Initial API and implementation
* Yuan Zhang / Beth Tibbitts (IBM Research)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@ -16,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
@ -92,8 +88,10 @@ public class CASTSwitchStatement extends ASTNode implements
default: break;
}
}
if( controller != null ) if( !controller.accept( action ) ) return false;
if( body != null ) if( !body.accept( action ) ) return false;
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)) {
@ -107,14 +105,12 @@ public class CASTSwitchStatement extends ASTNode implements
@Override
public void replace(IASTNode child, IASTNode other) {
if( body == child )
{
if (body == child) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
body = (IASTStatement) other;
}
if( child == controller )
{
if (child == controller) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
controller = (IASTExpression) other;

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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);
@ -393,6 +401,16 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
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);

View file

@ -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

View file

@ -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);

View file

@ -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,6 +1338,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
// Accept __attribute__ or __declspec between pointer operators and declarator.
List<IASTAttribute> attributes =
__attribute_decl_seq(supportAttributeSpecifiers, supportDeclspecSpecifiers);
// Look for identifier or nested declarator
@ -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<IASTPointerOperator> pointerOps,
final IASTName declaratorName, final IASTDeclarator nestedDeclarator,
final int startingOffset, int endOffset,
List<IASTAttribute> 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;
}

View file

@ -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;
@ -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

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2011 IBM Wind River Systems, Inc. and others.
* Copyright (c) 2009, 2012 IBM Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,10 +7,12 @@
*
* Contributors:
* Markus Schorn - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTAttribute;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName;
@ -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;
@ -98,7 +99,6 @@ public class CPPASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implement
IASTDeclarator dtor= fSimpleDecl.getDeclarators()[0];
dtor.accept(resolver);
// find nested names
final NameCollector nameCollector= new NameCollector();
dtor.accept(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);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2011 IBM Corporation and others.
* Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,10 +8,12 @@
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTAttribute;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -23,9 +25,7 @@ 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 {
public class CPPASTAmbiguousStatement extends ASTAmbiguousNode implements IASTAmbiguousStatement {
private IASTStatement[] stmts = new IASTStatement[2];
private int stmtsPos= -1;
private IScope fScope;
@ -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();
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2011 IBM Corporation and others.
* Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* IBM - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -14,14 +15,14 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.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
@ -71,7 +68,9 @@ public class CPPASTCaseStatement extends ASTNode implements IASTCaseStatement, I
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)) {
@ -85,12 +84,10 @@ public class CPPASTCaseStatement extends ASTNode implements IASTCaseStatement, I
@Override
public void replace(IASTNode child, IASTNode other) {
if( child == expression )
{
if (child == expression) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
expression = (IASTExpression) other;
}
}
}

View file

@ -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;

View file

@ -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());

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -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
@ -13,6 +13,7 @@
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) {

View file

@ -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);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2011 IBM Corporation and others.
* Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* IBM - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -15,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
@ -91,8 +87,11 @@ public class CPPASTDoStatement extends ASTNode implements IASTDoStatement, IASTA
default: break;
}
}
if( body != null ) if( !body.accept( action ) ) return false;
if( condition != null ) if( !condition.accept( action ) ) return false;
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;
@ -105,14 +104,12 @@ public class CPPASTDoStatement extends ASTNode implements IASTDoStatement, IASTA
@Override
public void replace(IASTNode child, IASTNode other) {
if( body == child )
{
if (body == child) {
other.setPropertyInParent(body.getPropertyInParent());
other.setParent(body.getParent());
body = (IASTStatement) other;
}
if( child == condition )
{
if (child == condition) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());
condition = (IASTExpression) other;

View file

@ -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;

View file

@ -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;

View file

@ -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,22 +7,21 @@
*
* Contributors:
* IBM - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
/**
* @author jcamelon
*/
public class CPPASTGotoStatement extends ASTNode implements IASTGotoStatement {
public class CPPASTGotoStatement extends ASTAttributeOwner implements IASTGotoStatement {
private IASTName name;
public CPPASTGotoStatement() {
}
@ -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
@ -69,7 +64,9 @@ public class CPPASTGotoStatement extends ASTNode implements IASTGotoStatement {
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.shouldVisitStatements) {
switch (action.leave(this)) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2011 IBM Corporation and others.
* Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors:
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -19,13 +20,13 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
/**
* If statement in C++
*/
public class CPPASTIfStatement extends ASTNode implements ICPPASTIfStatement, IASTAmbiguityParent {
public class CPPASTIfStatement extends ASTAttributeOwner implements ICPPASTIfStatement, IASTAmbiguityParent {
private IASTExpression condition;
private IASTStatement thenClause;
private IASTStatement elseClause;
@ -59,11 +60,7 @@ public class CPPASTIfStatement extends ASTNode implements ICPPASTIfStatement, IA
copy.setConditionExpression(condition == null ? null : condition.copy(style));
copy.setThenClause(thenClause == null ? null : thenClause.copy(style));
copy.setElseClause(elseClause == null ? null : elseClause.copy(style));
copy.setOffsetAndLength(this);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override
@ -135,6 +132,9 @@ public class CPPASTIfStatement extends ASTNode implements ICPPASTIfStatement, IA
default: break;
}
}
if (!((CPPASTIfStatement) stmt).acceptByAttributes(action)) return false;
IASTNode child = stmt.getConditionExpression();
if (child != null && !child.accept(action))
return false;
@ -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;

View file

@ -26,8 +26,7 @@ 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 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;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2011 IBM Corporation and others.
* Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* IBM - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -15,19 +16,17 @@ 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
@ -77,8 +72,10 @@ public class CPPASTLabelStatement extends ASTNode implements
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)) {
@ -113,12 +110,10 @@ public class CPPASTLabelStatement extends ASTNode implements
@Override
public void replace(IASTNode child, IASTNode other) {
if( child == nestedStatement )
{
if (child == nestedStatement) {
other.setParent(this);
other.setPropertyInParent(child.getPropertyInParent());
setNestedStatement((IASTStatement) other);
}
}
}

View file

@ -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);
}
}

View file

@ -36,11 +36,7 @@ public class CPPASTProblemDeclaration extends CPPASTProblemOwner implements IAST
@Override
public CPPASTProblemDeclaration copy(CopyStyle style) {
CPPASTProblemDeclaration copy = new CPPASTProblemDeclaration();
copyBaseProblem(copy, style);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override
@ -62,5 +58,4 @@ public class CPPASTProblemDeclaration extends CPPASTProblemOwner implements IAST
}
return true;
}
}

View file

@ -36,11 +36,7 @@ public class CPPASTProblemExpression extends CPPASTProblemOwner implements IASTP
@Override
public CPPASTProblemExpression copy(CopyStyle style) {
CPPASTProblemExpression copy = new CPPASTProblemExpression();
copyBaseProblem(copy, style);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override

View file

@ -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;
@ -20,10 +21,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
* @author jcamelon
*/
abstract class CPPASTProblemOwner extends ASTNode implements IASTProblemHolder {
private IASTProblem problem;
public CPPASTProblemOwner() {
}
@ -31,9 +30,9 @@ abstract class CPPASTProblemOwner extends ASTNode implements IASTProblemHolder {
setProblem(problem);
}
protected void copyBaseProblem(CPPASTProblemOwner copy, CopyStyle style) {
protected <T extends CPPASTProblemOwner> T copy(T copy, CopyStyle style) {
copy.setProblem(problem == null ? null : problem.copy(style));
copy.setOffsetAndLength(this);
return super.copy(copy, style);
}
@Override

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2011 IBM Corporation and others.
* Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -8,10 +8,12 @@
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTAttribute;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
@ -36,11 +38,7 @@ public class CPPASTProblemStatement extends CPPASTProblemOwner implements IASTPr
@Override
public CPPASTProblemStatement copy(CopyStyle style) {
CPPASTProblemStatement copy = new CPPASTProblemStatement();
copyBaseProblem(copy, style);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override
@ -62,4 +60,15 @@ public class CPPASTProblemStatement extends CPPASTProblemOwner implements IASTPr
}
return true;
}
@Override
public IASTAttribute[] getAttributes() {
return IASTAttribute.EMPTY_ATTRIBUTE_ARRAY;
}
@Override
public void addAttribute(IASTAttribute attribute) {
assertNotFrozen();
// Ignore.
}
}

View file

@ -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;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2011 Wind River Systems, Inc. and others.
* Copyright (c) 2010, 2012 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* Markus Schorn - Initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -25,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.internal.core.dom.parser.ASTAttributeOwner;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
@ -34,7 +36,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
/**
* Range based for loop in c++.
*/
public class CPPASTRangeBasedForStatement extends ASTNode implements ICPPASTRangeBasedForStatement, IASTAmbiguityParent {
public class CPPASTRangeBasedForStatement extends ASTAttributeOwner
implements ICPPASTRangeBasedForStatement, IASTAmbiguityParent {
private IScope fScope;
private IASTDeclaration fDeclaration;
private IASTInitializerClause fInitClause;
@ -55,11 +58,7 @@ public class CPPASTRangeBasedForStatement extends ASTNode implements ICPPASTRang
copy.setDeclaration(fDeclaration == null ? null : fDeclaration.copy(style));
copy.setInitializerClause(fInitClause == null ? null : fInitClause.copy(style));
copy.setBody(fBody == null ? null : fBody.copy(style));
copy.setOffsetAndLength(this);
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
}
return copy;
return copy(copy, style);
}
@Override
@ -183,6 +182,8 @@ public class CPPASTRangeBasedForStatement extends ASTNode implements ICPPASTRang
default: break;
}
}
if (!acceptByAttributes(action)) return false;
if (fDeclaration != null && !fDeclaration.accept(action))
return false;
if (fInitClause != null && !fInitClause.accept(action))

View file

@ -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)) {

View file

@ -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
@ -73,10 +75,6 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
}
}
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++) {
@ -129,5 +128,4 @@ public class CPPASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclar
}
}
}
}

Some files were not shown because too many files have changed in this diff Show more