diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java
index 1c0ce140708..ba13a86fded 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java
@@ -34,17 +34,11 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class EmptyIndexFragment implements IIndexFragment {
public void acquireReadLock() throws InterruptedException {}
- public IIndexFragmentBinding adaptBinding(IBinding binding)
- throws CoreException {
+ public IIndexFragmentBinding adaptBinding(IBinding binding) {
return null;
}
- public IIndexFragmentBinding adaptBinding(IIndexFragmentBinding proxy)
- throws CoreException {
- return null;
- }
-
- public IIndexFragmentBinding findBinding(IASTName astName) throws CoreException {
+ public IIndexFragmentBinding findBinding(IASTName astName) {
return null;
}
@@ -74,8 +68,7 @@ public class EmptyIndexFragment implements IIndexFragment {
return IIndexFragmentInclude.EMPTY_FRAGMENT_INCLUDES_ARRAY;
}
- public IIndexFragmentName[] findNames(IIndexFragmentBinding binding,
- int flags) throws CoreException {
+ public IIndexFragmentName[] findNames(IBinding binding, int flags) {
return IIndexFragmentName.EMPTY_NAME_ARRAY;
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java
index 2b8c9f1422d..248997ec22a 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java
@@ -258,13 +258,13 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
IndexFilter CLinkage= new IndexFilter() {
public boolean acceptLinkage(ILinkage linkage) {
- return linkage.getID().equals(ILinkage.C_LINKAGE_ID);
+ return linkage.getLinkageID() == ILinkage.C_LINKAGE_ID;
}
};
IndexFilter CPPLinkage= new IndexFilter() {
public boolean acceptLinkage(ILinkage linkage) {
- return linkage.getID().equals(ILinkage.CPP_LINKAGE_ID);
+ return linkage.getLinkageID() == ILinkage.CPP_LINKAGE_ID;
}
};
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java
index 1e4a7ba58b0..906a9653ab2 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMCPPBugsTest.java
@@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Andrew Ferguson (Symbian) - Initial implementation
- * Markus Schorn (Wind River Systems)
+ * Andrew Ferguson (Symbian) - Initial implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
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.ast.IFunction;
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.IIndexLocationConverter;
import org.eclipse.cdt.core.index.IndexFilter;
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.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.util.BaseTestCase;
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.runtime.CoreException;
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
@@ -208,21 +202,14 @@ public class PDOMCPPBugsTest extends BaseTestCase {
pdom.releaseWriteLock();
}
- public void _test191679() throws Exception {
+ public void test191679() throws Exception {
IProject project= cproject.getProject();
IFolder cHeaders= cproject.getProject().getFolder("cHeaders");
cHeaders.create(true, true, NPM);
LanguageManager lm= LanguageManager.getInstance();
- IFile cHeader= TestSourceReader.createFile(cHeaders, "cHeader.h", "extern \"C\" void foo(int i) {}\n");
- ICProjectDescription pd= CCorePlugin.getDefault().getProjectDescription(project);
- 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);}");
+ IFile cHeader= TestSourceReader.createFile(cHeaders, "cSource.c", "void foo(int i){}");
+ IFile cppSource= TestSourceReader.createFile(cHeaders, "cppSource.cpp", "extern \"C\" void foo(int i); void ref() {foo(1);}");
IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER);
CCorePlugin.getIndexManager().reindex(cproject);
@@ -233,14 +220,29 @@ public class PDOMCPPBugsTest extends BaseTestCase {
try {
{ // test reference to 'foo' was resolved correctly
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 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);
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 {
pdom.releaseReadLock();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ILinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ILinkage.java
index 5312756e578..1343a83b6a1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ILinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ILinkage.java
@@ -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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -22,10 +22,23 @@ package org.eclipse.cdt.core.dom;
* @since 4.0
*/
public interface ILinkage {
- final static String NO_LINKAGE_ID= "none"; //$NON-NLS-1$
- final static String C_LINKAGE_ID= "C"; //$NON-NLS-1$
- final static String CPP_LINKAGE_ID= "C++"; //$NON-NLS-1$
- final static String FORTRAN_LINKAGE_ID= "Fortran"; //$NON-NLS-1$
+ final static String NO_LINKAGE_NAME= "none"; //$NON-NLS-1$
+ final static String C_LINKAGE_NAME= "C"; //$NON-NLS-1$
+ final static String CPP_LINKAGE_NAME= "C++"; //$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();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java
index b88101729a7..688cee8e997 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPFunction.java
@@ -37,6 +37,7 @@ public interface ICPPFunction extends IFunction, ICPPBinding {
/**
* Returns whether this function is declared as extern "C".
+ * @since 5.0
*/
public boolean isExternC() throws DOMException;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java
index b3401b5a6bf..9b2be5a4914 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java
@@ -62,6 +62,12 @@ public interface IIndex {
* Constant to search for all declarations including definitions.
*/
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.
*/
@@ -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
* or definitions, or a combination of those.
* @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
* @throws CoreException
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java
index 090898db776..0a1df4daf34 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java
@@ -31,8 +31,8 @@ import org.eclipse.core.runtime.CoreException;
abstract public class IndexFilter {
public static final IndexFilter ALL = new IndexFilter() {};
- public static final IndexFilter ALL_DECLARED = getDeclaredBindingFilter(null, false);
- public static final IndexFilter ALL_DECLARED_OR_IMPLICIT = getDeclaredBindingFilter(null, true);
+ public static final IndexFilter ALL_DECLARED = getDeclaredBindingFilter(-1, false);
+ 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 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
* @return an IndexFilter instance
*/
- public static IndexFilter getFilter(final String linkageID) {
+ public static IndexFilter getFilter(final int linkageID) {
return new IndexFilter() {
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
* 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
*/
- public static IndexFilter getDeclaredBindingFilter(final String linkageID, boolean acceptImplicit) {
+ public static IndexFilter getDeclaredBindingFilter(final int linkageID, boolean acceptImplicit) {
return new DeclaredBindingsFilter(linkageID, acceptImplicit);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java
index 41fb2efcba4..d7bc638cb7e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java
@@ -15,10 +15,10 @@ import org.eclipse.cdt.core.dom.ILinkage;
public class Linkage implements ILinkage {
- public static final ILinkage NO_LINKAGE = new Linkage(NO_LINKAGE_ID);
- public static final ILinkage C_LINKAGE = new Linkage(C_LINKAGE_ID);
- public static final ILinkage CPP_LINKAGE = new Linkage(CPP_LINKAGE_ID);
- public static final ILinkage FORTRAN_LINKAGE = new Linkage(FORTRAN_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, C_LINKAGE_NAME);
+ 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, FORTRAN_LINKAGE_NAME);
private static final ILinkage[] LINKAGES= {C_LINKAGE, CPP_LINKAGE, FORTRAN_LINKAGE};
@@ -26,11 +26,16 @@ public class Linkage implements ILinkage {
return LINKAGES;
}
- private String fID;
- private Linkage(String id) {
+ private int fID;
+ private String fName;
+ private Linkage(int id, String name) {
fID= id;
+ fName= name;
}
- public String getID() {
+ public int getLinkageID() {
return fID;
}
+ public String getLinkageName() {
+ return fName;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java
index e82066e8d80..9b7b0cdd548 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java
@@ -78,7 +78,7 @@ public class CIndex implements IIndex {
for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexFragmentBinding binding= fFragments[i].findBinding((IASTName) name);
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;
}
}
- ICompositesFactory factory = getCompositesFactory(linkages[j].getID());
+ ICompositesFactory factory = getCompositesFactory(linkages[j].getLinkageID());
result.add(factory.getCompositeBindings(fragmentBindings));
}
}
@@ -121,13 +121,10 @@ public class CIndex implements IIndex {
LinkedList result= new LinkedList();
int fragCount= 0;
for (int i = 0; i < fPrimaryFragmentCount; i++) {
- IIndexFragmentBinding adaptedBinding= fFragments[i].adaptBinding(binding);
- if (adaptedBinding != null) {
- final IIndexFragmentName[] names = fFragments[i].findNames(adaptedBinding, flags);
- if (names.length > 0) {
- result.addAll(Arrays.asList(names));
- fragCount++;
- }
+ final IIndexFragmentName[] names = fFragments[i].findNames(binding, flags);
+ if (names.length > 0) {
+ result.addAll(Arrays.asList(names));
+ fragCount++;
}
}
// 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;
}
}
- ICompositesFactory factory = getCompositesFactory(linkages[j].getID());
+ ICompositesFactory factory = getCompositesFactory(linkages[j].getLinkageID());
result.add(factory.getCompositeBindings(fragmentBindings));
}
}
@@ -351,7 +348,7 @@ public class CIndex implements IIndex {
for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexFragmentBinding adaptedBinding= fFragments[i].adaptBinding(binding);
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()]);
}
- private ICompositesFactory getCompositesFactory(String linkageID) {
- if(linkageID.equals(ILinkage.CPP_LINKAGE_ID)) {
+ private ICompositesFactory getCompositesFactory(int linkageID) {
+ switch (linkageID) {
+ case ILinkage.CPP_LINKAGE_ID:
if(cppCF==null) {
cppCF = new CPPCompositesFactory(new CIndex(fFragments, fFragments.length));
}
return cppCF;
- }
- if(linkageID.equals(ILinkage.C_LINKAGE_ID)) {
+
+ case ILinkage.C_LINKAGE_ID:
if(cCF==null) {
cCF = new CCompositesFactory(new CIndex(fFragments, fFragments.length));
}
return cCF;
- }
- if(linkageID.equals(ILinkage.FORTRAN_LINKAGE_ID)) {
+
+ case ILinkage.FORTRAN_LINKAGE_ID:
if(fCF==null) {
fCF = new CCompositesFactory(new CIndex(fFragments, fFragments.length));
}
@@ -431,7 +429,7 @@ public class CIndex implements IIndex {
return filter.acceptBinding(binding);
}
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;
}
}
- ICompositesFactory factory = getCompositesFactory(linkages[j].getID());
+ ICompositesFactory factory = getCompositesFactory(linkages[j].getLinkageID());
result.add(factory.getCompositeBindings(fragmentBindings));
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/DeclaredBindingsFilter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/DeclaredBindingsFilter.java
index 828fc4c405b..829b7e4a31f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/DeclaredBindingsFilter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/DeclaredBindingsFilter.java
@@ -18,20 +18,20 @@ import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.core.runtime.CoreException;
public class DeclaredBindingsFilter extends IndexFilter {
- final private String fLinkageID;
+ final private int fLinkageID;
final private boolean fAcceptImplicit;
public DeclaredBindingsFilter() {
- this(null, false);
+ this(-1, false);
}
- public DeclaredBindingsFilter(String linkageID, boolean acceptImplicit) {
+ public DeclaredBindingsFilter(int linkageID, boolean acceptImplicit) {
fLinkageID= linkageID;
fAcceptImplicit= acceptImplicit;
}
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 {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java
index 6270560cfaa..18091a19250 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java
@@ -43,6 +43,10 @@ public interface IIndexFragment {
* @see 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
*/
@@ -89,7 +93,7 @@ public interface IIndexFragment {
* another fragment. All of the include directives returned must belong to files managed by
* this fragment.
* @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
*/
IIndexFragmentInclude[] findIncludedBy(IIndexFragmentFile file) throws CoreException;
@@ -103,15 +107,6 @@ public interface IIndexFragment {
*/
IIndexFragmentBinding adaptBinding(IBinding binding) throws CoreException;
- /**
- * Looks for a proxy binding matching the given one. May return null
, if no
- * such binding exists. The binding may belong to another index fragment.
- * @param proxy the binding to look for.
- * @return the binding, or null
- * @throws CoreException
- */
- IIndexFragmentBinding adaptBinding(IIndexFragmentBinding proxy) throws CoreException;
-
/**
* Looks for a binding of the given name from the AST. May return null
, if no
* such binding exists.
@@ -153,7 +148,7 @@ public interface IIndexFragment {
* @return an array of names
* @throws CoreException
*/
- IIndexFragmentName[] findNames(IIndexFragmentBinding binding, int flags) throws CoreException;
+ IIndexFragmentName[] findNames(IBinding binding, int flags) throws CoreException;
/**
* Acquires a read lock.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
index d11849b7b8c..aded3430b6c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
@@ -31,8 +31,15 @@ import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMNode;
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.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.IIndexFileLocation;
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.IIndexName;
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.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
@@ -75,7 +83,7 @@ import org.eclipse.core.runtime.Status;
*
* @author Doug Schaefer
*/
-public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
+public class PDOM extends PlatformObject implements IPDOM {
/**
* Identifier for PDOM format
* @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);
}
@@ -549,7 +557,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
public void insertLinkage(PDOMLinkage linkage) throws CoreException {
linkage.setNext(db.getInt(LINKAGES));
db.putInt(LINKAGES, linkage.getRecord());
- fLinkageIDCache.put(linkage.getID(), linkage);
+ fLinkageIDCache.put(linkage.getLinkageName(), linkage);
}
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 {
- return (PDOMLinkage) fLinkageIDCache.get(linkage.getID());
+ return (PDOMLinkage) fLinkageIDCache.get(linkage.getLinkageName());
}
public IIndexFragmentBinding adaptBinding(IBinding binding) throws CoreException {
+ if (binding == null) {
+ return null;
+ }
PDOMBinding pdomBinding= (PDOMBinding) binding.getAdapter(PDOMBinding.class);
if (pdomBinding != null && pdomBinding.getPDOM() == this) {
return pdomBinding;
@@ -686,13 +697,6 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
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 {
if (indexName instanceof PDOMName) {
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 {
- IIndexFragmentBinding proxyBinding= adaptBinding(binding);
- if (proxyBinding != null) {
- return findNames(proxyBinding, options);
+ ArrayList names= new ArrayList();
+ PDOMBinding pdomBinding = (PDOMBinding) adaptBinding(binding);
+ 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 {
- PDOMBinding pdomBinding = (PDOMBinding) adaptBinding(binding);
-
- if (pdomBinding != null) {
- PDOMName name;
- List names = new ArrayList();
- if ((options & FIND_DECLARATIONS) != 0) {
- for (name= pdomBinding.getFirstDeclaration(); name != null; name= name.getNextInBinding()) {
- names.add(name);
- }
+ private void findNamesForMyBinding(PDOMBinding pdomBinding, int options, ArrayList names)
+ throws CoreException {
+ PDOMName 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 {
@@ -872,4 +878,82 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
public String createKeyForCache(int record, char[] name) {
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;
+ }
+
+
}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java
index 1155b5c79ad..de108946e10 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java
@@ -61,12 +61,6 @@ public class PDOMProxy implements IPDOM {
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 {
if (fDelegate != null)
return fDelegate.findBinding(astName);
@@ -104,7 +98,7 @@ public class PDOMProxy implements IPDOM {
return new IIndexFragmentInclude[0];
}
- public synchronized IIndexFragmentName[] findNames(IIndexFragmentBinding binding, int flags)
+ public synchronized IIndexFragmentName[] findNames(IBinding binding, int flags)
throws CoreException {
if (fDelegate != null)
return fDelegate.findNames(binding, flags);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
index 508bde45d3b..cfa854ca794 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
@@ -79,7 +79,7 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
public PDOMBinding addBinding(IASTName name) throws CoreException {
PDOMBinding result= null;
- PDOMLinkage linkage= createLinkage(name.getLinkage().getID());
+ PDOMLinkage linkage= createLinkage(name.getLinkage().getLinkageName());
if (linkage == null) {
CCorePlugin.log(MessageFormat.format(Messages.WritablePDOM_error_unknownLinkage, new Object[]{name.getLinkage()}));
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java
index d5e5ab016d8..97d74261d4f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java
@@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Andrew Ferguson (Symbian)
+ * QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Andrew Ferguson (Symbian)
*******************************************************************************/
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 {
- if (tBinding instanceof IBinding) {
+ if (tBinding instanceof PDOMBinding) {
if (filter == null || filter.acceptBinding((IBinding) tBinding)) {
return super.addNode(tBinding);
}
@@ -50,8 +50,8 @@ public final class BindingCollector extends NamedNodeCollector {
return true; // look for more
}
- public IBinding[] getBindings() {
+ public PDOMBinding[] getBindings() {
List bindings= getNodeList();
- return (IBinding[])bindings.toArray(new IBinding[bindings.size()]);
+ return (PDOMBinding[])bindings.toArray(new PDOMBinding[bindings.size()]);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
index a6da94c6195..aeb09e2c267 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
@@ -37,6 +37,7 @@ import org.eclipse.core.runtime.CoreException;
*
*/
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_DEF_OFFSET = PDOMNamedNode.RECORD_SIZE + 4; // size 4
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
index ef2f046d9cb..3b646a4e511 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
@@ -52,14 +52,18 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
}
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() {
return LINKAGE;
}
- public String getID() {
+ public String getLinkageName() {
+ return C_LINKAGE_NAME;
+ }
+
+ public int getLinkageID() {
return C_LINKAGE_ID;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java
index b307ea14d39..d271ad7ac04 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java
@@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Andrew Ferguson (Symbian)
+ * QNX - Initial API and implementation
+ * Andrew Ferguson (Symbian)
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@@ -163,7 +164,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
return !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPSpecialization);
}
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);
}
public boolean acceptLinkage(ILinkage linkage) {
- return linkage.getID() == ILinkage.CPP_LINKAGE_ID;
+ return linkage.getLinkageID() == ILinkage.CPP_LINKAGE_ID;
}
};
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
index a43b7dde899..9b9ceddd835 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
@@ -82,10 +82,14 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
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;
}