diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java index cc18ec0bcf8..a1a373ff377 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/BaseScanner2Test.java @@ -215,7 +215,7 @@ public class BaseScanner2Test extends TestCase { Object expObject = scanner.getRealDefinitions().get(name.toCharArray()); assertNotNull(expObject); assertTrue(expObject instanceof ObjectStyleMacro); - assertCharArrayEquals(value.toCharArray(), ((ObjectStyleMacro)expObject).expansion); + assertCharArrayEquals(value.toCharArray(), ((ObjectStyleMacro)expObject).getExpansion()); } public void validateDefinition(String name, int value) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java index 09e7e7825c0..9f5525dea6e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java @@ -2113,18 +2113,18 @@ public class Scanner2Test extends BaseScanner2Test assertTrue(new String(debug.arglist[0]).equals("__VA_ARGS__")); //$NON-NLS-1$ assertTrue(debug.hasVarArgs()); assertFalse(debug.hasGCCVarArgs()); - assertTrue(new String(debug.expansion).equals("fprintf(stderr, __VA_ARGS__)") ); //$NON-NLS-1$ + assertTrue(new String(debug.getExpansion()).equals("fprintf(stderr, __VA_ARGS__)") ); //$NON-NLS-1$ FunctionStyleMacro showlist = (FunctionStyleMacro)defs.get("showlist"); //$NON-NLS-1$ assertTrue(new String(showlist.arglist[0]).equals("__VA_ARGS__")); //$NON-NLS-1$ assertTrue(showlist.hasVarArgs()); assertFalse(showlist.hasGCCVarArgs()); - assertTrue(new String(showlist.expansion).equals("puts(#__VA_ARGS__)")); //$NON-NLS-1$ + assertTrue(new String(showlist.getExpansion()).equals("puts(#__VA_ARGS__)")); //$NON-NLS-1$ FunctionStyleMacro report = (FunctionStyleMacro)defs.get("report"); //$NON-NLS-1$ assertTrue(new String(report.arglist[0]).equals("test")); //$NON-NLS-1$ assertTrue(new String(report.arglist[1]).equals("__VA_ARGS__")); //$NON-NLS-1$ assertTrue(report.hasVarArgs()); assertFalse(report.hasGCCVarArgs()); - assertTrue(new String(report.expansion).equals("((test)?puts(#test): printf(__VA_ARGS__))")); //$NON-NLS-1$ + assertTrue(new String(report.getExpansion()).equals("((test)?puts(#test): printf(__VA_ARGS__))")); //$NON-NLS-1$ validate39688Common(writer, callback); } @@ -2155,18 +2155,18 @@ public class Scanner2Test extends BaseScanner2Test assertTrue(new String(debug.arglist[0]).equals("vars")); //$NON-NLS-1$ assertFalse(debug.hasVarArgs()); assertTrue(debug.hasGCCVarArgs()); - assertTrue(new String(debug.expansion).equals("fprintf(stderr, vars)") ); //$NON-NLS-1$ + assertTrue(new String(debug.getExpansion()).equals("fprintf(stderr, vars)") ); //$NON-NLS-1$ FunctionStyleMacro showlist = (FunctionStyleMacro)defs.get("showlist"); //$NON-NLS-1$ assertTrue(new String(showlist.arglist[0]).equals("vars")); //$NON-NLS-1$ assertFalse(showlist.hasVarArgs()); assertTrue(showlist.hasGCCVarArgs()); - assertTrue(new String(showlist.expansion).equals("puts(#vars)")); //$NON-NLS-1$ + assertTrue(new String(showlist.getExpansion()).equals("puts(#vars)")); //$NON-NLS-1$ FunctionStyleMacro report = (FunctionStyleMacro)defs.get("report"); //$NON-NLS-1$ assertTrue(new String(report.arglist[0]).equals("test")); //$NON-NLS-1$ assertTrue(new String(report.arglist[1]).equals("vars")); //$NON-NLS-1$ assertFalse(report.hasVarArgs()); assertTrue(report.hasGCCVarArgs()); - assertTrue(new String(report.expansion).equals("((test)?puts(#test): printf(vars))")); //$NON-NLS-1$ + assertTrue(new String(report.getExpansion()).equals("((test)?puts(#test): printf(vars))")); //$NON-NLS-1$ validate39688Common(writer, callback); } diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/AllTypesCache.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/AllTypesCache.java index 7f52a6c8869..40942ef5807 100644 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/AllTypesCache.java +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/AllTypesCache.java @@ -21,13 +21,11 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage; import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage; -import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError; import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCStructure; import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPClassType; import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPNamespace; @@ -52,12 +50,10 @@ public class AllTypesCache { private abstract static class TypesCollector implements IPDOMVisitor { private final int[] kinds; protected final List types; - protected final ICProject project; - protected TypesCollector(int[] kinds, List types, ICProject project) { + protected TypesCollector(int[] kinds, List types) { this.kinds = kinds; this.types = types; - this.project = project; } protected abstract void visitKind(IPDOMNode node, int kind); @@ -74,8 +70,8 @@ public class AllTypesCache { } private static class CTypesCollector extends TypesCollector { - public CTypesCollector(int[] kinds, List types, ICProject project) { - super(kinds, types, project); + public CTypesCollector(int[] kinds, List types) { + super(kinds, types); } protected void visitKind(IPDOMNode node, int kind) { @@ -86,7 +82,7 @@ public class AllTypesCache { return; case ICElement.C_STRUCT: if (node instanceof PDOMCStructure) - types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project)); + types.add(new PDOMTypeInfo((PDOMBinding)node, kind)); return; case ICElement.C_UNION: return; @@ -99,8 +95,8 @@ public class AllTypesCache { } private static class CPPTypesCollector extends TypesCollector { - public CPPTypesCollector(int[] kinds, List types, ICProject project) { - super(kinds, types, project); + public CPPTypesCollector(int[] kinds, List types) { + super(kinds, types); } protected void visitKind(IPDOMNode node, int kind) { @@ -108,22 +104,22 @@ public class AllTypesCache { switch (kind) { case ICElement.C_NAMESPACE: if (node instanceof PDOMCPPNamespace || node instanceof PDOMCPPNamespaceAlias) - types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project)); + types.add(new PDOMTypeInfo((PDOMBinding)node, kind)); return; case ICElement.C_CLASS: if (node instanceof PDOMCPPClassType && ((PDOMCPPClassType)node).getKey() == ICPPClassType.k_class) - types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project)); + types.add(new PDOMTypeInfo((PDOMBinding)node, kind)); return; case ICElement.C_STRUCT: if (node instanceof PDOMCPPClassType && ((PDOMCPPClassType)node).getKey() == ICPPClassType.k_struct) - types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project)); + types.add(new PDOMTypeInfo((PDOMBinding)node, kind)); return; case ICElement.C_UNION: if (node instanceof PDOMCPPClassType && ((PDOMCPPClassType)node).getKey() == ICPPClassType.k_union) - types.add(new PDOMTypeInfo((PDOMBinding)node, kind, project)); + types.add(new PDOMTypeInfo((PDOMBinding)node, kind)); return; case ICElement.C_ENUMERATION: return; @@ -140,17 +136,14 @@ public class AllTypesCache { List types = new ArrayList(); IPDOMManager pdomManager = CCorePlugin.getPDOMManager(); - for (int i = 0; i < projects.length; ++i) { - ICProject project = projects[i]; - CTypesCollector cCollector = new CTypesCollector(kinds, types, project); - CPPTypesCollector cppCollector = new CPPTypesCollector(kinds, types, project); + CTypesCollector cCollector = new CTypesCollector(kinds, types); + CPPTypesCollector cppCollector = new CPPTypesCollector(kinds, types); - PDOM pdom = (PDOM)pdomManager.getPDOM(project); - PDOMLinkage cLinkage = pdom.getLinkage(GCCLanguage.getDefault()); - cLinkage.accept(cCollector); - PDOMLinkage cppLinkage = pdom.getLinkage(GPPLanguage.getDefault()); - cppLinkage.accept(cppCollector); - } + PDOM pdom = (PDOM)pdomManager.getPDOM(); + PDOMLinkage cLinkage = pdom.getLinkage(GCCLanguage.getDefault()); + cLinkage.accept(cCollector); + PDOMLinkage cppLinkage = pdom.getLinkage(GPPLanguage.getDefault()); + cppLinkage.accept(cppCollector); return (ITypeInfo[])types.toArray(new ITypeInfo[types.size()]); } @@ -160,8 +153,20 @@ public class AllTypesCache { */ public static ITypeInfo[] getAllTypes() { try { - ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects(); - return getTypes(projects, ITypeInfo.KNOWN_TYPES); + List types = new ArrayList(); + IPDOMManager pdomManager = CCorePlugin.getPDOMManager(); + + int[] kinds = ITypeInfo.KNOWN_TYPES; + CTypesCollector cCollector = new CTypesCollector(kinds, types); + CPPTypesCollector cppCollector = new CPPTypesCollector(kinds, types); + + PDOM pdom = (PDOM)pdomManager.getPDOM(); + PDOMLinkage cLinkage = pdom.getLinkage(GCCLanguage.getDefault()); + cLinkage.accept(cCollector); + PDOMLinkage cppLinkage = pdom.getLinkage(GPPLanguage.getDefault()); + cppLinkage.accept(cppCollector); + + return (ITypeInfo[])types.toArray(new ITypeInfo[types.size()]); } catch (CoreException e) { CCorePlugin.log(e); return new ITypeInfo[0]; diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeInfo.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeInfo.java index 25d34d150f5..14ee82c867d 100644 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeInfo.java +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeInfo.java @@ -27,12 +27,10 @@ public class PDOMTypeInfo implements ITypeInfo { private final PDOMBinding binding; private final int elementType; - private final ICProject project; - public PDOMTypeInfo(PDOMBinding binding, int elementType, ICProject project) { + public PDOMTypeInfo(PDOMBinding binding, int elementType) { this.binding = binding; this.elementType = elementType; - this.project = project; } public void addDerivedReference(ITypeReference location) { @@ -76,7 +74,7 @@ public class PDOMTypeInfo implements ITypeInfo { } public ICProject getEnclosingProject() { - return project; + throw new PDOMNotImplementedError(); } public ITypeInfo getEnclosingType() { @@ -105,7 +103,7 @@ public class PDOMTypeInfo implements ITypeInfo { public ITypeReference getResolvedReference() { try { PDOMName name = binding.getFirstDefinition(); - return name != null ? new PDOMTypeReference(name, project) : null; + return name != null ? new PDOMTypeReference(name) : null; } catch (CoreException e) { CCorePlugin.log(e); return null; diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeReference.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeReference.java index 398aac9d493..f0f70036622 100644 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeReference.java +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/PDOMTypeReference.java @@ -13,7 +13,6 @@ package org.eclipse.cdt.core.browser; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; @@ -30,13 +29,16 @@ import org.eclipse.core.runtime.Path; public class PDOMTypeReference implements ITypeReference { private final PDOMName name; - private final ICProject project; - private final IPath path; + private final IPath path; + private ITranslationUnit tu; - public PDOMTypeReference(PDOMName name, ICProject project) { + public PDOMTypeReference(PDOMName name) { this.name = name; - this.project = project; this.path = new Path(name.getFileLocation().getFileName()); + + ICElement element = CoreModel.getDefault().create(path); + if (element instanceof ITranslationUnit) + tu = (ITranslationUnit)element; } public ICElement[] getCElements() { @@ -60,7 +62,7 @@ public class PDOMTypeReference implements ITypeReference { } public IProject getProject() { - throw new PDOMNotImplementedError(); + return tu != null ? tu.getUnderlyingResource().getProject() : null; } public IPath getRelativeIncludePath(IProject project) { @@ -76,7 +78,7 @@ public class PDOMTypeReference implements ITypeReference { } public ITranslationUnit getTranslationUnit() { - return CoreModel.getDefault().createTranslationUnitFrom(project, path); + return tu; } public IWorkingCopy getWorkingCopy() { diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java index b56477a92a4..24cbc73c47b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.core.model; import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; @@ -251,5 +250,4 @@ public interface ICProject extends IParent, IOpenable, ICElement { */ Object[] getNonCResources() throws CModelException; - IPDOM getIndex(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java index 19de2ee13ec..36e845c12c1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.core.dom.ICodeReaderFactory; import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; /** @@ -67,7 +68,7 @@ public interface ILanguage extends IAdaptable { */ public IASTTranslationUnit getASTTranslationUnit( ITranslationUnit file, - int style); + int style) throws CoreException; /** * Create the AST for the given file with the given style with a given @@ -80,7 +81,7 @@ public interface ILanguage extends IAdaptable { public IASTTranslationUnit getASTTranslationUnit( ITranslationUnit file, ICodeReaderFactory codeReaderFactory, - int style); + int style) throws CoreException; /** * Return the AST Completion Node for the given working copy at the given @@ -90,7 +91,7 @@ public interface ILanguage extends IAdaptable { * @param offset * @return */ - public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset); + public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset) throws CoreException; /** * Gather the list of IASTNames that appear the selection with the given start offset diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java index 67b6988ef5c..2f81831cc6b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java @@ -26,7 +26,6 @@ import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModelUtil; @@ -696,8 +695,4 @@ public class CProject extends Openable implements ICProject { } } - public IPDOM getIndex() { - return CCorePlugin.getPDOMManager().getPDOM(this); - } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOM.java index 347a8fc26ae..313aefd39c4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOM.java @@ -59,9 +59,6 @@ public interface IPDOM extends IAdaptable { public ICodeReaderFactory getCodeReaderFactory(IWorkingCopy root); - public IPDOMIndexer getIndexer(); - public void setIndexer(IPDOMIndexer indexer) throws CoreException; - public void acquireReadLock() throws InterruptedException; public void releaseReadLock(); public void acquireWriteLock() throws InterruptedException; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexer.java index b9cbc50d9ed..fbfbe71e914 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexer.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.core.dom; import org.eclipse.cdt.core.model.ICElementDelta; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.runtime.CoreException; @@ -21,10 +22,11 @@ import org.eclipse.core.runtime.CoreException; */ public interface IPDOMIndexer { - public void setPDOM(IPDOM pdom); + public void setProject(ICProject project); + public ICProject getProject(); - public void handleDelta(ICElementDelta delta); + public void handleDelta(ICElementDelta delta) throws CoreException; - public void reindex() throws CoreException; + public void indexAll() throws CoreException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexerTask.java new file mode 100644 index 00000000000..e0faa680887 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexerTask.java @@ -0,0 +1,22 @@ +/** + * + */ +package org.eclipse.cdt.core.dom; + +import org.eclipse.core.runtime.IProgressMonitor; + + +/** + * @author dschaefer + * + */ +public interface IPDOMIndexerTask { + + /** + * Run the sub job progress to the main job. + * + * @param mainJob + */ + public void run(IProgressMonitor monitor); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMManager.java index 3334a732ae9..61cacec9d36 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMManager.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.core.dom; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; /** @@ -21,9 +22,11 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule; */ public interface IPDOMManager { - // Getting and deleting a PDOM for a project - public IPDOM getPDOM(ICProject project); - public void deletePDOM(ICProject project) throws CoreException; + // Getting the PDOM + public IPDOM getPDOM() throws CoreException; + + // Get the indexer for a given project + public IPDOMIndexer getIndexer(ICProject project); // Getting and setting indexer Ids public String getDefaultIndexerId(); @@ -32,8 +35,16 @@ public interface IPDOMManager { public String getIndexerId(ICProject project) throws CoreException; public void setIndexerId(ICProject project, String indexerId) throws CoreException; + // Enqueue and indexer sub job + public void enqueue(IPDOMIndexerTask subjob); + + // Reindex the workspace + public void reindex(); + // Scheduling rule used by indexers to make sure we don't get // Too much indexing going on. public ISchedulingRule getIndexerSchedulingRule(); + public IProgressMonitor getProgressGroup(); + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java index d25e8159eb1..e1377d176d5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; -import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.parser.ParserLanguage; @@ -190,20 +189,6 @@ public interface IASTTranslationUnit extends IASTNode { */ public ParserLanguage getParserLanguage(); - /** - * Return the Index associated with this translation unit. - * - * @return the Index for this translation unit - */ - public IPDOM getIndex(); - - /** - * Set the Index to be used for this translation unit. - * - * @param index - */ - public void setIndex(IPDOM index); - /** * Returns the language for this translation unit. * @@ -211,4 +196,17 @@ public interface IASTTranslationUnit extends IASTNode { */ public ILanguage getLanguage(); + /** + * Set whether to use the index when resolving bindings in this TU. + * + * @param value + */ + public void useIndex(boolean value); + + /** + * Is the index used to resolve bindings in this TU. + * @return + */ + public boolean useIndex(); + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java index d148b430855..23c1b5f16c1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java @@ -49,6 +49,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.PlatformObject; /** @@ -78,10 +79,10 @@ public class GCCLanguage extends PlatformObject implements ILanguage { return super.getAdapter(adapter); } - public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, int style) { + public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, int style) throws CoreException { ICodeReaderFactory fileCreator; if ((style & (ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_SKIP_ALL_HEADERS)) != 0) { - PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(file.getCProject()).getAdapter(PDOM.class); + PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM().getAdapter(PDOM.class); fileCreator = new PDOMCodeReaderFactory(pdom); } else fileCreator = SavedCodeReaderFactory.getInstance(); @@ -92,7 +93,7 @@ public class GCCLanguage extends PlatformObject implements ILanguage { public IASTTranslationUnit getASTTranslationUnit( ITranslationUnit file, ICodeReaderFactory codeReaderFactory, - int style) { + int style) throws CoreException { IResource resource = file.getResource(); ICProject project = file.getCProject(); IProject rproject = project.getProject(); @@ -110,7 +111,6 @@ public class GCCLanguage extends PlatformObject implements ILanguage { scanInfo = new ScannerInfo(); } - PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project).getAdapter(PDOM.class); CodeReader reader; IFile rfile = (IFile)file.getResource(); String path = rfile != null ? rfile.getLocation().toOSString() : file.getPath().toOSString(); @@ -134,14 +134,11 @@ public class GCCLanguage extends PlatformObject implements ILanguage { // Parse IASTTranslationUnit ast = parser.parse(); - - if ((style & AST_USE_INDEX) != 0) - ast.setIndex(pdom); - + ast.useIndex((style & AST_USE_INDEX) != 0); return ast; } - public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset) { + public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset) throws CoreException { IResource resource = workingCopy.getResource(); ICProject project = workingCopy.getCProject(); IProject rproject = project.getProject(); @@ -157,7 +154,7 @@ public class GCCLanguage extends PlatformObject implements ILanguage { scanInfo = new ScannerInfo(); } - PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project).getAdapter(PDOM.class); + PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM().getAdapter(PDOM.class); ICodeReaderFactory fileCreator = new PDOMCodeReaderFactory(pdom); String path diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java index 27946be0b1b..012616579f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java @@ -49,6 +49,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.PlatformObject; /** @@ -77,10 +78,10 @@ public class GPPLanguage extends PlatformObject implements ILanguage { return super.getAdapter(adapter); } - public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, int style) { + public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, int style) throws CoreException { ICodeReaderFactory fileCreator; if ((style & (ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_SKIP_ALL_HEADERS)) != 0) { - PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(file.getCProject()).getAdapter(PDOM.class); + PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM().getAdapter(PDOM.class); fileCreator = new PDOMCodeReaderFactory(pdom); } else fileCreator = SavedCodeReaderFactory.getInstance(); @@ -91,7 +92,7 @@ public class GPPLanguage extends PlatformObject implements ILanguage { public IASTTranslationUnit getASTTranslationUnit( ITranslationUnit file, ICodeReaderFactory codeReaderFactory, - int style) { + int style) throws CoreException { IResource resource = file.getResource(); ICProject project = file.getCProject(); IProject rproject = project.getProject(); @@ -109,8 +110,6 @@ public class GPPLanguage extends PlatformObject implements ILanguage { scanInfo = new ScannerInfo(); } - PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project).getAdapter(PDOM.class); - CodeReader reader; IFile rfile = (IFile)file.getResource(); String path = rfile != null ? rfile.getLocation().toOSString() : file.getPath().toOSString(); @@ -134,14 +133,11 @@ public class GPPLanguage extends PlatformObject implements ILanguage { // Parse IASTTranslationUnit ast = parser.parse(); - - if ((style & AST_USE_INDEX) != 0) - ast.setIndex(pdom); - + ast.useIndex((style & AST_USE_INDEX) != 0); return ast; } - public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset) { + public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset) throws CoreException { IResource resource = workingCopy.getResource(); ICProject project = workingCopy.getCProject(); IProject rproject = project.getProject(); @@ -157,7 +153,7 @@ public class GPPLanguage extends PlatformObject implements ILanguage { scanInfo = new ScannerInfo(); } - PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(project).getAdapter(PDOM.class); + PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM().getAdapter(PDOM.class); ICodeReaderFactory fileCreator = new PDOMCodeReaderFactory(pdom); CodeReader reader = new CodeReader(resource.getLocation().toOSString(), workingCopy.getContents()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacro.java index 4d7fa77f3d9..743506c0914 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacro.java @@ -22,4 +22,5 @@ public interface IMacro { //for function-like macros, the signature includes the parameters public char[] getSignature(); public char[] getName(); + public char[] getExpansion(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java index 53967ccf6d1..c54bb2e6170 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java @@ -31,6 +31,7 @@ public interface IScanner { public IMacro addDefinition(char[] key, char[] value); public IMacro addDefinition(char[] name, char[][] params, char[] expansion); + public void addDefinition(IMacro macro); public Map getDefinitions(); public String[] getIncludePaths(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index 3f5ea80846a..b4bfacf8534 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOMResolver; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; @@ -66,7 +65,7 @@ public class CASTTranslationUnit extends CASTNode implements private ILocationResolver resolver; - private IPDOM pdom; + private boolean useIndex; private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0]; @@ -130,9 +129,10 @@ public class CASTTranslationUnit extends CASTNode implements } IASTName[] names = CVisitor.getDeclarations(this, binding); - if (names.length == 0 && pdom != null) { + if (names.length == 0 && useIndex) { try { - binding = ((PDOM)pdom).getLinkage(getLanguage()).adaptBinding(binding); + PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(); + binding = pdom.getLinkage(getLanguage()).adaptBinding(binding); if (binding != null) names = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).getDeclarations(binding); } catch (CoreException e) { @@ -163,9 +163,10 @@ public class CASTTranslationUnit extends CASTNode implements } names = (IASTName[])ArrayUtil.removeNulls(IASTName.class, names); - if (names.length == 0 && pdom != null) { + if (names.length == 0 && useIndex) { try { - binding = ((PDOM)pdom).getLinkage(getLanguage()).adaptBinding(binding); + PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(); + binding = pdom.getLinkage(getLanguage()).adaptBinding(binding); if (binding != null) names = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).getDefinitions(binding); } catch (CoreException e) { @@ -559,12 +560,12 @@ public class CASTTranslationUnit extends CASTNode implements return new GCCLanguage(); } - public IPDOM getIndex() { - return pdom; + public boolean useIndex() { + return useIndex; } - public void setIndex(IPDOM pdom) { - this.pdom = pdom; + public void useIndex(boolean value) { + this.useIndex = value; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 05bd6d8ff80..e73995e3c71 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOMResolver; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; @@ -95,6 +96,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; +import org.eclipse.core.runtime.CoreException; /** * Created on Nov 5, 2004 @@ -1301,11 +1303,15 @@ public class CVisitor { if( blockItem != null) { // We're at the end of our rope, check the PDOM if we can IASTTranslationUnit tu = (IASTTranslationUnit)blockItem; - IPDOM pdom = tu.getIndex(); - binding = null; - if (pdom != null) - binding = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).resolveBinding(name); - + if (tu.useIndex()) { + IPDOM pdom = null; + try { + pdom = CCorePlugin.getPDOMManager().getPDOM(); + binding = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).resolveBinding(name); + } catch (CoreException e) { + } + } + if (binding == null) return externalBinding( (IASTTranslationUnit) blockItem, name ); else diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java index 5ecfd98d2af..1d7d2e2fba2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTConstructorInitializer.java @@ -12,13 +12,15 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer; +import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** * @author jcamelon */ public class CPPASTConstructorInitializer extends CPPASTNode implements - ICPPASTConstructorInitializer { + ICPPASTConstructorInitializer, IASTAmbiguityParent { private IASTExpression exp; @@ -48,4 +50,11 @@ public class CPPASTConstructorInitializer extends CPPASTNode implements return true; } + public void replace(IASTNode child, IASTNode other) { + if (child == exp) { + other.setPropertyInParent(child.getPropertyInParent()); + other.setParent(child.getParent()); + exp = (IASTExpression) other; + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index f0406bad670..7ef7ff509f5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOMResolver; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; @@ -81,7 +80,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements private ILocationResolver resolver; - private IPDOM pdom; + private boolean useIndex; private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0]; @@ -188,10 +187,11 @@ public class CPPASTTranslationUnit extends CPPASTNode implements return resolver.getDeclarations( (IMacroBinding)b ); } IASTName[] names = CPPVisitor.getDeclarations( this, b ); - if (names.length == 0 && pdom != null) { + if (names.length == 0 && useIndex) { try { - b = ((PDOM)pdom).getLinkage(getLanguage()).adaptBinding(b); - if (binding != null) + PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(); + b = pdom.getLinkage(getLanguage()).adaptBinding(b); + if (b != null) names = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).getDeclarations(b); } catch (CoreException e) { CCorePlugin.log(e); @@ -221,9 +221,10 @@ public class CPPASTTranslationUnit extends CPPASTNode implements } names = (IASTName[])ArrayUtil.removeNulls(IASTName.class, names); - if (names.length == 0 && pdom != null) { + if (names.length == 0 && useIndex) { try { - binding = ((PDOM)pdom).getLinkage(getLanguage()).adaptBinding(binding); + PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(); + binding = pdom.getLinkage(getLanguage()).adaptBinding(binding); if (binding != null) names = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).getDefinitions(binding); } catch (CoreException e) { @@ -610,12 +611,12 @@ public class CPPASTTranslationUnit extends CPPASTNode implements return new GPPLanguage(); } - public IPDOM getIndex() { - return pdom; + public boolean useIndex() { + return useIndex; } - public void setIndex(IPDOM pdom) { - this.pdom = pdom; + public void useIndex(boolean value) { + this.useIndex = value; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index 8e125b76189..a2c20725925 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -13,6 +13,7 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOMResolver; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; @@ -126,6 +127,7 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil.ArrayWrapper; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; +import org.eclipse.core.runtime.CoreException; /** * @author aniefer @@ -747,10 +749,15 @@ public class CPPSemantics { } if( binding == null ){ // Let's try the pdom - IPDOM pdom = name.getTranslationUnit().getIndex(); - if (pdom != null) - binding = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).resolveBinding(name); - + if (name.getTranslationUnit().useIndex()) { + IPDOM pdom = null; + try { + pdom = CCorePlugin.getPDOMManager().getPDOM(); + binding = ((IPDOMResolver)pdom.getAdapter(IPDOMResolver.class)).resolveBinding(name); + } catch (CoreException e) { + } + } + // If we're still null... if (binding == null) { if( name instanceof ICPPASTQualifiedName && data.forDefinition() ) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java index d33c0eea289..307b451d910 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java @@ -659,7 +659,7 @@ abstract class BaseScanner implements IScanner { handleFunctionStyleMacro((FunctionStyleMacro) expObject); } else if (expObject instanceof ObjectStyleMacro) { ObjectStyleMacro expMacro = (ObjectStyleMacro) expObject; - char[] expText = expMacro.expansion; + char[] expText = expMacro.getExpansion(); if (expText.length > 0) pushContext(expText, expMacro); } else if (expObject instanceof char[]) { @@ -944,7 +944,7 @@ abstract class BaseScanner implements IScanner { break; } - char[] expText = macro.expansion; + char[] expText = macro.getExpansion(); if (expText.length > 0) pushContext(expText, exp); } @@ -1440,6 +1440,10 @@ abstract class BaseScanner implements IScanner { return macro; } + public void addDefinition(IMacro macro) { + definitions.put(macro.getName(), macro); + } + public int getCount() { return count; } @@ -2086,7 +2090,7 @@ abstract class BaseScanner implements IScanner { expanding = false; } else if (expObject instanceof ObjectStyleMacro) { ObjectStyleMacro expMacro = (ObjectStyleMacro) expObject; - char[] expText = expMacro.expansion; + char[] expText = expMacro.getExpansion(); if (expText.length > 0) pushContext(expText, new MacroData( bufferPos[bufferStackPos] - expMacro.name.length + 1, @@ -2799,7 +2803,7 @@ abstract class BaseScanner implements IScanner { t = handleFunctionStyleMacro( (FunctionStyleMacro) expObject, false); } else if (expObject instanceof ObjectStyleMacro) { - t = ((ObjectStyleMacro) expObject).expansion; + t = ((ObjectStyleMacro) expObject).getExpansion(); } if (t != null) { t = replaceArgumentMacros(t); @@ -4085,10 +4089,10 @@ abstract class BaseScanner implements IScanner { } else { CharArrayObjectMap replacedArgs = new CharArrayObjectMap(argmap .size()); - int size = expandFunctionStyleMacro(macro.expansion, argmap, + int size = expandFunctionStyleMacro(macro.getExpansion(), argmap, replacedArgs, null); result = new char[size]; - expandFunctionStyleMacro(macro.expansion, argmap, replacedArgs, + expandFunctionStyleMacro(macro.getExpansion(), argmap, replacedArgs, result); } if (pushContext) @@ -4152,7 +4156,7 @@ abstract class BaseScanner implements IScanner { popContext(); } else if (expObject instanceof ObjectStyleMacro) { ObjectStyleMacro expMacro = (ObjectStyleMacro) expObject; - expansion = expMacro.expansion; + expansion = expMacro.getExpansion(); } else if (expObject instanceof char[]) { expansion = (char[]) expObject; } else if (expObject instanceof DynamicStyleMacro) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java index e46dd72018c..308786341c5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java @@ -101,18 +101,9 @@ public class DOMScanner extends BaseScanner { } } - public IMacro addDefinition(char[] key, char[] value) { - IMacro macro = super.addDefinition(key, value); - if (locationMap != null) - registerMacro(macro); - return macro; - } - - public IMacro addDefinition(char[] name, char[][] params, char[] expansion) { - IMacro macro = super.addDefinition(name, params, expansion); - if (locationMap != null) - registerMacro(macro); - return macro; + public void addDefinition(IMacro macro) { + super.addDefinition(macro); + registerMacro(macro); } public ILocationResolver getLocationResolver() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicStyleMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicStyleMacro.java index 2b37d460d69..8e74ae2985f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicStyleMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicStyleMacro.java @@ -36,4 +36,7 @@ public abstract class DynamicStyleMacro implements IMacro{ { return name; } + public char[] getExpansion() { + return execute(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index 39910d4117f..f52dd2336d6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode; import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.core.parser.IMacro; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -1125,10 +1126,21 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { this.nameOffset = nameOffset; } + public _MacroDefinition(_CompositeContext parent, int startOffset, + int endOffset, char[] name, int nameOffset, IMacro macro) { + super(parent, startOffset, endOffset); + this.name = name; + this.macro = macro; + this.nameOffset = nameOffset; + } + public final char[] name; - public final char[] expansion; public final int nameOffset; public IASTPreprocessorMacroDefinition astNode; + + // expansions can be in the IMacro if there is one + private char[] expansion; + private IMacro macro; private IMacroBinding bind; @@ -1137,6 +1149,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { } public char[] getExpansion() { + if (expansion == null && macro != null) + expansion = macro.getExpansion(); return expansion; } @@ -1166,6 +1180,12 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { char[] expansion) { super(parent, startOffset, endOffset, name, nameOffset, expansion); } + + public _ObjectMacroDefinition(_CompositeContext parent, + int startOffset, int endOffset, char[] name, int nameOffset, + IMacro macro) { + super(parent, startOffset, endOffset, name, nameOffset, macro); + } } @@ -1187,6 +1207,13 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { this.parms = parameters; } + public _FunctionMacroDefinition(_CompositeContext parent, + int startOffset, int endOffset, char[] name, int nameOffset, + IMacro macro, char[][] parameters) { + super(parent, startOffset, endOffset, name, nameOffset, macro); + this.parms = parameters; + } + public char[][] getParms() { return parms; } @@ -1334,7 +1361,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { name.setParent(r); ((ASTNode) name).setOffsetAndLength(d.nameOffset, d.name.length); r.setName(name); - r.setExpansion(new String(d.expansion)); + r.setExpansion(new String(d.getExpansion())); ((ASTNode) r).setOffsetAndLength(d.context_directive_start, d.context_directive_end - d.context_directive_start); d.astNode = r; @@ -1913,7 +1940,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { int startOffset, int nameOffset, int nameEndOffset, int endOffset) { _ObjectMacroDefinition objectMacroDefinition = new _ObjectMacroDefinition( currentContext, startOffset, endOffset, m.name, nameOffset, - m.expansion); + m.getExpansion()); currentContext.addSubContext(objectMacroDefinition); return objectMacroDefinition; } @@ -1928,7 +1955,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { int startOffset, int nameOffset, int nameEndOffset, int endOffset) { final _FunctionMacroDefinition functionMacroDefinition = new _FunctionMacroDefinition( currentContext, startOffset, endOffset, m.name, nameOffset, - m.expansion, removeNullArguments(m.arglist)); + m.getExpansion(), removeNullArguments(m.arglist)); currentContext.addSubContext(functionMacroDefinition); return functionMacroDefinition; } @@ -2511,19 +2538,19 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { } public IMacroDefinition registerBuiltinObjectStyleMacro(ObjectStyleMacro macro) { - IMacroDefinition result = new _ObjectMacroDefinition( tu, -1, -1, macro.name, -1, macro.expansion ); + IMacroDefinition result = new _ObjectMacroDefinition( tu, -1, -1, macro.name, -1, macro ); tu.addBuiltinMacro( result ); return result; } public IMacroDefinition registerBuiltinFunctionStyleMacro(FunctionStyleMacro macro) { - IMacroDefinition result = new _FunctionMacroDefinition( tu, -1, -1, macro.name, -1, macro.expansion, removeNullArguments( macro.arglist ) ); + IMacroDefinition result = new _FunctionMacroDefinition( tu, -1, -1, macro.name, -1, macro, removeNullArguments( macro.arglist ) ); tu.addBuiltinMacro( result ); return result; } public IMacroDefinition registerBuiltinDynamicFunctionStyleMacro(DynamicFunctionStyleMacro macro) { - IMacroDefinition result = new _MacroDefinition( tu, -1, -1, macro.name, -1, macro.expansion ); + IMacroDefinition result = new _MacroDefinition( tu, -1, -1, macro.name, -1, macro.getExpansion() ); tu.addBuiltinMacro( result ); return result; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ObjectStyleMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ObjectStyleMacro.java index 8a1f8e6e192..bc5c8bb8f45 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ObjectStyleMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ObjectStyleMacro.java @@ -16,10 +16,10 @@ import org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog.IMa /** * @author Doug Schaefer */ -public class ObjectStyleMacro implements IMacro{ +public class ObjectStyleMacro implements IMacro { public char[] name; - public char[] expansion; + protected char[] expansion; public IMacroDefinition attachment; public ObjectStyleMacro(char[] name, char[] expansion) { @@ -38,4 +38,9 @@ public class ObjectStyleMacro implements IMacro{ public String toString() { return new String( name ); } + + public char[] getExpansion() { + return expansion; + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 84af9d685ab..a362e44297d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -21,20 +21,12 @@ import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ICodeReaderFactory; import org.eclipse.cdt.core.dom.IPDOM; -import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.dom.IPDOMResolver; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.IPDOMWriter; -import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; -import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ILanguage; -import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.internal.core.pdom.db.BTree; @@ -47,12 +39,9 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Comparator; import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile.Finder; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.QualifiedName; /** * The PDOM Database. @@ -62,8 +51,7 @@ import org.eclipse.core.runtime.QualifiedName; public class PDOM extends PlatformObject implements IPDOM, IPDOMResolver, IPDOMWriter { - private final ICProject project; - private IPDOMIndexer indexer; + private static final String dbName = "pdom"; //$NON-NLS-1$ private final IPath dbPath; private Database db; @@ -84,29 +72,15 @@ public class PDOM extends PlatformObject private BTree fileIndex; private Map linkageCache = new HashMap(); - private static final QualifiedName dbNameProperty - = new QualifiedName(CCorePlugin.PLUGIN_ID, "dbName"); //$NON-NLS-1$ - - public PDOM(ICProject project, IPDOMIndexer indexer) throws CoreException { - this.project = project; - this.indexer = indexer; - indexer.setPDOM(this); - + public PDOM() throws CoreException { // Load up the database - IProject rproject = project.getProject(); - String dbName = rproject.getPersistentProperty(dbNameProperty); - if (dbName == null) { - dbName = project.getElementName() + "_" - + System.currentTimeMillis() + ".pdom"; - rproject.setPersistentProperty(dbNameProperty, dbName); - } dbPath = CCorePlugin.getDefault().getStateLocation().append(dbName); db = new Database(dbPath.toOSString()); // Check the version and force a rebuild if needed. // TODO Conversion might be a nicer story down the road if (db.getVersion() != VERSION) { - indexer.reindex(); + CCorePlugin.getPDOMManager().reindex(); } else { // populate the linkage cache PDOMLinkage linkage = getFirstLinkage(); @@ -131,24 +105,6 @@ public class PDOM extends PlatformObject return super.getAdapter(adapter); } - public ICProject getProject() { - return project; - } - - public IPDOMIndexer getIndexer() { - return indexer; - } - - public void setIndexer(IPDOMIndexer indexer) throws CoreException { - // Force a reindex if indexer changes - boolean reindex = indexer != null && this.indexer != indexer; - this.indexer = indexer; - indexer.setPDOM(this); - - if (reindex) - indexer.reindex(); - } - public void accept(IPDOMVisitor visitor) throws CoreException { for (PDOMLinkage linkage = getFirstLinkage(); linkage != null; linkage = linkage.getNextLinkage()) linkage.accept(visitor); @@ -210,76 +166,6 @@ public class PDOM extends PlatformObject return file; } - public void addSymbolsXXX(ILanguage language, IASTTranslationUnit ast) throws CoreException { - final PDOMLinkage linkage = getLinkage(language); - if (linkage == null) - return; - - // Add in the includes - IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives(); - for (int i = 0; i < includes.length; ++i) { - IASTPreprocessorIncludeStatement include = includes[i]; - - IASTFileLocation sourceLoc = include.getFileLocation(); - String sourcePath - = sourceLoc != null - ? sourceLoc.getFileName() - : ast.getFilePath(); // command-line includes - - PDOMFile sourceFile = addFile(sourcePath); - String destPath = include.getPath(); - PDOMFile destFile = addFile(destPath); - sourceFile.addIncludeTo(destFile); - } - - // Add in the macros - IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions(); - for (int i = 0; i < macros.length; ++i) { - IASTPreprocessorMacroDefinition macro = macros[i]; - - IASTFileLocation sourceLoc = macro.getFileLocation(); - if (sourceLoc == null) - continue; // skip built-ins and command line macros - - PDOMFile sourceFile = getFile(sourceLoc.getFileName()); - if (sourceFile != null) // not sure why this would be null - sourceFile.addMacro(macro); - } - - // Add in the names - ast.accept(new ASTVisitor() { - { - shouldVisitNames = true; - shouldVisitDeclarations = true; - } - - public int visit(IASTName name) { - try { - IASTFileLocation fileloc = name.getFileLocation(); - if (fileloc != null) { - PDOMFile file = addFile(fileloc.getFileName()); - linkage.addName(name, file); - } - return PROCESS_CONTINUE; - } catch (CoreException e) { - CCorePlugin.log(e); - return PROCESS_ABORT; - } - }; - });; - - // Tell the world - fireChange(); - } - - public void removeSymbols(ITranslationUnit tu) throws CoreException { - String filename = ((IFile)tu.getResource()).getLocation().toOSString(); - PDOMFile file = getFile(filename); - if (file == null) - return; - file.clear(); - } - public void clear() throws CoreException { Database db = getDB(); db.clear(); @@ -397,6 +283,7 @@ public class PDOM extends PlatformObject Collection values = linkageCache.values(); return (PDOMLinkage[])values.toArray(new PDOMLinkage[values.size()]); } + public void insertLinkage(PDOMLinkage linkage) throws CoreException { linkage.setNext(db.getInt(LINKAGES)); db.putInt(LINKAGES, linkage.getRecord()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMCodeReaderFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMCodeReaderFactory.java index a6597539bc3..428fa1dbf83 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMCodeReaderFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMCodeReaderFactory.java @@ -13,8 +13,11 @@ package org.eclipse.cdt.internal.core.pdom; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import org.eclipse.cdt.core.CCorePlugin; @@ -23,13 +26,13 @@ import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.ICodeReaderCache; +import org.eclipse.cdt.core.parser.IMacro; import org.eclipse.cdt.core.parser.IScanner; import org.eclipse.cdt.core.parser.ParserUtil; -import org.eclipse.cdt.internal.core.pdom.db.IString; +import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro; import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile; import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude; import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacro; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacroParameter; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -43,6 +46,10 @@ public class PDOMCodeReaderFactory implements ICodeReaderFactory { private final PDOM pdom; private List workingCopies = new ArrayList(1); + private Map fileCache = new HashMap(); // filename, pdomFile + private Map macroCache = new HashMap();// record, list of IMacros + + private List usedMacros = new ArrayList(); private static final char[] EMPTY_CHARS = new char[0]; @@ -55,6 +62,15 @@ public class PDOMCodeReaderFactory implements ICodeReaderFactory { workingCopies.add(workingCopy); } + public PDOMFile getCachedFile(String filename) throws CoreException { + PDOMFile file = (PDOMFile)fileCache.get(filename); + if (file == null) { + file = pdom.addFile(filename); + fileCache.put(filename, file); + } + return file; + } + public int getUniqueIdentifier() { return 0; } @@ -69,11 +85,11 @@ public class PDOMCodeReaderFactory implements ICodeReaderFactory { } private void fillMacros(PDOMFile file, IScanner scanner, Set visited) throws CoreException { - IString filename = file.getFileName(); - if (visited.contains(filename)) + Integer record = new Integer(file.getRecord()); + if (visited.contains(record)) return; - visited.add(filename); - + visited.add(record); + // Follow the includes PDOMInclude include = file.getFirstInclude(); while (include != null) { @@ -82,24 +98,23 @@ public class PDOMCodeReaderFactory implements ICodeReaderFactory { } // Add in my macros now - PDOMMacro macro = file.getFirstMacro(); - while (macro != null) { - char[] name = macro.getName().getChars(); - char[] expansion = macro.getExpansion().getChars(); - - PDOMMacroParameter param = macro.getFirstParameter(); - if (param != null) { - List paramList = new ArrayList(); - while (param != null) { - paramList.add(param.getName().getChars()); - param = param.getNextParameter(); - } - char[][] params = (char[][])paramList.toArray(new char[paramList.size()][]); - scanner.addDefinition(name, params, expansion); - } else - scanner.addDefinition(name, expansion); - macro = macro.getNextMacro(); + IMacro[] macros = (IMacro[])macroCache.get(record); + if (macros == null) { + List macroList = new ArrayList(); + PDOMMacro macro = file.getFirstMacro(); + while (macro != null) { + macroList.add(macro.getMacro()); + macro = macro.getNextMacro(); + } + macros = (IMacro[])macroList.toArray(new IMacro[macroList.size()]); + macroCache.put(record, macros); } + + for (int i = 0; i < macros.length; ++i) + scanner.addDefinition(macros[i]); + + // record the macros we used. + usedMacros.add(macros); } public CodeReader createCodeReaderForInclusion(IScanner scanner, String path) { @@ -109,11 +124,16 @@ public class PDOMCodeReaderFactory implements ICodeReaderFactory { File file = new File(path); if (!file.exists()) return null; - path = new File(path).getCanonicalPath(); + path = file.getCanonicalPath(); } catch (IOException e) { // ignore and use the path we were passed in } - PDOMFile file = pdom.getFile(path); + PDOMFile file = (PDOMFile)fileCache.get(path); + if (file == null) { + file = pdom.getFile(path); + if (file != null) + fileCache.put(path, file); + } if (file != null) { // Already got things from here, // add the macros to the scanner @@ -127,6 +147,19 @@ public class PDOMCodeReaderFactory implements ICodeReaderFactory { return ParserUtil.createReader(path, null); } + + public void clearMacros() { + Iterator i = usedMacros.iterator(); + while (i.hasNext()) { + IMacro[] macros = (IMacro[])i.next(); + for (int j = 0; j < macros.length; ++j) { + if (macros[j] instanceof ObjectStyleMacro) { + ((ObjectStyleMacro)macros[j]).attachment = null; + } + } + } + usedMacros.clear(); + } public ICodeReaderCache getCodeReaderCache() { // No need for cache here diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMIndexerJob.java new file mode 100644 index 00000000000..314acfe34c6 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMIndexerJob.java @@ -0,0 +1,67 @@ +/** + * + */ +package org.eclipse.cdt.internal.core.pdom; + +import java.util.LinkedList; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.IPDOMIndexerTask; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; + +/** + * @author dschaefer + * + */ +public class PDOMIndexerJob extends Job { + + private final PDOMManager manager; + + private LinkedList queue = new LinkedList(); + + public PDOMIndexerJob(PDOMManager manager) { + super(CCorePlugin.getResourceString("pdom.indexer.name")); //$NON-NLS-1$ + this.manager = manager; + setPriority(Job.LONG); + } + + protected IStatus run(IProgressMonitor monitor) { + long start = System.currentTimeMillis(); + + String taskName = CCorePlugin.getResourceString("pdom.indexer.task"); //$NON-NLS-1$ + monitor.beginTask(taskName, IProgressMonitor.UNKNOWN); + + fillQueue(); + while (true) { + while (!queue.isEmpty()) { + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; + IPDOMIndexerTask task = (IPDOMIndexerTask)queue.removeFirst(); + task.run(monitor); + } + if (manager.finishIndexerJob()) + break; + else + fillQueue(); + } + + 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 Indexer Job Time: " + (System.currentTimeMillis() - start)); + + return Status.OK_STATUS; + } + + private void fillQueue() { + IPDOMIndexerTask task = manager.getNextTask(); + while (task != null) { + queue.addLast(task); + task = manager.getNextTask(); + } + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index e7f69ca0055..1b8092288d7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -10,11 +10,14 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom; +import java.util.LinkedList; + import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICExtensionReference; import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOMIndexer; +import org.eclipse.cdt.core.dom.IPDOMIndexerTask; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ElementChangedEvent; @@ -49,9 +52,12 @@ import org.osgi.service.prefs.BackingStoreException; */ public class PDOMManager implements IPDOMManager, IElementChangedListener { - private static final QualifiedName pdomProperty - = new QualifiedName(CCorePlugin.PLUGIN_ID, "pdom"); //$NON-NLS-1$ + private static final QualifiedName indexerProperty + = new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomIndexer"); //$NON-NLS-1$ + private IProgressMonitor group; + private IPDOM pdom; + private final ISchedulingRule indexerSchedulingRule = new ISchedulingRule() { public boolean contains(ISchedulingRule rule) { return rule == this; @@ -61,33 +67,42 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener { } }; - public synchronized IPDOM getPDOM(ICProject project) { + public synchronized IPDOM getPDOM() throws CoreException { + if (pdom == null) + pdom = new PDOM(); + return pdom; + } + + public IPDOMIndexer getIndexer(ICProject project) { try { IProject rproject = project.getProject(); - IPDOM pdom = (IPDOM)rproject.getSessionProperty(pdomProperty); + IPDOMIndexer indexer = (IPDOMIndexer)rproject.getSessionProperty(indexerProperty); - if (pdom == null) { - pdom = new PDOM(project, createIndexer(getIndexerId(project))); - rproject.setSessionProperty(pdomProperty, pdom); + if (indexer == null) { + indexer = createIndexer(getIndexerId(project), project); } - return pdom; + return indexer; } catch (CoreException e) { CCorePlugin.log(e); return null; } } - + public synchronized void elementChanged(ElementChangedEvent event) { // Only respond to post change events if (event.getType() != ElementChangedEvent.POST_CHANGE) return; // Walk the delta sending the subtrees to the appropriate indexers - processDelta(event.getDelta()); + try { + processDelta(event.getDelta()); + } catch (CoreException e) { + CCorePlugin.log(e); + } } - private void processDelta(ICElementDelta delta) { + private void processDelta(ICElementDelta delta) throws CoreException { int type = delta.getElement().getElementType(); switch (type) { case ICElement.C_MODEL: @@ -101,23 +116,16 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener { ICProject project = (ICProject)delta.getElement(); if (delta.getKind() != ICElementDelta.REMOVED) { if (project.getProject().exists()) { - IPDOM pdom = getPDOM(project); - if (pdom != null) + IPDOMIndexer indexer = getIndexer(project); + if (indexer != null) // TODO project delete, should do something fancier here. - pdom.getIndexer().handleDelta(delta); + indexer.handleDelta(delta); } } // TODO handle delete too. } } - public void deletePDOM(ICProject project) throws CoreException { - IProject rproject = project.getProject(); - IPDOM pdom = (IPDOM)rproject.getSessionProperty(pdomProperty); - rproject.setSessionProperty(pdomProperty, null); - pdom.clear(); - } - public IElementChangedListener getElementChangedListener() { return this; } @@ -187,6 +195,7 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener { super("Set Indexer Id"); this.project = project; this.indexerId = indexerId; + setSystem(true); } protected IStatus run(IProgressMonitor monitor) { try { @@ -212,11 +221,12 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener { public void setIndexerId(ICProject project, String indexerId) throws CoreException { setId(project, indexerId); - IPDOM pdom = getPDOM(project); - pdom.setIndexer(createIndexer(indexerId)); + if (project.getProject().getSessionProperty(indexerProperty) != null) + createIndexer(indexerId, project); } - private IPDOMIndexer createIndexer(String indexerId) throws CoreException { + private IPDOMIndexer createIndexer(String indexerId, ICProject project) throws CoreException { + IPDOMIndexer indexer = null; // Look up in extension point IExtension indexerExt = Platform.getExtensionRegistry() .getExtension(CCorePlugin.INDEXER_UNIQ_ID, indexerId); @@ -224,18 +234,93 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener { IConfigurationElement[] elements = indexerExt.getConfigurationElements(); for (int i = 0; i < elements.length; ++i) { IConfigurationElement element = elements[i]; - if ("run".equals(element.getName())) //$NON-NLS-1$ - return (IPDOMIndexer)element.createExecutableExtension("class"); //$NON-NLS-1$ + if ("run".equals(element.getName())) { //$NON-NLS-1$ + indexer = (IPDOMIndexer)element.createExecutableExtension("class"); //$NON-NLS-1$ + break; + } } } - // Unknown index, default to the null one - return new PDOMNullIndexer(); + if (indexer == null) + // Unknown index, default to the null one + indexer = new PDOMNullIndexer(); + + indexer.setProject(project); + project.getProject().setSessionProperty(indexerProperty, indexer); + + return indexer; } + // Indexer manager + private PDOMIndexerJob indexerJob; + private LinkedList indexerJobQueue = new LinkedList(); + private Object indexerJobMutex = new Object(); + + public void enqueue(IPDOMIndexerTask subjob) { + synchronized (indexerJobMutex) { + indexerJobQueue.addLast(subjob); + if (indexerJob == null) { + indexerJob = new PDOMIndexerJob(this); + indexerJob.schedule(); + } + } + } + + IPDOMIndexerTask getNextTask() { + synchronized (indexerJobMutex) { + return indexerJobQueue.isEmpty() + ? null + : (IPDOMIndexerTask)indexerJobQueue.removeFirst(); + } + } + + boolean finishIndexerJob() { + synchronized (indexerJobMutex) { + if (indexerJobQueue.isEmpty()) { + indexerJob = null; + return true; + } else + // No way, there's more work to do + return false; + } + } + public ISchedulingRule getIndexerSchedulingRule() { return indexerSchedulingRule; } + public IProgressMonitor getProgressGroup() { + if (group == null) + group = Platform.getJobManager().createProgressGroup(); + return group; + } + + private class Reindex extends Job { + public Reindex() { + super("Reindex"); //$NON-NLS-1$ + setSystem(true); + } + protected IStatus run(IProgressMonitor monitor) { + try { + pdom.acquireWriteLock(); + pdom.clear(); + pdom.releaseWriteLock(); + + ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects(); + for (int i = 0; i < projects.length; ++i) + getIndexer(projects[i]).indexAll(); + + return Status.OK_STATUS; + } catch (Exception e) { + CCorePlugin.log(e); + return Status.CANCEL_STATUS; + } + } + } + + public void reindex() { + new Reindex().schedule(); + } + /** * Startup the PDOM. This mainly sets us up to handle model * change events. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java index b64b4f7a7f6..8e2034bae5e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java @@ -46,6 +46,18 @@ public class Chunk { return buffer.get(offset % Database.CHUNK_SIZE); } + public byte[] getBytes(int offset, int length) { + byte[] bytes = new byte[length]; + buffer.position(offset % Database.CHUNK_SIZE); + buffer.get(bytes, 0, length); + return bytes; + } + + public void putBytes(int offset, byte[] bytes) { + buffer.position(offset % Database.CHUNK_SIZE); + buffer.put(bytes, 0, bytes.length); + } + public void putInt(int offset, int value) { buffer.putInt(offset % Database.CHUNK_SIZE, value); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBindingAdapterFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBindingAdapterFactory.java index f31cf8282cd..6ac7a57d779 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBindingAdapterFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBindingAdapterFactory.java @@ -35,8 +35,7 @@ public class PDOMBindingAdapterFactory implements IAdapterFactory { IBinding binding = (IBinding)adaptableObject; ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects(); for (int i = 0; i < projects.length; ++i) { - IPDOM ipdom = CCorePlugin.getPDOMManager().getPDOM(projects[i]); - + IPDOM ipdom = CCorePlugin.getPDOMManager().getPDOM(); if (ipdom == null || !(ipdom instanceof PDOM)) continue; PDOM pdom = (PDOM)ipdom; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java index e9aafb86561..1b8568870b3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java @@ -11,9 +11,16 @@ package org.eclipse.cdt.internal.core.pdom.dom; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; +import org.eclipse.cdt.core.parser.IMacro; +import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro; +import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.IString; @@ -103,4 +110,45 @@ public class PDOMMacro { return rec != 0 ? new PDOMMacroParameter(pdom, rec) : null; } + private class ObjectStylePDOMMacro extends ObjectStyleMacro { + public ObjectStylePDOMMacro(char[] name) { + super(name, null); + } + public char[] getExpansion() { + return getMacroExpansion(); + } + } + + private class FunctionStylePDOMMacro extends FunctionStyleMacro { + public FunctionStylePDOMMacro(char[] name, char[][] arglist) { + super(name, null, arglist); + } + public char[] getExpansion() { + return getMacroExpansion(); + } + } + + private char[] getMacroExpansion() { + try { + return PDOMMacro.this.getExpansion().getChars(); + } catch (CoreException e) { + CCorePlugin.log(e); + return new char[] { ' ' }; + } + } + + public IMacro getMacro() throws CoreException { + char[] name = getName().getChars(); + PDOMMacroParameter param = getFirstParameter(); + if (param != null) { + List paramList = new ArrayList(); + while (param != null) { + paramList.add(param.getName().getChars()); + param = param.getNextParameter(); + } + char[][] params = (char[][])paramList.toArray(new char[paramList.size()][]); + return new FunctionStylePDOMMacro(name, params); + } else + return new ObjectStylePDOMMacro(name); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMTranslationUnit.java index 04ce58439b2..8652cb7c30e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMTranslationUnit.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom; -import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; @@ -109,14 +108,14 @@ public class PDOMTranslationUnit implements IASTTranslationUnit { throw new PDOMNotImplementedError(); } - public IPDOM getIndex() { + public boolean useIndex() { throw new PDOMNotImplementedError(); } - - public void setIndex(IPDOM pdom) { + + public void useIndex(boolean value) { throw new PDOMNotImplementedError(); } - + public IASTTranslationUnit getTranslationUnit() { throw new PDOMNotImplementedError(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsHandleDelta.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsHandleDelta.java index 076049f6318..1736262aedd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsHandleDelta.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsHandleDelta.java @@ -40,7 +40,7 @@ public class CtagsHandleDelta extends CtagsIndexerJob { private List changed = new ArrayList(); private List removed = new ArrayList(); - public CtagsHandleDelta(CtagsIndexer indexer, ICElementDelta delta) { + public CtagsHandleDelta(CtagsIndexer indexer, ICElementDelta delta) throws CoreException { super(indexer); this.delta = delta; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsIndexer.java index 2625595bee7..48c752d7021 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsIndexer.java @@ -14,11 +14,9 @@ package org.eclipse.cdt.internal.core.pdom.indexer.ctags; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICExtensionReference; -import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.internal.core.pdom.PDOM; -import org.eclipse.core.resources.IProject; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Platform; @@ -32,30 +30,29 @@ import org.osgi.service.prefs.BackingStoreException; */ public class CtagsIndexer implements IPDOMIndexer { - private PDOM pdom; + private ICProject project; private boolean useCtagsOnPath = true; private String ctagsCommand = ""; //$NON-NLS-1$ private boolean useInternalCtagsFile = true; private String ctagsFileName = ""; //$NON-NLS-1$ - public void handleDelta(ICElementDelta delta) { + public void handleDelta(ICElementDelta delta) throws CoreException { new CtagsHandleDelta(this,delta).schedule(); } - public void reindex() throws CoreException { + public void indexAll() throws CoreException { new CtagsReindex(this).schedule(); } - public void setPDOM(IPDOM pdom) { - this.pdom = (PDOM)pdom; - loadPreferences(); - } - - public IPDOM getPDOM() { - return pdom; + public ICProject getProject() { + return project; } + public void setProject(ICProject project) { + this.project = project; + } + // Preference Management private static final String useCtagsOnPathId = "useCtagsOnPath"; //$NON-NLS-1$ private static final String ctagsCommandId = "ctagsCommand"; //$NON-NLS-1$ @@ -64,7 +61,6 @@ public class CtagsIndexer implements IPDOMIndexer { // project preferences private void loadPreferences() { - IProject project = pdom.getProject().getProject(); IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID); if (prefs == null) return; @@ -77,7 +73,7 @@ public class CtagsIndexer implements IPDOMIndexer { } else { // Not defined yet check in cdescriptor try { - ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(project, false); + ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(project.getProject(), false); if (desc != null) { ICExtensionReference[] cext = desc.get(CCorePlugin.INDEXER_UNIQ_ID); if (cext.length > 0) { @@ -119,7 +115,6 @@ public class CtagsIndexer implements IPDOMIndexer { boolean useInternalCtagsFile, String ctagsFileName) throws CoreException { - IProject project = pdom.getProject().getProject(); IEclipsePreferences prefs = new ProjectScope(project.getProject()).getNode(CCorePlugin.PLUGIN_ID); if (prefs == null) return; @@ -155,7 +150,7 @@ public class CtagsIndexer implements IPDOMIndexer { } catch (BackingStoreException e) { CCorePlugin.log(e); } - reindex(); + indexAll(); } } @@ -182,7 +177,7 @@ public class CtagsIndexer implements IPDOMIndexer { public String getResolvedCtagsFileName() { if (useInternalCtagsFile) - return CCorePlugin.getDefault().getStateLocation().append(pdom.getProject().getElementName() + ".ctags").toOSString(); //$NON-NLS-1$ + return CCorePlugin.getDefault().getStateLocation().append(project.getElementName() + ".ctags").toOSString(); //$NON-NLS-1$ else return ctagsFileName; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsIndexerJob.java index a9c9d4f1b31..871da8feac3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsIndexerJob.java @@ -38,10 +38,10 @@ public abstract class CtagsIndexerJob extends Job { protected final CtagsIndexer indexer; protected final PDOM pdom; - public CtagsIndexerJob(CtagsIndexer indexer) { - super("ctags Indexer: " + ((PDOM)indexer.getPDOM()).getProject().getElementName()); + public CtagsIndexerJob(CtagsIndexer indexer) throws CoreException { + super("ctags Indexer: " + indexer.getProject().getElementName()); this.indexer = indexer; - this.pdom = (PDOM)indexer.getPDOM(); + this.pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(); setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule()); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsReindex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsReindex.java index d9c4b6e8758..071e2eb0e67 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsReindex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ctags/CtagsReindex.java @@ -25,14 +25,14 @@ import org.eclipse.core.runtime.Status; */ public class CtagsReindex extends CtagsIndexerJob { - public CtagsReindex(CtagsIndexer indexer) { + public CtagsReindex(CtagsIndexer indexer) throws CoreException { super(indexer); } protected IStatus run(IProgressMonitor monitor) { try { // What do we need to index - final ICProject project = pdom.getProject(); + final ICProject project = indexer.getProject(); // final IIncludeReference[] pincludes = project.getIncludeReferences(); // IIncludeReference[] includes = new IIncludeReference[pincludes.length]; // System.arraycopy(pincludes, 0, includes, 0, pincludes.length); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java index adc588212e7..6787bd44f6e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastHandleDelta.java @@ -21,16 +21,13 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOMCodeReaderFactory; import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; class PDOMFastHandleDelta extends PDOMFastIndexerJob { @@ -40,69 +37,55 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob { private List changed = new ArrayList(); private List removed = new ArrayList(); - public PDOMFastHandleDelta(PDOM pdom, ICElementDelta delta) { - super(pdom); + public PDOMFastHandleDelta(PDOMFastIndexer indexer, ICElementDelta delta) throws CoreException { + super(indexer); this.delta = delta; } - protected IStatus run(IProgressMonitor monitor) { + public void run(IProgressMonitor monitor) { try { long start = System.currentTimeMillis(); - - processDelta(delta); - int count = changed.size() + added.size() + removed.size(); - - if (count > 0) { - monitor.beginTask("Indexing", count); - - Iterator i = changed.iterator(); - while (i.hasNext()) { - ITranslationUnit tu = (ITranslationUnit)i.next(); - monitor.subTask(tu.getElementName()); - try { - changeTU(tu); - } catch (Throwable e) { - CCorePlugin.log(e); - if (++errorCount > MAX_ERRORS) - return Status.CANCEL_STATUS; - } - monitor.worked(1); - } - - i = added.iterator(); - while (i.hasNext()) { - ITranslationUnit tu = (ITranslationUnit)i.next(); - monitor.subTask(tu.getElementName()); - try { - addTU(tu); - } catch (Throwable e) { - CCorePlugin.log(e); - if (++errorCount > MAX_ERRORS) - return Status.CANCEL_STATUS; - } - 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 - + "/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$ - } + processDelta(delta); - return Status.OK_STATUS; + Iterator i = changed.iterator(); + while (i.hasNext()) { + ITranslationUnit tu = (ITranslationUnit)i.next(); + try { + changeTU(tu); + } catch (Throwable e) { + CCorePlugin.log(e); + if (++errorCount > MAX_ERRORS) + return; + } + } + + i = added.iterator(); + while (i.hasNext()) { + ITranslationUnit tu = (ITranslationUnit)i.next(); + try { + addTU(tu); + } catch (Throwable e) { + CCorePlugin.log(e); + if (++errorCount > MAX_ERRORS) + return; + } + } + + i = removed.iterator(); + while (i.hasNext()) { + ITranslationUnit tu = (ITranslationUnit)i.next(); + removeTU(tu); + } + + 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$ + } catch (CoreException e) { - return e.getStatus(); + CCorePlugin.log(e); } catch (InterruptedException e) { - return Status.CANCEL_STATUS; } } @@ -152,6 +135,9 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob { if (ast == null) return; + // Clear the macros + codeReaderFactory.clearMacros(); + pdom.acquireWriteLock(); try { // Remove the old symbols in the tu diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java index 6b122e34b24..8f64c0c4470 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexer.java @@ -12,10 +12,10 @@ package org.eclipse.cdt.internal.core.pdom.indexer.fast; -import org.eclipse.cdt.core.dom.IPDOM; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.runtime.CoreException; /** @@ -24,18 +24,30 @@ import org.eclipse.core.runtime.CoreException; */ public class PDOMFastIndexer implements IPDOMIndexer { - private IPDOM pdom; + // Must match extension id + public static final String ID = "org.eclipse.cdt.core.fastIndexer"; + + protected ICProject project; + + public PDOMFastIndexer() { + } - public void setPDOM(IPDOM pdom) { - this.pdom = pdom; + public ICProject getProject() { + return project; } - public void handleDelta(ICElementDelta delta) { - new PDOMFastHandleDelta((PDOM)pdom, delta).schedule(); + public void setProject(ICProject project) { + this.project = project; } - public void reindex() throws CoreException { - new PDOMFastReindex((PDOM)pdom).schedule(); + public void handleDelta(ICElementDelta delta) throws CoreException { + CCorePlugin.getPDOMManager().enqueue( + new PDOMFastHandleDelta(this, delta)); + } + + public void indexAll() throws CoreException { + CCorePlugin.getPDOMManager().enqueue( + new PDOMFastReindex(this)); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java index cd395187738..e1685958064 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastIndexerJob.java @@ -11,10 +11,8 @@ package org.eclipse.cdt.internal.core.pdom.indexer.fast; -import java.util.HashMap; -import java.util.Map; - import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.IPDOMIndexerTask; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -28,49 +26,41 @@ import org.eclipse.cdt.internal.core.pdom.PDOMCodeReaderFactory; import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.jobs.Job; /** * @author Doug Schaefer * */ -public abstract class PDOMFastIndexerJob extends Job { +public abstract class PDOMFastIndexerJob implements IPDOMIndexerTask { - protected final Map fileMap = new HashMap(); + protected final PDOMFastIndexer indexer; protected final PDOM pdom; + protected final PDOMCodeReaderFactory codeReaderFactory; // Error counter. If we too many errors we bail protected int errorCount; protected final int MAX_ERRORS = 10; - public PDOMFastIndexerJob(PDOM pdom) { - super("Fast Indexer: " + pdom.getProject().getElementName()); - this.pdom = pdom; - setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule()); + public PDOMFastIndexerJob(PDOMFastIndexer indexer) throws CoreException { + this.indexer = indexer; + this.pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(); + this.codeReaderFactory = new PDOMCodeReaderFactory(pdom); } - protected PDOMFile getCachedFile(String filename) throws CoreException { - PDOMFile file = (PDOMFile)fileMap.get(filename); - if (file == null) { - file = pdom.addFile(filename); - fileMap.put(filename, file); - } - return file; - } - protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException { ILanguage language = tu.getLanguage(); if (language == null) return; - PDOMCodeReaderFactory codeReaderFactory = new PDOMCodeReaderFactory(pdom); - // get the AST in a "Fast" way IASTTranslationUnit ast = language.getASTTranslationUnit(tu, codeReaderFactory, ILanguage.AST_USE_INDEX | ILanguage.AST_SKIP_IF_NO_BUILD_INFO); if (ast == null) return; + + // Clear the macros + codeReaderFactory.clearMacros(); pdom.acquireWriteLock(); try { @@ -78,7 +68,7 @@ public abstract class PDOMFastIndexerJob extends Job { } finally { pdom.releaseWriteLock(); } - + // Tell the world pdom.fireChange(); } @@ -99,9 +89,9 @@ public abstract class PDOMFastIndexerJob extends Job { ? sourceLoc.getFileName() : ast.getFilePath(); // command-line includes - PDOMFile sourceFile = getCachedFile(sourcePath); + PDOMFile sourceFile = codeReaderFactory.getCachedFile(sourcePath); String destPath = include.getPath(); - PDOMFile destFile = getCachedFile(destPath); + PDOMFile destFile = codeReaderFactory.getCachedFile(destPath); sourceFile.addIncludeTo(destFile); } @@ -115,7 +105,7 @@ public abstract class PDOMFastIndexerJob extends Job { continue; // skip built-ins and command line macros String filename = sourceLoc.getFileName(); - PDOMFile sourceFile = getCachedFile(filename); + PDOMFile sourceFile = codeReaderFactory.getCachedFile(filename); sourceFile.addMacro(macro); } @@ -129,7 +119,7 @@ public abstract class PDOMFastIndexerJob extends Job { try { IASTFileLocation nameLoc = name.getFileLocation(); if (nameLoc != null) - linkage.addName(name, getCachedFile(nameLoc.getFileName())); + linkage.addName(name, codeReaderFactory.getCachedFile(nameLoc.getFileName())); return PROCESS_CONTINUE; } catch (Throwable e) { CCorePlugin.log(e); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java index 765565da475..ddbdf4506a0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/fast/PDOMFastReindex.java @@ -12,14 +12,11 @@ package org.eclipse.cdt.internal.core.pdom.indexer.fast; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementVisitor; +import org.eclipse.cdt.core.model.ICContainer; +import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.internal.core.pdom.PDOM; -import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; @@ -29,105 +26,48 @@ import org.eclipse.core.runtime.Status; */ public class PDOMFastReindex extends PDOMFastIndexerJob { - public PDOMFastReindex(PDOM pdom) { - super(pdom); + public PDOMFastReindex(PDOMFastIndexer indexer) throws CoreException { + super(indexer); } - protected IStatus run(final IProgressMonitor monitor) { + private void addSources(ICContainer container, IProgressMonitor monitor) throws CoreException { + ITranslationUnit[] tus = container.getTranslationUnits(); + for (int i = 0; i < tus.length; ++i) { + if (monitor.isCanceled()) + throw new CoreException(Status.CANCEL_STATUS); + ITranslationUnit tu = tus[i]; + if (tu.isSourceUnit()) { + try { + addTU(tu); + } catch (Throwable e) { + CCorePlugin.log(e); + if (++errorCount > MAX_ERRORS) + throw new CoreException(Status.CANCEL_STATUS); + } + } + } + + ICContainer[] childContainers = container.getCContainers(); + for (int i = 0; i < childContainers.length; ++i) + addSources(childContainers[i], monitor); + } + + public void run(final IProgressMonitor monitor) { try { long start = System.currentTimeMillis(); - // First clear out the DB - pdom.clear(); - - // Get a count of all the elements that we'll be visiting for the monitor - final int[] count = { 0 }; - pdom.getProject().accept(new ICElementVisitor() { - public boolean visit(ICElement element) throws CoreException { - if (monitor.isCanceled()) - throw new CoreException(Status.CANCEL_STATUS); - switch (element.getElementType()) { - case ICElement.C_UNIT: - ++count[0]; - return false; - case ICElement.C_CCONTAINER: - case ICElement.C_PROJECT: - return true; - } - return false; - } - }); - - monitor.beginTask("Indexing", count[0]); - - // First index all the source files (i.e. not headers) - pdom.getProject().accept(new ICElementVisitor() { - public boolean visit(ICElement element) throws CoreException { - if (monitor.isCanceled()) - throw new CoreException(Status.CANCEL_STATUS); - switch (element.getElementType()) { - case ICElement.C_UNIT: - ITranslationUnit tu = (ITranslationUnit)element; - if (tu.isSourceUnit()) { - monitor.subTask(tu.getElementName()); - try { - addTU(tu); - } catch (Throwable e) { - CCorePlugin.log(e); - if (++errorCount > MAX_ERRORS) - throw new CoreException(Status.CANCEL_STATUS); - } - monitor.worked(1); - } - return false; - case ICElement.C_CCONTAINER: - case ICElement.C_PROJECT: - return true; - } - return false; - } - }); - - // Now add in the header files but only if they aren't already indexed - pdom.getProject().accept(new ICElementVisitor() { - public boolean visit(ICElement element) throws CoreException { - if (monitor.isCanceled()) - throw new CoreException(Status.CANCEL_STATUS); - switch (element.getElementType()) { - case ICElement.C_UNIT: - ITranslationUnit tu = (ITranslationUnit)element; - if (tu.isHeaderUnit()) { - IFile rfile = (IFile)tu.getUnderlyingResource(); - String filename = rfile.getLocation().toOSString(); - if (pdom.getFile(filename) == null) { - monitor.subTask(tu.getElementName()); - try { - addTU(tu); - } catch (Throwable e) { - CCorePlugin.log(e); - if (++errorCount > MAX_ERRORS) - throw new CoreException(Status.CANCEL_STATUS); - } - } - monitor.worked(1); - } - return false; - case ICElement.C_CCONTAINER: - case ICElement.C_PROJECT: - return true; - } - return false; - } - }); - + ISourceRoot[] roots = indexer.getProject().getAllSourceRoots(); + for (int i = 0; i < roots.length; ++i) + addSources(roots[i], monitor); + 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 Fast Reindex Time: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$ + System.out.println("PDOM Fast Reindex Time: " + (System.currentTimeMillis() - start) + + " " + indexer.getProject().getElementName()); //$NON-NLS-1$ - return Status.OK_STATUS; } catch (CoreException e) { - return e.getStatus(); + CCorePlugin.log(e); } } 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 741451b1b7e..320d9570351 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 @@ -24,7 +24,6 @@ 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; @@ -50,8 +49,8 @@ public class PDOMFullHandleDelta extends PDOMFullIndexerJob { private List added = new ArrayList(); private List removed = new ArrayList(); - public PDOMFullHandleDelta(PDOM pdom, ICElementDelta delta) { - super(pdom); + public PDOMFullHandleDelta(PDOMFullIndexer indexer, ICElementDelta delta) throws CoreException { + super(indexer); this.delta = delta; } 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 191b091cba3..96fcf2d3b35 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 @@ -11,10 +11,9 @@ package org.eclipse.cdt.internal.core.pdom.indexer.full; -import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.runtime.CoreException; /** @@ -26,18 +25,22 @@ import org.eclipse.core.runtime.CoreException; */ public class PDOMFullIndexer implements IPDOMIndexer { - private IPDOM pdom; + private ICProject project; - public void handleDelta(ICElementDelta delta) { - new PDOMFullHandleDelta((PDOM)pdom, delta).schedule(); + public ICProject getProject() { + return project; + } + + public void setProject(ICProject project) { + this.project = project; + } + + public void handleDelta(ICElementDelta delta) throws CoreException { + new PDOMFullHandleDelta(this, delta).schedule(); } - public void reindex() throws CoreException { - new PDOMFullReindex((PDOM)pdom).schedule(); - } - - public void setPDOM(IPDOM pdom) { - this.pdom = pdom; + public void indexAll() throws CoreException { + new PDOMFullReindex(this).schedule(); } } 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 60876424601..16d14adbef1 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 @@ -32,15 +32,17 @@ import org.eclipse.core.runtime.jobs.Job; */ public abstract class PDOMFullIndexerJob extends Job { + protected final PDOMFullIndexer indexer; protected final PDOM pdom; // Error count, bail when it gets too high protected int errorCount; protected final int MAX_ERRORS = 10; - public PDOMFullIndexerJob(PDOM pdom) { - super("Full Indexer: " + pdom.getProject().getElementName()); - this.pdom = pdom; + public PDOMFullIndexerJob(PDOMFullIndexer indexer) throws CoreException { + super("Full Indexer: " + indexer.getProject().getElementName()); + this.indexer = indexer; + this.pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(); setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule()); } 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 9f19810769a..98dc690a149 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 @@ -15,7 +15,6 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElementVisitor; import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -29,8 +28,8 @@ import org.eclipse.core.runtime.Status; */ public class PDOMFullReindex extends PDOMFullIndexerJob { - public PDOMFullReindex(PDOM pdom) { - super(pdom); + public PDOMFullReindex(PDOMFullIndexer indexer) throws CoreException { + super(indexer); } protected IStatus run(final IProgressMonitor monitor) { @@ -42,7 +41,7 @@ public class PDOMFullReindex extends PDOMFullIndexerJob { // Get a count of all the elements that we'll be visiting for the monitor final int[] count = { 0 }; - pdom.getProject().accept(new ICElementVisitor() { + indexer.getProject().accept(new ICElementVisitor() { public boolean visit(ICElement element) throws CoreException { if (monitor.isCanceled()) throw new CoreException(Status.CANCEL_STATUS); @@ -61,7 +60,7 @@ public class PDOMFullReindex extends PDOMFullIndexerJob { monitor.beginTask("Indexing", count[0]); // First index all the source files (i.e. not headers) - pdom.getProject().accept(new ICElementVisitor() { + indexer.getProject().accept(new ICElementVisitor() { public boolean visit(ICElement element) throws CoreException { if (monitor.isCanceled()) throw new CoreException(Status.CANCEL_STATUS); @@ -89,7 +88,7 @@ public class PDOMFullReindex extends PDOMFullIndexerJob { }); // Now add in the header files but only if they aren't already indexed - pdom.getProject().accept(new ICElementVisitor() { + indexer.getProject().accept(new ICElementVisitor() { public boolean visit(ICElement element) throws CoreException { if (monitor.isCanceled()) throw new CoreException(Status.CANCEL_STATUS); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java index 892c3460da5..4171ef345b7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullIndexer.java @@ -11,10 +11,9 @@ package org.eclipse.cdt.internal.core.pdom.indexer.nulli; -import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.internal.core.pdom.PDOM; +import org.eclipse.cdt.core.model.ICProject; import org.eclipse.core.runtime.CoreException; /** @@ -24,17 +23,20 @@ import org.eclipse.core.runtime.CoreException; */ public class PDOMNullIndexer implements IPDOMIndexer { - private IPDOM pdom; + private ICProject project; - public void setPDOM(IPDOM pdom) { - this.pdom = pdom; + public ICProject getProject() { + return project; } - + + public void setProject(ICProject project) { + this.project = project; + } + public void handleDelta(ICElementDelta delta) { } - public void reindex() throws CoreException { - new PDOMNullReindex((PDOM)pdom).schedule(); + public void indexAll() throws CoreException { } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullReindex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullReindex.java deleted file mode 100644 index 0e640bbd655..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/nulli/PDOMNullReindex.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * QNX - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.pdom.indexer.nulli; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.internal.core.pdom.PDOM; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; - -/** - * @author Doug Schaefer - * - */ -public class PDOMNullReindex extends Job { - - private final PDOM pdom; - - public PDOMNullReindex(PDOM pdom) { - super("Null Indexer: " + pdom.getProject().getElementName()); - this.pdom = pdom; - setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule()); - } - - protected IStatus run(IProgressMonitor monitor) { - try { - pdom.acquireWriteLock(); - pdom.clear(); - pdom.fireChange(); - } catch (CoreException e) { - return e.getStatus(); - } catch (InterruptedException e) { - return Status.CANCEL_STATUS; - } finally { - pdom.releaseWriteLock(); - } - return Status.OK_STATUS; - } - -} diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties index b46be3dcc5a..f64e42aed0f 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/CCorePluginResources.properties @@ -73,3 +73,7 @@ dom.languageError=Language not found indexer.notFound = Indexer not found pdom.requestTooLarge=Request too large +pdom.indexer.name=C/C++ Indexer +pdom.indexer.task=Indexing +pdom.indexer.filling=Counting files +pdom.indexer.message=file {0} of {1}: {2} diff --git a/core/org.eclipse.cdt.ui.tests/plugin.xml b/core/org.eclipse.cdt.ui.tests/plugin.xml index 6e420b224ba..4558a7f2a73 100644 --- a/core/org.eclipse.cdt.ui.tests/plugin.xml +++ b/core/org.eclipse.cdt.ui.tests/plugin.xml @@ -26,14 +26,6 @@ name="DOM AST" id="org.eclipse.cdt.ui.tests.DOMAST.DOMAST"> - @@ -79,20 +71,6 @@ - - - - - - - - diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index f363e423b1a..7ca0de91648 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -1066,33 +1066,6 @@ showScopeSection="true" sizeHint="460, 160"/> - - - - - - - - - -