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]; */
38 # if defined(__MINGW_PRINTF_FORMAT)
39 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, argument_index)))
41 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(printf, string_index, argument_index)))
43 #elif defined(__clang__)
44 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
46 # define RUBYPARSER_ATTRIBUTE_FORMAT(string_index, argument_index)
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
;
63 /* Length of the string, not including terminating NUL character. */
65 /* Pointer to the contents of the string. */
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
,
195 typedef struct rb_ast_id_table
{
197 ID ids
[FLEX_ARY_LEN
];
200 typedef struct rb_code_position_struct
{
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
{
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
228 /* Header part of AST Node */
229 typedef struct RNode
{
231 rb_code_location_t nd_loc
;
235 typedef struct RNode_SCOPE
{
238 rb_ast_id_table_t
*nd_tbl
;
239 struct RNode
*nd_body
;
240 struct RNode_ARGS
*nd_args
;
243 typedef struct RNode_BLOCK
{
246 struct RNode
*nd_head
;
247 struct RNode
*nd_end
;
248 struct RNode
*nd_next
;
251 typedef struct RNode_IF
{
254 struct RNode
*nd_cond
;
255 struct RNode
*nd_body
;
256 struct RNode
*nd_else
;
259 typedef struct RNode_UNLESS
{
262 struct RNode
*nd_cond
;
263 struct RNode
*nd_body
;
264 struct RNode
*nd_else
;
267 typedef struct RNode_CASE
{
270 struct RNode
*nd_head
;
271 struct RNode
*nd_body
;
274 typedef struct RNode_CASE2
{
277 struct RNode
*nd_head
;
278 struct RNode
*nd_body
;
281 typedef struct RNode_CASE3
{
284 struct RNode
*nd_head
;
285 struct RNode
*nd_body
;
288 typedef struct RNode_WHEN
{
291 struct RNode
*nd_head
;
292 struct RNode
*nd_body
;
293 struct RNode
*nd_next
;
296 typedef struct RNode_IN
{
299 struct RNode
*nd_head
;
300 struct RNode
*nd_body
;
301 struct RNode
*nd_next
;
304 /* RNode_WHILE and RNode_UNTIL should be same structure */
305 typedef struct RNode_WHILE
{
308 struct RNode
*nd_cond
;
309 struct RNode
*nd_body
;
313 typedef struct RNode_UNTIL
{
316 struct RNode
*nd_cond
;
317 struct RNode
*nd_body
;
321 /* RNode_ITER and RNode_FOR should be same structure */
322 typedef struct RNode_ITER
{
325 struct RNode
*nd_body
;
326 struct RNode
*nd_iter
;
329 typedef struct RNode_FOR
{
332 struct RNode
*nd_body
;
333 struct RNode
*nd_iter
;
336 typedef struct RNode_FOR_MASGN
{
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
{
346 struct RNode
*nd_chain
;
347 struct RNode
*nd_stts
;
350 typedef struct RNode_NEXT
{
353 struct RNode
*nd_chain
;
354 struct RNode
*nd_stts
;
357 typedef struct RNode_REDO
{
360 struct RNode
*nd_chain
;
363 typedef struct RNode_RETRY
{
367 typedef struct RNode_BEGIN
{
370 struct RNode
*nd_body
;
373 typedef struct RNode_RESCUE
{
376 struct RNode
*nd_head
;
377 struct RNode
*nd_resq
;
378 struct RNode
*nd_else
;
381 typedef struct RNode_RESBODY
{
384 struct RNode
*nd_args
;
385 struct RNode
*nd_body
;
386 struct RNode
*nd_next
;
389 typedef struct RNode_ENSURE
{
392 struct RNode
*nd_head
;
393 struct RNode
*nd_ensr
;
396 /* RNode_AND and RNode_OR should be same structure */
397 typedef struct RNode_AND
{
400 struct RNode
*nd_1st
;
401 struct RNode
*nd_2nd
;
404 typedef struct RNode_OR
{
407 struct RNode
*nd_1st
;
408 struct RNode
*nd_2nd
;
411 typedef struct RNode_MASGN
{
414 struct RNode
*nd_head
;
415 struct RNode
*nd_value
;
416 struct RNode
*nd_args
;
419 typedef struct RNode_LASGN
{
423 struct RNode
*nd_value
;
426 typedef struct RNode_DASGN
{
430 struct RNode
*nd_value
;
433 typedef struct RNode_GASGN
{
437 struct RNode
*nd_value
;
440 typedef struct RNode_IASGN
{
444 struct RNode
*nd_value
;
447 typedef struct RNode_CDECL
{
451 struct RNode
*nd_value
;
452 struct RNode
*nd_else
;
453 enum rb_parser_shareability shareability
;
456 typedef struct RNode_CVASGN
{
460 struct RNode
*nd_value
;
463 typedef struct RNode_OP_ASGN1
{
466 struct RNode
*nd_recv
;
468 struct RNode
*nd_index
;
469 struct RNode
*nd_rvalue
;
470 } rb_node_op_asgn1_t
;
472 typedef struct RNode_OP_ASGN2
{
475 struct RNode
*nd_recv
;
476 struct RNode
*nd_value
;
480 } rb_node_op_asgn2_t
;
482 typedef struct RNode_OP_ASGN_AND
{
485 struct RNode
*nd_head
;
486 struct RNode
*nd_value
;
487 } rb_node_op_asgn_and_t
;
489 typedef struct RNode_OP_ASGN_OR
{
492 struct RNode
*nd_head
;
493 struct RNode
*nd_value
;
494 } rb_node_op_asgn_or_t
;
496 typedef struct RNode_OP_CDECL
{
499 struct RNode
*nd_head
;
500 struct RNode
*nd_value
;
502 enum rb_parser_shareability shareability
;
503 } rb_node_op_cdecl_t
;
505 typedef struct RNode_CALL
{
508 struct RNode
*nd_recv
;
510 struct RNode
*nd_args
;
513 typedef struct RNode_OPCALL
{
516 struct RNode
*nd_recv
;
518 struct RNode
*nd_args
;
521 typedef struct RNode_FCALL
{
525 struct RNode
*nd_args
;
528 typedef struct RNode_VCALL
{
534 typedef struct RNode_QCALL
{
537 struct RNode
*nd_recv
;
539 struct RNode
*nd_args
;
542 typedef struct RNode_SUPER
{
545 struct RNode
*nd_args
;
548 typedef struct RNode_ZSUPER
{
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
{
567 struct RNode
*nd_head
; /* element */
570 struct RNode
*nd_end
; /* Second list node has this structure */
572 struct RNode
*nd_next
; /* next list node */
575 typedef struct RNode_ZLIST
{
579 typedef struct RNode_VALUES
{
582 struct RNode
*nd_head
;
584 struct RNode
*nd_next
;
587 typedef struct RNode_HASH
{
590 struct RNode
*nd_head
;
594 typedef struct RNode_RETURN
{
597 struct RNode
*nd_stts
;
600 typedef struct RNode_YIELD
{
603 struct RNode
*nd_head
;
606 typedef struct RNode_LVAR
{
612 typedef struct RNode_DVAR
{
618 typedef struct RNode_GVAR
{
624 typedef struct RNode_IVAR
{
630 typedef struct RNode_CONST
{
636 typedef struct RNode_CVAR
{
642 typedef struct RNode_NTH_REF
{
648 typedef struct RNode_BACK_REF
{
652 } rb_node_back_ref_t
;
654 /* RNode_MATCH and RNode_REGX should be same structure */
655 typedef struct RNode_MATCH
{
658 struct rb_parser_string
*string
;
662 typedef struct RNode_MATCH2
{
665 struct RNode
*nd_recv
;
666 struct RNode
*nd_value
;
667 struct RNode
*nd_args
;
670 typedef struct RNode_MATCH3
{
673 struct RNode
*nd_recv
;
674 struct RNode
*nd_value
;
677 typedef struct RNode_INTEGER
{
685 typedef struct RNode_FLOAT
{
692 typedef struct RNode_RATIONAL
{
699 } rb_node_rational_t
;
701 enum rb_numeric_type
{
707 typedef struct RNode_IMAGINARY
{
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
{
721 struct rb_parser_string
*string
;
724 /* RNode_DSTR, RNode_DXSTR and RNode_DSYM should be same structure */
725 typedef struct RNode_DSTR
{
728 struct rb_parser_string
*string
;
731 struct RNode
*nd_end
; /* Second dstr node has this structure. See also RNode_LIST */
733 struct RNode_LIST
*nd_next
;
736 typedef struct RNode_XSTR
{
739 struct rb_parser_string
*string
;
742 typedef struct RNode_DXSTR
{
745 struct rb_parser_string
*string
;
747 struct RNode_LIST
*nd_next
;
750 typedef struct RNode_EVSTR
{
753 struct RNode
*nd_body
;
756 typedef struct RNode_REGX
{
759 struct rb_parser_string
*string
;
763 typedef struct RNode_DREGX
{
766 struct rb_parser_string
*string
;
768 struct RNode_LIST
*nd_next
;
771 typedef struct RNode_ONCE
{
774 struct RNode
*nd_body
;
777 struct rb_args_info
{
781 int pre_args_num
; /* count of mandatory pre-arguments */
782 int post_args_num
; /* count of mandatory post-arguments */
789 struct RNode_KW_ARG
*kw_args
;
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
{
801 struct rb_args_info nd_ainfo
;
804 typedef struct RNode_ARGS_AUX
{
809 struct RNode
*nd_next
;
810 } rb_node_args_aux_t
;
812 typedef struct RNode_OPT_ARG
{
815 struct RNode
*nd_body
;
816 struct RNode_OPT_ARG
*nd_next
;
819 typedef struct RNode_KW_ARG
{
822 struct RNode
*nd_body
;
823 struct RNode_KW_ARG
*nd_next
;
826 typedef struct RNode_POSTARG
{
829 struct RNode
*nd_1st
;
830 struct RNode
*nd_2nd
;
833 typedef struct RNode_ARGSCAT
{
836 struct RNode
*nd_head
;
837 struct RNode
*nd_body
;
840 typedef struct RNode_ARGSPUSH
{
843 struct RNode
*nd_head
;
844 struct RNode
*nd_body
;
845 } rb_node_argspush_t
;
847 typedef struct RNode_SPLAT
{
850 struct RNode
*nd_head
;
853 typedef struct RNode_BLOCK_PASS
{
856 struct RNode
*nd_head
;
857 struct RNode
*nd_body
;
858 } rb_node_block_pass_t
;
860 typedef struct RNode_DEFN
{
864 struct RNode
*nd_defn
;
867 typedef struct RNode_DEFS
{
870 struct RNode
*nd_recv
;
872 struct RNode
*nd_defn
;
875 typedef struct RNode_ALIAS
{
878 struct RNode
*nd_1st
;
879 struct RNode
*nd_2nd
;
882 typedef struct RNode_VALIAS
{
889 typedef struct RNode_UNDEF
{
892 struct RNode
*nd_undef
;
895 typedef struct RNode_CLASS
{
898 struct RNode
*nd_cpath
;
899 struct RNode
*nd_body
;
900 struct RNode
*nd_super
;
903 typedef struct RNode_MODULE
{
906 struct RNode
*nd_cpath
;
907 struct RNode
*nd_body
;
910 typedef struct RNode_SCLASS
{
913 struct RNode
*nd_recv
;
914 struct RNode
*nd_body
;
917 typedef struct RNode_COLON2
{
920 struct RNode
*nd_head
;
924 typedef struct RNode_COLON3
{
930 /* RNode_DOT2, RNode_DOT3, RNode_FLIP2 and RNode_FLIP3 should be same structure */
931 typedef struct RNode_DOT2
{
934 struct RNode
*nd_beg
;
935 struct RNode
*nd_end
;
938 typedef struct RNode_DOT3
{
941 struct RNode
*nd_beg
;
942 struct RNode
*nd_end
;
945 typedef struct RNode_FLIP2
{
948 struct RNode
*nd_beg
;
949 struct RNode
*nd_end
;
952 typedef struct RNode_FLIP3
{
955 struct RNode
*nd_beg
;
956 struct RNode
*nd_end
;
959 typedef struct RNode_SELF
{
962 long nd_state
; /* Default 1. See NEW_SELF. */
965 typedef struct RNode_NIL
{
969 typedef struct RNode_TRUE
{
973 typedef struct RNode_FALSE
{
977 typedef struct RNode_ERRINFO
{
981 typedef struct RNode_DEFINED
{
984 struct RNode
*nd_head
;
987 typedef struct RNode_POSTEXE
{
990 struct RNode
*nd_body
;
993 typedef struct RNode_SYM
{
996 struct rb_parser_string
*string
;
999 typedef struct RNode_DSYM
{
1002 struct rb_parser_string
*string
;
1004 struct RNode_LIST
*nd_next
;
1007 typedef struct RNode_ATTRASGN
{
1010 struct RNode
*nd_recv
;
1012 struct RNode
*nd_args
;
1013 } rb_node_attrasgn_t
;
1015 typedef struct RNode_LAMBDA
{
1018 struct RNode
*nd_body
;
1021 typedef struct RNode_ARYPTN
{
1024 struct RNode
*nd_pconst
;
1030 typedef struct RNode_HSHPTN
{
1033 struct RNode
*nd_pconst
;
1034 struct RNode
*nd_pkwargs
;
1035 struct RNode
*nd_pkwrestarg
;
1038 typedef struct RNode_FNDPTN
{
1041 struct RNode
*nd_pconst
;
1044 NODE
*post_rest_arg
;
1047 typedef struct RNode_LINE
{
1051 typedef struct RNode_FILE
{
1054 struct rb_parser_string
*path
;
1057 typedef struct RNode_ENCODING
{
1060 } rb_node_encoding_t
;
1062 typedef struct RNode_ERROR
{
1066 #define RNODE(obj) ((struct RNode *)(obj))
1068 #define RNODE_SCOPE(node) ((struct RNode_SCOPE *)(node))
1069 #define RNODE_BLOCK(node) ((struct RNode_BLOCK *)(node))
1070 #define RNODE_IF(node) ((struct RNode_IF *)(node))
1071 #define RNODE_UNLESS(node) ((struct RNode_UNLESS *)(node))
1072 #define RNODE_CASE(node) ((struct RNode_CASE *)(node))
1073 #define RNODE_CASE2(node) ((struct RNode_CASE2 *)(node))
1074 #define RNODE_CASE3(node) ((struct RNode_CASE3 *)(node))
1075 #define RNODE_WHEN(node) ((struct RNode_WHEN *)(node))
1076 #define RNODE_IN(node) ((struct RNode_IN *)(node))
1077 #define RNODE_WHILE(node) ((struct RNode_WHILE *)(node))
1078 #define RNODE_UNTIL(node) ((struct RNode_UNTIL *)(node))
1079 #define RNODE_ITER(node) ((struct RNode_ITER *)(node))
1080 #define RNODE_FOR(node) ((struct RNode_FOR *)(node))
1081 #define RNODE_FOR_MASGN(node) ((struct RNode_FOR_MASGN *)(node))
1082 #define RNODE_BREAK(node) ((struct RNode_BREAK *)(node))
1083 #define RNODE_NEXT(node) ((struct RNode_NEXT *)(node))
1084 #define RNODE_REDO(node) ((struct RNode_REDO *)(node))
1085 #define RNODE_RETRY(node) ((struct RNode_RETRY *)(node))
1086 #define RNODE_BEGIN(node) ((struct RNode_BEGIN *)(node))
1087 #define RNODE_RESCUE(node) ((struct RNode_RESCUE *)(node))
1088 #define RNODE_RESBODY(node) ((struct RNode_RESBODY *)(node))
1089 #define RNODE_ENSURE(node) ((struct RNode_ENSURE *)(node))
1090 #define RNODE_AND(node) ((struct RNode_AND *)(node))
1091 #define RNODE_OR(node) ((struct RNode_OR *)(node))
1092 #define RNODE_MASGN(node) ((struct RNode_MASGN *)(node))
1093 #define RNODE_LASGN(node) ((struct RNode_LASGN *)(node))
1094 #define RNODE_DASGN(node) ((struct RNode_DASGN *)(node))
1095 #define RNODE_GASGN(node) ((struct RNode_GASGN *)(node))
1096 #define RNODE_IASGN(node) ((struct RNode_IASGN *)(node))
1097 #define RNODE_CDECL(node) ((struct RNode_CDECL *)(node))
1098 #define RNODE_CVASGN(node) ((struct RNode_CVASGN *)(node))
1099 #define RNODE_OP_ASGN1(node) ((struct RNode_OP_ASGN1 *)(node))
1100 #define RNODE_OP_ASGN2(node) ((struct RNode_OP_ASGN2 *)(node))
1101 #define RNODE_OP_ASGN_AND(node) ((struct RNode_OP_ASGN_AND *)(node))
1102 #define RNODE_OP_ASGN_OR(node) ((struct RNode_OP_ASGN_OR *)(node))
1103 #define RNODE_OP_CDECL(node) ((struct RNode_OP_CDECL *)(node))
1104 #define RNODE_CALL(node) ((struct RNode_CALL *)(node))
1105 #define RNODE_OPCALL(node) ((struct RNode_OPCALL *)(node))
1106 #define RNODE_FCALL(node) ((struct RNode_FCALL *)(node))
1107 #define RNODE_VCALL(node) ((struct RNode_VCALL *)(node))
1108 #define RNODE_QCALL(node) ((struct RNode_QCALL *)(node))
1109 #define RNODE_SUPER(node) ((struct RNode_SUPER *)(node))
1110 #define RNODE_ZSUPER(node) ((struct RNode_ZSUPER *)(node))
1111 #define RNODE_LIST(node) ((struct RNode_LIST *)(node))
1112 #define RNODE_ZLIST(node) ((struct RNode_ZLIST *)(node))
1113 #define RNODE_HASH(node) ((struct RNode_HASH *)(node))
1114 #define RNODE_RETURN(node) ((struct RNode_RETURN *)(node))
1115 #define RNODE_YIELD(node) ((struct RNode_YIELD *)(node))
1116 #define RNODE_LVAR(node) ((struct RNode_LVAR *)(node))
1117 #define RNODE_DVAR(node) ((struct RNode_DVAR *)(node))
1118 #define RNODE_GVAR(node) ((struct RNode_GVAR *)(node))
1119 #define RNODE_IVAR(node) ((struct RNode_IVAR *)(node))
1120 #define RNODE_CONST(node) ((struct RNode_CONST *)(node))
1121 #define RNODE_CVAR(node) ((struct RNode_CVAR *)(node))
1122 #define RNODE_NTH_REF(node) ((struct RNode_NTH_REF *)(node))
1123 #define RNODE_BACK_REF(node) ((struct RNode_BACK_REF *)(node))
1124 #define RNODE_MATCH(node) ((struct RNode_MATCH *)(node))
1125 #define RNODE_MATCH2(node) ((struct RNode_MATCH2 *)(node))
1126 #define RNODE_MATCH3(node) ((struct RNode_MATCH3 *)(node))
1127 #define RNODE_INTEGER(node) ((struct RNode_INTEGER *)(node))
1128 #define RNODE_FLOAT(node) ((struct RNode_FLOAT *)(node))
1129 #define RNODE_RATIONAL(node) ((struct RNode_RATIONAL *)(node))
1130 #define RNODE_IMAGINARY(node) ((struct RNode_IMAGINARY *)(node))
1131 #define RNODE_STR(node) ((struct RNode_STR *)(node))
1132 #define RNODE_DSTR(node) ((struct RNode_DSTR *)(node))
1133 #define RNODE_XSTR(node) ((struct RNode_XSTR *)(node))
1134 #define RNODE_DXSTR(node) ((struct RNode_DXSTR *)(node))
1135 #define RNODE_EVSTR(node) ((struct RNode_EVSTR *)(node))
1136 #define RNODE_REGX(node) ((struct RNode_REGX *)(node))
1137 #define RNODE_DREGX(node) ((struct RNode_DREGX *)(node))
1138 #define RNODE_ONCE(node) ((struct RNode_ONCE *)(node))
1139 #define RNODE_ARGS(node) ((struct RNode_ARGS *)(node))
1140 #define RNODE_ARGS_AUX(node) ((struct RNode_ARGS_AUX *)(node))
1141 #define RNODE_OPT_ARG(node) ((struct RNode_OPT_ARG *)(node))
1142 #define RNODE_KW_ARG(node) ((struct RNode_KW_ARG *)(node))
1143 #define RNODE_POSTARG(node) ((struct RNode_POSTARG *)(node))
1144 #define RNODE_ARGSCAT(node) ((struct RNode_ARGSCAT *)(node))
1145 #define RNODE_ARGSPUSH(node) ((struct RNode_ARGSPUSH *)(node))
1146 #define RNODE_SPLAT(node) ((struct RNode_SPLAT *)(node))
1147 #define RNODE_BLOCK_PASS(node) ((struct RNode_BLOCK_PASS *)(node))
1148 #define RNODE_DEFN(node) ((struct RNode_DEFN *)(node))
1149 #define RNODE_DEFS(node) ((struct RNode_DEFS *)(node))
1150 #define RNODE_ALIAS(node) ((struct RNode_ALIAS *)(node))
1151 #define RNODE_VALIAS(node) ((struct RNode_VALIAS *)(node))
1152 #define RNODE_UNDEF(node) ((struct RNode_UNDEF *)(node))
1153 #define RNODE_CLASS(node) ((struct RNode_CLASS *)(node))
1154 #define RNODE_MODULE(node) ((struct RNode_MODULE *)(node))
1155 #define RNODE_SCLASS(node) ((struct RNode_SCLASS *)(node))
1156 #define RNODE_COLON2(node) ((struct RNode_COLON2 *)(node))
1157 #define RNODE_COLON3(node) ((struct RNode_COLON3 *)(node))
1158 #define RNODE_DOT2(node) ((struct RNode_DOT2 *)(node))
1159 #define RNODE_DOT3(node) ((struct RNode_DOT3 *)(node))
1160 #define RNODE_FLIP2(node) ((struct RNode_FLIP2 *)(node))
1161 #define RNODE_FLIP3(node) ((struct RNode_FLIP3 *)(node))
1162 #define RNODE_SELF(node) ((struct RNode_SELF *)(node))
1163 #define RNODE_NIL(node) ((struct RNode_NIL *)(node))
1164 #define RNODE_TRUE(node) ((struct RNode_TRUE *)(node))
1165 #define RNODE_FALSE(node) ((struct RNode_FALSE *)(node))
1166 #define RNODE_ERRINFO(node) ((struct RNode_ERRINFO *)(node))
1167 #define RNODE_DEFINED(node) ((struct RNode_DEFINED *)(node))
1168 #define RNODE_POSTEXE(node) ((struct RNode_POSTEXE *)(node))
1169 #define RNODE_SYM(node) ((struct RNode_SYM *)(node))
1170 #define RNODE_DSYM(node) ((struct RNode_DSYM *)(node))
1171 #define RNODE_ATTRASGN(node) ((struct RNode_ATTRASGN *)(node))
1172 #define RNODE_LAMBDA(node) ((struct RNode_LAMBDA *)(node))
1173 #define RNODE_ARYPTN(node) ((struct RNode_ARYPTN *)(node))
1174 #define RNODE_HSHPTN(node) ((struct RNode_HSHPTN *)(node))
1175 #define RNODE_FNDPTN(node) ((struct RNode_FNDPTN *)(node))
1176 #define RNODE_LINE(node) ((struct RNode_LINE *)(node))
1177 #define RNODE_FILE(node) ((struct RNode_FILE *)(node))
1178 #define RNODE_ENCODING(node) ((struct RNode_ENCODING *)(node))
1180 /* FL : 0..4: T_TYPES, 5: KEEP_WB, 6: PROMOTED, 7: FINALIZE, 8: UNUSED, 9: UNUSED, 10: EXIVAR, 11: FREEZE */
1181 /* NODE_FL: 0..4: T_TYPES, 5: KEEP_WB, 6: PROMOTED, 7: NODE_FL_NEWLINE,
1185 #define NODE_FL_NEWLINE (((VALUE)1)<<7)
1187 #define NODE_TYPESHIFT 8
1188 #define NODE_TYPEMASK (((VALUE)0x7f)<<NODE_TYPESHIFT)
1190 #define nd_fl_newline(n) (n)->flags & NODE_FL_NEWLINE
1191 #define nd_set_fl_newline(n) (n)->flags |= NODE_FL_NEWLINE
1192 #define nd_unset_fl_newline(n) (n)->flags &= ~NODE_FL_NEWLINE
1194 #define nd_type(n) ((int) ((RNODE(n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
1195 #define nd_set_type(n,t) \
1196 rb_node_set_type(n, t)
1197 #define nd_init_type(n,t) \
1198 (n)->flags=(((n)->flags&~NODE_TYPEMASK)|((((unsigned long)(t))<<NODE_TYPESHIFT)&NODE_TYPEMASK))
1200 typedef struct node_buffer_struct node_buffer_t
;
1202 typedef struct rb_ast_body_struct
{
1205 // script_lines is either:
1206 // - a Fixnum that represents the line count of the original source, or
1207 // - an Array that contains the lines of the original source
1208 signed int frozen_string_literal
:2; /* -1: not specified, 0: false, 1: true */
1209 signed int coverage_enabled
:2; /* -1: not specified, 0: false, 1: true */
1211 typedef struct rb_ast_struct
{
1213 node_buffer_t
*node_buffer
;
1224 typedef struct parser_params rb_parser_t
;
1225 #ifndef INTERNAL_IMEMO_H
1226 typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t
;
1229 #ifdef UNIVERSAL_PARSER
1230 typedef struct rb_parser_config_struct
{
1232 void *(*malloc
)(size_t size
);
1233 void *(*calloc
)(size_t number
, size_t size
);
1234 void *(*realloc
)(void *ptr
, size_t newsiz
);
1235 void (*free
)(void *ptr
);
1236 void *(*alloc_n
)(size_t nelems
, size_t elemsiz
);
1237 void *(*alloc
)(size_t elemsiz
);
1238 void *(*realloc_n
)(void *ptr
, size_t newelems
, size_t newsiz
);
1239 void *(*zalloc
)(size_t elemsiz
);
1240 void *(*rb_memmove
)(void *dest
, const void *src
, size_t t
, size_t n
);
1241 void *(*nonempty_memcpy
)(void *dest
, const void *src
, size_t t
, size_t n
);
1242 void *(*xmalloc_mul_add
)(size_t x
, size_t y
, size_t z
);
1245 rb_ast_t
*(*ast_new
)(VALUE nb
);
1247 // VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
1248 VALUE (*compile_callback
)(VALUE (*func
)(VALUE
), VALUE arg
);
1249 NODE
*(*reg_named_capture_assign
)(struct parser_params
* p
, VALUE regexp
, const rb_code_location_t
*loc
);
1252 VALUE (*obj_freeze
)(VALUE obj
);
1253 VALUE (*obj_hide
)(VALUE obj
);
1254 void (*obj_freeze_raw
)(VALUE obj
);
1256 int (*fixnum_p
)(VALUE
);
1257 int (*symbol_p
)(VALUE
);
1260 VALUE (*attr_get
)(VALUE obj
, ID id
);
1263 VALUE (*ary_new
)(void);
1264 VALUE (*ary_push
)(VALUE ary
, VALUE elem
);
1265 VALUE (*ary_new_from_args
)(long n
, ...);
1266 VALUE (*ary_unshift
)(VALUE ary
, VALUE item
);
1267 VALUE (*ary_new2
)(long capa
); // ary_new_capa
1268 VALUE (*ary_clear
)(VALUE ary
);
1269 void (*ary_modify
)(VALUE ary
);
1270 long (*array_len
)(VALUE a
);
1271 VALUE (*array_aref
)(VALUE
, long);
1274 ID (*make_temporary_id
)(size_t n
);
1275 int (*is_local_id
)(ID
);
1276 int (*is_attrset_id
)(ID
);
1277 int (*is_global_name_punct
)(const int c
);
1278 int (*id_type
)(ID id
);
1279 ID (*id_attrset
)(ID
);
1280 ID (*intern
)(const char *name
);
1281 ID (*intern2
)(const char *name
, long len
);
1282 ID (*intern3
)(const char *name
, long len
, rb_encoding
*enc
);
1283 ID (*intern_str
)(VALUE str
);
1284 int (*is_notop_id
)(ID
);
1285 int (*enc_symname_type
)(const char *name
, long len
, rb_encoding
*enc
, unsigned int allowed_attrset
);
1286 const char *(*id2name
)(ID id
);
1287 VALUE (*id2str
)(ID id
);
1288 VALUE (*id2sym
)(ID x
);
1289 ID (*sym2id
)(VALUE sym
);
1292 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 3)
1293 VALUE (*str_catf
)(VALUE str
, const char *format
, ...);
1294 VALUE (*str_cat_cstr
)(VALUE str
, const char *ptr
);
1295 VALUE (*str_subseq
)(VALUE str
, long beg
, long len
);
1296 VALUE (*str_new_frozen
)(VALUE orig
);
1297 VALUE (*str_buf_new
)(long capa
);
1298 VALUE (*str_buf_cat
)(VALUE
, const char*, long);
1299 void (*str_modify
)(VALUE str
);
1300 void (*str_set_len
)(VALUE str
, long len
);
1301 VALUE (*str_cat
)(VALUE str
, const char *ptr
, long len
);
1302 VALUE (*str_resize
)(VALUE str
, long len
);
1303 VALUE (*str_new
)(const char *ptr
, long len
);
1304 VALUE (*str_new_cstr
)(const char *ptr
);
1305 VALUE (*str_to_interned_str
)(VALUE
);
1306 int (*is_ascii_string
)(VALUE str
);
1307 VALUE (*enc_str_new
)(const char *ptr
, long len
, rb_encoding
*enc
);
1308 VALUE (*enc_str_buf_cat
)(VALUE str
, const char *ptr
, long len
, rb_encoding
*enc
);
1309 VALUE (*str_buf_append
)(VALUE str
, VALUE str2
);
1310 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 0)
1311 VALUE (*str_vcatf
)(VALUE str
, const char *fmt
, va_list ap
);
1312 char *(*string_value_cstr
)(volatile VALUE
*ptr
);
1313 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 1, 2)
1314 VALUE (*rb_sprintf
)(const char *format
, ...);
1315 char *(*rstring_ptr
)(VALUE str
);
1316 char *(*rstring_end
)(VALUE str
);
1317 long (*rstring_len
)(VALUE str
);
1318 VALUE (*filesystem_str_new_cstr
)(const char *ptr
);
1319 VALUE (*obj_as_string
)(VALUE
);
1322 VALUE (*hash_clear
)(VALUE hash
);
1323 VALUE (*hash_new
)(void);
1324 VALUE (*hash_aset
)(VALUE hash
, VALUE key
, VALUE val
);
1325 VALUE (*hash_delete
)(VALUE hash
, VALUE key
);
1326 VALUE (*hash_lookup
)(VALUE hash
, VALUE key
);
1327 VALUE (*ident_hash_new
)(void);
1330 int (*num2int
)(VALUE val
);
1331 VALUE (*int2num
)(int v
);
1334 int (*stderr_tty_p
)(void);
1335 void (*write_error_str
)(VALUE mesg
);
1336 VALUE (*default_rs
)(void);
1337 VALUE (*io_write
)(VALUE io
, VALUE str
);
1338 VALUE (*io_flush
)(VALUE io
);
1339 VALUE (*io_puts
)(int argc
, const VALUE
*argv
, VALUE out
);
1340 VALUE (*io_gets_internal
)(VALUE io
);
1343 VALUE (*debug_output_stdout
)(void);
1344 VALUE (*debug_output_stderr
)(void);
1347 int (*is_usascii_enc
)(rb_encoding
*enc
);
1348 int (*enc_isalnum
)(OnigCodePoint c
, rb_encoding
*enc
);
1349 int (*enc_precise_mbclen
)(const char *p
, const char *e
, rb_encoding
*enc
);
1350 int (*mbclen_charfound_p
)(int len
);
1351 int (*mbclen_charfound_len
)(int len
);
1352 const char *(*enc_name
)(rb_encoding
*enc
);
1353 char *(*enc_prev_char
)(const char *s
, const char *p
, const char *e
, rb_encoding
*enc
);
1354 rb_encoding
* (*enc_get
)(VALUE obj
);
1355 int (*enc_asciicompat
)(rb_encoding
*enc
);
1356 rb_encoding
*(*utf8_encoding
)(void);
1357 VALUE (*enc_associate
)(VALUE obj
, rb_encoding
*enc
);
1358 rb_encoding
*(*ascii8bit_encoding
)(void);
1359 int (*enc_codelen
)(int c
, rb_encoding
*enc
);
1360 int (*enc_mbcput
)(unsigned int c
, void *buf
, rb_encoding
*enc
);
1361 int (*enc_find_index
)(const char *name
);
1362 rb_encoding
*(*enc_from_index
)(int idx
);
1363 VALUE (*enc_associate_index
)(VALUE obj
, int encindex
);
1364 int (*enc_isspace
)(OnigCodePoint c
, rb_encoding
*enc
);
1365 rb_encoding
*(*enc_compatible
)(VALUE str1
, VALUE str2
);
1366 VALUE (*enc_from_encoding
)(rb_encoding
*enc
);
1367 int (*encoding_is_ascii8bit
)(VALUE obj
);
1368 rb_encoding
*(*usascii_encoding
)(void);
1369 int enc_coderange_broken
;
1370 int (*enc_mbminlen
)(rb_encoding
*enc
);
1371 bool (*enc_isascii
)(OnigCodePoint c
, rb_encoding
*enc
);
1372 OnigCodePoint (*enc_mbc_to_codepoint
)(const char *p
, const char *e
, rb_encoding
*enc
);
1375 // int rb_local_defined(ID id, const rb_iseq_t *iseq);
1376 int (*local_defined
)(ID
, const void*);
1377 // int rb_dvar_defined(ID id, const rb_iseq_t *iseq);
1378 int (*dvar_defined
)(ID
, const void*);
1380 /* Error (Exception) */
1381 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 6, 0)
1382 VALUE (*syntax_error_append
)(VALUE
, VALUE
, int, int, rb_encoding
*, const char*, va_list);
1383 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 3)
1384 void (*raise
)(VALUE exc
, const char *fmt
, ...);
1385 VALUE (*syntax_error_new
)(void);
1388 VALUE (*errinfo
)(void);
1389 void (*set_errinfo
)(VALUE err
);
1390 void (*exc_raise
)(VALUE mesg
);
1391 VALUE (*make_exception
)(int argc
, const VALUE
*argv
);
1394 void (*sized_xfree
)(void *x
, size_t size
);
1395 void *(*sized_realloc_n
)(void *ptr
, size_t new_count
, size_t element_size
, size_t old_count
);
1396 VALUE (*obj_write
)(VALUE
, VALUE
*, VALUE
);
1397 VALUE (*obj_written
)(VALUE
, VALUE
, VALUE
);
1398 void (*gc_guard
)(VALUE
);
1399 void (*gc_mark
)(VALUE
);
1400 void (*gc_mark_and_move
)(VALUE
*ptr
);
1401 VALUE (*gc_location
)(VALUE value
);
1404 VALUE (*reg_compile
)(VALUE str
, int options
, const char *sourcefile
, int sourceline
);
1405 VALUE (*reg_check_preprocess
)(VALUE str
);
1406 int (*memcicmp
)(const void *x
, const void *y
, long len
);
1409 void (*compile_warn
)(const char *file
, int line
, const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(3, 4);
1410 void (*compile_warning
)(const char *file
, int line
, const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(3, 4);
1411 void (*bug
)(const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(1, 2);
1412 void (*fatal
)(const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(1, 2);
1413 VALUE (*verbose
)(void);
1414 int *(*errno_ptr
)(void);
1417 VALUE (*make_backtrace
)(void);
1420 unsigned long (*scan_hex
)(const char *start
, size_t len
, size_t *retlen
);
1421 unsigned long (*scan_oct
)(const char *start
, size_t len
, size_t *retlen
);
1422 unsigned long (*scan_digits
)(const char *str
, ssize_t len
, int base
, size_t *retlen
, int *overflow
);
1423 double (*strtod
)(const char *s00
, char **se
);
1426 VALUE (*rbool
)(VALUE
);
1427 int (*undef_p
)(VALUE
);
1428 int (*rtest
)(VALUE obj
);
1429 int (*nil_p
)(VALUE obj
);
1434 VALUE (*eArgError
)(void);
1435 VALUE (*mRubyVMFrozenCore
)(void);
1436 int (*long2int
)(long);
1438 VALUE (*node_case_when_optimizable_literal
)(const NODE
*const node
);
1441 int enc_coderange_7bit
;
1442 int enc_coderange_unknown
;
1443 VALUE (*static_id2sym
)(ID id
);
1444 long (*str_coderange_scan_restartable
)(const char *s
, const char *e
, rb_encoding
*enc
, int *cr
);
1445 } rb_parser_config_t
;
1448 #undef OnigCodePoint
1449 #endif /* UNIVERSAL_PARSER */
1451 RUBY_SYMBOL_EXPORT_BEGIN
1452 void rb_ruby_parser_free(void *ptr
);
1453 rb_ast_t
* rb_ruby_parser_compile_string(rb_parser_t
*p
, const char *f
, VALUE s
, int line
);
1455 #ifdef UNIVERSAL_PARSER
1456 rb_parser_t
*rb_ruby_parser_allocate(const rb_parser_config_t
*config
);
1457 rb_parser_t
*rb_ruby_parser_new(const rb_parser_config_t
*config
);
1460 long rb_parser_string_length(rb_parser_string_t
*str
);
1461 char *rb_parser_string_pointer(rb_parser_string_t
*str
);
1463 RUBY_SYMBOL_EXPORT_END
1465 #endif /* RUBY_RUBYPARSER_H */