mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 23:05:47 +02:00
Distinction of c- and c++ functions in call hierarchy, bug 260262.
This commit is contained in:
parent
938969ae49
commit
843732d750
7 changed files with 126 additions and 32 deletions
|
@ -354,4 +354,64 @@ public class CallHierarchyBugs extends CallHierarchyBaseTest {
|
||||||
chTree= checkTreeNode(ch, 0, "call(int)").getParent();
|
chTree= checkTreeNode(ch, 0, "call(int)").getParent();
|
||||||
ti= checkTreeNode(chTree, 0, 0, "PREFIX_Test(char *, char *)");
|
ti= checkTreeNode(chTree, 0, 0, "PREFIX_Test(char *, char *)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void shared_func();
|
||||||
|
|
||||||
|
// #include "260262.h"
|
||||||
|
|
||||||
|
// void call() {
|
||||||
|
// shared_func();
|
||||||
|
// }
|
||||||
|
public void testMultiLanguageWithPrototype_260262() throws Exception {
|
||||||
|
final StringBuffer[] contents = getContentsForTest(3);
|
||||||
|
final String hcontent = contents[0].toString();
|
||||||
|
final String content_inc = contents[1].toString();
|
||||||
|
final String content_full = content_inc + contents[2].toString();
|
||||||
|
IFile header= createFile(getProject(), "260262.h", hcontent);
|
||||||
|
IFile f1= createFile(getProject(), "260262.c", content_full);
|
||||||
|
IFile f2= createFile(getProject(), "260262.cpp", content_inc);
|
||||||
|
waitForIndexer(fIndex, f2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||||
|
|
||||||
|
final CHViewPart ch= (CHViewPart) activateView(CUIPlugin.ID_CALL_HIERARCHY);
|
||||||
|
|
||||||
|
// open editor, check outline
|
||||||
|
CEditor editor= openEditor(header);
|
||||||
|
int idx = hcontent.indexOf("shared_func()");
|
||||||
|
editor.selectAndReveal(idx, 0);
|
||||||
|
openCallHierarchy(editor, true);
|
||||||
|
|
||||||
|
Tree chTree= checkTreeNode(ch, 0, "shared_func()").getParent();
|
||||||
|
TreeItem ti= checkTreeNode(chTree, 0, 0, "call()");
|
||||||
|
checkTreeNode(chTree, 0, 1, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// inline void shared_func() {}
|
||||||
|
|
||||||
|
// #include "260262.h"
|
||||||
|
|
||||||
|
// void call() {
|
||||||
|
// shared_func();
|
||||||
|
// }
|
||||||
|
public void testMultiLanguageWithInlinedfunc_260262() throws Exception {
|
||||||
|
final StringBuffer[] contents = getContentsForTest(3);
|
||||||
|
final String hcontent = contents[0].toString();
|
||||||
|
final String content_inc = contents[1].toString();
|
||||||
|
final String content_full = content_inc + contents[2].toString();
|
||||||
|
IFile header= createFile(getProject(), "260262.h", hcontent);
|
||||||
|
IFile f1= createFile(getProject(), "260262.c", content_full);
|
||||||
|
IFile f2= createFile(getProject(), "260262.cpp", content_inc);
|
||||||
|
waitForIndexer(fIndex, f2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
|
||||||
|
|
||||||
|
final CHViewPart ch= (CHViewPart) activateView(CUIPlugin.ID_CALL_HIERARCHY);
|
||||||
|
|
||||||
|
// open editor, check outline
|
||||||
|
CEditor editor= openEditor(header);
|
||||||
|
int idx = hcontent.indexOf("shared_func()");
|
||||||
|
editor.selectAndReveal(idx, 0);
|
||||||
|
openCallHierarchy(editor, true);
|
||||||
|
|
||||||
|
Tree chTree= checkTreeNode(ch, 0, "shared_func()").getParent();
|
||||||
|
TreeItem ti= checkTreeNode(chTree, 0, 0, "call()");
|
||||||
|
checkTreeNode(chTree, 0, 1, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
@ -129,7 +130,7 @@ public class CHContentProvider extends AsyncTreeContentProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ITranslationUnit tu= CModelUtil.getTranslationUnit(element);
|
ITranslationUnit tu= CModelUtil.getTranslationUnit(element);
|
||||||
return new Object[] { new CHNode(null, tu, 0, element) };
|
return new Object[] { new CHNode(null, tu, 0, element, -1) };
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
index.releaseReadLock();
|
index.releaseReadLock();
|
||||||
|
@ -193,7 +194,8 @@ public class CHContentProvider extends AsyncTreeContentProvider {
|
||||||
|
|
||||||
private CHNode createRefbyNode(CHNode parent, ICElement element, IIndexName[] refs) throws CoreException {
|
private CHNode createRefbyNode(CHNode parent, ICElement element, IIndexName[] refs) throws CoreException {
|
||||||
ITranslationUnit tu= CModelUtil.getTranslationUnit(element);
|
ITranslationUnit tu= CModelUtil.getTranslationUnit(element);
|
||||||
CHNode node= new CHNode(parent, tu, refs[0].getFile().getTimestamp(), element);
|
final IIndexFile file = refs[0].getFile();
|
||||||
|
CHNode node= new CHNode(parent, tu, file.getTimestamp(), element, file.getLinkageID());
|
||||||
if (element instanceof IVariable || element instanceof IEnumerator) {
|
if (element instanceof IVariable || element instanceof IEnumerator) {
|
||||||
node.setInitializer(true);
|
node.setInitializer(true);
|
||||||
}
|
}
|
||||||
|
@ -231,14 +233,15 @@ public class CHContentProvider extends AsyncTreeContentProvider {
|
||||||
private CHNode createReftoNode(CHNode parent, ITranslationUnit tu, ICElement[] elements, IIndexName[] references) throws CoreException {
|
private CHNode createReftoNode(CHNode parent, ITranslationUnit tu, ICElement[] elements, IIndexName[] references) throws CoreException {
|
||||||
assert elements.length > 0;
|
assert elements.length > 0;
|
||||||
|
|
||||||
CHNode node;
|
final IIndexFile file = references[0].getFile();
|
||||||
long timestamp= references[0].getFile().getTimestamp();
|
final long timestamp= file.getTimestamp();
|
||||||
|
final int linkageID= file.getLinkageID();
|
||||||
|
|
||||||
|
CHNode node;
|
||||||
if (elements.length == 1) {
|
if (elements.length == 1) {
|
||||||
node= new CHNode(parent, tu, timestamp, elements[0]);
|
node= new CHNode(parent, tu, timestamp, elements[0], linkageID);
|
||||||
}
|
} else {
|
||||||
else {
|
node= new CHMultiDefNode(parent, tu, timestamp, elements, linkageID);
|
||||||
node= new CHMultiDefNode(parent, tu, timestamp, elements);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean readAccess= false;
|
boolean readAccess= false;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
* Copyright (c) 2007, 2008 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
|
||||||
|
@ -8,22 +8,18 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.callhierarchy;
|
package org.eclipse.cdt.internal.ui.callhierarchy;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a node in the include browser
|
* Represents a child of a node with multiple definitions.
|
||||||
*/
|
*/
|
||||||
public class CHMultiDefChildNode extends CHNode {
|
public class CHMultiDefChildNode extends CHNode {
|
||||||
|
|
||||||
/**
|
public CHMultiDefChildNode(CHMultiDefNode parent, ITranslationUnit fileOfReferences, long timestamp, ICElement decl, int linkageID) {
|
||||||
* Creates a new node for the include browser
|
super(parent, fileOfReferences, timestamp, decl, linkageID);
|
||||||
*/
|
|
||||||
public CHMultiDefChildNode(CHMultiDefNode parent, ITranslationUnit fileOfReferences, long timestamp, ICElement decl) {
|
|
||||||
super(parent, fileOfReferences, timestamp, decl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,8 +19,8 @@ public class CHMultiDefNode extends CHNode {
|
||||||
|
|
||||||
private CHNode[] fChildren;
|
private CHNode[] fChildren;
|
||||||
|
|
||||||
public CHMultiDefNode(CHNode parent, ITranslationUnit tu, long timestamp, ICElement[] elements) {
|
public CHMultiDefNode(CHNode parent, ITranslationUnit tu, long timestamp, ICElement[] elements, int linkageID) {
|
||||||
super(parent, tu, timestamp, null);
|
super(parent, tu, timestamp, null, linkageID);
|
||||||
if (elements.length == 0) {
|
if (elements.length == 0) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class CHMultiDefNode extends CHNode {
|
||||||
fChildren= new CHNode[elements.length];
|
fChildren= new CHNode[elements.length];
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
ICElement element = elements[i];
|
ICElement element = elements[i];
|
||||||
fChildren[i]= new CHMultiDefChildNode(this, tu, timestamp, element);
|
fChildren[i]= new CHMultiDefChildNode(this, tu, timestamp, element, linkageID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,12 @@ public class CHNode implements IAdaptable {
|
||||||
private boolean fIsInitializer;
|
private boolean fIsInitializer;
|
||||||
private boolean fIsReadAccess;
|
private boolean fIsReadAccess;
|
||||||
private boolean fIsWriteAccess;
|
private boolean fIsWriteAccess;
|
||||||
|
private final int fLinkageID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new node for the include browser
|
* Creates a new node for the include browser
|
||||||
*/
|
*/
|
||||||
public CHNode(CHNode parent, ITranslationUnit fileOfReferences, long timestamp, ICElement decl) {
|
public CHNode(CHNode parent, ITranslationUnit fileOfReferences, long timestamp, ICElement decl, int linkageID) {
|
||||||
fParent= parent;
|
fParent= parent;
|
||||||
fFileOfReferences= fileOfReferences;
|
fFileOfReferences= fileOfReferences;
|
||||||
fReferences= Collections.emptyList();
|
fReferences= Collections.emptyList();
|
||||||
|
@ -51,6 +52,7 @@ public class CHNode implements IAdaptable {
|
||||||
fIsRecursive= computeIsRecursive(fParent, decl);
|
fIsRecursive= computeIsRecursive(fParent, decl);
|
||||||
fHashCode= computeHashCode();
|
fHashCode= computeHashCode();
|
||||||
fTimestamp= timestamp;
|
fTimestamp= timestamp;
|
||||||
|
fLinkageID= linkageID;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int computeHashCode() {
|
private int computeHashCode() {
|
||||||
|
@ -100,6 +102,9 @@ public class CHNode implements IAdaptable {
|
||||||
return fParent;
|
return fParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getLinkageID() {
|
||||||
|
return fLinkageID;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isRecursive() {
|
public boolean isRecursive() {
|
||||||
return fIsRecursive;
|
return fIsRecursive;
|
||||||
|
|
|
@ -16,6 +16,8 @@ import java.util.Arrays;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.dom.ILinkage;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
|
@ -51,8 +53,27 @@ public class CHQueries {
|
||||||
if (! (callee instanceof ISourceReference)) {
|
if (! (callee instanceof ISourceReference)) {
|
||||||
return EMPTY_NODES;
|
return EMPTY_NODES;
|
||||||
}
|
}
|
||||||
|
boolean done= false;
|
||||||
|
int linkageID= node.getLinkageID();
|
||||||
|
if (linkageID == -1) {
|
||||||
|
final String ct = ((ISourceReference) callee).getTranslationUnit().getContentTypeId();
|
||||||
|
if (ct.equals(CCorePlugin.CONTENT_TYPE_CXXHEADER)) {
|
||||||
|
// bug 260262: in a header file we need to consider c and c++
|
||||||
|
findCalledBy(callee, ILinkage.C_LINKAGE_ID, index, result);
|
||||||
|
findCalledBy(callee, ILinkage.CPP_LINKAGE_ID, index, result);
|
||||||
|
done= true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!done) {
|
||||||
|
findCalledBy(callee, linkageID, index, result);
|
||||||
|
}
|
||||||
|
return cp.createNodes(node, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void findCalledBy(ICElement callee, int linkageID, IIndex index, CalledByResult result)
|
||||||
|
throws CoreException {
|
||||||
final ICProject project = callee.getCProject();
|
final ICProject project = callee.getCProject();
|
||||||
IIndexBinding calleeBinding= IndexUI.elementToBinding(index, callee);
|
IIndexBinding calleeBinding= IndexUI.elementToBinding(index, callee, linkageID);
|
||||||
if (calleeBinding != null) {
|
if (calleeBinding != null) {
|
||||||
findCalledBy(index, calleeBinding, true, project, result);
|
findCalledBy(index, calleeBinding, true, project, result);
|
||||||
if (calleeBinding instanceof ICPPMethod) {
|
if (calleeBinding instanceof ICPPMethod) {
|
||||||
|
@ -66,7 +87,6 @@ public class CHQueries {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cp.createNodes(node, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void findCalledBy(IIndex index, IBinding callee, boolean includeOrdinaryCalls, ICProject project, CalledByResult result)
|
private static void findCalledBy(IIndex index, IBinding callee, boolean includeOrdinaryCalls, ICProject project, CalledByResult result)
|
||||||
|
|
|
@ -91,11 +91,15 @@ public class IndexUI {
|
||||||
private static final ICElementHandle[] EMPTY_ELEMENTS = new ICElementHandle[0];
|
private static final ICElementHandle[] EMPTY_ELEMENTS = new ICElementHandle[0];
|
||||||
|
|
||||||
public static IIndexBinding elementToBinding(IIndex index, ICElement element) throws CoreException {
|
public static IIndexBinding elementToBinding(IIndex index, ICElement element) throws CoreException {
|
||||||
|
return elementToBinding(index, element, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IIndexBinding elementToBinding(IIndex index, ICElement element, int linkageID) throws CoreException {
|
||||||
if (element instanceof ISourceReference) {
|
if (element instanceof ISourceReference) {
|
||||||
ISourceReference sf = ((ISourceReference)element);
|
ISourceReference sf = ((ISourceReference)element);
|
||||||
ISourceRange range= sf.getSourceRange();
|
ISourceRange range= sf.getSourceRange();
|
||||||
if (range.getIdLength() != 0) {
|
if (range.getIdLength() != 0) {
|
||||||
IIndexName name= elementToName(index, element);
|
IIndexName name= elementToName(index, element, linkageID);
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
return index.findBinding(name);
|
return index.findBinding(name);
|
||||||
}
|
}
|
||||||
|
@ -172,6 +176,10 @@ public class IndexUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IIndexName elementToName(IIndex index, ICElement element) throws CoreException {
|
public static IIndexName elementToName(IIndex index, ICElement element) throws CoreException {
|
||||||
|
return elementToName(index, element, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IIndexName elementToName(IIndex index, ICElement element, int linkageID) throws CoreException {
|
||||||
if (element instanceof ISourceReference) {
|
if (element instanceof ISourceReference) {
|
||||||
ISourceReference sf = ((ISourceReference)element);
|
ISourceReference sf = ((ISourceReference)element);
|
||||||
ITranslationUnit tu= sf.getTranslationUnit();
|
ITranslationUnit tu= sf.getTranslationUnit();
|
||||||
|
@ -181,6 +189,7 @@ public class IndexUI {
|
||||||
IIndexFile[] files= index.getFiles(location);
|
IIndexFile[] files= index.getFiles(location);
|
||||||
for (int i = 0; i < files.length; i++) {
|
for (int i = 0; i < files.length; i++) {
|
||||||
IIndexFile file = files[i];
|
IIndexFile file = files[i];
|
||||||
|
if (linkageID == -1 || file.getLinkageID() == linkageID) {
|
||||||
String elementName= element.getElementName();
|
String elementName= element.getElementName();
|
||||||
int idx= elementName.lastIndexOf(":")+1; //$NON-NLS-1$
|
int idx= elementName.lastIndexOf(":")+1; //$NON-NLS-1$
|
||||||
ISourceRange pos= sf.getSourceRange();
|
ISourceRange pos= sf.getSourceRange();
|
||||||
|
@ -196,6 +205,7 @@ public class IndexUI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue