mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
fix IScope.find( String ) to do an unqualified lookup on the given string
This commit is contained in:
parent
b7f2832d92
commit
6cbe7a043b
6 changed files with 204 additions and 633 deletions
|
@ -13,7 +13,6 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
|
@ -30,7 +29,6 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||||
|
@ -51,10 +49,10 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPCompositeBinding;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPCompositeBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||||
|
@ -1591,41 +1589,41 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
tu.accept( col);
|
tu.accept( col);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFindTypeBinding_1() throws Exception {
|
// public void testFindTypeBinding_1() throws Exception {
|
||||||
IASTTranslationUnit tu = parse(
|
// IASTTranslationUnit tu = parse(
|
||||||
"int x = 5; int y(x);", ParserLanguage.CPP); //$NON-NLS-1$
|
// "int x = 5; int y(x);", ParserLanguage.CPP); //$NON-NLS-1$
|
||||||
|
//
|
||||||
IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) ((IASTSimpleDeclaration) tu
|
// IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) ((IASTSimpleDeclaration) tu
|
||||||
.getDeclarations()[1]).getDeclarators()[0];
|
// .getDeclarations()[1]).getDeclarators()[0];
|
||||||
IASTName name = fdtor.getParameters()[0].getDeclarator().getName();
|
// IASTName name = fdtor.getParameters()[0].getDeclarator().getName();
|
||||||
IBinding binding = CPPSemantics.findTypeBinding(tu, name);
|
// IBinding binding = CPPSemantics.findTypeBinding(tu, name);
|
||||||
assertNull(binding);
|
// assertNull(binding);
|
||||||
|
//
|
||||||
tu = parse("struct x; int y(x);", ParserLanguage.CPP); //$NON-NLS-1$
|
// tu = parse("struct x; int y(x);", ParserLanguage.CPP); //$NON-NLS-1$
|
||||||
|
//
|
||||||
fdtor = (IASTStandardFunctionDeclarator) ((IASTSimpleDeclaration) tu
|
// fdtor = (IASTStandardFunctionDeclarator) ((IASTSimpleDeclaration) tu
|
||||||
.getDeclarations()[1]).getDeclarators()[0];
|
// .getDeclarations()[1]).getDeclarators()[0];
|
||||||
name = ((ICPPASTNamedTypeSpecifier) fdtor.getParameters()[0]
|
// name = ((ICPPASTNamedTypeSpecifier) fdtor.getParameters()[0]
|
||||||
.getDeclSpecifier()).getName();
|
// .getDeclSpecifier()).getName();
|
||||||
binding = CPPSemantics.findTypeBinding(tu, name);
|
// binding = CPPSemantics.findTypeBinding(tu, name);
|
||||||
assertNotNull(binding);
|
// assertNotNull(binding);
|
||||||
assertTrue(binding instanceof ICPPClassType);
|
// assertTrue(binding instanceof ICPPClassType);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void testFindTypeBinding_2() throws Exception {
|
// public void testFindTypeBinding_2() throws Exception {
|
||||||
IASTTranslationUnit tu = parse(
|
// IASTTranslationUnit tu = parse(
|
||||||
"struct B; void f() { B * bp; }", ParserLanguage.CPP); //$NON-NLS-1$
|
// "struct B; void f() { B * bp; }", ParserLanguage.CPP); //$NON-NLS-1$
|
||||||
IASTCompoundStatement compound = (IASTCompoundStatement) ((IASTFunctionDefinition) tu
|
// IASTCompoundStatement compound = (IASTCompoundStatement) ((IASTFunctionDefinition) tu
|
||||||
.getDeclarations()[1]).getBody();
|
// .getDeclarations()[1]).getBody();
|
||||||
IASTBinaryExpression b = (IASTBinaryExpression) ((IASTExpressionStatement)compound.getStatements()[0]).getExpression();
|
// IASTBinaryExpression b = (IASTBinaryExpression) ((IASTExpressionStatement)compound.getStatements()[0]).getExpression();
|
||||||
IBinding binding = ((IASTIdExpression)b.getOperand1()).getName().resolveBinding();
|
// IBinding binding = ((IASTIdExpression)b.getOperand1()).getName().resolveBinding();
|
||||||
// IASTSimpleDeclaration decl = (IASTSimpleDeclaration) ((IASTDeclarationStatement) compound
|
//// IASTSimpleDeclaration decl = (IASTSimpleDeclaration) ((IASTDeclarationStatement) compound
|
||||||
// .getStatements()[0]).getDeclaration();
|
//// .getStatements()[0]).getDeclaration();
|
||||||
// IBinding binding = CPPSemantics.findTypeBinding(compound,
|
//// IBinding binding = CPPSemantics.findTypeBinding(compound,
|
||||||
// ((ICPPASTNamedTypeSpecifier)decl.getDeclSpecifier()).getName());
|
//// ((ICPPASTNamedTypeSpecifier)decl.getDeclSpecifier()).getName());
|
||||||
assertNotNull(binding);
|
// assertNotNull(binding);
|
||||||
assertTrue(binding instanceof ICPPClassType);
|
// assertTrue(binding instanceof ICPPClassType);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// public void testBug85049() throws Exception {
|
// public void testBug85049() throws Exception {
|
||||||
// StringBuffer buffer = new StringBuffer( "struct B { };\n" ); //$NON-NLS-1$
|
// StringBuffer buffer = new StringBuffer( "struct B { };\n" ); //$NON-NLS-1$
|
||||||
|
@ -2669,5 +2667,119 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
assertEquals( refs.length, 1 );
|
assertEquals( refs.length, 1 );
|
||||||
assertSame( refs[0], col.getName(3) );
|
assertSame( refs[0], col.getName(3) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testFind_1() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("void f( int par ) { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" int v1; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" int v2; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" } \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
tu.accept(col);
|
||||||
|
|
||||||
|
IVariable v1 = (IVariable) col.getName(2).resolveBinding();
|
||||||
|
IVariable v2 = (IVariable) col.getName(3).resolveBinding();
|
||||||
|
|
||||||
|
ICPPBlockScope scope = (ICPPBlockScope) v2.getScope();
|
||||||
|
IBinding [] bs = scope.find( "v1" ); //$NON-NLS-1$
|
||||||
|
assertEquals( bs.length, 1 );
|
||||||
|
assertSame( bs[0], v1 );
|
||||||
|
}
|
||||||
|
public void testFind_2() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("class A { int a; }; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("class B : public A { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" void f(); \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("}; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("void B::f() { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
tu.accept(col);
|
||||||
|
|
||||||
|
ICPPClassType A = (ICPPClassType) col.getName(0).resolveBinding();
|
||||||
|
ICPPField a = (ICPPField) col.getName(1).resolveBinding();
|
||||||
|
ICPPMethod f = (ICPPMethod) col.getName(7).resolveBinding();
|
||||||
|
|
||||||
|
IScope scope = f.getFunctionScope();
|
||||||
|
IBinding [] bs = scope.find( "a" ); //$NON-NLS-1$
|
||||||
|
assertEquals( bs.length, 1 );
|
||||||
|
assertSame( bs[0], a );
|
||||||
|
|
||||||
|
bs = scope.find( "~B" ); //$NON-NLS-1$
|
||||||
|
assertEquals( bs.length, 1 );
|
||||||
|
assertTrue( bs[0] instanceof ICPPMethod );
|
||||||
|
assertTrue( bs[0].getName().equals( "~B" ) ); //$NON-NLS-1$
|
||||||
|
|
||||||
|
bs = scope.find( "A" ); //$NON-NLS-1$
|
||||||
|
assertEquals( bs.length, 1 );
|
||||||
|
assertSame( bs[0], A );
|
||||||
|
}
|
||||||
|
public void testFind_3() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("namespace A { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" void f( int ); \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" void f( double ); \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("void g() { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" void f( char ); \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" using A::f; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
tu.accept(col);
|
||||||
|
|
||||||
|
IFunction f1 = (IFunction) col.getName(1).resolveBinding();
|
||||||
|
IFunction f2 = (IFunction) col.getName(3).resolveBinding();
|
||||||
|
IFunction f3 = (IFunction) col.getName(6).resolveBinding();
|
||||||
|
|
||||||
|
IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(5).getParent().getParent();
|
||||||
|
IScope scope = ((IASTCompoundStatement)def.getBody()).getScope();
|
||||||
|
IBinding [] bs = scope.find( "f" ); //$NON-NLS-1$
|
||||||
|
assertEquals( bs.length, 3 );
|
||||||
|
assertSame( bs[0], f3 );
|
||||||
|
assertSame( bs[1], f1 );
|
||||||
|
assertSame( bs[2], f2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testFind_4() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("namespace A { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" struct f; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" void f(); \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("namespace B { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" void f( int ); \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("namespace C { \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" using namespace B; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("void g(){ \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" using namespace A; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append(" using namespace C; \n"); //$NON-NLS-1$
|
||||||
|
buffer.append("} \n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||||
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
|
tu.accept(col);
|
||||||
|
|
||||||
|
ICPPClassType f = (ICPPClassType) col.getName(1).resolveBinding();
|
||||||
|
IFunction f1 = (IFunction) col.getName(2).resolveBinding();
|
||||||
|
IFunction f2 = (IFunction) col.getName(4).resolveBinding();
|
||||||
|
|
||||||
|
IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(8).getParent().getParent();
|
||||||
|
IScope scope = ((IASTCompoundStatement)def.getBody()).getScope();
|
||||||
|
IBinding [] bs = scope.find( "f" ); //$NON-NLS-1$
|
||||||
|
assertEquals( bs.length, 3 );
|
||||||
|
assertSame( bs[0], f );
|
||||||
|
assertSame( bs[1], f1 );
|
||||||
|
assertSame( bs[2], f2 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,6 +186,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isConstructorReference( IASTName name ){
|
private boolean isConstructorReference( IASTName name ){
|
||||||
|
if( name.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY ) return false;
|
||||||
IASTNode node = name.getParent();
|
IASTNode node = name.getParent();
|
||||||
if( node instanceof ICPPASTQualifiedName ){
|
if( node instanceof ICPPASTQualifiedName ){
|
||||||
IASTName [] ns = ((ICPPASTQualifiedName)node).getNames();
|
IASTName [] ns = ((ICPPASTQualifiedName)node).getNames();
|
||||||
|
|
|
@ -23,10 +23,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics.LookupData;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -67,27 +64,12 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public IBinding[] find(String name) {
|
public IBinding[] find(String name) throws DOMException {
|
||||||
char [] n = name.toCharArray();
|
char [] n = name.toCharArray();
|
||||||
if( labels.containsKey( n ) )
|
if( labels.containsKey( n ) )
|
||||||
return new IBinding[] { (IBinding) labels.get( n ) };
|
return new IBinding[] { (IBinding) labels.get( n ) };
|
||||||
|
|
||||||
LookupData data = new LookupData( n );
|
return super.find( name );
|
||||||
try {
|
|
||||||
data.foundItems = CPPSemantics.lookupInScope( data, this, null, null );
|
|
||||||
} catch ( DOMException e ) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if( data.foundItems != null ){
|
|
||||||
IASTName [] ns = (IASTName[]) data.foundItems;
|
|
||||||
ObjectSet set = new ObjectSet( ns.length );
|
|
||||||
for( int i = 0; i < ns.length && ns[i] != null; i++ ){
|
|
||||||
set.put( ns[i].resolveBinding() );
|
|
||||||
}
|
|
||||||
return (IBinding[]) ArrayUtil.trim( IBinding.class, set.keyArray(), true );
|
|
||||||
}
|
|
||||||
|
|
||||||
return new IBinding[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IScope getParent() throws DOMException {
|
public IScope getParent() throws DOMException {
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics.LookupData;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -147,7 +146,7 @@ abstract public class CPPScope implements ICPPScope{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isfull = false;
|
private boolean isfull = false;
|
||||||
public void setFullyCached( boolean full ){
|
public void setFullyCached( boolean full ){
|
||||||
isfull = full;
|
isfull = full;
|
||||||
}
|
}
|
||||||
|
@ -160,31 +159,6 @@ abstract public class CPPScope implements ICPPScope{
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public IBinding[] find(String name) throws DOMException {
|
public IBinding[] find(String name) throws DOMException {
|
||||||
char [] n = name.toCharArray();
|
return CPPSemantics.findBindings( this, name );
|
||||||
if( isFullyCached() ){
|
|
||||||
if( bindings != null ) {
|
|
||||||
Object o = bindings.get( n );
|
|
||||||
if( o instanceof IBinding[] )
|
|
||||||
return (IBinding[]) ArrayUtil.trim( IBinding.class, (Object[]) o );
|
|
||||||
return new IBinding[] { (IBinding) o };
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LookupData data = new LookupData( n );
|
|
||||||
try {
|
|
||||||
data.foundItems = CPPSemantics.lookupInScope( data, this, null, null );
|
|
||||||
} catch ( DOMException e ) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if( data.foundItems != null ){
|
|
||||||
IASTName [] ns = (IASTName[]) data.foundItems;
|
|
||||||
ObjectSet set = new ObjectSet( ns.length );
|
|
||||||
for( int i = 0; i < ns.length && ns[i] != null; i++ ){
|
|
||||||
set.put( ns[i].resolveBinding() );
|
|
||||||
}
|
|
||||||
return (IBinding[]) ArrayUtil.trim( IBinding.class, set.keyArray(), true );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new IBinding[0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||||
*/
|
*/
|
||||||
public class CPPSemantics {
|
public class CPPSemantics {
|
||||||
|
|
||||||
|
protected static final ASTNodeProperty STRING_LOOKUP_PROPERTY = new ASTNodeProperty("STRING_LOOKUP"); //$NON-NLS-1$
|
||||||
public static final char[] EMPTY_NAME_ARRAY = new char[0];
|
public static final char[] EMPTY_NAME_ARRAY = new char[0];
|
||||||
public static final String EMPTY_NAME = ""; //$NON-NLS-1$
|
public static final String EMPTY_NAME = ""; //$NON-NLS-1$
|
||||||
public static final char[] OPERATOR_ = new char[] {'o','p','e','r','a','t','o','r',' '}; //$NON-NLS-1$
|
public static final char[] OPERATOR_ = new char[] {'o','p','e','r','a','t','o','r',' '}; //$NON-NLS-1$
|
||||||
|
@ -649,12 +650,12 @@ public class CPPSemantics {
|
||||||
|
|
||||||
while( scope != null ){
|
while( scope != null ){
|
||||||
IASTNode blockItem = CPPVisitor.getContainingBlockItem( node );
|
IASTNode blockItem = CPPVisitor.getContainingBlockItem( node );
|
||||||
if( scope.getPhysicalNode() != blockItem.getParent() && !(scope instanceof ICPPNamespaceScope) )
|
if( blockItem != null && scope.getPhysicalNode() != blockItem.getParent() && !(scope instanceof ICPPNamespaceScope) )
|
||||||
blockItem = node;
|
blockItem = node;
|
||||||
|
|
||||||
ArrayWrapper directives = null;
|
ArrayWrapper directives = null;
|
||||||
if( !data.usingDirectivesOnly ){
|
if( !data.usingDirectivesOnly ){
|
||||||
if( scope.isFullyCached() && !data.prefixLookup ){
|
if( scope.isFullyCached() && !data.prefixLookup && data.astName != null ){
|
||||||
IBinding binding = data.prefixLookup ? null : scope.getBinding( data.astName, true );
|
IBinding binding = data.prefixLookup ? null : scope.getBinding( data.astName, true );
|
||||||
if( binding != null &&
|
if( binding != null &&
|
||||||
( CPPSemantics.declaredBefore( binding, data.astName ) ||
|
( CPPSemantics.declaredBefore( binding, data.astName ) ||
|
||||||
|
@ -764,7 +765,7 @@ public class CPPSemantics {
|
||||||
//is circular inheritance
|
//is circular inheritance
|
||||||
if( ! data.inheritanceChain.containsKey( parent ) ){
|
if( ! data.inheritanceChain.containsKey( parent ) ){
|
||||||
//is this name define in this scope?
|
//is this name define in this scope?
|
||||||
if( !data.prefixLookup && parent.isFullyCached() )
|
if( data.astName != null && !data.prefixLookup && parent.isFullyCached() )
|
||||||
inherited = parent.getBinding( data.astName, true );
|
inherited = parent.getBinding( data.astName, true );
|
||||||
else
|
else
|
||||||
inherited = lookupInScope( data, parent, null, null );
|
inherited = lookupInScope( data, parent, null, null );
|
||||||
|
@ -998,6 +999,8 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( item instanceof IASTDeclarationStatement )
|
||||||
|
item = ((IASTDeclarationStatement)item).getDeclaration();
|
||||||
if( item instanceof ICPPASTUsingDirective ||
|
if( item instanceof ICPPASTUsingDirective ||
|
||||||
(item instanceof ICPPASTNamespaceDefinition &&
|
(item instanceof ICPPASTNamespaceDefinition &&
|
||||||
((ICPPASTNamespaceDefinition)item).getName().toCharArray().length == 0) )
|
((ICPPASTNamespaceDefinition)item).getName().toCharArray().length == 0) )
|
||||||
|
@ -1261,6 +1264,7 @@ public class CPPSemantics {
|
||||||
|
|
||||||
static public boolean declaredBefore( Object obj, IASTNode node ){
|
static public boolean declaredBefore( Object obj, IASTNode node ){
|
||||||
if( node == null ) return true;
|
if( node == null ) return true;
|
||||||
|
if( node.getPropertyInParent() == STRING_LOOKUP_PROPERTY ) return true;
|
||||||
|
|
||||||
ASTNode nd = null;
|
ASTNode nd = null;
|
||||||
if( obj instanceof ICPPBinding ){
|
if( obj instanceof ICPPBinding ){
|
||||||
|
@ -2271,56 +2275,50 @@ public class CPPSemantics {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static IBinding[] findBindings( IScope scope, String name ) throws DOMException{
|
||||||
* Find the binding for the type for the given name, if the given name is not a type, or can not
|
CPPASTName astName = new CPPASTName();
|
||||||
* be resolved, null is returned.
|
astName.setName( name.toCharArray() );
|
||||||
* @param mostRelevantScope
|
astName.setParent( scope.getPhysicalNode() );
|
||||||
* @param name
|
astName.setPropertyInParent( STRING_LOOKUP_PROPERTY );
|
||||||
* @return
|
|
||||||
*/
|
LookupData data = new LookupData( astName );
|
||||||
public static IBinding findTypeBinding( IASTNode mostRelevantScope, IASTName name ){
|
|
||||||
IScope scope = null;
|
try {
|
||||||
if( mostRelevantScope instanceof IASTCompoundStatement )
|
|
||||||
scope = ((IASTCompoundStatement) mostRelevantScope).getScope();
|
|
||||||
else if ( mostRelevantScope instanceof IASTTranslationUnit )
|
|
||||||
scope = ((IASTTranslationUnit) mostRelevantScope).getScope();
|
|
||||||
else if ( mostRelevantScope instanceof ICPPASTNamespaceDefinition )
|
|
||||||
scope = ((ICPPASTNamespaceDefinition) mostRelevantScope).getScope();
|
|
||||||
else if( mostRelevantScope instanceof ICPPASTCompositeTypeSpecifier )
|
|
||||||
scope = ((ICPPASTCompositeTypeSpecifier) mostRelevantScope).getScope();
|
|
||||||
|
|
||||||
if( scope == null )
|
|
||||||
return null;
|
|
||||||
|
|
||||||
LookupData data = new LookupData( name ){
|
|
||||||
public boolean typesOnly(){ return true; }
|
|
||||||
public boolean forUsingDeclaration(){ return false; }
|
|
||||||
public boolean forDefinition(){ return false; }
|
|
||||||
public boolean considerConstructors(){ return false; }
|
|
||||||
public boolean functionCall(){ return false; }
|
|
||||||
public boolean qualified(){
|
|
||||||
IASTNode p1 = astName.getParent();
|
|
||||||
if( p1 instanceof ICPPASTQualifiedName ){
|
|
||||||
return ((ICPPASTQualifiedName)p1).getNames()[0] != astName;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
lookup( data, scope );
|
lookup( data, scope );
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
return null;
|
return new IBinding [] { e.getProblem() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object [] items = (Object[]) data.foundItems;
|
||||||
|
if( items == null )
|
||||||
|
return new IBinding[0];
|
||||||
|
|
||||||
|
ObjectSet set = new ObjectSet( items.length );
|
||||||
IBinding binding = null;
|
IBinding binding = null;
|
||||||
try {
|
for( int i = 0; i < items.length; i++ ){
|
||||||
binding = resolveAmbiguities( data, name );
|
if( items[i] instanceof IASTName )
|
||||||
} catch ( DOMException e2 ) {
|
binding = ((IASTName) items[i]).resolveBinding();
|
||||||
}
|
else if( items[i] instanceof IBinding )
|
||||||
|
binding = (IBinding) items[i];
|
||||||
return binding;
|
else
|
||||||
|
binding = null;
|
||||||
|
|
||||||
|
if( binding != null )
|
||||||
|
if( binding instanceof ICPPCompositeBinding ){
|
||||||
|
try {
|
||||||
|
IBinding [] bs = ((ICPPCompositeBinding)binding).getBindings();
|
||||||
|
for( int j = 0; j < bs.length; j++ ){
|
||||||
|
set.put( bs[j] );
|
||||||
|
}
|
||||||
|
} catch ( DOMException e1 ) {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
set.put( binding );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (IBinding[]) ArrayUtil.trim( IBinding.class, set.keyArray(), true );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IBinding [] prefixLookup( IASTName name ){
|
public static IBinding [] prefixLookup( IASTName name ){
|
||||||
LookupData data = createLookupData( name, true );
|
LookupData data = createLookupData( name, true );
|
||||||
data.prefixLookup = true;
|
data.prefixLookup = true;
|
||||||
|
|
|
@ -628,9 +628,11 @@ public class CPPVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IASTNode getContainingBlockItem( IASTNode node ){
|
public static IASTNode getContainingBlockItem( IASTNode node ){
|
||||||
|
if( node == null ) return null;
|
||||||
|
if( node.getPropertyInParent() == CPPSemantics.STRING_LOOKUP_PROPERTY ) return null;
|
||||||
IASTNode parent = node.getParent();
|
IASTNode parent = node.getParent();
|
||||||
if( parent == null )
|
if( parent == null )
|
||||||
return null;
|
return null;
|
||||||
while( parent != null ) {
|
while( parent != null ) {
|
||||||
if( parent instanceof IASTDeclaration ){
|
if( parent instanceof IASTDeclaration ){
|
||||||
IASTNode p = parent.getParent();
|
IASTNode p = parent.getParent();
|
||||||
|
@ -1044,504 +1046,6 @@ public class CPPVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private IASTTranslationUnit tu = null;
|
|
||||||
// public CPPVisitor( ICPPASTTranslationUnit tu ){
|
|
||||||
// this.tu = tu;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void visitTranslationUnit( ASTVisitor action ){
|
|
||||||
// IASTDeclaration [] decls = tu.getDeclarations();
|
|
||||||
// for( int i = 0; i < decls.length; i++ ){
|
|
||||||
// if( !visitDeclaration( decls[i], action ) ) return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public boolean visitNamespaceDefinition( ICPPASTNamespaceDefinition namespace, ASTVisitor action ){
|
|
||||||
// if( action instanceof CPPASTVisitor && ((CPPASTVisitor)action).processNamespaces ){
|
|
||||||
// switch( ((CPPASTVisitor)action).processNamespace( namespace ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( !visitName( namespace.getName(), action ) ) return false;
|
|
||||||
// IASTDeclaration [] decls = namespace.getDeclarations();
|
|
||||||
// for( int i = 0; i < decls.length; i++ ){
|
|
||||||
// if( !visitDeclaration( decls[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// /**
|
|
||||||
// * @param declaration
|
|
||||||
// * @param action
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public boolean visitDeclaration(IASTDeclaration declaration, ASTVisitor action) {
|
|
||||||
// if( declaration instanceof ICPPASTNamespaceDefinition )
|
|
||||||
// return visitNamespaceDefinition( (ICPPASTNamespaceDefinition) declaration, action );
|
|
||||||
//
|
|
||||||
// if( action.processDeclarations ) {
|
|
||||||
// switch( action.processDeclaration( declaration ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( declaration instanceof IASTSimpleDeclaration ){
|
|
||||||
// IASTSimpleDeclaration simple = (IASTSimpleDeclaration) declaration;
|
|
||||||
// if( !visitDeclSpecifier( simple.getDeclSpecifier(), action ) ) return false;
|
|
||||||
// IASTDeclarator [] dtors = simple.getDeclarators();
|
|
||||||
// for( int i = 0; i < dtors.length; i++ ){
|
|
||||||
// if( !visitDeclarator( dtors[i], action) ) return false;
|
|
||||||
// }
|
|
||||||
// } else if( declaration instanceof IASTFunctionDefinition ){
|
|
||||||
// IASTFunctionDefinition function = (IASTFunctionDefinition) declaration;
|
|
||||||
// if( !visitDeclSpecifier( function.getDeclSpecifier(), action ) ) return false;
|
|
||||||
// if( !visitDeclarator( function.getDeclarator(), action ) ) return false;
|
|
||||||
// if( !visitStatement( function.getBody(), action ) ) return false;
|
|
||||||
// } else if( declaration instanceof ICPPASTUsingDeclaration ){
|
|
||||||
// if( !visitName( ((ICPPASTUsingDeclaration)declaration).getName(), action ) ) return false;
|
|
||||||
// } else if( declaration instanceof ICPPASTUsingDirective ){
|
|
||||||
// if( !visitName( ((ICPPASTUsingDirective)declaration).getQualifiedName(), action ) ) return false;
|
|
||||||
// } else if( declaration instanceof ICPPASTNamespaceAlias ){
|
|
||||||
// ICPPASTNamespaceAlias alias = (ICPPASTNamespaceAlias) declaration;
|
|
||||||
// if( !visitName( alias.getAlias(), action ) ) return false;
|
|
||||||
// if( !visitName( alias.getQualifiedName(), action ) ) return false;
|
|
||||||
// } else if( declaration instanceof ICPPASTLinkageSpecification ){
|
|
||||||
// IASTDeclaration [] decls = ((ICPPASTLinkageSpecification) declaration).getDeclarations();
|
|
||||||
// for( int i = 0; i < decls.length; i++ ){
|
|
||||||
// if( !visitDeclaration( decls[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// } else if( declaration instanceof ICPPASTTemplateDeclaration ){
|
|
||||||
// ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) declaration;
|
|
||||||
// ICPPASTTemplateParameter [] params = template.getTemplateParameters();
|
|
||||||
// for( int i = 0; i < params.length; i++ ){
|
|
||||||
// if( !visitTemplateParameter( params[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// if( !visitDeclaration( template.getDeclaration(), action ) ) return false;
|
|
||||||
// } else if( declaration instanceof ICPPASTTemplateSpecialization ){
|
|
||||||
// if( !visitDeclaration( ((ICPPASTTemplateSpecialization) declaration).getDeclaration(), action ) ) return false;
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @param name
|
|
||||||
// * @param action
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public boolean visitName(IASTName name, ASTVisitor action) {
|
|
||||||
// if( action.processNames ){
|
|
||||||
// switch( action.processName( name ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( name instanceof ICPPASTQualifiedName ){
|
|
||||||
// IASTName [] names = ((ICPPASTQualifiedName)name).getNames();
|
|
||||||
// for( int i = 0; i < names.length; i++ ){
|
|
||||||
// if( i == names.length - 1 ){
|
|
||||||
// if( names[i].toCharArray().length > 0 && !visitName( names[i], action ) ) return false;
|
|
||||||
// } else if( !visitName( names[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @param declSpecifier
|
|
||||||
// * @param action
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public boolean visitDeclSpecifier(IASTDeclSpecifier declSpecifier, ASTVisitor action) {
|
|
||||||
// if( action.processDeclSpecifiers ){
|
|
||||||
// switch( action.processDeclSpecifier( declSpecifier ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( declSpecifier instanceof ICPPASTCompositeTypeSpecifier ){
|
|
||||||
// ICPPASTCompositeTypeSpecifier composite = (ICPPASTCompositeTypeSpecifier) declSpecifier;
|
|
||||||
// if( !visitName( composite.getName(), action ) ) return false;
|
|
||||||
// ICPPASTBaseSpecifier [] bases = composite.getBaseSpecifiers();
|
|
||||||
// for( int i = 0; i < bases.length; i++ ) {
|
|
||||||
// if( !visitBaseSpecifier( bases[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// IASTDeclaration [] decls = composite.getMembers();
|
|
||||||
// for( int i = 0; i < decls.length; i++ ){
|
|
||||||
// if( !visitDeclaration( decls[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// } else if( declSpecifier instanceof ICPPASTElaboratedTypeSpecifier ){
|
|
||||||
// if( !visitName( ((ICPPASTElaboratedTypeSpecifier) declSpecifier).getName(), action ) ) return false;
|
|
||||||
// } else if( declSpecifier instanceof IASTEnumerationSpecifier ){
|
|
||||||
// IASTEnumerationSpecifier enumeration = (IASTEnumerationSpecifier) declSpecifier;
|
|
||||||
// if( !visitName( enumeration.getName(), action ) ) return false;
|
|
||||||
// IASTEnumerator [] etors = enumeration.getEnumerators();
|
|
||||||
// for( int i = 0; i < etors.length; i++ ){
|
|
||||||
// if( !visitEnumerator( etors[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// } else if( declSpecifier instanceof ICPPASTNamedTypeSpecifier ){
|
|
||||||
// if( !visitName( ((ICPPASTNamedTypeSpecifier)declSpecifier).getName(), action ) ) return false;
|
|
||||||
// } else if( declSpecifier instanceof IGPPASTSimpleDeclSpecifier ) {
|
|
||||||
// IASTExpression typeOf = ((IGPPASTSimpleDeclSpecifier)declSpecifier).getTypeofExpression();
|
|
||||||
// if( typeOf != null )
|
|
||||||
// if( !visitExpression( typeOf, action ) ) return false;
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @param declarator
|
|
||||||
// * @param action
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public boolean visitDeclarator(IASTDeclarator declarator, ASTVisitor action) {
|
|
||||||
// if( action.processDeclarators ){
|
|
||||||
// switch( action.processDeclarator( declarator ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// IASTPointerOperator [] ptrs = declarator.getPointerOperators();
|
|
||||||
// if( ptrs.length > 0 ){
|
|
||||||
// for( int i = 0; i < ptrs.length; i++ ){
|
|
||||||
// if( ptrs[i] instanceof ICPPASTPointerToMember ){
|
|
||||||
// if( !visitName( ((ICPPASTPointerToMember) ptrs[i]).getName(), action ) ) return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( declarator.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR &&
|
|
||||||
// declarator.getNestedDeclarator() == null )
|
|
||||||
// {
|
|
||||||
// if( !visitName( declarator.getName(), action ) ) return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( declarator.getNestedDeclarator() != null )
|
|
||||||
// if( !visitDeclarator( declarator.getNestedDeclarator(), action ) ) return false;
|
|
||||||
//
|
|
||||||
// if( declarator instanceof ICPPASTFunctionDeclarator ){
|
|
||||||
// ICPPASTFunctionDeclarator fdtor = (ICPPASTFunctionDeclarator) declarator;
|
|
||||||
// IASTParameterDeclaration [] list = fdtor.getParameters();
|
|
||||||
// for( int i = 0; i < list.length; i++ ){
|
|
||||||
// if( !visitParameterDeclaration( list[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// ICPPASTConstructorChainInitializer [] ctorChain = fdtor.getConstructorChain();
|
|
||||||
// for( int i = 0; i < ctorChain.length; i++ ){
|
|
||||||
// if( !visitName( ctorChain[i].getMemberInitializerId(), action ) ) return false;
|
|
||||||
// if( !visitExpression( ctorChain[i].getInitializerValue(), action ) ) return false;
|
|
||||||
// }
|
|
||||||
// IASTTypeId [] typeIds = fdtor.getExceptionSpecification();
|
|
||||||
// for( int i = 0; i < typeIds.length; i++ ){
|
|
||||||
// if( !visitTypeId( typeIds[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( declarator instanceof ICPPASTFunctionTryBlockDeclarator ){
|
|
||||||
// ICPPASTCatchHandler [] catchHandlers = ((ICPPASTFunctionTryBlockDeclarator)declarator).getCatchHandlers();
|
|
||||||
// for( int i = 0; i < catchHandlers.length; i++ ){
|
|
||||||
// if( !visitStatement( catchHandlers[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// if( declarator instanceof IASTArrayDeclarator ){
|
|
||||||
// IASTArrayModifier [] mods = ((IASTArrayDeclarator) declarator).getArrayModifiers();
|
|
||||||
// for( int i = 0; i < mods.length; i++ ){
|
|
||||||
// if( mods[i].getConstantExpression() != null && !visitExpression( mods[i].getConstantExpression(), action ) ) return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( declarator.getInitializer() != null )
|
|
||||||
// if( !visitInitializer( declarator.getInitializer(), action ) ) return false;
|
|
||||||
//
|
|
||||||
// if( declarator instanceof IASTFieldDeclarator )
|
|
||||||
// if( ! visitExpression( ((IASTFieldDeclarator) declarator).getBitFieldSize(), action ) ) return false;
|
|
||||||
//
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private boolean visitIfStatement( IASTIfStatement ifStatement, ASTVisitor action ){
|
|
||||||
// while( ifStatement != null ){
|
|
||||||
// if( action.processStatements ){
|
|
||||||
// switch( action.processStatement( ifStatement ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if( !visitExpression( ifStatement.getCondition(), action ) ) return false;
|
|
||||||
// if( !visitStatement( ifStatement.getThenClause(), action ) ) return false;
|
|
||||||
// if( ifStatement.getElseClause() != null ){
|
|
||||||
// IASTStatement statement = ifStatement.getElseClause();
|
|
||||||
// if( statement instanceof IASTIfStatement ){
|
|
||||||
// ifStatement = (IASTIfStatement) statement;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// if( !visitStatement( statement, action ) ) return false;
|
|
||||||
// }
|
|
||||||
// ifStatement = null;
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// /**
|
|
||||||
// * @param body
|
|
||||||
// * @param action
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public boolean visitStatement(IASTStatement statement, ASTVisitor action) {
|
|
||||||
// //handle if's in a non-recursive manner to avoid stack overflows in case of huge number of elses
|
|
||||||
// if( statement instanceof IASTIfStatement )
|
|
||||||
// return visitIfStatement( (IASTIfStatement) statement, action );
|
|
||||||
//
|
|
||||||
// if( action.processStatements ){
|
|
||||||
// switch( action.processStatement( statement ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( statement instanceof IASTCompoundStatement ){
|
|
||||||
// IASTStatement [] list = ((IASTCompoundStatement) statement).getStatements();
|
|
||||||
// for( int i = 0; i < list.length; i++ ){
|
|
||||||
// if( list[i] == null ) break;
|
|
||||||
// if( !visitStatement( list[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// } else if( statement instanceof IASTDeclarationStatement ){
|
|
||||||
// if( !visitDeclaration( ((IASTDeclarationStatement)statement).getDeclaration(), action ) ) return false;
|
|
||||||
// } else if( statement instanceof IASTExpressionStatement ){
|
|
||||||
// if( !visitExpression( ((IASTExpressionStatement)statement).getExpression(), action ) ) return false;
|
|
||||||
// } else if( statement instanceof IASTCaseStatement ){
|
|
||||||
// if( !visitExpression( ((IASTCaseStatement)statement).getExpression(), action ) ) return false;
|
|
||||||
// } else if( statement instanceof IASTDoStatement ){
|
|
||||||
// if( !visitStatement( ((IASTDoStatement)statement).getBody(), action ) ) return false;
|
|
||||||
// if( !visitExpression( ((IASTDoStatement)statement).getCondition(), action ) ) return false;
|
|
||||||
// } else if( statement instanceof IASTGotoStatement ){
|
|
||||||
// if( !visitName( ((IASTGotoStatement)statement).getName(), action ) ) return false;
|
|
||||||
// } else if( statement instanceof IASTLabelStatement ){
|
|
||||||
// if( !visitName( ((IASTLabelStatement)statement).getName(), action ) ) return false;
|
|
||||||
// } else if( statement instanceof IASTReturnStatement ){
|
|
||||||
// if( !visitExpression( ((IASTReturnStatement) statement ).getReturnValue(), action ) ) return false;
|
|
||||||
// } else if( statement instanceof IASTSwitchStatement ){
|
|
||||||
// if( !visitExpression( ((IASTSwitchStatement) statement ).getController(), action ) ) return false;
|
|
||||||
// if( !visitStatement( ((IASTSwitchStatement) statement ).getBody(), action ) ) return false;
|
|
||||||
// } else if( statement instanceof IASTWhileStatement ){
|
|
||||||
// IASTWhileStatement whileStatement = (IASTWhileStatement) statement;
|
|
||||||
// if( whileStatement.getCondition() != null && !visitExpression( (whileStatement ).getCondition(), action ) ) return false;
|
|
||||||
// if( !visitStatement( (whileStatement ).getBody(), action ) ) return false;
|
|
||||||
// if( whileStatement instanceof ICPPASTWhileStatement )
|
|
||||||
// {
|
|
||||||
// ICPPASTWhileStatement cppWhile = ((ICPPASTWhileStatement)whileStatement);
|
|
||||||
// if ( cppWhile.getConditionDeclaration() != null && !visitDeclaration( cppWhile.getConditionDeclaration(), action ) ) return false;
|
|
||||||
// }
|
|
||||||
// } else if( statement instanceof IASTForStatement ){
|
|
||||||
// IASTForStatement s = (IASTForStatement) statement;
|
|
||||||
// if( s.getInitDeclaration() != null )
|
|
||||||
// if( !visitDeclaration( s.getInitDeclaration(), action ) ) return false;
|
|
||||||
// if( s.getInitExpression() != null )
|
|
||||||
// if( !visitExpression( s.getInitExpression(), action ) ) return false;
|
|
||||||
// if( !visitExpression( s.getCondition(), action ) ) return false;
|
|
||||||
// if( !visitExpression( s.getIterationExpression(), action ) ) return false;
|
|
||||||
// if( !visitStatement( s.getBody(), action ) ) return false;
|
|
||||||
// } else if( statement instanceof ICPPASTCatchHandler ){
|
|
||||||
// if( !visitDeclaration( ((ICPPASTCatchHandler) statement).getDeclaration(), action ) ) return false;
|
|
||||||
// if( !visitStatement( ((ICPPASTCatchHandler) statement).getCatchBody(), action ) ) return false;
|
|
||||||
// } else if( statement instanceof ICPPASTTryBlockStatement ){
|
|
||||||
// if( !visitStatement( ((ICPPASTTryBlockStatement)statement).getTryBody(), action ) ) return false;
|
|
||||||
// ICPPASTCatchHandler [] handlers = ((ICPPASTTryBlockStatement)statement).getCatchHandlers();
|
|
||||||
// for( int i = 0; i < handlers.length; i++ ){
|
|
||||||
// if( !visitStatement( handlers[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @param typeOf
|
|
||||||
// * @param action
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public boolean visitExpression(IASTExpression expression, ASTVisitor action) {
|
|
||||||
// if( action.processExpressions ){
|
|
||||||
// switch( action.processExpression( expression ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( expression instanceof IASTArraySubscriptExpression ){
|
|
||||||
// if( !visitExpression( ((IASTArraySubscriptExpression)expression).getArrayExpression(), action ) ) return false;
|
|
||||||
// if( !visitExpression( ((IASTArraySubscriptExpression)expression).getSubscriptExpression(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof IASTBinaryExpression ){
|
|
||||||
// if( !visitExpression( ((IASTBinaryExpression)expression).getOperand1(), action ) ) return false;
|
|
||||||
// if( !visitExpression( ((IASTBinaryExpression)expression).getOperand2(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof IASTConditionalExpression){
|
|
||||||
// if( !visitExpression( ((IASTConditionalExpression)expression).getLogicalConditionExpression(), action ) ) return false;
|
|
||||||
// if( !visitExpression( ((IASTConditionalExpression)expression).getNegativeResultExpression(), action ) ) return false;
|
|
||||||
// if( !visitExpression( ((IASTConditionalExpression)expression).getPositiveResultExpression(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof IASTExpressionList ){
|
|
||||||
// IASTExpression[] list = ((IASTExpressionList)expression).getExpressions();
|
|
||||||
// for( int i = 0; i < list.length; i++){
|
|
||||||
// if( list[i] == null ) break;
|
|
||||||
// if( !visitExpression( list[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// } else if( expression instanceof IASTFieldReference ){
|
|
||||||
// if( !visitExpression( ((IASTFieldReference)expression).getFieldOwner(), action ) ) return false;
|
|
||||||
// if( !visitName( ((IASTFieldReference)expression).getFieldName(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof IASTFunctionCallExpression ){
|
|
||||||
// if( !visitExpression( ((IASTFunctionCallExpression)expression).getFunctionNameExpression(), action ) ) return false;
|
|
||||||
// if( ((IASTFunctionCallExpression)expression).getParameterExpression() != null )
|
|
||||||
// if( !visitExpression( ((IASTFunctionCallExpression)expression).getParameterExpression(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof IASTIdExpression ){
|
|
||||||
// if( !visitName( ((IASTIdExpression)expression).getName(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof IASTTypeIdExpression ){
|
|
||||||
// if( !visitTypeId( ((IASTTypeIdExpression)expression).getTypeId(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof IASTCastExpression ){
|
|
||||||
// if( !visitTypeId( ((IASTCastExpression)expression).getTypeId(), action ) ) return false;
|
|
||||||
// if( !visitExpression( ((IASTCastExpression)expression).getOperand(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof IASTUnaryExpression ){
|
|
||||||
// if( !visitExpression( ((IASTUnaryExpression)expression).getOperand(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof IGNUASTCompoundStatementExpression ){
|
|
||||||
// if( !visitStatement( ((IGNUASTCompoundStatementExpression)expression).getCompoundStatement(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof ICPPASTDeleteExpression ){
|
|
||||||
// if( !visitExpression( ((ICPPASTDeleteExpression)expression).getOperand(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof ICPPASTNewExpression ) {
|
|
||||||
// ICPPASTNewExpression newExp = (ICPPASTNewExpression) expression;
|
|
||||||
// if( newExp.getNewPlacement() != null )
|
|
||||||
// if( !visitExpression( newExp.getNewPlacement(), action ) ) return false;
|
|
||||||
// if( newExp.getTypeId() != null )
|
|
||||||
// if( !visitTypeId( newExp.getTypeId(), action ) ) return false;
|
|
||||||
// IASTExpression [] exps = newExp.getNewTypeIdArrayExpressions();
|
|
||||||
// for( int i = 0; i < exps.length; i++ ){
|
|
||||||
// if( !visitExpression( exps[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// if( newExp.getNewInitializer() != null )
|
|
||||||
// if( !visitExpression( newExp.getNewInitializer(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof ICPPASTSimpleTypeConstructorExpression ){
|
|
||||||
// if( !visitExpression( ((ICPPASTSimpleTypeConstructorExpression)expression).getInitialValue(), action ) ) return false;
|
|
||||||
// } else if( expression instanceof ICPPASTTypenameExpression ){
|
|
||||||
// if( !visitName( ((ICPPASTTypenameExpression)expression).getName(), action ) ) return false;
|
|
||||||
// if( !visitExpression( ((ICPPASTTypenameExpression)expression).getInitialValue(), action ) ) return false;
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @param typeId
|
|
||||||
// * @param action
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public boolean visitTypeId(IASTTypeId typeId, ASTVisitor action) {
|
|
||||||
// if( action.processTypeIds ){
|
|
||||||
// switch( action.processTypeId( typeId ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if( !visitDeclSpecifier( typeId.getDeclSpecifier(), action ) ) return false;
|
|
||||||
// if( !visitDeclarator( typeId.getAbstractDeclarator(), action ) ) return false;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @param initializer
|
|
||||||
// * @param action
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public boolean visitInitializer(IASTInitializer initializer, ASTVisitor action) {
|
|
||||||
// if( action.processInitializers ){
|
|
||||||
// switch( action.processInitializer( initializer ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( initializer instanceof IASTInitializerExpression ){
|
|
||||||
// if( !visitExpression( ((IASTInitializerExpression) initializer).getExpression(), action ) ) return false;
|
|
||||||
// } else if( initializer instanceof IASTInitializerList ){
|
|
||||||
// IASTInitializer [] list = ((IASTInitializerList) initializer).getInitializers();
|
|
||||||
// for( int i = 0; i < list.length; i++ ){
|
|
||||||
// if( !visitInitializer( list[i], action ) ) return false;
|
|
||||||
// }
|
|
||||||
// } else if( initializer instanceof ICPPASTConstructorInitializer ){
|
|
||||||
// if( !visitExpression( ((ICPPASTConstructorInitializer) initializer).getExpression(), action ) ) return false;
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @param enumerator
|
|
||||||
// * @param action
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public boolean visitEnumerator(IASTEnumerator enumerator, ASTVisitor action) {
|
|
||||||
// if( action.processEnumerators ){
|
|
||||||
// switch( action.processEnumerator( enumerator ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( !visitName( enumerator.getName(), action ) ) return false;
|
|
||||||
// if( enumerator.getValue() != null )
|
|
||||||
// if( !visitExpression( enumerator.getValue(), action ) ) return false;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @param specifier
|
|
||||||
// * @param action
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public boolean visitBaseSpecifier(ICPPASTBaseSpecifier specifier, ASTVisitor action) {
|
|
||||||
// if( action instanceof CPPASTVisitor && ((CPPASTVisitor)action).processBaseSpecifiers ){
|
|
||||||
// switch( ((CPPASTVisitor)action).processBaseSpecifier( specifier ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( !visitName( specifier.getName(), action ) ) return false;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public boolean visitParameterDeclaration( IASTParameterDeclaration parameterDeclaration, ASTVisitor action ){
|
|
||||||
// if( action.processParameterDeclarations ){
|
|
||||||
// switch( action.processParameterDeclaration( parameterDeclaration ) ){
|
|
||||||
// case ASTVisitor.PROCESS_ABORT : return false;
|
|
||||||
// case ASTVisitor.PROCESS_SKIP : return true;
|
|
||||||
// default : break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if( !visitDeclSpecifier( parameterDeclaration.getDeclSpecifier(), action ) ) return false;
|
|
||||||
// if( !visitDeclarator( parameterDeclaration.getDeclarator(), action ) ) return false;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @param parameter
|
|
||||||
// * @param action
|
|
||||||
// * @return
|
|
||||||
// */
|
|
||||||
// public boolean visitTemplateParameter(ICPPASTTemplateParameter parameter, ASTVisitor action) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a function type for an implicit function.
|
* Generate a function type for an implicit function.
|
||||||
* NOTE: This does not currectly handle parameters with typedef types.
|
* NOTE: This does not currectly handle parameters with typedef types.
|
||||||
|
|
Loading…
Add table
Reference in a new issue