1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

fix bug 90039

when getting expression types, don't try to reresolve bindings for names that already
have a binding.  Also, handle enumerators when they are the result of the expression
This commit is contained in:
Andrew Niefer 2005-04-02 01:22:44 +00:00
parent 67c1fbfc3f
commit 407dc37063
2 changed files with 41 additions and 13 deletions

View file

@ -3155,5 +3155,28 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame( bs[0], f1 ); assertSame( bs[0], f1 );
assertSame( bs[1], f2 ); assertSame( bs[1], f2 );
} }
public void testBug90039() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("class A { \n"); //$NON-NLS-1$
buffer.append(" enum type { t1, t2 }; \n"); //$NON-NLS-1$
buffer.append(" void f( type t ); \n"); //$NON-NLS-1$
buffer.append("}; \n"); //$NON-NLS-1$
buffer.append("class B : public A { \n"); //$NON-NLS-1$
buffer.append(" void g() { \n"); //$NON-NLS-1$
buffer.append(" f( A::t1 ); \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 );
IFunction f = (IFunction) col.getName( 10 ).resolveBinding();
IEnumerator t1 = (IEnumerator) col.getName( 13 ).resolveBinding();
assertInstances( col, f, 2 );
assertInstances( col, t1, 3 );
}
} }

View file

@ -59,6 +59,7 @@ import org.eclipse.cdt.core.dom.ast.IBasicType;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.ILabel; import org.eclipse.cdt.core.dom.ast.ILabel;
@ -739,12 +740,15 @@ public class CPPVisitor {
node = null; node = null;
} }
if( name != null ){ if( name != null ){
IBinding binding = CPPSemantics.resolveBinding( name );
if( name instanceof ICPPASTQualifiedName ){ if( name instanceof ICPPASTQualifiedName ){
IASTName ns [] = ((ICPPASTQualifiedName)name).getNames(); IASTName ns [] = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ]; name = ns[ ns.length - 1 ];
} }
IBinding binding = name.getBinding();
if( binding == null ){
binding = CPPSemantics.resolveBinding( name );
name.setBinding( binding ); name.setBinding( binding );
}
return binding; return binding;
} }
return null; return null;
@ -1382,21 +1386,20 @@ public class CPPVisitor {
return null; return null;
if( expression instanceof IASTIdExpression ){ if( expression instanceof IASTIdExpression ){
IBinding binding = resolveBinding( expression ); IBinding binding = resolveBinding( expression );
if( binding instanceof IVariable ){
try { try {
if( binding instanceof IVariable ){
return ((IVariable)binding).getType(); return ((IVariable)binding).getType();
} catch ( DOMException e ) { } else if( binding instanceof IEnumerator ){
return e.getProblem(); return ((IEnumerator)binding).getType();
}
} else if( binding instanceof IProblemBinding ){ } else if( binding instanceof IProblemBinding ){
return (IType) binding; return (IType) binding;
} else if( binding instanceof IFunction ){ } else if( binding instanceof IFunction ){
try {
return ((IFunction)binding).getType(); return ((IFunction)binding).getType();
}
} catch ( DOMException e ){ } catch ( DOMException e ){
return e.getProblem(); return e.getProblem();
} }
}
} else if( expression instanceof IASTCastExpression ){ } else if( expression instanceof IASTCastExpression ){
IASTTypeId id = ((IASTCastExpression)expression).getTypeId(); IASTTypeId id = ((IASTCastExpression)expression).getTypeId();
IType type = createType( id.getDeclSpecifier() ); IType type = createType( id.getDeclSpecifier() );
@ -1515,6 +1518,8 @@ public class CPPVisitor {
return ((IVariable)binding).getType(); return ((IVariable)binding).getType();
else if( binding instanceof IFunction ) else if( binding instanceof IFunction )
return ((IFunction)binding).getType(); return ((IFunction)binding).getType();
else if( binding instanceof IEnumerator )
return ((IEnumerator)binding).getType();
} catch ( DOMException e ) { } catch ( DOMException e ) {
return e.getProblem(); return e.getProblem();
} }