Skip to content

Commit

Permalink
Clean up is_parsed flag #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Feb 20, 2015
1 parent d5f0b67 commit 36c3af6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 57 deletions.
18 changes: 8 additions & 10 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,16 +1429,16 @@ inline string normalize(const string& str) {
protected:
size_t hash_;
public:
String_Constant(ParserState pstate, bool wq, string val, bool unq = false, bool norm = false)
String_Constant(ParserState pstate, string val, bool unq = false, bool norm = false)
: String(pstate, unq, true), marker_(false), was_quoted_(false), quotemark_(0), value_(val), hash_(0)
{ if(norm) value_ = normalize(value_); }
String_Constant(ParserState pstate, bool wq, const char* beg, bool unq = false, bool norm = false)
String_Constant(ParserState pstate, const char* beg, bool unq = false, bool norm = false)
: String(pstate, unq, true), marker_(false), was_quoted_(false), quotemark_(0), value_(string(beg)), hash_(0)
{ if(norm) value_ = normalize(value_); }
String_Constant(ParserState pstate, bool wq, const char* beg, const char* end, bool unq = false, bool norm = false)
String_Constant(ParserState pstate, const char* beg, const char* end, bool unq = false, bool norm = false)
: String(pstate, unq, true), marker_(false), was_quoted_(false), quotemark_(0), value_(string(beg, end-beg)), hash_(0)
{ if(norm) value_ = normalize(value_); }
String_Constant(ParserState pstate, bool wq, const Token& tok, bool unq = false, bool norm = false)
String_Constant(ParserState pstate, const Token& tok, bool unq = false, bool norm = false)
: String(pstate, unq, true), marker_(false), was_quoted_(false), quotemark_(0), value_(string(tok.begin, tok.end)), hash_(0)
{ if(norm) value_ = normalize(value_); }
string type() { return "string"; }
Expand Down Expand Up @@ -1477,7 +1477,7 @@ inline string normalize(const string& str) {
class String_Quoted : public String_Constant {
public:
String_Quoted(ParserState pstate, string val, bool unq = false, bool norm = false)
: String_Constant(pstate, false, val, unq, norm)
: String_Constant(pstate, val, unq, norm)
{
char q = 0;
value_ = unquote(value_, &q);
Expand All @@ -1488,18 +1488,16 @@ inline string normalize(const string& str) {
quotemark_ = *val.begin();
}
}
} else {
// value_ = string_unescape(value_);
}
}
String_Quoted(ParserState pstate, const char* beg, bool unq = false, bool norm = false)
: String_Constant(pstate, false, beg, unq, norm)
: String_Constant(pstate, beg, unq, norm)
{ }
String_Quoted(ParserState pstate, const char* beg, const char* end, bool unq = false, bool norm = false)
: String_Constant(pstate, false, beg, end, unq, norm)
: String_Constant(pstate, beg, end, unq, norm)
{ }
String_Quoted(ParserState pstate, const Token& tok, bool unq = false, bool norm = false)
: String_Constant(pstate, false, tok, unq, norm)
: String_Constant(pstate, tok, unq, norm)
{ }
string type() { return "string"; }
static string type_name() { return "string"; }
Expand Down
4 changes: 2 additions & 2 deletions cssize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ namespace Sass {
case Statement::NONE:
default:
error("unknown internal error; please contact the LibSass maintainers", s->pstate(), backtrace);
String_Constant* msg = new (ctx.mem) String_Constant(ParserState("[WARN]"), false, string("`CSSize` can't clone ") + typeid(*s).name());
String_Constant* msg = new (ctx.mem) String_Constant(ParserState("[WARN]"), string("`CSSize` can't clone ") + typeid(*s).name());
return new (ctx.mem) Warning(ParserState("[WARN]"), msg);
}
}
Expand Down Expand Up @@ -542,7 +542,7 @@ namespace Sass {
);

if (!type.empty()) {
mm->media_type(new (ctx.mem) String_Constant(mq1->pstate(), false, type));
mm->media_type(new (ctx.mem) String_Constant(mq1->pstate(), type));
}

*mm += mq2;
Expand Down
16 changes: 7 additions & 9 deletions eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,10 @@ ll->is_inspecting(l->is_inspecting());
// Special cases: +/- variables which evaluate to null ouput just +/-,
// but +/- null itself outputs the string
if (operand->concrete_type() == Expression::NULL_VAL && typeid(*(u->operand())) == typeid(Variable)) {
u->operand(new (ctx.mem) String_Constant(u->pstate(), false, ""));
u->operand(new (ctx.mem) String_Constant(u->pstate(), ""));
}
else u->operand(operand);
String_Constant* result = new (ctx.mem) String_Constant(u->pstate(), false,
u->perform(&to_string));
String_Constant* result = new (ctx.mem) String_Constant(u->pstate(), u->perform(&to_string));
return result;
}
// unreachable
Expand Down Expand Up @@ -462,8 +461,7 @@ ll->is_inspecting(l->is_inspecting());
args);
To_String to_string(&ctx);
to_string.in_decl_list = true;
return new (ctx.mem) String_Constant(c->pstate(), false,
lit->perform(&to_string));
return new (ctx.mem) String_Constant(c->pstate(), lit->perform(&to_string));
}

Expression* result = c;
Expand Down Expand Up @@ -524,7 +522,7 @@ ll->is_inspecting(l->is_inspecting());
else if (c_func) {

if (full_name == "*[f]") {
String_Constant *str = new (ctx.mem) String_Constant(c->pstate(), false, c->name());
String_Constant *str = new (ctx.mem) String_Constant(c->pstate(), c->name());
Arguments* new_args = new (ctx.mem) Arguments(c->pstate());
*new_args << new (ctx.mem) Argument(c->pstate(), str);
*new_args += args;
Expand Down Expand Up @@ -1049,7 +1047,7 @@ ll->is_inspecting(l->is_inspecting());
double rv = r->value();
Binary_Expression::Type op = b->type();
if (op == Binary_Expression::DIV && !rv) {
return new (ctx.mem) String_Constant(l->pstate(), false, "Infinity");
return new (ctx.mem) String_Constant(l->pstate(), "Infinity");
}
if (op == Binary_Expression::MOD && !rv) {
error("division by zero", r->pstate());
Expand Down Expand Up @@ -1116,7 +1114,7 @@ ll->is_inspecting(l->is_inspecting());
string color(r->sixtuplet() && (ctx.output_style == NESTED || ctx.output_style == EXPANDED) ?
r->perform(&to_string) :
Util::normalize_sixtuplet(r->perform(&to_string)));
return new (ctx.mem) String_Constant(l->pstate(), false,
return new (ctx.mem) String_Constant(l->pstate(),
l->perform(&to_string)
+ sep
+ color);
Expand Down Expand Up @@ -1228,7 +1226,7 @@ ll->is_inspecting(l->is_inspecting());
e = new (ctx.mem) Color(pstate, sass_color_get_r(v), sass_color_get_g(v), sass_color_get_b(v), sass_color_get_a(v));
} break;
case SASS_STRING: {
e = new (ctx.mem) String_Constant(pstate, false, sass_string_get_value(v));
e = new (ctx.mem) String_Constant(pstate, sass_string_get_value(v));
} break;
case SASS_LIST: {
List* l = new (ctx.mem) List(pstate, sass_list_get_length(v), sass_list_get_separator(v) == SASS_COMMA ? List::COMMA : List::SPACE);
Expand Down
6 changes: 3 additions & 3 deletions expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace Sass {
Keyframe_Rule* k = new (ctx.mem) Keyframe_Rule(r->pstate(), r->block()->perform(this)->block());
if (r->selector()) {
string s(r->selector()->perform(eval->with(env, backtrace))->perform(&to_string));
String_Constant* ss = new (ctx.mem) String_Constant(r->selector()->pstate(), false, s);
String_Constant* ss = new (ctx.mem) String_Constant(r->selector()->pstate(), s);
k->rules(ss);
}
in_at_root = old_in_at_root;
Expand Down Expand Up @@ -122,7 +122,7 @@ namespace Sass {
String_Schema* combined_prop = new (ctx.mem) String_Schema(p->pstate());
if (!property_stack.empty()) {
*combined_prop << property_stack.back()
<< new (ctx.mem) String_Constant(p->pstate(), false, "-")
<< new (ctx.mem) String_Constant(p->pstate(), "-")
<< dec->property(); // TODO: eval the prop into a string constant
}
else {
Expand Down Expand Up @@ -486,7 +486,7 @@ namespace Sass {
inline Statement* Expand::fallback_impl(AST_Node* n)
{
error("unknown internal error; please contact the LibSass maintainers", n->pstate(), backtrace);
String_Constant* msg = new (ctx.mem) String_Constant(ParserState("[WARN]"), false, string("`Expand` doesn't handle ") + typeid(*n).name());
String_Constant* msg = new (ctx.mem) String_Constant(ParserState("[WARN]"), string("`Expand` doesn't handle ") + typeid(*n).name());
return new (ctx.mem) Warning(ParserState("[WARN]"), msg);
}

Expand Down
44 changes: 22 additions & 22 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ namespace Sass {
Number* amount = dynamic_cast<Number*>(env["$amount"]);
if (!amount) {
To_String to_string(&ctx);
return new (ctx.mem) String_Constant(pstate, false, "saturate(" + env["$color"]->perform(&to_string) + ")");
return new (ctx.mem) String_Constant(pstate, "saturate(" + env["$color"]->perform(&to_string) + ")");
}

ARGR("$amount", Number, 0, 100);
Expand Down Expand Up @@ -461,7 +461,7 @@ namespace Sass {
Number* amount = dynamic_cast<Number*>(env["$color"]);
if (amount) {
To_String to_string(&ctx);
return new (ctx.mem) String_Constant(pstate, false, "grayscale(" + amount->perform(&to_string) + ")");
return new (ctx.mem) String_Constant(pstate, "grayscale(" + amount->perform(&to_string) + ")");
}

Color* rgb_color = ARG("$color", Color);
Expand Down Expand Up @@ -498,7 +498,7 @@ namespace Sass {
Number* amount = dynamic_cast<Number*>(env["$color"]);
if (amount) {
To_String to_string(&ctx);
return new (ctx.mem) String_Constant(pstate, false, "invert(" + amount->perform(&to_string) + ")");
return new (ctx.mem) String_Constant(pstate, "invert(" + amount->perform(&to_string) + ")");
}

Color* rgb_color = ARG("$color", Color);
Expand All @@ -518,14 +518,14 @@ namespace Sass {
{
String_Constant* ie_kwd = dynamic_cast<String_Constant*>(env["$color"]);
if (ie_kwd) {
return new (ctx.mem) String_Constant(pstate, false, "alpha(" + ie_kwd->value() + ")");
return new (ctx.mem) String_Constant(pstate, "alpha(" + ie_kwd->value() + ")");
}

// CSS3 filter function overload: pass literal through directly
Number* amount = dynamic_cast<Number*>(env["$color"]);
if (amount) {
To_String to_string(&ctx);
return new (ctx.mem) String_Constant(pstate, false, "opacity(" + amount->perform(&to_string) + ")");
return new (ctx.mem) String_Constant(pstate, "opacity(" + amount->perform(&to_string) + ")");
}

return new (ctx.mem) Number(pstate, ARG("$color", Color)->a());
Expand Down Expand Up @@ -735,7 +735,7 @@ namespace Sass {
result[i] = std::toupper(result[i]);
}

return new (ctx.mem) String_Constant(pstate, false, result);
return new (ctx.mem) String_Constant(pstate, result);

}

Expand All @@ -753,14 +753,14 @@ namespace Sass {
String_Constant* result = 0;
String_Quoted* string_quoted = dynamic_cast<String_Quoted*>(arg);
if (string_quoted) {
// result = new (ctx.mem) String_Constant(734, pstate, false, string_quoted->value());
result = new (ctx.mem) String_Constant(pstate, false, str);
// result = new (ctx.mem) String_Constant(pstate, string_quoted->value());
result = new (ctx.mem) String_Constant(pstate, str);
result->marker(string_quoted->was_quoted());
} else if (/* String_Constant* string_constant = */ dynamic_cast<String_Constant*>(arg)) {
result = new (ctx.mem) String_Constant(pstate, false, str);
result = new (ctx.mem) String_Constant(pstate, str);
result->was_quoted(false);
} else {
result = new (ctx.mem) String_Constant(pstate, false, str);
result = new (ctx.mem) String_Constant(pstate, str);
result->was_quoted(false);
}

Expand All @@ -773,7 +773,7 @@ namespace Sass {
To_String to_string(&ctx);
AST_Node* arg = env["$string"];
string str(quote(arg->perform(&to_string), String_Constant::auto_quote()));
String_Constant* result = new (ctx.mem) String_Constant(pstate, false, str);
String_Constant* result = new (ctx.mem) String_Constant(pstate, str);
result->is_delayed(true);
return result;
}
Expand Down Expand Up @@ -860,7 +860,7 @@ namespace Sass {
error(msg, pstate, backtrace);
}
catch (...) { throw; }
return new (ctx.mem) String_Constant(pstate, false, str);
return new (ctx.mem) String_Constant(pstate, str);
}

Signature str_index_sig = "str-index($string, $substring)";
Expand Down Expand Up @@ -955,7 +955,7 @@ namespace Sass {
}
catch (...) { throw; }

return new (ctx.mem) String_Constant(pstate, true, newstr);
return new (ctx.mem) String_Constant(pstate, newstr);

}

Expand All @@ -972,7 +972,7 @@ namespace Sass {
}

str = s->was_quoted() ? quote(str, '"') : str;
return new (ctx.mem) String_Constant(pstate, true, str);
return new (ctx.mem) String_Constant(pstate, str);
}

Signature to_lower_case_sig = "to-lower-case($string)";
Expand All @@ -988,7 +988,7 @@ namespace Sass {
}

str = s->was_quoted() ? quote(str, '"') : str;
return new (ctx.mem) String_Constant(pstate, true, str);
return new (ctx.mem) String_Constant(pstate, str);
}

///////////////////
Expand Down Expand Up @@ -1282,7 +1282,7 @@ namespace Sass {
l = new (ctx.mem) List(pstate, 1);
*l << ARG("$list", Expression);
}
return new (ctx.mem) String_Constant(pstate, false,
return new (ctx.mem) String_Constant(pstate,
l->separator() == List::COMMA ? "comma" : "space");
}

Expand Down Expand Up @@ -1374,7 +1374,7 @@ namespace Sass {
for (size_t i = 0, L = arglist->length(); i < L; ++i) {
string name = string(((Argument*)(*arglist)[i])->name());
string sanitized_name = string(name, 1);
*result << make_pair(new (ctx.mem) String_Constant(pstate, false, sanitized_name),
*result << make_pair(new (ctx.mem) String_Constant(pstate, sanitized_name),
((Argument*)(*arglist)[i])->value());
}
return result;
Expand All @@ -1392,10 +1392,10 @@ namespace Sass {
To_String to_string(&ctx);
string str(v->perform(&to_string));
if (ctx.names_to_colors.count(str)) {
return new (ctx.mem) String_Constant(pstate, false, "color");
return new (ctx.mem) String_Constant(pstate, "color");
}
}
return new (ctx.mem) String_Constant(pstate, false, ARG("$value", Expression)->type());
return new (ctx.mem) String_Constant(pstate, ARG("$value", Expression)->type());
}

Signature unit_sig = "unit($number)";
Expand Down Expand Up @@ -1544,9 +1544,9 @@ namespace Sass {
{
Expression* v = ARG("$value", Expression);
if (v->concrete_type() == Expression::NULL_VAL) {
return new (ctx.mem) String_Constant(pstate, false, "null");
return new (ctx.mem) String_Constant(pstate, "null");
} else if (v->concrete_type() == Expression::BOOLEAN && *v == 0) {
return new (ctx.mem) String_Constant(pstate, false, "false");
return new (ctx.mem) String_Constant(pstate, "false");
}
v->is_inspecting(true);
v->is_inspected(true);
Expand All @@ -1560,7 +1560,7 @@ namespace Sass {
uniform_real_distribution<> distributor(0, 4294967296); // 16^8
uint_fast32_t distributed = distributor(rand);
ss << "u" << setfill('0') << setw(8) << std::hex << distributed;
return new (ctx.mem) String_Constant(pstate, false, ss.str());
return new (ctx.mem) String_Constant(pstate, ss.str());
}

}
Expand Down
Loading

0 comments on commit 36c3af6

Please sign in to comment.