mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Abstract base class for the implementations of IASTTranslationUnit.
This commit is contained in:
parent
ed9b414f4d
commit
e7eaa2fb93
4 changed files with 364 additions and 576 deletions
|
@ -0,0 +1,311 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.dom.parser;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.dom.IName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||||
|
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.index.IIndex;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||||
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class for all translation units.
|
||||||
|
*/
|
||||||
|
public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslationUnit, ISkippedIndexedFilesListener {
|
||||||
|
|
||||||
|
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[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$
|
||||||
|
|
||||||
|
protected IASTDeclaration[] fDeclarations = null;
|
||||||
|
protected int fLastDeclaration=-1;
|
||||||
|
|
||||||
|
protected ILocationResolver fLocationResolver;
|
||||||
|
private IIndex fIndex;
|
||||||
|
private boolean fIsHeader= true;
|
||||||
|
private IIndexFileSet fIndexFileSet;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final IASTTranslationUnit getTranslationUnit() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void addDeclaration(IASTDeclaration d) {
|
||||||
|
if (d != null) {
|
||||||
|
d.setParent(this);
|
||||||
|
d.setPropertyInParent(OWNED_DECLARATION);
|
||||||
|
fDeclarations = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, fDeclarations, ++fLastDeclaration, d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations()
|
||||||
|
*/
|
||||||
|
public final IASTDeclaration[] getDeclarations() {
|
||||||
|
if (fDeclarations == null) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
|
||||||
|
fDeclarations= (IASTDeclaration[]) ArrayUtil.removeNullsAfter( IASTDeclaration.class, fDeclarations, fLastDeclaration);
|
||||||
|
return fDeclarations;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding)
|
||||||
|
*/
|
||||||
|
public final IName[] getDeclarations(IBinding binding) {
|
||||||
|
IName[] names= getDeclarationsInAST(binding);
|
||||||
|
if (names.length == 0 && fIndex != null) {
|
||||||
|
try {
|
||||||
|
names = fIndex.findDeclarations(binding);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final IASTName[] getMacroDefinitionsInAST(IMacroBinding binding) {
|
||||||
|
if (fLocationResolver == null)
|
||||||
|
return IASTName.EMPTY_NAME_ARRAY;
|
||||||
|
return fLocationResolver.getDeclarations(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final IASTName[] getMacroReferencesInAST(IMacroBinding binding) {
|
||||||
|
if (fLocationResolver == null)
|
||||||
|
return IASTName.EMPTY_NAME_ARRAY;
|
||||||
|
return fLocationResolver.getReferences(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDefinitions(org.eclipse.cdt.core.dom.ast.IBinding)
|
||||||
|
*/
|
||||||
|
public final IName[] getDefinitions(IBinding binding) {
|
||||||
|
IName[] names= getDefinitionsInAST(binding);
|
||||||
|
if (names.length == 0 && fIndex != null) {
|
||||||
|
try {
|
||||||
|
names= fIndex.findDefinitions(binding);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
|
||||||
|
*/
|
||||||
|
public final IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
|
||||||
|
if (fLocationResolver == null)
|
||||||
|
return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
|
||||||
|
return fLocationResolver.getMacroDefinitions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
|
||||||
|
*/
|
||||||
|
public final IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() {
|
||||||
|
if (fLocationResolver == null)
|
||||||
|
return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
|
||||||
|
return fLocationResolver.getBuiltinMacroDefinitions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives()
|
||||||
|
*/
|
||||||
|
public final IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
||||||
|
if (fLocationResolver == null)
|
||||||
|
return EMPTY_PREPROCESSOR_INCLUSION_ARRAY;
|
||||||
|
return fLocationResolver.getIncludeDirectives();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements()
|
||||||
|
*/
|
||||||
|
public final IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
||||||
|
if (fLocationResolver == null)
|
||||||
|
return EMPTY_PREPROCESSOR_STATEMENT_ARRAY;
|
||||||
|
return fLocationResolver.getAllPreprocessorStatements();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation#setLocationResolver(org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver)
|
||||||
|
*/
|
||||||
|
public final void setLocationResolver(ILocationResolver resolver) {
|
||||||
|
fLocationResolver= resolver;
|
||||||
|
resolver.setRootNode(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems()
|
||||||
|
*/
|
||||||
|
public final IASTProblem[] getPreprocessorProblems() {
|
||||||
|
if (fLocationResolver == null)
|
||||||
|
return EMPTY_PROBLEM_ARRAY;
|
||||||
|
IASTProblem[] result = fLocationResolver.getScannerProblems();
|
||||||
|
for (int i = 0; i < result.length; ++i) {
|
||||||
|
IASTProblem p = result[i];
|
||||||
|
p.setParent(this);
|
||||||
|
p.setPropertyInParent(IASTTranslationUnit.SCANNER_PROBLEM);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final int getPreprocessorProblemsCount() {
|
||||||
|
return fLocationResolver == null ? 0 : fLocationResolver.getScannerProblemsCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getFilePath()
|
||||||
|
*/
|
||||||
|
public final String getFilePath() {
|
||||||
|
if (fLocationResolver == null)
|
||||||
|
return EMPTY_STRING;
|
||||||
|
return new String(fLocationResolver.getTranslationUnitPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean accept( ASTVisitor action ){
|
||||||
|
if( action.shouldVisitTranslationUnit){
|
||||||
|
switch( action.visit( this ) ){
|
||||||
|
case ASTVisitor.PROCESS_ABORT : return false;
|
||||||
|
case ASTVisitor.PROCESS_SKIP : return true;
|
||||||
|
default : break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IASTDeclaration [] ds = getDeclarations();
|
||||||
|
for( int i = 0; i < ds.length; i++ ){
|
||||||
|
if( !ds[i].accept( action ) ) return false;
|
||||||
|
}
|
||||||
|
if( action.shouldVisitTranslationUnit){
|
||||||
|
switch( action.leave( this ) ){
|
||||||
|
case ASTVisitor.PROCESS_ABORT : return false;
|
||||||
|
case ASTVisitor.PROCESS_SKIP : return true;
|
||||||
|
default : break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final IASTFileLocation flattenLocationsToFile(IASTNodeLocation[] nodeLocations) {
|
||||||
|
if (fLocationResolver == null)
|
||||||
|
return null;
|
||||||
|
return fLocationResolver.flattenLocations( nodeLocations );
|
||||||
|
}
|
||||||
|
|
||||||
|
public final IDependencyTree getDependencyTree() {
|
||||||
|
if (fLocationResolver == null)
|
||||||
|
return null;
|
||||||
|
return fLocationResolver.getDependencyTree();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getContainingFilename(int offset) {
|
||||||
|
if (fLocationResolver == null)
|
||||||
|
return EMPTY_STRING;
|
||||||
|
return fLocationResolver.getContainingFilePath( offset );
|
||||||
|
}
|
||||||
|
|
||||||
|
public final IIndex getIndex() {
|
||||||
|
return fIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setIndex(IIndex index) {
|
||||||
|
this.fIndex = index;
|
||||||
|
if (index != null) {
|
||||||
|
fIndexFileSet= index.createFileSet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final IASTComment[] getComments() {
|
||||||
|
if (fLocationResolver != null) {
|
||||||
|
return fLocationResolver.getComments();
|
||||||
|
}
|
||||||
|
return new IASTComment[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public final Object getAdapter(Class adapter) {
|
||||||
|
if (adapter.isAssignableFrom(fLocationResolver.getClass())) {
|
||||||
|
return fLocationResolver;
|
||||||
|
}
|
||||||
|
if (adapter.isAssignableFrom(IIndexFileSet.class)) {
|
||||||
|
return fIndexFileSet;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean isHeaderUnit() {
|
||||||
|
return fIsHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setIsHeaderUnit(boolean headerUnit) {
|
||||||
|
fIsHeader= headerUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
|
||||||
|
*/
|
||||||
|
public void skippedFile(int offset, IncludeFileContent fileContent) {
|
||||||
|
if (fIndexFileSet != null) {
|
||||||
|
List<IIndexFile> files= fileContent.getFilesIncluded();
|
||||||
|
for (IIndexFile indexFile : files) {
|
||||||
|
fIndexFileSet.add(indexFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final IIndexFileSet getIndexFileSet() {
|
||||||
|
return fIndexFileSet;
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,32 +12,20 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.dom.ILinkage;
|
import org.eclipse.cdt.core.dom.ILinkage;
|
||||||
import org.eclipse.cdt.core.dom.IName;
|
import org.eclipse.cdt.core.dom.IName;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
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;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||||
|
@ -45,63 +33,17 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
|
||||||
import org.eclipse.cdt.core.index.IIndexFile;
|
|
||||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* C-specific implementation of a translation unit.
|
||||||
*/
|
*/
|
||||||
public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit, ISkippedIndexedFilesListener {
|
public class CASTTranslationUnit extends ASTTranslationUnit {
|
||||||
|
|
||||||
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[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$
|
|
||||||
private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0];
|
|
||||||
|
|
||||||
private IASTDeclaration[] decls = null;
|
|
||||||
private int declsPos=-1;
|
|
||||||
|
|
||||||
private CScope compilationUnit = null;
|
private CScope compilationUnit = null;
|
||||||
private ILocationResolver resolver;
|
|
||||||
private IIndex index;
|
|
||||||
private boolean fIsHeader= true;
|
|
||||||
private IIndexFileSet fIndexFileSet;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IASTTranslationUnit getTranslationUnit() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addDeclaration(IASTDeclaration d) {
|
|
||||||
if (d != null) {
|
|
||||||
d.setParent(this);
|
|
||||||
d.setPropertyInParent(OWNED_DECLARATION);
|
|
||||||
decls = (IASTDeclaration[]) ArrayUtil.append( IASTDeclaration.class, decls, ++declsPos, d );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations()
|
|
||||||
*/
|
|
||||||
public IASTDeclaration[] getDeclarations() {
|
|
||||||
if (decls == null) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
|
|
||||||
decls = (IASTDeclaration[]) ArrayUtil.removeNullsAfter( IASTDeclaration.class, decls, declsPos );
|
|
||||||
return decls;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
@ -114,59 +56,17 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
||||||
return compilationUnit;
|
return compilationUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding)
|
|
||||||
*/
|
|
||||||
public IName[] getDeclarations(IBinding binding) {
|
|
||||||
IName[] names= getDeclarationsInAST(binding);
|
|
||||||
if (names.length == 0 && index != null) {
|
|
||||||
try {
|
|
||||||
names = index.findDeclarations(binding);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTName[] getDeclarationsInAST(IBinding binding) {
|
public IASTName[] getDeclarationsInAST(IBinding binding) {
|
||||||
if( binding instanceof IMacroBinding )
|
if (binding instanceof IMacroBinding) {
|
||||||
{
|
return getMacroDefinitionsInAST((IMacroBinding) binding);
|
||||||
if( resolver == null )
|
|
||||||
return EMPTY_NAME_ARRAY;
|
|
||||||
return resolver.getDeclarations( (IMacroBinding)binding );
|
|
||||||
}
|
}
|
||||||
return CVisitor.getDeclarations(this, binding);
|
return CVisitor.getDeclarations(this, binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDefinitions(org.eclipse.cdt.core.dom.ast.IBinding)
|
|
||||||
*/
|
|
||||||
public IName[] getDefinitions(IBinding binding) {
|
|
||||||
IName[] names= getDefinitionsInAST(binding);
|
|
||||||
if (names.length == 0 && index != null) {
|
|
||||||
try {
|
|
||||||
names= index.findDefinitions(binding);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTName[] getDefinitionsInAST(IBinding binding) {
|
public IASTName[] getDefinitionsInAST(IBinding binding) {
|
||||||
if (binding instanceof IMacroBinding) {
|
if (binding instanceof IMacroBinding) {
|
||||||
if (resolver != null) {
|
return getMacroDefinitionsInAST((IMacroBinding) binding);
|
||||||
return resolver.getDeclarations((IMacroBinding)binding);
|
|
||||||
}
|
|
||||||
return IASTName.EMPTY_NAME_ARRAY;
|
|
||||||
}
|
}
|
||||||
IName[] names = CVisitor.getDeclarations(this, binding);
|
IName[] names = CVisitor.getDeclarations(this, binding);
|
||||||
for (int i = 0; i < names.length; i++) {
|
for (int i = 0; i < names.length; i++) {
|
||||||
|
@ -184,11 +84,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
||||||
*/
|
*/
|
||||||
public IASTName[] getReferences(IBinding binding) {
|
public IASTName[] getReferences(IBinding binding) {
|
||||||
if (binding instanceof IMacroBinding)
|
if (binding instanceof IMacroBinding)
|
||||||
{
|
return getMacroReferencesInAST((IMacroBinding) binding);
|
||||||
if( resolver == null )
|
|
||||||
return EMPTY_NAME_ARRAY;
|
|
||||||
return resolver.getReferences( (IMacroBinding)binding );
|
|
||||||
}
|
|
||||||
return CVisitor.getReferences(this, binding);
|
return CVisitor.getReferences(this, binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,12 +282,12 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
||||||
*/
|
*/
|
||||||
public IASTNode selectNodeForLocation(String path, int realOffset, int realLength) {
|
public IASTNode selectNodeForLocation(String path, int realOffset, int realLength) {
|
||||||
IASTNode result= null;
|
IASTNode result= null;
|
||||||
if (resolver != null) {
|
if (fLocationResolver != null) {
|
||||||
int start= resolver.getSequenceNumberForFileOffset(path, realOffset);
|
int start= fLocationResolver.getSequenceNumberForFileOffset(path, realOffset);
|
||||||
if (start >= 0) {
|
if (start >= 0) {
|
||||||
int length= realLength < 1 ? 0 :
|
int length= realLength < 1 ? 0 :
|
||||||
resolver.getSequenceNumberForFileOffset(path, realOffset+realLength-1) + 1 - start;
|
fLocationResolver.getSequenceNumberForFileOffset(path, realOffset+realLength-1) + 1 - start;
|
||||||
result= resolver.findSurroundingPreprocessorNode(start, length);
|
result= fLocationResolver.findSurroundingPreprocessorNode(start, length);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(start, length);
|
CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(start, length);
|
||||||
accept(nodeFinder);
|
accept(nodeFinder);
|
||||||
|
@ -402,197 +298,11 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (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();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
|
|
||||||
*/
|
|
||||||
public IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() {
|
|
||||||
if (resolver == null)
|
|
||||||
return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
|
|
||||||
IASTPreprocessorMacroDefinition[] result = resolver
|
|
||||||
.getBuiltinMacroDefinitions();
|
|
||||||
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();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (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();
|
|
||||||
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;
|
|
||||||
resolver.setRootNode( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems()
|
|
||||||
*/
|
|
||||||
public IASTProblem[] getPreprocessorProblems() {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getPreprocessorProblemsCount() {
|
|
||||||
return resolver == null ? 0 : resolver.getScannerProblemsCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (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());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean accept( ASTVisitor action ){
|
|
||||||
if( action.shouldVisitTranslationUnit){
|
|
||||||
switch( action.visit( this ) ){
|
|
||||||
case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
default : break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IASTDeclaration [] ds = getDeclarations();
|
|
||||||
for( int i = 0; i < ds.length; i++ ){
|
|
||||||
if( !ds[i].accept( action ) ) return false;
|
|
||||||
}
|
|
||||||
if( action.shouldVisitTranslationUnit){
|
|
||||||
switch( action.leave( this ) ){
|
|
||||||
case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
default : break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTFileLocation flattenLocationsToFile(IASTNodeLocation[] nodeLocations) {
|
|
||||||
if( resolver == null )
|
|
||||||
return null;
|
|
||||||
return resolver.flattenLocations( nodeLocations );
|
|
||||||
}
|
|
||||||
|
|
||||||
public IDependencyTree getDependencyTree() {
|
|
||||||
if( resolver == null )
|
|
||||||
return null;
|
|
||||||
return resolver.getDependencyTree();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContainingFilename(int offset) {
|
|
||||||
if( resolver == null )
|
|
||||||
return EMPTY_STRING;
|
|
||||||
return resolver.getContainingFilePath( offset );
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParserLanguage getParserLanguage() {
|
public ParserLanguage getParserLanguage() {
|
||||||
return ParserLanguage.C;
|
return ParserLanguage.C;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IIndex getIndex() {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIndex(IIndex index) {
|
|
||||||
this.index = index;
|
|
||||||
if (index != null) {
|
|
||||||
fIndexFileSet= index.createFileSet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTComment[] getComments() {
|
|
||||||
if (resolver != null) {
|
|
||||||
return resolver.getComments();
|
|
||||||
}
|
|
||||||
return new IASTComment[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Object getAdapter(Class adapter) {
|
|
||||||
if (adapter.isAssignableFrom(resolver.getClass())) {
|
|
||||||
return resolver;
|
|
||||||
}
|
|
||||||
if (adapter.isAssignableFrom(IIndexFileSet.class)) {
|
|
||||||
return fIndexFileSet;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ILinkage getLinkage() {
|
public ILinkage getLinkage() {
|
||||||
return Linkage.C_LINKAGE;
|
return Linkage.C_LINKAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHeaderUnit() {
|
|
||||||
return fIsHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsHeaderUnit(boolean headerUnit) {
|
|
||||||
fIsHeader= headerUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
|
|
||||||
*/
|
|
||||||
public void skippedFile(int offset, IncludeFileContent fileContent) {
|
|
||||||
if (fIndexFileSet != null) {
|
|
||||||
List<IIndexFile> files= fileContent.getFilesIncluded();
|
|
||||||
for (IIndexFile indexFile : files) {
|
|
||||||
fIndexFileSet.add(indexFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,33 +11,20 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.dom.ILinkage;
|
import org.eclipse.cdt.core.dom.ILinkage;
|
||||||
import org.eclipse.cdt.core.dom.IName;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
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;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
@ -57,73 +44,34 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
|
||||||
import org.eclipse.cdt.core.index.IIndexFile;
|
|
||||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter;
|
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
|
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* C++-specific implementation of a translation-unit.
|
||||||
*/
|
*/
|
||||||
public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslationUnit, IASTAmbiguityParent, ISkippedIndexedFilesListener {
|
public class CPPASTTranslationUnit extends ASTTranslationUnit implements ICPPASTTranslationUnit, IASTAmbiguityParent {
|
||||||
|
private CPPNamespaceScope fScope = null;
|
||||||
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
|
private ICPPNamespace fBinding = null;
|
||||||
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 String EMPTY_STRING = ""; //$NON-NLS-1$
|
|
||||||
private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0];
|
|
||||||
private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0];
|
|
||||||
|
|
||||||
private IASTDeclaration[] decls = new IASTDeclaration[32];
|
|
||||||
private ICPPNamespace binding = null;
|
|
||||||
private CPPNamespaceScope scope = null;
|
|
||||||
private ILocationResolver resolver;
|
|
||||||
private IIndex index;
|
|
||||||
private IIndexFileSet fIndexFileSet;
|
|
||||||
private boolean fIsHeader= true;
|
|
||||||
private CPPScopeMapper fScopeMapper= new CPPScopeMapper(this);
|
private CPPScopeMapper fScopeMapper= new CPPScopeMapper(this);
|
||||||
|
|
||||||
public CPPASTTranslationUnit() {
|
public CPPASTTranslationUnit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IASTTranslationUnit getTranslationUnit() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addDeclaration(IASTDeclaration d) {
|
|
||||||
decls = (IASTDeclaration [])ArrayUtil.append( IASTDeclaration.class, decls, d );
|
|
||||||
if (d != null) {
|
|
||||||
d.setParent(this);
|
|
||||||
d.setPropertyInParent(OWNED_DECLARATION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public IASTDeclaration[] getDeclarations() {
|
|
||||||
if (decls == null)
|
|
||||||
return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
|
|
||||||
return (IASTDeclaration[]) ArrayUtil.trim( IASTDeclaration.class, decls );
|
|
||||||
}
|
|
||||||
|
|
||||||
public CPPNamespaceScope getScope() {
|
public CPPNamespaceScope getScope() {
|
||||||
if (scope == null) {
|
if (fScope == null) {
|
||||||
scope = new CPPNamespaceScope(this);
|
fScope = new CPPNamespaceScope(this);
|
||||||
addBuiltinOperators(scope);
|
addBuiltinOperators(fScope);
|
||||||
}
|
}
|
||||||
|
return fScope;
|
||||||
return scope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBuiltinOperators(IScope theScope) {
|
private void addBuiltinOperators(IScope theScope) {
|
||||||
|
@ -173,37 +121,17 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
|
||||||
} catch (DOMException de) {}
|
} catch (DOMException de) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTName[] getDeclarationsInAST(IBinding b) {
|
public IASTName[] getDeclarationsInAST(IBinding binding) {
|
||||||
if( b instanceof IMacroBinding )
|
if (binding instanceof IMacroBinding) {
|
||||||
{
|
return getMacroDefinitionsInAST((IMacroBinding) binding);
|
||||||
if( resolver == null )
|
|
||||||
return EMPTY_NAME_ARRAY;
|
|
||||||
return resolver.getDeclarations( (IMacroBinding)b );
|
|
||||||
}
|
}
|
||||||
return CPPVisitor.getDeclarations( this, b );
|
return CPPVisitor.getDeclarations(this, binding);
|
||||||
}
|
|
||||||
|
|
||||||
public IName[] getDeclarations(IBinding b) {
|
|
||||||
IName[] names = getDeclarationsInAST(b);
|
|
||||||
if (names.length == 0 && index != null) {
|
|
||||||
try {
|
|
||||||
names = index.findDeclarations(b);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return names;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTName[] getDefinitionsInAST(IBinding binding) {
|
public IASTName[] getDefinitionsInAST(IBinding binding) {
|
||||||
if (binding instanceof IMacroBinding) {
|
if (binding instanceof IMacroBinding) {
|
||||||
if( resolver == null )
|
return getMacroDefinitionsInAST((IMacroBinding) binding);
|
||||||
return EMPTY_NAME_ARRAY;
|
|
||||||
return resolver.getDeclarations((IMacroBinding)binding);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTName[] names = CPPVisitor.getDeclarations(this, binding);
|
IASTName[] names = CPPVisitor.getDeclarations(this, binding);
|
||||||
for (int i = 0; i < names.length; i++) {
|
for (int i = 0; i < names.length; i++) {
|
||||||
if (!names[i].isDefinition())
|
if (!names[i].isDefinition())
|
||||||
|
@ -213,29 +141,11 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
|
||||||
return (IASTName[])ArrayUtil.removeNulls(IASTName.class, names);
|
return (IASTName[])ArrayUtil.removeNulls(IASTName.class, names);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IName[] getDefinitions(IBinding binding) {
|
public IASTName[] getReferences(IBinding binding) {
|
||||||
IName[] names = getDefinitionsInAST(binding);
|
if (binding instanceof IMacroBinding) {
|
||||||
if (names.length == 0 && index != null) {
|
return getMacroReferencesInAST((IMacroBinding) binding);
|
||||||
try {
|
|
||||||
names = index.findDefinitions(binding);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CCorePlugin.log(e);
|
|
||||||
return names;
|
|
||||||
}
|
}
|
||||||
}
|
return CPPVisitor.getReferences(this, binding);
|
||||||
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public IASTName[] getReferences(IBinding b) {
|
|
||||||
if( b instanceof IMacroBinding )
|
|
||||||
{
|
|
||||||
if( resolver == null )
|
|
||||||
return EMPTY_NAME_ARRAY;
|
|
||||||
return resolver.getReferences( (IMacroBinding)b );
|
|
||||||
}
|
|
||||||
return CPPVisitor.getReferences(this, b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CPPFindNodeForOffsetAction extends CPPASTVisitor {
|
private class CPPFindNodeForOffsetAction extends CPPASTVisitor {
|
||||||
|
@ -383,12 +293,12 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
|
||||||
|
|
||||||
public IASTNode selectNodeForLocation(String path, int realOffset, int realLength) {
|
public IASTNode selectNodeForLocation(String path, int realOffset, int realLength) {
|
||||||
IASTNode result= null;
|
IASTNode result= null;
|
||||||
if (resolver != null) {
|
if (fLocationResolver != null) {
|
||||||
int start= resolver.getSequenceNumberForFileOffset(path, realOffset);
|
int start= fLocationResolver.getSequenceNumberForFileOffset(path, realOffset);
|
||||||
if (start >= 0) {
|
if (start >= 0) {
|
||||||
int length= realLength < 1 ? 0 :
|
int length= realLength < 1 ? 0 :
|
||||||
resolver.getSequenceNumberForFileOffset(path, realOffset+realLength-1) + 1 - start;
|
fLocationResolver.getSequenceNumberForFileOffset(path, realOffset+realLength-1) + 1 - start;
|
||||||
result= resolver.findSurroundingPreprocessorNode(start, length);
|
result= fLocationResolver.findSurroundingPreprocessorNode(start, length);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
CPPFindNodeForOffsetAction nodeFinder = new CPPFindNodeForOffsetAction(start, length);
|
CPPFindNodeForOffsetAction nodeFinder = new CPPFindNodeForOffsetAction(start, length);
|
||||||
accept(nodeFinder);
|
accept(nodeFinder);
|
||||||
|
@ -399,117 +309,20 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
|
|
||||||
if( resolver == null ) return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
|
|
||||||
IASTPreprocessorMacroDefinition [] result = resolver.getMacroDefinitions();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() {
|
|
||||||
if( resolver == null ) return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
|
|
||||||
IASTPreprocessorMacroDefinition [] result = resolver.getBuiltinMacroDefinitions();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
|
||||||
if( resolver == null ) return EMPTY_PREPROCESSOR_INCLUSION_ARRAY;
|
|
||||||
IASTPreprocessorIncludeStatement [] result = resolver.getIncludeDirectives();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
|
|
||||||
if (resolver == null)
|
|
||||||
return EMPTY_PREPROCESSOR_STATEMENT_ARRAY;
|
|
||||||
IASTPreprocessorStatement [] result = resolver.getAllPreprocessorStatements();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocationResolver(ILocationResolver resolver) {
|
|
||||||
this.resolver = resolver;
|
|
||||||
resolver.setRootNode( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
public IBinding resolveBinding() {
|
public IBinding resolveBinding() {
|
||||||
if (binding == null)
|
if (fBinding == null)
|
||||||
binding = new CPPNamespace(this);
|
fBinding = new CPPNamespace(this);
|
||||||
return binding;
|
return fBinding;
|
||||||
}
|
|
||||||
|
|
||||||
public IASTProblem[] getPreprocessorProblems() {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPreprocessorProblemsCount() {
|
|
||||||
return resolver == null ? 0 : resolver.getScannerProblemsCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFilePath() {
|
|
||||||
if (resolver == null)
|
|
||||||
return EMPTY_STRING;
|
|
||||||
return new String(resolver.getTranslationUnitPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean accept( ASTVisitor action ){
|
|
||||||
if( action.shouldVisitTranslationUnit){
|
|
||||||
switch( action.visit( this ) ){
|
|
||||||
case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
default : break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IASTDeclaration [] ds = getDeclarations();
|
|
||||||
for( int i = 0; i < ds.length; i++ ){
|
|
||||||
if( !ds[i].accept( action ) ) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( action.shouldVisitTranslationUnit){
|
|
||||||
switch( action.leave( this ) ){
|
|
||||||
case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
default : break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTFileLocation flattenLocationsToFile(IASTNodeLocation[] nodeLocations) {
|
|
||||||
if( resolver == null )
|
|
||||||
return null;
|
|
||||||
return resolver.flattenLocations( nodeLocations );
|
|
||||||
}
|
|
||||||
|
|
||||||
public IDependencyTree getDependencyTree() {
|
|
||||||
if( resolver == null )
|
|
||||||
return null;
|
|
||||||
return resolver.getDependencyTree();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContainingFilename(int offset) {
|
|
||||||
if( resolver == null )
|
|
||||||
return EMPTY_STRING;
|
|
||||||
return resolver.getContainingFilePath( offset );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replace(IASTNode child, IASTNode other) {
|
public void replace(IASTNode child, IASTNode other) {
|
||||||
if( decls == null ) return;
|
if (fDeclarations == null) return;
|
||||||
for( int i = 0; i < decls.length; ++i )
|
for(int i=0; i < fDeclarations.length; ++i) {
|
||||||
{
|
if (fDeclarations[i] == null) break;
|
||||||
if( decls[i] == null ) break;
|
if (fDeclarations[i] == child) {
|
||||||
if( decls[i] == child )
|
|
||||||
{
|
|
||||||
other.setParent(child.getParent());
|
other.setParent(child.getParent());
|
||||||
other.setPropertyInParent(child.getPropertyInParent());
|
other.setPropertyInParent(child.getPropertyInParent());
|
||||||
decls[i] = (IASTDeclaration) other;
|
fDeclarations[i] = (IASTDeclaration) other;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,53 +331,18 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
|
||||||
return ParserLanguage.CPP;
|
return ParserLanguage.CPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndex getIndex() {
|
/* (non-Javadoc)
|
||||||
return index;
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLinkage()
|
||||||
}
|
*/
|
||||||
|
public ILinkage getLinkage() {
|
||||||
public void setIndex(IIndex pdom) {
|
return Linkage.CPP_LINKAGE;
|
||||||
this.index = pdom;
|
|
||||||
if (index != null) {
|
|
||||||
fIndexFileSet= index.createFileSet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTComment[] getComments() {
|
|
||||||
if (resolver != null) {
|
|
||||||
return resolver.getComments();
|
|
||||||
}
|
|
||||||
return new IASTComment[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Object getAdapter(Class adapter) {
|
|
||||||
if (adapter.isAssignableFrom(resolver.getClass())) {
|
|
||||||
return resolver;
|
|
||||||
}
|
|
||||||
if (adapter.isAssignableFrom(IIndexFileSet.class)) {
|
|
||||||
return fIndexFileSet;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHeaderUnit() {
|
|
||||||
return fIsHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsHeaderUnit(boolean headerUnit) {
|
|
||||||
fIsHeader= headerUnit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
|
* @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
|
||||||
*/
|
*/
|
||||||
public void skippedFile(int offset, IncludeFileContent fileContent) {
|
public void skippedFile(int offset, IncludeFileContent fileContent) {
|
||||||
if (fIndexFileSet != null) {
|
super.skippedFile(offset, fileContent);
|
||||||
final List<IIndexFile> files= fileContent.getFilesIncluded();
|
|
||||||
for (IIndexFile indexFile : files) {
|
|
||||||
fIndexFileSet.add(indexFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
|
fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,15 +357,4 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
|
||||||
void handleAdditionalDirectives(ICPPNamespaceScope scope) {
|
void handleAdditionalDirectives(ICPPNamespaceScope scope) {
|
||||||
fScopeMapper.handleAdditionalDirectives(scope);
|
fScopeMapper.handleAdditionalDirectives(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
IIndexFileSet getFileSet() {
|
|
||||||
return fIndexFileSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLinkage()
|
|
||||||
*/
|
|
||||||
public ILinkage getLinkage() {
|
|
||||||
return Linkage.CPP_LINKAGE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1022,7 +1022,7 @@ public class CPPSemantics {
|
||||||
IIndexFileSet fileSet= IIndexFileSet.EMPTY;
|
IIndexFileSet fileSet= IIndexFileSet.EMPTY;
|
||||||
boolean isIndexBased= false;
|
boolean isIndexBased= false;
|
||||||
if (data.tu != null) {
|
if (data.tu != null) {
|
||||||
final IIndexFileSet fs= data.tu.getFileSet();
|
final IIndexFileSet fs= data.tu.getIndexFileSet();
|
||||||
if (fs != null) {
|
if (fs != null) {
|
||||||
fileSet= fs;
|
fileSet= fs;
|
||||||
isIndexBased= true;
|
isIndexBased= true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue