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

Navigation of macro parameters, bug 105929

This commit is contained in:
Markus Schorn 2009-06-24 12:31:34 +00:00
parent da06944678
commit 6bc28a4959
2 changed files with 37 additions and 3 deletions

View file

@ -275,7 +275,7 @@ class ASTInclusionStatement extends ASTPreprocessorNode implements IASTPreproces
class ASTMacroDefinition extends ASTPreprocessorNode implements IASTPreprocessorObjectStyleMacroDefinition { class ASTMacroDefinition extends ASTPreprocessorNode implements IASTPreprocessorObjectStyleMacroDefinition {
private final ASTPreprocessorName fName; private final ASTPreprocessorName fName;
private final int fExpansionNumber; protected final int fExpansionNumber;
private final int fExpansionOffset; private final int fExpansionOffset;
private final boolean fActive; private final boolean fActive;
@ -404,8 +404,27 @@ class ASTFunctionStyleMacroDefinition extends ASTMacroDefinition implements IAST
IMacroBinding macro= getMacro(); IMacroBinding macro= getMacro();
char[][] paramList= macro.getParameterList(); char[][] paramList= macro.getParameterList();
IASTFunctionStyleMacroParameter[] result= new IASTFunctionStyleMacroParameter[paramList.length]; IASTFunctionStyleMacroParameter[] result= new IASTFunctionStyleMacroParameter[paramList.length];
char[] image= getRawSignatureChars();
int idx= 0;
int defOffset = getOffset();
int endIdx= Math.min(fExpansionNumber - defOffset, image.length);
char start= '(';
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
result[i]= new ASTMacroParameter(this, paramList[i], -1, -1); while(idx < endIdx && image[idx] != start)
idx++;
idx++;
while(idx < endIdx && Character.isWhitespace(image[idx]))
idx++;
start= ',';
char[] param = paramList[i];
int poffset= -1;
int pendOffset= -1;
if (idx + param.length <= endIdx) {
poffset= defOffset+idx;
pendOffset= poffset+param.length;
}
result[i]= new ASTMacroParameter(this, param, poffset, pendOffset);
} }
return result; return result;
} }

View file

@ -42,11 +42,13 @@ import org.eclipse.cdt.core.dom.ast.ASTNameCollector;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
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;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
@ -253,6 +255,16 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
if (node instanceof IASTPreprocessorIncludeStatement) { if (node instanceof IASTPreprocessorIncludeStatement) {
openInclude((IASTPreprocessorIncludeStatement) node); openInclude((IASTPreprocessorIncludeStatement) node);
return Status.OK_STATUS; return Status.OK_STATUS;
} else if (node instanceof IASTPreprocessorFunctionStyleMacroDefinition) {
IASTPreprocessorFunctionStyleMacroDefinition mdef= (IASTPreprocessorFunctionStyleMacroDefinition) node;
for (IASTFunctionStyleMacroParameter par: mdef.getParameters()) {
String parName= par.getParameter();
if (parName.equals(fSelectedText)) {
if (navigateToLocation(par.getFileLocation())) {
return Status.OK_STATUS;
}
}
}
} }
if (!navigationFallBack(ast, null, NameKind.REFERENCE)) { if (!navigationFallBack(ast, null, NameKind.REFERENCE)) {
reportSelectionMatchFailure(); reportSelectionMatchFailure();
@ -473,7 +485,10 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
} }
private boolean navigateToName(IName name) { private boolean navigateToName(IName name) {
IASTFileLocation fileloc = name.getFileLocation(); return navigateToLocation(name.getFileLocation());
}
private boolean navigateToLocation(IASTFileLocation fileloc) {
if (fileloc == null) { if (fileloc == null) {
return false; return false;
} }