print lineno of dumping node

parent 7477d0c1
...@@ -5609,8 +5609,9 @@ mrb_load_string(mrb_state *mrb, const char *s) ...@@ -5609,8 +5609,9 @@ mrb_load_string(mrb_state *mrb, const char *s)
#ifdef ENABLE_STDIO #ifdef ENABLE_STDIO
static void static void
dump_prefix(int offset) dump_prefix(node *tree, int offset)
{ {
printf("%05d ", tree->lineno);
while (offset--) { while (offset--) {
putc(' ', stdout); putc(' ', stdout);
putc(' ', stdout); putc(' ', stdout);
...@@ -5636,7 +5637,7 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5636,7 +5637,7 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
if (!tree) return; if (!tree) return;
again: again:
dump_prefix(offset); dump_prefix(tree, offset);
n = (int)(intptr_t)tree->car; n = (int)(intptr_t)tree->car;
tree = tree->cdr; tree = tree->cdr;
switch (n) { switch (n) {
...@@ -5648,7 +5649,7 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5648,7 +5649,7 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_RESCUE: case NODE_RESCUE:
printf("NODE_RESCUE:\n"); printf("NODE_RESCUE:\n");
if (tree->car) { if (tree->car) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("body:\n"); printf("body:\n");
mrb_parser_dump(mrb, tree->car, offset+2); mrb_parser_dump(mrb, tree->car, offset+2);
} }
...@@ -5656,22 +5657,22 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5656,22 +5657,22 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
if (tree->car) { if (tree->car) {
node *n2 = tree->car; node *n2 = tree->car;
dump_prefix(offset+1); dump_prefix(n2, offset+1);
printf("rescue:\n"); printf("rescue:\n");
while (n2) { while (n2) {
node *n3 = n2->car; node *n3 = n2->car;
if (n3->car) { if (n3->car) {
dump_prefix(offset+2); dump_prefix(n2, offset+2);
printf("handle classes:\n"); printf("handle classes:\n");
dump_recur(mrb, n3->car, offset+3); dump_recur(mrb, n3->car, offset+3);
} }
if (n3->cdr->car) { if (n3->cdr->car) {
dump_prefix(offset+2); dump_prefix(n3, offset+2);
printf("exc_var:\n"); printf("exc_var:\n");
mrb_parser_dump(mrb, n3->cdr->car, offset+3); mrb_parser_dump(mrb, n3->cdr->car, offset+3);
} }
if (n3->cdr->cdr->car) { if (n3->cdr->cdr->car) {
dump_prefix(offset+2); dump_prefix(n3, offset+2);
printf("rescue body:\n"); printf("rescue body:\n");
mrb_parser_dump(mrb, n3->cdr->cdr->car, offset+3); mrb_parser_dump(mrb, n3->cdr->cdr->car, offset+3);
} }
...@@ -5680,7 +5681,7 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5680,7 +5681,7 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
} }
tree = tree->cdr; tree = tree->cdr;
if (tree->car) { if (tree->car) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("else:\n"); printf("else:\n");
mrb_parser_dump(mrb, tree->car, offset+2); mrb_parser_dump(mrb, tree->car, offset+2);
} }
...@@ -5688,10 +5689,10 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5688,10 +5689,10 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_ENSURE: case NODE_ENSURE:
printf("NODE_ENSURE:\n"); printf("NODE_ENSURE:\n");
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("body:\n"); printf("body:\n");
mrb_parser_dump(mrb, tree->car, offset+2); mrb_parser_dump(mrb, tree->car, offset+2);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("ensure:\n"); printf("ensure:\n");
mrb_parser_dump(mrb, tree->cdr->cdr, offset+2); mrb_parser_dump(mrb, tree->cdr->cdr, offset+2);
break; break;
...@@ -5708,19 +5709,19 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5708,19 +5709,19 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
node *n = tree->car; node *n = tree->car;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("mandatory args:\n"); printf("mandatory args:\n");
dump_recur(mrb, n->car, offset+2); dump_recur(mrb, n->car, offset+2);
} }
n = n->cdr; n = n->cdr;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("optional args:\n"); printf("optional args:\n");
{ {
node *n2 = n->car; node *n2 = n->car;
while (n2) { while (n2) {
dump_prefix(offset+2); dump_prefix(n2, offset+2);
printf("%s=", mrb_sym2name(mrb, sym(n2->car->car))); printf("%s=", mrb_sym2name(mrb, sym(n2->car->car)));
mrb_parser_dump(mrb, n2->car->cdr, 0); mrb_parser_dump(mrb, n2->car->cdr, 0);
n2 = n2->cdr; n2 = n2->cdr;
...@@ -5729,36 +5730,36 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5729,36 +5730,36 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
} }
n = n->cdr; n = n->cdr;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car))); printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car)));
} }
n = n->cdr; n = n->cdr;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("post mandatory args:\n"); printf("post mandatory args:\n");
dump_recur(mrb, n->car, offset+2); dump_recur(mrb, n->car, offset+2);
} }
n = n->cdr; n = n->cdr;
if (n) { if (n) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("blk=&%s\n", mrb_sym2name(mrb, sym(n))); printf("blk=&%s\n", mrb_sym2name(mrb, sym(n)));
} }
} }
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("body:\n"); printf("body:\n");
mrb_parser_dump(mrb, tree->cdr->car, offset+2); mrb_parser_dump(mrb, tree->cdr->car, offset+2);
break; break;
case NODE_IF: case NODE_IF:
printf("NODE_IF:\n"); printf("NODE_IF:\n");
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("cond:\n"); printf("cond:\n");
mrb_parser_dump(mrb, tree->car, offset+2); mrb_parser_dump(mrb, tree->car, offset+2);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("then:\n"); printf("then:\n");
mrb_parser_dump(mrb, tree->cdr->car, offset+2); mrb_parser_dump(mrb, tree->cdr->car, offset+2);
if (tree->cdr->cdr->car) { if (tree->cdr->cdr->car) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("else:\n"); printf("else:\n");
mrb_parser_dump(mrb, tree->cdr->cdr->car, offset+2); mrb_parser_dump(mrb, tree->cdr->cdr->car, offset+2);
} }
...@@ -5783,10 +5784,10 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5783,10 +5784,10 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
} }
tree = tree->cdr; tree = tree->cdr;
while (tree) { while (tree) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("case:\n"); printf("case:\n");
dump_recur(mrb, tree->car->car, offset+2); dump_recur(mrb, tree->car->car, offset+2);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("body:\n"); printf("body:\n");
mrb_parser_dump(mrb, tree->car->cdr, offset+2); mrb_parser_dump(mrb, tree->car->cdr, offset+2);
tree = tree->cdr; tree = tree->cdr;
...@@ -5795,47 +5796,47 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5795,47 +5796,47 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_WHILE: case NODE_WHILE:
printf("NODE_WHILE:\n"); printf("NODE_WHILE:\n");
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("cond:\n"); printf("cond:\n");
mrb_parser_dump(mrb, tree->car, offset+2); mrb_parser_dump(mrb, tree->car, offset+2);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("body:\n"); printf("body:\n");
mrb_parser_dump(mrb, tree->cdr, offset+2); mrb_parser_dump(mrb, tree->cdr, offset+2);
break; break;
case NODE_UNTIL: case NODE_UNTIL:
printf("NODE_UNTIL:\n"); printf("NODE_UNTIL:\n");
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("cond:\n"); printf("cond:\n");
mrb_parser_dump(mrb, tree->car, offset+2); mrb_parser_dump(mrb, tree->car, offset+2);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("body:\n"); printf("body:\n");
mrb_parser_dump(mrb, tree->cdr, offset+2); mrb_parser_dump(mrb, tree->cdr, offset+2);
break; break;
case NODE_FOR: case NODE_FOR:
printf("NODE_FOR:\n"); printf("NODE_FOR:\n");
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("var:\n"); printf("var:\n");
{ {
node *n2 = tree->car; node *n2 = tree->car;
if (n2->car) { if (n2->car) {
dump_prefix(offset+2); dump_prefix(n2, offset+2);
printf("pre:\n"); printf("pre:\n");
dump_recur(mrb, n2->car, offset+3); dump_recur(mrb, n2->car, offset+3);
} }
n2 = n2->cdr; n2 = n2->cdr;
if (n2) { if (n2) {
if (n2->car) { if (n2->car) {
dump_prefix(offset+2); dump_prefix(n2, offset+2);
printf("rest:\n"); printf("rest:\n");
mrb_parser_dump(mrb, n2->car, offset+3); mrb_parser_dump(mrb, n2->car, offset+3);
} }
n2 = n2->cdr; n2 = n2->cdr;
if (n2) { if (n2) {
if (n2->car) { if (n2->car) {
dump_prefix(offset+2); dump_prefix(n2, offset+2);
printf("post:\n"); printf("post:\n");
dump_recur(mrb, n2->car, offset+3); dump_recur(mrb, n2->car, offset+3);
} }
...@@ -5843,11 +5844,11 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5843,11 +5844,11 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
} }
} }
tree = tree->cdr; tree = tree->cdr;
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("in:\n"); printf("in:\n");
mrb_parser_dump(mrb, tree->car, offset+2); mrb_parser_dump(mrb, tree->car, offset+2);
tree = tree->cdr; tree = tree->cdr;
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("do:\n"); printf("do:\n");
mrb_parser_dump(mrb, tree->car, offset+2); mrb_parser_dump(mrb, tree->car, offset+2);
break; break;
...@@ -5859,9 +5860,9 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5859,9 +5860,9 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
mrb_bool first_lval = TRUE; mrb_bool first_lval = TRUE;
if (n2 && (n2->car || n2->cdr)) { if (n2 && (n2->car || n2->cdr)) {
dump_prefix(offset+1); dump_prefix(n2, offset+1);
printf("local variables:\n"); printf("local variables:\n");
dump_prefix(offset+2); dump_prefix(n2, offset+2);
while (n2) { while (n2) {
if (n2->car) { if (n2->car) {
if (!first_lval) printf(", "); if (!first_lval) printf(", ");
...@@ -5881,17 +5882,17 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5881,17 +5882,17 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_CALL: case NODE_CALL:
printf("NODE_CALL:\n"); printf("NODE_CALL:\n");
mrb_parser_dump(mrb, tree->car, offset+1); mrb_parser_dump(mrb, tree->car, offset+1);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("method='%s' (%d)\n", printf("method='%s' (%d)\n",
mrb_sym2name(mrb, sym(tree->cdr->car)), mrb_sym2name(mrb, sym(tree->cdr->car)),
(int)(intptr_t)tree->cdr->car); (int)(intptr_t)tree->cdr->car);
tree = tree->cdr->cdr->car; tree = tree->cdr->cdr->car;
if (tree) { if (tree) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("args:\n"); printf("args:\n");
dump_recur(mrb, tree->car, offset+2); dump_recur(mrb, tree->car, offset+2);
if (tree->cdr) { if (tree->cdr) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("block:\n"); printf("block:\n");
mrb_parser_dump(mrb, tree->cdr, offset+2); mrb_parser_dump(mrb, tree->cdr, offset+2);
} }
...@@ -5913,13 +5914,13 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5913,13 +5914,13 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_COLON2: case NODE_COLON2:
printf("NODE_COLON2:\n"); printf("NODE_COLON2:\n");
mrb_parser_dump(mrb, tree->car, offset+1); mrb_parser_dump(mrb, tree->car, offset+1);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("::%s\n", mrb_sym2name(mrb, sym(tree->cdr))); printf("::%s\n", mrb_sym2name(mrb, sym(tree->cdr)));
break; break;
case NODE_COLON3: case NODE_COLON3:
printf("NODE_COLON3:\n"); printf("NODE_COLON3:\n");
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("::%s\n", mrb_sym2name(mrb, sym(tree))); printf("::%s\n", mrb_sym2name(mrb, sym(tree)));
break; break;
...@@ -5931,10 +5932,10 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5931,10 +5932,10 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_HASH: case NODE_HASH:
printf("NODE_HASH:\n"); printf("NODE_HASH:\n");
while (tree) { while (tree) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("key:\n"); printf("key:\n");
mrb_parser_dump(mrb, tree->car->car, offset+2); mrb_parser_dump(mrb, tree->car->car, offset+2);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("value:\n"); printf("value:\n");
mrb_parser_dump(mrb, tree->car->cdr, offset+2); mrb_parser_dump(mrb, tree->car->cdr, offset+2);
tree = tree->cdr; tree = tree->cdr;
...@@ -5948,33 +5949,33 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5948,33 +5949,33 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_ASGN: case NODE_ASGN:
printf("NODE_ASGN:\n"); printf("NODE_ASGN:\n");
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("lhs:\n"); printf("lhs:\n");
mrb_parser_dump(mrb, tree->car, offset+2); mrb_parser_dump(mrb, tree->car, offset+2);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("rhs:\n"); printf("rhs:\n");
mrb_parser_dump(mrb, tree->cdr, offset+2); mrb_parser_dump(mrb, tree->cdr, offset+2);
break; break;
case NODE_MASGN: case NODE_MASGN:
printf("NODE_MASGN:\n"); printf("NODE_MASGN:\n");
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("mlhs:\n"); printf("mlhs:\n");
{ {
node *n2 = tree->car; node *n2 = tree->car;
if (n2->car) { if (n2->car) {
dump_prefix(offset+2); dump_prefix(tree, offset+2);
printf("pre:\n"); printf("pre:\n");
dump_recur(mrb, n2->car, offset+3); dump_recur(mrb, n2->car, offset+3);
} }
n2 = n2->cdr; n2 = n2->cdr;
if (n2) { if (n2) {
if (n2->car) { if (n2->car) {
dump_prefix(offset+2); dump_prefix(n2, offset+2);
printf("rest:\n"); printf("rest:\n");
if (n2->car == (node*)-1) { if (n2->car == (node*)-1) {
dump_prefix(offset+2); dump_prefix(n2, offset+2);
printf("(empty)\n"); printf("(empty)\n");
} }
else { else {
...@@ -5984,25 +5985,25 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -5984,25 +5985,25 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
n2 = n2->cdr; n2 = n2->cdr;
if (n2) { if (n2) {
if (n2->car) { if (n2->car) {
dump_prefix(offset+2); dump_prefix(n2, offset+2);
printf("post:\n"); printf("post:\n");
dump_recur(mrb, n2->car, offset+3); dump_recur(mrb, n2->car, offset+3);
} }
} }
} }
} }
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("rhs:\n"); printf("rhs:\n");
mrb_parser_dump(mrb, tree->cdr, offset+2); mrb_parser_dump(mrb, tree->cdr, offset+2);
break; break;
case NODE_OP_ASGN: case NODE_OP_ASGN:
printf("NODE_OP_ASGN:\n"); printf("NODE_OP_ASGN:\n");
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("lhs:\n"); printf("lhs:\n");
mrb_parser_dump(mrb, tree->car, offset+2); mrb_parser_dump(mrb, tree->car, offset+2);
tree = tree->cdr; tree = tree->cdr;
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("op='%s' (%d)\n", mrb_sym2name(mrb, sym(tree->car)), (int)(intptr_t)tree->car); printf("op='%s' (%d)\n", mrb_sym2name(mrb, sym(tree->car)), (int)(intptr_t)tree->car);
tree = tree->cdr; tree = tree->cdr;
mrb_parser_dump(mrb, tree->car, offset+1); mrb_parser_dump(mrb, tree->car, offset+1);
...@@ -6011,11 +6012,11 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -6011,11 +6012,11 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_SUPER: case NODE_SUPER:
printf("NODE_SUPER:\n"); printf("NODE_SUPER:\n");
if (tree) { if (tree) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("args:\n"); printf("args:\n");
dump_recur(mrb, tree->car, offset+2); dump_recur(mrb, tree->car, offset+2);
if (tree->cdr) { if (tree->cdr) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("block:\n"); printf("block:\n");
mrb_parser_dump(mrb, tree->cdr, offset+2); mrb_parser_dump(mrb, tree->cdr, offset+2);
} }
...@@ -6076,10 +6077,10 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -6076,10 +6077,10 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_MATCH: case NODE_MATCH:
printf("NODE_MATCH:\n"); printf("NODE_MATCH:\n");
dump_prefix(offset + 1); dump_prefix(tree, offset + 1);
printf("lhs:\n"); printf("lhs:\n");
mrb_parser_dump(mrb, tree->car, offset + 2); mrb_parser_dump(mrb, tree->car, offset + 2);
dump_prefix(offset + 1); dump_prefix(tree, offset + 1);
printf("rhs:\n"); printf("rhs:\n");
mrb_parser_dump(mrb, tree->cdr, offset + 2); mrb_parser_dump(mrb, tree->cdr, offset + 2);
break; break;
...@@ -6139,9 +6140,9 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -6139,9 +6140,9 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_DREGX: case NODE_DREGX:
printf("NODE_DREGX\n"); printf("NODE_DREGX\n");
dump_recur(mrb, tree->car, offset+1); dump_recur(mrb, tree->car, offset+1);
dump_prefix(offset); dump_prefix(tree, offset);
printf("tail: %s\n", (char*)tree->cdr->cdr->car); printf("tail: %s\n", (char*)tree->cdr->cdr->car);
dump_prefix(offset); dump_prefix(tree, offset);
printf("opt: %s\n", (char*)tree->cdr->cdr->cdr); printf("opt: %s\n", (char*)tree->cdr->cdr->cdr);
break; break;
...@@ -6186,24 +6187,24 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -6186,24 +6187,24 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_CLASS: case NODE_CLASS:
printf("NODE_CLASS:\n"); printf("NODE_CLASS:\n");
if (tree->car->car == (node*)0) { if (tree->car->car == (node*)0) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf(":%s\n", mrb_sym2name(mrb, sym(tree->car->cdr))); printf(":%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
} }
else if (tree->car->car == (node*)1) { else if (tree->car->car == (node*)1) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr))); printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
} }
else { else {
mrb_parser_dump(mrb, tree->car->car, offset+1); mrb_parser_dump(mrb, tree->car->car, offset+1);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr))); printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
} }
if (tree->cdr->car) { if (tree->cdr->car) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("super:\n"); printf("super:\n");
mrb_parser_dump(mrb, tree->cdr->car, offset+2); mrb_parser_dump(mrb, tree->cdr->car, offset+2);
} }
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("body:\n"); printf("body:\n");
mrb_parser_dump(mrb, tree->cdr->cdr->car->cdr, offset+2); mrb_parser_dump(mrb, tree->cdr->cdr->car->cdr, offset+2);
break; break;
...@@ -6211,19 +6212,19 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -6211,19 +6212,19 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_MODULE: case NODE_MODULE:
printf("NODE_MODULE:\n"); printf("NODE_MODULE:\n");
if (tree->car->car == (node*)0) { if (tree->car->car == (node*)0) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf(":%s\n", mrb_sym2name(mrb, sym(tree->car->cdr))); printf(":%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
} }
else if (tree->car->car == (node*)1) { else if (tree->car->car == (node*)1) {
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr))); printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
} }
else { else {
mrb_parser_dump(mrb, tree->car->car, offset+1); mrb_parser_dump(mrb, tree->car->car, offset+1);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr))); printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
} }
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("body:\n"); printf("body:\n");
mrb_parser_dump(mrb, tree->cdr->car->cdr, offset+2); mrb_parser_dump(mrb, tree->cdr->car->cdr, offset+2);
break; break;
...@@ -6231,14 +6232,14 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -6231,14 +6232,14 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_SCLASS: case NODE_SCLASS:
printf("NODE_SCLASS:\n"); printf("NODE_SCLASS:\n");
mrb_parser_dump(mrb, tree->car, offset+1); mrb_parser_dump(mrb, tree->car, offset+1);
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("body:\n"); printf("body:\n");
mrb_parser_dump(mrb, tree->cdr->car->cdr, offset+2); mrb_parser_dump(mrb, tree->cdr->car->cdr, offset+2);
break; break;
case NODE_DEF: case NODE_DEF:
printf("NODE_DEF:\n"); printf("NODE_DEF:\n");
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf("%s\n", mrb_sym2name(mrb, sym(tree->car))); printf("%s\n", mrb_sym2name(mrb, sym(tree->car)));
tree = tree->cdr; tree = tree->cdr;
{ {
...@@ -6246,9 +6247,9 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -6246,9 +6247,9 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
mrb_bool first_lval = TRUE; mrb_bool first_lval = TRUE;
if (n2 && (n2->car || n2->cdr)) { if (n2 && (n2->car || n2->cdr)) {
dump_prefix(offset+1); dump_prefix(n2, offset+1);
printf("local variables:\n"); printf("local variables:\n");
dump_prefix(offset+2); dump_prefix(n2, offset+2);
while (n2) { while (n2) {
if (n2->car) { if (n2->car) {
if (!first_lval) printf(", "); if (!first_lval) printf(", ");
...@@ -6265,19 +6266,19 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -6265,19 +6266,19 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
node *n = tree->car; node *n = tree->car;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("mandatory args:\n"); printf("mandatory args:\n");
dump_recur(mrb, n->car, offset+2); dump_recur(mrb, n->car, offset+2);
} }
n = n->cdr; n = n->cdr;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("optional args:\n"); printf("optional args:\n");
{ {
node *n2 = n->car; node *n2 = n->car;
while (n2) { while (n2) {
dump_prefix(offset+2); dump_prefix(n2, offset+2);
printf("%s=", mrb_sym2name(mrb, sym(n2->car->car))); printf("%s=", mrb_sym2name(mrb, sym(n2->car->car)));
mrb_parser_dump(mrb, n2->car->cdr, 0); mrb_parser_dump(mrb, n2->car->cdr, 0);
n2 = n2->cdr; n2 = n2->cdr;
...@@ -6286,18 +6287,18 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -6286,18 +6287,18 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
} }
n = n->cdr; n = n->cdr;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car))); printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car)));
} }
n = n->cdr; n = n->cdr;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("post mandatory args:\n"); printf("post mandatory args:\n");
dump_recur(mrb, n->car, offset+2); dump_recur(mrb, n->car, offset+2);
} }
n = n->cdr; n = n->cdr;
if (n) { if (n) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("blk=&%s\n", mrb_sym2name(mrb, sym(n))); printf("blk=&%s\n", mrb_sym2name(mrb, sym(n)));
} }
} }
...@@ -6308,26 +6309,26 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -6308,26 +6309,26 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
printf("NODE_SDEF:\n"); printf("NODE_SDEF:\n");
mrb_parser_dump(mrb, tree->car, offset+1); mrb_parser_dump(mrb, tree->car, offset+1);
tree = tree->cdr; tree = tree->cdr;
dump_prefix(offset+1); dump_prefix(tree, offset+1);
printf(":%s\n", mrb_sym2name(mrb, sym(tree->car))); printf(":%s\n", mrb_sym2name(mrb, sym(tree->car)));
tree = tree->cdr->cdr; tree = tree->cdr->cdr;
if (tree->car) { if (tree->car) {
node *n = tree->car; node *n = tree->car;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("mandatory args:\n"); printf("mandatory args:\n");
dump_recur(mrb, n->car, offset+2); dump_recur(mrb, n->car, offset+2);
} }
n = n->cdr; n = n->cdr;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("optional args:\n"); printf("optional args:\n");
{ {
node *n2 = n->car; node *n2 = n->car;
while (n2) { while (n2) {
dump_prefix(offset+2); dump_prefix(n2, offset+2);
printf("%s=", mrb_sym2name(mrb, sym(n2->car->car))); printf("%s=", mrb_sym2name(mrb, sym(n2->car->car)));
mrb_parser_dump(mrb, n2->car->cdr, 0); mrb_parser_dump(mrb, n2->car->cdr, 0);
n2 = n2->cdr; n2 = n2->cdr;
...@@ -6336,18 +6337,18 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset) ...@@ -6336,18 +6337,18 @@ mrb_parser_dump(mrb_state *mrb, node *tree, int offset)
} }
n = n->cdr; n = n->cdr;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car))); printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car)));
} }
n = n->cdr; n = n->cdr;
if (n->car) { if (n->car) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("post mandatory args:\n"); printf("post mandatory args:\n");
dump_recur(mrb, n->car, offset+2); dump_recur(mrb, n->car, offset+2);
} }
n = n->cdr; n = n->cdr;
if (n) { if (n) {
dump_prefix(offset+1); dump_prefix(n, offset+1);
printf("blk=&%s\n", mrb_sym2name(mrb, sym(n))); printf("blk=&%s\n", mrb_sym2name(mrb, sym(n)));
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment