#define NPattr_PADNAME 0x03
#define NPattr_PADTMP 0x04
#define NPattr_NOTE 0x05
-#define NPattr_PRE_ATTR 0x06
+#define NPattr_PRE_ATTR 0x06 /* deprecated */
#define _ADD_ATTR_NP(st, attr_type, attr_name, attr_value, np) (st->add_attr_cb && st->add_attr_cb(st, np, attr_type, attr_name, attr_value))
#define ADD_ATTR(st, attr_type, attr_name, attr_value) _ADD_ATTR_NP(st, attr_type, attr_name, attr_value, NP-1)
+#define ADD_LINK_ATTR(st, attr_type, attr_name, attr_value) (assert(NP->seqn), _ADD_ATTR_NP(st, attr_type, attr_name, attr_value, NP))
#define ADD_PRE_ATTR(st, attr_type, attr_name, attr_value) (assert(!attr_type), _ADD_ATTR_NP(st, NPattr_PRE_ATTR, attr_name, attr_value, NP-1))
#define _NPathLink(np, nid, ntype) (((np)->id=nid), ((np)->type=ntype), ((np)->seqn=0))
SSize_t i = AvFILLp(thing) + 1;
while (i--) {
- ADD_PRE_ATTR(st, 0, "index", i);
- sv_size(aTHX_ st, NPathLink("AVelem"), AvARRAY(thing)[i], recurse);
+ if (sv_size(aTHX_ st, NPathLink("AVelem"), AvARRAY(thing)[i], recurse))
+ ADD_LINK_ATTR(st, NPattr_NOTE, "i", i);
}
}
}
free_memnode_state(pTHX_ struct state *st)
{
if (st->node_stream_fh && st->node_stream_name && *st->node_stream_name) {
- fprintf(st->node_stream_fh, "E %lu %f %s\n",
+ fprintf(st->node_stream_fh, "E %d %f %s\n",
getpid(), gettimeofday_nv()-st->start_time_nv, "unnamed");
if (*st->node_stream_name == '|') {
if (pclose(st->node_stream_fh))
croak("Can't open '%s' for writing: %s", st->node_stream_name, strerror(errno));
if(0)setlinebuf(st->node_stream_fh); /* XXX temporary for debugging */
st->add_attr_cb = np_stream_node_path_info;
- fprintf(st->node_stream_fh, "S %lu %f %s\n",
+ fprintf(st->node_stream_fh, "S %d %f %s\n",
getpid(), st->start_time_nv, "unnamed");
}
else
use constant NPattr_PADTMP => 0x04;
use constant NPattr_NOTE => 0x05;
use constant NPattr_PRE_ATTR => 0x06;
+my @attr_type_name = (qw(size NAME PADFAKE my PADTMP NOTE PREATTR)); # XXX get from XS in some way
GetOptions(
sub enter_node {
my $x = shift;
- warn "enter_node $x->{id}\n" if $opt_debug;
+ warn ">> enter_node $x->{id}\n" if $opt_debug;
my $parent = $stack[-1];
if ($parent) {
if ($x->{name} eq 'AVelem' and $parent->{name} eq 'SV(PVAV)') {
- my $index = $x->{attr}{index};
+ my $index = $x->{attr}{+NPattr_NOTE}{i};
+ Dwarn $x->{attr};
+ Dwarn $index;
# If node is an AVelem of a CvPADLIST propagate pad name to AVelem
if (@stack >= 4 and (my $cvpl = $stack[-4])->{name} eq 'CvPADLIST') {
my $padnames = $cvpl->{_cached}{padnames} ||= do {
$x->{name} = "[$index]" if defined $index;
}
}
+
}
return $x;
sub leave_node {
my $x = shift;
confess unless defined $x->{id};
- warn "leave_node $x->{id}\n" if $opt_debug;
+ warn "<< leave_node $x->{id}\n" if $opt_debug;
delete $seqn2node{$x->{id}};
my $self_size = 0; $self_size += $_ for values %{$x->{leaves}};
$x->{self_size} = $self_size;
+ if ($x->{name} eq 'AVelem') {
+ my $index = $x->{attr}{+NPattr_NOTE}{i};
+ $x->{name} = "[$index]" if defined $index;
+ }
+
my $parent = $stack[-1];
if ($parent) {
# link to parent
$parent ? $parent->{id} : "",
$parent ? $parent->{type} : ""
if 0;
+
if ($x->{type} != NPtype_LINK) {
my $name = $x->{title} ? "\"$x->{title}\" $x->{name}" : $x->{name};
sprintf("label=%s", $dotnode->($name)),
"id=$x->{id}",
);
- my @link_attr;
- #if ($x->{name} eq 'hek') { push @node_attr, "shape=point"; push @node_attr, "labelfontsize=6"; }
- if ($parent) { # probably a link
- my $parent_id = $parent->{id};
- my @link_attr = ("id=$parent_id");
- if ($parent->{type} == NPtype_LINK) { # link
- (my $link_name = $parent->{name}) =~ s/->$//;
- push @link_attr, (sprintf "label=%s", $dotnode->($link_name));
- $parent_id = ($stack[-2]||die "panic")->{id};
- }
+ printf $dot_fh qq{n%d [ %s ];\n}, $x->{id}, join(",", @node_attr);
+ }
+ else { # NPtype_LINK
+ my @kids = @{$x->{child_id}};
+ die "panic: NPtype_LINK has more than one child: @kids"
+ if @kids > 1;
+ for my $child_id (@kids) { # wouldn't work right, eg id= attr
+ #die Dwarn $x;
+ my @link_attr = ("id=$x->{id}");
+ (my $link_name = $x->{name}) =~ s/->$//;
+ push @link_attr, (sprintf "label=%s", $dotnode->($link_name));
printf $dot_fh qq{n%d -> n%d [%s];\n},
- $parent_id, $x->{id}, join(",", @link_attr);
+ $x->{parent_id}, $child_id, join(",", @link_attr);
}
- printf $dot_fh qq{n%d [ %s ];\n}, $x->{id}, join(",", @node_attr);
}
}
}
my $indent = ": ";
-my @attr_type_name = (qw(size NAME PADFAKE my PADTMP NOTE)); # XXX get from XS in some way
my $pending_pre_attr = {};
while (<>) {
- warn $_ if $opt_debug;
+ warn "== $_" if $opt_debug;
chomp;
my ($type, $id, $val, $name, $extra) = split / /, $_, 5;
if $opt_text;
warn "Node $id already has attribute $type:$name (value $attr->{$type}{$name})\n"
if exists $attr->{$type}{$name};
- $attr->{$type}{$name} = $val || $id;
- $node->{title} = $name if $type == 1 and !$val;
+ $attr->{$type}{$name} = $val;
+ Dwarn $attr;
+ $node->{title} = $name if $type == NPattr_NAME and !$val; # XXX hack
}
# attributes where the number is a key (or always zero)
elsif (NPattr_PADFAKE==$type or NPattr_PADTMP==$type or NPattr_PADNAME==$type) {