prism 1.9.0 → 2.0.0.rc2
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/CHANGELOG.md +88 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/LICENSE.md +1 -1
- data/Makefile +41 -12
- data/README.md +35 -97
- data/config.yml +174 -161
- data/docs/build_system.md +2 -2
- data/docs/configuration.md +5 -4
- data/docs/encoding.md +2 -2
- data/docs/fuzzing.md +4 -11
- data/docs/javascript.md +19 -4
- data/docs/mapping.md +1 -1
- data/docs/releasing.md +77 -5
- data/docs/relocation.md +2 -4
- data/docs/serialization.md +22 -24
- data/docs/testing.md +46 -29
- data/ext/prism/api_node.c +1461 -1401
- data/ext/prism/extconf.rb +3 -4
- data/ext/prism/extension.c +796 -422
- data/ext/prism/extension.h +3 -3
- data/include/prism/arena.h +37 -0
- data/include/prism/ast.h +2727 -610
- data/include/prism/buffer.h +52 -0
- data/include/prism/comments.h +55 -0
- data/include/prism/compiler/accel.h +26 -0
- data/include/prism/compiler/align.h +36 -0
- data/include/prism/compiler/assume.h +25 -0
- data/include/prism/compiler/bswap.h +46 -0
- data/include/prism/compiler/endianness.h +34 -0
- data/include/prism/compiler/exported.h +24 -0
- data/include/prism/compiler/fallthrough.h +22 -0
- data/include/prism/compiler/filesystem.h +32 -0
- data/include/prism/compiler/flex_array.h +19 -0
- data/include/prism/compiler/force_inline.h +21 -0
- data/include/prism/compiler/format.h +25 -0
- data/include/prism/compiler/inline.h +17 -0
- data/include/prism/compiler/nodiscard.h +22 -0
- data/include/prism/compiler/nonnull.h +18 -0
- data/include/prism/compiler/unused.h +18 -0
- data/include/prism/constant_pool.h +81 -0
- data/include/prism/diagnostic.h +38 -403
- data/include/prism/errors_format.h +53 -0
- data/include/prism/excludes.h +29 -0
- data/include/prism/integer.h +41 -0
- data/include/prism/internal/allocator.h +68 -0
- data/include/prism/internal/allocator_debug.h +88 -0
- data/include/prism/internal/arena.h +108 -0
- data/include/prism/internal/bit.h +42 -0
- data/include/prism/internal/buffer.h +94 -0
- data/include/prism/internal/char.h +145 -0
- data/include/prism/internal/comments.h +53 -0
- data/include/prism/internal/constant_pool.h +152 -0
- data/include/prism/internal/diagnostic.h +389 -0
- data/include/prism/{encoding.h → internal/encoding.h} +27 -68
- data/include/prism/internal/integer.h +68 -0
- data/include/prism/internal/isinf.h +16 -0
- data/include/prism/internal/line_offset_list.h +34 -0
- data/include/prism/{util/pm_list.h → internal/list.h} +11 -52
- data/include/prism/internal/magic_comments.h +23 -0
- data/include/prism/internal/memchr.h +15 -0
- data/include/prism/internal/node.h +38 -0
- data/include/prism/internal/options.h +232 -0
- data/include/prism/internal/parser.h +1004 -0
- data/include/prism/internal/regexp.h +26 -0
- data/include/prism/internal/serialize.h +39 -0
- data/include/prism/internal/source.h +72 -0
- data/include/prism/{static_literals.h → internal/static_literals.h} +26 -47
- data/include/prism/internal/stringy.h +35 -0
- data/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
- data/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
- data/include/prism/internal/tokens.h +11 -0
- data/include/prism/internal/xxh3.h +16 -0
- data/include/prism/json.h +32 -0
- data/include/prism/line_offset_list.h +61 -0
- data/include/prism/magic_comments.h +35 -0
- data/include/prism/node.h +18 -53
- data/include/prism/options.h +146 -280
- data/include/prism/parser.h +356 -867
- data/include/prism/prettyprint.h +6 -9
- data/include/prism/serialize.h +115 -0
- data/include/prism/source.h +155 -0
- data/include/prism/stream.h +28 -0
- data/include/prism/string_query.h +74 -0
- data/include/prism/stringy.h +72 -0
- data/include/prism/version.h +12 -3
- data/include/prism.h +43 -320
- data/lib/prism/compiler.rb +319 -305
- data/lib/prism/desugar_compiler.rb +105 -34
- data/lib/prism/dispatcher.rb +646 -473
- data/lib/prism/dot_visitor.rb +592 -511
- data/lib/prism/dsl.rb +391 -25
- data/lib/prism/ffi.rb +258 -90
- data/lib/prism/inspect_visitor.rb +357 -325
- data/lib/prism/lex_compat.rb +254 -212
- data/lib/prism/mutation_compiler.rb +313 -305
- data/lib/prism/node.rb +20966 -6992
- data/lib/prism/node_ext.rb +180 -187
- data/lib/prism/node_find.rb +215 -0
- data/lib/prism/parse_result/errors.rb +7 -1
- data/lib/prism/parse_result/newlines.rb +276 -8
- data/lib/prism/parse_result.rb +468 -139
- data/lib/prism/pattern.rb +65 -20
- data/lib/prism/reflection.rb +23 -12
- data/lib/prism/relocation.rb +149 -87
- data/lib/prism/serialize.rb +3460 -539
- data/lib/prism/string_query.rb +24 -1
- data/lib/prism/translation/parser/builder.rb +10 -2
- data/lib/prism/translation/parser/compiler.rb +44 -52
- data/lib/prism/translation/parser/lexer.rb +41 -92
- data/lib/prism/translation/parser.rb +1 -1
- data/lib/prism/translation/parser_current.rb +1 -1
- data/lib/prism/translation/ripper/lexer.rb +8 -10
- data/lib/prism/translation/ripper/sexp.rb +2 -10
- data/lib/prism/translation/ripper/shim.rb +2 -0
- data/lib/prism/translation/ripper.rb +967 -209
- data/lib/prism/translation/ruby_parser.rb +73 -316
- data/lib/prism/translation.rb +2 -0
- data/lib/prism/visitor.rb +632 -5
- data/lib/prism.rb +79 -9
- data/prism.gemspec +128 -62
- data/rbi/generated/prism/compiler.rbi +489 -0
- data/rbi/generated/prism/desugar_compiler.rbi +306 -0
- data/rbi/generated/prism/dispatcher.rbi +1138 -0
- data/rbi/generated/prism/dot_visitor.rbi +618 -0
- data/rbi/generated/prism/dsl.rbi +751 -0
- data/rbi/generated/prism/inspect_visitor.rbi +503 -0
- data/rbi/generated/prism/lex_compat.rbi +162 -0
- data/rbi/generated/prism/mutation_compiler.rbi +464 -0
- data/rbi/generated/prism/node.rbi +14407 -0
- data/rbi/generated/prism/node_ext.rbi +259 -0
- data/rbi/generated/prism/node_find.rbi +79 -0
- data/rbi/generated/prism/parse_result/errors.rbi +21 -0
- data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
- data/rbi/generated/prism/parse_result.rbi +776 -0
- data/rbi/generated/prism/pattern.rbi +134 -0
- data/rbi/generated/prism/reflection.rbi +89 -0
- data/rbi/generated/prism/relocation.rbi +329 -0
- data/rbi/generated/prism/serialize.rbi +184 -0
- data/rbi/generated/prism/string_query.rbi +43 -0
- data/rbi/generated/prism/translation.rbi +7 -0
- data/rbi/generated/prism/visitor.rbi +650 -0
- data/rbi/generated/prism.rbi +86 -0
- data/rbi/prism/translation/parser_versions.rbi +5 -0
- data/rbi/rubyvm/node_find.rbi +14 -0
- data/sig/generated/prism/compiler.rbs +492 -0
- data/sig/generated/prism/desugar_compiler.rbs +305 -0
- data/sig/generated/prism/dispatcher.rbs +1292 -0
- data/sig/generated/prism/dot_visitor.rbs +635 -0
- data/sig/generated/prism/dsl.rbs +928 -0
- data/sig/generated/prism/inspect_visitor.rbs +509 -0
- data/sig/generated/prism/lex_compat.rbs +166 -0
- data/sig/{prism → generated/prism}/mutation_compiler.rbs +309 -4
- data/sig/generated/prism/node.rbs +20896 -0
- data/sig/generated/prism/node_ext.rbs +290 -0
- data/sig/generated/prism/node_find.rbs +90 -0
- data/sig/generated/prism/parse_result/errors.rbs +22 -0
- data/sig/generated/prism/parse_result/newlines.rbs +223 -0
- data/sig/generated/prism/parse_result.rbs +871 -0
- data/sig/generated/prism/pattern.rbs +156 -0
- data/sig/generated/prism/reflection.rbs +101 -0
- data/sig/generated/prism/relocation.rbs +428 -0
- data/sig/generated/prism/serialize.rbs +198 -0
- data/sig/generated/prism/string_query.rbs +43 -0
- data/sig/generated/prism/translation.rbs +8 -0
- data/sig/generated/prism/visitor.rbs +1111 -0
- data/sig/generated/prism.rbs +84 -0
- data/sig/manifest.yaml +2 -0
- data/src/arena.c +117 -0
- data/src/{util/pm_buffer.c → buffer.c} +53 -21
- data/src/{util/pm_char.c → char.c} +28 -57
- data/src/comments.c +454 -0
- data/src/constant_pool.c +406 -0
- data/src/diagnostic.c +97 -65
- data/src/encoding.c +8 -3
- data/src/errors_format.c +519 -0
- data/src/{util/pm_integer.c → integer.c} +33 -22
- data/src/json.c +5733 -0
- data/src/line_offset_list.c +100 -0
- data/src/list.c +24 -0
- data/src/{util/pm_memchr.c → memchr.c} +8 -6
- data/src/node.c +3504 -7674
- data/src/options.c +162 -49
- data/src/parser.c +367 -0
- data/src/prettyprint.c +421 -354
- data/src/prism.c +8402 -7161
- data/src/regexp.c +961 -45
- data/src/serialize.c +460 -424
- data/src/source.c +518 -0
- data/src/static_literals.c +111 -43
- data/src/string_query.c +180 -0
- data/src/stringy.c +91 -0
- data/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
- data/src/strpbrk.c +447 -0
- data/src/{token_type.c → tokens.c} +39 -18
- data/src/xxh3.c +292 -0
- metadata +128 -63
- data/ext/prism/api_pack.c +0 -276
- data/include/prism/defines.h +0 -260
- data/include/prism/pack.h +0 -163
- data/include/prism/regexp.h +0 -43
- data/include/prism/util/pm_buffer.h +0 -236
- data/include/prism/util/pm_char.h +0 -204
- data/include/prism/util/pm_constant_pool.h +0 -218
- data/include/prism/util/pm_integer.h +0 -130
- data/include/prism/util/pm_memchr.h +0 -29
- data/include/prism/util/pm_newline_list.h +0 -113
- data/include/prism/util/pm_string.h +0 -200
- data/lib/prism/pack.rb +0 -230
- data/lib/prism/parse_result/comments.rb +0 -188
- data/rbi/prism/compiler.rbi +0 -12
- data/rbi/prism/dsl.rbi +0 -524
- data/rbi/prism/inspect_visitor.rbi +0 -12
- data/rbi/prism/node.rbi +0 -8750
- data/rbi/prism/node_ext.rbi +0 -107
- data/rbi/prism/parse_result.rbi +0 -404
- data/rbi/prism/reflection.rbi +0 -58
- data/rbi/prism/string_query.rbi +0 -12
- data/rbi/prism/visitor.rbi +0 -473
- data/rbi/prism.rbi +0 -63
- data/sig/prism/compiler.rbs +0 -9
- data/sig/prism/dispatcher.rbs +0 -19
- data/sig/prism/dot_visitor.rbs +0 -6
- data/sig/prism/dsl.rbs +0 -351
- data/sig/prism/inspect_visitor.rbs +0 -22
- data/sig/prism/lex_compat.rbs +0 -10
- data/sig/prism/node.rbs +0 -4042
- data/sig/prism/node_ext.rbs +0 -149
- data/sig/prism/pack.rbs +0 -43
- data/sig/prism/parse_result/comments.rbs +0 -38
- data/sig/prism/parse_result.rbs +0 -197
- data/sig/prism/pattern.rbs +0 -13
- data/sig/prism/reflection.rbs +0 -50
- data/sig/prism/relocation.rbs +0 -185
- data/sig/prism/serialize.rbs +0 -8
- data/sig/prism/string_query.rbs +0 -11
- data/sig/prism/visitor.rbs +0 -169
- data/sig/prism.rbs +0 -272
- data/src/pack.c +0 -509
- data/src/util/pm_constant_pool.c +0 -342
- data/src/util/pm_list.c +0 -49
- data/src/util/pm_newline_list.c +0 -125
- data/src/util/pm_string.c +0 -381
- data/src/util/pm_strpbrk.c +0 -206
data/src/options.c
CHANGED
|
@@ -1,18 +1,78 @@
|
|
|
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
|
+
return options;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Free the internal memory associated with the options.
|
|
25
|
+
*/
|
|
26
|
+
void
|
|
27
|
+
pm_options_cleanup(pm_options_t *options) {
|
|
28
|
+
pm_string_cleanup(&options->filepath);
|
|
29
|
+
pm_string_cleanup(&options->encoding);
|
|
30
|
+
|
|
31
|
+
for (size_t scope_index = 0; scope_index < options->scopes_count; scope_index++) {
|
|
32
|
+
pm_options_scope_t *scope = &options->scopes[scope_index];
|
|
33
|
+
|
|
34
|
+
for (size_t local_index = 0; local_index < scope->locals_count; local_index++) {
|
|
35
|
+
pm_string_cleanup(&scope->locals[local_index]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
xfree_sized(scope->locals, scope->locals_count * sizeof(pm_string_t));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
xfree_sized(options->scopes, options->scopes_count * sizeof(pm_options_scope_t));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Free both the held memory of the given options struct and the struct itself.
|
|
46
|
+
*
|
|
47
|
+
* @param options The options struct to free.
|
|
48
|
+
*/
|
|
49
|
+
void
|
|
50
|
+
pm_options_free(pm_options_t *options) {
|
|
51
|
+
pm_options_cleanup(options);
|
|
52
|
+
xfree_sized(options, sizeof(pm_options_t));
|
|
53
|
+
}
|
|
2
54
|
|
|
3
55
|
/**
|
|
4
56
|
* Set the shebang callback option on the given options struct.
|
|
5
57
|
*/
|
|
6
|
-
|
|
58
|
+
void
|
|
7
59
|
pm_options_shebang_callback_set(pm_options_t *options, pm_options_shebang_callback_t shebang_callback, void *shebang_callback_data) {
|
|
8
60
|
options->shebang_callback = shebang_callback;
|
|
9
61
|
options->shebang_callback_data = shebang_callback_data;
|
|
10
62
|
}
|
|
11
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Get the filepath option on the given options struct.
|
|
66
|
+
*/
|
|
67
|
+
const pm_string_t *
|
|
68
|
+
pm_options_filepath(const pm_options_t *options) {
|
|
69
|
+
return &options->filepath;
|
|
70
|
+
}
|
|
71
|
+
|
|
12
72
|
/**
|
|
13
73
|
* Set the filepath option on the given options struct.
|
|
14
74
|
*/
|
|
15
|
-
|
|
75
|
+
void
|
|
16
76
|
pm_options_filepath_set(pm_options_t *options, const char *filepath) {
|
|
17
77
|
pm_string_constant_init(&options->filepath, filepath, strlen(filepath));
|
|
18
78
|
}
|
|
@@ -20,7 +80,7 @@ pm_options_filepath_set(pm_options_t *options, const char *filepath) {
|
|
|
20
80
|
/**
|
|
21
81
|
* Set the encoding option on the given options struct.
|
|
22
82
|
*/
|
|
23
|
-
|
|
83
|
+
void
|
|
24
84
|
pm_options_encoding_set(pm_options_t *options, const char *encoding) {
|
|
25
85
|
pm_string_constant_init(&options->encoding, encoding, strlen(encoding));
|
|
26
86
|
}
|
|
@@ -28,7 +88,7 @@ pm_options_encoding_set(pm_options_t *options, const char *encoding) {
|
|
|
28
88
|
/**
|
|
29
89
|
* Set the encoding_locked option on the given options struct.
|
|
30
90
|
*/
|
|
31
|
-
|
|
91
|
+
void
|
|
32
92
|
pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked) {
|
|
33
93
|
options->encoding_locked = encoding_locked;
|
|
34
94
|
}
|
|
@@ -36,7 +96,7 @@ pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked) {
|
|
|
36
96
|
/**
|
|
37
97
|
* Set the line option on the given options struct.
|
|
38
98
|
*/
|
|
39
|
-
|
|
99
|
+
void
|
|
40
100
|
pm_options_line_set(pm_options_t *options, int32_t line) {
|
|
41
101
|
options->line = line;
|
|
42
102
|
}
|
|
@@ -44,7 +104,7 @@ pm_options_line_set(pm_options_t *options, int32_t line) {
|
|
|
44
104
|
/**
|
|
45
105
|
* Set the frozen string literal option on the given options struct.
|
|
46
106
|
*/
|
|
47
|
-
|
|
107
|
+
void
|
|
48
108
|
pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal) {
|
|
49
109
|
options->frozen_string_literal = frozen_string_literal ? PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED : PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED;
|
|
50
110
|
}
|
|
@@ -52,7 +112,7 @@ pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_l
|
|
|
52
112
|
/**
|
|
53
113
|
* Sets the command line option on the given options struct.
|
|
54
114
|
*/
|
|
55
|
-
|
|
115
|
+
void
|
|
56
116
|
pm_options_command_line_set(pm_options_t *options, uint8_t command_line) {
|
|
57
117
|
options->command_line = command_line;
|
|
58
118
|
}
|
|
@@ -60,7 +120,7 @@ pm_options_command_line_set(pm_options_t *options, uint8_t command_line) {
|
|
|
60
120
|
/**
|
|
61
121
|
* Checks if the given slice represents a number.
|
|
62
122
|
*/
|
|
63
|
-
static
|
|
123
|
+
static PRISM_INLINE bool
|
|
64
124
|
is_number(const char *string, size_t length) {
|
|
65
125
|
return pm_strspn_decimal_digit((const uint8_t *) string, (ptrdiff_t) length) == length;
|
|
66
126
|
}
|
|
@@ -70,7 +130,7 @@ is_number(const char *string, size_t length) {
|
|
|
70
130
|
* string. If the string contains an invalid option, this returns false.
|
|
71
131
|
* Otherwise, it returns true.
|
|
72
132
|
*/
|
|
73
|
-
|
|
133
|
+
bool
|
|
74
134
|
pm_options_version_set(pm_options_t *options, const char *version, size_t length) {
|
|
75
135
|
if (version == NULL) {
|
|
76
136
|
options->version = PM_OPTIONS_VERSION_LATEST;
|
|
@@ -123,8 +183,8 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
|
|
|
123
183
|
}
|
|
124
184
|
}
|
|
125
185
|
|
|
126
|
-
if (length
|
|
127
|
-
if (strncmp(version, "latest",
|
|
186
|
+
if (length == 6) {
|
|
187
|
+
if (strncmp(version, "latest", 6) == 0) {
|
|
128
188
|
options->version = PM_OPTIONS_VERSION_LATEST;
|
|
129
189
|
return true;
|
|
130
190
|
}
|
|
@@ -133,10 +193,28 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
|
|
|
133
193
|
return false;
|
|
134
194
|
}
|
|
135
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Set the version option on the given options struct to the lowest version of
|
|
198
|
+
* Ruby that prism supports.
|
|
199
|
+
*/
|
|
200
|
+
void
|
|
201
|
+
pm_options_version_set_lowest(pm_options_t *options) {
|
|
202
|
+
options->version = PM_OPTIONS_VERSION_CRUBY_3_3;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Set the version option on the given options struct to the highest version of
|
|
207
|
+
* Ruby that prism supports.
|
|
208
|
+
*/
|
|
209
|
+
void
|
|
210
|
+
pm_options_version_set_highest(pm_options_t *options) {
|
|
211
|
+
options->version = PM_OPTIONS_VERSION_LATEST;
|
|
212
|
+
}
|
|
213
|
+
|
|
136
214
|
/**
|
|
137
215
|
* Set the main script option on the given options struct.
|
|
138
216
|
*/
|
|
139
|
-
|
|
217
|
+
void
|
|
140
218
|
pm_options_main_script_set(pm_options_t *options, bool main_script) {
|
|
141
219
|
options->main_script = main_script;
|
|
142
220
|
}
|
|
@@ -144,19 +222,57 @@ pm_options_main_script_set(pm_options_t *options, bool main_script) {
|
|
|
144
222
|
/**
|
|
145
223
|
* Set the partial script option on the given options struct.
|
|
146
224
|
*/
|
|
147
|
-
|
|
225
|
+
void
|
|
148
226
|
pm_options_partial_script_set(pm_options_t *options, bool partial_script) {
|
|
149
227
|
options->partial_script = partial_script;
|
|
150
228
|
}
|
|
151
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Get the freeze option on the given options struct.
|
|
232
|
+
*/
|
|
233
|
+
bool
|
|
234
|
+
pm_options_freeze(const pm_options_t *options) {
|
|
235
|
+
return options->freeze;
|
|
236
|
+
}
|
|
237
|
+
|
|
152
238
|
/**
|
|
153
239
|
* Set the freeze option on the given options struct.
|
|
154
240
|
*/
|
|
155
|
-
|
|
241
|
+
void
|
|
156
242
|
pm_options_freeze_set(pm_options_t *options, bool freeze) {
|
|
157
243
|
options->freeze = freeze;
|
|
158
244
|
}
|
|
159
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Get the attach_comments option on the given options struct.
|
|
248
|
+
*/
|
|
249
|
+
bool
|
|
250
|
+
pm_options_attach_comments(const pm_options_t *options) {
|
|
251
|
+
return options->attach_comments;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Set the attach_comments option on the given options struct.
|
|
256
|
+
*/
|
|
257
|
+
void
|
|
258
|
+
pm_options_attach_comments_set(pm_options_t *options, bool attach_comments) {
|
|
259
|
+
options->attach_comments = attach_comments;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Get the raise_error option on the given options struct.
|
|
264
|
+
*/
|
|
265
|
+
uint8_t pm_options_raise_error(const pm_options_t *options) {
|
|
266
|
+
return options->raise_error;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Set the raise_error option on the given options struct.
|
|
271
|
+
*/
|
|
272
|
+
void pm_options_raise_error_set(pm_options_t *options, uint8_t raise_error) {
|
|
273
|
+
options->raise_error = raise_error;
|
|
274
|
+
}
|
|
275
|
+
|
|
160
276
|
// For some reason, GCC analyzer thinks we're leaking allocated scopes and
|
|
161
277
|
// locals here, even though we definitely aren't. This is a false positive.
|
|
162
278
|
// Ideally we wouldn't need to suppress this.
|
|
@@ -168,7 +284,7 @@ pm_options_freeze_set(pm_options_t *options, bool freeze) {
|
|
|
168
284
|
/**
|
|
169
285
|
* Allocate and zero out the scopes array on the given options struct.
|
|
170
286
|
*/
|
|
171
|
-
|
|
287
|
+
bool
|
|
172
288
|
pm_options_scopes_init(pm_options_t *options, size_t scopes_count) {
|
|
173
289
|
options->scopes_count = scopes_count;
|
|
174
290
|
options->scopes = xcalloc(scopes_count, sizeof(pm_options_scope_t));
|
|
@@ -176,10 +292,20 @@ pm_options_scopes_init(pm_options_t *options, size_t scopes_count) {
|
|
|
176
292
|
}
|
|
177
293
|
|
|
178
294
|
/**
|
|
179
|
-
* Return a pointer to the scope at the given index within the given
|
|
295
|
+
* Return a constant pointer to the scope at the given index within the given
|
|
296
|
+
* options.
|
|
180
297
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
298
|
+
const pm_options_scope_t *
|
|
299
|
+
pm_options_scope(const pm_options_t *options, size_t index) {
|
|
300
|
+
return &options->scopes[index];
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Return a mutable pointer to the scope at the given index within the given
|
|
305
|
+
* options.
|
|
306
|
+
*/
|
|
307
|
+
pm_options_scope_t *
|
|
308
|
+
pm_options_scope_mut(pm_options_t *options, size_t index) {
|
|
183
309
|
return &options->scopes[index];
|
|
184
310
|
}
|
|
185
311
|
|
|
@@ -187,49 +313,38 @@ pm_options_scope_get(const pm_options_t *options, size_t index) {
|
|
|
187
313
|
* Create a new options scope struct. This will hold a set of locals that are in
|
|
188
314
|
* scope surrounding the code that is being parsed.
|
|
189
315
|
*/
|
|
190
|
-
|
|
316
|
+
void
|
|
191
317
|
pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count) {
|
|
192
318
|
scope->locals_count = locals_count;
|
|
193
319
|
scope->locals = xcalloc(locals_count, sizeof(pm_string_t));
|
|
194
320
|
scope->forwarding = PM_OPTIONS_SCOPE_FORWARDING_NONE;
|
|
195
|
-
|
|
321
|
+
if (scope->locals == NULL) abort();
|
|
196
322
|
}
|
|
197
323
|
|
|
198
324
|
/**
|
|
199
|
-
* Return a pointer to the local at the given index within the given
|
|
325
|
+
* Return a constant pointer to the local at the given index within the given
|
|
326
|
+
* scope.
|
|
200
327
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
328
|
+
const pm_string_t *
|
|
329
|
+
pm_options_scope_local(const pm_options_scope_t *scope, size_t index) {
|
|
203
330
|
return &scope->locals[index];
|
|
204
331
|
}
|
|
205
332
|
|
|
206
333
|
/**
|
|
207
|
-
*
|
|
334
|
+
* Return a mutable pointer to the local at the given index within the given
|
|
335
|
+
* scope.
|
|
208
336
|
*/
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
scope->
|
|
337
|
+
pm_string_t *
|
|
338
|
+
pm_options_scope_local_mut(pm_options_scope_t *scope, size_t index) {
|
|
339
|
+
return &scope->locals[index];
|
|
212
340
|
}
|
|
213
341
|
|
|
214
342
|
/**
|
|
215
|
-
*
|
|
343
|
+
* Set the forwarding option on the given scope struct.
|
|
216
344
|
*/
|
|
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);
|
|
345
|
+
void
|
|
346
|
+
pm_options_scope_forwarding_set(pm_options_scope_t *scope, uint8_t forwarding) {
|
|
347
|
+
scope->forwarding = forwarding;
|
|
233
348
|
}
|
|
234
349
|
|
|
235
350
|
/**
|
|
@@ -302,6 +417,7 @@ pm_options_read(pm_options_t *options, const char *data) {
|
|
|
302
417
|
options->main_script = ((uint8_t) *data++) > 0;
|
|
303
418
|
options->partial_script = ((uint8_t) *data++) > 0;
|
|
304
419
|
options->freeze = ((uint8_t) *data++) > 0;
|
|
420
|
+
options->attach_comments = ((uint8_t) *data++) > 0;
|
|
305
421
|
|
|
306
422
|
uint32_t scopes_count = pm_options_read_u32(data);
|
|
307
423
|
data += 4;
|
|
@@ -314,10 +430,7 @@ pm_options_read(pm_options_t *options, const char *data) {
|
|
|
314
430
|
data += 4;
|
|
315
431
|
|
|
316
432
|
pm_options_scope_t *scope = &options->scopes[scope_index];
|
|
317
|
-
|
|
318
|
-
pm_options_free(options);
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
433
|
+
pm_options_scope_init(scope, locals_count);
|
|
321
434
|
|
|
322
435
|
uint8_t forwarding = (uint8_t) *data++;
|
|
323
436
|
pm_options_scope_forwarding_set(&options->scopes[scope_index], forwarding);
|