Skip to content

Commit 633ac21

Browse files
committed
Change operators to use to_string from Value base
1 parent 74c7514 commit 633ac21

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

debugger.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
462462
} else if (dynamic_cast<Binary_Expression*>(node)) {
463463
Binary_Expression* expression = dynamic_cast<Binary_Expression*>(node);
464464
cerr << ind << "Binary_Expression " << expression;
465+
cerr << " [delayed: " << expression->is_delayed() << "] ";
465466
cerr << " (" << pstate_source_position(node) << ")";
466467
cerr << " [" << expression->type_name() << "]" << endl;
467468
debug_ast(expression->left(), ind + " left: ", env);
@@ -587,6 +588,7 @@ inline void debug_node(Node* node, string ind = "")
587588
case Complex_Selector::ADJACENT_TO: cerr << "{+} "; break;
588589
case Complex_Selector::PARENT_OF: cerr << "{>} "; break;
589590
case Complex_Selector::PRECEDES: cerr << "{~} "; break;
591+
case Complex_Selector::REFERENCE: cerr << "{@} "; break;
590592
case Complex_Selector::ANCESTOR_OF: cerr << "{ } "; break;
591593
}
592594
cerr << endl;

environment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ namespace Sass {
168168
for (typename map<string, T>::iterator i = local_frame_.begin(); i != local_frame_.end(); ++i) {
169169
if (!ends_with(i->first, "[f]") && !ends_with(i->first, "[f]4") && !ends_with(i->first, "[f]2")) {
170170
cerr << prefix << string(indent, ' ') << i->first << " " << i->second;
171-
// if (Value* val = dynamic_cast<Value*>(i->second))
172-
// { cerr << " : " << val->to_string(true, 5); }
171+
if (Value* val = dynamic_cast<Value*>(i->second))
172+
{ cerr << " : " << val->to_string(true, 5); }
173173
cerr << endl;
174174
}
175175
}

eval.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ namespace Sass {
11671167
return l->value() < tmp_r.value();
11681168
}
11691169

1170-
Value* Eval::op_numbers(Context& ctx, enum Sass_OP op, Number* l, Number* r)
1170+
Value* Eval::op_numbers(Context& ctx, enum Sass_OP op, Number* l, Number* r, bool compressed, int precision)
11711171
{
11721172
double lv = l->value();
11731173
double rv = r->value();
@@ -1217,7 +1217,7 @@ namespace Sass {
12171217
return v;
12181218
}
12191219

1220-
Value* Eval::op_number_color(Context& ctx, enum Sass_OP op, Number* l, Color* r)
1220+
Value* Eval::op_number_color(Context& ctx, enum Sass_OP op, Number* l, Color* r, bool compressed, int precision)
12211221
{
12221222
// TODO: currently SASS converts colors to standard form when adding to strings;
12231223
// when https://github.com/nex3/sass/issues/363 is added this can be removed to
@@ -1236,14 +1236,11 @@ namespace Sass {
12361236
case Sass_OP::SUB:
12371237
case Sass_OP::DIV: {
12381238
string sep(op == Sass_OP::SUB ? "-" : "/");
1239-
To_String to_string(&ctx);
1240-
string color(r->sixtuplet() && (ctx.output_style != COMPRESSED) ?
1241-
r->perform(&to_string) :
1242-
Util::normalize_sixtuplet(r->perform(&to_string)));
1239+
string color(r->to_string(compressed||!r->sixtuplet(), precision));
12431240
return new (ctx.mem) String_Quoted(l->pstate(),
1244-
l->perform(&to_string)
1245-
+ sep
1246-
+ color);
1241+
l->to_string(compressed, precision)
1242+
+ sep
1243+
+ color);
12471244
} break;
12481245
case Sass_OP::MOD: {
12491246
error("cannot divide a number by a color", r->pstate());
@@ -1254,7 +1251,7 @@ namespace Sass {
12541251
return l;
12551252
}
12561253

1257-
Value* Eval::op_color_number(Context& ctx, enum Sass_OP op, Color* l, Number* r)
1254+
Value* Eval::op_color_number(Context& ctx, enum Sass_OP op, Color* l, Number* r, bool compressed, int precision)
12581255
{
12591256
double rv = r->value();
12601257
if (op == Sass_OP::DIV && !rv) error("division by zero", r->pstate());
@@ -1265,7 +1262,7 @@ namespace Sass {
12651262
l->a());
12661263
}
12671264

1268-
Value* Eval::op_colors(Context& ctx, enum Sass_OP op, Color* l, Color* r)
1265+
Value* Eval::op_colors(Context& ctx, enum Sass_OP op, Color* l, Color* r, bool compressed, int precision)
12691266
{
12701267
if (l->a() != r->a()) {
12711268
error("alpha channels must be equal when combining colors", r->pstate());
@@ -1281,14 +1278,17 @@ namespace Sass {
12811278
l->a());
12821279
}
12831280

1284-
Value* Eval::op_strings(Context& ctx, enum Sass_OP op, Value* lhs, Value*rhs)
1281+
Value* Eval::op_strings(Context& ctx, enum Sass_OP op, Value* lhs, Value*rhs, bool compressed, int precision)
12851282
{
12861283
To_String to_string(&ctx);
12871284
Expression::Concrete_Type ltype = lhs->concrete_type();
12881285
Expression::Concrete_Type rtype = rhs->concrete_type();
12891286

1290-
string lstr(lhs->perform(&to_string));
1291-
string rstr(rhs->perform(&to_string));
1287+
String_Quoted* lqstr = dynamic_cast<String_Quoted*>(lhs);
1288+
String_Quoted* rqstr = dynamic_cast<String_Quoted*>(rhs);
1289+
1290+
string lstr(lqstr ? lqstr->value() : lhs->to_string(compressed, precision));
1291+
string rstr(rqstr ? rqstr->value() : rhs->to_string(compressed, precision));
12921292

12931293
bool l_str_quoted = ((Sass::String*)lhs) && ((Sass::String*)lhs)->sass_fix_1291();
12941294
bool r_str_quoted = ((Sass::String*)rhs) && ((Sass::String*)rhs)->sass_fix_1291();

eval.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ namespace Sass {
8989
static bool eq(Expression*, Expression*);
9090
static bool lt(Expression*, Expression*);
9191
// -- arithmetic on the combinations that matter
92-
static Value* op_numbers(Context&, enum Sass_OP, Number*, Number*);
93-
static Value* op_number_color(Context&, enum Sass_OP, Number*, Color*);
94-
static Value* op_color_number(Context&, enum Sass_OP, Color*, Number*);
95-
static Value* op_colors(Context&, enum Sass_OP, Color*, Color*);
96-
static Value* op_strings(Context&, enum Sass_OP, Value*, Value*);
92+
static Value* op_numbers(Context&, enum Sass_OP, Number*, Number*, bool compressed = false, int precision = 5);
93+
static Value* op_number_color(Context&, enum Sass_OP, Number*, Color*, bool compressed = false, int precision = 5);
94+
static Value* op_color_number(Context&, enum Sass_OP, Color*, Number*, bool compressed = false, int precision = 5);
95+
static Value* op_colors(Context&, enum Sass_OP, Color*, Color*, bool compressed = false, int precision = 5);
96+
static Value* op_strings(Context&, enum Sass_OP, Value*, Value*, bool compressed = false, int precision = 5);
9797

9898
private:
9999
string interpolation(Expression* s);

0 commit comments

Comments
 (0)