mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 09:16:02 +02:00
Bug 509733 - Open Declaration with source and target inside a macro invocation
Change-Id: I1f31a94caa0b48ba07380f28dc11ba74629b202e
This commit is contained in:
parent
a72d9b4198
commit
2a613abcd2
2 changed files with 39 additions and 5 deletions
|
@ -1315,4 +1315,23 @@ public class CPPSelectionTestsIndexer extends BaseSelectionTestsIndexer {
|
||||||
String expansion = new String(((IMacroBinding) binding).getExpansion());
|
String expansion = new String(((IMacroBinding) binding).getExpansion());
|
||||||
assertTrue(expansion.contains("42"));
|
assertTrue(expansion.contains("42"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #define DEFINE_FUNC(...) void foo() { __VA_ARGS__ }
|
||||||
|
// struct Waldo {
|
||||||
|
// void find();
|
||||||
|
// };
|
||||||
|
// DEFINE_FUNC
|
||||||
|
// (
|
||||||
|
// Waldo waldo;
|
||||||
|
// waldo.find();
|
||||||
|
// )
|
||||||
|
public void testDeclarationInMacroArgment_509733() throws Exception {
|
||||||
|
String code = getAboveComment();
|
||||||
|
IFile file = importFile("test.cpp", code);
|
||||||
|
waitUntilFileIsIndexed(index, file);
|
||||||
|
|
||||||
|
int offset= code.indexOf("waldo.find()");
|
||||||
|
IASTNode def = testF3(file, offset + 1);
|
||||||
|
assertTrue(def instanceof IASTName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTImageLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
|
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
|
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
@ -428,18 +429,32 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean areOverlappingNames(IName n1, IName n2) {
|
private static boolean areOverlappingNames(IName n1, IName n2) {
|
||||||
if (n1 == n2)
|
if (n1 == n2)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
IASTFileLocation loc1 = n1.getFileLocation();
|
IASTFileLocation loc1 = getFileLocation(n1);
|
||||||
IASTFileLocation loc2 = n2.getFileLocation();
|
IASTFileLocation loc2 = getFileLocation(n2);
|
||||||
if (loc1 == null || loc2 == null)
|
if (loc1 == null || loc2 == null)
|
||||||
return false;
|
return false;
|
||||||
return loc1.getFileName().equals(loc2.getFileName()) &&
|
return loc1.getFileName().equals(loc2.getFileName()) &&
|
||||||
max(loc1.getNodeOffset(), loc2.getNodeOffset()) <
|
max(loc1.getNodeOffset(), loc2.getNodeOffset()) <
|
||||||
min(loc1.getNodeOffset() + loc1.getNodeLength(), loc2.getNodeOffset() + loc2.getNodeLength());
|
min(loc1.getNodeOffset() + loc1.getNodeLength(), loc2.getNodeOffset() + loc2.getNodeLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IASTFileLocation getFileLocation(IName name) {
|
||||||
|
IASTFileLocation fileLocation = name.getFileLocation();
|
||||||
|
if (name instanceof IASTName) {
|
||||||
|
IASTName astName = (IASTName) name;
|
||||||
|
IASTImageLocation imageLocation = astName.getImageLocation();
|
||||||
|
if (imageLocation != null &&
|
||||||
|
imageLocation.getLocationKind() != IASTImageLocation.MACRO_DEFINITION &&
|
||||||
|
astName.getTranslationUnit().getFilePath().equals(fileLocation.getFileName())) {
|
||||||
|
fileLocation = imageLocation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fileLocation;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isInSameFunction(IASTName refName, IName funcDeclName) {
|
private static boolean isInSameFunction(IASTName refName, IName funcDeclName) {
|
||||||
if (funcDeclName instanceof IASTName) {
|
if (funcDeclName instanceof IASTName) {
|
||||||
|
@ -517,7 +532,7 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
if (tu instanceof IWorkingCopy)
|
if (tu instanceof IWorkingCopy)
|
||||||
tu = ((IWorkingCopy) tu).getOriginalElement();
|
tu = ((IWorkingCopy) tu).getOriginalElement();
|
||||||
IASTFileLocation loc= astName.getFileLocation();
|
IASTFileLocation loc= getFileLocation(astName);
|
||||||
IRegion region= new Region(loc.getNodeOffset(), loc.getNodeLength());
|
IRegion region= new Region(loc.getNodeOffset(), loc.getNodeLength());
|
||||||
return CElementHandleFactory.create(tu, binding, astName.isDefinition(), region, 0);
|
return CElementHandleFactory.create(tu, binding, astName.isDefinition(), region, 0);
|
||||||
}
|
}
|
||||||
|
@ -653,7 +668,7 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean navigateToName(IName name) {
|
private boolean navigateToName(IName name) {
|
||||||
return navigateToLocation(name.getFileLocation());
|
return navigateToLocation(getFileLocation(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean navigateToLocation(IASTFileLocation fileloc) {
|
private boolean navigateToLocation(IASTFileLocation fileloc) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue