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
{