mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-30 21:55:31 +02:00
fix bug 84228
This commit is contained in:
parent
9b8605a1cf
commit
25288449a4
2 changed files with 76 additions and 18 deletions
|
@ -2772,5 +2772,36 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
IFunctionType ft = (IFunctionType) t;
|
IFunctionType ft = (IFunctionType) t;
|
||||||
assertTrue( ft.getReturnType() instanceof IPointerType );
|
assertTrue( ft.getReturnType() instanceof IPointerType );
|
||||||
assertSame( ((IPointerType)ft.getReturnType()).getType(), S );
|
assertSame( ((IPointerType)ft.getReturnType()).getType(), S );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug84228() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "void f( int m, int c[m][m] ); \n" ); //$NON-NLS-1$
|
||||||
|
buffer.append( "void f( int m, int c[m][m] ){ \n" ); //$NON-NLS-1$
|
||||||
|
buffer.append( " int x; \n" ); //$NON-NLS-1$
|
||||||
|
buffer.append( " { int x = x; } \n" ); //$NON-NLS-1$
|
||||||
|
buffer.append( "} \n" ); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||||
|
CNameCollector col = new CNameCollector();
|
||||||
|
CVisitor.visitTranslationUnit(tu, col);
|
||||||
|
|
||||||
|
assertEquals(col.size(), 13);
|
||||||
|
|
||||||
|
IParameter m = (IParameter) col.getName(1).resolveBinding();
|
||||||
|
IVariable x3 = (IVariable) col.getName(12).resolveBinding();
|
||||||
|
IVariable x2 = (IVariable) col.getName(11).resolveBinding();
|
||||||
|
IVariable x1 = (IVariable) col.getName(10).resolveBinding();
|
||||||
|
|
||||||
|
assertSame( x2, x3 );
|
||||||
|
assertNotSame( x1, x2 );
|
||||||
|
|
||||||
|
assertInstances( col, m, 6 );
|
||||||
|
assertInstances( col, x1, 1 );
|
||||||
|
assertInstances( col, x2, 2 );
|
||||||
|
|
||||||
|
IASTName [] ds = tu.getDeclarations( x2 );
|
||||||
|
assertEquals( ds.length, 1 );
|
||||||
|
assertSame( ds[0], col.getName(11) );
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -475,9 +475,10 @@ public class CVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
//lookup bits
|
//lookup bits
|
||||||
private static final int COMPLETE = 0;
|
private static final int COMPLETE = 0;
|
||||||
private static final int CURRENT_SCOPE = 1;
|
private static final int CURRENT_SCOPE = 1;
|
||||||
private static final int TAGS = 2;
|
private static final int TAGS = 1 << 1;
|
||||||
|
private static final int INCLUDE_BLOCK_ITEM = 1 << 2;
|
||||||
|
|
||||||
//definition lookup start loc
|
//definition lookup start loc
|
||||||
protected static final int AT_BEGINNING = 1;
|
protected static final int AT_BEGINNING = 1;
|
||||||
|
@ -488,7 +489,7 @@ public class CVisitor {
|
||||||
IASTNode parent = name.getParent();
|
IASTNode parent = name.getParent();
|
||||||
|
|
||||||
if( parent instanceof CASTIdExpression ){
|
if( parent instanceof CASTIdExpression ){
|
||||||
binding = resolveBinding( parent );
|
binding = resolveBinding( parent, COMPLETE | INCLUDE_BLOCK_ITEM );
|
||||||
} else if( parent instanceof ICASTTypedefNameSpecifier ){
|
} else if( parent instanceof ICASTTypedefNameSpecifier ){
|
||||||
binding = resolveBinding( parent );
|
binding = resolveBinding( parent );
|
||||||
} else if( parent instanceof IASTFieldReference ){
|
} else if( parent instanceof IASTFieldReference ){
|
||||||
|
@ -1043,7 +1044,8 @@ public class CVisitor {
|
||||||
//if parent is something that can contain a declaration
|
//if parent is something that can contain a declaration
|
||||||
else if ( parent instanceof IASTCompoundStatement ||
|
else if ( parent instanceof IASTCompoundStatement ||
|
||||||
parent instanceof IASTTranslationUnit ||
|
parent instanceof IASTTranslationUnit ||
|
||||||
parent instanceof IASTForStatement )
|
parent instanceof IASTForStatement ||
|
||||||
|
parent instanceof IASTFunctionDeclarator )
|
||||||
{
|
{
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -1066,10 +1068,18 @@ public class CVisitor {
|
||||||
IASTTranslationUnit translation = (IASTTranslationUnit) parent;
|
IASTTranslationUnit translation = (IASTTranslationUnit) parent;
|
||||||
nodes = translation.getDeclarations();
|
nodes = translation.getDeclarations();
|
||||||
scope = (ICScope) translation.getScope();
|
scope = (ICScope) translation.getScope();
|
||||||
|
} else if( parent instanceof IASTStandardFunctionDeclarator ){
|
||||||
|
IASTStandardFunctionDeclarator dtor = (IASTStandardFunctionDeclarator) parent;
|
||||||
|
nodes = dtor.getParameters();
|
||||||
|
scope = (ICScope) getContainingScope( blockItem );
|
||||||
|
} else if( parent instanceof ICASTKnRFunctionDeclarator ){
|
||||||
|
ICASTKnRFunctionDeclarator dtor = (ICASTKnRFunctionDeclarator) parent;
|
||||||
|
nodes = dtor.getParameterDeclarations();
|
||||||
|
scope = (ICScope) getContainingScope( blockItem );
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean typesOnly = (bits & TAGS) != 0;
|
boolean typesOnly = (bits & TAGS) != 0;
|
||||||
|
boolean includeBlockItem = (bits & INCLUDE_BLOCK_ITEM) != 0;
|
||||||
if( scope != null ){
|
if( scope != null ){
|
||||||
int namespaceType = typesOnly ? ICScope.NAMESPACE_TYPE_TAG : ICScope.NAMESPACE_TYPE_OTHER;
|
int namespaceType = typesOnly ? ICScope.NAMESPACE_TYPE_TAG : ICScope.NAMESPACE_TYPE_OTHER;
|
||||||
try {
|
try {
|
||||||
|
@ -1084,17 +1094,22 @@ public class CVisitor {
|
||||||
if( nodes != null ){
|
if( nodes != null ){
|
||||||
for( int i = 0; i < nodes.length; i++ ){
|
for( int i = 0; i < nodes.length; i++ ){
|
||||||
IASTNode node = nodes[i];
|
IASTNode node = nodes[i];
|
||||||
if( node == null || node == blockItem )
|
if( node == null || ( !includeBlockItem && node == blockItem ) )
|
||||||
break;
|
break;
|
||||||
if( node instanceof IASTDeclarationStatement ){
|
if( node instanceof IASTDeclarationStatement ){
|
||||||
IASTDeclarationStatement declStatement = (IASTDeclarationStatement) node;
|
IASTDeclarationStatement declStatement = (IASTDeclarationStatement) node;
|
||||||
binding = checkForBinding( declStatement.getDeclaration(), name, typesOnly );
|
binding = checkForBinding( declStatement.getDeclaration(), name, typesOnly );
|
||||||
} else if( node instanceof IASTDeclaration ){
|
} else if( node instanceof IASTDeclaration ){
|
||||||
binding = checkForBinding( (IASTDeclaration) node, name, typesOnly );
|
binding = checkForBinding( (IASTDeclaration) node, name, typesOnly );
|
||||||
|
} else if( node instanceof IASTParameterDeclaration ){
|
||||||
|
binding = checkForBinding( (IASTParameterDeclaration) node, name, typesOnly );
|
||||||
}
|
}
|
||||||
if( binding != null ){
|
if( binding != null ){
|
||||||
return binding;
|
return binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( includeBlockItem && node == blockItem )
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//check the parent
|
//check the parent
|
||||||
|
@ -1186,6 +1201,24 @@ public class CVisitor {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
private static IBinding checkForBinding( IASTParameterDeclaration paramDecl, IASTName name, boolean typesOnly ){
|
||||||
|
if( paramDecl == null ) return null;
|
||||||
|
|
||||||
|
if( typesOnly ){
|
||||||
|
return checkForBinding( paramDecl.getDeclSpecifier(), name, typesOnly );
|
||||||
|
}
|
||||||
|
|
||||||
|
IASTDeclarator dtor = paramDecl.getDeclarator();
|
||||||
|
while( dtor.getNestedDeclarator() != null ){
|
||||||
|
dtor = dtor.getNestedDeclarator();
|
||||||
|
}
|
||||||
|
IASTName declName = dtor.getName();
|
||||||
|
if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
|
||||||
|
return declName.resolveBinding();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static IBinding checkForBinding( IASTDeclaration declaration, IASTName name, boolean typesOnly ){
|
private static IBinding checkForBinding( IASTDeclaration declaration, IASTName name, boolean typesOnly ){
|
||||||
IASTName tempName = null;
|
IASTName tempName = null;
|
||||||
if( declaration instanceof IASTSimpleDeclaration ){
|
if( declaration instanceof IASTSimpleDeclaration ){
|
||||||
|
@ -1219,16 +1252,10 @@ public class CVisitor {
|
||||||
//check the parameters
|
//check the parameters
|
||||||
IASTParameterDeclaration [] parameters = declarator.getParameters();
|
IASTParameterDeclaration [] parameters = declarator.getParameters();
|
||||||
for( int i = 0; i < parameters.length; i++ ){
|
for( int i = 0; i < parameters.length; i++ ){
|
||||||
IASTParameterDeclaration parameterDeclaration = parameters[i];
|
IBinding binding = checkForBinding( parameters[i], name, typesOnly );
|
||||||
if( parameterDeclaration == null ) break;
|
if( binding != null ){
|
||||||
IASTDeclarator dtor = parameterDeclaration.getDeclarator();
|
return binding;
|
||||||
while( dtor.getNestedDeclarator() != null ){
|
}
|
||||||
dtor = dtor.getNestedDeclarator();
|
|
||||||
}
|
|
||||||
declName = dtor.getName();
|
|
||||||
if( CharArrayUtils.equals( declName.toCharArray(), name.toCharArray() ) ){
|
|
||||||
return declName.resolveBinding();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (functionDef.getDeclarator() instanceof ICASTKnRFunctionDeclarator) {
|
} else if (functionDef.getDeclarator() instanceof ICASTKnRFunctionDeclarator) {
|
||||||
CASTKnRFunctionDeclarator declarator = (CASTKnRFunctionDeclarator) functionDef.getDeclarator();
|
CASTKnRFunctionDeclarator declarator = (CASTKnRFunctionDeclarator) functionDef.getDeclarator();
|
||||||
|
|
Loading…
Add table
Reference in a new issue