Skip to content

Commit 811c559

Browse files
committed
Trace String_Quoted/Constant lifecycle
Check results of dynamic casting between String_Quoted and String_Constant
1 parent 7c38282 commit 811c559

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

ast.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#endif
3232

33+
#include "debug.hpp"
3334
#include "util.hpp"
3435
#include "units.hpp"
3536
#include "context.hpp"
@@ -1367,16 +1368,16 @@ namespace Sass {
13671368
public:
13681369
String_Constant(ParserState pstate, string val)
13691370
: String(pstate), quote_mark_(0), can_compress_whitespace_(false), value_(read_css_string(val)), hash_(0)
1370-
{ }
1371+
{ TRACEINST(this) << "String_Constant created " << this; }
13711372
String_Constant(ParserState pstate, const char* beg)
13721373
: String(pstate), quote_mark_(0), can_compress_whitespace_(false), value_(read_css_string(string(beg))), hash_(0)
1373-
{ }
1374+
{ TRACEINST(this) << "String_Constant created " << this; }
13741375
String_Constant(ParserState pstate, const char* beg, const char* end)
13751376
: String(pstate), quote_mark_(0), can_compress_whitespace_(false), value_(read_css_string(string(beg, end-beg))), hash_(0)
1376-
{ }
1377+
{ TRACEINST(this) << "String_Constant created " << this; }
13771378
String_Constant(ParserState pstate, const Token& tok)
13781379
: String(pstate), quote_mark_(0), can_compress_whitespace_(false), value_(read_css_string(string(tok.begin, tok.end))), hash_(0)
1379-
{ }
1380+
{ TRACEINST(this) << "String_Constant created " << this; }
13801381
string type() { return "string"; }
13811382
static string type_name() { return "string"; }
13821383

@@ -1404,6 +1405,16 @@ namespace Sass {
14041405
static char double_quote() { return '"'; }
14051406
static char single_quote() { return '\''; }
14061407

1408+
friend std::ostream& operator << (std::ostream& os, String_Constant& sq) {
1409+
os << "(" << (sq.quote_mark_ ? sq.quote_mark_ : '0') << ",\"" << sq.value_ << "\")";
1410+
return os;
1411+
}
1412+
1413+
friend std::ostream& operator << (std::ostream& os, String_Constant* sq) {
1414+
os << "(" << (sq->quote_mark_ ? sq->quote_mark_ : '0') << ",\"" << sq->value_ << "\")";
1415+
return os;
1416+
}
1417+
14071418
ATTACH_OPERATIONS();
14081419
};
14091420

@@ -1416,6 +1427,7 @@ namespace Sass {
14161427
: String_Constant(pstate, val)
14171428
{
14181429
value_ = unquote(value_, &quote_mark_);
1430+
TRACEINST(this) << "String_Quoted created " << this;
14191431
}
14201432
ATTACH_OPERATIONS();
14211433
};

eval.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,11 +734,14 @@ namespace Sass {
734734
}
735735
else if (value->concrete_type() == Expression::STRING) {
736736
if (auto str = dynamic_cast<String_Quoted*>(value)) {
737+
TRACEINST(str) << "dynamic_cast to String_Quoted worked " << str;
737738
value = new (ctx.mem) String_Quoted(*str);
738739
} else if (auto str = dynamic_cast<String_Constant*>(value)) {
739740
if (str->quote_mark()) {
741+
TRACEINST(str) << "dynamic_cast to String_Quoted did not work, but we have quote " << str;
740742
value = new (ctx.mem) String_Quoted(str->pstate(), str->perform(&to_string));
741743
} else {
744+
TRACEINST(str) << "dynamic_cast to String_Quoted did not work, we are String_Constant " << str;
742745
value = new (ctx.mem) String_Constant(str->pstate(), unquote(str->value()));
743746
}
744747
}
@@ -856,18 +859,26 @@ namespace Sass {
856859

857860
string Eval::interpolation(Expression* s) {
858861
if (String_Quoted* str_quoted = dynamic_cast<String_Quoted*>(s)) {
862+
TRACEINST(str_quoted) << "dynamic_cast to String_Quoted worked " << str_quoted;
859863
if (str_quoted->quote_mark()) {
860864
if (str_quoted->quote_mark() == '*' || str_quoted->is_delayed()) {
865+
TRACEINST(str_quoted) << "... will do interpolation()";
861866
return interpolation(new (ctx.mem) String_Constant(*str_quoted));
862867
} else {
868+
TRACEINST(str_quoted) << "... will string_escape()";
863869
return string_escape(quote(str_quoted->value(), str_quoted->quote_mark()));
864870
}
865871
} else {
872+
TRACEINST(str_quoted) << "dynamic_cast to String_Quoted failed, will evacuate_escapes()";
866873
return evacuate_escapes(str_quoted->value());
867874
}
868875
} else if (String_Constant* str_constant = dynamic_cast<String_Constant*>(s)) {
876+
TRACEINST(str_constant) << "dynamic_cast to String_Constant worked";
869877
string str = str_constant->value();
870-
if (!str_constant->quote_mark()) str = unquote(str);
878+
if (!str_constant->quote_mark()) {
879+
TRACEINST(str_constant) << "... but still need to unquote()";
880+
str = unquote(str);
881+
}
871882
return evacuate_escapes(str);
872883
} else if (String_Schema* str_schema = dynamic_cast<String_Schema*>(s)) {
873884
string res = "";
@@ -1011,14 +1022,22 @@ namespace Sass {
10111022
Expression* feature = e->feature();
10121023
feature = (feature ? feature->perform(this) : 0);
10131024
if (feature && dynamic_cast<String_Quoted*>(feature)) {
1025+
String_Quoted *qfeature = dynamic_cast<String_Quoted*>(feature);
1026+
TRACEINST(qfeature) << "dynamic_cast to String_Quoted worked " << qfeature;
10141027
feature = new (ctx.mem) String_Constant(feature->pstate(),
10151028
dynamic_cast<String_Quoted*>(feature)->value());
1029+
} else {
1030+
TRACEINST(feature) << "dynamic_cast to String_Quoted did not work for " << feature;
10161031
}
10171032
Expression* value = e->value();
10181033
value = (value ? value->perform(this) : 0);
10191034
if (value && dynamic_cast<String_Quoted*>(value)) {
1035+
String_Quoted *qvalue = dynamic_cast<String_Quoted*>(value);
1036+
TRACEINST(qvalue) << "dynamic_cast to String_Quoted worked " << qvalue;
10201037
value = new (ctx.mem) String_Constant(value->pstate(),
10211038
dynamic_cast<String_Quoted*>(value)->value());
1039+
} else {
1040+
TRACEINST(value) << "dynamic_cast to String_Quoted did not work for " << value;
10221041
}
10231042
return new (ctx.mem) Media_Query_Expression(e->pstate(),
10241043
feature,

output.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,27 +372,35 @@ namespace Sass {
372372

373373
void Output::operator()(String_Quoted* s)
374374
{
375+
TRACEINST(s) << "This should be a quoted string... " << s;
375376
if (s->quote_mark()) {
377+
TRACEINST(s) << "... it even has a quote mark property, sending with quote marks";
376378
append_token(quote(s->value(), s->quote_mark()), s);
377379
} else if (!in_comment) {
380+
TRACEINST(s) << "... no quote mark(?), sending via string_to_output";
378381
append_token(string_to_output(s->value()), s);
379382
} else {
383+
TRACEINST(s) << "... no quote mark(?), sending directly (in comment)";
380384
append_token(s->value(), s);
381385
}
382386
}
383387

384388
void Output::operator()(String_Constant* s)
385389
{
390+
TRACEINST(s) << "This should be a constant string... " << s;
386391
if (String_Quoted* quoted = dynamic_cast<String_Quoted*>(s)) {
392+
TRACEINST(s) << "... but dynamic_cast<String_Quoted*> worked";
387393
return Output::operator()(quoted);
388394
} else {
389395
string value(s->value());
390396
if (s->can_compress_whitespace() && output_style() == COMPRESSED) {
391397
value.erase(std::remove_if(value.begin(), value.end(), ::isspace), value.end());
392398
}
393399
if (!in_comment) {
400+
TRACEINST(s) << "... sending via string_to_output";
394401
append_token(string_to_output(value), s);
395402
} else {
403+
TRACEINST(s) << "... sending directly (in comment)";
396404
append_token(value, s);
397405
}
398406
}

parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ namespace Sass {
13811381

13821382
if (lex< identifier >()) {
13831383
String_Constant* str = new (ctx.mem) String_Quoted(pstate, lexed);
1384+
TRACEINST(str) << "We have just created a new instance " << str;
13841385
// Dont' delay this string if it is a name color. Fixes #652.
13851386
str->is_delayed(ctx.names_to_colors.count(unquote(lexed)) == 0);
13861387
return str;

to_c.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ namespace Sass {
1919
{ return sass_make_color(c->r(), c->g(), c->b(), c->a()); }
2020

2121
Sass_Value* To_C::operator()(String_Constant* s)
22-
{ return sass_make_string(s->value().c_str()); }
22+
{ TRACEINST(s) << "Converting unquoted value to C" << s;
23+
return sass_make_string(s->value().c_str()); }
2324

2425
Sass_Value* To_C::operator()(List* l)
2526
{

0 commit comments

Comments
 (0)