/src/libsass/src/remove_placeholders.cpp
Line | Count | Source |
1 | | // sass.hpp must go before all system headers to get the |
2 | | // __EXTENSIONS__ fix on Solaris. |
3 | | #include "sass.hpp" |
4 | | #include "ast.hpp" |
5 | | |
6 | | #include "remove_placeholders.hpp" |
7 | | |
8 | | namespace Sass { |
9 | | |
10 | | Remove_Placeholders::Remove_Placeholders() |
11 | 4 | { } |
12 | | |
13 | 4 | void Remove_Placeholders::operator()(Block* b) { |
14 | 5 | for (size_t i = 0, L = b->length(); i < L; ++i) { |
15 | 1 | if (b->get(i)) b->get(i)->perform(this); |
16 | 1 | } |
17 | 4 | } |
18 | | |
19 | | void Remove_Placeholders::remove_placeholders(SimpleSelector* simple) |
20 | 1 | { |
21 | 1 | if (PseudoSelector * pseudo = simple->getPseudoSelector()) { |
22 | 0 | if (pseudo->selector()) remove_placeholders(pseudo->selector()); |
23 | 0 | } |
24 | 1 | } |
25 | | |
26 | | void Remove_Placeholders::remove_placeholders(CompoundSelector* compound) |
27 | 1 | { |
28 | 2 | for (size_t i = 0, L = compound->length(); i < L; ++i) { |
29 | 1 | if (compound->get(i)) remove_placeholders(compound->get(i)); |
30 | 1 | } |
31 | 1 | listEraseItemIf(compound->elements(), listIsEmpty<SimpleSelector>); |
32 | 1 | } |
33 | | |
34 | | void Remove_Placeholders::remove_placeholders(ComplexSelector* complex) |
35 | 1 | { |
36 | 1 | if (complex->has_placeholder()) { |
37 | 0 | complex->clear(); // remove all |
38 | 0 | } |
39 | 1 | else { |
40 | 2 | for (size_t i = 0, L = complex->length(); i < L; ++i) { |
41 | 1 | if (CompoundSelector * compound = complex->get(i)->getCompound()) { |
42 | 1 | if (compound) remove_placeholders(compound); |
43 | 1 | } |
44 | 1 | } |
45 | 1 | listEraseItemIf(complex->elements(), listIsEmpty<SelectorComponent>); |
46 | 1 | } |
47 | 1 | } |
48 | | |
49 | | SelectorList* Remove_Placeholders::remove_placeholders(SelectorList* sl) |
50 | 1 | { |
51 | 2 | for (size_t i = 0, L = sl->length(); i < L; ++i) { |
52 | 1 | if (sl->get(i)) remove_placeholders(sl->get(i)); |
53 | 1 | } |
54 | 1 | listEraseItemIf(sl->elements(), listIsEmpty<ComplexSelector>); |
55 | 1 | return sl; |
56 | 1 | } |
57 | | |
58 | | void Remove_Placeholders::operator()(CssMediaRule* rule) |
59 | 0 | { |
60 | 0 | if (rule->block()) operator()(rule->block()); |
61 | 0 | } |
62 | | |
63 | | void Remove_Placeholders::operator()(StyleRule* r) |
64 | 1 | { |
65 | 1 | if (SelectorListObj sl = r->selector()) { |
66 | | // Set the new placeholder selector list |
67 | 1 | r->selector((remove_placeholders(sl))); |
68 | 1 | } |
69 | | // Iterate into child blocks |
70 | 1 | Block_Obj b = r->block(); |
71 | 2 | for (size_t i = 0, L = b->length(); i < L; ++i) { |
72 | 1 | if (b->get(i)) { b->get(i)->perform(this); } |
73 | 1 | } |
74 | 1 | } |
75 | | |
76 | | void Remove_Placeholders::operator()(SupportsRule* m) |
77 | 0 | { |
78 | 0 | if (m->block()) operator()(m->block()); |
79 | 0 | } |
80 | | |
81 | | void Remove_Placeholders::operator()(AtRule* a) |
82 | 0 | { |
83 | 0 | if (a->block()) a->block()->perform(this); |
84 | 0 | } |
85 | | |
86 | | } |