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
= 1,
228 PARSER_ARY_DATA_SCRIPT_LINE
,
232 typedef struct rb_parser_ary
{
233 enum rb_parser_ary_data_type data_type
;
234 rb_parser_ary_data
*data
;
235 long len
; // current size
236 long capa
; // capacity
239 /* Header part of AST Node */
240 typedef struct RNode
{
242 rb_code_location_t nd_loc
;
246 typedef struct RNode_SCOPE
{
249 rb_ast_id_table_t
*nd_tbl
;
250 struct RNode
*nd_body
;
251 struct RNode_ARGS
*nd_args
;
254 typedef struct RNode_BLOCK
{
257 struct RNode
*nd_head
;
258 struct RNode
*nd_end
;
259 struct RNode
*nd_next
;
262 typedef struct RNode_IF
{
265 struct RNode
*nd_cond
;
266 struct RNode
*nd_body
;
267 struct RNode
*nd_else
;
270 typedef struct RNode_UNLESS
{
273 struct RNode
*nd_cond
;
274 struct RNode
*nd_body
;
275 struct RNode
*nd_else
;
276 rb_code_location_t keyword_loc
;
277 rb_code_location_t then_keyword_loc
;
278 rb_code_location_t end_keyword_loc
;
281 typedef struct RNode_CASE
{
284 struct RNode
*nd_head
;
285 struct RNode
*nd_body
;
286 rb_code_location_t case_keyword_loc
;
287 rb_code_location_t end_keyword_loc
;
290 typedef struct RNode_CASE2
{
293 struct RNode
*nd_head
;
294 struct RNode
*nd_body
;
295 rb_code_location_t case_keyword_loc
;
296 rb_code_location_t end_keyword_loc
;
299 typedef struct RNode_CASE3
{
302 struct RNode
*nd_head
;
303 struct RNode
*nd_body
;
304 rb_code_location_t case_keyword_loc
;
305 rb_code_location_t end_keyword_loc
;
308 typedef struct RNode_WHEN
{
311 struct RNode
*nd_head
;
312 struct RNode
*nd_body
;
313 struct RNode
*nd_next
;
314 rb_code_location_t keyword_loc
;
315 rb_code_location_t then_keyword_loc
;
318 typedef struct RNode_IN
{
321 struct RNode
*nd_head
;
322 struct RNode
*nd_body
;
323 struct RNode
*nd_next
;
326 typedef struct RNode_LOOP
{
329 struct RNode
*nd_cond
;
330 struct RNode
*nd_body
;
332 rb_code_location_t keyword_loc
;
333 rb_code_location_t closing_loc
;
334 } rb_node_while_t
, rb_node_until_t
;
336 typedef struct RNode_ITER
{
339 struct RNode
*nd_body
;
340 struct RNode
*nd_iter
;
341 } rb_node_iter_t
, rb_node_for_t
;
343 typedef struct RNode_FOR_MASGN
{
346 struct RNode
*nd_var
;
347 } rb_node_for_masgn_t
;
349 typedef struct RNode_EXITS
{
352 struct RNode
*nd_chain
;
353 struct RNode
*nd_stts
;
354 rb_code_location_t keyword_loc
;
355 } rb_node_exits_t
, rb_node_break_t
, rb_node_next_t
, rb_node_redo_t
;
357 typedef struct RNode_RETRY
{
361 typedef struct RNode_BEGIN
{
364 struct RNode
*nd_body
;
367 typedef struct RNode_RESCUE
{
370 struct RNode
*nd_head
;
371 struct RNode
*nd_resq
;
372 struct RNode
*nd_else
;
375 typedef struct RNode_RESBODY
{
378 struct RNode
*nd_args
;
379 struct RNode
*nd_exc_var
;
380 struct RNode
*nd_body
;
381 struct RNode
*nd_next
;
384 typedef struct RNode_ENSURE
{
387 struct RNode
*nd_head
;
388 struct RNode
*nd_ensr
;
394 struct RNode
*nd_1st
;
395 struct RNode
*nd_2nd
;
396 rb_code_location_t operator_loc
;
397 } rb_node_and_t
, rb_node_or_t
;
399 typedef struct RNode_MASGN
{
402 struct RNode
*nd_head
;
403 struct RNode
*nd_value
;
404 struct RNode
*nd_args
;
407 typedef struct RNode_LASGN
{
411 struct RNode
*nd_value
;
414 typedef struct RNode_DASGN
{
418 struct RNode
*nd_value
;
421 typedef struct RNode_GASGN
{
425 struct RNode
*nd_value
;
428 typedef struct RNode_IASGN
{
432 struct RNode
*nd_value
;
435 typedef struct RNode_CDECL
{
439 struct RNode
*nd_value
;
440 struct RNode
*nd_else
;
441 enum rb_parser_shareability shareability
;
444 typedef struct RNode_CVASGN
{
448 struct RNode
*nd_value
;
451 typedef struct RNode_OP_ASGN1
{
454 struct RNode
*nd_recv
;
456 struct RNode
*nd_index
;
457 struct RNode
*nd_rvalue
;
458 rb_code_location_t call_operator_loc
;
459 rb_code_location_t opening_loc
;
460 rb_code_location_t closing_loc
;
461 rb_code_location_t binary_operator_loc
;
462 } rb_node_op_asgn1_t
;
464 typedef struct RNode_OP_ASGN2
{
467 struct RNode
*nd_recv
;
468 struct RNode
*nd_value
;
472 } rb_node_op_asgn2_t
;
474 typedef struct RNode_OP_ASGN_AND
{
477 struct RNode
*nd_head
;
478 struct RNode
*nd_value
;
479 } rb_node_op_asgn_and_t
;
481 typedef struct RNode_OP_ASGN_OR
{
484 struct RNode
*nd_head
;
485 struct RNode
*nd_value
;
486 } rb_node_op_asgn_or_t
;
488 typedef struct RNode_OP_CDECL
{
491 struct RNode
*nd_head
;
492 struct RNode
*nd_value
;
494 enum rb_parser_shareability shareability
;
495 } rb_node_op_cdecl_t
;
497 typedef struct RNode_CALL
{
500 struct RNode
*nd_recv
;
502 struct RNode
*nd_args
;
505 typedef struct RNode_OPCALL
{
508 struct RNode
*nd_recv
;
510 struct RNode
*nd_args
;
513 typedef struct RNode_FCALL
{
517 struct RNode
*nd_args
;
520 typedef struct RNode_VCALL
{
526 typedef struct RNode_QCALL
{
529 struct RNode
*nd_recv
;
531 struct RNode
*nd_args
;
534 typedef struct RNode_SUPER
{
537 struct RNode
*nd_args
;
540 typedef struct RNode_ZSUPER
{
549 * head --> element | * head
550 * alen (length of list) | * nd_end (point to the last LIST)
551 * next -----------------+ * next
554 typedef struct RNode_LIST
{
557 struct RNode
*nd_head
; /* element */
560 struct RNode
*nd_end
; /* Second list node has this structure */
562 struct RNode
*nd_next
; /* next list node */
565 typedef struct RNode_ZLIST
{
569 typedef struct RNode_HASH
{
572 struct RNode
*nd_head
;
576 typedef struct RNode_RETURN
{
579 struct RNode
*nd_stts
;
580 rb_code_location_t keyword_loc
;
583 typedef struct RNode_YIELD
{
586 struct RNode
*nd_head
;
589 typedef struct RNode_LVAR
{
595 typedef struct RNode_DVAR
{
601 typedef struct RNode_GVAR
{
607 typedef struct RNode_IVAR
{
613 typedef struct RNode_CONST
{
619 typedef struct RNode_CVAR
{
625 typedef struct RNode_NTH_REF
{
631 typedef struct RNode_BACK_REF
{
635 } rb_node_back_ref_t
;
637 typedef struct RNode_MATCH2
{
640 struct RNode
*nd_recv
;
641 struct RNode
*nd_value
;
642 struct RNode
*nd_args
;
645 typedef struct RNode_MATCH3
{
648 struct RNode
*nd_recv
;
649 struct RNode
*nd_value
;
652 typedef struct RNode_INTEGER
{
660 typedef struct RNode_FLOAT
{
667 typedef struct RNode_RATIONAL
{
674 } rb_node_rational_t
;
676 enum rb_numeric_type
{
682 typedef struct RNode_IMAGINARY
{
689 enum rb_numeric_type type
;
690 } rb_node_imaginary_t
;
692 typedef struct RNode_STR
{
695 struct rb_parser_string
*string
;
698 /* NODE_DSTR, NODE_DXSTR, NODE_DREGX, NODE_DSYM */
699 typedef struct RNode_DSTR
{
702 struct rb_parser_string
*string
;
706 struct RNode
*nd_end
; /* Second dstr node has this structure. See also RNode_LIST */
708 struct RNode_LIST
*nd_next
;
711 typedef rb_node_str_t rb_node_xstr_t
;
713 typedef rb_node_dstr_t rb_node_dxstr_t
;
715 typedef struct RNode_EVSTR
{
718 struct RNode
*nd_body
;
721 typedef struct RNode_REGX
{ /* also RNode_MATCH */
724 struct rb_parser_string
*string
;
726 } rb_node_regx_t
, rb_node_match_t
;
728 typedef rb_node_dstr_t rb_node_dregx_t
;
730 typedef struct RNode_ONCE
{
733 struct RNode
*nd_body
;
736 struct rb_args_info
{
740 int pre_args_num
; /* count of mandatory pre-arguments */
741 int post_args_num
; /* count of mandatory post-arguments */
748 struct RNode_KW_ARG
*kw_args
;
751 struct RNode_OPT_ARG
*opt_args
;
752 unsigned int no_kwarg
: 1;
753 unsigned int ruby2_keywords
: 1;
754 unsigned int forwarding
: 1;
757 typedef struct RNode_ARGS
{
760 struct rb_args_info nd_ainfo
;
763 typedef struct RNode_ARGS_AUX
{
768 struct RNode
*nd_next
;
769 } rb_node_args_aux_t
;
771 typedef struct RNode_OPT_ARG
{
774 struct RNode
*nd_body
;
775 struct RNode_OPT_ARG
*nd_next
;
778 typedef struct RNode_KW_ARG
{
781 struct RNode
*nd_body
;
782 struct RNode_KW_ARG
*nd_next
;
785 typedef struct RNode_POSTARG
{
788 struct RNode
*nd_1st
;
789 struct RNode
*nd_2nd
;
792 typedef struct RNode_ARGSCAT
{
795 struct RNode
*nd_head
;
796 struct RNode
*nd_body
;
799 typedef struct RNode_ARGSPUSH
{
802 struct RNode
*nd_head
;
803 struct RNode
*nd_body
;
804 } rb_node_argspush_t
;
806 typedef struct RNode_SPLAT
{
809 struct RNode
*nd_head
;
812 typedef struct RNode_BLOCK_PASS
{
815 struct RNode
*nd_head
;
816 struct RNode
*nd_body
;
817 unsigned int forwarding
: 1;
818 rb_code_location_t operator_loc
;
819 } rb_node_block_pass_t
;
821 typedef struct RNode_DEFN
{
825 struct RNode
*nd_defn
;
828 typedef struct RNode_DEFS
{
831 struct RNode
*nd_recv
;
833 struct RNode
*nd_defn
;
836 typedef struct RNode_ALIAS
{
839 struct RNode
*nd_1st
;
840 struct RNode
*nd_2nd
;
841 rb_code_location_t keyword_loc
;
844 typedef struct RNode_VALIAS
{
849 rb_code_location_t keyword_loc
;
852 typedef struct RNode_UNDEF
{
855 rb_parser_ary_t
*nd_undefs
;
856 rb_code_location_t keyword_loc
;
859 typedef struct RNode_CLASS
{
862 struct RNode
*nd_cpath
;
863 struct RNode
*nd_body
;
864 struct RNode
*nd_super
;
867 typedef struct RNode_MODULE
{
870 struct RNode
*nd_cpath
;
871 struct RNode
*nd_body
;
874 typedef struct RNode_SCLASS
{
877 struct RNode
*nd_recv
;
878 struct RNode
*nd_body
;
881 typedef struct RNode_COLON2
{
884 struct RNode
*nd_head
;
888 typedef struct RNode_COLON3
{
894 /* NODE_DOT2, NODE_DOT3, NODE_FLIP2, NODE_FLIP3 */
895 typedef struct RNode_DOTS
{
898 struct RNode
*nd_beg
;
899 struct RNode
*nd_end
;
900 } rb_node_dot2_t
, rb_node_dot3_t
, rb_node_flip2_t
, rb_node_flip3_t
;
902 typedef struct RNode_SELF
{
905 long nd_state
; /* Default 1. See NEW_SELF. */
908 typedef struct RNode_NIL
{
912 typedef struct RNode_TRUE
{
916 typedef struct RNode_FALSE
{
920 typedef struct RNode_ERRINFO
{
924 typedef struct RNode_DEFINED
{
927 struct RNode
*nd_head
;
930 typedef struct RNode_POSTEXE
{
933 struct RNode
*nd_body
;
936 typedef struct RNode_SYM
{
939 struct rb_parser_string
*string
;
942 typedef rb_node_dstr_t rb_node_dsym_t
;
944 typedef struct RNode_ATTRASGN
{
947 struct RNode
*nd_recv
;
949 struct RNode
*nd_args
;
950 } rb_node_attrasgn_t
;
952 typedef struct RNode_LAMBDA
{
955 struct RNode
*nd_body
;
958 typedef struct RNode_ARYPTN
{
961 struct RNode
*nd_pconst
;
967 typedef struct RNode_HSHPTN
{
970 struct RNode
*nd_pconst
;
971 struct RNode
*nd_pkwargs
;
972 struct RNode
*nd_pkwrestarg
;
975 typedef struct RNode_FNDPTN
{
978 struct RNode
*nd_pconst
;
984 typedef struct RNode_LINE
{
988 typedef struct RNode_FILE
{
991 struct rb_parser_string
*path
;
994 typedef struct RNode_ENCODING
{
997 } rb_node_encoding_t
;
999 typedef struct RNode_ERROR
{
1003 #define RNODE(obj) ((NODE *)(obj))
1005 #define RNODE_SCOPE(node) ((rb_node_scope_t *)(node))
1006 #define RNODE_BLOCK(node) ((rb_node_block_t *)(node))
1007 #define RNODE_IF(node) ((rb_node_if_t *)(node))
1008 #define RNODE_UNLESS(node) ((rb_node_unless_t *)(node))
1009 #define RNODE_CASE(node) ((rb_node_case_t *)(node))
1010 #define RNODE_CASE2(node) ((rb_node_case2_t *)(node))
1011 #define RNODE_CASE3(node) ((rb_node_case3_t *)(node))
1012 #define RNODE_WHEN(node) ((rb_node_when_t *)(node))
1013 #define RNODE_IN(node) ((rb_node_in_t *)(node))
1014 #define RNODE_WHILE(node) ((rb_node_while_t *)(node))
1015 #define RNODE_UNTIL(node) ((rb_node_until_t *)(node))
1016 #define RNODE_ITER(node) ((rb_node_iter_t *)(node))
1017 #define RNODE_FOR(node) ((rb_node_for_t *)(node))
1018 #define RNODE_FOR_MASGN(node) ((rb_node_for_masgn_t *)(node))
1019 #define RNODE_BREAK(node) ((rb_node_break_t *)(node))
1020 #define RNODE_NEXT(node) ((rb_node_next_t *)(node))
1021 #define RNODE_REDO(node) ((rb_node_redo_t *)(node))
1022 #define RNODE_RETRY(node) ((rb_node_retry_t *)(node))
1023 #define RNODE_BEGIN(node) ((rb_node_begin_t *)(node))
1024 #define RNODE_RESCUE(node) ((rb_node_rescue_t *)(node))
1025 #define RNODE_RESBODY(node) ((rb_node_resbody_t *)(node))
1026 #define RNODE_ENSURE(node) ((rb_node_ensure_t *)(node))
1027 #define RNODE_AND(node) ((rb_node_and_t *)(node))
1028 #define RNODE_OR(node) ((rb_node_or_t *)(node))
1029 #define RNODE_MASGN(node) ((rb_node_masgn_t *)(node))
1030 #define RNODE_LASGN(node) ((rb_node_lasgn_t *)(node))
1031 #define RNODE_DASGN(node) ((rb_node_dasgn_t *)(node))
1032 #define RNODE_GASGN(node) ((rb_node_gasgn_t *)(node))
1033 #define RNODE_IASGN(node) ((rb_node_iasgn_t *)(node))
1034 #define RNODE_CDECL(node) ((rb_node_cdecl_t *)(node))
1035 #define RNODE_CVASGN(node) ((rb_node_cvasgn_t *)(node))
1036 #define RNODE_OP_ASGN1(node) ((rb_node_op_asgn1_t *)(node))
1037 #define RNODE_OP_ASGN2(node) ((rb_node_op_asgn2_t *)(node))
1038 #define RNODE_OP_ASGN_AND(node) ((rb_node_op_asgn_and_t *)(node))
1039 #define RNODE_OP_ASGN_OR(node) ((rb_node_op_asgn_or_t *)(node))
1040 #define RNODE_OP_CDECL(node) ((rb_node_op_cdecl_t *)(node))
1041 #define RNODE_CALL(node) ((rb_node_call_t *)(node))
1042 #define RNODE_OPCALL(node) ((rb_node_opcall_t *)(node))
1043 #define RNODE_FCALL(node) ((rb_node_fcall_t *)(node))
1044 #define RNODE_VCALL(node) ((rb_node_vcall_t *)(node))
1045 #define RNODE_QCALL(node) ((rb_node_qcall_t *)(node))
1046 #define RNODE_SUPER(node) ((rb_node_super_t *)(node))
1047 #define RNODE_ZSUPER(node) ((rb_node_zsuper_t *)(node))
1048 #define RNODE_LIST(node) ((rb_node_list_t *)(node))
1049 #define RNODE_ZLIST(node) ((rb_node_zlist_t *)(node))
1050 #define RNODE_HASH(node) ((rb_node_hash_t *)(node))
1051 #define RNODE_RETURN(node) ((rb_node_return_t *)(node))
1052 #define RNODE_YIELD(node) ((rb_node_yield_t *)(node))
1053 #define RNODE_LVAR(node) ((rb_node_lvar_t *)(node))
1054 #define RNODE_DVAR(node) ((rb_node_dvar_t *)(node))
1055 #define RNODE_GVAR(node) ((rb_node_gvar_t *)(node))
1056 #define RNODE_IVAR(node) ((rb_node_ivar_t *)(node))
1057 #define RNODE_CONST(node) ((rb_node_const_t *)(node))
1058 #define RNODE_CVAR(node) ((rb_node_cvar_t *)(node))
1059 #define RNODE_NTH_REF(node) ((rb_node_nth_ref_t *)(node))
1060 #define RNODE_BACK_REF(node) ((rb_node_back_ref_t *)(node))
1061 #define RNODE_MATCH(node) ((rb_node_match_t *)(node))
1062 #define RNODE_MATCH2(node) ((rb_node_match2_t *)(node))
1063 #define RNODE_MATCH3(node) ((rb_node_match3_t *)(node))
1064 #define RNODE_INTEGER(node) ((rb_node_integer_t *)(node))
1065 #define RNODE_FLOAT(node) ((rb_node_float_t *)(node))
1066 #define RNODE_RATIONAL(node) ((rb_node_rational_t *)(node))
1067 #define RNODE_IMAGINARY(node) ((rb_node_imaginary_t *)(node))
1068 #define RNODE_STR(node) ((rb_node_str_t *)(node))
1069 #define RNODE_DSTR(node) ((rb_node_dstr_t *)(node))
1070 #define RNODE_XSTR(node) ((rb_node_xstr_t *)(node))
1071 #define RNODE_DXSTR(node) ((rb_node_dxstr_t *)(node))
1072 #define RNODE_EVSTR(node) ((rb_node_evstr_t *)(node))
1073 #define RNODE_REGX(node) ((rb_node_regx_t *)(node))
1074 #define RNODE_DREGX(node) ((rb_node_dregx_t *)(node))
1075 #define RNODE_ONCE(node) ((rb_node_once_t *)(node))
1076 #define RNODE_ARGS(node) ((rb_node_args_t *)(node))
1077 #define RNODE_ARGS_AUX(node) ((rb_node_args_aux_t *)(node))
1078 #define RNODE_OPT_ARG(node) ((rb_node_opt_arg_t *)(node))
1079 #define RNODE_KW_ARG(node) ((rb_node_kw_arg_t *)(node))
1080 #define RNODE_POSTARG(node) ((rb_node_postarg_t *)(node))
1081 #define RNODE_ARGSCAT(node) ((rb_node_argscat_t *)(node))
1082 #define RNODE_ARGSPUSH(node) ((rb_node_argspush_t *)(node))
1083 #define RNODE_SPLAT(node) ((rb_node_splat_t *)(node))
1084 #define RNODE_BLOCK_PASS(node) ((rb_node_block_pass_t *)(node))
1085 #define RNODE_DEFN(node) ((rb_node_defn_t *)(node))
1086 #define RNODE_DEFS(node) ((rb_node_defs_t *)(node))
1087 #define RNODE_ALIAS(node) ((rb_node_alias_t *)(node))
1088 #define RNODE_VALIAS(node) ((rb_node_valias_t *)(node))
1089 #define RNODE_UNDEF(node) ((rb_node_undef_t *)(node))
1090 #define RNODE_CLASS(node) ((rb_node_class_t *)(node))
1091 #define RNODE_MODULE(node) ((rb_node_module_t *)(node))
1092 #define RNODE_SCLASS(node) ((rb_node_sclass_t *)(node))
1093 #define RNODE_COLON2(node) ((rb_node_colon2_t *)(node))
1094 #define RNODE_COLON3(node) ((rb_node_colon3_t *)(node))
1095 #define RNODE_DOT2(node) ((rb_node_dot2_t *)(node))
1096 #define RNODE_DOT3(node) ((rb_node_dot3_t *)(node))
1097 #define RNODE_FLIP2(node) ((rb_node_flip2_t *)(node))
1098 #define RNODE_FLIP3(node) ((rb_node_flip3_t *)(node))
1099 #define RNODE_SELF(node) ((rb_node_self_t *)(node))
1100 #define RNODE_NIL(node) ((rb_node_nil_t *)(node))
1101 #define RNODE_TRUE(node) ((rb_node_true_t *)(node))
1102 #define RNODE_FALSE(node) ((rb_node_false_t *)(node))
1103 #define RNODE_ERRINFO(node) ((rb_node_errinfo_t *)(node))
1104 #define RNODE_DEFINED(node) ((rb_node_defined_t *)(node))
1105 #define RNODE_POSTEXE(node) ((rb_node_postexe_t *)(node))
1106 #define RNODE_SYM(node) ((rb_node_sym_t *)(node))
1107 #define RNODE_DSYM(node) ((rb_node_dsym_t *)(node))
1108 #define RNODE_ATTRASGN(node) ((rb_node_attrasgn_t *)(node))
1109 #define RNODE_LAMBDA(node) ((rb_node_lambda_t *)(node))
1110 #define RNODE_ARYPTN(node) ((rb_node_aryptn_t *)(node))
1111 #define RNODE_HSHPTN(node) ((rb_node_hshptn_t *)(node))
1112 #define RNODE_FNDPTN(node) ((rb_node_fndptn_t *)(node))
1113 #define RNODE_LINE(node) ((rb_node_line_t *)(node))
1114 #define RNODE_FILE(node) ((rb_node_file_t *)(node))
1115 #define RNODE_ENCODING(node) ((rb_node_encoding_t *)(node))
1117 /* FL : 0..4: T_TYPES, 5: KEEP_WB, 6: PROMOTED, 7: FINALIZE, 8: UNUSED, 9: UNUSED, 10: EXIVAR, 11: FREEZE */
1118 /* NODE_FL: 0..4: UNUSED, 5: UNUSED, 6: UNUSED, 7: NODE_FL_NEWLINE,
1122 #define NODE_FL_NEWLINE (((VALUE)1)<<7)
1124 #define NODE_TYPESHIFT 8
1125 #define NODE_TYPEMASK (((VALUE)0x7f)<<NODE_TYPESHIFT)
1127 #define nd_fl_newline(n) ((n)->flags & NODE_FL_NEWLINE)
1128 #define nd_set_fl_newline(n) ((n)->flags |= NODE_FL_NEWLINE)
1129 #define nd_unset_fl_newline(n) ((n)->flags &= ~NODE_FL_NEWLINE)
1131 #define nd_type(n) ((int) ((RNODE(n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
1132 #define nd_set_type(n,t) \
1133 rb_node_set_type(n, t)
1134 #define nd_init_type(n,t) \
1135 (n)->flags=(((n)->flags&~NODE_TYPEMASK)|((((unsigned long)(t))<<NODE_TYPESHIFT)&NODE_TYPEMASK))
1137 typedef struct node_buffer_struct node_buffer_t
;
1139 #ifdef UNIVERSAL_PARSER
1140 typedef struct rb_parser_config_struct rb_parser_config_t
;
1143 typedef struct rb_ast_body_struct
{
1145 rb_parser_ary_t
*script_lines
;
1147 signed int frozen_string_literal
:2; /* -1: not specified, 0: false, 1: true */
1148 signed int coverage_enabled
:2; /* -1: not specified, 0: false, 1: true */
1150 typedef struct rb_ast_struct
{
1151 node_buffer_t
*node_buffer
;
1153 #ifdef UNIVERSAL_PARSER
1154 const rb_parser_config_t
*config
;
1165 typedef struct parser_params rb_parser_t
;
1166 #ifndef INTERNAL_IMEMO_H
1167 typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t
;
1170 #ifdef UNIVERSAL_PARSER
1171 typedef struct rb_parser_config_struct
{
1173 void *(*malloc
)(size_t size
);
1174 void *(*calloc
)(size_t number
, size_t size
);
1175 void *(*realloc
)(void *ptr
, size_t newsiz
);
1176 void (*free
)(void *ptr
);
1177 void *(*alloc_n
)(size_t nelems
, size_t elemsiz
);
1178 void *(*alloc
)(size_t elemsiz
);
1179 void *(*realloc_n
)(void *ptr
, size_t newelems
, size_t newsiz
);
1180 void *(*zalloc
)(size_t elemsiz
);
1181 void *(*rb_memmove
)(void *dest
, const void *src
, size_t t
, size_t n
);
1182 void *(*nonempty_memcpy
)(void *dest
, const void *src
, size_t t
, size_t n
);
1183 void *(*xmalloc_mul_add
)(size_t x
, size_t y
, size_t z
);
1185 // VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
1186 VALUE (*compile_callback
)(VALUE (*func
)(VALUE
), VALUE arg
);
1187 NODE
*(*reg_named_capture_assign
)(struct parser_params
* p
, VALUE regexp
, const rb_code_location_t
*loc
);
1190 VALUE (*attr_get
)(VALUE obj
, ID id
);
1193 VALUE (*ary_new
)(void);
1194 VALUE (*ary_push
)(VALUE ary
, VALUE elem
);
1195 VALUE (*ary_new_from_args
)(long n
, ...);
1196 VALUE (*ary_unshift
)(VALUE ary
, VALUE item
);
1199 ID (*make_temporary_id
)(size_t n
);
1200 int (*is_local_id
)(ID
);
1201 int (*is_attrset_id
)(ID
);
1202 int (*is_global_name_punct
)(const int c
);
1203 int (*id_type
)(ID id
);
1204 ID (*id_attrset
)(ID
);
1205 ID (*intern
)(const char *name
);
1206 ID (*intern2
)(const char *name
, long len
);
1207 ID (*intern3
)(const char *name
, long len
, rb_encoding
*enc
);
1208 ID (*intern_str
)(VALUE str
);
1209 int (*is_notop_id
)(ID
);
1210 int (*enc_symname_type
)(const char *name
, long len
, rb_encoding
*enc
, unsigned int allowed_attrset
);
1211 const char *(*id2name
)(ID id
);
1212 VALUE (*id2str
)(ID id
);
1213 VALUE (*id2sym
)(ID x
);
1214 ID (*sym2id
)(VALUE sym
);
1217 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 3)
1218 VALUE (*str_catf
)(VALUE str
, const char *format
, ...);
1219 VALUE (*str_cat_cstr
)(VALUE str
, const char *ptr
);
1220 VALUE (*str_resize
)(VALUE str
, long len
);
1221 VALUE (*str_new
)(const char *ptr
, long len
);
1222 VALUE (*str_new_cstr
)(const char *ptr
);
1223 VALUE (*str_to_interned_str
)(VALUE
);
1224 int (*is_ascii_string
)(VALUE str
);
1225 VALUE (*enc_str_new
)(const char *ptr
, long len
, rb_encoding
*enc
);
1226 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 0)
1227 VALUE (*str_vcatf
)(VALUE str
, const char *fmt
, va_list ap
);
1228 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 1, 2)
1229 VALUE (*rb_sprintf
)(const char *format
, ...);
1230 char *(*rstring_ptr
)(VALUE str
);
1231 char *(*rstring_end
)(VALUE str
);
1232 long (*rstring_len
)(VALUE str
);
1233 VALUE (*obj_as_string
)(VALUE
);
1236 VALUE (*int2num
)(int v
);
1239 int (*stderr_tty_p
)(void);
1240 void (*write_error_str
)(VALUE mesg
);
1241 VALUE (*io_write
)(VALUE io
, VALUE str
);
1242 VALUE (*io_flush
)(VALUE io
);
1243 VALUE (*io_puts
)(int argc
, const VALUE
*argv
, VALUE out
);
1246 VALUE (*debug_output_stdout
)(void);
1247 VALUE (*debug_output_stderr
)(void);
1250 int (*is_usascii_enc
)(rb_encoding
*enc
);
1251 int (*enc_isalnum
)(OnigCodePoint c
, rb_encoding
*enc
);
1252 int (*enc_precise_mbclen
)(const char *p
, const char *e
, rb_encoding
*enc
);
1253 int (*mbclen_charfound_p
)(int len
);
1254 int (*mbclen_charfound_len
)(int len
);
1255 const char *(*enc_name
)(rb_encoding
*enc
);
1256 char *(*enc_prev_char
)(const char *s
, const char *p
, const char *e
, rb_encoding
*enc
);
1257 rb_encoding
* (*enc_get
)(VALUE obj
);
1258 int (*enc_asciicompat
)(rb_encoding
*enc
);
1259 rb_encoding
*(*utf8_encoding
)(void);
1260 VALUE (*enc_associate
)(VALUE obj
, rb_encoding
*enc
);
1261 rb_encoding
*(*ascii8bit_encoding
)(void);
1262 int (*enc_codelen
)(int c
, rb_encoding
*enc
);
1263 int (*enc_mbcput
)(unsigned int c
, void *buf
, rb_encoding
*enc
);
1264 int (*enc_find_index
)(const char *name
);
1265 rb_encoding
*(*enc_from_index
)(int idx
);
1266 int (*enc_isspace
)(OnigCodePoint c
, rb_encoding
*enc
);
1267 rb_encoding
*(*usascii_encoding
)(void);
1268 int (*enc_mbminlen
)(rb_encoding
*enc
);
1269 bool (*enc_isascii
)(OnigCodePoint c
, rb_encoding
*enc
);
1270 OnigCodePoint (*enc_mbc_to_codepoint
)(const char *p
, const char *e
, rb_encoding
*enc
);
1273 // int rb_local_defined(ID id, const rb_iseq_t *iseq);
1274 int (*local_defined
)(ID
, const void*);
1275 // int rb_dvar_defined(ID id, const rb_iseq_t *iseq);
1276 int (*dvar_defined
)(ID
, const void*);
1278 /* Error (Exception) */
1279 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 6, 0)
1280 VALUE (*syntax_error_append
)(VALUE
, VALUE
, int, int, rb_encoding
*, const char*, va_list);
1281 RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT
, 2, 3)
1282 void (*raise
)(VALUE exc
, const char *fmt
, ...);
1283 VALUE (*syntax_error_new
)(void);
1286 VALUE (*errinfo
)(void);
1287 void (*set_errinfo
)(VALUE err
);
1288 void (*exc_raise
)(VALUE mesg
);
1289 VALUE (*make_exception
)(int argc
, const VALUE
*argv
);
1292 void (*sized_xfree
)(void *x
, size_t size
);
1293 void *(*sized_realloc_n
)(void *ptr
, size_t new_count
, size_t element_size
, size_t old_count
);
1294 void (*gc_guard
)(VALUE
);
1295 void (*gc_mark
)(VALUE
);
1298 VALUE (*reg_compile
)(VALUE str
, int options
, const char *sourcefile
, int sourceline
);
1299 VALUE (*reg_check_preprocess
)(VALUE str
);
1300 int (*memcicmp
)(const void *x
, const void *y
, long len
);
1303 void (*compile_warn
)(const char *file
, int line
, const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(3, 4);
1304 void (*compile_warning
)(const char *file
, int line
, const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(3, 4);
1305 void (*bug
)(const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(1, 2);
1306 void (*fatal
)(const char *fmt
, ...) RUBYPARSER_ATTRIBUTE_FORMAT(1, 2);
1307 VALUE (*verbose
)(void);
1308 int *(*errno_ptr
)(void);
1311 VALUE (*make_backtrace
)(void);
1314 unsigned long (*scan_hex
)(const char *start
, size_t len
, size_t *retlen
);
1315 unsigned long (*scan_oct
)(const char *start
, size_t len
, size_t *retlen
);
1316 unsigned long (*scan_digits
)(const char *str
, ssize_t len
, int base
, size_t *retlen
, int *overflow
);
1317 double (*strtod
)(const char *s00
, char **se
);
1320 int (*rtest
)(VALUE obj
);
1321 int (*nil_p
)(VALUE obj
);
1324 VALUE (*eArgError
)(void);
1325 int (*long2int
)(long);
1328 int enc_coderange_7bit
;
1329 int enc_coderange_unknown
;
1330 VALUE (*static_id2sym
)(ID id
);
1331 long (*str_coderange_scan_restartable
)(const char *s
, const char *e
, rb_encoding
*enc
, int *cr
);
1332 } rb_parser_config_t
;
1335 #undef OnigCodePoint
1336 #endif /* UNIVERSAL_PARSER */
1338 RUBY_SYMBOL_EXPORT_BEGIN
1339 void rb_ruby_parser_free(void *ptr
);
1341 #ifdef UNIVERSAL_PARSER
1342 rb_parser_t
*rb_ruby_parser_allocate(const rb_parser_config_t
*config
);
1343 rb_parser_t
*rb_ruby_parser_new(const rb_parser_config_t
*config
);
1346 RUBY_SYMBOL_EXPORT_END
1348 #endif /* RUBY_RUBYPARSER_H */