herb 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +4 -2
- data/config.yml +6 -0
- data/ext/herb/extconf.rb +8 -31
- data/ext/herb/nodes.c +75 -75
- data/ext/herb/parser_options_helpers.c +26 -0
- data/lib/herb/analysis/partial_index.rb +1 -1
- data/lib/herb/analysis/partial_resolution.rb +27 -0
- data/lib/herb/ast/helpers.rb +1 -1
- data/lib/herb/configuration.rb +11 -1
- data/lib/herb/dev/classifier.rb +1 -1
- data/lib/herb/engine/compiler.rb +5 -8
- data/lib/herb/engine/slots/dynamics_compiler.rb +53 -14
- data/lib/herb/engine/slots/subtree_compiler.rb +1 -1
- data/lib/herb/engine/slots/visitor.rb +32 -4
- data/lib/herb/engine/visitors/instrumentation_visitor.rb +18 -6
- data/lib/herb/parser_options.rb +6 -3
- data/lib/herb/project.rb +19 -8
- data/lib/herb/version.rb +1 -1
- data/lib/herb.rb +1 -1
- data/sig/herb/analysis/partial_resolution.rbs +8 -0
- data/sig/herb/configuration.rbs +3 -0
- data/sig/herb/engine/slots/dynamics_compiler.rbs +24 -7
- data/sig/herb/engine/slots/visitor.rbs +14 -0
- data/sig/herb/engine/visitors/instrumentation_visitor.rbs +5 -1
- data/sig/herb/parser_options.rbs +6 -4
- data/sig/herb.rbs +2 -2
- data/src/analyze/action_view/attribute_extraction_helpers.c +40 -21
- data/src/analyze/action_view/generated_handlers.c +36 -36
- data/src/analyze/action_view/image_tag.c +7 -3
- data/src/analyze/action_view/javascript_include_tag.c +6 -3
- data/src/analyze/action_view/link_to.c +23 -23
- data/src/analyze/action_view/registry.c +7 -3
- data/src/analyze/action_view/tag_helper_node_builders.c +6 -13
- data/src/analyze/action_view/tag_helpers.c +139 -90
- data/src/analyze/action_view/turbo_frame_tag.c +5 -4
- data/src/analyze/analyze.c +35 -19
- data/src/analyze/analyze_helpers.c +161 -188
- data/src/analyze/analyzed_ruby.c +8 -7
- data/src/analyze/control_type.c +29 -22
- data/src/analyze/herb_directives.c +16 -20
- data/src/analyze/iteration_nodes.c +69 -24
- data/src/analyze/parse_errors.c +32 -22
- data/src/analyze/postfix_conditionals.c +23 -13
- data/src/analyze/prism_annotate.c +29 -28
- data/src/analyze/render_nodes.c +51 -41
- data/src/analyze/strict_locals.c +14 -15
- data/src/analyze/ternary_conditionals.c +14 -10
- data/src/herb.c +10 -8
- data/src/include/analyze/action_view/tag_helper_handler.h +1 -1
- data/src/include/analyze/action_view/tag_helper_node_builders.h +1 -0
- data/src/include/analyze/action_view/tag_helpers.h +1 -1
- data/src/include/analyze/analyze.h +3 -2
- data/src/include/analyze/analyzed_ruby.h +4 -2
- data/src/include/analyze/helpers.h +6 -6
- data/src/include/herb.h +3 -2
- data/src/include/parser/parser_options.h +5 -0
- data/src/include/prism/prism_context.h +12 -12
- data/src/include/prism/prism_helpers.h +30 -0
- data/src/include/prism_version.h +11 -0
- data/src/include/version.h +1 -1
- data/src/parser/parser_helpers.c +1 -2
- data/src/parser.c +6 -7
- data/src/parser_options_defaults.c +1 -0
- data/src/prism/prism_helpers.c +84 -50
- data/src/prism/ruby_parser.c +20 -20
- data/templates/ext/herb/nodes.c.erb +5 -5
- data/templates/ext/herb/parser_options_helpers.c.erb +33 -0
- data/templates/java/nodes.c.erb +6 -6
- data/templates/java/parser_options_helpers.c.erb +41 -2
- data/templates/java/parser_options_helpers.h.erb +2 -1
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +5 -5
- data/templates/javascript/packages/node/extension/parser_options_helpers.cpp.erb +34 -2
- data/templates/javascript/packages/node/extension/parser_options_helpers.h.erb +1 -1
- data/templates/lib/herb/parser_options.rb.erb +1 -1
- data/templates/rust/src/prism/generated_deserialize.rs.erb +90 -44
- data/templates/rust/src/prism/generated_prettyprint.rs.erb +18 -27
- data/templates/src/analyze/action_view/generated_handlers.c.erb +23 -22
- data/templates/src/include/parser/parser_options.h.erb +10 -0
- data/templates/src/include/prism_version.h.erb +17 -0
- data/templates/src/parser_options_defaults.c.erb +1 -1
- data/templates/template.rb +17 -2
- data/templates/wasm/nodes.cpp.erb +5 -5
- data/templates/wasm/parser_options_helpers.cpp.erb +24 -0
- data/vendor/prism/Rakefile +76 -7
- data/vendor/prism/config.yml +174 -161
- data/vendor/prism/include/prism/arena.h +45 -0
- data/vendor/prism/include/prism/arena.hpp +42 -0
- data/vendor/prism/include/prism/ast.h +2738 -611
- data/vendor/prism/include/prism/ast.hpp +641 -0
- data/vendor/prism/include/prism/buffer.h +60 -0
- data/vendor/prism/include/prism/buffer.hpp +55 -0
- data/vendor/prism/include/prism/comments.h +72 -0
- data/vendor/prism/include/prism/compiler/accel.h +26 -0
- data/vendor/prism/include/prism/compiler/align.h +36 -0
- data/vendor/prism/include/prism/compiler/assume.h +25 -0
- data/vendor/prism/include/prism/compiler/branch.h +26 -0
- data/vendor/prism/include/prism/compiler/bswap.h +46 -0
- data/vendor/prism/include/prism/compiler/cplusplus.hpp +16 -0
- data/vendor/prism/include/prism/compiler/endianness.h +34 -0
- data/vendor/prism/include/prism/compiler/exceptions.hpp +17 -0
- data/vendor/prism/include/prism/compiler/exported.h +24 -0
- data/vendor/prism/include/prism/compiler/fallthrough.h +22 -0
- data/vendor/prism/include/prism/compiler/filesystem.h +32 -0
- data/vendor/prism/include/prism/compiler/flex_array.h +19 -0
- data/vendor/prism/include/prism/compiler/force_inline.h +21 -0
- data/vendor/prism/include/prism/compiler/format.h +27 -0
- data/vendor/prism/include/prism/compiler/inline.h +17 -0
- data/vendor/prism/include/prism/compiler/lifetimebound.hpp +25 -0
- data/vendor/prism/include/prism/compiler/nodiscard.h +22 -0
- data/vendor/prism/include/prism/compiler/nonnull.h +18 -0
- data/vendor/prism/include/prism/compiler/unused.h +18 -0
- data/vendor/prism/include/prism/constant_pool.h +106 -0
- data/vendor/prism/include/prism/diagnostic.h +55 -402
- data/vendor/prism/include/prism/errors_format.h +61 -0
- data/vendor/prism/include/prism/excludes.h +29 -0
- data/vendor/prism/include/prism/integer.h +41 -0
- data/vendor/prism/include/prism/internal/allocator.h +68 -0
- data/vendor/prism/include/prism/internal/allocator_debug.h +88 -0
- data/vendor/prism/include/prism/internal/arena.h +108 -0
- data/vendor/prism/include/prism/internal/bit.h +42 -0
- data/vendor/prism/include/prism/internal/buffer.h +94 -0
- data/vendor/prism/include/prism/internal/char.h +145 -0
- data/vendor/prism/include/prism/internal/comments.h +54 -0
- data/vendor/prism/include/prism/internal/constant_pool.h +152 -0
- data/vendor/prism/include/prism/internal/diagnostic.h +389 -0
- data/vendor/prism/include/prism/{encoding.h → internal/encoding.h} +27 -68
- data/vendor/prism/include/prism/internal/integer.h +68 -0
- data/vendor/prism/include/prism/internal/isinf.h +16 -0
- data/vendor/prism/include/prism/internal/line_offset_list.h +34 -0
- data/vendor/prism/include/prism/{util/pm_list.h → internal/list.h} +11 -52
- data/vendor/prism/include/prism/internal/magic_comments.h +23 -0
- data/vendor/prism/include/prism/internal/memchr.h +15 -0
- data/vendor/prism/include/prism/internal/node.h +42 -0
- data/vendor/prism/include/prism/internal/options.h +232 -0
- data/vendor/prism/include/prism/internal/parser.h +1015 -0
- data/vendor/prism/include/prism/internal/regexp.h +26 -0
- data/vendor/prism/include/prism/internal/serialize.h +39 -0
- data/vendor/prism/include/prism/internal/source.h +72 -0
- data/vendor/prism/include/prism/internal/static_literals.h +60 -0
- data/vendor/prism/include/prism/internal/stringy.h +30 -0
- data/vendor/prism/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
- data/vendor/prism/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
- data/vendor/prism/include/prism/internal/tokens.h +11 -0
- data/vendor/prism/include/prism/internal/xxh3.h +16 -0
- data/vendor/prism/include/prism/json.h +40 -0
- data/vendor/prism/include/prism/line_offset_list.h +69 -0
- data/vendor/prism/include/prism/magic_comments.h +53 -0
- data/vendor/prism/include/prism/node.h +59 -49
- data/vendor/prism/include/prism/node.hpp +272 -0
- data/vendor/prism/include/prism/node_type.hpp +38 -0
- data/vendor/prism/include/prism/options.h +154 -279
- data/vendor/prism/include/prism/options.hpp +43 -0
- data/vendor/prism/include/prism/parser.h +367 -870
- data/vendor/prism/include/prism/parser.hpp +274 -0
- data/vendor/prism/include/prism/prettyprint.h +14 -9
- data/vendor/prism/include/prism/serialize.h +123 -0
- data/vendor/prism/include/prism/source.h +163 -0
- data/vendor/prism/include/prism/stream.h +36 -0
- data/vendor/prism/include/prism/string_query.h +82 -0
- data/vendor/prism/include/prism/stringy.h +61 -0
- data/vendor/prism/include/prism/stringy.hpp +31 -0
- data/vendor/prism/include/prism/version.h +20 -3
- data/vendor/prism/include/prism.h +35 -320
- data/vendor/prism/include/prism.hpp +24 -0
- data/vendor/prism/src/arena.c +122 -0
- data/vendor/prism/src/{util/pm_buffer.c → buffer.c} +53 -21
- data/vendor/prism/src/{util/pm_char.c → char.c} +28 -57
- data/vendor/prism/src/comments.c +455 -0
- data/vendor/prism/src/constant_pool.c +406 -0
- data/vendor/prism/src/diagnostic.c +120 -68
- data/vendor/prism/src/encoding.c +8 -3
- data/vendor/prism/src/errors_format.c +519 -0
- data/vendor/prism/src/{util/pm_integer.c → integer.c} +38 -22
- data/vendor/prism/src/json.c +5733 -0
- data/vendor/prism/src/line_offset_list.c +100 -0
- data/vendor/prism/src/list.c +24 -0
- data/vendor/prism/src/{util/pm_memchr.c → memchr.c} +8 -6
- data/vendor/prism/src/node.c +3465 -7787
- data/vendor/prism/src/options.c +161 -54
- data/vendor/prism/src/parser.c +371 -0
- data/vendor/prism/src/prettyprint.c +421 -354
- data/vendor/prism/src/prism.c +8522 -7280
- data/vendor/prism/src/regexp.c +960 -45
- data/vendor/prism/src/serialize.c +2434 -2048
- data/vendor/prism/src/source.c +524 -0
- data/vendor/prism/src/static_literals.c +303 -360
- data/vendor/prism/src/string_query.c +180 -0
- data/vendor/prism/src/stringy.c +61 -0
- data/vendor/prism/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
- data/vendor/prism/src/strpbrk.c +447 -0
- data/vendor/prism/src/{token_type.c → tokens.c} +39 -18
- data/vendor/prism/src/xxh3.c +292 -0
- data/vendor/prism/templates/ext/prism/api_node.c.erb +58 -44
- data/vendor/prism/templates/include/prism/ast.h.erb +67 -17
- data/vendor/prism/templates/include/prism/ast.hpp.erb +31 -0
- data/vendor/prism/templates/include/prism/internal/diagnostic.h.erb +60 -0
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/AbstractNodeVisitor.java.erb +1 -1
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Loader.java.erb +232 -133
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Nodes.java.erb +62 -23
- data/vendor/prism/templates/javascript/src/deserialize.js.erb +153 -146
- data/vendor/prism/templates/javascript/src/nodes.js.erb +4 -9
- data/vendor/prism/templates/lib/prism/compiler.rb.erb +14 -5
- data/vendor/prism/templates/lib/prism/dispatcher.rb.erb +20 -12
- data/vendor/prism/templates/lib/prism/dot_visitor.rb.erb +37 -11
- data/vendor/prism/templates/lib/prism/dsl.rb.erb +43 -4
- data/vendor/prism/templates/lib/prism/inspect_visitor.rb.erb +26 -10
- data/vendor/prism/templates/lib/prism/mutation_compiler.rb.erb +5 -2
- data/vendor/prism/templates/lib/prism/node.rb.erb +283 -105
- data/vendor/prism/templates/lib/prism/reflection.rb.erb +11 -2
- data/vendor/prism/templates/lib/prism/serialize.rb.erb +291 -134
- data/vendor/prism/templates/lib/prism/visitor.rb.erb +18 -0
- data/vendor/prism/templates/src/diagnostic.c.erb +114 -63
- data/vendor/prism/templates/src/json.c.erb +130 -0
- data/vendor/prism/templates/src/node.c.erb +79 -236
- data/vendor/prism/templates/src/prettyprint.c.erb +24 -13
- data/vendor/prism/templates/src/serialize.c.erb +369 -183
- data/vendor/prism/templates/src/{token_type.c.erb → tokens.c.erb} +22 -11
- data/vendor/prism/templates/template.rb +193 -91
- metadata +100 -42
- data/vendor/prism/include/prism/defines.h +0 -260
- data/vendor/prism/include/prism/pack.h +0 -163
- data/vendor/prism/include/prism/regexp.h +0 -43
- data/vendor/prism/include/prism/static_literals.h +0 -121
- data/vendor/prism/include/prism/util/pm_buffer.h +0 -236
- data/vendor/prism/include/prism/util/pm_char.h +0 -204
- data/vendor/prism/include/prism/util/pm_constant_pool.h +0 -218
- data/vendor/prism/include/prism/util/pm_integer.h +0 -130
- data/vendor/prism/include/prism/util/pm_memchr.h +0 -29
- data/vendor/prism/include/prism/util/pm_newline_list.h +0 -113
- data/vendor/prism/include/prism/util/pm_string.h +0 -200
- data/vendor/prism/src/pack.c +0 -509
- data/vendor/prism/src/util/pm_constant_pool.c +0 -342
- data/vendor/prism/src/util/pm_list.c +0 -49
- data/vendor/prism/src/util/pm_newline_list.c +0 -125
- data/vendor/prism/src/util/pm_string.c +0 -381
- data/vendor/prism/src/util/pm_strpbrk.c +0 -206
- data/vendor/prism/templates/include/prism/diagnostic.h.erb +0 -130
- data/vendor/prism/templates/rbi/prism/dsl.rbi.erb +0 -68
- data/vendor/prism/templates/rbi/prism/node.rbi.erb +0 -167
- data/vendor/prism/templates/rbi/prism/visitor.rbi.erb +0 -18
- data/vendor/prism/templates/sig/prism/_private/dot_visitor.rbs.erb +0 -45
- data/vendor/prism/templates/sig/prism/dsl.rbs.erb +0 -31
- data/vendor/prism/templates/sig/prism/mutation_compiler.rbs.erb +0 -7
- data/vendor/prism/templates/sig/prism/node.rbs.erb +0 -136
- data/vendor/prism/templates/sig/prism/visitor.rbs.erb +0 -17
- data/vendor/prism/templates/sig/prism.rbs.erb +0 -92
data/vendor/prism/src/options.c
CHANGED
|
@@ -1,34 +1,88 @@
|
|
|
1
|
-
#include "prism/options.h"
|
|
1
|
+
#include "prism/internal/options.h"
|
|
2
|
+
|
|
3
|
+
#include "prism/compiler/inline.h"
|
|
4
|
+
|
|
5
|
+
#include "prism/internal/allocator.h"
|
|
6
|
+
#include "prism/internal/char.h"
|
|
7
|
+
#include "prism/internal/stringy.h"
|
|
8
|
+
|
|
9
|
+
#include <stdlib.h>
|
|
10
|
+
#include <string.h>
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Allocate a new options struct. If the options struct cannot be allocated,
|
|
14
|
+
* this function aborts the process.
|
|
15
|
+
*/
|
|
16
|
+
pm_options_t *
|
|
17
|
+
pm_options_new(void) {
|
|
18
|
+
pm_options_t *options = xcalloc(1, sizeof(pm_options_t));
|
|
19
|
+
if (options == NULL) abort();
|
|
20
|
+
|
|
21
|
+
options->line = 1;
|
|
22
|
+
return options;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Free the internal memory associated with the options.
|
|
27
|
+
*/
|
|
28
|
+
void
|
|
29
|
+
pm_options_cleanup(pm_options_t *options) {
|
|
30
|
+
for (size_t scope_index = 0; scope_index < options->scopes_count; scope_index++) {
|
|
31
|
+
pm_options_scope_t *scope = &options->scopes[scope_index];
|
|
32
|
+
xfree_sized(scope->locals, scope->locals_count * sizeof(pm_string_t));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
xfree_sized(options->scopes, options->scopes_count * sizeof(pm_options_scope_t));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Free both the held memory of the given options struct and the struct itself.
|
|
40
|
+
*
|
|
41
|
+
* @param options The options struct to free.
|
|
42
|
+
*/
|
|
43
|
+
void
|
|
44
|
+
pm_options_free(pm_options_t *options) {
|
|
45
|
+
pm_options_cleanup(options);
|
|
46
|
+
xfree_sized(options, sizeof(pm_options_t));
|
|
47
|
+
}
|
|
2
48
|
|
|
3
49
|
/**
|
|
4
50
|
* Set the shebang callback option on the given options struct.
|
|
5
51
|
*/
|
|
6
|
-
|
|
52
|
+
void
|
|
7
53
|
pm_options_shebang_callback_set(pm_options_t *options, pm_options_shebang_callback_t shebang_callback, void *shebang_callback_data) {
|
|
8
54
|
options->shebang_callback = shebang_callback;
|
|
9
55
|
options->shebang_callback_data = shebang_callback_data;
|
|
10
56
|
}
|
|
11
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Get the filepath option on the given options struct.
|
|
60
|
+
*/
|
|
61
|
+
const pm_string_t *
|
|
62
|
+
pm_options_filepath(const pm_options_t *options) {
|
|
63
|
+
return &options->filepath;
|
|
64
|
+
}
|
|
65
|
+
|
|
12
66
|
/**
|
|
13
67
|
* Set the filepath option on the given options struct.
|
|
14
68
|
*/
|
|
15
|
-
|
|
69
|
+
void
|
|
16
70
|
pm_options_filepath_set(pm_options_t *options, const char *filepath) {
|
|
17
|
-
|
|
71
|
+
pm_string_init(&options->filepath, (const uint8_t *) filepath, strlen(filepath));
|
|
18
72
|
}
|
|
19
73
|
|
|
20
74
|
/**
|
|
21
75
|
* Set the encoding option on the given options struct.
|
|
22
76
|
*/
|
|
23
|
-
|
|
77
|
+
void
|
|
24
78
|
pm_options_encoding_set(pm_options_t *options, const char *encoding) {
|
|
25
|
-
|
|
79
|
+
pm_string_init(&options->encoding, (const uint8_t *) encoding, strlen(encoding));
|
|
26
80
|
}
|
|
27
81
|
|
|
28
82
|
/**
|
|
29
83
|
* Set the encoding_locked option on the given options struct.
|
|
30
84
|
*/
|
|
31
|
-
|
|
85
|
+
void
|
|
32
86
|
pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked) {
|
|
33
87
|
options->encoding_locked = encoding_locked;
|
|
34
88
|
}
|
|
@@ -36,7 +90,7 @@ pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked) {
|
|
|
36
90
|
/**
|
|
37
91
|
* Set the line option on the given options struct.
|
|
38
92
|
*/
|
|
39
|
-
|
|
93
|
+
void
|
|
40
94
|
pm_options_line_set(pm_options_t *options, int32_t line) {
|
|
41
95
|
options->line = line;
|
|
42
96
|
}
|
|
@@ -44,7 +98,7 @@ pm_options_line_set(pm_options_t *options, int32_t line) {
|
|
|
44
98
|
/**
|
|
45
99
|
* Set the frozen string literal option on the given options struct.
|
|
46
100
|
*/
|
|
47
|
-
|
|
101
|
+
void
|
|
48
102
|
pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal) {
|
|
49
103
|
options->frozen_string_literal = frozen_string_literal ? PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED : PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED;
|
|
50
104
|
}
|
|
@@ -52,7 +106,7 @@ pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_l
|
|
|
52
106
|
/**
|
|
53
107
|
* Sets the command line option on the given options struct.
|
|
54
108
|
*/
|
|
55
|
-
|
|
109
|
+
void
|
|
56
110
|
pm_options_command_line_set(pm_options_t *options, uint8_t command_line) {
|
|
57
111
|
options->command_line = command_line;
|
|
58
112
|
}
|
|
@@ -60,7 +114,7 @@ pm_options_command_line_set(pm_options_t *options, uint8_t command_line) {
|
|
|
60
114
|
/**
|
|
61
115
|
* Checks if the given slice represents a number.
|
|
62
116
|
*/
|
|
63
|
-
static
|
|
117
|
+
static PRISM_INLINE bool
|
|
64
118
|
is_number(const char *string, size_t length) {
|
|
65
119
|
return pm_strspn_decimal_digit((const uint8_t *) string, (ptrdiff_t) length) == length;
|
|
66
120
|
}
|
|
@@ -70,7 +124,7 @@ is_number(const char *string, size_t length) {
|
|
|
70
124
|
* string. If the string contains an invalid option, this returns false.
|
|
71
125
|
* Otherwise, it returns true.
|
|
72
126
|
*/
|
|
73
|
-
|
|
127
|
+
bool
|
|
74
128
|
pm_options_version_set(pm_options_t *options, const char *version, size_t length) {
|
|
75
129
|
if (version == NULL) {
|
|
76
130
|
options->version = PM_OPTIONS_VERSION_LATEST;
|
|
@@ -123,8 +177,8 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
|
|
|
123
177
|
}
|
|
124
178
|
}
|
|
125
179
|
|
|
126
|
-
if (length
|
|
127
|
-
if (strncmp(version, "latest",
|
|
180
|
+
if (length == 6) {
|
|
181
|
+
if (strncmp(version, "latest", 6) == 0) {
|
|
128
182
|
options->version = PM_OPTIONS_VERSION_LATEST;
|
|
129
183
|
return true;
|
|
130
184
|
}
|
|
@@ -133,10 +187,28 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
|
|
|
133
187
|
return false;
|
|
134
188
|
}
|
|
135
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Set the version option on the given options struct to the lowest version of
|
|
192
|
+
* Ruby that prism supports.
|
|
193
|
+
*/
|
|
194
|
+
void
|
|
195
|
+
pm_options_version_set_lowest(pm_options_t *options) {
|
|
196
|
+
options->version = PM_OPTIONS_VERSION_CRUBY_3_3;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Set the version option on the given options struct to the highest version of
|
|
201
|
+
* Ruby that prism supports.
|
|
202
|
+
*/
|
|
203
|
+
void
|
|
204
|
+
pm_options_version_set_highest(pm_options_t *options) {
|
|
205
|
+
options->version = PM_OPTIONS_VERSION_LATEST;
|
|
206
|
+
}
|
|
207
|
+
|
|
136
208
|
/**
|
|
137
209
|
* Set the main script option on the given options struct.
|
|
138
210
|
*/
|
|
139
|
-
|
|
211
|
+
void
|
|
140
212
|
pm_options_main_script_set(pm_options_t *options, bool main_script) {
|
|
141
213
|
options->main_script = main_script;
|
|
142
214
|
}
|
|
@@ -144,19 +216,57 @@ pm_options_main_script_set(pm_options_t *options, bool main_script) {
|
|
|
144
216
|
/**
|
|
145
217
|
* Set the partial script option on the given options struct.
|
|
146
218
|
*/
|
|
147
|
-
|
|
219
|
+
void
|
|
148
220
|
pm_options_partial_script_set(pm_options_t *options, bool partial_script) {
|
|
149
221
|
options->partial_script = partial_script;
|
|
150
222
|
}
|
|
151
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Get the freeze option on the given options struct.
|
|
226
|
+
*/
|
|
227
|
+
bool
|
|
228
|
+
pm_options_freeze(const pm_options_t *options) {
|
|
229
|
+
return options->freeze;
|
|
230
|
+
}
|
|
231
|
+
|
|
152
232
|
/**
|
|
153
233
|
* Set the freeze option on the given options struct.
|
|
154
234
|
*/
|
|
155
|
-
|
|
235
|
+
void
|
|
156
236
|
pm_options_freeze_set(pm_options_t *options, bool freeze) {
|
|
157
237
|
options->freeze = freeze;
|
|
158
238
|
}
|
|
159
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Get the attach_comments option on the given options struct.
|
|
242
|
+
*/
|
|
243
|
+
bool
|
|
244
|
+
pm_options_attach_comments(const pm_options_t *options) {
|
|
245
|
+
return options->attach_comments;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Set the attach_comments option on the given options struct.
|
|
250
|
+
*/
|
|
251
|
+
void
|
|
252
|
+
pm_options_attach_comments_set(pm_options_t *options, bool attach_comments) {
|
|
253
|
+
options->attach_comments = attach_comments;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Get the raise_error option on the given options struct.
|
|
258
|
+
*/
|
|
259
|
+
uint8_t pm_options_raise_error(const pm_options_t *options) {
|
|
260
|
+
return options->raise_error;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Set the raise_error option on the given options struct.
|
|
265
|
+
*/
|
|
266
|
+
void pm_options_raise_error_set(pm_options_t *options, uint8_t raise_error) {
|
|
267
|
+
options->raise_error = raise_error;
|
|
268
|
+
}
|
|
269
|
+
|
|
160
270
|
// For some reason, GCC analyzer thinks we're leaking allocated scopes and
|
|
161
271
|
// locals here, even though we definitely aren't. This is a false positive.
|
|
162
272
|
// Ideally we wouldn't need to suppress this.
|
|
@@ -168,7 +278,7 @@ pm_options_freeze_set(pm_options_t *options, bool freeze) {
|
|
|
168
278
|
/**
|
|
169
279
|
* Allocate and zero out the scopes array on the given options struct.
|
|
170
280
|
*/
|
|
171
|
-
|
|
281
|
+
bool
|
|
172
282
|
pm_options_scopes_init(pm_options_t *options, size_t scopes_count) {
|
|
173
283
|
options->scopes_count = scopes_count;
|
|
174
284
|
options->scopes = xcalloc(scopes_count, sizeof(pm_options_scope_t));
|
|
@@ -176,10 +286,20 @@ pm_options_scopes_init(pm_options_t *options, size_t scopes_count) {
|
|
|
176
286
|
}
|
|
177
287
|
|
|
178
288
|
/**
|
|
179
|
-
* Return a pointer to the scope at the given index within the given
|
|
289
|
+
* Return a constant pointer to the scope at the given index within the given
|
|
290
|
+
* options.
|
|
180
291
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
292
|
+
const pm_options_scope_t *
|
|
293
|
+
pm_options_scope(const pm_options_t *options, size_t index) {
|
|
294
|
+
return &options->scopes[index];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Return a mutable pointer to the scope at the given index within the given
|
|
299
|
+
* options.
|
|
300
|
+
*/
|
|
301
|
+
pm_options_scope_t *
|
|
302
|
+
pm_options_scope_mut(pm_options_t *options, size_t index) {
|
|
183
303
|
return &options->scopes[index];
|
|
184
304
|
}
|
|
185
305
|
|
|
@@ -187,49 +307,38 @@ pm_options_scope_get(const pm_options_t *options, size_t index) {
|
|
|
187
307
|
* Create a new options scope struct. This will hold a set of locals that are in
|
|
188
308
|
* scope surrounding the code that is being parsed.
|
|
189
309
|
*/
|
|
190
|
-
|
|
310
|
+
void
|
|
191
311
|
pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count) {
|
|
192
312
|
scope->locals_count = locals_count;
|
|
193
313
|
scope->locals = xcalloc(locals_count, sizeof(pm_string_t));
|
|
194
314
|
scope->forwarding = PM_OPTIONS_SCOPE_FORWARDING_NONE;
|
|
195
|
-
|
|
315
|
+
if (scope->locals == NULL) abort();
|
|
196
316
|
}
|
|
197
317
|
|
|
198
318
|
/**
|
|
199
|
-
* Return a pointer to the local at the given index within the given
|
|
319
|
+
* Return a constant pointer to the local at the given index within the given
|
|
320
|
+
* scope.
|
|
200
321
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
322
|
+
const pm_string_t *
|
|
323
|
+
pm_options_scope_local(const pm_options_scope_t *scope, size_t index) {
|
|
203
324
|
return &scope->locals[index];
|
|
204
325
|
}
|
|
205
326
|
|
|
206
327
|
/**
|
|
207
|
-
*
|
|
328
|
+
* Return a mutable pointer to the local at the given index within the given
|
|
329
|
+
* scope.
|
|
208
330
|
*/
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
scope->
|
|
331
|
+
pm_string_t *
|
|
332
|
+
pm_options_scope_local_mut(pm_options_scope_t *scope, size_t index) {
|
|
333
|
+
return &scope->locals[index];
|
|
212
334
|
}
|
|
213
335
|
|
|
214
336
|
/**
|
|
215
|
-
*
|
|
337
|
+
* Set the forwarding option on the given scope struct.
|
|
216
338
|
*/
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
pm_string_free(&options->encoding);
|
|
221
|
-
|
|
222
|
-
for (size_t scope_index = 0; scope_index < options->scopes_count; scope_index++) {
|
|
223
|
-
pm_options_scope_t *scope = &options->scopes[scope_index];
|
|
224
|
-
|
|
225
|
-
for (size_t local_index = 0; local_index < scope->locals_count; local_index++) {
|
|
226
|
-
pm_string_free(&scope->locals[local_index]);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
xfree(scope->locals);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
xfree(options->scopes);
|
|
339
|
+
void
|
|
340
|
+
pm_options_scope_forwarding_set(pm_options_scope_t *scope, uint8_t forwarding) {
|
|
341
|
+
scope->forwarding = forwarding;
|
|
233
342
|
}
|
|
234
343
|
|
|
235
344
|
/**
|
|
@@ -280,7 +389,7 @@ pm_options_read(pm_options_t *options, const char *data) {
|
|
|
280
389
|
data += 4;
|
|
281
390
|
|
|
282
391
|
if (filepath_length > 0) {
|
|
283
|
-
|
|
392
|
+
pm_string_init(&options->filepath, (const uint8_t *) data, filepath_length);
|
|
284
393
|
data += filepath_length;
|
|
285
394
|
}
|
|
286
395
|
|
|
@@ -291,7 +400,7 @@ pm_options_read(pm_options_t *options, const char *data) {
|
|
|
291
400
|
data += 4;
|
|
292
401
|
|
|
293
402
|
if (encoding_length > 0) {
|
|
294
|
-
|
|
403
|
+
pm_string_init(&options->encoding, (const uint8_t *) data, encoding_length);
|
|
295
404
|
data += encoding_length;
|
|
296
405
|
}
|
|
297
406
|
|
|
@@ -302,6 +411,7 @@ pm_options_read(pm_options_t *options, const char *data) {
|
|
|
302
411
|
options->main_script = ((uint8_t) *data++) > 0;
|
|
303
412
|
options->partial_script = ((uint8_t) *data++) > 0;
|
|
304
413
|
options->freeze = ((uint8_t) *data++) > 0;
|
|
414
|
+
options->attach_comments = ((uint8_t) *data++) > 0;
|
|
305
415
|
|
|
306
416
|
uint32_t scopes_count = pm_options_read_u32(data);
|
|
307
417
|
data += 4;
|
|
@@ -314,10 +424,7 @@ pm_options_read(pm_options_t *options, const char *data) {
|
|
|
314
424
|
data += 4;
|
|
315
425
|
|
|
316
426
|
pm_options_scope_t *scope = &options->scopes[scope_index];
|
|
317
|
-
|
|
318
|
-
pm_options_free(options);
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
427
|
+
pm_options_scope_init(scope, locals_count);
|
|
321
428
|
|
|
322
429
|
uint8_t forwarding = (uint8_t) *data++;
|
|
323
430
|
pm_options_scope_forwarding_set(&options->scopes[scope_index], forwarding);
|
|
@@ -326,7 +433,7 @@ pm_options_read(pm_options_t *options, const char *data) {
|
|
|
326
433
|
uint32_t local_length = pm_options_read_u32(data);
|
|
327
434
|
data += 4;
|
|
328
435
|
|
|
329
|
-
|
|
436
|
+
pm_string_init(&scope->locals[local_index], (const uint8_t *) data, local_length);
|
|
330
437
|
data += local_length;
|
|
331
438
|
}
|
|
332
439
|
}
|