1a9619bf31a1c9ef87a965ad62b7d7fe9522b6c9
[ruby.git] / universal_parser.c
blob1a9619bf31a1c9ef87a965ad62b7d7fe9522b6c9
1 #include <alloca.h>
2 #include <string.h>
3 #include <stdarg.h>
4 #include <stdbool.h>
5 #include <stddef.h>
7 /* Dependency */
8 #include "internal/parse.h"
9 #include "node.h"
10 #include "id.h"
12 #include "internal/compilers.h"
13 #include "ruby/backward/2/inttypes.h"
14 #include "probes.h"
16 #define LIKELY(x) RB_LIKELY(x)
17 #define UNLIKELY(x) RB_UNLIKELY(x)
18 #ifndef TRUE
19 # define TRUE 1
20 #endif
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))
34 /* parser_st */
35 #define st_table parser_st_table
36 #define st_data_t parser_st_data_t
37 #define st_hash_type parser_st_hash_type
38 #define ST_CONTINUE ST2_CONTINUE
39 #define ST_STOP ST2_STOP
40 #define ST_DELETE ST2_DELETE
41 #define ST_CHECK ST2_CHECK
42 #define ST_REPLACE ST2_REPLACE
43 #undef st_init_numtable
44 #define st_init_numtable rb_parser_st_init_numtable
45 #undef st_free_table
46 #define st_free_table rb_parser_st_free_table
47 #undef st_init_table_with_size
48 #define st_init_table_with_size rb_parser_st_init_table_with_size
49 #undef st_insert
50 #define st_insert rb_parser_st_insert
51 #undef st_foreach
52 #define st_foreach rb_parser_st_foreach
53 #undef st_delete
54 #define st_delete rb_parser_st_delete
55 #undef st_is_member
56 #define st_is_member parser_st_is_member
57 #undef st_init_table
58 #define st_init_table rb_parser_st_init_table
59 #undef st_lookup
60 #define st_lookup rb_parser_st_lookup
62 #define rb_encoding void
64 #undef xmalloc
65 #define xmalloc p->config->malloc
66 #undef xcalloc
67 #define xcalloc p->config->calloc
68 #undef xrealloc
69 #define xrealloc p->config->realloc
70 #undef ALLOC_N
71 #define ALLOC_N(type,n) ((type *)p->config->alloc_n((n), sizeof(type)))
72 #undef ALLOC
73 #define ALLOC(type) ((type *)p->config->alloc(sizeof(type)))
74 #undef xfree
75 #define xfree p->config->free
76 #undef ALLOCA_N
77 // alloca(rbimpl_size_mul_or_raise(x, y));
78 #define ALLOCA_N(type,n) ((type *)alloca(sizeof(type) * (n)))
79 #undef REALLOC_N
80 #define REALLOC_N(var,type,n) ((var) = (type *)p->config->realloc_n((void *)var, n, sizeof(type)))
81 #undef ZALLOC
82 #define ZALLOC(type) ((type *)p->config->zalloc(sizeof(type)))
83 #undef MEMMOVE
84 #define MEMMOVE(p1,p2,type,n) (p->config->rb_memmove((p1), (p2), sizeof(type), (n)))
85 #undef MEMCPY
86 #define MEMCPY(p1,p2,type,n) (p->config->nonempty_memcpy((p1), (p2), sizeof(type), (n)))
88 #define compile_callback p->config->compile_callback
89 #define reg_named_capture_assign p->config->reg_named_capture_assign
91 #undef FIXNUM_P
92 #define FIXNUM_P p->config->fixnum_p
93 #undef SYMBOL_P
94 #define SYMBOL_P p->config->symbol_p
96 #define rb_attr_get p->config->attr_get
98 #define rb_ary_new p->config->ary_new
99 #define rb_ary_push p->config->ary_push
100 #undef rb_ary_new_from_args
101 #define rb_ary_new_from_args p->config->ary_new_from_args
102 #define rb_ary_unshift p->config->ary_unshift
103 #undef rb_ary_new2
104 #define rb_ary_new2 p->config->ary_new2
105 #define rb_ary_clear p->config->ary_clear
106 #define rb_ary_modify p->config->ary_modify
107 #undef RARRAY_LEN
108 #define RARRAY_LEN p->config->array_len
109 #define RARRAY_AREF p->config->array_aref
111 #define rb_make_temporary_id p->config->make_temporary_id
112 #define is_local_id p->config->is_local_id
113 #define is_attrset_id p->config->is_attrset_id
114 #define is_global_name_punct p->config->is_global_name_punct
115 #define id_type p->config->id_type
116 #define rb_id_attrset p->config->id_attrset
117 #undef rb_intern
118 #define rb_intern p->config->intern
119 #define rb_intern2 p->config->intern2
120 #define rb_intern3 p->config->intern3
121 #define rb_intern_str p->config->intern_str
122 #define is_notop_id p->config->is_notop_id
123 #define rb_enc_symname_type p->config->enc_symname_type
124 #define rb_id2name p->config->id2name
125 #define rb_id2str p->config->id2str
126 #undef ID2SYM
127 #define ID2SYM p->config->id2sym
128 #undef SYM2ID
129 #define SYM2ID p->config->sym2id
131 #define rb_str_catf p->config->str_catf
132 #undef rb_str_cat_cstr
133 #define rb_str_cat_cstr p->config->str_cat_cstr
134 #define rb_str_subseq p->config->str_subseq
135 #define rb_str_new_frozen p->config->str_new_frozen
136 #define rb_str_buf_new p->config->str_buf_new
137 #undef rb_str_buf_cat
138 #define rb_str_buf_cat p->config->str_buf_cat
139 #define rb_str_modify p->config->str_modify
140 #define rb_str_set_len p->config->str_set_len
141 #define rb_str_cat p->config->str_cat
142 #define rb_str_resize p->config->str_resize
143 #undef rb_str_new
144 #define rb_str_new p->config->str_new
145 #undef rb_str_new_cstr
146 #define rb_str_new_cstr p->config->str_new_cstr
147 #define rb_str_to_interned_str p->config->str_to_interned_str
148 #define is_ascii_string p->config->is_ascii_string
149 #define rb_enc_str_new p->config->enc_str_new
150 #define rb_enc_str_buf_cat p->config->enc_str_buf_cat
151 #define rb_str_buf_append p->config->str_buf_append
152 #define rb_str_vcatf p->config->str_vcatf
153 #undef StringValueCStr
154 #define StringValueCStr(v) p->config->string_value_cstr(&(v))
155 #define rb_sprintf p->config->rb_sprintf
156 #undef RSTRING_PTR
157 #define RSTRING_PTR p->config->rstring_ptr
158 #undef RSTRING_END
159 #define RSTRING_END p->config->rstring_end
160 #undef RSTRING_LEN
161 #define RSTRING_LEN p->config->rstring_len
162 #define rb_filesystem_str_new_cstr p->config->filesystem_str_new_cstr
163 #define rb_obj_as_string p->config->obj_as_string
165 #undef NUM2INT
166 #define NUM2INT p->config->num2int
167 #undef INT2NUM
168 #define INT2NUM p->config->int2num
170 #define rb_stderr_tty_p p->config->stderr_tty_p
171 #define rb_write_error_str p->config->write_error_str
172 #define rb_default_rs p->config->default_rs()
173 #define rb_io_write p->config->io_write
174 #define rb_io_flush p->config->io_flush
175 #define rb_io_puts p->config->io_puts
176 #define rb_io_gets_internal p->config->io_gets_internal
178 #define rb_ractor_stdout p->config->debug_output_stdout
179 #define rb_ractor_stderr p->config->debug_output_stderr
181 #define rb_is_usascii_enc p->config->is_usascii_enc
182 #define rb_enc_isalnum p->config->enc_isalnum
183 #define rb_enc_precise_mbclen p->config->enc_precise_mbclen
184 #define MBCLEN_CHARFOUND_P p->config->mbclen_charfound_p
185 #define MBCLEN_CHARFOUND_LEN p->config->mbclen_charfound_len
186 #define rb_enc_name p->config->enc_name
187 #define rb_enc_prev_char p->config->enc_prev_char
188 #define rb_enc_get p->config->enc_get
189 #define rb_enc_asciicompat p->config->enc_asciicompat
190 #define rb_utf8_encoding p->config->utf8_encoding
191 #define rb_enc_associate p->config->enc_associate
192 #define rb_ascii8bit_encoding p->config->ascii8bit_encoding
193 #define rb_enc_codelen p->config->enc_codelen
194 #define rb_enc_mbcput p->config->enc_mbcput
195 #define rb_enc_find_index p->config->enc_find_index
196 #define rb_enc_from_index p->config->enc_from_index
197 #define rb_enc_associate_index p->config->enc_associate_index
198 #define rb_enc_isspace p->config->enc_isspace
199 #define ENC_CODERANGE_7BIT p->config->enc_coderange_7bit
200 #define ENC_CODERANGE_UNKNOWN p->config->enc_coderange_unknown
201 #define rb_enc_compatible p->config->enc_compatible
202 #define rb_enc_from_encoding p->config->enc_from_encoding
203 #define ENCODING_IS_ASCII8BIT p->config->encoding_is_ascii8bit
204 #define rb_usascii_encoding p->config->usascii_encoding
206 #define rb_local_defined p->config->local_defined
207 #define rb_dvar_defined p->config->dvar_defined
209 #define rb_syntax_error_append p->config->syntax_error_append
210 #define rb_raise p->config->raise
211 #define syntax_error_new p->config->syntax_error_new
213 #define rb_errinfo p->config->errinfo
214 #define rb_set_errinfo p->config->set_errinfo
215 #define rb_exc_raise p->config->exc_raise
216 #define rb_make_exception p->config->make_exception
218 #define ruby_sized_xfree p->config->sized_xfree
219 #define SIZED_REALLOC_N(v, T, m, n) ((v) = (T *)p->config->sized_realloc_n((void *)(v), (m), sizeof(T), (n)))
220 #undef RB_OBJ_WRITE
221 #define RB_OBJ_WRITE(old, slot, young) p->config->obj_write((VALUE)(old), (VALUE *)(slot), (VALUE)(young))
222 #undef RB_GC_GUARD
223 #define RB_GC_GUARD p->config->gc_guard
224 #define rb_gc_mark p->config->gc_mark
226 #define rb_reg_compile p->config->reg_compile
227 #define rb_reg_check_preprocess p->config->reg_check_preprocess
228 #define rb_memcicmp p->config->memcicmp
230 #define rb_compile_warn p->config->compile_warn
231 #define rb_compile_warning p->config->compile_warning
232 #define rb_bug p->config->bug
233 #define rb_fatal p->config->fatal
234 #undef ruby_verbose
235 #define ruby_verbose p->config->verbose()
236 #undef errno
237 #define errno (*p->config->errno_ptr())
239 #define rb_make_backtrace p->config->make_backtrace
241 #define ruby_scan_hex p->config->scan_hex
242 #define ruby_scan_oct p->config->scan_oct
243 #define ruby_scan_digits p->config->scan_digits
244 #define strtod p->config->strtod
246 #undef RBOOL
247 #define RBOOL p->config->rbool
248 #undef UNDEF_P
249 #define UNDEF_P p->config->undef_p
250 #undef RTEST
251 #define RTEST p->config->rtest
252 #undef NIL_P
253 #define NIL_P p->config->nil_p
254 #undef Qnil
255 #define Qnil p->config->qnil
256 #undef Qtrue
257 #define Qtrue p->config->qtrue
258 #undef Qfalse
259 #define Qfalse p->config->qfalse
260 #undef Qundef
261 #define Qundef p->config->qundef
262 #define rb_eArgError p->config->eArgError()
263 #undef rb_long2int
264 #define rb_long2int p->config->long2int
265 #define rb_enc_mbminlen p->config->enc_mbminlen
266 #define rb_enc_isascii p->config->enc_isascii
267 #define rb_enc_mbc_to_codepoint p->config->enc_mbc_to_codepoint
269 #undef st_init_table_with_size
270 #define st_init_table_with_size rb_parser_st_init_table_with_size
272 #define rb_ast_new() \
273 rb_ast_new(p->config)