Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and refactor delayed evaluation flag #2059

Merged
merged 2 commits into from
Apr 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 18 additions & 14 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 @@ -391,7 +396,7 @@ namespace Sass {
ADD_PROPERTY(bool, group_end)
public:
Statement(ParserState pstate, Statement_Type st = NONE, size_t t = 0)
: AST_Node(pstate), statement_type_(st), tabs_(t), group_end_(false)
: AST_Node(pstate), block_(0), statement_type_(st), tabs_(t), group_end_(false)
{ }
virtual ~Statement() = 0;
// needed for rearranging nested rulesets during CSS emission
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
12 changes: 11 additions & 1 deletion src/cssize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,20 @@ namespace Sass {
{
p_stack.push_back(r);
s_stack.push_back(dynamic_cast<Selector_List*>(r->selector()));
// this can return a string schema
// string schema is not a statement!
// r->block() is already a string schema
// and that is comming from propset expand
Statement* stmt = r->block()->perform(this);
// this should protect us (at least a bit) from our mess
// fixing this properly is harder that it should be ...
if (dynamic_cast<Statement*>((AST_Node*)stmt) == NULL) {
error("Illegal nesting: Only properties may be nested beneath properties.", r->block()->pstate());
}
Ruleset* rr = SASS_MEMORY_NEW(ctx.mem, Ruleset,
r->pstate(),
r->selector(),
r->block()->perform(this)->block());
stmt->block());
rr->is_root(r->is_root());
// rr->tabs(r->block()->tabs());
s_stack.pop_back();
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