newobj_of(): Use parameter instead of GET_RACTOR()
[ruby.git] / node_dump.c
blob5656f1d812c5a93d11d201e36dcc203b743b048b
1 /**********************************************************************
3 node_dump.c - dump ruby node tree
5 $Author: mame $
6 created at: 09/12/06 21:23:44 JST
8 Copyright (C) 2009 Yusuke Endoh
10 **********************************************************************/
12 #include "internal.h"
13 #include "internal/class.h"
14 #include "internal/hash.h"
15 #include "internal/ruby_parser.h"
16 #include "internal/variable.h"
17 #include "ruby/ruby.h"
18 #include "vm_core.h"
20 #define A(str) rb_str_cat2(buf, (str))
21 #define AR(str) rb_str_concat(buf, (str))
23 #define A_INDENT add_indent(buf, indent)
24 #define D_INDENT rb_str_cat2(indent, next_indent)
25 #define D_DEDENT rb_str_resize(indent, RSTRING_LEN(indent) - 4)
26 #define A_ID(id) add_id(buf, (id))
27 #define A_INT(val) rb_str_catf(buf, "%d", (val))
28 #define A_LONG(val) rb_str_catf(buf, "%ld", (val))
29 #define A_LIT(lit) AR(rb_dump_literal(lit))
30 #define A_NODE_HEADER(node, term) \
31 rb_str_catf(buf, "@ %s (id: %d, line: %d, location: (%d,%d)-(%d,%d))%s"term, \
32 ruby_node_name(nd_type(node)), nd_node_id(node), nd_line(node), \
33 nd_first_lineno(node), nd_first_column(node), \
34 nd_last_lineno(node), nd_last_column(node), \
35 (nd_fl_newline(node) ? "*" : ""))
36 #define A_FIELD_HEADER(len, name, term) \
37 rb_str_catf(buf, "+- %.*s:"term, (len), (name))
38 #define D_FIELD_HEADER(len, name, term) (A_INDENT, A_FIELD_HEADER(len, name, term))
40 #define D_NULL_NODE (A_INDENT, A("(null node)\n"))
41 #define D_NODE_HEADER(node) (A_INDENT, A_NODE_HEADER(node, "\n"))
43 #define COMPOUND_FIELD(len, name) \
44 FIELD_BLOCK((D_FIELD_HEADER((len), (name), "\n"), D_INDENT), D_DEDENT)
46 #define COMPOUND_FIELD1(name, ann) \
47 COMPOUND_FIELD(FIELD_NAME_LEN(name, ann), \
48 FIELD_NAME_DESC(name, ann))
50 #define FIELD_NAME_DESC(name, ann) name " (" ann ")"
51 #define FIELD_NAME_LEN(name, ann) (int)( \
52 comment ? \
53 rb_strlen_lit(FIELD_NAME_DESC(name, ann)) : \
54 rb_strlen_lit(name))
55 #define SIMPLE_FIELD(len, name) \
56 FIELD_BLOCK(D_FIELD_HEADER((len), (name), " "), A("\n"))
58 #define FIELD_BLOCK(init, reset) \
59 for (init, field_flag = 1; \
60 field_flag; /* should be optimized away */ \
61 reset, field_flag = 0)
63 #define A_SHAREABILITY(shareability) \
64 switch (shareability) { \
65 case rb_parser_shareable_none: \
66 rb_str_cat_cstr(buf, "none"); \
67 break; \
68 case rb_parser_shareable_literal: \
69 rb_str_cat_cstr(buf, "literal"); \
70 break; \
71 case rb_parser_shareable_copy: \
72 rb_str_cat_cstr(buf, "experimental_copy"); \
73 break; \
74 case rb_parser_shareable_everything: \
75 rb_str_cat_cstr(buf, "experimental_everything"); \
76 break; \
79 #define SIMPLE_FIELD1(name, ann) SIMPLE_FIELD(FIELD_NAME_LEN(name, ann), FIELD_NAME_DESC(name, ann))
80 #define F_CUSTOM1(name, ann) SIMPLE_FIELD1(#name, ann)
81 #define F_ID(name, type, ann) SIMPLE_FIELD1(#name, ann) A_ID(type(node)->name)
82 #define F_INT(name, type, ann) SIMPLE_FIELD1(#name, ann) A_INT(type(node)->name)
83 #define F_LONG(name, type, ann) SIMPLE_FIELD1(#name, ann) A_LONG(type(node)->name)
84 #define F_LIT(name, type, ann) SIMPLE_FIELD1(#name, ann) A_LIT(type(node)->name)
85 #define F_VALUE(name, val, ann) SIMPLE_FIELD1(#name, ann) A_LIT(val)
86 #define F_MSG(name, ann, desc) SIMPLE_FIELD1(#name, ann) A(desc)
87 #define F_SHAREABILITY(name, type, ann) SIMPLE_FIELD1(#name, ann) A_SHAREABILITY(type(node)->name)
89 #define F_NODE(name, type, ann) \
90 COMPOUND_FIELD1(#name, ann) {dump_node(buf, indent, comment, RNODE(type(node)->name));}
92 #define F_NODE2(name, n, ann) \
93 COMPOUND_FIELD1(#name, ann) {dump_node(buf, indent, comment, n);}
95 #define F_ARRAY(name, type, ann) \
96 COMPOUND_FIELD1(#name, ann) {dump_parser_array(buf, indent, comment, type(node)->name);}
98 #define ANN(ann) \
99 if (comment) { \
100 A_INDENT; A("| # " ann "\n"); \
103 #define LAST_NODE (next_indent = " ")
105 VALUE
106 rb_dump_literal(VALUE lit)
108 if (!RB_SPECIAL_CONST_P(lit)) {
109 VALUE str;
110 switch (RB_BUILTIN_TYPE(lit)) {
111 case T_CLASS: case T_MODULE: case T_ICLASS:
112 str = rb_class_path(lit);
113 if (RCLASS_SINGLETON_P(lit)) {
114 str = rb_sprintf("<%"PRIsVALUE">", str);
116 return str;
117 default:
118 break;
121 return rb_inspect(lit);
124 static void
125 add_indent(VALUE buf, VALUE indent)
127 AR(indent);
130 static void
131 add_id(VALUE buf, ID id)
133 if (id == 0) {
134 A("(null)");
136 else {
137 VALUE str = rb_id2str(id);
138 if (str) {
139 A(":"); AR(str);
141 else {
142 rb_str_catf(buf, "(internal variable: 0x%"PRIsVALUE")", id);
147 struct add_option_arg {
148 VALUE buf, indent;
149 st_index_t count;
152 static void dump_node(VALUE, VALUE, int, const NODE *);
153 static const char default_indent[] = "| ";
155 static void
156 dump_array(VALUE buf, VALUE indent, int comment, const NODE *node)
158 int field_flag;
159 const char *next_indent = default_indent;
160 F_LONG(as.nd_alen, RNODE_LIST, "length");
161 F_NODE(nd_head, RNODE_LIST, "element");
162 while (RNODE_LIST(node)->nd_next && nd_type_p(RNODE_LIST(node)->nd_next, NODE_LIST)) {
163 node = RNODE_LIST(node)->nd_next;
164 F_NODE(nd_head, RNODE_LIST, "element");
166 LAST_NODE;
167 F_NODE(nd_next, RNODE_LIST, "next element");
170 static void
171 dump_parser_array(VALUE buf, VALUE indent, int comment, const rb_parser_ary_t *ary)
173 int field_flag;
174 const char *next_indent = default_indent;
176 if (ary->data_type != PARSER_ARY_DATA_NODE) {
177 rb_bug("unexpected rb_parser_ary_data_type: %d", ary->data_type);
180 F_CUSTOM1(length, "length") { A_LONG(ary->len); }
181 for (long i = 0; i < ary->len; i++) {
182 if (i == ary->len - 1) LAST_NODE;
183 A_INDENT;
184 rb_str_catf(buf, "+- element (%s%ld):\n",
185 comment ? "statement #" : "", i);
186 D_INDENT;
187 dump_node(buf, indent, comment, ary->data[i]);
188 D_DEDENT;
192 static void
193 dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
195 int field_flag;
196 int i;
197 const char *next_indent = default_indent;
198 enum node_type type;
200 if (!node) {
201 D_NULL_NODE;
202 return;
205 D_NODE_HEADER(node);
207 type = nd_type(node);
208 switch (type) {
209 case NODE_BLOCK:
210 ANN("statement sequence");
211 ANN("format: [nd_head]; ...; [nd_next]");
212 ANN("example: foo; bar");
213 i = 0;
214 do {
215 A_INDENT;
216 rb_str_catf(buf, "+- nd_head (%s%d):\n",
217 comment ? "statement #" : "", ++i);
218 if (!RNODE_BLOCK(node)->nd_next) LAST_NODE;
219 D_INDENT;
220 dump_node(buf, indent, comment, RNODE_BLOCK(node)->nd_head);
221 D_DEDENT;
222 } while (RNODE_BLOCK(node)->nd_next &&
223 nd_type_p(RNODE_BLOCK(node)->nd_next, NODE_BLOCK) &&
224 (node = RNODE_BLOCK(node)->nd_next, 1));
225 if (RNODE_BLOCK(node)->nd_next) {
226 LAST_NODE;
227 F_NODE(nd_next, RNODE_BLOCK, "next block");
229 return;
231 case NODE_IF:
232 ANN("if statement");
233 ANN("format: if [nd_cond] then [nd_body] else [nd_else] end");
234 ANN("example: if x == 1 then foo else bar end");
235 F_NODE(nd_cond, RNODE_IF, "condition expr");
236 F_NODE(nd_body, RNODE_IF, "then clause");
237 LAST_NODE;
238 F_NODE(nd_else, RNODE_IF, "else clause");
239 return;
241 case NODE_UNLESS:
242 ANN("unless statement");
243 ANN("format: unless [nd_cond] then [nd_body] else [nd_else] end");
244 ANN("example: unless x == 1 then foo else bar end");
245 F_NODE(nd_cond, RNODE_UNLESS, "condition expr");
246 F_NODE(nd_body, RNODE_UNLESS, "then clause");
247 LAST_NODE;
248 F_NODE(nd_else, RNODE_UNLESS, "else clause");
249 return;
251 case NODE_CASE:
252 ANN("case statement");
253 ANN("format: case [nd_head]; [nd_body]; end");
254 ANN("example: case x; when 1; foo; when 2; bar; else baz; end");
255 F_NODE(nd_head, RNODE_CASE, "case expr");
256 LAST_NODE;
257 F_NODE(nd_body, RNODE_CASE, "when clauses");
258 return;
259 case NODE_CASE2:
260 ANN("case statement with no head");
261 ANN("format: case; [nd_body]; end");
262 ANN("example: case; when 1; foo; when 2; bar; else baz; end");
263 F_NODE(nd_head, RNODE_CASE2, "case expr");
264 LAST_NODE;
265 F_NODE(nd_body, RNODE_CASE2, "when clauses");
266 return;
267 case NODE_CASE3:
268 ANN("case statement (pattern matching)");
269 ANN("format: case [nd_head]; [nd_body]; end");
270 ANN("example: case x; in 1; foo; in 2; bar; else baz; end");
271 F_NODE(nd_head, RNODE_CASE3, "case expr");
272 LAST_NODE;
273 F_NODE(nd_body, RNODE_CASE3, "in clauses");
274 return;
276 case NODE_WHEN:
277 ANN("when clause");
278 ANN("format: when [nd_head]; [nd_body]; (when or else) [nd_next]");
279 ANN("example: case x; when 1; foo; when 2; bar; else baz; end");
280 F_NODE(nd_head, RNODE_WHEN, "when value");
281 F_NODE(nd_body, RNODE_WHEN, "when body");
282 LAST_NODE;
283 F_NODE(nd_next, RNODE_WHEN, "next when clause");
284 return;
286 case NODE_IN:
287 ANN("in clause");
288 ANN("format: in [nd_head]; [nd_body]; (in or else) [nd_next]");
289 ANN("example: case x; in 1; foo; in 2; bar; else baz; end");
290 F_NODE(nd_head, RNODE_IN, "in pattern");
291 F_NODE(nd_body, RNODE_IN, "in body");
292 LAST_NODE;
293 F_NODE(nd_next, RNODE_IN, "next in clause");
294 return;
296 case NODE_WHILE:
297 ANN("while statement");
298 ANN("format: while [nd_cond]; [nd_body]; end");
299 ANN("example: while x == 1; foo; end");
300 goto loop;
301 case NODE_UNTIL:
302 ANN("until statement");
303 ANN("format: until [nd_cond]; [nd_body]; end");
304 ANN("example: until x == 1; foo; end");
305 loop:
306 F_CUSTOM1(nd_state, "begin-end-while?") {
307 A_INT((int)RNODE_WHILE(node)->nd_state);
308 A((RNODE_WHILE(node)->nd_state == 1) ? " (while-end)" : " (begin-end-while)");
310 F_NODE(nd_cond, RNODE_WHILE, "condition");
311 LAST_NODE;
312 F_NODE(nd_body, RNODE_WHILE, "body");
313 return;
315 case NODE_ITER:
316 ANN("method call with block");
317 ANN("format: [nd_iter] { [nd_body] }");
318 ANN("example: 3.times { foo }");
319 goto iter;
320 case NODE_FOR:
321 ANN("for statement");
322 ANN("format: for * in [nd_iter] do [nd_body] end");
323 ANN("example: for i in 1..3 do foo end");
324 iter:
325 F_NODE(nd_iter, RNODE_ITER, "iteration receiver");
326 LAST_NODE;
327 F_NODE(nd_body, RNODE_ITER, "body");
328 return;
330 case NODE_FOR_MASGN:
331 ANN("vars of for statement with masgn");
332 ANN("format: for [nd_var] in ... do ... end");
333 ANN("example: for x, y in 1..3 do foo end");
334 LAST_NODE;
335 F_NODE(nd_var, RNODE_FOR_MASGN, "var");
336 return;
338 case NODE_BREAK:
339 ANN("break statement");
340 ANN("format: break [nd_stts]");
341 ANN("example: break 1");
342 LAST_NODE;
343 F_NODE(nd_stts, RNODE_BREAK, "value");
344 return;
345 case NODE_NEXT:
346 ANN("next statement");
347 ANN("format: next [nd_stts]");
348 ANN("example: next 1");
349 LAST_NODE;
350 F_NODE(nd_stts, RNODE_NEXT, "value");
351 return;
352 case NODE_RETURN:
353 ANN("return statement");
354 ANN("format: return [nd_stts]");
355 ANN("example: return 1");
356 LAST_NODE;
357 F_NODE(nd_stts, RNODE_RETURN, "value");
358 return;
360 case NODE_REDO:
361 ANN("redo statement");
362 ANN("format: redo");
363 ANN("example: redo");
364 return;
366 case NODE_RETRY:
367 ANN("retry statement");
368 ANN("format: retry");
369 ANN("example: retry");
370 return;
372 case NODE_BEGIN:
373 ANN("begin statement");
374 ANN("format: begin; [nd_body]; end");
375 ANN("example: begin; 1; end");
376 LAST_NODE;
377 F_NODE(nd_body, RNODE_BEGIN, "body");
378 return;
380 case NODE_RESCUE:
381 ANN("rescue clause");
382 ANN("format: begin; [nd_body]; (rescue) [nd_resq]; else [nd_else]; end");
383 ANN("example: begin; foo; rescue; bar; else; baz; end");
384 F_NODE(nd_head, RNODE_RESCUE, "body");
385 F_NODE(nd_resq, RNODE_RESCUE, "rescue clause list");
386 LAST_NODE;
387 F_NODE(nd_else, RNODE_RESCUE, "rescue else clause");
388 return;
390 case NODE_RESBODY:
391 ANN("rescue clause (cont'd)");
392 ANN("format: rescue [nd_args]; [nd_body]; (rescue) [nd_head]");
393 ANN("example: begin; foo; rescue; bar; else; baz; end");
394 F_NODE(nd_args, RNODE_RESBODY, "rescue exceptions");
395 F_NODE(nd_body, RNODE_RESBODY, "rescue clause");
396 LAST_NODE;
397 F_NODE(nd_next, RNODE_RESBODY, "next rescue clause");
398 return;
400 case NODE_ENSURE:
401 ANN("ensure clause");
402 ANN("format: begin; [nd_head]; ensure; [nd_ensr]; end");
403 ANN("example: begin; foo; ensure; bar; end");
404 F_NODE(nd_head, RNODE_ENSURE, "body");
405 LAST_NODE;
406 F_NODE(nd_ensr, RNODE_ENSURE, "ensure clause");
407 return;
409 case NODE_AND:
410 ANN("&& operator");
411 ANN("format: [nd_1st] && [nd_2nd]");
412 ANN("example: foo && bar");
413 goto andor;
414 case NODE_OR:
415 ANN("|| operator");
416 ANN("format: [nd_1st] || [nd_2nd]");
417 ANN("example: foo || bar");
418 andor:
419 while (1) {
420 F_NODE(nd_1st, RNODE_AND, "left expr");
421 if (!RNODE_AND(node)->nd_2nd || !nd_type_p(RNODE_AND(node)->nd_2nd, type))
422 break;
423 node = RNODE_AND(node)->nd_2nd;
425 LAST_NODE;
426 F_NODE(nd_2nd, RNODE_AND, "right expr");
427 return;
429 case NODE_MASGN:
430 ANN("multiple assignment");
431 ANN("format: [nd_head], [nd_args] = [nd_value]");
432 ANN("example: a, b = foo");
433 F_NODE(nd_value, RNODE_MASGN, "rhsn");
434 F_NODE(nd_head, RNODE_MASGN, "lhsn");
435 if (NODE_NAMED_REST_P(RNODE_MASGN(node)->nd_args)) {
436 LAST_NODE;
437 F_NODE(nd_args, RNODE_MASGN, "splatn");
439 else {
440 F_MSG(nd_args, "splatn", "NODE_SPECIAL_NO_NAME_REST (rest argument without name)");
442 return;
444 case NODE_LASGN:
445 ANN("local variable assignment");
446 ANN("format: [nd_vid](lvar) = [nd_value]");
447 ANN("example: x = foo");
448 F_ID(nd_vid, RNODE_LASGN, "local variable");
449 if (NODE_REQUIRED_KEYWORD_P(RNODE_LASGN(node)->nd_value)) {
450 F_MSG(nd_value, "rvalue", "NODE_SPECIAL_REQUIRED_KEYWORD (required keyword argument)");
452 else {
453 LAST_NODE;
454 F_NODE(nd_value, RNODE_LASGN, "rvalue");
456 return;
457 case NODE_DASGN:
458 ANN("dynamic variable assignment");
459 ANN("format: [nd_vid](dvar) = [nd_value]");
460 ANN("example: x = nil; 1.times { x = foo }");
461 ANN("example: 1.times { x = foo }");
462 F_ID(nd_vid, RNODE_DASGN, "local variable");
463 if (NODE_REQUIRED_KEYWORD_P(RNODE_DASGN(node)->nd_value)) {
464 F_MSG(nd_value, "rvalue", "NODE_SPECIAL_REQUIRED_KEYWORD (required keyword argument)");
466 else {
467 LAST_NODE;
468 F_NODE(nd_value, RNODE_DASGN, "rvalue");
470 return;
471 case NODE_IASGN:
472 ANN("instance variable assignment");
473 ANN("format: [nd_vid](ivar) = [nd_value]");
474 ANN("example: @x = foo");
475 F_ID(nd_vid, RNODE_IASGN, "instance variable");
476 LAST_NODE;
477 F_NODE(nd_value, RNODE_IASGN, "rvalue");
478 return;
479 case NODE_CVASGN:
480 ANN("class variable assignment");
481 ANN("format: [nd_vid](cvar) = [nd_value]");
482 ANN("example: @@x = foo");
483 F_ID(nd_vid, RNODE_CVASGN, "class variable");
484 LAST_NODE;
485 F_NODE(nd_value, RNODE_CVASGN, "rvalue");
486 return;
487 case NODE_GASGN:
488 ANN("global variable assignment");
489 ANN("format: [nd_vid](gvar) = [nd_value]");
490 ANN("example: $x = foo");
491 F_ID(nd_vid, RNODE_GASGN, "global variable");
492 LAST_NODE;
493 F_NODE(nd_value, RNODE_GASGN, "rvalue");
494 return;
496 case NODE_CDECL:
497 ANN("constant declaration");
498 ANN("format: [nd_else]::[nd_vid](constant) = [nd_value]");
499 ANN("example: X = foo");
500 if (RNODE_CDECL(node)->nd_vid) {
501 F_ID(nd_vid, RNODE_CDECL, "constant");
502 F_MSG(nd_else, "extension", "not used");
504 else {
505 F_MSG(nd_vid, "constant", "0 (see extension field)");
506 F_NODE(nd_else, RNODE_CDECL, "extension");
508 F_SHAREABILITY(shareability, RNODE_CDECL, "shareability");
509 LAST_NODE;
510 F_NODE(nd_value, RNODE_CDECL, "rvalue");
511 return;
513 case NODE_OP_ASGN1:
514 ANN("array assignment with operator");
515 ANN("format: [nd_recv] [ [nd_index] ] [nd_mid]= [nd_rvalue]");
516 ANN("example: ary[1] += foo");
517 F_NODE(nd_recv, RNODE_OP_ASGN1, "receiver");
518 F_ID(nd_mid, RNODE_OP_ASGN1, "operator");
519 F_NODE(nd_index, RNODE_OP_ASGN1, "index");
520 LAST_NODE;
521 F_NODE(nd_rvalue, RNODE_OP_ASGN1, "rvalue");
522 return;
524 case NODE_OP_ASGN2:
525 ANN("attr assignment with operator");
526 ANN("format: [nd_recv].[nd_vid] [nd_mid]= [nd_value]");
527 ANN("example: struct.field += foo");
528 F_NODE(nd_recv, RNODE_OP_ASGN2, "receiver");
529 F_CUSTOM1(nd_vid, "attr") {
530 if (RNODE_OP_ASGN2(node)->nd_aid) A("? ");
531 A_ID(RNODE_OP_ASGN2(node)->nd_vid);
533 F_ID(nd_mid, RNODE_OP_ASGN2, "operator");
534 LAST_NODE;
535 F_NODE(nd_value, RNODE_OP_ASGN2, "rvalue");
536 return;
538 case NODE_OP_ASGN_AND:
539 ANN("assignment with && operator");
540 ANN("format: [nd_head] &&= [nd_value]");
541 ANN("example: foo &&= bar");
542 goto asgn_andor;
543 case NODE_OP_ASGN_OR:
544 ANN("assignment with || operator");
545 ANN("format: [nd_head] ||= [nd_value]");
546 ANN("example: foo ||= bar");
547 asgn_andor:
548 F_NODE(nd_head, RNODE_OP_ASGN_AND, "variable");
549 LAST_NODE;
550 F_NODE(nd_value, RNODE_OP_ASGN_AND, "rvalue");
551 return;
553 case NODE_OP_CDECL:
554 ANN("constant declaration with operator");
555 ANN("format: [nd_head](constant) [nd_aid]= [nd_value]");
556 ANN("example: A::B ||= 1");
557 F_NODE(nd_head, RNODE_OP_CDECL, "constant");
558 F_ID(nd_aid, RNODE_OP_CDECL, "operator");
559 F_SHAREABILITY(shareability, RNODE_OP_CDECL, "shareability");
560 LAST_NODE;
561 F_NODE(nd_value, RNODE_OP_CDECL, "rvalue");
562 return;
564 case NODE_CALL:
565 ANN("method invocation");
566 ANN("format: [nd_recv].[nd_mid]([nd_args])");
567 ANN("example: obj.foo(1)");
568 F_ID(nd_mid, RNODE_CALL, "method id");
569 F_NODE(nd_recv, RNODE_CALL, "receiver");
570 LAST_NODE;
571 F_NODE(nd_args, RNODE_CALL, "arguments");
572 return;
574 case NODE_OPCALL:
575 ANN("method invocation");
576 ANN("format: [nd_recv] [nd_mid] [nd_args]");
577 ANN("example: foo + bar");
578 F_ID(nd_mid, RNODE_OPCALL, "method id");
579 F_NODE(nd_recv, RNODE_OPCALL, "receiver");
580 LAST_NODE;
581 F_NODE(nd_args, RNODE_OPCALL, "arguments");
582 return;
584 case NODE_FCALL:
585 ANN("function call");
586 ANN("format: [nd_mid]([nd_args])");
587 ANN("example: foo(1)");
588 F_ID(nd_mid, RNODE_FCALL, "method id");
589 LAST_NODE;
590 F_NODE(nd_args, RNODE_FCALL, "arguments");
591 return;
593 case NODE_VCALL:
594 ANN("function call with no argument");
595 ANN("format: [nd_mid]");
596 ANN("example: foo");
597 F_ID(nd_mid, RNODE_VCALL, "method id");
598 return;
600 case NODE_QCALL:
601 ANN("safe method invocation");
602 ANN("format: [nd_recv]&.[nd_mid]([nd_args])");
603 ANN("example: obj&.foo(1)");
604 F_ID(nd_mid, RNODE_QCALL, "method id");
605 F_NODE(nd_recv, RNODE_QCALL, "receiver");
606 LAST_NODE;
607 F_NODE(nd_args, RNODE_QCALL, "arguments");
608 return;
610 case NODE_SUPER:
611 ANN("super invocation");
612 ANN("format: super [nd_args]");
613 ANN("example: super 1");
614 LAST_NODE;
615 F_NODE(nd_args, RNODE_SUPER, "arguments");
616 return;
618 case NODE_ZSUPER:
619 ANN("super invocation with no argument");
620 ANN("format: super");
621 ANN("example: super");
622 return;
624 case NODE_LIST:
625 ANN("list constructor");
626 ANN("format: [ [nd_head], [nd_next].. ] (length: [nd_alen])");
627 ANN("example: [1, 2, 3]");
628 dump_array(buf, indent, comment, node);
629 return;
631 case NODE_ZLIST:
632 ANN("empty list constructor");
633 ANN("format: []");
634 ANN("example: []");
635 return;
637 case NODE_HASH:
638 if (!RNODE_HASH(node)->nd_brace) {
639 ANN("keyword arguments");
640 ANN("format: [nd_head]");
641 ANN("example: a: 1, b: 2");
643 else {
644 ANN("hash constructor");
645 ANN("format: { [nd_head] }");
646 ANN("example: { 1 => 2, 3 => 4 }");
648 F_CUSTOM1(nd_brace, "keyword arguments or hash literal") {
649 switch (RNODE_HASH(node)->nd_brace) {
650 case 0: A("0 (keyword argument)"); break;
651 case 1: A("1 (hash literal)"); break;
654 LAST_NODE;
655 F_NODE(nd_head, RNODE_HASH, "contents");
656 return;
658 case NODE_YIELD:
659 ANN("yield invocation");
660 ANN("format: yield [nd_head]");
661 ANN("example: yield 1");
662 LAST_NODE;
663 F_NODE(nd_head, RNODE_YIELD, "arguments");
664 return;
666 case NODE_LVAR:
667 ANN("local variable reference");
668 ANN("format: [nd_vid](lvar)");
669 ANN("example: x");
670 F_ID(nd_vid, RNODE_LVAR, "local variable");
671 return;
672 case NODE_DVAR:
673 ANN("dynamic variable reference");
674 ANN("format: [nd_vid](dvar)");
675 ANN("example: 1.times { x = 1; x }");
676 F_ID(nd_vid, RNODE_DVAR, "local variable");
677 return;
678 case NODE_IVAR:
679 ANN("instance variable reference");
680 ANN("format: [nd_vid](ivar)");
681 ANN("example: @x");
682 F_ID(nd_vid, RNODE_IVAR, "instance variable");
683 return;
684 case NODE_CONST:
685 ANN("constant reference");
686 ANN("format: [nd_vid](constant)");
687 ANN("example: X");
688 F_ID(nd_vid, RNODE_CONST, "constant");
689 return;
690 case NODE_CVAR:
691 ANN("class variable reference");
692 ANN("format: [nd_vid](cvar)");
693 ANN("example: @@x");
694 F_ID(nd_vid, RNODE_CVAR, "class variable");
695 return;
697 case NODE_GVAR:
698 ANN("global variable reference");
699 ANN("format: [nd_vid](gvar)");
700 ANN("example: $x");
701 F_ID(nd_vid, RNODE_GVAR, "global variable");
702 return;
704 case NODE_NTH_REF:
705 ANN("nth special variable reference");
706 ANN("format: $[nd_nth]");
707 ANN("example: $1, $2, ..");
708 F_CUSTOM1(nd_nth, "variable") { A("$"); A_LONG(RNODE_NTH_REF(node)->nd_nth); }
709 return;
711 case NODE_BACK_REF:
712 ANN("back special variable reference");
713 ANN("format: $[nd_nth]");
714 ANN("example: $&, $`, $', $+");
715 F_CUSTOM1(nd_nth, "variable") {
716 char name[3] = "$ ";
717 name[1] = (char)RNODE_BACK_REF(node)->nd_nth;
718 A(name);
720 return;
722 case NODE_MATCH:
723 ANN("match expression (against $_ implicitly)");
724 ANN("format: [nd_lit] (in condition)");
725 ANN("example: if /foo/; foo; end");
726 LAST_NODE;
727 F_VALUE(string, rb_node_regx_string_val(node), "string");
728 return;
730 case NODE_MATCH2:
731 ANN("match expression (regexp first)");
732 ANN("format: [nd_recv] =~ [nd_value]");
733 ANN("example: /foo/ =~ 'foo'");
734 F_NODE(nd_recv, RNODE_MATCH2, "regexp (receiver)");
735 if (!RNODE_MATCH2(node)->nd_args) LAST_NODE;
736 F_NODE(nd_value, RNODE_MATCH2, "string (argument)");
737 if (RNODE_MATCH2(node)->nd_args) {
738 LAST_NODE;
739 F_NODE(nd_args, RNODE_MATCH2, "named captures");
741 return;
743 case NODE_MATCH3:
744 ANN("match expression (regexp second)");
745 ANN("format: [nd_recv] =~ [nd_value]");
746 ANN("example: 'foo' =~ /foo/");
747 F_NODE(nd_recv, RNODE_MATCH3, "string (receiver)");
748 LAST_NODE;
749 F_NODE(nd_value, RNODE_MATCH3, "regexp (argument)");
750 return;
752 case NODE_STR:
753 ANN("string literal");
754 ANN("format: [nd_lit]");
755 ANN("example: 'foo'");
756 goto str;
757 case NODE_XSTR:
758 ANN("xstring literal");
759 ANN("format: [nd_lit]");
760 ANN("example: `foo`");
761 str:
762 F_VALUE(string, rb_node_str_string_val(node), "literal");
763 return;
765 case NODE_INTEGER:
766 ANN("integer literal");
767 ANN("format: [val]");
768 ANN("example: 1");
769 F_VALUE(val, rb_node_integer_literal_val(node), "val");
770 return;
772 case NODE_FLOAT:
773 ANN("float literal");
774 ANN("format: [val]");
775 ANN("example: 1.2");
776 F_VALUE(val, rb_node_float_literal_val(node), "val");
777 return;
779 case NODE_RATIONAL:
780 ANN("rational number literal");
781 ANN("format: [val]");
782 ANN("example: 1r");
783 F_VALUE(val, rb_node_rational_literal_val(node), "val");
784 return;
786 case NODE_IMAGINARY:
787 ANN("complex number literal");
788 ANN("format: [val]");
789 ANN("example: 1i");
790 F_VALUE(val, rb_node_imaginary_literal_val(node), "val");
791 return;
793 case NODE_REGX:
794 ANN("regexp literal");
795 ANN("format: [string]");
796 ANN("example: /foo/");
797 LAST_NODE;
798 F_VALUE(string, rb_node_regx_string_val(node), "string");
799 return;
801 case NODE_ONCE:
802 ANN("once evaluation");
803 ANN("format: [nd_body]");
804 ANN("example: /foo#{ bar }baz/o");
805 LAST_NODE;
806 F_NODE(nd_body, RNODE_ONCE, "body");
807 return;
809 case NODE_DSTR:
810 ANN("string literal with interpolation");
811 ANN("format: [nd_lit]");
812 ANN("example: \"foo#{ bar }baz\"");
813 goto dlit;
814 case NODE_DXSTR:
815 ANN("xstring literal with interpolation");
816 ANN("format: [nd_lit]");
817 ANN("example: `foo#{ bar }baz`");
818 goto dlit;
819 case NODE_DREGX:
820 ANN("regexp literal with interpolation");
821 ANN("format: [nd_lit]");
822 ANN("example: /foo#{ bar }baz/");
823 goto dlit;
824 case NODE_DSYM:
825 ANN("symbol literal with interpolation");
826 ANN("format: [nd_lit]");
827 ANN("example: :\"foo#{ bar }baz\"");
828 dlit:
829 F_VALUE(string, rb_node_dstr_string_val(node), "preceding string");
830 if (!RNODE_DSTR(node)->nd_next) return;
831 F_NODE(nd_next->nd_head, RNODE_DSTR, "interpolation");
832 LAST_NODE;
833 F_NODE(nd_next->nd_next, RNODE_DSTR, "tailing strings");
834 return;
836 case NODE_SYM:
837 ANN("symbol literal");
838 ANN("format: [string]");
839 ANN("example: :foo");
840 F_VALUE(string, rb_node_sym_string_val(node), "string");
841 return;
843 case NODE_EVSTR:
844 ANN("interpolation expression");
845 ANN("format: \"..#{ [nd_body] }..\"");
846 ANN("example: \"foo#{ bar }baz\"");
847 LAST_NODE;
848 F_NODE(nd_body, RNODE_EVSTR, "body");
849 return;
851 case NODE_ARGSCAT:
852 ANN("splat argument following arguments");
853 ANN("format: ..(*[nd_head], [nd_body..])");
854 ANN("example: foo(*ary, post_arg1, post_arg2)");
855 F_NODE(nd_head, RNODE_ARGSCAT, "preceding array");
856 LAST_NODE;
857 F_NODE(nd_body, RNODE_ARGSCAT, "following array");
858 return;
860 case NODE_ARGSPUSH:
861 ANN("splat argument following one argument");
862 ANN("format: ..(*[nd_head], [nd_body])");
863 ANN("example: foo(*ary, post_arg)");
864 F_NODE(nd_head, RNODE_ARGSPUSH, "preceding array");
865 LAST_NODE;
866 F_NODE(nd_body, RNODE_ARGSPUSH, "following element");
867 return;
869 case NODE_SPLAT:
870 ANN("splat argument");
871 ANN("format: *[nd_head]");
872 ANN("example: foo(*ary)");
873 LAST_NODE;
874 F_NODE(nd_head, RNODE_SPLAT, "splat'ed array");
875 return;
877 case NODE_BLOCK_PASS:
878 ANN("arguments with block argument");
879 ANN("format: ..([nd_head], &[nd_body])");
880 ANN("example: foo(x, &blk)");
881 F_NODE(nd_head, RNODE_BLOCK_PASS, "other arguments");
882 LAST_NODE;
883 F_NODE(nd_body, RNODE_BLOCK_PASS, "block argument");
884 return;
886 case NODE_DEFN:
887 ANN("method definition");
888 ANN("format: def [nd_mid] [nd_defn]; end");
889 ANN("example: def foo; bar; end");
890 F_ID(nd_mid, RNODE_DEFN, "method name");
891 LAST_NODE;
892 F_NODE(nd_defn, RNODE_DEFN, "method definition");
893 return;
895 case NODE_DEFS:
896 ANN("singleton method definition");
897 ANN("format: def [nd_recv].[nd_mid] [nd_defn]; end");
898 ANN("example: def obj.foo; bar; end");
899 F_NODE(nd_recv, RNODE_DEFS, "receiver");
900 F_ID(nd_mid, RNODE_DEFS, "method name");
901 LAST_NODE;
902 F_NODE(nd_defn, RNODE_DEFS, "method definition");
903 return;
905 case NODE_ALIAS:
906 ANN("method alias statement");
907 ANN("format: alias [nd_1st] [nd_2nd]");
908 ANN("example: alias bar foo");
909 F_NODE(nd_1st, RNODE_ALIAS, "new name");
910 LAST_NODE;
911 F_NODE(nd_2nd, RNODE_ALIAS, "old name");
912 return;
914 case NODE_VALIAS:
915 ANN("global variable alias statement");
916 ANN("format: alias [nd_alias](gvar) [nd_orig](gvar)");
917 ANN("example: alias $y $x");
918 F_ID(nd_alias, RNODE_VALIAS, "new name");
919 F_ID(nd_orig, RNODE_VALIAS, "old name");
920 return;
922 case NODE_UNDEF:
923 ANN("method undef statement");
924 ANN("format: undef [nd_undefs]");
925 ANN("example: undef foo");
926 LAST_NODE;
927 F_ARRAY(nd_undefs, RNODE_UNDEF, "nd_undefs");
928 return;
930 case NODE_CLASS:
931 ANN("class definition");
932 ANN("format: class [nd_cpath] < [nd_super]; [nd_body]; end");
933 ANN("example: class C2 < C; ..; end");
934 F_NODE(nd_cpath, RNODE_CLASS, "class path");
935 F_NODE(nd_super, RNODE_CLASS, "superclass");
936 LAST_NODE;
937 F_NODE(nd_body, RNODE_CLASS, "class definition");
938 return;
940 case NODE_MODULE:
941 ANN("module definition");
942 ANN("format: module [nd_cpath]; [nd_body]; end");
943 ANN("example: module M; ..; end");
944 F_NODE(nd_cpath, RNODE_MODULE, "module path");
945 LAST_NODE;
946 F_NODE(nd_body, RNODE_MODULE, "module definition");
947 return;
949 case NODE_SCLASS:
950 ANN("singleton class definition");
951 ANN("format: class << [nd_recv]; [nd_body]; end");
952 ANN("example: class << obj; ..; end");
953 F_NODE(nd_recv, RNODE_SCLASS, "receiver");
954 LAST_NODE;
955 F_NODE(nd_body, RNODE_SCLASS, "singleton class definition");
956 return;
958 case NODE_COLON2:
959 ANN("scoped constant reference");
960 ANN("format: [nd_head]::[nd_mid]");
961 ANN("example: M::C");
962 F_ID(nd_mid, RNODE_COLON2, "constant name");
963 LAST_NODE;
964 F_NODE(nd_head, RNODE_COLON2, "receiver");
965 return;
967 case NODE_COLON3:
968 ANN("top-level constant reference");
969 ANN("format: ::[nd_mid]");
970 ANN("example: ::Object");
971 F_ID(nd_mid, RNODE_COLON3, "constant name");
972 return;
974 case NODE_DOT2:
975 ANN("range constructor (incl.)");
976 ANN("format: [nd_beg]..[nd_end]");
977 ANN("example: 1..5");
978 goto dot;
979 case NODE_DOT3:
980 ANN("range constructor (excl.)");
981 ANN("format: [nd_beg]...[nd_end]");
982 ANN("example: 1...5");
983 goto dot;
984 case NODE_FLIP2:
985 ANN("flip-flop condition (incl.)");
986 ANN("format: [nd_beg]..[nd_end]");
987 ANN("example: if (x==1)..(x==5); foo; end");
988 goto dot;
989 case NODE_FLIP3:
990 ANN("flip-flop condition (excl.)");
991 ANN("format: [nd_beg]...[nd_end]");
992 ANN("example: if (x==1)...(x==5); foo; end");
993 dot:
994 F_NODE(nd_beg, RNODE_DOT2, "begin");
995 LAST_NODE;
996 F_NODE(nd_end, RNODE_DOT2, "end");
997 return;
999 case NODE_SELF:
1000 ANN("self");
1001 ANN("format: self");
1002 ANN("example: self");
1003 F_CUSTOM1(nd_state, "nd_state") {
1004 A_INT((int)RNODE_SELF(node)->nd_state);
1006 return;
1008 case NODE_NIL:
1009 ANN("nil");
1010 ANN("format: nil");
1011 ANN("example: nil");
1012 return;
1014 case NODE_TRUE:
1015 ANN("true");
1016 ANN("format: true");
1017 ANN("example: true");
1018 return;
1020 case NODE_FALSE:
1021 ANN("false");
1022 ANN("format: false");
1023 ANN("example: false");
1024 return;
1026 case NODE_ERRINFO:
1027 ANN("virtual reference to $!");
1028 ANN("format: rescue => id");
1029 ANN("example: rescue => id");
1030 return;
1032 case NODE_DEFINED:
1033 ANN("defined? expression");
1034 ANN("format: defined?([nd_head])");
1035 ANN("example: defined?(foo)");
1036 F_NODE(nd_head, RNODE_DEFINED, "expr");
1037 return;
1039 case NODE_POSTEXE:
1040 ANN("post-execution");
1041 ANN("format: END { [nd_body] }");
1042 ANN("example: END { foo }");
1043 LAST_NODE;
1044 F_NODE(nd_body, RNODE_POSTEXE, "END clause");
1045 return;
1047 case NODE_ATTRASGN:
1048 ANN("attr assignment");
1049 ANN("format: [nd_recv].[nd_mid] = [nd_args]");
1050 ANN("example: struct.field = foo");
1051 F_NODE(nd_recv, RNODE_ATTRASGN, "receiver");
1052 F_ID(nd_mid, RNODE_ATTRASGN, "method name");
1053 LAST_NODE;
1054 F_NODE(nd_args, RNODE_ATTRASGN, "arguments");
1055 return;
1057 case NODE_LAMBDA:
1058 ANN("lambda expression");
1059 ANN("format: -> [nd_body]");
1060 ANN("example: -> { foo }");
1061 LAST_NODE;
1062 F_NODE(nd_body, RNODE_LAMBDA, "lambda clause");
1063 return;
1065 case NODE_OPT_ARG:
1066 ANN("optional arguments");
1067 ANN("format: def method_name([nd_body=some], [nd_next..])");
1068 ANN("example: def foo(a, b=1, c); end");
1069 F_NODE(nd_body, RNODE_OPT_ARG, "body");
1070 LAST_NODE;
1071 F_NODE(nd_next, RNODE_OPT_ARG, "next");
1072 return;
1074 case NODE_KW_ARG:
1075 ANN("keyword arguments");
1076 ANN("format: def method_name([nd_body=some], [nd_next..])");
1077 ANN("example: def foo(a:1, b:2); end");
1078 F_NODE(nd_body, RNODE_KW_ARG, "body");
1079 LAST_NODE;
1080 F_NODE(nd_next, RNODE_KW_ARG, "next");
1081 return;
1083 case NODE_POSTARG:
1084 ANN("post arguments");
1085 ANN("format: *[nd_1st], [nd_2nd..] = ..");
1086 ANN("example: a, *rest, z = foo");
1087 if (NODE_NAMED_REST_P(RNODE_POSTARG(node)->nd_1st)) {
1088 F_NODE(nd_1st, RNODE_POSTARG, "rest argument");
1090 else {
1091 F_MSG(nd_1st, "rest argument", "NODE_SPECIAL_NO_NAME_REST (rest argument without name)");
1093 LAST_NODE;
1094 F_NODE(nd_2nd, RNODE_POSTARG, "post arguments");
1095 return;
1097 case NODE_ARGS:
1098 ANN("method parameters");
1099 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])");
1100 ANN("example: def foo(a, b, opt1=1, opt2=2, *rest, y, z, kw: 1, **kwrest, &blk); end");
1101 F_INT(nd_ainfo.pre_args_num, RNODE_ARGS, "count of mandatory (pre-)arguments");
1102 F_NODE(nd_ainfo.pre_init, RNODE_ARGS, "initialization of (pre-)arguments");
1103 F_INT(nd_ainfo.post_args_num, RNODE_ARGS, "count of mandatory post-arguments");
1104 F_NODE(nd_ainfo.post_init, RNODE_ARGS, "initialization of post-arguments");
1105 F_ID(nd_ainfo.first_post_arg, RNODE_ARGS, "first post argument");
1106 F_CUSTOM1(nd_ainfo.rest_arg, "rest argument") {
1107 if (RNODE_ARGS(node)->nd_ainfo.rest_arg == NODE_SPECIAL_EXCESSIVE_COMMA) {
1108 A("1 (excessed comma)");
1110 else {
1111 A_ID(RNODE_ARGS(node)->nd_ainfo.rest_arg);
1114 F_ID(nd_ainfo.block_arg, RNODE_ARGS, "block argument");
1115 F_NODE(nd_ainfo.opt_args, RNODE_ARGS, "optional arguments");
1116 F_NODE(nd_ainfo.kw_args, RNODE_ARGS, "keyword arguments");
1117 LAST_NODE;
1118 F_NODE(nd_ainfo.kw_rest_arg, RNODE_ARGS, "keyword rest argument");
1119 return;
1121 case NODE_SCOPE:
1122 ANN("new scope");
1123 ANN("format: [nd_tbl]: local table, [nd_args]: arguments, [nd_body]: body");
1124 F_CUSTOM1(nd_tbl, "local table") {
1125 rb_ast_id_table_t *tbl = RNODE_SCOPE(node)->nd_tbl;
1126 int i;
1127 int size = tbl ? tbl->size : 0;
1128 if (size == 0) A("(empty)");
1129 for (i = 0; i < size; i++) {
1130 A_ID(tbl->ids[i]); if (i < size - 1) A(",");
1133 F_NODE(nd_args, RNODE_SCOPE, "arguments");
1134 LAST_NODE;
1135 F_NODE(nd_body, RNODE_SCOPE, "body");
1136 return;
1138 case NODE_ARYPTN:
1139 ANN("array pattern");
1140 ANN("format: [nd_pconst]([pre_args], ..., *[rest_arg], [post_args], ...)");
1141 F_NODE(nd_pconst, RNODE_ARYPTN, "constant");
1142 F_NODE(pre_args, RNODE_ARYPTN, "pre arguments");
1143 if (NODE_NAMED_REST_P(RNODE_ARYPTN(node)->rest_arg)) {
1144 F_NODE(rest_arg, RNODE_ARYPTN, "rest argument");
1146 else {
1147 F_MSG(rest_arg, "rest argument", "NODE_SPECIAL_NO_NAME_REST (rest argument without name)");
1149 LAST_NODE;
1150 F_NODE(post_args, RNODE_ARYPTN, "post arguments");
1151 return;
1153 case NODE_FNDPTN:
1154 ANN("find pattern");
1155 ANN("format: [nd_pconst](*[pre_rest_arg], args, ..., *[post_rest_arg])");
1156 F_NODE(nd_pconst, RNODE_FNDPTN, "constant");
1157 if (NODE_NAMED_REST_P(RNODE_FNDPTN(node)->pre_rest_arg)) {
1158 F_NODE(pre_rest_arg, RNODE_FNDPTN, "pre rest argument");
1160 else {
1161 F_MSG(pre_rest_arg, "pre rest argument", "NODE_SPECIAL_NO_NAME_REST (rest argument without name)");
1163 F_NODE(args, RNODE_FNDPTN, "arguments");
1165 LAST_NODE;
1166 if (NODE_NAMED_REST_P(RNODE_FNDPTN(node)->post_rest_arg)) {
1167 F_NODE(post_rest_arg, RNODE_FNDPTN, "post rest argument");
1169 else {
1170 F_MSG(post_rest_arg, "post rest argument", "NODE_SPECIAL_NO_NAME_REST (rest argument without name)");
1172 return;
1174 case NODE_HSHPTN:
1175 ANN("hash pattern");
1176 ANN("format: [nd_pconst]([nd_pkwargs], ..., **[nd_pkwrestarg])");
1177 F_NODE(nd_pconst, RNODE_HSHPTN, "constant");
1178 F_NODE(nd_pkwargs, RNODE_HSHPTN, "keyword arguments");
1179 LAST_NODE;
1180 if (RNODE_HSHPTN(node)->nd_pkwrestarg == NODE_SPECIAL_NO_REST_KEYWORD) {
1181 F_MSG(nd_pkwrestarg, "keyword rest argument", "NODE_SPECIAL_NO_REST_KEYWORD (**nil)");
1183 else {
1184 F_NODE(nd_pkwrestarg, RNODE_HSHPTN, "keyword rest argument");
1186 return;
1188 case NODE_LINE:
1189 ANN("line");
1190 ANN("format: [lineno]");
1191 ANN("example: __LINE__");
1192 return;
1194 case NODE_FILE:
1195 ANN("line");
1196 ANN("format: [path]");
1197 ANN("example: __FILE__");
1198 F_VALUE(path, rb_node_file_path_val(node), "path");
1199 return;
1201 case NODE_ENCODING:
1202 ANN("encoding");
1203 ANN("format: [enc]");
1204 ANN("example: __ENCODING__");
1205 F_VALUE(enc, rb_node_encoding_val(node), "enc");
1206 return;
1208 case NODE_ERROR:
1209 ANN("Broken input recovered by Error Tolerant mode");
1210 return;
1212 case NODE_ARGS_AUX:
1213 case NODE_LAST:
1214 break;
1217 rb_bug("dump_node: unknown node: %s", ruby_node_name(nd_type(node)));
1220 VALUE
1221 rb_parser_dump_tree(const NODE *node, int comment)
1223 VALUE buf = rb_str_new_cstr(
1224 "###########################################################\n"
1225 "## Do NOT use this node dump for any purpose other than ##\n"
1226 "## debug and research. Compatibility is not guaranteed. ##\n"
1227 "###########################################################\n\n"
1229 dump_node(buf, rb_str_new_cstr("# "), comment, node);
1230 return buf;