diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 8ea2260a6f3..76354569e44 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -1013,8 +1013,7 @@ public class AST2CPPTests extends AST2BaseTest { IASTFunctionDefinition def = (IASTFunctionDefinition) tu .getDeclarations()[0]; - IFunction f = (IFunction) def.getDeclarator().getNestedDeclarator() - .getName().resolveBinding(); + IFunction f = (IFunction) def.getDeclarator().getName().resolveBinding(); IFunctionType ft = f.getType(); assertTrue(ft.getReturnType() instanceof IPointerType); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index bf44ca0f848..88b9597d4aa 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -2086,10 +2086,9 @@ public class AST2Tests extends AST2BaseTest { IASTTranslationUnit tu = parse( "void ( * f( int ) )(){}", ParserLanguage.C); //$NON-NLS-1$ - IASTFunctionDefinition def = (IASTFunctionDefinition) tu - .getDeclarations()[0]; - IFunction f = (IFunction) def.getDeclarator().getNestedDeclarator() - .getName().resolveBinding(); + IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[0]; + final IASTName fname = def.getDeclarator().getName(); + IFunction f = (IFunction) fname.resolveBinding(); IFunctionType ft = f.getType(); assertTrue(ft.getReturnType() instanceof IPointerType); @@ -2097,11 +2096,9 @@ public class AST2Tests extends AST2BaseTest { assertEquals(ft.getParameterTypes().length, 1); // test tu.getDeclarationsInAST(IBinding) - IASTName[] decls = tu.getDeclarationsInAST(def.getDeclarator() - .getNestedDeclarator().getName().resolveBinding()); + IASTName[] decls = tu.getDeclarationsInAST(f); assertEquals(decls.length, 1); - assertEquals(decls[0], def.getDeclarator().getNestedDeclarator() - .getName()); + assertEquals(decls[0], fname); } // test C99: 6.7.5.3-7 A declaration of a parameter as ''array of type'' @@ -2173,11 +2170,9 @@ public class AST2Tests extends AST2BaseTest { assertEquals(decls.length, 1); assertEquals(decls[0], def2.getDeclarator().getName()); - decls = tu.getDeclarationsInAST(def3.getDeclarator().getNestedDeclarator() - .getName().resolveBinding()); + decls = tu.getDeclarationsInAST(def3.getDeclarator().getName().resolveBinding()); assertEquals(decls.length, 1); - assertEquals(decls[0], def3.getDeclarator().getNestedDeclarator() - .getName()); + assertEquals(decls[0], def3.getDeclarator().getName()); } // any parameter to type function returning T is adjusted to be pointer to @@ -4859,8 +4854,8 @@ public class AST2Tests extends AST2BaseTest { } // int (*f1(int par))[5] {}; - public void _testFunctionReturningPtrToArray_Bug216609() throws Exception { - // works for plain-c, see testcase below. + // int (*f1 (int par))[5]; + public void testFunctionReturningPtrToArray_Bug216609() throws Exception { final String comment= getAboveComment(); final boolean[] isCpps= {false, true}; for (boolean isCpp : isCpps) { @@ -4868,6 +4863,68 @@ public class AST2Tests extends AST2BaseTest { IFunction f= ba.assertNonProblem("f1", 2, IFunction.class); isTypeEqual(f.getType(), "int [] * (int)"); + + f= ba.assertNonProblem("f1 ", 2, IFunction.class); + isTypeEqual(f.getType(), "int [] * (int)"); + } + } + + // void f1(){} + // void (f2)(){} + // void (f3()){} + // void ((f4)()){} + // void f1(); + // void (f2)(); + // void (f3()); + // void ((f4)()); + public void testNestedFunctionDeclarators() throws Exception { + final String comment= getAboveComment(); + final boolean[] isCpps= {false, true}; + for (ParserLanguage lang: ParserLanguage.values()) { + IASTTranslationUnit tu= parseAndCheckBindings(comment, lang); + IASTFunctionDefinition fdef= getDeclaration(tu, 0); + IASTDeclarator dtor= fdef.getDeclarator(); + assertNull(dtor.getNestedDeclarator()); + assertInstance(dtor.getParent(), IASTFunctionDefinition.class); + assertInstance(dtor.getName().resolveBinding(), IFunction.class); + + fdef= getDeclaration(tu, 1); + dtor= fdef.getDeclarator(); + assertNotNull(dtor.getNestedDeclarator()); + assertInstance(dtor.getParent(), IASTFunctionDefinition.class); + assertInstance(dtor.getNestedDeclarator().getName().resolveBinding(), IFunction.class); + + fdef= getDeclaration(tu, 2); + dtor= fdef.getDeclarator(); + assertNull(dtor.getNestedDeclarator()); + assertInstance(dtor.getParent().getParent(), IASTFunctionDefinition.class); + assertInstance(dtor.getName().resolveBinding(), IFunction.class); + + fdef= getDeclaration(tu, 3); + dtor= fdef.getDeclarator(); + assertNotNull(dtor.getNestedDeclarator()); + assertInstance(dtor.getParent().getParent(), IASTFunctionDefinition.class); + assertInstance(dtor.getNestedDeclarator().getName().resolveBinding(), IFunction.class); + + IASTSimpleDeclaration sdef= getDeclaration(tu, 4); + IBinding binding= sdef.getDeclarators()[0].getName().resolveBinding(); + assertInstance(binding, IFunction.class); + assertEquals(2, tu.getDeclarationsInAST(binding).length); + + sdef= getDeclaration(tu, 5); + binding= sdef.getDeclarators()[0].getNestedDeclarator().getName().resolveBinding(); + assertInstance(binding, IFunction.class); + assertEquals(2, tu.getDeclarationsInAST(binding).length); + + sdef= getDeclaration(tu, 6); + binding= sdef.getDeclarators()[0].getName().resolveBinding(); + assertInstance(binding, IFunction.class); + assertEquals(2, tu.getDeclarationsInAST(binding).length); + + sdef= getDeclaration(tu, 7); + binding= sdef.getDeclarators()[0].getNestedDeclarator().getName().resolveBinding(); + assertInstance(binding, IFunction.class); + assertEquals(2, tu.getDeclarationsInAST(binding).length); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDefinition.java index 04adfd68ba5..905436961f1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDefinition.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTFunctionDefinition.java @@ -54,14 +54,26 @@ public interface IASTFunctionDefinition extends IASTDeclaration { public void setDeclSpecifier(IASTDeclSpecifier declSpec); /** - * Get the declarator for the function. - * + * Get the function declarator of the function. + * Note, that the function declarator may contain nested declarators and may also nest within + * another declarator. In the latter case this function definition is always the parent of the + * outermost declarator. + *
+ * void (f)(int a); // has nested declarator + * void (f(int a)); // is nested in another declarator + **/ public IASTFunctionDeclarator getDeclarator(); /** - * Set the declarator for the function. - * + * Set the declarator for the function. + * Note, that the function declarator may contain nested declarators and may also nest within + * another declarator. In the latter case this function definition is set to be the parent of the + * outermost declarator. + *
+ * void (f)(int a); // has nested declarator + * void (f(int a)); // is nested in another declarator + ** @param declarator */ public void setDeclarator(IASTFunctionDeclarator declarator); @@ -86,5 +98,4 @@ public interface IASTFunctionDefinition extends IASTDeclaration { * @return
IScope
representing function body.
*/
public IScope getScope();
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java
index 297541ca06e..9332f0d6e0e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTFunctionDefinition.java
@@ -6,12 +6,14 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Rational Software - Initial API and implementation
+ * IBM Rational Software - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -61,8 +63,9 @@ public class CASTFunctionDefinition extends CASTNode implements
public void setDeclarator(IASTFunctionDeclarator declarator) {
this.declarator = declarator;
if (declarator != null) {
- declarator.setParent(this);
- declarator.setPropertyInParent(DECLARATOR);
+ IASTDeclarator outerDtor= CVisitor.findOutermostDeclarator(declarator);
+ outerDtor.setParent(this);
+ outerDtor.setPropertyInParent(DECLARATOR);
}
}
@@ -95,7 +98,8 @@ public class CASTFunctionDefinition extends CASTNode implements
}
if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false;
- if( declarator != null ) if( !declarator.accept( action ) ) return false;
+ final IASTDeclarator outerDtor= CVisitor.findOutermostDeclarator(declarator);
+ if( outerDtor != null ) if( !outerDtor.accept( action ) ) return false;
if( bodyStatement != null ) if( !bodyStatement.accept( action ) ) return false;
if( action.shouldVisitDeclarations ){
@@ -116,6 +120,4 @@ public class CASTFunctionDefinition extends CASTNode implements
bodyStatement = (IASTStatement) other;
}
}
-
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
index 2088f0bdc60..d08b5b4891f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
@@ -1040,7 +1040,7 @@ public class CVisitor {
if (node instanceof IASTFunctionDefinition) {
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) node;
IASTFunctionDeclarator functionDeclartor = functionDef.getDeclarator();
- IASTName name = functionDeclartor.getName();
+ IASTName name = findInnermostDeclarator(functionDeclartor).getName();
IASTNode blockItem = getContainingBlockItem(node);
try {
return (IBinding) findBinding(blockItem, name, bits);
@@ -1211,7 +1211,7 @@ public class CVisitor {
scope = getContainingScope((IASTStatement)parent);
} else if (parent instanceof IASTFunctionDefinition) {
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent).getDeclarator();
- IBinding function = fnDeclarator.getName().resolveBinding();
+ IBinding function = CVisitor.findInnermostDeclarator(fnDeclarator).getName().resolveBinding();
try {
if (function instanceof IFunction) {
scope = ((IFunction)function).getFunctionScope();
@@ -1611,9 +1611,7 @@ public class CVisitor {
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration;
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
for (IASTDeclarator declarator : declarators) {
- while (declarator.getNestedDeclarator() != null) {
- declarator = declarator.getNestedDeclarator();
- }
+ declarator= CVisitor.findInnermostDeclarator(declarator);
tempName = declarator.getName();
if (scope != null)
ASTInternal.addName(scope, tempName);
@@ -1633,7 +1631,7 @@ public class CVisitor {
} else if (!typesOnly && declaration instanceof IASTFunctionDefinition) {
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
- IASTDeclarator dtor = functionDef.getDeclarator();
+ IASTDeclarator dtor = CVisitor.findInnermostDeclarator(functionDef.getDeclarator());
tempName = dtor.getName();
if (scope != null)
ASTInternal.addName(scope, tempName);
@@ -1692,7 +1690,7 @@ public class CVisitor {
if (node instanceof IASTFunctionDefinition && decl instanceof IASTFunctionDeclarator) {
IASTFunctionDeclarator dtor = ((IASTFunctionDefinition) node).getDeclarator();
- IASTName name = dtor.getName();
+ IASTName name = CVisitor.findInnermostDeclarator(dtor).getName();
if (name.toString().equals(declName)) {
return dtor;
}
@@ -2179,14 +2177,13 @@ public class CVisitor {
* @since 5.0
*/
public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) {
- while(true) {
- IASTNode parent= declarator.getParent();
- if (parent instanceof IASTDeclarator) {
- declarator= (IASTDeclarator) parent;
- } else {
- return declarator;
- }
+ IASTDeclarator outermost= null;
+ IASTNode candidate= declarator;
+ while(candidate instanceof IASTDeclarator) {
+ outermost= (IASTDeclarator) candidate;
+ candidate= outermost.getParent();
}
+ return outermost;
}
/**
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
index ac1676681e8..cace918efae 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
@@ -432,15 +432,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (declarators.length != 1)
throwBacktrack(firstOffset, LA(1).getEndOffset());
-// IASTDeclarator declarator= CVisitor.findTypeRelevantDeclarator(declarators[0]); // mstodo
-
- IASTDeclarator declarator = declarators[0];
- if (!(declarator instanceof IASTFunctionDeclarator))
- throwBacktrack(firstOffset, LA(1).getEndOffset());
+ final IASTDeclarator outerDtor= declarators[0];
+ final IASTDeclarator fdtor= CVisitor.findTypeRelevantDeclarator(outerDtor);
+ if (fdtor instanceof IASTFunctionDeclarator == false)
+ throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
IASTFunctionDefinition funcDefinition = createFunctionDefinition();
funcDefinition.setDeclSpecifier(declSpec);
- funcDefinition.setDeclarator((IASTFunctionDeclarator) declarator);
+ funcDefinition.setDeclarator((IASTFunctionDeclarator) fdtor);
IASTStatement s= handleFunctionBody();
funcDefinition.setBody(s);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java
index cff573d62f8..ce91d846191 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTFunctionDefinition.java
@@ -6,12 +6,14 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * IBM - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -19,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* @author jcamelon
@@ -59,8 +62,9 @@ public class CPPASTFunctionDefinition extends CPPASTNode implements
public void setDeclarator(IASTFunctionDeclarator declarator) {
this.declarator = declarator;
if (declarator != null) {
- declarator.setParent(this);
- declarator.setPropertyInParent(DECLARATOR);
+ IASTDeclarator outerDtor= CPPVisitor.findOutermostDeclarator(declarator);
+ outerDtor.setParent(this);
+ outerDtor.setPropertyInParent(DECLARATOR);
}
}
@@ -91,7 +95,8 @@ public class CPPASTFunctionDefinition extends CPPASTNode implements
}
if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false;
- if( declarator != null ) if( !declarator.accept( action ) ) return false;
+ final IASTDeclarator outerDtor= CPPVisitor.findOutermostDeclarator(declarator);
+ if( outerDtor != null ) if( !outerDtor.accept( action ) ) return false;
if( bodyStatement != null ) if( !bodyStatement.accept( action ) ) return false;
if( action.shouldVisitDeclarations ){
@@ -112,5 +117,4 @@ public class CPPASTFunctionDefinition extends CPPASTNode implements
bodyStatement = (IASTStatement) other;
}
}
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java
index 60cd148be6c..107f8f0ec63 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPBlockScope.java
@@ -17,9 +17,11 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
* @author aniefer
@@ -32,8 +34,13 @@ public class CPPBlockScope extends CPPNamespaceScope implements ICPPBlockScope {
@Override
public IName getScopeName(){
IASTNode node = getPhysicalNode();
- if( node instanceof IASTCompoundStatement && node.getParent() instanceof IASTFunctionDefinition ){
- return ((IASTFunctionDefinition)node.getParent()).getDeclarator().getName();
+ if (node instanceof IASTCompoundStatement) {
+ final IASTNode parent= node.getParent();
+ if (parent instanceof IASTFunctionDefinition) {
+ IASTDeclarator dtor= ((IASTFunctionDefinition)parent).getDeclarator();
+ dtor = CPPVisitor.findInnermostDeclarator(dtor);
+ return dtor.getName();
+ }
}
return null;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java
index 6b83625c43e..d99ecd8a58b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java
@@ -463,12 +463,12 @@ class ImplicitsAnalysis {
}
boolean nameEquals= false;
+ char[] dtorname= CPPVisitor.findInnermostDeclarator(dcltor).getName().toCharArray();
if (constructor) {
- nameEquals= CharArrayUtils.equals(dcltor.getName().toCharArray(), name);
+ nameEquals= CharArrayUtils.equals(dtorname, name);
} else {
- char[] cname= dcltor.getName().toCharArray();
- if (cname.length > 0 && cname[0] == '~') {
- nameEquals= CharArrayUtils.equals(cname, 1, name.length, name);
+ if (dtorname.length > 0 && dtorname[0] == '~') {
+ nameEquals= CharArrayUtils.equals(dtorname, 1, name.length, name);
}
}
@@ -493,11 +493,13 @@ class ImplicitsAnalysis {
} else if (member instanceof IASTFunctionDefinition) {
dcltor = ((IASTFunctionDefinition)member).getDeclarator();
}
- if (!(dcltor instanceof ICPPASTFunctionDeclarator) ||
- !CharArrayUtils.equals(dcltor.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray())) {
+ if (dcltor instanceof ICPPASTFunctionDeclarator == false)
+ continue;
+
+ final char[] nchars= CPPVisitor.findInnermostDeclarator(dcltor).getName().toCharArray();
+ if (!CharArrayUtils.equals(nchars, OverloadableOperator.ASSIGN.toCharArray()))
continue;
- }
-
+
IASTParameterDeclaration[] ps = ((ICPPASTFunctionDeclarator)dcltor).getParameters();
if (ps.length != 1 || !paramHasTypeReferenceToTheAssociatedClassType(ps[0], null))
continue;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java
index 49b08a96e45..76d848095c6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassSpecialization.java
@@ -182,7 +182,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements
}
} else if( decl instanceof IASTFunctionDefinition ){
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
- dtor = CPPVisitor.getMostNestedDeclarator( dtor );
+ dtor = CPPVisitor.findInnermostDeclarator(dtor);
binding = dtor.getName().resolveBinding();
if( binding instanceof ICPPMethod ){
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
@@ -225,10 +225,12 @@ public class CPPClassSpecialization extends CPPSpecialization implements
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
for (IASTDeclarator dtor : dtors) {
if( dtor == null ) break;
+ dtor= CPPVisitor.findInnermostDeclarator(dtor);
ASTInternal.addName(scope, dtor.getName() );
}
} else if( decl instanceof IASTFunctionDefinition ){
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
+ dtor= CPPVisitor.findInnermostDeclarator(dtor);
ASTInternal.addName(scope, dtor.getName() );
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java
index e798ac297b6..c9159156ac1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java
@@ -109,7 +109,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
public CPPFunction(ICPPASTFunctionDeclarator declarator) {
if (declarator != null) {
- IASTNode parent = declarator.getParent();
+ IASTNode parent = CPPVisitor.findOutermostDeclarator(declarator).getParent();
if (parent instanceof IASTFunctionDefinition)
definition = declarator;
else
@@ -160,48 +160,54 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
}
public void addDefinition(IASTNode node) {
- if (node instanceof IASTName)
- node = node.getParent();
- if (!(node instanceof ICPPASTFunctionDeclarator))
- return;
- ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node;
- updateParameterBindings(dtor);
- definition = dtor;
- }
- public void addDeclaration(IASTNode node) {
- if (node instanceof IASTName)
- node = node.getParent();
- if (!(node instanceof ICPPASTFunctionDeclarator))
- return;
-
- ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node;
- updateParameterBindings(dtor);
-
- if (declarations == null) {
- declarations = new ICPPASTFunctionDeclarator[] { dtor };
- return;
- }
-
- // Keep the lowest offset declaration in [0]
- if (declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset()) {
- declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.prepend(ICPPASTFunctionDeclarator.class,
- declarations, dtor);
- } else {
- declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.append(ICPPASTFunctionDeclarator.class,
- declarations, dtor);
+ ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node);
+ if (dtor != null) {
+ updateParameterBindings(dtor);
+ definition = dtor;
}
}
- public void removeDeclaration(IASTNode node) {
- while (node instanceof IASTName) {
- node = node.getParent();
+ public void addDeclaration(IASTNode node) {
+ ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node);
+ if (dtor != null) {
+ updateParameterBindings(dtor);
+
+ if (declarations == null) {
+ declarations = new ICPPASTFunctionDeclarator[] { dtor };
+ return;
+ }
+
+ // Keep the lowest offset declaration in [0]
+ if (declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset()) {
+ declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.prepend(ICPPASTFunctionDeclarator.class,
+ declarations, dtor);
+ } else {
+ declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.append(ICPPASTFunctionDeclarator.class,
+ declarations, dtor);
+ }
}
- if (definition == node) {
+ }
+
+ private ICPPASTFunctionDeclarator extractFunctionDtor(IASTNode node) {
+ if (node instanceof IASTName)
+ node = node.getParent();
+ if (node instanceof IASTDeclarator == false)
+ return null;
+ node= CPPVisitor.findTypeRelevantDeclarator((IASTDeclarator) node);
+ if (node instanceof ICPPASTFunctionDeclarator == false)
+ return null;
+
+ return (ICPPASTFunctionDeclarator) node;
+ }
+
+ public void removeDeclaration(IASTNode node) {
+ ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node);
+ if (definition == dtor) {
definition = null;
return;
}
if (declarations != null) {
- ArrayUtil.remove(declarations, node);
+ ArrayUtil.remove(declarations, dtor);
}
}
@@ -250,11 +256,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
protected IASTName getASTName() {
IASTDeclarator dtor = (definition != null) ? definition : declarations[0];
- IASTDeclarator nested= dtor.getNestedDeclarator();
- while (nested != null) {
- dtor= nested;
- nested= nested.getNestedDeclarator();
- }
+ dtor= CPPVisitor.findInnermostDeclarator(dtor);
IASTName name= dtor.getName();
if (name instanceof ICPPASTQualifiedName) {
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
@@ -263,23 +265,17 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
return name;
}
-
-
public IScope getScope() {
IASTName n = getASTName();
IScope scope = CPPVisitor.getContainingScope(n);
if (scope instanceof ICPPClassScope) {
ICPPASTDeclSpecifier declSpec = null;
if (definition != null) {
- IASTNode node = definition.getParent();
- while (node instanceof IASTDeclarator)
- node = node.getParent();
+ IASTNode node = CPPVisitor.findOutermostDeclarator(definition).getParent();
IASTFunctionDefinition def = (IASTFunctionDefinition) node;
declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier();
} else {
- IASTNode node = declarations[0].getParent();
- while (node instanceof IASTDeclarator)
- node = node.getParent();
+ IASTNode node = CPPVisitor.findOutermostDeclarator(declarations[0]).getParent();
IASTSimpleDeclaration decl = (IASTSimpleDeclaration)node;
declSpec = (ICPPASTDeclSpecifier) decl.getDeclSpecifier();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java
index 5c917103a1d..c1d99e2c0c1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPImplicitMethod.java
@@ -74,11 +74,11 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
//first check if we already know it
if( declarations != null ){
- for (ICPPASTFunctionDeclarator declaration : declarations) {
- if (declaration == null) {
+ for (ICPPASTFunctionDeclarator dtor : declarations) {
+ if (dtor == null)
break;
- }
- IASTDeclaration decl = (IASTDeclaration) declaration.getParent();
+
+ IASTDeclaration decl= (IASTDeclaration) CPPVisitor.findOutermostDeclarator(dtor).getParent();
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
return decl;
}
@@ -108,8 +108,8 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
di = 0;
dtor = ds[0];
while( dtor != null ){
- IASTName name = dtor.getName();
- if( dtor instanceof ICPPASTFunctionDeclarator &&
+ IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
+ if( CPPVisitor.findTypeRelevantDeclarator(dtor) instanceof ICPPASTFunctionDeclarator &&
CharArrayUtils.equals( name.toCharArray(), getNameCharArray() ) )
{
IType t0= CPPVisitor.createType( dtor );
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java
index 135997100c5..a6ca9dc6367 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethod.java
@@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -83,13 +84,11 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
//first check if we already know it
if( declarations != null ){
- for( int i = 0; i < declarations.length; i++ ){
- IASTDeclarator dtor = declarations[i];
+ for (IASTDeclarator dtor : declarations) {
if (dtor == null) {
break;
}
- while( dtor.getParent() instanceof IASTDeclarator )
- dtor = (IASTDeclarator) dtor.getParent();
+ dtor= CPPVisitor.findOutermostDeclarator(dtor);
IASTDeclaration decl = (IASTDeclaration) dtor.getParent();
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
return decl;
@@ -102,23 +101,24 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope);
if (compSpec != null) {
IASTDeclaration [] members = compSpec.getMembers();
- for( int i = 0; i < members.length; i++ ){
- if( members[i] instanceof IASTSimpleDeclaration ){
- IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators();
- for( int j = 0; j < dtors.length; j++ ){
- IASTName name = dtors[j].getName();
+ for (IASTDeclaration member : members) {
+ if( member instanceof IASTSimpleDeclaration ){
+ IASTDeclarator [] dtors = ((IASTSimpleDeclaration)member).getDeclarators();
+ for (IASTDeclarator dtor : dtors) {
+ IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this )
{
- return members[i];
+ return member;
}
}
- } else if( members[i] instanceof IASTFunctionDefinition ){
- IASTName name = ((IASTFunctionDefinition) members[i]).getDeclarator().getName();
+ } else if( member instanceof IASTFunctionDefinition ){
+ final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition) member).getDeclarator();
+ IASTName name = CPPVisitor.findInnermostDeclarator(declarator).getName();
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this )
{
- return members[i];
+ return member;
}
}
}
@@ -143,10 +143,10 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent();
IASTDeclaration [] members = cls.getMembers();
ICPPASTVisibilityLabel vis = null;
- for( int i = 0; i < members.length; i++ ){
- if( members[i] instanceof ICPPASTVisibilityLabel )
- vis = (ICPPASTVisibilityLabel) members[i];
- else if( members[i] == decl )
+ for (IASTDeclaration member : members) {
+ if( member instanceof ICPPASTVisibilityLabel )
+ vis = (ICPPASTVisibilityLabel) member;
+ else if( member == decl )
break;
}
if( vis != null ){
@@ -162,30 +162,23 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
return scope.getClassType();
}
- @Override
- public IScope getScope() {
- IASTNode node = (declarations != null && declarations.length > 0) ? declarations[0] : definition;
- if( node instanceof IASTDeclarator ){
- IASTName name = ((IASTDeclarator)node).getName();
- if( name instanceof ICPPASTQualifiedName ){
- IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
- name = ns[ ns.length - 1 ];
- }
- return CPPVisitor.getContainingScope( name );
- }
- return CPPVisitor.getContainingScope( node );
- }
-
@Override
protected IASTName getASTName() {
- IASTName name= definition != null ? definition.getName() : declarations[0].getName();
- if( name instanceof ICPPASTQualifiedName ){
- final IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
- return ns[ns.length - 1];
+ IASTDeclarator dtor= (declarations != null && declarations.length > 0) ? declarations[0] : definition;
+ dtor= CPPVisitor.findInnermostDeclarator(dtor);
+ IASTName name= dtor.getName();
+ if (name instanceof ICPPASTQualifiedName) {
+ IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
+ name = ns[ ns.length - 1 ];
}
return name;
}
+ @Override
+ public IScope getScope() {
+ return CPPVisitor.getContainingScope(getASTName());
+ }
+
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual()
*/
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java
index efa5d5f7577..41cd57db3c6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java
@@ -9,9 +9,6 @@
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
-/*
- * Created on Mar 31, 2005
- */
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
@@ -75,7 +72,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
if( decl instanceof IASTSimpleDeclaration ){
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
for (IASTDeclarator dtor : dtors) {
- IASTName name = CPPVisitor.getMostNestedDeclarator( dtor ).getName();
+ IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this )
{
@@ -83,7 +80,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
}
}
} else if( decl instanceof IASTFunctionDefinition ){
- IASTName name = CPPVisitor.getMostNestedDeclarator( ((IASTFunctionDefinition) decl).getDeclarator() ).getName();
+ IASTName name = CPPVisitor.findInnermostDeclarator(((IASTFunctionDefinition) decl).getDeclarator()).getName();
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this )
{
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeMixin.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeMixin.java
index 1c3333b90a6..76d489396f4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeMixin.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeMixin.java
@@ -72,8 +72,7 @@ class ClassTypeMixin {
}
ObjectSetdeclarator
nests within, or
* declarator
itself.
- * @since 5.0
*/
public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) {
- while(true) {
- IASTNode parent= declarator.getParent();
- if (parent instanceof IASTDeclarator) {
- declarator= (IASTDeclarator) parent;
- } else {
- return declarator;
- }
+ IASTDeclarator outermost= null;
+ IASTNode candidate= declarator;
+ while(candidate instanceof IASTDeclarator) {
+ outermost= (IASTDeclarator) candidate;
+ candidate= outermost.getParent();
}
+ return outermost;
}
/**
* Returns the innermost declarator nested within the given declarator
, or
* declarator
itself.
- * @since 5.1
*/
public static IASTDeclarator findInnermostDeclarator(IASTDeclarator declarator) {
IASTDeclarator innermost= null;
@@ -2473,7 +2447,6 @@ public class CPPVisitor {
/**
* Searches for the innermost declarator that contributes the the type declared.
- * @since 5.1
*/
public static IASTDeclarator findTypeRelevantDeclarator(IASTDeclarator declarator) {
IASTDeclarator result= findInnermostDeclarator(declarator);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java
index 47d7c727b6e..691b8ca1452 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java
@@ -7,7 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
@@ -15,7 +16,6 @@ import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
-import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
@@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
@@ -278,7 +279,7 @@ public class DeclarationWriter extends NodeWriter{
}else {
scribe.printSpace();
}
- IASTFunctionDeclarator declarator = funcDef.getDeclarator();
+ IASTDeclarator declarator = CPPVisitor.findOutermostDeclarator(funcDef.getDeclarator());
declarator.accept(visitor);
scribe.newLine();
funcDef.getBody().accept(visitor);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoring.java
index f2b4d3fdb01..faddf10f407 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoring.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/hidemethod/HideMethodRefactoring.java
@@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange;
@@ -109,7 +110,7 @@ public class HideMethodRefactoring extends CRefactoring {
sm.worked(1);
if(methodToHideDecl instanceof IASTFunctionDefinition) {
IASTDeclarator declarator = ((IASTFunctionDefinition)methodToHideDecl).getDeclarator();
- if(declarator.getName().getRawSignature().equals(name.getRawSignature())) {
+ if(CPPVisitor.findInnermostDeclarator(declarator).getName().getRawSignature().equals(name.getRawSignature())) {
if (!(declarator instanceof IASTFunctionDeclarator)) {
initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods);
return initStatus;
@@ -215,7 +216,7 @@ public class HideMethodRefactoring extends CRefactoring {
IASTNode parent = compStat.getParent();
if(parent instanceof IASTFunctionDefinition) {
IASTDeclarator declarator = ((IASTFunctionDefinition)parent).getDeclarator();
- IASTName declaratorName = getLastName(declarator);
+ IASTName declaratorName = getLastName(CPPVisitor.findInnermostDeclarator(declarator));
DeclarationFinderDO data = DeclarationFinder.getDeclaration(declaratorName, getIndex());
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NodeHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NodeHelper.java
index 1bd5aade32e..cc12c8acdd9 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NodeHelper.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NodeHelper.java
@@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
@@ -108,7 +109,7 @@ public class NodeHelper {
found = true;
context.setType(MethodContext.ContextType.FUNCTION);
} else if (node instanceof IASTFunctionDefinition){
- name=((IASTFunctionDefinition)node).getDeclarator().getName();
+ name=CPPVisitor.findInnermostDeclarator(((IASTFunctionDefinition)node).getDeclarator()).getName();
found = true;
context.setType(MethodContext.ContextType.FUNCTION);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java
index bb5f18d1fe5..1b6d2c38a64 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java
@@ -90,6 +90,7 @@ import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
+import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.model.ASTCache;
@@ -230,7 +231,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
if (declaration instanceof IASTFunctionDefinition) {
final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition)declaration).getDeclarator();
if (declarator != null) {
- fFunction= new String(declarator.getName().toCharArray());
+ fFunction= new String(CVisitor.findInnermostDeclarator(declarator).getName().toCharArray());
fLevel= 0;
}
}