Skip to content

Commit d977f42

Browse files
committed
Preparations for directive refactoring
1 parent 57fbfb9 commit d977f42

28 files changed

+191
-145
lines changed

src/ast.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace Sass {
6060
bool Compound_Selector::has_parent_ref()
6161
{
6262
for (Simple_Selector* s : *this) {
63-
if (s->has_parent_ref()) return true;
63+
if (s && s->has_parent_ref()) return true;
6464
}
6565
return false;
6666
}
@@ -1293,7 +1293,7 @@ namespace Sass {
12931293
bool Selector_List::has_parent_ref()
12941294
{
12951295
for (Complex_Selector* s : *this) {
1296-
if (s->has_parent_ref()) return true;
1296+
if (s && s->has_parent_ref()) return true;
12971297
}
12981298
return false;
12991299
}

src/ast.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,12 @@ namespace Sass {
524524
// At-rules -- arbitrary directives beginning with "@" that may have an
525525
// optional statement block.
526526
///////////////////////////////////////////////////////////////////////
527-
class At_Rule : public Has_Block {
527+
class Directive : public Has_Block {
528528
ADD_PROPERTY(std::string, keyword)
529529
ADD_PROPERTY(Selector*, selector)
530530
ADD_PROPERTY(Expression*, value)
531531
public:
532-
At_Rule(ParserState pstate, std::string kwd, Selector* sel = 0, Block* b = 0, Expression* val = 0)
532+
Directive(ParserState pstate, std::string kwd, Selector* sel = 0, Block* b = 0, Expression* val = 0)
533533
: Has_Block(pstate, b), keyword_(kwd), selector_(sel), value_(val) // set value manually if needed
534534
{ statement_type(DIRECTIVE); }
535535
bool bubbles() { return is_keyframes() || is_media(); }
@@ -1696,13 +1696,13 @@ namespace Sass {
16961696
/////////////////////////////////////////////////
16971697
// At root expressions (for use inside @at-root).
16981698
/////////////////////////////////////////////////
1699-
class At_Root_Expression : public Expression {
1699+
class At_Root_Query : public Expression {
17001700
private:
17011701
ADD_PROPERTY(String*, feature)
17021702
ADD_PROPERTY(Expression*, value)
17031703
ADD_PROPERTY(bool, is_interpolated)
17041704
public:
1705-
At_Root_Expression(ParserState pstate, String* f = 0, Expression* v = 0, bool i = false)
1705+
At_Root_Query(ParserState pstate, String* f = 0, Expression* v = 0, bool i = false)
17061706
: Expression(pstate), feature_(f), value_(v), is_interpolated_(i)
17071707
{ }
17081708
bool exclude(std::string str)
@@ -1739,17 +1739,17 @@ namespace Sass {
17391739
// At-root.
17401740
///////////
17411741
class At_Root_Block : public Has_Block {
1742-
ADD_PROPERTY(At_Root_Expression*, expression)
1742+
ADD_PROPERTY(At_Root_Query*, expression)
17431743
public:
1744-
At_Root_Block(ParserState pstate, Block* b = 0, At_Root_Expression* e = 0)
1744+
At_Root_Block(ParserState pstate, Block* b = 0, At_Root_Query* e = 0)
17451745
: Has_Block(pstate, b), expression_(e)
17461746
{ statement_type(ATROOT); }
17471747
bool is_hoistable() { return true; }
17481748
bool bubbles() { return true; }
17491749
bool exclude_node(Statement* s) {
17501750
if (s->statement_type() == Statement::DIRECTIVE)
17511751
{
1752-
return expression()->exclude(static_cast<At_Rule*>(s)->keyword().erase(0, 1));
1752+
return expression()->exclude(static_cast<Directive*>(s)->keyword().erase(0, 1));
17531753
}
17541754
if (s->statement_type() == Statement::MEDIA)
17551755
{
@@ -1763,7 +1763,7 @@ namespace Sass {
17631763
{
17641764
return expression()->exclude("supports");
17651765
}
1766-
if (static_cast<At_Rule*>(s)->is_keyframes())
1766+
if (static_cast<Directive*>(s)->is_keyframes())
17671767
{
17681768
return expression()->exclude("keyframes");
17691769
}

src/ast_factory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Sass {
1717
Supports_Query* new_Supports_Query(std::string p, size_t l, Supports_Query* f, Block* b);
1818
Media_Query* new_Media_Query(std::string p, size_t l, List* q, Block* b);
1919
At_Root_Block* new_At_Root_Block(std::string p, size_t l, Selector* sel, Block* b);
20-
At_Rule* new_At_Rule(std::string p, size_t l, std::string kwd, Selector* sel, Block* b);
20+
Directive* new_At_Rule(std::string p, size_t l, std::string kwd, Selector* sel, Block* b);
2121
Keyframe_Rule* new_Keyframe_Rule(std::string p, size_t l, Block* b);
2222
Declaration* new_Declaration(std::string p, size_t l, String* prop, List* vals);
2323
Assignment* new_Assignment(std::string p, size_t l, std::string var, Expression* val, bool guarded = false);

src/ast_fwd_decl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Sass {
1515
class Bubble;
1616
class Media_Block;
1717
class Supports_Block;
18-
class At_Rule;
18+
class Directive;
1919
class Keyframe_Rule;
2020
class At_Root_Block;
2121
class Declaration;
@@ -62,7 +62,7 @@ namespace Sass {
6262
class Supports_Negation;
6363
class Supports_Declaration;
6464
class Supports_Interpolation;
65-
class At_Root_Expression;
65+
class At_Root_Query;
6666
class Null;
6767
class Parent_Selector;
6868
// parameters and arguments

src/cssize.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@ namespace Sass {
1313
: ctx(ctx),
1414
block_stack(std::vector<Block*>()),
1515
p_stack(std::vector<Statement*>()),
16+
s_stack(std::vector<Selector_List*>()),
1617
backtrace(bt)
17-
{ }
18+
{
19+
s_stack.push_back(NULL);
20+
}
1821

1922
Statement* Cssize::parent()
2023
{
2124
return p_stack.size() ? p_stack.back() : block_stack.front();
2225
}
2326

27+
Selector_List* Cssize::selector()
28+
{
29+
return s_stack.size() ? s_stack.back() : NULL;
30+
}
31+
2432
Statement* Cssize::operator()(Block* b)
2533
{
2634
Block* bb = SASS_MEMORY_NEW(ctx.mem, Block, b->pstate(), b->length(), b->is_root());
@@ -31,7 +39,7 @@ namespace Sass {
3139
return bb;
3240
}
3341

34-
Statement* Cssize::operator()(At_Rule* r)
42+
Statement* Cssize::operator()(Directive* r)
3543
{
3644
if (!r->block() || !r->block()->length()) return r;
3745

@@ -41,7 +49,7 @@ namespace Sass {
4149
}
4250

4351
p_stack.push_back(r);
44-
At_Rule* rr = SASS_MEMORY_NEW(ctx.mem, At_Rule,
52+
Directive* rr = SASS_MEMORY_NEW(ctx.mem, Directive,
4553
r->pstate(),
4654
r->keyword(),
4755
r->selector(),
@@ -57,15 +65,15 @@ namespace Sass {
5765
else {
5866
s = static_cast<Bubble*>(s)->node();
5967
if (s->statement_type() != Statement::DIRECTIVE) directive_exists = false;
60-
else directive_exists = (static_cast<At_Rule*>(s)->keyword() == rr->keyword());
68+
else directive_exists = (static_cast<Directive*>(s)->keyword() == rr->keyword());
6169
}
6270

6371
}
6472

6573
Block* result = SASS_MEMORY_NEW(ctx.mem, Block, rr->pstate());
6674
if (!(directive_exists || rr->is_keyframes()))
6775
{
68-
At_Rule* empty_node = static_cast<At_Rule*>(rr);
76+
Directive* empty_node = static_cast<Directive*>(rr);
6977
empty_node->block(SASS_MEMORY_NEW(ctx.mem, Block, rr->block() ? rr->block()->pstate() : rr->pstate()));
7078
*result << empty_node;
7179
}
@@ -93,12 +101,14 @@ namespace Sass {
93101
Statement* Cssize::operator()(Ruleset* r)
94102
{
95103
p_stack.push_back(r);
104+
s_stack.push_back(dynamic_cast<Selector_List*>(r->selector()));
96105
Ruleset* rr = SASS_MEMORY_NEW(ctx.mem, Ruleset,
97106
r->pstate(),
98107
r->selector(),
99108
r->block()->perform(this)->block());
100109
rr->is_root(r->is_root());
101110
// rr->tabs(r->block()->tabs());
111+
s_stack.pop_back();
102112
p_stack.pop_back();
103113

104114
if (!rr->block()) {
@@ -214,7 +224,7 @@ namespace Sass {
214224
return bubble(m);
215225
}
216226

217-
Statement* Cssize::bubble(At_Rule* m)
227+
Statement* Cssize::bubble(Directive* m)
218228
{
219229
Block* bb = SASS_MEMORY_NEW(ctx.mem, Block, this->parent()->pstate());
220230
Has_Block* new_rule = static_cast<Has_Block*>(shallow_copy(this->parent()));
@@ -228,7 +238,7 @@ namespace Sass {
228238

229239
Block* wrapper_block = SASS_MEMORY_NEW(ctx.mem, Block, m->block() ? m->block()->pstate() : m->pstate());
230240
*wrapper_block << new_rule;
231-
At_Rule* mm = SASS_MEMORY_NEW(ctx.mem, At_Rule,
241+
Directive* mm = SASS_MEMORY_NEW(ctx.mem, Directive,
232242
m->pstate(),
233243
m->keyword(),
234244
m->selector(),
@@ -375,7 +385,7 @@ namespace Sass {
375385
case Statement::BUBBLE:
376386
return SASS_MEMORY_NEW(ctx.mem, Bubble, *static_cast<Bubble*>(s));
377387
case Statement::DIRECTIVE:
378-
return SASS_MEMORY_NEW(ctx.mem, At_Rule, *static_cast<At_Rule*>(s));
388+
return SASS_MEMORY_NEW(ctx.mem, Directive, *static_cast<Directive*>(s));
379389
case Statement::SUPPORTS:
380390
return SASS_MEMORY_NEW(ctx.mem, Supports_Block, *static_cast<Supports_Block*>(s));
381391
case Statement::ATROOT:

src/cssize.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Sass {
1616
Context& ctx;
1717
std::vector<Block*> block_stack;
1818
std::vector<Statement*> p_stack;
19+
std::vector<Selector_List*> s_stack;
1920
Backtrace* backtrace;
2021

2122
Statement* fallback_impl(AST_Node* n);
@@ -24,14 +25,16 @@ namespace Sass {
2425
Cssize(Context&, Backtrace*);
2526
~Cssize() { }
2627

28+
Selector_List* selector();
29+
2730
Statement* operator()(Block*);
2831
Statement* operator()(Ruleset*);
2932
// Statement* operator()(Propset*);
3033
// Statement* operator()(Bubble*);
3134
Statement* operator()(Media_Block*);
3235
Statement* operator()(Supports_Block*);
3336
Statement* operator()(At_Root_Block*);
34-
Statement* operator()(At_Rule*);
37+
Statement* operator()(Directive*);
3538
Statement* operator()(Keyframe_Rule*);
3639
// Statement* operator()(Declaration*);
3740
// Statement* operator()(Assignment*);
@@ -53,7 +56,7 @@ namespace Sass {
5356

5457
Statement* parent();
5558
std::vector<std::pair<bool, Block*>> slice_by_bubble(Statement*);
56-
Statement* bubble(At_Rule*);
59+
Statement* bubble(Directive*);
5760
Statement* bubble(At_Root_Block*);
5861
Statement* bubble(Media_Block*);
5962
Statement* bubble(Supports_Block*);

src/debugger.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,9 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
388388
std::cerr << " " << has_block->tabs() << std::endl;
389389
if (has_block->selector()) debug_ast(has_block->selector(), ind + "@");
390390
if (has_block->block()) for(auto i : has_block->block()->elements()) { debug_ast(i, ind + " ", env); }
391-
} else if (dynamic_cast<At_Rule*>(node)) {
392-
At_Rule* block = dynamic_cast<At_Rule*>(node);
393-
std::cerr << ind << "At_Rule " << block;
391+
} else if (dynamic_cast<Directive*>(node)) {
392+
Directive* block = dynamic_cast<Directive*>(node);
393+
std::cerr << ind << "Directive " << block;
394394
std::cerr << " (" << pstate_source_position(node) << ")";
395395
std::cerr << " [" << block->keyword() << "] " << block->tabs() << std::endl;
396396
debug_ast(block->selector(), ind + "~", env);

src/eval.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,17 +1280,16 @@ namespace Sass {
12801280
return cc;
12811281
}
12821282

1283-
Expression* Eval::operator()(At_Root_Expression* e)
1283+
Expression* Eval::operator()(At_Root_Query* e)
12841284
{
12851285
Expression* feature = e->feature();
12861286
feature = (feature ? feature->perform(this) : 0);
12871287
Expression* value = e->value();
12881288
value = (value ? value->perform(this) : 0);
1289-
Expression* ee = SASS_MEMORY_NEW(ctx.mem, At_Root_Expression,
1289+
Expression* ee = SASS_MEMORY_NEW(ctx.mem, At_Root_Query,
12901290
e->pstate(),
12911291
static_cast<String*>(feature),
1292-
value,
1293-
e->is_interpolated());
1292+
value);
12941293
return ee;
12951294
}
12961295

@@ -1682,6 +1681,7 @@ namespace Sass {
16821681
{
16831682
std::vector<Selector_List*> rv;
16841683
Selector_List* sl = SASS_MEMORY_NEW(ctx.mem, Selector_List, s->pstate());
1684+
sl->is_optional(s->is_optional());
16851685
sl->media_block(s->media_block());
16861686
sl->is_optional(s->is_optional());
16871687
for (size_t i = 0, iL = s->length(); i < iL; ++i) {

src/eval.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace Sass {
5757
// Expression* operator()(Selector_List*);
5858
Expression* operator()(Media_Query*);
5959
Expression* operator()(Media_Query_Expression*);
60-
Expression* operator()(At_Root_Expression*);
60+
Expression* operator()(At_Root_Query*);
6161
Expression* operator()(Supports_Operator*);
6262
Expression* operator()(Supports_Negation*);
6363
Expression* operator()(Supports_Declaration*);

src/expand.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,17 @@ namespace Sass {
222222
// if (ab) ab->is_root(true);
223223
Expression* ae = a->expression();
224224
if (ae) ae = ae->perform(&eval);
225-
else ae = SASS_MEMORY_NEW(ctx.mem, At_Root_Expression, a->pstate());
225+
else ae = SASS_MEMORY_NEW(ctx.mem, At_Root_Query, a->pstate());
226226
Block* bb = ab ? ab->perform(this)->block() : 0;
227227
At_Root_Block* aa = SASS_MEMORY_NEW(ctx.mem, At_Root_Block,
228228
a->pstate(),
229229
bb,
230-
static_cast<At_Root_Expression*>(ae));
230+
static_cast<At_Root_Query*>(ae));
231231
// aa->block()->is_root(true);
232232
return aa;
233233
}
234234

235-
Statement* Expand::operator()(At_Rule* a)
235+
Statement* Expand::operator()(Directive* a)
236236
{
237237
LOCAL_FLAG(in_keyframes, a->is_keyframes());
238238
Block* ab = a->block();
@@ -243,7 +243,7 @@ namespace Sass {
243243
if (as) as = dynamic_cast<Selector*>(as->perform(&eval));
244244
selector_stack.pop_back();
245245
Block* bb = ab ? ab->perform(this)->block() : 0;
246-
At_Rule* aa = SASS_MEMORY_NEW(ctx.mem, At_Rule,
246+
Directive* aa = SASS_MEMORY_NEW(ctx.mem, Directive,
247247
a->pstate(),
248248
a->keyword(),
249249
as,

0 commit comments

Comments
 (0)