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

Cleanup handling of new file-versions.

This commit is contained in:
Markus Schorn 2011-10-05 13:50:34 +02:00
parent 923b1a5068
commit 333559e5ea
2 changed files with 73 additions and 77 deletions

View file

@ -99,7 +99,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
private static class LocationTask { private static class LocationTask {
private boolean fAddRequested; private boolean fCountedUnknownVersion;
private boolean fStoredAVersion;
Object fTu; Object fTu;
UpdateKind fKind= UpdateKind.OTHER_HEADER; UpdateKind fKind= UpdateKind.OTHER_HEADER;
private List<FileVersionTask> fVersionTasks= Collections.emptyList(); private List<FileVersionTask> fVersionTasks= Collections.emptyList();
@ -115,21 +116,28 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (ifile == null) { if (ifile == null) {
assert fVersionTasks.isEmpty(); assert fVersionTasks.isEmpty();
final boolean count= !fAddRequested; final boolean countRequest= !fCountedUnknownVersion;
fAddRequested= true; fCountedUnknownVersion= true;
return count; return countRequest;
} }
return addVersionTask(ifile).requestUpdate(); return addVersionTask(ifile);
} }
private FileVersionTask addVersionTask(IIndexFragmentFile ifile) { /**
* Return whether the task needs to be counted.
*/
private boolean addVersionTask(IIndexFragmentFile ifile) {
FileVersionTask fc= findVersion(ifile); FileVersionTask fc= findVersion(ifile);
if (fc != null) if (fc != null)
return fc; return false;
fc= new FileVersionTask(ifile, fAddRequested); fc= new FileVersionTask(ifile);
fAddRequested= false; boolean countRequest= true;
if (fCountedUnknownVersion) {
fCountedUnknownVersion= false;
countRequest= false;
}
switch (fVersionTasks.size()) { switch (fVersionTasks.size()) {
case 0: case 0:
@ -145,7 +153,15 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
fVersionTasks.add(fc); fVersionTasks.add(fc);
break; break;
} }
return fc; return countRequest;
}
void removeVersionTask(Iterator<FileVersionTask> it) {
if (fVersionTasks.size() == 1) {
fVersionTasks= Collections.emptyList();
} else {
it.remove();
}
} }
private FileVersionTask findVersion(IIndexFile ifile) { private FileVersionTask findVersion(IIndexFile ifile) {
@ -165,44 +181,35 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
boolean isCompleted() { boolean isCompleted() {
if (fVersionTasks.isEmpty())
return !fAddRequested;
for (FileVersionTask fc : fVersionTasks) { for (FileVersionTask fc : fVersionTasks) {
if (fc.fUpdateRequested) if (fc.fOutdated)
return false; return false;
} }
return true; if (fKind == UpdateKind.OTHER_HEADER)
return true;
return fStoredAVersion;
} }
public boolean needsVersion() { public boolean needsVersion() {
if (fKind == UpdateKind.OTHER_HEADER) if (fKind == UpdateKind.OTHER_HEADER)
return false; return false;
for (FileVersionTask fc : fVersionTasks) {
if (fc.fUpdateRequested) return !fStoredAVersion;
return true;
}
return fVersionTasks.isEmpty() && fAddRequested;
} }
} }
public static class FileVersionTask { public static class FileVersionTask {
private final IIndexFragmentFile fIndexFile; private final IIndexFragmentFile fIndexFile;
private boolean fUpdateRequested; private boolean fOutdated;
FileVersionTask(IIndexFragmentFile file, boolean requestUpdate) { FileVersionTask(IIndexFragmentFile file) {
fIndexFile= file; fIndexFile= file;
fUpdateRequested= requestUpdate; fOutdated= true;
} }
boolean requestUpdate() {
boolean result= !fUpdateRequested;
fUpdateRequested= true;
return result;
}
void setUpdated() { void setUpdated() {
fUpdateRequested= false; fOutdated= false;
} }
} }
@ -428,8 +435,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
} }
private final void reportFile(boolean requested, UpdateKind kind) { private final void reportFile(boolean wasCounted, UpdateKind kind) {
if (requested) { if (wasCounted) {
if (kind == UpdateKind.REQUIRED_SOURCE) { if (kind == UpdateKind.REQUIRED_SOURCE) {
updateFileCount(1, 0, 0); updateFileCount(1, 0, 0);
} else { } else {
@ -704,41 +711,30 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
@Override @Override
protected void reportFileWrittenToIndex(FileInAST file, IIndexFragmentFile ifile, protected void reportFileWrittenToIndex(FileInAST file, IIndexFragmentFile ifile) throws CoreException {
IIndexFragmentFile replaces) throws CoreException {
final FileContentKey fck = file.fFileContentKey; final FileContentKey fck = file.fFileContentKey;
boolean wasRequested= false; boolean wasCounted= false;
UpdateKind kind= UpdateKind.OTHER_HEADER; UpdateKind kind= UpdateKind.OTHER_HEADER;
LinkageTask map = findRequestMap(fck.getLinkageID()); LinkageTask map = findRequestMap(fck.getLinkageID());
if (map != null) { if (map != null) {
LocationTask locTask = map.find(fck.getLocation()); LocationTask locTask = map.find(fck.getLocation());
if (locTask != null) { if (locTask != null) {
kind= locTask.fKind; kind= locTask.fKind;
FileVersionTask v = locTask.addVersionTask(ifile); FileVersionTask v = locTask.findVersion(ifile);
wasRequested= v.fUpdateRequested; if (v != null) {
v.setUpdated(); wasCounted= v.fOutdated;
v.setUpdated();
} else {
// We have added a version, the request is fulfilled.
wasCounted= locTask.fCountedUnknownVersion;
locTask.fCountedUnknownVersion= false;
}
locTask.fStoredAVersion= true;
} }
} }
fIndexContentCache.remove(ifile); fIndexContentCache.remove(ifile);
fIndexFilesCache.remove(file.fFileContentKey.getLocation()); fIndexFilesCache.remove(file.fFileContentKey.getLocation());
reportFile(wasRequested, kind); reportFile(wasCounted, kind);
if (replaces != null) {
if (map != null) {
LocationTask locTask = map.find(fck.getLocation());
if (locTask != null) {
kind= locTask.fKind;
FileVersionTask v = locTask.findVersion(ifile);
if (v != null) {
if (v.fUpdateRequested) {
reportFile(true, locTask.fKind);
v.setUpdated();
}
}
}
}
fIndexContentCache.remove(replaces);
}
} }
private void removeFilesInIndex(List<Object> filesToRemove, List<IIndexFragmentFile> indexFilesToRemove, private void removeFilesInIndex(List<Object> filesToRemove, List<IIndexFragmentFile> indexFilesToRemove,
@ -801,12 +797,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (locTask == null || locTask.isCompleted()) { if (locTask == null || locTask.isCompleted()) {
it.remove(); it.remove();
} else { } else {
// Additional version tasks may be added while parsing a file, for (FileVersionTask versionTask : locTask.fVersionTasks) {
// use an integer to iterate over the list. if (versionTask.fOutdated) {
final List<FileVersionTask> versionTasks = locTask.fVersionTasks;
for (int i= 0; i < versionTasks.size(); i++) {
FileVersionTask versionTask = versionTasks.get(i);
if (versionTask.fUpdateRequested) {
if (monitor.isCanceled() || hasUrgentTasks()) if (monitor.isCanceled() || hasUrgentTasks())
return; return;
parseVersionInContext(linkageID, map, ifl, versionTask, locTask.fTu, parseVersionInContext(linkageID, map, ifl, versionTask, locTask.fTu,
@ -845,10 +837,15 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (!locTask.needsVersion()) { if (!locTask.needsVersion()) {
if (monitor.isCanceled() || hasUrgentTasks()) if (monitor.isCanceled() || hasUrgentTasks())
return; return;
for (FileVersionTask v : locTask.fVersionTasks) { Iterator<FileVersionTask> it= locTask.fVersionTasks.iterator();
if (v.fUpdateRequested) { while (it.hasNext()) {
FileVersionTask v = it.next();
if (v.fOutdated) {
fIndex.clearFile(v.fIndexFile); fIndex.clearFile(v.fIndexFile);
reportFile(true, locTask.fKind); reportFile(true, locTask.fKind);
locTask.removeVersionTask(it);
fIndexContentCache.remove(v.fIndexFile);
fIndexFilesCache.remove(ifl);
} }
} }
} }
@ -877,12 +874,12 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
LocationTask ctxTask= map.find(ctxIfl); LocationTask ctxTask= map.find(ctxIfl);
if (ctxTask != null) { if (ctxTask != null) {
FileVersionTask ctxVersionTask = ctxTask.findVersion(nextCtx); FileVersionTask ctxVersionTask = ctxTask.findVersion(nextCtx);
if (ctxVersionTask != null && ctxVersionTask.fUpdateRequested) { if (ctxVersionTask != null && ctxVersionTask.fOutdated) {
// Handle the context first. // Handle the context first.
parseVersionInContext(linkageID, map, ctxIfl, ctxVersionTask, ctxTask.fTu, parseVersionInContext(linkageID, map, ctxIfl, ctxVersionTask, ctxTask.fTu,
safeGuard, monitor); safeGuard, monitor);
if (ctxVersionTask.fUpdateRequested // This is unexpected. if (ctxVersionTask.fOutdated // This is unexpected.
|| !versionTask.fUpdateRequested) // Our file was parsed. || !versionTask.fOutdated) // Our file was parsed.
return; return;
// The file is no longer a context, look for a different one. // The file is no longer a context, look for a different one.
@ -1115,7 +1112,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (locTask != null) { if (locTask != null) {
FileVersionTask task = locTask.findVersion(sigMacros); FileVersionTask task = locTask.findVersion(sigMacros);
if (task != null) { if (task != null) {
return task.fUpdateRequested; return task.fOutdated;
} }
} }
} }
@ -1139,12 +1136,12 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
for (FileInAST fileKey : fileKeys) { for (FileInAST fileKey : fileKeys) {
LocationTask locTask = map.find(fileKey.fFileContentKey.getLocation()); LocationTask locTask = map.find(fileKey.fFileContentKey.getLocation());
if (locTask != null) { if (locTask != null) {
if (locTask.fAddRequested) { if (locTask.fCountedUnknownVersion) {
locTask.fAddRequested= false; locTask.fCountedUnknownVersion= false;
reportFile(true, locTask.fKind); reportFile(true, locTask.fKind);
} else { } else {
for (FileVersionTask fc : locTask.fVersionTasks) { for (FileVersionTask fc : locTask.fVersionTasks) {
if (fc.fUpdateRequested) { if (fc.fOutdated) {
reportFile(true, locTask.fKind); reportFile(true, locTask.fKind);
fc.setUpdated(); fc.setUpdated();
} }
@ -1162,7 +1159,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
LocationTask request= map.find(ifl); LocationTask request= map.find(ifl);
if (request != null) { if (request != null) {
FileVersionTask task= request.findVersion(file); FileVersionTask task= request.findVersion(file);
if (task != null && task.fUpdateRequested) if (task != null && task.fOutdated)
return null; return null;
} }
} }
@ -1182,7 +1179,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
for (FileVersionTask fileVersion : request.fVersionTasks) { for (FileVersionTask fileVersion : request.fVersionTasks) {
final IIndexFile indexFile = fileVersion.fIndexFile; final IIndexFile indexFile = fileVersion.fIndexFile;
if (md.satisfies(indexFile.getSignificantMacros())) { if (md.satisfies(indexFile.getSignificantMacros())) {
if (fileVersion.fUpdateRequested) if (fileVersion.fOutdated)
return null; return null;
return indexFile; return indexFile;
} }

View file

@ -247,9 +247,9 @@ abstract public class PDOMWriter {
IIndexFragmentFile ifile= storeFileInIndex(data, fileInAST, linkageID, lock); IIndexFragmentFile ifile= storeFileInIndex(data, fileInAST, linkageID, lock);
if (fileInAST.fIncludeStatement == null && replaceFile != null && !replaceFile.equals(ifile)) { if (fileInAST.fIncludeStatement == null && replaceFile != null && !replaceFile.equals(ifile)) {
data.fIndex.transferIncluders(replaceFile, ifile); data.fIndex.transferIncluders(replaceFile, ifile);
reportFileWrittenToIndex(fileInAST, ifile, replaceFile); reportFileWrittenToIndex(fileInAST, ifile);
} else { } else {
reportFileWrittenToIndex(fileInAST, ifile, null); reportFileWrittenToIndex(fileInAST, ifile);
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
th= e; th= e;
@ -556,8 +556,7 @@ abstract public class PDOMWriter {
/** /**
* Informs the subclass that a file has been stored in the index. * Informs the subclass that a file has been stored in the index.
*/ */
protected abstract void reportFileWrittenToIndex(FileInAST file, IIndexFragmentFile iFile, protected abstract void reportFileWrittenToIndex(FileInAST file, IIndexFragmentFile iFile) throws CoreException;
IIndexFragmentFile replacesFile) throws CoreException;
private String getLocationInfo(String filename, int lineNumber) { private String getLocationInfo(String filename, int lineNumber) {
return " at " + filename + "(" + lineNumber + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ return " at " + filename + "(" + lineNumber + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$