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 const 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
,
76 typedef void* rb_parser_input_data
;
197 typedef struct rb_ast_id_table
{
199 ID ids
[FLEX_ARY_LEN
];
202 typedef struct rb_code_position_struct
{
205 } rb_code_position_t
;
207 typedef struct rb_code_location_struct
{
208 rb_code_position_t beg_pos
;
209 rb_code_position_t end_pos
;
210 } rb_code_location_t
;
211 #define YYLTYPE rb_code_location_t
212 #define YYLTYPE_IS_DECLARED 1
214 typedef struct rb_parser_ast_token
{
216 const char *type_name
;
217 rb_parser_string_t
*str
;
218 rb_code_location_t loc
;
219 } rb_parser_ast_token_t
;
222 * Array-like object for parser
224 typedef void* rb_parser_ary_data
;
226 enum rb_parser_ary_data_type
{
227 PARSER_ARY_DATA_AST_TOKEN
,
228 PARSER_ARY_DATA_SCRIPT_LINE
231 typedef struct rb_parser_ary
{
232 enum rb_parser_ary_data_type data_type
;
233 rb_parser_ary_data
*data
;
234 long len
; // current size
235 long capa
; // capacity
238 /* Header part of AST Node */
239 typedef struct RNode
{
241 rb_code_location_t nd_loc
;
245 typedef struct RNode_SCOPE
{
248 rb_ast_id_table_t
*nd_tbl
;
249 struct RNode
*nd_body
;
250 struct RNode_ARGS
*nd_args
;
253 typedef struct RNode_BLOCK
{
256 struct RNode
*nd_head
;
257 struct RNode
*nd_end
;
258 struct RNode
*nd_next
;
261 typedef struct RNode_IF
{
264 struct RNode
*nd_cond
;
265 struct RNode
*nd_body
;
266 struct RNode
*nd_else
;
269 typedef struct RNode_UNLESS
{
272 struct RNode
*nd_cond
;
273 struct RNode
*nd_body
;
274 struct RNode
*nd_else
;
277 typedef struct RNode_CASE
{
280 struct RNode
*nd_head
;
281 struct RNode
*nd_body
;
284 typedef struct RNode_CASE2
{
287 struct RNode
*nd_head
;
288 struct RNode
*nd_body
;
291 typedef struct RNode_CASE3
{
294 struct RNode
*nd_head
;
295 struct RNode
*nd_body
;
298 typedef struct RNode_WHEN
{
301 struct RNode
*nd_head
;
302 struct RNode
*nd_body
;
303 struct RNode
*nd_next
;
306 typedef struct RNode_IN
{
309 struct RNode
*nd_head
;
310 struct RNode
*nd_body
;
311 struct RNode
*nd_next
;
314 /* RNode_WHILE and RNode_UNTIL should be same structure */
315 typedef struct RNode_WHILE
{
318 struct RNode
*nd_cond
;
319 struct RNode
*nd_body
;
323 typedef struct RNode_UNTIL
{
326 struct RNode
*nd_cond
;
327 struct RNode
*nd_body
;
331 /* RNode_ITER and RNode_FOR should be same structure */
332 typedef struct RNode_ITER
{
335 struct RNode
*nd_body
;
336 struct RNode
*nd_iter
;
339 typedef struct RNode_FOR
{
342 struct RNode
*nd_body
;
343 struct RNode
*nd_iter
;
346 typedef struct RNode_FOR_MASGN
{
349 struct RNode
*nd_var
;
350 } rb_node_for_masgn_t
;
352 /* RNode_BREAK, RNode_NEXT and RNode_REDO should be same structure */
353 typedef struct RNode_BREAK
{
356 struct RNode
*nd_chain
;
357 struct RNode
*nd_stts
;
360 typedef struct RNode_NEXT
{
363 struct RNode
*nd_chain
;
364 struct RNode
*nd_stts
;
367 typedef struct RNode_REDO
{
370 struct RNode
*nd_chain
;
373 typedef struct RNode_RETRY
{
377 typedef struct RNode_BEGIN
{
380 struct RNode
*nd_body
;
383 typedef struct RNode_RESCUE
{
386 struct RNode
*nd_head
;
387 struct RNode
*nd_resq
;
388 struct RNode
*nd_else
;
391 typedef struct RNode_RESBODY
{
394 struct RNode
*nd_args
;
395 struct RNode
*nd_body
;
396 struct RNode
*nd_next
;
399 typedef struct RNode_ENSURE
{
402 struct RNode
*nd_head
;
403 struct RNode
*nd_ensr
;
406 /* RNode_AND and RNode_OR should be same structure */
407 typedef struct RNode_AND
{
410 struct RNode
*nd_1st
;
411 struct RNode
*nd_2nd
;
414 typedef struct RNode_OR
{
417 struct RNode
*nd_1st
;
418 struct RNode
*nd_2nd
;
421 typedef struct RNode_MASGN
{
424 struct RNode
*nd_head
;
425 struct RNode
*nd_value
;
426 struct RNode
*nd_args
;
429 typedef struct RNode_LASGN
{
433 struct RNode
*nd_value
;
436 typedef struct RNode_DASGN
{
440 struct RNode
*nd_value
;
443 typedef struct RNode_GASGN
{
447 struct RNode
*nd_value
;
450 typedef struct RNode_IASGN
{
454 struct RNode
*nd_value
;
457 typedef struct RNode_CDECL
{
461 struct RNode
*nd_value
;
462 struct RNode
*nd_else
;
463 enum rb_parser_shareability shareability
;
466 typedef struct RNode_CVASGN
{
470 struct RNode
*nd_value
;
473 typedef struct RNode_OP_ASGN1
{
476 struct RNode
*nd_recv
;
478 struct RNode
*nd_index
;
479 struct RNode
*nd_rvalue
;
480 } rb_node_op_asgn1_t
;
482 typedef struct RNode_OP_ASGN2
{
485 struct RNode
*nd_recv
;
486 struct RNode
*nd_value
;
490 } rb_node_op_asgn2_t
;
492 typedef struct RNode_OP_ASGN_AND
{
495 struct RNode
*nd_head
;
496 struct RNode
*nd_value
;
497 } rb_node_op_asgn_and_t
;
499 typedef struct RNode_OP_ASGN_OR
{
502 struct RNode
*nd_head
;
503 struct RNode
*nd_value
;
504 } rb_node_op_asgn_or_t
;
506 typedef struct RNode_OP_CDECL
{
509 struct RNode
*nd_head
;
510 struct RNode
*nd_value
;
512 enum rb_parser_shareability shareability
;
513 } rb_node_op_cdecl_t
;
515 typedef struct RNode_CALL
{
518 struct RNode
*nd_recv
;
520 struct RNode
*nd_args
;
523 typedef struct RNode_OPCALL
{
526 struct RNode
*nd_recv
;
528 struct RNode
*nd_args
;
531 typedef struct RNode_FCALL
{
535 struct RNode
*nd_args
;
538 typedef struct RNode_VCALL
{
544 typedef struct RNode_QCALL
{
547 struct RNode
*nd_recv
;
549 struct RNode
*nd_args
;
552 typedef struct RNode_SUPER
{
555 struct RNode
*nd_args
;
558 typedef struct RNode_ZSUPER
{
567 * head --> element | * head
568 * alen (length of list) | * nd_end (point to the last LIST)
569 * next -----------------+ * next
572 RNode_LIST and RNode_VALUES should be same structure
574 typedef struct RNode_LIST
{
577 struct RNode
*nd_head
; /* element */
580 struct RNode
*nd_end
; /* Second list node has this structure */
582 struct RNode
*nd_next
; /* next list node */
585 typedef struct RNode_ZLIST
{
589 typedef struct RNode_VALUES
{
592 struct RNode
*nd_head
;
594 struct RNode
*nd_next
;
597 typedef struct RNode_HASH
{
600 struct RNode
*nd_head
;
604 typedef struct RNode_RETURN
{
607 struct RNode
*nd_stts
;
610 typedef struct RNode_YIELD
{
613 struct RNode
*nd_head
;
616 typedef struct RNode_LVAR
{
622 typedef struct RNode_DVAR
{
628 typedef struct RNode_GVAR
{
634 typedef struct RNode_IVAR
{
640 typedef struct RNode_CONST
{
646 typedef struct RNode_CVAR
{
652 typedef struct RNode_NTH_REF
{
658 typedef struct RNode_BACK_REF
{
662 } rb_node_back_ref_t
;
664 /* RNode_MATCH and RNode_REGX should be same structure */
665 typedef struct RNode_MATCH
{
668 struct rb_parser_string
*string
;
672 typedef struct RNode_MATCH2
{
675 struct RNode
*nd_recv
;
676 struct RNode
*nd_value
;
677 struct RNode
*nd_args
;
680 typedef struct RNode_MATCH3
{
683 struct RNode
*nd_recv
;
684 struct RNode
*nd_value
;
687 typedef struct RNode_INTEGER
{
695 typedef struct RNode_FLOAT
{
702 typedef struct RNode_RATIONAL
{
709 } rb_node_rational_t
;
711 enum rb_numeric_type
{
717 typedef struct RNode_IMAGINARY
{
724 enum rb_numeric_type type
;
725 } rb_node_imaginary_t
;
727 /* RNode_STR and RNode_XSTR should be same structure */
728 typedef struct RNode_STR
{
731 struct rb_parser_string
*string
;
734 /* RNode_DSTR, RNode_DXSTR, RNode_DREGX and RNode_DSYM should be same structure */
735 typedef struct RNode_DSTR
{
738 struct rb_parser_string
*string
;
742 struct RNode
*nd_end
; /* Second dstr node has this structure. See also RNode_LIST */
744 struct RNode_LIST
*nd_next
;
747 typedef rb_node_str_t rb_node_xstr_t
;
749 typedef rb_node_dstr_t rb_node_dxstr_t
;
751 typedef struct RNode_EVSTR
{
754 struct RNode
*nd_body
;
757 typedef struct RNode_REGX
{
760 struct rb_parser_string
*string
;
764 typedef rb_node_dstr_t rb_node_dregx_t
;
766 typedef struct RNode_ONCE
{
769 struct RNode
*nd_body
;
772 struct rb_args_info
{
776 int pre_args_num
; /* count of mandatory pre-arguments */
777 int post_args_num
; /* count of mandatory post-arguments */
784 struct RNode_KW_ARG
*kw_args
;
787 struct RNode_OPT_ARG
*opt_args
;
788 unsigned int no_kwarg
: 1;
789 unsigned int ruby2_keywords
: 1;
790 unsigned int forwarding
: 1;
793 typedef struct RNode_ARGS
{
796 struct rb_args_info nd_ainfo
;
799 typedef struct RNode_ARGS_AUX
{
804 struct RNode
*nd_next
;
805 } rb_node_args_aux_t
;
807 typedef struct RNode_OPT_ARG
{
810 struct RNode
*nd_body
;
811 struct RNode_OPT_ARG
*nd_next
;
814 typedef struct RNode_KW_ARG
{
817 struct RNode
*nd_body
;
818 struct RNode_KW_ARG
*nd_next
;
821 typedef struct RNode_POSTARG
{
824 struct RNode
*nd_1st
;
825 struct RNode
*nd_2nd
;
828 typedef struct RNode_ARGSCAT
{
831 struct RNode
*nd_head
;
832 struct RNode
*nd_body
;
835 typedef struct RNode_ARGSPUSH
{
838 struct RNode
*nd_head
;
839 struct RNode
*nd_body
;
840 } rb_node_argspush_t
;
842 typedef struct RNode_SPLAT
{
845 struct RNode
*nd_head
;
848 typedef struct RNode_BLOCK_PASS
{
851 struct RNode
*nd_head
;
852 struct RNode
*nd_body
;
853 } rb_node_block_pass_t
;
855 typedef struct RNode_DEFN
{
859 struct RNode
*nd_defn
;
862 typedef struct RNode_DEFS
{
865 struct RNode
*nd_recv
;
867 struct RNode
*nd_defn
;
870 typedef struct RNode_ALIAS
{
873 struct RNode
*nd_1st
;
874 struct RNode
*nd_2nd
;
877 typedef struct RNode_VALIAS
{
884 typedef struct RNode_UNDEF
{
887 struct RNode
*nd_undef
;
890 typedef struct RNode_CLASS
{
893 struct RNode
*nd_cpath
;
894 struct RNode
*nd_body
;
895 struct RNode
*nd_super
;
898 typedef struct RNode_MODULE
{
901 struct RNode
*nd_cpath
;
902 struct RNode
*nd_body
;
905 typedef struct RNode_SCLASS
{
908 struct RNode
*nd_recv
;
909 struct RNode
*nd_body
;
912 typedef struct RNode_COLON2
{
915 struct RNode
*nd_head
;
919 typedef struct RNode_COLON3
{
925 /* RNode_DOT2, RNode_DOT3, RNode_FLIP2 and RNode_FLIP3 should be same structure */
926 typedef struct RNode_DOT2
{
929 struct RNode
*nd_beg
;
930 struct RNode
*nd_end
;
933 typedef struct RNode_DOT3
{
936 struct RNode
*nd_beg
;
937 struct RNode
*nd_end
;
940 typedef rb_node_dot2_t rb_node_flip2_t
;
941 typedef rb_node_dot3_t rb_node_flip3_t
;
943 typedef struct RNode_SELF
{
946 long nd_state
; /* Default 1. See NEW_SELF. */
949 typedef struct RNode_NIL
{
953 typedef struct RNode_TRUE
{
957 typedef struct RNode_FALSE
{
961 typedef struct RNode_ERRINFO
{
965 typedef struct RNode_DEFINED
{
968 struct RNode
*nd_head
;
971 typedef struct RNode_POSTEXE
{
974 struct RNode
*nd_body
;
977 typedef struct RNode_SYM
{
980 struct rb_parser_string
*string
;
983 typedef rb_node_dstr_t rb_node_dsym_t
;
985 typedef struct RNode_ATTRASGN
{
988 struct RNode
*nd_recv
;
990 struct RNode
*nd_args
;
991 } rb_node_attrasgn_t
;
993 typedef struct RNode_LAMBDA
{
996 struct RNode
*nd_body
;
999 typedef struct RNode_ARYPTN
{
1002 struct RNode
*nd_pconst
;
1008 typedef struct RNode_HSHPTN
{
1011 struct RNode
*nd_pconst
;
1012 struct RNode
*nd_pkwargs
;
1013 struct RNode
*nd_pkwrestarg
;
1016 typedef struct RNode_FNDPTN
{
1019 struct RNode
*nd_pconst
;
1022 NODE
*post_rest_arg
;
1025 typedef struct RNode_LINE
{
1029 typedef struct RNode_FILE
{
1032 struct rb_parser_string
*path
;
1035 typedef struct RNode_ENCODING
{
1038 } rb_node_encoding_t
;
1040 typedef struct RNode_ERROR
{
1044 #define RNODE(obj) ((NODE *)(obj))
1046 #define RNODE_SCOPE(node) ((rb_node_scope_t *)(node))
1047 #define RNODE_BLOCK(node) ((rb_node_block_t *)(node))
1048 #define RNODE_IF(node) ((rb_node_if_t *)(node))
1049 #define RNODE_UNLESS(node) ((rb_node_unless_t *)(node))
1050 #define RNODE_CASE(node) ((rb_node_case_t *)(node))
1051 #define RNODE_CASE2(node) ((rb_node_case2_t *)(node))
1052 #define RNODE_CASE3(node) ((rb_node_case3_t *)(node))
1053 #define RNODE_WHEN(node) ((rb_node_when_t *)(node))
1054 #define RNODE_IN(node) ((rb_node_in_t *)(node))
1055 #define RNODE_WHILE(node) ((rb_node_while_t *)(node))
1056 #define RNODE_UNTIL(node) ((rb_node_until_t *)(node))
1057 #define RNODE_ITER(node) ((rb_node_iter_t *)(node))
1058 #define RNODE_FOR(node) ((rb_node_for_t *)(node))
1059 #define RNODE_FOR_MASGN(node) ((rb_node_for_masgn_t *)(node))
1060 #define RNODE_BREAK(node) ((rb_node_break_t *)(node))
1061 #define RNODE_NEXT(node) ((rb_node_next_t *)(node))
1062 #define RNODE_REDO(node) ((rb_node_redo_t *)(node))
1063 #define RNODE_RETRY(node) ((rb_node_retry_t *)(node))
1064 #define RNODE_BEGIN(node) ((rb_node_begin_t *)(node))
1065 #define RNODE_RESCUE(node) ((rb_node_rescue_t *)(node))
1066 #define RNODE_RESBODY(node) ((rb_node_resbody_t *)(node))
1067 #define RNODE_ENSURE(node) ((rb_node_ensure_t *)(node))
1068 #define RNODE_AND(node) ((rb_node_and_t *)(node))
1069 #define RNODE_OR(node) ((rb_node_or_t *)(node))
1070 #define RNODE_MASGN(node) ((rb_node_masgn_t *)(node))
1071 #define RNODE_LASGN(node) ((rb_node_lasgn_t *)(node))
1072 #define RNODE_DASGN(node) ((rb_node_dasgn_t *)(node))
1073 #define RNODE_GASGN(node) ((rb_node_gasgn_t *)(node))
1074 #define RNODE_IASGN(node) ((rb_node_iasgn_t *)(node))
1075 #define RNODE_CDECL(node) ((rb_node_cdecl_t *)(node))
1076 #define RNODE_CVASGN(node) ((rb_node_cvasgn_t *)(node))
1077 #define RNODE_OP_ASGN1(node) ((rb_node_op_asgn1_t *)(node))
1078 #define RNODE_OP_ASGN2(node) ((rb_node_op_asgn2_t *)(node))
1079 #define RNODE_OP_ASGN_AND(node) ((rb_node_op_asgn_and_t *)(node))
1080 #define RNODE_OP_ASGN_OR(node) ((rb_node_op_asgn_or_t *)(node))
1081 #define RNODE_OP_CDECL(node) ((rb_node_op_cdecl_t *)(node))
1082 #define RNODE_CALL(node) ((rb_node_call_t *)(node))
1083 #define RNODE_OPCALL(node) ((rb_node_opcall_t *)(node))
1084 #define RNODE_FCALL(node) ((rb_node_fcall_t *)(node))
1085 #define RNODE_VCALL(node) ((rb_node_vcall_t *)(node))
1086 #define RNODE_QCALL(node) ((rb_node_qcall_t *)(node))
1087 #define RNODE_SUPER(node) ((rb_node_super_t *)(node))
1088 #define RNODE_ZSUPER(node) ((rb_node_zsuper_t *)(node))
1089 #define RNODE_LIST(node) ((rb_node_list_t *)(node))
1090 #define RNODE_ZLIST(node) ((rb_node_zlist_t *)(node))
1091 #define RNODE_HASH(node) ((rb_node_hash_t *)(node))
1092 #define RNODE_RETURN(node) ((rb_node_return_t *)(node))
1093 #define RNODE_YIELD(node) ((rb_node_yield_t *)(node))
1094 #define RNODE_LVAR(node) ((rb_node_lvar_t *)(node))
1095 #define RNODE_DVAR(node) ((rb_node_dvar_t *)(node))
1096 #define RNODE_GVAR(node) ((rb_node_gvar_t *)(node))
1097 #define RNODE_IVAR(node) ((rb_node_ivar_t *)(node))
1098 #define RNODE_CONST(node) ((rb_node_const_t *)(node))
1099 #define RNODE_CVAR(node) ((rb_node_cvar_t *)(node))
1100 #define RNODE_NTH_REF(node) ((rb_node_nth_ref_t *)(node))
1101 #define RNODE_BACK_REF(node) ((rb_node_back_ref_t *)(node))
1102 #define RNODE_MATCH(node) ((rb_node_match_t *)(node))
1103 #define RNODE_MATCH2(node) ((rb_node_match2_t *)(node))
1104 #define RNODE_MATCH3(node) ((rb_node_match3_t *)(node))
1105 #define RNODE_INTEGER(node) ((rb_node_integer_t *)(node))
1106 #define RNODE_FLOAT(node) ((rb_node_float_t *)(node))
1107 #define RNODE_RATIONAL(node) ((rb_node_rational_t *)(node))
1108 #define RNODE_IMAGINARY(node) ((rb_node_imaginary_t *)(node))
1109 #define RNODE_STR(node) ((rb_node_str_t *)(node))
1110 #define RNODE_DSTR(node) ((rb_node_dstr_t *)(node))
1111 #define RNODE_XSTR(node) ((rb_node_xstr_t *)(node))
1112 #define RNODE_DXSTR(node) ((rb_node_dxstr_t *)(node))
1113 #define RNODE_EVSTR(node) ((rb_node_evstr_t *)(node))
1114 #define RNODE_REGX(node) ((rb_node_regx_t *)(node))
1115 #define RNODE_DREGX(node) ((rb_node_dregx_t *)(node))
1116 #define RNODE_ONCE(node) ((rb_node_once_t *)(node))
1117 #define RNODE_ARGS(node) ((rb_node_args_t *)(node))
1118 #define RNODE_ARGS_AUX(node) ((rb_node_args_aux_t *)(node))
1119 #define RNODE_OPT_ARG(node) ((rb_node_opt_arg_t *)(node))
1120 #define RNODE_KW_ARG(node) ((rb_node_kw_arg_t *)(node))
1121 #define RNODE_POSTARG(node) ((rb_node_postarg_t *)(node))
1122 #define RNODE_ARGSCAT(node) ((rb_node_argscat_t *)(node))
1123 #define RNODE_ARGSPUSH(node) ((rb_node_argspush_t *)(node))
1124 #define RNODE_SPLAT(node) ((rb_node_splat_t *)(node))
1125 #define RNODE_BLOCK_PASS(node) ((rb_node_block_pass_t *)(node))
1126 #define RNODE_DEFN(node) ((rb_node_defn_t *)(node))
1127 #define RNODE_DEFS(node) ((rb_node_defs_t *)(node))
1128 #define RNODE_ALIAS(node) ((rb_node_alias_t *)(node))
1129 #define RNODE_VALIAS(node) ((rb_node_valias_t *)(node))
1130 #define RNODE_UNDEF(node) ((rb_node_undef_t *)(node))
1131 #define RNODE_CLASS(node) ((rb_node_class_t *)(node))
1132 #define RNODE_MODULE(node) ((rb_node_module_t *)(node))
1133 #define RNODE_SCLASS(node) ((rb_node_sclass_t *)(node))
1134 #define RNODE_COLON2(node) ((rb_node_colon2_t *)(node))
1135 #define RNODE_COLON3(node) ((rb_node_colon3_t *)(node))
1136 #define RNODE_DOT2(node) ((rb_node_dot2_t *)(node))
1137 #define RNODE_DOT3(node) ((rb_node_dot3_t *)(node))
1138 #define RNODE_FLIP2(node) ((rb_node_flip2_t *)(node))
1139 #define RNODE_FLIP3(node) ((rb_node_flip3_t *)(node))
1140 #define RNODE_SELF(node) ((rb_node_self_t *)(node))
1141 #define RNODE_NIL(node) ((rb_node_nil_t *)(node))
1142 #define RNODE_TRUE(node) ((rb_node_true_t *)(node))
1143 #define RNODE_FALSE(node) ((rb_node_false_t *)(node))
1144 #define RNODE_ERRINFO(node) ((rb_node_errinfo_t *)(node))
1145 #define RNODE_DEFINED(node) ((rb_node_defined_t *)(node))
1146 #define RNODE_POSTEXE(node) ((rb_node_postexe_t *)(node))
1147 #define RNODE_SYM(node) ((rb_node_sym_t *)(node))
1148 #define RNODE_DSYM(node) ((rb_node_dsym_t *)(node))
1149 #define RNODE_ATTRASGN(node) ((rb_node_attrasgn_t *)(node))
1150 #define RNODE_LAMBDA(node) ((rb_node_lambda_t *)(node))
1151 #define RNODE_ARYPTN(node) ((rb_node_aryptn_t *)(node))
1152 #define RNODE_HSHPTN(node) ((rb_node_hshptn_t *)(node))
1153 #define RNODE_FNDPTN(node) ((rb_node_fndptn_t *)(node))
1154 #define RNODE_LINE(node) ((rb_node_line_t *)(node))
1155 #define RNODE_FILE(node) ((rb_node_file_t *)(node))
1156 #define RNODE_ENCODING(node) ((rb_node_encoding_t *)(node))
1158 /* FL : 0..4: T_TYPES, 5: KEEP_WB, 6: PROMOTED, 7: FINALIZE, 8: UNUSED, 9: UNUSED, 10: EXIVAR, 11: FREEZE */
1159 /* NODE_FL: 0..4: UNUSED, 5: UNUSED, 6: UNUSED, 7: NODE_FL_NEWLINE,
1163 #define NODE_FL_NEWLINE (((VALUE)1)<<7)
1165 #define NODE_TYPESHIFT 8
1166 #define NODE_TYPEMASK (((VALUE)0x7f)<<NODE_TYPESHIFT)
1168 #define nd_fl_newline(n) (n)->flags & NODE_FL_NEWLINE
1169 #define nd_set_fl_newline(n) (n)->flags |= NODE_FL_NEWLINE
1170 #define nd_unset_fl_newline(n) (n)->flags &= ~NODE_FL_NEWLINE
1172 #define nd_type(n) ((int) ((RNODE(n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
1173 #define nd_set_type(n,t) \
1174 rb_node_set_type(n, t)
1175 #define nd_init_type(n,t) \
1176 (n)->flags=(((n)->flags&~NODE_TYPEMASK)|((((unsigned long)(t))<<NODE_TYPESHIFT)&NODE_TYPEMASK))
1178 typedef struct node_buffer_struct node_buffer_t
;
1180 #ifdef UNIVERSAL_PARSER
1181 typedef struct rb_parser_config_struct rb_parser_config_t
;
1184 typedef struct rb_ast_body_struct
{
1186 rb_parser_ary_t
*script_lines
;
1188 signed int frozen_string_literal
:2; /* -1: not specified, 0: false, 1: true */
1189 signed int coverage_enabled
:2; /* -1: not specified, 0: false, 1: true */
1191 typedef struct rb_ast_struct
{
1192 node_buffer_t
*node_buffer
;
1194 #ifdef UNIVERSAL_PARSER
1195 const rb_parser_config_t
*config
;
1206 typedef struct parser_params rb_parser_t
;
1207 #ifndef INTERNAL_IMEMO_H
1208 typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t
;
1211 #ifdef UNIVERSAL_PARSER
1212 typedef struct rb_parser_config_struct
{
1214 void *(*malloc
)(size_t size
);
1215 void *(*calloc
)(size_t number
, size_t size
);
1216 void *(*realloc
)(void *ptr
, size_t newsiz
);
1217 void (*free
)(void *ptr
);
1218 void *(*alloc_n
)(size_t nelems
, size_t elemsiz
);
1219 void *(*alloc
)(size_t elemsiz
);
1220 void *(*realloc_n
)(void *ptr
, size_t newelems
, size_t newsiz
);
1221 void *(*zalloc
)(size_t elemsiz
);
1222 void *(*rb_memmove
)(void *dest
, const void *src
, size_t t
, size_t n
);
1223 void *(*nonempty_memcpy
)(void *dest
, const void *src
, size_t t
, size_t n
);
1224 void *(*xmalloc_mul_add
)(size_t x
, size_t y
, size_t z
);
1226 // VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
1227 VALUE (*compile_callback
)(VALUE (*func
)(VALUE
), VALUE arg
);
1228 NODE
*(*reg_named_capture_assign
)(struct parser_params
* p
, VALUE regexp
, const rb_code_location_t
*loc
);
1231 VALUE (*attr_get
)(VALUE obj
, ID id
);
1234 VALUE (*ary_new
)(void);
1235 VALUE (*ary_push
)(VALUE ary
, VALUE elem
);
1236 VALUE (*ary_new_from_args
)(long n
, ...);
1237 VALUE (*ary_unshift
)(VALUE ary
, VALUE item
);
1240 ID (*make_temporary_id
)(size_t n
);
1241 int (*is_local_id
)(ID
);
1242 int (*is_attrset_id
)(ID
);
1243 int (*is_global_name_punct
)(const int c
);
1244 int (*id_type
)(ID id
);
1245 ID (*id_attrset
)(ID
);
1246 ID (*intern
)(const char *name
);
1247 ID (*intern2
)(const char *name
, long len
);
1248 ID (*intern3
)(const char *name
, long len
, rb_encoding
*enc
);
1249 ID (*intern_str
)(VALUE str
);
1250 int (*is_notop_id
)(ID
);
1251 int (*enc_symname_type
)(const char *name
, long len
, rb_encoding
*enc
, unsigned int allowed_attrset
);
1252 const char *(*id2name
)(ID id
);
1253 VALUE (*id2str
)(ID id
);
1254 VALUE (*id2sym
)(ID x
);
1255 ID (*sym2id
)(VALUE sym
);
1258 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 3)
1259 VALUE (*str_catf
)(VALUE str
, const char *format
, ...);
1260 VALUE (*str_cat_cstr
)(VALUE str
, const char *ptr
);
1261 void (*str_modify
)(VALUE str
);
1262 void (*str_set_len
)(VALUE str
, long len
);
1263 VALUE (*str_cat
)(VALUE str
, const char *ptr
, long len
);
1264 VALUE (*str_resize
)(VALUE str
, long len
);
1265 VALUE (*str_new
)(const char *ptr
, long len
);
1266 VALUE (*str_new_cstr
)(const char *ptr
);
1267 VALUE (*str_to_interned_str
)(VALUE
);
1268 int (*is_ascii_string
)(VALUE str
);
1269 VALUE (*enc_str_new
)(const char *ptr
, long len
, rb_encoding
*enc
);
1270 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 0)
1271 VALUE (*str_vcatf
)(VALUE str
, const char *fmt
, va_list ap
);
1272 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 1, 2)
1273 VALUE (*rb_sprintf
)(const char *format
, ...);
1274 char *(*rstring_ptr
)(VALUE str
);
1275 char *(*rstring_end
)(VALUE str
);
1276 long (*rstring_len
)(VALUE str
);
1277 VALUE (*obj_as_string
)(VALUE
);
1280 VALUE (*int2num
)(int v
);
1283 int (*stderr_tty_p
)(void);
1284 void (*write_error_str
)(VALUE mesg
);
1285 VALUE (*io_write
)(VALUE io
, VALUE str
);
1286 VALUE (*io_flush
)(VALUE io
);
1287 VALUE (*io_puts
)(int argc
, const VALUE
*argv
, VALUE out
);
1290 VALUE (*debug_output_stdout
)(void);
1291 VALUE (*debug_output_stderr
)(void);
1294 int (*is_usascii_enc
)(rb_encoding
*enc
);
1295 int (*enc_isalnum
)(OnigCodePoint c
, rb_encoding
*enc
);
1296 int (*enc_precise_mbclen
)(const char *p
, const char *e
, rb_encoding
*enc
);
1297 int (*mbclen_charfound_p
)(int len
);
1298 int (*mbclen_charfound_len
)(int len
);
1299 const char *(*enc_name
)(rb_encoding
*enc
);
1300 char *(*enc_prev_char
)(const char *s
, const char *p
, const char *e
, rb_encoding
*enc
);
1301 rb_encoding
* (*enc_get
)(VALUE obj
);
1302 int (*enc_asciicompat
)(rb_encoding
*enc
);
1303 rb_encoding
*(*utf8_encoding
)(void);
1304 VALUE (*enc_associate
)(VALUE obj
, rb_encoding
*enc
);
1305 rb_encoding
*(*ascii8bit_encoding
)(void);
1306 int (*enc_codelen
)(int c
, rb_encoding
*enc
);
1307 int (*enc_mbcput
)(unsigned int c
, void *buf
, rb_encoding
*enc
);
1308 int (*enc_find_index
)(const char *name
);
1309 rb_encoding
*(*enc_from_index
)(int idx
);
1310 int (*enc_isspace
)(OnigCodePoint c
, rb_encoding
*enc
);
1311 rb_encoding
*(*usascii_encoding
)(void);
1312 int enc_coderange_broken
;
1313 int (*enc_mbminlen
)(rb_encoding
*enc
);
1314 bool (*enc_isascii
)(OnigCodePoint c
, rb_encoding
*enc
);
1315 OnigCodePoint (*enc_mbc_to_codepoint
)(const char *p
, const char *e
, rb_encoding
*enc
);
1318 // int rb_local_defined(ID id, const rb_iseq_t *iseq);
1319 int (*local_defined
)(ID
, const void*);
1320 // int rb_dvar_defined(ID id, const rb_iseq_t *iseq);
1321 int (*dvar_defined
)(ID
, const void*);
1323 /* Error (Exception) */
1324 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 6, 0)
1325 VALUE (*syntax_error_append
)(VALUE
, VALUE
, int, int, rb_encoding
*, const char*, va_list);
1326 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 3)
1327 void (*raise
)(VALUE exc
, const char *fmt
, ...);
1328 VALUE (*syntax_error_new
)(void);
1331 VALUE (*errinfo
)(void);
1332 void (*set_errinfo
)(VALUE err
);
1333 void (*exc_raise
)(VALUE mesg
);
1334 VALUE (*make_exception
)(int argc
, const VALUE
*argv
);
1337 void (*sized_xfree
)(void *x
, size_t size
);
1338 void *(*sized_realloc_n
)(void *ptr
, size_t new_count
, size_t element_size
, size_t old_count
);
1339 void (*gc_guard
)(VALUE
);
1340 void (*gc_mark
)(VALUE
);
1343 VALUE (*reg_compile
)(VALUE str
, int options
, const char *sourcefile
, int sourceline
);
1344 VALUE (*reg_check_preprocess
)(VALUE str
);
1345 int (*memcicmp
)(const void *x
, const void *y
, long len
);
1348 void (*compile_warn
)(const char *file
, int line
, const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(3, 4);
1349 void (*compile_warning
)(const char *file
, int line
, const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(3, 4);
1350 void (*bug
)(const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(1, 2);
1351 void (*fatal
)(const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(1, 2);
1352 VALUE (*verbose
)(void);
1353 int *(*errno_ptr
)(void);
1356 VALUE (*make_backtrace
)(void);
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
);
1365 int (*rtest
)(VALUE obj
);
1366 int (*nil_p
)(VALUE obj
);
1369 VALUE (*eArgError
)(void);
1370 int (*long2int
)(long);
1373 int enc_coderange_7bit
;
1374 int enc_coderange_unknown
;
1375 VALUE (*static_id2sym
)(ID id
);
1376 long (*str_coderange_scan_restartable
)(const char *s
, const char *e
, rb_encoding
*enc
, int *cr
);
1377 } rb_parser_config_t
;
1380 #undef OnigCodePoint
1381 #endif /* UNIVERSAL_PARSER */
1383 RUBY_SYMBOL_EXPORT_BEGIN
1384 void rb_ruby_parser_free(void *ptr
);
1386 #ifdef UNIVERSAL_PARSER
1387 rb_parser_t
*rb_ruby_parser_allocate(const rb_parser_config_t
*config
);
1388 rb_parser_t
*rb_ruby_parser_new(const rb_parser_config_t
*config
);
1391 long rb_parser_string_length(rb_parser_string_t
*str
);
1392 char *rb_parser_string_pointer(rb_parser_string_t
*str
);
1394 RUBY_SYMBOL_EXPORT_END
1396 #endif /* RUBY_RUBYPARSER_H */