mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
don't need separate name visitors for C and C++
This commit is contained in:
parent
628c4193a9
commit
c099d478d2
1 changed files with 26 additions and 52 deletions
|
@ -16,6 +16,7 @@ import java.util.List;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
@ -134,8 +135,7 @@ public class AST2SpecBaseTest extends TestCase {
|
|||
|
||||
// resolve all bindings
|
||||
if (checkBindings) {
|
||||
if ( lang == ParserLanguage.CPP ) {
|
||||
CPPNameResolver res = new CPPNameResolver();
|
||||
NameResolver res = new NameResolver();
|
||||
tu.accept( res );
|
||||
if (res.problemBindings.size() != expectedProblemBindings )
|
||||
throw new ParserException("Expected " + expectedProblemBindings + " problems, encountered " + res.problemBindings.size() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
@ -144,17 +144,6 @@ public class AST2SpecBaseTest extends TestCase {
|
|||
assertEquals(problems[i], res.problemBindings.get(i));
|
||||
}
|
||||
}
|
||||
} else if (lang == ParserLanguage.C ) {
|
||||
CNameResolver res = new CNameResolver();
|
||||
tu.accept( res );
|
||||
if (res.problemBindings.size() != expectedProblemBindings )
|
||||
throw new ParserException("Expected " + expectedProblemBindings + " problems, encountered " + res.problemBindings.size() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
if (problems != null) {
|
||||
for (int i = 0; i < problems.length; i++) {
|
||||
assertEquals(problems[i], res.problemBindings.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( parser2.encounteredError() && expectNoProblems )
|
||||
|
@ -182,39 +171,20 @@ public class AST2SpecBaseTest extends TestCase {
|
|||
return tu;
|
||||
}
|
||||
|
||||
static protected class CNameResolver extends CASTVisitor {
|
||||
|
||||
|
||||
static protected class NameResolver extends ASTVisitor {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
}
|
||||
public ArrayList<String> problemBindings=new ArrayList<String>();
|
||||
public int numNullBindings=0;
|
||||
public List nameList = new ArrayList();
|
||||
public int visit( IASTName name ){
|
||||
nameList.add( name );
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (binding instanceof IProblemBinding)
|
||||
problemBindings.add(name.toString());
|
||||
if (binding == null)
|
||||
numNullBindings++;
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
public IASTName getName( int idx ){
|
||||
if( idx < 0 || idx >= nameList.size() )
|
||||
return null;
|
||||
return (IASTName) nameList.get( idx );
|
||||
}
|
||||
public int size() { return nameList.size(); }
|
||||
}
|
||||
|
||||
static protected class CPPNameResolver extends CPPASTVisitor {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
}
|
||||
public ArrayList<String> problemBindings=new ArrayList<String>();
|
||||
public int numNullBindings=0;
|
||||
public List nameList = new ArrayList();
|
||||
public int visit( IASTName name ){
|
||||
nameList.add( name );
|
||||
public List<IASTName> nameList = new ArrayList<IASTName>();
|
||||
public List<String> problemBindings = new ArrayList<String>();
|
||||
public int numNullBindings = 0;
|
||||
|
||||
|
||||
public int visit(IASTName name) {
|
||||
nameList.add(name);
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (binding instanceof IProblemBinding)
|
||||
problemBindings.add(name.toString());
|
||||
|
@ -222,12 +192,16 @@ public class AST2SpecBaseTest extends TestCase {
|
|||
numNullBindings++;
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
public IASTName getName( int idx ){
|
||||
if( idx < 0 || idx >= nameList.size() )
|
||||
|
||||
public IASTName getName(int idx) {
|
||||
if(idx < 0 || idx >= nameList.size())
|
||||
return null;
|
||||
return (IASTName) nameList.get( idx );
|
||||
return nameList.get(idx);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return nameList.size();
|
||||
}
|
||||
public int size() { return nameList.size(); }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue