1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

bug 256125 - Introduce factories for AST nodes. Freeze the AST returned by the parser.

This commit is contained in:
Mike Kucera 2008-12-04 15:13:40 +00:00
parent d10ad69f49
commit 9c1746c42a
179 changed files with 1434 additions and 2130 deletions

View file

@ -2019,8 +2019,8 @@ public class CompleteParser2Tests extends BaseTestCase {
writer.write("void foo() "); //$NON-NLS-1$ writer.write("void foo() "); //$NON-NLS-1$
writer.write("{ "); //$NON-NLS-1$ writer.write("{ "); //$NON-NLS-1$
writer.write(" if (0) { } "); //$NON-NLS-1$ writer.write(" if (0) { } "); //$NON-NLS-1$
writer.write(" /* 5,000 else if's. */ "); //$NON-NLS-1$ writer.write(" /* 3,000 else if's. */ "); //$NON-NLS-1$
writer.write(" THOU THOU THOU THOU THOU "); //$NON-NLS-1$ writer.write(" THOU THOU THOU "); //$NON-NLS-1$
writer.write("} "); //$NON-NLS-1$ writer.write("} "); //$NON-NLS-1$
parse( writer.toString() ); parse( writer.toString() );

View file

@ -184,4 +184,13 @@ public interface IASTNode {
* @since 5.1 * @since 5.1
*/ */
public IToken getTrailingSyntax() throws ExpansionOverlapsBoundaryException, UnsupportedOperationException; public IToken getTrailingSyntax() throws ExpansionOverlapsBoundaryException, UnsupportedOperationException;
/**
* Returns true if this node is frozen, false otherwise.
* If the node is frozen then any attempt to call a method that changes
* the node's state will result in an IllegalStateException.
* @since 5.1
*/
public boolean isFrozen();
} }

View file

@ -274,4 +274,22 @@ public interface IASTTranslationUnit extends IASTNode, IAdaptable {
* Sets whether this ast represents a header file. * Sets whether this ast represents a header file.
*/ */
public void setIsHeaderUnit(boolean headerUnit); public void setIsHeaderUnit(boolean headerUnit);
/**
* Returns the node factory that was used to build the AST.
*
* @noreference This method is not intended to be referenced by clients.
* @since 5.1
*/
public INodeFactory getASTNodeFactory();
/**
* Causes this node and all the nodes rooted at this node to become immutable.
* Once the AST is frozen any calls to set or add methods on any of the nodes
* in the AST will result in an IllegalStateException.
*
* @noreference This method is not intended to be referenced by clients.
* @since 5.1
*/
public void freeze();
} }

View file

@ -8,78 +8,47 @@
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action; package org.eclipse.cdt.core.dom.ast;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
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.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTProblemExpression;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
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.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
/** /**
* Abstract factory interface for creating AST node objects. * Factory for creating AST nodes. This interface contains factory methods
* for nodes that are available for both C and C++.
*
* Extending interfaces should use covariant return types where appropriate to
* allow the construction of language-specific versions of certain nodes.
*
* Most methods accept child nodes as parameters when constructing a new node.
* For convenience it is always allowed to pass null for any of these parameters.
* In this case the newly constructed node may be initialized using its
* set() and add() methods instead.
*
* Nodes created by this factory are not frozen, i.e. for any node created by this
* factory the following holds <code> node.isFrozen() == false </code>.
*
* None of the factory methods should return null.
* *
* @author Mike Kucera * @author Mike Kucera
* @since 5.1
*/ */
@SuppressWarnings("restriction") public interface INodeFactory {
public interface IASTNodeFactory {
/**
* Creates a "dummy" name using an empty char array.
*/
public IASTName newName();
public IASTName newName(char[] name); public IASTName newName(char[] name);
public IASTName newName(); /**
* Calling the method getASTNodeFactory() on the translation unit returned by this
* method will return the node factory that was used to create the IASTTranslationUnit.
*/
public IASTTranslationUnit newTranslationUnit();
// TODO this should return IASTCompletionNode
public ASTCompletionNode newCompletionNode(String prefix, IASTTranslationUnit tu);
public IASTLiteralExpression newLiteralExpression(int kind, String rep); public IASTLiteralExpression newLiteralExpression(int kind, String rep);
@ -111,7 +80,7 @@ public interface IASTNodeFactory {
public IASTCompoundStatement newCompoundStatement(); public IASTCompoundStatement newCompoundStatement();
public IASTSwitchStatement newSwitchStatment(IASTExpression controller, IASTStatement body); public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body);
public IASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause); public IASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause);
@ -147,17 +116,15 @@ public interface IASTNodeFactory {
public IASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier, public IASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
IASTFunctionDeclarator declarator, IASTStatement bodyStatement); IASTFunctionDeclarator declarator, IASTStatement bodyStatement);
public IASTTranslationUnit newTranslationUnit();
public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name); public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name);
public IASTASMDeclaration newASMDeclaration(String assembly); public IASTASMDeclaration newASMDeclaration(String assembly);
public IASTProblemDeclaration newProblemDeclaration(); public IASTProblemDeclaration newProblemDeclaration(IASTProblem problem);
public IASTProblemStatement newProblemStatement(); public IASTProblemStatement newProblemStatement(IASTProblem problem);
public IASTProblemExpression newProblemExpression(); public IASTProblemExpression newProblemExpression(IASTProblem problem);
public IASTProblem newProblem(int id, char[] arg, boolean error); public IASTProblem newProblem(int id, char[] arg, boolean error);
@ -175,10 +142,16 @@ public interface IASTNodeFactory {
public IASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize); public IASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize);
public IASTAmbiguousStatement newAmbiguousStatement(IASTStatement... statements); public IASTSimpleDeclSpecifier newSimpleDeclSpecifier();
public IASTAmbiguousExpression newAmbiguousExpression(IASTExpression... expressions); public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement);
public IASTDeclSpecifier newSimpleDeclSpecifier(); public IASTPointer newPointer();
public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner);
public IASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name);
public IASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
} }

View file

@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.c;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.INodeFactory;
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.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
/**
* Factory for AST nodes for the C programming language.
*
* @author Mike Kucera
* @since 5.1
*/
public interface ICNodeFactory extends INodeFactory {
public ICASTEnumerationSpecifier newEnumerationSpecifier(IASTName name);
public ICASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name);
public ICASTSimpleDeclSpecifier newSimpleDeclSpecifier();
public ICASTPointer newPointer();
public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name);
public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
public ICASTArrayModifier newModifiedArrayModifier(IASTExpression expr);
public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer);
public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator(IASTName[] parameterNames, IASTDeclaration[] parameterDeclarations);
public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializer rhs);
public ICASTArrayDesignator newArrayDesignator(IASTExpression exp);
public ICASTFieldDesignator newFieldDesignator(IASTName name);
public IGCCASTArrayRangeDesignator newArrayRangeDesignatorGCC(IASTExpression floor, IASTExpression ceiling);
public IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression);
}

View file

@ -0,0 +1,157 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.INodeFactory;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
/**
* Factory for AST nodes for the C++ programming language.
*
* @author Mike Kucera
* @since 5.1
*/
public interface ICPPNodeFactory extends INodeFactory {
public ICPPASTTranslationUnit newTranslationUnit();
public ICPPASTLiteralExpression newLiteralExpression(int kind, String rep);
public ICPPASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand);
public ICPPASTCastExpression newCastExpression(int operator, IASTTypeId typeId, IASTExpression operand);
public ICPPASTBinaryExpression newBinaryExpression(int op, IASTExpression expr1, IASTExpression expr2);
public ICPPASTTypeIdExpression newTypeIdExpression(int operator, IASTTypeId typeId);
public ICPPASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
IASTFunctionDeclarator declarator, IASTStatement bodyStatement);
public ICPPASTFunctionDeclarator newFunctionDeclarator(IASTName name);
public ICPPASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name);
public ICPPASTParameterDeclaration newParameterDeclaration(IASTDeclSpecifier declSpec, IASTDeclarator declarator);
public ICPPASTSimpleDeclSpecifier newSimpleDeclSpecifier();
public ICPPASTOperatorName newOperatorName(char[] name);
public ICPPASTNewExpression newNewExpression(IASTExpression placement, IASTExpression initializer, IASTTypeId typeId);
public ICPPASTFieldReference newFieldReference(IASTName name, IASTExpression owner);
public ICPPASTTemplateId newTemplateId(IASTName templateName);
public ICPPASTConversionName newConversionName(char[] name, IASTTypeId typeId);
public ICPPASTQualifiedName newQualifiedName();
public ICPPASTSwitchStatement newSwitchStatement(IASTExpression controlloer, IASTStatement body);
public ICPPASTSwitchStatement newSwitchStatement(IASTDeclaration controller, IASTStatement body);
public ICPPASTSwitchStatement newSwitchStatement();
public ICPPASTIfStatement newIfStatement(IASTExpression condition, IASTStatement then, IASTStatement elseClause);
public ICPPASTIfStatement newIfStatement(IASTDeclaration condition, IASTStatement then, IASTStatement elseClause);
public ICPPASTIfStatement newIfStatement();
public ICPPASTForStatement newForStatement(IASTStatement init, IASTExpression condition,
IASTExpression iterationExpression, IASTStatement body);
public ICPPASTForStatement newForStatement(IASTStatement init, IASTDeclaration condition,
IASTExpression iterationExpression, IASTStatement body);
public ICPPASTForStatement newForStatement();
public ICPPASTWhileStatement newWhileStatement(IASTExpression condition, IASTStatement body);
public ICPPASTWhileStatement newWhileStatement(IASTDeclaration condition, IASTStatement body);
public ICPPASTWhileStatement newWhileStatement();
public ICPPASTDeleteExpression newDeleteExpression(IASTExpression operand);
public IGPPASTSimpleDeclSpecifier newSimpleDeclSpecifierGPP();
public ICPPASTSimpleTypeConstructorExpression newSimpleTypeConstructorExpression(int type, IASTExpression expression);
public ICPPASTTypenameExpression newTypenameExpression(IASTName qualifiedName, IASTExpression expr, boolean isTemplate);
public ICPPASTNamespaceAlias newNamespaceAlias(IASTName alias, IASTName qualifiedName);
public ICPPASTUsingDeclaration newUsingDeclaration(IASTName name);
public ICPPASTUsingDirective newUsingDirective(IASTName name);
public ICPPASTLinkageSpecification newLinkageSpecification(String literal);
public ICPPASTNamespaceDefinition newNamespaceDefinition(IASTName name);
public ICPPASTTemplateDeclaration newTemplateDeclaration(IASTDeclaration declaration);
public ICPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiation(IASTDeclaration declaration);
public IGPPASTExplicitTemplateInstantiation newExplicitTemplateInstantiationGPP(IASTDeclaration declaration);
public ICPPASTTemplateSpecialization newTemplateSpecialization(IASTDeclaration declaration);
public ICPPASTTryBlockStatement newTryBlockStatement(IASTStatement body);
public ICPPASTCatchHandler newCatchHandler(IASTDeclaration decl, IASTStatement body);
public ICPPASTVisibilityLabel newVisibilityLabel(int visibility);
public ICPPASTBaseSpecifier newBaseSpecifier(IASTName name, int visibility, boolean isVirtual);
public ICPPASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
public ICPPASTNamedTypeSpecifier newTypedefNameSpecifier(IASTName name);
public IGPPASTPointer newPointerGPP();
public ICPPASTReferenceOperator newReferenceOperator();
public ICPPASTPointerToMember newPointerToMember(IASTName name);
public IGPPASTPointerToMember newPointerToMemberGPP(IASTName name);
public ICPPASTConstructorInitializer newConstructorInitializer(IASTExpression exp);
public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName memberInitializerId, IASTExpression initializerValue);
public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
IASTStatement bodyStatement);
public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId);
public ICPPASTTemplatedTypeTemplateParameter newTemplatedTypeTemplateParameter(IASTName name, IASTExpression defaultValue);
public IASTProblemTypeId newProblemTypeId(IASTProblem problem);
}

View file

@ -32,8 +32,11 @@ public interface ISourceCodeParser {
/** /**
* Compute an abstract syntax tree (AST). * Compute an abstract syntax tree (AST).
* @return the AST, should not return <code>null</code>
* *
* The returned AST is frozen, any attempt modify any of the nodes in
* the AST will result in an IllegalStateException.
*
* @return the AST, should not return <code>null</code>
* @throws ParseError if parsing has been cancelled or for other reasons * @throws ParseError if parsing has been cancelled or for other reasons
*/ */
public IASTTranslationUnit parse(); public IASTTranslationUnit parse();

View file

@ -37,6 +37,7 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);
@ -49,6 +50,7 @@ public abstract class ASTEnumerator extends ASTNode implements IASTEnumerator, I
} }
public void setValue(IASTExpression expression) { public void setValue(IASTExpression expression) {
assertNotFrozen();
this.value = expression; this.value = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -40,6 +40,8 @@ public abstract class ASTNode implements IASTNode {
private int length; private int length;
private int offset; private int offset;
private boolean frozen = false;
public IASTNode getParent() { public IASTNode getParent() {
return parent; return parent;
} }
@ -49,7 +51,26 @@ public abstract class ASTNode implements IASTNode {
return collector.getChildren(); return collector.getChildren();
} }
public boolean isFrozen() {
return frozen;
}
public void freeze() {
frozen = true;
for(IASTNode child : getChildren()) {
if(child != null) {
((ASTNode)child).freeze();
}
}
}
protected void assertNotFrozen() throws IllegalStateException {
if(frozen)
throw new IllegalStateException("attempt to modify frozen AST node"); //$NON-NLS-1$
}
public void setParent(IASTNode node) { public void setParent(IASTNode node) {
assertNotFrozen();
this.parent = node; this.parent = node;
} }
@ -58,6 +79,7 @@ public abstract class ASTNode implements IASTNode {
} }
public void setPropertyInParent(ASTNodeProperty property) { public void setPropertyInParent(ASTNodeProperty property) {
assertNotFrozen();
this.property = property; this.property = property;
} }

View file

@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.INodeFactory;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexFileSet;
@ -58,6 +59,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
private IIndex fIndex; private IIndex fIndex;
private boolean fIsHeader= true; private boolean fIsHeader= true;
private IIndexFileSet fIndexFileSet; private IIndexFileSet fIndexFileSet;
private INodeFactory fNodeFactory;
@Override @Override
public final IASTTranslationUnit getTranslationUnit() { public final IASTTranslationUnit getTranslationUnit() {
@ -280,6 +282,14 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
} }
} }
public final INodeFactory getASTNodeFactory() {
return fNodeFactory;
}
public final void setASTNodeFactory(INodeFactory nodeFactory) {
this.fNodeFactory = nodeFactory;
}
public final IASTComment[] getComments() { public final IASTComment[] getComments() {
if (fLocationResolver != null) { if (fLocationResolver != null) {
return fLocationResolver.getComments(); return fLocationResolver.getComments();

View file

@ -62,6 +62,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement; import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.INodeFactory;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
@ -76,6 +77,7 @@ import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
import org.eclipse.cdt.core.parser.ParseError; import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor; import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver; import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
@ -147,8 +149,11 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected ASTCompletionNode completionNode; protected ASTCompletionNode completionNode;
protected IASTTypeId fTypeIdForCastAmbiguity; protected IASTTypeId fTypeIdForCastAmbiguity;
private final INodeFactory nodeFactory;
protected AbstractGNUSourceCodeParser(IScanner scanner, protected AbstractGNUSourceCodeParser(IScanner scanner,
IParserLogService logService, ParserMode parserMode, IParserLogService logService, ParserMode parserMode,
INodeFactory nodeFactory,
boolean supportStatementsInExpressions, boolean supportStatementsInExpressions,
boolean supportTypeOfUnaries, boolean supportAlignOfUnaries, boolean supportTypeOfUnaries, boolean supportAlignOfUnaries,
boolean supportKnRC, boolean supportAttributeSpecifiers, boolean supportKnRC, boolean supportAttributeSpecifiers,
@ -164,6 +169,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
this.supportAttributeSpecifiers = supportAttributeSpecifiers; this.supportAttributeSpecifiers = supportAttributeSpecifiers;
this.supportDeclspecSpecifiers = supportDeclspecSpecifiers; this.supportDeclspecSpecifiers = supportDeclspecSpecifiers;
this.builtinBindingsProvider= builtinBindingsProvider; this.builtinBindingsProvider= builtinBindingsProvider;
this.nodeFactory = nodeFactory;
} }
/** /**
@ -436,26 +442,28 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return result; return result;
} }
protected abstract IASTProblem createProblem(int signal, int offset, int length);
protected final IASTProblem createProblem(int signal, int offset, int length) {
IASTProblem result = nodeFactory.newProblem(signal, CharArrayUtils.EMPTY, true);
((ASTNode) result).setOffsetAndLength(offset, length);
return result;
}
protected void logThrowable(String methodName, Throwable e) { protected void logThrowable(String methodName, Throwable e) {
if (e != null) { if (e != null) {
if (log.isTracing()) { if (log.isTracing()) {
StringBuffer buffer = new StringBuffer(); String message =
buffer.append("Parser: Unexpected throwable in "); //$NON-NLS-1$ String.format("Parser: Unexpected throwable in %s:%s::%s. w/%s", //$NON-NLS-1$
buffer.append(methodName); methodName, e.getClass().getName(), e.getMessage(), scanner);
buffer.append(":"); //$NON-NLS-1$ log.traceLog(message);
buffer.append(e.getClass().getName());
buffer.append("::"); //$NON-NLS-1$
buffer.append(e.getMessage());
buffer.append(". w/"); //$NON-NLS-1$
buffer.append(scanner.toString());
log.traceLog(buffer.toString());
} }
log.traceException(e); log.traceException(e);
} }
} }
@Override @Override
public String toString() { public String toString() {
return scanner.toString(); return scanner.toString();
@ -468,17 +476,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected void logException(String methodName, Exception e) { protected void logException(String methodName, Exception e) {
if (!(e instanceof EndOfFileException) && e != null) { if (!(e instanceof EndOfFileException) && e != null) {
if (log.isTracing()) { if (log.isTracing()) {
StringBuffer buffer = new StringBuffer(); String message =
buffer.append("Parser: Unexpected exception in "); //$NON-NLS-1$ String.format("Parser: Unexpected exception in %s:%s::%s. w/%s", //$NON-NLS-1$
buffer.append(methodName); methodName, e.getClass().getName(), e.getMessage(), scanner);
buffer.append(":"); //$NON-NLS-1$ log.traceLog(message);
buffer.append(e.getClass().getName());
buffer.append("::"); //$NON-NLS-1$
buffer.append(e.getMessage());
buffer.append(". w/"); //$NON-NLS-1$
buffer.append(scanner.toString());
log.traceLog(buffer.toString());
// log.errorLog(buffer.toString());
} }
log.traceException(e); log.traceException(e);
} }
@ -510,6 +511,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
); );
IASTTranslationUnit result = getTranslationUnit(); IASTTranslationUnit result = getTranslationUnit();
nullifyTranslationUnit(); nullifyTranslationUnit();
result.freeze(); // make the AST immutable
return result; return result;
} }
@ -552,7 +554,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
declarationMark= null; declarationMark= null;
int endOffset = skipToSemiOrClosingBrace(offset, false); int endOffset = skipToSemiOrClosingBrace(offset, false);
IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset);
return createProblemDeclaration(problem); return buildProblemDeclaration(problem);
} }
protected IASTProblemStatement skipProblemStatement(int offset) { protected IASTProblemStatement skipProblemStatement(int offset) {
@ -560,7 +562,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
declarationMark= null; declarationMark= null;
int endOffset = skipToSemiOrClosingBrace(offset, false); int endOffset = skipToSemiOrClosingBrace(offset, false);
IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset);
return createProblemStatement(problem); return buildProblemStatement(problem);
} }
private IASTProblem skipProblemEnumerator(int offset) { private IASTProblem skipProblemEnumerator(int offset) {
@ -651,7 +653,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
endOffset= eofOffset; endOffset= eofOffset;
} }
IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset);
return createProblemExpression(problem); return buildProblemExpression(problem);
} }
/** /**
@ -659,7 +661,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
* @throws BacktrackException * @throws BacktrackException
*/ */
protected IASTCompoundStatement compoundStatement() throws EndOfFileException, BacktrackException { protected IASTCompoundStatement compoundStatement() throws EndOfFileException, BacktrackException {
IASTCompoundStatement result = createCompoundStatement(); IASTCompoundStatement result = nodeFactory.newCompoundStatement();
if (LT(1) == IToken.tEOC) if (LT(1) == IToken.tEOC)
return result; return result;
@ -714,27 +716,21 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return result; return result;
} }
protected abstract IASTProblemStatement createProblemStatement();
protected abstract IASTProblemDeclaration createProblemDeclaration();
protected abstract IASTCompoundStatement createCompoundStatement();
private IASTProblemDeclaration createProblemDeclaration(IASTProblem problem) { private IASTProblemDeclaration buildProblemDeclaration(IASTProblem problem) {
IASTProblemDeclaration pd = createProblemDeclaration(); IASTProblemDeclaration pd = nodeFactory.newProblemDeclaration(problem);
pd.setProblem(problem);
((ASTNode) pd).setOffsetAndLength(((ASTNode) problem)); ((ASTNode) pd).setOffsetAndLength(((ASTNode) problem));
return pd; return pd;
} }
private IASTProblemStatement createProblemStatement(IASTProblem problem) { private IASTProblemStatement buildProblemStatement(IASTProblem problem) {
IASTProblemStatement pstmt = createProblemStatement(); IASTProblemStatement pstmt = nodeFactory.newProblemStatement(problem);
pstmt.setProblem(problem);
((ASTNode) pstmt).setOffsetAndLength(((ASTNode) problem)); ((ASTNode) pstmt).setOffsetAndLength(((ASTNode) problem));
return pstmt; return pstmt;
} }
private IASTProblemExpression createProblemExpression(IASTProblem problem) { private IASTProblemExpression buildProblemExpression(IASTProblem problem) {
IASTProblemExpression pexpr = createProblemExpression(); IASTProblemExpression pexpr = nodeFactory.newProblemExpression(problem);
pexpr.setProblem(problem);
((ASTNode) pexpr).setOffsetAndLength(((ASTNode) problem)); ((ASTNode) pexpr).setOffsetAndLength(((ASTNode) problem));
return pexpr; return pexpr;
} }
@ -753,21 +749,16 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
compoundStatement = compoundStatement(); compoundStatement = compoundStatement();
int lastOffset = consume(IToken.tRPAREN).getEndOffset(); int lastOffset = consume(IToken.tRPAREN).getEndOffset();
IGNUASTCompoundStatementExpression resultExpression = createCompoundStatementExpression(); IGNUASTCompoundStatementExpression resultExpression = nodeFactory.newGNUCompoundStatementExpression(compoundStatement);
((ASTNode) resultExpression).setOffsetAndLength(startingOffset, lastOffset - startingOffset); ((ASTNode) resultExpression).setOffsetAndLength(startingOffset, lastOffset - startingOffset);
if (compoundStatement != null) {
resultExpression.setCompoundStatement(compoundStatement);
}
return resultExpression; return resultExpression;
} }
protected abstract IGNUASTCompoundStatementExpression createCompoundStatementExpression();
protected IASTExpression possiblyEmptyExpressionList(int endToken) throws BacktrackException, EndOfFileException { protected IASTExpression possiblyEmptyExpressionList(int endToken) throws BacktrackException, EndOfFileException {
IToken la1= LA(1); IToken la1= LA(1);
if (la1.getType() == endToken) { if (la1.getType() == endToken) {
IASTExpressionList expressionList = createExpressionList(); IASTExpressionList expressionList = nodeFactory.newExpressionList();
((ASTNode) expressionList).setOffsetAndLength(la1.getOffset(), 0); ((ASTNode) expressionList).setOffsetAndLength(la1.getOffset(), 0);
return expressionList; return expressionList;
} }
@ -781,7 +772,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
if (LT(1) != IToken.tCOMMA) if (LT(1) != IToken.tCOMMA)
return assignmentExpression; return assignmentExpression;
IASTExpressionList expressionList = createExpressionList(); IASTExpressionList expressionList = nodeFactory.newExpressionList();
((ASTNode) expressionList).setOffset(startingOffset); ((ASTNode) expressionList).setOffset(startingOffset);
expressionList.addExpression(assignmentExpression); expressionList.addExpression(assignmentExpression);
@ -796,7 +787,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return expressionList; return expressionList;
} }
protected abstract IASTExpressionList createExpressionList();
protected abstract IASTExpression assignmentExpression() protected abstract IASTExpression assignmentExpression()
throws BacktrackException, EndOfFileException; throws BacktrackException, EndOfFileException;
@ -873,8 +863,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
backup(mark); backup(mark);
try { try {
IASTExpression expr= primaryExpression(); IASTExpression expr= primaryExpression();
IASTFunctionCallExpression fcall= createFunctionCallExpression(); IASTFunctionCallExpression fcall = nodeFactory.newFunctionCallExpression(expr, null);
fcall.setFunctionNameExpression(expr);
IASTAmbiguousExpression ambiguity = createAmbiguousCastVsFunctionCallExpression(result, fcall); IASTAmbiguousExpression ambiguity = createAmbiguousCastVsFunctionCallExpression(result, fcall);
((ASTNode) ambiguity).setOffsetAndLength((ASTNode) result); ((ASTNode) ambiguity).setOffsetAndLength((ASTNode) result);
return ambiguity; return ambiguity;
@ -898,8 +887,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected abstract IASTExpression unaryExpression() throws BacktrackException, EndOfFileException; protected abstract IASTExpression unaryExpression() throws BacktrackException, EndOfFileException;
protected abstract IASTExpression primaryExpression() throws BacktrackException, EndOfFileException; protected abstract IASTExpression primaryExpression() throws BacktrackException, EndOfFileException;
protected abstract IASTExpression buildTypeIdExpression(int op, protected abstract IASTExpression buildTypeIdExpression(int op, IASTTypeId typeId, int startingOffset, int endingOffset);
IASTTypeId typeId, int startingOffset, int endingOffset);
protected abstract IASTTranslationUnit getTranslationUnit(); protected abstract IASTTranslationUnit getTranslationUnit();
@ -968,8 +956,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return conditionalExpression(); return conditionalExpression();
} }
protected IASTExpression logicalOrExpression() throws BacktrackException, protected IASTExpression logicalOrExpression() throws BacktrackException, EndOfFileException {
EndOfFileException {
IASTExpression firstExpression = logicalAndExpression(); IASTExpression firstExpression = logicalAndExpression();
while (LT(1) == IToken.tOR) { while (LT(1) == IToken.tOR) {
consume(); consume();
@ -981,8 +968,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return firstExpression; return firstExpression;
} }
protected IASTExpression logicalAndExpression() throws BacktrackException, protected IASTExpression logicalAndExpression() throws BacktrackException, EndOfFileException {
EndOfFileException {
IASTExpression firstExpression = inclusiveOrExpression(); IASTExpression firstExpression = inclusiveOrExpression();
while (LT(1) == IToken.tAND) { while (LT(1) == IToken.tAND) {
consume(); consume();
@ -994,8 +980,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return firstExpression; return firstExpression;
} }
protected IASTExpression inclusiveOrExpression() throws BacktrackException, protected IASTExpression inclusiveOrExpression() throws BacktrackException, EndOfFileException {
EndOfFileException {
IASTExpression firstExpression = exclusiveOrExpression(); IASTExpression firstExpression = exclusiveOrExpression();
while (LT(1) == IToken.tBITOR) { while (LT(1) == IToken.tBITOR) {
consume(); consume();
@ -1007,8 +992,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return firstExpression; return firstExpression;
} }
protected IASTExpression exclusiveOrExpression() throws BacktrackException, protected IASTExpression exclusiveOrExpression() throws BacktrackException, EndOfFileException {
EndOfFileException {
IASTExpression firstExpression = andExpression(); IASTExpression firstExpression = andExpression();
while (LT(1) == IToken.tXOR) { while (LT(1) == IToken.tXOR) {
consume(); consume();
@ -1036,16 +1020,14 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return firstExpression; return firstExpression;
} }
protected IASTExpression equalityExpression() throws EndOfFileException, protected IASTExpression equalityExpression() throws EndOfFileException, BacktrackException {
BacktrackException {
IASTExpression firstExpression = relationalExpression(); IASTExpression firstExpression = relationalExpression();
for (;;) { for (;;) {
switch (LT(1)) { switch (LT(1)) {
case IToken.tEQUAL: case IToken.tEQUAL:
case IToken.tNOTEQUAL: case IToken.tNOTEQUAL:
IToken t = consume(); IToken t = consume();
int operator = ((t.getType() == IToken.tEQUAL) ? IASTBinaryExpression.op_equals int operator = ((t.getType() == IToken.tEQUAL) ? IASTBinaryExpression.op_equals : IASTBinaryExpression.op_notequals);
: IASTBinaryExpression.op_notequals);
IASTExpression secondExpression = relationalExpression(); IASTExpression secondExpression = relationalExpression();
firstExpression = buildBinaryExpression(operator, firstExpression = buildBinaryExpression(operator,
firstExpression, secondExpression, firstExpression, secondExpression,
@ -1057,31 +1039,21 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
} }
protected IASTExpression buildBinaryExpression(int operator, protected IASTExpression buildBinaryExpression(int operator, IASTExpression expr1, IASTExpression expr2, int lastOffset) {
IASTExpression firstExpression, IASTExpression secondExpression, IASTBinaryExpression result = nodeFactory.newBinaryExpression(operator, expr1, expr2);
int lastOffset) { int o = ((ASTNode) expr1).getOffset();
IASTBinaryExpression result = createBinaryExpression();
result.setOperator(operator);
int o = ((ASTNode) firstExpression).getOffset();
((ASTNode) result).setOffsetAndLength(o, lastOffset - o); ((ASTNode) result).setOffsetAndLength(o, lastOffset - o);
result.setOperand1(firstExpression);
result.setOperand2(secondExpression);
return result; return result;
} }
protected abstract IASTBinaryExpression createBinaryExpression(); protected IASTExpression shiftExpression() throws BacktrackException, EndOfFileException {
protected abstract IASTFunctionCallExpression createFunctionCallExpression();
protected IASTExpression shiftExpression() throws BacktrackException,
EndOfFileException {
IASTExpression firstExpression = additiveExpression(); IASTExpression firstExpression = additiveExpression();
for (;;) { for (;;) {
switch (LT(1)) { switch (LT(1)) {
case IToken.tSHIFTL: case IToken.tSHIFTL:
case IToken.tSHIFTR: case IToken.tSHIFTR:
IToken t = consume(); IToken t = consume();
int operator = t.getType() == IToken.tSHIFTL ? IASTBinaryExpression.op_shiftLeft int operator = t.getType() == IToken.tSHIFTL ? IASTBinaryExpression.op_shiftLeft : IASTBinaryExpression.op_shiftRight;
: IASTBinaryExpression.op_shiftRight;
IASTExpression secondExpression = additiveExpression(); IASTExpression secondExpression = additiveExpression();
firstExpression = buildBinaryExpression(operator, firstExpression = buildBinaryExpression(operator,
firstExpression, secondExpression, firstExpression, secondExpression,
@ -1113,8 +1085,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
final int offset= consume().getOffset(); final int offset= consume().getOffset();
final IASTTypeId typeid= fTypeIdForCastAmbiguity; fTypeIdForCastAmbiguity= null; final IASTTypeId typeid= fTypeIdForCastAmbiguity; fTypeIdForCastAmbiguity= null;
IASTExpression secondExpression = multiplicativeExpression(); IASTExpression secondExpression = multiplicativeExpression();
result = buildBinaryExpression(operator, result, secondExpression, result = buildBinaryExpression(operator, result, secondExpression, calculateEndOffset(secondExpression));
calculateEndOffset(secondExpression));
if (typeid != null) { if (typeid != null) {
result = createCastVsBinaryExpressionAmbiguity((IASTBinaryExpression) result, typeid, unaryOperator, offset); result = createCastVsBinaryExpressionAmbiguity((IASTBinaryExpression) result, typeid, unaryOperator, offset);
} }
@ -1154,8 +1125,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
private IASTExpression createCastVsBinaryExpressionAmbiguity(IASTBinaryExpression expr, final IASTTypeId typeid, int unaryOperator, int unaryOpOffset) { private IASTExpression createCastVsBinaryExpressionAmbiguity(IASTBinaryExpression expr, final IASTTypeId typeid, int unaryOperator, int unaryOpOffset) {
IASTUnaryExpression unary= createUnaryExpression(); IASTUnaryExpression unary= nodeFactory.newUnaryExpression(unaryOperator, null);
unary.setOperator(unaryOperator);
((ASTNode) unary).setOffset(unaryOpOffset); ((ASTNode) unary).setOffset(unaryOpOffset);
IASTCastExpression castExpr = buildCastExpression(IASTCastExpression.op_cast, typeid, unary, 0, 0); IASTCastExpression castExpr = buildCastExpression(IASTCastExpression.op_cast, typeid, unary, 0, 0);
IASTExpression result= createAmbiguousBinaryVsCastExpression(expr, castExpr); IASTExpression result= createAmbiguousBinaryVsCastExpression(expr, castExpr);
@ -1163,8 +1133,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return result; return result;
} }
protected IASTExpression conditionalExpression() throws BacktrackException, protected IASTExpression conditionalExpression() throws BacktrackException, EndOfFileException {
EndOfFileException {
IASTExpression firstExpression = logicalOrExpression(); IASTExpression firstExpression = logicalOrExpression();
if (LT(1) == IToken.tQUESTION) { if (LT(1) == IToken.tQUESTION) {
consume(); consume();
@ -1179,11 +1148,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
thirdExpression = assignmentExpression(); thirdExpression = assignmentExpression();
} }
IASTConditionalExpression result = createConditionalExpression(); IASTConditionalExpression result = nodeFactory.newConditionalExpession(firstExpression, secondExpression, thirdExpression);
result.setLogicalConditionExpression(firstExpression);
result.setPositiveResultExpression(secondExpression);
if (thirdExpression != null) { if (thirdExpression != null) {
result.setNegativeResultExpression(thirdExpression);
((ASTNode) result).setOffsetAndLength(((ASTNode) firstExpression) ((ASTNode) result).setOffsetAndLength(((ASTNode) firstExpression)
.getOffset(), calculateEndOffset(thirdExpression) .getOffset(), calculateEndOffset(thirdExpression)
- ((ASTNode) firstExpression).getOffset()); - ((ASTNode) firstExpression).getOffset());
@ -1194,8 +1160,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return firstExpression; return firstExpression;
} }
protected abstract IASTConditionalExpression createConditionalExpression();
protected IASTExpression unarayExpression(int operator) throws EndOfFileException, BacktrackException { protected IASTExpression unarayExpression(int operator) throws EndOfFileException, BacktrackException {
final IToken operatorToken= consume(); final IToken operatorToken= consume();
final IASTExpression operand= castExpression(); final IASTExpression operand= castExpression();
@ -1216,21 +1180,18 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
protected IASTExpression buildUnaryExpression(int operator, IASTExpression operand, int offset, int lastOffset) { protected IASTExpression buildUnaryExpression(int operator, IASTExpression operand, int offset, int lastOffset) {
IASTUnaryExpression result = createUnaryExpression(); IASTUnaryExpression result = nodeFactory.newUnaryExpression(operator, operand);
setRange(result, offset, lastOffset); setRange(result, offset, lastOffset);
result.setOperator(operator);
result.setOperand(operand);
return result; return result;
} }
protected abstract IASTUnaryExpression createUnaryExpression();
protected IASTStatement handleFunctionBody() throws BacktrackException, EndOfFileException { protected IASTStatement handleFunctionBody() throws BacktrackException, EndOfFileException {
declarationMark= null; declarationMark= null;
if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE) { if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE) {
IToken curr = LA(1); IToken curr = LA(1);
IToken last = skipOverCompoundStatement(); IToken last = skipOverCompoundStatement();
IASTCompoundStatement cs = createCompoundStatement(); IASTCompoundStatement cs = nodeFactory.newCompoundStatement();
((ASTNode) cs).setOffsetAndLength(curr.getOffset(), last.getEndOffset() - curr.getOffset()); ((ASTNode) cs).setOffsetAndLength(curr.getOffset(), last.getEndOffset() - curr.getOffset());
return cs; return cs;
} else if (mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE) { } else if (mode == ParserMode.COMPLETION_PARSE || mode == ParserMode.SELECTION_PARSE) {
@ -1238,7 +1199,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return functionBody(); return functionBody();
IToken curr = LA(1); IToken curr = LA(1);
IToken last = skipOverCompoundStatement(); IToken last = skipOverCompoundStatement();
IASTCompoundStatement cs = createCompoundStatement(); IASTCompoundStatement cs = nodeFactory.newCompoundStatement();
((ASTNode) cs).setOffsetAndLength(curr.getOffset(), last.getEndOffset() - curr.getOffset()); ((ASTNode) cs).setOffsetAndLength(curr.getOffset(), last.getEndOffset() - curr.getOffset());
return cs; return cs;
} }
@ -1309,7 +1270,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
if (LT(1) == IToken.tIDENTIFIER) { if (LT(1) == IToken.tIDENTIFIER) {
name= createName(identifier()); name= createName(identifier());
} else { } else {
name= createName(); name= nodeFactory.newName();
} }
if (LT(1) != IToken.tLBRACE) { if (LT(1) != IToken.tLBRACE) {
@ -1317,8 +1278,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
throwBacktrack(mark); throwBacktrack(mark);
} }
final IASTEnumerationSpecifier result= createEnumerationSpecifier(); final IASTEnumerationSpecifier result= nodeFactory.newEnumerationSpecifier(name);
result.setName(name);
boolean needComma= false; boolean needComma= false;
int endOffset= consume().getEndOffset(); // IToken.tLBRACE int endOffset= consume().getEndOffset(); // IToken.tLBRACE
@ -1348,9 +1308,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
if (needComma) if (needComma)
throw backtrack; throw backtrack;
final IASTEnumerator enumerator= createEnumerator();
final IASTName etorName= createName(identifier()); final IASTName etorName= createName(identifier());
enumerator.setName(etorName); final IASTEnumerator enumerator= nodeFactory.newEnumerator(etorName, null);
endOffset= calculateEndOffset(etorName); endOffset= calculateEndOffset(etorName);
setRange(enumerator, problemOffset, endOffset); setRange(enumerator, problemOffset, endOffset);
result.addEnumerator(enumerator); result.addEnumerator(enumerator);
@ -1380,12 +1339,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected abstract IASTStatement statement() throws EndOfFileException, BacktrackException; protected abstract IASTStatement statement() throws EndOfFileException, BacktrackException;
protected abstract IASTEnumerator createEnumerator();
protected abstract IASTEnumerationSpecifier createEnumerationSpecifier();
protected abstract IASTName createName();
protected abstract IASTName createName(IToken token); protected abstract IASTName createName(IToken token);
protected IASTExpression condition(boolean followedByParenthesis) throws BacktrackException, EndOfFileException { protected IASTExpression condition(boolean followedByParenthesis) throws BacktrackException, EndOfFileException {
@ -1412,51 +1365,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return !parsePassed; return !parsePassed;
} }
protected abstract IASTSimpleDeclaration createSimpleDeclaration();
protected abstract IASTNamedTypeSpecifier createNamedTypeSpecifier();
protected abstract IASTDeclarationStatement createDeclarationStatement();
protected abstract IASTExpressionStatement createExpressionStatement();
protected abstract IASTFunctionDefinition createFunctionDefinition();
protected abstract IASTLabelStatement createLabelStatement();
protected abstract IASTNullStatement createNullStatement();
protected abstract IASTGotoStatement createGoToStatement();
protected abstract IASTReturnStatement createReturnStatement();
protected abstract IASTContinueStatement createContinueStatement();
protected abstract IASTBreakStatement createBreakStatement();
protected abstract IASTDoStatement createDoStatement();
protected abstract IASTWhileStatement createWhileStatement();
protected abstract IASTIdExpression createIdExpression();
protected abstract IASTDefaultStatement createDefaultStatement();
protected abstract IASTCaseStatement createCaseStatement();
protected abstract IASTDeclaration declaration(DeclarationOptions option) throws BacktrackException, EndOfFileException; protected abstract IASTDeclaration declaration(DeclarationOptions option) throws BacktrackException, EndOfFileException;
protected abstract IASTDeclSpecifier declSpecifierSeq(DeclarationOptions option) throws BacktrackException, EndOfFileException, FoundDeclaratorException, FoundAggregateInitializer; protected abstract IASTDeclSpecifier declSpecifierSeq(DeclarationOptions option) throws BacktrackException, EndOfFileException, FoundDeclaratorException, FoundAggregateInitializer;
@ -1469,7 +1377,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
IASTNode n= bt.getNodeBeforeProblem(); IASTNode n= bt.getNodeBeforeProblem();
if (n instanceof IASTDeclaration) { if (n instanceof IASTDeclaration) {
declarationMark= null; declarationMark= null;
return new IASTDeclaration[] {(IASTDeclaration) n, createProblemDeclaration(origProblem)}; return new IASTDeclaration[] {(IASTDeclaration) n, buildProblemDeclaration(origProblem)};
} }
if (declarationMark != null) { if (declarationMark != null) {
@ -1498,7 +1406,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
n= bt.getNodeBeforeProblem(); n= bt.getNodeBeforeProblem();
if (n instanceof IASTDeclaration) { if (n instanceof IASTDeclaration) {
decl= (IASTDeclaration) n; decl= (IASTDeclaration) n;
trailingProblem= createProblemDeclaration(bt.getProblem()); trailingProblem= buildProblemDeclaration(bt.getProblem());
break; break;
} }
} catch (EndOfFileException e) { } catch (EndOfFileException e) {
@ -1511,7 +1419,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
if (decl != null) { if (decl != null) {
IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset); IASTProblem problem= createProblem(IProblem.SYNTAX_ERROR, offset, endOffset-offset);
IASTDeclaration pd= createProblemDeclaration(problem); IASTDeclaration pd= buildProblemDeclaration(problem);
if (trailingProblem != null) if (trailingProblem != null)
return new IASTDeclaration[] {pd, decl, trailingProblem}; return new IASTDeclaration[] {pd, decl, trailingProblem};
return new IASTDeclaration[] {pd, decl}; return new IASTDeclaration[] {pd, decl};
@ -1521,8 +1429,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return new IASTDeclaration[] {skipProblemDeclaration(offset)}; return new IASTDeclaration[] {skipProblemDeclaration(offset)};
} }
protected IASTDeclaration asmDeclaration() throws EndOfFileException, protected IASTDeclaration asmDeclaration() throws EndOfFileException, BacktrackException {
BacktrackException {
final int offset= consume().getOffset(); // t_asm final int offset= consume().getOffset(); // t_asm
if (LT(1) == IToken.t_volatile) { if (LT(1) == IToken.t_volatile) {
consume(); consume();
@ -1570,16 +1477,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
if (dtor instanceof IASTFunctionDeclarator == false) if (dtor instanceof IASTFunctionDeclarator == false)
throwBacktrack(offset, LA(1).getEndOffset() - offset); throwBacktrack(offset, LA(1).getEndOffset() - offset);
IASTFunctionDefinition funcDefinition = createFunctionDefinition();
funcDefinition.setDeclSpecifier(declSpec);
funcDefinition.setDeclarator((IASTFunctionDeclarator) fdtor);
final int compoundOffset= LA(1).getOffset(); final int compoundOffset= LA(1).getOffset();
final int endOffset= skipOverCompoundStatement().getEndOffset(); final int endOffset= skipOverCompoundStatement().getEndOffset();
IASTCompoundStatement cs = createCompoundStatement(); IASTCompoundStatement cs = nodeFactory.newCompoundStatement(); //createCompoundStatement();
((ASTNode)cs).setOffsetAndLength(compoundOffset, endOffset - compoundOffset); ((ASTNode)cs).setOffsetAndLength(compoundOffset, endOffset - compoundOffset);
funcDefinition.setBody(cs); IASTFunctionDefinition funcDefinition = nodeFactory.newFunctionDefinition(declSpec, (IASTFunctionDeclarator)fdtor, cs);
((ASTNode) funcDefinition).setOffsetAndLength(offset, endOffset - offset); ((ASTNode) funcDefinition).setOffsetAndLength(offset, endOffset - offset);
return funcDefinition; return funcDefinition;
@ -1617,34 +1520,20 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return t; return t;
} }
protected IASTASMDeclaration buildASMDirective(int offset, String assembly, protected IASTASMDeclaration buildASMDirective(int offset, String assembly, int lastOffset) {
int lastOffset) { IASTASMDeclaration result = nodeFactory.newASMDeclaration(assembly);
IASTASMDeclaration result = createASMDirective();
((ASTNode) result).setOffsetAndLength(offset, lastOffset - offset); ((ASTNode) result).setOffsetAndLength(offset, lastOffset - offset);
result.setAssembly(assembly);
return result; return result;
} }
protected abstract IASTASMDeclaration createASMDirective(); protected IASTCastExpression buildCastExpression(int op, IASTTypeId typeId, IASTExpression operand, int offset, int endOffset) {
IASTCastExpression result = nodeFactory.newCastExpression(op, typeId, operand);
protected IASTCastExpression buildCastExpression(int op, IASTTypeId typeId, IASTExpression operand,
int offset, int endOffset) {
IASTCastExpression result = createCastExpression();
result.setOperator(op);
((ASTNode) result).setOffsetAndLength(offset, endOffset - offset); ((ASTNode) result).setOffsetAndLength(offset, endOffset - offset);
result.setTypeId(typeId);
if (operand != null) { // which it can be in a completion
result.setOperand(operand);
}
return result; return result;
} }
protected abstract IASTCastExpression createCastExpression();
/** /**
* There are many ambiguities in C and C++ between expressions and declarations. * There are many ambiguities in C and C++ between expressions and declarations.
* This method will attempt to parse a statement as both an expression and a declaration, * This method will attempt to parse a statement as both an expression and a declaration,
@ -1663,8 +1552,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
lastTokenOfExpression = consume(); lastTokenOfExpression = consume();
else else
lastTokenOfExpression = consume(IToken.tSEMI); lastTokenOfExpression = consume(IToken.tSEMI);
expressionStatement = createExpressionStatement(); expressionStatement = nodeFactory.newExpressionStatement(expression);
expressionStatement.setExpression(expression);
((ASTNode) expressionStatement).setOffsetAndLength(mark.getOffset(), lastTokenOfExpression.getEndOffset() - mark.getOffset()); ((ASTNode) expressionStatement).setOffsetAndLength(mark.getOffset(), lastTokenOfExpression.getEndOffset() - mark.getOffset());
} catch (BacktrackException b) { } catch (BacktrackException b) {
} }
@ -1675,8 +1563,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
IASTDeclarationStatement ds = null; IASTDeclarationStatement ds = null;
try { try {
IASTDeclaration d = declaration(option); IASTDeclaration d = declaration(option);
ds = createDeclarationStatement(); ds = nodeFactory.newDeclarationStatement(d);
ds.setDeclaration(d);
((ASTNode) ds).setOffsetAndLength(((ASTNode) d).getOffset(), ((ASTNode) d).getLength()); ((ASTNode) ds).setOffsetAndLength(((ASTNode) d).getOffset(), ((ASTNode) d).getLength());
} catch (BacktrackException b) { } catch (BacktrackException b) {
backup(mark); backup(mark);
@ -1778,50 +1665,43 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected abstract IASTAmbiguousStatement createAmbiguousStatement(); protected abstract IASTAmbiguousStatement createAmbiguousStatement();
protected IASTStatement parseLabelStatement() throws EndOfFileException, protected IASTStatement parseLabelStatement() throws EndOfFileException, BacktrackException {
BacktrackException {
IToken labelName = consume(); // tIDENTIFIER IToken labelName = consume(); // tIDENTIFIER
consume(); // tCOLON consume(); // tCOLON
IASTStatement nestedStatement = statement(); IASTStatement nestedStatement = statement();
int lastOffset = calculateEndOffset( nestedStatement ); int lastOffset = calculateEndOffset( nestedStatement );
IASTLabelStatement label_statement = createLabelStatement();
((ASTNode) label_statement).setOffsetAndLength(labelName.getOffset(),
lastOffset - labelName.getOffset());
IASTName name = createName(labelName); IASTName name = createName(labelName);
label_statement.setName(name);
label_statement.setNestedStatement(nestedStatement); IASTLabelStatement label_statement = nodeFactory.newLabelStatement(name, nestedStatement);
((ASTNode) label_statement).setOffsetAndLength(labelName.getOffset(), lastOffset - labelName.getOffset());
return label_statement; return label_statement;
} }
protected IASTStatement parseNullStatement() throws EndOfFileException, protected IASTStatement parseNullStatement() throws EndOfFileException, BacktrackException {
BacktrackException {
IToken t = consume(); // tSEMI IToken t = consume(); // tSEMI
IASTNullStatement null_statement = createNullStatement(); IASTNullStatement null_statement = nodeFactory.newNullStatement();
((ASTNode) null_statement).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset()); ((ASTNode) null_statement).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset());
return null_statement; return null_statement;
} }
protected IASTStatement parseGotoStatement() throws EndOfFileException, protected IASTStatement parseGotoStatement() throws EndOfFileException, BacktrackException {
BacktrackException {
int startOffset = consume().getOffset(); // t_goto int startOffset = consume().getOffset(); // t_goto
IToken identifier = consume(IToken.tIDENTIFIER); IToken identifier = consume(IToken.tIDENTIFIER);
int lastOffset = consume(IToken.tSEMI).getEndOffset(); int lastOffset = consume(IToken.tSEMI).getEndOffset();
IASTName goto_label_name = createName(identifier); IASTName goto_label_name = createName(identifier);
IASTGotoStatement goto_statement = createGoToStatement(); IASTGotoStatement goto_statement = nodeFactory.newGotoStatement(goto_label_name);
((ASTNode) goto_statement).setOffsetAndLength(startOffset, lastOffset - startOffset); ((ASTNode) goto_statement).setOffsetAndLength(startOffset, lastOffset - startOffset);
goto_statement.setName(goto_label_name);
return goto_statement; return goto_statement;
} }
protected IASTStatement parseBreakStatement() throws EndOfFileException, protected IASTStatement parseBreakStatement() throws EndOfFileException, BacktrackException {
BacktrackException {
int startOffset = consume().getOffset(); // t_break int startOffset = consume().getOffset(); // t_break
int lastOffset = consume(IToken.tSEMI).getEndOffset(); int lastOffset = consume(IToken.tSEMI).getEndOffset();
IASTBreakStatement break_statement = createBreakStatement(); IASTBreakStatement break_statement = nodeFactory.newBreakStatement();
((ASTNode) break_statement).setOffsetAndLength(startOffset, lastOffset - startOffset); ((ASTNode) break_statement).setOffsetAndLength(startOffset, lastOffset - startOffset);
return break_statement; return break_statement;
} }
@ -1835,7 +1715,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return stmt; return stmt;
// bug 105334, switch without compound statement // bug 105334, switch without compound statement
IASTCompoundStatement comp= createCompoundStatement(); IASTCompoundStatement comp= nodeFactory.newCompoundStatement();
((ASTNode) comp).setOffsetAndLength((ASTNode) stmt); ((ASTNode) comp).setOffsetAndLength((ASTNode) stmt);
comp.addStatement(stmt); comp.addStatement(stmt);
@ -1847,18 +1727,16 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return comp; return comp;
} }
protected IASTStatement parseContinueStatement() throws EndOfFileException, protected IASTStatement parseContinueStatement() throws EndOfFileException, BacktrackException {
BacktrackException {
int startOffset = consume().getOffset(); // t_continue int startOffset = consume().getOffset(); // t_continue
int lastOffset = consume(IToken.tSEMI).getEndOffset(); int lastOffset = consume(IToken.tSEMI).getEndOffset();
IASTContinueStatement continue_statement = createContinueStatement(); IASTContinueStatement continue_statement = nodeFactory.newContinueStatement();
((ASTNode) continue_statement).setOffsetAndLength(startOffset, lastOffset - startOffset); ((ASTNode) continue_statement).setOffsetAndLength(startOffset, lastOffset - startOffset);
return continue_statement; return continue_statement;
} }
protected IASTStatement parseReturnStatement() throws EndOfFileException, protected IASTStatement parseReturnStatement() throws EndOfFileException, BacktrackException {
BacktrackException {
int startOffset; int startOffset;
startOffset = consume().getOffset(); // t_return startOffset = consume().getOffset(); // t_return
IASTExpression result = null; IASTExpression result = null;
@ -1868,8 +1746,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
case IToken.tEOC: case IToken.tEOC:
// We're trying to start one // We're trying to start one
IASTName name = createName(LA(1)); IASTName name = createName(LA(1));
IASTIdExpression idExpr = createIdExpression(); IASTIdExpression idExpr = nodeFactory.newIdExpression(name);
idExpr.setName(name);
result = idExpr; result = idExpr;
break; break;
case IToken.tSEMI: case IToken.tSEMI:
@ -1891,12 +1768,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
throwBacktrack(LA(1)); throwBacktrack(LA(1));
} }
IASTReturnStatement return_statement = createReturnStatement(); IASTReturnStatement return_statement = nodeFactory.newReturnStatement(result);
((ASTNode) return_statement).setOffsetAndLength(startOffset, lastOffset ((ASTNode) return_statement).setOffsetAndLength(startOffset, lastOffset - startOffset);
- startOffset);
if (result != null) {
return_statement.setReturnValue(result);
}
return return_statement; return return_statement;
} }
@ -1931,15 +1804,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
throw backtrack; throw backtrack;
} }
IASTDoStatement do_statement = nodeFactory.newDoStatement(do_body, do_condition);
IASTDoStatement do_statement = createDoStatement();
((ASTNode) do_statement).setOffsetAndLength(startOffset, lastOffset - startOffset); ((ASTNode) do_statement).setOffsetAndLength(startOffset, lastOffset - startOffset);
do_statement.setBody(do_body);
if (do_condition != null) {
do_statement.setCondition(do_condition);
}
return do_statement; return do_statement;
} }
@ -1960,11 +1826,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
if (LT(1) != IToken.tEOC) if (LT(1) != IToken.tEOC)
while_body = statement(); while_body = statement();
IASTWhileStatement while_statement = createWhileStatement(); IASTWhileStatement while_statement = nodeFactory.newWhileStatement(while_condition, while_body);
((ASTNode) while_statement).setOffsetAndLength(startOffset, ((ASTNode) while_statement).setOffsetAndLength(startOffset,
(while_body != null ? calculateEndOffset(while_body) : LA(1).getEndOffset()) - startOffset); (while_body != null ? calculateEndOffset(while_body) : LA(1).getEndOffset()) - startOffset);
while_statement.setCondition(while_condition);
while_statement.setBody(while_body);
return while_statement; return while_statement;
} }
@ -1996,7 +1860,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
} }
protected abstract IASTProblemExpression createProblemExpression();
protected IASTStatement parseCompoundStatement() throws EndOfFileException, BacktrackException { protected IASTStatement parseCompoundStatement() throws EndOfFileException, BacktrackException {
IASTCompoundStatement compound = compoundStatement(); IASTCompoundStatement compound = compoundStatement();
@ -2007,7 +1870,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
int startOffset = consume().getOffset(); // t_default int startOffset = consume().getOffset(); // t_default
int lastOffset = consume(IToken.tCOLON).getEndOffset(); int lastOffset = consume(IToken.tCOLON).getEndOffset();
IASTDefaultStatement df = createDefaultStatement(); IASTDefaultStatement df = nodeFactory.newDefaultStatement();
((ASTNode) df).setOffsetAndLength(startOffset, lastOffset - startOffset); ((ASTNode) df).setOffsetAndLength(startOffset, lastOffset - startOffset);
return df; return df;
} }
@ -2033,9 +1896,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
throwBacktrack(LA(1)); throwBacktrack(LA(1));
} }
IASTCaseStatement cs = createCaseStatement(); IASTCaseStatement cs = nodeFactory.newCaseStatement(caseExpression);
((ASTNode) cs).setOffsetAndLength(startOffset, lastOffset - startOffset); ((ASTNode) cs).setOffsetAndLength(startOffset, lastOffset - startOffset);
cs.setExpression(caseExpression);
return cs; return cs;
} }
@ -2047,8 +1909,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} }
protected int figureEndOffset(IASTDeclSpecifier declSpecifier, protected int figureEndOffset(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
IASTDeclarator declarator) {
if (declarator == null || ((ASTNode) declarator).getLength() == 0) if (declarator == null || ((ASTNode) declarator).getLength() == 0)
return calculateEndOffset(declSpecifier); return calculateEndOffset(declSpecifier);
return calculateEndOffset(declarator); return calculateEndOffset(declarator);
@ -2087,7 +1948,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
expr= buildTypeIdExpression(IASTTypeIdExpression.op_typeof, typeid, typeidOffset, calculateEndOffset(typeid)); expr= buildTypeIdExpression(IASTTypeIdExpression.op_typeof, typeid, typeidOffset, calculateEndOffset(typeid));
IASTExpressionList expressionList = createExpressionList(); IASTExpressionList expressionList = nodeFactory.newExpressionList();
((ASTNode) expressionList).setOffsetAndLength(typeidOffset, calculateEndOffset(expr2)-typeidOffset); ((ASTNode) expressionList).setOffsetAndLength(typeidOffset, calculateEndOffset(expr2)-typeidOffset);
expressionList.addExpression(expr); expressionList.addExpression(expr);
if (expr2 instanceof IASTExpressionList) { if (expr2 instanceof IASTExpressionList) {

View file

@ -35,6 +35,7 @@ public class CASTASMDeclaration extends ASTNode implements IASTASMDeclaration {
} }
public void setAssembly(String assembly) { public void setAssembly(String assembly) {
assertNotFrozen();
this.assembly = assembly.toCharArray(); this.assembly = assembly.toCharArray();
} }

View file

@ -40,6 +40,7 @@ public class CASTAmbiguousDeclarator extends CASTAmbiguity implements IASTAmbigu
} }
public void addDeclarator(IASTDeclarator d) { public void addDeclarator(IASTDeclarator d) {
assertNotFrozen();
if (d != null) { if (d != null) {
dtors = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, dtors, ++dtorPos, d); dtors = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, dtors, ++dtorPos, d);
d.setParent(this); d.setParent(this);
@ -78,18 +79,22 @@ public class CASTAmbiguousDeclarator extends CASTAmbiguity implements IASTAmbigu
} }
public void addPointerOperator(IASTPointerOperator operator) { public void addPointerOperator(IASTPointerOperator operator) {
assertNotFrozen();
Assert.isLegal(false); Assert.isLegal(false);
} }
public void setInitializer(IASTInitializer initializer) { public void setInitializer(IASTInitializer initializer) {
assertNotFrozen();
Assert.isLegal(false); Assert.isLegal(false);
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
Assert.isLegal(false); Assert.isLegal(false);
} }
public void setNestedDeclarator(IASTDeclarator nested) { public void setNestedDeclarator(IASTDeclarator nested) {
assertNotFrozen();
Assert.isLegal(false); Assert.isLegal(false);
} }
} }

View file

@ -36,6 +36,7 @@ public class CASTAmbiguousExpression extends CASTAmbiguity implements IASTAmbigu
} }
public void addExpression(IASTExpression e) { public void addExpression(IASTExpression e) {
assertNotFrozen();
if (e != null) { if (e != null) {
expressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, expressions, ++expressionsPos, e ); expressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, expressions, ++expressionsPos, e );
e.setParent(this); e.setParent(this);

View file

@ -36,6 +36,7 @@ public class CASTAmbiguousParameterDeclaration extends CASTAmbiguity implements
} }
public void addParameterDeclaration(IASTParameterDeclaration d) { public void addParameterDeclaration(IASTParameterDeclaration d) {
assertNotFrozen();
if (d != null) { if (d != null) {
paramDecls = (IASTParameterDeclaration[]) ArrayUtil.append(IASTParameterDeclaration.class, paramDecls, ++declPos, d); paramDecls = (IASTParameterDeclaration[]) ArrayUtil.append(IASTParameterDeclaration.class, paramDecls, ++declPos, d);
d.setParent(this); d.setParent(this);
@ -62,10 +63,12 @@ public class CASTAmbiguousParameterDeclaration extends CASTAmbiguity implements
} }
public void setDeclSpecifier(IASTDeclSpecifier declSpec) { public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
assertNotFrozen();
Assert.isLegal(false); Assert.isLegal(false);
} }
public void setDeclarator(IASTDeclarator declarator) { public void setDeclarator(IASTDeclarator declarator) {
assertNotFrozen();
Assert.isLegal(false); Assert.isLegal(false);
} }
} }

View file

@ -31,6 +31,7 @@ public class CASTAmbiguousStatement extends CASTAmbiguity implements
public void addStatement(IASTStatement s) { public void addStatement(IASTStatement s) {
assertNotFrozen();
if (s != null) { if (s != null) {
stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, ++stmtsPos, s ); stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, ++stmtsPos, s );
s.setParent(this); s.setParent(this);

View file

@ -45,6 +45,7 @@ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDecl
} }
public void addArrayModifier(IASTArrayModifier arrayModifier) { public void addArrayModifier(IASTArrayModifier arrayModifier) {
assertNotFrozen();
if (arrayModifier != null) { if (arrayModifier != null) {
arrayModifier.setParent(this); arrayModifier.setParent(this);
arrayModifier.setPropertyInParent(ARRAY_MODIFIER); arrayModifier.setPropertyInParent(ARRAY_MODIFIER);

View file

@ -42,6 +42,7 @@ public class CASTArrayDesignator extends ASTNode implements
} }
public void setSubscriptExpression(IASTExpression value) { public void setSubscriptExpression(IASTExpression value) {
assertNotFrozen();
exp = value; exp = value;
if(value != null) { if(value != null) {
value.setParent(this); value.setParent(this);

View file

@ -39,6 +39,7 @@ public class CASTArrayModifier extends ASTNode implements IASTArrayModifier, IAS
} }
public void setConstantExpression(IASTExpression expression) { public void setConstantExpression(IASTExpression expression) {
assertNotFrozen();
this.exp = expression; this.exp = expression;
if(expression != null) { if(expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -41,6 +41,7 @@ public class CASTArrayRangeDesignator extends ASTNode implements
} }
public void setRangeFloor(IASTExpression expression) { public void setRangeFloor(IASTExpression expression) {
assertNotFrozen();
floor = expression; floor = expression;
if(expression != null) { if(expression != null) {
expression.setParent(this); expression.setParent(this);
@ -53,6 +54,7 @@ public class CASTArrayRangeDesignator extends ASTNode implements
} }
public void setRangeCeiling(IASTExpression expression) { public void setRangeCeiling(IASTExpression expression) {
assertNotFrozen();
ceiling = expression; ceiling = expression;
if(expression != null) { if(expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -41,6 +41,7 @@ public class CASTArraySubscriptExpression extends ASTNode implements
} }
public void setArrayExpression(IASTExpression expression) { public void setArrayExpression(IASTExpression expression) {
assertNotFrozen();
array = expression; array = expression;
if(expression != null) { if(expression != null) {
expression.setParent(this); expression.setParent(this);
@ -53,6 +54,7 @@ public class CASTArraySubscriptExpression extends ASTNode implements
} }
public void setSubscriptExpression(IASTExpression expression) { public void setSubscriptExpression(IASTExpression expression) {
assertNotFrozen();
this.subscript = expression; this.subscript = expression;
if(expression != null) { if(expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -46,22 +46,27 @@ public abstract class CASTBaseDeclSpecifier extends ASTNode implements ICASTDecl
} }
public void setStorageClass(int storageClass) { public void setStorageClass(int storageClass) {
assertNotFrozen();
this.storageClass = storageClass; this.storageClass = storageClass;
} }
public void setConst(boolean value) { public void setConst(boolean value) {
assertNotFrozen();
this.isConst = value; this.isConst = value;
} }
public void setVolatile(boolean value) { public void setVolatile(boolean value) {
assertNotFrozen();
this.isVolatile = value; this.isVolatile = value;
} }
public void setRestrict(boolean value) { public void setRestrict(boolean value) {
assertNotFrozen();
this.isRestrict = value; this.isRestrict = value;
} }
public void setInline(boolean value) { public void setInline(boolean value) {
assertNotFrozen();
this.isInline = value; this.isInline = value;
} }
} }

View file

@ -54,10 +54,12 @@ public class CASTBinaryExpression extends ASTNode implements
* @param op An op_X field from {@link IASTBinaryExpression} * @param op An op_X field from {@link IASTBinaryExpression}
*/ */
public void setOperator(int op) { public void setOperator(int op) {
assertNotFrozen();
this.op = op; this.op = op;
} }
public void setOperand1(IASTExpression expression) { public void setOperand1(IASTExpression expression) {
assertNotFrozen();
operand1 = expression; operand1 = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);
@ -66,6 +68,7 @@ public class CASTBinaryExpression extends ASTNode implements
} }
public void setOperand2(IASTExpression expression) { public void setOperand2(IASTExpression expression) {
assertNotFrozen();
operand2 = expression; operand2 = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -38,6 +38,7 @@ public class CASTCaseStatement extends ASTNode implements IASTCaseStatement, IAS
} }
public void setExpression(IASTExpression expression) { public void setExpression(IASTExpression expression) {
assertNotFrozen();
this.expression = expression; this.expression = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -32,6 +32,7 @@ public class CASTCastExpression extends CASTUnaryExpression implements IASTCastE
} }
public void setTypeId(IASTTypeId typeId) { public void setTypeId(IASTTypeId typeId) {
assertNotFrozen();
this.typeId = typeId; this.typeId = typeId;
if (typeId != null) { if (typeId != null) {
typeId.setParent(this); typeId.setParent(this);

View file

@ -42,6 +42,7 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements
} }
public void setKey(int key) { public void setKey(int key) {
assertNotFrozen();
this.key = key; this.key = key;
} }
@ -50,6 +51,7 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);
@ -71,6 +73,7 @@ public class CASTCompositeTypeSpecifier extends CASTBaseDeclSpecifier implements
public void addMemberDeclaration(IASTDeclaration declaration) { public void addMemberDeclaration(IASTDeclaration declaration) {
assertNotFrozen();
if (declaration != null) { if (declaration != null) {
declaration.setParent(this); declaration.setParent(this);
declaration.setPropertyInParent(MEMBER_DECLARATION); declaration.setPropertyInParent(MEMBER_DECLARATION);

View file

@ -36,6 +36,7 @@ public class CASTCompoundStatement extends ASTNode implements IASTCompoundStatem
} }
public void addStatement(IASTStatement statement) { public void addStatement(IASTStatement statement) {
assertNotFrozen();
statements = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, statements, statement ); statements = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, statements, statement );
if(statement != null) { if(statement != null) {
statement.setParent(this); statement.setParent(this);

View file

@ -37,6 +37,7 @@ public class CASTCompoundStatementExpression extends ASTNode implements
} }
public void setCompoundStatement(IASTCompoundStatement statement) { public void setCompoundStatement(IASTCompoundStatement statement) {
assertNotFrozen();
this.statement = statement; this.statement = statement;
if (statement != null) { if (statement != null) {
statement.setParent(this); statement.setParent(this);

View file

@ -44,6 +44,7 @@ public class CASTConditionalExpression extends ASTNode implements
} }
public void setLogicalConditionExpression(IASTExpression expression) { public void setLogicalConditionExpression(IASTExpression expression) {
assertNotFrozen();
condition = expression; condition = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);
@ -56,6 +57,7 @@ public class CASTConditionalExpression extends ASTNode implements
} }
public void setPositiveResultExpression(IASTExpression expression) { public void setPositiveResultExpression(IASTExpression expression) {
assertNotFrozen();
this.positive = expression; this.positive = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);
@ -68,6 +70,7 @@ public class CASTConditionalExpression extends ASTNode implements
} }
public void setNegativeResultExpression(IASTExpression expression) { public void setNegativeResultExpression(IASTExpression expression) {
assertNotFrozen();
this.negative = expression; this.negative = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -36,6 +36,7 @@ public class CASTDeclarationStatement extends ASTNode implements IASTDeclaration
} }
public void setDeclaration(IASTDeclaration declaration) { public void setDeclaration(IASTDeclaration declaration) {
assertNotFrozen();
this.declaration = declaration; this.declaration = declaration;
if (declaration != null) { if (declaration != null) {
declaration.setParent(this); declaration.setParent(this);

View file

@ -70,6 +70,7 @@ public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbig
} }
public void setInitializer(IASTInitializer initializer) { public void setInitializer(IASTInitializer initializer) {
assertNotFrozen();
this.initializer = initializer; this.initializer = initializer;
if (initializer != null) { if (initializer != null) {
initializer.setParent(this); initializer.setParent(this);
@ -78,6 +79,7 @@ public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbig
} }
public void addPointerOperator(IASTPointerOperator operator) { public void addPointerOperator(IASTPointerOperator operator) {
assertNotFrozen();
if (operator != null) { if (operator != null) {
operator.setParent(this); operator.setParent(this);
operator.setPropertyInParent(POINTER_OPERATOR); operator.setPropertyInParent(POINTER_OPERATOR);
@ -86,6 +88,7 @@ public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbig
} }
public void setNestedDeclarator(IASTDeclarator nested) { public void setNestedDeclarator(IASTDeclarator nested) {
assertNotFrozen();
this.nestedDeclarator = nested; this.nestedDeclarator = nested;
if (nested != null) { if (nested != null) {
nested.setParent(this); nested.setParent(this);
@ -94,6 +97,7 @@ public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbig
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);

View file

@ -30,11 +30,12 @@ public class CASTDesignatedInitializer extends ASTNode implements
public CASTDesignatedInitializer() { public CASTDesignatedInitializer() {
} }
public CASTDesignatedInitializer(IASTInitializer rhs) { public CASTDesignatedInitializer(IASTInitializer operandInitializer) {
setOperandInitializer(rhs); setOperandInitializer(operandInitializer);
} }
public void addDesignator(ICASTDesignator designator) { public void addDesignator(ICASTDesignator designator) {
assertNotFrozen();
if (designator != null) { if (designator != null) {
designator.setParent(this); designator.setParent(this);
designator.setPropertyInParent(DESIGNATOR); designator.setPropertyInParent(DESIGNATOR);
@ -59,6 +60,7 @@ public class CASTDesignatedInitializer extends ASTNode implements
public void setOperandInitializer(IASTInitializer rhs) { public void setOperandInitializer(IASTInitializer rhs) {
assertNotFrozen();
this.rhs = rhs; this.rhs = rhs;
if (rhs != null) { if (rhs != null) {
rhs.setParent(this); rhs.setParent(this);

View file

@ -41,6 +41,7 @@ public class CASTDoStatement extends ASTNode implements IASTDoStatement, IASTAmb
} }
public void setBody(IASTStatement body) { public void setBody(IASTStatement body) {
assertNotFrozen();
this.body = body; this.body = body;
if (body != null) { if (body != null) {
body.setParent(this); body.setParent(this);
@ -55,6 +56,7 @@ public class CASTDoStatement extends ASTNode implements IASTDoStatement, IASTAmb
public void setCondition(IASTExpression condition) { public void setCondition(IASTExpression condition) {
assertNotFrozen();
this.condition = condition; this.condition = condition;
if (condition != null) { if (condition != null) {
condition.setParent(this); condition.setParent(this);

View file

@ -43,6 +43,7 @@ public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implement
} }
public void setKind(int value) { public void setKind(int value) {
assertNotFrozen();
this.kind = value; this.kind = value;
} }
@ -51,6 +52,7 @@ public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implement
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);

View file

@ -44,6 +44,7 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier
} }
public void addEnumerator(IASTEnumerator enumerator) { public void addEnumerator(IASTEnumerator enumerator) {
assertNotFrozen();
if (enumerator != null) { if (enumerator != null) {
enumerator.setParent(this); enumerator.setParent(this);
enumerator.setPropertyInParent(ENUMERATOR); enumerator.setPropertyInParent(ENUMERATOR);
@ -63,6 +64,7 @@ public class CASTEnumerationSpecifier extends CASTBaseDeclSpecifier
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);

View file

@ -34,6 +34,7 @@ public class CASTExpressionList extends ASTNode implements IASTExpressionList,
} }
public void addExpression(IASTExpression expression) { public void addExpression(IASTExpression expression) {
assertNotFrozen();
expressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, expressions, expression ); expressions = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, expressions, expression );
if(expression != null) { if(expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -39,6 +39,7 @@ public class CASTExpressionStatement extends ASTNode implements
} }
public void setExpression(IASTExpression expression) { public void setExpression(IASTExpression expression) {
assertNotFrozen();
this.expression = expression; this.expression = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -37,6 +37,7 @@ public class CASTFieldDeclarator extends CASTDeclarator implements IASTFieldDecl
public void setBitFieldSize(IASTExpression size) { public void setBitFieldSize(IASTExpression size) {
assertNotFrozen();
bitFieldSize = size; bitFieldSize = size;
if (size != null) { if (size != null) {
size.setParent(this); size.setParent(this);

View file

@ -39,6 +39,7 @@ public class CASTFieldDesignator extends ASTNode implements
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);

View file

@ -52,6 +52,7 @@ public class CASTFieldReference extends ASTNode implements IASTFieldReference, I
} }
public void setFieldOwner(IASTExpression expression) { public void setFieldOwner(IASTExpression expression) {
assertNotFrozen();
this.owner = expression; this.owner = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);
@ -64,6 +65,7 @@ public class CASTFieldReference extends ASTNode implements IASTFieldReference, I
} }
public void setFieldName(IASTName name) { public void setFieldName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);
@ -76,6 +78,7 @@ public class CASTFieldReference extends ASTNode implements IASTFieldReference, I
} }
public void setIsPointerDereference(boolean value) { public void setIsPointerDereference(boolean value) {
assertNotFrozen();
ptr = value; ptr = value;
} }

View file

@ -48,6 +48,7 @@ public class CASTForStatement extends ASTNode implements IASTForStatement, IASTA
} }
public void setConditionExpression(IASTExpression condition) { public void setConditionExpression(IASTExpression condition) {
assertNotFrozen();
this.condition = condition; this.condition = condition;
if (condition != null) { if (condition != null) {
condition.setParent(this); condition.setParent(this);
@ -60,6 +61,7 @@ public class CASTForStatement extends ASTNode implements IASTForStatement, IASTA
} }
public void setIterationExpression(IASTExpression iterator) { public void setIterationExpression(IASTExpression iterator) {
assertNotFrozen();
this.iterationExpression = iterator; this.iterationExpression = iterator;
if (iterator != null) { if (iterator != null) {
iterator.setParent(this); iterator.setParent(this);
@ -72,6 +74,7 @@ public class CASTForStatement extends ASTNode implements IASTForStatement, IASTA
} }
public void setInitializerStatement(IASTStatement statement) { public void setInitializerStatement(IASTStatement statement) {
assertNotFrozen();
init = statement; init = statement;
if (statement != null) { if (statement != null) {
statement.setParent(this); statement.setParent(this);
@ -83,6 +86,7 @@ public class CASTForStatement extends ASTNode implements IASTForStatement, IASTA
} }
public void setBody(IASTStatement statement) { public void setBody(IASTStatement statement) {
assertNotFrozen();
body = statement; body = statement;
if (statement != null) { if (statement != null) {
statement.setParent(this); statement.setParent(this);

View file

@ -38,6 +38,7 @@ public class CASTFunctionCallExpression extends ASTNode implements
} }
public void setFunctionNameExpression(IASTExpression expression) { public void setFunctionNameExpression(IASTExpression expression) {
assertNotFrozen();
this.functionName = expression; this.functionName = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);
@ -50,6 +51,7 @@ public class CASTFunctionCallExpression extends ASTNode implements
} }
public void setParameterExpression(IASTExpression expression) { public void setParameterExpression(IASTExpression expression) {
assertNotFrozen();
this.parameter = expression; this.parameter = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -41,6 +41,7 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda
} }
public void addParameterDeclaration(IASTParameterDeclaration parameter) { public void addParameterDeclaration(IASTParameterDeclaration parameter) {
assertNotFrozen();
if (parameter != null) { if (parameter != null) {
parameter.setParent(this); parameter.setParent(this);
parameter.setPropertyInParent(FUNCTION_PARAMETER); parameter.setPropertyInParent(FUNCTION_PARAMETER);
@ -53,6 +54,7 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda
} }
public void setVarArgs(boolean value) { public void setVarArgs(boolean value) {
assertNotFrozen();
varArgs = value; varArgs = value;
} }

View file

@ -50,6 +50,7 @@ public class CASTFunctionDefinition extends ASTNode implements
} }
public void setDeclSpecifier(IASTDeclSpecifier declSpec) { public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
assertNotFrozen();
declSpecifier = declSpec; declSpecifier = declSpec;
if (declSpec != null) { if (declSpec != null) {
declSpec.setParent(this); declSpec.setParent(this);
@ -62,6 +63,7 @@ public class CASTFunctionDefinition extends ASTNode implements
} }
public void setDeclarator(IASTFunctionDeclarator declarator) { public void setDeclarator(IASTFunctionDeclarator declarator) {
assertNotFrozen();
this.declarator = declarator; this.declarator = declarator;
if (declarator != null) { if (declarator != null) {
IASTDeclarator outerDtor= CVisitor.findOutermostDeclarator(declarator); IASTDeclarator outerDtor= CVisitor.findOutermostDeclarator(declarator);
@ -75,6 +77,7 @@ public class CASTFunctionDefinition extends ASTNode implements
} }
public void setBody(IASTStatement statement) { public void setBody(IASTStatement statement) {
assertNotFrozen();
bodyStatement = statement; bodyStatement = statement;
if (statement != null) { if (statement != null) {
statement.setParent(this); statement.setParent(this);

View file

@ -35,6 +35,7 @@ public class CASTGotoStatement extends ASTNode implements IASTGotoStatement {
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);

View file

@ -44,6 +44,7 @@ public class CASTIdExpression extends ASTNode implements IASTIdExpression, IASTC
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);

View file

@ -49,6 +49,7 @@ public class CASTIfStatement extends ASTNode implements IASTIfStatement, IASTAmb
} }
public void setConditionExpression(IASTExpression condition) { public void setConditionExpression(IASTExpression condition) {
assertNotFrozen();
this.condition = condition; this.condition = condition;
if (condition != null) { if (condition != null) {
condition.setParent(this); condition.setParent(this);
@ -61,6 +62,7 @@ public class CASTIfStatement extends ASTNode implements IASTIfStatement, IASTAmb
} }
public void setThenClause(IASTStatement thenClause) { public void setThenClause(IASTStatement thenClause) {
assertNotFrozen();
this.thenClause = thenClause; this.thenClause = thenClause;
if (thenClause != null) { if (thenClause != null) {
thenClause.setParent(this); thenClause.setParent(this);
@ -73,6 +75,7 @@ public class CASTIfStatement extends ASTNode implements IASTIfStatement, IASTAmb
} }
public void setElseClause(IASTStatement elseClause) { public void setElseClause(IASTStatement elseClause) {
assertNotFrozen();
this.elseClause = elseClause; this.elseClause = elseClause;
if (elseClause != null) { if (elseClause != null) {
elseClause.setParent(this); elseClause.setParent(this);

View file

@ -39,6 +39,7 @@ public class CASTInitializerExpression extends ASTNode implements
} }
public void setExpression(IASTExpression expression) { public void setExpression(IASTExpression expression) {
assertNotFrozen();
this.expression = expression; this.expression = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -32,6 +32,7 @@ public class CASTInitializerList extends ASTNode implements
} }
public void addInitializer( IASTInitializer d ) { public void addInitializer( IASTInitializer d ) {
assertNotFrozen();
if (d != null) { if (d != null) {
initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, ++initializersPos, d ); initializers = (IASTInitializer[]) ArrayUtil.append( IASTInitializer.class, initializers, ++initializersPos, d );
d.setParent(this); d.setParent(this);

View file

@ -40,15 +40,17 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn
public void setParameterNames(IASTName[] names) { public void setParameterNames(IASTName[] names) {
assertNotFrozen();
parameterNames = names; parameterNames = names;
for(int i = 0; i < names.length; i++) { if(names != null) {
IASTName name = names[i]; for(IASTName name : names) {
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);
name.setPropertyInParent(PARAMETER_NAME); name.setPropertyInParent(PARAMETER_NAME);
} }
} }
} }
}
public IASTName[] getParameterNames() { public IASTName[] getParameterNames() {
@ -57,15 +59,17 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn
public void setParameterDeclarations(IASTDeclaration[] decls) { public void setParameterDeclarations(IASTDeclaration[] decls) {
assertNotFrozen();
parameterDeclarations = decls; parameterDeclarations = decls;
for(int i = 0; i < parameterDeclarations.length; i++) { if(decls != null) {
IASTDeclaration decl = parameterDeclarations[i]; for(IASTDeclaration decl : decls) {
if (decl != null) { if (decl != null) {
decl.setParent(this); decl.setParent(this);
decl.setPropertyInParent(FUNCTION_PARAMETER); decl.setPropertyInParent(FUNCTION_PARAMETER);
} }
} }
} }
}
public IASTDeclaration[] getParameterDeclarations() { public IASTDeclaration[] getParameterDeclarations() {

View file

@ -41,6 +41,7 @@ public class CASTLabelStatement extends ASTNode implements IASTLabelStatement, I
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);
@ -80,6 +81,7 @@ public class CASTLabelStatement extends ASTNode implements IASTLabelStatement, I
} }
public void setNestedStatement(IASTStatement s) { public void setNestedStatement(IASTStatement s) {
assertNotFrozen();
nestedStatement = s; nestedStatement = s;
if (s != null) { if (s != null) {
s.setParent(this); s.setParent(this);

View file

@ -39,6 +39,7 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress
} }
public void setKind(int value) { public void setKind(int value) {
assertNotFrozen();
kind = value; kind = value;
} }
@ -47,6 +48,7 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress
} }
public void setValue(char[] value) { public void setValue(char[] value) {
assertNotFrozen();
this.value= value; this.value= value;
} }
@ -83,6 +85,7 @@ public class CASTLiteralExpression extends ASTNode implements IASTLiteralExpress
*/ */
@Deprecated @Deprecated
public void setValue(String value) { public void setValue(String value) {
assertNotFrozen();
this.value = value.toCharArray(); this.value = value.toCharArray();
} }

View file

@ -48,18 +48,22 @@ public class CASTModifiedArrayModifier extends CASTArrayModifier implements ICAS
} }
public void setConst(boolean value) { public void setConst(boolean value) {
assertNotFrozen();
this.isConst = value; this.isConst = value;
} }
public void setVolatile(boolean value) { public void setVolatile(boolean value) {
assertNotFrozen();
this.isVolatile = value; this.isVolatile = value;
} }
public void setRestrict(boolean value) { public void setRestrict(boolean value) {
assertNotFrozen();
this.isRestrict = value; this.isRestrict = value;
} }
public void setStatic(boolean value) { public void setStatic(boolean value) {
assertNotFrozen();
this.isStatic = value; this.isStatic = value;
} }
@ -68,6 +72,7 @@ public class CASTModifiedArrayModifier extends CASTArrayModifier implements ICAS
} }
public void setVariableSized(boolean value) { public void setVariableSized(boolean value) {
assertNotFrozen();
varSized = value; varSized = value;
} }
} }

View file

@ -45,6 +45,7 @@ public class CASTParameterDeclaration extends ASTNode implements IASTParameterDe
} }
public void setDeclSpecifier(IASTDeclSpecifier declSpec) { public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
assertNotFrozen();
this.declSpec = declSpec; this.declSpec = declSpec;
if (declSpec != null) { if (declSpec != null) {
declSpec.setParent(this); declSpec.setParent(this);
@ -53,6 +54,7 @@ public class CASTParameterDeclaration extends ASTNode implements IASTParameterDe
} }
public void setDeclarator(IASTDeclarator declarator) { public void setDeclarator(IASTDeclarator declarator) {
assertNotFrozen();
this.declarator = declarator; this.declarator = declarator;
if (declarator != null) { if (declarator != null) {
declarator.setParent(this); declarator.setParent(this);

View file

@ -28,6 +28,7 @@ public class CASTPointer extends ASTNode implements ICASTPointer {
} }
public void setRestrict(boolean value) { public void setRestrict(boolean value) {
assertNotFrozen();
isRestrict = value; isRestrict = value;
} }
@ -40,10 +41,12 @@ public class CASTPointer extends ASTNode implements ICASTPointer {
} }
public void setConst(boolean value) { public void setConst(boolean value) {
assertNotFrozen();
isConst = value; isConst = value;
} }
public void setVolatile(boolean value) { public void setVolatile(boolean value) {
assertNotFrozen();
isVolatile = value; isVolatile = value;
} }

View file

@ -35,6 +35,7 @@ abstract class CASTProblemOwner extends ASTNode implements IASTProblemHolder {
} }
public void setProblem(IASTProblem p) { public void setProblem(IASTProblem p) {
assertNotFrozen();
problem = p; problem = p;
if (p != null) { if (p != null) {
p.setParent(this); p.setParent(this);

View file

@ -39,6 +39,7 @@ public class CASTReturnStatement extends ASTNode implements
public void setReturnValue(IASTExpression returnValue) { public void setReturnValue(IASTExpression returnValue) {
assertNotFrozen();
retValue = returnValue; retValue = returnValue;
if (returnValue != null) { if (returnValue != null) {
returnValue.setParent(this); returnValue.setParent(this);

View file

@ -49,22 +49,27 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
} }
public void setType(int type) { public void setType(int type) {
assertNotFrozen();
simpleType = type; simpleType = type;
} }
public void setShort(boolean value) { public void setShort(boolean value) {
assertNotFrozen();
isShort = value; isShort = value;
} }
public void setLong(boolean value) { public void setLong(boolean value) {
assertNotFrozen();
isLong = value; isLong = value;
} }
public void setUnsigned(boolean value) { public void setUnsigned(boolean value) {
assertNotFrozen();
isUnsigned = value; isUnsigned = value;
} }
public void setSigned(boolean value) { public void setSigned(boolean value) {
assertNotFrozen();
isSigned = value; isSigned = value;
} }
@ -73,6 +78,7 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
} }
public void setLongLong(boolean value) { public void setLongLong(boolean value) {
assertNotFrozen();
longlong = value; longlong = value;
} }
@ -100,6 +106,7 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
} }
public void setComplex(boolean value) { public void setComplex(boolean value) {
assertNotFrozen();
this.complex = value; this.complex = value;
} }
@ -108,6 +115,7 @@ public class CASTSimpleDeclSpecifier extends CASTBaseDeclSpecifier implements IC
} }
public void setImaginary(boolean value) { public void setImaginary(boolean value) {
assertNotFrozen();
this.imaginary = value; this.imaginary = value;
} }
} }

View file

@ -43,6 +43,7 @@ public class CASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclarat
} }
public void addDeclarator( IASTDeclarator d ) { public void addDeclarator( IASTDeclarator d ) {
assertNotFrozen();
if (d != null) { if (d != null) {
d.setParent(this); d.setParent(this);
d.setPropertyInParent(DECLARATOR); d.setPropertyInParent(DECLARATOR);
@ -57,6 +58,7 @@ public class CASTSimpleDeclaration extends ASTNode implements IASTSimpleDeclarat
public void setDeclSpecifier(IASTDeclSpecifier declSpecifier) { public void setDeclSpecifier(IASTDeclSpecifier declSpecifier) {
assertNotFrozen();
this.declSpecifier = declSpecifier; this.declSpecifier = declSpecifier;
if (declSpecifier != null) { if (declSpecifier != null) {
declSpecifier.setParent(this); declSpecifier.setParent(this);

View file

@ -41,6 +41,7 @@ public class CASTSwitchStatement extends ASTNode implements
} }
public void setControllerExpression(IASTExpression controller) { public void setControllerExpression(IASTExpression controller) {
assertNotFrozen();
this.controller = controller; this.controller = controller;
if (controller != null) { if (controller != null) {
controller.setParent(this); controller.setParent(this);
@ -53,6 +54,7 @@ public class CASTSwitchStatement extends ASTNode implements
} }
public void setBody(IASTStatement body) { public void setBody(IASTStatement body) {
assertNotFrozen();
this.body = body; this.body = body;
if (body != null) { if (body != null) {
body.setParent(this); body.setParent(this);

View file

@ -38,6 +38,7 @@ public class CASTTypeId extends ASTNode implements IASTTypeId {
} }
public void setDeclSpecifier(IASTDeclSpecifier declSpec) { public void setDeclSpecifier(IASTDeclSpecifier declSpec) {
assertNotFrozen();
this.declSpecifier = declSpec; this.declSpecifier = declSpec;
if (declSpec != null) { if (declSpec != null) {
declSpec.setParent(this); declSpec.setParent(this);
@ -50,6 +51,7 @@ public class CASTTypeId extends ASTNode implements IASTTypeId {
} }
public void setAbstractDeclarator(IASTDeclarator abstractDeclarator) { public void setAbstractDeclarator(IASTDeclarator abstractDeclarator) {
assertNotFrozen();
declarator = abstractDeclarator; declarator = abstractDeclarator;
if (abstractDeclarator != null) { if (abstractDeclarator != null) {
abstractDeclarator.setParent(this); abstractDeclarator.setParent(this);

View file

@ -39,10 +39,12 @@ public class CASTTypeIdExpression extends ASTNode implements
} }
public void setOperator(int value) { public void setOperator(int value) {
assertNotFrozen();
this.op = value; this.op = value;
} }
public void setTypeId(IASTTypeId typeId) { public void setTypeId(IASTTypeId typeId) {
assertNotFrozen();
this.typeId = typeId; this.typeId = typeId;
if (typeId != null) { if (typeId != null) {
typeId.setParent(this); typeId.setParent(this);

View file

@ -41,6 +41,7 @@ public class CASTTypeIdInitializerExpression extends ASTNode implements
} }
public void setTypeId(IASTTypeId typeId) { public void setTypeId(IASTTypeId typeId) {
assertNotFrozen();
this.typeId = typeId; this.typeId = typeId;
if (typeId != null) { if (typeId != null) {
typeId.setParent(this); typeId.setParent(this);
@ -53,6 +54,7 @@ public class CASTTypeIdInitializerExpression extends ASTNode implements
} }
public void setInitializer(IASTInitializer initializer) { public void setInitializer(IASTInitializer initializer) {
assertNotFrozen();
this.initializer = initializer; this.initializer = initializer;
if (initializer != null) { if (initializer != null) {
initializer.setParent(this); initializer.setParent(this);

View file

@ -41,6 +41,7 @@ public class CASTTypedefNameSpecifier extends CASTBaseDeclSpecifier implements
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);

View file

@ -42,6 +42,7 @@ public class CASTUnaryExpression extends ASTNode implements
} }
public void setOperator(int value) { public void setOperator(int value) {
assertNotFrozen();
this.operator = value; this.operator = value;
} }
@ -50,6 +51,7 @@ public class CASTUnaryExpression extends ASTNode implements
} }
public void setOperand(IASTExpression expression) { public void setOperand(IASTExpression expression) {
assertNotFrozen();
operand = expression; operand = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -41,6 +41,7 @@ public class CASTWhileStatement extends ASTNode implements IASTWhileStatement, I
} }
public void setCondition(IASTExpression condition) { public void setCondition(IASTExpression condition) {
assertNotFrozen();
this.condition = condition; this.condition = condition;
if (condition != null) { if (condition != null) {
condition.setParent(this); condition.setParent(this);
@ -53,6 +54,7 @@ public class CASTWhileStatement extends ASTNode implements IASTWhileStatement, I
} }
public void setBody(IASTStatement body) { public void setBody(IASTStatement body) {
assertNotFrozen();
this.body = body; this.body = body;
if (body != null) { if (body != null) {
body.setParent(this); body.setParent(this);

View file

@ -8,7 +8,7 @@
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.c99; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration; import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
@ -27,7 +27,6 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
import org.eclipse.cdt.core.dom.ast.IASTDoStatement; import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList; import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
@ -67,78 +66,19 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier; import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator; import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer; import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICNodeFactory;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.dom.lrparser.action.ASTCompletionNode; import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression; import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTASMDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTAmbiguousExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTAmbiguousStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTArrayDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTArrayDesignator;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTArrayModifier;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTArraySubscriptExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTBinaryExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTBreakStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTCaseStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTCastExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTCompositeTypeSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTCompoundStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTConditionalExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTContinueStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTDeclarationStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTDefaultStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTDesignatedInitializer;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTDoStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTElaboratedTypeSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTEnumerationSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTEnumerator;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTExpressionList;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTExpressionStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTFieldDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTFieldDesignator;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTFieldReference;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTForStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTFunctionCallExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTFunctionDefinition;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTGotoStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTIfStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTInitializerExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTInitializerList;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTKnRFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTLabelStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTLiteralExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTModifiedArrayModifier;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTName;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTNullStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTParameterDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTPointer;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTProblem;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTProblemDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTProblemExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTProblemStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTReturnStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTSimpleDeclSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTSimpleDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTSwitchStatement;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTTypeId;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTTypeIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTTypeIdInitializerExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTTypedefNameSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTUnaryExpression;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTWhileStatement;
@SuppressWarnings("restriction") // all AST node constructors are internal
/** /**
* Abstract factory implementation that creates AST nodes for C99. * Abstract factory implementation that creates AST nodes for C99.
* These can be overridden in subclasses to change the * These can be overridden in subclasses to change the
@ -146,10 +86,20 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CASTWhileStatement;
* *
* @author Mike Kucera * @author Mike Kucera
*/ */
public class C99ASTNodeFactory implements IC99ASTNodeFactory { public class CNodeFactory implements ICNodeFactory {
public static final C99ASTNodeFactory DEFAULT_INSTANCE = new C99ASTNodeFactory(); private static final CNodeFactory DEFAULT_INSTANCE = new CNodeFactory();
public static CNodeFactory getDefault() {
return DEFAULT_INSTANCE;
}
public IASTTranslationUnit newTranslationUnit() {
CASTTranslationUnit tu = new CASTTranslationUnit();
tu.setASTNodeFactory(this);
return tu;
}
public IASTName newName(char[] name) { public IASTName newName(char[] name) {
return new CASTName(name); return new CASTName(name);
@ -159,15 +109,8 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTName(); return new CASTName();
} }
/**
* TODO: this should return IASTCompletionNode
*/
public ASTCompletionNode newCompletionNode(String prefix, IASTTranslationUnit tu) {
return new ASTCompletionNode((prefix == null || prefix.length() == 0) ? null : prefix, tu);
}
public IASTLiteralExpression newLiteralExpression(int kind, String rep) { public IASTLiteralExpression newLiteralExpression(int kind, String rep) {
return new CASTLiteralExpression(kind, rep); return new CASTLiteralExpression(kind, rep.toCharArray());
} }
public IASTIdExpression newIdExpression(IASTName name) { public IASTIdExpression newIdExpression(IASTName name) {
@ -194,8 +137,8 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTExpressionList(); return new CASTExpressionList();
} }
public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner, boolean isPointerDereference) { public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner) {
return new CASTFieldReference(name, owner, isPointerDereference); return new CASTFieldReference(name, owner);
} }
public IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) { public IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
@ -206,8 +149,8 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTTypeIdExpression(operator, typeId); return new CASTTypeIdExpression(operator, typeId);
} }
public ICASTTypeIdInitializerExpression newCTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializerList list) { public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
return new CASTTypeIdInitializerExpression(typeId, list); return new CASTTypeIdInitializerExpression(typeId, initializer);
} }
/** /**
@ -229,23 +172,23 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTArrayDeclarator(name); return new CASTArrayDeclarator(name);
} }
public ICASTArrayModifier newModifiedArrayModifier() {
return new CASTModifiedArrayModifier();
}
public IASTArrayModifier newArrayModifier(IASTExpression expr) { public IASTArrayModifier newArrayModifier(IASTExpression expr) {
return new CASTArrayModifier(expr); return new CASTArrayModifier(expr);
} }
public ICASTArrayModifier newModifiedArrayModifier(IASTExpression expr) {
return new CASTModifiedArrayModifier(expr);
}
public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name) { public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name) {
return new CASTFunctionDeclarator(name); return new CASTFunctionDeclarator(name);
} }
public ICASTKnRFunctionDeclarator newCKnRFunctionDeclarator() { public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator(IASTName[] parameterNames, IASTDeclaration[] parameterDeclarations) {
return new CASTKnRFunctionDeclarator(); return new CASTKnRFunctionDeclarator(parameterNames, parameterDeclarations);
} }
public ICASTPointer newCPointer() { public ICASTPointer newPointer() {
return new CASTPointer(); return new CASTPointer();
} }
@ -261,24 +204,20 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTInitializerList(); return new CASTInitializerList();
} }
public ICASTDesignatedInitializer newCDesignatedInitializer(IASTInitializer rhs) { public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializer operandInitializer) {
return new CASTDesignatedInitializer(rhs); return new CASTDesignatedInitializer(operandInitializer);
} }
public ICASTArrayDesignator newCArrayDesignator(IASTExpression exp) { public ICASTArrayDesignator newArrayDesignator(IASTExpression exp) {
return new CASTArrayDesignator(exp); return new CASTArrayDesignator(exp);
} }
public ICASTFieldDesignator newCFieldDesignator(IASTName name) { public ICASTFieldDesignator newFieldDesignator(IASTName name) {
return new CASTFieldDesignator(name); return new CASTFieldDesignator(name);
} }
public ICASTSimpleDeclSpecifier newCSimpleDeclSpecifier() { public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name) {
return new CASTSimpleDeclSpecifier(); return new CASTTypedefNameSpecifier(name);
}
public ICASTTypedefNameSpecifier newCTypedefNameSpecifier() {
return new CASTTypedefNameSpecifier();
} }
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) { public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
@ -289,11 +228,11 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTFieldDeclarator(name, bitFieldSize); return new CASTFieldDeclarator(name, bitFieldSize);
} }
public ICASTCompositeTypeSpecifier newCCompositeTypeSpecifier(int key, IASTName name) { public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name) {
return new CASTCompositeTypeSpecifier(key, name); return new CASTCompositeTypeSpecifier(key, name);
} }
public IASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) { public ICASTElaboratedTypeSpecifier newElaboratedTypeSpecifier(int kind, IASTName name) {
return new CASTElaboratedTypeSpecifier(kind, name); return new CASTElaboratedTypeSpecifier(kind, name);
} }
@ -358,7 +297,7 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTDefaultStatement(); return new CASTDefaultStatement();
} }
public IASTSwitchStatement newSwitchStatment(IASTExpression controller, IASTStatement body) { public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body) {
return new CASTSwitchStatement(controller, body); return new CASTSwitchStatement(controller, body);
} }
@ -371,34 +310,22 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTFunctionDefinition(declSpecifier, declarator, bodyStatement); return new CASTFunctionDefinition(declSpecifier, declarator, bodyStatement);
} }
public IASTProblemDeclaration newProblemDeclaration() { public IASTProblemDeclaration newProblemDeclaration(IASTProblem problem) {
return new CASTProblemDeclaration(); return new CASTProblemDeclaration(problem);
} }
public IASTProblemStatement newProblemStatement() { public IASTProblemStatement newProblemStatement(IASTProblem problem) {
return new CASTProblemStatement(); return new CASTProblemStatement(problem);
} }
public IASTProblemExpression newProblemExpression() { public IASTProblemExpression newProblemExpression(IASTProblem problem) {
return new CASTProblemExpression(); return new CASTProblemExpression(problem);
} }
public IASTProblem newProblem(int id, char[] arg, boolean error) { public IASTProblem newProblem(int id, char[] arg, boolean error) {
return new CASTProblem(id, arg, error); return new CASTProblem(id, arg, error);
} }
public IASTAmbiguousExpression newAmbiguousExpression(IASTExpression... expressions) {
return new CASTAmbiguousExpression(expressions);
}
public IASTAmbiguousStatement newAmbiguousStatement(IASTStatement... statements) {
return new CASTAmbiguousStatement(statements);
}
public IASTTranslationUnit newTranslationUnit() {
return new CASTTranslationUnit();
}
public IASTASMDeclaration newASMDeclaration(String assembly) { public IASTASMDeclaration newASMDeclaration(String assembly) {
return new CASTASMDeclaration(assembly); return new CASTASMDeclaration(assembly);
} }
@ -407,11 +334,21 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTEnumerationSpecifier(name); return new CASTEnumerationSpecifier(name);
} }
public IASTDeclSpecifier newSimpleDeclSpecifier() { public ICASTSimpleDeclSpecifier newSimpleDeclSpecifier() {
return newCSimpleDeclSpecifier(); return new CASTSimpleDeclSpecifier();
} }
public IGNUASTCompoundStatementExpression newGNUCompoundStatementExpression(IASTCompoundStatement compoundStatement) {
return new CASTCompoundStatementExpression(compoundStatement);
}
public IGCCASTArrayRangeDesignator newArrayRangeDesignatorGCC(IASTExpression floor, IASTExpression ceiling) {
return new CASTArrayRangeDesignator(floor, ceiling);
}
public IGCCASTSimpleDeclSpecifier newSimpleDeclSpecifierGCC(IASTExpression typeofExpression) {
return new GCCASTSimpleDeclSpecifier(typeofExpression);
}
} }

View file

@ -34,6 +34,7 @@ public class CPPASTASMDeclaration extends ASTNode implements IASTASMDeclaration
} }
public void setAssembly(String assembly) { public void setAssembly(String assembly) {
assertNotFrozen();
this.assembly = assembly.toCharArray(); this.assembly = assembly.toCharArray();
} }

View file

@ -31,6 +31,7 @@ public class CPPASTAmbiguousDeclaration extends CPPASTAmbiguity implements IASTA
} }
public void addDeclaration(IASTDeclaration d) { public void addDeclaration(IASTDeclaration d) {
assertNotFrozen();
if (d != null) { if (d != null) {
decls = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class, decls, ++declsPos, d ); decls = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class, decls, ++declsPos, d );
d.setParent(this); d.setParent(this);

View file

@ -40,6 +40,7 @@ public class CPPASTAmbiguousDeclarator extends CPPASTAmbiguity implements IASTAm
} }
public void addDeclarator(IASTDeclarator d) { public void addDeclarator(IASTDeclarator d) {
assertNotFrozen();
if (d != null) { if (d != null) {
dtors = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, dtors, ++dtorPos, d); dtors = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, dtors, ++dtorPos, d);
d.setParent(this); d.setParent(this);
@ -78,18 +79,22 @@ public class CPPASTAmbiguousDeclarator extends CPPASTAmbiguity implements IASTAm
} }
public void addPointerOperator(IASTPointerOperator operator) { public void addPointerOperator(IASTPointerOperator operator) {
assertNotFrozen();
Assert.isLegal(false); Assert.isLegal(false);
} }
public void setInitializer(IASTInitializer initializer) { public void setInitializer(IASTInitializer initializer) {
assertNotFrozen();
Assert.isLegal(false); Assert.isLegal(false);
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
Assert.isLegal(false); Assert.isLegal(false);
} }
public void setNestedDeclarator(IASTDeclarator nested) { public void setNestedDeclarator(IASTDeclarator nested) {
assertNotFrozen();
Assert.isLegal(false); Assert.isLegal(false);
} }
} }

View file

@ -36,6 +36,7 @@ public class CPPASTAmbiguousExpression extends CPPASTAmbiguity implements
} }
public void addExpression(IASTExpression e) { public void addExpression(IASTExpression e) {
assertNotFrozen();
if (e != null) { if (e != null) {
exp = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, exp, ++expPos, e ); exp = (IASTExpression[]) ArrayUtil.append( IASTExpression.class, exp, ++expPos, e );
e.setParent(this); e.setParent(this);

View file

@ -27,6 +27,7 @@ public class CPPASTAmbiguousStatement extends CPPASTAmbiguity implements
} }
public void addStatement(IASTStatement s) { public void addStatement(IASTStatement s) {
assertNotFrozen();
if (s != null) { if (s != null) {
stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, ++stmtsPos, s ); stmts = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, stmts, ++stmtsPos, s );
s.setParent(this); s.setParent(this);

View file

@ -61,10 +61,12 @@ public class CPPASTAmbiguousTemplateArgument extends CPPASTAmbiguity implements
} }
public void addTypeId(IASTTypeId typeId) { public void addTypeId(IASTTypeId typeId) {
assertNotFrozen();
addNode(typeId); addNode(typeId);
} }
public void addIdExpression(IASTIdExpression idExpression) { public void addIdExpression(IASTIdExpression idExpression) {
assertNotFrozen();
addNode(idExpression); addNode(idExpression);
} }

View file

@ -47,6 +47,7 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements
} }
public void addArrayModifier(IASTArrayModifier arrayModifier) { public void addArrayModifier(IASTArrayModifier arrayModifier) {
assertNotFrozen();
if (arrayModifier != null) { if (arrayModifier != null) {
arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, ++arrayModsPos, arrayModifier ); arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, ++arrayModsPos, arrayModifier );
arrayModifier.setParent(this); arrayModifier.setParent(this);

View file

@ -37,6 +37,7 @@ public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, I
} }
public void setConstantExpression(IASTExpression expression) { public void setConstantExpression(IASTExpression expression) {
assertNotFrozen();
exp = expression; exp = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -41,6 +41,7 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements IASTArray
} }
public void setArrayExpression(IASTExpression expression) { public void setArrayExpression(IASTExpression expression) {
assertNotFrozen();
arrayExpression = expression; arrayExpression = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);
@ -53,6 +54,7 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements IASTArray
} }
public void setSubscriptExpression(IASTExpression expression) { public void setSubscriptExpression(IASTExpression expression) {
assertNotFrozen();
subscriptExp = expression; subscriptExp = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -36,6 +36,7 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST
} }
public void setStorageClass(int storageClass) { public void setStorageClass(int storageClass) {
assertNotFrozen();
sc = storageClass; sc = storageClass;
} }
@ -44,6 +45,7 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST
} }
public void setConst(boolean value) { public void setConst(boolean value) {
assertNotFrozen();
isConst = value; isConst = value;
} }
@ -52,6 +54,7 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST
} }
public void setVolatile(boolean value) { public void setVolatile(boolean value) {
assertNotFrozen();
volatil = value; volatil = value;
} }
@ -60,10 +63,12 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST
} }
public void setInline(boolean value) { public void setInline(boolean value) {
assertNotFrozen();
this.inline = value; this.inline = value;
} }
public void setFriend(boolean value) { public void setFriend(boolean value) {
assertNotFrozen();
friend = value; friend = value;
} }
@ -72,6 +77,7 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST
} }
public void setVirtual(boolean value) { public void setVirtual(boolean value) {
assertNotFrozen();
virtual = value; virtual = value;
} }
@ -80,6 +86,7 @@ public abstract class CPPASTBaseDeclSpecifier extends ASTNode implements ICPPAST
} }
public void setExplicit(boolean value) { public void setExplicit(boolean value) {
assertNotFrozen();
this.explicit = value; this.explicit = value;
} }

View file

@ -51,6 +51,7 @@ public class CPPASTBaseSpecifier extends ASTNode implements
} }
public void setVirtual(boolean value) { public void setVirtual(boolean value) {
assertNotFrozen();
isVirtual = value; isVirtual = value;
} }
@ -59,6 +60,7 @@ public class CPPASTBaseSpecifier extends ASTNode implements
} }
public void setVisibility(int visibility) { public void setVisibility(int visibility) {
assertNotFrozen();
this.visibility = visibility; this.visibility = visibility;
} }
@ -67,6 +69,7 @@ public class CPPASTBaseSpecifier extends ASTNode implements
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);

View file

@ -51,10 +51,12 @@ public class CPPASTBinaryExpression extends ASTNode implements
} }
public void setOperator(int op) { public void setOperator(int op) {
assertNotFrozen();
this.op = op; this.op = op;
} }
public void setOperand1(IASTExpression expression) { public void setOperand1(IASTExpression expression) {
assertNotFrozen();
operand1 = expression; operand1 = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);
@ -63,6 +65,7 @@ public class CPPASTBinaryExpression extends ASTNode implements
} }
public void setOperand2(IASTExpression expression) { public void setOperand2(IASTExpression expression) {
assertNotFrozen();
operand2 = expression; operand2 = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -36,6 +36,7 @@ public class CPPASTCaseStatement extends ASTNode implements IASTCaseStatement, I
} }
public void setExpression(IASTExpression expression) { public void setExpression(IASTExpression expression) {
assertNotFrozen();
this.expression = expression; this.expression = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -32,6 +32,7 @@ public class CPPASTCastExpression extends CPPASTUnaryExpression implements ICPPA
} }
public void setTypeId(IASTTypeId typeId) { public void setTypeId(IASTTypeId typeId) {
assertNotFrozen();
this.typeId = typeId; this.typeId = typeId;
if (typeId != null) { if (typeId != null) {
typeId.setParent(this); typeId.setParent(this);
@ -45,6 +46,7 @@ public class CPPASTCastExpression extends CPPASTUnaryExpression implements ICPPA
@Override @Override
public void setOperand(IASTExpression expression) { public void setOperand(IASTExpression expression) {
assertNotFrozen();
super.setOperand(expression); super.setOperand(expression);
// this needs to be overridden because CPPASTUnaryExpression sets // this needs to be overridden because CPPASTUnaryExpression sets
// propertyInParent to ICPPASTUnaryExpression.OPERAND, we want // propertyInParent to ICPPASTUnaryExpression.OPERAND, we want

View file

@ -39,6 +39,7 @@ public class CPPASTCatchHandler extends ASTNode implements ICPPASTCatchHandler,
} }
public void setIsCatchAll(boolean isEllipsis) { public void setIsCatchAll(boolean isEllipsis) {
assertNotFrozen();
isCatchAll = isEllipsis; isCatchAll = isEllipsis;
} }
@ -47,6 +48,7 @@ public class CPPASTCatchHandler extends ASTNode implements ICPPASTCatchHandler,
} }
public void setCatchBody(IASTStatement compoundStatement) { public void setCatchBody(IASTStatement compoundStatement) {
assertNotFrozen();
body = compoundStatement; body = compoundStatement;
if (compoundStatement != null) { if (compoundStatement != null) {
compoundStatement.setParent(this); compoundStatement.setParent(this);
@ -59,6 +61,7 @@ public class CPPASTCatchHandler extends ASTNode implements ICPPASTCatchHandler,
} }
public void setDeclaration(IASTDeclaration decl) { public void setDeclaration(IASTDeclaration decl) {
assertNotFrozen();
declaration = decl; declaration = decl;
if (decl != null) { if (decl != null) {
decl.setParent(this); decl.setParent(this);

View file

@ -52,6 +52,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
} }
public void addBaseSpecifier(ICPPASTBaseSpecifier baseSpec) { public void addBaseSpecifier(ICPPASTBaseSpecifier baseSpec) {
assertNotFrozen();
if (baseSpec != null) { if (baseSpec != null) {
baseSpec.setParent(this); baseSpec.setParent(this);
baseSpec.setPropertyInParent(BASE_SPECIFIER); baseSpec.setPropertyInParent(BASE_SPECIFIER);
@ -64,6 +65,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
} }
public void setKey(int key) { public void setKey(int key) {
assertNotFrozen();
k = key; k = key;
} }
@ -72,6 +74,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.n = name; this.n = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);
@ -86,6 +89,7 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
} }
public void addMemberDeclaration(IASTDeclaration decl) { public void addMemberDeclaration(IASTDeclaration decl) {
assertNotFrozen();
declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, decl ); declarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, declarations, decl );
if(decl != null) { if(decl != null) {
decl.setParent(this); decl.setParent(this);

View file

@ -36,6 +36,7 @@ public class CPPASTCompoundStatement extends ASTNode implements
} }
public void addStatement(IASTStatement statement) { public void addStatement(IASTStatement statement) {
assertNotFrozen();
statements = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, statements, statement ); statements = (IASTStatement[]) ArrayUtil.append( IASTStatement.class, statements, statement );
if (statement != null) { if (statement != null) {
statement.setParent(this); statement.setParent(this);

View file

@ -37,6 +37,7 @@ public class CPPASTCompoundStatementExpression extends ASTNode implements IGNUAS
} }
public void setCompoundStatement(IASTCompoundStatement statement) { public void setCompoundStatement(IASTCompoundStatement statement) {
assertNotFrozen();
this.statement = statement; this.statement = statement;
if (statement != null) { if (statement != null) {
statement.setParent(this); statement.setParent(this);

View file

@ -44,6 +44,7 @@ public class CPPASTConditionalExpression extends ASTNode implements
} }
public void setLogicalConditionExpression(IASTExpression expression) { public void setLogicalConditionExpression(IASTExpression expression) {
assertNotFrozen();
condition = expression; condition = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);
@ -56,6 +57,7 @@ public class CPPASTConditionalExpression extends ASTNode implements
} }
public void setPositiveResultExpression(IASTExpression expression) { public void setPositiveResultExpression(IASTExpression expression) {
assertNotFrozen();
this.postive = expression; this.postive = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);
@ -68,6 +70,7 @@ public class CPPASTConditionalExpression extends ASTNode implements
} }
public void setNegativeResultExpression(IASTExpression expression) { public void setNegativeResultExpression(IASTExpression expression) {
assertNotFrozen();
this.negative = expression; this.negative = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -32,9 +32,9 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
public CPPASTConstructorChainInitializer() { public CPPASTConstructorChainInitializer() {
} }
public CPPASTConstructorChainInitializer(IASTName name, IASTExpression value) { public CPPASTConstructorChainInitializer(IASTName memberInitializerid, IASTExpression initializerValue) {
setMemberInitializerId(name); setMemberInitializerId(memberInitializerid);
setInitializerValue(value); setInitializerValue(initializerValue);
} }
public IASTName getMemberInitializerId() { public IASTName getMemberInitializerId() {
@ -42,6 +42,7 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
} }
public void setMemberInitializerId(IASTName name) { public void setMemberInitializerId(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if(name != null) { if(name != null) {
name.setParent(this); name.setParent(this);
@ -55,6 +56,7 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
public void setInitializerValue(IASTExpression expression) { public void setInitializerValue(IASTExpression expression) {
assertNotFrozen();
value = expression; value = expression;
if(expression != null) { if(expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -38,6 +38,7 @@ public class CPPASTConstructorInitializer extends ASTNode implements
} }
public void setExpression(IASTExpression expression) { public void setExpression(IASTExpression expression) {
assertNotFrozen();
this.exp = expression; this.exp = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -41,6 +41,7 @@ public class CPPASTConversionName extends CPPASTName implements ICPPASTConversio
} }
public void setTypeId(IASTTypeId typeId) { public void setTypeId(IASTTypeId typeId) {
assertNotFrozen();
this.typeId=typeId; this.typeId=typeId;
if (typeId != null) { if (typeId != null) {
typeId.setParent(this); typeId.setParent(this);

View file

@ -38,6 +38,7 @@ public class CPPASTDeclarationStatement extends ASTNode implements
} }
public void setDeclaration(IASTDeclaration declaration) { public void setDeclaration(IASTDeclaration declaration) {
assertNotFrozen();
this.declaration = declaration; this.declaration = declaration;
if (declaration != null) { if (declaration != null) {
declaration.setParent(this); declaration.setParent(this);

View file

@ -69,6 +69,7 @@ public class CPPASTDeclarator extends ASTNode implements IASTDeclarator {
} }
public void setInitializer(IASTInitializer initializer) { public void setInitializer(IASTInitializer initializer) {
assertNotFrozen();
this.initializer = initializer; this.initializer = initializer;
if (initializer != null) { if (initializer != null) {
initializer.setParent(this); initializer.setParent(this);
@ -77,6 +78,7 @@ public class CPPASTDeclarator extends ASTNode implements IASTDeclarator {
} }
public void addPointerOperator(IASTPointerOperator operator) { public void addPointerOperator(IASTPointerOperator operator) {
assertNotFrozen();
if (operator != null) { if (operator != null) {
operator.setParent(this); operator.setParent(this);
operator.setPropertyInParent(POINTER_OPERATOR); operator.setPropertyInParent(POINTER_OPERATOR);
@ -85,6 +87,7 @@ public class CPPASTDeclarator extends ASTNode implements IASTDeclarator {
} }
public void setNestedDeclarator(IASTDeclarator nested) { public void setNestedDeclarator(IASTDeclarator nested) {
assertNotFrozen();
this.nestedDeclarator = nested; this.nestedDeclarator = nested;
if (nested != null) { if (nested != null) {
nested.setParent(this); nested.setParent(this);
@ -93,6 +96,7 @@ public class CPPASTDeclarator extends ASTNode implements IASTDeclarator {
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);

View file

@ -42,6 +42,7 @@ public class CPPASTDeleteExpression extends ASTNode implements
} }
public void setOperand(IASTExpression expression) { public void setOperand(IASTExpression expression) {
assertNotFrozen();
operand = expression; operand = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);
@ -50,6 +51,7 @@ public class CPPASTDeleteExpression extends ASTNode implements
} }
public void setIsGlobal(boolean global) { public void setIsGlobal(boolean global) {
assertNotFrozen();
isGlobal = global; isGlobal = global;
} }
@ -58,6 +60,7 @@ public class CPPASTDeleteExpression extends ASTNode implements
} }
public void setIsVectored(boolean vectored) { public void setIsVectored(boolean vectored) {
assertNotFrozen();
isVectored = vectored; isVectored = vectored;
} }

View file

@ -40,6 +40,7 @@ public class CPPASTDoStatement extends ASTNode implements IASTDoStatement, IASTA
} }
public void setBody(IASTStatement body) { public void setBody(IASTStatement body) {
assertNotFrozen();
this.body = body; this.body = body;
if (body != null) { if (body != null) {
body.setParent(this); body.setParent(this);
@ -52,6 +53,7 @@ public class CPPASTDoStatement extends ASTNode implements IASTDoStatement, IASTA
} }
public void setCondition(IASTExpression condition) { public void setCondition(IASTExpression condition) {
assertNotFrozen();
this.condition = condition; this.condition = condition;
if (condition != null) { if (condition != null) {
condition.setParent(this); condition.setParent(this);

View file

@ -44,6 +44,7 @@ public class CPPASTElaboratedTypeSpecifier extends CPPASTBaseDeclSpecifier
} }
public void setKind(int value) { public void setKind(int value) {
assertNotFrozen();
this.kind = value; this.kind = value;
} }
@ -52,6 +53,7 @@ public class CPPASTElaboratedTypeSpecifier extends CPPASTBaseDeclSpecifier
} }
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);

View file

@ -42,6 +42,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier
} }
public void addEnumerator(IASTEnumerator enumerator) { public void addEnumerator(IASTEnumerator enumerator) {
assertNotFrozen();
if (enumerator != null) { if (enumerator != null) {
enumerator.setParent(this); enumerator.setParent(this);
enumerator.setPropertyInParent(ENUMERATOR); enumerator.setPropertyInParent(ENUMERATOR);
@ -61,6 +62,7 @@ public class CPPASTEnumerationSpecifier extends CPPASTBaseDeclSpecifier
private int enumeratorsPos=-1; private int enumeratorsPos=-1;
public void setName(IASTName name) { public void setName(IASTName name) {
assertNotFrozen();
this.name = name; this.name = name;
if (name != null) { if (name != null) {
name.setParent(this); name.setParent(this);

View file

@ -38,6 +38,7 @@ public class CPPASTExplicitTemplateInstantiation extends ASTNode implements
} }
public void setDeclaration(IASTDeclaration declaration) { public void setDeclaration(IASTDeclaration declaration) {
assertNotFrozen();
this.declaration = declaration; this.declaration = declaration;
if (declaration != null) { if (declaration != null) {
declaration.setParent(this); declaration.setParent(this);

View file

@ -32,6 +32,7 @@ public class CPPASTExpressionList extends ASTNode implements
} }
public void addExpression(IASTExpression expression) { public void addExpression(IASTExpression expression) {
assertNotFrozen();
expressions = (IASTExpression [])ArrayUtil.append( IASTExpression.class, expressions, expression ); expressions = (IASTExpression [])ArrayUtil.append( IASTExpression.class, expressions, expression );
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -38,6 +38,7 @@ public class CPPASTExpressionStatement extends ASTNode implements
} }
public void setExpression(IASTExpression expression) { public void setExpression(IASTExpression expression) {
assertNotFrozen();
this.expression = expression; this.expression = expression;
if (expression != null) { if (expression != null) {
expression.setParent(this); expression.setParent(this);

View file

@ -40,6 +40,7 @@ public class CPPASTFieldDeclarator extends CPPASTDeclarator implements
} }
public void setBitFieldSize(IASTExpression size) { public void setBitFieldSize(IASTExpression size) {
assertNotFrozen();
this.bitField = size; this.bitField = size;
if (size != null) { if (size != null) {
size.setParent(this); size.setParent(this);

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