Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Data Structures | Macros | Typedefs | Functions
node.c File Reference
`#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_inspect(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)->id)
#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_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_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 17 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 33 of file node.c.

## ◆ A_ID

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

Definition at line 23 of file node.c.

## ◆ A_INDENT

#define A_INDENT add_indent(buf, indent)

Definition at line 20 of file node.c.

## ◆ A_INT

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

Definition at line 24 of file node.c.

## ◆ A_LIT

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

Definition at line 26 of file node.c.

## ◆ A_LONG

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

Definition at line 25 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 ? "*" : ""))

Definition at line 27 of file node.c.

## ◆ ANN

#define ANN | ( |  | ann | ) |

Value:
if (comment) { \
A_INDENT; A("| # " ann "\n"); \
}

Definition at line 72 of file node.c.

## ◆ AR

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

Definition at line 18 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 40 of file node.c.

## ◆ COMPOUND_FIELD1

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

Value:
COMPOUND_FIELD(FIELD_NAME_LEN(name, ann), \
FIELD_NAME_DESC(name, ann))

Definition at line 43 of file node.c.

## ◆ D_DEDENT

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

Definition at line 22 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 35 of file node.c.

## ◆ D_INDENT

#define D_INDENT rb_str_cat2(indent, next_indent)

Definition at line 21 of file node.c.

## ◆ D_NODE_HEADER

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

Definition at line 38 of file node.c.

## ◆ D_NULL_NODE

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

Definition at line 37 of file node.c.

## ◆ F_CUSTOM1

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

Definition at line 61 of file node.c.

## ◆ F_GENTRY

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

Definition at line 63 of file node.c.

## ◆ F_ID

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

Definition at line 62 of file node.c.

## ◆ F_INT

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

Definition at line 64 of file node.c.

## ◆ F_LIT

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

Definition at line 66 of file node.c.

## ◆ F_LONG

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

Definition at line 65 of file node.c.

## ◆ F_MSG

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

Definition at line 67 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 69 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 55 of file node.c.

## ◆ FIELD_NAME_DESC

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

Definition at line 47 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))

Definition at line 48 of file node.c.

## ◆ LAST_NODE

#define LAST_NODE (next_indent = " ")

Definition at line 77 of file node.c.

## ◆ NODE_BUF_DEFAULT_LEN

#define NODE_BUF_DEFAULT_LEN 16

Definition at line 15 of file node.c.

## ◆ SIMPLE_FIELD

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

Definition at line 52 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 60 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 1226 of file node.c.

## Function Documentation

## ◆ rb_ast_add_mark_object()

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

Definition at line 1395 of file node.c.

References NIL_P, rb_ast_struct::node_buffer, obj, 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 1211 of file node.c.

References n, and void.

## ◆ rb_ast_dispose()

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

Definition at line 1389 of file node.c.

References rb_ast_free().

## ◆ rb_ast_free()

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

Definition at line 1354 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 1342 of file node.c.

References rb_ast_struct::body, rb_ast_body_struct::compile_option, rb_ast_struct::node_buffer, and rb_gc_mark().

## ◆ rb_ast_memsize()

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

Definition at line 1375 of file node.c.

References buf, NODE_BUF_DEFAULT_LEN, rb_ast_struct::node_buffer, offsetof, and size.

## ◆ rb_ast_new()

rb_ast_t* rb_ast_new | ( | void |  | ) |

Definition at line 1219 of file node.c.

## ◆ rb_ast_newnode()

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

Definition at line 1189 of file node.c.

References NODE_ARGS, NODE_ARYPTN, rb_ast_struct::node_buffer, NODE_DREGX, NODE_DSTR, NODE_DSYM, NODE_DXSTR, NODE_LIT, NODE_MATCH, NODE_SCOPE, NODE_STR, and NODE_XSTR.

## ◆ rb_ast_update_references()

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

Definition at line 1332 of file node.c.

References rb_ast_struct::node_buffer.

## ◆ rb_node_init()

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

Definition at line 1095 of file node.c.

References n, nd_set_type, and T_NODE.

## ◆ rb_parser_dump_tree()

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

Definition at line 1076 of file node.c.

References buf, and rb_str_new_cstr.

NODE_FL_NEWLINE
#define NODE_FL_NEWLINE
Definition: node.h:183
ruby_node_name
const char * ruby_node_name(int node)
Definition: iseq.c:2534
nd_last_lineno
#define nd_last_lineno(n)
Definition: node.h:207
int
__inline__ int
Definition: rb_mjit_min_header-2.7.0.h:2839
COMPOUND_FIELD
#define COMPOUND_FIELD(len, name)
Definition: node.c:40
A
#define A(str)
Definition: node.c:17
term
const char term
Definition: id.c:37
nd_first_column
#define nd_first_column(n)
Definition: node.h:198
FIELD_NAME_DESC
#define FIELD_NAME_DESC(name, ann)
Definition: node.c:47
nd_last_column
#define nd_last_column(n)
Definition: node.h:205
buf
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4322
FIELD_NAME_LEN
#define FIELD_NAME_LEN(name, ann)
Definition: node.c:48
nd_first_lineno
#define nd_first_lineno(n)
Definition: node.h:200
rb_str_catf
VALUE rb_str_catf(VALUE str, const char *format,...)
Definition: sprintf.c:1237
nd_line
#define nd_line(n)
Definition: node.h:194
nd_type
#define nd_type(n)
Definition: node.h:188
rb_strlen_lit
#define rb_strlen_lit(str)
Definition: intern.h:913
name
const char * name
Definition: nkf.c:208