Remove unused function from `struct rb_parser_config_struct`
[ruby.git] / rubyparser.h
blob268e8deeff6f412a10a774dc0e960673af06d87a
1 #ifndef RUBY_RUBYPARSER_H
2 #define RUBY_RUBYPARSER_H 1
3 /*
4 * This is a header file for librubyparser interface
5 */
7 #include <stdarg.h> /* for va_list */
8 #include <assert.h>
10 #ifdef UNIVERSAL_PARSER
12 #define rb_encoding void
13 #define OnigCodePoint unsigned int
14 #include "parser_st.h"
15 #ifndef RUBY_RUBY_H
16 #include "parser_value.h"
17 #endif
19 #else
21 #include "ruby/encoding.h"
23 #endif
25 #ifndef FLEX_ARY_LEN
26 /* From internal/compilers.h */
27 /* A macro for defining a flexible array, like: VALUE ary[FLEX_ARY_LEN]; */
28 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
29 # define FLEX_ARY_LEN /* VALUE ary[]; */
30 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
31 # define FLEX_ARY_LEN 0 /* VALUE ary[0]; */
32 #else
33 # define FLEX_ARY_LEN 1 /* VALUE ary[1]; */
34 #endif
35 #endif
37 #if defined(__GNUC__)
38 # if defined(__MINGW_PRINTF_FORMAT)
39 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, argument_index)))
40 # else
41 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(printf, string_index, argument_index)))
42 # endif
43 #elif defined(__clang__)
44 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
45 #else
46 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index)
47 #endif
50 * Parser String
52 enum rb_parser_string_coderange_type {
53 /** The object's coderange is unclear yet. */
54 RB_PARSER_ENC_CODERANGE_UNKNOWN = 0,
55 RB_PARSER_ENC_CODERANGE_7BIT = 1,
56 RB_PARSER_ENC_CODERANGE_VALID = 2,
57 RB_PARSER_ENC_CODERANGE_BROKEN = 3
60 typedef struct rb_parser_string {
61 enum rb_parser_string_coderange_type coderange;
62 rb_encoding *enc;
63 /* Length of the string, not including terminating NUL character. */
64 long len;
65 /* Pointer to the contents of the string. */
66 char *ptr;
67 } rb_parser_string_t;
69 enum rb_parser_shareability {
70 rb_parser_shareable_none,
71 rb_parser_shareable_literal,
72 rb_parser_shareable_copy,
73 rb_parser_shareable_everything,
77 * AST Node
79 enum node_type {
80 NODE_SCOPE,
81 NODE_BLOCK,
82 NODE_IF,
83 NODE_UNLESS,
84 NODE_CASE,
85 NODE_CASE2,
86 NODE_CASE3,
87 NODE_WHEN,
88 NODE_IN,
89 NODE_WHILE,
90 NODE_UNTIL,
91 NODE_ITER,
92 NODE_FOR,
93 NODE_FOR_MASGN,
94 NODE_BREAK,
95 NODE_NEXT,
96 NODE_REDO,
97 NODE_RETRY,
98 NODE_BEGIN,
99 NODE_RESCUE,
100 NODE_RESBODY,
101 NODE_ENSURE,
102 NODE_AND,
103 NODE_OR,
104 NODE_MASGN,
105 NODE_LASGN,
106 NODE_DASGN,
107 NODE_GASGN,
108 NODE_IASGN,
109 NODE_CDECL,
110 NODE_CVASGN,
111 NODE_OP_ASGN1,
112 NODE_OP_ASGN2,
113 NODE_OP_ASGN_AND,
114 NODE_OP_ASGN_OR,
115 NODE_OP_CDECL,
116 NODE_CALL,
117 NODE_OPCALL,
118 NODE_FCALL,
119 NODE_VCALL,
120 NODE_QCALL,
121 NODE_SUPER,
122 NODE_ZSUPER,
123 NODE_LIST,
124 NODE_ZLIST,
125 NODE_HASH,
126 NODE_RETURN,
127 NODE_YIELD,
128 NODE_LVAR,
129 NODE_DVAR,
130 NODE_GVAR,
131 NODE_IVAR,
132 NODE_CONST,
133 NODE_CVAR,
134 NODE_NTH_REF,
135 NODE_BACK_REF,
136 NODE_MATCH,
137 NODE_MATCH2,
138 NODE_MATCH3,
139 NODE_INTEGER,
140 NODE_FLOAT,
141 NODE_RATIONAL,
142 NODE_IMAGINARY,
143 NODE_STR,
144 NODE_DSTR,
145 NODE_XSTR,
146 NODE_DXSTR,
147 NODE_EVSTR,
148 NODE_REGX,
149 NODE_DREGX,
150 NODE_ONCE,
151 NODE_ARGS,
152 NODE_ARGS_AUX,
153 NODE_OPT_ARG,
154 NODE_KW_ARG,
155 NODE_POSTARG,
156 NODE_ARGSCAT,
157 NODE_ARGSPUSH,
158 NODE_SPLAT,
159 NODE_BLOCK_PASS,
160 NODE_DEFN,
161 NODE_DEFS,
162 NODE_ALIAS,
163 NODE_VALIAS,
164 NODE_UNDEF,
165 NODE_CLASS,
166 NODE_MODULE,
167 NODE_SCLASS,
168 NODE_COLON2,
169 NODE_COLON3,
170 NODE_DOT2,
171 NODE_DOT3,
172 NODE_FLIP2,
173 NODE_FLIP3,
174 NODE_SELF,
175 NODE_NIL,
176 NODE_TRUE,
177 NODE_FALSE,
178 NODE_ERRINFO,
179 NODE_DEFINED,
180 NODE_POSTEXE,
181 NODE_SYM,
182 NODE_DSYM,
183 NODE_ATTRASGN,
184 NODE_LAMBDA,
185 NODE_ARYPTN,
186 NODE_HSHPTN,
187 NODE_FNDPTN,
188 NODE_ERROR,
189 NODE_LINE,
190 NODE_FILE,
191 NODE_ENCODING,
192 NODE_LAST
195 typedef struct rb_ast_id_table {
196 int size;
197 ID ids[FLEX_ARY_LEN];
198 } rb_ast_id_table_t;
200 typedef struct rb_code_position_struct {
201 int lineno;
202 int column;
203 } rb_code_position_t;
205 typedef struct rb_code_location_struct {
206 rb_code_position_t beg_pos;
207 rb_code_position_t end_pos;
208 } rb_code_location_t;
209 #define YYLTYPE rb_code_location_t
210 #define YYLTYPE_IS_DECLARED 1
212 typedef struct rb_parser_ast_token {
213 int id;
214 const char *type_name;
215 rb_parser_string_t *str;
216 rb_code_location_t loc;
217 } rb_parser_ast_token_t;
220 * Array-like object for parser
222 typedef struct rb_parser_ary {
223 rb_parser_ast_token_t **data;
224 long len; // current size
225 long capa; // capacity
226 } rb_parser_ary_t;
228 /* Header part of AST Node */
229 typedef struct RNode {
230 VALUE flags;
231 rb_code_location_t nd_loc;
232 int node_id;
233 } NODE;
235 typedef struct RNode_SCOPE {
236 NODE node;
238 rb_ast_id_table_t *nd_tbl;
239 struct RNode *nd_body;
240 struct RNode_ARGS *nd_args;
241 } rb_node_scope_t;
243 typedef struct RNode_BLOCK {
244 NODE node;
246 struct RNode *nd_head;
247 struct RNode *nd_end;
248 struct RNode *nd_next;
249 } rb_node_block_t;
251 typedef struct RNode_IF {
252 NODE node;
254 struct RNode *nd_cond;
255 struct RNode *nd_body;
256 struct RNode *nd_else;
257 } rb_node_if_t;
259 typedef struct RNode_UNLESS {
260 NODE node;
262 struct RNode *nd_cond;
263 struct RNode *nd_body;
264 struct RNode *nd_else;
265 } rb_node_unless_t;
267 typedef struct RNode_CASE {
268 NODE node;
270 struct RNode *nd_head;
271 struct RNode *nd_body;
272 } rb_node_case_t;
274 typedef struct RNode_CASE2 {
275 NODE node;
277 struct RNode *nd_head;
278 struct RNode *nd_body;
279 } rb_node_case2_t;
281 typedef struct RNode_CASE3 {
282 NODE node;
284 struct RNode *nd_head;
285 struct RNode *nd_body;
286 } rb_node_case3_t;
288 typedef struct RNode_WHEN {
289 NODE node;
291 struct RNode *nd_head;
292 struct RNode *nd_body;
293 struct RNode *nd_next;
294 } rb_node_when_t;
296 typedef struct RNode_IN {
297 NODE node;
299 struct RNode *nd_head;
300 struct RNode *nd_body;
301 struct RNode *nd_next;
302 } rb_node_in_t;
304 /* RNode_WHILE and RNode_UNTIL should be same structure */
305 typedef struct RNode_WHILE {
306 NODE node;
308 struct RNode *nd_cond;
309 struct RNode *nd_body;
310 long nd_state;
311 } rb_node_while_t;
313 typedef struct RNode_UNTIL {
314 NODE node;
316 struct RNode *nd_cond;
317 struct RNode *nd_body;
318 long nd_state;
319 } rb_node_until_t;
321 /* RNode_ITER and RNode_FOR should be same structure */
322 typedef struct RNode_ITER {
323 NODE node;
325 struct RNode *nd_body;
326 struct RNode *nd_iter;
327 } rb_node_iter_t;
329 typedef struct RNode_FOR {
330 NODE node;
332 struct RNode *nd_body;
333 struct RNode *nd_iter;
334 } rb_node_for_t;
336 typedef struct RNode_FOR_MASGN {
337 NODE node;
339 struct RNode *nd_var;
340 } rb_node_for_masgn_t;
342 /* RNode_BREAK, RNode_NEXT and RNode_REDO should be same structure */
343 typedef struct RNode_BREAK {
344 NODE node;
346 struct RNode *nd_chain;
347 struct RNode *nd_stts;
348 } rb_node_break_t;
350 typedef struct RNode_NEXT {
351 NODE node;
353 struct RNode *nd_chain;
354 struct RNode *nd_stts;
355 } rb_node_next_t;
357 typedef struct RNode_REDO {
358 NODE node;
360 struct RNode *nd_chain;
361 } rb_node_redo_t;
363 typedef struct RNode_RETRY {
364 NODE node;
365 } rb_node_retry_t;
367 typedef struct RNode_BEGIN {
368 NODE node;
370 struct RNode *nd_body;
371 } rb_node_begin_t;
373 typedef struct RNode_RESCUE {
374 NODE node;
376 struct RNode *nd_head;
377 struct RNode *nd_resq;
378 struct RNode *nd_else;
379 } rb_node_rescue_t;
381 typedef struct RNode_RESBODY {
382 NODE node;
384 struct RNode *nd_args;
385 struct RNode *nd_body;
386 struct RNode *nd_next;
387 } rb_node_resbody_t;
389 typedef struct RNode_ENSURE {
390 NODE node;
392 struct RNode *nd_head;
393 struct RNode *nd_ensr;
394 } rb_node_ensure_t;
396 /* RNode_AND and RNode_OR should be same structure */
397 typedef struct RNode_AND {
398 NODE node;
400 struct RNode *nd_1st;
401 struct RNode *nd_2nd;
402 } rb_node_and_t;
404 typedef struct RNode_OR {
405 NODE node;
407 struct RNode *nd_1st;
408 struct RNode *nd_2nd;
409 } rb_node_or_t;
411 typedef struct RNode_MASGN {
412 NODE node;
414 struct RNode *nd_head;
415 struct RNode *nd_value;
416 struct RNode *nd_args;
417 } rb_node_masgn_t;
419 typedef struct RNode_LASGN {
420 NODE node;
422 ID nd_vid;
423 struct RNode *nd_value;
424 } rb_node_lasgn_t;
426 typedef struct RNode_DASGN {
427 NODE node;
429 ID nd_vid;
430 struct RNode *nd_value;
431 } rb_node_dasgn_t;
433 typedef struct RNode_GASGN {
434 NODE node;
436 ID nd_vid;
437 struct RNode *nd_value;
438 } rb_node_gasgn_t;
440 typedef struct RNode_IASGN {
441 NODE node;
443 ID nd_vid;
444 struct RNode *nd_value;
445 } rb_node_iasgn_t;
447 typedef struct RNode_CDECL {
448 NODE node;
450 ID nd_vid;
451 struct RNode *nd_value;
452 struct RNode *nd_else;
453 enum rb_parser_shareability shareability;
454 } rb_node_cdecl_t;
456 typedef struct RNode_CVASGN {
457 NODE node;
459 ID nd_vid;
460 struct RNode *nd_value;
461 } rb_node_cvasgn_t;
463 typedef struct RNode_OP_ASGN1 {
464 NODE node;
466 struct RNode *nd_recv;
467 ID nd_mid;
468 struct RNode *nd_index;
469 struct RNode *nd_rvalue;
470 } rb_node_op_asgn1_t;
472 typedef struct RNode_OP_ASGN2 {
473 NODE node;
475 struct RNode *nd_recv;
476 struct RNode *nd_value;
477 ID nd_vid;
478 ID nd_mid;
479 bool nd_aid;
480 } rb_node_op_asgn2_t;
482 typedef struct RNode_OP_ASGN_AND {
483 NODE node;
485 struct RNode *nd_head;
486 struct RNode *nd_value;
487 } rb_node_op_asgn_and_t;
489 typedef struct RNode_OP_ASGN_OR {
490 NODE node;
492 struct RNode *nd_head;
493 struct RNode *nd_value;
494 } rb_node_op_asgn_or_t;
496 typedef struct RNode_OP_CDECL {
497 NODE node;
499 struct RNode *nd_head;
500 struct RNode *nd_value;
501 ID nd_aid;
502 enum rb_parser_shareability shareability;
503 } rb_node_op_cdecl_t;
505 typedef struct RNode_CALL {
506 NODE node;
508 struct RNode *nd_recv;
509 ID nd_mid;
510 struct RNode *nd_args;
511 } rb_node_call_t;
513 typedef struct RNode_OPCALL {
514 NODE node;
516 struct RNode *nd_recv;
517 ID nd_mid;
518 struct RNode *nd_args;
519 } rb_node_opcall_t;
521 typedef struct RNode_FCALL {
522 NODE node;
524 ID nd_mid;
525 struct RNode *nd_args;
526 } rb_node_fcall_t;
528 typedef struct RNode_VCALL {
529 NODE node;
531 ID nd_mid;
532 } rb_node_vcall_t;
534 typedef struct RNode_QCALL {
535 NODE node;
537 struct RNode *nd_recv;
538 ID nd_mid;
539 struct RNode *nd_args;
540 } rb_node_qcall_t;
542 typedef struct RNode_SUPER {
543 NODE node;
545 struct RNode *nd_args;
546 } rb_node_super_t;
548 typedef struct RNode_ZSUPER {
549 NODE node;
550 } rb_node_zsuper_t;
554 Structure of LIST:
556 LIST +--> LIST
557 * head --> element | * head
558 * alen (length of list) | * nd_end (point to the last LIST)
559 * next -----------------+ * next
562 RNode_LIST and RNode_VALUES should be same structure
564 typedef struct RNode_LIST {
565 NODE node;
567 struct RNode *nd_head; /* element */
568 union {
569 long nd_alen;
570 struct RNode *nd_end; /* Second list node has this structure */
571 } as;
572 struct RNode *nd_next; /* next list node */
573 } rb_node_list_t;
575 typedef struct RNode_ZLIST {
576 NODE node;
577 } rb_node_zlist_t;
579 typedef struct RNode_VALUES {
580 NODE node;
582 struct RNode *nd_head;
583 long nd_alen;
584 struct RNode *nd_next;
585 } rb_node_values_t;
587 typedef struct RNode_HASH {
588 NODE node;
590 struct RNode *nd_head;
591 long nd_brace;
592 } rb_node_hash_t;
594 typedef struct RNode_RETURN {
595 NODE node;
597 struct RNode *nd_stts;
598 } rb_node_return_t;
600 typedef struct RNode_YIELD {
601 NODE node;
603 struct RNode *nd_head;
604 } rb_node_yield_t;
606 typedef struct RNode_LVAR {
607 NODE node;
609 ID nd_vid;
610 } rb_node_lvar_t;
612 typedef struct RNode_DVAR {
613 NODE node;
615 ID nd_vid;
616 } rb_node_dvar_t;
618 typedef struct RNode_GVAR {
619 NODE node;
621 ID nd_vid;
622 } rb_node_gvar_t;
624 typedef struct RNode_IVAR {
625 NODE node;
627 ID nd_vid;
628 } rb_node_ivar_t;
630 typedef struct RNode_CONST {
631 NODE node;
633 ID nd_vid;
634 } rb_node_const_t;
636 typedef struct RNode_CVAR {
637 NODE node;
639 ID nd_vid;
640 } rb_node_cvar_t;
642 typedef struct RNode_NTH_REF {
643 NODE node;
645 long nd_nth;
646 } rb_node_nth_ref_t;
648 typedef struct RNode_BACK_REF {
649 NODE node;
651 long nd_nth;
652 } rb_node_back_ref_t;
654 /* RNode_MATCH and RNode_REGX should be same structure */
655 typedef struct RNode_MATCH {
656 NODE node;
658 struct rb_parser_string *string;
659 int options;
660 } rb_node_match_t;
662 typedef struct RNode_MATCH2 {
663 NODE node;
665 struct RNode *nd_recv;
666 struct RNode *nd_value;
667 struct RNode *nd_args;
668 } rb_node_match2_t;
670 typedef struct RNode_MATCH3 {
671 NODE node;
673 struct RNode *nd_recv;
674 struct RNode *nd_value;
675 } rb_node_match3_t;
677 typedef struct RNode_INTEGER {
678 NODE node;
680 char *val;
681 int minus;
682 int base;
683 } rb_node_integer_t;
685 typedef struct RNode_FLOAT {
686 NODE node;
688 char *val;
689 int minus;
690 } rb_node_float_t;
692 typedef struct RNode_RATIONAL {
693 NODE node;
695 char *val;
696 int minus;
697 int base;
698 int seen_point;
699 } rb_node_rational_t;
701 enum rb_numeric_type {
702 integer_literal,
703 float_literal,
704 rational_literal
707 typedef struct RNode_IMAGINARY {
708 NODE node;
710 char *val;
711 int minus;
712 int base;
713 int seen_point;
714 enum rb_numeric_type type;
715 } rb_node_imaginary_t;
717 /* RNode_STR and RNode_XSTR should be same structure */
718 typedef struct RNode_STR {
719 NODE node;
721 struct rb_parser_string *string;
722 } rb_node_str_t;
724 /* RNode_DSTR, RNode_DXSTR and RNode_DSYM should be same structure */
725 typedef struct RNode_DSTR {
726 NODE node;
728 struct rb_parser_string *string;
729 union {
730 long nd_alen;
731 struct RNode *nd_end; /* Second dstr node has this structure. See also RNode_LIST */
732 } as;
733 struct RNode_LIST *nd_next;
734 } rb_node_dstr_t;
736 typedef struct RNode_XSTR {
737 NODE node;
739 struct rb_parser_string *string;
740 } rb_node_xstr_t;
742 typedef struct RNode_DXSTR {
743 NODE node;
745 struct rb_parser_string *string;
746 long nd_alen;
747 struct RNode_LIST *nd_next;
748 } rb_node_dxstr_t;
750 typedef struct RNode_EVSTR {
751 NODE node;
753 struct RNode *nd_body;
754 } rb_node_evstr_t;
756 typedef struct RNode_REGX {
757 NODE node;
759 struct rb_parser_string *string;
760 int options;
761 } rb_node_regx_t;
763 typedef struct RNode_DREGX {
764 NODE node;
766 struct rb_parser_string *string;
767 ID nd_cflag;
768 struct RNode_LIST *nd_next;
769 } rb_node_dregx_t;
771 typedef struct RNode_ONCE {
772 NODE node;
774 struct RNode *nd_body;
775 } rb_node_once_t;
777 struct rb_args_info {
778 NODE *pre_init;
779 NODE *post_init;
781 int pre_args_num; /* count of mandatory pre-arguments */
782 int post_args_num; /* count of mandatory post-arguments */
784 ID first_post_arg;
786 ID rest_arg;
787 ID block_arg;
789 struct RNode_KW_ARG *kw_args;
790 NODE *kw_rest_arg;
792 struct RNode_OPT_ARG *opt_args;
793 unsigned int no_kwarg: 1;
794 unsigned int ruby2_keywords: 1;
795 unsigned int forwarding: 1;
798 typedef struct RNode_ARGS {
799 NODE node;
801 struct rb_args_info nd_ainfo;
802 } rb_node_args_t;
804 typedef struct RNode_ARGS_AUX {
805 NODE node;
807 ID nd_pid;
808 int nd_plen;
809 struct RNode *nd_next;
810 } rb_node_args_aux_t;
812 typedef struct RNode_OPT_ARG {
813 NODE node;
815 struct RNode *nd_body;
816 struct RNode_OPT_ARG *nd_next;
817 } rb_node_opt_arg_t;
819 typedef struct RNode_KW_ARG {
820 NODE node;
822 struct RNode *nd_body;
823 struct RNode_KW_ARG *nd_next;
824 } rb_node_kw_arg_t;
826 typedef struct RNode_POSTARG {
827 NODE node;
829 struct RNode *nd_1st;
830 struct RNode *nd_2nd;
831 } rb_node_postarg_t;
833 typedef struct RNode_ARGSCAT {
834 NODE node;
836 struct RNode *nd_head;
837 struct RNode *nd_body;
838 } rb_node_argscat_t;
840 typedef struct RNode_ARGSPUSH {
841 NODE node;
843 struct RNode *nd_head;
844 struct RNode *nd_body;
845 } rb_node_argspush_t;
847 typedef struct RNode_SPLAT {
848 NODE node;