Ruby: node.h Source File

Ruby 3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0)

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, ...);
19
20 typedef struct node_buffer_elem_struct {
21 struct node_buffer_elem_struct *next;
22 long len; /* Length of nodes */
23 size_t allocated; /* Total memory size of allocated buf */
24 size_t used; /* Current usage of buf */
25 NODE **nodes; /* Array of node pointers */
26 NODE *buf[FLEX_ARY_LEN];
27} node_buffer_elem_t;
28
29 typedef struct {
30 node_buffer_elem_t *head;
31 node_buffer_elem_t *last;
32} node_buffer_list_t;
33
34 struct node_buffer_struct {
35 node_buffer_list_t unmarkable;
36 node_buffer_list_t markable;
37 struct rb_ast_local_table_link *local_tables;
38 VALUE mark_hash;
39 // - id (sequence number)
40 // - token_type
41 // - text of token
42 // - location info
43 // Array, whose entry is array
44 VALUE tokens;
45#ifdef UNIVERSAL_PARSER
46 rb_parser_config_t *config;
47#endif
48};
49
50RUBY_SYMBOL_EXPORT_BEGIN
51
52#ifdef UNIVERSAL_PARSER
53 rb_ast_t *rb_ast_new(rb_parser_config_t *config);
54#else
55 rb_ast_t *rb_ast_new(void);
56#endif
57size_t rb_ast_memsize(const rb_ast_t*);
58void rb_ast_dispose(rb_ast_t*);
59 VALUE rb_ast_tokens(rb_ast_t *ast);
60#if RUBY_DEBUG
61void rb_ast_node_type_change(NODE *n, enum node_type type);
62#endif
63const char *ruby_node_name(int node);
64void rb_node_init(NODE *n, enum node_type type);
65
66void rb_ast_mark(rb_ast_t*);
67void rb_ast_update_references(rb_ast_t*);
68void rb_ast_free(rb_ast_t*);
69void rb_ast_add_mark_object(rb_ast_t*, VALUE);
70void rb_ast_delete_mark_object(rb_ast_t*, VALUE);
71void rb_ast_set_tokens(rb_ast_t*, VALUE);
72 NODE *rb_ast_newnode(rb_ast_t*, enum node_type type, size_t size, size_t alignment);
73void rb_ast_delete_node(rb_ast_t*, NODE *n);
74 rb_ast_id_table_t *rb_ast_new_local_table(rb_ast_t*, int);
75 rb_ast_id_table_t *rb_ast_resize_latest_local_table(rb_ast_t*, int);
76
77 VALUE rb_parser_dump_tree(const NODE *node, int comment);
78
79const struct kwtable *rb_reserved_word(const char *, unsigned int);
80
81struct parser_params;
82void *rb_parser_malloc(struct parser_params *, size_t);
83void *rb_parser_realloc(struct parser_params *, void *, size_t);
84void *rb_parser_calloc(struct parser_params *, size_t, size_t);
85void rb_parser_free(struct parser_params *, void *);
86PRINTF_ARGS(void rb_parser_printf(struct parser_params *parser, const char *fmt, ...), 2, 3);
87 VALUE rb_node_set_type(NODE *n, enum node_type t);
88
89RUBY_SYMBOL_EXPORT_END
90
91#define NODE_LSHIFT (NODE_TYPESHIFT+7)
92#define NODE_LMASK (((SIGNED_VALUE)1<<(sizeof(VALUE)*CHAR_BIT-NODE_LSHIFT))-1)
93
94#define nd_line(n) (int)(((SIGNED_VALUE)(n)->flags)>>NODE_LSHIFT)
95#define nd_set_line(n,l) \
96 (n)->flags=(((n)->flags&~((VALUE)(-1)<<NODE_LSHIFT))|((VALUE)((l)&NODE_LMASK)<<NODE_LSHIFT))
97
98
99#define NODE_SPECIAL_REQUIRED_KEYWORD ((NODE *)-1)
100#define NODE_REQUIRED_KEYWORD_P(node) ((node) == NODE_SPECIAL_REQUIRED_KEYWORD)
101#define NODE_SPECIAL_NO_NAME_REST ((NODE *)-1)
102#define NODE_NAMED_REST_P(node) ((node) != NODE_SPECIAL_NO_NAME_REST)
103#define NODE_SPECIAL_EXCESSIVE_COMMA ((ID)1)
104#define NODE_SPECIAL_NO_REST_KEYWORD ((NODE *)-1)
105
106#define nd_first_column(n) ((int)(RNODE(n)->nd_loc.beg_pos.column))
107#define nd_set_first_column(n, v) (RNODE(n)->nd_loc.beg_pos.column = (v))
108#define nd_first_lineno(n) ((int)(RNODE(n)->nd_loc.beg_pos.lineno))
109#define nd_set_first_lineno(n, v) (RNODE(n)->nd_loc.beg_pos.lineno = (v))
110#define nd_first_loc(n) (RNODE(n)->nd_loc.beg_pos)
111#define nd_set_first_loc(n, v) (nd_first_loc(n) = (v))
112
113#define nd_last_column(n) ((int)(RNODE(n)->nd_loc.end_pos.column))
114#define nd_set_last_column(n, v) (RNODE(n)->nd_loc.end_pos.column = (v))
115#define nd_last_lineno(n) ((int)(RNODE(n)->nd_loc.end_pos.lineno))
116#define nd_set_last_lineno(n, v) (RNODE(n)->nd_loc.end_pos.lineno = (v))
117#define nd_last_loc(n) (RNODE(n)->nd_loc.end_pos)
118#define nd_set_last_loc(n, v) (nd_last_loc(n) = (v))
119#define nd_node_id(n) (RNODE(n)->node_id)
120#define nd_set_node_id(n,id) (RNODE(n)->node_id = (id))
121
122static inline bool
123nd_type_p(const NODE *n, enum node_type t)
124{
125 return (enum node_type)nd_type(n) == t;
126}
127
128#endif /* RUBY_NODE_H */
len
int len
Length of the buffer.
Definition io.h:8
ruby::backward::cxxanyargs::type
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition cxxanyargs.hpp:56
stdbool.h
C99 shim for <stdbool.h>
RNode
Definition rubyparser.h:166
kwtable
Definition lex.c:34
node_buffer_elem_struct
Definition node.h:20
node_buffer_list_t
Definition node.h:29
node_buffer_struct
Definition node.h:34
parser_params
Definition parse.c:481
rb_ast_id_table
Definition rubyparser.h:150
rb_ast_local_table_link
Definition node.c:164
rb_ast_struct
Definition rubyparser.h:1096
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40