1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +02:00

Follow up 181305, binding returns empty name for 'void (fn)();'

This commit is contained in:
Markus Schorn 2007-04-16 14:55:42 +00:00
parent 2b14d7a898
commit a8ced8a5d3
3 changed files with 32 additions and 24 deletions

View file

@ -3603,6 +3603,7 @@ public class AST2Tests extends AST2BaseTest {
IBinding binding= idExpr.getName().resolveBinding(); IBinding binding= idExpr.getName().resolveBinding();
assertTrue(lang.toString(), binding instanceof IFunction); assertTrue(lang.toString(), binding instanceof IFunction);
assertFalse(lang.toString(), binding instanceof IProblemBinding); assertFalse(lang.toString(), binding instanceof IProblemBinding);
assertEquals(binding.getName(), "decl");
} }
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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() * @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/ */
public String getName() { public String getName() {
IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0]; return getASTName().toString();
return dtor.getName().toString();
} }
public char[] getNameCharArray(){ public char[] getNameCharArray(){
IASTFunctionDeclarator dtor = ( definition != null ) ? definition : declarators[0]; return getASTName().toCharArray();
return dtor.getName().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) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/ */

View file

@ -155,11 +155,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
else else
declarations = new ICPPASTFunctionDeclarator [] { declarator }; declarations = new ICPPASTFunctionDeclarator [] { declarator };
IASTName name = declarator.getName(); IASTName name= getASTName();
if( name instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ];
}
name.setBinding( this ); name.setBinding( this );
} }
} }
@ -283,35 +279,37 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName() * @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/ */
public String getName() { public String getName() {
IASTName name = (definition != null ) ? definition.getName() : declarations[0].getName(); return getASTName().toString();
if( name instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ];
}
return name.toString();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray() * @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
*/ */
public char[] 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 ){ if( name instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ]; name = ns[ ns.length - 1 ];
} }
return name.toCharArray(); return name;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope() * @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/ */
public IScope getScope() { public IScope getScope() {
IASTName n = definition != null ? definition.getName() : declarations[0].getName(); IASTName n= getASTName();
if( n instanceof ICPPASTQualifiedName ){
IASTName [] ns = ((ICPPASTQualifiedName)n).getNames();
n = ns[ ns.length - 1 ];
}
IScope scope = CPPVisitor.getContainingScope( n ); IScope scope = CPPVisitor.getContainingScope( n );
if( scope instanceof ICPPClassScope ){ if( scope instanceof ICPPClassScope ){
ICPPASTDeclSpecifier declSpec = null; ICPPASTDeclSpecifier declSpec = null;
@ -497,7 +495,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
static public boolean hasStorageClass( ICPPInternalFunction function, int storage ){ static public boolean hasStorageClass( ICPPInternalFunction function, int storage ){
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) function.getDefinition(); ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) function.getDefinition();
IASTNode[] ds = (IASTNode[]) function.getDeclarations(); IASTNode[] ds = function.getDeclarations();
int i = -1; int i = -1;
do{ do{