diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java index bb6175640ce..dcaf3c8f0b6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java @@ -151,6 +151,8 @@ public class PDOMFile { public PDOMInclude addIncludeTo(PDOMFile file) throws CoreException { PDOMInclude include = new PDOMInclude(pdom); + include.setIncludedBy(this); + include.setIncludes(file); PDOMInclude firstInclude = getFirstInclude(); if (firstInclude != null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java index d4a01af69a1..a4c5d305145 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java @@ -67,7 +67,8 @@ public class PDOMInclude { } public void setIncludes(PDOMFile includes) throws CoreException { - pdom.getDB().putInt(record + INCLUDES, includes.getRecord()); + int rec = includes != null ? includes.getRecord() : 0; + pdom.getDB().putInt(record + INCLUDES, rec); } public PDOMFile getIncludedBy() throws CoreException { @@ -86,7 +87,8 @@ public class PDOMInclude { } public void setNextInIncludes(PDOMInclude include) throws CoreException { - pdom.getDB().putInt(record + INCLUDES_NEXT, include.getRecord()); + int rec = include != null ? include.getRecord() : 0; + pdom.getDB().putInt(record + INCLUDES_NEXT, rec); } public PDOMInclude getNextInIncludedBy() throws CoreException { @@ -95,7 +97,8 @@ public class PDOMInclude { } public void setNextInIncludedBy(PDOMInclude include) throws CoreException { - pdom.getDB().putInt(record + INCLUDED_BY_NEXT, include.getRecord()); + int rec = include != null ? include.getRecord() : 0; + pdom.getDB().putInt(record + INCLUDED_BY_NEXT, rec); } public PDOMInclude getPrevInIncludedBy() throws CoreException { @@ -104,7 +107,8 @@ public class PDOMInclude { } public void setPrevInIncludedBy(PDOMInclude include) throws CoreException { - pdom.getDB().putInt(record + INCLUDED_BY_PREV, include.getRecord()); + int rec = include != null ? include.getRecord() : 0; + pdom.getDB().putInt(record + INCLUDED_BY_PREV, rec); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java index 6e9cf89df3e..048373a8a52 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullHandleDelta.java @@ -11,10 +11,27 @@ package org.eclipse.cdt.internal.core.pdom.indexer.full; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElementDelta; +import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; /** @@ -25,19 +42,113 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob { private final ICElementDelta delta; + // Map of filename, TU of files that need to be parsed. + private Map todo = new HashMap(); + public PDOMFullHandleDelta(PDOM pdom, ICElementDelta delta) { super(pdom); this.delta = delta; } protected IStatus run(IProgressMonitor monitor) { -// try { + try { long start = System.currentTimeMillis(); + + processDelta(delta); + + if (!todo.isEmpty()) { + monitor.beginTask("Indexing", todo.size()); + + Iterator i = todo.values().iterator(); + while (i.hasNext()) { + ITranslationUnit tu = (ITranslationUnit)i.next(); + monitor.subTask(tu.getElementName()); + addTU(tu); + monitor.worked(1); + } + } + + String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID + + "/debug/pdomtimings"); //$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$ return Status.OK_STATUS; -// } catch (CoreException e) { -// return e.getStatus(); -// } + } catch (CoreException e) { + return e.getStatus(); + } } + protected void processDelta(ICElementDelta delta) throws CoreException { + int flags = delta.getFlags(); + + if ((flags & ICElementDelta.F_CHILDREN) != 0) { + ICElementDelta[] children = delta.getAffectedChildren(); + for (int i = 0; i < children.length; ++i) { + processDelta(children[i]); + } + } + + if ((flags & ICElementDelta.F_CONTENT) != 0) { + ICElement element = delta.getElement(); + switch (element.getElementType()) { + case ICElement.C_UNIT: + processTranslationUnit((ITranslationUnit)element); + break; + } + } + } + + protected void processTranslationUnit(ITranslationUnit tu) throws CoreException { + String filename = tu.getUnderlyingResource().getLocation().toOSString(); + PDOMFile pdomFile = pdom.getFile(filename); + boolean found = false; + if (pdomFile != null) { + // Look for all source units in the included list, + // If none, then add the header + PDOMFile[] includedBy = pdomFile.getAllIncludedBy(); + if (includedBy.length > 0) { + IProject project = tu.getCProject().getProject(); + for (int i = 0; i < includedBy.length; ++i) { + String incfilename = includedBy[i].getFileName(); + if (CoreModel.isValidSourceUnitName(project, incfilename)) { + if (todo.get(incfilename) == null) { + IFile[] rfiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(incfilename)); + for (int j = 0; j < rfiles.length; ++j) { + if (rfiles[j].getProject().equals(project)) { + ITranslationUnit inctu = (ITranslationUnit)CoreModel.getDefault().create(rfiles[j]); + todo.put(incfilename, inctu); + found = true; + } + } + } + } + } + } + } + if (!found) + todo.put(filename, tu); + } + + protected void addTU(ITranslationUnit tu) throws CoreException { + IASTTranslationUnit ast = parse(tu); + + // Remove the old symbols in the tu and all the headers + String filename = ((IFile)tu.getResource()).getLocation().toOSString(); + PDOMFile file = pdom.getFile(filename); + if (file != null) + file.clear(); + + IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives(); + for (int i = 0; i < includes.length; ++i) { + String incname = includes[i].getFileLocation().getFileName(); + PDOMFile incfile = pdom.getFile(incname); + if (incfile != null) + incfile.clear(); + } + + // Add the new symbols + pdom.addSymbols(tu.getLanguage(), ast); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java index a282e0849ac..191b091cba3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexer.java @@ -29,8 +29,7 @@ public class PDOMFullIndexer implements IPDOMIndexer { private IPDOM pdom; public void handleDelta(ICElementDelta delta) { - // TODO Auto-generated method stub - + new PDOMFullHandleDelta((PDOM)pdom, delta).schedule(); } public void reindex() throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java index 7b3b7e6d9e5..b0c5d02211f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullIndexerJob.java @@ -33,23 +33,13 @@ public abstract class PDOMFullIndexerJob extends Job { setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule()); } - protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException { + protected IASTTranslationUnit parse(ITranslationUnit tu) throws CoreException { ILanguage language = tu.getLanguage(); if (language == null) - return; + return null; // get the AST in the "Full" way, i.e. don't skip anything. - IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_IF_NO_BUILD_INFO); - - if (ast == null) - return; - - pdom.acquireWriteLock(); - try { - pdom.addSymbols(language, ast); - } finally { - pdom.releaseWriteLock(); - } + return language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_IF_NO_BUILD_INFO); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java index 53981630722..47f3d2153c7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/full/PDOMFullReindex.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.pdom.indexer.full; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElementVisitor; import org.eclipse.cdt.core.model.ITranslationUnit; @@ -121,4 +122,17 @@ public class PDOMFullReindex extends PDOMFullIndexerJob { } } + protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException { + IASTTranslationUnit ast = parse(tu); + if (ast == null) + return; + + pdom.acquireWriteLock(); + try { + pdom.addSymbols(tu.getLanguage(), ast); + } finally { + pdom.releaseWriteLock(); + } + } + }