Ruby: node.h Source File

Ruby 3.4.8p72 (2025-12-17 revision 995b59f66677d44767ce9faac6957e5543617ff9)

node.h
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
18typedef 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;
31} node_buffer_list_t;
32
33 struct node_buffer_struct {
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
44RUBY_SYMBOL_EXPORT_BEGIN
45
46#ifdef UNIVERSAL_PARSER
47rb_ast_t *rb_ast_new(const rb_parser_config_t *config);
48#else
49rb_ast_t *rb_ast_new(void);
50#endif
51size_t rb_ast_memsize(const rb_ast_t*);
52void rb_ast_dispose(rb_ast_t*);
53const char *ruby_node_name(int node);
54void rb_node_init(NODE *n, enum node_type type);
55
56void rb_ast_update_references(rb_ast_t*);
57void rb_ast_free(rb_ast_t*);
58NODE *rb_ast_newnode(rb_ast_t*, enum node_type type, size_t size, size_t alignment);
59void rb_ast_delete_node(rb_ast_t*, NODE *n);
60rb_ast_id_table_t *rb_ast_new_local_table(rb_ast_t*, int);
61rb_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
65const struct kwtable *rb_reserved_word(const char *, unsigned int);
66
67struct parser_params;
68PRINTF_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
71RUBY_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
105static inline bool
106nd_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 */
ruby::backward::cxxanyargs::type
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition cxxanyargs.hpp:56
stdbool.h
C99 shim for <stdbool.h>
kwtable
Definition lex.c:33
node_buffer_elem_struct
Definition node.h:19
node_buffer_list_t
Definition node.h:28
node_buffer_struct
Definition node.h:33
parser_params
Definition parse.c:543
rb_ast_local_table_link
Definition node.c:131
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40