mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Fix NPE's && CCE's during resolution of bindings
bug 86187
This commit is contained in:
parent
12cdf18a80
commit
877ceeab4e
7 changed files with 51 additions and 17 deletions
|
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -109,8 +110,8 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId {
|
|||
* @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding()
|
||||
*/
|
||||
public IBinding resolveBinding() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
// TODO templates not yet supported
|
||||
return new ProblemBinding( -1, templateName.toCharArray() );
|
||||
}
|
||||
|
||||
public IBinding[] resolvePrefix() {
|
||||
|
|
|
@ -180,7 +180,7 @@ public class CPPImplicitMethod extends CPPMethod {
|
|||
IType [] ps = t.getParameterTypes();
|
||||
if( ps.length == params.length ){
|
||||
int idx = 0;
|
||||
for( ; idx < ps.length; idx++ ){
|
||||
for( ; idx < ps.length && ps[idx] != null; idx++ ){
|
||||
if( !ps[idx].equals(params[idx]) )
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,9 @@ public class CPPPointerType implements IPointerType, ITypeContainer {
|
|||
if( !( o instanceof CPPPointerType ) )
|
||||
return false;
|
||||
|
||||
if( type == null )
|
||||
return false;
|
||||
|
||||
CPPPointerType pt = (CPPPointerType) o;
|
||||
if( isConst() == pt.isConst() && isVolatile() == pt.isVolatile() )
|
||||
return type.equals( pt.getType() );
|
||||
|
|
|
@ -431,9 +431,11 @@ public class CPPSemantics {
|
|||
ICPPClassType cls = (ICPPClassType) binding;
|
||||
try {
|
||||
//force resolution of constructor bindings
|
||||
cls.getConstructors();
|
||||
//then use the class scope to resolve which one.
|
||||
binding = ((ICPPClassScope)cls.getCompositeScope()).getBinding( data.astName );
|
||||
IBinding [] ctors = cls.getConstructors();
|
||||
if( ctors.length > 0 && !(ctors[0] instanceof IProblemBinding) ){
|
||||
//then use the class scope to resolve which one.
|
||||
binding = ((ICPPClassScope)cls.getCompositeScope()).getBinding( data.astName );
|
||||
}
|
||||
} catch ( DOMException e ) {
|
||||
binding = e.getProblem();
|
||||
}
|
||||
|
@ -1527,14 +1529,17 @@ public class CPPSemantics {
|
|||
cost.rank = Cost.IDENTITY_RANK; //exact match, no cost
|
||||
} else {
|
||||
cost = checkStandardConversionSequence( source, target );
|
||||
|
||||
//12.3-4 At most one user-defined conversion is implicitly applied to
|
||||
//a single value. (also prevents infinite loop)
|
||||
if( cost.rank == Cost.NO_MATCH_RANK && !data.forUserDefinedConversion ){
|
||||
temp = checkUserDefinedConversionSequence( source, target );
|
||||
if( temp != null ){
|
||||
cost = temp;
|
||||
if( !data.forDefinition() ){
|
||||
//12.3-4 At most one user-defined conversion is implicitly applied to
|
||||
//a single value. (also prevents infinite loop)
|
||||
if( cost.rank == Cost.NO_MATCH_RANK && !data.forUserDefinedConversion ){
|
||||
temp = checkUserDefinedConversionSequence( source, target );
|
||||
if( temp != null ){
|
||||
cost = temp;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cost.rank = Cost.NO_MATCH_RANK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1829,6 +1834,12 @@ public class CPPSemantics {
|
|||
//was the qualification conversion enough?
|
||||
IType s = getUltimateType( cost.source, true );
|
||||
IType t = getUltimateType( cost.target, true );
|
||||
|
||||
if( s == null || t == null ){
|
||||
cost.rank = Cost.NO_MATCH_RANK;
|
||||
return cost;
|
||||
}
|
||||
|
||||
if( s.equals( t ) ){
|
||||
return cost;
|
||||
}
|
||||
|
|
|
@ -54,9 +54,14 @@ public class CPPTypedef implements ITypedef, ITypeContainer, ICPPBinding {
|
|||
}
|
||||
|
||||
public boolean equals( Object o ){
|
||||
if( o == this )
|
||||
return true;
|
||||
if( o instanceof ITypedef )
|
||||
try {
|
||||
return getType().equals( ((ITypedef)o).getType());
|
||||
IType t = getType();
|
||||
if( t != null )
|
||||
return t.equals( ((ITypedef)o).getType());
|
||||
return false;
|
||||
} catch ( DOMException e ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -64,7 +69,10 @@ public class CPPTypedef implements ITypedef, ITypeContainer, ICPPBinding {
|
|||
if( !( o instanceof IType ) )
|
||||
return false;
|
||||
|
||||
return getType().equals( o );
|
||||
IType t = getType();
|
||||
if( t != null )
|
||||
return t.equals( o );
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -49,12 +49,13 @@ public class CPPVariable implements IVariable, ICPPBinding {
|
|||
private IType type = null;
|
||||
|
||||
public CPPVariable( IASTName name ){
|
||||
boolean isDef = isDefinition( name );
|
||||
if( name instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = ns[ ns.length - 1 ];
|
||||
}
|
||||
|
||||
if( isDefinition( name ) )
|
||||
if( isDef )
|
||||
definition = name;
|
||||
else
|
||||
declarations = new IASTName [] { name };
|
||||
|
@ -62,6 +63,13 @@ public class CPPVariable implements IVariable, ICPPBinding {
|
|||
}
|
||||
|
||||
protected boolean isDefinition( IASTName name ){
|
||||
IASTNode node = name.getParent();
|
||||
if( node instanceof ICPPASTQualifiedName )
|
||||
node = node.getParent();
|
||||
|
||||
if( !( node instanceof IASTDeclarator ) )
|
||||
return false;
|
||||
|
||||
IASTDeclarator dtor = (IASTDeclarator) name.getParent();
|
||||
while( dtor.getParent() instanceof IASTDeclarator )
|
||||
dtor = (IASTDeclarator) dtor.getParent();
|
||||
|
|
|
@ -548,7 +548,10 @@ public class CPPVisitor implements ICPPASTVisitor {
|
|||
else if( prop == IASTFunctionDefinition.DECLARATOR )
|
||||
return ((IASTCompoundStatement)((IASTFunctionDefinition)dtor.getParent()).getBody()).getScope();
|
||||
} else if( node instanceof IASTInitializerExpression ){
|
||||
IASTDeclarator dtor = (IASTDeclarator) node.getParent();
|
||||
IASTNode parent = node.getParent();
|
||||
while( !(parent instanceof IASTDeclarator) )
|
||||
parent = parent.getParent();
|
||||
IASTDeclarator dtor = (IASTDeclarator) parent;
|
||||
IASTName name = dtor.getName();
|
||||
if( name instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
|
|
Loading…
Add table
Reference in a new issue