Ruby 3.3.0p0 (2023-12-25 revision 5124f9ac7513eb590c37717337c430cb93caa151)
rubyparser.h
1#ifndef RUBY_RUBYPARSER_H
2#define RUBY_RUBYPARSER_H 1
3/*
4 * This is a header file for librubyparser interface
5 */
6
7#include <stdarg.h> /* for va_list */
8#include <assert.h>
9
10#ifdef UNIVERSAL_PARSER
11
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
18
19#else
20
21#include "ruby/encoding.h"
22
23#endif
24
25/*
26 * AST Node
27 */
28enum node_type {
29 NODE_SCOPE,
30 NODE_BLOCK,
31 NODE_IF,
32 NODE_UNLESS,
33 NODE_CASE,
34 NODE_CASE2,
35 NODE_CASE3,
36 NODE_WHEN,
37 NODE_IN,
38 NODE_WHILE,
39 NODE_UNTIL,
40 NODE_ITER,
41 NODE_FOR,
42 NODE_FOR_MASGN,
43 NODE_BREAK,
44 NODE_NEXT,
45 NODE_REDO,
46 NODE_RETRY,
47 NODE_BEGIN,
48 NODE_RESCUE,
49 NODE_RESBODY,
50 NODE_ENSURE,
51 NODE_AND,
52 NODE_OR,
53 NODE_MASGN,
54 NODE_LASGN,
55 NODE_DASGN,
56 NODE_GASGN,
57 NODE_IASGN,
58 NODE_CDECL,
59 NODE_CVASGN,
60 NODE_OP_ASGN1,
61 NODE_OP_ASGN2,
62 NODE_OP_ASGN_AND,
63 NODE_OP_ASGN_OR,
64 NODE_OP_CDECL,
65 NODE_CALL,
66 NODE_OPCALL,
67 NODE_FCALL,
68 NODE_VCALL,
69 NODE_QCALL,
70 NODE_SUPER,
71 NODE_ZSUPER,
72 NODE_LIST,
73 NODE_ZLIST,
74 NODE_HASH,
75 NODE_RETURN,
76 NODE_YIELD,
77 NODE_LVAR,
78 NODE_DVAR,
79 NODE_GVAR,
80 NODE_IVAR,
81 NODE_CONST,
82 NODE_CVAR,
83 NODE_NTH_REF,
84 NODE_BACK_REF,
85 NODE_MATCH,
86 NODE_MATCH2,
87 NODE_MATCH3,
88 NODE_LIT,
89 NODE_STR,
90 NODE_DSTR,
91 NODE_XSTR,
92 NODE_DXSTR,
93 NODE_EVSTR,
94 NODE_DREGX,
95 NODE_ONCE,
96 NODE_ARGS,
97 NODE_ARGS_AUX,
98 NODE_OPT_ARG,
99 NODE_KW_ARG,
100 NODE_POSTARG,
101 NODE_ARGSCAT,
102 NODE_ARGSPUSH,
103 NODE_SPLAT,
104 NODE_BLOCK_PASS,
105 NODE_DEFN,
106 NODE_DEFS,
107 NODE_ALIAS,
108 NODE_VALIAS,
109 NODE_UNDEF,
110 NODE_CLASS,
111 NODE_MODULE,
112 NODE_SCLASS,
113 NODE_COLON2,
114 NODE_COLON3,
115 NODE_DOT2,
116 NODE_DOT3,
117 NODE_FLIP2,
118 NODE_FLIP3,
119 NODE_SELF,
120 NODE_NIL,
121 NODE_TRUE,
122 NODE_FALSE,
123 NODE_ERRINFO,
124 NODE_DEFINED,
125 NODE_POSTEXE,
126 NODE_DSYM,
127 NODE_ATTRASGN,
128 NODE_LAMBDA,
129 NODE_ARYPTN,
130 NODE_HSHPTN,
131 NODE_FNDPTN,
132 NODE_ERROR,
133 NODE_RIPPER,
134 NODE_RIPPER_VALUES,
135 NODE_LAST
136};
137
138#ifndef FLEX_ARY_LEN
139/* From internal/compilers.h */
140/* A macro for defining a flexible array, like: VALUE ary[FLEX_ARY_LEN]; */
141#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
142# define FLEX_ARY_LEN /* VALUE ary[]; */
143#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
144# define FLEX_ARY_LEN 0 /* VALUE ary[0]; */
145#else
146# define FLEX_ARY_LEN 1 /* VALUE ary[1]; */
147#endif
148#endif
149
150typedef struct rb_ast_id_table {
151 int size;
152 ID ids[FLEX_ARY_LEN];
154
156 int lineno;
157 int column;
159
164
165/* Header part of AST Node */
166typedef struct RNode {
167 VALUE flags;
168 rb_code_location_t nd_loc;
169 int node_id;
170} NODE;
171
172typedef struct RNode_SCOPE {
173 NODE node;
174
175 rb_ast_id_table_t *nd_tbl;
176 struct RNode *nd_body;
177 struct RNode_ARGS *nd_args;
179
180typedef struct RNode_BLOCK {
181 NODE node;
182
183 struct RNode *nd_head;
184 struct RNode *nd_end;
185 struct RNode *nd_next;
187
188typedef struct RNode_IF {
189 NODE node;
190
191 struct RNode *nd_cond;
192 struct RNode *nd_body;
193 struct RNode *nd_else;
195
196typedef struct RNode_UNLESS {
197 NODE node;
198
199 struct RNode *nd_cond;
200 struct RNode *nd_body;
201 struct RNode *nd_else;
203
204typedef struct RNode_CASE {
205 NODE node;
206
207 struct RNode *nd_head;
208 struct RNode *nd_body;
210
211typedef struct RNode_CASE2 {
212 NODE node;
213
214 struct RNode *nd_head;
215 struct RNode *nd_body;
217
218typedef struct RNode_CASE3 {
219 NODE node;
220
221 struct RNode *nd_head;
222 struct RNode *nd_body;
224
225typedef struct RNode_WHEN {
226 NODE node;
227
228 struct RNode *nd_head;
229 struct RNode *nd_body;
230 struct RNode *nd_next;
232
233typedef struct RNode_IN {
234 NODE node;
235
236 struct RNode *nd_head;
237 struct RNode *nd_body;
238 struct RNode *nd_next;
240
241/* RNode_WHILE and RNode_UNTIL should be same structure */
242typedef struct RNode_WHILE {
243 NODE node;
244
245 struct RNode *nd_cond;
246 struct RNode *nd_body;
247 long nd_state;
249
250typedef struct RNode_UNTIL {
251 NODE node;
252
253 struct RNode *nd_cond;
254 struct RNode *nd_body;
255 long nd_state;
257
258/* RNode_ITER and RNode_FOR should be same structure */
259typedef struct RNode_ITER {
260 NODE node;
261
262 struct RNode *nd_body;
263 struct RNode *nd_iter;
265
266typedef struct RNode_FOR {
267 NODE node;
268
269 struct RNode *nd_body;
270 struct RNode *nd_iter;
272
273typedef struct RNode_FOR_MASGN {
274 NODE node;
275
276 struct RNode *nd_var;
278
279/* RNode_BREAK, RNode_NEXT and RNode_REDO should be same structure */
280typedef struct RNode_BREAK {
281 NODE node;
282
283 struct RNode *nd_chain;
284 struct RNode *nd_stts;
286
287typedef struct RNode_NEXT {
288 NODE node;
289
290 struct RNode *nd_chain;
291 struct RNode *nd_stts;
293
294typedef struct RNode_REDO {
295 NODE node;
296
297 struct RNode *nd_chain;
299
300typedef struct RNode_RETRY {
301 NODE node;
303
304typedef struct RNode_BEGIN {
305 NODE node;
306
307 struct RNode *nd_body;
309
310typedef struct RNode_RESCUE {
311 NODE node;
312
313 struct RNode *nd_head;
314 struct RNode *nd_resq;
315 struct RNode *nd_else;
317
318typedef struct RNode_RESBODY {
319 NODE node;
320
321 struct RNode *nd_head;
322 struct RNode *nd_body;
323 struct RNode *nd_args;
325
326typedef struct RNode_ENSURE {
327 NODE node;
328
329 struct RNode *nd_head;
330 struct RNode *nd_resq; /* Maybe not used other than reduce_nodes */
331 struct RNode *nd_ensr;
333
334/* RNode_AND and RNode_OR should be same structure */
335typedef struct RNode_AND {
336 NODE node;
337
338 struct RNode *nd_1st;
339 struct RNode *nd_2nd;
341
342typedef struct RNode_OR {
343 NODE node;
344
345 struct RNode *nd_1st;
346 struct RNode *nd_2nd;
348
349typedef struct RNode_MASGN {
350 NODE node;
351
352 struct RNode *nd_head;
353 struct RNode *nd_value;
354 struct RNode *nd_args;
356
357typedef struct RNode_LASGN {
358 NODE node;
359
360 ID nd_vid;
361 struct RNode *nd_value;
363
364typedef struct RNode_DASGN {
365 NODE node;
366
367 ID nd_vid;
368 struct RNode *nd_value;
370
371typedef struct RNode_GASGN {
372 NODE node;
373
374 ID nd_vid;
375 struct RNode *nd_value;
377
378typedef struct RNode_IASGN {
379 NODE node;
380
381 ID nd_vid;
382 struct RNode *nd_value;
384
385typedef struct RNode_CDECL {
386 NODE node;
387
388 ID nd_vid;
389 struct RNode *nd_value;
390 struct RNode *nd_else;
392
393typedef struct RNode_CVASGN {
394 NODE node;
395
396 ID nd_vid;
397 struct RNode *nd_value;
399
400typedef struct RNode_OP_ASGN1 {
401 NODE node;
402
403 struct RNode *nd_recv;
404 ID nd_mid;
405 struct RNode *nd_index;
406 struct RNode *nd_rvalue;
408
409typedef struct RNode_OP_ASGN2 {
410 NODE node;
411
412 struct RNode *nd_recv;
413 struct RNode *nd_value;
414 ID nd_vid;
415 ID nd_mid;
416 bool nd_aid;
418
419typedef struct RNode_OP_ASGN_AND {
420 NODE node;
421
422 struct RNode *nd_head;
423 struct RNode *nd_value;
425
426typedef struct RNode_OP_ASGN_OR {
427 NODE node;
428
429 struct RNode *nd_head;
430 struct RNode *nd_value;
432
433typedef struct RNode_OP_CDECL {
434 NODE node;
435
436 struct RNode *nd_head;
437 struct RNode *nd_value;
438 ID nd_aid;
440
441typedef struct RNode_CALL {
442 NODE node;
443
444 struct RNode *nd_recv;
445 ID nd_mid;
446 struct RNode *nd_args;
448
449typedef struct RNode_OPCALL {
450 NODE node;
451
452 struct RNode *nd_recv;
453 ID nd_mid;
454 struct RNode *nd_args;
456
457typedef struct RNode_FCALL {
458 NODE node;
459
460 ID nd_mid;
461 struct RNode *nd_args;
463
464typedef struct RNode_VCALL {
465 NODE node;
466
467 ID nd_mid;
469
470typedef struct RNode_QCALL {
471 NODE node;
472
473 struct RNode *nd_recv;
474 ID nd_mid;
475 struct RNode *nd_args;
477
478typedef struct RNode_SUPER {
479 NODE node;
480
481 struct RNode *nd_args;
483
484typedef struct RNode_ZSUPER {
485 NODE node;
487
488/*
489
490 Structure of LIST:
491
492 LIST +--> LIST
493 * head --> element | * head
494 * alen (length of list) | * nd_end (point to the last LIST)
495 * next -----------------+ * next
496
497
498 RNode_LIST and RNode_VALUES should be same structure
499*/
500typedef struct RNode_LIST {
501 NODE node;
502
503 struct RNode *nd_head; /* element */
504 union {
505 long nd_alen;
506 struct RNode *nd_end; /* Second list node has this structure */
507 } as;
508 struct RNode *nd_next; /* next list node */
510
511typedef struct RNode_ZLIST {
512 NODE node;
514
515typedef struct RNode_VALUES {
516 NODE node;
517
518 struct RNode *nd_head;
519 long nd_alen;
520 struct RNode *nd_next;
522
523typedef struct RNode_HASH {
524 NODE node;
525
526 struct RNode *nd_head;
527 long nd_brace;
529
530typedef struct RNode_RETURN {
531 NODE node;
532
533 struct RNode *nd_stts;
535
536typedef struct RNode_YIELD {
537 NODE node;
538
539 struct RNode *nd_head;
541
542typedef struct RNode_LVAR {
543 NODE node;
544
545 ID nd_vid;
547
548typedef struct RNode_DVAR {
549 NODE node;
550
551 ID nd_vid;
553
554typedef struct RNode_GVAR {
555 NODE node;
556
557 ID nd_vid;
559
560typedef struct RNode_IVAR {
561 NODE node;
562
563 ID nd_vid;
565
566typedef struct RNode_CONST {
567 NODE node;
568
569 ID nd_vid;
571
572typedef struct RNode_CVAR {
573 NODE node;
574
575 ID nd_vid;
577
578typedef struct RNode_NTH_REF {
579 NODE node;
580
581 long nd_nth;
583
584typedef struct RNode_BACK_REF {
585 NODE node;
586
587 long nd_nth;
589
590/* RNode_MATCH, RNode_LIT, RNode_STR and RNode_XSTR should be same structure */
591typedef struct RNode_MATCH {
592 NODE node;
593
594 VALUE nd_lit;
596
597typedef struct RNode_MATCH2 {
598 NODE node;
599
600 struct RNode *nd_recv;
601 struct RNode *nd_value;
602 struct RNode *nd_args;
604
605typedef struct RNode_MATCH3 {
606 NODE node;
607
608 struct RNode *nd_recv;
609 struct RNode *nd_value;
611
612typedef struct RNode_LIT {
613 NODE node;
614
615 VALUE nd_lit;
617
618typedef struct RNode_STR {
619 NODE node;
620
621 VALUE nd_lit;
623
624/* RNode_DSTR, RNode_DXSTR and RNode_DSYM should be same structure */
625typedef struct RNode_DSTR {
626 NODE node;
627
628 VALUE nd_lit;
629 union {
630 long nd_alen;
631 struct RNode *nd_end; /* Second dstr node has this structure. See also RNode_LIST */
632 } as;
633 struct RNode_LIST *nd_next;
635
636typedef struct RNode_XSTR {
637 NODE node;
638
639 VALUE nd_lit;
641
642typedef struct RNode_DXSTR {
643 NODE node;
644
645 VALUE nd_lit;
646 long nd_alen;
647 struct RNode_LIST *nd_next;
649
650typedef struct RNode_EVSTR {
651 NODE node;
652
653 struct RNode *nd_body;
655
656typedef struct RNode_DREGX {
657 NODE node;
658
659 VALUE nd_lit;
660 ID nd_cflag;
661 struct RNode_LIST *nd_next;
663
664typedef struct RNode_ONCE {
665 NODE node;
666
667 struct RNode *nd_body;
669
671 NODE *pre_init;
672 NODE *post_init;
673
674 int pre_args_num; /* count of mandatory pre-arguments */
675 int post_args_num; /* count of mandatory post-arguments */
676
677 ID first_post_arg;
678
679 ID rest_arg;
680 ID block_arg;
681
682 struct RNode_KW_ARG *kw_args;
683 NODE *kw_rest_arg;
684
685 struct RNode_OPT_ARG *opt_args;
686 unsigned int no_kwarg: 1;
687 unsigned int ruby2_keywords: 1;
688 unsigned int forwarding: 1;
689};
690
691typedef struct RNode_ARGS {
692 NODE node;
693
694 struct rb_args_info nd_ainfo;
696
697typedef struct RNode_ARGS_AUX {
698 NODE node;
699
700 ID nd_pid;
701 long nd_plen;
702 struct RNode *nd_next;
704
705typedef struct RNode_OPT_ARG {
706 NODE node;
707
708 struct RNode *nd_body;
709 struct RNode_OPT_ARG *nd_next;
711
712typedef struct RNode_KW_ARG {
713 NODE node;
714
715 struct RNode *nd_body;
716 struct RNode_KW_ARG *nd_next;
718
719typedef struct RNode_POSTARG {
720 NODE node;
721
722 struct RNode *nd_1st;
723 struct RNode *nd_2nd;
725
726typedef struct RNode_ARGSCAT {
727 NODE node;
728
729 struct RNode *nd_head;
730 struct RNode *nd_body;
732
733typedef struct RNode_ARGSPUSH {
734 NODE node;
735
736 struct RNode *nd_head;
737 struct RNode *nd_body;
739
740typedef struct RNode_SPLAT {
741 NODE node;
742
743 struct RNode *nd_head;
745
746typedef struct RNode_BLOCK_PASS {
747 NODE node;
748
749 struct RNode *nd_head;
750 struct RNode *nd_body;
752
753typedef struct RNode_DEFN {
754 NODE node;
755
756 ID nd_mid;
757 struct RNode *nd_defn;
759
760typedef struct RNode_DEFS {
761 NODE node;
762
763 struct RNode *nd_recv;
764 ID nd_mid;
765 struct RNode *nd_defn;
767
768typedef struct RNode_ALIAS {
769 NODE node;
770
771 struct RNode *nd_1st;
772 struct RNode *nd_2nd;
774
775typedef struct RNode_VALIAS {
776 NODE node;
777
778 ID nd_alias;
779 ID nd_orig;
781
782typedef struct RNode_UNDEF {
783 NODE node;
784
785 struct RNode *nd_undef;
787
788typedef struct RNode_CLASS {
789 NODE node;
790
791 struct RNode *nd_cpath;
792 struct RNode *nd_body;
793 struct RNode *nd_super;
795
796typedef struct RNode_MODULE {
797 NODE node;
798
799 struct RNode *nd_cpath;
800 struct RNode *nd_body;
802
803typedef struct RNode_SCLASS {
804 NODE node;
805
806 struct RNode *nd_recv;
807 struct RNode *nd_body;
809
810typedef struct RNode_COLON2 {
811 NODE node;
812
813 struct RNode *nd_head;
814 ID nd_mid;
816
817typedef struct RNode_COLON3 {
818 NODE node;
819
820 ID nd_mid;
822
823/* RNode_DOT2, RNode_DOT3, RNode_FLIP2 and RNode_FLIP3 should be same structure */
824typedef struct RNode_DOT2 {
825 NODE node;
826
827 struct RNode *nd_beg;
828 struct RNode *nd_end;
830
831typedef struct RNode_DOT3 {
832 NODE node;
833
834 struct RNode *nd_beg;
835 struct RNode *nd_end;
837
838typedef struct RNode_FLIP2 {
839 NODE node;
840
841 struct RNode *nd_beg;
842 struct RNode *nd_end;
844
845typedef struct RNode_FLIP3 {
846 NODE node;
847
848 struct RNode *nd_beg;
849 struct RNode *nd_end;
851
852typedef struct RNode_SELF {
853 NODE node;
854
855 long nd_state; /* Default 1. See NEW_SELF. */
857
858typedef struct RNode_NIL {
859 NODE node;
861
862typedef struct RNode_TRUE {
863 NODE node;
865
866typedef struct RNode_FALSE {
867 NODE node;
869
870typedef struct RNode_ERRINFO {
871 NODE node;
873
874typedef struct RNode_DEFINED {
875 NODE node;
876
877 struct RNode *nd_head;
879
880typedef struct RNode_POSTEXE {
881 NODE node;
882
883 struct RNode *nd_body;
885
886typedef struct RNode_DSYM {
887 NODE node;
888
889 VALUE nd_lit;
890 long nd_alen;
891 struct RNode_LIST *nd_next;
893
894typedef struct RNode_ATTRASGN {
895 NODE node;
896
897 struct RNode *nd_recv;
898 ID nd_mid;
899 struct RNode *nd_args;
901
902typedef struct RNode_LAMBDA {
903 NODE node;
904
905 struct RNode *nd_body;
907
908typedef struct RNode_ARYPTN {
909 NODE node;
910
911 struct RNode *nd_pconst;
912 NODE *pre_args;
913 NODE *rest_arg;
914 NODE *post_args;
916
917typedef struct RNode_HSHPTN {
918 NODE node;
919
920 struct RNode *nd_pconst;
921 struct RNode *nd_pkwargs;
922 struct RNode *nd_pkwrestarg;
924
925typedef struct RNode_FNDPTN {
926 NODE node;
927
928 struct RNode *nd_pconst;
929 NODE *pre_rest_arg;
930 NODE *args;
931 NODE *post_rest_arg;
933
934typedef struct RNode_ERROR {
935 NODE node;
937
938#define RNODE(obj) ((struct RNode *)(obj))
939
940#define RNODE_SCOPE(node) ((struct RNode_SCOPE *)(node))
941#define RNODE_BLOCK(node) ((struct RNode_BLOCK *)(node))
942#define RNODE_IF(node) ((struct RNode_IF *)(node))
943#define RNODE_UNLESS(node) ((struct RNode_UNLESS *)(node))
944#define RNODE_CASE(node) ((struct RNode_CASE *)(node))
945#define RNODE_CASE2(node) ((struct RNode_CASE2 *)(node))
946#define RNODE_CASE3(node) ((struct RNode_CASE3 *)(node))
947#define RNODE_WHEN(node) ((struct RNode_WHEN *)(node))
948#define RNODE_IN(node) ((struct RNode_IN *)(node))
949#define RNODE_WHILE(node) ((struct RNode_WHILE *)(node))
950#define RNODE_UNTIL(node) ((struct RNode_UNTIL *)(node))
951#define RNODE_ITER(node) ((struct RNode_ITER *)(node))
952#define RNODE_FOR(node) ((struct RNode_FOR *)(node))
953#define RNODE_FOR_MASGN(node) ((struct RNode_FOR_MASGN *)(node))
954#define RNODE_BREAK(node) ((struct RNode_BREAK *)(node))
955#define RNODE_NEXT(node) ((struct RNode_NEXT *)(node))
956#define RNODE_REDO(node) ((struct RNode_REDO *)(node))
957#define RNODE_RETRY(node) ((struct RNode_RETRY *)(node))
958#define RNODE_BEGIN(node) ((struct RNode_BEGIN *)(node))
959#define RNODE_RESCUE(node) ((struct RNode_RESCUE *)(node))
960#define RNODE_RESBODY(node) ((struct RNode_RESBODY *)(node))
961#define RNODE_ENSURE(node) ((struct RNode_ENSURE *)(node))
962#define RNODE_AND(node) ((struct RNode_AND *)(node))
963#define RNODE_OR(node) ((struct RNode_OR *)(node))
964#define RNODE_MASGN(node) ((struct RNode_MASGN *)(node))
965#define RNODE_LASGN(node) ((struct RNode_LASGN *)(node))
966#define RNODE_DASGN(node) ((struct RNode_DASGN *)(node))
967#define RNODE_GASGN(node) ((struct RNode_GASGN *)(node))
968#define RNODE_IASGN(node) ((struct RNode_IASGN *)(node))
969#define RNODE_CDECL(node) ((struct RNode_CDECL *)(node))
970#define RNODE_CVASGN(node) ((struct RNode_CVASGN *)(node))
971#define RNODE_OP_ASGN1(node) ((struct RNode_OP_ASGN1 *)(node))
972#define RNODE_OP_ASGN2(node) ((struct RNode_OP_ASGN2 *)(node))
973#define RNODE_OP_ASGN_AND(node) ((struct RNode_OP_ASGN_AND *)(node))
974#define RNODE_OP_ASGN_OR(node) ((struct RNode_OP_ASGN_OR *)(node))
975#define RNODE_OP_CDECL(node) ((struct RNode_OP_CDECL *)(node))
976#define RNODE_CALL(node) ((struct RNode_CALL *)(node))
977#define RNODE_OPCALL(node) ((struct RNode_OPCALL *)(node))
978#define RNODE_FCALL(node) ((struct RNode_FCALL *)(node))
979#define RNODE_VCALL(node) ((struct RNode_VCALL *)(node))
980#define RNODE_QCALL(node) ((struct RNode_QCALL *)(node))
981#define RNODE_SUPER(node) ((struct RNode_SUPER *)(node))
982#define RNODE_ZSUPER(node) ((struct RNode_ZSUPER *)(node))
983#define RNODE_LIST(node) ((struct RNode_LIST *)(node))
984#define RNODE_ZLIST(node) ((struct RNode_ZLIST *)(node))
985#define RNODE_HASH(node) ((struct RNode_HASH *)(node))
986#define RNODE_RETURN(node) ((struct RNode_RETURN *)(node))
987#define RNODE_YIELD(node) ((struct RNode_YIELD *)(node))
988#define RNODE_LVAR(node) ((struct RNode_LVAR *)(node))
989#define RNODE_DVAR(node) ((struct RNode_DVAR *)(node))
990#define RNODE_GVAR(node) ((struct RNode_GVAR *)(node))
991#define RNODE_IVAR(node) ((struct RNode_IVAR *)(node))
992#define RNODE_CONST(node) ((struct RNode_CONST *)(node))
993#define RNODE_CVAR(node) ((struct RNode_CVAR *)(node))
994#define RNODE_NTH_REF(node) ((struct RNode_NTH_REF *)(node))
995#define RNODE_BACK_REF(node) ((struct RNode_BACK_REF *)(node))
996#define RNODE_MATCH(node) ((struct RNode_MATCH *)(node))
997#define RNODE_MATCH2(node) ((struct RNode_MATCH2 *)(node))
998#define RNODE_MATCH3(node) ((struct RNode_MATCH3 *)(node))
999#define RNODE_LIT(node) ((struct RNode_LIT *)(node))
1000#define RNODE_STR(node) ((struct RNode_STR *)(node))
1001#define RNODE_DSTR(node) ((struct RNode_DSTR *)(node))
1002#define RNODE_XSTR(node) ((struct RNode_XSTR *)(node))
1003#define RNODE_DXSTR(node) ((struct RNode_DXSTR *)(node))
1004#define RNODE_EVSTR(node) ((struct RNode_EVSTR *)(node))
1005#define RNODE_DREGX(node) ((struct RNode_DREGX *)(node))
1006#define RNODE_ONCE(node) ((struct RNode_ONCE *)(node))
1007#define RNODE_ARGS(node) ((struct RNode_ARGS *)(node))
1008#define RNODE_ARGS_AUX(node) ((struct RNode_ARGS_AUX *)(node))
1009#define RNODE_OPT_ARG(node) ((struct RNode_OPT_ARG *)(node))
1010#define RNODE_KW_ARG(node) ((struct RNode_KW_ARG *)(node))
1011#define RNODE_POSTARG(node) ((struct RNode_POSTARG *)(node))
1012#define RNODE_ARGSCAT(node) ((struct RNode_ARGSCAT *)(node))
1013#define RNODE_ARGSPUSH(node) ((struct RNode_ARGSPUSH *)(node))
1014#define RNODE_SPLAT(node) ((struct RNode_SPLAT *)(node))
1015#define RNODE_BLOCK_PASS(node) ((struct RNode_BLOCK_PASS *)(node))
1016#define RNODE_DEFN(node) ((struct RNode_DEFN *)(node))
1017#define RNODE_DEFS(node) ((struct RNode_DEFS *)(node))
1018#define RNODE_ALIAS(node) ((struct RNode_ALIAS *)(node))
1019#define RNODE_VALIAS(node) ((struct RNode_VALIAS *)(node))
1020#define RNODE_UNDEF(node) ((struct RNode_UNDEF *)(node))
1021#define RNODE_CLASS(node) ((struct RNode_CLASS *)(node))
1022#define RNODE_MODULE(node) ((struct RNode_MODULE *)(node))
1023#define RNODE_SCLASS(node) ((struct RNode_SCLASS *)(node))
1024#define RNODE_COLON2(node) ((struct RNode_COLON2 *)(node))
1025#define RNODE_COLON3(node) ((struct RNode_COLON3 *)(node))
1026#define RNODE_DOT2(node) ((struct RNode_DOT2 *)(node))
1027#define RNODE_DOT3(node) ((struct RNode_DOT3 *)(node))
1028#define RNODE_FLIP2(node) ((struct RNode_FLIP2 *)(node))
1029#define RNODE_FLIP3(node) ((struct RNode_FLIP3 *)(node))
1030#define RNODE_SELF(node) ((struct RNode_SELF *)(node))
1031#define RNODE_NIL(node) ((struct RNode_NIL *)(node))
1032#define RNODE_TRUE(node) ((struct RNode_TRUE *)(node))
1033#define RNODE_FALSE(node) ((struct RNode_FALSE *)(node))
1034#define RNODE_ERRINFO(node) ((struct RNode_ERRINFO *)(node))
1035#define RNODE_DEFINED(node) ((struct RNode_DEFINED *)(node))
1036#define RNODE_POSTEXE(node) ((struct RNode_POSTEXE *)(node))
1037#define RNODE_DSYM(node) ((struct RNode_DSYM *)(node))
1038#define RNODE_ATTRASGN(node) ((struct RNode_ATTRASGN *)(node))
1039#define RNODE_LAMBDA(node) ((struct RNode_LAMBDA *)(node))
1040#define RNODE_ARYPTN(node) ((struct RNode_ARYPTN *)(node))
1041#define RNODE_HSHPTN(node) ((struct RNode_HSHPTN *)(node))
1042#define RNODE_FNDPTN(node) ((struct RNode_FNDPTN *)(node))
1043
1044#ifdef RIPPER
1045typedef struct RNode_RIPPER {
1046 NODE node;
1047
1048 ID nd_vid;
1049 VALUE nd_rval;
1050 VALUE nd_cval;
1051} rb_node_ripper_t;
1052
1053typedef struct RNode_RIPPER_VALUES {
1054 NODE node;
1055
1056 VALUE nd_val1;
1057 VALUE nd_val2;
1058 VALUE nd_val3;
1059} rb_node_ripper_values_t;
1060
1061#define RNODE_RIPPER(node) ((struct RNode_RIPPER *)(node))
1062#define RNODE_RIPPER_VALUES(node) ((struct RNode_RIPPER_VALUES *)(node))
1063#endif
1064
1065/* FL : 0..4: T_TYPES, 5: KEEP_WB, 6: PROMOTED, 7: FINALIZE, 8: UNUSED, 9: UNUSED, 10: EXIVAR, 11: FREEZE */
1066/* NODE_FL: 0..4: T_TYPES, 5: KEEP_WB, 6: PROMOTED, 7: NODE_FL_NEWLINE,
1067 * 8..14: nd_type,
1068 * 15..: nd_line
1069 */
1070#define NODE_FL_NEWLINE (((VALUE)1)<<7)
1071
1072#define NODE_TYPESHIFT 8
1073#define NODE_TYPEMASK (((VALUE)0x7f)<<NODE_TYPESHIFT)
1074
1075#define nd_fl_newline(n) (n)->flags & NODE_FL_NEWLINE
1076#define nd_set_fl_newline(n) (n)->flags |= NODE_FL_NEWLINE
1077#define nd_unset_fl_newline(n) (n)->flags &= ~NODE_FL_NEWLINE
1078
1079#define nd_type(n) ((int) ((RNODE(n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
1080#define nd_set_type(n,t) \
1081 rb_node_set_type(n, t)
1082#define nd_init_type(n,t) \
1083 (n)->flags=(((n)->flags&~NODE_TYPEMASK)|((((unsigned long)(t))<<NODE_TYPESHIFT)&NODE_TYPEMASK))
1084
1085typedef struct node_buffer_struct node_buffer_t;
1086/* T_IMEMO/ast */
1087typedef struct rb_ast_body_struct {
1088 const NODE *root;
1089 VALUE script_lines;
1090 // script_lines is either:
1091 // - a Fixnum that represents the line count of the original source, or
1092 // - an Array that contains the lines of the original source
1093 signed int frozen_string_literal:2; /* -1: not specified, 0: false, 1: true */
1094 signed int coverage_enabled:2; /* -1: not specified, 0: false, 1: true */
1096typedef struct rb_ast_struct {
1097 VALUE flags;
1098 node_buffer_t *node_buffer;
1099 rb_ast_body_t body;
1100} rb_ast_t;
1101
1102
1103
1104/*
1105 * Parser Interface
1106 */
1107
1108
1109typedef struct parser_params rb_parser_t;
1110#ifndef INTERNAL_IMEMO_H
1112#endif
1113
1114#ifdef UNIVERSAL_PARSER
1115typedef struct rb_parser_config_struct {
1116 /*
1117 * Reference counter.
1118 * This is needed because both parser and ast refer
1119 * same config pointer.
1120 * We can remove this, once decuple parser and ast from Ruby GC.
1121 */
1122 int counter;
1123
1124 /* Memory */
1125 void *(*malloc)(size_t size);
1126 void *(*calloc)(size_t number, size_t size);
1127 void *(*realloc)(void *ptr, size_t newsiz);
1128 void (*free)(void *ptr);
1129 void *(*alloc_n)(size_t nelems, size_t elemsiz);
1130 void *(*alloc)(size_t elemsiz);
1131 void *(*realloc_n)(void *ptr, size_t newelems, size_t newsiz);
1132 void *(*zalloc)(size_t elemsiz);
1133 void *(*rb_memmove)(void *dest, const void *src, size_t t, size_t n);
1134 void *(*nonempty_memcpy)(void *dest, const void *src, size_t t, size_t n);
1135 void *(*xmalloc_mul_add)(size_t x, size_t y, size_t z);
1136
1137 /* imemo */
1138 rb_imemo_tmpbuf_t *(*tmpbuf_parser_heap)(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
1139 rb_ast_t *(*ast_new)(VALUE nb);
1140
1141 // VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
1142 VALUE (*compile_callback)(VALUE (*func)(VALUE), VALUE arg);
1143 NODE *(*reg_named_capture_assign)(struct parser_params* p, VALUE regexp, const rb_code_location_t *loc);
1144
1145 /* Object */
1146 VALUE (*obj_freeze)(VALUE obj);
1147 VALUE (*obj_hide)(VALUE obj);
1148 int (*obj_frozen)(VALUE obj);
1149 int (*type_p)(VALUE, int);
1150 void (*obj_freeze_raw)(VALUE obj);
1151
1152 int (*fixnum_p)(VALUE);
1153 int (*symbol_p)(VALUE);
1154
1155 /* Variable */
1156 VALUE (*attr_get)(VALUE obj, ID id);
1157
1158 /* Array */
1159 VALUE (*ary_new)(void);
1160 VALUE (*ary_push)(VALUE ary, VALUE elem);
1161 VALUE (*ary_new_from_args)(long n, ...);
1162 VALUE (*ary_pop)(VALUE ary);
1163 VALUE (*ary_last)(int argc, const VALUE *argv, VALUE ary);
1164 VALUE (*ary_unshift)(VALUE ary, VALUE item);
1165 VALUE (*ary_new2)(long capa); // ary_new_capa
1166 VALUE (*ary_entry)(VALUE ary, long offset);
1167 VALUE (*ary_join)(VALUE ary, VALUE sep);
1168 VALUE (*ary_reverse)(VALUE ary);
1169 VALUE (*ary_clear)(VALUE ary);
1170 long (*array_len)(VALUE a);
1171 VALUE (*array_aref)(VALUE, long);
1172
1173 /* Symbol */
1174 VALUE (*sym_intern_ascii_cstr)(const char *ptr);
1175 ID (*make_temporary_id)(size_t n);
1176 int (*is_local_id)(ID);
1177 int (*is_attrset_id)(ID);
1178 int (*is_global_name_punct)(const int c);
1179 int (*id_type)(ID id);
1180 ID (*id_attrset)(ID);
1181 ID (*intern)(const char *name);
1182 ID (*intern2)(const char *name, long len);
1183 ID (*intern3)(const char *name, long len, rb_encoding *enc);
1184 ID (*intern_str)(VALUE str);
1185 int (*is_notop_id)(ID);
1186 int (*enc_symname_type)(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset);
1187 VALUE (*str_intern)(VALUE str);
1188 const char *(*id2name)(ID id);
1189 VALUE (*id2str)(ID id);
1190 VALUE (*id2sym)(ID x);
1191 ID (*sym2id)(VALUE sym);
1192
1193 /* String */
1194 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
1195 VALUE (*str_catf)(VALUE str, const char *format, ...);
1196 VALUE (*str_cat_cstr)(VALUE str, const char *ptr);
1197 VALUE (*str_subseq)(VALUE str, long beg, long len);
1198 VALUE (*str_dup)(VALUE str);
1199 VALUE (*str_new_frozen)(VALUE orig);
1200 VALUE (*str_buf_new)(long capa);
1201 VALUE (*str_buf_cat)(VALUE, const char*, long);
1202 void (*str_modify)(VALUE str);
1203 void (*str_set_len)(VALUE str, long len);
1204 VALUE (*str_cat)(VALUE str, const char *ptr, long len);
1205 VALUE (*str_resize)(VALUE str, long len);
1206 VALUE (*str_new)(const char *ptr, long len);
1207 VALUE (*str_new_cstr)(const char *ptr);
1208 VALUE (*fstring)(VALUE);
1209 int (*is_ascii_string)(VALUE str);
1210 VALUE (*enc_str_new)(const char *ptr, long len, rb_encoding *enc);
1211 VALUE (*enc_str_buf_cat)(VALUE str, const char *ptr, long len, rb_encoding *enc);
1212 VALUE (*str_buf_append)(VALUE str, VALUE str2);
1213 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 0)
1214 VALUE (*str_vcatf)(VALUE str, const char *fmt, va_list ap);
1215 char *(*string_value_cstr)(volatile VALUE *ptr);
1216 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 1, 2)
1217 VALUE (*rb_sprintf)(const char *format, ...);
1218 char *(*rstring_ptr)(VALUE str);
1219 char *(*rstring_end)(VALUE str);
1220 long (*rstring_len)(VALUE str);
1221 VALUE (*filesystem_str_new_cstr)(const char *ptr);
1222 VALUE (*obj_as_string)(VALUE);
1223
1224 /* Hash */
1225 VALUE (*hash_clear)(VALUE hash);
1226 VALUE (*hash_new)(void);
1227 VALUE (*hash_aset)(VALUE hash, VALUE key, VALUE val);
1228 VALUE (*hash_delete)(VALUE hash, VALUE key);
1229 VALUE (*hash_lookup)(VALUE hash, VALUE key);
1230 VALUE (*ident_hash_new)(void);
1231
1232 /* Fixnum */
1233 VALUE (*int2fix)(long i);
1234
1235 /* Bignum */
1236 void (*bignum_negate)(VALUE b);
1237 VALUE (*big_norm)(VALUE x);
1238 VALUE (*cstr_to_inum)(const char *str, int base, int badcheck);
1239
1240 /* Float */
1241 VALUE (*float_new)(double d);
1242 double (*float_value)(VALUE v);
1243
1244 /* Numeric */
1245 int (*num2int)(VALUE val);
1246 VALUE (*int_positive_pow)(long x, unsigned long y);
1247 VALUE (*int2num)(int v);
1248 long (*fix2long)(VALUE val);
1249
1250 /* Rational */
1251 VALUE (*rational_new)(VALUE x, VALUE y);
1252 VALUE (*rational_raw1)(VALUE x);
1253 void (*rational_set_num)(VALUE r, VALUE n);
1254 VALUE (*rational_get_num)(VALUE obj);
1255
1256 /* Complex */
1257 VALUE (*complex_raw)(VALUE x, VALUE y);
1258 void (*rcomplex_set_real)(VALUE cmp, VALUE r);
1259 void (*rcomplex_set_imag)(VALUE cmp, VALUE i);
1260 VALUE (*rcomplex_get_real)(VALUE obj);
1261 VALUE (*rcomplex_get_imag)(VALUE obj);
1262
1263 /* IO */
1264 int (*stderr_tty_p)(void);
1265 void (*write_error_str)(VALUE mesg);
1266 VALUE (*default_rs)(void);
1267 VALUE (*io_write)(VALUE io, VALUE str);
1268 VALUE (*io_flush)(VALUE io);
1269 VALUE (*io_puts)(int argc, const VALUE *argv, VALUE out);
1270 VALUE (*io_gets_internal)(VALUE io);
1271
1272 /* IO (Ractor) */
1273 VALUE (*debug_output_stdout)(void);
1274 VALUE (*debug_output_stderr)(void);
1275
1276 /* Encoding */
1277 int (*is_usascii_enc)(rb_encoding *enc);
1278 int (*enc_isalnum)(OnigCodePoint c, rb_encoding *enc);
1279 int (*enc_precise_mbclen)(const char *p, const char *e, rb_encoding *enc);
1280 int (*mbclen_charfound_p)(int len);
1281 const char *(*enc_name)(rb_encoding *enc);
1282 char *(*enc_prev_char)(const char *s, const char *p, const char *e, rb_encoding *enc);
1283 rb_encoding* (*enc_get)(VALUE obj);
1284 int (*enc_asciicompat)(rb_encoding *enc);
1285 rb_encoding *(*utf8_encoding)(void);
1286 VALUE (*enc_associate)(VALUE obj, rb_encoding *enc);
1287 rb_encoding *(*ascii8bit_encoding)(void);
1288 int (*enc_codelen)(int c, rb_encoding *enc);
1289 int (*enc_mbcput)(unsigned int c, void *buf, rb_encoding *enc);
1290 int (*char_to_option_kcode)(int c, int *option, int *kcode);
1291 int (*ascii8bit_encindex)(void);
1292 int (*enc_find_index)(const char *name);
1293 rb_encoding *(*enc_from_index)(int idx);
1294 VALUE (*enc_associate_index)(VALUE obj, int encindex);
1295 int (*enc_isspace)(OnigCodePoint c, rb_encoding *enc);
1296 int enc_coderange_7bit;
1297 int enc_coderange_unknown;
1298 rb_encoding *(*enc_compatible)(VALUE str1, VALUE str2);
1299 VALUE (*enc_from_encoding)(rb_encoding *enc);
1300 int (*encoding_get)(VALUE obj);
1301 void (*encoding_set)(VALUE obj, int encindex);
1302 int (*encoding_is_ascii8bit)(VALUE obj);
1303 rb_encoding *(*usascii_encoding)(void);
1304
1305 /* Ractor */
1306 VALUE (*ractor_make_shareable)(VALUE obj);
1307
1308 /* Compile */
1309 // int rb_local_defined(ID id, const rb_iseq_t *iseq);
1310 int (*local_defined)(ID, const void*);
1311 // int rb_dvar_defined(ID id, const rb_iseq_t *iseq);
1312 int (*dvar_defined)(ID, const void*);
1313
1314 /* Compile (parse.y) */
1315 int (*literal_cmp)(VALUE val, VALUE lit);
1316 parser_st_index_t (*literal_hash)(VALUE a);
1317
1318 /* Error (Exception) */
1319 const char *(*builtin_class_name)(VALUE x);
1320 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 6, 0)
1321 VALUE (*syntax_error_append)(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list);
1322 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
1323 void (*raise)(VALUE exc, const char *fmt, ...);
1324 VALUE (*syntax_error_new)(void);
1325
1326 /* Eval */
1327 VALUE (*errinfo)(void);
1328 void (*set_errinfo)(VALUE err);
1329 void (*exc_raise)(VALUE mesg);
1330 VALUE (*make_exception)(int argc, const VALUE *argv);
1331
1332 /* GC */
1333 void (*sized_xfree)(void *x, size_t size);
1334 void *(*sized_realloc_n)(void *ptr, size_t new_count, size_t element_size, size_t old_count);
1335 VALUE (*obj_write)(VALUE, VALUE *, VALUE);
1336 VALUE (*obj_written)(VALUE, VALUE, VALUE);
1337 void (*gc_register_mark_object)(VALUE object);
1338 void (*gc_guard)(VALUE);
1339 void (*gc_mark)(VALUE);
1340 void (*gc_mark_movable)(VALUE ptr);
1341 VALUE (*gc_location)(VALUE value);
1342
1343 /* Re */
1344 VALUE (*reg_compile)(VALUE str, int options, const char *sourcefile, int sourceline);
1345 VALUE (*reg_check_preprocess)(VALUE str);
1346 int (*memcicmp)(const void *x, const void *y, long len);
1347
1348 /* Error */
1349 void (*compile_warn)(const char *file, int line, const char *fmt, ...);
1350 void (*compile_warning)(const char *file, int line, const char *fmt, ...);
1351 void (*bug)(const char *fmt, ...);
1352 void (*fatal)(const char *fmt, ...);
1353 VALUE (*verbose)(void);
1354
1355 /* VM */
1356 VALUE (*make_backtrace)(void);
1357
1358 /* Util */
1359 unsigned long (*scan_hex)(const char *start, size_t len, size_t *retlen);
1360 unsigned long (*scan_oct)(const char *start, size_t len, size_t *retlen);
1361 unsigned long (*scan_digits)(const char *str, ssize_t len, int base, size_t *retlen, int *overflow);
1362 double (*strtod)(const char *s00, char **se);
1363
1364 /* Misc */
1365 VALUE (*rbool)(VALUE);
1366 int (*undef_p)(VALUE);
1367 int (*rtest)(VALUE obj);
1368 int (*nil_p)(VALUE obj);
1369 int (*flonum_p)(VALUE obj);
1370 VALUE qnil;
1371 VALUE qtrue;
1372 VALUE qfalse;
1373 VALUE qundef;
1374 VALUE eArgError;
1375 VALUE mRubyVMFrozenCore;
1376 int (*long2int)(long);
1377 int (*special_const_p)(VALUE);
1378 int (*builtin_type)(VALUE);
1379
1380 VALUE (*node_case_when_optimizable_literal)(const NODE *const node);
1381
1382 /* For Ripper */
1383 VALUE (*static_id2sym)(ID id);
1384 long (*str_coderange_scan_restartable)(const char *s, const char *e, rb_encoding *enc, int *cr);
1385} rb_parser_config_t;
1386
1387#undef rb_encoding
1388#undef OnigCodePoint
1389#endif /* UNIVERSAL_PARSER */
1390
1391RUBY_SYMBOL_EXPORT_BEGIN
1392void rb_ruby_parser_free(void *ptr);
1393rb_ast_t* rb_ruby_parser_compile_string(rb_parser_t *p, const char *f, VALUE s, int line);
1394
1395#ifdef UNIVERSAL_PARSER
1396rb_parser_config_t *rb_ruby_parser_config_new(void *(*malloc)(size_t size));
1397void rb_ruby_parser_config_free(rb_parser_config_t *config);
1398rb_parser_t *rb_ruby_parser_allocate(rb_parser_config_t *config);
1399rb_parser_t *rb_ruby_parser_new(rb_parser_config_t *config);
1400#endif
1401RUBY_SYMBOL_EXPORT_END
1402
1403#endif /* RUBY_RUBYPARSER_H */
#define RBIMPL_ATTR_FORMAT(x, y, z)
Wraps (or simulates) __attribute__((format))
Definition format.h:29
#define scan_hex(s, l, e)
Old name of ruby_scan_hex.
Definition util.h:108
#define scan_oct(s, l, e)
Old name of ruby_scan_oct.
Definition util.h:85
Encoding relates APIs.
int capa
Designed capacity of the buffer.
Definition io.h:11
int len
Length of the buffer.
Definition io.h:8
#define strtod(s, e)
Just another name of ruby_strtod.
Definition util.h:223
Defines old _.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40