Debian Codegraph @

src/options.c

raw symbols SCIP
1 #cxx . . $ `<file>/src/options.c`/include "prism/options.h"cxx . . $ `<file>/include/prism/options.h`/
2
3 /**
4 * Set the shebang callback option on the given options struct.
5 */
6 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
7 pm_options_shebang_callback_setcxx . . $ pm_options_shebang_callback_set(29b05883d7c7b904).(pm_options_tcxx . . $ pm_options_t# *options, pm_options_shebang_callback_tcxx . . $ pm_options_shebang_callback_t# shebang_callback, void *shebang_callback_data) {
8 options->shebang_callbackcxx . . $ pm_options#shebang_callback. = shebang_callback;
9 options->shebang_callback_datacxx . . $ pm_options#shebang_callback_data. = shebang_callback_data;
10 }
11
12 /**
13 * Set the filepath option on the given options struct.
14 */
15 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
16 pm_options_filepath_setcxx . . $ pm_options_filepath_set(239867bec45910cb).(pm_options_tcxx . . $ pm_options_t# *options, const char *filepath) {
17 pm_string_constant_initcxx . . $ pm_string_constant_init(501226d9fb5d86b1).(&options->filepathcxx . . $ pm_options#filepath., filepath, strlencxx . . $ strlen(751346f8406fd082).(filepath));
18 }
19
20 /**
21 * Set the encoding option on the given options struct.
22 */
23 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
24 pm_options_encoding_setcxx . . $ pm_options_encoding_set(239867bec45910cb).(pm_options_tcxx . . $ pm_options_t# *options, const char *encoding) {
25 pm_string_constant_initcxx . . $ pm_string_constant_init(501226d9fb5d86b1).(&options->encodingcxx . . $ pm_options#encoding., encoding, strlencxx . . $ strlen(751346f8406fd082).(encoding));
26 }
27
28 /**
29 * Set the encoding_locked option on the given options struct.
30 */
31 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
32 pm_options_encoding_locked_setcxx . . $ pm_options_encoding_locked_set(7c61585248544a2b).(pm_options_tcxx . . $ pm_options_t# *options, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! encoding_locked) {
33 options->encoding_lockedcxx . . $ pm_options#encoding_locked. = encoding_locked;
34 }
35
36 /**
37 * Set the line option on the given options struct.
38 */
39 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
40 pm_options_line_setcxx . . $ pm_options_line_set(d970da66061709f4).(pm_options_tcxx . . $ pm_options_t# *options, int32_tcxx . . $ int32_t# line) {
41 options->linecxx . . $ pm_options#line. = line;
42 }
43
44 /**
45 * Set the frozen string literal option on the given options struct.
46 */
47 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
48 pm_options_frozen_string_literal_setcxx . . $ pm_options_frozen_string_literal_set(7c61585248544a2b).(pm_options_tcxx . . $ pm_options_t# *options, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! frozen_string_literal) {
49 options->frozen_string_literalcxx . . $ pm_options#frozen_string_literal. = frozen_string_literal ? PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLEDcxx . . $ `include/prism/options.h:31:9`! : PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLEDcxx . . $ `include/prism/options.h:20:9`!;
50 }
51
52 /**
53 * Sets the command line option on the given options struct.
54 */
55 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
56 pm_options_command_line_setcxx . . $ pm_options_command_line_set(6b7d1e3f7ba772f0).(pm_options_tcxx . . $ pm_options_t# *options, uint8_tcxx . . $ uint8_t# command_line) {
57 options->command_linecxx . . $ pm_options#command_line. = command_line;
58 }
59
60 /**
61 * Checks if the given slice represents a number.
62 */
63 static inline boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
64 is_numbercxx . . $ is_number(4be6f7de8d2c8d82).(const char *string, size_t length) {
65 return pm_strspn_decimal_digitcxx . . $ pm_strspn_decimal_digit(dc9dc2cf7fc514b1).((const uint8_tcxx . . $ 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_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
74 pm_options_version_setcxx . . $ pm_options_version_set(c11dea70fd9c60a4).(pm_options_tcxx . . $ pm_options_t# *options, const char *version, size_t length) {
75 if (version == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
76 options->versioncxx . . $ pm_options#version. = PM_OPTIONS_VERSION_LATESTcxx . . $ PM_OPTIONS_VERSION_LATEST.;
77 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
78 }
79
80 if (length == 3) {
81 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(version, "3.3", 3) == 0) {
82 options->versioncxx . . $ pm_options#version. = PM_OPTIONS_VERSION_CRUBY_3_3cxx . . $ PM_OPTIONS_VERSION_CRUBY_3_3.;
83 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
84 }
85
86 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(version, "3.4", 3) == 0) {
87 options->versioncxx . . $ pm_options#version. = PM_OPTIONS_VERSION_CRUBY_3_4cxx . . $ PM_OPTIONS_VERSION_CRUBY_3_4.;
88 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
89 }
90
91 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(version, "3.5", 3) == 0 || strncmpcxx . . $ strncmp(fd278af2f295fa2e).(version, "4.0", 3) == 0) {
92 options->versioncxx . . $ pm_options#version. = PM_OPTIONS_VERSION_CRUBY_4_0cxx . . $ PM_OPTIONS_VERSION_CRUBY_4_0.;
93 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
94 }
95
96 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(version, "4.1", 3) == 0) {
97 options->versioncxx . . $ pm_options#version. = PM_OPTIONS_VERSION_CRUBY_4_1cxx . . $ PM_OPTIONS_VERSION_CRUBY_4_1.;
98 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
99 }
100
101 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
102 }
103
104 if (length >= 4 && is_numbercxx . . $ is_number(4be6f7de8d2c8d82).(version + 4, length - 4)) {
105 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(version, "3.3.", 4) == 0) {
106 options->versioncxx . . $ pm_options#version. = PM_OPTIONS_VERSION_CRUBY_3_3cxx . . $ PM_OPTIONS_VERSION_CRUBY_3_3.;
107 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
108 }
109
110 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(version, "3.4.", 4) == 0) {
111 options->versioncxx . . $ pm_options#version. = PM_OPTIONS_VERSION_CRUBY_3_4cxx . . $ PM_OPTIONS_VERSION_CRUBY_3_4.;
112 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
113 }
114
115 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(version, "3.5.", 4) == 0 || strncmpcxx . . $ strncmp(fd278af2f295fa2e).(version, "4.0.", 4) == 0) {
116 options->versioncxx . . $ pm_options#version. = PM_OPTIONS_VERSION_CRUBY_4_0cxx . . $ PM_OPTIONS_VERSION_CRUBY_4_0.;
117 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
118 }
119
120 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(version, "4.1.", 4) == 0) {
121 options->versioncxx . . $ pm_options#version. = PM_OPTIONS_VERSION_CRUBY_4_1cxx . . $ PM_OPTIONS_VERSION_CRUBY_4_1.;
122 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
123 }
124 }
125
126 if (length >= 6) {
127 if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(version, "latest", 7) == 0) { // 7 to compare the \0 as well
128 options->versioncxx . . $ pm_options#version. = PM_OPTIONS_VERSION_LATESTcxx . . $ PM_OPTIONS_VERSION_LATEST.;
129 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
130 }
131 }
132
133 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
134 }
135
136 /**
137 * Set the main script option on the given options struct.
138 */
139 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
140 pm_options_main_script_setcxx . . $ pm_options_main_script_set(7c61585248544a2b).(pm_options_tcxx . . $ pm_options_t# *options, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! main_script) {
141 options->main_scriptcxx . . $ pm_options#main_script. = main_script;
142 }
143
144 /**
145 * Set the partial script option on the given options struct.
146 */
147 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
148 pm_options_partial_script_setcxx . . $ pm_options_partial_script_set(7c61585248544a2b).(pm_options_tcxx . . $ pm_options_t# *options, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! partial_script) {
149 options->partial_scriptcxx . . $ pm_options#partial_script. = partial_script;
150 }
151
152 /**
153 * Set the freeze option on the given options struct.
154 */
155 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
156 pm_options_freeze_setcxx . . $ pm_options_freeze_set(7c61585248544a2b).(pm_options_tcxx . . $ pm_options_t# *options, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! freeze) {
157 options->freezecxx . . $ pm_options#freeze. = freeze;
158 }
159
160 // For some reason, GCC analyzer thinks we're leaking allocated scopes and
161 // locals here, even though we definitely aren't. This is a false positive.
162 // Ideally we wouldn't need to suppress this.
163 #if defined(__GNUC__cxx . . $ `<built-in>:8:9`!) && (__GNUC__cxx . . $ `<built-in>:8:9`! >= 10)
164 #pragma GCC diagnostic push
165 #pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
166 #endif
167
168 /**
169 * Allocate and zero out the scopes array on the given options struct.
170 */
171 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
172 pm_options_scopes_initcxx . . $ pm_options_scopes_init(5ee016fc4c856b83).(pm_options_tcxx . . $ pm_options_t# *options, size_t scopes_count) {
173 options->scopes_countcxx . . $ pm_options#scopes_count. = scopes_count;
174 options->scopescxx . . $ pm_options#scopes. = xcalloccxx . . $ `include/prism/defines.h:195:17`!(scopes_count, sizeof(pm_options_scope_tcxx . . $ pm_options_scope_t#));
175 return options->scopescxx . . $ pm_options#scopes. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
176 }
177
178 /**
179 * Return a pointer to the scope at the given index within the given options.
180 */
181 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! const pm_options_scope_tcxx . . $ pm_options_scope_t# *
182 pm_options_scope_getcxx . . $ pm_options_scope_get(e9b4524d8891f222).(const pm_options_tcxx . . $ pm_options_t# *options, size_t index) {
183 return &options->scopescxx . . $ pm_options#scopes.[index];
184 }
185
186 /**
187 * Create a new options scope struct. This will hold a set of locals that are in
188 * scope surrounding the code that is being parsed.
189 */
190 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
191 pm_options_scope_initcxx . . $ pm_options_scope_init(2b6f67558e0f78e1).(pm_options_scope_tcxx . . $ pm_options_scope_t# *scope, size_t locals_count) {
192 scope->locals_countcxx . . $ pm_options_scope#locals_count. = locals_count;
193 scope->localscxx . . $ pm_options_scope#locals. = xcalloccxx . . $ `include/prism/defines.h:195:17`!(locals_count, sizeof(pm_string_tcxx . . $ pm_string_t#));
194 scope->forwardingcxx . . $ pm_options_scope#forwarding. = PM_OPTIONS_SCOPE_FORWARDING_NONEcxx . . $ PM_OPTIONS_SCOPE_FORWARDING_NONE.;
195 return scope->localscxx . . $ pm_options_scope#locals. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
196 }
197
198 /**
199 * Return a pointer to the local at the given index within the given scope.
200 */
201 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! const pm_string_tcxx . . $ pm_string_t# *
202 pm_options_scope_local_getcxx . . $ pm_options_scope_local_get(93ddb7b63e20f64a).(const pm_options_scope_tcxx . . $ pm_options_scope_t# *scope, size_t index) {
203 return &scope->localscxx . . $ pm_options_scope#locals.[index];
204 }
205
206 /**
207 * Set the forwarding option on the given scope struct.
208 */
209 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
210 pm_options_scope_forwarding_setcxx . . $ pm_options_scope_forwarding_set(5663f940b86bb34d).(pm_options_scope_tcxx . . $ pm_options_scope_t# *scope, uint8_tcxx . . $ uint8_t# forwarding) {
211 scope->forwardingcxx . . $ pm_options_scope#forwarding. = forwarding;
212 }
213
214 /**
215 * Free the internal memory associated with the options.
216 */
217 PRISM_EXPORTED_FUNCTIONcxx . . $ `include/prism/defines.h:50:19`! void
218 pm_options_freecxx . . $ pm_options_free(e46c1f23b4b55852).(pm_options_tcxx . . $ pm_options_t# *options) {
219 pm_string_freecxx . . $ pm_string_free(c15d128c68b0cb72).(&options->filepathcxx . . $ pm_options#filepath.);
220 pm_string_freecxx . . $ pm_string_free(c15d128c68b0cb72).(&options->encodingcxx . . $ pm_options#encoding.);
221
222 for (size_t scope_index = 0; scope_index < options->scopes_countcxx . . $ pm_options#scopes_count.; scope_index++) {
223 pm_options_scope_tcxx . . $ pm_options_scope_t# *scope = &options->scopescxx . . $ pm_options#scopes.[scope_index];
224
225 for (size_t local_index = 0; local_index < scope->locals_countcxx . . $ pm_options_scope#locals_count.; local_index++) {
226 pm_string_freecxx . . $ pm_string_free(c15d128c68b0cb72).(&scope->localscxx . . $ pm_options_scope#locals.[local_index]);
227 }
228
229 xfreecxx . . $ `include/prism/defines.h:203:17`!(scope->localscxx . . $ pm_options_scope#locals.);
230 }
231
232 xfreecxx . . $ `include/prism/defines.h:203:17`!(options->scopescxx . . $ pm_options#scopes.);
233 }
234
235 /**
236 * Read a 32-bit unsigned integer from a pointer. This function is used to read
237 * the options that are passed into the parser from the Ruby implementation. It
238 * handles aligned and unaligned reads.
239 */
240 static uint32_tcxx . . $ uint32_t#
241 pm_options_read_u32cxx . . $ pm_options_read_u32(c61c63047ce273de).(const char *data) {
242 if (((uintptr_tcxx . . $ uintptr_t#) data) % sizeof(uint32_tcxx . . $ uint32_t#) == 0) {
243 return *((uint32_tcxx . . $ uint32_t# *) data);
244 } else {
245 uint32_tcxx . . $ uint32_t# value;
246 memcpycxx . . $ memcpy(cc817cb175f282d).(&value, data, sizeof(uint32_tcxx . . $ uint32_t#));
247 return value;
248 }
249 }
250
251 /**
252 * Read a 32-bit signed integer from a pointer. This function is used to read
253 * the options that are passed into the parser from the Ruby implementation. It
254 * handles aligned and unaligned reads.
255 */
256 static int32_tcxx . . $ int32_t#
257 pm_options_read_s32cxx . . $ pm_options_read_s32(5c4306d8553b3696).(const char *data) {
258 if (((uintptr_tcxx . . $ uintptr_t#) data) % sizeof(int32_tcxx . . $ int32_t#) == 0) {
259 return *((int32_tcxx . . $ int32_t# *) data);
260 } else {
261 int32_tcxx . . $ int32_t# value;
262 memcpycxx . . $ memcpy(cc817cb175f282d).(&value, data, sizeof(int32_tcxx . . $ int32_t#));
263 return value;
264 }
265 }
266
267 /**
268 * Deserialize an options struct from the given binary string. This is used to
269 * pass options to the parser from an FFI call so that consumers of the library
270 * from an FFI perspective don't have to worry about the structure of our
271 * options structs. Since the source of these calls will be from Ruby
272 * implementation internals we assume it is from a trusted source.
273 */
274 void
275 pm_options_readcxx . . $ pm_options_read(239867bec45910cb).(pm_options_tcxx . . $ pm_options_t# *options, const char *data) {
276 options->linecxx . . $ pm_options#line. = 1; // default
277 if (data == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return;
278
279 uint32_tcxx . . $ uint32_t# filepath_length = pm_options_read_u32cxx . . $ pm_options_read_u32(c61c63047ce273de).(data);
280 data += 4;
281
282 if (filepath_length > 0) {
283 pm_string_constant_initcxx . . $ pm_string_constant_init(501226d9fb5d86b1).(&options->filepathcxx . . $ pm_options#filepath., data, filepath_length);
284 data += filepath_length;
285 }
286
287 options->linecxx . . $ pm_options#line. = pm_options_read_s32cxx . . $ pm_options_read_s32(5c4306d8553b3696).(data);
288 data += 4;
289
290 uint32_tcxx . . $ uint32_t# encoding_length = pm_options_read_u32cxx . . $ pm_options_read_u32(c61c63047ce273de).(data);
291 data += 4;
292
293 if (encoding_length > 0) {
294 pm_string_constant_initcxx . . $ pm_string_constant_init(501226d9fb5d86b1).(&options->encodingcxx . . $ pm_options#encoding., data, encoding_length);
295 data += encoding_length;
296 }
297
298 options->frozen_string_literalcxx . . $ pm_options#frozen_string_literal. = (int8_tcxx . . $ int8_t#) *data++;
299 options->command_linecxx . . $ pm_options#command_line. = (uint8_tcxx . . $ uint8_t#) *data++;
300 options->versioncxx . . $ pm_options#version. = (pm_options_version_tcxx . . $ pm_options_version_t#) *data++;
301 options->encoding_lockedcxx . . $ pm_options#encoding_locked. = ((uint8_tcxx . . $ uint8_t#) *data++) > 0;
302 options->main_scriptcxx . . $ pm_options#main_script. = ((uint8_tcxx . . $ uint8_t#) *data++) > 0;
303 options->partial_scriptcxx . . $ pm_options#partial_script. = ((uint8_tcxx . . $ uint8_t#) *data++) > 0;
304 options->freezecxx . . $ pm_options#freeze. = ((uint8_tcxx . . $ uint8_t#) *data++) > 0;
305
306 uint32_tcxx . . $ uint32_t# scopes_count = pm_options_read_u32cxx . . $ pm_options_read_u32(c61c63047ce273de).(data);
307 data += 4;
308
309 if (scopes_count > 0) {
310 if (!pm_options_scopes_initcxx . . $ pm_options_scopes_init(5ee016fc4c856b83).(options, scopes_count)) return;
311
312 for (size_t scope_index = 0; scope_index < scopes_count; scope_index++) {
313 uint32_tcxx . . $ uint32_t# locals_count = pm_options_read_u32cxx . . $ pm_options_read_u32(c61c63047ce273de).(data);
314 data += 4;
315
316 pm_options_scope_tcxx . . $ pm_options_scope_t# *scope = &options->scopescxx . . $ pm_options#scopes.[scope_index];
317 if (!pm_options_scope_initcxx . . $ pm_options_scope_init(2b6f67558e0f78e1).(scope, locals_count)) {
318 pm_options_freecxx . . $ pm_options_free(e46c1f23b4b55852).(options);
319 return;
320 }
321
322 uint8_tcxx . . $ uint8_t# forwarding = (uint8_tcxx . . $ uint8_t#) *data++;
323 pm_options_scope_forwarding_setcxx . . $ pm_options_scope_forwarding_set(5663f940b86bb34d).(&options->scopescxx . . $ pm_options#scopes.[scope_index], forwarding);
324
325 for (size_t local_index = 0; local_index < locals_count; local_index++) {
326 uint32_tcxx . . $ uint32_t# local_length = pm_options_read_u32cxx . . $ pm_options_read_u32(c61c63047ce273de).(data);
327 data += 4;
328
329 pm_string_constant_initcxx . . $ pm_string_constant_init(501226d9fb5d86b1).(&scope->localscxx . . $ pm_options_scope#locals.[local_index], data, local_length);
330 data += local_length;
331 }
332 }
333 }
334 }
335
336 #if defined(__GNUC__cxx . . $ `<built-in>:8:9`!) && (__GNUC__cxx . . $ `<built-in>:8:9`! >= 10)
337 #pragma GCC diagnostic pop
338 #endif