Ruby: universal_parser.c Source File

Ruby 3.4.7p58 (2025-10-08 revision 7a5688e2a27668e48f8d6ff4af5b2208b98a2f5e)

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 "") / sizeof(str ""[0])) - 1)
27#undef FIXNUM_MAX
28#define FIXNUM_MAX (LONG_MAX / 2)
29
30/* parser_st */
31#define st_table parser_st_table
32#define st_data_t parser_st_data_t
33#define st_hash_type parser_st_hash_type
34#define ST_CONTINUE ST2_CONTINUE
35#define ST_STOP ST2_STOP
36#define ST_DELETE ST2_DELETE
37#define ST_CHECK ST2_CHECK
38#define ST_REPLACE ST2_REPLACE
39#undef st_init_numtable
40#define st_init_numtable rb_parser_st_init_numtable
41#undef st_free_table
42#define st_free_table rb_parser_st_free_table
43#undef st_init_table_with_size
44#define st_init_table_with_size rb_parser_st_init_table_with_size
45#undef st_insert
46#define st_insert rb_parser_st_insert
47#undef st_foreach
48#define st_foreach rb_parser_st_foreach
49#undef st_delete
50#define st_delete rb_parser_st_delete
51#undef st_is_member
52#define st_is_member parser_st_is_member
53#undef st_init_table
54#define st_init_table rb_parser_st_init_table
55#undef st_lookup
56#define st_lookup rb_parser_st_lookup
57
58#define rb_encoding const void
59
60#undef xmalloc
61#define xmalloc p->config->malloc
62#undef xcalloc
63#define xcalloc p->config->calloc
64#undef xrealloc
65#define xrealloc p->config->realloc
66#undef ALLOC_N
67#define ALLOC_N(type,n) ((type *)p->config->alloc_n((n), sizeof(type)))
68#undef ALLOC
69#define ALLOC(type) ((type *)p->config->alloc(sizeof(type)))
70#undef xfree
71#define xfree p->config->free
72#undef ALLOCA_N
73// alloca(rbimpl_size_mul_or_raise(x, y));
74#define ALLOCA_N(type,n) ((type *)alloca(sizeof(type) * (n)))
75#undef REALLOC_N
76#define REALLOC_N(var,type,n) ((var) = (type *)p->config->realloc_n((void *)var, n, sizeof(type)))
77#undef ZALLOC
78#define ZALLOC(type) ((type *)p->config->zalloc(sizeof(type)))
79#undef MEMMOVE
80#define MEMMOVE(p1,p2,type,n) (p->config->rb_memmove((p1), (p2), sizeof(type), (n)))
81#undef MEMCPY
82#define MEMCPY(p1,p2,type,n) (p->config->nonempty_memcpy((p1), (p2), sizeof(type), (n)))
83
84#define compile_callback p->config->compile_callback
85#define reg_named_capture_assign p->config->reg_named_capture_assign
86
87#define rb_attr_get p->config->attr_get
88
89#define rb_ary_push p->config->ary_push
90#undef rb_ary_new_from_args
91#define rb_ary_new_from_args p->config->ary_new_from_args
92#define rb_ary_unshift p->config->ary_unshift
93
94#define rb_make_temporary_id p->config->make_temporary_id
95#define is_local_id p->config->is_local_id
96#define is_attrset_id p->config->is_attrset_id
97#define is_global_name_punct p->config->is_global_name_punct
98#define id_type p->config->id_type
99#define rb_id_attrset p->config->id_attrset
100#undef rb_intern
101#define rb_intern p->config->intern
102#define rb_intern2 p->config->intern2
103#define rb_intern3 p->config->intern3
104#define rb_intern_str p->config->intern_str
105#define is_notop_id p->config->is_notop_id
106#define rb_enc_symname_type p->config->enc_symname_type
107#define rb_id2name p->config->id2name
108#define rb_id2str p->config->id2str
109#undef ID2SYM
110#define ID2SYM p->config->id2sym
111#undef SYM2ID
112#define SYM2ID p->config->sym2id
113
114#define rb_str_catf p->config->str_catf
115#undef rb_str_cat_cstr
116#define rb_str_cat_cstr p->config->str_cat_cstr
117#define rb_str_resize p->config->str_resize
118#undef rb_str_new
119#define rb_str_new p->config->str_new
120#undef rb_str_new_cstr
121#define rb_str_new_cstr p->config->str_new_cstr
122#define rb_str_to_interned_str p->config->str_to_interned_str
123#define rb_enc_str_new p->config->enc_str_new
124#define rb_str_vcatf p->config->str_vcatf
125#define rb_sprintf p->config->rb_sprintf
126#undef RSTRING_PTR
127#define RSTRING_PTR p->config->rstring_ptr
128#undef RSTRING_LEN
129#define RSTRING_LEN p->config->rstring_len
130#define rb_obj_as_string p->config->obj_as_string
131
132#undef INT2NUM
133#define INT2NUM p->config->int2num
134
135#define rb_stderr_tty_p p->config->stderr_tty_p
136#define rb_write_error_str p->config->write_error_str
137#define rb_io_write p->config->io_write
138#define rb_io_flush p->config->io_flush
139#define rb_io_puts p->config->io_puts
140
141#define rb_ractor_stdout p->config->debug_output_stdout
142#define rb_ractor_stderr p->config->debug_output_stderr
143
144#define rb_is_usascii_enc p->config->is_usascii_enc
145#define rb_enc_isalnum p->config->enc_isalnum
146#define rb_enc_precise_mbclen p->config->enc_precise_mbclen
147#define MBCLEN_CHARFOUND_P p->config->mbclen_charfound_p
148#define MBCLEN_CHARFOUND_LEN p->config->mbclen_charfound_len
149#define rb_enc_name p->config->enc_name
150#define rb_enc_prev_char p->config->enc_prev_char
151#define rb_enc_get p->config->enc_get
152#define rb_enc_asciicompat p->config->enc_asciicompat
153#define rb_utf8_encoding p->config->utf8_encoding
154#define rb_enc_associate p->config->enc_associate
155#define rb_ascii8bit_encoding p->config->ascii8bit_encoding
156#define rb_enc_codelen p->config->enc_codelen
157#define rb_enc_mbcput p->config->enc_mbcput
158#define rb_enc_find_index p->config->enc_find_index
159#define rb_enc_from_index p->config->enc_from_index
160#define rb_enc_isspace p->config->enc_isspace
161#define ENC_CODERANGE_7BIT p->config->enc_coderange_7bit
162#define ENC_CODERANGE_UNKNOWN p->config->enc_coderange_unknown
163#define rb_usascii_encoding p->config->usascii_encoding
164
165#define rb_local_defined p->config->local_defined
166#define rb_dvar_defined p->config->dvar_defined
167
168#define rb_syntax_error_append p->config->syntax_error_append
169#define rb_raise p->config->raise
170#define syntax_error_new p->config->syntax_error_new
171
172#define rb_errinfo p->config->errinfo
173#define rb_set_errinfo p->config->set_errinfo
174#define rb_exc_raise p->config->exc_raise
175#define rb_make_exception p->config->make_exception
176
177#define ruby_sized_xfree p->config->sized_xfree
178#define SIZED_REALLOC_N(v, T, m, n) ((v) = (T *)p->config->sized_realloc_n((void *)(v), (m), sizeof(T), (n)))
179#undef RB_GC_GUARD
180#define RB_GC_GUARD p->config->gc_guard
181#define rb_gc_mark p->config->gc_mark
182
183#define rb_reg_compile p->config->reg_compile
184#define rb_reg_check_preprocess p->config->reg_check_preprocess
185#define rb_memcicmp p->config->memcicmp
186
187#define rb_compile_warn p->config->compile_warn
188#define rb_compile_warning p->config->compile_warning
189#define rb_bug p->config->bug
190#define rb_fatal p->config->fatal
191#undef ruby_verbose
192#define ruby_verbose p->config->verbose()
193#undef errno
194#define errno (*p->config->errno_ptr())
195
196#define rb_make_backtrace p->config->make_backtrace
197
198#define ruby_scan_hex p->config->scan_hex
199#define ruby_scan_oct p->config->scan_oct
200#define ruby_scan_digits p->config->scan_digits
201#define strtod p->config->strtod
202
203#undef RTEST
204#define RTEST p->config->rtest
205#undef NIL_P
206#define NIL_P p->config->nil_p
207#undef Qnil
208#define Qnil p->config->qnil
209#undef Qfalse
210#define Qfalse p->config->qfalse
211#define rb_eArgError p->config->eArgError()
212#undef rb_long2int
213#define rb_long2int p->config->long2int
214#define rb_enc_mbminlen p->config->enc_mbminlen
215#define rb_enc_isascii p->config->enc_isascii
216#define rb_enc_mbc_to_codepoint p->config->enc_mbc_to_codepoint
217
218#define rb_ast_new() \
219 rb_ast_new(p->config)
stdarg.h
Defines old _.
stdbool.h
C99 shim for <stdbool.h>