Skip to content

Commit 3401f3f

Browse files
committed
Change operators to use lt from Value base
1 parent 633ac21 commit 3401f3f

File tree

1 file changed

+8
-73
lines changed

1 file changed

+8
-73
lines changed

eval.cpp

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,83 +1088,18 @@ namespace Sass {
10881088

10891089
bool Eval::eq(Expression* lhs, Expression* rhs)
10901090
{
1091-
Expression::Concrete_Type ltype = lhs->concrete_type();
1092-
Expression::Concrete_Type rtype = rhs->concrete_type();
1093-
if (ltype != rtype) return false;
1094-
switch (ltype) {
1095-
1096-
case Expression::BOOLEAN: {
1097-
return static_cast<Boolean*>(lhs)->value() ==
1098-
static_cast<Boolean*>(rhs)->value();
1099-
} break;
1100-
1101-
case Expression::NUMBER: {
1102-
Number* l = static_cast<Number*>(lhs);
1103-
Number* r = static_cast<Number*>(rhs);
1104-
return (l->value() == r->value()) &&
1105-
(l->numerator_units() == r->numerator_units()) &&
1106-
(l->denominator_units() == r->denominator_units());
1107-
} break;
1108-
1109-
case Expression::COLOR: {
1110-
Color* l = static_cast<Color*>(lhs);
1111-
Color* r = static_cast<Color*>(rhs);
1112-
return l->r() == r->r() &&
1113-
l->g() == r->g() &&
1114-
l->b() == r->b() &&
1115-
l->a() == r->a();
1116-
} break;
1117-
1118-
case Expression::STRING: {
1119-
string slhs = static_cast<String_Quoted*>(lhs)->value();
1120-
string srhs = static_cast<String_Quoted*>(rhs)->value();
1121-
return unquote(slhs) == unquote(srhs) &&
1122-
(!(is_quoted(slhs) || is_quoted(srhs)) || slhs[0] == srhs[0]);
1123-
} break;
1124-
1125-
case Expression::LIST: {
1126-
List* l = static_cast<List*>(lhs);
1127-
List* r = static_cast<List*>(rhs);
1128-
if (l->length() != r->length()) return false;
1129-
if (l->separator() != r->separator()) return false;
1130-
for (size_t i = 0, L = l->length(); i < L; ++i) {
1131-
if (!eq((*l)[i], (*r)[i])) return false;
1132-
}
1133-
return true;
1134-
} break;
1135-
1136-
case Expression::MAP: {
1137-
Map* l = static_cast<Map*>(lhs);
1138-
Map* r = static_cast<Map*>(rhs);
1139-
if (l->length() != r->length()) return false;
1140-
for (auto key : l->keys())
1141-
if (!eq(l->at(key), r->at(key))) return false;
1142-
return true;
1143-
} break;
1144-
case Expression::NULL_VAL: {
1145-
return true;
1146-
} break;
1147-
1148-
default: break;
1149-
}
1150-
return false;
1091+
// use compare operator from ast node
1092+
return lhs && rhs && *lhs == *rhs;
11511093
}
11521094

11531095
bool Eval::lt(Expression* lhs, Expression* rhs)
11541096
{
1155-
if (lhs->concrete_type() != Expression::NUMBER ||
1156-
rhs->concrete_type() != Expression::NUMBER)
1157-
error("may only compare numbers", lhs->pstate());
1158-
Number* l = static_cast<Number*>(lhs);
1159-
Number* r = static_cast<Number*>(rhs);
1160-
Number tmp_r(*r);
1161-
tmp_r.normalize(l->find_convertible_unit());
1162-
string l_unit(l->unit());
1163-
string r_unit(tmp_r.unit());
1164-
if (!l_unit.empty() && !r_unit.empty() && l->unit() != tmp_r.unit()) {
1165-
error("cannot compare numbers with incompatible units", l->pstate());
1166-
}
1167-
return l->value() < tmp_r.value();
1097+
Number* l = dynamic_cast<Number*>(lhs);
1098+
Number* r = dynamic_cast<Number*>(rhs);
1099+
if (!l) error("may only compare numbers", lhs->pstate());
1100+
if (!r) error("may only compare numbers", rhs->pstate());
1101+
// use compare operator from ast node
1102+
return *l < *r;
11681103
}
11691104

11701105
Value* Eval::op_numbers(Context& ctx, enum Sass_OP op, Number* l, Number* r, bool compressed, int precision)

0 commit comments

Comments
 (0)