mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Cosmetics.
This commit is contained in:
parent
b41dac654c
commit
a562b0332e
1 changed files with 63 additions and 72 deletions
|
@ -75,17 +75,16 @@ public class Conversions {
|
||||||
|
|
||||||
if (target instanceof ICPPReferenceType) {
|
if (target instanceof ICPPReferenceType) {
|
||||||
// [13.3.3.3.1] Reference binding
|
// [13.3.3.3.1] Reference binding
|
||||||
IType cv1T1= getUltimateTypeViaTypedefs(((ICPPReferenceType)target).getType());
|
IType cv1T1= getUltimateTypeViaTypedefs(((ICPPReferenceType) target).getType());
|
||||||
cost= new Cost(source, cv1T1);
|
cost= new Cost(source, cv1T1);
|
||||||
cost.targetHadReference= true;
|
cost.targetHadReference= true;
|
||||||
|
|
||||||
boolean lvalue= sourceExp == null || !CPPVisitor.isRValue(sourceExp);
|
boolean lvalue= sourceExp == null || !CPPVisitor.isRValue(sourceExp);
|
||||||
IType T2= source instanceof IQualifierType ? getUltimateTypeViaTypedefs(((IQualifierType)source).getType()) : source;
|
IType T2= source instanceof IQualifierType ? getUltimateTypeViaTypedefs(((IQualifierType) source).getType()) : source;
|
||||||
|
|
||||||
if (lvalue && isReferenceCompatible(cv1T1, source)) {
|
if (lvalue && isReferenceCompatible(cv1T1, source)) {
|
||||||
/* Direct reference binding */
|
// Direct reference binding
|
||||||
// [13.3.3.1.4]
|
// [13.3.3.1.4]
|
||||||
|
|
||||||
if (cost.source.isSameType(cost.target) ||
|
if (cost.source.isSameType(cost.target) ||
|
||||||
// 7.3.3.13 for overload resolution the implicit this pointer is treated as if
|
// 7.3.3.13 for overload resolution the implicit this pointer is treated as if
|
||||||
// it were a pointer to the derived class
|
// it were a pointer to the derived class
|
||||||
|
@ -94,27 +93,23 @@ public class Conversions {
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Is an lvalue (but is not a bit-field), and "cv1 T1" is reference-compatible with "cv2 T2,"
|
||||||
* is an lvalue (but is not a bit-field), and "cv1 T1" is reference-compatible with "cv2 T2,"
|
|
||||||
*/
|
|
||||||
// [13.3.3.1.4-1] direct binding
|
// [13.3.3.1.4-1] direct binding
|
||||||
// [8.5.3-5]
|
// [8.5.3-5]
|
||||||
qualificationConversion(cost);
|
qualificationConversion(cost);
|
||||||
|
|
||||||
derivedToBaseConversion(cost);
|
derivedToBaseConversion(cost);
|
||||||
} else if (T2 instanceof ICPPClassType) {
|
} else if (T2 instanceof ICPPClassType) {
|
||||||
if(allowUDC) {
|
if (allowUDC) {
|
||||||
/*
|
// Or has a class type (i.e., T2 is a class type) and can be implicitly converted to
|
||||||
* or has a class type (i.e., T2 is a class type) and can be implicitly converted to
|
// an lvalue of type "cv3 T3," where "cv1 T1" is reference-compatible with "cv3 T3" 92)
|
||||||
* an lvalue of type "cv3 T3," where "cv1 T1" is reference-compatible with "cv3 T3" 92)
|
// (this conversion is selected by enumerating the applicable conversion functions
|
||||||
* (this conversion is selected by enumerating the applicable conversion functions (13.3.1.6)
|
// (13.3.1.6) and choosing the best one through overload resolution (13.3)).
|
||||||
* and choosing the best one through overload resolution (13.3)).
|
ICPPMethod[] fcns= SemanticUtil.getConversionOperators((ICPPClassType) T2);
|
||||||
*/
|
|
||||||
ICPPMethod[] fcns= SemanticUtil.getConversionOperators((ICPPClassType)T2);
|
|
||||||
Cost operatorCost= null;
|
Cost operatorCost= null;
|
||||||
ICPPMethod conv= null;
|
ICPPMethod conv= null;
|
||||||
boolean ambiguousConversionOperator= false;
|
boolean ambiguousConversionOperator= false;
|
||||||
if (fcns.length > 0 && fcns[0] instanceof IProblemBinding == false) {
|
if (fcns.length > 0 && !(fcns[0] instanceof IProblemBinding)) {
|
||||||
for (final ICPPMethod op : fcns) {
|
for (final ICPPMethod op : fcns) {
|
||||||
Cost cost2 = checkStandardConversionSequence(op.getType().getReturnType(), target, false);
|
Cost cost2 = checkStandardConversionSequence(op.getType().getReturnType(), target, false);
|
||||||
if (cost2.rank != Cost.NO_MATCH_RANK) {
|
if (cost2.rank != Cost.NO_MATCH_RANK) {
|
||||||
|
@ -145,16 +140,15 @@ public class Conversions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Direct binding failed */
|
// Direct binding failed
|
||||||
|
|
||||||
if (cost.rank == Cost.NO_MATCH_RANK) {
|
if (cost.rank == Cost.NO_MATCH_RANK) {
|
||||||
// 8.5.3-5 - Otherwise
|
// 8.5.3-5 - Otherwise
|
||||||
|
|
||||||
boolean cv1isConst= false;
|
boolean cv1isConst= false;
|
||||||
if (cv1T1 instanceof IQualifierType) {
|
if (cv1T1 instanceof IQualifierType) {
|
||||||
cv1isConst= ((IQualifierType)cv1T1).isConst() && !((IQualifierType)cv1T1).isVolatile();
|
cv1isConst= ((IQualifierType) cv1T1).isConst() && !((IQualifierType) cv1T1).isVolatile();
|
||||||
} else if (cv1T1 instanceof IPointerType) {
|
} else if (cv1T1 instanceof IPointerType) {
|
||||||
cv1isConst= ((IPointerType)cv1T1).isConst() && !((IPointerType)cv1T1).isVolatile();
|
cv1isConst= ((IPointerType) cv1T1).isConst() && !((IPointerType) cv1T1).isVolatile();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cv1isConst) {
|
if (cv1isConst) {
|
||||||
|
@ -176,7 +170,7 @@ public class Conversions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we must do a non-reference initialization
|
// We must do a non-reference initialization
|
||||||
if (!illformed) {
|
if (!illformed) {
|
||||||
cost= checkStandardConversionSequence(source, cv1T1, isImpliedObject);
|
cost= checkStandardConversionSequence(source, cv1T1, isImpliedObject);
|
||||||
// 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
|
||||||
|
@ -271,13 +265,13 @@ public class Conversions {
|
||||||
// The way cv-qualification is currently modeled means
|
// The way cv-qualification is currently modeled means
|
||||||
// we must cope with IPointerType objects separately.
|
// we must cope with IPointerType objects separately.
|
||||||
if (t1 instanceof IPointerType && t2 instanceof IPointerType) {
|
if (t1 instanceof IPointerType && t2 instanceof IPointerType) {
|
||||||
IType ptt1= ((IPointerType)t1).getType();
|
IType ptt1= ((IPointerType) t1).getType();
|
||||||
IType ptt2= ((IPointerType)t2).getType();
|
IType ptt2= ((IPointerType) t2).getType();
|
||||||
return ptt1 != null && ptt2 != null ? ptt1.isSameType(ptt2) : ptt1 == ptt2;
|
return ptt1 != null && ptt2 != null ? ptt1.isSameType(ptt2) : ptt1 == ptt2;
|
||||||
}
|
}
|
||||||
|
|
||||||
t1= t1 instanceof IQualifierType ? ((IQualifierType)t1).getType() : t1;
|
t1= t1 instanceof IQualifierType ? ((IQualifierType) t1).getType() : t1;
|
||||||
t2= t2 instanceof IQualifierType ? ((IQualifierType)t2).getType() : t2;
|
t2= t2 instanceof IQualifierType ? ((IQualifierType) t2).getType() : t2;
|
||||||
|
|
||||||
if (t1 instanceof ICPPClassType && t2 instanceof ICPPClassType) {
|
if (t1 instanceof ICPPClassType && t2 instanceof ICPPClassType) {
|
||||||
return calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, t2, t1) >= 0;
|
return calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, t2, t1) >= 0;
|
||||||
|
@ -319,8 +313,8 @@ public class Conversions {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cost.source.isSameType(cost.target) ||
|
if (cost.source.isSameType(cost.target) ||
|
||||||
// 7.3.3.13 for overload resolution the implicit this pointer is treated as if
|
// 7.3.3.13 for overload resolution the implicit this pointer is treated as
|
||||||
// it were a pointer to the derived class
|
// if it were a pointer to the derived class
|
||||||
(isImplicitThis && cost.source instanceof ICPPClassType && cost.target instanceof ICPPClassType)) {
|
(isImplicitThis && cost.source instanceof ICPPClassType && cost.target instanceof ICPPClassType)) {
|
||||||
cost.rank = Cost.IDENTITY_RANK;
|
cost.rank = Cost.IDENTITY_RANK;
|
||||||
return cost;
|
return cost;
|
||||||
|
@ -328,12 +322,12 @@ public class Conversions {
|
||||||
|
|
||||||
qualificationConversion(cost);
|
qualificationConversion(cost);
|
||||||
|
|
||||||
//if we can't convert the qualifications, then we can't do anything
|
// If we can't convert the qualifications, then we can't do anything
|
||||||
if (cost.qualification == Cost.NO_MATCH_RANK) {
|
if (cost.qualification == Cost.NO_MATCH_RANK) {
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
//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);
|
||||||
|
|
||||||
|
@ -383,8 +377,8 @@ public class Conversions {
|
||||||
|
|
||||||
//constructors
|
//constructors
|
||||||
if (t instanceof ICPPClassType) {
|
if (t instanceof ICPPClassType) {
|
||||||
ICPPConstructor [] constructors= ((ICPPClassType)t).getConstructors();
|
ICPPConstructor [] constructors= ((ICPPClassType) t).getConstructors();
|
||||||
if (constructors.length > 0 && constructors[0] instanceof IProblemBinding == false) {
|
if (constructors.length > 0 && !(constructors[0] instanceof IProblemBinding)) {
|
||||||
LookupData data= new LookupData();
|
LookupData data= new LookupData();
|
||||||
data.forUserDefinedConversion= true;
|
data.forUserDefinedConversion= true;
|
||||||
data.functionParameters= new IType [] { source };
|
data.functionParameters= new IType [] { source };
|
||||||
|
@ -404,15 +398,14 @@ public class Conversions {
|
||||||
//conversion operators
|
//conversion operators
|
||||||
boolean ambiguousConversionOperator= false;
|
boolean ambiguousConversionOperator= false;
|
||||||
if (s instanceof ICPPClassType) {
|
if (s instanceof ICPPClassType) {
|
||||||
ICPPMethod [] ops = SemanticUtil.getConversionOperators((ICPPClassType)s);
|
ICPPMethod [] ops = SemanticUtil.getConversionOperators((ICPPClassType) s);
|
||||||
if (ops.length > 0 && ops[0] instanceof IProblemBinding == false) {
|
if (ops.length > 0 && !(ops[0] instanceof IProblemBinding)) {
|
||||||
for (final ICPPMethod op : ops) {
|
for (final ICPPMethod op : ops) {
|
||||||
Cost cost= checkStandardConversionSequence(op.getType().getReturnType(), target, false);
|
Cost cost= checkStandardConversionSequence(op.getType().getReturnType(), target, false);
|
||||||
if (cost.rank != Cost.NO_MATCH_RANK) {
|
if (cost.rank != Cost.NO_MATCH_RANK) {
|
||||||
if (operatorCost == null) {
|
if (operatorCost == null) {
|
||||||
operatorCost= cost;
|
operatorCost= cost;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
int cmp= operatorCost.compare(cost);
|
int cmp= operatorCost.compare(cost);
|
||||||
if (cmp >= 0) {
|
if (cmp >= 0) {
|
||||||
ambiguousConversionOperator= cmp == 0;
|
ambiguousConversionOperator= cmp == 0;
|
||||||
|
@ -428,9 +421,8 @@ public class Conversions {
|
||||||
if (operatorCost == null || ambiguousConversionOperator) {
|
if (operatorCost == null || ambiguousConversionOperator) {
|
||||||
constructorCost.userDefined = Cost.USERDEFINED_CONVERSION;
|
constructorCost.userDefined = Cost.USERDEFINED_CONVERSION;
|
||||||
constructorCost.rank = Cost.USERDEFINED_CONVERSION_RANK;
|
constructorCost.rank = Cost.USERDEFINED_CONVERSION_RANK;
|
||||||
}
|
} else {
|
||||||
else {
|
// If both are valid, then the conversion is ambiguous
|
||||||
//if both are valid, then the conversion is ambiguous
|
|
||||||
constructorCost.userDefined = Cost.AMBIGUOUS_USERDEFINED_CONVERSION;
|
constructorCost.userDefined = Cost.AMBIGUOUS_USERDEFINED_CONVERSION;
|
||||||
constructorCost.rank = Cost.USERDEFINED_CONVERSION_RANK;
|
constructorCost.rank = Cost.USERDEFINED_CONVERSION_RANK;
|
||||||
}
|
}
|
||||||
|
@ -440,8 +432,7 @@ public class Conversions {
|
||||||
operatorCost.rank = Cost.USERDEFINED_CONVERSION_RANK;
|
operatorCost.rank = Cost.USERDEFINED_CONVERSION_RANK;
|
||||||
if (ambiguousConversionOperator) {
|
if (ambiguousConversionOperator) {
|
||||||
operatorCost.userDefined = Cost.AMBIGUOUS_USERDEFINED_CONVERSION;
|
operatorCost.userDefined = Cost.AMBIGUOUS_USERDEFINED_CONVERSION;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
operatorCost.userDefined = Cost.USERDEFINED_CONVERSION;
|
operatorCost.userDefined = Cost.USERDEFINED_CONVERSION;
|
||||||
}
|
}
|
||||||
return operatorCost;
|
return operatorCost;
|
||||||
|
@ -465,8 +456,8 @@ public class Conversions {
|
||||||
|
|
||||||
if (maxdepth > 0 && type instanceof ICPPClassType && ancestorToFind instanceof ICPPClassType) {
|
if (maxdepth > 0 && type instanceof ICPPClassType && ancestorToFind instanceof ICPPClassType) {
|
||||||
ICPPClassType clazz = (ICPPClassType) type;
|
ICPPClassType clazz = (ICPPClassType) type;
|
||||||
if(clazz instanceof ICPPDeferredClassInstance) {
|
if (clazz instanceof ICPPDeferredClassInstance) {
|
||||||
clazz= (ICPPClassType) ((ICPPDeferredClassInstance)clazz).getSpecializedBinding();
|
clazz= (ICPPClassType) ((ICPPDeferredClassInstance) clazz).getSpecializedBinding();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ICPPBase cppBase : clazz.getBases()) {
|
for (ICPPBase cppBase : clazz.getBases()) {
|
||||||
|
@ -474,8 +465,8 @@ public class Conversions {
|
||||||
if (base instanceof IType) {
|
if (base instanceof IType) {
|
||||||
IType tbase= (IType) base;
|
IType tbase= (IType) base;
|
||||||
if (tbase.isSameType(ancestorToFind) ||
|
if (tbase.isSameType(ancestorToFind) ||
|
||||||
(ancestorToFind instanceof ICPPSpecialization && /*allow some flexibility with templates*/
|
(ancestorToFind instanceof ICPPSpecialization && // allow some flexibility with templates
|
||||||
((IType)((ICPPSpecialization)ancestorToFind).getSpecializedBinding()).isSameType(tbase))) {
|
((IType)((ICPPSpecialization) ancestorToFind).getSpecializedBinding()).isSameType(tbase))) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,16 +511,16 @@ public class Conversions {
|
||||||
cost.targetHadReference = true;
|
cost.targetHadReference = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//4.3 function to pointer conversion
|
// 4.3 function to pointer conversion
|
||||||
if (target instanceof IPointerType && ((IPointerType)target).getType() instanceof IFunctionType &&
|
if (target instanceof IPointerType && ((IPointerType) target).getType() instanceof IFunctionType &&
|
||||||
source instanceof IFunctionType) {
|
source instanceof IFunctionType) {
|
||||||
source = new CPPPointerType(source);
|
source = new CPPPointerType(source);
|
||||||
} else if (target instanceof IPointerType && source instanceof IArrayType) {
|
} else if (target instanceof IPointerType && source instanceof IArrayType) {
|
||||||
//4.2 Array-To-Pointer conversion
|
// 4.2 Array-To-Pointer conversion
|
||||||
source = new CPPPointerType(((IArrayType)source).getType());
|
source = new CPPPointerType(((IArrayType) source).getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
//4.1 if T is a non-class type, the type of the rvalue is the cv-unqualified version of T
|
// 4.1 if T is a non-class type, the type of the rvalue is the cv-unqualified version of T
|
||||||
if (source instanceof IQualifierType) {
|
if (source instanceof IQualifierType) {
|
||||||
IType t = ((IQualifierType) source).getType();
|
IType t = ((IQualifierType) source).getType();
|
||||||
while (t instanceof ITypedef)
|
while (t instanceof ITypedef)
|
||||||
|
@ -538,7 +529,7 @@ public class Conversions {
|
||||||
source = t;
|
source = t;
|
||||||
}
|
}
|
||||||
} else if (source instanceof IPointerType &&
|
} else if (source instanceof IPointerType &&
|
||||||
(((IPointerType)source).isConst() || ((IPointerType)source).isVolatile())) {
|
(((IPointerType) source).isConst() || ((IPointerType) source).isVolatile())) {
|
||||||
IType t= ((IPointerType) source).getType();
|
IType t= ((IPointerType) source).getType();
|
||||||
while (t instanceof ITypedef)
|
while (t instanceof ITypedef)
|
||||||
t= ((ITypedef) t).getType();
|
t= ((ITypedef) t).getType();
|
||||||
|
@ -592,17 +583,17 @@ public class Conversions {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// both are pointers
|
// Both are pointers
|
||||||
IPointerType op1= (IPointerType) s;
|
IPointerType op1= (IPointerType) s;
|
||||||
IPointerType op2= (IPointerType) t;
|
IPointerType op2= (IPointerType) t;
|
||||||
|
|
||||||
//if const is in cv1,j then const is in cv2,j. Similary for volatile
|
// If const is in cv1,j then const is in cv2,j. Similarly for volatile
|
||||||
if ((op1.isConst() && !op2.isConst()) || (op1.isVolatile() && !op2.isVolatile())) {
|
if ((op1.isConst() && !op2.isConst()) || (op1.isVolatile() && !op2.isVolatile())) {
|
||||||
canConvert = false;
|
canConvert = false;
|
||||||
requiredConversion = Cost.NO_MATCH_RANK;
|
requiredConversion = Cost.NO_MATCH_RANK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//if cv1,j and cv2,j are different then const is in every cv2,k for 0<k<j
|
// If cv1,j and cv2,j are different then const is in every cv2,k for 0<k<j
|
||||||
if (!constInEveryCV2k && (op1.isConst() != op2.isConst() ||
|
if (!constInEveryCV2k && (op1.isConst() != op2.isConst() ||
|
||||||
op1.isVolatile() != op2.isVolatile())) {
|
op1.isVolatile() != op2.isVolatile())) {
|
||||||
canConvert = false;
|
canConvert = false;
|
||||||
|
@ -628,15 +619,15 @@ public class Conversions {
|
||||||
requiredConversion = Cost.CONVERSION_RANK;
|
requiredConversion = Cost.CONVERSION_RANK;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//4.2-2 a string literal can be converted to pointer to char
|
// 4.2-2 a string literal can be converted to pointer to char
|
||||||
if (t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_char &&
|
if (t instanceof IBasicType && ((IBasicType) t).getType() == IBasicType.t_char &&
|
||||||
s instanceof IQualifierType) {
|
s instanceof IQualifierType) {
|
||||||
IType qt = ((IQualifierType) s).getType();
|
IType qt = ((IQualifierType) s).getType();
|
||||||
if (qt instanceof CPPBasicType) {
|
if (qt instanceof CPPBasicType) {
|
||||||
IASTExpression val = ((CPPBasicType) qt).getCreatedFromExpression();
|
IASTExpression val = ((CPPBasicType) qt).getCreatedFromExpression();
|
||||||
canConvert = (val != null &&
|
canConvert = (val != null &&
|
||||||
val instanceof IASTLiteralExpression &&
|
val instanceof IASTLiteralExpression &&
|
||||||
((IASTLiteralExpression)val).getKind() == IASTLiteralExpression.lk_string_literal);
|
((IASTLiteralExpression) val).getKind() == IASTLiteralExpression.lk_string_literal);
|
||||||
} else {
|
} else {
|
||||||
canConvert = false;
|
canConvert = false;
|
||||||
requiredConversion = Cost.NO_MATCH_RANK;
|
requiredConversion = Cost.NO_MATCH_RANK;
|
||||||
|
@ -678,7 +669,7 @@ public class Conversions {
|
||||||
}
|
}
|
||||||
|
|
||||||
cost.qualification = requiredConversion;
|
cost.qualification = requiredConversion;
|
||||||
if (canConvert == true) {
|
if (canConvert) {
|
||||||
cost.rank = Cost.LVALUE_OR_QUALIFICATION_RANK;
|
cost.rank = Cost.LVALUE_OR_QUALIFICATION_RANK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -705,11 +696,11 @@ public class Conversions {
|
||||||
if (src instanceof IBasicType && trg instanceof IBasicType) {
|
if (src instanceof IBasicType && trg instanceof IBasicType) {
|
||||||
int sType = ((IBasicType) src).getType();
|
int sType = ((IBasicType) src).getType();
|
||||||
int tType = ((IBasicType) trg).getType();
|
int tType = ((IBasicType) trg).getType();
|
||||||
if ((tType == IBasicType.t_int && (sType == IBasicType.t_int || //short, long , unsigned etc
|
if ((tType == IBasicType.t_int && (sType == IBasicType.t_int || // short, long, unsigned etc
|
||||||
sType == IBasicType.t_char ||
|
sType == IBasicType.t_char ||
|
||||||
sType == ICPPBasicType.t_bool ||
|
sType == ICPPBasicType.t_bool ||
|
||||||
sType == ICPPBasicType.t_wchar_t ||
|
sType == ICPPBasicType.t_wchar_t ||
|
||||||
sType == IBasicType.t_unspecified)) || //treat unspecified as int
|
sType == IBasicType.t_unspecified)) || // treat unspecified as int
|
||||||
(tType == IBasicType.t_double && sType == IBasicType.t_float)) {
|
(tType == IBasicType.t_double && sType == IBasicType.t_float)) {
|
||||||
cost.promotion = 1;
|
cost.promotion = 1;
|
||||||
}
|
}
|
||||||
|
@ -755,17 +746,17 @@ public class Conversions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (sPrev instanceof IPointerType) {
|
} else if (sPrev instanceof IPointerType) {
|
||||||
//4.10-2 an rvalue of type "pointer to cv T", where T is an object type can be
|
// 4.10-2 an rvalue of type "pointer to cv T", where T is an object type can be
|
||||||
//converted to an rvalue of type "pointer to cv void"
|
// converted to an rvalue of type "pointer to cv void"
|
||||||
if (tPrev instanceof IPointerType && t instanceof IBasicType &&
|
if (tPrev instanceof IPointerType && t instanceof IBasicType &&
|
||||||
((IBasicType)t).getType() == IBasicType.t_void) {
|
((IBasicType) t).getType() == IBasicType.t_void) {
|
||||||
cost.rank = Cost.CONVERSION_RANK;
|
cost.rank = Cost.CONVERSION_RANK;
|
||||||
cost.conversion = 1;
|
cost.conversion = 1;
|
||||||
cost.detail = 2;
|
cost.detail = 2;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//4.10-3 An rvalue of type "pointer to cv D", where D is a class type can be converted
|
// 4.10-3 An rvalue of type "pointer to cv D", where D is a class type can be converted
|
||||||
//to an rvalue of type "pointer to cv B", where B is a base class of D.
|
// to an rvalue of type "pointer to cv B", where B is a base class of D.
|
||||||
else if (s instanceof ICPPClassType && tPrev instanceof IPointerType && t instanceof ICPPClassType) {
|
else if (s instanceof ICPPClassType && tPrev instanceof IPointerType && t instanceof ICPPClassType) {
|
||||||
int depth= calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, s, t);
|
int depth= calculateInheritanceDepth(CPPSemantics.MAX_INHERITANCE_DEPTH, s, t);
|
||||||
cost.rank= (depth > -1) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK;
|
cost.rank= (depth > -1) ? Cost.CONVERSION_RANK : Cost.NO_MATCH_RANK;
|
||||||
|
@ -774,25 +765,25 @@ public class Conversions {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 4.12 if the target is a bool, we can still convert
|
// 4.12 if the target is a bool, we can still convert
|
||||||
else if (!(trg instanceof IBasicType && ((IBasicType)trg).getType() == ICPPBasicType.t_bool)) {
|
else if (!(trg instanceof IBasicType && ((IBasicType) trg).getType() == ICPPBasicType.t_bool)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t instanceof IBasicType && s instanceof IBasicType || s instanceof IEnumeration) {
|
if (t instanceof IBasicType && s instanceof IBasicType || s instanceof IEnumeration) {
|
||||||
//4.7 An rvalue of an integer type can be converted to an rvalue of another integer type.
|
// 4.7 An rvalue of an integer type can be converted to an rvalue of another integer type.
|
||||||
//An rvalue of an enumeration type can be converted to an rvalue of an integer type.
|
// An rvalue of an enumeration type can be converted to an rvalue of an integer type.
|
||||||
cost.rank = Cost.CONVERSION_RANK;
|
cost.rank = Cost.CONVERSION_RANK;
|
||||||
cost.conversion = 1;
|
cost.conversion = 1;
|
||||||
} else if (trg instanceof IBasicType && ((IBasicType)trg).getType() == ICPPBasicType.t_bool &&
|
} else if (trg instanceof IBasicType && ((IBasicType) trg).getType() == ICPPBasicType.t_bool &&
|
||||||
s instanceof IPointerType) {
|
s instanceof IPointerType) {
|
||||||
//4.12 pointer or pointer to member type can be converted to an rvalue of type bool
|
// 4.12 pointer or pointer to member type can be converted to an rvalue of type bool
|
||||||
cost.rank = Cost.CONVERSION_RANK;
|
cost.rank = Cost.CONVERSION_RANK;
|
||||||
cost.conversion = 1;
|
cost.conversion = 1;
|
||||||
} else if (s instanceof ICPPPointerToMemberType && t instanceof ICPPPointerToMemberType) {
|
} else if (s instanceof ICPPPointerToMemberType && t instanceof ICPPPointerToMemberType) {
|
||||||
//4.11-2 An rvalue of type "pointer to member of B of type cv T", where B is a class type,
|
// 4.11-2 An rvalue of type "pointer to member of B of type cv T", where B is a class type,
|
||||||
//can be converted to an rvalue of type "pointer to member of D of type cv T" where D is a
|
// can be converted to an rvalue of type "pointer to member of D of type cv T" where D is a
|
||||||
//derived class of B
|
// derived class of B
|
||||||
ICPPPointerToMemberType spm = (ICPPPointerToMemberType) s;
|
ICPPPointerToMemberType spm = (ICPPPointerToMemberType) s;
|
||||||
ICPPPointerToMemberType tpm = (ICPPPointerToMemberType) t;
|
ICPPPointerToMemberType tpm = (ICPPPointerToMemberType) t;
|
||||||
IType st = spm.getType();
|
IType st = spm.getType();
|
||||||
|
|
Loading…
Add table
Reference in a new issue