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

Bug 338349. Added IASTTranslationUnit.getOriginatingTranslationUnit method.

This commit is contained in:
Sergey Prigogin 2011-03-25 21:39:08 +00:00
parent 8de0852813
commit 67cc996e49
3 changed files with 75 additions and 42 deletions

View file

@ -66,6 +66,7 @@ import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
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.parser.InternalParserUtil;
import org.eclipse.cdt.internal.core.parser.ParserLogService;
@ -92,7 +93,6 @@ import org.eclipse.core.runtime.content.IContentType;
* @see ITranslationUnit
*/
public class TranslationUnit extends Openable implements ITranslationUnit {
private URI location = null;
private String contentTypeId;
@ -775,35 +775,39 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
}
FileContent fileContent= FileContent.create(this);
if (fileContent != null) {
ILanguage language= configureWith.getLanguage();
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);
}
if (fileContent == null) {
return null;
}
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) {
@ -897,6 +901,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
final IASTTranslationUnit ast = result.getTranslationUnit();
if (ast != null) {
ast.setIsHeaderUnit(!isSourceUnit());
((ASTTranslationUnit) ast).setOriginatingTranslationUnit(this);
}
}
return result;

View file

@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.core.runtime.IAdaptable;
@ -325,7 +326,8 @@ public interface IASTTranslationUnit extends IASTDeclarationListOwner, IAdaptabl
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()
*
@ -333,4 +335,12 @@ public interface IASTTranslationUnit extends IASTDeclarationListOwner, IAdaptabl
* @since 5.3
*/
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();
}

View file

@ -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.IIndexFile;
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.internal.core.index.IndexBasedFileContentProvider;
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.
*
* 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 {
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];
@ -66,9 +69,9 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
private IIndexFileSet fASTFileSet;
private INodeFactory fNodeFactory;
private boolean fForContentAssist;
@Override
private ITranslationUnit fOriginatingTranslationUnit;
@Override
public final IASTTranslationUnit getTranslationUnit() {
return this;
}
@ -77,7 +80,8 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
if (d != null) {
d.setParent(this);
d.setPropertyInParent(OWNED_DECLARATION);
fAllDeclarations = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, d);
fAllDeclarations = (IASTDeclaration[]) ArrayUtil.append(IASTDeclaration.class,
fAllDeclarations, ++fLastDeclaration, d);
fActiveDeclarations= null;
}
}
@ -93,7 +97,8 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
public final IASTDeclaration[] getDeclarations(boolean includeInactive) {
if (includeInactive) {
fAllDeclarations= (IASTDeclaration[]) ArrayUtil.removeNullsAfter(IASTDeclaration.class, fAllDeclarations, fLastDeclaration);
fAllDeclarations= (IASTDeclaration[]) ArrayUtil.removeNullsAfter(IASTDeclaration.class,
fAllDeclarations, fLastDeclaration);
return fAllDeclarations;
}
return getDeclarations();
@ -386,8 +391,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
public final IIndexFileSet getASTFileSet() {
return fASTFileSet;
}
/*
* (non-Javadoc)
*
@ -408,14 +412,15 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
protected void copyAbstractTU(ASTTranslationUnit copy, CopyStyle style) {
copy.setIndex(fIndex);
copy.setIsHeaderUnit(fIsHeader);
copy.setASTNodeFactory(fNodeFactory);
copy.fIsHeader = fIsHeader;
copy.fNodeFactory = fNodeFactory;
copy.setLocationResolver(fLocationResolver);
copy.setIsForContentAssist(fForContentAssist);
copy.fForContentAssist = fForContentAssist;
copy.fOriginatingTranslationUnit = fOriginatingTranslationUnit;
for (IASTDeclaration declaration : getDeclarations())
copy.addDeclaration(declaration == null ? null : declaration.copy(style));
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;
}
}