Ruby  3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
node.h (892c46283a5ea4179500d951c9d4866c0051f27b)
1 #ifndef RUBY_NODE_H
2 #define RUBY_NODE_H 1
3 /**********************************************************************
4 
5  node.h -
6 
7  $Author$
8  created at: Fri May 28 15:14:02 JST 1993
9 
10  Copyright (C) 1993-2007 Yukihiro Matsumoto
11 
12 **********************************************************************/
13 
14 #include <stdbool.h>
15 #include "rubyparser.h"
16 #include "ruby/backward/2/attributes.h"
17 
18 typedef void (*bug_report_func)(const char *fmt, ...) RUBYPARSER_ATTRIBUTE_FORMAT(1, 2);
19 typedef struct node_buffer_elem_struct {
20  struct node_buffer_elem_struct *next;
21  long len; /* Length of nodes */
22  size_t allocated; /* Total memory size of allocated buf */
23  size_t used; /* Current usage of buf */
24  NODE **nodes; /* Array of node pointers */
25  NODE *buf[FLEX_ARY_LEN];
26 } node_buffer_elem_t;
27 
28 typedef struct {
29  node_buffer_elem_t *head;
30  node_buffer_elem_t *last;
32 
34  node_buffer_list_t buffer_list;
35  struct rb_ast_local_table_link *local_tables;
36  // - id (sequence number)
37  // - token_type
38  // - text of token
39  // - location info
40  // Array, whose entry is array
41  rb_parser_ary_t *tokens;
42 };
43 
44 RUBY_SYMBOL_EXPORT_BEGIN
45 
46 #ifdef UNIVERSAL_PARSER
47 rb_ast_t *rb_ast_new(const rb_parser_config_t *config);
48 #else
49 rb_ast_t *rb_ast_new(void);
50 #endif
51 size_t rb_ast_memsize(const rb_ast_t*);
52 void rb_ast_dispose(rb_ast_t*);
53 const char *ruby_node_name(int node);
54 void rb_node_init(NODE *n, enum node_type type);
55 
56 void rb_ast_update_references(rb_ast_t*);
57 void rb_ast_free(rb_ast_t*);
58 NODE *rb_ast_newnode(rb_ast_t*, enum node_type type, size_t size, size_t alignment);
59 void rb_ast_delete_node(rb_ast_t*, NODE *n);
60 rb_ast_id_table_t *rb_ast_new_local_table(rb_ast_t*, int);
61 rb_ast_id_table_t *rb_ast_resize_latest_local_table(rb_ast_t*, int);
62 
63 VALUE rb_parser_dump_tree(const NODE *node, int comment);
64 
65 const struct kwtable *rb_reserved_word(const char *, unsigned int);
66 
67 struct parser_params;
68 PRINTF_ARGS(void rb_parser_printf(struct parser_params *parser, const char *fmt, ...), 2, 3);
69 VALUE rb_node_set_type(NODE *n, enum node_type t);
70 
71 RUBY_SYMBOL_EXPORT_END
72 
73 #define NODE_LSHIFT (NODE_TYPESHIFT+7)
74 #define NODE_LMASK (((SIGNED_VALUE)1<<(sizeof(VALUE)*CHAR_BIT-NODE_LSHIFT))-1)
75 
76 #define nd_line(n) (int)(((SIGNED_VALUE)(n)->flags)>>NODE_LSHIFT)
77 #define nd_set_line(n,l) \
78  (n)->flags=(((n)->flags&~((VALUE)(-1)<<NODE_LSHIFT))|((VALUE)((l)&NODE_LMASK)<<NODE_LSHIFT))
79 
80 
81 #define NODE_SPECIAL_REQUIRED_KEYWORD ((NODE *)-1)
82 #define NODE_REQUIRED_KEYWORD_P(node) ((node) == NODE_SPECIAL_REQUIRED_KEYWORD)
83 #define NODE_SPECIAL_NO_NAME_REST ((NODE *)-1)
84 #define NODE_NAMED_REST_P(node) ((node) != NODE_SPECIAL_NO_NAME_REST)
85 #define NODE_SPECIAL_EXCESSIVE_COMMA ((ID)1)
86 #define NODE_SPECIAL_NO_REST_KEYWORD ((NODE *)-1)
87 
88 #define nd_code_loc(n) (&RNODE(n)->nd_loc)
89 #define nd_first_column(n) ((int)(RNODE(n)->nd_loc.beg_pos.column))
90 #define nd_set_first_column(n, v) (RNODE(n)->nd_loc.beg_pos.column = (v))
91 #define nd_first_lineno(n) ((int)(RNODE(n)->nd_loc.beg_pos.lineno))
92 #define nd_set_first_lineno(n, v) (RNODE(n)->nd_loc.beg_pos.lineno = (v))
93 #define nd_first_loc(n) (RNODE(n)->nd_loc.beg_pos)
94 #define nd_set_first_loc(n, v) (nd_first_loc(n) = (v))
95 
96 #define nd_last_column(n) ((int)(RNODE(n)->nd_loc.end_pos.column))
97 #define nd_set_last_column(n, v) (RNODE(n)->nd_loc.end_pos.column = (v))
98 #define nd_last_lineno(n) ((int)(RNODE(n)->nd_loc.end_pos.lineno))
99 #define nd_set_last_lineno(n, v) (RNODE(n)->nd_loc.end_pos.lineno = (v))
100 #define nd_last_loc(n) (RNODE(n)->nd_loc.end_pos)
101 #define nd_set_last_loc(n, v) (nd_last_loc(n) = (v))
102 #define nd_node_id(n) (RNODE(n)->node_id)
103 #define nd_set_node_id(n,id) (RNODE(n)->node_id = (id))
104 
105 static inline bool
106 nd_type_p(const NODE *n, enum node_type t)
107 {
108  return (enum node_type)nd_type(n) == t;
109 }
110 
111 #endif /* RUBY_NODE_H */
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:56
C99 shim for <stdbool.h>
Definition: lex.c:33
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40