Skip to content

Commit b31cf55

Browse files
authored
Merge pull request #2313 from sass/cleanup/ctx-and-extend
Cleanup context usage and extend code
2 parents 27437bc + aea1ffb commit b31cf55

File tree

13 files changed

+292
-313
lines changed

13 files changed

+292
-313
lines changed

src/ast.cpp

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,14 @@ namespace Sass {
296296
return false;
297297
}
298298

299-
Compound_Selector_Ptr Compound_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
299+
Compound_Selector_Ptr Compound_Selector::unify_with(Compound_Selector_Ptr rhs)
300300
{
301301
if (empty()) return rhs;
302302
Compound_Selector_Obj unified = SASS_MEMORY_COPY(rhs);
303303
for (size_t i = 0, L = length(); i < L; ++i)
304304
{
305305
if (unified.isNull()) break;
306-
unified = at(i)->unify_with(unified, ctx);
306+
unified = at(i)->unify_with(unified);
307307
}
308308
return unified.detach();
309309
}
@@ -472,10 +472,10 @@ namespace Sass {
472472
return false;
473473
}
474474

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

480480
// check for pseudo elements because they are always last
481481
size_t i, L;
@@ -505,7 +505,7 @@ namespace Sass {
505505
return rhs;
506506
}
507507

508-
Simple_Selector_Ptr Element_Selector::unify_with(Simple_Selector_Ptr rhs, Context& ctx)
508+
Simple_Selector_Ptr Element_Selector::unify_with(Simple_Selector_Ptr rhs)
509509
{
510510
// check if ns can be extended
511511
// true for no ns or universal
@@ -536,7 +536,7 @@ namespace Sass {
536536
return this;
537537
}
538538

539-
Compound_Selector_Ptr Element_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
539+
Compound_Selector_Ptr Element_Selector::unify_with(Compound_Selector_Ptr rhs)
540540
{
541541
// TODO: handle namespaces
542542

@@ -554,7 +554,7 @@ namespace Sass {
554554
{
555555
// if rhs is universal, just return this tagname + rhs's qualifiers
556556
Element_Selector_Ptr ts = Cast<Element_Selector>(rhs_0);
557-
rhs->at(0) = this->unify_with(ts, ctx);
557+
rhs->at(0) = this->unify_with(ts);
558558
return rhs;
559559
}
560560
else if (Cast<Class_Selector>(rhs_0) || Cast<Id_Selector>(rhs_0)) {
@@ -574,7 +574,7 @@ namespace Sass {
574574
// if rhs is universal, just return this tagname + rhs's qualifiers
575575
if (rhs_0->name() != "*" && rhs_0->ns() != "*" && rhs_0->name() != name()) return 0;
576576
// otherwise create new compound and unify first simple selector
577-
rhs->at(0) = this->unify_with(rhs_0, ctx);
577+
rhs->at(0) = this->unify_with(rhs_0);
578578
return rhs;
579579

580580
}
@@ -583,13 +583,13 @@ namespace Sass {
583583
return rhs;
584584
}
585585

586-
Compound_Selector_Ptr Class_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
586+
Compound_Selector_Ptr Class_Selector::unify_with(Compound_Selector_Ptr rhs)
587587
{
588588
rhs->has_line_break(has_line_break());
589-
return Simple_Selector::unify_with(rhs, ctx);
589+
return Simple_Selector::unify_with(rhs);
590590
}
591591

592-
Compound_Selector_Ptr Id_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
592+
Compound_Selector_Ptr Id_Selector::unify_with(Compound_Selector_Ptr rhs)
593593
{
594594
for (size_t i = 0, L = rhs->length(); i < L; ++i)
595595
{
@@ -598,10 +598,10 @@ namespace Sass {
598598
}
599599
}
600600
rhs->has_line_break(has_line_break());
601-
return Simple_Selector::unify_with(rhs, ctx);
601+
return Simple_Selector::unify_with(rhs);
602602
}
603603

604-
Compound_Selector_Ptr Pseudo_Selector::unify_with(Compound_Selector_Ptr rhs, Context& ctx)
604+
Compound_Selector_Ptr Pseudo_Selector::unify_with(Compound_Selector_Ptr rhs)
605605
{
606606
if (is_pseudo_element())
607607
{
@@ -612,7 +612,7 @@ namespace Sass {
612612
}
613613
}
614614
}
615-
return Simple_Selector::unify_with(rhs, ctx);
615+
return Simple_Selector::unify_with(rhs);
616616
}
617617

618618
bool Attribute_Selector::operator< (const Attribute_Selector& rhs) const
@@ -913,7 +913,7 @@ namespace Sass {
913913
0);
914914
}
915915

916-
Selector_List_Ptr Complex_Selector::unify_with(Complex_Selector_Ptr other, Context& ctx)
916+
Selector_List_Ptr Complex_Selector::unify_with(Complex_Selector_Ptr other)
917917
{
918918

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

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

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

958958
// create nodes from both selectors
959-
Node lhsNode = complexSelectorToNode(this, ctx);
960-
Node rhsNode = complexSelectorToNode(other, ctx);
959+
Node lhsNode = complexSelectorToNode(this);
960+
Node rhsNode = complexSelectorToNode(other);
961961

962962
// overwrite universal base
963963
if (!is_universal)
964964
{
965965
// create some temporaries to convert to node
966966
Complex_Selector_Obj fake = unified->to_complex();
967-
Node unified_node = complexSelectorToNode(fake, ctx);
967+
Node unified_node = complexSelectorToNode(fake);
968968
// add to permutate the list?
969969
rhsNode.plus(unified_node);
970970
}
971971

972972
// do some magic we inherit from node and extend
973-
Node node = Extend::subweave(lhsNode, rhsNode, ctx);
973+
Node node = subweave(lhsNode, rhsNode);
974974
Selector_List_Ptr result = SASS_MEMORY_NEW(Selector_List, pstate());
975975
NodeDequePtr col = node.collection(); // move from collection to list
976976
for (NodeDeque::iterator it = col->begin(), end = col->end(); it != end; it++)
977-
{ result->append(nodeToComplexSelector(Node::naiveTrim(*it, ctx), ctx)); }
977+
{ result->append(nodeToComplexSelector(Node::naiveTrim(*it))); }
978978

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

11161116
Complex_Selector_Obj t = ss->tail();
@@ -1196,21 +1196,21 @@ namespace Sass {
11961196
return list;
11971197
}
11981198

1199-
Selector_List_Ptr Selector_List::resolve_parent_refs(Context& ctx, std::vector<Selector_List_Obj>& pstack, bool implicit_parent)
1199+
Selector_List_Ptr Selector_List::resolve_parent_refs(std::vector<Selector_List_Obj>& pstack, bool implicit_parent)
12001200
{
12011201
if (!this->has_parent_ref()) return this;
12021202
Selector_List_Ptr ss = SASS_MEMORY_NEW(Selector_List, pstate());
12031203
Selector_List_Ptr ps = pstack.back();
12041204
for (size_t pi = 0, pL = ps->length(); pi < pL; ++pi) {
12051205
for (size_t si = 0, sL = this->length(); si < sL; ++si) {
1206-
Selector_List_Obj rv = at(si)->resolve_parent_refs(ctx, pstack, implicit_parent);
1206+
Selector_List_Obj rv = at(si)->resolve_parent_refs(pstack, implicit_parent);
12071207
ss->concat(rv);
12081208
}
12091209
}
12101210
return ss;
12111211
}
12121212

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

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

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

@@ -1269,7 +1269,7 @@ namespace Sass {
12691269
// keep old parser state
12701270
s->pstate(pstate());
12711271
// append new tail
1272-
s->append(ctx, ss);
1272+
s->append(ss);
12731273
retval->append(s);
12741274
}
12751275
}
@@ -1307,7 +1307,7 @@ namespace Sass {
13071307
// keep old parser state
13081308
s->pstate(pstate());
13091309
// append new tail
1310-
s->append(ctx, ss);
1310+
s->append(ss);
13111311
retval->append(s);
13121312
}
13131313
}
@@ -1338,13 +1338,13 @@ namespace Sass {
13381338
}
13391339
// no parent selector in head
13401340
else {
1341-
retval = this->tails(ctx, tails);
1341+
retval = this->tails(tails);
13421342
}
13431343

13441344
for (Simple_Selector_Obj ss : head->elements()) {
13451345
if (Wrapped_Selector_Ptr ws = Cast<Wrapped_Selector>(ss)) {
13461346
if (Selector_List_Ptr sl = Cast<Selector_List>(ws->selector())) {
1347-
if (parents) ws->selector(sl->resolve_parent_refs(ctx, pstack, implicit_parent));
1347+
if (parents) ws->selector(sl->resolve_parent_refs(pstack, implicit_parent));
13481348
}
13491349
}
13501350
}
@@ -1354,14 +1354,14 @@ namespace Sass {
13541354
}
13551355
// has no head
13561356
else {
1357-
return this->tails(ctx, tails);
1357+
return this->tails(tails);
13581358
}
13591359

13601360
// unreachable
13611361
return 0;
13621362
}
13631363

1364-
Selector_List_Ptr Complex_Selector::tails(Context& ctx, Selector_List_Ptr tails)
1364+
Selector_List_Ptr Complex_Selector::tails(Selector_List_Ptr tails)
13651365
{
13661366
Selector_List_Ptr rv = SASS_MEMORY_NEW(Selector_List, pstate_);
13671367
if (tails && tails->length()) {
@@ -1586,15 +1586,15 @@ namespace Sass {
15861586
return false;
15871587
}
15881588

1589-
Selector_List_Ptr Selector_List::unify_with(Selector_List_Ptr rhs, Context& ctx) {
1589+
Selector_List_Ptr Selector_List::unify_with(Selector_List_Ptr rhs) {
15901590
std::vector<Complex_Selector_Obj> unified_complex_selectors;
15911591
// Unify all of children with RHS's children, storing the results in `unified_complex_selectors`
15921592
for (size_t lhs_i = 0, lhs_L = length(); lhs_i < lhs_L; ++lhs_i) {
15931593
Complex_Selector_Obj seq1 = (*this)[lhs_i];
15941594
for(size_t rhs_i = 0, rhs_L = rhs->length(); rhs_i < rhs_L; ++rhs_i) {
15951595
Complex_Selector_Ptr seq2 = rhs->at(rhs_i);
15961596

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

1614-
void Selector_List::populate_extends(Selector_List_Obj extendee, Context& ctx, Subset_Map& extends)
1614+
void Selector_List::populate_extends(Selector_List_Obj extendee, Subset_Map& extends)
16151615
{
16161616

16171617
Selector_List_Ptr extender = this;
@@ -1650,7 +1650,7 @@ namespace Sass {
16501650
pstate_.offset += element->pstate().offset;
16511651
}
16521652

1653-
Compound_Selector_Ptr Compound_Selector::minus(Compound_Selector_Ptr rhs, Context& ctx)
1653+
Compound_Selector_Ptr Compound_Selector::minus(Compound_Selector_Ptr rhs)
16541654
{
16551655
Compound_Selector_Ptr result = SASS_MEMORY_NEW(Compound_Selector, pstate());
16561656
// result->has_parent_reference(has_parent_reference());
@@ -1659,10 +1659,10 @@ namespace Sass {
16591659
for (size_t i = 0, L = length(); i < L; ++i)
16601660
{
16611661
bool found = false;
1662-
std::string thisSelector((*this)[i]->to_string(ctx.c_options));
1662+
std::string thisSelector((*this)[i]->to_string());
16631663
for (size_t j = 0, M = rhs->length(); j < M; ++j)
16641664
{
1665-
if (thisSelector == (*rhs)[j]->to_string(ctx.c_options))
1665+
if (thisSelector == (*rhs)[j]->to_string())
16661666
{
16671667
found = true;
16681668
break;
@@ -1674,7 +1674,7 @@ namespace Sass {
16741674
return result;
16751675
}
16761676

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

23492349
for (auto key : keys()) {

0 commit comments

Comments
 (0)