1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 19:35:36 +02:00

Better delta handling for Full indexer.

This commit is contained in:
Doug Schaefer 2006-04-24 17:54:17 +00:00
parent 363013fb48
commit 7f420507cd
2 changed files with 103 additions and 37 deletions

View file

@ -178,6 +178,10 @@ public class PDOM extends PlatformObject
return record != 0 ? new PDOMFile(this, record) : null; return record != 0 ? new PDOMFile(this, record) : null;
} }
public PDOMFile getFile(IPath path) throws CoreException {
return getFile(path.toOSString());
}
public PDOMFile addFile(String filename) throws CoreException { public PDOMFile addFile(String filename) throws CoreException {
PDOMFile file = getFile(filename); PDOMFile file = getFile(filename);
if (file == null) { if (file == null) {

View file

@ -11,8 +11,10 @@
package org.eclipse.cdt.internal.core.pdom.indexer.full; package org.eclipse.cdt.internal.core.pdom.indexer.full;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
@ -28,6 +30,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
@ -43,7 +46,9 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob {
private final ICElementDelta delta; private final ICElementDelta delta;
// Map of filename, TU of files that need to be parsed. // Map of filename, TU of files that need to be parsed.
private Map todo = new HashMap(); private Map changed = new HashMap();
private List added = new ArrayList();
private List removed = new ArrayList();
public PDOMFullHandleDelta(PDOM pdom, ICElementDelta delta) { public PDOMFullHandleDelta(PDOM pdom, ICElementDelta delta) {
super(pdom); super(pdom);
@ -56,26 +61,46 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob {
processDelta(delta); processDelta(delta);
if (!todo.isEmpty()) { int count = changed.size() + added.size() + removed.size();
monitor.beginTask("Indexing", todo.size());
Iterator i = todo.values().iterator(); if (count > 0) {
monitor.beginTask("Indexing", count);
Iterator i = changed.values().iterator();
while (i.hasNext()) {
ITranslationUnit tu = (ITranslationUnit)i.next();
monitor.subTask(tu.getElementName());
changeTU(tu);
monitor.worked(1);
}
i = added.iterator();
while (i.hasNext()) { while (i.hasNext()) {
ITranslationUnit tu = (ITranslationUnit)i.next(); ITranslationUnit tu = (ITranslationUnit)i.next();
monitor.subTask(tu.getElementName()); monitor.subTask(tu.getElementName());
addTU(tu); addTU(tu);
monitor.worked(1); monitor.worked(1);
} }
i = removed.iterator();
while (i.hasNext()) {
ITranslationUnit tu = (ITranslationUnit)i.next();
monitor.subTask(tu.getElementName());
removeTU(tu);
monitor.worked(1);
} }
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
+ "/debug/pdomtimings"); //$NON-NLS-1$ + "/debug/pdomtimings"); //$NON-NLS-1$
if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$ if (showTimings != null && showTimings.equalsIgnoreCase("true")) //$NON-NLS-1$
System.out.println("PDOM Full Delta Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$ System.out.println("PDOM Full Delta Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
}
return Status.OK_STATUS; return Status.OK_STATUS;
} catch (CoreException e) { } catch (CoreException e) {
return e.getStatus(); return e.getStatus();
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
} }
} }
@ -89,19 +114,31 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob {
} }
} }
if ((flags & ICElementDelta.F_CONTENT) != 0) {
ICElement element = delta.getElement(); ICElement element = delta.getElement();
switch (element.getElementType()) { switch (element.getElementType()) {
case ICElement.C_UNIT: case ICElement.C_UNIT:
processTranslationUnit((ITranslationUnit)element); ITranslationUnit tu = (ITranslationUnit)element;
switch (delta.getKind()) {
case ICElementDelta.CHANGED:
if ((flags & ICElementDelta.F_CONTENT) != 0)
processTranslationUnit(tu);
break;
case ICElementDelta.ADDED:
if (!tu.isWorkingCopy())
added.add(tu);
break;
case ICElementDelta.REMOVED:
if (!tu.isWorkingCopy())
removed.add(tu);
break; break;
} }
break;
} }
} }
protected void processTranslationUnit(ITranslationUnit tu) throws CoreException { protected void processTranslationUnit(ITranslationUnit tu) throws CoreException {
String filename = tu.getUnderlyingResource().getLocation().toOSString(); IPath path = tu.getUnderlyingResource().getLocation();
PDOMFile pdomFile = pdom.getFile(filename); PDOMFile pdomFile = pdom.getFile(path);
boolean found = false; boolean found = false;
if (pdomFile != null) { if (pdomFile != null) {
// Look for all source units in the included list, // Look for all source units in the included list,
@ -112,12 +149,12 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob {
for (int i = 0; i < includedBy.length; ++i) { for (int i = 0; i < includedBy.length; ++i) {
String incfilename = includedBy[i].getFileName(); String incfilename = includedBy[i].getFileName();
if (CoreModel.isValidSourceUnitName(project, incfilename)) { if (CoreModel.isValidSourceUnitName(project, incfilename)) {
if (todo.get(incfilename) == null) { if (changed.get(incfilename) == null) {
IFile[] rfiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(incfilename)); IFile[] rfiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(incfilename));
for (int j = 0; j < rfiles.length; ++j) { for (int j = 0; j < rfiles.length; ++j) {
if (rfiles[j].getProject().equals(project)) { if (rfiles[j].getProject().equals(project)) {
ITranslationUnit inctu = (ITranslationUnit)CoreModel.getDefault().create(rfiles[j]); ITranslationUnit inctu = (ITranslationUnit)CoreModel.getDefault().create(rfiles[j]);
todo.put(incfilename, inctu); changed.put(incfilename, inctu);
found = true; found = true;
} }
} }
@ -127,17 +164,19 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob {
} }
} }
if (!found) if (!found)
todo.put(filename, tu); changed.put(path.toOSString(), tu);
} }
protected void addTU(ITranslationUnit tu) throws CoreException { protected void changeTU(ITranslationUnit tu) throws CoreException, InterruptedException {
IASTTranslationUnit ast = parse(tu); IASTTranslationUnit ast = parse(tu);
if (ast == null)
return;
pdom.acquireWriteLock();
try {
// Remove the old symbols in the tu and all the headers // Remove the old symbols in the tu and all the headers
String filename = ((IFile)tu.getResource()).getLocation().toOSString(); removeTU(tu);
PDOMFile file = pdom.getFile(filename);
if (file != null)
file.clear();
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives(); IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
for (int i = 0; i < includes.length; ++i) { for (int i = 0; i < includes.length; ++i) {
@ -149,6 +188,29 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob {
// Add the new symbols // Add the new symbols
pdom.addSymbols(tu.getLanguage(), ast); pdom.addSymbols(tu.getLanguage(), ast);
} finally {
pdom.releaseWriteLock();
}
}
protected void addTU(ITranslationUnit tu) throws CoreException, InterruptedException {
IASTTranslationUnit ast = parse(tu);
if (ast == null)
return;
pdom.acquireWriteLock();
try {
pdom.addSymbols(tu.getLanguage(), ast);
} finally {
pdom.releaseWriteLock();
}
}
protected void removeTU(ITranslationUnit tu) throws CoreException, InterruptedException {
IPath path = ((IFile)tu.getResource()).getLocation();
PDOMFile file = pdom.getFile(path);
if (file != null)
file.clear();
} }
} }