mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Bug 338349. Added IASTTranslationUnit.getOriginatingTranslationUnit method.
This commit is contained in:
parent
8de0852813
commit
67cc996e49
3 changed files with 75 additions and 42 deletions
|
@ -66,6 +66,7 @@ import org.eclipse.cdt.core.parser.ParserUtil;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
|
||||||
import org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider;
|
import org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider;
|
||||||
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserLogService;
|
import org.eclipse.cdt.internal.core.parser.ParserLogService;
|
||||||
|
@ -92,7 +93,6 @@ import org.eclipse.core.runtime.content.IContentType;
|
||||||
* @see ITranslationUnit
|
* @see ITranslationUnit
|
||||||
*/
|
*/
|
||||||
public class TranslationUnit extends Openable implements ITranslationUnit {
|
public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
|
|
||||||
private URI location = null;
|
private URI location = null;
|
||||||
private String contentTypeId;
|
private String contentTypeId;
|
||||||
|
|
||||||
|
@ -775,35 +775,39 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
}
|
}
|
||||||
|
|
||||||
FileContent fileContent= FileContent.create(this);
|
FileContent fileContent= FileContent.create(this);
|
||||||
if (fileContent != null) {
|
if (fileContent == null) {
|
||||||
ILanguage language= configureWith.getLanguage();
|
return null;
|
||||||
fLanguageOfContext= language;
|
|
||||||
if (language != null) {
|
|
||||||
IncludeFileContentProvider crf= getIncludeFileContentProvider(style, index, language.getLinkageID());
|
|
||||||
int options= 0;
|
|
||||||
if ((style & AST_SKIP_FUNCTION_BODIES) != 0) {
|
|
||||||
options |= ILanguage.OPTION_SKIP_FUNCTION_BODIES;
|
|
||||||
}
|
|
||||||
if ((style & AST_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS) != 0) {
|
|
||||||
options |= ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS;
|
|
||||||
}
|
|
||||||
if ((style & AST_PARSE_INACTIVE_CODE) != 0) {
|
|
||||||
options |= ILanguage.OPTION_PARSE_INACTIVE_CODE;
|
|
||||||
}
|
|
||||||
if (isSourceUnit()) {
|
|
||||||
options |= ILanguage.OPTION_IS_SOURCE_UNIT;
|
|
||||||
}
|
|
||||||
final IParserLogService log;
|
|
||||||
if (monitor instanceof ICanceler) {
|
|
||||||
log= new ParserLogService(DebugLogConstants.PARSER, (ICanceler)monitor);
|
|
||||||
} else {
|
|
||||||
log= ParserUtil.getParserLogService();
|
|
||||||
}
|
|
||||||
return ((AbstractLanguage) language).getASTTranslationUnit(fileContent, scanInfo, crf, index,
|
|
||||||
options, log);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
ILanguage language= configureWith.getLanguage();
|
||||||
|
fLanguageOfContext= language;
|
||||||
|
if (language == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
IncludeFileContentProvider crf= getIncludeFileContentProvider(style, index, language.getLinkageID());
|
||||||
|
int options= 0;
|
||||||
|
if ((style & AST_SKIP_FUNCTION_BODIES) != 0) {
|
||||||
|
options |= ILanguage.OPTION_SKIP_FUNCTION_BODIES;
|
||||||
|
}
|
||||||
|
if ((style & AST_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS) != 0) {
|
||||||
|
options |= ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS;
|
||||||
|
}
|
||||||
|
if ((style & AST_PARSE_INACTIVE_CODE) != 0) {
|
||||||
|
options |= ILanguage.OPTION_PARSE_INACTIVE_CODE;
|
||||||
|
}
|
||||||
|
if (isSourceUnit()) {
|
||||||
|
options |= ILanguage.OPTION_IS_SOURCE_UNIT;
|
||||||
|
}
|
||||||
|
final IParserLogService log;
|
||||||
|
if (monitor instanceof ICanceler) {
|
||||||
|
log= new ParserLogService(DebugLogConstants.PARSER, (ICanceler)monitor);
|
||||||
|
} else {
|
||||||
|
log= ParserUtil.getParserLogService();
|
||||||
|
}
|
||||||
|
ASTTranslationUnit ast = (ASTTranslationUnit) ((AbstractLanguage) language).getASTTranslationUnit(
|
||||||
|
fileContent, scanInfo, crf, index, options, log);
|
||||||
|
ast.setOriginatingTranslationUnit(this);
|
||||||
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IncludeFileContentProvider getIncludeFileContentProvider(int style, IIndex index, int linkageID) {
|
private IncludeFileContentProvider getIncludeFileContentProvider(int style, IIndex index, int linkageID) {
|
||||||
|
@ -897,6 +901,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
final IASTTranslationUnit ast = result.getTranslationUnit();
|
final IASTTranslationUnit ast = result.getTranslationUnit();
|
||||||
if (ast != null) {
|
if (ast != null) {
|
||||||
ast.setIsHeaderUnit(!isSourceUnit());
|
ast.setIsHeaderUnit(!isSourceUnit());
|
||||||
|
((ASTTranslationUnit) ast).setOriginatingTranslationUnit(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -15,6 +15,7 @@ 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.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||||
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
|
||||||
|
@ -325,7 +326,8 @@ public interface IASTTranslationUnit extends IASTDeclarationListOwner, IAdaptabl
|
||||||
public IASTTranslationUnit copy();
|
public IASTTranslationUnit copy();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a copy of the AST, however the ILocationResolver and the preprocessor nodes are not copied.
|
* Returns a copy of the AST, however the ILocationResolver and the preprocessor nodes are not
|
||||||
|
* copied.
|
||||||
*
|
*
|
||||||
* @see IASTNode#copy()
|
* @see IASTNode#copy()
|
||||||
*
|
*
|
||||||
|
@ -333,4 +335,12 @@ public interface IASTTranslationUnit extends IASTDeclarationListOwner, IAdaptabl
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
public IASTTranslationUnit copy(CopyStyle style);
|
public IASTTranslationUnit copy(CopyStyle style);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ITranslationUnit this AST originated from, or <code>null</code> if the AST
|
||||||
|
* does not correspond to an ITranslationUnit.
|
||||||
|
*
|
||||||
|
* @since 5.3
|
||||||
|
*/
|
||||||
|
public ITranslationUnit getOriginatingTranslationUnit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexFile;
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||||
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider;
|
import org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
||||||
|
@ -46,9 +47,11 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for all translation units.
|
* Abstract base class for all translation units.
|
||||||
|
*
|
||||||
|
* This class and other ASTNode subclasses are not thread safe.
|
||||||
|
* Even 'get' methods may cause changes to the underlying object.
|
||||||
*/
|
*/
|
||||||
public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslationUnit, ISkippedIndexedFilesListener {
|
public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslationUnit, ISkippedIndexedFilesListener {
|
||||||
|
|
||||||
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
|
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 IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
|
||||||
private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0];
|
private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0];
|
||||||
|
@ -66,9 +69,9 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
private IIndexFileSet fASTFileSet;
|
private IIndexFileSet fASTFileSet;
|
||||||
private INodeFactory fNodeFactory;
|
private INodeFactory fNodeFactory;
|
||||||
private boolean fForContentAssist;
|
private boolean fForContentAssist;
|
||||||
|
private ITranslationUnit fOriginatingTranslationUnit;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final IASTTranslationUnit getTranslationUnit() {
|
public final IASTTranslationUnit getTranslationUnit() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +80,8 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
d.setParent(this);
|
d.setParent(this);
|
||||||
d.setPropertyInParent(OWNED_DECLARATION);
|
d.setPropertyInParent(OWNED_DECLARATION);
|
||||||
fAllDeclarations = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, d);
|
fAllDeclarations = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class,
|
||||||
|
fAllDeclarations, ++fLastDeclaration, d);
|
||||||
fActiveDeclarations= null;
|
fActiveDeclarations= null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +97,8 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
|
|
||||||
public final IASTDeclaration[] getDeclarations(boolean includeInactive) {
|
public final IASTDeclaration[] getDeclarations(boolean includeInactive) {
|
||||||
if (includeInactive) {
|
if (includeInactive) {
|
||||||
fAllDeclarations= (IASTDeclaration[]) ArrayUtil.removeNullsAfter(IASTDeclaration.class, fAllDeclarations, fLastDeclaration);
|
fAllDeclarations= (IASTDeclaration[]) ArrayUtil.removeNullsAfter(IASTDeclaration.class,
|
||||||
|
fAllDeclarations, fLastDeclaration);
|
||||||
return fAllDeclarations;
|
return fAllDeclarations;
|
||||||
}
|
}
|
||||||
return getDeclarations();
|
return getDeclarations();
|
||||||
|
@ -386,8 +391,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
public final IIndexFileSet getASTFileSet() {
|
public final IIndexFileSet getASTFileSet() {
|
||||||
return fASTFileSet;
|
return fASTFileSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
@ -408,14 +412,15 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
|
|
||||||
protected void copyAbstractTU(ASTTranslationUnit copy, CopyStyle style) {
|
protected void copyAbstractTU(ASTTranslationUnit copy, CopyStyle style) {
|
||||||
copy.setIndex(fIndex);
|
copy.setIndex(fIndex);
|
||||||
copy.setIsHeaderUnit(fIsHeader);
|
copy.fIsHeader = fIsHeader;
|
||||||
copy.setASTNodeFactory(fNodeFactory);
|
copy.fNodeFactory = fNodeFactory;
|
||||||
copy.setLocationResolver(fLocationResolver);
|
copy.setLocationResolver(fLocationResolver);
|
||||||
copy.setIsForContentAssist(fForContentAssist);
|
copy.fForContentAssist = fForContentAssist;
|
||||||
|
copy.fOriginatingTranslationUnit = fOriginatingTranslationUnit;
|
||||||
|
|
||||||
for (IASTDeclaration declaration : getDeclarations())
|
for (IASTDeclaration declaration : getDeclarations())
|
||||||
copy.addDeclaration(declaration == null ? null : declaration.copy(style));
|
copy.addDeclaration(declaration == null ? null : declaration.copy(style));
|
||||||
|
|
||||||
copy.setOffsetAndLength(this);
|
copy.setOffsetAndLength(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,4 +433,17 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getOriginatingTranslationUnit()
|
||||||
|
*/
|
||||||
|
public ITranslationUnit getOriginatingTranslationUnit() {
|
||||||
|
return fOriginatingTranslationUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginatingTranslationUnit(ITranslationUnit tu) {
|
||||||
|
this.fOriginatingTranslationUnit = tu;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue