| 1 | # You may distribute under the terms of either the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # (C) Paul Evans, 2013-2026 -- leonerd@leonerd.org.uk | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | package Devel::MAT::Tool::Reachability 0.56; | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use feature qw( postderef signatures ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | no warnings qw( experimental::postderef experimental::signatures ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use constant FOR_UI => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use List::Util qw( pairvalues ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | C<Devel::MAT::Tool::Reachability> - analyse how SVs are reachable | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | This C<Devel::MAT> tool determines which SVs are reachable via any known roots | ||||||||||||||||||||||||||||||||||||||||||
| 25 | and which are not. For reachable SVs, they are classified into several broad | ||||||||||||||||||||||||||||||||||||||||||
| 26 | categories: | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | SVs that directly make up the symbol table. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | SVs that form the padlist of functions or store the names of lexical | ||||||||||||||||||||||||||||||||||||||||||
| 37 | variables. | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | SVs that hold the value of lexical variables. | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | User data stored in package globals, lexical variables, or referenced | ||||||||||||||||||||||||||||||||||||||||||
| 46 | recursively via structures stored in them. | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | Miscellaneous other SVs that are used to implement the internals of the | ||||||||||||||||||||||||||||||||||||||||||
| 51 | interpreter. | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 5 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | REACH_SYMTAB => 1, | |||||||||||||||||||||||||||||||||||||||||
| 59 | REACH_USER => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | REACH_PADLIST => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | REACH_LEXICAL => 4, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | REACH_INTERNAL => 5, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | sub new ( $class, $pmat, %args ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | *Devel::MAT::SV::reachable = sub ( $sv ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | return $sv->{tool_reachable}; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | $class->mark_reachable( $pmat->dumpfile, progress => $args{progress} ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | return $class; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | my @ICONS = ( | |||||||||||||||||||||||||||||||||||||||||
| 77 | "none", "symtab", "user", "padlist", "lexical", "internal" | ||||||||||||||||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub _reach2icon ( $sv ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reach2icon: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $reach = $sv->{tool_reachable} // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$sv->{"tool_reachable"} // 0
MC/DC0%0/1
$sv->{"tool_reachable"} // 0
$sv->{"tool_reachable"}
Truth table0%0/2
A
A= $sv->{"tool_reachable"}
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $icon = $ICONS[$reach] // die "Unknown reachability value $reach"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ICONS[$reach] // die("Unknown reachability value $reach")
MC/DC0%0/1
$ICONS[$reach] // die("Unknown reachability value $reach")
$ICONS[$reach]
Truth table0%0/2
A
A= $ICONS[$reach]
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | return "reachable-$icon"; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub init_ui ( $self, $ui ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_ui: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | foreach ( @ICONS ) { | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $ui->register_icon( | |||||||||||||||||||||||||||||||||||||||||
| 91 | name => "reachable-$_", | ||||||||||||||||||||||||||||||||||||||||||
| 92 | svg => "icons/reachable-$_.svg" | ||||||||||||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $column = $ui->provides_svlist_column( | |||||||||||||||||||||||||||||||||||||||||
| 97 | title => "R", | ||||||||||||||||||||||||||||||||||||||||||
| 98 | type => "icon", | ||||||||||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $ui->provides_sv_detail( | |||||||||||||||||||||||||||||||||||||||||
| 102 | title => "Reachable", | ||||||||||||||||||||||||||||||||||||||||||
| 103 | type => "icon", | ||||||||||||||||||||||||||||||||||||||||||
| 104 | render => \&_reach2icon, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $ui->set_svlist_column_values( | |||||||||||||||||||||||||||||||||||||||||
| 108 | column => $column, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | from => \&_reach2icon, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | sub mark_reachable ( $self, $df, %args ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mark_reachable: called CC=68 SCAR=48.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | my $progress = $args{progress}; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | my @user; | |||||||||||||||||||||||||||||||||||||||||
| 118 | my @internal; | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | # First, walk the symbol table | ||||||||||||||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | my @symtab = ( $df->defstash ); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | $symtab[0]->{tool_reachable} = REACH_SYMTAB; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | while( @symtab ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 425 | my $stash = shift @symtab; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 425 | ▶ | $stash->type =~ m/^(?:STASH|CLASS)$/ or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | die "ARGH! Encountered non-stash ".$stash->desc_addr; | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 425 | my @more_symtab; | |||||||||||||||||||||||||||||||||||||||||
| 132 | my @more_user; | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 425 | foreach my $key ( $stash->keys ) { | |||||||||||||||||||||||||||||||||||||||||
| 135 | 10428 | my $value = $stash->value( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | # Keys ending :: signify sub-stashes | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 10428 | ▶ | if( $key =~ m/::$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 425 | push @more_symtab, $value->hash; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | # Otherwise it might be a glob | ||||||||||||||||||||||||||||||||||||||||||
| 142 | elsif( $value->type eq "GLOB" ) { | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 9970 | my $gv = $value; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 9970 | $gv->{tool_reachable} = REACH_SYMTAB; | |||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 9970 | ▶ | defined $_ and push @more_user, $_ for | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | $gv->scalar, $gv->array, $gv->hash, $gv->code, $gv->io, $gv->form; | ||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | # Otherwise it might be a SCALAR/ARRAY/HASH directly in the STASH | ||||||||||||||||||||||||||||||||||||||||||
| 150 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 33 | push @more_user, $value; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 10428 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 10428 | ▶ | $progress->( sprintf "Walking symbol table %d...", $count ) if $progress and $count % 1000 == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$progress and $count % 1000 == 0
MC/DC0%0/2
$progress and $count % 1000 == 0
$progress
$count % 1000 == 0
Truth table33%1/3
A and B
A= $progressB= $count % 1000 == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | !$_->{tool_reachable} and | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 425 | ▶ | $_->{tool_reachable} = REACH_SYMTAB, push @symtab, $_ for @more_symtab; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | !$_->{tool_reachable} and | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 425 | ▶ | $_->{tool_reachable} = REACH_USER, push @user, $_ for @more_user; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | !$_->{tool_reachable} and | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 425 | ▶ | $_->{tool_reachable} = REACH_INTERNAL, push @internal, $_ for grep { defined } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | $stash->backrefs, | ||||||||||||||||||||||||||||||||||||||||||
| 167 | $stash->mro_linearall, | ||||||||||||||||||||||||||||||||||||||||||
| 168 | $stash->mro_linearcurrent, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | $stash->mro_nextmethod, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | $stash->mro_isa, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | $stash->magic_svs; | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 425 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 425 | ▶ | $progress->( sprintf "Walking symbol table %d...", $count ) if $progress and $count % 1000 == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$progress and $count % 1000 == 0
MC/DC0%0/2
$progress and $count % 1000 == 0
$progress
$count % 1000 == 0
Truth table33%1/3
A and B
A= $progressB= $count % 1000 == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | # Next the reachable user data, recursively | ||||||||||||||||||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | push @user, $df->main_cv; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | ▶ | while( @user ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 35331 | ▶ | my $sv = shift @user or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 35331 | my @more_user; | |||||||||||||||||||||||||||||||||||||||||
| 186 | my @more_internal; | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 35331 | for( $sv->type ) { | |||||||||||||||||||||||||||||||||||||||||
| 189 | 35331 | ▶ | if ( $_ eq "REF" ) { push @more_user, $sv->rv if $sv->rv } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 598 | elsif( $_ eq "ARRAY" ) { push @more_user, $sv->elems; } | |||||||||||||||||||||||||||||||||||||||||
| 191 | 637 | elsif( $_ eq "HASH" ) { push @more_user, $sv->values; } | |||||||||||||||||||||||||||||||||||||||||
| 192 | elsif( $_ eq "GLOB" ) { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | my $gv = $sv; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | ▶ | next if $gv->{tool_reachable}; # already on symbol table | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | warn "Found non-SYMTAB GLOB " . $gv->desc_addr . " user reachable\n"; | |||||||||||||||||||||||||||||||||||||||||
| 197 | # Hard to know if the GV is being used for GVSV, GVAV, GVHV or GVCV | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | push @more_user, $gv->scalar, $gv->array, $gv->hash, $gv->code, $gv->egv, $gv->io, $gv->form; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | elsif( $_ eq "CODE" ) { | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 7054 | my $cv = $sv; | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 7054 | my @more_padlist; | |||||||||||||||||||||||||||||||||||||||||
| 204 | my @more_lexical; | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 7054 | push @more_padlist, $cv->padlist; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 7054 | my $padnames_av = $cv->padnames_av; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 7054 | ▶ | if( $padnames_av ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | push @more_padlist, $padnames_av, $padnames_av->elems; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 7054 | foreach my $pad ( $cv->pads ) { | |||||||||||||||||||||||||||||||||||||||||
| 214 | 3793 | ▶ | $pad or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 3791 | push @more_padlist, $pad; | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | # PAD slot 0 is always @_ | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 3791 | ▶ | if( my $argsav = $pad->elem( 0 ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 3562 | push @more_internal, $argsav; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 3791 | foreach my $padix ( 1 .. $pad->elems-1 ) { | |||||||||||||||||||||||||||||||||||||||||
| 223 | 39488 | ▶ | my $padname_sv = $padnames_av ? $padnames_av->elem( $padix ) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 39488 | ▶ | my $padname = $padname_sv && $padname_sv->type eq "SCALAR" ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$padname_sv and $padname_sv->type eq "SCALAR"
MC/DC0%0/2
$padname_sv and $padname_sv->type eq "SCALAR"
$padname_sv
$padname_sv->type eq "SCALAR"
Truth table33%1/3
A and B
A= $padname_svB= $padname_sv->type eq "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | $padname_sv->pv : undef; | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 39488 | ▶ | my $padsv = $pad->elem( $padix ) or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 39277 | ▶ | $padsv->immortal and next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 39277 | ▶ | if( $padname and $padname eq "&" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$padname and $padname eq "&"
MC/DC0%0/2
$padname and $padname eq "&"
$padname
$padname eq "&"
Truth table33%1/3
A and B
A= $padnameB= $padname eq "&"
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | # Slots named "&" are closure prototype subs | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | push @more_user, $padsv; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | elsif( $padname ) { | ||||||||||||||||||||||||||||||||||||||||||
| 235 | # Other named slots are lexical vars | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | push @more_lexical, $padsv; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | # Unnamed slots are just part of the padlist | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 39277 | push @more_internal, $padsv; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 7054 | ▶ | $_ and push @more_user, $_ for | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | $cv->scope, $cv->constval, $cv->constants, $cv->globrefs; | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | $_ and !$_->{tool_reachable} and | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 7054 | ▶ | $_->{tool_reachable} = REACH_PADLIST for @more_padlist; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_ and not $_->{"tool_reachable"}
MC/DC50%1/2
$_ and not $_->{"tool_reachable"}
$_
not $_->{"tool_reachable"}
Truth table66%2/3
A and not(B)
A= $_B= not $_->{"tool_reachable"}
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | $_ and !$_->{tool_reachable} and | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 7054 | ▶ | $_->{tool_reachable} = REACH_LEXICAL, push @user, $_ for @more_lexical; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ and not $_->{"tool_reachable"}
MC/DC0%0/2
$_ and not $_->{"tool_reachable"}
$_
not $_->{"tool_reachable"}
Truth table0%0/3
A and not(B)
A= $_B= not $_->{"tool_reachable"}
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | elsif( $_ eq "LVALUE" ) { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $lv = $sv; | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | push @more_internal, $lv->target if $lv->target; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | elsif( $_ =~ m/^(?:UNDEF|BOOL|SCALAR|IO|REGEXP|FORMAT)$/ ) { } # ignore | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | else { warn "Not sure what to do with user data item ".$sv->desc_addr."\n"; } | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | $_ and !$_->{tool_reachable} and !$_->immortal and | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 35331 | ▶ | $_->{tool_reachable} = REACH_USER, push @user, $_ for @more_user; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$_ and not $_->{"tool_reachable"} and not $_->immortal
$_ and not $_->{"tool_reachable"}
MC/DC66%2/3
$_ and not $_->{"tool_reachable"} and not $_->immortal
$_
not $_->{"tool_reachable"}
not $_->immortal
Truth table75%3/4
A and not(B) and not(C)
A= $_B= not $_->{"tool_reachable"}C= not $_->immortal
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | $_ and !$_->{tool_reachable} and !$_->immortal and | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 35331 | $_->{tool_reachable} = REACH_INTERNAL, push @internal, $_ for | |||||||||||||||||||||||||||||||||||||||||
| 269 | @more_internal, | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 464 | ▶ | grep { defined } $sv->magic_svs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$_ and not $_->{"tool_reachable"} and not $_->immortal
$_ and not $_->{"tool_reachable"}
MC/DC33%1/3
$_ and not $_->{"tool_reachable"} and not $_->immortal
$_
not $_->{"tool_reachable"}
not $_->immortal
Truth table50%2/4
A and not(B) and not(C)
A= $_B= not $_->{"tool_reachable"}C= not $_->immortal
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 35331 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 35331 | ▶ | $progress->( sprintf "Marking user reachability %d...", $count ) if $progress and $count % 1000 == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$progress and $count % 1000 == 0
MC/DC0%0/2
$progress and $count % 1000 == 0
$progress
$count % 1000 == 0
Truth table33%1/3
A and B
A= $progressB= $count % 1000 == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | # Finally internals | ||||||||||||||||||||||||||||||||||||||||||
| 278 | { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | push @internal, pairvalues $df->roots; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 1 | ▶ | while( @internal ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 43685 | ▶ | my $sv = shift @internal or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 43664 | ▶ | next if $sv->{tool_reachable}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 256 | $sv->{tool_reachable} = REACH_INTERNAL; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 256 | ▶ | push @internal, map { $_->sv ? $_->sv : () } $sv->outrefs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 256 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 256 | ▶ | $progress->( sprintf "Marking internal reachability %d...", $count ) if $progress and $count % 1000 == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$progress and $count % 1000 == 0
MC/DC0%0/2
$progress and $count % 1000 == 0
$progress
$count % 1000 == 0
Truth table33%1/3
A and B
A= $progressB= $count % 1000 == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | =head1 SV METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | =for highlighter language=perl | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | This tool adds the following SV methods. | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | =head2 reachable | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | $r = $sv->reachable; | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | Returns true if the SV is reachable from a known root. | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 5 | 0x55AA; | |||||||||||||||||||||||||||||||||||||||||