diff options
Diffstat (limited to 'node.c')
-rw-r--r-- | node.c | 53 |
1 files changed, 27 insertions, 26 deletions
@@ -20,17 +20,18 @@ #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 A_NODE_HEADER(node, term) \ + rb_str_catf(buf, "@ %s (line: %d)"term, ruby_node_name(nd_type(node)), nd_line(node)) +#define A_FIELD_HEADER(name, term) \ + rb_str_catf(buf, "+- %s:"term, (name)) +#define D_FIELD_HEADER(name, term) (A_INDENT, A_FIELD_HEADER(name, term)) -#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 D_NULL_NODE (A_INDENT, A("(null node)\n")) +#define D_NODE_HEADER(node) (A_INDENT, A_NODE_HEADER(node, "\n")) #define COMPOUND_FIELD(name, name2, block) \ do { \ - A_INDENT; A_FIELD_HEADER(comment ? (name2) : (name)); A("\n"); \ + D_FIELD_HEADER(comment ? (name2) : (name), "\n"); \ rb_str_cat2(indent, next_indent); \ block; \ rb_str_resize(indent, RSTRING_LEN(indent) - 4); \ @@ -38,7 +39,7 @@ #define SIMPLE_FIELD(name, name2, block) \ do { \ - A_INDENT; A_FIELD_HEADER(comment ? (name2) : (name)); A(" "); block; A("\n"); \ + D_FIELD_HEADER(comment ? (name2) : (name), " "); block; A("\n"); \ } while (0) #define F_CUSTOM1(name, ann, block) SIMPLE_FIELD(#name, #name " (" ann ")", block) @@ -149,8 +150,8 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node) ANN("example: until x == 1; foo; end"); loop: F_CUSTOM1(nd_state, "begin-end-while?", { - A_INT((int)node->nd_state); - A((node->nd_state == 1) ? " (while-end)" : " (begin-end-while)"); + A_INT((int)node->nd_state); + A((node->nd_state == 1) ? " (while-end)" : " (begin-end-while)"); }); F_NODE(nd_cond, "condition"); LAST_NODE; @@ -351,11 +352,11 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node) F_ID(nd_next->nd_vid, "reader"); F_ID(nd_next->nd_aid, "writer"); F_CUSTOM1(nd_next->nd_mid, "operator", { - switch (node->nd_next->nd_mid) { - case 0: A("0 (||)"); break; - case 1: A("1 (&&)"); break; - default: A_ID(node->nd_next->nd_mid); - } + switch (node->nd_next->nd_mid) { + case 0: A("0 (||)"); break; + case 1: A("1 (&&)"); break; + default: A_ID(node->nd_next->nd_mid); + } }); LAST_NODE; F_NODE(nd_value, "rvalue"); @@ -501,11 +502,11 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node) ANN("format: $[nd_nth]"); ANN("example: $&, $`, $', $+"); F_CUSTOM1(nd_nth, "variable", { - char name[3]; - name[0] = '$'; - name[1] = (char)node->nd_nth; - name[2] = '\0'; - A(name); + char name[3]; + name[0] = '$'; + name[1] = (char)node->nd_nth; + name[2] = '\0'; + A(name); }); break; @@ -871,13 +872,13 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node) ANN("new scope"); ANN("format: [nd_tbl]: local table, [nd_args]: arguments, [nd_body]: body"); F_CUSTOM1(nd_tbl, "local table", { - ID *tbl = node->nd_tbl; - int i; - int size = tbl ? (int)*tbl++ : 0; - if (size == 0) A("(empty)"); - for (i = 0; i < size; i++) { + ID *tbl = node->nd_tbl; + int i; + int size = tbl ? (int)*tbl++ : 0; + if (size == 0) A("(empty)"); + for (i = 0; i < size; i++) { A_ID(tbl[i]); if (i < size - 1) A(","); - } + } }); F_NODE(nd_args, "arguments"); LAST_NODE; |