1 #ifndef RUBY_RUBYPARSER_H
2 #define RUBY_RUBYPARSER_H 1
4 * This is a header file for librubyparser interface
7 #include <stdarg.h> /* for va_list */
10 #ifdef UNIVERSAL_PARSER
12 #define rb_encoding void
13 #define OnigCodePoint unsigned int
14 #include "parser_st.h"
16 #include "parser_value.h"
21 #include "ruby/encoding.h"
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]; */
33 # define FLEX_ARY_LEN 1 /* VALUE ary[1]; */
40 enum rb_parser_string_coderange_type
{
41 /** The object's coderange is unclear yet. */
42 RB_PARSER_ENC_CODERANGE_UNKNOWN
= 0,
43 RB_PARSER_ENC_CODERANGE_7BIT
= 1,
44 RB_PARSER_ENC_CODERANGE_VALID
= 2,
45 RB_PARSER_ENC_CODERANGE_BROKEN
= 3
48 typedef struct rb_parser_string
{
49 enum rb_parser_string_coderange_type coderange
;
51 /* Length of the string, not including terminating NUL character. */
53 /* Pointer to the contents of the string. */
177 typedef struct rb_ast_id_table
{
179 ID ids
[FLEX_ARY_LEN
];
182 typedef struct rb_code_position_struct
{
185 } rb_code_position_t
;
187 typedef struct rb_code_location_struct
{
188 rb_code_position_t beg_pos
;
189 rb_code_position_t end_pos
;
190 } rb_code_location_t
;
192 /* Header part of AST Node */
193 typedef struct RNode
{
195 rb_code_location_t nd_loc
;
199 typedef struct RNode_SCOPE
{
202 rb_ast_id_table_t
*nd_tbl
;
203 struct RNode
*nd_body
;
204 struct RNode_ARGS
*nd_args
;
207 typedef struct RNode_BLOCK
{
210 struct RNode
*nd_head
;
211 struct RNode
*nd_end
;
212 struct RNode
*nd_next
;
215 typedef struct RNode_IF
{
218 struct RNode
*nd_cond
;
219 struct RNode
*nd_body
;
220 struct RNode
*nd_else
;
223 typedef struct RNode_UNLESS
{
226 struct RNode
*nd_cond
;
227 struct RNode
*nd_body
;
228 struct RNode
*nd_else
;
231 typedef struct RNode_CASE
{
234 struct RNode
*nd_head
;
235 struct RNode
*nd_body
;
238 typedef struct RNode_CASE2
{
241 struct RNode
*nd_head
;
242 struct RNode
*nd_body
;
245 typedef struct RNode_CASE3
{
248 struct RNode
*nd_head
;
249 struct RNode
*nd_body
;
252 typedef struct RNode_WHEN
{
255 struct RNode
*nd_head
;
256 struct RNode
*nd_body
;
257 struct RNode
*nd_next
;
260 typedef struct RNode_IN
{
263 struct RNode
*nd_head
;
264 struct RNode
*nd_body
;
265 struct RNode
*nd_next
;
268 /* RNode_WHILE and RNode_UNTIL should be same structure */
269 typedef struct RNode_WHILE
{
272 struct RNode
*nd_cond
;
273 struct RNode
*nd_body
;
277 typedef struct RNode_UNTIL
{
280 struct RNode
*nd_cond
;
281 struct RNode
*nd_body
;
285 /* RNode_ITER and RNode_FOR should be same structure */
286 typedef struct RNode_ITER
{
289 struct RNode
*nd_body
;
290 struct RNode
*nd_iter
;
293 typedef struct RNode_FOR
{
296 struct RNode
*nd_body
;
297 struct RNode
*nd_iter
;
300 typedef struct RNode_FOR_MASGN
{
303 struct RNode
*nd_var
;
304 } rb_node_for_masgn_t
;
306 /* RNode_BREAK, RNode_NEXT and RNode_REDO should be same structure */
307 typedef struct RNode_BREAK
{
310 struct RNode
*nd_chain
;
311 struct RNode
*nd_stts
;
314 typedef struct RNode_NEXT
{
317 struct RNode
*nd_chain
;
318 struct RNode
*nd_stts
;
321 typedef struct RNode_REDO
{
324 struct RNode
*nd_chain
;
327 typedef struct RNode_RETRY
{
331 typedef struct RNode_BEGIN
{
334 struct RNode
*nd_body
;
337 typedef struct RNode_RESCUE
{
340 struct RNode
*nd_head
;
341 struct RNode
*nd_resq
;
342 struct RNode
*nd_else
;
345 typedef struct RNode_RESBODY
{
348 struct RNode
*nd_args
;
349 struct RNode
*nd_body
;
350 struct RNode
*nd_next
;
353 typedef struct RNode_ENSURE
{
356 struct RNode
*nd_head
;
357 struct RNode
*nd_ensr
;
360 /* RNode_AND and RNode_OR should be same structure */
361 typedef struct RNode_AND
{
364 struct RNode
*nd_1st
;
365 struct RNode
*nd_2nd
;
368 typedef struct RNode_OR
{
371 struct RNode
*nd_1st
;
372 struct RNode
*nd_2nd
;
375 typedef struct RNode_MASGN
{
378 struct RNode
*nd_head
;
379 struct RNode
*nd_value
;
380 struct RNode
*nd_args
;
383 typedef struct RNode_LASGN
{
387 struct RNode
*nd_value
;
390 typedef struct RNode_DASGN
{
394 struct RNode
*nd_value
;
397 typedef struct RNode_GASGN
{
401 struct RNode
*nd_value
;
404 typedef struct RNode_IASGN
{
408 struct RNode
*nd_value
;
411 typedef struct RNode_CDECL
{
415 struct RNode
*nd_value
;
416 struct RNode
*nd_else
;
419 typedef struct RNode_CVASGN
{
423 struct RNode
*nd_value
;
426 typedef struct RNode_OP_ASGN1
{
429 struct RNode
*nd_recv
;
431 struct RNode
*nd_index
;
432 struct RNode
*nd_rvalue
;
433 } rb_node_op_asgn1_t
;
435 typedef struct RNode_OP_ASGN2
{
438 struct RNode
*nd_recv
;
439 struct RNode
*nd_value
;
443 } rb_node_op_asgn2_t
;
445 typedef struct RNode_OP_ASGN_AND
{
448 struct RNode
*nd_head
;
449 struct RNode
*nd_value
;
450 } rb_node_op_asgn_and_t
;
452 typedef struct RNode_OP_ASGN_OR
{
455 struct RNode
*nd_head
;
456 struct RNode
*nd_value
;
457 } rb_node_op_asgn_or_t
;
459 typedef struct RNode_OP_CDECL
{
462 struct RNode
*nd_head
;
463 struct RNode
*nd_value
;
465 } rb_node_op_cdecl_t
;
467 typedef struct RNode_CALL
{
470 struct RNode
*nd_recv
;
472 struct RNode
*nd_args
;
475 typedef struct RNode_OPCALL
{
478 struct RNode
*nd_recv
;
480 struct RNode
*nd_args
;
483 typedef struct RNode_FCALL
{
487 struct RNode
*nd_args
;
490 typedef struct RNode_VCALL
{
496 typedef struct RNode_QCALL
{
499 struct RNode
*nd_recv
;
501 struct RNode
*nd_args
;
504 typedef struct RNode_SUPER
{
507 struct RNode
*nd_args
;
510 typedef struct RNode_ZSUPER
{
519 * head --> element | * head
520 * alen (length of list) | * nd_end (point to the last LIST)
521 * next -----------------+ * next
524 RNode_LIST and RNode_VALUES should be same structure
526 typedef struct RNode_LIST
{
529 struct RNode
*nd_head
; /* element */
532 struct RNode
*nd_end
; /* Second list node has this structure */
534 struct RNode
*nd_next
; /* next list node */
537 typedef struct RNode_ZLIST
{
541 typedef struct RNode_VALUES
{
544 struct RNode
*nd_head
;
546 struct RNode
*nd_next
;
549 typedef struct RNode_HASH
{
552 struct RNode
*nd_head
;
556 typedef struct RNode_RETURN
{
559 struct RNode
*nd_stts
;
562 typedef struct RNode_YIELD
{
565 struct RNode
*nd_head
;
568 typedef struct RNode_LVAR
{
574 typedef struct RNode_DVAR
{
580 typedef struct RNode_GVAR
{
586 typedef struct RNode_IVAR
{
592 typedef struct RNode_CONST
{
598 typedef struct RNode_CVAR
{
604 typedef struct RNode_NTH_REF
{
610 typedef struct RNode_BACK_REF
{
614 } rb_node_back_ref_t
;
616 /* RNode_MATCH and RNode_REGX should be same structure */
617 typedef struct RNode_MATCH
{
620 struct rb_parser_string
*string
;
624 typedef struct RNode_MATCH2
{
627 struct RNode
*nd_recv
;
628 struct RNode
*nd_value
;
629 struct RNode
*nd_args
;
632 typedef struct RNode_MATCH3
{
635 struct RNode
*nd_recv
;
636 struct RNode
*nd_value
;
639 typedef struct RNode_LIT
{
645 typedef struct RNode_INTEGER
{
653 typedef struct RNode_FLOAT
{
660 typedef struct RNode_RATIONAL
{
667 } rb_node_rational_t
;
669 enum rb_numeric_type
{
675 typedef struct RNode_IMAGINARY
{
682 enum rb_numeric_type type
;
683 } rb_node_imaginary_t
;
685 /* RNode_STR and RNode_XSTR should be same structure */
686 typedef struct RNode_STR
{
689 struct rb_parser_string
*string
;
692 /* RNode_DSTR, RNode_DXSTR and RNode_DSYM should be same structure */
693 typedef struct RNode_DSTR
{
696 struct rb_parser_string
*string
;
699 struct RNode
*nd_end
; /* Second dstr node has this structure. See also RNode_LIST */
701 struct RNode_LIST
*nd_next
;
704 typedef struct RNode_XSTR
{
707 struct rb_parser_string
*string
;
710 typedef struct RNode_DXSTR
{
713 struct rb_parser_string
*string
;
715 struct RNode_LIST
*nd_next
;
718 typedef struct RNode_EVSTR
{
721 struct RNode
*nd_body
;
724 typedef struct RNode_REGX
{
727 struct rb_parser_string
*string
;
731 typedef struct RNode_DREGX
{
734 struct rb_parser_string
*string
;
736 struct RNode_LIST
*nd_next
;
739 typedef struct RNode_ONCE
{
742 struct RNode
*nd_body
;
745 struct rb_args_info
{
749 int pre_args_num
; /* count of mandatory pre-arguments */
750 int post_args_num
; /* count of mandatory post-arguments */
757 struct RNode_KW_ARG
*kw_args
;
760 struct RNode_OPT_ARG
*opt_args
;
761 unsigned int no_kwarg
: 1;
762 unsigned int ruby2_keywords
: 1;
763 unsigned int forwarding
: 1;
766 typedef struct RNode_ARGS
{
769 struct rb_args_info nd_ainfo
;
772 typedef struct RNode_ARGS_AUX
{
777 struct RNode
*nd_next
;
778 } rb_node_args_aux_t
;
780 typedef struct RNode_OPT_ARG
{
783 struct RNode
*nd_body
;
784 struct RNode_OPT_ARG
*nd_next
;
787 typedef struct RNode_KW_ARG
{
790 struct RNode
*nd_body
;
791 struct RNode_KW_ARG
*nd_next
;
794 typedef struct RNode_POSTARG
{
797 struct RNode
*nd_1st
;
798 struct RNode
*nd_2nd
;
801 typedef struct RNode_ARGSCAT
{
804 struct RNode
*nd_head
;
805 struct RNode
*nd_body
;
808 typedef struct RNode_ARGSPUSH
{
811 struct RNode
*nd_head
;
812 struct RNode
*nd_body
;
813 } rb_node_argspush_t
;
815 typedef struct RNode_SPLAT
{
818 struct RNode
*nd_head
;
821 typedef struct RNode_BLOCK_PASS
{
824 struct RNode
*nd_head
;
825 struct RNode
*nd_body
;
826 } rb_node_block_pass_t
;
828 typedef struct RNode_DEFN
{
832 struct RNode
*nd_defn
;
835 typedef struct RNode_DEFS
{
838 struct RNode
*nd_recv
;
840 struct RNode
*nd_defn
;
843 typedef struct RNode_ALIAS
{
846 struct RNode
*nd_1st
;
847 struct RNode
*nd_2nd
;
850 typedef struct RNode_VALIAS
{
857 typedef struct RNode_UNDEF
{
860 struct RNode
*nd_undef
;
863 typedef struct RNode_CLASS
{
866 struct RNode
*nd_cpath
;
867 struct RNode
*nd_body
;
868 struct RNode
*nd_super
;
871 typedef struct RNode_MODULE
{
874 struct RNode
*nd_cpath
;
875 struct RNode
*nd_body
;
878 typedef struct RNode_SCLASS
{
881 struct RNode
*nd_recv
;
882 struct RNode
*nd_body
;
885 typedef struct RNode_COLON2
{
888 struct RNode
*nd_head
;
892 typedef struct RNode_COLON3
{
898 /* RNode_DOT2, RNode_DOT3, RNode_FLIP2 and RNode_FLIP3 should be same structure */
899 typedef struct RNode_DOT2
{
902 struct RNode
*nd_beg
;
903 struct RNode
*nd_end
;
906 typedef struct RNode_DOT3
{
909 struct RNode
*nd_beg
;
910 struct RNode
*nd_end
;
913 typedef struct RNode_FLIP2
{
916 struct RNode
*nd_beg
;
917 struct RNode
*nd_end
;
920 typedef struct RNode_FLIP3
{
923 struct RNode
*nd_beg
;
924 struct RNode
*nd_end
;
927 typedef struct RNode_SELF
{
930 long nd_state
; /* Default 1. See NEW_SELF. */
933 typedef struct RNode_NIL
{
937 typedef struct RNode_TRUE
{
941 typedef struct RNode_FALSE
{
945 typedef struct RNode_ERRINFO
{
949 typedef struct RNode_DEFINED
{
952 struct RNode
*nd_head
;
955 typedef struct RNode_POSTEXE
{
958 struct RNode
*nd_body
;
961 typedef struct RNode_SYM
{
964 struct rb_parser_string
*string
;
967 typedef struct RNode_DSYM
{
970 struct rb_parser_string
*string
;
972 struct RNode_LIST
*nd_next
;
975 typedef struct RNode_ATTRASGN
{
978 struct RNode
*nd_recv
;
980 struct RNode
*nd_args
;
981 } rb_node_attrasgn_t
;
983 typedef struct RNode_LAMBDA
{
986 struct RNode
*nd_body
;
989 typedef struct RNode_ARYPTN
{
992 struct RNode
*nd_pconst
;
998 typedef struct RNode_HSHPTN
{
1001 struct RNode
*nd_pconst
;
1002 struct RNode
*nd_pkwargs
;
1003 struct RNode
*nd_pkwrestarg
;
1006 typedef struct RNode_FNDPTN
{
1009 struct RNode
*nd_pconst
;
1012 NODE
*post_rest_arg
;
1015 typedef struct RNode_LINE
{
1019 typedef struct RNode_FILE
{
1022 struct rb_parser_string
*path
;
1025 typedef struct RNode_ENCODING
{
1028 } rb_node_encoding_t
;
1030 typedef struct RNode_ERROR
{
1034 #define RNODE(obj) ((struct RNode *)(obj))
1036 #define RNODE_SCOPE(node) ((struct RNode_SCOPE *)(node))
1037 #define RNODE_BLOCK(node) ((struct RNode_BLOCK *)(node))
1038 #define RNODE_IF(node) ((struct RNode_IF *)(node))
1039 #define RNODE_UNLESS(node) ((struct RNode_UNLESS *)(node))
1040 #define RNODE_CASE(node) ((struct RNode_CASE *)(node))
1041 #define RNODE_CASE2(node) ((struct RNode_CASE2 *)(node))
1042 #define RNODE_CASE3(node) ((struct RNode_CASE3 *)(node))
1043 #define RNODE_WHEN(node) ((struct RNode_WHEN *)(node))
1044 #define RNODE_IN(node) ((struct RNode_IN *)(node))
1045 #define RNODE_WHILE(node) ((struct RNode_WHILE *)(node))
1046 #define RNODE_UNTIL(node) ((struct RNode_UNTIL *)(node))
1047 #define RNODE_ITER(node) ((struct RNode_ITER *)(node))
1048 #define RNODE_FOR(node) ((struct RNode_FOR *)(node))
1049 #define RNODE_FOR_MASGN(node) ((struct RNode_FOR_MASGN *)(node))
1050 #define RNODE_BREAK(node) ((struct RNode_BREAK *)(node))
1051 #define RNODE_NEXT(node) ((struct RNode_NEXT *)(node))
1052 #define RNODE_REDO(node) ((struct RNode_REDO *)(node))
1053 #define RNODE_RETRY(node) ((struct RNode_RETRY *)(node))
1054 #define RNODE_BEGIN(node) ((struct RNode_BEGIN *)(node))
1055 #define RNODE_RESCUE(node) ((struct RNode_RESCUE *)(node))
1056 #define RNODE_RESBODY(node) ((struct RNode_RESBODY *)(node))
1057 #define RNODE_ENSURE(node) ((struct RNode_ENSURE *)(node))
1058 #define RNODE_AND(node) ((struct RNode_AND *)(node))
1059 #define RNODE_OR(node) ((struct RNode_OR *)(node))
1060 #define RNODE_MASGN(node) ((struct RNode_MASGN *)(node))
1061 #define RNODE_LASGN(node) ((struct RNode_LASGN *)(node))
1062 #define RNODE_DASGN(node) ((struct RNode_DASGN *)(node))
1063 #define RNODE_GASGN(node) ((struct RNode_GASGN *)(node))
1064 #define RNODE_IASGN(node) ((struct RNode_IASGN *)(node))
1065 #define RNODE_CDECL(node) ((struct RNode_CDECL *)(node))
1066 #define RNODE_CVASGN(node) ((struct RNode_CVASGN *)(node))
1067 #define RNODE_OP_ASGN1(node) ((struct RNode_OP_ASGN1 *)(node))
1068 #define RNODE_OP_ASGN2(node) ((struct RNode_OP_ASGN2 *)(node))
1069 #define RNODE_OP_ASGN_AND(node) ((struct RNode_OP_ASGN_AND *)(node))
1070 #define RNODE_OP_ASGN_OR(node) ((struct RNode_OP_ASGN_OR *)(node))
1071 #define RNODE_OP_CDECL(node) ((struct RNode_OP_CDECL *)(node))
1072 #define RNODE_CALL(node) ((struct RNode_CALL *)(node))
1073 #define RNODE_OPCALL(node) ((struct RNode_OPCALL *)(node))
1074 #define RNODE_FCALL(node) ((struct RNode_FCALL *)(node))
1075 #define RNODE_VCALL(node) ((struct RNode_VCALL *)(node))
1076 #define RNODE_QCALL(node) ((struct RNode_QCALL *)(node))
1077 #define RNODE_SUPER(node) ((struct RNode_SUPER *)(node))
1078 #define RNODE_ZSUPER(node) ((struct RNode_ZSUPER *)(node))
1079 #define RNODE_LIST(node) ((struct RNode_LIST *)(node))
1080 #define RNODE_ZLIST(node) ((struct RNode_ZLIST *)(node))
1081 #define RNODE_HASH(node) ((struct RNode_HASH *)(node))
1082 #define RNODE_RETURN(node) ((struct RNode_RETURN *)(node))
1083 #define RNODE_YIELD(node) ((struct RNode_YIELD *)(node))
1084 #define RNODE_LVAR(node) ((struct RNode_LVAR *)(node))
1085 #define RNODE_DVAR(node) ((struct RNode_DVAR *)(node))
1086 #define RNODE_GVAR(node) ((struct RNode_GVAR *)(node))
1087 #define RNODE_IVAR(node) ((struct RNode_IVAR *)(node))
1088 #define RNODE_CONST(node) ((struct RNode_CONST *)(node))
1089 #define RNODE_CVAR(node) ((struct RNode_CVAR *)(node))
1090 #define RNODE_NTH_REF(node) ((struct RNode_NTH_REF *)(node))
1091 #define RNODE_BACK_REF(node) ((struct RNode_BACK_REF *)(node))
1092 #define RNODE_MATCH(node) ((struct RNode_MATCH *)(node))
1093 #define RNODE_MATCH2(node) ((struct RNode_MATCH2 *)(node))
1094 #define RNODE_MATCH3(node) ((struct RNode_MATCH3 *)(node))
1095 #define RNODE_LIT(node) ((struct RNode_LIT *)(node))
1096 #define RNODE_INTEGER(node) ((struct RNode_INTEGER *)(node))
1097 #define RNODE_FLOAT(node) ((struct RNode_FLOAT *)(node))
1098 #define RNODE_RATIONAL(node) ((struct RNode_RATIONAL *)(node))
1099 #define RNODE_IMAGINARY(node) ((struct RNode_IMAGINARY *)(node))
1100 #define RNODE_STR(node) ((struct RNode_STR *)(node))
1101 #define RNODE_DSTR(node) ((struct RNode_DSTR *)(node))
1102 #define RNODE_XSTR(node) ((struct RNode_XSTR *)(node))
1103 #define RNODE_DXSTR(node) ((struct RNode_DXSTR *)(node))
1104 #define RNODE_EVSTR(node) ((struct RNode_EVSTR *)(node))
1105 #define RNODE_REGX(node) ((struct RNode_REGX *)(node))
1106 #define RNODE_DREGX(node) ((struct RNode_DREGX *)(node))
1107 #define RNODE_ONCE(node) ((struct RNode_ONCE *)(node))
1108 #define RNODE_ARGS(node) ((struct RNode_ARGS *)(node))
1109 #define RNODE_ARGS_AUX(node) ((struct RNode_ARGS_AUX *)(node))
1110 #define RNODE_OPT_ARG(node) ((struct RNode_OPT_ARG *)(node))
1111 #define RNODE_KW_ARG(node) ((struct RNode_KW_ARG *)(node))
1112 #define RNODE_POSTARG(node) ((struct RNode_POSTARG *)(node))
1113 #define RNODE_ARGSCAT(node) ((struct RNode_ARGSCAT *)(node))
1114 #define RNODE_ARGSPUSH(node) ((struct RNode_ARGSPUSH *)(node))
1115 #define RNODE_SPLAT(node) ((struct RNode_SPLAT *)(node))
1116 #define RNODE_BLOCK_PASS(node) ((struct RNode_BLOCK_PASS *)(node))
1117 #define RNODE_DEFN(node) ((struct RNode_DEFN *)(node))
1118 #define RNODE_DEFS(node) ((struct RNode_DEFS *)(node))
1119 #define RNODE_ALIAS(node) ((struct RNode_ALIAS *)(node))
1120 #define RNODE_VALIAS(node) ((struct RNode_VALIAS *)(node))
1121 #define RNODE_UNDEF(node) ((struct RNode_UNDEF *)(node))
1122 #define RNODE_CLASS(node) ((struct RNode_CLASS *)(node))
1123 #define RNODE_MODULE(node) ((struct RNode_MODULE *)(node))
1124 #define RNODE_SCLASS(node) ((struct RNode_SCLASS *)(node))
1125 #define RNODE_COLON2(node) ((struct RNode_COLON2 *)(node))
1126 #define RNODE_COLON3(node) ((struct RNode_COLON3 *)(node))
1127 #define RNODE_DOT2(node) ((struct RNode_DOT2 *)(node))
1128 #define RNODE_DOT3(node) ((struct RNode_DOT3 *)(node))
1129 #define RNODE_FLIP2(node) ((struct RNode_FLIP2 *)(node))
1130 #define RNODE_FLIP3(node) ((struct RNode_FLIP3 *)(node))
1131 #define RNODE_SELF(node) ((struct RNode_SELF *)(node))
1132 #define RNODE_NIL(node) ((struct RNode_NIL *)(node))
1133 #define RNODE_TRUE(node) ((struct RNode_TRUE *)(node))
1134 #define RNODE_FALSE(node) ((struct RNode_FALSE *)(node))
1135 #define RNODE_ERRINFO(node) ((struct RNode_ERRINFO *)(node))
1136 #define RNODE_DEFINED(node) ((struct RNode_DEFINED *)(node))
1137 #define RNODE_POSTEXE(node) ((struct RNode_POSTEXE *)(node))
1138 #define RNODE_SYM(node) ((struct RNode_SYM *)(node))
1139 #define RNODE_DSYM(node) ((struct RNode_DSYM *)(node))
1140 #define RNODE_ATTRASGN(node) ((struct RNode_ATTRASGN *)(node))
1141 #define RNODE_LAMBDA(node) ((struct RNode_LAMBDA *)(node))
1142 #define RNODE_ARYPTN(node) ((struct RNode_ARYPTN *)(node))
1143 #define RNODE_HSHPTN(node) ((struct RNode_HSHPTN *)(node))
1144 #define RNODE_FNDPTN(node) ((struct RNode_FNDPTN *)(node))
1145 #define RNODE_LINE(node) ((struct RNode_LINE *)(node))
1146 #define RNODE_FILE(node) ((struct RNode_FILE *)(node))
1147 #define RNODE_ENCODING(node) ((struct RNode_ENCODING *)(node))
1149 /* FL : 0..4: T_TYPES, 5: KEEP_WB, 6: PROMOTED, 7: FINALIZE, 8: UNUSED, 9: UNUSED, 10: EXIVAR, 11: FREEZE */
1150 /* NODE_FL: 0..4: T_TYPES, 5: KEEP_WB, 6: PROMOTED, 7: NODE_FL_NEWLINE,
1154 #define NODE_FL_NEWLINE (((VALUE)1)<<7)
1156 #define NODE_TYPESHIFT 8
1157 #define NODE_TYPEMASK (((VALUE)0x7f)<<NODE_TYPESHIFT)
1159 #define nd_fl_newline(n) (n)->flags & NODE_FL_NEWLINE
1160 #define nd_set_fl_newline(n) (n)->flags |= NODE_FL_NEWLINE
1161 #define nd_unset_fl_newline(n) (n)->flags &= ~NODE_FL_NEWLINE
1163 #define nd_type(n) ((int) ((RNODE(n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
1164 #define nd_set_type(n,t) \
1165 rb_node_set_type(n, t)
1166 #define nd_init_type(n,t) \
1167 (n)->flags=(((n)->flags&~NODE_TYPEMASK)|((((unsigned long)(t))<<NODE_TYPESHIFT)&NODE_TYPEMASK))
1169 typedef struct node_buffer_struct node_buffer_t
;
1171 typedef struct rb_ast_body_struct
{
1174 // script_lines is either:
1175 // - a Fixnum that represents the line count of the original source, or
1176 // - an Array that contains the lines of the original source
1177 signed int frozen_string_literal
:2; /* -1: not specified, 0: false, 1: true */
1178 signed int coverage_enabled
:2; /* -1: not specified, 0: false, 1: true */
1180 typedef struct rb_ast_struct
{
1182 node_buffer_t
*node_buffer
;
1193 typedef struct parser_params rb_parser_t
;
1194 #ifndef INTERNAL_IMEMO_H
1195 typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t
;
1198 #ifdef UNIVERSAL_PARSER
1199 typedef struct rb_parser_config_struct
{
1201 void *(*malloc
)(size_t size
);
1202 void *(*calloc
)(size_t number
, size_t size
);
1203 void *(*realloc
)(void *ptr
, size_t newsiz
);
1204 void (*free
)(void *ptr
);
1205 void *(*alloc_n
)(size_t nelems
, size_t elemsiz
);
1206 void *(*alloc
)(size_t elemsiz
);
1207 void *(*realloc_n
)(void *ptr
, size_t newelems
, size_t newsiz
);
1208 void *(*zalloc
)(size_t elemsiz
);
1209 void *(*rb_memmove
)(void *dest
, const void *src
, size_t t
, size_t n
);
1210 void *(*nonempty_memcpy
)(void *dest
, const void *src
, size_t t
, size_t n
);
1211 void *(*xmalloc_mul_add
)(size_t x
, size_t y
, size_t z
);
1214 rb_imemo_tmpbuf_t
*(*tmpbuf_parser_heap
)(void *buf
, rb_imemo_tmpbuf_t
*old_heap
, size_t cnt
);
1215 rb_ast_t
*(*ast_new
)(VALUE nb
);
1217 // VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
1218 VALUE (*compile_callback
)(VALUE (*func
)(VALUE
), VALUE arg
);
1219 NODE
*(*reg_named_capture_assign
)(struct parser_params
* p
, VALUE regexp
, const rb_code_location_t
*loc
);
1222 VALUE (*obj_freeze
)(VALUE obj
);
1223 VALUE (*obj_hide
)(VALUE obj
);
1224 void (*obj_freeze_raw
)(VALUE obj
);
1226 int (*fixnum_p
)(VALUE
);
1227 int (*symbol_p
)(VALUE
);
1230 VALUE (*attr_get
)(VALUE obj
, ID id
);
1233 VALUE (*ary_new
)(void);
1234 VALUE (*ary_push
)(VALUE ary
, VALUE elem
);
1235 VALUE (*ary_new_from_args
)(long n
, ...);
1236 VALUE (*ary_unshift
)(VALUE ary
, VALUE item
);
1237 VALUE (*ary_new2
)(long capa
); // ary_new_capa
1238 VALUE (*ary_clear
)(VALUE ary
);
1239 void (*ary_modify
)(VALUE ary
);
1240 long (*array_len
)(VALUE a
);
1241 VALUE (*array_aref
)(VALUE
, long);
1244 ID (*make_temporary_id
)(size_t n
);
1245 int (*is_local_id
)(ID
);
1246 int (*is_attrset_id
)(ID
);
1247 int (*is_global_name_punct
)(const int c
);
1248 int (*id_type
)(ID id
);
1249 ID (*id_attrset
)(ID
);
1250 ID (*intern
)(const char *name
);
1251 ID (*intern2
)(const char *name
, long len
);
1252 ID (*intern3
)(const char *name
, long len
, rb_encoding
*enc
);
1253 ID (*intern_str
)(VALUE str
);
1254 int (*is_notop_id
)(ID
);
1255 int (*enc_symname_type
)(const char *name
, long len
, rb_encoding
*enc
, unsigned int allowed_attrset
);
1256 const char *(*id2name
)(ID id
);
1257 VALUE (*id2str
)(ID id
);
1258 VALUE (*id2sym
)(ID x
);
1259 ID (*sym2id
)(VALUE sym
);
1262 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 3)
1263 VALUE (*str_catf
)(VALUE str
, const char *format
, ...);
1264 VALUE (*str_cat_cstr
)(VALUE str
, const char *ptr
);
1265 VALUE (*str_subseq
)(VALUE str
, long beg
, long len
);
1266 VALUE (*str_new_frozen
)(VALUE orig
);
1267 VALUE (*str_buf_new
)(long capa
);
1268 VALUE (*str_buf_cat
)(VALUE
, const char*, long);
1269 void (*str_modify
)(VALUE str
);
1270 void (*str_set_len
)(VALUE str
, long len
);
1271 VALUE (*str_cat
)(VALUE str
, const char *ptr
, long len
);
1272 VALUE (*str_resize
)(VALUE str
, long len
);
1273 VALUE (*str_new
)(const char *ptr
, long len
);
1274 VALUE (*str_new_cstr
)(const char *ptr
);
1275 VALUE (*fstring
)(VALUE
);
1276 int (*is_ascii_string
)(VALUE str
);
1277 VALUE (*enc_str_new
)(const char *ptr
, long len
, rb_encoding
*enc
);
1278 VALUE (*enc_str_buf_cat
)(VALUE str
, const char *ptr
, long len
, rb_encoding
*enc
);
1279 VALUE (*str_buf_append
)(VALUE str
, VALUE str2
);
1280 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 0)
1281 VALUE (*str_vcatf
)(VALUE str
, const char *fmt
, va_list ap
);
1282 char *(*string_value_cstr
)(volatile VALUE
*ptr
);
1283 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 1, 2)
1284 VALUE (*rb_sprintf
)(const char *format
, ...);
1285 char *(*rstring_ptr
)(VALUE str
);
1286 char *(*rstring_end
)(VALUE str
);
1287 long (*rstring_len
)(VALUE str
);
1288 VALUE (*filesystem_str_new_cstr
)(const char *ptr
);
1289 VALUE (*obj_as_string
)(VALUE
);
1292 VALUE (*hash_clear
)(VALUE hash
);
1293 VALUE (*hash_new
)(void);
1294 VALUE (*hash_aset
)(VALUE hash
, VALUE key
, VALUE val
);
1295 VALUE (*hash_delete
)(VALUE hash
, VALUE key
);
1296 VALUE (*hash_lookup
)(VALUE hash
, VALUE key
);
1297 VALUE (*ident_hash_new
)(void);
1300 int (*num2int
)(VALUE val
);
1301 VALUE (*int2num
)(int v
);
1304 int (*stderr_tty_p
)(void);
1305 void (*write_error_str
)(VALUE mesg
);
1306 VALUE (*default_rs
)(void);
1307 VALUE (*io_write
)(VALUE io
, VALUE str
);
1308 VALUE (*io_flush
)(VALUE io
);
1309 VALUE (*io_puts
)(int argc
, const VALUE
*argv
, VALUE out
);
1310 VALUE (*io_gets_internal
)(VALUE io
);
1313 VALUE (*debug_output_stdout
)(void);
1314 VALUE (*debug_output_stderr
)(void);
1317 int (*is_usascii_enc
)(rb_encoding
*enc
);
1318 int (*enc_isalnum
)(OnigCodePoint c
, rb_encoding
*enc
);
1319 int (*enc_precise_mbclen
)(const char *p
, const char *e
, rb_encoding
*enc
);
1320 int (*mbclen_charfound_p
)(int len
);
1321 int (*mbclen_charfound_len
)(int len
);
1322 const char *(*enc_name
)(rb_encoding
*enc
);
1323 char *(*enc_prev_char
)(const char *s
, const char *p
, const char *e
, rb_encoding
*enc
);
1324 rb_encoding
* (*enc_get
)(VALUE obj
);
1325 int (*enc_asciicompat
)(rb_encoding
*enc
);
1326 rb_encoding
*(*utf8_encoding
)(void);
1327 VALUE (*enc_associate
)(VALUE obj
, rb_encoding
*enc
);
1328 rb_encoding
*(*ascii8bit_encoding
)(void);
1329 int (*enc_codelen
)(int c
, rb_encoding
*enc
);
1330 int (*enc_mbcput
)(unsigned int c
, void *buf
, rb_encoding
*enc
);
1331 int (*char_to_option_kcode
)(int c
, int *option
, int *kcode
);
1332 int (*ascii8bit_encindex
)(void);
1333 int (*enc_find_index
)(const char *name
);
1334 rb_encoding
*(*enc_from_index
)(int idx
);
1335 VALUE (*enc_associate_index
)(VALUE obj
, int encindex
);
1336 int (*enc_isspace
)(OnigCodePoint c
, rb_encoding
*enc
);
1337 rb_encoding
*(*enc_compatible
)(VALUE str1
, VALUE str2
);
1338 VALUE (*enc_from_encoding
)(rb_encoding
*enc
);
1339 int (*encoding_get
)(VALUE obj
);
1340 void (*encoding_set
)(VALUE obj
, int encindex
);
1341 int (*encoding_is_ascii8bit
)(VALUE obj
);
1342 rb_encoding
*(*usascii_encoding
)(void);
1345 VALUE (*ractor_make_shareable
)(VALUE obj
);
1348 // int rb_local_defined(ID id, const rb_iseq_t *iseq);
1349 int (*local_defined
)(ID
, const void*);
1350 // int rb_dvar_defined(ID id, const rb_iseq_t *iseq);
1351 int (*dvar_defined
)(ID
, const void*);
1353 /* Compile (parse.y) */
1354 int (*literal_cmp
)(VALUE val
, VALUE lit
);
1355 parser_st_index_t (*literal_hash
)(VALUE a
);
1357 /* Error (Exception) */
1358 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 6, 0)
1359 VALUE (*syntax_error_append
)(VALUE
, VALUE
, int, int, rb_encoding
*, const char*, va_list);
1360 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 3)
1361 void (*raise
)(VALUE exc
, const char *fmt
, ...);
1362 VALUE (*syntax_error_new
)(void);
1365 VALUE (*errinfo
)(void);
1366 void (*set_errinfo
)(VALUE err
);
1367 void (*exc_raise
)(VALUE mesg
);
1368 VALUE (*make_exception
)(int argc
, const VALUE
*argv
);
1371 void (*sized_xfree
)(void *x
, size_t size
);
1372 void *(*sized_realloc_n
)(void *ptr
, size_t new_count
, size_t element_size
, size_t old_count
);
1373 VALUE (*obj_write
)(VALUE
, VALUE
*, VALUE
);
1374 VALUE (*obj_written
)(VALUE
, VALUE
, VALUE
);
1375 void (*gc_guard
)(VALUE
);
1376 void (*gc_mark
)(VALUE
);
1377 void (*gc_mark_and_move
)(VALUE
*ptr
);
1378 VALUE (*gc_location
)(VALUE value
);
1381 VALUE (*reg_compile
)(VALUE str
, int options
, const char *sourcefile
, int sourceline
);
1382 VALUE (*reg_check_preprocess
)(VALUE str
);
1383 int (*memcicmp
)(const void *x
, const void *y
, long len
);
1386 void (*compile_warn
)(const char *file
, int line
, const char *fmt
, ...);
1387 void (*compile_warning
)(const char *file
, int line
, const char *fmt
, ...);
1388 void (*bug
)(const char *fmt
, ...);
1389 void (*fatal
)(const char *fmt
, ...);
1390 VALUE (*verbose
)(void);
1391 int *(*errno_ptr
)(void);
1394 VALUE (*make_backtrace
)(void);
1397 unsigned long (*scan_hex
)(const char *start
, size_t len
, size_t *retlen
);
1398 unsigned long (*scan_oct
)(const char *start
, size_t len
, size_t *retlen
);
1399 unsigned long (*scan_digits
)(const char *str
, ssize_t len
, int base
, size_t *retlen
, int *overflow
);
1400 double (*strtod
)(const char *s00
, char **se
);
1403 VALUE (*rbool
)(VALUE
);
1404 int (*undef_p
)(VALUE
);
1405 int (*rtest
)(VALUE obj
);
1406 int (*nil_p
)(VALUE obj
);
1411 VALUE (*eArgError
)(void);
1412 VALUE (*mRubyVMFrozenCore
)(void);
1413 int (*long2int
)(long);
1415 VALUE (*node_case_when_optimizable_literal
)(const NODE
*const node
);
1418 int enc_coderange_7bit
;
1419 int enc_coderange_unknown
;
1420 VALUE (*static_id2sym
)(ID id
);
1421 long (*str_coderange_scan_restartable
)(const char *s
, const char *e
, rb_encoding
*enc
, int *cr
);
1422 } rb_parser_config_t
;
1425 #undef OnigCodePoint
1426 #endif /* UNIVERSAL_PARSER */
1428 RUBY_SYMBOL_EXPORT_BEGIN
1429 void rb_ruby_parser_free(void *ptr
);
1430 rb_ast_t
* rb_ruby_parser_compile_string(rb_parser_t
*p
, const char *f
, VALUE s
, int line
);
1432 #ifdef UNIVERSAL_PARSER
1433 rb_parser_t
*rb_ruby_parser_allocate(const rb_parser_config_t
*config
);
1434 rb_parser_t
*rb_ruby_parser_new(const rb_parser_config_t
*config
);
1437 long rb_parser_string_length(rb_parser_string_t
*str
);
1438 char *rb_parser_string_pointer(rb_parser_string_t
*str
);
1440 RUBY_SYMBOL_EXPORT_END
1442 #endif /* RUBY_RUBYPARSER_H */