64 is_number(
const char *
string,
size_t length) {
75 if (version == NULL) {
81 if (strncmp(version,
"3.3", 3) == 0) {
86 if (strncmp(version,
"3.4", 3) == 0) {
95 if (strncmp(version,
"3.3.", 4) == 0 && is_number(version + 4, length - 4)) {
100 if (strncmp(version,
"3.4.", 4) == 0 && is_number(version + 4, length - 4)) {
107 if (strncmp(version,
"latest", 7) == 0) {
135 #if defined(__GNUC__) && (__GNUC__ >= 10)
136 #pragma GCC diagnostic push
137 #pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
147 return options->
scopes != NULL;
155 return &options->
scopes[index];
166 return scope->
locals != NULL;
174 return &scope->
locals[index];
185 for (
size_t scope_index = 0; scope_index < options->
scopes_count; scope_index++) {
188 for (
size_t local_index = 0; local_index < scope->
locals_count; local_index++) {
204 pm_options_read_u32(
const char *data) {
205 if (((uintptr_t) data) %
sizeof(uint32_t) == 0) {
206 return *((uint32_t *) data);
209 memcpy(&value, data,
sizeof(uint32_t));
220 pm_options_read_s32(
const char *data) {
221 if (((uintptr_t) data) %
sizeof(int32_t) == 0) {
222 return *((int32_t *) data);
225 memcpy(&value, data,
sizeof(int32_t));
240 if (data == NULL)
return;
242 uint32_t filepath_length = pm_options_read_u32(data);
245 if (filepath_length > 0) {
247 data += filepath_length;
250 options->
line = pm_options_read_s32(data);
253 uint32_t encoding_length = pm_options_read_u32(data);
256 if (encoding_length > 0) {
258 data += encoding_length;
268 uint32_t scopes_count = pm_options_read_u32(data);
271 if (scopes_count > 0) {
274 for (
size_t scope_index = 0; scope_index < scopes_count; scope_index++) {
275 uint32_t locals_count = pm_options_read_u32(data);
284 for (
size_t local_index = 0; local_index < locals_count; local_index++) {
285 uint32_t local_length = pm_options_read_u32(data);
289 data += local_length;
295 #if defined(__GNUC__) && (__GNUC__ >= 10)
296 #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.
PRISM_EXPORTED_FUNCTION void pm_options_shebang_callback_set(pm_options_t *options, pm_options_shebang_callback_t shebang_callback, void *shebang_callback_data)
Set the shebang callback option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding)
Set the encoding option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options)
Free the internal memory associated with the options.
PRISM_EXPORTED_FUNCTION void pm_options_partial_script_set(pm_options_t *options, bool partial_script)
Set the partial script option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_main_script_set(pm_options_t *options, bool main_script)
Set the main script option on the given options struct.
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...
void pm_options_read(pm_options_t *options, const char *data)
Deserialize an options struct from the given binary string.
PRISM_EXPORTED_FUNCTION bool pm_options_version_set(pm_options_t *options, const char *version, size_t length)
Set the version option on the given options struct by parsing the given string.
PRISM_EXPORTED_FUNCTION bool pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count)
Create a new options scope struct.
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line)
Set the line option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked)
Set the encoding_locked option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal)
Set the frozen string literal option on the given options struct.
#define PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED
String literals should be made frozen.
PRISM_EXPORTED_FUNCTION const pm_options_scope_t * pm_options_scope_get(const pm_options_t *options, size_t index)
Return a pointer to the scope at the given index within the given options.
#define PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED
String literals should be made mutable.
PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local_get(const pm_options_scope_t *scope, size_t index)
Return a pointer to the local at the given index within the given scope.
PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options, uint8_t command_line)
Sets the command line option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath)
Set the filepath option on the given options struct.
PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_t scopes_count)
Allocate and zero out the scopes array on the given options struct.
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.
size_t pm_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length)
Returns the number of characters at the start of the string that are decimal digits.
void pm_string_constant_init(pm_string_t *string, const char *source, size_t length)
Initialize a constant string that doesn't own its memory source.
PRISM_EXPORTED_FUNCTION void pm_string_free(pm_string_t *string)
Free the associated memory of the given string.
#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.
pm_string_t * locals
The names of the locals in the scope.
The options that can be passed to the parser.
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.