1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 17:55:39 +02:00

Removed warning.

Added IASTTranslationUnit#getFilePath().
This commit is contained in:
John Camelon 2005-02-23 19:55:18 +00:00
parent 42141ccb94
commit 37bbc9660f
3 changed files with 411 additions and 320 deletions

View file

@ -75,4 +75,5 @@ public interface IASTTranslationUnit extends IASTNode {
public IASTVisitor getVisitor(); public IASTVisitor getVisitor();
public String getFilePath();
} }

View file

@ -9,7 +9,6 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
@ -43,366 +42,447 @@ import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeExce
/** /**
* @author jcamelon * @author jcamelon
*/ */
public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit, IRequiresLocationInformation { public class CASTTranslationUnit extends CASTNode implements
IASTTranslationUnit, IRequiresLocationInformation {
private IASTDeclaration[] decls = null;
private IASTDeclaration [] decls = null; private static final int DEFAULT_CHILDREN_LIST_SIZE = 8;
private static final int DEFAULT_CHILDREN_LIST_SIZE = 8;
private int currentIndex = 0;
//Binding
private CScope compilationUnit = null;
private CVisitor visitor = null;
private ILocationResolver resolver;
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0];
private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0];
private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0];
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
public void addDeclaration( IASTDeclaration d )
{
if( decls == null )
{
decls = new IASTDeclaration[ DEFAULT_CHILDREN_LIST_SIZE ];
currentIndex = 0;
}
if( decls.length == currentIndex )
{
IASTDeclaration [] old = decls;
decls = new IASTDeclaration[ old.length * 2 ];
for( int i = 0; i < old.length; ++i )
decls[i] = old[i];
}
decls[ currentIndex++ ] = d;
}
private int currentIndex = 0;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations()
*/
public IASTDeclaration[] getDeclarations() {
if( decls == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations();
return decls;
}
/** // Binding
* @param decls2 private CScope compilationUnit = null;
*/
private void removeNullDeclarations() {
int nullCount = 0;
for( int i = 0; i < decls.length; ++i )
if( decls[i] == null )
++nullCount;
if( nullCount == 0 ) return;
IASTDeclaration [] old = decls;
int newSize = old.length - nullCount;
decls = new IASTDeclaration[ newSize ];
for( int i = 0; i < newSize; ++i )
decls[i] = old[i];
currentIndex = newSize;
}
/* (non-Javadoc) private CVisitor visitor = null;
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope()
*/ private ILocationResolver resolver;
public IScope getScope() {
if( compilationUnit == null ) private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
compilationUnit = new CScope( this );
return compilationUnit; private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0];
}
private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
/* (non-Javadoc)
private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0];
private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0];
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
public void addDeclaration(IASTDeclaration d) {
if (decls == null) {
decls = new IASTDeclaration[DEFAULT_CHILDREN_LIST_SIZE];
currentIndex = 0;
}
if (decls.length == currentIndex) {
IASTDeclaration[] old = decls;
decls = new IASTDeclaration[old.length * 2];
for (int i = 0; i < old.length; ++i)
decls[i] = old[i];
}
decls[currentIndex++] = d;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations()
*/
public IASTDeclaration[] getDeclarations() {
if (decls == null)
return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations();
return decls;
}
/**
* @param decls2
*/
private void removeNullDeclarations() {
int nullCount = 0;
for (int i = 0; i < decls.length; ++i)
if (decls[i] == null)
++nullCount;
if (nullCount == 0)
return;
IASTDeclaration[] old = decls;
int newSize = old.length - nullCount;
decls = new IASTDeclaration[newSize];
for (int i = 0; i < newSize; ++i)
decls[i] = old[i];
currentIndex = newSize;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope()
*/
public IScope getScope() {
if (compilationUnit == null)
compilationUnit = new CScope(this);
return compilationUnit;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding) * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding)
*/ */
public IASTName[] getDeclarations(IBinding binding) { public IASTName[] getDeclarations(IBinding binding) {
//TODO if binding is macro, circumvent the visitor // TODO if binding is macro, circumvent the visitor
return CVisitor.getDeclarations(this, binding); return CVisitor.getDeclarations(this, binding);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getReferences(org.eclipse.cdt.core.dom.ast.IBinding) * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getReferences(org.eclipse.cdt.core.dom.ast.IBinding)
*/ */
public IASTName[] getReferences(IBinding binding) { public IASTName[] getReferences(IBinding binding) {
//TODO if binding is macro, circumvent the visitor // TODO if binding is macro, circumvent the visitor
return CVisitor.getReferences( this, binding ); return CVisitor.getReferences(this, binding);
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int,
* int)
*/
public IASTNodeLocation[] getLocationInfo(int offset, int length) {
if (resolver == null)
return EMPTY_PREPROCESSOR_LOCATION_ARRAY;
return resolver.getLocations(offset, length);
}
private class CFindNodeForOffsetAction extends CVisitor.CBaseVisitorAction {
{
processNames = true;
processDeclarations = true;
processInitializers = true;
processParameterDeclarations = true;
processDeclarators = true;
processDeclSpecifiers = true;
processDesignators = true;
processExpressions = true;
processStatements = true;
processTypeIds = true;
processEnumerators = true;
}
/* (non-Javadoc) IASTNode foundNode = null;
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int, int)
*/
public IASTNodeLocation[] getLocationInfo(int offset, int length) {
if( resolver == null ) return EMPTY_PREPROCESSOR_LOCATION_ARRAY;
return resolver.getLocations(offset,length);
}
private class CFindNodeForOffsetAction extends CVisitor.CBaseVisitorAction { int offset = 0;
{
processNames = true; int length = 0;
processDeclarations = true;
processInitializers = true; /**
processParameterDeclarations = true;
processDeclarators = true;
processDeclSpecifiers = true;
processDesignators = true;
processExpressions = true;
processStatements = true;
processTypeIds = true;
processEnumerators = true;
}
IASTNode foundNode = null;
int offset = 0;
int length = 0;
/**
* *
*/ */
public CFindNodeForOffsetAction(int offset, int length) { public CFindNodeForOffsetAction(int offset, int length) {
this.offset = offset; this.offset = offset;
this.length = length; this.length = length;
} }
public int processNode(IASTNode node) {
if (foundNode != null)
return PROCESS_ABORT;
if (node instanceof ASTNode &&
((ASTNode)node).getOffset() == offset &&
((ASTNode)node).getLength() == length) {
foundNode = node;
return PROCESS_ABORT;
}
// skip the rest of this node if the selection is outside of its bounds
if (node instanceof ASTNode &&
offset > ((ASTNode)node).getOffset() + ((ASTNode)node).getLength())
return PROCESS_SKIP;
return PROCESS_CONTINUE;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
*/
public int processDeclaration(IASTDeclaration declaration) {
// use declarations to determine if the search has gone past the offset (i.e. don't know the order the visitor visits the nodes)
if (declaration instanceof ASTNode && ((ASTNode)declaration).getOffset() > offset)
return PROCESS_ABORT;
return processNode(declaration);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
*/
public int processDeclarator(IASTDeclarator declarator) {
int ret = processNode(declarator);
IASTPointerOperator[] ops = declarator.getPointerOperators();
for(int i=0; i<ops.length; i++)
processNode(ops[i]);
if (declarator instanceof IASTArrayDeclarator) {
IASTArrayModifier[] mods = ((IASTArrayDeclarator)declarator).getArrayModifiers();
for(int i=0; i<mods.length; i++)
processNode(mods[i]);
}
return ret;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator)
*/
public int processDesignator(ICASTDesignator designator) {
return processNode(designator);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
*/
public int processDeclSpecifier(IASTDeclSpecifier declSpec) {
return processNode(declSpec);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
*/
public int processEnumerator(IASTEnumerator enumerator) {
return processNode((IASTNode)enumerator);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
*/
public int processExpression(IASTExpression expression) {
return processNode(expression);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
*/
public int processInitializer(IASTInitializer initializer) {
return processNode(initializer);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
*/
public int processName(IASTName name) {
if ( name.toString() != null )
return processNode(name);
return PROCESS_CONTINUE;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
*/
public int processParameterDeclaration(
IASTParameterDeclaration parameterDeclaration) {
return processNode(parameterDeclaration);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
*/
public int processStatement(IASTStatement statement) {
return processNode(statement);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
*/
public int processTypeId(IASTTypeId typeId) {
return processNode(typeId);
}
public IASTNode getNode() { public int processNode(IASTNode node) {
return foundNode; if (foundNode != null)
} return PROCESS_ABORT;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation)
*/
public IASTNode selectNodeForLocation(String path, int realOffset, int realLength) {
IASTNode node = null;
try {
node = resolver.getPreprocessorNode(path, realOffset, realLength);
} catch (InvalidPreprocessorNodeException ipne) {
// extract global offset from the exception, use it to get the node from the AST if it's valid
int globalOffset = ipne.getGlobalOffset();
if (globalOffset >= 0) {
CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(globalOffset, realLength);
getVisitor().visitTranslationUnit(nodeFinder);
node = nodeFinder.getNode();
}
}
return node;
}
if (node instanceof ASTNode
&& ((ASTNode) node).getOffset() == offset
&& ((ASTNode) node).getLength() == length) {
foundNode = node;
return PROCESS_ABORT;
}
/* (non-Javadoc) // skip the rest of this node if the selection is outside of its
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions() // bounds
*/ if (node instanceof ASTNode
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() { && offset > ((ASTNode) node).getOffset()
if( resolver == null ) return EMPTY_PREPROCESSOR_MACRODEF_ARRAY; + ((ASTNode) node).getLength())
IASTPreprocessorMacroDefinition [] result = resolver.getMacroDefinitions(); return PROCESS_SKIP;
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT );
return result;
}
return PROCESS_CONTINUE;
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives() * (non-Javadoc)
*/ *
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() { * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
if( resolver == null ) return EMPTY_PREPROCESSOR_INCLUSION_ARRAY; */
IASTPreprocessorIncludeStatement [] result = resolver.getIncludeDirectives(); public int processDeclaration(IASTDeclaration declaration) {
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT ); // use declarations to determine if the search has gone past the
return result; // offset (i.e. don't know the order the visitor visits the nodes)
} if (declaration instanceof ASTNode
&& ((ASTNode) declaration).getOffset() > offset)
return PROCESS_ABORT;
return processNode(declaration);
}
/** /*
* @param result * (non-Javadoc)
* @param preprocessor_statement *
*/ * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
protected void setParentRelationship(IASTNode[] result, ASTNodeProperty property ) { */
for( int i = 0; i < result.length; ++i ) public int processDeclarator(IASTDeclarator declarator) {
{ int ret = processNode(declarator);
result[i].setParent( this );
result[i].setPropertyInParent( property );
}
}
IASTPointerOperator[] ops = declarator.getPointerOperators();
for (int i = 0; i < ops.length; i++)
processNode(ops[i]);
/* (non-Javadoc) if (declarator instanceof IASTArrayDeclarator) {
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements() IASTArrayModifier[] mods = ((IASTArrayDeclarator) declarator)
*/ .getArrayModifiers();
public IASTPreprocessorStatement[] getAllPreprocessorStatements() { for (int i = 0; i < mods.length; i++)
if( resolver == null ) return EMPTY_PREPROCESSOR_STATEMENT_ARRAY; processNode(mods[i]);
IASTPreprocessorStatement [] result = resolver.getAllPreprocessorStatements(); }
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT );
return result;
}
return ret;
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation#setLocationResolver(org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver) * (non-Javadoc)
*/ *
public void setLocationResolver(ILocationResolver resolver) { * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator)
this.resolver = resolver; */
} public int processDesignator(ICASTDesignator designator) {
return processNode(designator);
}
/*
/* (non-Javadoc) * (non-Javadoc)
* @see java.lang.Object#finalize() *
*/ * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
protected void finalize() throws Throwable { */
if( resolver != null ) resolver.cleanup(); public int processDeclSpecifier(IASTDeclSpecifier declSpec) {
super.finalize(); return processNode(declSpec);
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
*/
public int processEnumerator(IASTEnumerator enumerator) {
return processNode((IASTNode) enumerator);
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems() * (non-Javadoc)
*/ *
public IASTProblem[] getPreprocesorProblems() { * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
if( resolver == null ) return EMPTY_PROBLEM_ARRAY; */
IASTProblem [] result = resolver.getScannerProblems(); public int processExpression(IASTExpression expression) {
for( int i = 0; i < result.length; ++i ) return processNode(expression);
{ }
IASTProblem p = result[i];
p.setParent( this );
p.setPropertyInParent( IASTTranslationUnit.SCANNER_PROBLEM );
}
return result;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
*/
public int processInitializer(IASTInitializer initializer) {
return processNode(initializer);
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getUnpreprocessedSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[]) * (non-Javadoc)
*/ *
public String getUnpreprocessedSignature(IASTNodeLocation[] locations) { * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
if( resolver == null ) return EMPTY_STRING; */
return new String( resolver.getUnpreprocessedSignature(locations) ); public int processName(IASTName name) {
} if (name.toString() != null)
return processNode(name);
return PROCESS_CONTINUE;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
*/
public int processParameterDeclaration(
IASTParameterDeclaration parameterDeclaration) {
return processNode(parameterDeclaration);
}
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
*/
public int processStatement(IASTStatement statement) {
return processNode(statement);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
*/
public int processTypeId(IASTTypeId typeId) {
return processNode(typeId);
}
public IASTNode getNode() {
return foundNode;
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation)
*/
public IASTNode selectNodeForLocation(String path, int realOffset,
int realLength) {
IASTNode node = null;
try {
node = resolver.getPreprocessorNode(path, realOffset, realLength);
} catch (InvalidPreprocessorNodeException ipne) {
// extract global offset from the exception, use it to get the node
// from the AST if it's valid
int globalOffset = ipne.getGlobalOffset();
if (globalOffset >= 0) {
CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(
globalOffset, realLength);
getVisitor().visitTranslationUnit(nodeFinder);
node = nodeFinder.getNode();
}
}
return node;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
*/
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
if (resolver == null)
return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
IASTPreprocessorMacroDefinition[] result = resolver
.getMacroDefinitions();
setParentRelationship(result,
IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives()
*/
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
if (resolver == null)
return EMPTY_PREPROCESSOR_INCLUSION_ARRAY;
IASTPreprocessorIncludeStatement[] result = resolver
.getIncludeDirectives();
setParentRelationship(result,
IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result;
}
/**
* @param result
* @param preprocessor_statement
*/
protected void setParentRelationship(IASTNode[] result,
ASTNodeProperty property) {
for (int i = 0; i < result.length; ++i) {
result[i].setParent(this);
result[i].setPropertyInParent(property);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements()
*/
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
if (resolver == null)
return EMPTY_PREPROCESSOR_STATEMENT_ARRAY;
IASTPreprocessorStatement[] result = resolver
.getAllPreprocessorStatements();
setParentRelationship(result,
IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation#setLocationResolver(org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver)
*/
public void setLocationResolver(ILocationResolver resolver) {
this.resolver = resolver;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#finalize()
*/
protected void finalize() throws Throwable {
if (resolver != null)
resolver.cleanup();
super.finalize();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems()
*/
public IASTProblem[] getPreprocesorProblems() {
if (resolver == null)
return EMPTY_PROBLEM_ARRAY;
IASTProblem[] result = resolver.getScannerProblems();
for (int i = 0; i < result.length; ++i) {
IASTProblem p = result[i];
p.setParent(this);
p.setPropertyInParent(IASTTranslationUnit.SCANNER_PROBLEM);
}
return result;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getUnpreprocessedSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[])
*/
public String getUnpreprocessedSignature(IASTNodeLocation[] locations) {
if (resolver == null)
return EMPTY_STRING;
return new String(resolver.getUnpreprocessedSignature(locations));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getVisitor() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getVisitor()
*/ */
public IASTVisitor getVisitor() { public IASTVisitor getVisitor() {
if( visitor == null ) if (visitor == null)
visitor = new CVisitor( this ); visitor = new CVisitor(this);
return visitor; return visitor;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getFilePath()
*/
public String getFilePath() {
if (resolver == null)
return EMPTY_STRING;
return new String(resolver.getTranslationUnitPath());
}
} }

View file

@ -67,7 +67,6 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
private ILocationResolver resolver; private ILocationResolver resolver;
private static final IASTNode[] EMPTY_NODE_ARRAY = new IASTNode[0];
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0]; private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
@ -451,4 +450,15 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
visitor = new CPPVisitor( this ); visitor = new CPPVisitor( this );
return visitor; return visitor;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getFilePath()
*/
public String getFilePath() {
if (resolver == null)
return EMPTY_STRING;
return new String(resolver.getTranslationUnitPath());
}
} }