@@ -807,7 +807,7 @@ namespace Sass {
807
807
return ns () < rhs.ns ();
808
808
}
809
809
810
- bool Wrapped_Selector::is_superselector_of (Wrapped_Selector_Obj sub)
810
+ bool Wrapped_Selector::is_superselector_of (Wrapped_Selector_Obj sub) const
811
811
{
812
812
if (this ->name () != sub->name ()) return false ;
813
813
if (this ->name () == " :current" ) return false ;
@@ -820,23 +820,23 @@ namespace Sass {
820
820
return false ;
821
821
}
822
822
823
- bool Compound_Selector::is_superselector_of (Selector_List_Obj rhs, std::string wrapped)
823
+ bool Compound_Selector::is_superselector_of (Selector_List_Obj rhs, std::string wrapped) const
824
824
{
825
825
for (Complex_Selector_Obj item : rhs->elements ()) {
826
826
if (is_superselector_of (item, wrapped)) return true ;
827
827
}
828
828
return false ;
829
829
}
830
830
831
- bool Compound_Selector::is_superselector_of (Complex_Selector_Obj rhs, std::string wrapped)
831
+ bool Compound_Selector::is_superselector_of (Complex_Selector_Obj rhs, std::string wrapped) const
832
832
{
833
833
if (rhs->head ()) return is_superselector_of (rhs->head (), wrapped);
834
834
return false ;
835
835
}
836
836
837
- bool Compound_Selector::is_superselector_of (Compound_Selector_Obj rhs, std::string wrapping)
837
+ bool Compound_Selector::is_superselector_of (Compound_Selector_Obj rhs, std::string wrapping) const
838
838
{
839
- Compound_Selector_Ptr lhs = this ;
839
+ Compound_Selector_Ptr_Const lhs = this ;
840
840
Simple_Selector_Ptr lbase = lhs->base ();
841
841
Simple_Selector_Ptr rbase = rhs->base ();
842
842
@@ -963,8 +963,8 @@ namespace Sass {
963
963
{
964
964
965
965
// get last tails (on the right side)
966
- Complex_Selector_Obj l_last = this ->last ();
967
- Complex_Selector_Obj r_last = other->last ();
966
+ Complex_Selector_Obj l_last = this ->mutable_last ();
967
+ Complex_Selector_Obj r_last = other->mutable_last ();
968
968
969
969
// check valid pointers (assertion)
970
970
SASS_ASSERT (l_last, " lhs is null" );
@@ -1059,21 +1059,21 @@ namespace Sass {
1059
1059
// there is no break?!
1060
1060
}
1061
1061
1062
- bool Complex_Selector::is_superselector_of (Compound_Selector_Obj rhs, std::string wrapping)
1062
+ bool Complex_Selector::is_superselector_of (Compound_Selector_Obj rhs, std::string wrapping) const
1063
1063
{
1064
1064
return last ()->head () && last ()->head ()->is_superselector_of (rhs, wrapping);
1065
1065
}
1066
1066
1067
- bool Complex_Selector::is_superselector_of (Complex_Selector_Obj rhs, std::string wrapping)
1067
+ bool Complex_Selector::is_superselector_of (Complex_Selector_Obj rhs, std::string wrapping) const
1068
1068
{
1069
- Complex_Selector_Ptr lhs = this ;
1069
+ Complex_Selector_Ptr_Const lhs = this ;
1070
1070
// check for selectors with leading or trailing combinators
1071
1071
if (!lhs->head () || !rhs->head ())
1072
1072
{ return false ; }
1073
- Complex_Selector_Obj l_innermost = lhs->innermost ();
1073
+ Complex_Selector_Ptr_Const l_innermost = lhs->last ();
1074
1074
if (l_innermost->combinator () != Complex_Selector::ANCESTOR_OF)
1075
1075
{ return false ; }
1076
- Complex_Selector_Obj r_innermost = rhs->innermost ();
1076
+ Complex_Selector_Ptr_Const r_innermost = rhs->last ();
1077
1077
if (r_innermost->combinator () != Complex_Selector::ANCESTOR_OF)
1078
1078
{ return false ; }
1079
1079
// more complex (i.e., longer) selectors are always more specific
@@ -1212,19 +1212,20 @@ namespace Sass {
1212
1212
// std::cerr << "has no or empty head\n";
1213
1213
}
1214
1214
1215
- if (last ()) {
1216
- if (last ()->combinator () != ANCESTOR_OF && c != ANCESTOR_OF) {
1215
+ Complex_Selector_Ptr last = mutable_last ();
1216
+ if (last) {
1217
+ if (last->combinator () != ANCESTOR_OF && c != ANCESTOR_OF) {
1217
1218
Complex_Selector_Ptr inter = SASS_MEMORY_NEW (Complex_Selector, pstate ());
1218
1219
inter->reference (r);
1219
1220
inter->combinator (c);
1220
1221
inter->tail (t);
1221
- last () ->tail (inter);
1222
+ last->tail (inter);
1222
1223
} else {
1223
- if (last () ->combinator () == ANCESTOR_OF) {
1224
- last () ->combinator (c);
1225
- last () ->reference (r);
1224
+ if (last->combinator () == ANCESTOR_OF) {
1225
+ last->combinator (c);
1226
+ last->reference (r);
1226
1227
}
1227
- last () ->tail (t);
1228
+ last->tail (t);
1228
1229
}
1229
1230
}
1230
1231
@@ -1413,16 +1414,16 @@ namespace Sass {
1413
1414
}
1414
1415
1415
1416
// return the last tail that is defined
1416
- Complex_Selector_Obj Complex_Selector::first ()
1417
+ Complex_Selector_Ptr_Const Complex_Selector::first () const
1417
1418
{
1418
1419
// declare variables used in loop
1419
- Complex_Selector_Obj cur = this ;
1420
- Compound_Selector_Obj head;
1420
+ Complex_Selector_Ptr_Const cur = this ;
1421
+ Compound_Selector_Ptr_Const head;
1421
1422
// processing loop
1422
1423
while (cur)
1423
1424
{
1424
1425
// get the head
1425
- head = cur->head_ ;
1426
+ head = cur->head_ . ptr () ;
1426
1427
// abort (and return) if it is not a parent selector
1427
1428
if (!head || head->length () != 1 || !Cast<Parent_Selector>((*head)[0 ])) {
1428
1429
break ;
@@ -1434,35 +1435,45 @@ namespace Sass {
1434
1435
return cur;
1435
1436
}
1436
1437
1438
+ Complex_Selector_Ptr Complex_Selector::mutable_first ()
1439
+ {
1440
+ return const_cast <Complex_Selector_Ptr>(first ());
1441
+ }
1442
+
1437
1443
// return the last tail that is defined
1438
- Complex_Selector_Obj Complex_Selector::last ()
1444
+ Complex_Selector_Ptr_Const Complex_Selector::last () const
1439
1445
{
1440
- Complex_Selector_Ptr cur = this ;
1441
- Complex_Selector_Ptr nxt = cur;
1446
+ Complex_Selector_Ptr_Const cur = this ;
1447
+ Complex_Selector_Ptr_Const nxt = cur;
1442
1448
// loop until last
1443
1449
while (nxt) {
1444
1450
cur = nxt;
1445
- nxt = cur->tail ();
1451
+ nxt = cur->tail_ . ptr ();
1446
1452
}
1447
1453
return cur;
1448
1454
}
1449
1455
1456
+ Complex_Selector_Ptr Complex_Selector::mutable_last ()
1457
+ {
1458
+ return const_cast <Complex_Selector_Ptr>(last ());
1459
+ }
1460
+
1450
1461
Complex_Selector::Combinator Complex_Selector::clear_innermost ()
1451
1462
{
1452
1463
Combinator c;
1453
1464
if (!tail () || tail ()->tail () == 0 )
1454
1465
{ c = combinator (); combinator (ANCESTOR_OF); tail (0 ); }
1455
1466
else
1456
- { c = tail () ->clear_innermost (); }
1467
+ { c = tail_ ->clear_innermost (); }
1457
1468
return c;
1458
1469
}
1459
1470
1460
1471
void Complex_Selector::set_innermost (Complex_Selector_Obj val, Combinator c)
1461
1472
{
1462
- if (!tail () )
1463
- { tail ( val) ; combinator (c); }
1473
+ if (!tail_ )
1474
+ { tail_ = val; combinator (c); }
1464
1475
else
1465
- { tail () ->set_innermost (val, c); }
1476
+ { tail_ ->set_innermost (val, c); }
1466
1477
}
1467
1478
1468
1479
void Complex_Selector::cloneChildren ()
@@ -1515,7 +1526,7 @@ namespace Sass {
1515
1526
}
1516
1527
}
1517
1528
1518
- size_t Wrapped_Selector::hash ()
1529
+ size_t Wrapped_Selector::hash () const
1519
1530
{
1520
1531
if (hash_ == 0 ) {
1521
1532
hash_combine (hash_, Simple_Selector::hash ());
@@ -1579,7 +1590,7 @@ namespace Sass {
1579
1590
1580
1591
// it's a superselector if every selector of the right side
1581
1592
// list is a superselector of the given left side selector
1582
- bool Complex_Selector::is_superselector_of (Selector_List_Obj sub, std::string wrapping)
1593
+ bool Complex_Selector::is_superselector_of (Selector_List_Obj sub, std::string wrapping) const
1583
1594
{
1584
1595
// Check every rhs selector against left hand list
1585
1596
for (size_t i = 0 , L = sub->length (); i < L; ++i) {
@@ -1590,7 +1601,7 @@ namespace Sass {
1590
1601
1591
1602
// it's a superselector if every selector of the right side
1592
1603
// list is a superselector of the given left side selector
1593
- bool Selector_List::is_superselector_of (Selector_List_Obj sub, std::string wrapping)
1604
+ bool Selector_List::is_superselector_of (Selector_List_Obj sub, std::string wrapping) const
1594
1605
{
1595
1606
// Check every rhs selector against left hand list
1596
1607
for (size_t i = 0 , L = sub->length (); i < L; ++i) {
@@ -1601,7 +1612,7 @@ namespace Sass {
1601
1612
1602
1613
// it's a superselector if every selector on the right side
1603
1614
// is a superselector of any one of the left side selectors
1604
- bool Selector_List::is_superselector_of (Compound_Selector_Obj sub, std::string wrapping)
1615
+ bool Selector_List::is_superselector_of (Compound_Selector_Obj sub, std::string wrapping) const
1605
1616
{
1606
1617
// Check every lhs selector against right hand
1607
1618
for (size_t i = 0 , L = length (); i < L; ++i) {
@@ -1612,7 +1623,7 @@ namespace Sass {
1612
1623
1613
1624
// it's a superselector if every selector on the right side
1614
1625
// is a superselector of any one of the left side selectors
1615
- bool Selector_List::is_superselector_of (Complex_Selector_Obj sub, std::string wrapping)
1626
+ bool Selector_List::is_superselector_of (Complex_Selector_Obj sub, std::string wrapping) const
1616
1627
{
1617
1628
// Check every lhs selector against right hand
1618
1629
for (size_t i = 0 , L = length (); i < L; ++i) {
@@ -1679,7 +1690,7 @@ namespace Sass {
1679
1690
}
1680
1691
};
1681
1692
1682
- void Compound_Selector::append (Simple_Selector_Ptr element)
1693
+ void Compound_Selector::append (Simple_Selector_Obj element)
1683
1694
{
1684
1695
Vectorized<Simple_Selector_Obj>::append (element);
1685
1696
pstate_.offset += element->pstate ().offset ;
@@ -2112,7 +2123,7 @@ namespace Sass {
2112
2123
catch (...) { throw ; }
2113
2124
}
2114
2125
2115
- size_t Function_Call::hash ()
2126
+ size_t Function_Call::hash () const
2116
2127
{
2117
2128
if (hash_ == 0 ) {
2118
2129
hash_ = std::hash<std::string>()(name ());
0 commit comments