Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit aa7386f

Browse files
committed
Cleanup CRTP implementation
1 parent 7cb696a commit aa7386f

19 files changed

+133
-172
lines changed

src/ast.hpp

Lines changed: 70 additions & 70 deletions
Large diffs are not rendered by default.

src/ast_def_macros.hpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ class LocalOption {
3535
LocalOption<size_t> cnt_##name(name, name + 1); \
3636
if (name > MAX_NESTING) throw Exception::NestingLimitError(pstate, traces); \
3737

38-
#define ATTACH_OPERATIONS()\
39-
virtual void perform(Operation<void>* op) { (*op)(this); }\
40-
virtual AST_Node_Ptr perform(Operation<AST_Node_Ptr>* op) { return (*op)(this); }\
41-
virtual Statement_Ptr perform(Operation<Statement_Ptr>* op) { return (*op)(this); }\
42-
virtual Expression_Ptr perform(Operation<Expression_Ptr>* op) { return (*op)(this); }\
43-
virtual Selector_Ptr perform(Operation<Selector_Ptr>* op) { return (*op)(this); }\
44-
virtual std::string perform(Operation<std::string>* op) { return (*op)(this); }\
45-
virtual union Sass_Value* perform(Operation<union Sass_Value*>* op) { return (*op)(this); }\
46-
virtual Value_Ptr perform(Operation<Value_Ptr>* op) { return (*op)(this); }
47-
4838
#define ADD_PROPERTY(type, name)\
4939
protected:\
5040
type name##_;\

src/check_nesting.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ namespace Sass {
132132
return i;
133133
}
134134

135-
Statement_Ptr CheckNesting::fallback_impl(Statement_Ptr s)
136-
{
137-
Block_Ptr b1 = Cast<Block>(s);
138-
Has_Block_Ptr b2 = Cast<Has_Block>(s);
139-
return b1 || b2 ? visit_children(s) : s;
140-
}
141-
142135
bool CheckNesting::should_visit(Statement_Ptr node)
143136
{
144137
if (!this->parent) return true;

src/check_nesting.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace Sass {
1313
Statement_Ptr parent;
1414
Definition_Ptr current_mixin_definition;
1515

16-
Statement_Ptr fallback_impl(Statement_Ptr);
1716
Statement_Ptr before(Statement_Ptr);
1817
Statement_Ptr visit_children(Statement_Ptr);
1918

@@ -27,11 +26,13 @@ namespace Sass {
2726

2827
template <typename U>
2928
Statement_Ptr fallback(U x) {
30-
Statement_Ptr n = Cast<Statement>(x);
31-
if (this->should_visit(n)) {
32-
return fallback_impl(n);
29+
Statement_Ptr s = Cast<Statement>(x);
30+
if (s && this->should_visit(s)) {
31+
Block_Ptr b1 = Cast<Block>(s);
32+
Has_Block_Ptr b2 = Cast<Has_Block>(s);
33+
if (b1 || b2) return visit_children(s);
3334
}
34-
return NULL;
35+
return s;
3536
}
3637

3738
private:

src/cssize.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,6 @@ namespace Sass {
509509
return flatten(result);
510510
}
511511

512-
Statement_Ptr Cssize::fallback_impl(AST_Node_Ptr n)
513-
{
514-
return static_cast<Statement_Ptr>(n);
515-
}
516-
517512
void Cssize::append_block(Block_Ptr b, Block_Ptr cur)
518513
{
519514
for (size_t i = 0, L = b->length(); i < L; ++i) {

src/cssize.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ namespace Sass {
1717
BlockStack block_stack;
1818
std::vector<Statement_Ptr> p_stack;
1919

20-
Statement_Ptr fallback_impl(AST_Node_Ptr n);
21-
2220
public:
2321
Cssize(Context&);
2422
~Cssize() { }
@@ -66,8 +64,10 @@ namespace Sass {
6664
List_Ptr merge_media_queries(Media_Block_Ptr, Media_Block_Ptr);
6765
Media_Query_Ptr merge_media_query(Media_Query_Ptr, Media_Query_Ptr);
6866

67+
// generic fallback
6968
template <typename U>
70-
Statement_Ptr fallback(U x) { return fallback_impl(x); }
69+
Statement_Ptr fallback(U x)
70+
{ return Cast<Statement>(x); }
7171

7272
void append_block(Block_Ptr, Block_Ptr);
7373
};

src/eval.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,11 +1467,6 @@ namespace Sass {
14671467
return 0;
14681468
}
14691469

1470-
inline Expression_Ptr Eval::fallback_impl(AST_Node_Ptr n)
1471-
{
1472-
return static_cast<Expression_Ptr>(n);
1473-
}
1474-
14751470
// All the binary helpers.
14761471

14771472
Expression_Ptr cval_to_astnode(union Sass_Value* v, Backtraces traces, ParserState pstate)

src/eval.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ namespace Sass {
1414

1515
class Eval : public Operation_CRTP<Expression_Ptr, Eval> {
1616

17-
private:
18-
Expression_Ptr fallback_impl(AST_Node_Ptr n);
19-
2017
public:
2118
Expand& exp;
2219
Context& ctx;
@@ -78,18 +75,23 @@ namespace Sass {
7875
Compound_Selector_Ptr operator()(Compound_Selector_Ptr);
7976
Simple_Selector_Ptr operator()(Simple_Selector_Ptr s);
8077
Wrapped_Selector_Ptr operator()(Wrapped_Selector_Ptr s);
78+
8179
// they don't have any specific implementation (yet)
82-
// Element_Selector_Ptr operator()(Element_Selector_Ptr s) { return s; };
83-
// Pseudo_Selector_Ptr operator()(Pseudo_Selector_Ptr s) { return s; };
84-
// Class_Selector_Ptr operator()(Class_Selector_Ptr s) { return s; };
85-
// Id_Selector_Ptr operator()(Id_Selector_Ptr s) { return s; };
86-
// Placeholder_Selector_Ptr operator()(Placeholder_Selector_Ptr s) { return s; };
80+
Id_Selector_Ptr operator()(Id_Selector_Ptr s) { return s; };
81+
Class_Selector_Ptr operator()(Class_Selector_Ptr s) { return s; };
82+
Pseudo_Selector_Ptr operator()(Pseudo_Selector_Ptr s) { return s; };
83+
Element_Selector_Ptr operator()(Element_Selector_Ptr s) { return s; };
84+
Attribute_Selector_Ptr operator()(Attribute_Selector_Ptr s) { return s; };
85+
Placeholder_Selector_Ptr operator()(Placeholder_Selector_Ptr s) { return s; };
86+
8787
// actual evaluated selectors
8888
Selector_List_Ptr operator()(Selector_Schema_Ptr);
8989
Expression_Ptr operator()(Parent_Selector_Ptr);
9090

91+
// generic fallback
9192
template <typename U>
92-
Expression_Ptr fallback(U x) { return fallback_impl(x); }
93+
Expression_Ptr fallback(U x)
94+
{ return Cast<Expression>(x); }
9395

9496
private:
9597
void interpolation(Context& ctx, std::string& res, Expression_Obj ex, bool into_quotes, bool was_itpl = false);

src/expand.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -792,15 +792,6 @@ namespace Sass {
792792
return trace.detach();
793793
}
794794

795-
// produce an error if something is not implemented
796-
inline Statement_Ptr Expand::fallback_impl(AST_Node_Ptr n)
797-
{
798-
std::string err =std:: string("`Expand` doesn't handle ") + typeid(*n).name();
799-
String_Quoted_Obj msg = SASS_MEMORY_NEW(String_Quoted, ParserState("[WARN]"), err);
800-
error("unknown internal error; please contact the LibSass maintainers", n->pstate(), traces);
801-
return SASS_MEMORY_NEW(Warning, ParserState("[WARN]"), msg);
802-
}
803-
804795
// process and add to last block on stack
805796
inline void Expand::append_block(Block_Ptr b)
806797
{

src/expand.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ namespace Sass {
3838

3939
Boolean_Obj bool_true;
4040

41-
Statement_Ptr fallback_impl(AST_Node_Ptr n);
42-
4341
private:
4442
void expand_selector_list(Selector_Obj, Selector_List_Obj extender);
4543

@@ -71,10 +69,8 @@ namespace Sass {
7169
Statement_Ptr operator()(Mixin_Call_Ptr);
7270
Statement_Ptr operator()(Content_Ptr);
7371

74-
template <typename U>
75-
Statement_Ptr fallback(U x) { return fallback_impl(x); }
76-
7772
void append_block(Block_Ptr);
73+
7874
};
7975

8076
}

0 commit comments

Comments
 (0)