node.c File Reference
`#include "ruby/ruby.h"`
`#include "vm_core.h"`

Go to the source code of this file.

## Macros

#define | A(str) rb_str_cat2(buf, (str))
#define | AR(str) rb_str_concat(buf, (str))
#define | A_INDENT add_indent(buf, indent)
#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) rb_str_catf(buf, "@ %s (line: %d)", ruby_node_name(nd_type(node)), nd_line(node))
#define | A_FIELD_HEADER(name) rb_str_catf(buf, "+- %s:", (name))
#define | D_NULL_NODE A_INDENT; A("(null node)"); A("\n");
#define | D_NODE_HEADER(node) A_INDENT; A_NODE_HEADER(node); A("\n");
#define | COMPOUND_FIELD(name, name2, block)
#define | SIMPLE_FIELD(name, name2, block)
#define | F_CUSTOM1(name, ann, block) SIMPLE_FIELD(#name, #name " (" ann ")", block)
#define | F_ID(name, ann) SIMPLE_FIELD(#name, #name " (" ann ")", A_ID(node->name))
#define | F_GENTRY(name, ann) SIMPLE_FIELD(#name, #name " (" ann ")", A_ID((node->name)->id))
#define | F_INT(name, ann) SIMPLE_FIELD(#name, #name " (" ann ")", A_INT(node->name))
#define | F_LONG(name, ann) SIMPLE_FIELD(#name, #name " (" ann ")", A_LONG(node->name))
#define | F_LIT(name, ann) SIMPLE_FIELD(#name, #name " (" ann ")", A_LIT(node->name))
#define | F_MSG(name, ann, desc) SIMPLE_FIELD(#name, #name " (" ann ")", A(desc))
#define | F_CUSTOM2(name, ann, block) COMPOUND_FIELD(#name, #name " (" ann ")", block)
#define | F_NODE(name, ann) COMPOUND_FIELD(#name, #name " (" ann ")", dump_node(buf, indent, comment, node->name))
#define | ANN(ann)
#define | LAST_NODE (next_indent = " ")

## Functions

static void | add_indent (VALUE buf, VALUE indent)
static void | add_id (VALUE buf, ID id)
static void | dump_node (VALUE buf, VALUE indent, int comment, NODE *node)
VALUE | rb_parser_dump_tree (NODE *node, int comment)

## Macro Definition Documentation

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

Definition at line 15 of file node.c.

Referenced by add_id(), and dump_node().

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

Definition at line 25 of file node.c.

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

Definition at line 19 of file node.c.

Referenced by dump_node().

#define A_INDENT add_indent(buf, indent)

Definition at line 18 of file node.c.

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

Definition at line 20 of file node.c.

Referenced by dump_node().

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

Definition at line 22 of file node.c.

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

Definition at line 21 of file node.c.

#define A_NODE_HEADER | ( |  | node | ) | rb_str_catf(buf, "@ %s (line: %d)", ruby_node_name(nd_type(node)), nd_line(node))

Definition at line 23 of file node.c.

#define ANN | ( |  | ann | ) |

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

Definition at line 58 of file node.c.

Referenced by dump_node().

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

Definition at line 16 of file node.c.

Referenced by add_id(), and add_indent().

#define COMPOUND_FIELD | ( |  | name,
|  |  | name2,
|  |  | block
| ) |  |

Value:
do { \
A_INDENT; A_FIELD_HEADER(comment ? (name2) : (name)); A("\n"); \
rb_str_cat2(indent, next_indent); \
block; \
rb_str_resize(indent, RSTRING_LEN(indent) - 4); \
} while (0)

Definition at line 31 of file node.c.

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

Definition at line 29 of file node.c.

Referenced by dump_node().

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

Definition at line 28 of file node.c.

Referenced by dump_node().

#define F_CUSTOM1 | ( |  | name,
|  |  | ann,
|  |  | block
| ) |  | SIMPLE_FIELD(#name, #name " (" ann ")", block)

Definition at line 44 of file node.c.

Referenced by dump_node().

#define F_CUSTOM2 | ( |  | name,
|  |  | ann,
|  |  | block
| ) |  | COMPOUND_FIELD(#name, #name " (" ann ")", block)

Definition at line 52 of file node.c.

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

Definition at line 46 of file node.c.

Referenced by dump_node().

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

Definition at line 45 of file node.c.

Referenced by dump_node().

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

Definition at line 47 of file node.c.

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

Definition at line 49 of file node.c.

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

Definition at line 48 of file node.c.

#define F_MSG | ( |  | name,
|  |  | ann,
|  |  | desc
| ) |  | SIMPLE_FIELD(#name, #name " (" ann ")", A(desc))

Definition at line 50 of file node.c.

Referenced by dump_node().

#define F_NODE | ( |  | name,
|  |  | ann
| ) |  | COMPOUND_FIELD(#name, #name " (" ann ")", dump_node(buf, indent, comment, node->name))

Definition at line 55 of file node.c.

Referenced by dump_node().

#define LAST_NODE (next_indent = " ")

Definition at line 63 of file node.c.

Referenced by dump_node().

#define SIMPLE_FIELD | ( |  | name,
|  |  | name2,
|  |  | block
| ) |  |

Value:
do { \
A_INDENT; A_FIELD_HEADER(comment ? (name2) : (name)); A(" "); block; A("\n"); \
} while (0)

Definition at line 39 of file node.c.

## Function Documentation

static void add_id | ( | VALUE | buf,
|  | ID | id
| ) |  |

static

Definition at line 72 of file node.c.

References A, AR, and rb_id2str().

static void add_indent | ( | VALUE | buf,
|  | VALUE | indent
| ) |  |

static

Definition at line 66 of file node.c.

References AR.

static void dump_node | ( | VALUE | buf,
|  | VALUE | indent,
|  | int | comment,
|  | NODE * | node
| ) |  |

static

Definition at line 89 of file node.c.

References A, A_ID, A_INT, ANN, D_NODE_HEADER, D_NULL_NODE, F_CUSTOM1, F_GENTRY, F_ID, F_MSG, F_NODE, LAST_NODE, nd_1st, nd_2nd, nd_args, nd_body, nd_cond, nd_else, nd_ensr, nd_entry, nd_head, nd_iter, nd_next, nd_recv, nd_resq, nd_state, nd_stts, nd_type, nd_value, nd_vid, NODE_AND, NODE_BEGIN, NODE_BLOCK, NODE_BREAK, NODE_CASE, NODE_CDECL, NODE_CVASGN, NODE_DASGN, NODE_DASGN_CURR, NODE_ENSURE, NODE_FOR, NODE_GASGN, NODE_IASGN, NODE_IF, NODE_ITER, NODE_LASGN, NODE_MASGN, NODE_NEXT, NODE_OP_ASGN1, NODE_OP_ASGN2, NODE_OPT_N, NODE_OR, NODE_REDO, NODE_RESBODY, NODE_RESCUE, NODE_RETRY, NODE_RETURN, NODE_UNTIL, NODE_WHEN, and NODE_WHILE.

Referenced by rb_parser_dump_tree().

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

Definition at line 911 of file node.c.

References buf, dump_node(), and rb_str_new_cstr().

Referenced by process_options().