Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup context usage and extend code #2313

Merged
merged 3 commits into from
Feb 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,14 @@ namespace Sass {
return false;
}

Compound_Selector_Ptr Compound_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
Compound_Selector_Ptr Compound_Selector::unify_with(Compound_Selector_Ptr rhs)
{
if (empty()) return rhs;
Compound_Selector_Obj unified = SASS_MEMORY_COPY(rhs);
for (size_t i = 0, L = length(); i < L; ++i)
{
if (unified.isNull()) break;
unified = at(i)->unify_with(unified, ctx);
unified = at(i)->unify_with(unified);
}
return unified.detach();
}
Expand Down Expand Up @@ -472,10 +472,10 @@ namespace Sass {
return false;
}

Compound_Selector_Ptr Simple_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
Compound_Selector_Ptr Simple_Selector::unify_with(Compound_Selector_Ptr rhs)
{
for (size_t i = 0, L = rhs->length(); i < L; ++i)
{ if (to_string(ctx.c_options) == rhs->at(i)->to_string(ctx.c_options)) return rhs; }
{ if (to_string() == rhs->at(i)->to_string()) return rhs; }

// check for pseudo elements because they are always last
size_t i, L;
Expand Down Expand Up @@ -505,7 +505,7 @@ namespace Sass {
return rhs;
}

Simple_Selector_Ptr Element_Selector::unify_with(Simple_Selector_Ptr rhs, Context& ctx)
Simple_Selector_Ptr Element_Selector::unify_with(Simple_Selector_Ptr rhs)
{
// check if ns can be extended
// true for no ns or universal
Expand Down Expand Up @@ -536,7 +536,7 @@ namespace Sass {
return this;
}

Compound_Selector_Ptr Element_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
Compound_Selector_Ptr Element_Selector::unify_with(Compound_Selector_Ptr rhs)
{
// TODO: handle namespaces

Expand All @@ -554,7 +554,7 @@ namespace Sass {
{
// if rhs is universal, just return this tagname + rhs's qualifiers
Element_Selector_Ptr ts = Cast<Element_Selector>(rhs_0);
rhs->at(0) = this->unify_with(ts, ctx);
rhs->at(0) = this->unify_with(ts);
return rhs;
}
else if (Cast<Class_Selector>(rhs_0) || Cast<Id_Selector>(rhs_0)) {
Expand All @@ -574,7 +574,7 @@ namespace Sass {
// if rhs is universal, just return this tagname + rhs's qualifiers
if (rhs_0->name() != "*" && rhs_0->ns() != "*" && rhs_0->name() != name()) return 0;
// otherwise create new compound and unify first simple selector
rhs->at(0) = this->unify_with(rhs_0, ctx);
rhs->at(0) = this->unify_with(rhs_0);
return rhs;

}
Expand All @@ -583,13 +583,13 @@ namespace Sass {
return rhs;
}

Compound_Selector_Ptr Class_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
Compound_Selector_Ptr Class_Selector::unify_with(Compound_Selector_Ptr rhs)
{
rhs->has_line_break(has_line_break());
return Simple_Selector::unify_with(rhs, ctx);
return Simple_Selector::unify_with(rhs);
}

Compound_Selector_Ptr Id_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
Compound_Selector_Ptr Id_Selector::unify_with(Compound_Selector_Ptr rhs)
{
for (size_t i = 0, L = rhs->length(); i < L; ++i)
{
Expand All @@ -598,10 +598,10 @@ namespace Sass {
}
}
rhs->has_line_break(has_line_break());
return Simple_Selector::unify_with(rhs, ctx);
return Simple_Selector::unify_with(rhs);
}

Compound_Selector_Ptr Pseudo_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
Compound_Selector_Ptr Pseudo_Selector::unify_with(Compound_Selector_Ptr rhs)
{
if (is_pseudo_element())
{
Expand All @@ -612,7 +612,7 @@ namespace Sass {
}
}
}
return Simple_Selector::unify_with(rhs, ctx);
return Simple_Selector::unify_with(rhs);
}

bool Attribute_Selector::operator< (const Attribute_Selector& rhs) const
Expand Down Expand Up @@ -913,7 +913,7 @@ namespace Sass {
0);
}

Selector_List_Ptr Complex_Selector::unify_with(Complex_Selector_Ptr other, Context& ctx)
Selector_List_Ptr Complex_Selector::unify_with(Complex_Selector_Ptr other)
{

// get last tails (on the right side)
Expand All @@ -939,7 +939,7 @@ namespace Sass {
SASS_ASSERT(r_last_head, "rhs head is null");

// get the unification of the last compound selectors
Compound_Selector_Obj unified = r_last_head->unify_with(l_last_head, ctx);
Compound_Selector_Obj unified = r_last_head->unify_with(l_last_head);

// abort if we could not unify heads
if (unified == 0) return 0;
Expand All @@ -956,25 +956,25 @@ namespace Sass {
}

// create nodes from both selectors
Node lhsNode = complexSelectorToNode(this, ctx);
Node rhsNode = complexSelectorToNode(other, ctx);
Node lhsNode = complexSelectorToNode(this);
Node rhsNode = complexSelectorToNode(other);

// overwrite universal base
if (!is_universal)
{
// create some temporaries to convert to node
Complex_Selector_Obj fake = unified->to_complex();
Node unified_node = complexSelectorToNode(fake, ctx);
Node unified_node = complexSelectorToNode(fake);
// add to permutate the list?
rhsNode.plus(unified_node);
}

// do some magic we inherit from node and extend
Node node = Extend::subweave(lhsNode, rhsNode, ctx);
Node node = subweave(lhsNode, rhsNode);
Selector_List_Ptr result = SASS_MEMORY_NEW(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->append(nodeToComplexSelector(Node::naiveTrim(*it, ctx), ctx)); }
{ result->append(nodeToComplexSelector(Node::naiveTrim(*it))); }

// only return if list has some entries
return result->length() ? result : 0;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ namespace Sass {
// check if we need to append some headers
// then we need to check for the combinator
// only then we can safely set the new tail
void Complex_Selector::append(Context& ctx, Complex_Selector_Obj ss)
void Complex_Selector::append(Complex_Selector_Obj ss)
{

Complex_Selector_Obj t = ss->tail();
Expand Down Expand Up @@ -1196,21 +1196,21 @@ namespace Sass {
return list;
}

Selector_List_Ptr Selector_List::resolve_parent_refs(Context& ctx, std::vector<Selector_List_Obj>& pstack, bool implicit_parent)
Selector_List_Ptr Selector_List::resolve_parent_refs(std::vector<Selector_List_Obj>& pstack, bool implicit_parent)
{
if (!this->has_parent_ref()) return this;
Selector_List_Ptr ss = SASS_MEMORY_NEW(Selector_List, pstate());
Selector_List_Ptr ps = pstack.back();
for (size_t pi = 0, pL = ps->length(); pi < pL; ++pi) {
for (size_t si = 0, sL = this->length(); si < sL; ++si) {
Selector_List_Obj rv = at(si)->resolve_parent_refs(ctx, pstack, implicit_parent);
Selector_List_Obj rv = at(si)->resolve_parent_refs(pstack, implicit_parent);
ss->concat(rv);
}
}
return ss;
}

Selector_List_Ptr Complex_Selector::resolve_parent_refs(Context& ctx, std::vector<Selector_List_Obj>& pstack, bool implicit_parent)
Selector_List_Ptr Complex_Selector::resolve_parent_refs(std::vector<Selector_List_Obj>& pstack, bool implicit_parent)
{
Complex_Selector_Obj tail = this->tail();
Compound_Selector_Obj head = this->head();
Expand All @@ -1223,7 +1223,7 @@ namespace Sass {
}

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

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

Expand Down Expand Up @@ -1269,7 +1269,7 @@ namespace Sass {
// keep old parser state
s->pstate(pstate());
// append new tail
s->append(ctx, ss);
s->append(ss);
retval->append(s);
}
}
Expand Down Expand Up @@ -1307,7 +1307,7 @@ namespace Sass {
// keep old parser state
s->pstate(pstate());
// append new tail
s->append(ctx, ss);
s->append(ss);
retval->append(s);
}
}
Expand Down Expand Up @@ -1338,13 +1338,13 @@ namespace Sass {
}
// no parent selector in head
else {
retval = this->tails(ctx, tails);
retval = this->tails(tails);
}

for (Simple_Selector_Obj ss : head->elements()) {
if (Wrapped_Selector_Ptr ws = Cast<Wrapped_Selector>(ss)) {
if (Selector_List_Ptr sl = Cast<Selector_List>(ws->selector())) {
if (parents) ws->selector(sl->resolve_parent_refs(ctx, pstack, implicit_parent));
if (parents) ws->selector(sl->resolve_parent_refs(pstack, implicit_parent));
}
}
}
Expand All @@ -1354,14 +1354,14 @@ namespace Sass {
}
// has no head
else {
return this->tails(ctx, tails);
return this->tails(tails);
}

// unreachable
return 0;
}

Selector_List_Ptr Complex_Selector::tails(Context& ctx, Selector_List_Ptr tails)
Selector_List_Ptr Complex_Selector::tails(Selector_List_Ptr tails)
{
Selector_List_Ptr rv = SASS_MEMORY_NEW(Selector_List, pstate_);
if (tails && tails->length()) {
Expand Down Expand Up @@ -1586,15 +1586,15 @@ namespace Sass {
return false;
}

Selector_List_Ptr Selector_List::unify_with(Selector_List_Ptr rhs, Context& ctx) {
Selector_List_Ptr Selector_List::unify_with(Selector_List_Ptr rhs) {
std::vector<Complex_Selector_Obj> 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) {
Complex_Selector_Obj seq1 = (*this)[lhs_i];
for(size_t rhs_i = 0, rhs_L = rhs->length(); rhs_i < rhs_L; ++rhs_i) {
Complex_Selector_Ptr seq2 = rhs->at(rhs_i);

Selector_List_Obj result = seq1->unify_with(seq2, ctx);
Selector_List_Obj result = seq1->unify_with(seq2);
if( result ) {
for(size_t i = 0, L = result->length(); i < L; ++i) {
unified_complex_selectors.push_back( (*result)[i] );
Expand All @@ -1611,7 +1611,7 @@ namespace Sass {
return final_result;
}

void Selector_List::populate_extends(Selector_List_Obj extendee, Context& ctx, Subset_Map& extends)
void Selector_List::populate_extends(Selector_List_Obj extendee, Subset_Map& extends)
{

Selector_List_Ptr extender = this;
Expand Down Expand Up @@ -1650,7 +1650,7 @@ namespace Sass {
pstate_.offset += element->pstate().offset;
}

Compound_Selector_Ptr Compound_Selector::minus(Compound_Selector_Ptr rhs, Context& ctx)
Compound_Selector_Ptr Compound_Selector::minus(Compound_Selector_Ptr rhs)
{
Compound_Selector_Ptr result = SASS_MEMORY_NEW(Compound_Selector, pstate());
// result->has_parent_reference(has_parent_reference());
Expand All @@ -1659,10 +1659,10 @@ namespace Sass {
for (size_t i = 0, L = length(); i < L; ++i)
{
bool found = false;
std::string thisSelector((*this)[i]->to_string(ctx.c_options));
std::string thisSelector((*this)[i]->to_string());
for (size_t j = 0, M = rhs->length(); j < M; ++j)
{
if (thisSelector == (*rhs)[j]->to_string(ctx.c_options))
if (thisSelector == (*rhs)[j]->to_string())
{
found = true;
break;
Expand All @@ -1674,7 +1674,7 @@ namespace Sass {
return result;
}

void Compound_Selector::mergeSources(ComplexSelectorSet& sources, Context& ctx)
void Compound_Selector::mergeSources(ComplexSelectorSet& sources)
{
for (ComplexSelectorSet::iterator iterator = sources.begin(), endIterator = sources.end(); iterator != endIterator; ++iterator) {
this->sources_.insert(SASS_MEMORY_CLONE(*iterator));
Expand Down Expand Up @@ -2343,7 +2343,7 @@ namespace Sass {
//////////////////////////////////////////////////////////////////////////////////////////
// Convert map to (key, value) list.
//////////////////////////////////////////////////////////////////////////////////////////
List_Obj Map::to_list(Context& ctx, ParserState& pstate) {
List_Obj Map::to_list(ParserState& pstate) {
List_Obj ret = SASS_MEMORY_NEW(List, pstate, length(), SASS_COMMA);

for (auto key : keys()) {
Expand Down
Loading