From 6bc28a4959b9f690a22f6c023fa035e7176facbf Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 24 Jun 2009 12:31:34 +0000 Subject: [PATCH] Navigation of macro parameters, bug 105929 --- .../parser/scanner/ASTPreprocessorNode.java | 23 +++++++++++++++++-- .../actions/OpenDeclarationsAction.java | 17 +++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java index 5ee55e3d2bf..9597f994af5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorNode.java @@ -275,7 +275,7 @@ class ASTInclusionStatement extends ASTPreprocessorNode implements IASTPreproces class ASTMacroDefinition extends ASTPreprocessorNode implements IASTPreprocessorObjectStyleMacroDefinition { private final ASTPreprocessorName fName; - private final int fExpansionNumber; + protected final int fExpansionNumber; private final int fExpansionOffset; private final boolean fActive; @@ -404,8 +404,27 @@ class ASTFunctionStyleMacroDefinition extends ASTMacroDefinition implements IAST IMacroBinding macro= getMacro(); char[][] paramList= macro.getParameterList(); 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++) { - 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; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java index f79fe3dd20c..7ca8b21ac81 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java @@ -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.IASTDeclaration; 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.IASTImplicitNameOwner; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; 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.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -253,6 +255,16 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR if (node instanceof IASTPreprocessorIncludeStatement) { openInclude((IASTPreprocessorIncludeStatement) node); 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)) { reportSelectionMatchFailure(); @@ -473,7 +485,10 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR } private boolean navigateToName(IName name) { - IASTFileLocation fileloc = name.getFileLocation(); + return navigateToLocation(name.getFileLocation()); + } + + private boolean navigateToLocation(IASTFileLocation fileloc) { if (fileloc == null) { return false; }