herb 0.7.1-arm-linux-musl → 0.7.3-arm-linux-musl

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 (137) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +2 -0
  3. data/README.md +1 -1
  4. data/Rakefile +46 -1
  5. data/config.yml +714 -0
  6. data/ext/herb/error_helpers.c +27 -27
  7. data/ext/herb/extconf.rb +2 -1
  8. data/ext/herb/extension.c +6 -6
  9. data/ext/herb/extension_helpers.c +3 -3
  10. data/ext/herb/nodes.c +35 -35
  11. data/herb.gemspec +3 -0
  12. data/lib/herb/3.0/herb.so +0 -0
  13. data/lib/herb/3.1/herb.so +0 -0
  14. data/lib/herb/3.2/herb.so +0 -0
  15. data/lib/herb/3.3/herb.so +0 -0
  16. data/lib/herb/3.4/herb.so +0 -0
  17. data/lib/herb/engine/debug_visitor.rb +41 -21
  18. data/lib/herb/engine.rb +20 -6
  19. data/lib/herb/version.rb +1 -1
  20. data/sig/herb/engine/debug_visitor.rbs +3 -3
  21. data/sig/herb/engine.rbs +5 -0
  22. data/src/analyze.c +5 -9
  23. data/src/analyze_helpers.c +17 -6
  24. data/src/include/pretty_print.h +1 -1
  25. data/src/include/version.h +1 -1
  26. data/src/parser.c +6 -9
  27. data/src/pretty_print.c +1 -1
  28. data/templates/ext/herb/error_helpers.c.erb +85 -0
  29. data/templates/ext/herb/error_helpers.h.erb +12 -0
  30. data/templates/ext/herb/nodes.c.erb +90 -0
  31. data/templates/ext/herb/nodes.h.erb +9 -0
  32. data/templates/javascript/packages/core/src/errors.ts.erb +193 -0
  33. data/templates/javascript/packages/core/src/node-type-guards.ts.erb +325 -0
  34. data/templates/javascript/packages/core/src/nodes.ts.erb +414 -0
  35. data/templates/javascript/packages/core/src/visitor.ts.erb +29 -0
  36. data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +113 -0
  37. data/templates/javascript/packages/node/extension/error_helpers.h.erb +17 -0
  38. data/templates/javascript/packages/node/extension/nodes.cpp.erb +111 -0
  39. data/templates/javascript/packages/node/extension/nodes.h.erb +17 -0
  40. data/templates/lib/herb/ast/nodes.rb.erb +117 -0
  41. data/templates/lib/herb/errors.rb.erb +106 -0
  42. data/templates/lib/herb/visitor.rb.erb +28 -0
  43. data/templates/sig/serialized_ast_errors.rbs.erb +10 -0
  44. data/templates/sig/serialized_ast_nodes.rbs.erb +10 -0
  45. data/templates/src/ast_nodes.c.erb +145 -0
  46. data/templates/src/ast_pretty_print.c.erb +97 -0
  47. data/templates/src/errors.c.erb +245 -0
  48. data/templates/src/include/ast_nodes.h.erb +46 -0
  49. data/templates/src/include/ast_pretty_print.h.erb +14 -0
  50. data/templates/src/include/errors.h.erb +58 -0
  51. data/templates/src/visitor.c.erb +47 -0
  52. data/templates/template.rb +406 -0
  53. data/templates/wasm/error_helpers.cpp.erb +93 -0
  54. data/templates/wasm/error_helpers.h.erb +15 -0
  55. data/templates/wasm/nodes.cpp.erb +79 -0
  56. data/templates/wasm/nodes.h.erb +15 -0
  57. data/vendor/prism/Rakefile +75 -0
  58. data/vendor/prism/config.yml +4713 -0
  59. data/vendor/prism/include/prism/ast.h +8190 -0
  60. data/vendor/prism/include/prism/defines.h +260 -0
  61. data/vendor/prism/include/prism/diagnostic.h +455 -0
  62. data/vendor/prism/include/prism/encoding.h +283 -0
  63. data/vendor/prism/include/prism/node.h +129 -0
  64. data/vendor/prism/include/prism/options.h +482 -0
  65. data/vendor/prism/include/prism/pack.h +163 -0
  66. data/vendor/prism/include/prism/parser.h +933 -0
  67. data/vendor/prism/include/prism/prettyprint.h +34 -0
  68. data/vendor/prism/include/prism/regexp.h +43 -0
  69. data/vendor/prism/include/prism/static_literals.h +121 -0
  70. data/vendor/prism/include/prism/util/pm_buffer.h +236 -0
  71. data/vendor/prism/include/prism/util/pm_char.h +204 -0
  72. data/vendor/prism/include/prism/util/pm_constant_pool.h +218 -0
  73. data/vendor/prism/include/prism/util/pm_integer.h +130 -0
  74. data/vendor/prism/include/prism/util/pm_list.h +103 -0
  75. data/vendor/prism/include/prism/util/pm_memchr.h +29 -0
  76. data/vendor/prism/include/prism/util/pm_newline_list.h +113 -0
  77. data/vendor/prism/include/prism/util/pm_string.h +200 -0
  78. data/vendor/prism/include/prism/util/pm_strncasecmp.h +32 -0
  79. data/vendor/prism/include/prism/util/pm_strpbrk.h +46 -0
  80. data/vendor/prism/include/prism/version.h +29 -0
  81. data/vendor/prism/include/prism.h +408 -0
  82. data/vendor/prism/src/diagnostic.c +848 -0
  83. data/vendor/prism/src/encoding.c +5235 -0
  84. data/vendor/prism/src/node.c +8676 -0
  85. data/vendor/prism/src/options.c +328 -0
  86. data/vendor/prism/src/pack.c +509 -0
  87. data/vendor/prism/src/prettyprint.c +8941 -0
  88. data/vendor/prism/src/prism.c +23302 -0
  89. data/vendor/prism/src/regexp.c +790 -0
  90. data/vendor/prism/src/serialize.c +2268 -0
  91. data/vendor/prism/src/static_literals.c +617 -0
  92. data/vendor/prism/src/token_type.c +703 -0
  93. data/vendor/prism/src/util/pm_buffer.c +357 -0
  94. data/vendor/prism/src/util/pm_char.c +318 -0
  95. data/vendor/prism/src/util/pm_constant_pool.c +342 -0
  96. data/vendor/prism/src/util/pm_integer.c +670 -0
  97. data/vendor/prism/src/util/pm_list.c +49 -0
  98. data/vendor/prism/src/util/pm_memchr.c +35 -0
  99. data/vendor/prism/src/util/pm_newline_list.c +125 -0
  100. data/vendor/prism/src/util/pm_string.c +383 -0
  101. data/vendor/prism/src/util/pm_strncasecmp.c +36 -0
  102. data/vendor/prism/src/util/pm_strpbrk.c +206 -0
  103. data/vendor/prism/templates/ext/prism/api_node.c.erb +282 -0
  104. data/vendor/prism/templates/include/prism/ast.h.erb +226 -0
  105. data/vendor/prism/templates/include/prism/diagnostic.h.erb +130 -0
  106. data/vendor/prism/templates/java/org/prism/AbstractNodeVisitor.java.erb +22 -0
  107. data/vendor/prism/templates/java/org/prism/Loader.java.erb +434 -0
  108. data/vendor/prism/templates/java/org/prism/Nodes.java.erb +403 -0
  109. data/vendor/prism/templates/javascript/src/deserialize.js.erb +448 -0
  110. data/vendor/prism/templates/javascript/src/nodes.js.erb +197 -0
  111. data/vendor/prism/templates/javascript/src/visitor.js.erb +78 -0
  112. data/vendor/prism/templates/lib/prism/compiler.rb.erb +43 -0
  113. data/vendor/prism/templates/lib/prism/dispatcher.rb.erb +103 -0
  114. data/vendor/prism/templates/lib/prism/dot_visitor.rb.erb +189 -0
  115. data/vendor/prism/templates/lib/prism/dsl.rb.erb +133 -0
  116. data/vendor/prism/templates/lib/prism/inspect_visitor.rb.erb +131 -0
  117. data/vendor/prism/templates/lib/prism/mutation_compiler.rb.erb +19 -0
  118. data/vendor/prism/templates/lib/prism/node.rb.erb +515 -0
  119. data/vendor/prism/templates/lib/prism/reflection.rb.erb +136 -0
  120. data/vendor/prism/templates/lib/prism/serialize.rb.erb +602 -0
  121. data/vendor/prism/templates/lib/prism/visitor.rb.erb +55 -0
  122. data/vendor/prism/templates/rbi/prism/dsl.rbi.erb +68 -0
  123. data/vendor/prism/templates/rbi/prism/node.rbi.erb +164 -0
  124. data/vendor/prism/templates/rbi/prism/visitor.rbi.erb +18 -0
  125. data/vendor/prism/templates/sig/prism/_private/dot_visitor.rbs.erb +45 -0
  126. data/vendor/prism/templates/sig/prism/dsl.rbs.erb +31 -0
  127. data/vendor/prism/templates/sig/prism/mutation_compiler.rbs.erb +7 -0
  128. data/vendor/prism/templates/sig/prism/node.rbs.erb +132 -0
  129. data/vendor/prism/templates/sig/prism/visitor.rbs.erb +17 -0
  130. data/vendor/prism/templates/sig/prism.rbs.erb +89 -0
  131. data/vendor/prism/templates/src/diagnostic.c.erb +523 -0
  132. data/vendor/prism/templates/src/node.c.erb +333 -0
  133. data/vendor/prism/templates/src/prettyprint.c.erb +166 -0
  134. data/vendor/prism/templates/src/serialize.c.erb +406 -0
  135. data/vendor/prism/templates/src/token_type.c.erb +369 -0
  136. data/vendor/prism/templates/template.rb +689 -0
  137. metadata +112 -2
@@ -0,0 +1,328 @@
1
+ #include "prism/options.h"
2
+
3
+ /**
4
+ * Set the shebang callback option on the given options struct.
5
+ */
6
+ PRISM_EXPORTED_FUNCTION void
7
+ pm_options_shebang_callback_set(pm_options_t *options, pm_options_shebang_callback_t shebang_callback, void *shebang_callback_data) {
8
+ options->shebang_callback = shebang_callback;
9
+ options->shebang_callback_data = shebang_callback_data;
10
+ }
11
+
12
+ /**
13
+ * Set the filepath option on the given options struct.
14
+ */
15
+ PRISM_EXPORTED_FUNCTION void
16
+ pm_options_filepath_set(pm_options_t *options, const char *filepath) {
17
+ pm_string_constant_init(&options->filepath, filepath, strlen(filepath));
18
+ }
19
+
20
+ /**
21
+ * Set the encoding option on the given options struct.
22
+ */
23
+ PRISM_EXPORTED_FUNCTION void
24
+ pm_options_encoding_set(pm_options_t *options, const char *encoding) {
25
+ pm_string_constant_init(&options->encoding, encoding, strlen(encoding));
26
+ }
27
+
28
+ /**
29
+ * Set the encoding_locked option on the given options struct.
30
+ */
31
+ PRISM_EXPORTED_FUNCTION void
32
+ pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked) {
33
+ options->encoding_locked = encoding_locked;
34
+ }
35
+
36
+ /**
37
+ * Set the line option on the given options struct.
38
+ */
39
+ PRISM_EXPORTED_FUNCTION void
40
+ pm_options_line_set(pm_options_t *options, int32_t line) {
41
+ options->line = line;
42
+ }
43
+
44
+ /**
45
+ * Set the frozen string literal option on the given options struct.
46
+ */
47
+ PRISM_EXPORTED_FUNCTION void
48
+ pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal) {
49
+ options->frozen_string_literal = frozen_string_literal ? PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED : PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED;
50
+ }
51
+
52
+ /**
53
+ * Sets the command line option on the given options struct.
54
+ */
55
+ PRISM_EXPORTED_FUNCTION void
56
+ pm_options_command_line_set(pm_options_t *options, uint8_t command_line) {
57
+ options->command_line = command_line;
58
+ }
59
+
60
+ /**
61
+ * Checks if the given slice represents a number.
62
+ */
63
+ static inline bool
64
+ is_number(const char *string, size_t length) {
65
+ return pm_strspn_decimal_digit((const uint8_t *) string, (ptrdiff_t) length) == length;
66
+ }
67
+
68
+ /**
69
+ * Set the version option on the given options struct by parsing the given
70
+ * string. If the string contains an invalid option, this returns false.
71
+ * Otherwise, it returns true.
72
+ */
73
+ PRISM_EXPORTED_FUNCTION bool
74
+ pm_options_version_set(pm_options_t *options, const char *version, size_t length) {
75
+ if (version == NULL) {
76
+ options->version = PM_OPTIONS_VERSION_LATEST;
77
+ return true;
78
+ }
79
+
80
+ if (length == 3) {
81
+ if (strncmp(version, "3.3", 3) == 0) {
82
+ options->version = PM_OPTIONS_VERSION_CRUBY_3_3;
83
+ return true;
84
+ }
85
+
86
+ if (strncmp(version, "3.4", 3) == 0) {
87
+ options->version = PM_OPTIONS_VERSION_CRUBY_3_4;
88
+ return true;
89
+ }
90
+
91
+ if (strncmp(version, "3.5", 3) == 0) {
92
+ options->version = PM_OPTIONS_VERSION_CRUBY_3_5;
93
+ return true;
94
+ }
95
+
96
+ return false;
97
+ }
98
+
99
+ if (length >= 4) {
100
+ if (strncmp(version, "3.3.", 4) == 0 && is_number(version + 4, length - 4)) {
101
+ options->version = PM_OPTIONS_VERSION_CRUBY_3_3;
102
+ return true;
103
+ }
104
+
105
+ if (strncmp(version, "3.4.", 4) == 0 && is_number(version + 4, length - 4)) {
106
+ options->version = PM_OPTIONS_VERSION_CRUBY_3_4;
107
+ return true;
108
+ }
109
+
110
+ if (strncmp(version, "3.5.", 4) == 0 && is_number(version + 4, length - 4)) {
111
+ options->version = PM_OPTIONS_VERSION_CRUBY_3_5;
112
+ return true;
113
+ }
114
+ }
115
+
116
+ if (length >= 6) {
117
+ if (strncmp(version, "latest", 7) == 0) { // 7 to compare the \0 as well
118
+ options->version = PM_OPTIONS_VERSION_LATEST;
119
+ return true;
120
+ }
121
+ }
122
+
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * Set the main script option on the given options struct.
128
+ */
129
+ PRISM_EXPORTED_FUNCTION void
130
+ pm_options_main_script_set(pm_options_t *options, bool main_script) {
131
+ options->main_script = main_script;
132
+ }
133
+
134
+ /**
135
+ * Set the partial script option on the given options struct.
136
+ */
137
+ PRISM_EXPORTED_FUNCTION void
138
+ pm_options_partial_script_set(pm_options_t *options, bool partial_script) {
139
+ options->partial_script = partial_script;
140
+ }
141
+
142
+ /**
143
+ * Set the freeze option on the given options struct.
144
+ */
145
+ PRISM_EXPORTED_FUNCTION void
146
+ pm_options_freeze_set(pm_options_t *options, bool freeze) {
147
+ options->freeze = freeze;
148
+ }
149
+
150
+ // For some reason, GCC analyzer thinks we're leaking allocated scopes and
151
+ // locals here, even though we definitely aren't. This is a false positive.
152
+ // Ideally we wouldn't need to suppress this.
153
+ #if defined(__GNUC__) && (__GNUC__ >= 10)
154
+ #pragma GCC diagnostic push
155
+ #pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
156
+ #endif
157
+
158
+ /**
159
+ * Allocate and zero out the scopes array on the given options struct.
160
+ */
161
+ PRISM_EXPORTED_FUNCTION bool
162
+ pm_options_scopes_init(pm_options_t *options, size_t scopes_count) {
163
+ options->scopes_count = scopes_count;
164
+ options->scopes = xcalloc(scopes_count, sizeof(pm_options_scope_t));
165
+ return options->scopes != NULL;
166
+ }
167
+
168
+ /**
169
+ * Return a pointer to the scope at the given index within the given options.
170
+ */
171
+ PRISM_EXPORTED_FUNCTION const pm_options_scope_t *
172
+ pm_options_scope_get(const pm_options_t *options, size_t index) {
173
+ return &options->scopes[index];
174
+ }
175
+
176
+ /**
177
+ * Create a new options scope struct. This will hold a set of locals that are in
178
+ * scope surrounding the code that is being parsed.
179
+ */
180
+ PRISM_EXPORTED_FUNCTION bool
181
+ pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count) {
182
+ scope->locals_count = locals_count;
183
+ scope->locals = xcalloc(locals_count, sizeof(pm_string_t));
184
+ scope->forwarding = PM_OPTIONS_SCOPE_FORWARDING_NONE;
185
+ return scope->locals != NULL;
186
+ }
187
+
188
+ /**
189
+ * Return a pointer to the local at the given index within the given scope.
190
+ */
191
+ PRISM_EXPORTED_FUNCTION const pm_string_t *
192
+ pm_options_scope_local_get(const pm_options_scope_t *scope, size_t index) {
193
+ return &scope->locals[index];
194
+ }
195
+
196
+ /**
197
+ * Set the forwarding option on the given scope struct.
198
+ */
199
+ PRISM_EXPORTED_FUNCTION void
200
+ pm_options_scope_forwarding_set(pm_options_scope_t *scope, uint8_t forwarding) {
201
+ scope->forwarding = forwarding;
202
+ }
203
+
204
+ /**
205
+ * Free the internal memory associated with the options.
206
+ */
207
+ PRISM_EXPORTED_FUNCTION void
208
+ pm_options_free(pm_options_t *options) {
209
+ pm_string_free(&options->filepath);
210
+ pm_string_free(&options->encoding);
211
+
212
+ for (size_t scope_index = 0; scope_index < options->scopes_count; scope_index++) {
213
+ pm_options_scope_t *scope = &options->scopes[scope_index];
214
+
215
+ for (size_t local_index = 0; local_index < scope->locals_count; local_index++) {
216
+ pm_string_free(&scope->locals[local_index]);
217
+ }
218
+
219
+ xfree(scope->locals);
220
+ }
221
+
222
+ xfree(options->scopes);
223
+ }
224
+
225
+ /**
226
+ * Read a 32-bit unsigned integer from a pointer. This function is used to read
227
+ * the options that are passed into the parser from the Ruby implementation. It
228
+ * handles aligned and unaligned reads.
229
+ */
230
+ static uint32_t
231
+ pm_options_read_u32(const char *data) {
232
+ if (((uintptr_t) data) % sizeof(uint32_t) == 0) {
233
+ return *((uint32_t *) data);
234
+ } else {
235
+ uint32_t value;
236
+ memcpy(&value, data, sizeof(uint32_t));
237
+ return value;
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Read a 32-bit signed integer from a pointer. This function is used to read
243
+ * the options that are passed into the parser from the Ruby implementation. It
244
+ * handles aligned and unaligned reads.
245
+ */
246
+ static int32_t
247
+ pm_options_read_s32(const char *data) {
248
+ if (((uintptr_t) data) % sizeof(int32_t) == 0) {
249
+ return *((int32_t *) data);
250
+ } else {
251
+ int32_t value;
252
+ memcpy(&value, data, sizeof(int32_t));
253
+ return value;
254
+ }
255
+ }
256
+
257
+ /**
258
+ * Deserialize an options struct from the given binary string. This is used to
259
+ * pass options to the parser from an FFI call so that consumers of the library
260
+ * from an FFI perspective don't have to worry about the structure of our
261
+ * options structs. Since the source of these calls will be from Ruby
262
+ * implementation internals we assume it is from a trusted source.
263
+ */
264
+ void
265
+ pm_options_read(pm_options_t *options, const char *data) {
266
+ options->line = 1; // default
267
+ if (data == NULL) return;
268
+
269
+ uint32_t filepath_length = pm_options_read_u32(data);
270
+ data += 4;
271
+
272
+ if (filepath_length > 0) {
273
+ pm_string_constant_init(&options->filepath, data, filepath_length);
274
+ data += filepath_length;
275
+ }
276
+
277
+ options->line = pm_options_read_s32(data);
278
+ data += 4;
279
+
280
+ uint32_t encoding_length = pm_options_read_u32(data);
281
+ data += 4;
282
+
283
+ if (encoding_length > 0) {
284
+ pm_string_constant_init(&options->encoding, data, encoding_length);
285
+ data += encoding_length;
286
+ }
287
+
288
+ options->frozen_string_literal = (int8_t) *data++;
289
+ options->command_line = (uint8_t) *data++;
290
+ options->version = (pm_options_version_t) *data++;
291
+ options->encoding_locked = ((uint8_t) *data++) > 0;
292
+ options->main_script = ((uint8_t) *data++) > 0;
293
+ options->partial_script = ((uint8_t) *data++) > 0;
294
+ options->freeze = ((uint8_t) *data++) > 0;
295
+
296
+ uint32_t scopes_count = pm_options_read_u32(data);
297
+ data += 4;
298
+
299
+ if (scopes_count > 0) {
300
+ if (!pm_options_scopes_init(options, scopes_count)) return;
301
+
302
+ for (size_t scope_index = 0; scope_index < scopes_count; scope_index++) {
303
+ uint32_t locals_count = pm_options_read_u32(data);
304
+ data += 4;
305
+
306
+ pm_options_scope_t *scope = &options->scopes[scope_index];
307
+ if (!pm_options_scope_init(scope, locals_count)) {
308
+ pm_options_free(options);
309
+ return;
310
+ }
311
+
312
+ uint8_t forwarding = (uint8_t) *data++;
313
+ pm_options_scope_forwarding_set(&options->scopes[scope_index], forwarding);
314
+
315
+ for (size_t local_index = 0; local_index < locals_count; local_index++) {
316
+ uint32_t local_length = pm_options_read_u32(data);
317
+ data += 4;
318
+
319
+ pm_string_constant_init(&scope->locals[local_index], data, local_length);
320
+ data += local_length;
321
+ }
322
+ }
323
+ }
324
+ }
325
+
326
+ #if defined(__GNUC__) && (__GNUC__ >= 10)
327
+ #pragma GCC diagnostic pop
328
+ #endif