sassc 2.0.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.gitmodules +1 -1
  4. data/.travis.yml +9 -3
  5. data/CHANGELOG.md +36 -0
  6. data/CODE_OF_CONDUCT.md +1 -1
  7. data/README.md +1 -1
  8. data/Rakefile +43 -7
  9. data/ext/depend +4 -0
  10. data/ext/extconf.rb +92 -0
  11. data/ext/libsass/VERSION +1 -0
  12. data/ext/libsass/include/sass/base.h +9 -1
  13. data/ext/libsass/include/sass/context.h +5 -1
  14. data/ext/libsass/src/MurmurHash2.hpp +91 -0
  15. data/ext/libsass/src/ast.cpp +755 -2028
  16. data/ext/libsass/src/ast.hpp +492 -2477
  17. data/ext/libsass/src/{to_c.cpp → ast2c.cpp} +22 -16
  18. data/ext/libsass/src/ast2c.hpp +39 -0
  19. data/ext/libsass/src/ast_def_macros.hpp +70 -10
  20. data/ext/libsass/src/ast_fwd_decl.cpp +5 -3
  21. data/ext/libsass/src/ast_fwd_decl.hpp +107 -296
  22. data/ext/libsass/src/ast_helpers.hpp +292 -0
  23. data/ext/libsass/src/ast_sel_cmp.cpp +396 -0
  24. data/ext/libsass/src/ast_sel_super.cpp +539 -0
  25. data/ext/libsass/src/ast_sel_unify.cpp +275 -0
  26. data/ext/libsass/src/ast_sel_weave.cpp +616 -0
  27. data/ext/libsass/src/ast_selectors.cpp +1043 -0
  28. data/ext/libsass/src/ast_selectors.hpp +522 -0
  29. data/ext/libsass/src/ast_supports.cpp +114 -0
  30. data/ext/libsass/src/ast_supports.hpp +121 -0
  31. data/ext/libsass/src/ast_values.cpp +1154 -0
  32. data/ext/libsass/src/ast_values.hpp +498 -0
  33. data/ext/libsass/src/backtrace.cpp +11 -7
  34. data/ext/libsass/src/backtrace.hpp +5 -5
  35. data/ext/libsass/src/base64vlq.cpp +5 -2
  36. data/ext/libsass/src/base64vlq.hpp +1 -1
  37. data/ext/libsass/src/bind.cpp +35 -34
  38. data/ext/libsass/src/bind.hpp +3 -1
  39. data/ext/libsass/src/c2ast.cpp +64 -0
  40. data/ext/libsass/src/c2ast.hpp +14 -0
  41. data/ext/libsass/src/cencode.c +4 -6
  42. data/ext/libsass/src/check_nesting.cpp +83 -88
  43. data/ext/libsass/src/check_nesting.hpp +39 -34
  44. data/ext/libsass/src/color_maps.cpp +168 -164
  45. data/ext/libsass/src/color_maps.hpp +152 -160
  46. data/ext/libsass/src/constants.cpp +20 -0
  47. data/ext/libsass/src/constants.hpp +19 -0
  48. data/ext/libsass/src/context.cpp +104 -121
  49. data/ext/libsass/src/context.hpp +43 -55
  50. data/ext/libsass/src/cssize.cpp +103 -188
  51. data/ext/libsass/src/cssize.hpp +45 -51
  52. data/ext/libsass/src/dart_helpers.hpp +199 -0
  53. data/ext/libsass/src/debugger.hpp +524 -361
  54. data/ext/libsass/src/emitter.cpp +26 -26
  55. data/ext/libsass/src/emitter.hpp +20 -18
  56. data/ext/libsass/src/environment.cpp +41 -27
  57. data/ext/libsass/src/environment.hpp +33 -22
  58. data/ext/libsass/src/error_handling.cpp +92 -94
  59. data/ext/libsass/src/error_handling.hpp +73 -50
  60. data/ext/libsass/src/eval.cpp +380 -515
  61. data/ext/libsass/src/eval.hpp +64 -57
  62. data/ext/libsass/src/eval_selectors.cpp +75 -0
  63. data/ext/libsass/src/expand.cpp +322 -263
  64. data/ext/libsass/src/expand.hpp +55 -39
  65. data/ext/libsass/src/extender.cpp +1188 -0
  66. data/ext/libsass/src/extender.hpp +399 -0
  67. data/ext/libsass/src/extension.cpp +43 -0
  68. data/ext/libsass/src/extension.hpp +89 -0
  69. data/ext/libsass/src/file.cpp +134 -88
  70. data/ext/libsass/src/file.hpp +28 -37
  71. data/ext/libsass/src/fn_colors.cpp +596 -0
  72. data/ext/libsass/src/fn_colors.hpp +85 -0
  73. data/ext/libsass/src/fn_lists.cpp +285 -0
  74. data/ext/libsass/src/fn_lists.hpp +34 -0
  75. data/ext/libsass/src/fn_maps.cpp +94 -0
  76. data/ext/libsass/src/fn_maps.hpp +30 -0
  77. data/ext/libsass/src/fn_miscs.cpp +244 -0
  78. data/ext/libsass/src/fn_miscs.hpp +40 -0
  79. data/ext/libsass/src/fn_numbers.cpp +227 -0
  80. data/ext/libsass/src/fn_numbers.hpp +45 -0
  81. data/ext/libsass/src/fn_selectors.cpp +205 -0
  82. data/ext/libsass/src/fn_selectors.hpp +35 -0
  83. data/ext/libsass/src/fn_strings.cpp +268 -0
  84. data/ext/libsass/src/fn_strings.hpp +34 -0
  85. data/ext/libsass/src/fn_utils.cpp +158 -0
  86. data/ext/libsass/src/fn_utils.hpp +62 -0
  87. data/ext/libsass/src/inspect.cpp +253 -266
  88. data/ext/libsass/src/inspect.hpp +72 -74
  89. data/ext/libsass/src/json.cpp +2 -2
  90. data/ext/libsass/src/lexer.cpp +25 -84
  91. data/ext/libsass/src/lexer.hpp +5 -16
  92. data/ext/libsass/src/listize.cpp +27 -43
  93. data/ext/libsass/src/listize.hpp +14 -11
  94. data/ext/libsass/src/mapping.hpp +1 -0
  95. data/ext/libsass/src/memory.hpp +12 -0
  96. data/ext/libsass/src/memory/allocator.cpp +48 -0
  97. data/ext/libsass/src/memory/allocator.hpp +138 -0
  98. data/ext/libsass/src/memory/config.hpp +20 -0
  99. data/ext/libsass/src/memory/memory_pool.hpp +186 -0
  100. data/ext/libsass/src/memory/shared_ptr.cpp +33 -0
  101. data/ext/libsass/src/memory/shared_ptr.hpp +332 -0
  102. data/ext/libsass/src/operation.hpp +193 -143
  103. data/ext/libsass/src/operators.cpp +56 -29
  104. data/ext/libsass/src/operators.hpp +11 -11
  105. data/ext/libsass/src/ordered_map.hpp +112 -0
  106. data/ext/libsass/src/output.cpp +59 -75
  107. data/ext/libsass/src/output.hpp +15 -22
  108. data/ext/libsass/src/parser.cpp +662 -818
  109. data/ext/libsass/src/parser.hpp +96 -100
  110. data/ext/libsass/src/parser_selectors.cpp +189 -0
  111. data/ext/libsass/src/permutate.hpp +164 -0
  112. data/ext/libsass/src/plugins.cpp +12 -8
  113. data/ext/libsass/src/plugins.hpp +8 -8
  114. data/ext/libsass/src/position.cpp +10 -26
  115. data/ext/libsass/src/position.hpp +44 -21
  116. data/ext/libsass/src/prelexer.cpp +14 -8
  117. data/ext/libsass/src/prelexer.hpp +9 -9
  118. data/ext/libsass/src/remove_placeholders.cpp +59 -57
  119. data/ext/libsass/src/remove_placeholders.hpp +20 -18
  120. data/ext/libsass/src/sass.cpp +25 -18
  121. data/ext/libsass/src/sass.hpp +22 -14
  122. data/ext/libsass/src/sass2scss.cpp +49 -18
  123. data/ext/libsass/src/sass_context.cpp +104 -132
  124. data/ext/libsass/src/sass_context.hpp +2 -2
  125. data/ext/libsass/src/sass_functions.cpp +7 -4
  126. data/ext/libsass/src/sass_functions.hpp +1 -1
  127. data/ext/libsass/src/sass_values.cpp +26 -21
  128. data/ext/libsass/src/settings.hpp +19 -0
  129. data/ext/libsass/src/source.cpp +69 -0
  130. data/ext/libsass/src/source.hpp +95 -0
  131. data/ext/libsass/src/source_data.hpp +32 -0
  132. data/ext/libsass/src/source_map.cpp +27 -20
  133. data/ext/libsass/src/source_map.hpp +14 -11
  134. data/ext/libsass/src/stylesheet.cpp +22 -0
  135. data/ext/libsass/src/stylesheet.hpp +57 -0
  136. data/ext/libsass/src/to_value.cpp +24 -22
  137. data/ext/libsass/src/to_value.hpp +18 -22
  138. data/ext/libsass/src/units.cpp +28 -22
  139. data/ext/libsass/src/units.hpp +9 -8
  140. data/ext/libsass/src/utf8/checked.h +12 -10
  141. data/ext/libsass/src/utf8/core.h +3 -0
  142. data/ext/libsass/src/utf8_string.cpp +12 -10
  143. data/ext/libsass/src/utf8_string.hpp +7 -6
  144. data/ext/libsass/src/util.cpp +97 -107
  145. data/ext/libsass/src/util.hpp +74 -30
  146. data/ext/libsass/src/util_string.cpp +125 -0
  147. data/ext/libsass/src/util_string.hpp +73 -0
  148. data/ext/libsass/src/values.cpp +33 -24
  149. data/ext/libsass/src/values.hpp +2 -2
  150. data/lib/sassc.rb +24 -0
  151. data/lib/sassc/engine.rb +7 -5
  152. data/lib/sassc/functions_handler.rb +11 -13
  153. data/lib/sassc/native.rb +10 -9
  154. data/lib/sassc/native/native_functions_api.rb +0 -5
  155. data/lib/sassc/script.rb +4 -6
  156. data/lib/sassc/version.rb +1 -1
  157. data/sassc.gemspec +32 -12
  158. data/test/engine_test.rb +32 -2
  159. data/test/functions_test.rb +38 -1
  160. data/test/native_test.rb +4 -4
  161. metadata +95 -109
  162. data/ext/Rakefile +0 -3
  163. data/ext/libsass/.editorconfig +0 -15
  164. data/ext/libsass/.gitattributes +0 -2
  165. data/ext/libsass/.github/CONTRIBUTING.md +0 -65
  166. data/ext/libsass/.github/ISSUE_TEMPLATE.md +0 -54
  167. data/ext/libsass/.gitignore +0 -85
  168. data/ext/libsass/.travis.yml +0 -64
  169. data/ext/libsass/COPYING +0 -25
  170. data/ext/libsass/GNUmakefile.am +0 -88
  171. data/ext/libsass/INSTALL +0 -1
  172. data/ext/libsass/LICENSE +0 -25
  173. data/ext/libsass/Makefile +0 -351
  174. data/ext/libsass/Makefile.conf +0 -55
  175. data/ext/libsass/Readme.md +0 -104
  176. data/ext/libsass/SECURITY.md +0 -10
  177. data/ext/libsass/appveyor.yml +0 -91
  178. data/ext/libsass/configure.ac +0 -138
  179. data/ext/libsass/contrib/libsass.spec +0 -66
  180. data/ext/libsass/docs/README.md +0 -20
  181. data/ext/libsass/docs/api-context-example.md +0 -45
  182. data/ext/libsass/docs/api-context-internal.md +0 -163
  183. data/ext/libsass/docs/api-context.md +0 -295
  184. data/ext/libsass/docs/api-doc.md +0 -215
  185. data/ext/libsass/docs/api-function-example.md +0 -67
  186. data/ext/libsass/docs/api-function-internal.md +0 -8
  187. data/ext/libsass/docs/api-function.md +0 -74
  188. data/ext/libsass/docs/api-importer-example.md +0 -112
  189. data/ext/libsass/docs/api-importer-internal.md +0 -20
  190. data/ext/libsass/docs/api-importer.md +0 -86
  191. data/ext/libsass/docs/api-value-example.md +0 -55
  192. data/ext/libsass/docs/api-value-internal.md +0 -76
  193. data/ext/libsass/docs/api-value.md +0 -154
  194. data/ext/libsass/docs/build-on-darwin.md +0 -27
  195. data/ext/libsass/docs/build-on-gentoo.md +0 -55
  196. data/ext/libsass/docs/build-on-windows.md +0 -139
  197. data/ext/libsass/docs/build-shared-library.md +0 -35
  198. data/ext/libsass/docs/build-with-autotools.md +0 -78
  199. data/ext/libsass/docs/build-with-makefiles.md +0 -68
  200. data/ext/libsass/docs/build-with-mingw.md +0 -107
  201. data/ext/libsass/docs/build-with-visual-studio.md +0 -90
  202. data/ext/libsass/docs/build.md +0 -97
  203. data/ext/libsass/docs/compatibility-plan.md +0 -48
  204. data/ext/libsass/docs/contributing.md +0 -17
  205. data/ext/libsass/docs/custom-functions-internal.md +0 -122
  206. data/ext/libsass/docs/dev-ast-memory.md +0 -223
  207. data/ext/libsass/docs/implementations.md +0 -56
  208. data/ext/libsass/docs/plugins.md +0 -47
  209. data/ext/libsass/docs/setup-environment.md +0 -68
  210. data/ext/libsass/docs/source-map-internals.md +0 -51
  211. data/ext/libsass/docs/trace.md +0 -26
  212. data/ext/libsass/docs/triage.md +0 -17
  213. data/ext/libsass/docs/unicode.md +0 -39
  214. data/ext/libsass/extconf.rb +0 -6
  215. data/ext/libsass/include/sass/version.h.in +0 -12
  216. data/ext/libsass/m4/.gitkeep +0 -0
  217. data/ext/libsass/m4/m4-ax_cxx_compile_stdcxx_11.m4 +0 -167
  218. data/ext/libsass/res/resource.rc +0 -35
  219. data/ext/libsass/script/bootstrap +0 -13
  220. data/ext/libsass/script/branding +0 -10
  221. data/ext/libsass/script/ci-build-libsass +0 -134
  222. data/ext/libsass/script/ci-build-plugin +0 -62
  223. data/ext/libsass/script/ci-install-compiler +0 -6
  224. data/ext/libsass/script/ci-install-deps +0 -20
  225. data/ext/libsass/script/ci-report-coverage +0 -42
  226. data/ext/libsass/script/spec +0 -5
  227. data/ext/libsass/script/tap-driver +0 -652
  228. data/ext/libsass/script/tap-runner +0 -1
  229. data/ext/libsass/script/test-leaks.pl +0 -103
  230. data/ext/libsass/src/GNUmakefile.am +0 -54
  231. data/ext/libsass/src/extend.cpp +0 -2130
  232. data/ext/libsass/src/extend.hpp +0 -86
  233. data/ext/libsass/src/functions.cpp +0 -2234
  234. data/ext/libsass/src/functions.hpp +0 -198
  235. data/ext/libsass/src/memory/SharedPtr.cpp +0 -114
  236. data/ext/libsass/src/memory/SharedPtr.hpp +0 -206
  237. data/ext/libsass/src/node.cpp +0 -319
  238. data/ext/libsass/src/node.hpp +0 -118
  239. data/ext/libsass/src/paths.hpp +0 -71
  240. data/ext/libsass/src/sass_util.cpp +0 -149
  241. data/ext/libsass/src/sass_util.hpp +0 -256
  242. data/ext/libsass/src/subset_map.cpp +0 -55
  243. data/ext/libsass/src/subset_map.hpp +0 -76
  244. data/ext/libsass/src/support/libsass.pc.in +0 -11
  245. data/ext/libsass/src/to_c.hpp +0 -39
  246. data/ext/libsass/test/test_node.cpp +0 -94
  247. data/ext/libsass/test/test_paths.cpp +0 -28
  248. data/ext/libsass/test/test_selector_difference.cpp +0 -25
  249. data/ext/libsass/test/test_specificity.cpp +0 -25
  250. data/ext/libsass/test/test_subset_map.cpp +0 -472
  251. data/ext/libsass/test/test_superselector.cpp +0 -69
  252. data/ext/libsass/test/test_unification.cpp +0 -31
  253. data/ext/libsass/version.sh +0 -10
  254. data/ext/libsass/win/libsass.sln +0 -39
  255. data/ext/libsass/win/libsass.sln.DotSettings +0 -9
  256. data/ext/libsass/win/libsass.targets +0 -118
  257. data/ext/libsass/win/libsass.vcxproj +0 -188
  258. data/ext/libsass/win/libsass.vcxproj.filters +0 -357
  259. data/lib/sassc/native/lib_c.rb +0 -21
  260. data/lib/tasks/libsass.rb +0 -33
@@ -1,4 +1,8 @@
1
+ // sass.hpp must go before all system headers to get the
2
+ // __EXTENSIONS__ fix on Solaris.
1
3
  #include "sass.hpp"
4
+
5
+ #include <cmath>
2
6
  #include "operators.hpp"
3
7
 
4
8
  namespace Sass {
@@ -27,7 +31,7 @@ namespace Sass {
27
31
  };
28
32
 
29
33
  /* static function, has no pstate or traces */
30
- bool eq(Expression_Obj lhs, Expression_Obj rhs)
34
+ bool eq(ExpressionObj lhs, ExpressionObj rhs)
31
35
  {
32
36
  // operation is undefined if one is not a number
33
37
  if (!lhs || !rhs) throw Exception::UndefinedOperation(lhs, rhs, Sass_OP::EQ);
@@ -36,7 +40,7 @@ namespace Sass {
36
40
  }
37
41
 
38
42
  /* static function, throws OperationError, has no pstate or traces */
39
- bool cmp(Expression_Obj lhs, Expression_Obj rhs, const Sass_OP op)
43
+ bool cmp(ExpressionObj lhs, ExpressionObj rhs, const Sass_OP op)
40
44
  {
41
45
  // can only compare numbers!?
42
46
  Number_Obj l = Cast<Number>(lhs);
@@ -48,27 +52,38 @@ namespace Sass {
48
52
  }
49
53
 
50
54
  /* static functions, throws OperationError, has no pstate or traces */
51
- bool lt(Expression_Obj lhs, Expression_Obj rhs) { return cmp(lhs, rhs, Sass_OP::LT); }
52
- bool neq(Expression_Obj lhs, Expression_Obj rhs) { return eq(lhs, rhs) == false; }
53
- bool gt(Expression_Obj lhs, Expression_Obj rhs) { return !cmp(lhs, rhs, Sass_OP::GT) && neq(lhs, rhs); }
54
- bool lte(Expression_Obj lhs, Expression_Obj rhs) { return cmp(lhs, rhs, Sass_OP::LTE) || eq(lhs, rhs); }
55
- bool gte(Expression_Obj lhs, Expression_Obj rhs) { return !cmp(lhs, rhs, Sass_OP::GTE) || eq(lhs, rhs); }
55
+ bool lt(ExpressionObj lhs, ExpressionObj rhs) { return cmp(lhs, rhs, Sass_OP::LT); }
56
+ bool neq(ExpressionObj lhs, ExpressionObj rhs) { return eq(lhs, rhs) == false; }
57
+ bool gt(ExpressionObj lhs, ExpressionObj rhs) { return !cmp(lhs, rhs, Sass_OP::GT) && neq(lhs, rhs); }
58
+ bool lte(ExpressionObj lhs, ExpressionObj rhs) { return cmp(lhs, rhs, Sass_OP::LTE) || eq(lhs, rhs); }
59
+ bool gte(ExpressionObj lhs, ExpressionObj rhs) { return !cmp(lhs, rhs, Sass_OP::GTE) || eq(lhs, rhs); }
60
+
61
+ /* colour math deprecation warning */
62
+ void op_color_deprecation(enum Sass_OP op, sass::string lsh, sass::string rhs, const SourceSpan& pstate)
63
+ {
64
+ deprecated(
65
+ "The operation `" + lsh + " " + sass_op_to_name(op) + " " + rhs +
66
+ "` is deprecated and will be an error in future versions.",
67
+ "Consider using Sass's color functions instead.\n"
68
+ "https://sass-lang.com/documentation/Sass/Script/Functions.html#other_color_functions",
69
+ /*with_column=*/false, pstate);
70
+ }
56
71
 
57
72
  /* static function, throws OperationError, has no traces but optional pstate for returned value */
58
- Value_Ptr op_strings(Sass::Operand operand, Value& lhs, Value& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
73
+ Value* op_strings(Sass::Operand operand, Value& lhs, Value& rhs, struct Sass_Inspect_Options opt, const SourceSpan& pstate, bool delayed)
59
74
  {
60
75
  enum Sass_OP op = operand.operand;
61
76
 
62
- String_Quoted_Ptr lqstr = Cast<String_Quoted>(&lhs);
63
- String_Quoted_Ptr rqstr = Cast<String_Quoted>(&rhs);
77
+ String_Quoted* lqstr = Cast<String_Quoted>(&lhs);
78
+ String_Quoted* rqstr = Cast<String_Quoted>(&rhs);
64
79
 
65
- std::string lstr(lqstr ? lqstr->value() : lhs.to_string(opt));
66
- std::string rstr(rqstr ? rqstr->value() : rhs.to_string(opt));
80
+ sass::string lstr(lqstr ? lqstr->value() : lhs.to_string(opt));
81
+ sass::string rstr(rqstr ? rqstr->value() : rhs.to_string(opt));
67
82
 
68
83
  if (Cast<Null>(&lhs)) throw Exception::InvalidNullOperation(&lhs, &rhs, op);
69
84
  if (Cast<Null>(&rhs)) throw Exception::InvalidNullOperation(&lhs, &rhs, op);
70
85
 
71
- std::string sep;
86
+ sass::string sep;
72
87
  switch (op) {
73
88
  case Sass_OP::ADD: sep = ""; break;
74
89
  case Sass_OP::SUB: sep = "-"; break;
@@ -104,16 +119,21 @@ namespace Sass {
104
119
  return SASS_MEMORY_NEW(String_Constant, pstate, lstr + sep + rstr);
105
120
  }
106
121
 
122
+ /* ToDo: allow to operate also with hsla colors */
107
123
  /* static function, throws OperationError, has no traces but optional pstate for returned value */
108
- Value_Ptr op_colors(enum Sass_OP op, const Color& lhs, const Color& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
124
+ Value* op_colors(enum Sass_OP op, const Color_RGBA& lhs, const Color_RGBA& rhs, struct Sass_Inspect_Options opt, const SourceSpan& pstate, bool delayed)
109
125
  {
126
+
110
127
  if (lhs.a() != rhs.a()) {
111
128
  throw Exception::AlphaChannelsNotEqual(&lhs, &rhs, op);
112
129
  }
113
- if (op == Sass_OP::DIV && (!rhs.r() || !rhs.g() || !rhs.b())) {
130
+ if ((op == Sass_OP::DIV || op == Sass_OP::MOD) && (!rhs.r() || !rhs.g() || !rhs.b())) {
114
131
  throw Exception::ZeroDivisionError(lhs, rhs);
115
132
  }
116
- return SASS_MEMORY_NEW(Color,
133
+
134
+ op_color_deprecation(op, lhs.to_string(), rhs.to_string(), pstate);
135
+
136
+ return SASS_MEMORY_NEW(Color_RGBA,
117
137
  pstate,
118
138
  ops[op](lhs.r(), rhs.r()),
119
139
  ops[op](lhs.g(), rhs.g()),
@@ -122,18 +142,18 @@ namespace Sass {
122
142
  }
123
143
 
124
144
  /* static function, throws OperationError, has no traces but optional pstate for returned value */
125
- Value_Ptr op_numbers(enum Sass_OP op, const Number& lhs, const Number& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
145
+ Value* op_numbers(enum Sass_OP op, const Number& lhs, const Number& rhs, struct Sass_Inspect_Options opt, const SourceSpan& pstate, bool delayed)
126
146
  {
127
147
  double lval = lhs.value();
128
148
  double rval = rhs.value();
129
149
 
130
- if (op == Sass_OP::DIV && rval == 0) {
131
- std::string result(lval ? "Infinity" : "NaN");
132
- return SASS_MEMORY_NEW(String_Quoted, pstate, result);
150
+ if (op == Sass_OP::MOD && rval == 0) {
151
+ return SASS_MEMORY_NEW(String_Quoted, pstate, "NaN");
133
152
  }
134
153
 
135
- if (op == Sass_OP::MOD && rval == 0) {
136
- throw Exception::ZeroDivisionError(lhs, rhs);
154
+ if (op == Sass_OP::DIV && rval == 0) {
155
+ sass::string result(lval ? "Infinity" : "NaN");
156
+ return SASS_MEMORY_NEW(String_Quoted, pstate, result);
137
157
  }
138
158
 
139
159
  size_t l_n_units = lhs.numerators.size();
@@ -145,7 +165,7 @@ namespace Sass {
145
165
  if (l_n_units + l_d_units <= 1 && r_n_units + r_d_units <= 1) {
146
166
  if (lhs.numerators == rhs.numerators) {
147
167
  if (lhs.denominators == rhs.denominators) {
148
- Number_Ptr v = SASS_MEMORY_COPY(&lhs);
168
+ Number* v = SASS_MEMORY_COPY(&lhs);
149
169
  v->value(ops[op](lval, rval));
150
170
  return v;
151
171
  }
@@ -192,13 +212,15 @@ namespace Sass {
192
212
  }
193
213
 
194
214
  /* static function, throws OperationError, has no traces but optional pstate for returned value */
195
- Value_Ptr op_number_color(enum Sass_OP op, const Number& lhs, const Color& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
215
+ Value* op_number_color(enum Sass_OP op, const Number& lhs, const Color_RGBA& rhs, struct Sass_Inspect_Options opt, const SourceSpan& pstate, bool delayed)
196
216
  {
197
217
  double lval = lhs.value();
218
+
198
219
  switch (op) {
199
220
  case Sass_OP::ADD:
200
221
  case Sass_OP::MUL: {
201
- return SASS_MEMORY_NEW(Color,
222
+ op_color_deprecation(op, lhs.to_string(), rhs.to_string(opt), pstate);
223
+ return SASS_MEMORY_NEW(Color_RGBA,
202
224
  pstate,
203
225
  ops[op](lval, rhs.r()),
204
226
  ops[op](lval, rhs.g()),
@@ -207,7 +229,8 @@ namespace Sass {
207
229
  }
208
230
  case Sass_OP::SUB:
209
231
  case Sass_OP::DIV: {
210
- std::string color(rhs.to_string(opt));
232
+ sass::string color(rhs.to_string(opt));
233
+ op_color_deprecation(op, lhs.to_string(), color, pstate);
211
234
  return SASS_MEMORY_NEW(String_Quoted,
212
235
  pstate,
213
236
  lhs.to_string(opt)
@@ -220,14 +243,18 @@ namespace Sass {
220
243
  }
221
244
 
222
245
  /* static function, throws OperationError, has no traces but optional pstate for returned value */
223
- Value_Ptr op_color_number(enum Sass_OP op, const Color& lhs, const Number& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
246
+ Value* op_color_number(enum Sass_OP op, const Color_RGBA& lhs, const Number& rhs, struct Sass_Inspect_Options opt, const SourceSpan& pstate, bool delayed)
224
247
  {
225
248
  double rval = rhs.value();
226
- if (op == Sass_OP::DIV && rval == 0) {
249
+
250
+ if ((op == Sass_OP::DIV || op == Sass_OP::DIV) && rval == 0) {
227
251
  // comparison of Fixnum with Float failed?
228
252
  throw Exception::ZeroDivisionError(lhs, rhs);
229
253
  }
230
- return SASS_MEMORY_NEW(Color,
254
+
255
+ op_color_deprecation(op, lhs.to_string(), rhs.to_string(), pstate);
256
+
257
+ return SASS_MEMORY_NEW(Color_RGBA,
231
258
  pstate,
232
259
  ops[op](lhs.r(), rval),
233
260
  ops[op](lhs.g(), rval),
@@ -9,19 +9,19 @@ namespace Sass {
9
9
  namespace Operators {
10
10
 
11
11
  // equality operator using AST Node operator==
12
- bool eq(Expression_Obj, Expression_Obj);
13
- bool neq(Expression_Obj, Expression_Obj);
12
+ bool eq(ExpressionObj, ExpressionObj);
13
+ bool neq(ExpressionObj, ExpressionObj);
14
14
  // specific operators based on cmp and eq
15
- bool lt(Expression_Obj, Expression_Obj);
16
- bool gt(Expression_Obj, Expression_Obj);
17
- bool lte(Expression_Obj, Expression_Obj);
18
- bool gte(Expression_Obj, Expression_Obj);
15
+ bool lt(ExpressionObj, ExpressionObj);
16
+ bool gt(ExpressionObj, ExpressionObj);
17
+ bool lte(ExpressionObj, ExpressionObj);
18
+ bool gte(ExpressionObj, ExpressionObj);
19
19
  // arithmetic for all the combinations that matter
20
- Value_Ptr op_strings(Sass::Operand, Value&, Value&, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed = false);
21
- Value_Ptr op_colors(enum Sass_OP, const Color&, const Color&, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed = false);
22
- Value_Ptr op_numbers(enum Sass_OP, const Number&, const Number&, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed = false);
23
- Value_Ptr op_number_color(enum Sass_OP, const Number&, const Color&, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed = false);
24
- Value_Ptr op_color_number(enum Sass_OP, const Color&, const Number&, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed = false);
20
+ Value* op_strings(Sass::Operand, Value&, Value&, struct Sass_Inspect_Options opt, const SourceSpan& pstate, bool delayed = false);
21
+ Value* op_colors(enum Sass_OP, const Color_RGBA&, const Color_RGBA&, struct Sass_Inspect_Options opt, const SourceSpan& pstate, bool delayed = false);
22
+ Value* op_numbers(enum Sass_OP, const Number&, const Number&, struct Sass_Inspect_Options opt, const SourceSpan& pstate, bool delayed = false);
23
+ Value* op_number_color(enum Sass_OP, const Number&, const Color_RGBA&, struct Sass_Inspect_Options opt, const SourceSpan& pstate, bool delayed = false);
24
+ Value* op_color_number(enum Sass_OP, const Color_RGBA&, const Number&, struct Sass_Inspect_Options opt, const SourceSpan& pstate, bool delayed = false);
25
25
 
26
26
  };
27
27
 
@@ -0,0 +1,112 @@
1
+ #ifndef SASS_ORDERED_MAP_H
2
+ #define SASS_ORDERED_MAP_H
3
+
4
+ namespace Sass {
5
+
6
+ // ##########################################################################
7
+ // Very simple and limited container for insert ordered hash map.
8
+ // Piggy-back implementation on std::unordered_map and sass::vector
9
+ // ##########################################################################
10
+ template<
11
+ class Key,
12
+ class T,
13
+ class Hash = std::hash<Key>,
14
+ class KeyEqual = std::equal_to<Key>,
15
+ class Allocator = std::allocator<std::pair<const Key, T>>
16
+ >
17
+ class ordered_map {
18
+
19
+ private:
20
+
21
+ using map_type = typename std::unordered_map< Key, T, Hash, KeyEqual, Allocator>;
22
+ using map_iterator = typename std::unordered_map< Key, T, Hash, KeyEqual, Allocator>::iterator;
23
+ using map_const_iterator = typename std::unordered_map< Key, T, Hash, KeyEqual, Allocator>::const_iterator;
24
+
25
+ // The main unordered map
26
+ map_type _map;
27
+
28
+ // Keep insertion order
29
+ sass::vector<Key> _keys;
30
+ sass::vector<T> _values;
31
+
32
+ const KeyEqual _keyEqual;
33
+
34
+ public:
35
+
36
+ ordered_map() :
37
+ _keyEqual(KeyEqual())
38
+ {
39
+ }
40
+
41
+ ordered_map& operator= (const ordered_map& other) {
42
+ _map = other._map;
43
+ _keys = other._keys;
44
+ _values = other._values;
45
+ return *this;
46
+ }
47
+
48
+ std::pair<Key, T> front() {
49
+ return std::make_pair(
50
+ _keys.front(),
51
+ _values.front()
52
+ );
53
+ }
54
+
55
+ bool empty() const {
56
+ return _keys.empty();
57
+ }
58
+
59
+ void insert(const Key& key, const T& val) {
60
+ if (!hasKey(key)) {
61
+ _values.push_back(val);
62
+ _keys.push_back(key);
63
+ }
64
+ _map[key] = val;
65
+ }
66
+
67
+ bool hasKey(const Key& key) const {
68
+ return _map.find(key) != _map.end();
69
+ }
70
+
71
+ bool erase(const Key& key) {
72
+ _map.erase(key);
73
+ // find the position in the array
74
+ for (size_t i = 0; i < _keys.size(); i += 1) {
75
+ if (_keyEqual(key, _keys[i])) {
76
+ _keys.erase(_keys.begin() + i);
77
+ _values.erase(_values.begin() + i);
78
+ return true;
79
+ }
80
+ }
81
+ return false;
82
+ }
83
+
84
+ const sass::vector<Key>& keys() const { return _keys; }
85
+ const sass::vector<T>& values() const { return _values; }
86
+
87
+ const T& get(const Key& key) {
88
+ if (hasKey(key)) {
89
+ return _map[key];
90
+ }
91
+ throw std::runtime_error("Key does not exist");
92
+ }
93
+
94
+ using iterator = typename sass::vector<Key>::iterator;
95
+ using const_iterator = typename sass::vector<Key>::const_iterator;
96
+ using reverse_iterator = typename sass::vector<Key>::reverse_iterator;
97
+ using const_reverse_iterator = typename sass::vector<Key>::const_reverse_iterator;
98
+
99
+ typename sass::vector<Key>::iterator end() { return _keys.end(); }
100
+ typename sass::vector<Key>::iterator begin() { return _keys.begin(); }
101
+ typename sass::vector<Key>::reverse_iterator rend() { return _keys.rend(); }
102
+ typename sass::vector<Key>::reverse_iterator rbegin() { return _keys.rbegin(); }
103
+ typename sass::vector<Key>::const_iterator end() const { return _keys.end(); }
104
+ typename sass::vector<Key>::const_iterator begin() const { return _keys.begin(); }
105
+ typename sass::vector<Key>::const_reverse_iterator rend() const { return _keys.rend(); }
106
+ typename sass::vector<Key>::const_reverse_iterator rbegin() const { return _keys.rbegin(); }
107
+
108
+ };
109
+
110
+ }
111
+
112
+ #endif
@@ -1,6 +1,10 @@
1
+ // sass.hpp must go before all system headers to get the
2
+ // __EXTENSIONS__ fix on Solaris.
1
3
  #include "sass.hpp"
4
+
2
5
  #include "ast.hpp"
3
6
  #include "output.hpp"
7
+ #include "util.hpp"
4
8
 
5
9
  namespace Sass {
6
10
 
@@ -12,12 +16,12 @@ namespace Sass {
12
16
 
13
17
  Output::~Output() { }
14
18
 
15
- void Output::fallback_impl(AST_Node_Ptr n)
19
+ void Output::fallback_impl(AST_Node* n)
16
20
  {
17
21
  return n->perform(this);
18
22
  }
19
23
 
20
- void Output::operator()(Number_Ptr n)
24
+ void Output::operator()(Number* n)
21
25
  {
22
26
  // check for a valid unit here
23
27
  // includes result for reporting
@@ -26,17 +30,17 @@ namespace Sass {
26
30
  throw Exception::InvalidValue({}, *n);
27
31
  }
28
32
  // use values to_string facility
29
- std::string res = n->to_string(opt);
33
+ sass::string res = n->to_string(opt);
30
34
  // output the final token
31
35
  append_token(res, n);
32
36
  }
33
37
 
34
- void Output::operator()(Import_Ptr imp)
38
+ void Output::operator()(Import* imp)
35
39
  {
36
40
  top_nodes.push_back(imp);
37
41
  }
38
42
 
39
- void Output::operator()(Map_Ptr m)
43
+ void Output::operator()(Map* m)
40
44
  {
41
45
  // should be handle in check_expression
42
46
  throw Exception::InvalidValue({}, *m);
@@ -73,7 +77,7 @@ namespace Sass {
73
77
  // declare the charset
74
78
  if (output_style() != COMPRESSED)
75
79
  charset = "@charset \"UTF-8\";"
76
- + std::string(opt.linefeed);
80
+ + sass::string(opt.linefeed);
77
81
  else charset = "\xEF\xBB\xBF";
78
82
  // abort search
79
83
  break;
@@ -86,9 +90,8 @@ namespace Sass {
86
90
 
87
91
  }
88
92
 
89
- void Output::operator()(Comment_Ptr c)
93
+ void Output::operator()(Comment* c)
90
94
  {
91
- std::string txt = c->text()->to_string(opt);
92
95
  // if (indentation && txt == "/**/") return;
93
96
  bool important = c->is_important();
94
97
  if (output_style() != COMPRESSED || important) {
@@ -108,16 +111,18 @@ namespace Sass {
108
111
  }
109
112
  }
110
113
 
111
- void Output::operator()(Ruleset_Ptr r)
114
+ void Output::operator()(StyleRule* r)
112
115
  {
113
- Selector_Obj s = r->selector();
114
- Block_Obj b = r->block();
116
+ Block_Obj b = r->block();
117
+ SelectorListObj s = r->selector();
118
+
119
+ if (!s || s->empty()) return;
115
120
 
116
121
  // Filter out rulesets that aren't printable (process its children though)
117
122
  if (!Util::isPrintable(r, output_style())) {
118
123
  for (size_t i = 0, L = b->length(); i < L; ++i) {
119
- const Statement_Obj& stm = b->at(i);
120
- if (Cast<Has_Block>(stm)) {
124
+ const Statement_Obj& stm = b->get(i);
125
+ if (Cast<ParentStatement>(stm)) {
121
126
  if (!Cast<Declaration>(stm)) {
122
127
  stm->perform(this);
123
128
  }
@@ -126,12 +131,14 @@ namespace Sass {
126
131
  return;
127
132
  }
128
133
 
129
- if (output_style() == NESTED) indentation += r->tabs();
134
+ if (output_style() == NESTED) {
135
+ indentation += r->tabs();
136
+ }
130
137
  if (opt.source_comments) {
131
- std::stringstream ss;
138
+ sass::ostream ss;
132
139
  append_indentation();
133
- std::string path(File::abs2rel(r->pstate().path));
134
- ss << "/* line " << r->pstate().line + 1 << ", " << path << " */";
140
+ sass::string path(File::abs2rel(r->pstate().getPath()));
141
+ ss << "/* line " << r->pstate().getLine() << ", " << path << " */";
135
142
  append_string(ss.str());
136
143
  append_optional_linefeed();
137
144
  }
@@ -139,22 +146,22 @@ namespace Sass {
139
146
  if (s) s->perform(this);
140
147
  append_scope_opener(b);
141
148
  for (size_t i = 0, L = b->length(); i < L; ++i) {
142
- Statement_Obj stm = b->at(i);
149
+ Statement_Obj stm = b->get(i);
143
150
  bool bPrintExpression = true;
144
151
  // Check print conditions
145
- if (Declaration_Ptr dec = Cast<Declaration>(stm)) {
146
- if (String_Constant_Ptr valConst = Cast<String_Constant>(dec->value())) {
147
- std::string val(valConst->value());
148
- if (String_Quoted_Ptr qstr = Cast<String_Quoted>(valConst)) {
152
+ if (Declaration* dec = Cast<Declaration>(stm)) {
153
+ if (const String_Constant* valConst = Cast<String_Constant>(dec->value())) {
154
+ const sass::string& val = valConst->value();
155
+ if (const String_Quoted* qstr = Cast<const String_Quoted>(valConst)) {
149
156
  if (!qstr->quote_mark() && val.empty()) {
150
157
  bPrintExpression = false;
151
158
  }
152
159
  }
153
160
  }
154
- else if (List_Ptr list = Cast<List>(dec->value())) {
161
+ else if (List* list = Cast<List>(dec->value())) {
155
162
  bool all_invisible = true;
156
163
  for (size_t list_i = 0, list_L = list->length(); list_i < list_L; ++list_i) {
157
- Expression_Ptr item = list->at(list_i);
164
+ Expression* item = list->get(list_i);
158
165
  if (!item->is_invisible()) all_invisible = false;
159
166
  }
160
167
  if (all_invisible && !list->is_bracketed()) bPrintExpression = false;
@@ -169,7 +176,7 @@ namespace Sass {
169
176
  append_scope_closer(b);
170
177
 
171
178
  }
172
- void Output::operator()(Keyframe_Rule_Ptr r)
179
+ void Output::operator()(Keyframe_Rule* r)
173
180
  {
174
181
  Block_Obj b = r->block();
175
182
  Selector_Obj v = r->name();
@@ -185,25 +192,25 @@ namespace Sass {
185
192
 
186
193
  append_scope_opener();
187
194
  for (size_t i = 0, L = b->length(); i < L; ++i) {
188
- Statement_Obj stm = b->at(i);
195
+ Statement_Obj stm = b->get(i);
189
196
  stm->perform(this);
190
197
  if (i < L - 1) append_special_linefeed();
191
198
  }
192
199
  append_scope_closer();
193
200
  }
194
201
 
195
- void Output::operator()(Supports_Block_Ptr f)
202
+ void Output::operator()(SupportsRule* f)
196
203
  {
197
204
  if (f->is_invisible()) return;
198
205
 
199
- Supports_Condition_Obj c = f->condition();
206
+ SupportsConditionObj c = f->condition();
200
207
  Block_Obj b = f->block();
201
208
 
202
209
  // Filter out feature blocks that aren't printable (process its children though)
203
210
  if (!Util::isPrintable(f, output_style())) {
204
211
  for (size_t i = 0, L = b->length(); i < L; ++i) {
205
- Statement_Obj stm = b->at(i);
206
- if (Cast<Has_Block>(stm)) {
212
+ Statement_Obj stm = b->get(i);
213
+ if (Cast<ParentStatement>(stm)) {
207
214
  stm->perform(this);
208
215
  }
209
216
  }
@@ -218,7 +225,7 @@ namespace Sass {
218
225
  append_scope_opener();
219
226
 
220
227
  for (size_t i = 0, L = b->length(); i < L; ++i) {
221
- Statement_Obj stm = b->at(i);
228
+ Statement_Obj stm = b->get(i);
222
229
  stm->perform(this);
223
230
  if (i < L - 1) append_special_linefeed();
224
231
  }
@@ -229,48 +236,28 @@ namespace Sass {
229
236
 
230
237
  }
231
238
 
232
- void Output::operator()(Media_Block_Ptr m)
239
+ void Output::operator()(CssMediaRule* rule)
233
240
  {
234
- if (m->is_invisible()) return;
235
-
236
- Block_Obj b = m->block();
237
-
238
- // Filter out media blocks that aren't printable (process its children though)
239
- if (!Util::isPrintable(m, output_style())) {
240
- for (size_t i = 0, L = b->length(); i < L; ++i) {
241
- Statement_Obj stm = b->at(i);
242
- if (Cast<Has_Block>(stm)) {
243
- stm->perform(this);
244
- }
245
- }
246
- return;
247
- }
248
- if (output_style() == NESTED) indentation += m->tabs();
249
- append_indentation();
250
- append_token("@media", m);
251
- append_mandatory_space();
252
- in_media_block = true;
253
- m->media_queries()->perform(this);
254
- in_media_block = false;
255
- append_scope_opener();
256
-
257
- for (size_t i = 0, L = b->length(); i < L; ++i) {
258
- if (b->at(i)) {
259
- Statement_Obj stm = b->at(i);
260
- stm->perform(this);
261
- }
262
- if (i < L - 1) append_special_linefeed();
241
+ // Avoid null pointer exception
242
+ if (rule == nullptr) return;
243
+ // Skip empty/invisible rule
244
+ if (rule->isInvisible()) return;
245
+ // Avoid null pointer exception
246
+ if (rule->block() == nullptr) return;
247
+ // Skip empty/invisible rule
248
+ if (rule->block()->isInvisible()) return;
249
+ // Skip if block is empty/invisible
250
+ if (Util::isPrintable(rule, output_style())) {
251
+ // Let inspect do its magic
252
+ Inspect::operator()(rule);
263
253
  }
264
-
265
- if (output_style() == NESTED) indentation -= m->tabs();
266
- append_scope_closer();
267
254
  }
268
255
 
269
- void Output::operator()(Directive_Ptr a)
256
+ void Output::operator()(AtRule* a)
270
257
  {
271
- std::string kwd = a->keyword();
258
+ sass::string kwd = a->keyword();
272
259
  Selector_Obj s = a->selector();
273
- Expression_Obj v = a->value();
260
+ ExpressionObj v = a->value();
274
261
  Block_Obj b = a->block();
275
262
 
276
263
  append_indentation();
@@ -301,15 +288,15 @@ namespace Sass {
301
288
  bool format = kwd != "@font-face";;
302
289
 
303
290
  for (size_t i = 0, L = b->length(); i < L; ++i) {
304
- Statement_Obj stm = b->at(i);
305
- stm->perform(this);
291
+ Statement_Obj stm = b->get(i);
292
+ if (stm) stm->perform(this);
306
293
  if (i < L - 1 && format) append_special_linefeed();
307
294
  }
308
295
 
309
296
  append_scope_closer();
310
297
  }
311
298
 
312
- void Output::operator()(String_Quoted_Ptr s)
299
+ void Output::operator()(String_Quoted* s)
313
300
  {
314
301
  if (s->quote_mark()) {
315
302
  append_token(quote(s->value(), s->quote_mark()), s);
@@ -320,12 +307,9 @@ namespace Sass {
320
307
  }
321
308
  }
322
309
 
323
- void Output::operator()(String_Constant_Ptr s)
310
+ void Output::operator()(String_Constant* s)
324
311
  {
325
- std::string value(s->value());
326
- if (s->can_compress_whitespace() && output_style() == COMPRESSED) {
327
- value.erase(std::remove_if(value.begin(), value.end(), ::isspace), value.end());
328
- }
312
+ sass::string value(s->value());
329
313
  if (!in_comment && !in_custom_property) {
330
314
  append_token(string_to_output(value), s);
331
315
  } else {