Skip to content

Commit ba972b6

Browse files
committed
Dump .fallback for VarWithFallback when doing --target=ast.
Generalize printing out of tagged children nodes.
1 parent 78a6682 commit ba972b6

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

src/QAST/Children.nqp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,27 @@ role QAST::Children {
3131
}
3232
}
3333

34+
method extra_children() {
35+
[];
36+
}
37+
3438
method dump_children(int $indent, @onto) {
35-
self.dump_node_list($indent, @onto, @!children);
39+
my $extra := 0;
40+
for self.extra_children -> $tag, $nodes {
41+
if $nodes {
42+
nqp::push(@onto, nqp::x(' ', $indent));
43+
nqp::push(@onto, "[" ~ $tag ~ "]");
44+
nqp::push(@onto, "\n");
45+
self.dump_node_list($indent+2, @onto, $nodes);
46+
}
47+
$extra := $extra + nqp::elems($nodes);
48+
}
49+
50+
if $extra && @!children {
51+
nqp::push(@onto, nqp::x(' ', $indent) ~ "[children]\n");
52+
self.dump_node_list($indent+2, @onto, @!children);
53+
} else {
54+
self.dump_node_list($indent, @onto, @!children);
55+
}
3656
}
3757
}

src/QAST/CompUnit.nqp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,10 @@ class QAST::CompUnit is QAST::Node does QAST::Children {
5959
$!code_ref_blocks := $value unless $value =:= NO_VALUE; $!code_ref_blocks
6060
}
6161

62-
method dump_children(int $indent, @onto) {
63-
if self.pre_deserialize {
64-
nqp::push(@onto, nqp::x(' ', $indent) ~ "[pre deserialize]\n");
65-
self.dump_node_list($indent, @onto, self.pre_deserialize);
66-
}
67-
68-
if self.post_deserialize {
69-
nqp::push(@onto, nqp::x(' ', $indent) ~ "[post deserialize]\n");
70-
self.dump_node_list($indent, @onto, self.post_deserialize);
71-
}
72-
73-
if self.pre_deserialize || self.post_deserialize {
74-
nqp::push(@onto, nqp::x(' ', $indent) ~ "[children]\n")
75-
}
76-
self.dump_node_list($indent, @onto, self.list);
62+
method extra_children() {
63+
[
64+
'pre_deserialize', self.pre_deserialize,
65+
'post_deserialize', self.post_deserialize
66+
];
7767
}
7868
}

src/QAST/VarWithFallback.nqp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
class QAST::VarWithFallback is QAST::Var {
22
has $!fallback;
33
method fallback($value = NO_VALUE) { $!fallback := $value unless $value =:= NO_VALUE; $!fallback }
4+
5+
method extra_children() {
6+
$!fallback ?? ['fallback', [$!fallback]] !! [];
7+
}
48
}

0 commit comments

Comments
 (0)