1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-08-31 17:47:57 -07:00
parent a5553b2507
commit b30497f5ec
2 changed files with 94 additions and 96 deletions

View file

@ -79,12 +79,12 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
private static class LinkageTask { private static class LinkageTask {
final int fLinkageID; final int fLinkageID;
private final Map<IIndexFileLocation, LocationTask> fLocationTasks; private final Map<IIndexFileLocation, LocationTask> fLocationTasks;
LinkageTask(int linkageID) { LinkageTask(int linkageID) {
fLinkageID= linkageID; fLinkageID= linkageID;
fLocationTasks= new HashMap<IIndexFileLocation, LocationTask>(); fLocationTasks= new HashMap<IIndexFileLocation, LocationTask>();
} }
boolean requestUpdate(IIndexFileLocation ifl, IIndexFragmentFile ifile, Object tu, boolean requestUpdate(IIndexFileLocation ifl, IIndexFragmentFile ifile, Object tu,
UpdateKind kind, Map<IIndexFileLocation, LocationTask> oneLinkageTasks) { UpdateKind kind, Map<IIndexFileLocation, LocationTask> oneLinkageTasks) {
LocationTask locTask= fLocationTasks.get(ifl); LocationTask locTask= fLocationTasks.get(ifl);
@ -93,11 +93,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
fLocationTasks.put(ifl, locTask); fLocationTasks.put(ifl, locTask);
} }
boolean result = locTask.requestUpdate(ifile, tu, kind); boolean result = locTask.requestUpdate(ifile, tu, kind);
// Store one-linkage tasks. // Store one-linkage tasks.
if (kind == UpdateKind.ONE_LINKAGE_HEADER && locTask.fVersionTasks.isEmpty()) if (kind == UpdateKind.ONE_LINKAGE_HEADER && locTask.fVersionTasks.isEmpty())
oneLinkageTasks.put(ifl, locTask); oneLinkageTasks.put(ifl, locTask);
return result; return result;
} }
@ -119,9 +119,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
boolean requestUpdate(IIndexFragmentFile ifile, Object tu, UpdateKind kind) { boolean requestUpdate(IIndexFragmentFile ifile, Object tu, UpdateKind kind) {
if (tu != null) if (tu != null)
fTu= tu; fTu= tu;
if (kind != null) if (fKind == null)
fKind= kind; fKind= kind;
if (ifile == null) { if (ifile == null) {
assert fVersionTasks.isEmpty(); assert fVersionTasks.isEmpty();
final boolean countRequest= !fCountedUnknownVersion; final boolean countRequest= !fCountedUnknownVersion;
@ -137,7 +137,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
*/ */
private boolean addVersionTask(IIndexFragmentFile ifile) { private boolean addVersionTask(IIndexFragmentFile ifile) {
FileVersionTask fc= findVersion(ifile); FileVersionTask fc= findVersion(ifile);
if (fc != null) if (fc != null)
return false; return false;
fc= new FileVersionTask(ifile); fc= new FileVersionTask(ifile);
@ -163,7 +163,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
return countRequest; return countRequest;
} }
void removeVersionTask(Iterator<FileVersionTask> it) { void removeVersionTask(Iterator<FileVersionTask> it) {
if (fVersionTasks.size() == 1) { if (fVersionTasks.size() == 1) {
fVersionTasks= Collections.emptyList(); fVersionTasks= Collections.emptyList();
@ -195,7 +195,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
if (fKind == UpdateKind.OTHER_HEADER) if (fKind == UpdateKind.OTHER_HEADER)
return true; return true;
return fStoredAVersion; return fStoredAVersion;
} }
@ -215,12 +215,12 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
fIndexFile= file; fIndexFile= file;
fOutdated= true; fOutdated= true;
} }
void setUpdated() { void setUpdated() {
fOutdated= false; fOutdated= false;
} }
} }
public static class IndexFileContent { public static class IndexFileContent {
private Object[] fPreprocessingDirectives; private Object[] fPreprocessingDirectives;
private ICPPUsingDirective[] fDirectives; private ICPPUsingDirective[] fDirectives;
@ -233,7 +233,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
public Object[] getPreprocessingDirectives() throws CoreException { public Object[] getPreprocessingDirectives() throws CoreException {
return fPreprocessingDirectives; return fPreprocessingDirectives;
} }
public ICPPUsingDirective[] getUsingDirectives() throws CoreException { public ICPPUsingDirective[] getUsingDirectives() throws CoreException {
return fDirectives; return fDirectives;
} }
@ -278,9 +278,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
} }
protected enum MessageKind { parsingFileTask, errorWhileParsing, tooManyIndexProblems } protected enum MessageKind { parsingFileTask, errorWhileParsing, tooManyIndexProblems }
private int fUpdateFlags= IIndexManager.UPDATE_ALL; private int fUpdateFlags= IIndexManager.UPDATE_ALL;
private UnusedHeaderStrategy fIndexHeadersWithoutContext= UnusedHeaderStrategy.useDefaultLanguage; private UnusedHeaderStrategy fIndexHeadersWithoutContext= UnusedHeaderStrategy.useDefaultLanguage;
private boolean fIndexFilesWithoutConfiguration= true; private boolean fIndexFilesWithoutConfiguration= true;
@ -288,12 +288,12 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
private Map<IIndexFile, IndexFileContent> fIndexContentCache= new LRUCache<IIndexFile, IndexFileContent>(500); private Map<IIndexFile, IndexFileContent> fIndexContentCache= new LRUCache<IIndexFile, IndexFileContent>(500);
private Map<IIndexFileLocation, IIndexFragmentFile[]> fIndexFilesCache= new LRUCache<IIndexFileLocation, IIndexFragmentFile[]>(5000); private Map<IIndexFileLocation, IIndexFragmentFile[]> fIndexFilesCache= new LRUCache<IIndexFileLocation, IIndexFragmentFile[]>(5000);
private Map<IIndexFileLocation, LocationTask> fOneLinkageTasks= new HashMap<IIndexFileLocation, AbstractIndexerTask.LocationTask>(); private Map<IIndexFileLocation, LocationTask> fOneLinkageTasks= new HashMap<IIndexFileLocation, AbstractIndexerTask.LocationTask>();
private Object[] fFilesToUpdate; private Object[] fFilesToUpdate;
private List<Object> fFilesToRemove = new ArrayList<Object>(); private List<Object> fFilesToRemove = new ArrayList<Object>();
private int fASTOptions; private int fASTOptions;
private int fForceNumberFiles= 0; private int fForceNumberFiles= 0;
protected IWritableIndex fIndex; protected IWritableIndex fIndex;
private ITodoTaskUpdater fTodoTaskUpdater; private ITodoTaskUpdater fTodoTaskUpdater;
private final boolean fIsFastIndexer; private final boolean fIsFastIndexer;
@ -302,7 +302,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
private int fSwallowOutOfMemoryError= 5; private int fSwallowOutOfMemoryError= 5;
/** /**
* A queue of urgent indexing tasks that contribute additional files to this task. * A queue of urgent indexing tasks that contribute additional files to this task.
* The files from the urgent tasks are indexed before all not yet processed files. * The files from the urgent tasks are indexed before all not yet processed files.
*/ */
private final LinkedList<AbstractIndexerTask> fUrgentTasks; private final LinkedList<AbstractIndexerTask> fUrgentTasks;
boolean fTaskCompleted; boolean fTaskCompleted;
@ -317,7 +317,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
incrementRequestedFilesCount(fFilesToUpdate.length + fFilesToRemove.size()); incrementRequestedFilesCount(fFilesToUpdate.length + fFilesToRemove.size());
fUrgentTasks = new LinkedList<AbstractIndexerTask>(); fUrgentTasks = new LinkedList<AbstractIndexerTask>();
} }
public final void setIndexHeadersWithoutContext(UnusedHeaderStrategy mode) { public final void setIndexHeadersWithoutContext(UnusedHeaderStrategy mode) {
fIndexHeadersWithoutContext= mode; fIndexHeadersWithoutContext= mode;
} }
@ -353,7 +353,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (!(urgentTask instanceof AbstractIndexerTask)) { if (!(urgentTask instanceof AbstractIndexerTask)) {
return false; return false;
} }
AbstractIndexerTask task = (AbstractIndexerTask) urgentTask; AbstractIndexerTask task = (AbstractIndexerTask) urgentTask;
if (task.fIsFastIndexer != fIsFastIndexer || if (task.fIsFastIndexer != fIsFastIndexer ||
task.fIndexFilesWithoutConfiguration != fIndexFilesWithoutConfiguration || task.fIndexFilesWithoutConfiguration != fIndexFilesWithoutConfiguration ||
(fIndexFilesWithoutConfiguration && task.fIndexHeadersWithoutContext != fIndexHeadersWithoutContext) || (fIndexFilesWithoutConfiguration && task.fIndexHeadersWithoutContext != fIndexHeadersWithoutContext) ||
@ -369,7 +369,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
fUrgentTasks.add(task); fUrgentTasks.add(task);
return true; return true;
} }
private synchronized boolean hasUrgentTasks() { private synchronized boolean hasUrgentTasks() {
return !fUrgentTasks.isEmpty(); return !fUrgentTasks.isEmpty();
} }
@ -389,7 +389,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
protected ITodoTaskUpdater createTodoTaskUpdater() { protected ITodoTaskUpdater createTodoTaskUpdater() {
return null; return null;
} }
/** /**
* @return array of linkage IDs that shall be parsed * @return array of linkage IDs that shall be parsed
*/ */
@ -443,7 +443,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
fInfo.fCompletedHeaders += header; fInfo.fCompletedHeaders += header;
} }
} }
private final void reportFile(boolean wasCounted, UpdateKind kind) { private final void reportFile(boolean wasCounted, UpdateKind kind) {
if (wasCounted) { if (wasCounted) {
if (kind == UpdateKind.REQUIRED_SOURCE) { if (kind == UpdateKind.REQUIRED_SOURCE) {
@ -470,13 +470,13 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (!fIndexFilesWithoutConfiguration) { if (!fIndexFilesWithoutConfiguration) {
fIndexHeadersWithoutContext= UnusedHeaderStrategy.skip; fIndexHeadersWithoutContext= UnusedHeaderStrategy.skip;
} }
fIndex= createIndex(); fIndex= createIndex();
if (fIndex == null) { if (fIndex == null) {
return; return;
} }
fTodoTaskUpdater= createTodoTaskUpdater(); fTodoTaskUpdater= createTodoTaskUpdater();
fASTOptions= ILanguage.OPTION_NO_IMAGE_LOCATIONS fASTOptions= ILanguage.OPTION_NO_IMAGE_LOCATIONS
| ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS; | ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS;
if (getSkipReferences() == SKIP_ALL_REFERENCES) { if (getSkipReferences() == SKIP_ALL_REFERENCES) {
@ -485,16 +485,16 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
fIndex.resetCacheCounters(); fIndex.resetCacheCounters();
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
try { try {
// Split into sources and headers, remove excluded sources. // Split into sources and headers, remove excluded sources.
HashMap<Integer, List<IIndexFileLocation>> files= new HashMap<Integer, List<IIndexFileLocation>>(); HashMap<Integer, List<IIndexFileLocation>> files= new HashMap<Integer, List<IIndexFileLocation>>();
final ArrayList<IIndexFragmentFile> indexFilesToRemove= new ArrayList<IIndexFragmentFile>(); final ArrayList<IIndexFragmentFile> indexFilesToRemove= new ArrayList<IIndexFragmentFile>();
extractFiles(files, indexFilesToRemove, monitor); extractFiles(files, indexFilesToRemove, monitor);
setResume(true); setResume(true);
// Remove files from index // Remove files from index
removeFilesInIndex(fFilesToRemove, indexFilesToRemove, monitor); removeFilesInIndex(fFilesToRemove, indexFilesToRemove, monitor);
@ -540,7 +540,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} else { } else {
list.addAll(0, entry.getValue()); list.addAll(0, entry.getValue());
} }
} }
} }
// Extract files from the urgent task. // Extract files from the urgent task.
files = new HashMap<Integer, List<IIndexFileLocation>>(); files = new HashMap<Integer, List<IIndexFileLocation>>();
@ -573,7 +573,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
private void setResume(boolean value) throws InterruptedException, CoreException { private void setResume(boolean value) throws InterruptedException, CoreException {
fIndex.acquireWriteLock(); fIndex.acquireWriteLock();
try { try {
fIndex.getWritableFragment().setProperty(IIndexFragment.PROPERTY_RESUME_INDEXER, String.valueOf(value)); fIndex.getWritableFragment().setProperty(IIndexFragment.PROPERTY_RESUME_INDEXER, String.valueOf(value));
} finally { } finally {
fIndex.releaseWriteLock(); fIndex.releaseWriteLock();
} }
@ -597,7 +597,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
final IIndexFileLocation ifl= fResolver.resolveFile(tu); final IIndexFileLocation ifl= fResolver.resolveFile(tu);
if (ifl == null) if (ifl == null)
continue; continue;
final IIndexFragmentFile[] indexFiles= fIndex.getWritableFiles(ifl); final IIndexFragmentFile[] indexFiles= fIndex.getWritableFiles(ifl);
final boolean isSourceUnit= fResolver.isSourceUnit(tu); final boolean isSourceUnit= fResolver.isSourceUnit(tu);
linkages.clear(); linkages.clear();
@ -605,7 +605,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
final boolean indexedUnconditionally = fResolver.isIndexedUnconditionally(ifl); final boolean indexedUnconditionally = fResolver.isIndexedUnconditionally(ifl);
if (regularContent || indexedUnconditionally) { if (regularContent || indexedUnconditionally) {
// Headers or sources required with a specific linkage // Headers or sources required with a specific linkage
final UpdateKind updateKind = isSourceUnit ? UpdateKind.REQUIRED_SOURCE final UpdateKind updateKind = isSourceUnit ? UpdateKind.REQUIRED_SOURCE
: regularContent && both ? UpdateKind.REQUIRED_HEADER : UpdateKind.ONE_LINKAGE_HEADER; : regularContent && both ? UpdateKind.REQUIRED_HEADER : UpdateKind.ONE_LINKAGE_HEADER;
if (regularContent || indexFiles.length == 0) { if (regularContent || indexFiles.length == 0) {
AbstractLanguage[] langs= fResolver.getLanguages(tu, fIndexHeadersWithoutContext); AbstractLanguage[] langs= fResolver.getLanguages(tu, fIndexHeadersWithoutContext);
@ -633,12 +633,12 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
} }
} }
// Handle other files present in index. // Handle other files present in index.
for (IIndexFragmentFile ifile : indexFiles) { for (IIndexFragmentFile ifile : indexFiles) {
if (ifile != null) { if (ifile != null) {
IIndexInclude ctx= ifile.getParsedInContext(); IIndexInclude ctx= ifile.getParsedInContext();
if (ctx == null && !indexedUnconditionally) { if (ctx == null && !indexedUnconditionally && ifile.hasContent()) {
iFilesToRemove.add(ifile); iFilesToRemove.add(ifile);
count++; count++;
} else { } else {
@ -674,13 +674,13 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
private boolean isRequiredInIndex(Object tu, IIndexFileLocation ifl, boolean isSourceUnit) { private boolean isRequiredInIndex(Object tu, IIndexFileLocation ifl, boolean isSourceUnit) {
// External files are never required // External files are never required
if (fResolver.isIndexedOnlyIfIncluded(tu)) if (fResolver.isIndexedOnlyIfIncluded(tu))
return false; return false;
// User preference to require all // User preference to require all
if (fIndexHeadersWithoutContext != UnusedHeaderStrategy.skip) if (fIndexHeadersWithoutContext != UnusedHeaderStrategy.skip)
return true; return true;
// Source file // Source file
if (isSourceUnit) { if (isSourceUnit) {
if (fIndexFilesWithoutConfiguration || fResolver.isFileBuildConfigured(tu)) if (fIndexFilesWithoutConfiguration || fResolver.isFileBuildConfigured(tu))
@ -692,7 +692,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
private boolean isModified(boolean checkTimestamps, boolean checkFileContentsHash, IIndexFileLocation ifl, private boolean isModified(boolean checkTimestamps, boolean checkFileContentsHash, IIndexFileLocation ifl,
Object tu, IIndexFragmentFile file) throws CoreException { Object tu, IIndexFragmentFile file) throws CoreException {
if (checkTimestamps) { if (checkTimestamps) {
if (fResolver.getLastModified(ifl) != file.getTimestamp() || if (fResolver.getLastModified(ifl) != file.getTimestamp() ||
computeFileSizeAndEncodingHashcode(ifl) != file.getSizeAndEncodingHashcode()) { computeFileSizeAndEncodingHashcode(ifl) != file.getSizeAndEncodingHashcode()) {
if (checkFileContentsHash && computeFileContentsHash(tu) == file.getContentsHash()) { if (checkFileContentsHash && computeFileContentsHash(tu) == file.getContentsHash()) {
return false; return false;
@ -712,7 +712,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
LinkageTask fileMap= createRequestMap(linkageID); LinkageTask fileMap= createRequestMap(linkageID);
return fileMap.requestUpdate(ifl, ifile, tu, kind, fOneLinkageTasks); return fileMap.requestUpdate(ifl, ifile, tu, kind, fOneLinkageTasks);
} }
private LinkageTask createRequestMap(int linkageID) { private LinkageTask createRequestMap(int linkageID) {
LinkageTask map= findRequestMap(linkageID); LinkageTask map= findRequestMap(linkageID);
if (map == null) { if (map == null) {
@ -729,7 +729,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
return null; return null;
} }
@Override @Override
protected void reportFileWrittenToIndex(FileInAST file, IIndexFragmentFile ifile) throws CoreException { protected void reportFileWrittenToIndex(FileInAST file, IIndexFragmentFile ifile) throws CoreException {
final FileContentKey fck = file.fileContentKey; final FileContentKey fck = file.fileContentKey;
@ -756,7 +756,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
fIndexContentCache.remove(ifile); fIndexContentCache.remove(ifile);
fIndexFilesCache.remove(file.fileContentKey.getLocation()); fIndexFilesCache.remove(file.fileContentKey.getLocation());
LocationTask task= fOneLinkageTasks.remove(location); LocationTask task= fOneLinkageTasks.remove(location);
if (task != null && task != locTask) { if (task != null && task != locTask) {
if (task.fKind == UpdateKind.ONE_LINKAGE_HEADER && !task.isCompleted()) { if (task.fKind == UpdateKind.ONE_LINKAGE_HEADER && !task.isCompleted()) {
@ -805,13 +805,13 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
filesToRemove.clear(); filesToRemove.clear();
} }
private void parseLinkage(int linkageID, List<IIndexFileLocation> files, IProgressMonitor monitor) private void parseLinkage(int linkageID, List<IIndexFileLocation> files, IProgressMonitor monitor)
throws CoreException, InterruptedException { throws CoreException, InterruptedException {
LinkageTask map = findRequestMap(linkageID); LinkageTask map = findRequestMap(linkageID);
if (map == null || files == null || files.isEmpty()) if (map == null || files == null || files.isEmpty())
return; return;
// First parse the required sources // First parse the required sources
for (Iterator<IIndexFileLocation> it= files.iterator(); it.hasNext();) { for (Iterator<IIndexFileLocation> it= files.iterator(); it.hasNext();) {
IIndexFileLocation ifl= it.next(); IIndexFileLocation ifl= it.next();
@ -826,7 +826,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
parseFile(tu, getLanguage(tu, linkageID), ifl, scannerInfo, null, monitor); parseFile(tu, getLanguage(tu, linkageID), ifl, scannerInfo, null, monitor);
} }
} }
// Files with context // Files with context
for (Iterator<IIndexFileLocation> it= files.iterator(); it.hasNext();) { for (Iterator<IIndexFileLocation> it= files.iterator(); it.hasNext();) {
IIndexFileLocation ifl= it.next(); IIndexFileLocation ifl= it.next();
@ -844,7 +844,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
} }
} }
// Files without context // Files without context
for (Iterator<IIndexFileLocation> it= files.iterator(); it.hasNext();) { for (Iterator<IIndexFileLocation> it= files.iterator(); it.hasNext();) {
IIndexFileLocation ifl= it.next(); IIndexFileLocation ifl= it.next();
@ -860,7 +860,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
parseFile(tu, getLanguage(tu, linkageID), ifl, scannerInfo, null, monitor); parseFile(tu, getLanguage(tu, linkageID), ifl, scannerInfo, null, monitor);
if (locTask.isCompleted()) if (locTask.isCompleted())
it.remove(); it.remove();
} }
} }
} }
@ -874,7 +874,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (!locTask.needsVersion()) { if (!locTask.needsVersion()) {
if (monitor.isCanceled() || hasUrgentTasks()) if (monitor.isCanceled() || hasUrgentTasks())
return; return;
Iterator<FileVersionTask> it= locTask.fVersionTasks.iterator(); Iterator<FileVersionTask> it= locTask.fVersionTasks.iterator();
while (it.hasNext()) { while (it.hasNext()) {
FileVersionTask v = it.next(); FileVersionTask v = it.next();
if (v.fOutdated) { if (v.fOutdated) {
@ -897,18 +897,18 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
final FileVersionTask versionTask, Object tu, LinkedHashSet<IIndexFile> safeGuard, final FileVersionTask versionTask, Object tu, LinkedHashSet<IIndexFile> safeGuard,
IProgressMonitor monitor) throws CoreException, InterruptedException { IProgressMonitor monitor) throws CoreException, InterruptedException {
final IIndexFragmentFile headerFile = versionTask.fIndexFile; final IIndexFragmentFile headerFile = versionTask.fIndexFile;
final int safeguardSize= safeGuard.size(); final int safeguardSize= safeGuard.size();
for(;;) { while (true) {
// Look for a context and parse the file // Look for a context and parse the file
IIndexFragmentFile ctxFile = findContextFile(linkageID, map, versionTask, safeGuard, monitor); IIndexFragmentFile ctxFile = findContextFile(linkageID, map, versionTask, safeGuard, monitor);
if (ctxFile == null || ctxFile == headerFile) if (ctxFile == null || ctxFile == headerFile)
return; return;
Object contextTu= fResolver.getInputFile(ctxFile.getLocation()); Object contextTu= fResolver.getInputFile(ctxFile.getLocation());
if (contextTu == null) if (contextTu == null)
return; return;
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, contextTu); final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, contextTu);
final AbstractLanguage language = getLanguage(contextTu, linkageID); final AbstractLanguage language = getLanguage(contextTu, linkageID);
final FileContext ctx= new FileContext(ctxFile, headerFile); final FileContext ctx= new FileContext(ctxFile, headerFile);
@ -926,14 +926,14 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (parseFile(d.fTu, language, d.fIndexFile.getLocation(), scannerInfo, new FileContext(ctxFile, d.fIndexFile), monitor) == null) if (parseFile(d.fTu, language, d.fIndexFile.getLocation(), scannerInfo, new FileContext(ctxFile, d.fIndexFile), monitor) == null)
done= false; done= false;
} }
} }
} }
if (!ctx.fLostPragmaOnceSemantics) if (!ctx.fLostPragmaOnceSemantics)
return; return;
// Try the next context // Try the next context
restoreSet(safeGuard, safeguardSize); restoreSet(safeGuard, safeguardSize);
} }
} }
private void restoreSet(LinkedHashSet<?> set, int restoreSize) { private void restoreSet(LinkedHashSet<?> set, int restoreSize) {
@ -943,7 +943,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
it.remove(); it.remove();
} else { } else {
restoreSize--; restoreSize--;
} }
} }
} }
@ -951,19 +951,19 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
final FileVersionTask versionTask, LinkedHashSet<IIndexFile> safeGuard, IProgressMonitor monitor) final FileVersionTask versionTask, LinkedHashSet<IIndexFile> safeGuard, IProgressMonitor monitor)
throws CoreException, InterruptedException { throws CoreException, InterruptedException {
IIndexFragmentFile ctxFile= versionTask.fIndexFile; IIndexFragmentFile ctxFile= versionTask.fIndexFile;
for(;;) { while (true) {
IIndexInclude ctxInclude= ctxFile.getParsedInContext(); IIndexInclude ctxInclude= ctxFile.getParsedInContext();
if (ctxInclude == null) if (ctxInclude == null)
return ctxFile; return ctxFile;
IIndexFragmentFile nextCtx= (IIndexFragmentFile) ctxInclude.getIncludedBy(); IIndexFragmentFile nextCtx= (IIndexFragmentFile) ctxInclude.getIncludedBy();
if (nextCtx == null) if (nextCtx == null)
return nextCtx; return nextCtx;
// Found a recursion // Found a recursion.
if (!safeGuard.add(nextCtx)) if (!safeGuard.add(nextCtx))
return null; return null;
final IIndexFileLocation ctxIfl = nextCtx.getLocation(); final IIndexFileLocation ctxIfl = nextCtx.getLocation();
LocationTask ctxTask= map.find(ctxIfl); LocationTask ctxTask= map.find(ctxIfl);
if (ctxTask != null) { if (ctxTask != null) {
@ -984,7 +984,6 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
} }
private DependsOnOutdatedFileException parseFile(Object tu, AbstractLanguage lang, private DependsOnOutdatedFileException parseFile(Object tu, AbstractLanguage lang,
IIndexFileLocation ifl, IScannerInfo scanInfo, FileContext ctx, IProgressMonitor pm) IIndexFileLocation ifl, IScannerInfo scanInfo, FileContext ctx, IProgressMonitor pm)
throws CoreException, InterruptedException { throws CoreException, InterruptedException {
@ -1035,7 +1034,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
return null; return null;
} }
private IPath getLabel(IIndexFileLocation ifl) { private IPath getLabel(IIndexFileLocation ifl) {
String fullPath= ifl.getFullPath(); String fullPath= ifl.getFullPath();
if (fullPath != null) { if (fullPath != null) {
@ -1061,7 +1060,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (CCorePlugin.PLUGIN_ID.equals(s.getPlugin())) if (CCorePlugin.PLUGIN_ID.equals(s.getPlugin()))
throw (CoreException) e; throw (CoreException) e;
} }
// mask errors in order to avoid dialog from platform // mask errors in order to avoid dialog from platform
Throwable exception = s.getException(); Throwable exception = s.getException();
if (exception != null) { if (exception != null) {
@ -1070,7 +1069,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
e= masked; e= masked;
exception= null; exception= null;
} }
} }
if (exception == null) { if (exception == null) {
s= new Status(s.getSeverity(), s.getPlugin(), s.getCode(), s.getMessage(), e); s= new Status(s.getSeverity(), s.getPlugin(), s.getCode(), s.getMessage(), e);
} }
@ -1102,7 +1101,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
if (fFileSizeLimit > 0 && fResolver.getFileSize(codeReader.getFileLocation()) > fFileSizeLimit) { if (fFileSizeLimit > 0 && fResolver.getFileSize(codeReader.getFileLocation()) > fFileSizeLimit) {
if (fShowActivity) { if (fShowActivity) {
trace("Indexer: Skipping large file " + codeReader.getFileLocation()); //$NON-NLS-1$ trace("Indexer: Skipping large file " + codeReader.getFileLocation()); //$NON-NLS-1$
} }
return null; return null;
} }
@ -1124,7 +1123,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
ibfcp.setContextToHeaderGap(ctx2header); ibfcp.setContextToHeaderGap(ctx2header);
ibfcp.setLinkage(language.getLinkageID()); ibfcp.setLinkage(language.getLinkageID());
} }
IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory, IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory,
fIndex, options, getLogService()); fIndex, options, getLogService());
if (pm.isCanceled()) { if (pm.isCanceled()) {
@ -1137,7 +1136,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
final IncludeFileContentProvider fileContentProvider = createReaderFactory(); final IncludeFileContentProvider fileContentProvider = createReaderFactory();
if (fileContentProvider instanceof InternalFileContentProvider) if (fileContentProvider instanceof InternalFileContentProvider)
return (InternalFileContentProvider) fileContentProvider; return (InternalFileContentProvider) fileContentProvider;
throw new IllegalArgumentException("Invalid file content provider"); //$NON-NLS-1$ throw new IllegalArgumentException("Invalid file content provider"); //$NON-NLS-1$
} }
@ -1145,7 +1144,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
FileContext ctx, IProgressMonitor pm) throws CoreException, InterruptedException { FileContext ctx, IProgressMonitor pm) throws CoreException, InterruptedException {
HashSet<FileContentKey> enteredFiles= new HashSet<FileContentKey>(); HashSet<FileContentKey> enteredFiles= new HashSet<FileContentKey>();
ArrayList<FileInAST> orderedFileKeys= new ArrayList<FileInAST>(); ArrayList<FileInAST> orderedFileKeys= new ArrayList<FileInAST>();
final IIndexFileLocation topIfl = fResolver.resolveASTPath(ast.getFilePath()); final IIndexFileLocation topIfl = fResolver.resolveASTPath(ast.getFilePath());
FileContentKey topKey = new FileContentKey(linkageID, topIfl, ast.getSignificantMacros()); FileContentKey topKey = new FileContentKey(linkageID, topIfl, ast.getSignificantMacros());
enteredFiles.add(topKey); enteredFiles.add(topKey);
@ -1154,7 +1153,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
for (IASTInclusionNode inclusion : inclusions) { for (IASTInclusionNode inclusion : inclusions) {
collectOrderedFileKeys(linkageID, inclusion, enteredFiles, orderedFileKeys); collectOrderedFileKeys(linkageID, inclusion, enteredFiles, orderedFileKeys);
} }
IIndexFragmentFile newFile= selectIndexFile(linkageID, topIfl, ast.getSignificantMacros()); IIndexFragmentFile newFile= selectIndexFile(linkageID, topIfl, ast.getSignificantMacros());
if (ctx != null) { if (ctx != null) {
orderedFileKeys.add(new FileInAST(topKey, codeReader)); orderedFileKeys.add(new FileInAST(topKey, codeReader));
@ -1163,7 +1162,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} else if (newFile == null) { } else if (newFile == null) {
orderedFileKeys.add(new FileInAST(topKey, codeReader)); orderedFileKeys.add(new FileInAST(topKey, codeReader));
} }
FileInAST[] fileKeys= orderedFileKeys.toArray(new FileInAST[orderedFileKeys.size()]); FileInAST[] fileKeys= orderedFileKeys.toArray(new FileInAST[orderedFileKeys.size()]);
try { try {
addSymbols(ast, fileKeys, fIndex, false, ctx, fTodoTaskUpdater, pm); addSymbols(ast, fileKeys, fIndex, false, ctx, fTodoTaskUpdater, pm);
@ -1237,7 +1236,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
return fc; return fc;
} }
IIndexFragmentFile selectIndexFile(int linkageID, IIndexFileLocation ifl, ISignificantMacros sigMacros) throws CoreException { IIndexFragmentFile selectIndexFile(int linkageID, IIndexFileLocation ifl, ISignificantMacros sigMacros) throws CoreException {
LinkageTask map = findRequestMap(linkageID); LinkageTask map = findRequestMap(linkageID);
if (map != null) { if (map != null) {
@ -1249,7 +1248,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
} }
} }
IIndexFragmentFile[] files = getAvailableIndexFiles(linkageID, ifl); IIndexFragmentFile[] files = getAvailableIndexFiles(linkageID, ifl);
for (IIndexFragmentFile file : files) { for (IIndexFragmentFile file : files) {
if (sigMacros.equals(file.getSignificantMacros())) if (sigMacros.equals(file.getSignificantMacros()))
@ -1273,7 +1272,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
} }
} }
IIndexFile[] files = getAvailableIndexFiles(linkageID, ifl); IIndexFile[] files = getAvailableIndexFiles(linkageID, ifl);
for (IIndexFile indexFile : files) { for (IIndexFile indexFile : files) {
if (md.satisfies(indexFile.getSignificantMacros())) { if (md.satisfies(indexFile.getSignificantMacros())) {
@ -1301,7 +1300,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} else { } else {
files= new IIndexFragmentFile[j]; files= new IIndexFragmentFile[j];
System.arraycopy(fragFiles, 0, files, 0, j); System.arraycopy(fragFiles, 0, files, 0, j);
} }
fIndexFilesCache.put(ifl, files); fIndexFilesCache.put(ifl, files);
} }
return files; return files;

View file

@ -107,13 +107,13 @@ abstract public class PDOMWriter {
return fileContentKey.toString(); return fileContentKey.toString();
} }
} }
public static class FileContext { public static class FileContext {
final IIndexFragmentFile fContext; final IIndexFragmentFile fContext;
final IIndexFragmentFile fOldFile; final IIndexFragmentFile fOldFile;
IIndexFragmentFile fNewFile; IIndexFragmentFile fNewFile;
public boolean fLostPragmaOnceSemantics; public boolean fLostPragmaOnceSemantics;
public FileContext(IIndexFragmentFile context, IIndexFragmentFile oldFile) { public FileContext(IIndexFragmentFile context, IIndexFragmentFile oldFile) {
fContext= context; fContext= context;
fOldFile= oldFile; fOldFile= oldFile;
@ -132,7 +132,7 @@ abstract public class PDOMWriter {
final ArrayList<IASTPreprocessorStatement> fMacros= new ArrayList<IASTPreprocessorStatement>(); final ArrayList<IASTPreprocessorStatement> fMacros= new ArrayList<IASTPreprocessorStatement>();
final ArrayList<IASTPreprocessorIncludeStatement> fIncludes= new ArrayList<IASTPreprocessorIncludeStatement>(); final ArrayList<IASTPreprocessorIncludeStatement> fIncludes= new ArrayList<IASTPreprocessorIncludeStatement>();
} }
private static class Data { private static class Data {
final IASTTranslationUnit fAST; final IASTTranslationUnit fAST;
final FileInAST[] fSelectedFiles; final FileInAST[] fSelectedFiles;
@ -140,7 +140,7 @@ abstract public class PDOMWriter {
final Map<IASTPreprocessorIncludeStatement, Symbols> fSymbolMap = new HashMap<IASTPreprocessorIncludeStatement, Symbols>(); final Map<IASTPreprocessorIncludeStatement, Symbols> fSymbolMap = new HashMap<IASTPreprocessorIncludeStatement, Symbols>();
final Set<IASTPreprocessorIncludeStatement> fContextIncludes = new HashSet<IASTPreprocessorIncludeStatement>(); final Set<IASTPreprocessorIncludeStatement> fContextIncludes = new HashSet<IASTPreprocessorIncludeStatement>();
final List<IStatus> fStati= new ArrayList<IStatus>(); final List<IStatus> fStati= new ArrayList<IStatus>();
public Data(IASTTranslationUnit ast, FileInAST[] selectedFiles, IWritableIndex index) { public Data(IASTTranslationUnit ast, FileInAST[] selectedFiles, IWritableIndex index) {
fAST= ast; fAST= ast;
fSelectedFiles= selectedFiles; fSelectedFiles= selectedFiles;
@ -202,8 +202,8 @@ abstract public class PDOMWriter {
/** /**
* Extracts symbols from the given AST and adds them to the index. * Extracts symbols from the given AST and adds them to the index.
* *
* When flushIndex is set to <code>false</code>, you must make sure to flush * When flushIndex is set to <code>false</code>, you must make sure to flush
* the index after your last write operation. * the index after your last write operation.
*/ */
final protected void addSymbols(IASTTranslationUnit ast, FileInAST[] selectedFiles, final protected void addSymbols(IASTTranslationUnit ast, FileInAST[] selectedFiles,
@ -215,23 +215,22 @@ abstract public class PDOMWriter {
fShowScannerProblems= true; fShowScannerProblems= true;
fShowSyntaxProblems= true; fShowSyntaxProblems= true;
} }
Data data= new Data(ast, selectedFiles, index); Data data= new Data(ast, selectedFiles, index);
for (FileInAST file : selectedFiles) { for (FileInAST file : selectedFiles) {
data.fSymbolMap.put(file.includeStatement, new Symbols()); data.fSymbolMap.put(file.includeStatement, new Symbols());
} }
// Extract symbols from AST // Extract symbols from AST.
extractSymbols(data); extractSymbols(data);
// Name resolution // Name resolution.
resolveNames(data, pm); resolveNames(data, pm);
// Index update // Index update.
storeSymbolsInIndex(data, ctx, flushIndex, pm); storeSymbolsInIndex(data, ctx, flushIndex, pm);
// Tasks update // Tasks update.
if (taskUpdater != null) { if (taskUpdater != null) {
Set<IIndexFileLocation> locations= new HashSet<IIndexFileLocation>(); Set<IIndexFileLocation> locations= new HashSet<IIndexFileLocation>();
for (FileInAST file : selectedFiles) { for (FileInAST file : selectedFiles) {
@ -283,8 +282,8 @@ abstract public class PDOMWriter {
if (!isReplacement || newFile == null) { if (!isReplacement || newFile == null) {
ifile= storeFileInIndex(data, fileInAST, linkageID, lock); ifile= storeFileInIndex(data, fileInAST, linkageID, lock);
reportFileWrittenToIndex(fileInAST, ifile); reportFileWrittenToIndex(fileInAST, ifile);
} }
if (isReplacement) { if (isReplacement) {
if (ifile == null) if (ifile == null)
ifile= newFile; ifile= newFile;
@ -297,7 +296,7 @@ abstract public class PDOMWriter {
data.fIndex.transferIncluders(ctx.fOldFile, ifile); data.fIndex.transferIncluders(ctx.fOldFile, ifile);
} }
} }
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
th= e; th= e;
} catch (StackOverflowError e) { } catch (StackOverflowError e) {
@ -538,13 +537,13 @@ abstract public class PDOMWriter {
// if another thread is waiting for a read lock. // if another thread is waiting for a read lock.
final FileContentKey fileKey = astFile.fileContentKey; final FileContentKey fileKey = astFile.fileContentKey;
final IASTPreprocessorIncludeStatement owner= astFile.includeStatement; final IASTPreprocessorIncludeStatement owner= astFile.includeStatement;
IIndexFileLocation location = fileKey.getLocation(); IIndexFileLocation location = fileKey.getLocation();
ISignificantMacros significantMacros = fileKey.getSignificantMacros(); ISignificantMacros significantMacros = fileKey.getSignificantMacros();
IIndexFragmentFile oldFile = index.getWritableFile(linkageID, location, significantMacros); IIndexFragmentFile oldFile = index.getWritableFile(linkageID, location, significantMacros);
file= index.addUncommittedFile(linkageID, location, significantMacros); file= index.addUncommittedFile(linkageID, location, significantMacros);
try { try {
boolean pragmaOnce= owner != null ? owner.hasPragmaOnceSemantics() : data.fAST.hasPragmaOnceSemantics(); boolean pragmaOnce= owner != null ? owner.hasPragmaOnceSemantics() : data.fAST.hasPragmaOnceSemantics();
file.setPragmaOnceSemantics(pragmaOnce); file.setPragmaOnceSemantics(pragmaOnce);
Symbols lists= data.fSymbolMap.get(owner); Symbols lists= data.fSymbolMap.get(owner);
@ -571,7 +570,7 @@ abstract public class PDOMWriter {
includeInfos.add(new IncludeInformation(stmt, targetLoc, sig, false)); includeInfos.add(new IncludeInformation(stmt, targetLoc, sig, false));
} }
} }
final boolean isContext = stmt.isActive() && stmt.isResolved() && final boolean isContext = stmt.isActive() && stmt.isResolved() &&
(data.fContextIncludes.contains(stmt) || isContextFor(oldFile, stmt)); (data.fContextIncludes.contains(stmt) || isContextFor(oldFile, stmt));
includeInfos.add(new IncludeInformation(stmt, targetLoc, mainSig, isContext)); includeInfos.add(new IncludeInformation(stmt, targetLoc, mainSig, isContext));
} }