Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Dump .fallback for VarWithFallback when doing --target=ast.
Generalize printing out of tagged children nodes.
  • Loading branch information
pmurias committed Oct 23, 2015
1 parent 78a6682 commit ba972b6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
22 changes: 21 additions & 1 deletion src/QAST/Children.nqp
Expand Up @@ -31,7 +31,27 @@ role QAST::Children {
}
}

method extra_children() {
[];
}

method dump_children(int $indent, @onto) {
self.dump_node_list($indent, @onto, @!children);
my $extra := 0;
for self.extra_children -> $tag, $nodes {
if $nodes {
nqp::push(@onto, nqp::x(' ', $indent));
nqp::push(@onto, "[" ~ $tag ~ "]");
nqp::push(@onto, "\n");
self.dump_node_list($indent+2, @onto, $nodes);
}
$extra := $extra + nqp::elems($nodes);
}

if $extra && @!children {
nqp::push(@onto, nqp::x(' ', $indent) ~ "[children]\n");
self.dump_node_list($indent+2, @onto, @!children);
} else {
self.dump_node_list($indent, @onto, @!children);
}
}
}
20 changes: 5 additions & 15 deletions src/QAST/CompUnit.nqp
Expand Up @@ -59,20 +59,10 @@ class QAST::CompUnit is QAST::Node does QAST::Children {
$!code_ref_blocks := $value unless $value =:= NO_VALUE; $!code_ref_blocks
}

method dump_children(int $indent, @onto) {
if self.pre_deserialize {
nqp::push(@onto, nqp::x(' ', $indent) ~ "[pre deserialize]\n");
self.dump_node_list($indent, @onto, self.pre_deserialize);
}

if self.post_deserialize {
nqp::push(@onto, nqp::x(' ', $indent) ~ "[post deserialize]\n");
self.dump_node_list($indent, @onto, self.post_deserialize);
}

if self.pre_deserialize || self.post_deserialize {
nqp::push(@onto, nqp::x(' ', $indent) ~ "[children]\n")
}
self.dump_node_list($indent, @onto, self.list);
method extra_children() {
[
'pre_deserialize', self.pre_deserialize,
'post_deserialize', self.post_deserialize
];
}
}
4 changes: 4 additions & 0 deletions src/QAST/VarWithFallback.nqp
@@ -1,4 +1,8 @@
class QAST::VarWithFallback is QAST::Var {
has $!fallback;
method fallback($value = NO_VALUE) { $!fallback := $value unless $value =:= NO_VALUE; $!fallback }

method extra_children() {
$!fallback ?? ['fallback', [$!fallback]] !! [];
}
}

0 comments on commit ba972b6

Please sign in to comment.