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

Extends IIndex-API to allow for searching across linkage boundaries.

This commit is contained in:
Markus Schorn 2007-11-28 14:30:05 +00:00
parent b2de7b53e3
commit 911444625c
19 changed files with 250 additions and 147 deletions

View file

@ -34,17 +34,11 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class EmptyIndexFragment implements IIndexFragment { public class EmptyIndexFragment implements IIndexFragment {
public void acquireReadLock() throws InterruptedException {} public void acquireReadLock() throws InterruptedException {}
public IIndexFragmentBinding adaptBinding(IBinding binding) public IIndexFragmentBinding adaptBinding(IBinding binding) {
throws CoreException {
return null; return null;
} }
public IIndexFragmentBinding adaptBinding(IIndexFragmentBinding proxy) public IIndexFragmentBinding findBinding(IASTName astName) {
throws CoreException {
return null;
}
public IIndexFragmentBinding findBinding(IASTName astName) throws CoreException {
return null; return null;
} }
@ -74,8 +68,7 @@ public class EmptyIndexFragment implements IIndexFragment {
return IIndexFragmentInclude.EMPTY_FRAGMENT_INCLUDES_ARRAY; return IIndexFragmentInclude.EMPTY_FRAGMENT_INCLUDES_ARRAY;
} }
public IIndexFragmentName[] findNames(IIndexFragmentBinding binding, public IIndexFragmentName[] findNames(IBinding binding, int flags) {
int flags) throws CoreException {
return IIndexFragmentName.EMPTY_NAME_ARRAY; return IIndexFragmentName.EMPTY_NAME_ARRAY;
} }

View file

@ -258,13 +258,13 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
IndexFilter CLinkage= new IndexFilter() { IndexFilter CLinkage= new IndexFilter() {
public boolean acceptLinkage(ILinkage linkage) { public boolean acceptLinkage(ILinkage linkage) {
return linkage.getID().equals(ILinkage.C_LINKAGE_ID); return linkage.getLinkageID() == ILinkage.C_LINKAGE_ID;
} }
}; };
IndexFilter CPPLinkage= new IndexFilter() { IndexFilter CPPLinkage= new IndexFilter() {
public boolean acceptLinkage(ILinkage linkage) { public boolean acceptLinkage(ILinkage linkage) {
return linkage.getID().equals(ILinkage.CPP_LINKAGE_ID); return linkage.getLinkageID() == ILinkage.CPP_LINKAGE_ID;
} }
}; };

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests; package org.eclipse.cdt.internal.pdom.tests;
@ -20,16 +20,12 @@ import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexLocationConverter; import org.eclipse.cdt.core.index.IIndexLocationConverter;
import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.index.ResourceContainerRelativeLocationConverter; import org.eclipse.cdt.core.index.ResourceContainerRelativeLocationConverter;
import org.eclipse.cdt.core.language.ProjectLanguageConfiguration;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
@ -47,8 +43,6 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
/** /**
* Tests bugs found in the PDOM * Tests bugs found in the PDOM
@ -208,21 +202,14 @@ public class PDOMCPPBugsTest extends BaseTestCase {
pdom.releaseWriteLock(); pdom.releaseWriteLock();
} }
public void _test191679() throws Exception { public void test191679() throws Exception {
IProject project= cproject.getProject(); IProject project= cproject.getProject();
IFolder cHeaders= cproject.getProject().getFolder("cHeaders"); IFolder cHeaders= cproject.getProject().getFolder("cHeaders");
cHeaders.create(true, true, NPM); cHeaders.create(true, true, NPM);
LanguageManager lm= LanguageManager.getInstance(); LanguageManager lm= LanguageManager.getInstance();
IFile cHeader= TestSourceReader.createFile(cHeaders, "cHeader.h", "extern \"C\" void foo(int i) {}\n"); IFile cHeader= TestSourceReader.createFile(cHeaders, "cSource.c", "void foo(int i){}");
ICProjectDescription pd= CCorePlugin.getDefault().getProjectDescription(project); IFile cppSource= TestSourceReader.createFile(cHeaders, "cppSource.cpp", "extern \"C\" void foo(int i); void ref() {foo(1);}");
ICConfigurationDescription cfgd= pd.getDefaultSettingConfiguration();
ProjectLanguageConfiguration plc= LanguageManager.getInstance().getLanguageConfiguration(project);
plc.addFileMapping(cfgd, cHeader, GCCLanguage.ID);
IContentType ct= Platform.getContentTypeManager().getContentType(CCorePlugin.CONTENT_TYPE_CHEADER);
lm.storeLanguageMappingConfiguration(project, new IContentType[] {ct});
IFile cppSource= TestSourceReader.createFile(cHeaders, "cppSource.cpp", "void ref() {foo(1);}");
IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER); IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER);
CCorePlugin.getIndexManager().reindex(cproject); CCorePlugin.getIndexManager().reindex(cproject);
@ -233,14 +220,29 @@ public class PDOMCPPBugsTest extends BaseTestCase {
try { try {
{ // test reference to 'foo' was resolved correctly { // test reference to 'foo' was resolved correctly
IIndexBinding[] ib= pdom.findBindings(new char[][]{"foo".toCharArray()}, IndexFilter.ALL, NPM); IIndexBinding[] ib= pdom.findBindings(new char[][]{"foo".toCharArray()}, IndexFilter.ALL, NPM);
assertEquals(1, ib.length); assertEquals(2, ib.length);
if (ib[0] instanceof ICPPBinding) {
IIndexBinding h= ib[0]; ib[0]= ib[1]; ib[1]= h;
}
assertTrue(ib[0] instanceof IFunction); assertTrue(ib[0] instanceof IFunction);
assertTrue(!(ib[0] instanceof ICPPBinding)); assertFalse(ib[0] instanceof ICPPBinding);
IName[] nms= pdom.findNames(ib[0], IIndexFragment.FIND_REFERENCES); assertTrue(ib[1] instanceof IFunction);
assertTrue(ib[1] instanceof ICPPBinding);
IName[] nms= pdom.findNames(ib[0], IIndexFragment.FIND_REFERENCES | IIndexFragment.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
assertEquals(1, nms.length); assertEquals(1, nms.length);
assertTrue(nms[0].getFileLocation().getFileName().endsWith(".cpp")); assertTrue(nms[0].getFileLocation().getFileName().endsWith(".cpp"));
nms= pdom.findNames(ib[0], IIndexFragment.FIND_REFERENCES);
assertEquals(0, nms.length);
nms= pdom.findNames(ib[1], IIndexFragment.FIND_DEFINITIONS | IIndexFragment.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
assertEquals(1, nms.length);
assertTrue(nms[0].getFileLocation().getFileName().endsWith(".c"));
nms= pdom.findNames(ib[1], IIndexFragment.FIND_DEFINITIONS);
assertEquals(0, nms.length);
} }
} finally { } finally {
pdom.releaseReadLock(); pdom.releaseReadLock();

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -22,10 +22,23 @@ package org.eclipse.cdt.core.dom;
* @since 4.0 * @since 4.0
*/ */
public interface ILinkage { public interface ILinkage {
final static String NO_LINKAGE_ID= "none"; //$NON-NLS-1$ final static String NO_LINKAGE_NAME= "none"; //$NON-NLS-1$
final static String C_LINKAGE_ID= "C"; //$NON-NLS-1$ final static String C_LINKAGE_NAME= "C"; //$NON-NLS-1$
final static String CPP_LINKAGE_ID= "C++"; //$NON-NLS-1$ final static String CPP_LINKAGE_NAME= "C++"; //$NON-NLS-1$
final static String FORTRAN_LINKAGE_ID= "Fortran"; //$NON-NLS-1$ final static String FORTRAN_LINKAGE_NAME= "Fortran"; //$NON-NLS-1$
String getID(); final static int NO_LINKAGE_ID= 0;
final static int C_LINKAGE_ID= 1;
final static int CPP_LINKAGE_ID= 2;
final static int FORTRAN_LINKAGE_ID= 3;
/**
* Returns the name of the linkage.
*/
String getLinkageName();
/**
* Returns a unique id for the linkage.
*/
int getLinkageID();
} }

View file

@ -37,6 +37,7 @@ public interface ICPPFunction extends IFunction, ICPPBinding {
/** /**
* Returns whether this function is declared as extern "C". * Returns whether this function is declared as extern "C".
* @since 5.0
*/ */
public boolean isExternC() throws DOMException; public boolean isExternC() throws DOMException;
} }

View file

@ -62,6 +62,12 @@ public interface IIndex {
* Constant to search for all declarations including definitions. * Constant to search for all declarations including definitions.
*/ */
final int FIND_REFERENCES = 0x4; final int FIND_REFERENCES = 0x4;
/**
* Constant to search for occurrences across language boundaries.
* You can use it to find the occurrences of a c++-function declared with 'extern "C"' within
* the c-linkage.
*/
final int SEARCH_ACCROSS_LANGUAGE_BOUNDARIES= 0x8;
/** /**
* Constant to search for references. This does not include declarations or definitions. * Constant to search for references. This does not include declarations or definitions.
*/ */
@ -293,7 +299,8 @@ public interface IIndex {
* Searches for all names that resolve to the given binding. You can limit the result to references, declarations * Searches for all names that resolve to the given binding. You can limit the result to references, declarations
* or definitions, or a combination of those. * or definitions, or a combination of those.
* @param binding a binding for which names are searched for * @param binding a binding for which names are searched for
* @param flags a combination of {@link #FIND_DECLARATIONS}, {@link #FIND_DEFINITIONS} and {@link #FIND_REFERENCES} * @param flags a combination of {@link #FIND_DECLARATIONS}, {@link #FIND_DEFINITIONS},
* {@link #FIND_REFERENCES} and {@link #SEARCH_ACCROSS_LANGUAGE_BOUNDARIES}.
* @return an array of names * @return an array of names
* @throws CoreException * @throws CoreException
*/ */

View file

@ -31,8 +31,8 @@ import org.eclipse.core.runtime.CoreException;
abstract public class IndexFilter { abstract public class IndexFilter {
public static final IndexFilter ALL = new IndexFilter() {}; public static final IndexFilter ALL = new IndexFilter() {};
public static final IndexFilter ALL_DECLARED = getDeclaredBindingFilter(null, false); public static final IndexFilter ALL_DECLARED = getDeclaredBindingFilter(-1, false);
public static final IndexFilter ALL_DECLARED_OR_IMPLICIT = getDeclaredBindingFilter(null, true); public static final IndexFilter ALL_DECLARED_OR_IMPLICIT = getDeclaredBindingFilter(-1, true);
public static final IndexFilter CPP_DECLARED_OR_IMPLICIT= getDeclaredBindingFilter(ILinkage.CPP_LINKAGE_ID, true); public static final IndexFilter CPP_DECLARED_OR_IMPLICIT= getDeclaredBindingFilter(ILinkage.CPP_LINKAGE_ID, true);
public static final IndexFilter C_DECLARED_OR_IMPLICIT= getDeclaredBindingFilter(ILinkage.C_LINKAGE_ID, true); public static final IndexFilter C_DECLARED_OR_IMPLICIT= getDeclaredBindingFilter(ILinkage.C_LINKAGE_ID, true);
@ -42,10 +42,10 @@ abstract public class IndexFilter {
* @param linkageID the id of the linkage whose bindings should be retained * @param linkageID the id of the linkage whose bindings should be retained
* @return an IndexFilter instance * @return an IndexFilter instance
*/ */
public static IndexFilter getFilter(final String linkageID) { public static IndexFilter getFilter(final int linkageID) {
return new IndexFilter() { return new IndexFilter() {
public boolean acceptLinkage(ILinkage linkage) { public boolean acceptLinkage(ILinkage linkage) {
return linkageID.equals(linkage.getID()); return linkageID == linkage.getLinkageID();
} }
}; };
} }
@ -53,10 +53,11 @@ abstract public class IndexFilter {
/** /**
* Get an IndexFilter that filters out bindings without declarations and those * Get an IndexFilter that filters out bindings without declarations and those
* from linkages other than that specified. * from linkages other than that specified.
* @param linkageID the id of the linkage whose bindings should be retained * @param linkageID the id of the linkage whose bindings should be retained, or -1
* to accept all linkages.
* @return an IndexFilter instance * @return an IndexFilter instance
*/ */
public static IndexFilter getDeclaredBindingFilter(final String linkageID, boolean acceptImplicit) { public static IndexFilter getDeclaredBindingFilter(final int linkageID, boolean acceptImplicit) {
return new DeclaredBindingsFilter(linkageID, acceptImplicit); return new DeclaredBindingsFilter(linkageID, acceptImplicit);
} }

View file

@ -15,10 +15,10 @@ import org.eclipse.cdt.core.dom.ILinkage;
public class Linkage implements ILinkage { public class Linkage implements ILinkage {
public static final ILinkage NO_LINKAGE = new Linkage(NO_LINKAGE_ID); public static final ILinkage NO_LINKAGE = new Linkage(NO_LINKAGE_ID, NO_LINKAGE_NAME);
public static final ILinkage C_LINKAGE = new Linkage(C_LINKAGE_ID); public static final ILinkage C_LINKAGE = new Linkage(C_LINKAGE_ID, C_LINKAGE_NAME);
public static final ILinkage CPP_LINKAGE = new Linkage(CPP_LINKAGE_ID); public static final ILinkage CPP_LINKAGE = new Linkage(CPP_LINKAGE_ID, CPP_LINKAGE_NAME);
public static final ILinkage FORTRAN_LINKAGE = new Linkage(FORTRAN_LINKAGE_ID); public static final ILinkage FORTRAN_LINKAGE = new Linkage(FORTRAN_LINKAGE_ID, FORTRAN_LINKAGE_NAME);
private static final ILinkage[] LINKAGES= {C_LINKAGE, CPP_LINKAGE, FORTRAN_LINKAGE}; private static final ILinkage[] LINKAGES= {C_LINKAGE, CPP_LINKAGE, FORTRAN_LINKAGE};
@ -26,11 +26,16 @@ public class Linkage implements ILinkage {
return LINKAGES; return LINKAGES;
} }
private String fID; private int fID;
private Linkage(String id) { private String fName;
private Linkage(int id, String name) {
fID= id; fID= id;
fName= name;
} }
public String getID() { public int getLinkageID() {
return fID; return fID;
} }
public String getLinkageName() {
return fName;
}
} }

View file

@ -78,7 +78,7 @@ public class CIndex implements IIndex {
for (int i = 0; i < fPrimaryFragmentCount; i++) { for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexFragmentBinding binding= fFragments[i].findBinding((IASTName) name); IIndexFragmentBinding binding= fFragments[i].findBinding((IASTName) name);
if(binding!=null) { if(binding!=null) {
return getCompositesFactory(binding.getLinkage().getID()).getCompositeBinding(binding); return getCompositesFactory(binding.getLinkage().getLinkageID()).getCompositeBinding(binding);
} }
} }
} }
@ -109,7 +109,7 @@ public class CIndex implements IIndex {
fragmentBindings[i] = IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; fragmentBindings[i] = IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
} }
} }
ICompositesFactory factory = getCompositesFactory(linkages[j].getID()); ICompositesFactory factory = getCompositesFactory(linkages[j].getLinkageID());
result.add(factory.getCompositeBindings(fragmentBindings)); result.add(factory.getCompositeBindings(fragmentBindings));
} }
} }
@ -121,13 +121,10 @@ public class CIndex implements IIndex {
LinkedList result= new LinkedList(); LinkedList result= new LinkedList();
int fragCount= 0; int fragCount= 0;
for (int i = 0; i < fPrimaryFragmentCount; i++) { for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexFragmentBinding adaptedBinding= fFragments[i].adaptBinding(binding); final IIndexFragmentName[] names = fFragments[i].findNames(binding, flags);
if (adaptedBinding != null) { if (names.length > 0) {
final IIndexFragmentName[] names = fFragments[i].findNames(adaptedBinding, flags); result.addAll(Arrays.asList(names));
if (names.length > 0) { fragCount++;
result.addAll(Arrays.asList(names));
fragCount++;
}
} }
} }
// bug 192352, files can reside in multiple fragments, remove duplicates // bug 192352, files can reside in multiple fragments, remove duplicates
@ -333,7 +330,7 @@ public class CIndex implements IIndex {
fragmentBindings[i] = IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; fragmentBindings[i] = IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
} }
} }
ICompositesFactory factory = getCompositesFactory(linkages[j].getID()); ICompositesFactory factory = getCompositesFactory(linkages[j].getLinkageID());
result.add(factory.getCompositeBindings(fragmentBindings)); result.add(factory.getCompositeBindings(fragmentBindings));
} }
} }
@ -351,7 +348,7 @@ public class CIndex implements IIndex {
for (int i = 0; i < fPrimaryFragmentCount; i++) { for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexFragmentBinding adaptedBinding= fFragments[i].adaptBinding(binding); IIndexFragmentBinding adaptedBinding= fFragments[i].adaptBinding(binding);
if (adaptedBinding != null) { if (adaptedBinding != null) {
return getCompositesFactory(binding.getLinkage().getID()).getCompositeBinding(adaptedBinding); return getCompositesFactory(binding.getLinkage().getLinkageID()).getCompositeBinding(adaptedBinding);
} }
} }
} }
@ -401,20 +398,21 @@ public class CIndex implements IIndex {
return (IIndexFragmentBinding[]) result.toArray(new IIndexFragmentBinding[result.size()]); return (IIndexFragmentBinding[]) result.toArray(new IIndexFragmentBinding[result.size()]);
} }
private ICompositesFactory getCompositesFactory(String linkageID) { private ICompositesFactory getCompositesFactory(int linkageID) {
if(linkageID.equals(ILinkage.CPP_LINKAGE_ID)) { switch (linkageID) {
case ILinkage.CPP_LINKAGE_ID:
if(cppCF==null) { if(cppCF==null) {
cppCF = new CPPCompositesFactory(new CIndex(fFragments, fFragments.length)); cppCF = new CPPCompositesFactory(new CIndex(fFragments, fFragments.length));
} }
return cppCF; return cppCF;
}
if(linkageID.equals(ILinkage.C_LINKAGE_ID)) { case ILinkage.C_LINKAGE_ID:
if(cCF==null) { if(cCF==null) {
cCF = new CCompositesFactory(new CIndex(fFragments, fFragments.length)); cCF = new CCompositesFactory(new CIndex(fFragments, fFragments.length));
} }
return cCF; return cCF;
}
if(linkageID.equals(ILinkage.FORTRAN_LINKAGE_ID)) { case ILinkage.FORTRAN_LINKAGE_ID:
if(fCF==null) { if(fCF==null) {
fCF = new CCompositesFactory(new CIndex(fFragments, fFragments.length)); fCF = new CCompositesFactory(new CIndex(fFragments, fFragments.length));
} }
@ -431,7 +429,7 @@ public class CIndex implements IIndex {
return filter.acceptBinding(binding); return filter.acceptBinding(binding);
} }
public boolean acceptLinkage(ILinkage other) { public boolean acceptLinkage(ILinkage other) {
return linkage.getID().equals(other.getID()); return linkage.getLinkageID() == other.getLinkageID();
} }
}; };
} }
@ -455,7 +453,7 @@ public class CIndex implements IIndex {
fragmentBindings[i] = IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; fragmentBindings[i] = IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
} }
} }
ICompositesFactory factory = getCompositesFactory(linkages[j].getID()); ICompositesFactory factory = getCompositesFactory(linkages[j].getLinkageID());
result.add(factory.getCompositeBindings(fragmentBindings)); result.add(factory.getCompositeBindings(fragmentBindings));
} }
} }

View file

@ -18,20 +18,20 @@ import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
public class DeclaredBindingsFilter extends IndexFilter { public class DeclaredBindingsFilter extends IndexFilter {
final private String fLinkageID; final private int fLinkageID;
final private boolean fAcceptImplicit; final private boolean fAcceptImplicit;
public DeclaredBindingsFilter() { public DeclaredBindingsFilter() {
this(null, false); this(-1, false);
} }
public DeclaredBindingsFilter(String linkageID, boolean acceptImplicit) { public DeclaredBindingsFilter(int linkageID, boolean acceptImplicit) {
fLinkageID= linkageID; fLinkageID= linkageID;
fAcceptImplicit= acceptImplicit; fAcceptImplicit= acceptImplicit;
} }
public boolean acceptLinkage(ILinkage linkage) { public boolean acceptLinkage(ILinkage linkage) {
return fLinkageID == null || fLinkageID.equals(linkage.getID()); return fLinkageID == -1 || fLinkageID == linkage.getLinkageID();
} }
public boolean acceptBinding(IBinding binding) throws CoreException { public boolean acceptBinding(IBinding binding) throws CoreException {

View file

@ -43,6 +43,10 @@ public interface IIndexFragment {
* @see IIndex#FIND_REFERENCES * @see IIndex#FIND_REFERENCES
*/ */
final int FIND_REFERENCES = IIndex.FIND_REFERENCES; final int FIND_REFERENCES = IIndex.FIND_REFERENCES;
/**
* @see IIndex#SEARCH_ACCROSS_LANGUAGE_BOUNDARIES
*/
final int SEARCH_ACCROSS_LANGUAGE_BOUNDARIES= IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES;
/** /**
* @see IIndex#FIND_DECLARATIONS_DEFINITIONS * @see IIndex#FIND_DECLARATIONS_DEFINITIONS
*/ */
@ -89,7 +93,7 @@ public interface IIndexFragment {
* another fragment. All of the include directives returned must belong to files managed by * another fragment. All of the include directives returned must belong to files managed by
* this fragment. * this fragment.
* @param file a file to search for includes pointing to it * @param file a file to search for includes pointing to it
* @return an array of inlucde directives managed by this fragment * @return an array of include directives managed by this fragment
* @throws CoreException * @throws CoreException
*/ */
IIndexFragmentInclude[] findIncludedBy(IIndexFragmentFile file) throws CoreException; IIndexFragmentInclude[] findIncludedBy(IIndexFragmentFile file) throws CoreException;
@ -103,15 +107,6 @@ public interface IIndexFragment {
*/ */
IIndexFragmentBinding adaptBinding(IBinding binding) throws CoreException; IIndexFragmentBinding adaptBinding(IBinding binding) throws CoreException;
/**
* Looks for a proxy binding matching the given one. May return <code>null</code>, if no
* such binding exists. The binding may belong to another index fragment.
* @param proxy the binding to look for.
* @return the binding, or <code>null</code>
* @throws CoreException
*/
IIndexFragmentBinding adaptBinding(IIndexFragmentBinding proxy) throws CoreException;
/** /**
* Looks for a binding of the given name from the AST. May return <code>null</code>, if no * Looks for a binding of the given name from the AST. May return <code>null</code>, if no
* such binding exists. * such binding exists.
@ -153,7 +148,7 @@ public interface IIndexFragment {
* @return an array of names * @return an array of names
* @throws CoreException * @throws CoreException
*/ */
IIndexFragmentName[] findNames(IIndexFragmentBinding binding, int flags) throws CoreException; IIndexFragmentName[] findNames(IBinding binding, int flags) throws CoreException;
/** /**
* Acquires a read lock. * Acquires a read lock.

View file

@ -31,8 +31,15 @@ import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexLinkage; import org.eclipse.cdt.core.index.IIndexLinkage;
@ -40,6 +47,7 @@ import org.eclipse.cdt.core.index.IIndexLocationConverter;
import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
@ -75,7 +83,7 @@ import org.eclipse.core.runtime.Status;
* *
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { public class PDOM extends PlatformObject implements IPDOM {
/** /**
* Identifier for PDOM format * Identifier for PDOM format
* @see IIndexFragment#PROPERTY_FRAGMENT_FORMAT_ID * @see IIndexFragment#PROPERTY_FRAGMENT_FORMAT_ID
@ -499,7 +507,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
} }
} }
public PDOMLinkage getLinkage(String linkageID) throws CoreException { public PDOMLinkage getLinkage(String linkageID) {
return (PDOMLinkage) fLinkageIDCache.get(linkageID); return (PDOMLinkage) fLinkageIDCache.get(linkageID);
} }
@ -549,7 +557,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
public void insertLinkage(PDOMLinkage linkage) throws CoreException { public void insertLinkage(PDOMLinkage linkage) throws CoreException {
linkage.setNext(db.getInt(LINKAGES)); linkage.setNext(db.getInt(LINKAGES));
db.putInt(LINKAGES, linkage.getRecord()); db.putInt(LINKAGES, linkage.getRecord());
fLinkageIDCache.put(linkage.getID(), linkage); fLinkageIDCache.put(linkage.getLinkageName(), linkage);
} }
public PDOMBinding getBinding(int record) throws CoreException { public PDOMBinding getBinding(int record) throws CoreException {
@ -670,10 +678,13 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
} }
protected PDOMLinkage adaptLinkage(ILinkage linkage) throws CoreException { protected PDOMLinkage adaptLinkage(ILinkage linkage) throws CoreException {
return (PDOMLinkage) fLinkageIDCache.get(linkage.getID()); return (PDOMLinkage) fLinkageIDCache.get(linkage.getLinkageName());
} }
public IIndexFragmentBinding adaptBinding(IBinding binding) throws CoreException { public IIndexFragmentBinding adaptBinding(IBinding binding) throws CoreException {
if (binding == null) {
return null;
}
PDOMBinding pdomBinding= (PDOMBinding) binding.getAdapter(PDOMBinding.class); PDOMBinding pdomBinding= (PDOMBinding) binding.getAdapter(PDOMBinding.class);
if (pdomBinding != null && pdomBinding.getPDOM() == this) { if (pdomBinding != null && pdomBinding.getPDOM() == this) {
return pdomBinding; return pdomBinding;
@ -686,13 +697,6 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
return null; return null;
} }
public IIndexFragmentBinding adaptBinding(IIndexFragmentBinding binding) throws CoreException {
if (binding != null) {
return adaptBinding((IBinding) binding);
}
return null;
}
public IIndexFragmentBinding findBinding(IIndexFragmentName indexName) throws CoreException { public IIndexFragmentBinding findBinding(IIndexFragmentName indexName) throws CoreException {
if (indexName instanceof PDOMName) { if (indexName instanceof PDOMName) {
PDOMName pdomName= (PDOMName) indexName; PDOMName pdomName= (PDOMName) indexName;
@ -702,37 +706,39 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
} }
public IIndexFragmentName[] findNames(IBinding binding, int options) throws CoreException { public IIndexFragmentName[] findNames(IBinding binding, int options) throws CoreException {
IIndexFragmentBinding proxyBinding= adaptBinding(binding); ArrayList names= new ArrayList();
if (proxyBinding != null) { PDOMBinding pdomBinding = (PDOMBinding) adaptBinding(binding);
return findNames(proxyBinding, options); if (pdomBinding != null) {
names= new ArrayList();
findNamesForMyBinding(pdomBinding, options, names);
} }
return IIndexFragmentName.EMPTY_NAME_ARRAY; if ((options & SEARCH_ACCROSS_LANGUAGE_BOUNDARIES) != 0) {
PDOMBinding[] xlangBindings= getCrossLanguageBindings(binding);
for (int j = 0; j < xlangBindings.length; j++) {
findNamesForMyBinding(xlangBindings[j], options, names);
}
}
return (IIndexFragmentName[]) names.toArray(new IIndexFragmentName[names.size()]);
} }
public IIndexFragmentName[] findNames(IIndexFragmentBinding binding, int options) throws CoreException { private void findNamesForMyBinding(PDOMBinding pdomBinding, int options, ArrayList names)
PDOMBinding pdomBinding = (PDOMBinding) adaptBinding(binding); throws CoreException {
PDOMName name;
if (pdomBinding != null) { if ((options & FIND_DECLARATIONS) != 0) {
PDOMName name; for (name= pdomBinding.getFirstDeclaration(); name != null; name= name.getNextInBinding()) {
List names = new ArrayList(); names.add(name);
if ((options & FIND_DECLARATIONS) != 0) { }
for (name= pdomBinding.getFirstDeclaration(); name != null; name= name.getNextInBinding()) { }
names.add(name); if ((options & FIND_DEFINITIONS) != 0) {
} for (name = pdomBinding.getFirstDefinition(); name != null; name= name.getNextInBinding()) {
names.add(name);
}
}
if ((options & FIND_REFERENCES) != 0) {
for (name = pdomBinding.getFirstReference(); name != null; name= name.getNextInBinding()) {
names.add(name);
} }
if ((options & FIND_DEFINITIONS) != 0) {
for (name = pdomBinding.getFirstDefinition(); name != null; name= name.getNextInBinding()) {
names.add(name);
}
}
if ((options & FIND_REFERENCES) != 0) {
for (name = pdomBinding.getFirstReference(); name != null; name= name.getNextInBinding()) {
names.add(name);
}
}
return (IIndexFragmentName[]) names.toArray(new IIndexFragmentName[names.size()]);
} }
return IIndexFragmentName.EMPTY_NAME_ARRAY;
} }
public IIndexFragmentInclude[] findIncludedBy(IIndexFragmentFile file) throws CoreException { public IIndexFragmentInclude[] findIncludedBy(IIndexFragmentFile file) throws CoreException {
@ -872,4 +878,82 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
public String createKeyForCache(int record, char[] name) { public String createKeyForCache(int record, char[] name) {
return new StringBuffer(name.length+2).append((char) (record >> 16)).append((char) record).append(name).toString(); return new StringBuffer(name.length+2).append((char) (record >> 16)).append((char) record).append(name).toString();
} }
private PDOMBinding[] getCrossLanguageBindings(IBinding binding) throws CoreException {
switch(binding.getLinkage().getLinkageID()) {
case ILinkage.C_LINKAGE_ID:
return getCPPBindingForC(binding);
case ILinkage.CPP_LINKAGE_ID:
return getCBindingForCPP(binding);
}
return PDOMBinding.EMPTY_PDOMBINDING_ARRAY;
}
private PDOMBinding[] getCBindingForCPP(IBinding binding) throws CoreException {
PDOMBinding result= null;
PDOMLinkage c= getLinkage(ILinkage.C_LINKAGE_NAME);
if (c == null) {
return PDOMBinding.EMPTY_PDOMBINDING_ARRAY;
}
try {
if (binding instanceof ICPPFunction) {
ICPPFunction func = (ICPPFunction) binding;
if (func.isExternC()) {
result = FindBinding.findBinding(c.getIndex(), this, func.getNameCharArray(),
new int[] { IIndexCBindingConstants.CFUNCTION });
}
} else if (binding instanceof ICPPVariable) {
ICPPVariable var = (ICPPVariable) binding;
if (var.isExternC()) {
result = FindBinding.findBinding(c.getIndex(), this, var.getNameCharArray(),
new int[] { IIndexCBindingConstants.CVARIABLE });
}
}
} catch (DOMException e) {
}
return result == null ? PDOMBinding.EMPTY_PDOMBINDING_ARRAY : new PDOMBinding[] {result};
}
private PDOMBinding[] getCPPBindingForC(IBinding binding) throws CoreException {
PDOMLinkage cpp= getLinkage(ILinkage.CPP_LINKAGE_NAME);
if (cpp == null) {
return PDOMBinding.EMPTY_PDOMBINDING_ARRAY;
}
IndexFilter filter= null;
if (binding instanceof IFunction) {
filter= new IndexFilter() {
public boolean acceptBinding(IBinding binding) {
try {
if (binding instanceof ICPPFunction) {
return ((ICPPFunction) binding).isExternC();
}
} catch (DOMException e) {
}
return false;
}
};
} else if (binding instanceof IVariable) {
if (!(binding instanceof IField) && !(binding instanceof IParameter)) {
filter= new IndexFilter() {
public boolean acceptBinding(IBinding binding) {
try {
if (binding instanceof ICPPVariable) {
return ((ICPPVariable) binding).isExternC();
}
} catch (DOMException e) {
}
return false;
}
};
}
}
if (filter != null) {
BindingCollector collector= new BindingCollector(cpp, binding.getNameCharArray(), filter, false, true);
cpp.accept(collector);
return collector.getBindings();
}
return PDOMBinding.EMPTY_PDOMBINDING_ARRAY;
}
} }

View file

@ -61,12 +61,6 @@ public class PDOMProxy implements IPDOM {
return null; return null;
} }
public synchronized IIndexFragmentBinding adaptBinding(IIndexFragmentBinding proxy) throws CoreException {
if (fDelegate != null)
return fDelegate.adaptBinding(proxy);
return null;
}
public synchronized IIndexFragmentBinding findBinding(IASTName astName) throws CoreException { public synchronized IIndexFragmentBinding findBinding(IASTName astName) throws CoreException {
if (fDelegate != null) if (fDelegate != null)
return fDelegate.findBinding(astName); return fDelegate.findBinding(astName);
@ -104,7 +98,7 @@ public class PDOMProxy implements IPDOM {
return new IIndexFragmentInclude[0]; return new IIndexFragmentInclude[0];
} }
public synchronized IIndexFragmentName[] findNames(IIndexFragmentBinding binding, int flags) public synchronized IIndexFragmentName[] findNames(IBinding binding, int flags)
throws CoreException { throws CoreException {
if (fDelegate != null) if (fDelegate != null)
return fDelegate.findNames(binding, flags); return fDelegate.findNames(binding, flags);

View file

@ -79,7 +79,7 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
public PDOMBinding addBinding(IASTName name) throws CoreException { public PDOMBinding addBinding(IASTName name) throws CoreException {
PDOMBinding result= null; PDOMBinding result= null;
PDOMLinkage linkage= createLinkage(name.getLinkage().getID()); PDOMLinkage linkage= createLinkage(name.getLinkage().getLinkageName());
if (linkage == null) { if (linkage == null) {
CCorePlugin.log(MessageFormat.format(Messages.WritablePDOM_error_unknownLinkage, new Object[]{name.getLinkage()})); CCorePlugin.log(MessageFormat.format(Messages.WritablePDOM_error_unknownLinkage, new Object[]{name.getLinkage()}));
} }

View file

@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom; package org.eclipse.cdt.internal.core.pdom.dom;
@ -42,7 +42,7 @@ public final class BindingCollector extends NamedNodeCollector {
} }
public boolean addNode(PDOMNamedNode tBinding) throws CoreException { public boolean addNode(PDOMNamedNode tBinding) throws CoreException {
if (tBinding instanceof IBinding) { if (tBinding instanceof PDOMBinding) {
if (filter == null || filter.acceptBinding((IBinding) tBinding)) { if (filter == null || filter.acceptBinding((IBinding) tBinding)) {
return super.addNode(tBinding); return super.addNode(tBinding);
} }
@ -50,8 +50,8 @@ public final class BindingCollector extends NamedNodeCollector {
return true; // look for more return true; // look for more
} }
public IBinding[] getBindings() { public PDOMBinding[] getBindings() {
List bindings= getNodeList(); List bindings= getNodeList();
return (IBinding[])bindings.toArray(new IBinding[bindings.size()]); return (PDOMBinding[])bindings.toArray(new PDOMBinding[bindings.size()]);
} }
} }

View file

@ -37,6 +37,7 @@ import org.eclipse.core.runtime.CoreException;
* *
*/ */
public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmentBinding { public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmentBinding {
public static final PDOMBinding[] EMPTY_PDOMBINDING_ARRAY = {};
private static final int FIRST_DECL_OFFSET = PDOMNamedNode.RECORD_SIZE + 0; // size 4 private static final int FIRST_DECL_OFFSET = PDOMNamedNode.RECORD_SIZE + 0; // size 4
private static final int FIRST_DEF_OFFSET = PDOMNamedNode.RECORD_SIZE + 4; // size 4 private static final int FIRST_DEF_OFFSET = PDOMNamedNode.RECORD_SIZE + 4; // size 4

View file

@ -52,14 +52,18 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
} }
public PDOMCLinkage(PDOM pdom) throws CoreException { public PDOMCLinkage(PDOM pdom) throws CoreException {
super(pdom, C_LINKAGE_ID, C_LINKAGE_ID.toCharArray()); super(pdom, C_LINKAGE_NAME, C_LINKAGE_NAME.toCharArray());
} }
public int getNodeType() { public int getNodeType() {
return LINKAGE; return LINKAGE;
} }
public String getID() { public String getLinkageName() {
return C_LINKAGE_NAME;
}
public int getLinkageID() {
return C_LINKAGE_ID; return C_LINKAGE_ID;
} }

View file

@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -163,7 +164,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
return !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPSpecialization); return !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPSpecialization);
} }
public boolean acceptLinkage(ILinkage linkage) { public boolean acceptLinkage(ILinkage linkage) {
return linkage.getID() == ILinkage.CPP_LINKAGE_ID; return linkage.getLinkageID() == ILinkage.CPP_LINKAGE_ID;
} }
}; };
@ -190,7 +191,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
return !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPSpecialization); return !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPSpecialization);
} }
public boolean acceptLinkage(ILinkage linkage) { public boolean acceptLinkage(ILinkage linkage) {
return linkage.getID() == ILinkage.CPP_LINKAGE_ID; return linkage.getLinkageID() == ILinkage.CPP_LINKAGE_ID;
} }
}; };

View file

@ -82,10 +82,14 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
} }
public PDOMCPPLinkage(PDOM pdom) throws CoreException { public PDOMCPPLinkage(PDOM pdom) throws CoreException {
super(pdom, CPP_LINKAGE_ID, CPP_LINKAGE_ID.toCharArray()); super(pdom, CPP_LINKAGE_NAME, CPP_LINKAGE_NAME.toCharArray());
} }
public String getID() { public String getLinkageName() {
return CPP_LINKAGE_NAME;
}
public int getLinkageID() {
return CPP_LINKAGE_ID; return CPP_LINKAGE_ID;
} }