sassc 2.2.1 → 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.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/CHANGELOG.md +18 -0
  4. data/Rakefile +1 -3
  5. data/ext/extconf.rb +13 -5
  6. data/ext/libsass/VERSION +1 -1
  7. data/ext/libsass/include/sass/base.h +2 -1
  8. data/ext/libsass/include/sass/context.h +4 -0
  9. data/ext/libsass/src/MurmurHash2.hpp +91 -0
  10. data/ext/libsass/src/ast.cpp +158 -168
  11. data/ext/libsass/src/ast.hpp +389 -230
  12. data/ext/libsass/src/ast_def_macros.hpp +18 -10
  13. data/ext/libsass/src/ast_fwd_decl.cpp +4 -3
  14. data/ext/libsass/src/ast_fwd_decl.hpp +98 -165
  15. data/ext/libsass/src/ast_helpers.hpp +292 -0
  16. data/ext/libsass/src/ast_sel_cmp.cpp +219 -732
  17. data/ext/libsass/src/ast_sel_super.cpp +539 -0
  18. data/ext/libsass/src/ast_sel_unify.cpp +207 -212
  19. data/ext/libsass/src/ast_sel_weave.cpp +616 -0
  20. data/ext/libsass/src/ast_selectors.cpp +594 -1026
  21. data/ext/libsass/src/ast_selectors.hpp +339 -385
  22. data/ext/libsass/src/ast_supports.cpp +36 -52
  23. data/ext/libsass/src/ast_supports.hpp +29 -29
  24. data/ext/libsass/src/ast_values.cpp +271 -84
  25. data/ext/libsass/src/ast_values.hpp +116 -107
  26. data/ext/libsass/src/backtrace.cpp +9 -9
  27. data/ext/libsass/src/backtrace.hpp +5 -5
  28. data/ext/libsass/src/base64vlq.cpp +2 -2
  29. data/ext/libsass/src/base64vlq.hpp +1 -1
  30. data/ext/libsass/src/bind.cpp +18 -18
  31. data/ext/libsass/src/bind.hpp +1 -1
  32. data/ext/libsass/src/c2ast.cpp +3 -3
  33. data/ext/libsass/src/c2ast.hpp +1 -1
  34. data/ext/libsass/src/cencode.c +4 -6
  35. data/ext/libsass/src/check_nesting.cpp +40 -41
  36. data/ext/libsass/src/check_nesting.hpp +6 -2
  37. data/ext/libsass/src/color_maps.cpp +14 -13
  38. data/ext/libsass/src/color_maps.hpp +1 -9
  39. data/ext/libsass/src/constants.cpp +5 -0
  40. data/ext/libsass/src/constants.hpp +6 -0
  41. data/ext/libsass/src/context.cpp +92 -119
  42. data/ext/libsass/src/context.hpp +41 -53
  43. data/ext/libsass/src/cssize.cpp +66 -149
  44. data/ext/libsass/src/cssize.hpp +17 -23
  45. data/ext/libsass/src/dart_helpers.hpp +199 -0
  46. data/ext/libsass/src/debugger.hpp +451 -295
  47. data/ext/libsass/src/emitter.cpp +15 -16
  48. data/ext/libsass/src/emitter.hpp +10 -12
  49. data/ext/libsass/src/environment.cpp +27 -27
  50. data/ext/libsass/src/environment.hpp +29 -24
  51. data/ext/libsass/src/error_handling.cpp +62 -41
  52. data/ext/libsass/src/error_handling.hpp +61 -51
  53. data/ext/libsass/src/eval.cpp +167 -281
  54. data/ext/libsass/src/eval.hpp +27 -29
  55. data/ext/libsass/src/eval_selectors.cpp +75 -0
  56. data/ext/libsass/src/expand.cpp +275 -222
  57. data/ext/libsass/src/expand.hpp +36 -16
  58. data/ext/libsass/src/extender.cpp +1188 -0
  59. data/ext/libsass/src/extender.hpp +399 -0
  60. data/ext/libsass/src/extension.cpp +43 -0
  61. data/ext/libsass/src/extension.hpp +89 -0
  62. data/ext/libsass/src/file.cpp +81 -72
  63. data/ext/libsass/src/file.hpp +28 -37
  64. data/ext/libsass/src/fn_colors.cpp +20 -18
  65. data/ext/libsass/src/fn_lists.cpp +30 -29
  66. data/ext/libsass/src/fn_maps.cpp +3 -3
  67. data/ext/libsass/src/fn_miscs.cpp +34 -46
  68. data/ext/libsass/src/fn_numbers.cpp +20 -13
  69. data/ext/libsass/src/fn_selectors.cpp +98 -128
  70. data/ext/libsass/src/fn_strings.cpp +47 -33
  71. data/ext/libsass/src/fn_utils.cpp +31 -29
  72. data/ext/libsass/src/fn_utils.hpp +17 -11
  73. data/ext/libsass/src/inspect.cpp +186 -148
  74. data/ext/libsass/src/inspect.hpp +31 -29
  75. data/ext/libsass/src/lexer.cpp +20 -82
  76. data/ext/libsass/src/lexer.hpp +5 -16
  77. data/ext/libsass/src/listize.cpp +23 -37
  78. data/ext/libsass/src/listize.hpp +8 -9
  79. data/ext/libsass/src/mapping.hpp +1 -0
  80. data/ext/libsass/src/memory/allocator.cpp +48 -0
  81. data/ext/libsass/src/memory/allocator.hpp +138 -0
  82. data/ext/libsass/src/memory/config.hpp +20 -0
  83. data/ext/libsass/src/memory/memory_pool.hpp +186 -0
  84. data/ext/libsass/src/memory/{SharedPtr.cpp → shared_ptr.cpp} +2 -2
  85. data/ext/libsass/src/memory/{SharedPtr.hpp → shared_ptr.hpp} +55 -9
  86. data/ext/libsass/src/memory.hpp +12 -0
  87. data/ext/libsass/src/operation.hpp +71 -61
  88. data/ext/libsass/src/operators.cpp +19 -18
  89. data/ext/libsass/src/operators.hpp +11 -11
  90. data/ext/libsass/src/ordered_map.hpp +112 -0
  91. data/ext/libsass/src/output.cpp +45 -64
  92. data/ext/libsass/src/output.hpp +6 -6
  93. data/ext/libsass/src/parser.cpp +512 -700
  94. data/ext/libsass/src/parser.hpp +89 -97
  95. data/ext/libsass/src/parser_selectors.cpp +189 -0
  96. data/ext/libsass/src/permutate.hpp +164 -0
  97. data/ext/libsass/src/plugins.cpp +7 -7
  98. data/ext/libsass/src/plugins.hpp +8 -8
  99. data/ext/libsass/src/position.cpp +7 -26
  100. data/ext/libsass/src/position.hpp +44 -21
  101. data/ext/libsass/src/prelexer.cpp +6 -6
  102. data/ext/libsass/src/remove_placeholders.cpp +55 -56
  103. data/ext/libsass/src/remove_placeholders.hpp +21 -18
  104. data/ext/libsass/src/sass.cpp +16 -15
  105. data/ext/libsass/src/sass.hpp +10 -5
  106. data/ext/libsass/src/sass2scss.cpp +4 -4
  107. data/ext/libsass/src/sass_context.cpp +91 -122
  108. data/ext/libsass/src/sass_context.hpp +2 -2
  109. data/ext/libsass/src/sass_functions.cpp +1 -1
  110. data/ext/libsass/src/sass_values.cpp +8 -11
  111. data/ext/libsass/src/settings.hpp +19 -0
  112. data/ext/libsass/src/source.cpp +69 -0
  113. data/ext/libsass/src/source.hpp +95 -0
  114. data/ext/libsass/src/source_data.hpp +32 -0
  115. data/ext/libsass/src/source_map.cpp +22 -18
  116. data/ext/libsass/src/source_map.hpp +12 -9
  117. data/ext/libsass/src/stylesheet.cpp +22 -0
  118. data/ext/libsass/src/stylesheet.hpp +57 -0
  119. data/ext/libsass/src/to_value.cpp +2 -2
  120. data/ext/libsass/src/to_value.hpp +1 -1
  121. data/ext/libsass/src/units.cpp +24 -22
  122. data/ext/libsass/src/units.hpp +8 -8
  123. data/ext/libsass/src/utf8_string.cpp +9 -10
  124. data/ext/libsass/src/utf8_string.hpp +7 -6
  125. data/ext/libsass/src/util.cpp +48 -50
  126. data/ext/libsass/src/util.hpp +20 -21
  127. data/ext/libsass/src/util_string.cpp +111 -61
  128. data/ext/libsass/src/util_string.hpp +62 -8
  129. data/ext/libsass/src/values.cpp +12 -12
  130. data/lib/sassc/engine.rb +5 -3
  131. data/lib/sassc/functions_handler.rb +8 -8
  132. data/lib/sassc/native.rb +4 -6
  133. data/lib/sassc/script.rb +4 -4
  134. data/lib/sassc/version.rb +1 -1
  135. data/test/functions_test.rb +18 -1
  136. data/test/native_test.rb +4 -4
  137. metadata +29 -15
  138. data/ext/libsass/src/extend.cpp +0 -2132
  139. data/ext/libsass/src/extend.hpp +0 -86
  140. data/ext/libsass/src/node.cpp +0 -322
  141. data/ext/libsass/src/node.hpp +0 -118
  142. data/ext/libsass/src/paths.hpp +0 -71
  143. data/ext/libsass/src/sass_util.cpp +0 -152
  144. data/ext/libsass/src/sass_util.hpp +0 -256
  145. data/ext/libsass/src/subset_map.cpp +0 -58
  146. data/ext/libsass/src/subset_map.hpp +0 -76
  147. data/lib/sassc/native/lib_c.rb +0 -21
@@ -1,152 +0,0 @@
1
- // sass.hpp must go before all system headers to get the
2
- // __EXTENSIONS__ fix on Solaris.
3
- #include "sass.hpp"
4
-
5
- #include "node.hpp"
6
-
7
- namespace Sass {
8
-
9
-
10
- /*
11
- # This is the equivalent of ruby's Sass::Util.paths.
12
- #
13
- # Return an array of all possible paths through the given arrays.
14
- #
15
- # @param arrs [NodeCollection<NodeCollection<Node>>]
16
- # @return [NodeCollection<NodeCollection<Node>>]
17
- #
18
- # @example
19
- # paths([[1, 2], [3, 4], [5]]) #=>
20
- # # [[1, 3, 5],
21
- # # [2, 3, 5],
22
- # # [1, 4, 5],
23
- # # [2, 4, 5]]
24
-
25
- The following is the modified version of the ruby code that was more portable to C++. You
26
- should be able to drop it into ruby 3.2.19 and get the same results from ruby sass.
27
-
28
- def paths(arrs)
29
- // I changed the inject and maps to an iterative approach to make it easier to implement in C++
30
- loopStart = [[]]
31
-
32
- for arr in arrs do
33
- permutations = []
34
- for e in arr do
35
- for path in loopStart do
36
- permutations.push(path + [e])
37
- end
38
- end
39
- loopStart = permutations
40
- end
41
- end
42
- */
43
- Node paths(const Node& arrs) {
44
-
45
- Node loopStart = Node::createCollection();
46
- loopStart.collection()->push_back(Node::createCollection());
47
-
48
- for (NodeDeque::iterator arrsIter = arrs.collection()->begin(), arrsEndIter = arrs.collection()->end();
49
- arrsIter != arrsEndIter; ++arrsIter) {
50
-
51
- Node& arr = *arrsIter;
52
-
53
- Node permutations = Node::createCollection();
54
-
55
- for (NodeDeque::iterator arrIter = arr.collection()->begin(), arrIterEnd = arr.collection()->end();
56
- arrIter != arrIterEnd; ++arrIter) {
57
-
58
- Node& e = *arrIter;
59
-
60
- for (NodeDeque::iterator loopStartIter = loopStart.collection()->begin(), loopStartIterEnd = loopStart.collection()->end();
61
- loopStartIter != loopStartIterEnd; ++loopStartIter) {
62
-
63
- Node& path = *loopStartIter;
64
-
65
- Node newPermutation = Node::createCollection();
66
- newPermutation.got_line_feed = arr.got_line_feed;
67
- newPermutation.plus(path);
68
- newPermutation.collection()->push_back(e);
69
-
70
- permutations.collection()->push_back(newPermutation);
71
- }
72
- }
73
-
74
- loopStart = permutations;
75
- }
76
-
77
- return loopStart;
78
- }
79
-
80
-
81
- /*
82
- This is the equivalent of ruby sass' Sass::Util.flatten and [].flatten.
83
- Sass::Util.flatten requires the number of levels to flatten, while
84
- [].flatten doesn't and will flatten the entire array. This function
85
- supports both.
86
-
87
- # Flattens the first `n` nested arrays. If n == -1, all arrays will be flattened
88
- #
89
- # @param arr [NodeCollection] The array to flatten
90
- # @param n [int] The number of levels to flatten
91
- # @return [NodeCollection] The flattened array
92
-
93
- The following is the modified version of the ruby code that was more portable to C++. You
94
- should be able to drop it into ruby 3.2.19 and get the same results from ruby sass.
95
-
96
- def flatten(arr, n = -1)
97
- if n != -1 and n == 0 then
98
- return arr
99
- end
100
-
101
- flattened = []
102
-
103
- for e in arr do
104
- if e.is_a?(Array) then
105
- flattened.concat(flatten(e, n - 1))
106
- else
107
- flattened << e
108
- end
109
- end
110
-
111
- return flattened
112
- end
113
- */
114
- Node flatten(Node& arr, int n) {
115
- if (n != -1 && n == 0) {
116
- return arr;
117
- }
118
-
119
- Node flattened = Node::createCollection();
120
- if (arr.got_line_feed) flattened.got_line_feed = true;
121
-
122
- for (NodeDeque::iterator iter = arr.collection()->begin(), iterEnd = arr.collection()->end();
123
- iter != iterEnd; iter++) {
124
- Node& e = *iter;
125
-
126
- // e has the lf set
127
- if (e.isCollection()) {
128
-
129
- // e.collection().got_line_feed = e.got_line_feed;
130
- Node recurseFlattened = flatten(e, n - 1);
131
-
132
- if(e.got_line_feed) {
133
- flattened.got_line_feed = e.got_line_feed;
134
- recurseFlattened.got_line_feed = e.got_line_feed;
135
- }
136
-
137
- for(auto i : (*recurseFlattened.collection())) {
138
- if (recurseFlattened.got_line_feed) {
139
-
140
- i.got_line_feed = true;
141
- }
142
- flattened.collection()->push_back(i);
143
- }
144
-
145
- } else {
146
- flattened.collection()->push_back(e);
147
- }
148
- }
149
-
150
- return flattened;
151
- }
152
- }
@@ -1,256 +0,0 @@
1
- #ifndef SASS_SASS_UTIL_H
2
- #define SASS_SASS_UTIL_H
3
-
4
- #include "ast.hpp"
5
- #include "node.hpp"
6
- #include "debug.hpp"
7
-
8
- namespace Sass {
9
-
10
-
11
-
12
-
13
- /*
14
- This is for ports of functions in the Sass:Util module.
15
- */
16
-
17
-
18
- /*
19
- # Return a Node collection of all possible paths through the given Node collection of Node collections.
20
- #
21
- # @param arrs [NodeCollection<NodeCollection<Node>>]
22
- # @return [NodeCollection<NodeCollection<Node>>]
23
- #
24
- # @example
25
- # paths([[1, 2], [3, 4], [5]]) #=>
26
- # # [[1, 3, 5],
27
- # # [2, 3, 5],
28
- # # [1, 4, 5],
29
- # # [2, 4, 5]]
30
- */
31
- Node paths(const Node& arrs);
32
-
33
-
34
- /*
35
- This class is a default implementation of a Node comparator that can be passed to the lcs function below.
36
- It uses operator== for equality comparision. It then returns one if the Nodes are equal.
37
- */
38
- class DefaultLcsComparator {
39
- public:
40
- bool operator()(const Node& one, const Node& two, Node& out) const {
41
- // TODO: Is this the correct C++ interpretation?
42
- // block ||= proc {|a, b| a == b && a}
43
- if (one == two) {
44
- out = one;
45
- return true;
46
- }
47
-
48
- return false;
49
- }
50
- };
51
-
52
-
53
- typedef std::vector<std::vector<int> > LCSTable;
54
-
55
-
56
- /*
57
- This is the equivalent of ruby's Sass::Util.lcs_backtrace.
58
-
59
- # Computes a single longest common subsequence for arrays x and y.
60
- # Algorithm from http://en.wikipedia.org/wiki/Longest_common_subsequence_problem#Reading_out_an_LCS
61
- */
62
- template<typename ComparatorType>
63
- Node lcs_backtrace(const LCSTable& c, const Node& x, const Node& y, int i, int j, const ComparatorType& comparator) {
64
- DEBUG_PRINTLN(LCS, "LCSBACK: X=" << x << " Y=" << y << " I=" << i << " J=" << j)
65
-
66
- if (i == 0 || j == 0) {
67
- DEBUG_PRINTLN(LCS, "RETURNING EMPTY")
68
- return Node::createCollection();
69
- }
70
-
71
- NodeDeque& xChildren = *(x.collection());
72
- NodeDeque& yChildren = *(y.collection());
73
-
74
- Node compareOut = Node::createNil();
75
- if (comparator(xChildren[i], yChildren[j], compareOut)) {
76
- DEBUG_PRINTLN(LCS, "RETURNING AFTER ELEM COMPARE")
77
- Node result = lcs_backtrace(c, x, y, i - 1, j - 1, comparator);
78
- result.collection()->push_back(compareOut);
79
- return result;
80
- }
81
-
82
- if (c[i][j - 1] > c[i - 1][j]) {
83
- DEBUG_PRINTLN(LCS, "RETURNING AFTER TABLE COMPARE")
84
- return lcs_backtrace(c, x, y, i, j - 1, comparator);
85
- }
86
-
87
- DEBUG_PRINTLN(LCS, "FINAL RETURN")
88
- return lcs_backtrace(c, x, y, i - 1, j, comparator);
89
- }
90
-
91
-
92
- /*
93
- This is the equivalent of ruby's Sass::Util.lcs_table.
94
-
95
- # Calculates the memoization table for the Least Common Subsequence algorithm.
96
- # Algorithm from http://en.wikipedia.org/wiki/Longest_common_subsequence_problem#Computing_the_length_of_the_LCS
97
- */
98
- template<typename ComparatorType>
99
- void lcs_table(const Node& x, const Node& y, const ComparatorType& comparator, LCSTable& out) {
100
- DEBUG_PRINTLN(LCS, "LCSTABLE: X=" << x << " Y=" << y)
101
-
102
- NodeDeque& xChildren = *(x.collection());
103
- NodeDeque& yChildren = *(y.collection());
104
-
105
- LCSTable c(xChildren.size(), std::vector<int>(yChildren.size()));
106
-
107
- // These shouldn't be necessary since the vector will be initialized to 0 already.
108
- // x.size.times {|i| c[i][0] = 0}
109
- // y.size.times {|j| c[0][j] = 0}
110
-
111
- for (size_t i = 1; i < xChildren.size(); i++) {
112
- for (size_t j = 1; j < yChildren.size(); j++) {
113
- Node compareOut = Node::createNil();
114
-
115
- if (comparator(xChildren[i], yChildren[j], compareOut)) {
116
- c[i][j] = c[i - 1][j - 1] + 1;
117
- } else {
118
- c[i][j] = std::max(c[i][j - 1], c[i - 1][j]);
119
- }
120
- }
121
- }
122
-
123
- out = c;
124
- }
125
-
126
-
127
- /*
128
- This is the equivalent of ruby's Sass::Util.lcs.
129
-
130
- # Computes a single longest common subsequence for `x` and `y`.
131
- # If there are more than one longest common subsequences,
132
- # the one returned is that which starts first in `x`.
133
-
134
- # @param x [NodeCollection]
135
- # @param y [NodeCollection]
136
- # @comparator An equality check between elements of `x` and `y`.
137
- # @return [NodeCollection] The LCS
138
-
139
- http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
140
- */
141
- template<typename ComparatorType>
142
- Node lcs(Node& x, Node& y, const ComparatorType& comparator) {
143
- DEBUG_PRINTLN(LCS, "LCS: X=" << x << " Y=" << y)
144
-
145
- Node newX = Node::createCollection();
146
- newX.collection()->push_back(Node::createNil());
147
- newX.plus(x);
148
-
149
- Node newY = Node::createCollection();
150
- newY.collection()->push_back(Node::createNil());
151
- newY.plus(y);
152
-
153
- LCSTable table;
154
- lcs_table(newX, newY, comparator, table);
155
-
156
- return lcs_backtrace(table, newX, newY, static_cast<int>(newX.collection()->size()) - 1, static_cast<int>(newY.collection()->size()) - 1, comparator);
157
- }
158
-
159
-
160
- /*
161
- This is the equivalent of ruby sass' Sass::Util.flatten and [].flatten.
162
- Sass::Util.flatten requires the number of levels to flatten, while
163
- [].flatten doesn't and will flatten the entire array. This function
164
- supports both.
165
-
166
- # Flattens the first `n` nested arrays. If n == -1, all arrays will be flattened
167
- #
168
- # @param arr [NodeCollection] The array to flatten
169
- # @param n [int] The number of levels to flatten
170
- # @return [NodeCollection] The flattened array
171
- */
172
- Node flatten(Node& arr, int n = -1);
173
-
174
-
175
- /*
176
- This is the equivalent of ruby's Sass::Util.group_by_to_a.
177
-
178
- # Performs the equivalent of `enum.group_by.to_a`, but with a guaranteed
179
- # order. Unlike [#hash_to_a], the resulting order isn't sorted key order;
180
- # instead, it's the same order as `#group_by` has under Ruby 1.9 (key
181
- # appearance order).
182
- #
183
- # @param enum [Enumerable]
184
- # @return [Array<[Object, Array]>] An array of pairs.
185
-
186
- TODO: update @param and @return once I know what those are.
187
-
188
- The following is the modified version of the ruby code that was more portable to C++. You
189
- should be able to drop it into ruby 3.2.19 and get the same results from ruby sass.
190
-
191
- def group_by_to_a(enum, &block)
192
- order = {}
193
-
194
- arr = []
195
-
196
- grouped = {}
197
-
198
- for e in enum do
199
- key = block[e]
200
- unless order.include?(key)
201
- order[key] = order.size
202
- end
203
-
204
- if not grouped.has_key?(key) then
205
- grouped[key] = [e]
206
- else
207
- grouped[key].push(e)
208
- end
209
- end
210
-
211
- grouped.each do |key, vals|
212
- arr[order[key]] = [key, vals]
213
- end
214
-
215
- arr
216
- end
217
-
218
- */
219
- template<typename EnumType, typename KeyType, typename KeyFunctorType>
220
- void group_by_to_a(std::vector<EnumType>& enumeration, KeyFunctorType& keyFunc, std::vector<std::pair<KeyType, std::vector<EnumType> > >& arr /*out*/) {
221
-
222
- std::map<unsigned int, KeyType> order;
223
-
224
- std::map<size_t, std::vector<EnumType> > grouped;
225
-
226
- for (typename std::vector<EnumType>::iterator enumIter = enumeration.begin(), enumIterEnd = enumeration.end(); enumIter != enumIterEnd; enumIter++) {
227
- EnumType& e = *enumIter;
228
-
229
- KeyType key = keyFunc(e);
230
-
231
- if (grouped.find(key->hash()) == grouped.end()) {
232
- order.insert(std::make_pair((unsigned int)order.size(), key));
233
-
234
- std::vector<EnumType> newCollection;
235
- newCollection.push_back(e);
236
- grouped.insert(std::make_pair(key->hash(), newCollection));
237
- } else {
238
- std::vector<EnumType>& collection = grouped.at(key->hash());
239
- collection.push_back(e);
240
- }
241
- }
242
-
243
- for (unsigned int index = 0; index < order.size(); index++) {
244
- KeyType& key = order.at(index);
245
- std::vector<EnumType>& values = grouped.at(key->hash());
246
-
247
- std::pair<KeyType, std::vector<EnumType> > grouping = std::make_pair(key, values);
248
-
249
- arr.push_back(grouping);
250
- }
251
- }
252
-
253
-
254
- }
255
-
256
- #endif
@@ -1,58 +0,0 @@
1
- // sass.hpp must go before all system headers to get the
2
- // __EXTENSIONS__ fix on Solaris.
3
- #include "sass.hpp"
4
-
5
- #include "ast.hpp"
6
- #include "subset_map.hpp"
7
-
8
- namespace Sass {
9
-
10
- void Subset_Map::put(const Compound_Selector_Obj& sel, const SubSetMapPair& value)
11
- {
12
- if (sel->empty()) throw std::runtime_error("internal error: subset map keys may not be empty");
13
- size_t index = values_.size();
14
- values_.push_back(value);
15
- for (size_t i = 0, S = sel->length(); i < S; ++i)
16
- {
17
- hash_[(*sel)[i]].push_back(std::make_pair(sel, index));
18
- }
19
- }
20
-
21
- std::vector<SubSetMapPair> Subset_Map::get_kv(const Compound_Selector_Obj& sel)
22
- {
23
- SimpleSelectorDict dict(sel->begin(), sel->end()); // XXX Set
24
- std::vector<size_t> indices;
25
- for (size_t i = 0, S = sel->length(); i < S; ++i) {
26
- if (!hash_.count((*sel)[i])) {
27
- continue;
28
- }
29
- const std::vector<std::pair<Compound_Selector_Obj, size_t> >& subsets = hash_[(*sel)[i]];
30
- for (const std::pair<Compound_Selector_Obj, size_t>& item : subsets) {
31
- bool include = true;
32
- for (const Simple_Selector_Obj& it : item.first->elements()) {
33
- auto found = dict.find(it);
34
- if (found == dict.end()) {
35
- include = false;
36
- break;
37
- }
38
- }
39
- if (include) indices.push_back(item.second);
40
- }
41
- }
42
- sort(indices.begin(), indices.end());
43
- std::vector<size_t>::iterator indices_end = unique(indices.begin(), indices.end());
44
- indices.resize(distance(indices.begin(), indices_end));
45
-
46
- std::vector<SubSetMapPair> results;
47
- for (size_t i = 0, S = indices.size(); i < S; ++i) {
48
- results.push_back(values_[indices[i]]);
49
- }
50
- return results;
51
- }
52
-
53
- std::vector<SubSetMapPair> Subset_Map::get_v(const Compound_Selector_Obj& sel)
54
- {
55
- return get_kv(sel);
56
- }
57
-
58
- }
@@ -1,76 +0,0 @@
1
- #ifndef SASS_SUBSET_MAP_H
2
- #define SASS_SUBSET_MAP_H
3
-
4
- #include <map>
5
- #include <set>
6
- #include <vector>
7
- #include <algorithm>
8
- #include <iterator>
9
-
10
- #include "ast_fwd_decl.hpp"
11
-
12
-
13
- // #include <iostream>
14
- // #include <sstream>
15
- // template<typename T>
16
- // std::string vector_to_string(std::vector<T> v)
17
- // {
18
- // std::stringstream buffer;
19
- // buffer << "[";
20
-
21
- // if (!v.empty())
22
- // { buffer << v[0]; }
23
- // else
24
- // { buffer << "]"; }
25
-
26
- // if (v.size() == 1)
27
- // { buffer << "]"; }
28
- // else
29
- // {
30
- // for (size_t i = 1, S = v.size(); i < S; ++i) buffer << ", " << v[i];
31
- // buffer << "]";
32
- // }
33
-
34
- // return buffer.str();
35
- // }
36
-
37
- // template<typename T>
38
- // std::string set_to_string(set<T> v)
39
- // {
40
- // std::stringstream buffer;
41
- // buffer << "[";
42
- // typename std::set<T>::iterator i = v.begin();
43
- // if (!v.empty())
44
- // { buffer << *i; }
45
- // else
46
- // { buffer << "]"; }
47
-
48
- // if (v.size() == 1)
49
- // { buffer << "]"; }
50
- // else
51
- // {
52
- // for (++i; i != v.end(); ++i) buffer << ", " << *i;
53
- // buffer << "]";
54
- // }
55
-
56
- // return buffer.str();
57
- // }
58
-
59
- namespace Sass {
60
-
61
- class Subset_Map {
62
- private:
63
- std::vector<SubSetMapPair> values_;
64
- std::map<Simple_Selector_Obj, std::vector<std::pair<Compound_Selector_Obj, size_t> >, OrderNodes > hash_;
65
- public:
66
- void put(const Compound_Selector_Obj& sel, const SubSetMapPair& value);
67
- std::vector<SubSetMapPair> get_kv(const Compound_Selector_Obj& s);
68
- std::vector<SubSetMapPair> get_v(const Compound_Selector_Obj& s);
69
- bool empty() { return values_.empty(); }
70
- void clear() { values_.clear(); hash_.clear(); }
71
- const std::vector<SubSetMapPair> values(void) { return values_; }
72
- };
73
-
74
- }
75
-
76
- #endif
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SassC
4
- module Native
5
- module LibC
6
- extend FFI::Library
7
- ffi_lib FFI::Library::LIBC
8
-
9
- # memory allocators
10
- attach_function :malloc, [:size_t], :pointer
11
- # attach_function :calloc, [:size_t], :pointer
12
- # attach_function :valloc, [:size_t], :pointer
13
- # attach_function :realloc, [:pointer, :size_t], :pointer
14
- # attach_function :free, [:pointer], :void
15
-
16
- # memory movers
17
- # attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
18
- # attach_function :bcopy, [:pointer, :pointer, :size_t], :void
19
- end
20
- end
21
- end