Skip to content

Commit 6be3eb0

Browse files
committed
Pass pstate by reference to op functions
1 parent c00da14 commit 6be3eb0

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

src/eval.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -700,22 +700,22 @@ namespace Sass {
700700
if (l_type == Expression::NUMBER && r_type == Expression::NUMBER) {
701701
Number_Ptr l_n = Cast<Number>(lhs);
702702
Number_Ptr r_n = Cast<Number>(rhs);
703-
rv = op_numbers(op_type, *l_n, *r_n, ctx.c_options, &pstate);
703+
rv = op_numbers(op_type, *l_n, *r_n, ctx.c_options, pstate);
704704
}
705705
else if (l_type == Expression::NUMBER && r_type == Expression::COLOR) {
706706
Number_Ptr l_n = Cast<Number>(lhs);
707707
Color_Ptr r_c = Cast<Color>(rhs);
708-
rv = op_number_color(op_type, *l_n, *r_c, ctx.c_options, &pstate);
708+
rv = op_number_color(op_type, *l_n, *r_c, ctx.c_options, pstate);
709709
}
710710
else if (l_type == Expression::COLOR && r_type == Expression::NUMBER) {
711711
Color_Ptr l_c = Cast<Color>(lhs);
712712
Number_Ptr r_n = Cast<Number>(rhs);
713-
rv = op_color_number(op_type, *l_c, *r_n, ctx.c_options, &pstate);
713+
rv = op_color_number(op_type, *l_c, *r_n, ctx.c_options, pstate);
714714
}
715715
else if (l_type == Expression::COLOR && r_type == Expression::COLOR) {
716716
Color_Ptr l_c = Cast<Color>(lhs);
717717
Color_Ptr r_c = Cast<Color>(rhs);
718-
rv = op_colors(op_type, *l_c, *r_c, ctx.c_options, &pstate);
718+
rv = op_colors(op_type, *l_c, *r_c, ctx.c_options, pstate);
719719
}
720720
else {
721721
To_Value to_value(ctx);
@@ -734,7 +734,7 @@ namespace Sass {
734734
if (r_type == Expression::MAP) {
735735
throw Exception::InvalidValue(*v_r);
736736
}
737-
Value_Ptr ex = op_strings(b->op(), *v_l, *v_r, ctx.c_options, &pstate, !interpolant); // pass true to compress
737+
Value_Ptr ex = op_strings(b->op(), *v_l, *v_r, ctx.c_options, pstate, !interpolant); // pass true to compress
738738
if (String_Constant_Ptr str = Cast<String_Constant>(ex))
739739
{
740740
if (str->concrete_type() == Expression::STRING)
@@ -1380,13 +1380,13 @@ namespace Sass {
13801380
return *l < *r;
13811381
}
13821382

1383-
Value_Ptr Eval::op_numbers(enum Sass_OP op, const Number& l, const Number& r, struct Sass_Inspect_Options opt, ParserState* pstate)
1383+
Value_Ptr Eval::op_numbers(enum Sass_OP op, const Number& l, const Number& r, struct Sass_Inspect_Options opt, const ParserState& pstate)
13841384
{
13851385
double lv = l.value();
13861386
double rv = r.value();
13871387
if (op == Sass_OP::DIV && rv == 0) {
13881388
// XXX: this is never hit via spec tests
1389-
return SASS_MEMORY_NEW(String_Quoted, pstate ? *pstate : l.pstate(), lv ? "Infinity" : "NaN");
1389+
return SASS_MEMORY_NEW(String_Quoted, pstate, lv ? "Infinity" : "NaN");
13901390
}
13911391
if (op == Sass_OP::MOD && !rv) {
13921392
// XXX: this is never hit via spec tests
@@ -1399,7 +1399,7 @@ namespace Sass {
13991399
std::string l_unit(l.unit());
14001400
std::string r_unit(tmp.unit());
14011401
Number_Obj v = SASS_MEMORY_COPY(&l); // copy
1402-
v->pstate(pstate ? *pstate : l.pstate());
1402+
v->pstate(pstate);
14031403
if (l_unit.empty() && (op == Sass_OP::ADD || op == Sass_OP::SUB || op == Sass_OP::MOD)) {
14041404
v->numerator_units() = r.numerator_units();
14051405
v->denominator_units() = r.denominator_units();
@@ -1431,14 +1431,14 @@ namespace Sass {
14311431
return v.detach();
14321432
}
14331433

1434-
Value_Ptr Eval::op_number_color(enum Sass_OP op, const Number& l, const Color& r, struct Sass_Inspect_Options opt, ParserState* pstate)
1434+
Value_Ptr Eval::op_number_color(enum Sass_OP op, const Number& l, const Color& r, struct Sass_Inspect_Options opt, const ParserState& pstate)
14351435
{
14361436
double lv = l.value();
14371437
switch (op) {
14381438
case Sass_OP::ADD:
14391439
case Sass_OP::MUL: {
14401440
return SASS_MEMORY_NEW(Color,
1441-
pstate ? *pstate : l.pstate(),
1441+
pstate,
14421442
ops[op](lv, r.r()),
14431443
ops[op](lv, r.g()),
14441444
ops[op](lv, r.b()),
@@ -1449,7 +1449,7 @@ namespace Sass {
14491449
std::string sep(op == Sass_OP::SUB ? "-" : "/");
14501450
std::string color(r.to_string(opt));
14511451
return SASS_MEMORY_NEW(String_Quoted,
1452-
pstate ? *pstate : l.pstate(),
1452+
pstate,
14531453
l.to_string(opt)
14541454
+ sep
14551455
+ color);
@@ -1463,22 +1463,22 @@ namespace Sass {
14631463
return NULL;
14641464
}
14651465

1466-
Value_Ptr Eval::op_color_number(enum Sass_OP op, const Color& l, const Number& r, struct Sass_Inspect_Options opt, ParserState* pstate)
1466+
Value_Ptr Eval::op_color_number(enum Sass_OP op, const Color& l, const Number& r, struct Sass_Inspect_Options opt, const ParserState& pstate)
14671467
{
14681468
double rv = r.value();
14691469
if (op == Sass_OP::DIV && !rv) {
14701470
// comparison of Fixnum with Float failed?
14711471
throw Exception::ZeroDivisionError(l, r);
14721472
}
14731473
return SASS_MEMORY_NEW(Color,
1474-
pstate ? *pstate : l.pstate(),
1474+
pstate,
14751475
ops[op](l.r(), rv),
14761476
ops[op](l.g(), rv),
14771477
ops[op](l.b(), rv),
14781478
l.a());
14791479
}
14801480

1481-
Value_Ptr Eval::op_colors(enum Sass_OP op, const Color& l, const Color& r, struct Sass_Inspect_Options opt, ParserState* pstate)
1481+
Value_Ptr Eval::op_colors(enum Sass_OP op, const Color& l, const Color& r, struct Sass_Inspect_Options opt, const ParserState& pstate)
14821482
{
14831483
if (l.a() != r.a()) {
14841484
throw Exception::AlphaChannelsNotEqual(&l, &r, "+");
@@ -1488,14 +1488,14 @@ namespace Sass {
14881488
throw Exception::ZeroDivisionError(l, r);
14891489
}
14901490
return SASS_MEMORY_NEW(Color,
1491-
pstate ? *pstate : l.pstate(),
1491+
pstate,
14921492
ops[op](l.r(), r.r()),
14931493
ops[op](l.g(), r.g()),
14941494
ops[op](l.b(), r.b()),
14951495
l.a());
14961496
}
14971497

1498-
Value_Ptr Eval::op_strings(Sass::Operand operand, Value& lhs, Value& rhs, struct Sass_Inspect_Options opt, ParserState* pstate, bool delayed)
1498+
Value_Ptr Eval::op_strings(Sass::Operand operand, Value& lhs, Value& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
14991499
{
15001500
Expression::Concrete_Type ltype = lhs.concrete_type();
15011501
Expression::Concrete_Type rtype = rhs.concrete_type();
@@ -1529,7 +1529,7 @@ namespace Sass {
15291529
(sep != "/" || !rqstr || !rqstr->quote_mark()) */
15301530
) {
15311531
// create a new string that might be quoted on output (but do not unquote what we pass)
1532-
return SASS_MEMORY_NEW(String_Quoted, pstate ? *pstate : lhs.pstate(), lstr + rstr, 0, false, true);
1532+
return SASS_MEMORY_NEW(String_Quoted, pstate, lstr + rstr, 0, false, true);
15331533
}
15341534

15351535
if (sep != "" && !delayed) {
@@ -1542,7 +1542,7 @@ namespace Sass {
15421542
if (rqstr && rqstr->quote_mark()) rstr = quote(rstr);
15431543
}
15441544

1545-
return SASS_MEMORY_NEW(String_Constant, pstate ? *pstate : lhs.pstate(), lstr + sep + rstr);
1545+
return SASS_MEMORY_NEW(String_Constant, pstate, lstr + sep + rstr);
15461546
}
15471547

15481548
Expression_Ptr cval_to_astnode(union Sass_Value* v, Backtrace* backtrace, ParserState pstate)

src/eval.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ namespace Sass {
9090
static bool eq(Expression_Obj, Expression_Obj);
9191
static bool lt(Expression_Obj, Expression_Obj, std::string op);
9292
// -- arithmetic on the combinations that matter
93-
static Value_Ptr op_numbers(enum Sass_OP, const Number&, const Number&, struct Sass_Inspect_Options opt, ParserState* pstate = 0);
94-
static Value_Ptr op_number_color(enum Sass_OP, const Number&, const Color&, struct Sass_Inspect_Options opt, ParserState* pstate = 0);
95-
static Value_Ptr op_color_number(enum Sass_OP, const Color&, const Number&, struct Sass_Inspect_Options opt, ParserState* pstate = 0);
96-
static Value_Ptr op_colors(enum Sass_OP, const Color&, const Color&, struct Sass_Inspect_Options opt, ParserState* pstate = 0);
97-
static Value_Ptr op_strings(Sass::Operand, Value&, Value&, struct Sass_Inspect_Options opt, ParserState* pstate = 0, bool interpolant = false);
93+
static Value_Ptr op_numbers(enum Sass_OP, const Number&, const Number&, struct Sass_Inspect_Options opt, const ParserState& pstate);
94+
static Value_Ptr op_number_color(enum Sass_OP, const Number&, const Color&, struct Sass_Inspect_Options opt, const ParserState& pstate);
95+
static Value_Ptr op_color_number(enum Sass_OP, const Color&, const Number&, struct Sass_Inspect_Options opt, const ParserState& pstate);
96+
static Value_Ptr op_colors(enum Sass_OP, const Color&, const Color&, struct Sass_Inspect_Options opt, const ParserState& pstate);
97+
static Value_Ptr op_strings(Sass::Operand, Value&, Value&, struct Sass_Inspect_Options opt, const ParserState& pstate, bool interpolant = false);
9898

9999
private:
100100
void interpolation(Context& ctx, std::string& res, Expression_Obj ex, bool into_quotes, bool was_itpl = false);

src/sass_values.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,27 +313,27 @@ extern "C" {
313313
if (sass_value_is_number(a) && sass_value_is_number(b)) {
314314
Number_Ptr_Const l_n = Cast<Number>(lhs);
315315
Number_Ptr_Const r_n = Cast<Number>(rhs);
316-
rv = Eval::op_numbers(op, *l_n, *r_n, options);
316+
rv = Eval::op_numbers(op, *l_n, *r_n, options, l_n->pstate());
317317
}
318318
else if (sass_value_is_number(a) && sass_value_is_color(a)) {
319319
Number_Ptr_Const l_n = Cast<Number>(lhs);
320320
Color_Ptr_Const r_c = Cast<Color>(rhs);
321-
rv = Eval::op_number_color(op, *l_n, *r_c, options);
321+
rv = Eval::op_number_color(op, *l_n, *r_c, options, l_n->pstate());
322322
}
323323
else if (sass_value_is_color(a) && sass_value_is_number(b)) {
324324
Color_Ptr_Const l_c = Cast<Color>(lhs);
325325
Number_Ptr_Const r_n = Cast<Number>(rhs);
326-
rv = Eval::op_color_number(op, *l_c, *r_n, options);
326+
rv = Eval::op_color_number(op, *l_c, *r_n, options, l_c->pstate());
327327
}
328328
else if (sass_value_is_color(a) && sass_value_is_color(b)) {
329329
Color_Ptr_Const l_c = Cast<Color>(lhs);
330330
Color_Ptr_Const r_c = Cast<Color>(rhs);
331-
rv = Eval::op_colors(op, *l_c, *r_c, options);
331+
rv = Eval::op_colors(op, *l_c, *r_c, options, l_c->pstate());
332332
}
333333
else /* convert other stuff to string and apply operation */ {
334334
Value_Ptr l_v = Cast<Value>(lhs);
335335
Value_Ptr r_v = Cast<Value>(rhs);
336-
rv = Eval::op_strings(op, *l_v, *r_v, options);
336+
rv = Eval::op_strings(op, *l_v, *r_v, options, l_v->pstate());
337337
}
338338

339339
// ToDo: maybe we should should return null value?

0 commit comments

Comments
 (0)