Ruby: node.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Typedefs | Functions
node.c File Reference
`#include "internal.h"`
`#include "internal/hash.h"`
`#include "internal/variable.h"`
`#include "ruby/ruby.h"`
`#include "vm_core.h"`

Go to the source code of this file.

## Data Structures
struct | add_option_arg
struct | node_buffer_elem_struct
struct | node_buffer_list_t
struct | node_buffer_struct

## Macros
#define | NODE_BUF_DEFAULT_LEN 16
#define | A(str) rb_str_cat2(buf, (str))
#define | AR(str) rb_str_concat(buf, (str))
#define | A_INDENT add_indent(buf, indent)
#define | D_INDENT rb_str_cat2(indent, next_indent)
#define | D_DEDENT rb_str_resize(indent, RSTRING_LEN(indent) - 4)
#define | A_ID(id) add_id(buf, (id))
#define | A_INT(val) rb_str_catf(buf, "%d", (val))
#define | A_LONG(val) rb_str_catf(buf, "%ld", (val))
#define | A_LIT(lit) AR(rb_dump_literal(lit))
#define | A_NODE_HEADER(node, term)
#define | A_FIELD_HEADER(len, name, term) rb_str_catf(buf, "+- %.*s:"term, (len), (name))
#define | D_FIELD_HEADER(len, name, term) (A_INDENT, A_FIELD_HEADER(len, name, term))
#define | D_NULL_NODE (A_INDENT, A("(null node)\n"))
#define | D_NODE_HEADER(node) (A_INDENT, A_NODE_HEADER(node, "\n"))
#define | COMPOUND_FIELD(len, name) FIELD_BLOCK((D_FIELD_HEADER((len), (name), "\n"), D_INDENT), D_DEDENT)
#define | COMPOUND_FIELD1(name, ann)
#define | FIELD_NAME_DESC(name, ann) name " (" ann ")"
#define | FIELD_NAME_LEN(name, ann)
#define | SIMPLE_FIELD(len, name) FIELD_BLOCK(D_FIELD_HEADER((len), (name), " "), A("\n"))
#define | FIELD_BLOCK(init, reset)
#define | SIMPLE_FIELD1(name, ann) SIMPLE_FIELD(FIELD_NAME_LEN(name, ann), FIELD_NAME_DESC(name, ann))
#define | F_CUSTOM1(name, ann) SIMPLE_FIELD1(#name, ann)
#define | F_ID(name, ann) SIMPLE_FIELD1(#name, ann) A_ID(node->name)
#define | F_GENTRY(name, ann) SIMPLE_FIELD1(#name, ann) A_ID(node->name)
#define | F_INT(name, ann) SIMPLE_FIELD1(#name, ann) A_INT(node->name)
#define | F_LONG(name, ann) SIMPLE_FIELD1(#name, ann) A_LONG(node->name)
#define | F_LIT(name, ann) SIMPLE_FIELD1(#name, ann) A_LIT(node->name)
#define | F_MSG(name, ann, desc) SIMPLE_FIELD1(#name, ann) A(desc)
#define | F_NODE(name, ann) COMPOUND_FIELD1(#name, ann) {dump_node(buf, indent, comment, node->name);}
#define | ANN(ann)
#define | LAST_NODE (next_indent = " ")

## Typedefs
typedef struct node_buffer_elem_struct | node_buffer_elem_t
typedef void | node_itr_t(void *ctx, NODE *node)

## Functions
VALUE | rb_dump_literal (VALUE lit)
VALUE | rb_parser_dump_tree (const NODE *node, int comment)
void | rb_node_init (NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2)
NODE * | rb_ast_newnode (rb_ast_t *ast, enum node_type type)
void | rb_ast_node_type_change (NODE *n, enum node_type type)
void | rb_ast_add_local_table (rb_ast_t *ast, ID *buf)
void | rb_ast_delete_node (rb_ast_t *ast, NODE *n)
rb_ast_t * | rb_ast_new (void)
void | rb_ast_update_references (rb_ast_t *ast)
void | rb_ast_mark (rb_ast_t *ast)
void | rb_ast_free (rb_ast_t *ast)
size_t | rb_ast_memsize (const rb_ast_t *ast)
void | rb_ast_dispose (rb_ast_t *ast)
void | rb_ast_add_mark_object (rb_ast_t *ast, VALUE obj)

## Macro Definition Documentation

## ◆ A

#define A | ( |  | str | ) | rb_str_cat2(buf, (str))

Definition at line 20 of file node.c.

## ◆ A_FIELD_HEADER

#define A_FIELD_HEADER | ( |  | len,
|  |  | name,
|  |  | term
| ) |  | rb_str_catf(buf, "+- %.*s:"term, (len), (name))

Definition at line 36 of file node.c.

## ◆ A_ID

#define A_ID | ( |  | id | ) | add_id(buf, (id))

Definition at line 26 of file node.c.

## ◆ A_INDENT

#define A_INDENT add_indent(buf, indent)

Definition at line 23 of file node.c.

## ◆ A_INT

#define A_INT | ( |  | val | ) | rb_str_catf(buf, "%d", (val))

Definition at line 27 of file node.c.

## ◆ A_LIT

#define A_LIT | ( |  | lit | ) | AR(rb_dump_literal(lit))

Definition at line 29 of file node.c.

## ◆ A_LONG

#define A_LONG | ( |  | val | ) | rb_str_catf(buf, "%ld", (val))

Definition at line 28 of file node.c.

## ◆ A_NODE_HEADER

#define A_NODE_HEADER | ( |  | node,
|  |  | term
| ) |  |

Value:
rb_str_catf(buf, "@ %s (line: %d, location: (%d,%d)-(%d,%d))%s"term, \
ruby_node_name(nd_type(node)), nd_line(node), \
nd_first_lineno(node), nd_first_column(node), \
nd_last_lineno(node), nd_last_column(node), \
(node->flags & NODE_FL_NEWLINE ? "*" : ""))
term
const char term
Definition: id.c:37
buf
voidpf void * buf
Definition: ioapi.h:138
ruby_node_name
const char * ruby_node_name(int node)
Definition: iseq.c:2593
nd_last_lineno
#define nd_last_lineno(n)
Definition: node.h:209
nd_first_lineno
#define nd_first_lineno(n)
Definition: node.h:202
nd_line
#define nd_line(n)
Definition: node.h:196
nd_first_column
#define nd_first_column(n)
Definition: node.h:200
nd_last_column
#define nd_last_column(n)
Definition: node.h:207
NODE_FL_NEWLINE
#define NODE_FL_NEWLINE
Definition: node.h:183
nd_type
#define nd_type(n)
Definition: node.h:188
rb_str_catf
VALUE rb_str_catf(VALUE, const char *,...)
Definition: sprintf.c:1243

Definition at line 30 of file node.c.

## ◆ ANN

#define ANN | ( |  | ann | ) |

Value:
if (comment) { \
A_INDENT; A("| # " ann "\n"); \
}
A_INDENT
#define A_INDENT
Definition: node.c:23
A
#define A(str)
Definition: node.c:20

Definition at line 75 of file node.c.

## ◆ AR

#define AR | ( |  | str | ) | rb_str_concat(buf, (str))

Definition at line 21 of file node.c.

## ◆ COMPOUND_FIELD

#define COMPOUND_FIELD | ( |  | len,
|  |  | name
| ) |  | FIELD_BLOCK((D_FIELD_HEADER((len), (name), "\n"), D_INDENT), D_DEDENT)

Definition at line 43 of file node.c.

## ◆ COMPOUND_FIELD1

#define COMPOUND_FIELD1 | ( |  | name,
|  |  | ann
| ) |  |

Value:
COMPOUND_FIELD(FIELD_NAME_LEN(name, ann), \
FIELD_NAME_DESC(name, ann))
name
const char * name
Definition: nkf.c:208
COMPOUND_FIELD
#define COMPOUND_FIELD(len, name)
Definition: node.c:43
FIELD_NAME_LEN
#define FIELD_NAME_LEN(name, ann)
Definition: node.c:51
FIELD_NAME_DESC
#define FIELD_NAME_DESC(name, ann)
Definition: node.c:50

Definition at line 46 of file node.c.

## ◆ D_DEDENT

#define D_DEDENT rb_str_resize(indent, RSTRING_LEN(indent) - 4)

Definition at line 25 of file node.c.

## ◆ D_FIELD_HEADER

#define D_FIELD_HEADER | ( |  | len,
|  |  | name,
|  |  | term
| ) |  | (A_INDENT, A_FIELD_HEADER(len, name, term))

Definition at line 38 of file node.c.

## ◆ D_INDENT

#define D_INDENT rb_str_cat2(indent, next_indent)

Definition at line 24 of file node.c.

## ◆ D_NODE_HEADER

#define D_NODE_HEADER | ( |  | node | ) | (A_INDENT, A_NODE_HEADER(node, "\n"))

Definition at line 41 of file node.c.

## ◆ D_NULL_NODE

#define D_NULL_NODE (A_INDENT, A("(null node)\n"))

Definition at line 40 of file node.c.

## ◆ F_CUSTOM1

#define F_CUSTOM1 | ( |  | name,
|  |  | ann
| ) |  | SIMPLE_FIELD1(#name, ann)

Definition at line 64 of file node.c.

## ◆ F_GENTRY

#define F_GENTRY | ( |  | name,
|  |  | ann
| ) |  | SIMPLE_FIELD1(#name, ann) A_ID(node->name)

Definition at line 66 of file node.c.

## ◆ F_ID

#define F_ID | ( |  | name,
|  |  | ann
| ) |  | SIMPLE_FIELD1(#name, ann) A_ID(node->name)

Definition at line 65 of file node.c.

## ◆ F_INT

#define F_INT | ( |  | name,
|  |  | ann
| ) |  | SIMPLE_FIELD1(#name, ann) A_INT(node->name)

Definition at line 67 of file node.c.

## ◆ F_LIT

#define F_LIT | ( |  | name,
|  |  | ann
| ) |  | SIMPLE_FIELD1(#name, ann) A_LIT(node->name)

Definition at line 69 of file node.c.

## ◆ F_LONG

#define F_LONG | ( |  | name,
|  |  | ann
| ) |  | SIMPLE_FIELD1(#name, ann) A_LONG(node->name)

Definition at line 68 of file node.c.

## ◆ F_MSG

#define F_MSG | ( |  | name,
|  |  | ann,
|  |  | desc
| ) |  | SIMPLE_FIELD1(#name, ann) A(desc)

Definition at line 70 of file node.c.

## ◆ F_NODE

#define F_NODE | ( |  | name,
|  |  | ann
| ) |  | COMPOUND_FIELD1(#name, ann) {dump_node(buf, indent, comment, node->name);}

Definition at line 72 of file node.c.

## ◆ FIELD_BLOCK

#define FIELD_BLOCK | ( |  | init,
|  |  | reset
| ) |  |

Value:
for (init, field_flag = 1; \
field_flag; /* should be optimized away */ \
reset, field_flag = 0)

Definition at line 58 of file node.c.

## ◆ FIELD_NAME_DESC

#define FIELD_NAME_DESC | ( |  | name,
|  |  | ann
| ) |  | name " (" ann ")"

Definition at line 50 of file node.c.

## ◆ FIELD_NAME_LEN

#define FIELD_NAME_LEN | ( |  | name,
|  |  | ann
| ) |  |

Value:
(int)( \
comment ? \
rb_strlen_lit(FIELD_NAME_DESC(name, ann)) : \
rb_strlen_lit(name))
rb_strlen_lit
#define rb_strlen_lit(str)
Definition: string.h:286
int
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

Definition at line 51 of file node.c.

## ◆ LAST_NODE

#define LAST_NODE (next_indent = " ")

Definition at line 80 of file node.c.

## ◆ NODE_BUF_DEFAULT_LEN

#define NODE_BUF_DEFAULT_LEN 16

Definition at line 18 of file node.c.

## ◆ SIMPLE_FIELD

#define SIMPLE_FIELD | ( |  | len,
|  |  | name
| ) |  | FIELD_BLOCK(D_FIELD_HEADER((len), (name), " "), A("\n"))

Definition at line 55 of file node.c.

## ◆ SIMPLE_FIELD1

#define SIMPLE_FIELD1 | ( |  | name,
|  |  | ann
| ) |  | SIMPLE_FIELD(FIELD_NAME_LEN(name, ann), FIELD_NAME_DESC(name, ann))

Definition at line 63 of file node.c.

## Typedef Documentation

## ◆ node_buffer_elem_t

typedef struct node_buffer_elem_struct node_buffer_elem_t

## ◆ node_itr_t

typedef void node_itr_t(void *ctx, NODE *node)

Definition at line 1306 of file node.c.

## Function Documentation

## ◆ rb_ast_add_local_table()

void rb_ast_add_local_table | ( | rb_ast_t * | ast,
|  | ID * | buf
| ) |  |

Definition at line 1283 of file node.c.

References int(), node_buffer_struct::local_tables, and rb_ast_struct::node_buffer.

Referenced by yyparse().

## ◆ rb_ast_add_mark_object()

void rb_ast_add_mark_object | ( | rb_ast_t * | ast,
|  | VALUE | obj
| ) |  |

Definition at line 1454 of file node.c.

References node_buffer_struct::mark_hash, NIL_P, rb_ast_struct::node_buffer, Qtrue, rb_hash_aset(), rb_ident_hash_new(), and RB_OBJ_WRITE.

## ◆ rb_ast_delete_node()

void rb_ast_delete_node | ( | rb_ast_t * | ast,
|  | NODE * | n
| ) |  |

Definition at line 1291 of file node.c.

## ◆ rb_ast_dispose()

void rb_ast_dispose | ( | rb_ast_t * | ast | ) |

Definition at line 1448 of file node.c.

References rb_ast_free().

## ◆ rb_ast_free()

void rb_ast_free | ( | rb_ast_t * | ast | ) |

Definition at line 1413 of file node.c.

References rb_ast_struct::node_buffer.

Referenced by rb_ast_dispose().

## ◆ rb_ast_mark()

void rb_ast_mark | ( | rb_ast_t * | ast | ) |

Definition at line 1401 of file node.c.

References rb_ast_struct::body, rb_ast_body_struct::compile_option, node_buffer_struct::mark_hash, node_buffer_struct::markable, rb_ast_struct::node_buffer, NULL, and rb_gc_mark().

## ◆ rb_ast_memsize()

size_t rb_ast_memsize | ( | const rb_ast_t * | ast | ) |

Definition at line 1434 of file node.c.

References node_buffer_struct::markable, NODE_BUF_DEFAULT_LEN, rb_ast_struct::node_buffer, offsetof, and node_buffer_struct::unmarkable.

## ◆ rb_ast_new()

rb_ast_t * rb_ast_new | ( | void |  | ) |

Definition at line 1299 of file node.c.

References imemo_ast, and rb_imemo_new().

## ◆ rb_ast_newnode()

NODE * rb_ast_newnode | ( | rb_ast_t * | ast,
|  | enum node_type | type
| ) |  |

Definition at line 1264 of file node.c.

References node_buffer_struct::markable, rb_ast_struct::node_buffer, and node_buffer_struct::unmarkable.

## ◆ rb_ast_node_type_change()

void rb_ast_node_type_change | ( | NODE * | n,
|  | enum node_type | type
| ) |  |

Definition at line 1273 of file node.c.

References nd_type, rb_bug(), and ruby_node_name().

## ◆ rb_ast_update_references()

void rb_ast_update_references | ( | rb_ast_t * | ast | ) |

Definition at line 1391 of file node.c.

References node_buffer_struct::markable, rb_ast_struct::node_buffer, and NULL.

## ◆ rb_dump_literal()

VALUE rb_dump_literal | ( | VALUE | lit | ) |

Definition at line 83 of file node.c.

References FL_SINGLETON, FL_TEST, PRIsVALUE, rb_class_path(), rb_inspect(), rb_sprintf(), str, T_CLASS, T_ICLASS, and T_MODULE.

Referenced by rb_insn_operand_intern().

## ◆ rb_node_init()

void rb_node_init | ( | NODE * | n,
|  | enum node_type | type,
|  | VALUE | a0,
|  | VALUE | a1,
|  | VALUE | a2
| ) |  |

Definition at line 1139 of file node.c.

References rb_code_location_struct::beg_pos, rb_code_position_struct::column, rb_code_location_struct::end_pos, RNode::flags, rb_code_position_struct::lineno, nd_init_type, RNode::nd_loc, T_NODE, RNode::u1, RNode::u2, RNode::u3, and RNode::value.

Referenced by rb_binding_add_dynavars().

## ◆ rb_parser_dump_tree()

VALUE rb_parser_dump_tree | ( | const NODE * | node,
|  | int | comment
| ) |  |

Definition at line 1120 of file node.c.

References rb_str_new_cstr.