mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
bug 98960
This commit is contained in:
parent
4c922d5214
commit
72278f3ec9
5 changed files with 73 additions and 36 deletions
|
@ -255,7 +255,7 @@ public class AST2KnRTests extends AST2BaseTest {
|
|||
CVisitor.clearBindings(tu);
|
||||
assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray()) ); //$NON-NLS-1$
|
||||
assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
|
||||
assertNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
|
||||
// assertNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testKRCProblem1() throws Exception {
|
||||
|
@ -547,7 +547,7 @@ public class AST2KnRTests extends AST2BaseTest {
|
|||
CVisitor.clearBindings(tu);
|
||||
assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_TAG, new String("A_struct").toCharArray()) ); //$NON-NLS-1$
|
||||
assertNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
|
||||
assertNull( ((CScope)((IASTCompoundStatement)f_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
|
||||
// assertNull( ((CScope)((IASTCompoundStatement)f_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3177,4 +3177,22 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertTrue(((IASTIdExpression)((IASTFunctionCallExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[1]).getBody()).getStatements()[0]).getReturnValue()).getFunctionNameExpression()).getName().resolveBinding() instanceof IFunction);
|
||||
}
|
||||
|
||||
public void testBug98960() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("void f() { \n");
|
||||
buffer.append(" int a; \n");
|
||||
buffer.append(" { a; int a; } \n");
|
||||
buffer.append("} \n");
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
|
||||
CNameCollector col = new CNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
IVariable a1 = (IVariable) col.getName(1).resolveBinding();
|
||||
IVariable a2 = (IVariable) col.getName(2).resolveBinding();
|
||||
IVariable a3 = (IVariable) col.getName(3).resolveBinding();
|
||||
|
||||
assertSame( a1, a2 );
|
||||
assertNotSame( a2, a3 );
|
||||
}
|
||||
}
|
|
@ -256,45 +256,31 @@ public class CFunction implements IFunction, ICInternalFunction {
|
|||
|
||||
protected void updateParameterBindings( IASTFunctionDeclarator fdtor ){
|
||||
CParameter temp = null;
|
||||
IParameter [] params = getParameters();
|
||||
if( fdtor instanceof IASTStandardFunctionDeclarator ){
|
||||
IASTStandardFunctionDeclarator orig = (IASTStandardFunctionDeclarator) getPhysicalNode();
|
||||
IASTParameterDeclaration [] ops = orig.getParameters();
|
||||
IASTParameterDeclaration [] nps = ((IASTStandardFunctionDeclarator)fdtor).getParameters();
|
||||
if(ops.length < nps.length )
|
||||
if(params.length < nps.length )
|
||||
return;
|
||||
for( int i = 0; i < nps.length; i++ ){
|
||||
IASTName origname = ops[i].getDeclarator().getName();
|
||||
if( origname.getBinding() != null ){
|
||||
temp = (CParameter) origname.getBinding();
|
||||
if( temp != null ){
|
||||
IASTName name = nps[i].getDeclarator().getName();
|
||||
name.setBinding( temp );
|
||||
temp.addDeclaration( name );
|
||||
}
|
||||
}
|
||||
|
||||
IASTName name = nps[i].getDeclarator().getName();
|
||||
temp = (CParameter) params[i];
|
||||
name.setBinding( temp );
|
||||
temp.addDeclaration( name );
|
||||
}
|
||||
} else {
|
||||
IASTParameterDeclaration [] ops = declarators[0].getParameters();
|
||||
IASTName [] ns = ((ICASTKnRFunctionDeclarator)fdtor).getParameterNames();
|
||||
if( ops.length > 0 && ops.length != ns.length )
|
||||
if( params.length > 0 && params.length != ns.length )
|
||||
return; //problem
|
||||
|
||||
for( int i = 0; i < ops.length; i++ ){
|
||||
IASTName origname = ops[i].getDeclarator().getName();
|
||||
if( origname.getBinding() != null ){
|
||||
temp = (CParameter) origname.resolveBinding();
|
||||
if( temp != null ){
|
||||
IASTName name = ns[i];
|
||||
name.setBinding( temp );
|
||||
|
||||
IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator( (ICASTKnRFunctionDeclarator) fdtor, name );
|
||||
if( dtor != null ){
|
||||
dtor.getName().setBinding( temp );
|
||||
temp.addDeclaration( dtor.getName() );
|
||||
}
|
||||
}
|
||||
}
|
||||
for( int i = 0; i < params.length; i++ ){
|
||||
IASTName name = ns[i];
|
||||
temp = (CParameter) params[i];
|
||||
name.setBinding( temp );
|
||||
IASTDeclarator dtor = CVisitor.getKnRParameterDeclarator( (ICASTKnRFunctionDeclarator) fdtor, name );
|
||||
if( dtor != null ){
|
||||
dtor.getName().setBinding( temp );
|
||||
temp.addDeclaration( dtor.getName() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,14 +72,38 @@ public class CParameter implements IParameter {
|
|||
return type;
|
||||
}
|
||||
|
||||
private IASTName getPrimaryDeclaration(){
|
||||
if( declarations != null ){
|
||||
for( int i = 0; i < declarations.length && declarations[i] != null; i++ ){
|
||||
IASTNode node = declarations[i].getParent();
|
||||
while( !(node instanceof IASTDeclaration) )
|
||||
node = node.getParent();
|
||||
|
||||
if( node.getPropertyInParent() == ICASTKnRFunctionDeclarator.FUNCTION_PARAMETER ||
|
||||
node instanceof IASTFunctionDefinition )
|
||||
{
|
||||
return declarations[i];
|
||||
}
|
||||
}
|
||||
return declarations[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return declarations[0].toString();
|
||||
IASTName name = getPrimaryDeclaration();
|
||||
if( name != null )
|
||||
return name.toString();
|
||||
return CVisitor.EMPTY_STRING;
|
||||
}
|
||||
public char[] getNameCharArray(){
|
||||
return declarations[0].toCharArray();
|
||||
IASTName name = getPrimaryDeclaration();
|
||||
if( name != null )
|
||||
return name.toCharArray();
|
||||
return CVisitor.EMPTY_CHAR_ARRAY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -435,6 +435,8 @@ public class CVisitor {
|
|||
protected static final ASTNodeProperty STRING_LOOKUP_PROPERTY = new ASTNodeProperty("CVisitor.STRING_LOOKUP_PROPERTY - STRING_LOOKUP"); //$NON-NLS-1$
|
||||
protected static final ASTNodeProperty STRING_LOOKUP_TAGS_PROPERTY = new ASTNodeProperty("CVisitor.STRING_LOOKUP_TAGS_PROPERTY - STRING_LOOKUP"); //$NON-NLS-1$
|
||||
private static final String SIZE_T = "size_t"; //$NON-NLS-1$
|
||||
public static final String EMPTY_STRING = "";
|
||||
public static final char [] EMPTY_CHAR_ARRAY = "".toCharArray();
|
||||
//lookup bits
|
||||
private static final int COMPLETE = 0;
|
||||
private static final int CURRENT_SCOPE = 1;
|
||||
|
@ -1207,6 +1209,7 @@ public class CVisitor {
|
|||
} else {
|
||||
|
||||
Object result = null;
|
||||
boolean reachedBlockItem = false;
|
||||
if( nodes != null ){
|
||||
int idx = -1;
|
||||
IASTNode node = ( nodes != null ? (nodes.length > 0 ? nodes[++idx] : null ) : parent );
|
||||
|
@ -1217,9 +1220,15 @@ public class CVisitor {
|
|||
} catch ( DOMException e ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( result == null && ( includeBlockItem || (node != blockItem) ) )
|
||||
|
||||
if( result == null && !reachedBlockItem &&
|
||||
( includeBlockItem || (node != blockItem) ) )
|
||||
{
|
||||
result = candidate;
|
||||
}
|
||||
if( node == blockItem ){
|
||||
reachedBlockItem = true;
|
||||
}
|
||||
|
||||
if( idx > -1 && ++idx < nodes.length ){
|
||||
node = nodes[idx];
|
||||
|
|
Loading…
Add table
Reference in a new issue