Skip to content

Commit

Permalink
Refactor supports/feature query parsing [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed May 30, 2015
1 parent 9dbf151 commit c82290e
Show file tree
Hide file tree
Showing 24 changed files with 161 additions and 141 deletions.
33 changes: 16 additions & 17 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ namespace Sass {
RULESET,
MEDIA,
DIRECTIVE,
FEATURE,
SUPPORTS,
ATROOT,
BUBBLE,
KEYFRAMERULE
Expand Down Expand Up @@ -388,16 +388,15 @@ namespace Sass {
ATTACH_OPERATIONS();
};

///////////////////
// Feature queries.
///////////////////
class Feature_Block : public Has_Block {
ADD_PROPERTY(Feature_Query*, feature_queries);
ADD_PROPERTY(Selector*, selector);
//////////////////
// Query features.
//////////////////
class Supports_Block : public Has_Block {
ADD_PROPERTY(Supports_Query*, queries);
public:
Feature_Block(ParserState pstate, Feature_Query* fqs, Block* b)
: Has_Block(pstate, b), feature_queries_(fqs), selector_(0)
{ statement_type(FEATURE); }
Supports_Block(ParserState pstate, Supports_Query* queries = 0, Block* block = 0)
: Has_Block(pstate, block), queries_(queries)
{ statement_type(SUPPORTS); }
bool is_hoistable() { return true; }
bool bubbles() { return true; }
ATTACH_OPERATIONS();
Expand Down Expand Up @@ -1458,18 +1457,18 @@ namespace Sass {
///////////////////
// Feature queries.
///////////////////
class Feature_Query : public Expression, public Vectorized<Feature_Query_Condition*> {
class Supports_Query : public Expression, public Vectorized<Supports_Condition*> {
public:
Feature_Query(ParserState pstate, size_t s = 0)
: Expression(pstate), Vectorized<Feature_Query_Condition*>(s)
Supports_Query(ParserState pstate, size_t s = 0)
: Expression(pstate), Vectorized<Supports_Condition*>(s)
{ }
ATTACH_OPERATIONS();
};

////////////////////////////////////////////////////////
// Feature expressions (for use inside feature queries).
////////////////////////////////////////////////////////
class Feature_Query_Condition : public Expression, public Vectorized<Feature_Query_Condition*> {
class Supports_Condition : public Expression, public Vectorized<Supports_Condition*> {
public:
enum Operand { NONE, AND, OR, NOT };
private:
Expand All @@ -1478,9 +1477,9 @@ namespace Sass {
ADD_PROPERTY(Operand, operand);
ADD_PROPERTY(bool, is_root);
public:
Feature_Query_Condition(ParserState pstate, size_t s = 0, String* f = 0,
Supports_Condition(ParserState pstate, size_t s = 0, String* f = 0,
Expression* v = 0, Operand o = NONE, bool r = false)
: Expression(pstate), Vectorized<Feature_Query_Condition*>(s),
: Expression(pstate), Vectorized<Supports_Condition*>(s),
feature_(f), value_(v), operand_(o), is_root_(r)
{ }
ATTACH_OPERATIONS();
Expand Down Expand Up @@ -1553,7 +1552,7 @@ namespace Sass {
{
return expression()->exclude("rule");
}
if (s->statement_type() == Statement::FEATURE)
if (s->statement_type() == Statement::SUPPORTS)
{
return expression()->exclude("supports");
}
Expand Down
4 changes: 2 additions & 2 deletions ast_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Sass {
Block* new_Block(string p, size_t l, size_t s = 0, bool r = false);
Ruleset* new_Ruleset(string p, size_t l, Selector* s, Block* b);
Propset* new_Propset(string p, size_t l, String* pf, Block* b);
Feature_Query* new_Feature_Query(string p, size_t l, Feature_Query* f, Block* b);
Supports_Query* new_Feature_Query(string p, size_t l, Supports_Query* f, Block* b);
Media_Query* new_Media_Query(string p, size_t l, List* q, Block* b);
At_Root_Block* new_At_Root_Block(string p, size_t l, Selector* sel, Block* b);
At_Rule* new_At_Rule(string p, size_t l, string kwd, Selector* sel, Block* b);
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace Sass {
String_Constant* new_String_Constant(string p, size_t l, string val);
String_Constant* new_String_Constant(string p, size_t l, const char* beg);
String_Constant* new_String_Constant(string p, size_t l, const char* beg, const char* end);
Feature_Query_Condition* new_Feature_Query_Condition(string p, size_t l, String* f, Expression* v);
Supports_Condition* new_Feature_Query_Condition(string p, size_t l, String* f, Expression* v);
Media_Expression* new_Media_Expression(string p, size_t l, String* f, Expression* v);
Parent_Selector* new_Parent_Selector(string p, size_t l, Selector* s);
// parameters and arguments
Expand Down
6 changes: 3 additions & 3 deletions ast_fwd_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Sass {
class Propset;
class Bubble;
class Media_Block;
class Feature_Block;
class Supports_Block;
class At_Rule;
class Keyframe_Rule;
class At_Root_Block;
Expand Down Expand Up @@ -56,8 +56,8 @@ namespace Sass {
class String_Quoted;
class Media_Query;
class Media_Query_Expression;
class Feature_Query;
class Feature_Query_Condition;
class Supports_Query;
class Supports_Condition;
class At_Root_Expression;
class Null;
class Parent_Selector;
Expand Down
16 changes: 8 additions & 8 deletions cssize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace Sass {
return debubble(mm->block(), mm)->block();
}

Statement* Cssize::operator()(Feature_Block* m)
Statement* Cssize::operator()(Supports_Block* m)
{
if (!m->block()->length())
{ return m; }
Expand All @@ -171,8 +171,8 @@ namespace Sass {

p_stack.push_back(m);

Feature_Block* mm = new (ctx.mem) Feature_Block(m->pstate(),
m->feature_queries(),
Supports_Block* mm = new (ctx.mem) Supports_Block(m->pstate(),
m->queries(),
m->block()->perform(this)->block());
mm->tabs(m->tabs());

Expand Down Expand Up @@ -253,7 +253,7 @@ namespace Sass {
return bubble;
}

Statement* Cssize::bubble(Feature_Block* m)
Statement* Cssize::bubble(Supports_Block* m)
{
Ruleset* parent = static_cast<Ruleset*>(shallow_copy(this->parent()));

Expand All @@ -269,8 +269,8 @@ namespace Sass {

Block* wrapper_block = new (ctx.mem) Block(m->block()->pstate());
*wrapper_block << new_rule;
Feature_Block* mm = new (ctx.mem) Feature_Block(m->pstate(),
m->feature_queries(),
Supports_Block* mm = new (ctx.mem) Supports_Block(m->pstate(),
m->queries(),
wrapper_block);

mm->tabs(m->tabs());
Expand Down Expand Up @@ -365,8 +365,8 @@ namespace Sass {
return new (ctx.mem) Bubble(*static_cast<Bubble*>(s));
case Statement::DIRECTIVE:
return new (ctx.mem) At_Rule(*static_cast<At_Rule*>(s));
case Statement::FEATURE:
return new (ctx.mem) Feature_Block(*static_cast<Feature_Block*>(s));
case Statement::SUPPORTS:
return new (ctx.mem) Supports_Block(*static_cast<Supports_Block*>(s));
case Statement::ATROOT:
return new (ctx.mem) At_Root_Block(*static_cast<At_Root_Block*>(s));
case Statement::KEYFRAMERULE:
Expand Down
4 changes: 2 additions & 2 deletions cssize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Sass {
// Statement* operator()(Propset*);
// Statement* operator()(Bubble*);
Statement* operator()(Media_Block*);
Statement* operator()(Feature_Block*);
Statement* operator()(Supports_Block*);
Statement* operator()(At_Root_Block*);
Statement* operator()(At_Rule*);
Statement* operator()(Keyframe_Rule*);
Expand All @@ -63,7 +63,7 @@ namespace Sass {
Statement* bubble(At_Rule*);
Statement* bubble(At_Root_Block*);
Statement* bubble(Media_Block*);
Statement* bubble(Feature_Block*);
Statement* bubble(Supports_Block*);
Statement* shallow_copy(Statement*);
Statement* debubble(Block* children, Statement* parent = 0);
Statement* flatten(Statement*);
Expand Down
6 changes: 3 additions & 3 deletions debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
debug_ast(block->media_queries(), ind + " =@ ");
debug_ast(block->selector(), ind + " -@ ");
if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
} else if (dynamic_cast<Feature_Block*>(node)) {
Feature_Block* block = dynamic_cast<Feature_Block*>(node);
cerr << ind << "Feature_Block " << block;
} else if (dynamic_cast<Supports_Block*>(node)) {
Supports_Block* block = dynamic_cast<Supports_Block*>(node);
cerr << ind << "Supports_Block " << block;
cerr << " (" << pstate_source_position(node) << ")";
cerr << " " << block->tabs() << endl;
if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
Expand Down
12 changes: 6 additions & 6 deletions eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,29 +957,29 @@ string qwe = sel ? sel->perform(&to_string) : "";
return s;
}

Expression* Eval::operator()(Feature_Query* q)
Expression* Eval::operator()(Supports_Query* q)
{
Feature_Query* qq = new (ctx.mem) Feature_Query(q->pstate(),
Supports_Query* qq = new (ctx.mem) Supports_Query(q->pstate(),
q->length());
for (size_t i = 0, L = q->length(); i < L; ++i) {
*qq << static_cast<Feature_Query_Condition*>((*q)[i]->perform(this));
*qq << static_cast<Supports_Condition*>((*q)[i]->perform(this));
}
return qq;
}

Expression* Eval::operator()(Feature_Query_Condition* c)
Expression* Eval::operator()(Supports_Condition* c)
{
String* feature = c->feature();
Expression* value = c->value();
value = (value ? value->perform(this) : 0);
Feature_Query_Condition* cc = new (ctx.mem) Feature_Query_Condition(c->pstate(),
Supports_Condition* cc = new (ctx.mem) Supports_Condition(c->pstate(),
c->length(),
feature,
value,
c->operand(),
c->is_root());
for (size_t i = 0, L = c->length(); i < L; ++i) {
*cc << static_cast<Feature_Query_Condition*>((*c)[i]->perform(this));
*cc << static_cast<Supports_Condition*>((*c)[i]->perform(this));
}
return cc;
}
Expand Down
4 changes: 2 additions & 2 deletions eval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ namespace Sass {
Expression* operator()(Media_Query*);
Expression* operator()(Media_Query_Expression*);
Expression* operator()(At_Root_Expression*);
Expression* operator()(Feature_Query*);
Expression* operator()(Feature_Query_Condition*);
Expression* operator()(Supports_Query*);
Expression* operator()(Supports_Condition*);
Expression* operator()(Null*);
Expression* operator()(Argument*);
Expression* operator()(Arguments*);
Expand Down
10 changes: 5 additions & 5 deletions expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ namespace Sass {
return 0;
}

Statement* Expand::operator()(Feature_Block* f)
Statement* Expand::operator()(Supports_Block* f)
{
Expression* feature_queries = f->feature_queries()->perform(&eval);
Feature_Block* ff = new (ctx.mem) Feature_Block(f->pstate(),
static_cast<Feature_Query*>(feature_queries),
Expression* queries = f->queries()->perform(&eval);
Supports_Block* ff = new (ctx.mem) Supports_Block(f->pstate(),
static_cast<Supports_Query*>(queries),
f->block()->perform(this)->block());
ff->selector(selector());
// ff->selector(selector());
return ff;
}

Expand Down
2 changes: 1 addition & 1 deletion expand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace Sass {
Statement* operator()(Ruleset*);
Statement* operator()(Propset*);
Statement* operator()(Media_Block*);
Statement* operator()(Feature_Block*);
Statement* operator()(Supports_Block*);
Statement* operator()(At_Root_Block*);
Statement* operator()(At_Rule*);
Statement* operator()(Declaration*);
Expand Down
8 changes: 4 additions & 4 deletions extend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1988,11 +1988,11 @@ namespace Sass {
pRuleset->block()->perform(this);
}

void Extend::operator()(Feature_Block* pFeatureBlock)
void Extend::operator()(Supports_Block* pFeatureBlock)
{
if (pFeatureBlock->selector()) {
extendObjectWithSelectorAndBlock(pFeatureBlock, ctx, subset_map);
}
// if (pFeatureBlock->selector()) {
// extendObjectWithSelectorAndBlock(pFeatureBlock, ctx, subset_map);
// }

pFeatureBlock->block()->perform(this);
}
Expand Down
2 changes: 1 addition & 1 deletion extend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Sass {

void operator()(Block*);
void operator()(Ruleset*);
void operator()(Feature_Block*);
void operator()(Supports_Block*);
void operator()(Media_Block*);
void operator()(At_Rule*);

Expand Down
14 changes: 7 additions & 7 deletions inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ namespace Sass {
media_block->block()->perform(this);
}

void Inspect::operator()(Feature_Block* feature_block)
void Inspect::operator()(Supports_Block* feature_block)
{
append_indentation();
append_token("@supports", feature_block);
append_mandatory_space();
feature_block->feature_queries()->perform(this);
feature_block->queries()->perform(this);
feature_block->block()->perform(this);
}

Expand Down Expand Up @@ -647,7 +647,7 @@ namespace Sass {
}
}

void Inspect::operator()(Feature_Query* fq)
void Inspect::operator()(Supports_Query* fq)
{
size_t i = 0;
(*fq)[i++]->perform(this);
Expand All @@ -656,17 +656,17 @@ namespace Sass {
}
}

void Inspect::operator()(Feature_Query_Condition* fqc)
void Inspect::operator()(Supports_Condition* fqc)
{
if (fqc->operand() == Feature_Query_Condition::AND) {
if (fqc->operand() == Supports_Condition::AND) {
append_mandatory_space();
append_token("and", fqc);
append_mandatory_space();
} else if (fqc->operand() == Feature_Query_Condition::OR) {
} else if (fqc->operand() == Supports_Condition::OR) {
append_mandatory_space();
append_token("or", fqc);
append_mandatory_space();
} else if (fqc->operand() == Feature_Query_Condition::NOT) {
} else if (fqc->operand() == Supports_Condition::NOT) {
append_mandatory_space();
append_token("not", fqc);
append_mandatory_space();
Expand Down
6 changes: 3 additions & 3 deletions inspect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Sass {
virtual void operator()(Ruleset*);
virtual void operator()(Propset*);
virtual void operator()(Bubble*);
virtual void operator()(Feature_Block*);
virtual void operator()(Supports_Block*);
virtual void operator()(Media_Block*);
virtual void operator()(At_Root_Block*);
virtual void operator()(At_Rule*);
Expand Down Expand Up @@ -65,8 +65,8 @@ namespace Sass {
virtual void operator()(String_Schema*);
virtual void operator()(String_Constant*);
virtual void operator()(String_Quoted*);
virtual void operator()(Feature_Query*);
virtual void operator()(Feature_Query_Condition*);
virtual void operator()(Supports_Query*);
virtual void operator()(Supports_Condition*);
virtual void operator()(Media_Query*);
virtual void operator()(Media_Query_Expression*);
virtual void operator()(At_Root_Expression*);
Expand Down
Loading

0 comments on commit c82290e

Please sign in to comment.