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
@@ -467,7 +467,7 @@ namespace Sass
467
467
  // right trim input
468
468
  sass = rtrim(sass);
469
469
 
470
- // get postion of first meaningfull character in string
470
+ // get position of first meaningfull character in string
471
471
  size_t pos_left = sass.find_first_not_of(SASS2SCSS_FIND_WHITESPACE);
472
472
 
473
473
  // special case for final run
@@ -557,7 +557,7 @@ namespace Sass
557
557
  // default to a selector
558
558
  // change back if property found
559
559
  converter.selector = true;
560
- // get postion of first whitespace char
560
+ // get position of first whitespace char
561
561
  size_t pos_wspace = sass.find_first_of(SASS2SCSS_FIND_WHITESPACE, pos_left);
562
562
  // assertion check for valid result
563
563
  if (pos_wspace != std::string::npos)
@@ -580,7 +580,7 @@ namespace Sass
580
580
  // assertion for valid result
581
581
  if (pos_colon != std::string::npos)
582
582
  {
583
- // ... after the first word (skip begining colons)
583
+ // ... after the first word (skip beginning colons)
584
584
  pos_colon = sass.find_first_of(":", pos_colon);
585
585
  // it is a selector if there was no colon found
586
586
  converter.selector = pos_colon == std::string::npos;
@@ -758,7 +758,7 @@ namespace Sass
758
758
  scss += flush(sass, converter);
759
759
  }
760
760
 
761
- // get postion of last meaningfull char
761
+ // get position of last meaningfull char
762
762
  size_t pos_right = sass.find_last_not_of(SASS2SCSS_FIND_WHITESPACE);
763
763
 
764
764
  // check for invalid result
@@ -1,44 +1,49 @@
1
1
  // sass.hpp must go before all system headers to get the
2
2
  // __EXTENSIONS__ fix on Solaris.
3
3
  #include "sass.hpp"
4
-
5
- #include <cstring>
6
- #include <stdexcept>
7
- #include <sstream>
8
- #include <string>
9
- #include <vector>
10
-
11
- #include "sass.h"
12
4
  #include "ast.hpp"
13
- #include "file.hpp"
14
- #include "json.hpp"
15
- #include "util.hpp"
16
- #include "context.hpp"
17
- #include "sass_context.hpp"
5
+
18
6
  #include "sass_functions.hpp"
19
- #include "ast_fwd_decl.hpp"
20
- #include "error_handling.hpp"
7
+ #include "json.hpp"
21
8
 
22
9
  #define LFEED "\n"
23
10
 
24
11
  // C++ helper
25
12
  namespace Sass {
26
- // see sass_copy_c_string(std::string str)
27
- static inline JsonNode* json_mkstream(const std::stringstream& stream)
13
+ // see sass_copy_c_string(sass::string str)
14
+ static inline JsonNode* json_mkstream(const sass::ostream& stream)
28
15
  {
29
16
  // hold on to string on stack!
30
- std::string str(stream.str());
17
+ sass::string str(stream.str());
31
18
  return json_mkstring(str.c_str());
32
19
  }
33
20
 
21
+ static void handle_string_error(Sass_Context* c_ctx, const sass::string& msg, int severety)
22
+ {
23
+ sass::ostream msg_stream;
24
+ JsonNode* json_err = json_mkobject();
25
+ msg_stream << "Internal Error: " << msg << std::endl;
26
+ json_append_member(json_err, "status", json_mknumber(severety));
27
+ json_append_member(json_err, "message", json_mkstring(msg.c_str()));
28
+ json_append_member(json_err, "formatted", json_mkstream(msg_stream));
29
+ try { c_ctx->error_json = json_stringify(json_err, " "); }
30
+ catch (...) {}
31
+ c_ctx->error_message = sass_copy_string(msg_stream.str());
32
+ c_ctx->error_text = sass_copy_c_string(msg.c_str());
33
+ c_ctx->error_status = severety;
34
+ c_ctx->output_string = 0;
35
+ c_ctx->source_map_string = 0;
36
+ json_delete(json_err);
37
+ }
38
+
34
39
  static int handle_error(Sass_Context* c_ctx) {
35
40
  try {
36
41
  throw;
37
42
  }
38
43
  catch (Exception::Base& e) {
39
- std::stringstream msg_stream;
40
- std::string cwd(Sass::File::get_cwd());
41
- std::string msg_prefix(e.errtype());
44
+ sass::ostream msg_stream;
45
+ sass::string cwd(Sass::File::get_cwd());
46
+ sass::string msg_prefix(e.errtype());
42
47
  bool got_newline = false;
43
48
  msg_stream << msg_prefix << ": ";
44
49
  const char* msg = e.what();
@@ -50,7 +55,7 @@ namespace Sass {
50
55
  got_newline = true;
51
56
  }
52
57
  else if (got_newline) {
53
- msg_stream << std::string(msg_prefix.size() + 2, ' ');
58
+ msg_stream << sass::string(msg_prefix.size() + 2, ' ');
54
59
  got_newline = false;
55
60
  }
56
61
  msg_stream << *msg;
@@ -60,24 +65,25 @@ namespace Sass {
60
65
 
61
66
  if (e.traces.empty()) {
62
67
  // we normally should have some traces, still here as a fallback
63
- std::string rel_path(Sass::File::abs2rel(e.pstate.path, cwd, cwd));
64
- msg_stream << std::string(msg_prefix.size() + 2, ' ');
65
- msg_stream << " on line " << e.pstate.line + 1 << " of " << rel_path << "\n";
68
+ sass::string rel_path(Sass::File::abs2rel(e.pstate.getPath(), cwd, cwd));
69
+ msg_stream << sass::string(msg_prefix.size() + 2, ' ');
70
+ msg_stream << " on line " << e.pstate.getLine() << " of " << rel_path << "\n";
66
71
  }
67
72
  else {
68
- std::string rel_path(Sass::File::abs2rel(e.pstate.path, cwd, cwd));
73
+ sass::string rel_path(Sass::File::abs2rel(e.pstate.getPath(), cwd, cwd));
69
74
  msg_stream << traces_to_string(e.traces, " ");
70
75
  }
71
76
 
72
77
  // now create the code trace (ToDo: maybe have util functions?)
73
- if (e.pstate.line != std::string::npos &&
74
- e.pstate.column != std::string::npos &&
75
- e.pstate.src != nullptr) {
76
- size_t lines = e.pstate.line;
78
+ if (e.pstate.position.line != sass::string::npos &&
79
+ e.pstate.position.column != sass::string::npos &&
80
+ e.pstate.source != nullptr) {
81
+ Offset offset(e.pstate.position);
82
+ size_t lines = offset.line;
77
83
  // scan through src until target line
78
84
  // move line_beg pointer to line start
79
85
  const char* line_beg;
80
- for (line_beg = e.pstate.src; *line_beg != '\0'; ++line_beg) {
86
+ for (line_beg = e.pstate.getRawData(); *line_beg != '\0'; ++line_beg) {
81
87
  if (lines == 0) break;
82
88
  if (*line_beg == '\n') --lines;
83
89
  }
@@ -91,12 +97,12 @@ namespace Sass {
91
97
  size_t move_in = 0; size_t shorten = 0;
92
98
  size_t left_chars = 42; size_t max_chars = 76;
93
99
  // reported excerpt should not exceed `max_chars` chars
94
- if (e.pstate.column > line_len) left_chars = e.pstate.column;
95
- if (e.pstate.column > left_chars) move_in = e.pstate.column - left_chars;
100
+ if (offset.column > line_len) left_chars = offset.column;
101
+ if (offset.column > left_chars) move_in = offset.column - left_chars;
96
102
  if (line_len > max_chars + move_in) shorten = line_len - move_in - max_chars;
97
103
  utf8::advance(line_beg, move_in, line_end);
98
104
  utf8::retreat(line_end, shorten, line_beg);
99
- std::string sanitized; std::string marker(e.pstate.column - move_in, '-');
105
+ sass::string sanitized; sass::string marker(offset.column - move_in, '-');
100
106
  utf8::replace_invalid(line_beg, line_end, std::back_inserter(sanitized));
101
107
  msg_stream << ">> " << sanitized << "\n";
102
108
  msg_stream << " " << marker << "^\n";
@@ -104,102 +110,40 @@ namespace Sass {
104
110
 
105
111
  JsonNode* json_err = json_mkobject();
106
112
  json_append_member(json_err, "status", json_mknumber(1));
107
- json_append_member(json_err, "file", json_mkstring(e.pstate.path));
108
- json_append_member(json_err, "line", json_mknumber((double)(e.pstate.line + 1)));
109
- json_append_member(json_err, "column", json_mknumber((double)(e.pstate.column + 1)));
113
+ json_append_member(json_err, "file", json_mkstring(e.pstate.getPath()));
114
+ json_append_member(json_err, "line", json_mknumber((double)(e.pstate.getLine())));
115
+ json_append_member(json_err, "column", json_mknumber((double)(e.pstate.getColumn())));
110
116
  json_append_member(json_err, "message", json_mkstring(e.what()));
111
117
  json_append_member(json_err, "formatted", json_mkstream(msg_stream));
112
118
  try { c_ctx->error_json = json_stringify(json_err, " "); }
113
- catch (...) {}
119
+ catch (...) {} // silently ignore this error?
114
120
  c_ctx->error_message = sass_copy_string(msg_stream.str());
115
121
  c_ctx->error_text = sass_copy_c_string(e.what());
116
122
  c_ctx->error_status = 1;
117
- c_ctx->error_file = sass_copy_c_string(e.pstate.path);
118
- c_ctx->error_line = e.pstate.line + 1;
119
- c_ctx->error_column = e.pstate.column + 1;
120
- c_ctx->error_src = e.pstate.src;
123
+ c_ctx->error_file = sass_copy_c_string(e.pstate.getPath());
124
+ c_ctx->error_line = e.pstate.getLine();
125
+ c_ctx->error_column = e.pstate.getColumn();
126
+ c_ctx->error_src = sass_copy_c_string(e.pstate.getRawData());
121
127
  c_ctx->output_string = 0;
122
128
  c_ctx->source_map_string = 0;
123
129
  json_delete(json_err);
124
130
  }
125
131
  catch (std::bad_alloc& ba) {
126
- std::stringstream msg_stream;
127
- JsonNode* json_err = json_mkobject();
128
- msg_stream << "Unable to allocate memory: " << ba.what() << std::endl;
129
- json_append_member(json_err, "status", json_mknumber(2));
130
- json_append_member(json_err, "message", json_mkstring(ba.what()));
131
- json_append_member(json_err, "formatted", json_mkstream(msg_stream));
132
- try { c_ctx->error_json = json_stringify(json_err, " "); }
133
- catch (...) {}
134
- c_ctx->error_message = sass_copy_string(msg_stream.str());
135
- c_ctx->error_text = sass_copy_c_string(ba.what());
136
- c_ctx->error_status = 2;
137
- c_ctx->output_string = 0;
138
- c_ctx->source_map_string = 0;
139
- json_delete(json_err);
132
+ sass::ostream msg_stream;
133
+ msg_stream << "Unable to allocate memory: " << ba.what();
134
+ handle_string_error(c_ctx, msg_stream.str(), 2);
140
135
  }
141
136
  catch (std::exception& e) {
142
- std::stringstream msg_stream;
143
- JsonNode* json_err = json_mkobject();
144
- msg_stream << "Internal Error: " << e.what() << std::endl;
145
- json_append_member(json_err, "status", json_mknumber(3));
146
- json_append_member(json_err, "message", json_mkstring(e.what()));
147
- json_append_member(json_err, "formatted", json_mkstream(msg_stream));
148
- try { c_ctx->error_json = json_stringify(json_err, " "); }
149
- catch (...) {}
150
- c_ctx->error_message = sass_copy_string(msg_stream.str());
151
- c_ctx->error_text = sass_copy_c_string(e.what());
152
- c_ctx->error_status = 3;
153
- c_ctx->output_string = 0;
154
- c_ctx->source_map_string = 0;
155
- json_delete(json_err);
137
+ handle_string_error(c_ctx, e.what(), 3);
156
138
  }
157
- catch (std::string& e) {
158
- std::stringstream msg_stream;
159
- JsonNode* json_err = json_mkobject();
160
- msg_stream << "Internal Error: " << e << std::endl;
161
- json_append_member(json_err, "status", json_mknumber(4));
162
- json_append_member(json_err, "message", json_mkstring(e.c_str()));
163
- json_append_member(json_err, "formatted", json_mkstream(msg_stream));
164
- try { c_ctx->error_json = json_stringify(json_err, " "); }
165
- catch (...) {}
166
- c_ctx->error_message = sass_copy_string(msg_stream.str());
167
- c_ctx->error_text = sass_copy_c_string(e.c_str());
168
- c_ctx->error_status = 4;
169
- c_ctx->output_string = 0;
170
- c_ctx->source_map_string = 0;
171
- json_delete(json_err);
139
+ catch (sass::string& e) {
140
+ handle_string_error(c_ctx, e, 4);
172
141
  }
173
142
  catch (const char* e) {
174
- std::stringstream msg_stream;
175
- JsonNode* json_err = json_mkobject();
176
- msg_stream << "Internal Error: " << e << std::endl;
177
- json_append_member(json_err, "status", json_mknumber(4));
178
- json_append_member(json_err, "message", json_mkstring(e));
179
- json_append_member(json_err, "formatted", json_mkstream(msg_stream));
180
- try { c_ctx->error_json = json_stringify(json_err, " "); }
181
- catch (...) {}
182
- c_ctx->error_message = sass_copy_string(msg_stream.str());
183
- c_ctx->error_text = sass_copy_c_string(e);
184
- c_ctx->error_status = 4;
185
- c_ctx->output_string = 0;
186
- c_ctx->source_map_string = 0;
187
- json_delete(json_err);
143
+ handle_string_error(c_ctx, e, 4);
188
144
  }
189
145
  catch (...) {
190
- std::stringstream msg_stream;
191
- JsonNode* json_err = json_mkobject();
192
- msg_stream << "Unknown error occurred" << std::endl;
193
- json_append_member(json_err, "status", json_mknumber(5));
194
- json_append_member(json_err, "message", json_mkstring("unknown"));
195
- try { c_ctx->error_json = json_stringify(json_err, " "); }
196
- catch (...) {}
197
- c_ctx->error_message = sass_copy_string(msg_stream.str());
198
- c_ctx->error_text = sass_copy_c_string("unknown");
199
- c_ctx->error_status = 5;
200
- c_ctx->output_string = 0;
201
- c_ctx->source_map_string = 0;
202
- json_delete(json_err);
146
+ handle_string_error(c_ctx, "unknown", 5);
203
147
  }
204
148
  return c_ctx->error_status;
205
149
  }
@@ -226,8 +170,8 @@ namespace Sass {
226
170
  try {
227
171
 
228
172
  // get input/output path from options
229
- std::string input_path = safe_str(c_ctx->input_path);
230
- std::string output_path = safe_str(c_ctx->output_path);
173
+ sass::string input_path = safe_str(c_ctx->input_path);
174
+ sass::string output_path = safe_str(c_ctx->output_path);
231
175
 
232
176
  // maybe skip some entries of included files
233
177
  // we do not include stdin for data contexts
@@ -334,10 +278,10 @@ extern "C" {
334
278
  c_ctx->error_message = 0;
335
279
  c_ctx->error_status = 0;
336
280
  // reset error position
337
- c_ctx->error_src = 0;
338
281
  c_ctx->error_file = 0;
339
- c_ctx->error_line = std::string::npos;
340
- c_ctx->error_column = std::string::npos;
282
+ c_ctx->error_src = 0;
283
+ c_ctx->error_line = sass::string::npos;
284
+ c_ctx->error_column = sass::string::npos;
341
285
 
342
286
  // allocate a new compiler instance
343
287
  void* ctxmem = calloc(1, sizeof(struct Sass_Compiler));
@@ -399,7 +343,9 @@ extern "C" {
399
343
 
400
344
  Sass_File_Context* ADDCALL sass_make_file_context(const char* input_path)
401
345
  {
402
- SharedObj::setTaint(true); // needed for static colors
346
+ #ifdef DEBUG_SHARED_PTR
347
+ SharedObj::setTaint(true);
348
+ #endif
403
349
  struct Sass_File_Context* ctx = (struct Sass_File_Context*) calloc(1, sizeof(struct Sass_File_Context));
404
350
  if (ctx == 0) { std::cerr << "Error allocating memory for file context" << std::endl; return 0; }
405
351
  ctx->type = SASS_CONTEXT_FILE;
@@ -416,6 +362,9 @@ extern "C" {
416
362
 
417
363
  Sass_Data_Context* ADDCALL sass_make_data_context(char* source_string)
418
364
  {
365
+ #ifdef DEBUG_SHARED_PTR
366
+ SharedObj::setTaint(true);
367
+ #endif
419
368
  struct Sass_Data_Context* ctx = (struct Sass_Data_Context*) calloc(1, sizeof(struct Sass_Data_Context));
420
369
  if (ctx == 0) { std::cerr << "Error allocating memory for data context" << std::endl; return 0; }
421
370
  ctx->type = SASS_CONTEXT_DATA;
@@ -451,7 +400,7 @@ extern "C" {
451
400
  return data_ctx->error_status;
452
401
  try {
453
402
  if (data_ctx->source_string == 0) { throw(std::runtime_error("Data context has no source string")); }
454
- // empty source string is a valid case, even if not really usefull (different than with file context)
403
+ // empty source string is a valid case, even if not really useful (different than with file context)
455
404
  // if (*data_ctx->source_string == 0) { throw(std::runtime_error("Data context has empty source string")); }
456
405
  }
457
406
  catch (...) { return handle_errors(data_ctx) | 1; }
@@ -533,7 +482,7 @@ extern "C" {
533
482
  static void sass_clear_options (struct Sass_Options* options)
534
483
  {
535
484
  if (options == 0) return;
536
- // Deallocate custom functions, headers and importes
485
+ // Deallocate custom functions, headers and imports
537
486
  sass_delete_function_list(options->c_functions);
538
487
  sass_delete_importer_list(options->c_importers);
539
488
  sass_delete_importer_list(options->c_headers);
@@ -594,6 +543,7 @@ extern "C" {
594
543
  if (ctx->error_text) free(ctx->error_text);
595
544
  if (ctx->error_json) free(ctx->error_json);
596
545
  if (ctx->error_file) free(ctx->error_file);
546
+ if (ctx->error_src) free(ctx->error_src);
597
547
  free_string_array(ctx->included_files);
598
548
  // play safe and reset properties
599
549
  ctx->output_string = 0;
@@ -602,6 +552,7 @@ extern "C" {
602
552
  ctx->error_text = 0;
603
553
  ctx->error_json = 0;
604
554
  ctx->error_file = 0;
555
+ ctx->error_src = 0;
605
556
  ctx->included_files = 0;
606
557
  // debug leaked memory
607
558
  #ifdef DEBUG_SHARED_PTR
@@ -656,7 +607,7 @@ extern "C" {
656
607
  void ADDCALL sass_file_context_set_options (struct Sass_File_Context* ctx, struct Sass_Options* opt) { copy_options(ctx, opt); }
657
608
  void ADDCALL sass_data_context_set_options (struct Sass_Data_Context* ctx, struct Sass_Options* opt) { copy_options(ctx, opt); }
658
609
 
659
- // Getters for Sass_Compiler options (get conected sass context)
610
+ // Getters for Sass_Compiler options (get connected sass context)
660
611
  enum Sass_Compiler_State ADDCALL sass_compiler_get_state(struct Sass_Compiler* compiler) { return compiler->state; }
661
612
  struct Sass_Context* ADDCALL sass_compiler_get_context(struct Sass_Compiler* compiler) { return compiler->c_ctx; }
662
613
  struct Sass_Options* ADDCALL sass_compiler_get_options(struct Sass_Compiler* compiler) { return compiler->c_ctx; }
@@ -700,9 +651,9 @@ extern "C" {
700
651
  IMPLEMENT_SASS_CONTEXT_GETTER(const char*, error_message);
701
652
  IMPLEMENT_SASS_CONTEXT_GETTER(const char*, error_text);
702
653
  IMPLEMENT_SASS_CONTEXT_GETTER(const char*, error_file);
654
+ IMPLEMENT_SASS_CONTEXT_GETTER(const char*, error_src);
703
655
  IMPLEMENT_SASS_CONTEXT_GETTER(size_t, error_line);
704
656
  IMPLEMENT_SASS_CONTEXT_GETTER(size_t, error_column);
705
- IMPLEMENT_SASS_CONTEXT_GETTER(const char*, error_src);
706
657
  IMPLEMENT_SASS_CONTEXT_GETTER(const char*, output_string);
707
658
  IMPLEMENT_SASS_CONTEXT_GETTER(const char*, source_map_string);
708
659
  IMPLEMENT_SASS_CONTEXT_GETTER(char**, included_files);
@@ -712,6 +663,7 @@ extern "C" {
712
663
  IMPLEMENT_SASS_CONTEXT_TAKER(char*, error_message);
713
664
  IMPLEMENT_SASS_CONTEXT_TAKER(char*, error_text);
714
665
  IMPLEMENT_SASS_CONTEXT_TAKER(char*, error_file);
666
+ IMPLEMENT_SASS_CONTEXT_TAKER(char*, error_src);
715
667
  IMPLEMENT_SASS_CONTEXT_TAKER(char*, output_string);
716
668
  IMPLEMENT_SASS_CONTEXT_TAKER(char*, source_map_string);
717
669
  IMPLEMENT_SASS_CONTEXT_TAKER(char**, included_files);
@@ -751,6 +703,23 @@ extern "C" {
751
703
  return cur->string;
752
704
  }
753
705
 
706
+ // Push function for plugin paths (no manipulation support for now)
707
+ size_t ADDCALL sass_option_get_plugin_path_size(struct Sass_Options* options)
708
+ {
709
+ size_t len = 0;
710
+ struct string_list* cur = options->plugin_paths;
711
+ while (cur) { len++; cur = cur->next; }
712
+ return len;
713
+ }
714
+
715
+ // Push function for plugin paths (no manipulation support for now)
716
+ const char* ADDCALL sass_option_get_plugin_path(struct Sass_Options* options, size_t i)
717
+ {
718
+ struct string_list* cur = options->plugin_paths;
719
+ while (i) { i--; cur = cur->next; }
720
+ return cur->string;
721
+ }
722
+
754
723
  // Push function for plugin paths (no manipulation support for now)
755
724
  void ADDCALL sass_option_push_plugin_path(struct Sass_Options* options, const char* path)
756
725
  {
@@ -90,7 +90,7 @@ struct Sass_Context : Sass_Options
90
90
  char* error_file;
91
91
  size_t error_line;
92
92
  size_t error_column;
93
- const char* error_src;
93
+ char* error_src;
94
94
 
95
95
  // report imported files
96
96
  char** included_files;
@@ -126,4 +126,4 @@ struct Sass_Compiler {
126
126
  Sass::Block_Obj root;
127
127
  };
128
128
 
129
- #endif
129
+ #endif
@@ -101,7 +101,7 @@ extern "C" {
101
101
  }
102
102
 
103
103
  // Creator for a single import entry returned by the custom importer inside the list
104
- // We take ownership of the memory for source and srcmap (freed when context is destroyd)
104
+ // We take ownership of the memory for source and srcmap (freed when context is destroyed)
105
105
  Sass_Import_Entry ADDCALL sass_make_import(const char* imp_path, const char* abs_path, char* source, char* srcmap)
106
106
  {
107
107
  Sass_Import* v = (Sass_Import*) calloc(1, sizeof(Sass_Import));
@@ -6,7 +6,6 @@
6
6
  #include <cstring>
7
7
  #include "util.hpp"
8
8
  #include "eval.hpp"
9
- #include "values.hpp"
10
9
  #include "operators.hpp"
11
10
  #include "sass/values.h"
12
11
  #include "sass_values.hpp"
@@ -284,21 +283,21 @@ extern "C" {
284
283
 
285
284
  union Sass_Value* ADDCALL sass_value_stringify (const union Sass_Value* v, bool compressed, int precision)
286
285
  {
287
- Value_Obj val = sass_value_to_ast_node(v);
286
+ ValueObj val = sass_value_to_ast_node(v);
288
287
  Sass_Inspect_Options options(compressed ? COMPRESSED : NESTED, precision);
289
- std::string str(val->to_string(options));
288
+ sass::string str(val->to_string(options));
290
289
  return sass_make_qstring(str.c_str());
291
290
  }
292
291
 
293
292
  union Sass_Value* ADDCALL sass_value_op (enum Sass_OP op, const union Sass_Value* a, const union Sass_Value* b)
294
293
  {
295
294
 
296
- Sass::Value_Obj rv;
295
+ Sass::ValueObj rv;
297
296
 
298
297
  try {
299
298
 
300
- Value_Obj lhs = sass_value_to_ast_node(a);
301
- Value_Obj rhs = sass_value_to_ast_node(b);
299
+ ValueObj lhs = sass_value_to_ast_node(a);
300
+ ValueObj rhs = sass_value_to_ast_node(b);
302
301
  struct Sass_Inspect_Options options(NESTED, 5);
303
302
 
304
303
  // see if it's a relational expression
@@ -341,12 +340,10 @@ extern "C" {
341
340
  rv = Operators::op_colors(op, *l_c, *r_c, options, l_c->pstate());
342
341
  }
343
342
  else /* convert other stuff to string and apply operation */ {
344
- Value* l_v = Cast<Value>(lhs);
345
- Value* r_v = Cast<Value>(rhs);
346
- rv = Operators::op_strings(op, *l_v, *r_v, options, l_v->pstate());
343
+ rv = Operators::op_strings(op, *lhs, *rhs, options, lhs->pstate());
347
344
  }
348
345
 
349
- // ToDo: maybe we should should return null value?
346
+ // ToDo: maybe we should return null value?
350
347
  if (!rv) return sass_make_error("invalid return value");
351
348
 
352
349
  // convert result back to ast node
@@ -357,7 +354,7 @@ extern "C" {
357
354
  catch (Exception::InvalidSass& e) { return sass_make_error(e.what()); }
358
355
  catch (std::bad_alloc&) { return sass_make_error("memory exhausted"); }
359
356
  catch (std::exception& e) { return sass_make_error(e.what()); }
360
- catch (std::string& e) { return sass_make_error(e.c_str()); }
357
+ catch (sass::string& e) { return sass_make_error(e.c_str()); }
361
358
  catch (const char* e) { return sass_make_error(e); }
362
359
  catch (...) { return sass_make_error("unknown"); }
363
360
  }
@@ -0,0 +1,19 @@
1
+ #ifndef SASS_SETTINGS_H
2
+ #define SASS_SETTINGS_H
3
+
4
+ // Global compile time settings should go here
5
+
6
+ // When enabled we use our custom memory pool allocator
7
+ // With intense workloads this can double the performance
8
+ // Max memory usage mostly only grows by a slight amount
9
+ // #define SASS_CUSTOM_ALLOCATOR
10
+
11
+ // How many buckets should we have for the free-list
12
+ // Determines when allocations go directly to malloc/free
13
+ // For maximum size of managed items multiply by alignment
14
+ #define SassAllocatorBuckets 512
15
+
16
+ // The size of the memory pool arenas in bytes.
17
+ #define SassAllocatorArenaSize (1024 * 256)
18
+
19
+ #endif
@@ -0,0 +1,69 @@
1
+ #include <stdio.h>
2
+ #include <string.h>
3
+ #include "source.hpp"
4
+ #include "utf8/checked.h"
5
+ #include "position.hpp"
6
+
7
+ namespace Sass {
8
+
9
+ SourceData::SourceData()
10
+ : SharedObj()
11
+ {
12
+ }
13
+
14
+ SourceFile::SourceFile(
15
+ const char* path,
16
+ const char* data,
17
+ size_t srcid) :
18
+ SourceData(),
19
+ path(sass_copy_c_string(path)),
20
+ data(sass_copy_c_string(data)),
21
+ length(0),
22
+ srcid(srcid)
23
+ {
24
+ length = strlen(data);
25
+ }
26
+
27
+ SourceFile::~SourceFile() {
28
+ sass_free_memory(path);
29
+ sass_free_memory(data);
30
+ }
31
+
32
+ const char* SourceFile::end() const
33
+ {
34
+ return data + length;
35
+ }
36
+
37
+ const char* SourceFile::begin() const
38
+ {
39
+ return data;
40
+ }
41
+
42
+ const char* SourceFile::getRawData() const
43
+ {
44
+ return data;
45
+ }
46
+
47
+ SourceSpan SourceFile::getSourceSpan()
48
+ {
49
+ return SourceSpan(this);
50
+ }
51
+
52
+ ItplFile::ItplFile(const char* data, const SourceSpan& pstate) :
53
+ SourceFile(pstate.getPath(),
54
+ data, pstate.getSrcId()),
55
+ pstate(pstate)
56
+ {}
57
+
58
+ const char* ItplFile::getRawData() const
59
+ {
60
+ return pstate.getRawData();
61
+ }
62
+
63
+ SourceSpan ItplFile::getSourceSpan()
64
+ {
65
+ return SourceSpan(pstate);
66
+ }
67
+
68
+ }
69
+
@@ -0,0 +1,95 @@
1
+ #ifndef SASS_SOURCE_H
2
+ #define SASS_SOURCE_H
3
+
4
+ #include "sass.hpp"
5
+ #include "memory.hpp"
6
+ #include "position.hpp"
7
+ #include "source_data.hpp"
8
+
9
+ namespace Sass {
10
+
11
+ class SourceFile :
12
+ public SourceData {
13
+ protected:
14
+ char* path;
15
+ char* data;
16
+ size_t length;
17
+ size_t srcid;
18
+ public:
19
+
20
+ SourceFile(
21
+ const char* path,
22
+ const char* data,
23
+ size_t srcid);
24
+
25
+ ~SourceFile();
26
+
27
+ const char* end() const override final;
28
+ const char* begin() const override final;
29
+ virtual const char* getRawData() const override;
30
+ virtual SourceSpan getSourceSpan() override;
31
+
32
+ size_t size() const override final {
33
+ return length;
34
+ }
35
+
36
+ virtual const char* getPath() const override {
37
+ return path;
38
+ }
39
+
40
+ virtual size_t getSrcId() const override {
41
+ return srcid;
42
+ }
43
+
44
+ };
45
+
46
+ class SynthFile :
47
+ public SourceData {
48
+ protected:
49
+ const char* path;
50
+ public:
51
+
52
+ SynthFile(
53
+ const char* path) :
54
+ path(path)
55
+ {}
56
+
57
+ ~SynthFile() {}
58
+
59
+ const char* end() const override final { return nullptr; }
60
+ const char* begin() const override final { return nullptr; };
61
+ virtual const char* getRawData() const override { return nullptr; };
62
+ virtual SourceSpan getSourceSpan() override { return SourceSpan(path); };
63
+
64
+ size_t size() const override final {
65
+ return 0;
66
+ }
67
+
68
+ virtual const char* getPath() const override {
69
+ return path;
70
+ }
71
+
72
+ virtual size_t getSrcId() const override {
73
+ return std::string::npos;
74
+ }
75
+
76
+ };
77
+
78
+
79
+ class ItplFile :
80
+ public SourceFile {
81
+ private:
82
+ SourceSpan pstate;
83
+ public:
84
+
85
+ ItplFile(const char* data,
86
+ const SourceSpan& pstate);
87
+
88
+ // Offset getPosition() const override final;
89
+ const char* getRawData() const override final;
90
+ SourceSpan getSourceSpan() override final;
91
+ };
92
+
93
+ }
94
+
95
+ #endif