Skip to content

Commit

Permalink
Rename CommaSequence_Selector to Selector_List
Browse files Browse the repository at this point in the history
Reverts sass#2101
  • Loading branch information
mgreter committed Nov 26, 2016
1 parent 0ff2474 commit c94322e
Show file tree
Hide file tree
Showing 26 changed files with 175 additions and 175 deletions.
90 changes: 45 additions & 45 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,18 +338,18 @@ namespace Sass {
return ns() < rhs.ns();
}

bool CommaSequence_Selector::operator== (const Selector& rhs) const
bool Selector_List::operator== (const Selector& rhs) const
{
// solve the double dispatch problem by using RTTI information via dynamic cast
if (const CommaSequence_Selector* ls = dynamic_cast<const CommaSequence_Selector*>(&rhs)) { return *this == *ls; }
if (const Selector_List* ls = dynamic_cast<const Selector_List*>(&rhs)) { return *this == *ls; }
else if (const Sequence_Selector* ls = dynamic_cast<const Sequence_Selector*>(&rhs)) { return *this == *ls; }
else if (const SimpleSequence_Selector* ls = dynamic_cast<const SimpleSequence_Selector*>(&rhs)) { return *this == *ls; }
// no compare method
return this == &rhs;
}

// Selector lists can be compared to comma lists
bool CommaSequence_Selector::operator==(const Expression& rhs) const
bool Selector_List::operator==(const Expression& rhs) const
{
// solve the double dispatch problem by using RTTI information via dynamic cast
if (const List* ls = dynamic_cast<const List*>(&rhs)) { return *this == *ls; }
Expand All @@ -358,7 +358,7 @@ namespace Sass {
return false;
}

bool CommaSequence_Selector::operator== (const CommaSequence_Selector& rhs) const
bool Selector_List::operator== (const Selector_List& rhs) const
{
// for array access
size_t i = 0, n = 0;
Expand Down Expand Up @@ -681,18 +681,18 @@ namespace Sass {
{
if (this->name() != sub->name()) return false;
if (this->name() == ":current") return false;
if (CommaSequence_Selector* rhs_list = dynamic_cast<CommaSequence_Selector*>(sub->selector())) {
if (CommaSequence_Selector* lhs_list = dynamic_cast<CommaSequence_Selector*>(selector())) {
if (Selector_List* rhs_list = dynamic_cast<Selector_List*>(sub->selector())) {
if (Selector_List* lhs_list = dynamic_cast<Selector_List*>(selector())) {
return lhs_list->is_superselector_of(rhs_list);
}
error("is_superselector expected a CommaSequence_Selector", sub->pstate());
error("is_superselector expected a Selector_List", sub->pstate());
} else {
error("is_superselector expected a CommaSequence_Selector", sub->pstate());
error("is_superselector expected a Selector_List", sub->pstate());
}
return false;
}

bool SimpleSequence_Selector::is_superselector_of(CommaSequence_Selector* rhs, std::string wrapped)
bool SimpleSequence_Selector::is_superselector_of(Selector_List* rhs, std::string wrapped)
{
for (Sequence_Selector* item : rhs->elements()) {
if (is_superselector_of(item, wrapped)) return true;
Expand Down Expand Up @@ -755,15 +755,15 @@ namespace Sass {
// very special case for wrapped matches selector
if (Wrapped_Selector* wrapped = dynamic_cast<Wrapped_Selector*>(lhs)) {
if (wrapped->name() == ":not") {
if (CommaSequence_Selector* not_list = dynamic_cast<CommaSequence_Selector*>(wrapped->selector())) {
if (Selector_List* not_list = dynamic_cast<Selector_List*>(wrapped->selector())) {
if (not_list->is_superselector_of(rhs, wrapped->name())) return false;
} else {
throw std::runtime_error("wrapped not selector is not a list");
}
}
if (wrapped->name() == ":matches" || wrapped->name() == ":-moz-any") {
lhs = wrapped->selector();
if (CommaSequence_Selector* list = dynamic_cast<CommaSequence_Selector*>(wrapped->selector())) {
if (Selector_List* list = dynamic_cast<Selector_List*>(wrapped->selector())) {
if (SimpleSequence_Selector* comp = dynamic_cast<SimpleSequence_Selector*>(rhs)) {
if (!wrapping.empty() && wrapping != wrapped->name()) return false;
if (wrapping.empty() || wrapping != wrapped->name()) {;
Expand Down Expand Up @@ -791,7 +791,7 @@ namespace Sass {
auto r = (*rhs)[n];
if (Wrapped_Selector* wrapped = dynamic_cast<Wrapped_Selector*>(r)) {
if (wrapped->name() == ":not") {
if (CommaSequence_Selector* ls = dynamic_cast<CommaSequence_Selector*>(wrapped->selector())) {
if (Selector_List* ls = dynamic_cast<Selector_List*>(wrapped->selector())) {
ls->remove_parent_selectors();
if (is_superselector_of(ls, wrapped->name())) return false;
}
Expand All @@ -800,7 +800,7 @@ namespace Sass {
if (!wrapping.empty()) {
if (wrapping != wrapped->name()) return false;
}
if (CommaSequence_Selector* ls = dynamic_cast<CommaSequence_Selector*>(wrapped->selector())) {
if (Selector_List* ls = dynamic_cast<Selector_List*>(wrapped->selector())) {
ls->remove_parent_selectors();
return (is_superselector_of(ls, wrapped->name()));
}
Expand Down Expand Up @@ -829,7 +829,7 @@ namespace Sass {
0);
}

CommaSequence_Selector* Sequence_Selector::unify_with(Sequence_Selector* other, Context& ctx)
Selector_List* Sequence_Selector::unify_with(Sequence_Selector* other, Context& ctx)
{

// get last tails (on the right side)
Expand Down Expand Up @@ -887,7 +887,7 @@ namespace Sass {

// do some magic we inherit from node and extend
Node node = Extend::subweave(lhsNode, rhsNode, ctx);
CommaSequence_Selector* result = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
Selector_List* result = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
NodeDequePtr col = node.collection(); // move from collection to list
for (NodeDeque::iterator it = col->begin(), end = col->end(); it != end; it++)
{ (*result) << nodeToComplexSelector(Node::naiveTrim(*it, ctx), ctx); }
Expand Down Expand Up @@ -1118,12 +1118,12 @@ namespace Sass {

}

CommaSequence_Selector* CommaSequence_Selector::resolve_parent_refs(Context& ctx, CommaSequence_Selector* ps, bool implicit_parent)
Selector_List* Selector_List::resolve_parent_refs(Context& ctx, Selector_List* ps, bool implicit_parent)
{
if (!this->has_parent_ref()/* && !implicit_parent*/) return this;
CommaSequence_Selector* ss = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
Selector_List* ss = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
for (size_t pi = 0, pL = ps->length(); pi < pL; ++pi) {
CommaSequence_Selector* list = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
Selector_List* list = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
*list << (*ps)[pi];
for (size_t si = 0, sL = this->length(); si < sL; ++si) {
*ss += (*this)[si]->resolve_parent_refs(ctx, list, implicit_parent);
Expand All @@ -1132,27 +1132,27 @@ namespace Sass {
return ss;
}

CommaSequence_Selector* Sequence_Selector::resolve_parent_refs(Context& ctx, CommaSequence_Selector* parents, bool implicit_parent)
Selector_List* Sequence_Selector::resolve_parent_refs(Context& ctx, Selector_List* parents, bool implicit_parent)
{
Sequence_Selector* tail = this->tail();
SimpleSequence_Selector* head = this->head();

if (!this->has_real_parent_ref() && !implicit_parent) {
CommaSequence_Selector* retval = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
Selector_List* retval = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
*retval << this;
return retval;
}

// first resolve_parent_refs the tail (which may return an expanded list)
CommaSequence_Selector* tails = tail ? tail->resolve_parent_refs(ctx, parents, implicit_parent) : 0;
Selector_List* tails = tail ? tail->resolve_parent_refs(ctx, parents, implicit_parent) : 0;

if (head && head->length() > 0) {

CommaSequence_Selector* retval = 0;
Selector_List* retval = 0;
// we have a parent selector in a simple compound list
// mix parent complex selector into the compound list
if (dynamic_cast<Parent_Selector*>((*head)[0])) {
retval = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
retval = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
if (parents && parents->length()) {
if (tails && tails->length() > 0) {
for (size_t n = 0, nL = tails->length(); n < nL; ++n) {
Expand Down Expand Up @@ -1246,7 +1246,7 @@ namespace Sass {

for (Simple_Selector* ss : *head) {
if (Wrapped_Selector* ws = dynamic_cast<Wrapped_Selector*>(ss)) {
if (CommaSequence_Selector* sl = dynamic_cast<CommaSequence_Selector*>(ws->selector())) {
if (Selector_List* sl = dynamic_cast<Selector_List*>(ws->selector())) {
if (parents) ws->selector(sl->resolve_parent_refs(ctx, parents, implicit_parent));
}
}
Expand All @@ -1264,9 +1264,9 @@ namespace Sass {
return 0;
}

CommaSequence_Selector* Sequence_Selector::tails(Context& ctx, CommaSequence_Selector* tails)
Selector_List* Sequence_Selector::tails(Context& ctx, Selector_List* tails)
{
CommaSequence_Selector* rv = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate_);
Selector_List* rv = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate_);
if (tails && tails->length()) {
for (size_t i = 0, iL = tails->length(); i < iL; ++i) {
Sequence_Selector* pr = this->clone(ctx);
Expand Down Expand Up @@ -1393,17 +1393,17 @@ namespace Sass {
return cpy;
}

CommaSequence_Selector* CommaSequence_Selector::clone(Context& ctx) const
Selector_List* Selector_List::clone(Context& ctx) const
{
CommaSequence_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, *this);
Selector_List* cpy = SASS_MEMORY_NEW(ctx.mem, Selector_List, *this);
cpy->is_optional(this->is_optional());
cpy->media_block(this->media_block());
return cpy;
}

CommaSequence_Selector* CommaSequence_Selector::cloneFully(Context& ctx) const
Selector_List* Selector_List::cloneFully(Context& ctx) const
{
CommaSequence_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
Selector_List* cpy = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
cpy->is_optional(this->is_optional());
cpy->media_block(this->media_block());
for (size_t i = 0, L = length(); i < L; ++i) {
Expand All @@ -1420,7 +1420,7 @@ namespace Sass {

// remove parent selector references
// basically unwraps parsed selectors
void CommaSequence_Selector::remove_parent_selectors()
void Selector_List::remove_parent_selectors()
{
// Check every rhs selector against left hand list
for(size_t i = 0, L = length(); i < L; ++i) {
Expand All @@ -1443,15 +1443,15 @@ namespace Sass {
}
}

bool CommaSequence_Selector::has_parent_ref()
bool Selector_List::has_parent_ref()
{
for (Sequence_Selector* s : *this) {
if (s && s->has_parent_ref()) return true;
}
return false;
}

bool CommaSequence_Selector::has_real_parent_ref()
bool Selector_List::has_real_parent_ref()
{
for (Sequence_Selector* s : *this) {
if (s && s->has_real_parent_ref()) return true;
Expand All @@ -1476,14 +1476,14 @@ namespace Sass {
return false;
}

void CommaSequence_Selector::adjust_after_pushing(Sequence_Selector* c)
void Selector_List::adjust_after_pushing(Sequence_Selector* c)
{
// if (c->has_reference()) has_reference(true);
}

// it's a superselector if every selector of the right side
// list is a superselector of the given left side selector
bool Sequence_Selector::is_superselector_of(CommaSequence_Selector *sub, std::string wrapping)
bool Sequence_Selector::is_superselector_of(Selector_List *sub, std::string wrapping)
{
// Check every rhs selector against left hand list
for(size_t i = 0, L = sub->length(); i < L; ++i) {
Expand All @@ -1494,7 +1494,7 @@ namespace Sass {

// it's a superselector if every selector of the right side
// list is a superselector of the given left side selector
bool CommaSequence_Selector::is_superselector_of(CommaSequence_Selector *sub, std::string wrapping)
bool Selector_List::is_superselector_of(Selector_List *sub, std::string wrapping)
{
// Check every rhs selector against left hand list
for(size_t i = 0, L = sub->length(); i < L; ++i) {
Expand All @@ -1505,7 +1505,7 @@ namespace Sass {

// it's a superselector if every selector on the right side
// is a superselector of any one of the left side selectors
bool CommaSequence_Selector::is_superselector_of(SimpleSequence_Selector *sub, std::string wrapping)
bool Selector_List::is_superselector_of(SimpleSequence_Selector *sub, std::string wrapping)
{
// Check every lhs selector against right hand
for(size_t i = 0, L = length(); i < L; ++i) {
Expand All @@ -1516,7 +1516,7 @@ namespace Sass {

// it's a superselector if every selector on the right side
// is a superselector of any one of the left side selectors
bool CommaSequence_Selector::is_superselector_of(Sequence_Selector *sub, std::string wrapping)
bool Selector_List::is_superselector_of(Sequence_Selector *sub, std::string wrapping)
{
// Check every lhs selector against right hand
for(size_t i = 0, L = length(); i < L; ++i) {
Expand All @@ -1525,15 +1525,15 @@ namespace Sass {
return false;
}

CommaSequence_Selector* CommaSequence_Selector::unify_with(CommaSequence_Selector* rhs, Context& ctx) {
Selector_List* Selector_List::unify_with(Selector_List* rhs, Context& ctx) {
std::vector<Sequence_Selector*> unified_complex_selectors;
// Unify all of children with RHS's children, storing the results in `unified_complex_selectors`
for (size_t lhs_i = 0, lhs_L = length(); lhs_i < lhs_L; ++lhs_i) {
Sequence_Selector* seq1 = (*this)[lhs_i];
for(size_t rhs_i = 0, rhs_L = rhs->length(); rhs_i < rhs_L; ++rhs_i) {
Sequence_Selector* seq2 = (*rhs)[rhs_i];

CommaSequence_Selector* result = seq1->unify_with(seq2, ctx);
Selector_List* result = seq1->unify_with(seq2, ctx);
if( result ) {
for(size_t i = 0, L = result->length(); i < L; ++i) {
unified_complex_selectors.push_back( (*result)[i] );
Expand All @@ -1542,18 +1542,18 @@ namespace Sass {
}
}

// Creates the final CommaSequence_Selector by combining all the complex selectors
CommaSequence_Selector* final_result = SASS_MEMORY_NEW(ctx.mem, CommaSequence_Selector, pstate());
// Creates the final Selector_List by combining all the complex selectors
Selector_List* final_result = SASS_MEMORY_NEW(ctx.mem, Selector_List, pstate());
for (auto itr = unified_complex_selectors.begin(); itr != unified_complex_selectors.end(); ++itr) {
*final_result << *itr;
}
return final_result;
}

void CommaSequence_Selector::populate_extends(CommaSequence_Selector* extendee, Context& ctx, ExtensionSubsetMap& extends)
void Selector_List::populate_extends(Selector_List* extendee, Context& ctx, ExtensionSubsetMap& extends)
{

CommaSequence_Selector* extender = this;
Selector_List* extender = this;
for (auto complex_sel : extendee->elements()) {
Sequence_Selector* c = complex_sel;

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

bool Ruleset::is_invisible() const {
if (CommaSequence_Selector* sl = dynamic_cast<CommaSequence_Selector*>(selector())) {
if (Selector_List* sl = dynamic_cast<Selector_List*>(selector())) {
for (size_t i = 0, L = sl->length(); i < L; ++i)
if (!(*sl)[i]->has_placeholder()) return false;
}
Expand Down
Loading

0 comments on commit c94322e

Please sign in to comment.