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 2f5abef4832..157499db875 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 @@ -3603,6 +3603,7 @@ public class AST2Tests extends AST2BaseTest { IBinding binding= idExpr.getName().resolveBinding(); assertTrue(lang.toString(), binding instanceof IFunction); assertFalse(lang.toString(), binding instanceof IProblemBinding); + assertEquals(binding.getName(), "decl"); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index bcd5c857a67..743c1e3b2dc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -157,14 +157,23 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() */ public String getName() { - IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0]; - return dtor.getName().toString(); + return getASTName().toString(); } + public char[] getNameCharArray(){ - IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0]; - return dtor.getName().toCharArray(); + return getASTName().toCharArray(); } + private IASTName getASTName() { + IASTDeclarator dtor = ( definition != null ) ? definition : declarators[0]; + IASTDeclarator nested= dtor.getNestedDeclarator(); + while (nested != null && nested.getPointerOperators().length == 0) { + dtor= nested; + nested= nested.getNestedDeclarator(); + } + return dtor.getName(); + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() */ 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 ce753276b51..31402182572 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 @@ -155,11 +155,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt else declarations = new ICPPASTFunctionDeclarator [] { declarator }; - IASTName name = declarator.getName(); - if( name instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); - name = ns[ ns.length - 1 ]; - } + IASTName name= getASTName(); name.setBinding( this ); } } @@ -283,35 +279,37 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt * @see org.eclipse.cdt.core.dom.ast.IBinding#getName() */ public String getName() { - IASTName name = (definition != null ) ? definition.getName() : declarations[0].getName(); - if( name instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); - name = ns[ ns.length - 1 ]; - } - return name.toString(); + return getASTName().toString(); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray() */ public char[] getNameCharArray() { - IASTName name = (definition != null ) ? definition.getName() : declarations[0].getName(); + return getASTName().toCharArray(); + } + + private IASTName getASTName() { + IASTDeclarator dtor = ( definition != null ) ? definition : declarations[0]; + IASTDeclarator nested= dtor.getNestedDeclarator(); + while (nested != null) { + dtor= nested; + nested= nested.getNestedDeclarator(); + } + IASTName name= dtor.getName(); if( name instanceof ICPPASTQualifiedName ){ IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); name = ns[ ns.length - 1 ]; } - return name.toCharArray(); + return name; } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() */ public IScope getScope() { - IASTName n = definition != null ? definition.getName() : declarations[0].getName(); - if( n instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)n).getNames(); - n = ns[ ns.length - 1 ]; - } + IASTName n= getASTName(); IScope scope = CPPVisitor.getContainingScope( n ); if( scope instanceof ICPPClassScope ){ ICPPASTDeclSpecifier declSpec = null; @@ -497,7 +495,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt static public boolean hasStorageClass( ICPPInternalFunction function, int storage ){ ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) function.getDefinition(); - IASTNode[] ds = (IASTNode[]) function.getDeclarations(); + IASTNode[] ds = function.getDeclarations(); int i = -1; do{