13#include "internal/hash.h"
14#include "internal/variable.h"
18#define A(str) rb_str_cat2(buf, (str))
19#define AR(str) rb_str_concat(buf, (str))
21#define A_INDENT add_indent(buf, indent)
22#define D_INDENT rb_str_cat2(indent, next_indent)
23#define D_DEDENT rb_str_resize(indent, RSTRING_LEN(indent) - 4)
24#define A_ID(id) add_id(buf, (id))
25#define A_INT(val) rb_str_catf(buf, "%d", (val))
26#define A_LONG(val) rb_str_catf(buf, "%ld", (val))
27#define A_LIT(lit) AR(rb_dump_literal(lit))
28#define A_NODE_HEADER(node, term) \
29 rb_str_catf(buf, "@ %s (id: %d, line: %d, location: (%d,%d)-(%d,%d))%s"term, \
30 ruby_node_name(nd_type(node)), nd_node_id(node), nd_line(node), \
31 nd_first_lineno(node), nd_first_column(node), \
32 nd_last_lineno(node), nd_last_column(node), \
33 (nd_fl_newline(node) ? "*" : ""))
34#define A_FIELD_HEADER(len, name, term) \
35 rb_str_catf(buf, "+- %.*s:"term, (len), (name))
36#define D_FIELD_HEADER(len, name, term) (A_INDENT, A_FIELD_HEADER(len, name, term))
38#define D_NULL_NODE (A_INDENT, A("(null node)\n"))
39#define D_NODE_HEADER(node) (A_INDENT, A_NODE_HEADER(node, "\n"))
41#define COMPOUND_FIELD(len, name) \
42 FIELD_BLOCK((D_FIELD_HEADER((len), (name), "\n"), D_INDENT), D_DEDENT)
44#define COMPOUND_FIELD1(name, ann) \
45 COMPOUND_FIELD(FIELD_NAME_LEN(name, ann), \
46 FIELD_NAME_DESC(name, ann))
48#define FIELD_NAME_DESC(name, ann) name " (" ann ")"
49#define FIELD_NAME_LEN(name, ann) (int)( \
51 rb_strlen_lit(FIELD_NAME_DESC(name, ann)) : \
53#define SIMPLE_FIELD(len, name) \
54 FIELD_BLOCK(D_FIELD_HEADER((len), (name), " "), A("\n"))
56#define FIELD_BLOCK(init, reset) \
57 for (init, field_flag = 1; \
59 reset, field_flag = 0)
61#define SIMPLE_FIELD1(name, ann) SIMPLE_FIELD(FIELD_NAME_LEN(name, ann), FIELD_NAME_DESC(name, ann))
62#define F_CUSTOM1(name, ann) SIMPLE_FIELD1(#name, ann)
63#define F_ID(name, type, ann) SIMPLE_FIELD1(#name, ann) A_ID(type(node)->name)
64#define F_INT(name, type, ann) SIMPLE_FIELD1(#name, ann) A_INT(type(node)->name)
65#define F_LONG(name, type, ann) SIMPLE_FIELD1(#name, ann) A_LONG(type(node)->name)
66#define F_LIT(name, type, ann) SIMPLE_FIELD1(#name, ann) A_LIT(type(node)->name)
67#define F_MSG(name, ann, desc) SIMPLE_FIELD1(#name, ann) A(desc)
69#define F_NODE(name, type, ann) \
70 COMPOUND_FIELD1(#name, ann) {dump_node(buf, indent, comment, RNODE(type(node)->name));}
72#define F_NODE2(name, n, ann) \
73 COMPOUND_FIELD1(#name, ann) {dump_node(buf, indent, comment, n);}
77 A_INDENT; A("| # " ann "\n"); \
80#define LAST_NODE (next_indent = " ")
83rb_dump_literal(
VALUE lit)
91 str = rb_sprintf(
"<%"PRIsVALUE
">", str);
114 VALUE str = rb_id2str(
id);
119 rb_str_catf(buf,
"(internal variable: 0x%"PRIsVALUE
")",
id);
129static void dump_node(
VALUE,
VALUE,
int,
const NODE *);
130static const char default_indent[] =
"| ";
133dump_array(
VALUE buf,
VALUE indent,
int comment,
const NODE *node)
136 const char *next_indent = default_indent;
137 F_LONG(as.nd_alen, RNODE_LIST,
"length");
138 F_NODE(nd_head, RNODE_LIST,
"element");
139 while (RNODE_LIST(node)->nd_next && nd_type_p(RNODE_LIST(node)->nd_next, NODE_LIST)) {
140 node = RNODE_LIST(node)->nd_next;
141 F_NODE(nd_head, RNODE_LIST,
"element");
144 F_NODE(nd_next, RNODE_LIST,
"next element");
148dump_node(
VALUE buf,
VALUE indent,
int comment,
const NODE * node)
152 const char *next_indent = default_indent;
162 type = nd_type(node);
165 ANN(
"statement sequence");
166 ANN(
"format: [nd_head]; ...; [nd_next]");
167 ANN(
"example: foo; bar");
171 rb_str_catf(buf,
"+- nd_head (%s%d):\n",
172 comment ?
"statement #" :
"", ++i);
173 if (!RNODE_BLOCK(node)->nd_next) LAST_NODE;
175 dump_node(buf, indent, comment, RNODE_BLOCK(node)->nd_head);
177 }
while (RNODE_BLOCK(node)->nd_next &&
178 nd_type_p(RNODE_BLOCK(node)->nd_next, NODE_BLOCK) &&
179 (node = RNODE_BLOCK(node)->nd_next, 1));
180 if (RNODE_BLOCK(node)->nd_next) {
182 F_NODE(nd_next, RNODE_BLOCK,
"next block");
188 ANN(
"format: if [nd_cond] then [nd_body] else [nd_else] end");
189 ANN(
"example: if x == 1 then foo else bar end");
190 F_NODE(nd_cond, RNODE_IF,
"condition expr");
191 F_NODE(nd_body, RNODE_IF,
"then clause");
193 F_NODE(nd_else, RNODE_IF,
"else clause");
197 ANN(
"unless statement");
198 ANN(
"format: unless [nd_cond] then [nd_body] else [nd_else] end");
199 ANN(
"example: unless x == 1 then foo else bar end");
200 F_NODE(nd_cond, RNODE_UNLESS,
"condition expr");
201 F_NODE(nd_body, RNODE_UNLESS,
"then clause");
203 F_NODE(nd_else, RNODE_UNLESS,
"else clause");
207 ANN(
"case statement");
208 ANN(
"format: case [nd_head]; [nd_body]; end");
209 ANN(
"example: case x; when 1; foo; when 2; bar; else baz; end");
210 F_NODE(nd_head, RNODE_CASE,
"case expr");
212 F_NODE(nd_body, RNODE_CASE,
"when clauses");
215 ANN(
"case statement with no head");
216 ANN(
"format: case; [nd_body]; end");
217 ANN(
"example: case; when 1; foo; when 2; bar; else baz; end");
218 F_NODE(nd_head, RNODE_CASE2,
"case expr");
220 F_NODE(nd_body, RNODE_CASE2,
"when clauses");
223 ANN(
"case statement (pattern matching)");
224 ANN(
"format: case [nd_head]; [nd_body]; end");
225 ANN(
"example: case x; in 1; foo; in 2; bar; else baz; end");
226 F_NODE(nd_head, RNODE_CASE3,
"case expr");
228 F_NODE(nd_body, RNODE_CASE3,
"in clauses");
233 ANN(
"format: when [nd_head]; [nd_body]; (when or else) [nd_next]");
234 ANN(
"example: case x; when 1; foo; when 2; bar; else baz; end");
235 F_NODE(nd_head, RNODE_WHEN,
"when value");
236 F_NODE(nd_body, RNODE_WHEN,
"when body");
238 F_NODE(nd_next, RNODE_WHEN,
"next when clause");
243 ANN(
"format: in [nd_head]; [nd_body]; (in or else) [nd_next]");
244 ANN(
"example: case x; in 1; foo; in 2; bar; else baz; end");
245 F_NODE(nd_head, RNODE_IN,
"in pattern");
246 F_NODE(nd_body, RNODE_IN,
"in body");
248 F_NODE(nd_next, RNODE_IN,
"next in clause");
252 ANN(
"while statement");
253 ANN(
"format: while [nd_cond]; [nd_body]; end");
254 ANN(
"example: while x == 1; foo; end");
257 ANN(
"until statement");
258 ANN(
"format: until [nd_cond]; [nd_body]; end");
259 ANN(
"example: until x == 1; foo; end");
261 F_CUSTOM1(nd_state,
"begin-end-while?") {
262 A_INT((
int)RNODE_WHILE(node)->nd_state);
263 A((RNODE_WHILE(node)->nd_state == 1) ?
" (while-end)" :
" (begin-end-while)");
265 F_NODE(nd_cond, RNODE_WHILE,
"condition");
267 F_NODE(nd_body, RNODE_WHILE,
"body");
271 ANN(
"method call with block");
272 ANN(
"format: [nd_iter] { [nd_body] }");
273 ANN(
"example: 3.times { foo }");
276 ANN(
"for statement");
277 ANN(
"format: for * in [nd_iter] do [nd_body] end");
278 ANN(
"example: for i in 1..3 do foo end");
280 F_NODE(nd_iter, RNODE_ITER,
"iteration receiver");
282 F_NODE(nd_body, RNODE_ITER,
"body");
286 ANN(
"vars of for statement with masgn");
287 ANN(
"format: for [nd_var] in ... do ... end");
288 ANN(
"example: for x, y in 1..3 do foo end");
290 F_NODE(nd_var, RNODE_FOR_MASGN,
"var");
294 ANN(
"break statement");
295 ANN(
"format: break [nd_stts]");
296 ANN(
"example: break 1");
298 F_NODE(nd_stts, RNODE_BREAK,
"value");
301 ANN(
"next statement");
302 ANN(
"format: next [nd_stts]");
303 ANN(
"example: next 1");
305 F_NODE(nd_stts, RNODE_NEXT,
"value");
308 ANN(
"return statement");
309 ANN(
"format: return [nd_stts]");
310 ANN(
"example: return 1");
312 F_NODE(nd_stts, RNODE_RETURN,
"value");
316 ANN(
"redo statement");
318 ANN(
"example: redo");
322 ANN(
"retry statement");
323 ANN(
"format: retry");
324 ANN(
"example: retry");
328 ANN(
"begin statement");
329 ANN(
"format: begin; [nd_body]; end");
330 ANN(
"example: begin; 1; end");
332 F_NODE(nd_body, RNODE_BEGIN,
"body");
336 ANN(
"rescue clause");
337 ANN(
"format: begin; [nd_body]; (rescue) [nd_resq]; else [nd_else]; end");
338 ANN(
"example: begin; foo; rescue; bar; else; baz; end");
339 F_NODE(nd_head, RNODE_RESCUE,
"body");
340 F_NODE(nd_resq, RNODE_RESCUE,
"rescue clause list");
342 F_NODE(nd_else, RNODE_RESCUE,
"rescue else clause");
346 ANN(
"rescue clause (cont'd)");
347 ANN(
"format: rescue [nd_args]; [nd_body]; (rescue) [nd_head]");
348 ANN(
"example: begin; foo; rescue; bar; else; baz; end");
349 F_NODE(nd_args, RNODE_RESBODY,
"rescue exceptions");
350 F_NODE(nd_body, RNODE_RESBODY,
"rescue clause");
352 F_NODE(nd_head, RNODE_RESBODY,
"next rescue clause");
356 ANN(
"ensure clause");
357 ANN(
"format: begin; [nd_head]; ensure; [nd_ensr]; end");
358 ANN(
"example: begin; foo; ensure; bar; end");
359 F_NODE(nd_head, RNODE_ENSURE,
"body");
361 F_NODE(nd_ensr, RNODE_ENSURE,
"ensure clause");
366 ANN(
"format: [nd_1st] && [nd_2nd]");
367 ANN(
"example: foo && bar");
371 ANN(
"format: [nd_1st] || [nd_2nd]");
372 ANN(
"example: foo || bar");
375 F_NODE(nd_1st, RNODE_AND,
"left expr");
376 if (!RNODE_AND(node)->nd_2nd || !nd_type_p(RNODE_AND(node)->nd_2nd,
type))
378 node = RNODE_AND(node)->nd_2nd;
381 F_NODE(nd_2nd, RNODE_AND,
"right expr");
385 ANN(
"multiple assignment");
386 ANN(
"format: [nd_head], [nd_args] = [nd_value]");
387 ANN(
"example: a, b = foo");
388 F_NODE(nd_value, RNODE_MASGN,
"rhsn");
389 F_NODE(nd_head, RNODE_MASGN,
"lhsn");
390 if (NODE_NAMED_REST_P(RNODE_MASGN(node)->nd_args)) {
392 F_NODE(nd_args, RNODE_MASGN,
"splatn");
395 F_MSG(nd_args,
"splatn",
"NODE_SPECIAL_NO_NAME_REST (rest argument without name)");
400 ANN(
"local variable assignment");
401 ANN(
"format: [nd_vid](lvar) = [nd_value]");
402 ANN(
"example: x = foo");
403 F_ID(nd_vid, RNODE_LASGN,
"local variable");
404 if (NODE_REQUIRED_KEYWORD_P(RNODE_LASGN(node)->nd_value)) {
405 F_MSG(nd_value,
"rvalue",
"NODE_SPECIAL_REQUIRED_KEYWORD (required keyword argument)");
409 F_NODE(nd_value, RNODE_LASGN,
"rvalue");
413 ANN(
"dynamic variable assignment");
414 ANN(
"format: [nd_vid](dvar) = [nd_value]");
415 ANN(
"example: x = nil; 1.times { x = foo }");
416 ANN(
"example: 1.times { x = foo }");
417 F_ID(nd_vid, RNODE_DASGN,
"local variable");
418 if (NODE_REQUIRED_KEYWORD_P(RNODE_DASGN(node)->nd_value)) {
419 F_MSG(nd_value,
"rvalue",
"NODE_SPECIAL_REQUIRED_KEYWORD (required keyword argument)");
423 F_NODE(nd_value, RNODE_DASGN,
"rvalue");
427 ANN(
"instance variable assignment");
428 ANN(
"format: [nd_vid](ivar) = [nd_value]");
429 ANN(
"example: @x = foo");
430 F_ID(nd_vid, RNODE_IASGN,
"instance variable");
432 F_NODE(nd_value, RNODE_IASGN,
"rvalue");
435 ANN(
"class variable assignment");
436 ANN(
"format: [nd_vid](cvar) = [nd_value]");
437 ANN(
"example: @@x = foo");
438 F_ID(nd_vid, RNODE_CVASGN,
"class variable");
440 F_NODE(nd_value, RNODE_CVASGN,
"rvalue");
443 ANN(
"global variable assignment");
444 ANN(
"format: [nd_vid](gvar) = [nd_value]");
445 ANN(
"example: $x = foo");
446 F_ID(nd_vid, RNODE_GASGN,
"global variable");
448 F_NODE(nd_value, RNODE_GASGN,
"rvalue");
452 ANN(
"constant declaration");
453 ANN(
"format: [nd_else]::[nd_vid](constant) = [nd_value]");
454 ANN(
"example: X = foo");
455 if (RNODE_CDECL(node)->nd_vid) {
456 F_ID(nd_vid, RNODE_CDECL,
"constant");
457 F_MSG(nd_else,
"extension",
"not used");
460 F_MSG(nd_vid,
"constant",
"0 (see extension field)");
461 F_NODE(nd_else, RNODE_CDECL,
"extension");
464 F_NODE(nd_value, RNODE_CDECL,
"rvalue");
468 ANN(
"array assignment with operator");
469 ANN(
"format: [nd_recv] [ [nd_index] ] [nd_mid]= [nd_rvalue]");
470 ANN(
"example: ary[1] += foo");
471 F_NODE(nd_recv, RNODE_OP_ASGN1,
"receiver");
472 F_ID(nd_mid, RNODE_OP_ASGN1,
"operator");
473 F_NODE(nd_index, RNODE_OP_ASGN1,
"index");
475 F_NODE(nd_rvalue, RNODE_OP_ASGN1,
"rvalue");
479 ANN(
"attr assignment with operator");
480 ANN(
"format: [nd_recv].[nd_vid] [nd_mid]= [nd_value]");
481 ANN(
"example: struct.field += foo");
482 F_NODE(nd_recv, RNODE_OP_ASGN2,
"receiver");
483 F_CUSTOM1(nd_vid,
"attr") {
484 if (RNODE_OP_ASGN2(node)->nd_aid) A(
"? ");
485 A_ID(RNODE_OP_ASGN2(node)->nd_vid);
487 F_ID(nd_mid, RNODE_OP_ASGN2,
"operator");
489 F_NODE(nd_value, RNODE_OP_ASGN2,
"rvalue");
492 case NODE_OP_ASGN_AND:
493 ANN(
"assignment with && operator");
494 ANN(
"format: [nd_head] &&= [nd_value]");
495 ANN(
"example: foo &&= bar");
497 case NODE_OP_ASGN_OR:
498 ANN(
"assignment with || operator");
499 ANN(
"format: [nd_head] ||= [nd_value]");
500 ANN(
"example: foo ||= bar");
502 F_NODE(nd_head, RNODE_OP_ASGN_AND,
"variable");
504 F_NODE(nd_value, RNODE_OP_ASGN_AND,
"rvalue");
508 ANN(
"constant declaration with operator");
509 ANN(
"format: [nd_head](constant) [nd_aid]= [nd_value]");
510 ANN(
"example: A::B ||= 1");
511 F_NODE(nd_head, RNODE_OP_CDECL,
"constant");
512 F_ID(nd_aid, RNODE_OP_CDECL,
"operator");
514 F_NODE(nd_value, RNODE_OP_CDECL,
"rvalue");
518 ANN(
"method invocation");
519 ANN(
"format: [nd_recv].[nd_mid]([nd_args])");
520 ANN(
"example: obj.foo(1)");
521 F_ID(nd_mid, RNODE_CALL,
"method id");
522 F_NODE(nd_recv, RNODE_CALL,
"receiver");
524 F_NODE(nd_args, RNODE_CALL,
"arguments");
528 ANN(
"method invocation");
529 ANN(
"format: [nd_recv] [nd_mid] [nd_args]");
530 ANN(
"example: foo + bar");
531 F_ID(nd_mid, RNODE_OPCALL,
"method id");
532 F_NODE(nd_recv, RNODE_OPCALL,
"receiver");
534 F_NODE(nd_args, RNODE_OPCALL,
"arguments");
538 ANN(
"function call");
539 ANN(
"format: [nd_mid]([nd_args])");
540 ANN(
"example: foo(1)");
541 F_ID(nd_mid, RNODE_FCALL,
"method id");
543 F_NODE(nd_args, RNODE_FCALL,
"arguments");
547 ANN(
"function call with no argument");
548 ANN(
"format: [nd_mid]");
550 F_ID(nd_mid, RNODE_VCALL,
"method id");
554 ANN(
"safe method invocation");
555 ANN(
"format: [nd_recv]&.[nd_mid]([nd_args])");
556 ANN(
"example: obj&.foo(1)");
557 F_ID(nd_mid, RNODE_QCALL,
"method id");
558 F_NODE(nd_recv, RNODE_QCALL,
"receiver");
560 F_NODE(nd_args, RNODE_QCALL,
"arguments");
564 ANN(
"super invocation");
565 ANN(
"format: super [nd_args]");
566 ANN(
"example: super 1");
568 F_NODE(nd_args, RNODE_SUPER,
"arguments");
572 ANN(
"super invocation with no argument");
573 ANN(
"format: super");
574 ANN(
"example: super");
578 ANN(
"list constructor");
579 ANN(
"format: [ [nd_head], [nd_next].. ] (length: [nd_alen])");
580 ANN(
"example: [1, 2, 3]");
581 dump_array(buf, indent, comment, node);
585 ANN(
"empty list constructor");
591 if (!RNODE_HASH(node)->nd_brace) {
592 ANN(
"keyword arguments");
593 ANN(
"format: [nd_head]");
594 ANN(
"example: a: 1, b: 2");
597 ANN(
"hash constructor");
598 ANN(
"format: { [nd_head] }");
599 ANN(
"example: { 1 => 2, 3 => 4 }");
601 F_CUSTOM1(nd_brace,
"keyword arguments or hash literal") {
602 switch (RNODE_HASH(node)->nd_brace) {
603 case 0: A(
"0 (keyword argument)");
break;
604 case 1: A(
"1 (hash literal)");
break;
608 F_NODE(nd_head, RNODE_HASH,
"contents");
612 ANN(
"yield invocation");
613 ANN(
"format: yield [nd_head]");
614 ANN(
"example: yield 1");
616 F_NODE(nd_head, RNODE_YIELD,
"arguments");
620 ANN(
"local variable reference");
621 ANN(
"format: [nd_vid](lvar)");
623 F_ID(nd_vid, RNODE_LVAR,
"local variable");
626 ANN(
"dynamic variable reference");
627 ANN(
"format: [nd_vid](dvar)");
628 ANN(
"example: 1.times { x = 1; x }");
629 F_ID(nd_vid, RNODE_DVAR,
"local variable");
632 ANN(
"instance variable reference");
633 ANN(
"format: [nd_vid](ivar)");
635 F_ID(nd_vid, RNODE_IVAR,
"instance variable");
638 ANN(
"constant reference");
639 ANN(
"format: [nd_vid](constant)");
641 F_ID(nd_vid, RNODE_CONST,
"constant");
644 ANN(
"class variable reference");
645 ANN(
"format: [nd_vid](cvar)");
647 F_ID(nd_vid, RNODE_CVAR,
"class variable");
651 ANN(
"global variable reference");
652 ANN(
"format: [nd_vid](gvar)");
654 F_ID(nd_vid, RNODE_GVAR,
"global variable");
658 ANN(
"nth special variable reference");
659 ANN(
"format: $[nd_nth]");
660 ANN(
"example: $1, $2, ..");
661 F_CUSTOM1(nd_nth,
"variable") { A(
"$"); A_LONG(RNODE_NTH_REF(node)->nd_nth); }
665 ANN(
"back special variable reference");
666 ANN(
"format: $[nd_nth]");
667 ANN(
"example: $&, $`, $', $+");
668 F_CUSTOM1(nd_nth,
"variable") {
670 name[1] = (char)RNODE_BACK_REF(node)->nd_nth;
676 ANN(
"match expression (against $_ implicitly)");
677 ANN(
"format: [nd_lit] (in condition)");
678 ANN(
"example: if /foo/; foo; end");
679 F_LIT(nd_lit, RNODE_MATCH,
"regexp");
683 ANN(
"match expression (regexp first)");
684 ANN(
"format: [nd_recv] =~ [nd_value]");
685 ANN(
"example: /foo/ =~ 'foo'");
686 F_NODE(nd_recv, RNODE_MATCH2,
"regexp (receiver)");
687 if (!RNODE_MATCH2(node)->nd_args) LAST_NODE;
688 F_NODE(nd_value, RNODE_MATCH2,
"string (argument)");
689 if (RNODE_MATCH2(node)->nd_args) {
691 F_NODE(nd_args, RNODE_MATCH2,
"named captures");
696 ANN(
"match expression (regexp second)");
697 ANN(
"format: [nd_recv] =~ [nd_value]");
698 ANN(
"example: 'foo' =~ /foo/");
699 F_NODE(nd_recv, RNODE_MATCH3,
"string (receiver)");
701 F_NODE(nd_value, RNODE_MATCH3,
"regexp (argument)");
706 ANN(
"format: [nd_lit]");
707 ANN(
"example: 1, /foo/");
710 ANN(
"string literal");
711 ANN(
"format: [nd_lit]");
712 ANN(
"example: 'foo'");
715 ANN(
"xstring literal");
716 ANN(
"format: [nd_lit]");
717 ANN(
"example: `foo`");
719 F_LIT(nd_lit, RNODE_LIT,
"literal");
723 ANN(
"once evaluation");
724 ANN(
"format: [nd_body]");
725 ANN(
"example: /foo#{ bar }baz/o");
727 F_NODE(nd_body, RNODE_ONCE,
"body");
731 ANN(
"string literal with interpolation");
732 ANN(
"format: [nd_lit]");
733 ANN(
"example: \"foo#{ bar }baz\"");
736 ANN(
"xstring literal with interpolation");
737 ANN(
"format: [nd_lit]");
738 ANN(
"example: `foo#{ bar }baz`");
741 ANN(
"regexp literal with interpolation");
742 ANN(
"format: [nd_lit]");
743 ANN(
"example: /foo#{ bar }baz/");
746 ANN(
"symbol literal with interpolation");
747 ANN(
"format: [nd_lit]");
748 ANN(
"example: :\"foo#{ bar }baz\"");
750 F_LIT(nd_lit, RNODE_DSTR,
"preceding string");
751 if (!RNODE_DSTR(node)->nd_next)
return;
752 F_NODE(nd_next->nd_head, RNODE_DSTR,
"interpolation");
754 F_NODE(nd_next->nd_next, RNODE_DSTR,
"tailing strings");
758 ANN(
"interpolation expression");
759 ANN(
"format: \"..#{ [nd_body] }..\"");
760 ANN(
"example: \"foo#{ bar }baz\"");
762 F_NODE(nd_body, RNODE_EVSTR,
"body");
766 ANN(
"splat argument following arguments");
767 ANN(
"format: ..(*[nd_head], [nd_body..])");
768 ANN(
"example: foo(*ary, post_arg1, post_arg2)");
769 F_NODE(nd_head, RNODE_ARGSCAT,
"preceding array");
771 F_NODE(nd_body, RNODE_ARGSCAT,
"following array");
775 ANN(
"splat argument following one argument");
776 ANN(
"format: ..(*[nd_head], [nd_body])");
777 ANN(
"example: foo(*ary, post_arg)");
778 F_NODE(nd_head, RNODE_ARGSPUSH,
"preceding array");
780 F_NODE(nd_body, RNODE_ARGSPUSH,
"following element");
784 ANN(
"splat argument");
785 ANN(
"format: *[nd_head]");
786 ANN(
"example: foo(*ary)");
788 F_NODE(nd_head, RNODE_SPLAT,
"splat'ed array");
791 case NODE_BLOCK_PASS:
792 ANN(
"arguments with block argument");
793 ANN(
"format: ..([nd_head], &[nd_body])");
794 ANN(
"example: foo(x, &blk)");
795 F_NODE(nd_head, RNODE_BLOCK_PASS,
"other arguments");
797 F_NODE(nd_body, RNODE_BLOCK_PASS,
"block argument");
801 ANN(
"method definition");
802 ANN(
"format: def [nd_mid] [nd_defn]; end");
803 ANN(
"example: def foo; bar; end");
804 F_ID(nd_mid, RNODE_DEFN,
"method name");
806 F_NODE(nd_defn, RNODE_DEFN,
"method definition");
810 ANN(
"singleton method definition");
811 ANN(
"format: def [nd_recv].[nd_mid] [nd_defn]; end");
812 ANN(
"example: def obj.foo; bar; end");
813 F_NODE(nd_recv, RNODE_DEFS,
"receiver");
814 F_ID(nd_mid, RNODE_DEFS,
"method name");
816 F_NODE(nd_defn, RNODE_DEFS,
"method definition");
820 ANN(
"method alias statement");
821 ANN(
"format: alias [nd_1st] [nd_2nd]");
822 ANN(
"example: alias bar foo");
823 F_NODE(nd_1st, RNODE_ALIAS,
"new name");
825 F_NODE(nd_2nd, RNODE_ALIAS,
"old name");
829 ANN(
"global variable alias statement");
830 ANN(
"format: alias [nd_alias](gvar) [nd_orig](gvar)");
831 ANN(
"example: alias $y $x");
832 F_ID(nd_alias, RNODE_VALIAS,
"new name");
833 F_ID(nd_orig, RNODE_VALIAS,
"old name");
837 ANN(
"method undef statement");
838 ANN(
"format: undef [nd_undef]");
839 ANN(
"example: undef foo");
841 F_NODE(nd_undef, RNODE_UNDEF,
"old name");
845 ANN(
"class definition");
846 ANN(
"format: class [nd_cpath] < [nd_super]; [nd_body]; end");
847 ANN(
"example: class C2 < C; ..; end");
848 F_NODE(nd_cpath, RNODE_CLASS,
"class path");
849 F_NODE(nd_super, RNODE_CLASS,
"superclass");
851 F_NODE(nd_body, RNODE_CLASS,
"class definition");
855 ANN(
"module definition");
856 ANN(
"format: module [nd_cpath]; [nd_body]; end");
857 ANN(
"example: module M; ..; end");
858 F_NODE(nd_cpath, RNODE_MODULE,
"module path");
860 F_NODE(nd_body, RNODE_MODULE,
"module definition");
864 ANN(
"singleton class definition");
865 ANN(
"format: class << [nd_recv]; [nd_body]; end");
866 ANN(
"example: class << obj; ..; end");
867 F_NODE(nd_recv, RNODE_SCLASS,
"receiver");
869 F_NODE(nd_body, RNODE_SCLASS,
"singleton class definition");
873 ANN(
"scoped constant reference");
874 ANN(
"format: [nd_head]::[nd_mid]");
875 ANN(
"example: M::C");
876 F_ID(nd_mid, RNODE_COLON2,
"constant name");
878 F_NODE(nd_head, RNODE_COLON2,
"receiver");
882 ANN(
"top-level constant reference");
883 ANN(
"format: ::[nd_mid]");
884 ANN(
"example: ::Object");
885 F_ID(nd_mid, RNODE_COLON3,
"constant name");
889 ANN(
"range constructor (incl.)");
890 ANN(
"format: [nd_beg]..[nd_end]");
891 ANN(
"example: 1..5");
894 ANN(
"range constructor (excl.)");
895 ANN(
"format: [nd_beg]...[nd_end]");
896 ANN(
"example: 1...5");
899 ANN(
"flip-flop condition (incl.)");
900 ANN(
"format: [nd_beg]..[nd_end]");
901 ANN(
"example: if (x==1)..(x==5); foo; end");
904 ANN(
"flip-flop condition (excl.)");
905 ANN(
"format: [nd_beg]...[nd_end]");
906 ANN(
"example: if (x==1)...(x==5); foo; end");
908 F_NODE(nd_beg, RNODE_DOT2,
"begin");
910 F_NODE(nd_end, RNODE_DOT2,
"end");
916 ANN(
"example: self");
928 ANN(
"example: true");
933 ANN(
"format: false");
934 ANN(
"example: false");
938 ANN(
"virtual reference to $!");
939 ANN(
"format: rescue => id");
940 ANN(
"example: rescue => id");
944 ANN(
"defined? expression");
945 ANN(
"format: defined?([nd_head])");
946 ANN(
"example: defined?(foo)");
947 F_NODE(nd_head, RNODE_DEFINED,
"expr");
951 ANN(
"post-execution");
952 ANN(
"format: END { [nd_body] }");
953 ANN(
"example: END { foo }");
955 F_NODE(nd_body, RNODE_POSTEXE,
"END clause");
959 ANN(
"attr assignment");
960 ANN(
"format: [nd_recv].[nd_mid] = [nd_args]");
961 ANN(
"example: struct.field = foo");
962 F_NODE(nd_recv, RNODE_ATTRASGN,
"receiver");
963 F_ID(nd_mid, RNODE_ATTRASGN,
"method name");
965 F_NODE(nd_args, RNODE_ATTRASGN,
"arguments");
969 ANN(
"lambda expression");
970 ANN(
"format: -> [nd_body]");
971 ANN(
"example: -> { foo }");
973 F_NODE(nd_body, RNODE_LAMBDA,
"lambda clause");
977 ANN(
"optional arguments");
978 ANN(
"format: def method_name([nd_body=some], [nd_next..])");
979 ANN(
"example: def foo(a, b=1, c); end");
980 F_NODE(nd_body, RNODE_OPT_ARG,
"body");
982 F_NODE(nd_next, RNODE_OPT_ARG,
"next");
986 ANN(
"keyword arguments");
987 ANN(
"format: def method_name([nd_body=some], [nd_next..])");
988 ANN(
"example: def foo(a:1, b:2); end");
989 F_NODE(nd_body, RNODE_KW_ARG,
"body");
991 F_NODE(nd_next, RNODE_KW_ARG,
"next");
995 ANN(
"post arguments");
996 ANN(
"format: *[nd_1st], [nd_2nd..] = ..");
997 ANN(
"example: a, *rest, z = foo");
998 if (NODE_NAMED_REST_P(RNODE_POSTARG(node)->nd_1st)) {
999 F_NODE(nd_1st, RNODE_POSTARG,
"rest argument");
1002 F_MSG(nd_1st,
"rest argument",
"NODE_SPECIAL_NO_NAME_REST (rest argument without name)");
1005 F_NODE(nd_2nd, RNODE_POSTARG,
"post arguments");
1009 ANN(
"method parameters");
1010 ANN(
"format: def method_name(.., [nd_ainfo.nd_optargs], *[nd_ainfo.rest_arg], [nd_ainfo.first_post_arg], .., [nd_ainfo.kw_args], **[nd_ainfo.kw_rest_arg], &[nd_ainfo.block_arg])");
1011 ANN(
"example: def foo(a, b, opt1=1, opt2=2, *rest, y, z, kw: 1, **kwrest, &blk); end");
1012 F_INT(nd_ainfo.pre_args_num, RNODE_ARGS,
"count of mandatory (pre-)arguments");
1013 F_NODE(nd_ainfo.pre_init, RNODE_ARGS,
"initialization of (pre-)arguments");
1014 F_INT(nd_ainfo.post_args_num, RNODE_ARGS,
"count of mandatory post-arguments");
1015 F_NODE(nd_ainfo.post_init, RNODE_ARGS,
"initialization of post-arguments");
1016 F_ID(nd_ainfo.first_post_arg, RNODE_ARGS,
"first post argument");
1017 F_CUSTOM1(nd_ainfo.rest_arg,
"rest argument") {
1018 if (RNODE_ARGS(node)->nd_ainfo.rest_arg == NODE_SPECIAL_EXCESSIVE_COMMA) {
1019 A(
"1 (excessed comma)");
1022 A_ID(RNODE_ARGS(node)->nd_ainfo.rest_arg);
1025 F_ID(nd_ainfo.block_arg, RNODE_ARGS,
"block argument");
1026 F_NODE(nd_ainfo.opt_args, RNODE_ARGS,
"optional arguments");
1027 F_NODE(nd_ainfo.kw_args, RNODE_ARGS,
"keyword arguments");
1029 F_NODE(nd_ainfo.kw_rest_arg, RNODE_ARGS,
"keyword rest argument");
1034 ANN(
"format: [nd_tbl]: local table, [nd_args]: arguments, [nd_body]: body");
1035 F_CUSTOM1(nd_tbl,
"local table") {
1036 rb_ast_id_table_t *tbl = RNODE_SCOPE(node)->nd_tbl;
1038 int size = tbl ? tbl->size : 0;
1039 if (size == 0) A(
"(empty)");
1040 for (i = 0; i < size; i++) {
1041 A_ID(tbl->ids[i]);
if (i < size - 1) A(
",");
1044 F_NODE(nd_args, RNODE_SCOPE,
"arguments");
1046 F_NODE(nd_body, RNODE_SCOPE,
"body");
1050 ANN(
"array pattern");
1051 ANN(
"format: [nd_pconst]([pre_args], ..., *[rest_arg], [post_args], ...)");
1052 F_NODE(nd_pconst, RNODE_ARYPTN,
"constant");
1053 F_NODE(pre_args, RNODE_ARYPTN,
"pre arguments");
1054 if (NODE_NAMED_REST_P(RNODE_ARYPTN(node)->rest_arg)) {
1055 F_NODE(rest_arg, RNODE_ARYPTN,
"rest argument");
1058 F_MSG(rest_arg,
"rest argument",
"NODE_SPECIAL_NO_NAME_REST (rest argument without name)");
1061 F_NODE(post_args, RNODE_ARYPTN,
"post arguments");
1065 ANN(
"find pattern");
1066 ANN(
"format: [nd_pconst](*[pre_rest_arg], args, ..., *[post_rest_arg])");
1067 F_NODE(nd_pconst, RNODE_FNDPTN,
"constant");
1068 if (NODE_NAMED_REST_P(RNODE_FNDPTN(node)->pre_rest_arg)) {
1069 F_NODE(pre_rest_arg, RNODE_FNDPTN,
"pre rest argument");
1072 F_MSG(pre_rest_arg,
"pre rest argument",
"NODE_SPECIAL_NO_NAME_REST (rest argument without name)");
1074 F_NODE(args, RNODE_FNDPTN,
"arguments");
1077 if (NODE_NAMED_REST_P(RNODE_FNDPTN(node)->post_rest_arg)) {
1078 F_NODE(post_rest_arg, RNODE_FNDPTN,
"post rest argument");
1081 F_MSG(post_rest_arg,
"post rest argument",
"NODE_SPECIAL_NO_NAME_REST (rest argument without name)");
1086 ANN(
"hash pattern");
1087 ANN(
"format: [nd_pconst]([nd_pkwargs], ..., **[nd_pkwrestarg])");
1088 F_NODE(nd_pconst, RNODE_HSHPTN,
"constant");
1089 F_NODE(nd_pkwargs, RNODE_HSHPTN,
"keyword arguments");
1091 if (RNODE_HSHPTN(node)->nd_pkwrestarg == NODE_SPECIAL_NO_REST_KEYWORD) {
1092 F_MSG(nd_pkwrestarg,
"keyword rest argument",
"NODE_SPECIAL_NO_REST_KEYWORD (**nil)");
1095 F_NODE(nd_pkwrestarg, RNODE_HSHPTN,
"keyword rest argument");
1099 ANN(
"Broken input recovered by Error Tolerant mode");
1104 case NODE_RIPPER_VALUES:
1109 rb_bug(
"dump_node: unknown node: %s", ruby_node_name(nd_type(node)));
1113rb_parser_dump_tree(
const NODE *node,
int comment)
1116 "###########################################################\n"
1117 "## Do NOT use this node dump for any purpose other than ##\n"
1118 "## debug and research. Compatibility is not guaranteed. ##\n"
1119 "###########################################################\n\n"
#define FL_SINGLETON
Old name of RUBY_FL_SINGLETON.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define T_CLASS
Old name of RUBY_T_CLASS.
#define FL_TEST
Old name of RB_FL_TEST.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
VALUE rb_class_path(VALUE mod)
Identical to rb_mod_name(), except it returns #<Class: ...> style inspection for anonymous modules.
VALUE type(ANYARGS)
ANYARGS-ed function type.
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static enum ruby_value_type RB_BUILTIN_TYPE(VALUE obj)
Queries the type of the object.