Skip to content

Commit 1c0cddf

Browse files
committed
Remove Separator from C++ and use enum from C-API
1 parent 4a5249c commit 1c0cddf

File tree

12 files changed

+41
-43
lines changed

12 files changed

+41
-43
lines changed

ast.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,14 +758,12 @@ namespace Sass {
758758
///////////////////////////////////////////////////////////////////////
759759
class List : public Expression, public Vectorized<Expression*> {
760760
void adjust_after_pushing(Expression* e) { is_expanded(false); }
761-
public:
762-
enum Separator { SPACE, COMMA };
763761
private:
764-
ADD_PROPERTY(Separator, separator)
762+
ADD_PROPERTY(enum Sass_Separator, separator)
765763
ADD_PROPERTY(bool, is_arglist)
766764
public:
767765
List(ParserState pstate,
768-
size_t size = 0, Separator sep = SPACE, bool argl = false)
766+
size_t size = 0, enum Sass_Separator sep = SASS_SPACE, bool argl = false)
769767
: Expression(pstate),
770768
Vectorized<Expression*>(size),
771769
separator_(sep), is_arglist_(argl)
@@ -783,7 +781,7 @@ namespace Sass {
783781
{
784782
if (hash_ > 0) return hash_;
785783

786-
hash_ = std::hash<string>()(separator() == COMMA ? "comma" : "space");
784+
hash_ = std::hash<string>()(separator() == SASS_COMMA ? "comma" : "space");
787785
for (size_t i = 0, L = length(); i < L; ++i)
788786
hash_combine(hash_, (elements()[i])->hash());
789787

ast_factory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Sass {
3737
Definition<FUNCTION>* new_Function_Definition(string p, size_t l, string n, Parameters* params, Block* b);
3838
Mixin_Call* new_Mixin_Call(string p, size_t l, string n, Arguments* args, Block* b = 0);
3939
// expressions
40-
List* new_List(string p, size_t l, size_t size = 0, List::Separator sep = List::space, bool argl = false);
40+
List* new_List(string p, size_t l, size_t size = 0, enum Sass_Separator sep = List::space, bool argl = false);
4141
Map* new_Map(string p, size_t l, size_t size = 0);
4242
Binary_Expression<AND>* new_And(string p, size_t l, Expression* lhs, Expression* rhs);
4343
Binary_Expression<OR>* new_Or(string p, size_t l, Expression* lhs, Expression* rhs);

bind.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace Sass {
9898
} else if (a->is_keyword_argument()) {
9999

100100
// expand keyword arguments into their parameters
101-
List* arglist = new (ctx.mem) List(p->pstate(), 0, List::COMMA, true);
101+
List* arglist = new (ctx.mem) List(p->pstate(), 0, SASS_COMMA, true);
102102
env->local_frame()[p->name()] = arglist;
103103
Map* argmap = static_cast<Map*>(a->value());
104104
for (auto key : argmap->keys()) {
@@ -115,7 +115,7 @@ namespace Sass {
115115
// create a new list object for wrapped items
116116
List* arglist = new (ctx.mem) List(p->pstate(),
117117
0,
118-
List::COMMA,
118+
SASS_COMMA,
119119
true);
120120
// consume the next args
121121
while (ia < LA) {
@@ -238,7 +238,7 @@ namespace Sass {
238238
if (leftover->is_rest_parameter()) {
239239
env->local_frame()[leftover->name()] = new (ctx.mem) List(leftover->pstate(),
240240
0,
241-
List::COMMA,
241+
SASS_COMMA,
242242
true);
243243
}
244244
else if (leftover->default_value()) {

cssize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ namespace Sass {
480480
{
481481
List* qq = new (ctx.mem) List(m1->media_queries()->pstate(),
482482
m1->media_queries()->length(),
483-
List::COMMA);
483+
SASS_COMMA);
484484

485485
for (size_t i = 0, L = m1->media_queries()->length(); i < L; i++) {
486486
for (size_t j = 0, K = m2->media_queries()->length(); j < K; j++) {

debugger.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
480480
cerr << ind << "List " << expression;
481481
cerr << " (" << pstate_source_position(node) << ")";
482482
cerr << " (" << expression->length() << ") " <<
483-
(expression->separator() == Sass::List::Separator::COMMA ? "Comma " : "Space ") <<
483+
(expression->separator() == SASS_COMMA ? "Comma " : "Space ") <<
484484
" [delayed: " << expression->is_delayed() << "] " <<
485485
" [interpolant: " << expression->is_interpolant() << "] " <<
486486
" [arglist: " << expression->is_arglist() << "] " <<

eval.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ namespace Sass {
223223
map = static_cast<Map*>(expr);
224224
}
225225
else if (expr->concrete_type() != Expression::LIST) {
226-
list = new (ctx.mem) List(expr->pstate(), 1, List::COMMA);
226+
list = new (ctx.mem) List(expr->pstate(), 1, SASS_COMMA);
227227
*list << expr;
228228
}
229229
else {
@@ -243,7 +243,7 @@ namespace Sass {
243243
Expression* value = map->at(key);
244244

245245
if (variables.size() == 1) {
246-
List* variable = new (ctx.mem) List(map->pstate(), 2, List::SPACE);
246+
List* variable = new (ctx.mem) List(map->pstate(), 2, SASS_SPACE);
247247
*variable << key;
248248
*variable << value;
249249
env->set_local(variables[0], variable);
@@ -260,7 +260,7 @@ namespace Sass {
260260
for (size_t i = 0, L = list->length(); i < L; ++i) {
261261
List* variable = 0;
262262
if ((*list)[i]->concrete_type() != Expression::LIST || variables.size() == 1) {
263-
variable = new (ctx.mem) List((*list)[i]->pstate(), 1, List::COMMA);
263+
variable = new (ctx.mem) List((*list)[i]->pstate(), 1, SASS_COMMA);
264264
*variable << (*list)[i];
265265
}
266266
else {
@@ -867,7 +867,7 @@ namespace Sass {
867867
}
868868
} else if (List* list = dynamic_cast<List*>(s)) {
869869
string acc = ""; // ToDo: different output styles
870-
string sep = list->separator() == List::Separator::COMMA ? "," : " ";
870+
string sep = list->separator() == SASS_COMMA ? "," : " ";
871871
if (ctx.output_style != COMPRESSED && sep == ",") sep += " ";
872872
bool initial = false;
873873
for(auto item : list->elements()) {
@@ -1032,7 +1032,7 @@ namespace Sass {
10321032
else if(val->concrete_type() != Expression::LIST) {
10331033
List* wrapper = new (ctx.mem) List(val->pstate(),
10341034
0,
1035-
List::COMMA,
1035+
SASS_COMMA,
10361036
true);
10371037
*wrapper << val;
10381038
val = wrapper;
@@ -1338,7 +1338,7 @@ namespace Sass {
13381338
}
13391339
} break;
13401340
case SASS_LIST: {
1341-
List* l = new (ctx.mem) List(pstate, sass_list_get_length(v), sass_list_get_separator(v) == SASS_COMMA ? List::COMMA : List::SPACE);
1341+
List* l = new (ctx.mem) List(pstate, sass_list_get_length(v), sass_list_get_separator(v));
13421342
for (size_t i = 0, L = sass_list_get_length(v); i < L; ++i) {
13431343
*l << cval_to_astnode(sass_list_get_value(v, i), ctx, backtrace, pstate);
13441344
}

expand.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ namespace Sass {
398398
map = static_cast<Map*>(expr);
399399
}
400400
else if (expr->concrete_type() != Expression::LIST) {
401-
list = new (ctx.mem) List(expr->pstate(), 1, List::COMMA);
401+
list = new (ctx.mem) List(expr->pstate(), 1, SASS_COMMA);
402402
*list << expr;
403403
}
404404
else {
@@ -419,7 +419,7 @@ namespace Sass {
419419
Expression* v = map->at(key)->perform(&eval);
420420

421421
if (variables.size() == 1) {
422-
List* variable = new (ctx.mem) List(map->pstate(), 2, List::SPACE);
422+
List* variable = new (ctx.mem) List(map->pstate(), 2, SASS_SPACE);
423423
*variable << k;
424424
*variable << v;
425425
env->set_local(variables[0], variable);
@@ -434,7 +434,7 @@ namespace Sass {
434434
for (size_t i = 0, L = list->length(); i < L; ++i) {
435435
List* variable = 0;
436436
if ((*list)[i]->concrete_type() != Expression::LIST || variables.size() == 1) {
437-
variable = new (ctx.mem) List((*list)[i]->pstate(), 1, List::COMMA);
437+
variable = new (ctx.mem) List((*list)[i]->pstate(), 1, SASS_COMMA);
438438
*variable << (*list)[i];
439439
}
440440
else {

functions.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,20 +1213,20 @@ namespace Sass {
12131213
List* l1 = dynamic_cast<List*>(env["$list1"]);
12141214
List* l2 = dynamic_cast<List*>(env["$list2"]);
12151215
String_Constant* sep = ARG("$separator", String_Constant);
1216-
List::Separator sep_val = (l1 ? l1->separator() : List::SPACE);
1216+
enum Sass_Separator sep_val = (l1 ? l1->separator() : SASS_SPACE);
12171217
if (!l1) {
12181218
l1 = new (ctx.mem) List(pstate, 1);
12191219
*l1 << ARG("$list1", Expression);
1220-
sep_val = (l2 ? l2->separator() : List::SPACE);
1220+
sep_val = (l2 ? l2->separator() : SASS_SPACE);
12211221
}
12221222
if (!l2) {
12231223
l2 = new (ctx.mem) List(pstate, 1);
12241224
*l2 << ARG("$list2", Expression);
12251225
}
12261226
size_t len = l1->length() + l2->length();
12271227
string sep_str = unquote(sep->value());
1228-
if (sep_str == "space") sep_val = List::SPACE;
1229-
else if (sep_str == "comma") sep_val = List::COMMA;
1228+
if (sep_str == "space") sep_val = SASS_SPACE;
1229+
else if (sep_str == "comma") sep_val = SASS_COMMA;
12301230
else if (sep_str != "auto") error("argument `$separator` of `" + string(sig) + "` must be `space`, `comma`, or `auto`", pstate);
12311231
List* result = new (ctx.mem) List(pstate, len, sep_val);
12321232
*result += l1;
@@ -1246,8 +1246,8 @@ namespace Sass {
12461246
}
12471247
List* result = new (ctx.mem) List(pstate, l->length() + 1, l->separator());
12481248
string sep_str(unquote(sep->value()));
1249-
if (sep_str == "space") result->separator(List::SPACE);
1250-
else if (sep_str == "comma") result->separator(List::COMMA);
1249+
if (sep_str == "space") result->separator(SASS_SPACE);
1250+
else if (sep_str == "comma") result->separator(SASS_COMMA);
12511251
else if (sep_str != "auto") error("argument `$separator` of `" + string(sig) + "` must be `space`, `comma`, or `auto`", pstate);
12521252
*result += l;
12531253
bool is_arglist = l->is_arglist();
@@ -1283,7 +1283,7 @@ namespace Sass {
12831283
}
12841284
shortest = (i ? std::min(shortest, ith->length()) : ith->length());
12851285
}
1286-
List* zippers = new (ctx.mem) List(pstate, shortest, List::COMMA);
1286+
List* zippers = new (ctx.mem) List(pstate, shortest, SASS_COMMA);
12871287
size_t L = arglist->length();
12881288
for (size_t i = 0; i < shortest; ++i) {
12891289
List* zipper = new (ctx.mem) List(pstate, L);
@@ -1304,7 +1304,7 @@ namespace Sass {
13041304
*l << ARG("$list", Expression);
13051305
}
13061306
return new (ctx.mem) String_Quoted(pstate,
1307-
l->separator() == List::COMMA ? "comma" : "space");
1307+
l->separator() == SASS_COMMA ? "comma" : "space");
13081308
}
13091309

13101310
/////////////////
@@ -1336,7 +1336,7 @@ namespace Sass {
13361336
BUILT_IN(map_keys)
13371337
{
13381338
Map* m = ARGM("$map", Map, ctx);
1339-
List* result = new (ctx.mem) List(pstate, m->length(), List::COMMA);
1339+
List* result = new (ctx.mem) List(pstate, m->length(), SASS_COMMA);
13401340
for ( auto key : m->keys()) {
13411341
*result << key;
13421342
}
@@ -1347,7 +1347,7 @@ namespace Sass {
13471347
BUILT_IN(map_values)
13481348
{
13491349
Map* m = ARGM("$map", Map, ctx);
1350-
List* result = new (ctx.mem) List(pstate, m->length(), List::COMMA);
1350+
List* result = new (ctx.mem) List(pstate, m->length(), SASS_COMMA);
13511351
for ( auto key : m->keys()) {
13521352
*result << m->at(key);
13531353
}
@@ -1746,7 +1746,7 @@ namespace Sass {
17461746
Compound_Selector* sel = ARGSEL("$selector", Compound_Selector, p_contextualize);
17471747

17481748
To_String to_string;
1749-
List* l = new (ctx.mem) List(sel->pstate(), sel->length(), List::COMMA);
1749+
List* l = new (ctx.mem) List(sel->pstate(), sel->length(), SASS_COMMA);
17501750

17511751
for (size_t i = 0, L = sel->length(); i < L; ++i) {
17521752
Simple_Selector* ss = (*sel)[i];

inspect.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ namespace Sass {
362362

363363
void Inspect::operator()(List* list)
364364
{
365-
string sep(list->separator() == List::SPACE ? " " : ",");
365+
string sep(list->separator() == SASS_SPACE ? " " : ",");
366366
if (output_style() != COMPRESSED && sep == ",") sep += " ";
367367
else if (in_media_block && sep != " ") sep += " "; // verified
368368
if (list->empty()) return;
@@ -371,14 +371,14 @@ namespace Sass {
371371
bool was_space_array = in_space_array;
372372
bool was_comma_array = in_comma_array;
373373
if (!in_declaration && (
374-
(list->separator() == List::SPACE && in_space_array) ||
375-
(list->separator() == List::COMMA && in_comma_array)
374+
(list->separator() == SASS_SPACE && in_space_array) ||
375+
(list->separator() == SASS_COMMA && in_comma_array)
376376
)) {
377377
append_string("(");
378378
}
379379

380-
if (list->separator() == List::SPACE) in_space_array = true;
381-
else if (list->separator() == List::COMMA) in_comma_array = true;
380+
if (list->separator() == SASS_SPACE) in_space_array = true;
381+
else if (list->separator() == SASS_COMMA) in_comma_array = true;
382382

383383
for (size_t i = 0, L = list->size(); i < L; ++i) {
384384
Expression* list_item = (*list)[i];
@@ -397,8 +397,8 @@ namespace Sass {
397397
in_comma_array = was_comma_array;
398398
in_space_array = was_space_array;
399399
if (!in_declaration && (
400-
(list->separator() == List::SPACE && in_space_array) ||
401-
(list->separator() == List::COMMA && in_comma_array)
400+
(list->separator() == SASS_SPACE && in_space_array) ||
401+
(list->separator() == SASS_COMMA && in_comma_array)
402402
)) {
403403
append_string(")");
404404
}

listize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Sass {
1515

1616
Expression* Listize::operator()(Selector_List* sel)
1717
{
18-
List* l = new (ctx.mem) List(sel->pstate(), sel->length(), List::COMMA);
18+
List* l = new (ctx.mem) List(sel->pstate(), sel->length(), SASS_COMMA);
1919
for (size_t i = 0, L = sel->length(); i < L; ++i) {
2020
if (!(*sel)[i]) continue;
2121
*l << (*sel)[i]->perform(this);

0 commit comments

Comments
 (0)