@@ -512,31 +512,33 @@ namespace Sass {
512
512
Expression::Concrete_Type l_type = lhs->concrete_type ();
513
513
Expression::Concrete_Type r_type = rhs->concrete_type ();
514
514
515
+ int precision = ctx.precision ;
516
+ bool compressed = ctx.output_style == COMPRESSED;
515
517
if (l_type == Expression::NUMBER && r_type == Expression::NUMBER) {
516
- Number* l_n = dynamic_cast <Number*>(lhs);
517
- Number* r_n = dynamic_cast <Number*>(rhs);
518
- return op_numbers (ctx, op_type, l_n, r_n);
518
+ const Number* l_n = dynamic_cast <const Number*>(lhs);
519
+ const Number* r_n = dynamic_cast <const Number*>(rhs);
520
+ return op_numbers (ctx. mem , op_type, * l_n, * r_n, compressed, precision );
519
521
}
520
522
if (l_type == Expression::NUMBER && r_type == Expression::COLOR) {
521
- Number* l_n = dynamic_cast <Number*>(lhs);
522
- Color* r_c = dynamic_cast <Color*>(rhs);
523
- return op_number_color (ctx, op_type, l_n, r_c);
523
+ const Number* l_n = dynamic_cast <const Number*>(lhs);
524
+ const Color* r_c = dynamic_cast <const Color*>(rhs);
525
+ return op_number_color (ctx. mem , op_type, * l_n, * r_c, compressed, precision );
524
526
}
525
527
if (l_type == Expression::COLOR && r_type == Expression::NUMBER) {
526
- Color* l_c = dynamic_cast <Color*>(lhs);
527
- Number* r_n = dynamic_cast <Number*>(rhs);
528
- return op_color_number (ctx, op_type, l_c, r_n);
528
+ const Color* l_c = dynamic_cast <const Color*>(lhs);
529
+ const Number* r_n = dynamic_cast <const Number*>(rhs);
530
+ return op_color_number (ctx. mem , op_type, * l_c, * r_n, compressed, precision );
529
531
}
530
532
if (l_type == Expression::COLOR && r_type == Expression::COLOR) {
531
- Color* l_c = dynamic_cast <Color*>(lhs);
532
- Color* r_c = dynamic_cast <Color*>(rhs);
533
- return op_colors (ctx, op_type, l_c, r_c);
533
+ const Color* l_c = dynamic_cast <const Color*>(lhs);
534
+ const Color* r_c = dynamic_cast <const Color*>(rhs);
535
+ return op_colors (ctx. mem , op_type, * l_c, * r_c, compressed, precision );
534
536
}
535
537
536
538
To_Value to_value (ctx, ctx.mem );
537
539
Value* v_l = dynamic_cast <Value*>(lhs->perform (&to_value));
538
540
Value* v_r = dynamic_cast <Value*>(rhs->perform (&to_value));
539
- Value* ex = op_strings (ctx, op_type, v_l, v_r);
541
+ Value* ex = op_strings (ctx. mem , op_type, * v_l, * v_r, compressed, precision );
540
542
if (String_Constant* str = dynamic_cast <String_Constant*>(ex))
541
543
{
542
544
if (str->concrete_type () != Expression::STRING) return ex;
@@ -1102,48 +1104,48 @@ namespace Sass {
1102
1104
return *l < *r;
1103
1105
}
1104
1106
1105
- Value* Eval::op_numbers (Context& ctx , enum Sass_OP op, Number* l, Number* r, bool compressed, int precision)
1107
+ Value* Eval::op_numbers (Memory_Manager<AST_Node>& mem , enum Sass_OP op, const Number& l, const Number& r, bool compressed, int precision)
1106
1108
{
1107
- double lv = l-> value ();
1108
- double rv = r-> value ();
1109
+ double lv = l. value ();
1110
+ double rv = r. value ();
1109
1111
if (op == Sass_OP::DIV && !rv) {
1110
- return new (ctx. mem ) String_Quoted (l-> pstate (), " Infinity" );
1112
+ return new (mem) String_Quoted (l. pstate (), " Infinity" );
1111
1113
}
1112
1114
if (op == Sass_OP::MOD && !rv) {
1113
- error (" division by zero" , r-> pstate ());
1115
+ error (" division by zero" , r. pstate ());
1114
1116
}
1115
1117
1116
- Number tmp (* r);
1117
- tmp.normalize (l-> find_convertible_unit ());
1118
- string l_unit (l-> unit ());
1118
+ Number tmp (r);
1119
+ tmp.normalize (l. find_convertible_unit ());
1120
+ string l_unit (l. unit ());
1119
1121
string r_unit (tmp.unit ());
1120
1122
if (l_unit != r_unit && !l_unit.empty () && !r_unit.empty () &&
1121
1123
(op == Sass_OP::ADD || op == Sass_OP::SUB)) {
1122
- error (" Incompatible units: '" +r_unit+" ' and '" +l_unit+" '." , l-> pstate ());
1124
+ error (" Incompatible units: '" +r_unit+" ' and '" +l_unit+" '." , l. pstate ());
1123
1125
}
1124
- Number* v = new (ctx. mem ) Number (* l);
1125
- v->pstate (l-> pstate ());
1126
+ Number* v = new (mem) Number (l);
1127
+ v->pstate (l. pstate ());
1126
1128
if (l_unit.empty () && (op == Sass_OP::ADD || op == Sass_OP::SUB || op == Sass_OP::MOD)) {
1127
- v->numerator_units () = r-> numerator_units ();
1128
- v->denominator_units () = r-> denominator_units ();
1129
+ v->numerator_units () = r. numerator_units ();
1130
+ v->denominator_units () = r. denominator_units ();
1129
1131
}
1130
1132
1131
1133
if (op == Sass_OP::MUL) {
1132
1134
v->value (ops[op](lv, rv));
1133
- for (size_t i = 0 , S = r-> numerator_units ().size (); i < S; ++i) {
1134
- v->numerator_units ().push_back (r-> numerator_units ()[i]);
1135
+ for (size_t i = 0 , S = r. numerator_units ().size (); i < S; ++i) {
1136
+ v->numerator_units ().push_back (r. numerator_units ()[i]);
1135
1137
}
1136
- for (size_t i = 0 , S = r-> denominator_units ().size (); i < S; ++i) {
1137
- v->denominator_units ().push_back (r-> denominator_units ()[i]);
1138
+ for (size_t i = 0 , S = r. denominator_units ().size (); i < S; ++i) {
1139
+ v->denominator_units ().push_back (r. denominator_units ()[i]);
1138
1140
}
1139
1141
}
1140
1142
else if (op == Sass_OP::DIV) {
1141
1143
v->value (ops[op](lv, rv));
1142
- for (size_t i = 0 , S = r-> numerator_units ().size (); i < S; ++i) {
1143
- v->denominator_units ().push_back (r-> numerator_units ()[i]);
1144
+ for (size_t i = 0 , S = r. numerator_units ().size (); i < S; ++i) {
1145
+ v->denominator_units ().push_back (r. numerator_units ()[i]);
1144
1146
}
1145
- for (size_t i = 0 , S = r-> denominator_units ().size (); i < S; ++i) {
1146
- v->numerator_units ().push_back (r-> denominator_units ()[i]);
1147
+ for (size_t i = 0 , S = r. denominator_units ().size (); i < S; ++i) {
1148
+ v->numerator_units ().push_back (r. denominator_units ()[i]);
1147
1149
}
1148
1150
} else {
1149
1151
v->value (ops[op](lv, tmp.value ()));
@@ -1152,121 +1154,117 @@ namespace Sass {
1152
1154
return v;
1153
1155
}
1154
1156
1155
- Value* Eval::op_number_color (Context& ctx , enum Sass_OP op, Number* l, Color* r , bool compressed, int precision)
1157
+ Value* Eval::op_number_color (Memory_Manager<AST_Node>& mem , enum Sass_OP op, const Number& l, const Color& rh , bool compressed, int precision)
1156
1158
{
1157
- // TODO: currently SASS converts colors to standard form when adding to strings;
1158
- // when https://github.com/nex3/sass/issues/363 is added this can be removed to
1159
- // preserve the original value
1160
- r->disp (" " );
1161
- double lv = l->value ();
1159
+ Color r (rh);
1160
+ r.disp (" " );
1161
+ double lv = l.value ();
1162
1162
switch (op) {
1163
1163
case Sass_OP::ADD:
1164
1164
case Sass_OP::MUL: {
1165
- return new (ctx. mem ) Color (l-> pstate (),
1166
- ops[op](lv, r-> r ()),
1167
- ops[op](lv, r-> g ()),
1168
- ops[op](lv, r-> b ()),
1169
- r-> a ());
1165
+ return new (mem) Color (l. pstate (),
1166
+ ops[op](lv, r. r ()),
1167
+ ops[op](lv, r. g ()),
1168
+ ops[op](lv, r. b ()),
1169
+ r. a ());
1170
1170
} break ;
1171
1171
case Sass_OP::SUB:
1172
1172
case Sass_OP::DIV: {
1173
1173
string sep (op == Sass_OP::SUB ? " -" : " /" );
1174
- string color (r-> to_string (compressed||!r-> sixtuplet (), precision));
1175
- return new (ctx. mem ) String_Quoted (l-> pstate (),
1176
- l-> to_string (compressed, precision)
1177
- + sep
1178
- + color);
1174
+ string color (r. to_string (compressed||!r. sixtuplet (), precision));
1175
+ return new (mem) String_Quoted (l. pstate (),
1176
+ l. to_string (compressed, precision)
1177
+ + sep
1178
+ + color);
1179
1179
} break ;
1180
1180
case Sass_OP::MOD: {
1181
- error (" cannot divide a number by a color" , r-> pstate ());
1181
+ error (" cannot divide a number by a color" , r. pstate ());
1182
1182
} break ;
1183
1183
default : break ; // caller should ensure that we don't get here
1184
1184
}
1185
1185
// unreachable
1186
- return l ;
1186
+ return new (mem) Color (rh) ;
1187
1187
}
1188
1188
1189
- Value* Eval::op_color_number (Context& ctx , enum Sass_OP op, Color* l, Number* r, bool compressed, int precision)
1189
+ Value* Eval::op_color_number (Memory_Manager<AST_Node>& mem , enum Sass_OP op, const Color& l, const Number& r, bool compressed, int precision)
1190
1190
{
1191
- double rv = r-> value ();
1192
- if (op == Sass_OP::DIV && !rv) error (" division by zero" , r-> pstate ());
1193
- return new (ctx. mem ) Color (l-> pstate (),
1194
- ops[op](l-> r (), rv),
1195
- ops[op](l-> g (), rv),
1196
- ops[op](l-> b (), rv),
1197
- l-> a ());
1191
+ double rv = r. value ();
1192
+ if (op == Sass_OP::DIV && !rv) error (" division by zero" , r. pstate ());
1193
+ return new (mem) Color (l. pstate (),
1194
+ ops[op](l. r (), rv),
1195
+ ops[op](l. g (), rv),
1196
+ ops[op](l. b (), rv),
1197
+ l. a ());
1198
1198
}
1199
1199
1200
- Value* Eval::op_colors (Context& ctx , enum Sass_OP op, Color* l, Color* r, bool compressed, int precision)
1200
+ Value* Eval::op_colors (Memory_Manager<AST_Node>& mem , enum Sass_OP op, const Color& l, const Color& r, bool compressed, int precision)
1201
1201
{
1202
- if (l->a () != r->a ()) {
1203
- error (" alpha channels must be equal when combining colors" , r->pstate ());
1204
- }
1205
- if ((op == Sass_OP::DIV || op == Sass_OP::MOD) &&
1206
- (!r->r () || !r->g () ||!r->b ())) {
1207
- error (" division by zero" , r->pstate ());
1208
- }
1209
- return new (ctx.mem ) Color (l->pstate (),
1210
- ops[op](l->r (), r->r ()),
1211
- ops[op](l->g (), r->g ()),
1212
- ops[op](l->b (), r->b ()),
1213
- l->a ());
1202
+ if (l.a () != r.a ()) {
1203
+ error (" alpha channels must be equal when combining colors" , r.pstate ());
1204
+ }
1205
+ if (op == Sass_OP::DIV && (!r.r () || !r.g () ||!r.b ())) {
1206
+ error (" division by zero" , r.pstate ());
1207
+ }
1208
+ return new (mem) Color (l.pstate (),
1209
+ ops[op](l.r (), r.r ()),
1210
+ ops[op](l.g (), r.g ()),
1211
+ ops[op](l.b (), r.b ()),
1212
+ l.a ());
1214
1213
}
1215
1214
1216
- Value* Eval::op_strings (Context& ctx , enum Sass_OP op, Value* lhs, Value* rhs, bool compressed, int precision)
1215
+ Value* Eval::op_strings (Memory_Manager<AST_Node>& mem , enum Sass_OP op, Value& lhs, Value& rhs, bool compressed, int precision)
1217
1216
{
1218
- To_String to_string (&ctx);
1219
- Expression::Concrete_Type ltype = lhs->concrete_type ();
1220
- Expression::Concrete_Type rtype = rhs->concrete_type ();
1217
+ Expression::Concrete_Type ltype = lhs.concrete_type ();
1218
+ Expression::Concrete_Type rtype = rhs.concrete_type ();
1221
1219
1222
- String_Quoted* lqstr = dynamic_cast <String_Quoted*>(lhs);
1223
- String_Quoted* rqstr = dynamic_cast <String_Quoted*>(rhs);
1220
+ String_Quoted* lqstr = dynamic_cast <String_Quoted*>(& lhs);
1221
+ String_Quoted* rqstr = dynamic_cast <String_Quoted*>(& rhs);
1224
1222
1225
- string lstr (lqstr ? lqstr->value () : lhs-> to_string (compressed, precision));
1226
- string rstr (rqstr ? rqstr->value () : rhs-> to_string (compressed, precision));
1223
+ string lstr (lqstr ? lqstr->value () : lhs. to_string (compressed, precision));
1224
+ string rstr (rqstr ? rqstr->value () : rhs. to_string (compressed, precision));
1227
1225
1228
- bool l_str_quoted = ((Sass::String*)lhs) && ((Sass::String*)lhs)->sass_fix_1291 ();
1229
- bool r_str_quoted = ((Sass::String*)rhs) && ((Sass::String*)rhs)->sass_fix_1291 ();
1226
+ bool l_str_quoted = ((Sass::String*)& lhs) && ((Sass::String*)& lhs)->sass_fix_1291 ();
1227
+ bool r_str_quoted = ((Sass::String*)& rhs) && ((Sass::String*)& rhs)->sass_fix_1291 ();
1230
1228
bool l_str_color = ltype == Expression::STRING && names_to_colors.count (lstr) && !l_str_quoted;
1231
1229
bool r_str_color = rtype == Expression::STRING && names_to_colors.count (rstr) && !r_str_quoted;
1232
1230
1233
1231
if (l_str_color && r_str_color) {
1234
- Color* l_c = name_to_color (lstr);
1235
- Color* r_c = name_to_color (rstr);
1236
- return op_colors (ctx , op, l_c, r_c );
1232
+ const Color* c_l = name_to_color (lstr);
1233
+ const Color* c_r = name_to_color (rstr);
1234
+ return op_colors (mem , op,*c_l, *c_r, compressed, precision );
1237
1235
}
1238
1236
else if (l_str_color && rtype == Expression::COLOR) {
1239
- Color* l_c = name_to_color (lstr);
1240
- Color* r_c = dynamic_cast <Color*>(rhs);
1241
- return op_colors (ctx , op, l_c, r_c );
1237
+ const Color* c_l = name_to_color (lstr);
1238
+ const Color* c_r = dynamic_cast <const Color*>(& rhs);
1239
+ return op_colors (mem , op, *c_l, *c_r, compressed, precision );
1242
1240
}
1243
1241
else if (ltype == Expression::COLOR && r_str_color) {
1244
- Color* l_c = dynamic_cast <Color*>(lhs);
1245
- Color* r_c = name_to_color (rstr);
1246
- return op_colors (ctx , op, l_c, r_c );
1242
+ const Color* c_l = dynamic_cast <const Color*>(& lhs);
1243
+ const Color* c_r = name_to_color (rstr);
1244
+ return op_colors (mem , op, *c_l, *c_r, compressed, precision );
1247
1245
}
1248
1246
else if (l_str_color && rtype == Expression::NUMBER) {
1249
- Color* l_c = name_to_color (lstr);
1250
- Number* r_n = dynamic_cast <Number*>(rhs);
1251
- return op_color_number (ctx , op, l_c, r_n );
1247
+ const Color* c_l = name_to_color (lstr);
1248
+ const Number* n_r = dynamic_cast <const Number*>(& rhs);
1249
+ return op_color_number (mem , op, *c_l, *n_r, compressed, precision );
1252
1250
}
1253
1251
else if (ltype == Expression::NUMBER && r_str_color) {
1254
- Number* l_n = dynamic_cast <Number*>(lhs);
1255
- Color* r_c = name_to_color (rstr);
1256
- return op_number_color (ctx , op, l_n, r_c );
1252
+ const Number* n_l = dynamic_cast <const Number*>(& lhs);
1253
+ const Color* c_r = name_to_color (rstr);
1254
+ return op_number_color (mem , op, *n_l, *c_r, compressed, precision );
1257
1255
}
1258
- if (op == Sass_OP::MUL) error (" invalid operands for multiplication" , lhs-> pstate ());
1259
- if (op == Sass_OP::MOD) error (" invalid operands for modulo" , lhs-> pstate ());
1256
+ if (op == Sass_OP::MUL) error (" invalid operands for multiplication" , lhs. pstate ());
1257
+ if (op == Sass_OP::MOD) error (" invalid operands for modulo" , lhs. pstate ());
1260
1258
string sep;
1261
1259
switch (op) {
1262
1260
case Sass_OP::SUB: sep = " -" ; break ;
1263
1261
case Sass_OP::DIV: sep = " /" ; break ;
1264
1262
default : break ;
1265
1263
}
1266
- if (ltype == Expression::NULL_VAL) error (" invalid null operation: \" null plus " +quote (unquote (rstr), ' "' )+" \" ." , lhs-> pstate ());
1267
- if (rtype == Expression::NULL_VAL) error (" invalid null operation: \" " +quote (unquote (lstr), ' "' )+" plus null\" ." , lhs-> pstate ());
1264
+ if (ltype == Expression::NULL_VAL) error (" invalid null operation: \" null plus " +quote (unquote (rstr), ' "' )+" \" ." , lhs. pstate ());
1265
+ if (rtype == Expression::NULL_VAL) error (" invalid null operation: \" " +quote (unquote (lstr), ' "' )+" plus null\" ." , rhs. pstate ());
1268
1266
string result ((lstr) + sep + (rstr));
1269
- String_Quoted* str = new (ctx. mem ) String_Quoted (lhs-> pstate (), result);
1267
+ String_Quoted* str = new (mem) String_Quoted (lhs. pstate (), result);
1270
1268
str->quote_mark (0 );
1271
1269
return str;
1272
1270
}
0 commit comments