1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

fix bug 86358

This commit is contained in:
Andrew Niefer 2005-02-24 20:45:41 +00:00
parent 92eae6c108
commit 885d10dd7a
2 changed files with 60 additions and 2 deletions

View file

@ -2289,5 +2289,52 @@ public class AST2CPPTests extends AST2BaseTest {
assertInstances( col, point, 4 );
}
public void testBug86358_1() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("namespace Outer{ \n"); //$NON-NLS-1$
buffer.append(" int i; \n"); //$NON-NLS-1$
buffer.append(" namespace Inner { \n"); //$NON-NLS-1$
buffer.append(" void f() { i++; } \n"); //$NON-NLS-1$
buffer.append(" int i; \n"); //$NON-NLS-1$
buffer.append(" void g() { i++; } \n"); //$NON-NLS-1$
buffer.append(" } \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
CPPNameCollector col = new CPPNameCollector();
tu.getVisitor().visitTranslationUnit(col);
IVariable i = (IVariable) col.getName(4).resolveBinding();
IVariable i2 = (IVariable) col.getName(7).resolveBinding();
assertInstances( col, i, 2 );
assertInstances( col, i2, 2 );
}
public void testBug86358_2() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("namespace Q { \n"); //$NON-NLS-1$
buffer.append(" namespace V { \n"); //$NON-NLS-1$
buffer.append(" void f(); \n"); //$NON-NLS-1$
buffer.append(" } \n"); //$NON-NLS-1$
buffer.append(" void V::f() {} \n"); //$NON-NLS-1$
buffer.append(" namespace V { \n"); //$NON-NLS-1$
buffer.append(" } \n"); //$NON-NLS-1$
buffer.append("} \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
CPPNameCollector col = new CPPNameCollector();
tu.getVisitor().visitTranslationUnit(col);
IFunction f1 = (IFunction) col.getName(2).resolveBinding();
IFunction f2 = (IFunction) col.getName(5).resolveBinding();
assertSame( f1, f2 );
IASTName [] decls = tu.getDeclarations( f2 );
assertEquals( decls.length, 2 );
assertSame( decls[0], col.getName(2) );
assertSame( decls[1], col.getName(5) );
}
}

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
@ -181,14 +182,24 @@ public class CPPFunction implements IFunction, ICPPBinding {
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
public String getName() {
return (definition != null ) ? definition.getName().toString() : declarations[0].getName().toString();
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();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
*/
public char[] getNameCharArray() {
return (definition != null ) ? definition.getName().toCharArray() : declarations[0].getName().toCharArray();
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.toCharArray();
}
/* (non-Javadoc)