Skip to content

Commit 1c2c101

Browse files
committed
support for dumping annotations
1 parent 60b9e20 commit 1c2c101

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/QAST/Children.nqp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ role QAST::Children {
2929
nqp::push(@onto, "\n");
3030
}
3131
}
32+
CATCH { nqp::push(@onto, "Oops!!!") }
3233
}
3334

3435
method extra_children() {

src/QAST/Node.nqp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,36 +109,43 @@ class QAST::Node {
109109
if nqp::chars($extra) {
110110
nqp::push(@chunks, "($extra)");
111111
}
112+
nqp::push(@chunks, ' ');
113+
nqp::push(@chunks, self.dump_annotations);
114+
if (self.node) {
115+
nqp::push(@chunks, ' ');
116+
my $escaped_node := nqp::escape(self.node);
117+
nqp::push(@chunks, nqp::substr($escaped_node, 0, 50));
118+
if (nqp::chars($escaped_node) > 50) {
119+
nqp::push(@chunks, "...");
120+
}
121+
}
122+
nqp::push(@chunks, "\n");
123+
self.dump_children($indent + 2, @chunks);
124+
return join('', @chunks);
125+
}
126+
127+
method dump_annotations() {
128+
my @anns;
112129
if nqp::ishash(%!annotations) {
113130
for %!annotations {
114131
my $k := $_.key;
115-
nqp::push(@chunks, ' :' ~ $k);
116132
my $v := $_.value;
117133
try {
118134
if nqp::isconcrete($v) {
119-
if $k eq 'context' {
120-
nqp::push(@chunks, '<' ~ $v ~ '>');
135+
if $k eq 'context' || $k eq 'IN_DECL' || $k eq 'BY' {
136+
nqp::push(@anns, ':' ~ $k ~ '<' ~ $v ~ '>');
121137
}
122138
elsif $k eq 'sink_ok' || $k eq 'WANTED' || $k eq 'final' {
139+
nqp::push(@anns, ':' ~ $k);
123140
}
124141
else { # dunno how to introspect
125-
nqp::push(@chunks, '<?>');
142+
nqp::push(@anns, ':' ~ $k ~ '<?>');
126143
}
127144
}
128145
}
129146
}
130147
}
131-
if (self.node) {
132-
nqp::push(@chunks, ' ');
133-
my $escaped_node := nqp::escape(self.node);
134-
nqp::push(@chunks, nqp::substr($escaped_node, 0, 50));
135-
if (nqp::chars($escaped_node) > 50) {
136-
nqp::push(@chunks, "...");
137-
}
138-
}
139-
nqp::push(@chunks, "\n");
140-
self.dump_children($indent + 2, @chunks);
141-
return join('', @chunks);
148+
nqp::join(' ',@anns);
142149
}
143150

144151
method dump_children(int $indent, @onto) { }

src/QAST/WVal.nqp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class QAST::WVal is QAST::Node does QAST::CompileTimeValue {
2323
}
2424

2525
method dump_extra_node_info() {
26+
CATCH { return "?" }
2627
my $v := self.compile_time_value();
2728
$v.HOW.name($v);
2829
}

0 commit comments

Comments
 (0)