mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
C Visitor - references: bugs 84090, 84092, 84096
This commit is contained in:
parent
257d3d67f4
commit
e4e8d7c6d4
2 changed files with 61 additions and 4 deletions
|
@ -2539,6 +2539,56 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals( ((IASTBinaryExpression)second_if_statement.getCondition()).getOperator(), IASTBinaryExpression.op_lessThan );
|
||||
IASTIfStatement third_if_statement = (IASTIfStatement) second_if_statement.getElseClause();
|
||||
assertEquals( ((IASTBinaryExpression)third_if_statement.getCondition()).getOperator(), IASTBinaryExpression.op_greaterThan );
|
||||
}
|
||||
|
||||
public void testBug84090_LabelReferences() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "void f() { \n"); //$NON-NLS-1$
|
||||
buffer.append( " while(1){ \n"); //$NON-NLS-1$
|
||||
buffer.append( " if( 1 ) goto end; \n"); //$NON-NLS-1$
|
||||
buffer.append( " } \n"); //$NON-NLS-1$
|
||||
buffer.append( " end: ; \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(), 3);
|
||||
ILabel end = (ILabel) col.getName(1).resolveBinding();
|
||||
|
||||
IASTName [] refs = tu.getReferences( end );
|
||||
assertEquals( refs.length, 1 );
|
||||
assertSame( refs[0].resolveBinding(), end );
|
||||
}
|
||||
|
||||
public void testBug84092_EnumReferences() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("enum col { red, blue }; \n"); //$NON-NLS-1$
|
||||
buffer.append("enum col c; \n"); //$NON-NLS-1$
|
||||
|
||||
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
|
||||
CNameCollector collector = new CNameCollector();
|
||||
CVisitor.visitTranslationUnit(tu, collector);
|
||||
|
||||
assertEquals(collector.size(), 5);
|
||||
IEnumeration col = (IEnumeration) collector.getName(0).resolveBinding();
|
||||
|
||||
IASTName [] refs = tu.getReferences( col );
|
||||
assertEquals( refs.length, 1 );
|
||||
assertSame( refs[0].resolveBinding(), col );
|
||||
}
|
||||
|
||||
public void testBug84096_FieldDesignatorRef() throws Exception {
|
||||
IASTTranslationUnit tu = parse("struct s { int a; } ss = { .a = 1 }; \n", ParserLanguage.C); //$NON-NLS-1$
|
||||
CNameCollector collector = new CNameCollector();
|
||||
CVisitor.visitTranslationUnit(tu, collector);
|
||||
|
||||
assertEquals(collector.size(), 4);
|
||||
IField a = (IField) collector.getName(1).resolveBinding();
|
||||
|
||||
IASTName [] refs = tu.getReferences( a );
|
||||
assertEquals( refs.length, 1 );
|
||||
assertSame( refs[0].resolveBinding(), a );
|
||||
}
|
||||
}
|
|
@ -406,9 +406,12 @@ public class CVisitor {
|
|||
processNames = true;
|
||||
if( binding instanceof ILabel )
|
||||
kind = KIND_LABEL;
|
||||
else if( binding instanceof ICompositeType || binding instanceof ITypedef )
|
||||
else if( binding instanceof ICompositeType ||
|
||||
binding instanceof ITypedef ||
|
||||
binding instanceof IEnumeration )
|
||||
{
|
||||
kind = KIND_TYPE;
|
||||
else
|
||||
} else
|
||||
kind = KIND_OBJ_FN;
|
||||
}
|
||||
|
||||
|
@ -416,7 +419,7 @@ public class CVisitor {
|
|||
ASTNodeProperty prop = name.getPropertyInParent();
|
||||
switch( kind ){
|
||||
case KIND_LABEL:
|
||||
if( prop == IASTGotoStatement.NAME || prop == IASTLabelStatement.NAME )
|
||||
if( prop == IASTGotoStatement.NAME )
|
||||
break;
|
||||
return PROCESS_CONTINUE;
|
||||
case KIND_TYPE:
|
||||
|
@ -432,8 +435,12 @@ public class CVisitor {
|
|||
}
|
||||
return PROCESS_CONTINUE;
|
||||
case KIND_OBJ_FN:
|
||||
if( prop == IASTIdExpression.ID_NAME || prop == IASTFieldReference.FIELD_NAME )
|
||||
if( prop == IASTIdExpression.ID_NAME ||
|
||||
prop == IASTFieldReference.FIELD_NAME ||
|
||||
prop == ICASTFieldDesignator.FIELD_NAME )
|
||||
{
|
||||
break;
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue