mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
fix bug 89851
when considering the offset of a binding, use the lowest offset of all its declarations/definitions instead of just the offset of the declaration that was resolved first.
This commit is contained in:
parent
9a6a9c9350
commit
cc1cf61ddf
2 changed files with 34 additions and 6 deletions
|
@ -3120,5 +3120,23 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
|
|
||||||
assertTrue( col.getName(4).resolveBinding() instanceof ICPPConstructor );
|
assertTrue( col.getName(4).resolveBinding() instanceof ICPPConstructor );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug89851() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "class B * b; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append( "class A { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append( " A * a; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append( "}; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append( "class A; \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP ); //$NON-NLS-1$
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
tu.accept( col );
|
||||||
|
|
||||||
|
assertTrue( col.getName(0).resolveBinding() instanceof ICPPClassType );
|
||||||
|
assertTrue( col.getName(1).resolveBinding() instanceof ICPPVariable );
|
||||||
|
assertTrue( col.getName(2).resolveBinding() instanceof ICPPClassType );
|
||||||
|
assertTrue( col.getName(3).resolveBinding() instanceof ICPPClassType );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1318,12 +1318,22 @@ public class CPPSemantics {
|
||||||
if( obj instanceof ICPPInternalBinding ){
|
if( obj instanceof ICPPInternalBinding ){
|
||||||
ICPPInternalBinding cpp = (ICPPInternalBinding) obj;
|
ICPPInternalBinding cpp = (ICPPInternalBinding) obj;
|
||||||
IASTNode[] n = cpp.getDeclarations();
|
IASTNode[] n = cpp.getDeclarations();
|
||||||
|
int o, offset = -1;
|
||||||
if( n != null && n.length > 0 )
|
if( n != null && n.length > 0 ) {
|
||||||
nd = (ASTNode) n[0];
|
nd = (ASTNode) n[0];
|
||||||
else if( cpp.getDefinition() != null )
|
offset = ((ASTNode) n[0]).getOffset();
|
||||||
|
for (int i = 1; i < n.length && n[i] != null; i++) {
|
||||||
|
o = ((ASTNode) n[i]).getOffset();
|
||||||
|
if( o < offset )
|
||||||
|
nd = (ASTNode) n[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( cpp.getDefinition() != null ){
|
||||||
|
if( nd == null || ((ASTNode)cpp.getDefinition()).getOffset() < nd.getOffset() )
|
||||||
nd = (ASTNode) cpp.getDefinition();
|
nd = (ASTNode) cpp.getDefinition();
|
||||||
else
|
|
||||||
|
}
|
||||||
|
if( nd == null )
|
||||||
return true;
|
return true;
|
||||||
} else if( obj instanceof ASTNode ){
|
} else if( obj instanceof ASTNode ){
|
||||||
nd = (ASTNode) obj;
|
nd = (ASTNode) obj;
|
||||||
|
|
Loading…
Add table
Reference in a new issue