sassc4 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.gitmodules +3 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +97 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +80 -0
- data/Rakefile +51 -0
- data/ext/depend +4 -0
- data/ext/extconf.rb +92 -0
- data/ext/libsass/VERSION +1 -0
- data/ext/libsass/contrib/plugin.cpp +60 -0
- data/ext/libsass/include/sass/base.h +97 -0
- data/ext/libsass/include/sass/context.h +174 -0
- data/ext/libsass/include/sass/functions.h +139 -0
- data/ext/libsass/include/sass/values.h +145 -0
- data/ext/libsass/include/sass/version.h +12 -0
- data/ext/libsass/include/sass.h +15 -0
- data/ext/libsass/include/sass2scss.h +120 -0
- data/ext/libsass/src/MurmurHash2.hpp +91 -0
- data/ext/libsass/src/ast.cpp +953 -0
- data/ext/libsass/src/ast.hpp +1064 -0
- data/ext/libsass/src/ast2c.cpp +80 -0
- data/ext/libsass/src/ast2c.hpp +39 -0
- data/ext/libsass/src/ast_def_macros.hpp +140 -0
- data/ext/libsass/src/ast_fwd_decl.cpp +31 -0
- data/ext/libsass/src/ast_fwd_decl.hpp +274 -0
- data/ext/libsass/src/ast_helpers.hpp +316 -0
- data/ext/libsass/src/ast_sel_cmp.cpp +396 -0
- data/ext/libsass/src/ast_sel_super.cpp +539 -0
- data/ext/libsass/src/ast_sel_unify.cpp +275 -0
- data/ext/libsass/src/ast_sel_weave.cpp +616 -0
- data/ext/libsass/src/ast_selectors.cpp +1070 -0
- data/ext/libsass/src/ast_selectors.hpp +523 -0
- data/ext/libsass/src/ast_supports.cpp +114 -0
- data/ext/libsass/src/ast_supports.hpp +121 -0
- data/ext/libsass/src/ast_values.cpp +1154 -0
- data/ext/libsass/src/ast_values.hpp +498 -0
- data/ext/libsass/src/b64/cencode.h +32 -0
- data/ext/libsass/src/b64/encode.h +79 -0
- data/ext/libsass/src/backtrace.cpp +50 -0
- data/ext/libsass/src/backtrace.hpp +29 -0
- data/ext/libsass/src/base64vlq.cpp +47 -0
- data/ext/libsass/src/base64vlq.hpp +30 -0
- data/ext/libsass/src/bind.cpp +312 -0
- data/ext/libsass/src/bind.hpp +15 -0
- data/ext/libsass/src/c2ast.cpp +64 -0
- data/ext/libsass/src/c2ast.hpp +14 -0
- data/ext/libsass/src/c99func.c +54 -0
- data/ext/libsass/src/cencode.c +106 -0
- data/ext/libsass/src/check_nesting.cpp +393 -0
- data/ext/libsass/src/check_nesting.hpp +70 -0
- data/ext/libsass/src/color_maps.cpp +652 -0
- data/ext/libsass/src/color_maps.hpp +323 -0
- data/ext/libsass/src/color_spaces.cpp +241 -0
- data/ext/libsass/src/color_spaces.hpp +227 -0
- data/ext/libsass/src/constants.cpp +199 -0
- data/ext/libsass/src/constants.hpp +200 -0
- data/ext/libsass/src/context.cpp +870 -0
- data/ext/libsass/src/context.hpp +140 -0
- data/ext/libsass/src/cssize.cpp +521 -0
- data/ext/libsass/src/cssize.hpp +71 -0
- data/ext/libsass/src/dart_helpers.hpp +199 -0
- data/ext/libsass/src/debug.hpp +43 -0
- data/ext/libsass/src/debugger.hpp +964 -0
- data/ext/libsass/src/emitter.cpp +297 -0
- data/ext/libsass/src/emitter.hpp +101 -0
- data/ext/libsass/src/environment.cpp +260 -0
- data/ext/libsass/src/environment.hpp +124 -0
- data/ext/libsass/src/error_handling.cpp +239 -0
- data/ext/libsass/src/error_handling.hpp +248 -0
- data/ext/libsass/src/eval.cpp +1543 -0
- data/ext/libsass/src/eval.hpp +110 -0
- data/ext/libsass/src/eval_selectors.cpp +75 -0
- data/ext/libsass/src/expand.cpp +875 -0
- data/ext/libsass/src/expand.hpp +98 -0
- data/ext/libsass/src/extender.cpp +1226 -0
- data/ext/libsass/src/extender.hpp +399 -0
- data/ext/libsass/src/extension.cpp +43 -0
- data/ext/libsass/src/extension.hpp +89 -0
- data/ext/libsass/src/file.cpp +531 -0
- data/ext/libsass/src/file.hpp +124 -0
- data/ext/libsass/src/fn_colors.cpp +836 -0
- data/ext/libsass/src/fn_colors.hpp +99 -0
- data/ext/libsass/src/fn_lists.cpp +285 -0
- data/ext/libsass/src/fn_lists.hpp +34 -0
- data/ext/libsass/src/fn_maps.cpp +94 -0
- data/ext/libsass/src/fn_maps.hpp +30 -0
- data/ext/libsass/src/fn_miscs.cpp +248 -0
- data/ext/libsass/src/fn_miscs.hpp +40 -0
- data/ext/libsass/src/fn_numbers.cpp +246 -0
- data/ext/libsass/src/fn_numbers.hpp +45 -0
- data/ext/libsass/src/fn_selectors.cpp +205 -0
- data/ext/libsass/src/fn_selectors.hpp +35 -0
- data/ext/libsass/src/fn_strings.cpp +268 -0
- data/ext/libsass/src/fn_strings.hpp +34 -0
- data/ext/libsass/src/fn_utils.cpp +159 -0
- data/ext/libsass/src/fn_utils.hpp +62 -0
- data/ext/libsass/src/inspect.cpp +1126 -0
- data/ext/libsass/src/inspect.hpp +101 -0
- data/ext/libsass/src/json.cpp +1436 -0
- data/ext/libsass/src/json.hpp +117 -0
- data/ext/libsass/src/kwd_arg_macros.hpp +28 -0
- data/ext/libsass/src/lexer.cpp +122 -0
- data/ext/libsass/src/lexer.hpp +304 -0
- data/ext/libsass/src/listize.cpp +70 -0
- data/ext/libsass/src/listize.hpp +37 -0
- data/ext/libsass/src/mapping.hpp +19 -0
- data/ext/libsass/src/memory/allocator.cpp +48 -0
- data/ext/libsass/src/memory/allocator.hpp +138 -0
- data/ext/libsass/src/memory/config.hpp +20 -0
- data/ext/libsass/src/memory/memory_pool.hpp +186 -0
- data/ext/libsass/src/memory/shared_ptr.cpp +33 -0
- data/ext/libsass/src/memory/shared_ptr.hpp +332 -0
- data/ext/libsass/src/memory.hpp +12 -0
- data/ext/libsass/src/operation.hpp +223 -0
- data/ext/libsass/src/operators.cpp +267 -0
- data/ext/libsass/src/operators.hpp +30 -0
- data/ext/libsass/src/ordered_map.hpp +112 -0
- data/ext/libsass/src/output.cpp +320 -0
- data/ext/libsass/src/output.hpp +47 -0
- data/ext/libsass/src/parser.cpp +3059 -0
- data/ext/libsass/src/parser.hpp +395 -0
- data/ext/libsass/src/parser_selectors.cpp +189 -0
- data/ext/libsass/src/permutate.hpp +164 -0
- data/ext/libsass/src/plugins.cpp +188 -0
- data/ext/libsass/src/plugins.hpp +57 -0
- data/ext/libsass/src/position.cpp +163 -0
- data/ext/libsass/src/position.hpp +147 -0
- data/ext/libsass/src/prelexer.cpp +1780 -0
- data/ext/libsass/src/prelexer.hpp +484 -0
- data/ext/libsass/src/remove_placeholders.cpp +86 -0
- data/ext/libsass/src/remove_placeholders.hpp +37 -0
- data/ext/libsass/src/sass.cpp +156 -0
- data/ext/libsass/src/sass.hpp +147 -0
- data/ext/libsass/src/sass2scss.cpp +895 -0
- data/ext/libsass/src/sass_context.cpp +742 -0
- data/ext/libsass/src/sass_context.hpp +129 -0
- data/ext/libsass/src/sass_functions.cpp +210 -0
- data/ext/libsass/src/sass_functions.hpp +50 -0
- data/ext/libsass/src/sass_values.cpp +362 -0
- data/ext/libsass/src/sass_values.hpp +82 -0
- data/ext/libsass/src/settings.hpp +19 -0
- data/ext/libsass/src/source.cpp +69 -0
- data/ext/libsass/src/source.hpp +95 -0
- data/ext/libsass/src/source_data.hpp +32 -0
- data/ext/libsass/src/source_map.cpp +202 -0
- data/ext/libsass/src/source_map.hpp +65 -0
- data/ext/libsass/src/stylesheet.cpp +22 -0
- data/ext/libsass/src/stylesheet.hpp +57 -0
- data/ext/libsass/src/to_value.cpp +114 -0
- data/ext/libsass/src/to_value.hpp +46 -0
- data/ext/libsass/src/units.cpp +507 -0
- data/ext/libsass/src/units.hpp +110 -0
- data/ext/libsass/src/utf8/checked.h +336 -0
- data/ext/libsass/src/utf8/core.h +332 -0
- data/ext/libsass/src/utf8/unchecked.h +235 -0
- data/ext/libsass/src/utf8.h +34 -0
- data/ext/libsass/src/utf8_string.cpp +104 -0
- data/ext/libsass/src/utf8_string.hpp +38 -0
- data/ext/libsass/src/util.cpp +723 -0
- data/ext/libsass/src/util.hpp +105 -0
- data/ext/libsass/src/util_string.cpp +125 -0
- data/ext/libsass/src/util_string.hpp +73 -0
- data/ext/libsass/src/values.cpp +140 -0
- data/ext/libsass/src/values.hpp +12 -0
- data/lib/sassc/dependency.rb +17 -0
- data/lib/sassc/engine.rb +141 -0
- data/lib/sassc/error.rb +37 -0
- data/lib/sassc/functions_handler.rb +73 -0
- data/lib/sassc/import_handler.rb +50 -0
- data/lib/sassc/importer.rb +31 -0
- data/lib/sassc/native/native_context_api.rb +147 -0
- data/lib/sassc/native/native_functions_api.rb +159 -0
- data/lib/sassc/native/sass2scss_api.rb +10 -0
- data/lib/sassc/native/sass_input_style.rb +13 -0
- data/lib/sassc/native/sass_output_style.rb +12 -0
- data/lib/sassc/native/sass_value.rb +97 -0
- data/lib/sassc/native/string_list.rb +10 -0
- data/lib/sassc/native.rb +64 -0
- data/lib/sassc/sass_2_scss.rb +9 -0
- data/lib/sassc/script/functions.rb +8 -0
- data/lib/sassc/script/value/bool.rb +32 -0
- data/lib/sassc/script/value/color.rb +95 -0
- data/lib/sassc/script/value/list.rb +136 -0
- data/lib/sassc/script/value/map.rb +69 -0
- data/lib/sassc/script/value/number.rb +389 -0
- data/lib/sassc/script/value/string.rb +96 -0
- data/lib/sassc/script/value.rb +137 -0
- data/lib/sassc/script/value_conversion/base.rb +13 -0
- data/lib/sassc/script/value_conversion/bool.rb +13 -0
- data/lib/sassc/script/value_conversion/color.rb +18 -0
- data/lib/sassc/script/value_conversion/list.rb +25 -0
- data/lib/sassc/script/value_conversion/map.rb +21 -0
- data/lib/sassc/script/value_conversion/number.rb +13 -0
- data/lib/sassc/script/value_conversion/string.rb +17 -0
- data/lib/sassc/script/value_conversion.rb +69 -0
- data/lib/sassc/script.rb +17 -0
- data/lib/sassc/util/normalized_map.rb +117 -0
- data/lib/sassc/util.rb +231 -0
- data/lib/sassc/version.rb +5 -0
- data/lib/sassc.rb +57 -0
- data/sassc.gemspec +69 -0
- data/test/css_color_level4_test.rb +168 -0
- data/test/custom_importer_test.rb +127 -0
- data/test/engine_test.rb +314 -0
- data/test/error_test.rb +29 -0
- data/test/fixtures/paths.scss +10 -0
- data/test/functions_test.rb +340 -0
- data/test/native_test.rb +213 -0
- data/test/output_style_test.rb +107 -0
- data/test/sass_2_scss_test.rb +14 -0
- data/test/test_helper.rb +45 -0
- metadata +396 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
#ifndef SASS_MEMORY_SHARED_PTR_H
|
|
2
|
+
#define SASS_MEMORY_SHARED_PTR_H
|
|
3
|
+
|
|
4
|
+
#include "sass/base.h"
|
|
5
|
+
|
|
6
|
+
#include "../sass.hpp"
|
|
7
|
+
#include "allocator.hpp"
|
|
8
|
+
#include <cstddef>
|
|
9
|
+
#include <iostream>
|
|
10
|
+
#include <string>
|
|
11
|
+
#include <type_traits>
|
|
12
|
+
#include <vector>
|
|
13
|
+
|
|
14
|
+
// https://lokiastari.com/blog/2014/12/30/c-plus-plus-by-example-smart-pointer/index.html
|
|
15
|
+
// https://lokiastari.com/blog/2015/01/15/c-plus-plus-by-example-smart-pointer-part-ii/index.html
|
|
16
|
+
// https://lokiastari.com/blog/2015/01/23/c-plus-plus-by-example-smart-pointer-part-iii/index.html
|
|
17
|
+
|
|
18
|
+
namespace Sass {
|
|
19
|
+
|
|
20
|
+
// Forward declaration
|
|
21
|
+
class SharedPtr;
|
|
22
|
+
|
|
23
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
24
|
+
// Use macros for the allocation task, since overloading operator `new`
|
|
25
|
+
// has been proven to be flaky under certain compilers (see comment below).
|
|
26
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
27
|
+
|
|
28
|
+
#ifdef DEBUG_SHARED_PTR
|
|
29
|
+
|
|
30
|
+
#define SASS_MEMORY_NEW(Class, ...) \
|
|
31
|
+
((Class*)(new Class(__VA_ARGS__))->trace(__FILE__, __LINE__)) \
|
|
32
|
+
|
|
33
|
+
#define SASS_MEMORY_COPY(obj) \
|
|
34
|
+
((obj)->copy(__FILE__, __LINE__)) \
|
|
35
|
+
|
|
36
|
+
#define SASS_MEMORY_CLONE(obj) \
|
|
37
|
+
((obj)->clone(__FILE__, __LINE__)) \
|
|
38
|
+
|
|
39
|
+
#else
|
|
40
|
+
|
|
41
|
+
#define SASS_MEMORY_NEW(Class, ...) \
|
|
42
|
+
new Class(__VA_ARGS__) \
|
|
43
|
+
|
|
44
|
+
#define SASS_MEMORY_COPY(obj) \
|
|
45
|
+
((obj)->copy()) \
|
|
46
|
+
|
|
47
|
+
#define SASS_MEMORY_CLONE(obj) \
|
|
48
|
+
((obj)->clone()) \
|
|
49
|
+
|
|
50
|
+
#endif
|
|
51
|
+
|
|
52
|
+
// SharedObj is the base class for all objects that can be stored as a shared object
|
|
53
|
+
// It adds the reference counter and other values directly to the objects
|
|
54
|
+
// This gives a slight overhead when directly used as a stack object, but has some
|
|
55
|
+
// advantages for our code. It is safe to create two shared pointers from the same
|
|
56
|
+
// objects, as the "control block" is directly attached to it. This would lead
|
|
57
|
+
// to undefined behavior with std::shared_ptr. This also avoids the need to
|
|
58
|
+
// allocate additional control blocks and/or the need to dereference two
|
|
59
|
+
// pointers on each operation. This can be optimized in `std::shared_ptr`
|
|
60
|
+
// too by using `std::make_shared` (where the control block and the actual
|
|
61
|
+
// object are allocated in one continuous memory block via one single call).
|
|
62
|
+
class SharedObj {
|
|
63
|
+
public:
|
|
64
|
+
SharedObj() : refcount(0), detached(false) {
|
|
65
|
+
#ifdef DEBUG_SHARED_PTR
|
|
66
|
+
if (taint) all.push_back(this);
|
|
67
|
+
#endif
|
|
68
|
+
}
|
|
69
|
+
virtual ~SharedObj() {
|
|
70
|
+
#ifdef DEBUG_SHARED_PTR
|
|
71
|
+
for (size_t i = 0; i < all.size(); i++) {
|
|
72
|
+
if (all[i] == this) {
|
|
73
|
+
all.erase(all.begin() + i);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
#endif
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#ifdef DEBUG_SHARED_PTR
|
|
81
|
+
static void dumpMemLeaks();
|
|
82
|
+
SharedObj* trace(sass::string file, size_t line) {
|
|
83
|
+
this->file = file;
|
|
84
|
+
this->line = line;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
sass::string getDbgFile() { return file; }
|
|
88
|
+
size_t getDbgLine() { return line; }
|
|
89
|
+
void setDbg(bool dbg) { this->dbg = dbg; }
|
|
90
|
+
size_t getRefCount() const { return refcount; }
|
|
91
|
+
#endif
|
|
92
|
+
|
|
93
|
+
static void setTaint(bool val) { taint = val; }
|
|
94
|
+
|
|
95
|
+
#ifdef SASS_CUSTOM_ALLOCATOR
|
|
96
|
+
inline void* operator new(size_t nbytes) {
|
|
97
|
+
return allocateMem(nbytes);
|
|
98
|
+
}
|
|
99
|
+
inline void operator delete(void* ptr) {
|
|
100
|
+
return deallocateMem(ptr);
|
|
101
|
+
}
|
|
102
|
+
#endif
|
|
103
|
+
|
|
104
|
+
virtual sass::string to_string() const = 0;
|
|
105
|
+
protected:
|
|
106
|
+
friend class SharedPtr;
|
|
107
|
+
friend class Memory_Manager;
|
|
108
|
+
size_t refcount;
|
|
109
|
+
bool detached;
|
|
110
|
+
static bool taint;
|
|
111
|
+
#ifdef DEBUG_SHARED_PTR
|
|
112
|
+
sass::string file;
|
|
113
|
+
size_t line;
|
|
114
|
+
bool dbg = false;
|
|
115
|
+
static sass::vector<SharedObj*> all;
|
|
116
|
+
#endif
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// SharedPtr is a intermediate (template-less) base class for SharedImpl.
|
|
120
|
+
// ToDo: there should be a way to include this in SharedImpl and to get
|
|
121
|
+
// ToDo: rid of all the static_cast that are now needed in SharedImpl.
|
|
122
|
+
class SharedPtr {
|
|
123
|
+
public:
|
|
124
|
+
SharedPtr() : node(nullptr) {}
|
|
125
|
+
SharedPtr(SharedObj* ptr) : node(ptr) {
|
|
126
|
+
incRefCount();
|
|
127
|
+
}
|
|
128
|
+
SharedPtr(const SharedPtr& obj) : SharedPtr(obj.node) {}
|
|
129
|
+
~SharedPtr() {
|
|
130
|
+
decRefCount();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
SharedPtr& operator=(SharedObj* other_node) {
|
|
134
|
+
if (node != other_node) {
|
|
135
|
+
decRefCount();
|
|
136
|
+
node = other_node;
|
|
137
|
+
incRefCount();
|
|
138
|
+
} else if (node != nullptr) {
|
|
139
|
+
node->detached = false;
|
|
140
|
+
}
|
|
141
|
+
return *this;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
SharedPtr& operator=(const SharedPtr& obj) {
|
|
145
|
+
return *this = obj.node;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Prevents all SharedPtrs from freeing this node until it is assigned to another SharedPtr.
|
|
149
|
+
SharedObj* detach() {
|
|
150
|
+
if (node != nullptr) node->detached = true;
|
|
151
|
+
#ifdef DEBUG_SHARED_PTR
|
|
152
|
+
if (node->dbg) {
|
|
153
|
+
std::cerr << "DETACHING NODE\n";
|
|
154
|
+
}
|
|
155
|
+
#endif
|
|
156
|
+
return node;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
SharedObj* obj() const { return node; }
|
|
160
|
+
SharedObj* operator->() const { return node; }
|
|
161
|
+
bool isNull() const { return node == nullptr; }
|
|
162
|
+
operator bool() const { return node != nullptr; }
|
|
163
|
+
|
|
164
|
+
protected:
|
|
165
|
+
SharedObj* node;
|
|
166
|
+
void decRefCount() {
|
|
167
|
+
if (node == nullptr) return;
|
|
168
|
+
--node->refcount;
|
|
169
|
+
#ifdef DEBUG_SHARED_PTR
|
|
170
|
+
if (node->dbg) std::cerr << "- " << node << " X " << node->refcount << " (" << this << ") " << "\n";
|
|
171
|
+
#endif
|
|
172
|
+
if (node->refcount == 0 && !node->detached) {
|
|
173
|
+
#ifdef DEBUG_SHARED_PTR
|
|
174
|
+
if (node->dbg) std::cerr << "DELETE NODE " << node << "\n";
|
|
175
|
+
#endif
|
|
176
|
+
delete node;
|
|
177
|
+
}
|
|
178
|
+
else if (node->refcount == 0) {
|
|
179
|
+
#ifdef DEBUG_SHARED_PTR
|
|
180
|
+
if (node->dbg) std::cerr << "NODE EVAEDED DELETE " << node << "\n";
|
|
181
|
+
#endif
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
void incRefCount() {
|
|
185
|
+
if (node == nullptr) return;
|
|
186
|
+
node->detached = false;
|
|
187
|
+
++node->refcount;
|
|
188
|
+
#ifdef DEBUG_SHARED_PTR
|
|
189
|
+
if (node->dbg) std::cerr << "+ " << node << " X " << node->refcount << " (" << this << ") " << "\n";
|
|
190
|
+
#endif
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
template <class T>
|
|
195
|
+
class SharedImpl : private SharedPtr {
|
|
196
|
+
|
|
197
|
+
public:
|
|
198
|
+
SharedImpl() : SharedPtr(nullptr) {}
|
|
199
|
+
|
|
200
|
+
template <class U>
|
|
201
|
+
SharedImpl(U* node) :
|
|
202
|
+
SharedPtr(static_cast<T*>(node)) {}
|
|
203
|
+
|
|
204
|
+
template <class U>
|
|
205
|
+
SharedImpl(const SharedImpl<U>& impl) :
|
|
206
|
+
SharedImpl(impl.ptr()) {}
|
|
207
|
+
|
|
208
|
+
template <class U>
|
|
209
|
+
SharedImpl<T>& operator=(U *rhs) {
|
|
210
|
+
return static_cast<SharedImpl<T>&>(
|
|
211
|
+
SharedPtr::operator=(static_cast<T*>(rhs)));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
template <class U>
|
|
215
|
+
SharedImpl<T>& operator=(const SharedImpl<U>& rhs) {
|
|
216
|
+
return static_cast<SharedImpl<T>&>(
|
|
217
|
+
SharedPtr::operator=(static_cast<const SharedImpl<T>&>(rhs)));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
operator sass::string() const {
|
|
221
|
+
if (node) return node->to_string();
|
|
222
|
+
return "null";
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
using SharedPtr::isNull;
|
|
226
|
+
using SharedPtr::operator bool;
|
|
227
|
+
operator T*() const { return static_cast<T*>(this->obj()); }
|
|
228
|
+
operator T&() const { return *static_cast<T*>(this->obj()); }
|
|
229
|
+
T& operator* () const { return *static_cast<T*>(this->obj()); };
|
|
230
|
+
T* operator-> () const { return static_cast<T*>(this->obj()); };
|
|
231
|
+
T* ptr () const { return static_cast<T*>(this->obj()); };
|
|
232
|
+
T* detach() { return static_cast<T*>(SharedPtr::detach()); }
|
|
233
|
+
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// Comparison operators, based on:
|
|
237
|
+
// https://en.cppreference.com/w/cpp/memory/unique_ptr/operator_cmp
|
|
238
|
+
|
|
239
|
+
template<class T1, class T2>
|
|
240
|
+
bool operator==(const SharedImpl<T1>& x, const SharedImpl<T2>& y) {
|
|
241
|
+
return x.ptr() == y.ptr();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
template<class T1, class T2>
|
|
245
|
+
bool operator!=(const SharedImpl<T1>& x, const SharedImpl<T2>& y) {
|
|
246
|
+
return x.ptr() != y.ptr();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
template<class T1, class T2>
|
|
250
|
+
bool operator<(const SharedImpl<T1>& x, const SharedImpl<T2>& y) {
|
|
251
|
+
using CT = typename std::common_type<T1*, T2*>::type;
|
|
252
|
+
return std::less<CT>()(x.get(), y.get());
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
template<class T1, class T2>
|
|
256
|
+
bool operator<=(const SharedImpl<T1>& x, const SharedImpl<T2>& y) {
|
|
257
|
+
return !(y < x);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
template<class T1, class T2>
|
|
261
|
+
bool operator>(const SharedImpl<T1>& x, const SharedImpl<T2>& y) {
|
|
262
|
+
return y < x;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
template<class T1, class T2>
|
|
266
|
+
bool operator>=(const SharedImpl<T1>& x, const SharedImpl<T2>& y) {
|
|
267
|
+
return !(x < y);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
template <class T>
|
|
271
|
+
bool operator==(const SharedImpl<T>& x, std::nullptr_t) noexcept {
|
|
272
|
+
return x.isNull();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
template <class T>
|
|
276
|
+
bool operator==(std::nullptr_t, const SharedImpl<T>& x) noexcept {
|
|
277
|
+
return x.isNull();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
template <class T>
|
|
281
|
+
bool operator!=(const SharedImpl<T>& x, std::nullptr_t) noexcept {
|
|
282
|
+
return !x.isNull();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
template <class T>
|
|
286
|
+
bool operator!=(std::nullptr_t, const SharedImpl<T>& x) noexcept {
|
|
287
|
+
return !x.isNull();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
template <class T>
|
|
291
|
+
bool operator<(const SharedImpl<T>& x, std::nullptr_t) {
|
|
292
|
+
return std::less<T*>()(x.get(), nullptr);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
template <class T>
|
|
296
|
+
bool operator<(std::nullptr_t, const SharedImpl<T>& y) {
|
|
297
|
+
return std::less<T*>()(nullptr, y.get());
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
template <class T>
|
|
301
|
+
bool operator<=(const SharedImpl<T>& x, std::nullptr_t) {
|
|
302
|
+
return !(nullptr < x);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
template <class T>
|
|
306
|
+
bool operator<=(std::nullptr_t, const SharedImpl<T>& y) {
|
|
307
|
+
return !(y < nullptr);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
template <class T>
|
|
311
|
+
bool operator>(const SharedImpl<T>& x, std::nullptr_t) {
|
|
312
|
+
return nullptr < x;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
template <class T>
|
|
316
|
+
bool operator>(std::nullptr_t, const SharedImpl<T>& y) {
|
|
317
|
+
return y < nullptr;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
template <class T>
|
|
321
|
+
bool operator>=(const SharedImpl<T>& x, std::nullptr_t) {
|
|
322
|
+
return !(x < nullptr);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
template <class T>
|
|
326
|
+
bool operator>=(std::nullptr_t, const SharedImpl<T>& y) {
|
|
327
|
+
return !(nullptr < y);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
} // namespace Sass
|
|
331
|
+
|
|
332
|
+
#endif
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
#ifndef SASS_OPERATION_H
|
|
2
|
+
#define SASS_OPERATION_H
|
|
3
|
+
|
|
4
|
+
// sass.hpp must go before all system headers to get the
|
|
5
|
+
// __EXTENSIONS__ fix on Solaris.
|
|
6
|
+
#include "sass.hpp"
|
|
7
|
+
|
|
8
|
+
// base classes to implement curiously recurring template pattern (CRTP)
|
|
9
|
+
// https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
|
|
10
|
+
|
|
11
|
+
#include <typeinfo>
|
|
12
|
+
#include <stdexcept>
|
|
13
|
+
|
|
14
|
+
#include "ast_fwd_decl.hpp"
|
|
15
|
+
#include "ast_def_macros.hpp"
|
|
16
|
+
|
|
17
|
+
namespace Sass {
|
|
18
|
+
|
|
19
|
+
#define ATTACH_ABSTRACT_CRTP_PERFORM_METHODS()\
|
|
20
|
+
virtual void perform(Operation<void>* op) = 0; \
|
|
21
|
+
virtual Value* perform(Operation<Value*>* op) = 0; \
|
|
22
|
+
virtual sass::string perform(Operation<sass::string>* op) = 0; \
|
|
23
|
+
virtual AST_Node* perform(Operation<AST_Node*>* op) = 0; \
|
|
24
|
+
virtual Selector* perform(Operation<Selector*>* op) = 0; \
|
|
25
|
+
virtual Statement* perform(Operation<Statement*>* op) = 0; \
|
|
26
|
+
virtual Expression* perform(Operation<Expression*>* op) = 0; \
|
|
27
|
+
virtual union Sass_Value* perform(Operation<union Sass_Value*>* op) = 0; \
|
|
28
|
+
virtual SupportsCondition* perform(Operation<SupportsCondition*>* op) = 0; \
|
|
29
|
+
|
|
30
|
+
// you must add operators to every class
|
|
31
|
+
// ensures `this` of actual instance type
|
|
32
|
+
// we therefore call the specific operator
|
|
33
|
+
// they are virtual so most specific is used
|
|
34
|
+
#define ATTACH_CRTP_PERFORM_METHODS()\
|
|
35
|
+
virtual void perform(Operation<void>* op) override { return (*op)(this); } \
|
|
36
|
+
virtual Value* perform(Operation<Value*>* op) override { return (*op)(this); } \
|
|
37
|
+
virtual sass::string perform(Operation<sass::string>* op) override { return (*op)(this); } \
|
|
38
|
+
virtual AST_Node* perform(Operation<AST_Node*>* op) override { return (*op)(this); } \
|
|
39
|
+
virtual Selector* perform(Operation<Selector*>* op) override { return (*op)(this); } \
|
|
40
|
+
virtual Statement* perform(Operation<Statement*>* op) override { return (*op)(this); } \
|
|
41
|
+
virtual Expression* perform(Operation<Expression*>* op) override { return (*op)(this); } \
|
|
42
|
+
virtual union Sass_Value* perform(Operation<union Sass_Value*>* op) override { return (*op)(this); } \
|
|
43
|
+
virtual SupportsCondition* perform(Operation<SupportsCondition*>* op) override { return (*op)(this); } \
|
|
44
|
+
|
|
45
|
+
template<typename T>
|
|
46
|
+
class Operation {
|
|
47
|
+
public:
|
|
48
|
+
virtual T operator()(AST_Node* x) = 0;
|
|
49
|
+
// statements
|
|
50
|
+
virtual T operator()(Block* x) = 0;
|
|
51
|
+
virtual T operator()(StyleRule* x) = 0;
|
|
52
|
+
virtual T operator()(Bubble* x) = 0;
|
|
53
|
+
virtual T operator()(Trace* x) = 0;
|
|
54
|
+
virtual T operator()(SupportsRule* x) = 0;
|
|
55
|
+
virtual T operator()(MediaRule* x) = 0;
|
|
56
|
+
virtual T operator()(CssMediaRule* x) = 0;
|
|
57
|
+
virtual T operator()(CssMediaQuery* x) = 0;
|
|
58
|
+
virtual T operator()(AtRootRule* x) = 0;
|
|
59
|
+
virtual T operator()(AtRule* x) = 0;
|
|
60
|
+
virtual T operator()(Keyframe_Rule* x) = 0;
|
|
61
|
+
virtual T operator()(Declaration* x) = 0;
|
|
62
|
+
virtual T operator()(Assignment* x) = 0;
|
|
63
|
+
virtual T operator()(Import* x) = 0;
|
|
64
|
+
virtual T operator()(Import_Stub* x) = 0;
|
|
65
|
+
virtual T operator()(WarningRule* x) = 0;
|
|
66
|
+
virtual T operator()(ErrorRule* x) = 0;
|
|
67
|
+
virtual T operator()(DebugRule* x) = 0;
|
|
68
|
+
virtual T operator()(Comment* x) = 0;
|
|
69
|
+
virtual T operator()(If* x) = 0;
|
|
70
|
+
virtual T operator()(ForRule* x) = 0;
|
|
71
|
+
virtual T operator()(EachRule* x) = 0;
|
|
72
|
+
virtual T operator()(WhileRule* x) = 0;
|
|
73
|
+
virtual T operator()(Return* x) = 0;
|
|
74
|
+
virtual T operator()(Content* x) = 0;
|
|
75
|
+
virtual T operator()(ExtendRule* x) = 0;
|
|
76
|
+
virtual T operator()(Definition* x) = 0;
|
|
77
|
+
virtual T operator()(Mixin_Call* x) = 0;
|
|
78
|
+
// expressions
|
|
79
|
+
virtual T operator()(Null* x) = 0;
|
|
80
|
+
virtual T operator()(List* x) = 0;
|
|
81
|
+
virtual T operator()(Map* x) = 0;
|
|
82
|
+
virtual T operator()(Function* x) = 0;
|
|
83
|
+
virtual T operator()(Binary_Expression* x) = 0;
|
|
84
|
+
virtual T operator()(Unary_Expression* x) = 0;
|
|
85
|
+
virtual T operator()(Function_Call* x) = 0;
|
|
86
|
+
virtual T operator()(Custom_Warning* x) = 0;
|
|
87
|
+
virtual T operator()(Custom_Error* x) = 0;
|
|
88
|
+
virtual T operator()(Variable* x) = 0;
|
|
89
|
+
virtual T operator()(Number* x) = 0;
|
|
90
|
+
virtual T operator()(Color* x) = 0;
|
|
91
|
+
virtual T operator()(Color_RGBA* x) = 0;
|
|
92
|
+
virtual T operator()(Color_HSLA* x) = 0;
|
|
93
|
+
virtual T operator()(Boolean* x) = 0;
|
|
94
|
+
virtual T operator()(String_Schema* x) = 0;
|
|
95
|
+
virtual T operator()(String_Quoted* x) = 0;
|
|
96
|
+
virtual T operator()(String_Constant* x) = 0;
|
|
97
|
+
virtual T operator()(SupportsCondition* x) = 0;
|
|
98
|
+
virtual T operator()(SupportsOperation* x) = 0;
|
|
99
|
+
virtual T operator()(SupportsNegation* x) = 0;
|
|
100
|
+
virtual T operator()(SupportsDeclaration* x) = 0;
|
|
101
|
+
virtual T operator()(Supports_Interpolation* x) = 0;
|
|
102
|
+
virtual T operator()(Media_Query* x) = 0;
|
|
103
|
+
virtual T operator()(Media_Query_Expression* x) = 0;
|
|
104
|
+
virtual T operator()(At_Root_Query* x) = 0;
|
|
105
|
+
virtual T operator()(Parent_Reference* x) = 0;
|
|
106
|
+
// parameters and arguments
|
|
107
|
+
virtual T operator()(Parameter* x) = 0;
|
|
108
|
+
virtual T operator()(Parameters* x) = 0;
|
|
109
|
+
virtual T operator()(Argument* x) = 0;
|
|
110
|
+
virtual T operator()(Arguments* x) = 0;
|
|
111
|
+
// selectors
|
|
112
|
+
virtual T operator()(Selector_Schema* x) = 0;
|
|
113
|
+
virtual T operator()(PlaceholderSelector* x) = 0;
|
|
114
|
+
virtual T operator()(TypeSelector* x) = 0;
|
|
115
|
+
virtual T operator()(ClassSelector* x) = 0;
|
|
116
|
+
virtual T operator()(IDSelector* x) = 0;
|
|
117
|
+
virtual T operator()(AttributeSelector* x) = 0;
|
|
118
|
+
virtual T operator()(PseudoSelector* x) = 0;
|
|
119
|
+
virtual T operator()(SelectorComponent* x) = 0;
|
|
120
|
+
virtual T operator()(SelectorCombinator* x) = 0;
|
|
121
|
+
virtual T operator()(CompoundSelector* x) = 0;
|
|
122
|
+
virtual T operator()(ComplexSelector* x) = 0;
|
|
123
|
+
virtual T operator()(SelectorList* x) = 0;
|
|
124
|
+
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// example: Operation_CRTP<Expression*, Eval>
|
|
128
|
+
// T is the base return type of all visitors
|
|
129
|
+
// D is the class derived visitor class
|
|
130
|
+
// normally you want to implement all operators
|
|
131
|
+
template <typename T, typename D>
|
|
132
|
+
class Operation_CRTP : public Operation<T> {
|
|
133
|
+
public:
|
|
134
|
+
T operator()(AST_Node* x) { return static_cast<D*>(this)->fallback(x); }
|
|
135
|
+
// statements
|
|
136
|
+
T operator()(Block* x) { return static_cast<D*>(this)->fallback(x); }
|
|
137
|
+
T operator()(StyleRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
138
|
+
T operator()(Bubble* x) { return static_cast<D*>(this)->fallback(x); }
|
|
139
|
+
T operator()(Trace* x) { return static_cast<D*>(this)->fallback(x); }
|
|
140
|
+
T operator()(SupportsRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
141
|
+
T operator()(MediaRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
142
|
+
T operator()(CssMediaRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
143
|
+
T operator()(CssMediaQuery* x) { return static_cast<D*>(this)->fallback(x); }
|
|
144
|
+
T operator()(AtRootRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
145
|
+
T operator()(AtRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
146
|
+
T operator()(Keyframe_Rule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
147
|
+
T operator()(Declaration* x) { return static_cast<D*>(this)->fallback(x); }
|
|
148
|
+
T operator()(Assignment* x) { return static_cast<D*>(this)->fallback(x); }
|
|
149
|
+
T operator()(Import* x) { return static_cast<D*>(this)->fallback(x); }
|
|
150
|
+
T operator()(Import_Stub* x) { return static_cast<D*>(this)->fallback(x); }
|
|
151
|
+
T operator()(WarningRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
152
|
+
T operator()(ErrorRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
153
|
+
T operator()(DebugRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
154
|
+
T operator()(Comment* x) { return static_cast<D*>(this)->fallback(x); }
|
|
155
|
+
T operator()(If* x) { return static_cast<D*>(this)->fallback(x); }
|
|
156
|
+
T operator()(ForRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
157
|
+
T operator()(EachRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
158
|
+
T operator()(WhileRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
159
|
+
T operator()(Return* x) { return static_cast<D*>(this)->fallback(x); }
|
|
160
|
+
T operator()(Content* x) { return static_cast<D*>(this)->fallback(x); }
|
|
161
|
+
T operator()(ExtendRule* x) { return static_cast<D*>(this)->fallback(x); }
|
|
162
|
+
T operator()(Definition* x) { return static_cast<D*>(this)->fallback(x); }
|
|
163
|
+
T operator()(Mixin_Call* x) { return static_cast<D*>(this)->fallback(x); }
|
|
164
|
+
// expressions
|
|
165
|
+
T operator()(Null* x) { return static_cast<D*>(this)->fallback(x); }
|
|
166
|
+
T operator()(List* x) { return static_cast<D*>(this)->fallback(x); }
|
|
167
|
+
T operator()(Map* x) { return static_cast<D*>(this)->fallback(x); }
|
|
168
|
+
T operator()(Function* x) { return static_cast<D*>(this)->fallback(x); }
|
|
169
|
+
T operator()(Binary_Expression* x) { return static_cast<D*>(this)->fallback(x); }
|
|
170
|
+
T operator()(Unary_Expression* x) { return static_cast<D*>(this)->fallback(x); }
|
|
171
|
+
T operator()(Function_Call* x) { return static_cast<D*>(this)->fallback(x); }
|
|
172
|
+
T operator()(Custom_Warning* x) { return static_cast<D*>(this)->fallback(x); }
|
|
173
|
+
T operator()(Custom_Error* x) { return static_cast<D*>(this)->fallback(x); }
|
|
174
|
+
T operator()(Variable* x) { return static_cast<D*>(this)->fallback(x); }
|
|
175
|
+
T operator()(Number* x) { return static_cast<D*>(this)->fallback(x); }
|
|
176
|
+
T operator()(Color* x) { return static_cast<D*>(this)->fallback(x); }
|
|
177
|
+
T operator()(Color_RGBA* x) { return static_cast<D*>(this)->fallback(x); }
|
|
178
|
+
T operator()(Color_HSLA* x) { return static_cast<D*>(this)->fallback(x); }
|
|
179
|
+
T operator()(Boolean* x) { return static_cast<D*>(this)->fallback(x); }
|
|
180
|
+
T operator()(String_Schema* x) { return static_cast<D*>(this)->fallback(x); }
|
|
181
|
+
T operator()(String_Constant* x) { return static_cast<D*>(this)->fallback(x); }
|
|
182
|
+
T operator()(String_Quoted* x) { return static_cast<D*>(this)->fallback(x); }
|
|
183
|
+
T operator()(SupportsCondition* x) { return static_cast<D*>(this)->fallback(x); }
|
|
184
|
+
T operator()(SupportsOperation* x) { return static_cast<D*>(this)->fallback(x); }
|
|
185
|
+
T operator()(SupportsNegation* x) { return static_cast<D*>(this)->fallback(x); }
|
|
186
|
+
T operator()(SupportsDeclaration* x) { return static_cast<D*>(this)->fallback(x); }
|
|
187
|
+
T operator()(Supports_Interpolation* x) { return static_cast<D*>(this)->fallback(x); }
|
|
188
|
+
T operator()(Media_Query* x) { return static_cast<D*>(this)->fallback(x); }
|
|
189
|
+
T operator()(Media_Query_Expression* x) { return static_cast<D*>(this)->fallback(x); }
|
|
190
|
+
T operator()(At_Root_Query* x) { return static_cast<D*>(this)->fallback(x); }
|
|
191
|
+
T operator()(Parent_Reference* x) { return static_cast<D*>(this)->fallback(x); }
|
|
192
|
+
// parameters and arguments
|
|
193
|
+
T operator()(Parameter* x) { return static_cast<D*>(this)->fallback(x); }
|
|
194
|
+
T operator()(Parameters* x) { return static_cast<D*>(this)->fallback(x); }
|
|
195
|
+
T operator()(Argument* x) { return static_cast<D*>(this)->fallback(x); }
|
|
196
|
+
T operator()(Arguments* x) { return static_cast<D*>(this)->fallback(x); }
|
|
197
|
+
// selectors
|
|
198
|
+
T operator()(Selector_Schema* x) { return static_cast<D*>(this)->fallback(x); }
|
|
199
|
+
T operator()(PlaceholderSelector* x) { return static_cast<D*>(this)->fallback(x); }
|
|
200
|
+
T operator()(TypeSelector* x) { return static_cast<D*>(this)->fallback(x); }
|
|
201
|
+
T operator()(ClassSelector* x) { return static_cast<D*>(this)->fallback(x); }
|
|
202
|
+
T operator()(IDSelector* x) { return static_cast<D*>(this)->fallback(x); }
|
|
203
|
+
T operator()(AttributeSelector* x) { return static_cast<D*>(this)->fallback(x); }
|
|
204
|
+
T operator()(PseudoSelector* x) { return static_cast<D*>(this)->fallback(x); }
|
|
205
|
+
T operator()(SelectorComponent* x) { return static_cast<D*>(this)->fallback(x); }
|
|
206
|
+
T operator()(SelectorCombinator* x) { return static_cast<D*>(this)->fallback(x); }
|
|
207
|
+
T operator()(CompoundSelector* x) { return static_cast<D*>(this)->fallback(x); }
|
|
208
|
+
T operator()(ComplexSelector* x) { return static_cast<D*>(this)->fallback(x); }
|
|
209
|
+
T operator()(SelectorList* x) { return static_cast<D*>(this)->fallback(x); }
|
|
210
|
+
|
|
211
|
+
// fallback with specific type U
|
|
212
|
+
// will be called if not overloaded
|
|
213
|
+
template <typename U> inline T fallback(U x)
|
|
214
|
+
{
|
|
215
|
+
throw std::runtime_error(
|
|
216
|
+
std::string(typeid(*this).name()) + ": CRTP not implemented for " + typeid(x).name());
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
#endif
|