Ruby: prism/options.h Source File

Ruby 3.3.7p123 (2025-01-15 revision be31f993d7fa0219d85f7b3c694d454da4ecc10b)

options.h
Go to the documentation of this file.
1
6#ifndef PRISM_OPTIONS_H
7#define PRISM_OPTIONS_H
8
9#include "prism/defines.h"
10#include "prism/util/pm_string.h"
11
12#include <stdbool.h>
13#include <stddef.h>
14#include <stdint.h>
15
19 typedef struct pm_options_scope {
21 size_t locals_count;
22
24 pm_string_t *locals;
25} pm_options_scope_t;
26
30 typedef struct {
32 pm_string_t filepath;
33
38 int32_t line;
39
44 pm_string_t encoding;
45
49 size_t scopes_count;
50
56 pm_options_scope_t *scopes;
57
59 bool frozen_string_literal;
60
66 bool suppress_warnings;
67} pm_options_t;
68
75 PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath);
76
83 PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line);
84
91 PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding);
92
99 PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal);
100
107 PRISM_EXPORTED_FUNCTION void pm_options_suppress_warnings_set(pm_options_t *options, bool suppress_warnings);
108
115 PRISM_EXPORTED_FUNCTION void pm_options_scopes_init(pm_options_t *options, size_t scopes_count);
116
124 PRISM_EXPORTED_FUNCTION const pm_options_scope_t * pm_options_scope_get(const pm_options_t *options, size_t index);
125
133 PRISM_EXPORTED_FUNCTION void pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count);
134
142 PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local_get(const pm_options_scope_t *scope, size_t index);
143
149 PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options);
150
202void pm_options_read(pm_options_t *options, const char *data);
203
204#endif
pm_options_encoding_set
PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding)
Set the encoding option on the given options struct.
Definition options.c:15
pm_options_free
PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options)
Free the internal memory associated with the options.
Definition options.c:84
pm_options_scope_t
struct pm_options_scope pm_options_scope_t
A scope of locals surrounding the code that is being parsed.
pm_options_scope_local_get
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.
Definition options.c:76
pm_options_read
void pm_options_read(pm_options_t *options, const char *data)
Deserialize an options struct from the given binary string.
Definition options.c:141
pm_options_scopes_init
PRISM_EXPORTED_FUNCTION void pm_options_scopes_init(pm_options_t *options, size_t scopes_count)
Allocate and zero out the scopes array on the given options struct.
Definition options.c:47
pm_options_suppress_warnings_set
PRISM_EXPORTED_FUNCTION void pm_options_suppress_warnings_set(pm_options_t *options, bool suppress_warnings)
Set the suppress warnings option on the given options struct.
Definition options.c:39
pm_options_line_set
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line)
Set the line option on the given options struct.
Definition options.c:23
pm_options_scope_get
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.
Definition options.c:57
pm_options_frozen_string_literal_set
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.
Definition options.c:31
pm_options_filepath_set
PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath)
Set the filepath option on the given options struct.
Definition options.c:7
pm_options_scope_init
PRISM_EXPORTED_FUNCTION void pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count)
Create a new options scope struct.
Definition options.c:66
pm_string.h
A generic string type that can have various ownership semantics.
defines.h
Macro definitions used throughout the prism library.
PRISM_EXPORTED_FUNCTION
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition defines.h:32
stdbool.h
C99 shim for <stdbool.h>
pm_options_scope
A scope of locals surrounding the code that is being parsed.
Definition options.h:19
pm_options_scope::locals_count
size_t locals_count
The number of locals in the scope.
Definition options.h:21
pm_options_scope::locals
pm_string_t * locals
The names of the locals in the scope.
Definition options.h:24
pm_options_t
The options that can be passed to the parser.
Definition options.h:30
pm_options_t::scopes
pm_options_scope_t * scopes
The scopes surrounding the code that is being parsed.
Definition options.h:56
pm_options_t::scopes_count
size_t scopes_count
The number of scopes surrounding the code that is being parsed.
Definition options.h:49
pm_options_t::suppress_warnings
bool suppress_warnings
Whether or not we should suppress warnings.
Definition options.h:66
pm_options_t::encoding
pm_string_t encoding
The name of the encoding that the source file is in.
Definition options.h:44
pm_options_t::frozen_string_literal
bool frozen_string_literal
Whether or not the frozen string literal option has been set.
Definition options.h:59
pm_options_t::line
int32_t line
The line within the file that the parse starts on.
Definition options.h:38
pm_options_t::filepath
pm_string_t filepath
The name of the file that is currently being parsed.
Definition options.h:32
pm_string_t
A generic string type that can have various ownership semantics.
Definition pm_string.h:30