1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +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("{ "); //$NON-NLS-1$
writer.write(" if (0) { } "); //$NON-NLS-1$
writer.write(" /* 5,000 else if's. */ "); //$NON-NLS-1$
writer.write(" THOU THOU THOU THOU THOU "); //$NON-NLS-1$
writer.write(" /* 3,000 else if's. */ "); //$NON-NLS-1$
writer.write(" THOU THOU THOU "); //$NON-NLS-1$
writer.write("} "); //$NON-NLS-1$
parse( writer.toString() );

View file

@ -184,4 +184,13 @@ public interface IASTNode {
* @since 5.1
*/
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.
*/
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:
* 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.internal.core.dom.parser.IASTAmbiguousExpression;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
/**
* 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
* @since 5.1
*/
@SuppressWarnings("restriction")
public interface IASTNodeFactory {
public interface INodeFactory {
/**
* Creates a "dummy" name using an empty char array.
*/
public IASTName newName();
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);
@ -111,7 +80,7 @@ public interface IASTNodeFactory {
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);
@ -147,17 +116,15 @@ public interface IASTNodeFactory {
public IASTFunctionDefinition newFunctionDefinition(IASTDeclSpecifier declSpecifier,
IASTFunctionDeclarator declarator, IASTStatement bodyStatement);
public IASTTranslationUnit newTranslationUnit();
public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name);
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);
@ -175,10 +142,16 @@ public interface IASTNodeFactory {
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).
* @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
*/
public IASTTranslationUnit parse();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -8,7 +8,7 @@
* Contributors:
* 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.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.IASTDefaultStatement;
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.IASTExpressionList;
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.ICASTCompositeTypeSpecifier;
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.ICASTFieldDesignator;
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.ICASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier;
import org.eclipse.cdt.core.dom.ast.c.ICNodeFactory;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.dom.lrparser.action.ASTCompletionNode;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
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;
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
@SuppressWarnings("restriction") // all AST node constructors are internal
/**
* Abstract factory implementation that creates AST nodes for C99.
* 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
*/
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) {
return new CASTName(name);
@ -159,15 +109,8 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
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) {
return new CASTLiteralExpression(kind, rep);
return new CASTLiteralExpression(kind, rep.toCharArray());
}
public IASTIdExpression newIdExpression(IASTName name) {
@ -194,8 +137,8 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTExpressionList();
}
public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner, boolean isPointerDereference) {
return new CASTFieldReference(name, owner, isPointerDereference);
public IASTFieldReference newFieldReference(IASTName name, IASTExpression owner) {
return new CASTFieldReference(name, owner);
}
public IASTUnaryExpression newUnaryExpression(int operator, IASTExpression operand) {
@ -206,8 +149,8 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTTypeIdExpression(operator, typeId);
}
public ICASTTypeIdInitializerExpression newCTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializerList list) {
return new CASTTypeIdInitializerExpression(typeId, list);
public ICASTTypeIdInitializerExpression newTypeIdInitializerExpression(IASTTypeId typeId, IASTInitializer initializer) {
return new CASTTypeIdInitializerExpression(typeId, initializer);
}
/**
@ -229,23 +172,23 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTArrayDeclarator(name);
}
public ICASTArrayModifier newModifiedArrayModifier() {
return new CASTModifiedArrayModifier();
}
public IASTArrayModifier newArrayModifier(IASTExpression expr) {
return new CASTArrayModifier(expr);
}
public ICASTArrayModifier newModifiedArrayModifier(IASTExpression expr) {
return new CASTModifiedArrayModifier(expr);
}
public IASTStandardFunctionDeclarator newFunctionDeclarator(IASTName name) {
return new CASTFunctionDeclarator(name);
}
public ICASTKnRFunctionDeclarator newCKnRFunctionDeclarator() {
return new CASTKnRFunctionDeclarator();
public ICASTKnRFunctionDeclarator newKnRFunctionDeclarator(IASTName[] parameterNames, IASTDeclaration[] parameterDeclarations) {
return new CASTKnRFunctionDeclarator(parameterNames, parameterDeclarations);
}
public ICASTPointer newCPointer() {
public ICASTPointer newPointer() {
return new CASTPointer();
}
@ -261,24 +204,20 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTInitializerList();
}
public ICASTDesignatedInitializer newCDesignatedInitializer(IASTInitializer rhs) {
return new CASTDesignatedInitializer(rhs);
public ICASTDesignatedInitializer newDesignatedInitializer(IASTInitializer operandInitializer) {
return new CASTDesignatedInitializer(operandInitializer);
}
public ICASTArrayDesignator newCArrayDesignator(IASTExpression exp) {
public ICASTArrayDesignator newArrayDesignator(IASTExpression exp) {
return new CASTArrayDesignator(exp);
}
public ICASTFieldDesignator newCFieldDesignator(IASTName name) {
public ICASTFieldDesignator newFieldDesignator(IASTName name) {
return new CASTFieldDesignator(name);
}
public ICASTSimpleDeclSpecifier newCSimpleDeclSpecifier() {
return new CASTSimpleDeclSpecifier();
}
public ICASTTypedefNameSpecifier newCTypedefNameSpecifier() {
return new CASTTypedefNameSpecifier();
public ICASTTypedefNameSpecifier newTypedefNameSpecifier(IASTName name) {
return new CASTTypedefNameSpecifier(name);
}
public IASTSimpleDeclaration newSimpleDeclaration(IASTDeclSpecifier declSpecifier) {
@ -289,11 +228,11 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTFieldDeclarator(name, bitFieldSize);
}
public ICASTCompositeTypeSpecifier newCCompositeTypeSpecifier(int key, IASTName name) {
public ICASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName 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);
}
@ -358,7 +297,7 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTDefaultStatement();
}
public IASTSwitchStatement newSwitchStatment(IASTExpression controller, IASTStatement body) {
public IASTSwitchStatement newSwitchStatement(IASTExpression controller, IASTStatement body) {
return new CASTSwitchStatement(controller, body);
}
@ -371,34 +310,22 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTFunctionDefinition(declSpecifier, declarator, bodyStatement);
}
public IASTProblemDeclaration newProblemDeclaration() {
return new CASTProblemDeclaration();
public IASTProblemDeclaration newProblemDeclaration(IASTProblem problem) {
return new CASTProblemDeclaration(problem);
}
public IASTProblemStatement newProblemStatement() {
return new CASTProblemStatement();
public IASTProblemStatement newProblemStatement(IASTProblem problem) {
return new CASTProblemStatement(problem);
}
public IASTProblemExpression newProblemExpression() {
return new CASTProblemExpression();
public IASTProblemExpression newProblemExpression(IASTProblem problem) {
return new CASTProblemExpression(problem);
}
public IASTProblem newProblem(int id, char[] arg, boolean 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) {
return new CASTASMDeclaration(assembly);
}
@ -407,11 +334,21 @@ public class C99ASTNodeFactory implements IC99ASTNodeFactory {
return new CASTEnumerationSpecifier(name);
}
public IASTDeclSpecifier newSimpleDeclSpecifier() {
return newCSimpleDeclSpecifier();
public ICASTSimpleDeclSpecifier newSimpleDeclSpecifier() {
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) {
assertNotFrozen();
this.assembly = assembly.toCharArray();
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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