Skip to content

Commit

Permalink
Fix and refactor delayed evaluation flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Apr 30, 2016
1 parent 2f6e81a commit 734668f
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 236 deletions.
38 changes: 15 additions & 23 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ namespace Sass {
ltrim();
}

void Argument::set_delayed(bool delayed)
{
if (value_) value_->set_delayed(delayed);
is_delayed(delayed);
}

void Arguments::set_delayed(bool delayed)
{
for (Argument* arg : elements()) {
if (arg) arg->set_delayed(delayed);
}
is_delayed(delayed);
}


bool At_Root_Query::exclude(std::string str)
{
bool with = feature() && unquote(feature()->to_string()).compare("with") == 0;
Expand Down Expand Up @@ -2149,29 +2164,6 @@ namespace Sass {
return is_interpolant() || (right() && right()->is_right_interpolant());
}

// delay binary expressions in function arguments
// https://github.com/sass/libsass/issues/1417
bool Binary_Expression::can_delay(void) const
{
bool l_delay = false;
bool r_delay = false;
if (op().operand == Sass_OP::DIV) {
if (Textual* tl = dynamic_cast<Textual*>(left())) {
l_delay = tl->type() == Textual::NUMBER ||
tl->type() == Textual::DIMENSION;
} else {
l_delay = dynamic_cast<Number*>(left()) != NULL;
}
if (Textual* tr = dynamic_cast<Textual*>(right())) {
r_delay = tr->type() == Textual::NUMBER ||
tr->type() == Textual::DIMENSION;
} else {
r_delay = dynamic_cast<Number*>(right()) != NULL;
}
}
return l_delay && r_delay;
}

std::string AST_Node::to_string(Sass_Inspect_Options opt) const
{
Sass_Output_Options out(opt);
Expand Down
30 changes: 17 additions & 13 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@

namespace Sass {

// easier to search with name
const bool DELAYED = true;

// ToDo: should this really be hardcoded
// Note: most methods follow precision option
const double NUMBER_EPSILON = 0.00000000000001;
Expand All @@ -67,7 +70,8 @@ namespace Sass {
bool ws_after;
};

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

//////////////////////////////////////////////////////////
// Abstract base class for all abstract syntax tree nodes.
Expand Down Expand Up @@ -905,9 +910,8 @@ namespace Sass {

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

virtual bool operator== (const Expression& rhs) const;
Expand Down Expand Up @@ -1031,12 +1035,6 @@ namespace Sass {
return is_left_interpolant() ||
is_right_interpolant();
}
virtual bool can_delay() const;
void reset_whitespace()
{
op_.ws_before = false;
op_.ws_after = false;
}
virtual void set_delayed(bool delayed)
{
right()->set_delayed(delayed);
Expand Down Expand Up @@ -1138,6 +1136,7 @@ namespace Sass {
}
}

virtual void set_delayed(bool delayed);
virtual bool operator==(const Expression& rhs) const
{
try
Expand Down Expand Up @@ -1185,6 +1184,8 @@ namespace Sass {
has_keyword_argument_(false)
{ }

virtual void set_delayed(bool delayed);

Argument* get_rest_argument();
Argument* get_keyword_argument();

Expand Down Expand Up @@ -1296,7 +1297,7 @@ namespace Sass {
size_t hash_;
public:
Textual(ParserState pstate, Type t, std::string val)
: Expression(pstate, true), type_(t), value_(val),
: Expression(pstate, DELAYED), type_(t), value_(val),
hash_(0)
{ }

Expand Down Expand Up @@ -1466,10 +1467,9 @@ namespace Sass {
// "flat" strings.
////////////////////////////////////////////////////////////////////////
class String : public Value {
ADD_PROPERTY(bool, sass_fix_1291)
public:
String(ParserState pstate, bool delayed = false, bool sass_fix_1291 = false)
: Value(pstate, delayed), sass_fix_1291_(sass_fix_1291)
String(ParserState pstate, bool delayed = false)
: Value(pstate, delayed)
{ concrete_type(STRING); }
static std::string type_name() { return "string"; }
virtual ~String() = 0;
Expand Down Expand Up @@ -1517,6 +1517,10 @@ namespace Sass {
return hash_;
}

virtual void set_delayed(bool delayed) {
is_delayed(delayed);
}

virtual bool operator==(const Expression& rhs) const;

ATTACH_OPERATIONS()
Expand Down
1 change: 0 additions & 1 deletion src/bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace Sass {
// force optional quotes (only if needed)
if (str->quote_mark()) {
str->quote_mark('*');
str->is_delayed(true);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
std::cerr << ind << "Warning " << block;
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " " << block->tabs() << std::endl;
debug_ast(block->message(), ind + " : ");
} else if (dynamic_cast<Error*>(node)) {
Error* block = dynamic_cast<Error*>(node);
std::cerr << ind << "Error " << block;
Expand Down Expand Up @@ -578,6 +579,7 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
Color* expression = dynamic_cast<Color*>(node);
std::cerr << ind << "Color " << expression;
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " [delayed: " << expression->is_delayed() << "] ";
std::cerr << " [interpolant: " << expression->is_interpolant() << "] ";
std::cerr << " [" << expression->r() << ":" << expression->g() << ":" << expression->b() << "@" << expression->a() << "]" << std::endl;
} else if (dynamic_cast<Number*>(node)) {
Expand All @@ -594,7 +596,6 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " [" << prettyprint(expression->value()) << "]";
if (expression->is_delayed()) std::cerr << " [delayed]";
if (expression->sass_fix_1291()) std::cerr << " [sass_fix_1291]";
if (expression->is_interpolant()) std::cerr << " [interpolant]";
if (expression->quote_mark()) std::cerr << " [quote_mark: " << expression->quote_mark() << "]";
std::cerr << " <" << prettyprint(expression->pstate().token.ws_before()) << ">" << std::endl;
Expand All @@ -607,7 +608,6 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " [" << prettyprint(expression->value()) << "]";
if (expression->is_delayed()) std::cerr << " [delayed]";
if (expression->sass_fix_1291()) std::cerr << " [sass_fix_1291]";
if (expression->is_interpolant()) std::cerr << " [interpolant]";
std::cerr << " <" << prettyprint(expression->pstate().token.ws_before()) << ">" << std::endl;
} else if (dynamic_cast<String_Schema*>(node)) {
Expand All @@ -626,7 +626,6 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
std::cerr << ind << "String " << expression;
std::cerr << " " << expression->concrete_type();
std::cerr << " (" << pstate_source_position(node) << ")";
if (expression->sass_fix_1291()) std::cerr << " [sass_fix_1291]";
if (expression->is_interpolant()) std::cerr << " [interpolant]";
std::cerr << " <" << prettyprint(expression->pstate().token.ws_before()) << ">" << std::endl;
} else if (dynamic_cast<Expression*>(node)) {
Expand Down
1 change: 0 additions & 1 deletion src/error_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ namespace Sass {
: Base(org.pstate()), dup(dup), org(org)
{
msg = "Duplicate key ";
dup.get_duplicate_key()->is_delayed(false);
msg += dup.get_duplicate_key()->inspect();
msg += " in map (";
msg += org.inspect();
Expand Down
Loading

0 comments on commit 734668f

Please sign in to comment.