16pm_options_filepath_set(
pm_options_t *options,
const char *filepath) {
17 pm_string_constant_init(&options->
filepath, filepath, strlen(filepath));
24pm_options_encoding_set(
pm_options_t *options,
const char *encoding) {
25 pm_string_constant_init(&options->
encoding, encoding, strlen(encoding));
32pm_options_encoding_locked_set(
pm_options_t *options,
bool encoding_locked) {
48pm_options_frozen_string_literal_set(
pm_options_t *options,
bool frozen_string_literal) {
56pm_options_command_line_set(
pm_options_t *options, uint8_t command_line) {
64is_number(
const char *
string,
size_t length) {
65 return pm_strspn_decimal_digit((
const uint8_t *)
string, (ptrdiff_t) length) == length;
74pm_options_version_set(
pm_options_t *options,
const char *version,
size_t length) {
75 if (version == NULL) {
81 if (strncmp(version,
"3.3", 3) == 0) {
86 if (strncmp(version,
"3.4", 3) == 0) {
91 if (strncmp(version,
"3.5", 3) == 0) {
100 if (strncmp(version,
"3.3.", 4) == 0 && is_number(version + 4, length - 4)) {
105 if (strncmp(version,
"3.4.", 4) == 0 && is_number(version + 4, length - 4)) {
110 if (strncmp(version,
"3.5.", 4) == 0 && is_number(version + 4, length - 4)) {
117 if (strncmp(version,
"latest", 7) == 0) {
138pm_options_partial_script_set(
pm_options_t *options,
bool partial_script) {
153#if defined(__GNUC__) && (__GNUC__ >= 10)
154#pragma GCC diagnostic push
155#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
165 return options->
scopes != NULL;
173 return &options->
scopes[index];
185 return scope->
locals != NULL;
193 return &scope->
locals[index];
212 for (
size_t scope_index = 0; scope_index < options->
scopes_count; scope_index++) {
215 for (
size_t local_index = 0; local_index < scope->
locals_count; local_index++) {
216 pm_string_free(&scope->
locals[local_index]);
231pm_options_read_u32(
const char *data) {
232 if (((uintptr_t) data) %
sizeof(uint32_t) == 0) {
233 return *((uint32_t *) data);
236 memcpy(&value, data,
sizeof(uint32_t));
247pm_options_read_s32(
const char *data) {
248 if (((uintptr_t) data) %
sizeof(int32_t) == 0) {
249 return *((int32_t *) data);
252 memcpy(&value, data,
sizeof(int32_t));
267 if (data == NULL)
return;
269 uint32_t filepath_length = pm_options_read_u32(data);
272 if (filepath_length > 0) {
273 pm_string_constant_init(&options->
filepath, data, filepath_length);
274 data += filepath_length;
277 options->
line = pm_options_read_s32(data);
280 uint32_t encoding_length = pm_options_read_u32(data);
283 if (encoding_length > 0) {
284 pm_string_constant_init(&options->
encoding, data, encoding_length);
285 data += encoding_length;
294 options->
freeze = ((uint8_t) *data++) > 0;
296 uint32_t scopes_count = pm_options_read_u32(data);
299 if (scopes_count > 0) {
300 if (!pm_options_scopes_init(options, scopes_count))
return;
302 for (
size_t scope_index = 0; scope_index < scopes_count; scope_index++) {
303 uint32_t locals_count = pm_options_read_u32(data);
307 if (!pm_options_scope_init(scope, locals_count)) {
308 pm_options_free(options);
312 uint8_t forwarding = (uint8_t) *data++;
313 pm_options_scope_forwarding_set(&options->
scopes[scope_index], forwarding);
315 for (
size_t local_index = 0; local_index < locals_count; local_index++) {
316 uint32_t local_length = pm_options_read_u32(data);
319 pm_string_constant_init(&scope->
locals[local_index], data, local_length);
320 data += local_length;
326#if defined(__GNUC__) && (__GNUC__ >= 10)
327#pragma GCC diagnostic pop
#define xfree
Old name of ruby_xfree.
#define xcalloc
Old name of ruby_xcalloc.
The options that can be passed to parsing.
void(* pm_options_shebang_callback_t)(struct pm_options *options, const uint8_t *source, size_t length, void *shebang_callback_data)
The callback called when additional switches are found in a shebang comment that need to be processed...
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_NONE
The default value for parameters.
#define PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED
String literals should be made frozen.
#define PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED
String literals should be made mutable.
pm_options_version_t
The version of Ruby syntax that we should be parsing with.
@ PM_OPTIONS_VERSION_CRUBY_3_3
The vendored version of prism in CRuby 3.3.x.
@ PM_OPTIONS_VERSION_LATEST
The current version of prism.
@ PM_OPTIONS_VERSION_CRUBY_3_4
The vendored version of prism in CRuby 3.4.x.
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
A scope of locals surrounding the code that is being parsed.
size_t locals_count
The number of locals in the scope.
uint8_t forwarding
Flags for the set of forwarding parameters in this scope.
pm_string_t * locals
The names of the locals in the scope.
The options that can be passed to the parser.
bool freeze
Whether or not the parser should freeze the nodes that it creates.
uint8_t command_line
A bitset of the various options that were set on the command line.
void * shebang_callback_data
Any additional data that should be passed along to the shebang callback if one was set.
bool encoding_locked
Whether or not the encoding magic comments should be respected.
pm_options_scope_t * scopes
The scopes surrounding the code that is being parsed.
bool main_script
When the file being parsed is the main script, the shebang will be considered for command-line flags ...
pm_string_t encoding
The name of the encoding that the source file is in.
int32_t line
The line within the file that the parse starts on.
pm_options_shebang_callback_t shebang_callback
The callback to call when additional switches are found in a shebang comment.
int8_t frozen_string_literal
Whether or not the frozen string literal option has been set.
bool partial_script
When the file being parsed is considered a "partial" script, jumps will not be marked as errors if th...
size_t scopes_count
The number of scopes surrounding the code that is being parsed.
pm_string_t filepath
The name of the file that is currently being parsed.
pm_options_version_t version
The version of prism that we should be parsing with.
A generic string type that can have various ownership semantics.