assert(0 && "getFloatingTypeOfSizeWithinDomain(): illegal domain");
}
-// maxFloatingType - handles the simple case, both operands are floats.
-QualType ASTContext::maxFloatingType(QualType lt, QualType rt) {
- return getFloatingRank(lt) > getFloatingRank(rt) ? lt : rt;
+/// compareFloatingType - Handles 3 different combos:
+/// float/float, float/complex, complex/complex.
+/// If lt > rt, return 1. If lt == rt, return 0. If lt < rt, return -1.
+int ASTContext::compareFloatingType(QualType lt, QualType rt) {
+ if (getFloatingRank(lt) == getFloatingRank(rt))
+ return 0;
+ if (getFloatingRank(lt) > getFloatingRank(rt))
+ return 1;
+ return -1;
}
// maxIntegerType - Returns the highest ranked integer type. Handles 3 case:
// real or complex domain, to the precision of the other type. For example,
// when combining a "long double" with a "double _Complex", the
// "double _Complex" is promoted to "long double _Complex".
- if (Context.maxFloatingType(lhs, rhs) == lhs) {
- // The left side is bigger, convert rhs within it's domain.
+ int result = Context.compareFloatingType(lhs, rhs);
+
+ if (result > 0) { // The left side is bigger, convert rhs.
QualType tMax = Context.getFloatingTypeOfSizeWithinDomain(lhs, rhs);
if (!isCompAssign) promoteExprToType(rhsExpr, tMax);
return tMax;
}
- // The right side is bigger, convert lhs within it's domain.
- QualType tMax = Context.getFloatingTypeOfSizeWithinDomain(rhs, lhs);
- if (!isCompAssign) promoteExprToType(lhsExpr, tMax);
- return tMax;
+ if (result < 0) { // The right side is bigger, convert lhs.
+ QualType tMax = Context.getFloatingTypeOfSizeWithinDomain(rhs, lhs);
+ if (!isCompAssign) promoteExprToType(lhsExpr, tMax);
+ return tMax;
+ }
+ // The floating point types were ranked equally.
+ if (lhs->isComplexType()) { // handle "_Complex double, double".
+ if (!isCompAssign) promoteExprToType(rhsExpr, lhs);
+ return lhs;
+ }
+ // The right side is complex, handle "double, _Complex double".
+ if (!isCompAssign) promoteExprToType(lhsExpr, rhs);
+ return rhs;
}
// Now handle "real" floating types (i.e. float, double, long double).
if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) {
}
// We have two real floating types, float/complex combos were handled above.
// Convert the smaller operand to the bigger result.
- if (Context.maxFloatingType(lhs, rhs) == lhs) { // convert the rhs
+ int result = Context.compareFloatingType(lhs, rhs);
+
+ if (result > 0) { // convert the rhs
if (!isCompAssign) promoteExprToType(rhsExpr, lhs);
return lhs;
}
- if (!isCompAssign) promoteExprToType(lhsExpr, rhs); // convert the lhs
- return rhs;
+ if (result < 0) { // convert the lhs
+ if (!isCompAssign) promoteExprToType(lhsExpr, rhs); // convert the lhs
+ return rhs;
+ }
+ assert(0 && "Sema::UsualArithmeticConversions(): illegal float comparison");
}
// Finally, we have two differing integer types.
if (Context.maxIntegerType(lhs, rhs) == lhs) { // convert the rhs
/// different type combos: unsigned/unsigned, signed/signed, signed/unsigned.
static QualType maxIntegerType(QualType lhs, QualType rhs);
- /// maxFloatingType - Returns the highest ranked float type. Handles 3
- /// different combos: float/float, float/complex, complex/complex.
- static QualType maxFloatingType(QualType lt, QualType rt);
+ /// compareFloatingType - Handles 3 different combos:
+ /// float/float, float/complex, complex/complex.
+ /// If lt > rt, return 1. If lt == rt, return 0. If lt < rt, return -1.
+ static int compareFloatingType(QualType lt, QualType rt);
/// getFloatingTypeOfSizeWithinDomain - Returns a real floating
/// point or a complex type (based on typeDomain/typeSize).