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