mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Two major PDOM changes. First, the PDOM is now per workspace. Indexers remain per project. There were a lot of changes to make this work.
Second, the macros are now cached on the PDOMCodeReaderFactory which is now used for the duration of a reindex request. This vastly improves the performance of the fast indexer.
This commit is contained in:
parent
2a042c66a1
commit
6fad7334f7
64 changed files with 879 additions and 784 deletions
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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() )
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -36,4 +36,7 @@ public abstract class DynamicStyleMacro implements IMacro{
|
|||
{
|
||||
return name;
|
||||
}
|
||||
public char[] getExpansion() {
|
||||
return execute();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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}
|
||||
|
|
|
@ -26,14 +26,6 @@
|
|||
name="DOM AST"
|
||||
id="org.eclipse.cdt.ui.tests.DOMAST.DOMAST">
|
||||
</view>
|
||||
<view
|
||||
allowMultiple="true"
|
||||
category="org.eclipse.cdt.ui.views"
|
||||
class="org.eclipse.cdt.ui.tests.IndexerView.IndexerView"
|
||||
fastViewWidthRatio="0.35"
|
||||
icon="icons/used/output_obj.gif"
|
||||
id="org.eclipse.cdt.ui.tests.IndexerView"
|
||||
name="Indexer View"/>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.perspectiveExtensions">
|
||||
|
@ -79,20 +71,6 @@
|
|||
</or>
|
||||
</visibility>
|
||||
</viewerContribution>
|
||||
<viewerContribution
|
||||
id="org.eclipse.cdt.ui.CView2"
|
||||
targetID="org.eclipse.cdt.ui.CView">
|
||||
<action
|
||||
class="org.eclipse.cdt.ui.tests.IndexerView.OpenIndexerViewAction"
|
||||
id="org.eclipse.cdt.ui.tests.IndexerView.OpenIndexerViewAction"
|
||||
label="Show in Indexer View"
|
||||
menubarPath="additions"/>
|
||||
<visibility>
|
||||
<or>
|
||||
<objectClass name="org.eclipse.cdt.internal.core.model.CProject"/>
|
||||
</or>
|
||||
</visibility>
|
||||
</viewerContribution>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.CElementFilters">
|
||||
|
|
|
@ -1066,33 +1066,6 @@
|
|||
showScopeSection="true"
|
||||
sizeHint="460, 160"/>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.search.searchResultSorters">
|
||||
<sorter
|
||||
pageId="org.eclipse.cdt.ui.CSearchPage"
|
||||
label="%ElementNameSorter.label"
|
||||
icon="icons/obj16/search_sortmatch.gif"
|
||||
class="org.eclipse.cdt.internal.ui.search.ElementNameSorter"
|
||||
tooltip="%ElementNameSorter.tooltip"
|
||||
id="org.eclipse.cdt.search.internal.ui.ElementNameSorter">
|
||||
</sorter>
|
||||
<sorter
|
||||
pageId="org.eclipse.cdt.ui.CSearchPage"
|
||||
label="%ParentNameSorter.label"
|
||||
icon="icons/obj16/search_sortmatch.gif"
|
||||
class="org.eclipse.cdt.internal.ui.search.ParentNameSorter"
|
||||
tooltip="%ParentNameSorter.tooltip"
|
||||
id="org.eclipse.cdt.search.internal.ui.ParentNameSorter">
|
||||
</sorter>
|
||||
<sorter
|
||||
pageId="org.eclipse.cdt.ui.CSearchPage"
|
||||
label="%PathNameSorter.label"
|
||||
icon="icons/obj16/search_sortmatch.gif"
|
||||
class="org.eclipse.cdt.internal.ui.search.PathNameSorter"
|
||||
tooltip="%PathNameSorter.tooltip"
|
||||
id="org.eclipse.cdt.search.internal.ui.PathNameSorter">
|
||||
</sorter>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.actionSets">
|
||||
<actionSet
|
||||
|
@ -1226,11 +1199,6 @@
|
|||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.search.searchResultViewPages">
|
||||
<viewPage
|
||||
class="org.eclipse.cdt.internal.ui.search.CSearchResultPage"
|
||||
searchResultClass="org.eclipse.cdt.internal.ui.search.CSearchResult"
|
||||
id="org.eclipse.cdt.ui.CSearchResultPage">
|
||||
</viewPage>
|
||||
<viewPage
|
||||
class="org.eclipse.cdt.internal.ui.search.PDOMSearchViewPage"
|
||||
id="org.eclipse.cdt.ui.pdomSearchViewPage"
|
||||
|
|
|
@ -326,3 +326,7 @@ IndexView.findReferences.name = Find References
|
|||
IndexView.findDeclarations.name = Find Declarations
|
||||
IndexView.ToggleExternals.name = Toggle Show Externals
|
||||
IndexView.ToggleExternals.tooltip = Show Externaly Defined Symbols
|
||||
IndexView.setFastIndexer.name = Use Fast Indexer
|
||||
IndexView.CountSymbols.name = Count Symbols
|
||||
IndexView.CountSymbols.title = Symbol Count
|
||||
IndexView.CountSymbols.message = The PDOM contains {0} symbols.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -35,9 +35,9 @@ public class PDOMUpdateProjectAction implements IObjectActionDelegate {
|
|||
continue;
|
||||
|
||||
ICProject project = (ICProject)objs[i];
|
||||
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(project);
|
||||
IPDOMIndexer indexer = CCorePlugin.getPDOMManager().getIndexer(project);
|
||||
try {
|
||||
pdom.getIndexer().reindex();
|
||||
indexer.indexAll();
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.eclipse.cdt.internal.ui.indexview;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacro;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
|
||||
/**
|
||||
* @author dschaefer
|
||||
*
|
||||
*/
|
||||
public class CountNodeAction extends IndexAction {
|
||||
|
||||
public CountNodeAction(TreeViewer viewer) {
|
||||
super(viewer, CUIPlugin.getResourceString("IndexView.CountSymbols.name")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public boolean valid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
final int[] count = new int[1];
|
||||
|
||||
try {
|
||||
final PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM();
|
||||
pdom.getFileIndex().accept(new IBTreeVisitor() {
|
||||
public int compare(int record) throws CoreException {
|
||||
return 1;
|
||||
}
|
||||
public boolean visit(int record) throws CoreException {
|
||||
if (record != 0) {
|
||||
PDOMFile file = new PDOMFile(pdom, record);
|
||||
PDOMMacro macro = file.getFirstMacro();
|
||||
while (macro != null) {
|
||||
++count[0];
|
||||
macro = macro.getNextMacro();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
pdom.accept(new IPDOMVisitor() {
|
||||
public boolean visit(IPDOMNode node) throws CoreException {
|
||||
count[0]++;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
|
||||
MessageDialog.openInformation(null,
|
||||
CUIPlugin.getResourceString("IndexView.CountSymbols.title"), //$NON-NLS-1$
|
||||
CUIPlugin.getFormattedString("IndexView.CountSymbols.message", //$NON-NLS-1$
|
||||
new String[] { String.valueOf(count[0]) }));
|
||||
}
|
||||
|
||||
}
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
package org.eclipse.cdt.internal.ui.indexview;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.ui.search.PDOMSearchBindingQuery;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
@ -42,9 +40,8 @@ public class FindDeclarationsAction extends IndexAction {
|
|||
|
||||
public void run() {
|
||||
PDOMBinding binding = getBinding();
|
||||
ICProject project = binding.getPDOM().getProject();
|
||||
PDOMSearchBindingQuery query = new PDOMSearchBindingQuery(
|
||||
new ICElement[] { project },
|
||||
null,
|
||||
binding,
|
||||
PDOMSearchBindingQuery.FIND_DECLARATIONS | PDOMSearchBindingQuery.FIND_DEFINITIONS);
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
package org.eclipse.cdt.internal.ui.indexview;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.ui.search.PDOMSearchBindingQuery;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
@ -41,10 +39,8 @@ public class FindReferencesAction extends IndexAction {
|
|||
}
|
||||
|
||||
public void run() {
|
||||
PDOMBinding binding = getBinding();
|
||||
ICProject project = binding.getPDOM().getProject();
|
||||
PDOMSearchBindingQuery query = new PDOMSearchBindingQuery(
|
||||
new ICElement[] { project },
|
||||
null,
|
||||
getBinding(),
|
||||
PDOMSearchBindingQuery.FIND_REFERENCES);
|
||||
|
||||
|
|
|
@ -21,9 +21,6 @@ import org.eclipse.cdt.core.dom.ast.IFunction;
|
|||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
|
@ -73,6 +70,8 @@ public class IndexView extends ViewPart implements PDOM.IListener {
|
|||
// private DrillDownAdapter drillDownAdapter;
|
||||
private ToggleLinkingAction toggleLinkingAction;
|
||||
private IndexAction rebuildAction;
|
||||
private IndexAction countSymbolsAction;
|
||||
private IndexAction setFastIndexAction;
|
||||
private IndexAction discardExternalDefsAction;
|
||||
private IndexAction openDefinitionAction;
|
||||
private IndexAction findDeclarationsAction;
|
||||
|
@ -181,22 +180,7 @@ public class IndexView extends ViewPart implements PDOM.IListener {
|
|||
private class IndexContentProvider implements ITreeContentProvider {
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
try {
|
||||
if (parentElement instanceof ICProject) {
|
||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM((ICProject)parentElement);
|
||||
int n = 0;
|
||||
PDOMLinkage firstLinkage = pdom.getFirstLinkage();
|
||||
for (PDOMLinkage linkage = firstLinkage; linkage != null; linkage = linkage.getNextLinkage())
|
||||
++n;
|
||||
if (n == 1) {
|
||||
// Skip linkages in hierarchy if there is only one
|
||||
return getChildren(firstLinkage);
|
||||
}
|
||||
PDOMLinkage[] linkages = new PDOMLinkage[n];
|
||||
int i = 0;
|
||||
for (PDOMLinkage linkage = pdom.getFirstLinkage(); linkage != null; linkage = linkage.getNextLinkage())
|
||||
linkages[i++] = linkage;
|
||||
return linkages;
|
||||
} else if (parentElement instanceof IPDOMNode) {
|
||||
if (parentElement instanceof IPDOMNode) {
|
||||
IPDOMNode node = (IPDOMNode)parentElement;
|
||||
Counter counter = new Counter();
|
||||
node.accept(counter);
|
||||
|
@ -218,8 +202,8 @@ public class IndexView extends ViewPart implements PDOM.IListener {
|
|||
|
||||
public boolean hasChildren(Object element) {
|
||||
try {
|
||||
if (element instanceof ICProject) {
|
||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM((ICProject)element);
|
||||
if (element instanceof PDOM) {
|
||||
PDOM pdom = (PDOM)element;
|
||||
PDOMLinkage[] linkages = pdom.getLinkages();
|
||||
if (linkages.length == 0)
|
||||
return false;
|
||||
|
@ -245,16 +229,11 @@ public class IndexView extends ViewPart implements PDOM.IListener {
|
|||
}
|
||||
|
||||
public Object[] getElements(Object inputElement) {
|
||||
try {
|
||||
if (inputElement instanceof ICModel) {
|
||||
ICModel model = (ICModel)inputElement;
|
||||
return model.getCProjects();
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
|
||||
return new Object[0];
|
||||
if (inputElement instanceof PDOM) {
|
||||
PDOM pdom = (PDOM)inputElement;
|
||||
return pdom.getLinkages();
|
||||
} else
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
@ -321,16 +300,11 @@ public class IndexView extends ViewPart implements PDOM.IListener {
|
|||
viewer.setContentProvider(new IndexContentProvider());
|
||||
viewer.setLabelProvider(new IndexLabelProvider());
|
||||
|
||||
ICModel model = CoreModel.getDefault().getCModel();
|
||||
viewer.setInput(model);
|
||||
try {
|
||||
ICProject[] projects = model.getCProjects();
|
||||
for (int i = 0; i < projects.length; ++i) {
|
||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(projects[i]);
|
||||
pdom.addListener(this);
|
||||
}
|
||||
viewer.setChildCount(model, projects.length);
|
||||
} catch (CModelException e) {
|
||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM();
|
||||
pdom.addListener(this);
|
||||
viewer.setInput(pdom);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
|
||||
|
@ -365,6 +339,8 @@ public class IndexView extends ViewPart implements PDOM.IListener {
|
|||
|
||||
private void makeActions() {
|
||||
rebuildAction = new RebuildIndexAction(viewer);
|
||||
countSymbolsAction = new CountNodeAction(viewer);
|
||||
setFastIndexAction = new SetFastIndexerAction(viewer);
|
||||
discardExternalDefsAction = new DiscardExternalDefsAction(viewer, this);
|
||||
toggleLinkingAction = new ToggleLinkingAction(this);
|
||||
openDefinitionAction = new OpenDefinitionAction(viewer);
|
||||
|
@ -388,6 +364,10 @@ public class IndexView extends ViewPart implements PDOM.IListener {
|
|||
private void fillContextMenu(IMenuManager manager) {
|
||||
if (rebuildAction.valid())
|
||||
manager.add(rebuildAction);
|
||||
if (countSymbolsAction.valid())
|
||||
manager.add(countSymbolsAction);
|
||||
if (setFastIndexAction.valid())
|
||||
manager.add(setFastIndexAction);
|
||||
if (discardExternalDefsAction.valid())
|
||||
manager.add(discardExternalDefsAction);
|
||||
if (openDefinitionAction.valid())
|
||||
|
|
|
@ -12,12 +12,7 @@
|
|||
package org.eclipse.cdt.internal.ui.indexview;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
|
||||
/**
|
||||
|
@ -31,34 +26,11 @@ public class RebuildIndexAction extends IndexAction {
|
|||
}
|
||||
|
||||
public void run() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
if (!(selection instanceof IStructuredSelection))
|
||||
return;
|
||||
|
||||
Object[] objs = ((IStructuredSelection)selection).toArray();
|
||||
for (int i = 0; i < objs.length; ++i) {
|
||||
if (!(objs[i] instanceof ICProject))
|
||||
continue;
|
||||
|
||||
ICProject project = (ICProject)objs[i];
|
||||
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(project);
|
||||
try {
|
||||
pdom.getIndexer().reindex();
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
CCorePlugin.getPDOMManager().reindex();
|
||||
}
|
||||
|
||||
public boolean valid() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
if (!(selection instanceof IStructuredSelection))
|
||||
return false;
|
||||
Object[] objs = ((IStructuredSelection)selection).toArray();
|
||||
for (int i = 0; i < objs.length; ++i)
|
||||
if (objs[i] instanceof ICProject)
|
||||
return true;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.eclipse.cdt.internal.ui.indexview;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.fast.PDOMFastIndexer;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
|
||||
/**
|
||||
* Sets all selected actions to use the Fast indexer.
|
||||
*
|
||||
* @author dschaefer
|
||||
*/
|
||||
public class SetFastIndexerAction extends IndexAction {
|
||||
|
||||
public SetFastIndexerAction(TreeViewer viewer) {
|
||||
super(viewer, CUIPlugin.getResourceString("IndexView.setFastIndexer.name"));
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
IPDOMManager manager = CCorePlugin.getPDOMManager();
|
||||
ICProject[] projects = CoreModel.getDefault().getCModel().getCProjects();
|
||||
for (int i = 0; i < projects.length; ++i) {
|
||||
try {
|
||||
manager.setIndexerId(projects[i], PDOMFastIndexer.ID);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean valid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,6 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
@ -62,16 +61,15 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
|||
|
||||
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||
try {
|
||||
for (int i = 0; i < projects.length; ++i)
|
||||
searchProject(projects[i], monitor);
|
||||
searchIndex(monitor);
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private void searchProject(ICProject project, IProgressMonitor monitor) throws CoreException {
|
||||
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(project);
|
||||
private void searchIndex(IProgressMonitor monitor) throws CoreException {
|
||||
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM();
|
||||
|
||||
try {
|
||||
pdom.acquireReadLock();
|
||||
|
|
|
@ -117,19 +117,17 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
|||
|
||||
protected void createMatches(ILanguage language, IBinding binding) throws CoreException {
|
||||
IPDOMManager manager = CCorePlugin.getPDOMManager();
|
||||
for (int i = 0; i < projects.length; ++i) {
|
||||
PDOM pdom = (PDOM)manager.getPDOM(projects[i]);
|
||||
PDOMBinding pdomBinding = (PDOMBinding)pdom.getLinkage(language).adaptBinding(binding);
|
||||
if (pdomBinding != null) {
|
||||
if ((flags & FIND_DECLARATIONS) != 0) {
|
||||
collectNames(pdomBinding.getFirstDeclaration());
|
||||
}
|
||||
if ((flags & FIND_DECLARATIONS) != 0) {
|
||||
collectNames(pdomBinding.getFirstDefinition());
|
||||
}
|
||||
if ((flags & FIND_REFERENCES) != 0) {
|
||||
collectNames(pdomBinding.getFirstReference());
|
||||
}
|
||||
PDOM pdom = (PDOM)manager.getPDOM();
|
||||
PDOMBinding pdomBinding = (PDOMBinding)pdom.getLinkage(language).adaptBinding(binding);
|
||||
if (pdomBinding != null) {
|
||||
if ((flags & FIND_DECLARATIONS) != 0) {
|
||||
collectNames(pdomBinding.getFirstDeclaration());
|
||||
}
|
||||
if ((flags & FIND_DECLARATIONS) != 0) {
|
||||
collectNames(pdomBinding.getFirstDefinition());
|
||||
}
|
||||
if ((flags & FIND_REFERENCES) != 0) {
|
||||
collectNames(pdomBinding.getFirstReference());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public class PDOMCompletionContributor extends DOMCompletionContributor implemen
|
|||
return;
|
||||
|
||||
try {
|
||||
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject());
|
||||
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM();
|
||||
IASTName[] names = completionNode.getNames();
|
||||
for (int i = 0; i < names.length; ++i) {
|
||||
IASTName name = names[i];
|
||||
|
|
|
@ -206,7 +206,7 @@ public class CTagsIndexerBlock extends AbstractIndexerPage {
|
|||
}
|
||||
|
||||
public void loadPersistedValues(ICProject project) throws CoreException {
|
||||
IPDOMIndexer indexer = CCorePlugin.getPDOMManager().getPDOM(project).getIndexer();
|
||||
IPDOMIndexer indexer = CCorePlugin.getPDOMManager().getIndexer(project);
|
||||
if (!(indexer instanceof CtagsIndexer))
|
||||
throw new CoreException(new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, "Wrong indexer", null));
|
||||
ctagsIndexer = (CtagsIndexer)indexer;
|
||||
|
|
Loading…
Add table
Reference in a new issue