Ruby: universal_parser.c Source File

Ruby 3.3.4p94 (2024-07-09 revision be1089c8ec5ba40e09b1553e36b3174bf4014d9d)

universal_parser.c
1#include <alloca.h>
2#include <string.h>
3#include <stdarg.h>
4#include <stdbool.h>
5#include <stddef.h>
6
7/* Dependency */
8#include "internal/parse.h"
9#include "node.h"
10#include "id.h"
11
12#include "internal/compilers.h"
13#include "ruby/backward/2/inttypes.h"
14#include "probes.h"
15
16#define LIKELY(x) RB_LIKELY(x)
17#define UNLIKELY(x) RB_UNLIKELY(x)
18#ifndef TRUE
19# define TRUE 1
20#endif
21
22#ifndef FALSE
23# define FALSE 0
24#endif
25#define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
26#define rb_strlen_lit(str) (sizeof(str "") - 1)
27#undef FIXNUM_MAX
28#define FIXNUM_MAX (LONG_MAX / 2)
29#undef RSTRING_GETMEM
30#define RSTRING_GETMEM(str, ptrvar, lenvar) \
31 ((ptrvar) = RSTRING_PTR(str), \
32 (lenvar) = RSTRING_LEN(str))
33#if defined(USE_FLONUM)
34# /* Take that. */
35#elif SIZEOF_VALUE >= SIZEOF_DOUBLE
36# define USE_FLONUM 1
37#else
38# define USE_FLONUM 0
39#endif
40
41/* parser_st */
42#define st_table parser_st_table
43#define st_data_t parser_st_data_t
44#define st_hash_type parser_st_hash_type
45#define ST_CONTINUE ST2_CONTINUE
46#define ST_STOP ST2_STOP
47#define ST_DELETE ST2_DELETE
48#define ST_CHECK ST2_CHECK
49#define ST_REPLACE ST2_REPLACE
50#undef st_init_numtable
51#define st_init_numtable rb_parser_st_init_numtable
52#undef st_free_table
53#define st_free_table rb_parser_st_free_table
54#undef st_init_table_with_size
55#define st_init_table_with_size rb_parser_st_init_table_with_size
56#undef st_insert
57#define st_insert rb_parser_st_insert
58#undef st_foreach
59#define st_foreach rb_parser_st_foreach
60#undef st_delete
61#define st_delete rb_parser_st_delete
62#undef st_is_member
63#define st_is_member parser_st_is_member
64
65#define rb_encoding void
66
67#undef T_FLOAT
68#define T_FLOAT 0x04
69#undef T_REGEXP
70#define T_REGEXP 0x06
71#undef T_HASH
72#define T_HASH 0x08
73#undef T_BIGNUM
74#define T_BIGNUM 0x0a
75#undef T_COMPLEX
76#define T_COMPLEX 0x0e
77#undef T_RATIONAL
78#define T_RATIONAL 0x0f
79
80#ifndef INTERNAL_IMEMO_H
81struct rb_imemo_tmpbuf_struct {
82 VALUE flags;
83 VALUE reserved;
84 VALUE *ptr; /* malloc'ed buffer */
85 struct rb_imemo_tmpbuf_struct *next; /* next imemo */
86 size_t cnt; /* buffer size in VALUE */
87};
88#endif
89
90#undef xmalloc
91#define xmalloc p->config->malloc
92#undef xcalloc
93#define xcalloc p->config->calloc
94#undef xrealloc
95#define xrealloc p->config->realloc
96#undef ALLOC_N
97#define ALLOC_N(type,n) ((type *)p->config->alloc_n((n), sizeof(type)))
98#undef ALLOC
99#define ALLOC(type) ((type *)p->config->alloc(sizeof(type)))
100#undef xfree
101#define xfree p->config->free
102#undef ALLOCA_N
103// alloca(rbimpl_size_mul_or_raise(x, y));
104#define ALLOCA_N(type,n) ((type *)alloca(sizeof(type) * (n)))
105#undef REALLOC_N
106#define REALLOC_N(var,type,n) ((var) = (type *)p->config->realloc_n((void *)var, n, sizeof(type)))
107#undef ZALLOC
108#define ZALLOC(type) ((type *)p->config->zalloc(sizeof(type)))
109#undef MEMMOVE
110#define MEMMOVE(p1,p2,type,n) (p->config->rb_memmove((p1), (p2), sizeof(type), (n)))
111#undef MEMCPY
112#define MEMCPY(p1,p2,type,n) (p->config->nonempty_memcpy((p1), (p2), sizeof(type), (n)))
113
114#define rb_imemo_tmpbuf_parser_heap p->config->tmpbuf_parser_heap
115
116#define compile_callback p->config->compile_callback
117#define reg_named_capture_assign p->config->reg_named_capture_assign
118#define script_lines_defined p->config->script_lines_defined
119#define script_lines_get p->config->script_lines_get
120
121#define rb_obj_freeze p->config->obj_freeze
122#define rb_obj_hide p->config->obj_hide
123#undef RB_OBJ_FROZEN
124#define RB_OBJ_FROZEN p->config->obj_frozen
125#undef RB_TYPE_P
126#define RB_TYPE_P p->config->type_p
127#undef OBJ_FREEZE_RAW
128#define OBJ_FREEZE_RAW p->config->obj_freeze_raw
129
130#undef FIXNUM_P
131#define FIXNUM_P p->config->fixnum_p
132#undef SYMBOL_P
133#define SYMBOL_P p->config->symbol_p
134
135#define rb_attr_get p->config->attr_get
136
137#define rb_ary_new p->config->ary_new
138#define rb_ary_push p->config->ary_push
139#undef rb_ary_new_from_args
140#define rb_ary_new_from_args p->config->ary_new_from_args
141#define rb_ary_pop p->config->ary_pop
142#define rb_ary_last p->config->ary_last
143#define rb_ary_unshift p->config->ary_unshift
144#undef rb_ary_new2
145#define rb_ary_new2 p->config->ary_new2
146#define rb_ary_entry p->config->ary_entry
147#define rb_ary_join p->config->ary_join
148#define rb_ary_reverse p->config->ary_reverse
149#define rb_ary_clear p->config->ary_clear
150#undef RARRAY_LEN
151#define RARRAY_LEN p->config->array_len
152#define RARRAY_AREF p->config->array_aref
153
154#undef rb_sym_intern_ascii_cstr
155#define rb_sym_intern_ascii_cstr p->config->sym_intern_ascii_cstr
156#define rb_make_temporary_id p->config->make_temporary_id
157#define is_local_id p->config->is_local_id
158#define is_attrset_id p->config->is_attrset_id
159#define is_global_name_punct p->config->is_global_name_punct
160#define id_type p->config->id_type
161#define rb_id_attrset p->config->id_attrset
162#undef rb_intern
163#define rb_intern p->config->intern
164#define rb_intern2 p->config->intern2
165#define rb_intern3 p->config->intern3
166#define rb_intern_str p->config->intern_str
167#define is_notop_id p->config->is_notop_id
168#define rb_enc_symname_type p->config->enc_symname_type
169#define rb_str_intern p->config->str_intern
170#define rb_id2name p->config->id2name
171#define rb_id2str p->config->id2str
172#define rb_id2sym p->config->id2sym
173#undef ID2SYM
174#define ID2SYM p->config->id2sym
175#undef SYM2ID
176#define SYM2ID p->config->sym2id
177
178#define rb_str_catf p->config->str_catf
179#undef rb_str_cat_cstr
180#define rb_str_cat_cstr p->config->str_cat_cstr
181#define rb_str_subseq p->config->str_subseq
182#define rb_str_dup p->config->str_dup
183#define rb_str_new_frozen p->config->str_new_frozen
184#define rb_str_buf_new p->config->str_buf_new
185#undef rb_str_buf_cat
186#define rb_str_buf_cat p->config->str_buf_cat
187#define rb_str_modify p->config->str_modify
188#define rb_str_set_len p->config->str_set_len
189#define rb_str_cat p->config->str_cat
190#define rb_str_resize p->config->str_resize
191#undef rb_str_new
192#define rb_str_new p->config->str_new
193#undef rb_str_new_cstr
194#define rb_str_new_cstr p->config->str_new_cstr
195#define rb_fstring p->config->fstring
196#define is_ascii_string p->config->is_ascii_string
197#define rb_enc_str_new p->config->enc_str_new
198#define rb_enc_str_buf_cat p->config->enc_str_buf_cat
199#define rb_str_buf_append p->config->str_buf_append
200#define rb_str_vcatf p->config->str_vcatf
201#undef StringValueCStr
202#define StringValueCStr(v) p->config->string_value_cstr(&(v))
203#define rb_sprintf p->config->rb_sprintf
204#undef RSTRING_PTR
205#define RSTRING_PTR p->config->rstring_ptr
206#undef RSTRING_END
207#define RSTRING_END p->config->rstring_end
208#undef RSTRING_LEN
209#define RSTRING_LEN p->config->rstring_len
210#define rb_filesystem_str_new_cstr p->config->filesystem_str_new_cstr
211#define rb_obj_as_string p->config->obj_as_string
212
213#define rb_hash_clear p->config->hash_clear
214#define rb_hash_new p->config->hash_new
215#define rb_hash_aset p->config->hash_aset
216#define rb_hash_lookup p->config->hash_lookup
217#define rb_ident_hash_new p->config->ident_hash_new
218
219#undef INT2FIX
220#define INT2FIX p->config->int2fix
221#undef LONG2FIX
222#define LONG2FIX p->config->int2fix
223
224#define bignum_negate p->config->bignum_negate
225#define rb_big_norm p->config->big_norm
226#define rb_cstr_to_inum p->config->cstr_to_inum
227
228#define rb_float_new p->config->float_new
229#undef RFLOAT_VALUE
230#define RFLOAT_VALUE p->config->float_value
231#undef DBL2NUM
232#define DBL2NUM p->config->float_new
233
234#undef NUM2INT
235#define NUM2INT p->config->num2int
236#define rb_int_positive_pow p->config->int_positive_pow
237#undef INT2NUM
238#define INT2NUM p->config->int2num
239#undef FIX2LONG
240#define FIX2LONG p->config->fix2long
241
242#define rb_rational_new p->config->rational_new
243#undef rb_rational_raw1
244#define rb_rational_raw1 p->config->rational_raw1
245#define rational_set_num p->config->rational_set_num
246#define rational_get_num p->config->rational_get_num
247
248#define rb_complex_raw p->config->complex_raw
249#define rcomplex_set_real p->config->rcomplex_set_real
250#define rcomplex_set_imag p->config->rcomplex_set_imag
251#define rcomplex_get_real p->config->rcomplex_get_real
252#define rcomplex_get_imag p->config->rcomplex_get_imag
253
254#define rb_stderr_tty_p p->config->stderr_tty_p
255#define rb_write_error_str p->config->write_error_str
256#define rb_default_rs p->config->default_rs()
257#define rb_io_write p->config->io_write
258#define rb_io_flush p->config->io_flush
259#define rb_io_puts p->config->io_puts
260#define rb_io_gets_internal p->config->io_gets_internal
261
262#define rb_ractor_stdout p->config->debug_output_stdout
263#define rb_ractor_stderr p->config->debug_output_stderr
264
265#define rb_is_usascii_enc p->config->is_usascii_enc
266#define rb_enc_isalnum p->config->enc_isalnum
267#define rb_enc_precise_mbclen p->config->enc_precise_mbclen
268#define MBCLEN_CHARFOUND_P p->config->mbclen_charfound_p
269#define rb_enc_name p->config->enc_name
270#define rb_enc_prev_char p->config->enc_prev_char
271#define rb_enc_get p->config->enc_get
272#define rb_enc_asciicompat p->config->enc_asciicompat
273#define rb_utf8_encoding p->config->utf8_encoding
274#define rb_enc_associate p->config->enc_associate
275#define rb_ascii8bit_encoding p->config->ascii8bit_encoding
276#define rb_enc_codelen p->config->enc_codelen
277#define rb_enc_mbcput p->config->enc_mbcput
278#define rb_char_to_option_kcode p->config->char_to_option_kcode
279#define rb_ascii8bit_encindex p->config->ascii8bit_encindex
280#define rb_enc_find_index p->config->enc_find_index
281#define rb_enc_from_index p->config->enc_from_index
282#define rb_enc_associate_index p->config->enc_associate_index
283#define rb_enc_isspace p->config->enc_isspace
284#define ENC_CODERANGE_7BIT p->config->enc_coderange_7bit
285#define ENC_CODERANGE_UNKNOWN p->config->enc_coderange_unknown
286#define ENC_CODERANGE_BROKEN p->config->enc_coderange_broken
287#define rb_enc_compatible p->config->enc_compatible
288#define rb_enc_from_encoding p->config->enc_from_encoding
289#define ENCODING_GET p->config->encoding_get
290#define ENCODING_SET p->config->encoding_set
291#define ENCODING_IS_ASCII8BIT p->config->encoding_is_ascii8bit
292#define rb_usascii_encoding p->config->usascii_encoding
293#define rb_enc_str_coderange p->config->enc_str_coderange
294
295#define rb_ractor_make_shareable p->config->ractor_make_shareable
296
297#define ruby_vm_keep_script_lines p->config->vm_keep_script_lines()
298#define rb_local_defined p->config->local_defined
299#define rb_dvar_defined p->config->dvar_defined
300
301#define literal_cmp p->config->literal_cmp
302#define literal_hash p->config->literal_hash
303
304#define rb_builtin_class_name p->config->builtin_class_name
305#define rb_syntax_error_append p->config->syntax_error_append
306#define rb_raise p->config->raise
307#define syntax_error_new p->config->syntax_error_new
308
309#define rb_errinfo p->config->errinfo
310#define rb_set_errinfo p->config->set_errinfo
311#define rb_exc_raise p->config->exc_raise
312#define rb_make_exception p->config->make_exception
313
314#define ruby_sized_xfree p->config->sized_xfree
315#define SIZED_REALLOC_N(v, T, m, n) ((v) = (T *)p->config->sized_realloc_n((void *)(v), (m), sizeof(T), (n)))
316#undef RB_OBJ_WRITE
317#define RB_OBJ_WRITE(old, slot, young) p->config->obj_write((VALUE)(old), (VALUE *)(slot), (VALUE)(young))
318#undef RB_OBJ_WRITTEN
319#define RB_OBJ_WRITTEN(old, oldv, young) p->config->obj_written((VALUE)(old), (VALUE)(oldv), (VALUE)(young))
320#define rb_gc_register_mark_object p->config->gc_register_mark_object
321#undef RB_GC_GUARD
322#define RB_GC_GUARD p->config->gc_guard
323#define rb_gc_mark p->config->gc_mark
324
325#define rb_reg_compile p->config->reg_compile
326#define rb_reg_check_preprocess p->config->reg_check_preprocess
327#define rb_memcicmp p->config->memcicmp
328
329#define rb_compile_warn p->config->compile_warn
330#define rb_compile_warning p->config->compile_warning
331#define rb_bug p->config->bug
332#define rb_fatal p->config->fatal
333#undef ruby_verbose
334#define ruby_verbose p->config->verbose()
335
336#define rb_make_backtrace p->config->make_backtrace
337
338#define ruby_scan_hex p->config->scan_hex
339#define ruby_scan_oct p->config->scan_oct
340#define ruby_scan_digits p->config->scan_digits
341#define strtod p->config->strtod
342
343#undef RBOOL
344#define RBOOL p->config->rbool
345#undef UNDEF_P
346#define UNDEF_P p->config->undef_p
347#undef RTEST
348#define RTEST p->config->rtest
349#undef NIL_P
350#define NIL_P p->config->nil_p
351#undef FLONUM_P
352#define FLONUM_P p->config->flonum_p
353#undef Qnil
354#define Qnil p->config->qnil
355#undef Qtrue
356#define Qtrue p->config->qtrue
357#undef Qfalse
358#define Qfalse p->config->qfalse
359#undef Qundef
360#define Qundef p->config->qundef
361#define rb_eArgError p->config->eArgError
362#define rb_mRubyVMFrozenCore p->config->mRubyVMFrozenCore
363#undef rb_long2int
364#define rb_long2int p->config->long2int
365#undef SPECIAL_CONST_P
366#define SPECIAL_CONST_P p->config->special_const_p
367#undef BUILTIN_TYPE
368#define BUILTIN_TYPE p->config->builtin_type
369#define ruby_snprintf p->config->snprintf
370
371#define rb_node_case_when_optimizable_literal p->config->node_case_when_optimizable_literal
372
373#undef st_init_table_with_size
374#define st_init_table_with_size rb_parser_st_init_table_with_size
375
376#define rb_ast_new() \
377 rb_ast_new(p->config)
stdarg.h
Defines old _.
stdbool.h
C99 shim for <stdbool.h>
rb_imemo_tmpbuf_struct
Definition imemo.h:91
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40