Skip to content

Commit c95478c

Browse files
committed
Merge pull request #2059 from mgreter/refactor/delayed-values
Fix and refactor delayed evaluation flag
2 parents 2f6e81a + 2c75e9b commit c95478c

File tree

14 files changed

+142
-243
lines changed

14 files changed

+142
-243
lines changed

src/ast.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ namespace Sass {
7474
ltrim();
7575
}
7676

77+
void Argument::set_delayed(bool delayed)
78+
{
79+
if (value_) value_->set_delayed(delayed);
80+
is_delayed(delayed);
81+
}
82+
83+
void Arguments::set_delayed(bool delayed)
84+
{
85+
for (Argument* arg : elements()) {
86+
if (arg) arg->set_delayed(delayed);
87+
}
88+
is_delayed(delayed);
89+
}
90+
91+
7792
bool At_Root_Query::exclude(std::string str)
7893
{
7994
bool with = feature() && unquote(feature()->to_string()).compare("with") == 0;
@@ -2149,29 +2164,6 @@ namespace Sass {
21492164
return is_interpolant() || (right() && right()->is_right_interpolant());
21502165
}
21512166

2152-
// delay binary expressions in function arguments
2153-
// https://github.com/sass/libsass/issues/1417
2154-
bool Binary_Expression::can_delay(void) const
2155-
{
2156-
bool l_delay = false;
2157-
bool r_delay = false;
2158-
if (op().operand == Sass_OP::DIV) {
2159-
if (Textual* tl = dynamic_cast<Textual*>(left())) {
2160-
l_delay = tl->type() == Textual::NUMBER ||
2161-
tl->type() == Textual::DIMENSION;
2162-
} else {
2163-
l_delay = dynamic_cast<Number*>(left()) != NULL;
2164-
}
2165-
if (Textual* tr = dynamic_cast<Textual*>(right())) {
2166-
r_delay = tr->type() == Textual::NUMBER ||
2167-
tr->type() == Textual::DIMENSION;
2168-
} else {
2169-
r_delay = dynamic_cast<Number*>(right()) != NULL;
2170-
}
2171-
}
2172-
return l_delay && r_delay;
2173-
}
2174-
21752167
std::string AST_Node::to_string(Sass_Inspect_Options opt) const
21762168
{
21772169
Sass_Output_Options out(opt);

src/ast.hpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050

5151
namespace Sass {
5252

53+
// easier to search with name
54+
const bool DELAYED = true;
55+
5356
// ToDo: should this really be hardcoded
5457
// Note: most methods follow precision option
5558
const double NUMBER_EPSILON = 0.00000000000001;
@@ -67,7 +70,8 @@ namespace Sass {
6770
bool ws_after;
6871
};
6972

70-
// from boost (functional/hash):
73+
//////////////////////////////////////////////////////////
74+
// `hash_combine` comes from boost (functional/hash):
7175
// http://www.boost.org/doc/libs/1_35_0/doc/html/hash/combine.html
7276
// Boost Software License - Version 1.0
7377
// http://www.boost.org/users/license.html
@@ -77,6 +81,7 @@ namespace Sass {
7781
seed ^= std::hash<T>()(val) + 0x9e3779b9
7882
+ (seed<<6) + (seed>>2);
7983
}
84+
//////////////////////////////////////////////////////////
8085

8186
//////////////////////////////////////////////////////////
8287
// Abstract base class for all abstract syntax tree nodes.
@@ -391,7 +396,7 @@ namespace Sass {
391396
ADD_PROPERTY(bool, group_end)
392397
public:
393398
Statement(ParserState pstate, Statement_Type st = NONE, size_t t = 0)
394-
: AST_Node(pstate), statement_type_(st), tabs_(t), group_end_(false)
399+
: AST_Node(pstate), block_(0), statement_type_(st), tabs_(t), group_end_(false)
395400
{ }
396401
virtual ~Statement() = 0;
397402
// needed for rearranging nested rulesets during CSS emission
@@ -905,9 +910,8 @@ namespace Sass {
905910

906911
virtual void set_delayed(bool delayed)
907912
{
908-
for (size_t i = 0, L = length(); i < L; ++i)
909-
(elements()[i])->set_delayed(delayed);
910913
is_delayed(delayed);
914+
// don't set children
911915
}
912916

913917
virtual bool operator== (const Expression& rhs) const;
@@ -1031,12 +1035,6 @@ namespace Sass {
10311035
return is_left_interpolant() ||
10321036
is_right_interpolant();
10331037
}
1034-
virtual bool can_delay() const;
1035-
void reset_whitespace()
1036-
{
1037-
op_.ws_before = false;
1038-
op_.ws_after = false;
1039-
}
10401038
virtual void set_delayed(bool delayed)
10411039
{
10421040
right()->set_delayed(delayed);
@@ -1138,6 +1136,7 @@ namespace Sass {
11381136
}
11391137
}
11401138

1139+
virtual void set_delayed(bool delayed);
11411140
virtual bool operator==(const Expression& rhs) const
11421141
{
11431142
try
@@ -1185,6 +1184,8 @@ namespace Sass {
11851184
has_keyword_argument_(false)
11861185
{ }
11871186

1187+
virtual void set_delayed(bool delayed);
1188+
11881189
Argument* get_rest_argument();
11891190
Argument* get_keyword_argument();
11901191

@@ -1296,7 +1297,7 @@ namespace Sass {
12961297
size_t hash_;
12971298
public:
12981299
Textual(ParserState pstate, Type t, std::string val)
1299-
: Expression(pstate, true), type_(t), value_(val),
1300+
: Expression(pstate, DELAYED), type_(t), value_(val),
13001301
hash_(0)
13011302
{ }
13021303

@@ -1466,10 +1467,9 @@ namespace Sass {
14661467
// "flat" strings.
14671468
////////////////////////////////////////////////////////////////////////
14681469
class String : public Value {
1469-
ADD_PROPERTY(bool, sass_fix_1291)
14701470
public:
1471-
String(ParserState pstate, bool delayed = false, bool sass_fix_1291 = false)
1472-
: Value(pstate, delayed), sass_fix_1291_(sass_fix_1291)
1471+
String(ParserState pstate, bool delayed = false)
1472+
: Value(pstate, delayed)
14731473
{ concrete_type(STRING); }
14741474
static std::string type_name() { return "string"; }
14751475
virtual ~String() = 0;
@@ -1517,6 +1517,10 @@ namespace Sass {
15171517
return hash_;
15181518
}
15191519

1520+
virtual void set_delayed(bool delayed) {
1521+
is_delayed(delayed);
1522+
}
1523+
15201524
virtual bool operator==(const Expression& rhs) const;
15211525

15221526
ATTACH_OPERATIONS()

src/bind.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ namespace Sass {
2121
// force optional quotes (only if needed)
2222
if (str->quote_mark()) {
2323
str->quote_mark('*');
24-
str->is_delayed(true);
2524
}
2625
}
2726
}

src/cssize.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,20 @@ namespace Sass {
102102
{
103103
p_stack.push_back(r);
104104
s_stack.push_back(dynamic_cast<Selector_List*>(r->selector()));
105+
// this can return a string schema
106+
// string schema is not a statement!
107+
// r->block() is already a string schema
108+
// and that is comming from propset expand
109+
Statement* stmt = r->block()->perform(this);
110+
// this should protect us (at least a bit) from our mess
111+
// fixing this properly is harder that it should be ...
112+
if (dynamic_cast<Statement*>((AST_Node*)stmt) == NULL) {
113+
error("Illegal nesting: Only properties may be nested beneath properties.", r->block()->pstate());
114+
}
105115
Ruleset* rr = SASS_MEMORY_NEW(ctx.mem, Ruleset,
106116
r->pstate(),
107117
r->selector(),
108-
r->block()->perform(this)->block());
118+
stmt->block());
109119
rr->is_root(r->is_root());
110120
// rr->tabs(r->block()->tabs());
111121
s_stack.pop_back();

src/debugger.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
311311
std::cerr << ind << "Warning " << block;
312312
std::cerr << " (" << pstate_source_position(node) << ")";
313313
std::cerr << " " << block->tabs() << std::endl;
314+
debug_ast(block->message(), ind + " : ");
314315
} else if (dynamic_cast<Error*>(node)) {
315316
Error* block = dynamic_cast<Error*>(node);
316317
std::cerr << ind << "Error " << block;
@@ -578,6 +579,7 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
578579
Color* expression = dynamic_cast<Color*>(node);
579580
std::cerr << ind << "Color " << expression;
580581
std::cerr << " (" << pstate_source_position(node) << ")";
582+
std::cerr << " [delayed: " << expression->is_delayed() << "] ";
581583
std::cerr << " [interpolant: " << expression->is_interpolant() << "] ";
582584
std::cerr << " [" << expression->r() << ":" << expression->g() << ":" << expression->b() << "@" << expression->a() << "]" << std::endl;
583585
} else if (dynamic_cast<Number*>(node)) {
@@ -594,7 +596,6 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
594596
std::cerr << " (" << pstate_source_position(node) << ")";
595597
std::cerr << " [" << prettyprint(expression->value()) << "]";
596598
if (expression->is_delayed()) std::cerr << " [delayed]";
597-
if (expression->sass_fix_1291()) std::cerr << " [sass_fix_1291]";
598599
if (expression->is_interpolant()) std::cerr << " [interpolant]";
599600
if (expression->quote_mark()) std::cerr << " [quote_mark: " << expression->quote_mark() << "]";
600601
std::cerr << " <" << prettyprint(expression->pstate().token.ws_before()) << ">" << std::endl;
@@ -607,7 +608,6 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
607608
std::cerr << " (" << pstate_source_position(node) << ")";
608609
std::cerr << " [" << prettyprint(expression->value()) << "]";
609610
if (expression->is_delayed()) std::cerr << " [delayed]";
610-
if (expression->sass_fix_1291()) std::cerr << " [sass_fix_1291]";
611611
if (expression->is_interpolant()) std::cerr << " [interpolant]";
612612
std::cerr << " <" << prettyprint(expression->pstate().token.ws_before()) << ">" << std::endl;
613613
} else if (dynamic_cast<String_Schema*>(node)) {
@@ -626,7 +626,6 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
626626
std::cerr << ind << "String " << expression;
627627
std::cerr << " " << expression->concrete_type();
628628
std::cerr << " (" << pstate_source_position(node) << ")";
629-
if (expression->sass_fix_1291()) std::cerr << " [sass_fix_1291]";
630629
if (expression->is_interpolant()) std::cerr << " [interpolant]";
631630
std::cerr << " <" << prettyprint(expression->pstate().token.ws_before()) << ">" << std::endl;
632631
} else if (dynamic_cast<Expression*>(node)) {

src/error_handling.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ namespace Sass {
7474
: Base(org.pstate()), dup(dup), org(org)
7575
{
7676
msg = "Duplicate key ";
77-
dup.get_duplicate_key()->is_delayed(false);
7877
msg += dup.get_duplicate_key()->inspect();
7978
msg += " in map (";
8079
msg += org.inspect();

0 commit comments

Comments
 (0)