1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2009-01-18 22:39:53 +00:00
parent b41dac654c
commit a562b0332e

View file

@ -83,9 +83,8 @@ public class Conversions {
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,9 +93,7 @@ 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);
@ -104,17 +101,15 @@ public class Conversions {
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,8 +140,7 @@ 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
@ -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
@ -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);
@ -384,7 +378,7 @@ 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 };
@ -405,14 +399,13 @@ public class Conversions {
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;
@ -474,7 +465,7 @@ 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;
} }
@ -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;
@ -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;
} }
} }