@@ -440,16 +440,6 @@ namespace Sass {
440
440
return mm;
441
441
}
442
442
443
- // -- only need to define two comparisons, and the rest can be implemented in terms of them
444
- bool eq (Expression*, Expression*, Context&, Eval*);
445
- bool lt (Expression*, Expression*, Context&);
446
- // -- arithmetic on the combinations that matter
447
- Expression* op_numbers (Context&, Binary_Expression*, Expression*, Expression*);
448
- Expression* op_number_color (Context&, enum Sass_OP, Expression*, Expression*);
449
- Expression* op_color_number (Context&, enum Sass_OP, Expression*, Expression*);
450
- Expression* op_colors (Context&, enum Sass_OP, Expression*, Expression*);
451
- Expression* op_strings (Context&, enum Sass_OP, Expression*, Expression*);
452
-
453
443
Expression* Eval::operator ()(Binary_Expression* b)
454
444
{
455
445
enum Sass_OP op_type = b->type ();
@@ -520,16 +510,24 @@ namespace Sass {
520
510
Expression::Concrete_Type r_type = rhs->concrete_type ();
521
511
522
512
if (l_type == Expression::NUMBER && r_type == Expression::NUMBER) {
523
- return op_numbers (ctx, b, lhs, rhs);
513
+ Number* l_n = static_cast <Number*>(lhs);
514
+ Number* r_n = static_cast <Number*>(rhs);
515
+ return op_numbers (ctx, op_type, l_n, r_n);
524
516
}
525
517
if (l_type == Expression::NUMBER && r_type == Expression::COLOR) {
526
- return op_number_color (ctx, op_type, lhs, rhs);
518
+ Number* l_n = static_cast <Number*>(lhs);
519
+ Color* r_c = static_cast <Color*>(rhs);
520
+ return op_number_color (ctx, op_type, l_n, r_c);
527
521
}
528
522
if (l_type == Expression::COLOR && r_type == Expression::NUMBER) {
529
- return op_color_number (ctx, op_type, lhs, rhs);
523
+ Color* l_c = static_cast <Color*>(lhs);
524
+ Number* r_n = static_cast <Number*>(rhs);
525
+ return op_color_number (ctx, op_type, l_c, r_n);
530
526
}
531
527
if (l_type == Expression::COLOR && r_type == Expression::COLOR) {
532
- return op_colors (ctx, op_type, lhs, rhs);
528
+ Color* l_c = static_cast <Color*>(lhs);
529
+ Color* r_c = static_cast <Color*>(rhs);
530
+ return op_colors (ctx, op_type, l_c, r_c);
533
531
}
534
532
535
533
Expression* ex = op_strings (ctx, op_type, lhs, rhs);
@@ -1066,7 +1064,7 @@ namespace Sass {
1066
1064
1067
1065
// All the binary helpers.
1068
1066
1069
- bool eq (Expression* lhs, Expression* rhs, Context& ctx)
1067
+ bool Eval:: eq (Expression* lhs, Expression* rhs, Context& ctx)
1070
1068
{
1071
1069
Expression::Concrete_Type ltype = lhs->concrete_type ();
1072
1070
Expression::Concrete_Type rtype = rhs->concrete_type ();
@@ -1130,7 +1128,7 @@ namespace Sass {
1130
1128
return false ;
1131
1129
}
1132
1130
1133
- bool lt (Expression* lhs, Expression* rhs, Context& ctx)
1131
+ bool Eval:: lt (Expression* lhs, Expression* rhs, Context& ctx)
1134
1132
{
1135
1133
if (lhs->concrete_type () != Expression::NUMBER ||
1136
1134
rhs->concrete_type () != Expression::NUMBER)
@@ -1147,13 +1145,10 @@ namespace Sass {
1147
1145
return l->value () < tmp_r.value ();
1148
1146
}
1149
1147
1150
- Expression* op_numbers (Context& ctx, Binary_Expression* b, Expression* lhs, Expression* rhs )
1148
+ Expression* Eval:: op_numbers (Context& ctx, enum Sass_OP op, Number* l, Number* r )
1151
1149
{
1152
- Number* l = static_cast <Number*>(lhs);
1153
- Number* r = static_cast <Number*>(rhs);
1154
1150
double lv = l->value ();
1155
1151
double rv = r->value ();
1156
- enum Sass_OP op = b->type ();
1157
1152
if (op == Sass_OP::DIV && !rv) {
1158
1153
return new (ctx.mem ) String_Quoted (l->pstate (), " Infinity" );
1159
1154
}
@@ -1170,7 +1165,7 @@ namespace Sass {
1170
1165
error (" Incompatible units: '" +r_unit+" ' and '" +l_unit+" '." , l->pstate ());
1171
1166
}
1172
1167
Number* v = new (ctx.mem ) Number (*l);
1173
- v->pstate (b ->pstate ());
1168
+ v->pstate (l ->pstate ());
1174
1169
if (l_unit.empty () && (op == Sass_OP::ADD || op == Sass_OP::SUB || op == Sass_OP::MOD)) {
1175
1170
v->numerator_units () = r->numerator_units ();
1176
1171
v->denominator_units () = r->denominator_units ();
@@ -1200,10 +1195,8 @@ namespace Sass {
1200
1195
return v;
1201
1196
}
1202
1197
1203
- Expression* op_number_color (Context& ctx, enum Sass_OP op, Expression* lhs, Expression* rhs )
1198
+ Expression* Eval:: op_number_color (Context& ctx, enum Sass_OP op, Number* l, Color* r )
1204
1199
{
1205
- Number* l = static_cast <Number*>(lhs);
1206
- Color* r = static_cast <Color*>(rhs);
1207
1200
// TODO: currently SASS converts colors to standard form when adding to strings;
1208
1201
// when https://github.com/nex3/sass/issues/363 is added this can be removed to
1209
1202
// preserve the original value
@@ -1239,10 +1232,8 @@ namespace Sass {
1239
1232
return l;
1240
1233
}
1241
1234
1242
- Expression* op_color_number (Context& ctx, enum Sass_OP op, Expression* lhs, Expression* rhs )
1235
+ Expression* Eval:: op_color_number (Context& ctx, enum Sass_OP op, Color* l, Number* r )
1243
1236
{
1244
- Color* l = static_cast <Color*>(lhs);
1245
- Number* r = static_cast <Number*>(rhs);
1246
1237
double rv = r->value ();
1247
1238
if (op == Sass_OP::DIV && !rv) error (" division by zero" , r->pstate ());
1248
1239
return new (ctx.mem ) Color (l->pstate (),
@@ -1252,10 +1243,8 @@ namespace Sass {
1252
1243
l->a ());
1253
1244
}
1254
1245
1255
- Expression* op_colors (Context& ctx, enum Sass_OP op, Expression* lhs, Expression* rhs )
1246
+ Expression* Eval:: op_colors (Context& ctx, enum Sass_OP op, Color* l, Color* r )
1256
1247
{
1257
- Color* l = static_cast <Color*>(lhs);
1258
- Color* r = static_cast <Color*>(rhs);
1259
1248
if (l->a () != r->a ()) {
1260
1249
error (" alpha channels must be equal when combining colors" , r->pstate ());
1261
1250
}
@@ -1270,7 +1259,7 @@ namespace Sass {
1270
1259
l->a ());
1271
1260
}
1272
1261
1273
- Expression* op_strings (Context& ctx, enum Sass_OP op, Expression* lhs, Expression*rhs)
1262
+ Expression* Eval:: op_strings (Context& ctx, enum Sass_OP op, Expression* lhs, Expression*rhs)
1274
1263
{
1275
1264
To_String to_string (&ctx);
1276
1265
Expression::Concrete_Type ltype = lhs->concrete_type ();
@@ -1285,19 +1274,29 @@ namespace Sass {
1285
1274
bool r_str_color = rtype == Expression::STRING && ctx.names_to_colors .count (rstr) && !r_str_quoted;
1286
1275
1287
1276
if (l_str_color && r_str_color) {
1288
- return op_colors (ctx, op, ctx.names_to_colors [lstr], ctx.names_to_colors [rstr]);
1277
+ Color* l_c = ctx.names_to_colors [lstr];
1278
+ Color* r_c = ctx.names_to_colors [rstr];
1279
+ return op_colors (ctx, op, l_c, r_c);
1289
1280
}
1290
1281
else if (l_str_color && rtype == Expression::COLOR) {
1291
- return op_colors (ctx, op, ctx.names_to_colors [lstr], rhs);
1292
- }
1293
- else if (l_str_color && rtype == Expression::NUMBER) {
1294
- return op_color_number (ctx, op, ctx.names_to_colors [lstr], rhs);
1282
+ Color* l_c = ctx.names_to_colors [lstr];
1283
+ Color* r_c = dynamic_cast <Color*>(rhs);
1284
+ return op_colors (ctx, op, l_c, r_c);
1295
1285
}
1296
1286
else if (ltype == Expression::COLOR && r_str_color) {
1297
- return op_number_color (ctx, op, lhs, ctx.names_to_colors [rstr]);
1287
+ Color* l_c = dynamic_cast <Color*>(lhs);
1288
+ Color* r_c = ctx.names_to_colors [rstr];
1289
+ return op_colors (ctx, op, l_c, r_c);
1290
+ }
1291
+ else if (l_str_color && rtype == Expression::NUMBER) {
1292
+ Color* l_c = ctx.names_to_colors [lstr];
1293
+ Number* r_n = dynamic_cast <Number*>(rhs);
1294
+ return op_color_number (ctx, op, l_c, r_n);
1298
1295
}
1299
1296
else if (ltype == Expression::NUMBER && r_str_color) {
1300
- return op_number_color (ctx, op, lhs, ctx.names_to_colors [rstr]);
1297
+ Number* l_n = dynamic_cast <Number*>(lhs);
1298
+ Color* r_c = ctx.names_to_colors [rstr];
1299
+ return op_number_color (ctx, op, l_n, r_c);
1301
1300
}
1302
1301
if (op == Sass_OP::MUL) error (" invalid operands for multiplication" , lhs->pstate ());
1303
1302
if (op == Sass_OP::MOD) error (" invalid operands for modulo" , lhs->pstate ());
0 commit comments