Skip to content

Commit 10085f6

Browse files
authored
Merge pull request #2300 from mgreter/refactor/selector-schema
Refactor selector list and schema handling
2 parents c6e8936 + 39e1c0e commit 10085f6

File tree

7 files changed

+153
-122
lines changed

7 files changed

+153
-122
lines changed

src/ast.cpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "ast.hpp"
33
#include "context.hpp"
44
#include "node.hpp"
5+
#include "eval.hpp"
56
#include "extend.hpp"
67
#include "emitter.hpp"
78
#include "color_maps.hpp"
@@ -126,29 +127,29 @@ namespace Sass {
126127
return length() < rhs.length();
127128
}
128129

129-
bool Compound_Selector::has_parent_ref()
130+
bool Compound_Selector::has_parent_ref() const
130131
{
131132
for (Simple_Selector_Obj s : *this) {
132133
if (s && s->has_parent_ref()) return true;
133134
}
134135
return false;
135136
}
136137

137-
bool Compound_Selector::has_real_parent_ref()
138+
bool Compound_Selector::has_real_parent_ref() const
138139
{
139140
for (Simple_Selector_Obj s : *this) {
140141
if (s && s->has_real_parent_ref()) return true;
141142
}
142143
return false;
143144
}
144145

145-
bool Complex_Selector::has_parent_ref()
146+
bool Complex_Selector::has_parent_ref() const
146147
{
147148
return (head() && head()->has_parent_ref()) ||
148149
(tail() && tail()->has_parent_ref());
149150
}
150151

151-
bool Complex_Selector::has_real_parent_ref()
152+
bool Complex_Selector::has_real_parent_ref() const
152153
{
153154
return (head() && head()->has_real_parent_ref()) ||
154155
(tail() && tail()->has_real_parent_ref());
@@ -1185,7 +1186,14 @@ namespace Sass {
11851186
}
11861187
}
11871188

1189+
}
11881190

1191+
Selector_List_Obj Selector_List::eval(Eval& eval)
1192+
{
1193+
Selector_List_Obj list = schema() ?
1194+
eval(schema()) : eval(this);
1195+
list->schema(schema());
1196+
return list;
11891197
}
11901198

11911199
Selector_List_Ptr Selector_List::resolve_parent_refs(Context& ctx, std::vector<Selector_List_Obj>& pstack, bool implicit_parent)
@@ -1472,31 +1480,55 @@ namespace Sass {
14721480
}
14731481
}
14741482

1475-
bool Selector_List::has_parent_ref()
1483+
size_t Wrapped_Selector::hash()
1484+
{
1485+
if (hash_ == 0) {
1486+
hash_combine(hash_, Simple_Selector::hash());
1487+
if (selector_) hash_combine(hash_, selector_->hash());
1488+
}
1489+
return hash_;
1490+
}
1491+
bool Wrapped_Selector::has_parent_ref() const {
1492+
// if (has_reference()) return true;
1493+
if (!selector()) return false;
1494+
return selector()->has_parent_ref();
1495+
}
1496+
bool Wrapped_Selector::has_real_parent_ref() const {
1497+
// if (has_reference()) return true;
1498+
if (!selector()) return false;
1499+
return selector()->has_real_parent_ref();
1500+
}
1501+
unsigned long Wrapped_Selector::specificity() const
1502+
{
1503+
return selector_ ? selector_->specificity() : 0;
1504+
}
1505+
1506+
1507+
bool Selector_List::has_parent_ref() const
14761508
{
14771509
for (Complex_Selector_Obj s : elements()) {
14781510
if (s && s->has_parent_ref()) return true;
14791511
}
14801512
return false;
14811513
}
14821514

1483-
bool Selector_List::has_real_parent_ref()
1515+
bool Selector_List::has_real_parent_ref() const
14841516
{
14851517
for (Complex_Selector_Obj s : elements()) {
14861518
if (s && s->has_real_parent_ref()) return true;
14871519
}
14881520
return false;
14891521
}
14901522

1491-
bool Selector_Schema::has_parent_ref()
1523+
bool Selector_Schema::has_parent_ref() const
14921524
{
14931525
if (String_Schema_Obj schema = Cast<String_Schema>(contents())) {
14941526
return schema->length() > 0 && Cast<Parent_Selector>(schema->at(0)) != NULL;
14951527
}
14961528
return false;
14971529
}
14981530

1499-
bool Selector_Schema::has_real_parent_ref()
1531+
bool Selector_Schema::has_real_parent_ref() const
15001532
{
15011533
if (String_Schema_Obj schema = Cast<String_Schema>(contents())) {
15021534
Parent_Selector_Obj p = Cast<Parent_Selector>(schema->at(0));

0 commit comments

Comments
 (0)