| 1 | # B::DeparseTree::P518.pm | ||
| 2 | # Copyright (c) 1998-2000, 2002, 2003, 2004, 2005, 2006 Stephen McCamant. | ||
| 3 | # Copyright (c) 2015, 2018 Rocky Bernstein | ||
| 4 | # All rights reserved. | ||
| 5 | # This module is free software; you can redistribute and/or modify | ||
| 6 | # it under the same terms as Perl itself. | ||
| 7 | |||
| 8 | # This is based on the module B::Deparse (for perl 5.20) by Stephen McCamant. | ||
| 9 | # It has been extended save tree structure, and is addressible | ||
| 10 | # by opcode address. | ||
| 11 | |||
| 12 | # B::Parse in turn is based on the module of the same name by Malcolm Beattie, | ||
| 13 | # but essentially none of his code remains. | ||
| 14 | |||
| 15 | use v5.16; | ||
| 16 | |||
| 17 | use rlib '../..'; | ||
| 18 | |||
| 19 | package B::DeparseTree::P518; | ||
| 20 | use Carp; | ||
| 21 | use B qw(class opnumber | ||
| 22 | OPf_KIDS OPf_REF OPf_STACKED OPf_SPECIAL OPf_MOD | ||
| 23 | OPpLVAL_INTRO OPpOUR_INTRO OPpENTERSUB_AMPER OPpSLICE OPpCONST_BARE | ||
| 24 | PMf_KEEP PMf_GLOBAL PMf_CONTINUE PMf_EVAL PMf_ONCE | ||
| 25 | SVpad_OUR SVf_FAKE SVs_RMG SVs_SMG | ||
| 26 | PMf_MULTILINE PMf_SINGLELINE PMf_FOLD PMf_EXTENDED); | ||
| 27 | |||
| 28 | use B::DeparseTree::PPfns; | ||
| 29 | use B::DeparseTree::SyntaxTree; | ||
| 30 | use B::DeparseTree::PP; | ||
| 31 | use B::Deparse; | ||
| 32 | |||
| 33 | # Copy unchanged functions from B::Deparse | ||
| 34 | *begin_is_use = *B::Deparse::begin_is_use; | ||
| 35 | *const_sv = *B::Deparse::const_sv; | ||
| 36 | *escape_extended_re = *B::Deparse::escape_extended_re; | ||
| 37 | *find_scope_en = *B::Deparse::find_scope_en; | ||
| 38 | *padany = *B::Deparse::padany; | ||
| 39 | *padname = *B::Deparse::padname; | ||
| 40 | *gv_name = *B::Deparse::gv_name; | ||
| 41 | *padname_sv = *B::Deparse::padname_sv; | ||
| 42 | *padval = *B::Deparse::padval; | ||
| 43 | *populate_curcvlex = *B::Deparse::populate_curcvlex; | ||
| 44 | *find_our_type = *B::Deparse::find_our_type; | ||
| 45 | *re_flags = *B::Deparse::re_flags; | ||
| 46 | *stash_variable = *B::Deparse::stash_variable; | ||
| 47 | *stash_variable_name = *B::Deparse::stash_variable_name; | ||
| 48 | *tr_chr = *B::Deparse::tr_chr; | ||
| 49 | |||
| 50 | use strict; | ||
| 51 | use vars qw/$AUTOLOAD/; | ||
| 52 | use warnings (); | ||
| 53 | require feature; | ||
| 54 | |||
| 55 | our(@EXPORT, @ISA); | ||
| 56 | our $VERSION = '3.2.0'; | ||
| 57 | |||
| 58 | @ISA = qw(Exporter); | ||
| 59 | |||
| 60 | BEGIN { | ||
| 61 | # List version-specific constants here. | ||
| 62 | # Easiest way to keep this code portable between version looks to | ||
| 63 | # be to fake up a dummy constant that will never actually be true. | ||
| 64 | foreach (qw(OPpSORT_INPLACE OPpSORT_DESCEND OPpITER_REVERSED OPpCONST_NOVER | ||
| 65 | OPpPAD_STATE PMf_SKIPWHITE RXf_SKIPWHITE | ||
| 66 | RXf_PMf_CHARSET RXf_PMf_KEEPCOPY | ||
| 67 | CVf_LOCKED OPpREVERSE_INPLACE OPpSUBSTR_REPL_FIRST | ||
| 68 | PMf_NONDESTRUCT OPpCONST_ARYBASE OPpEVAL_BYTES)) { | ||
| 69 | eval { import B $_ }; | ||
| 70 | no strict 'refs'; | ||
| 71 | *{$_} = sub () {0} unless *{$_}{CODE}; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | BEGIN { for (qw[rv2sv]) { | ||
| 76 | eval "sub OP_\U$_ () { " . opnumber($_) . "}" | ||
| 77 | }} | ||
| 78 | |||
| 79 | # The following OPs don't have functions: | ||
| 80 | |||
| 81 | # pp_padany -- does not exist after parsing | ||
| 82 | |||
| 83 | sub AUTOLOAD { | ||
| 84 | if ($AUTOLOAD =~ s/^.*::pp_//) { | ||
| 85 | warn "unexpected OP_".uc $AUTOLOAD; | ||
| 86 | } else { | ||
| 87 | Carp::confess "Undefined subroutine $AUTOLOAD called"; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | sub DESTROY {} # Do not AUTOLOAD | ||
| 92 | |||
| 93 | # The BEGIN {} is used here because otherwise this code isn't executed | ||
| 94 | # when you run B::Deparse on itself. | ||
| 95 | my %globalnames; | ||
| 96 | BEGIN { map($globalnames{$_}++, "SIG", "STDIN", "STDOUT", "STDERR", "INC", | ||
| 97 | "ENV", "ARGV", "ARGVOUT", "_"); } | ||
| 98 | |||
| 99 | sub gv_name { | ||
| 100 | my $self = shift; | ||
| 101 | my $gv = shift; | ||
| 102 | my $raw = shift; | ||
| 103 | Carp::confess() unless ref($gv) eq "B::GV"; | ||
| 104 | my $stash = $gv->STASH->NAME; | ||
| 105 | my $name = $raw ? $gv->NAME : $gv->SAFENAME; | ||
| 106 | if ($stash eq 'main' && $name =~ /^::/) { | ||
| 107 | $stash = '::'; | ||
| 108 | } | ||
| 109 | elsif (($stash eq 'main' | ||
| 110 | && ($globalnames{$name} || $name =~ /^[^A-Za-z_:]/)) | ||
| 111 | or ($stash eq $self->{'curstash'} && !$globalnames{$name} | ||
| 112 | && ($stash eq 'main' || $name !~ /::/)) | ||
| 113 | ) | ||
| 114 | { | ||
| 115 | $stash = ""; | ||
| 116 | } else { | ||
| 117 | $stash = $stash . "::"; | ||
| 118 | } | ||
| 119 | if (!$raw and $name =~ /^(\^..|{)/) { | ||
| 120 | $name = "{$name}"; # ${^WARNING_BITS}, etc and ${ | ||
| 121 | } | ||
| 122 | return $stash . $name; | ||
| 123 | } | ||
| 124 | |||
| 125 | my %feature_keywords = ( | ||
| 126 | # keyword => 'feature', | ||
| 127 | state => 'state', | ||
| 128 | say => 'say', | ||
| 129 | given => 'switch', | ||
| 130 | when => 'switch', | ||
| 131 | default => 'switch', | ||
| 132 | break => 'switch', | ||
| 133 | evalbytes=>'evalbytes', | ||
| 134 | __SUB__ => '__SUB__', | ||
| 135 | fc => 'fc', | ||
| 136 | ); | ||
| 137 | |||
| 138 | # keywords that are strong and also have a prototype | ||
| 139 | # | ||
| 140 | my %strong_proto_keywords = map { $_ => 1 } qw( | ||
| 141 | pos | ||
| 142 | prototype | ||
| 143 | scalar | ||
| 144 | study | ||
| 145 | undef | ||
| 146 | ); | ||
| 147 | |||
| 148 | # FIXME: These we don't seem to be able to put in a table. | ||
| 149 | sub pp_closedir { unop(@_, "closedir") } | ||
| 150 | |||
| 151 | # NOTE: This is the deparse 5.26 routine which | ||
| 152 | # differs from 5.18 in that adds CORE:: when | ||
| 153 | # appropriate. | ||
| 154 | sub keyword { | ||
| 155 | my $self = shift; | ||
| 156 | my $name = shift; | ||
| 157 | return $name if $name =~ /^CORE::/; # just in case | ||
| 158 | if (exists $feature_keywords{$name}) { | ||
| 159 | my $hh; | ||
| 160 | my $hints = $self->{hints} & $feature::hint_mask; | ||
| 161 | if ($hints && $hints != $feature::hint_mask) { | ||
| 162 | $hh = B::Deparse::_features_from_bundle($hints); | ||
| 163 | } | ||
| 164 | elsif ($hints) { $hh = $self->{'hinthash'} } | ||
| 165 | return "CORE::$name" | ||
| 166 | if !$hh | ||
| 167 | || !$hh->{"feature_$feature_keywords{$name}"} | ||
| 168 | } | ||
| 169 | if ($strong_proto_keywords{$name} | ||
| 170 | || ($name !~ /^(?:chom?p|do|exec|glob|s(?:elect|ystem))\z/ | ||
| 171 | && !defined eval{prototype "CORE::$name"}) | ||
| 172 | ) { return $name } | ||
| 173 | if ( | ||
| 174 | exists $self->{subs_declared}{$name} | ||
| 175 | or | ||
| 176 | exists &{"$self->{curstash}::$name"} | ||
| 177 | ) { | ||
| 178 | return "CORE::$name" | ||
| 179 | } | ||
| 180 | return $name; | ||
| 181 | } | ||
| 182 | |||
| 183 | { no strict 'refs'; *{"pp_r$_"} = *{"pp_$_"} for qw< keys each values >; } | ||
| 184 | |||
| 185 | sub pp_readline { | ||
| 186 | my $self = shift; | ||
| 187 | my($op, $cx) = @_; | ||
| 188 | my $kid = $op->first; | ||
| 189 | $kid = $kid->first if $kid->name eq "rv2gv"; # <$fh> | ||
| 190 | if (B::Deparse::is_scalar($kid)) { | ||
| 191 | my $body = [$self->deparse($kid, 1, $op)]; | ||
| 192 | return info_from_list($op, $self, ['<', $body->[0]{text}, '>'], '', | ||
| 193 | 'readline_scalar', {body=>$body}); | ||
| 194 | } | ||
| 195 | return $self->unop($op, $cx, "readline"); | ||
| 196 | } | ||
| 197 | |||
| 198 | sub pp_rcatline { | ||
| 199 | my $self = shift; | ||
| 200 | my($op) = @_; | ||
| 201 | return info_from_list($op, $self, ["<", $self->gv_name($self->gv_or_padgv($op)), ">"], | ||
| 202 | '', 'rcatline', {}); | ||
| 203 | } | ||
| 204 | |||
| 205 | sub pp_smartmatch { | ||
| 206 | my ($self, $op, $cx) = @_; | ||
| 207 | if ($op->flags & OPf_SPECIAL) { | ||
| 208 | return $self->deparse($op->last, $cx, $op); | ||
| 209 | } | ||
| 210 | else { | ||
| 211 | binop(@_, "~~", 14); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | sub bin_info_join($$$$$$$) { | ||
| 216 | my ($self, $op, $lhs, $rhs, $mid, $sep, $type) = @_; | ||
| 217 | my $texts = [$lhs->{text}, $mid, $rhs->{text}]; | ||
| 218 | return info_from_list($op, $self, $texts, ' ', $type, {}) | ||
| 219 | } | ||
| 220 | |||
| 221 | sub bin_info_join_maybe_parens($$$$$$$$$) { | ||
| 222 | my ($self, $op, $lhs, $rhs, $mid, $sep, $cx, $prec, $type) = @_; | ||
| 223 | my $info = bin_info_join($self, $op, $lhs, $rhs, $mid, $sep, $type); | ||
| 224 | $info->{text} = $self->maybe_parens($info->{text}, $cx, $prec); | ||
| 225 | return $info; | ||
| 226 | } | ||
| 227 | |||
| 228 | sub range { | ||
| 229 | my $self = shift; | ||
| 230 | my ($op, $cx, $type) = @_; | ||
| 231 | my $left = $op->first; | ||
| 232 | my $right = $left->sibling; | ||
| 233 | $left = $self->deparse($left, 9, $op); | ||
| 234 | $right = $self->deparse($right, 9, $op); | ||
| 235 | return info_from_list($op, $self, [$left, $type, $right], ' ', 'range', | ||
| 236 | {maybe_parens => [$self, $cx, 9]}); | ||
| 237 | } | ||
| 238 | |||
| 239 | sub pp_substr { | ||
| 240 | my ($self,$op,$cx) = @_; | ||
| 241 | if ($op->private & OPpSUBSTR_REPL_FIRST) { | ||
| 242 | my $left = listop($self, $op, 7, "substr", $op->first->sibling->sibling); | ||
| 243 | my $right = $self->deparse($op->first->sibling, 7, $op); | ||
| 244 | return info_from_list($op, $self,[$left, '=', $right], ' ', | ||
| 245 | 'substr_repl_first', {}); | ||
| 246 | } | ||
| 247 | return maybe_local(@_, listop(@_, "substr")) | ||
| 248 | } | ||
| 249 | sub pp_formline { listop(@_, "formline") } # see also deparse_format | ||
| 250 | sub pp_unpack { listop(@_, "unpack") } | ||
| 251 | sub pp_splice { listop(@_, "splice") } | ||
| 252 | sub pp_socket { listop(@_, "socket") } | ||
| 253 | sub pp_seekdir { listop(@_, "seekdir") } | ||
| 254 | |||
| 255 | sub for_loop { | ||
| 256 | my $self = shift; | ||
| 257 | my($op, $cx, $parent) = @_; | ||
| 258 | my $init = $self->deparse($op, 1, $parent); | ||
| 259 | my $s = $op->sibling; | ||
| 260 | my $ll = $s->name eq "unstack" ? $s->sibling : $s->first->sibling; | ||
| 261 | return $self->loop_common($ll, $cx, $init); | ||
| 262 | } | ||
| 263 | |||
| 264 | sub pp_padsv { | ||
| 265 | my $self = shift; | ||
| 266 | my($op, $cx, $forbid_parens) = @_; | ||
| 267 | return $self->maybe_my($op, $cx, $self->padname($op->targ), | ||
| 268 | $forbid_parens); | ||
| 269 | } | ||
| 270 | |||
| 271 | my @threadsv_names = B::threadsv_names; | ||
| 272 | sub pp_threadsv { | ||
| 273 | my $self = shift; | ||
| 274 | my($op, $cx) = @_; | ||
| 275 | return $self->maybe_local_str($op, $cx, "\$" . $threadsv_names[$op->targ]); | ||
| 276 | } | ||
| 277 | |||
| 278 | sub gv_or_padgv { | ||
| 279 | my $self = shift; | ||
| 280 | my $op = shift; | ||
| 281 | if (class($op) eq "PADOP") { | ||
| 282 | return $self->padval($op->padix); | ||
| 283 | } else { # class($op) eq "SVOP" | ||
| 284 | return $op->gv; | ||
| 285 | } | ||
| 286 | } | ||
| 287 | |||
| 288 | sub pp_aelemfast_lex | ||
| 289 | { | ||
| 290 | my($self, $op, $cx) = @_; | ||
| 291 | my $name = $self->padname($op->targ); | ||
| 292 | $name =~ s/^@/\$/; | ||
| 293 | return info_from_list($op, $self, [$name, "[", ($op->private + $self->{'arybase'}), "]"], | ||
| 294 | '', 'pp_aelemfast_lex', {}); | ||
| 295 | } | ||
| 296 | |||
| 297 | sub pp_aelemfast | ||
| 298 | { | ||
| 299 | my($self, $op, $cx) = @_; | ||
| 300 | # optimised PADAV, pre 5.15 | ||
| 301 | return $self->pp_aelemfast_lex(@_) if ($op->flags & OPf_SPECIAL); | ||
| 302 | |||
| 303 | my $gv = $self->gv_or_padgv($op); | ||
| 304 | my($name,$quoted) = $self->stash_variable_name('@',$gv); | ||
| 305 | $name = $quoted ? "$name->" : '$' . $name; | ||
| 306 | my $i = $op->private; | ||
| 307 | $i -= 256 if $i > 127; | ||
| 308 | return info_from_list($op, $self, [$name, "[", ($op->private + $self->{'arybase'}), "]"], | ||
| 309 | '', 'pp_aelemfast', {}); | ||
| 310 | } | ||
| 311 | |||
| 312 | sub pp_rv2sv { maybe_local(@_, rv2x(@_, "\$")) } | ||
| 313 | sub pp_rv2hv { maybe_local(@_, rv2x(@_, "%")) } | ||
| 314 | sub pp_rv2gv { maybe_local(@_, rv2x(@_, "*")) } | ||
| 315 | |||
| 316 | # skip rv2av | ||
| 317 | sub pp_av2arylen { | ||
| 318 | my $self = shift; | ||
| 319 | my($op, $cx) = @_; | ||
| 320 | if ($op->first->name eq "padav") { | ||
| 321 | return $self->maybe_local_str($op, $cx, '$#' . $self->padany($op->first)); | ||
| 322 | } else { | ||
| 323 | return $self->maybe_local($op, $cx, | ||
| 324 | $self->rv2x($op->first, $cx, '$#')); | ||
| 325 | } | ||
| 326 | } | ||
| 327 | |||
| 328 | sub list_const($$$) { | ||
| 329 | my $self = shift; | ||
| 330 | my($op, $cx, @list) = @_; | ||
| 331 | my @a = map $self->const($_, 6), @list; | ||
| 332 | my @texts = $self->map_texts(\@a); | ||
| 333 | my $type = 'list_const'; | ||
| 334 | my $prec = 6; | ||
| 335 | if (@texts == 0) { | ||
| 336 | return info_from_list($op, $self, ['(', ')'], '', 'list_const_null', {}); | ||
| 337 | } elsif (@texts == 1) { | ||
| 338 | return info_from_text($op, $self, $texts[0], 'list_const_one', | ||
| 339 | {body => \@a}); | ||
| 340 | } elsif ( @texts > 2 and !grep(!/^-?\d+$/, @texts)) { | ||
| 341 | # collapse (-1,0,1,2) into (-1..2) | ||
| 342 | my ($s, $e) = @texts[0,-1]; | ||
| 343 | my $i = $s; | ||
| 344 | unless (grep $i++ != $_, @texts) { | ||
| 345 | @texts = ($s, '..', $e); | ||
| 346 | $type = 'list_const_range'; | ||
| 347 | $prec = 9; | ||
| 348 | } | ||
| 349 | } | ||
| 350 | return info_from_list($op, $self, \@texts, '', $type, | ||
| 351 | {maybe_parens => [$self, $cx, $prec]}); | ||
| 352 | } | ||
| 353 | |||
| 354 | sub pp_rv2av { | ||
| 355 | my $self = shift; | ||
| 356 | my($op, $cx) = @_; | ||
| 357 | my $kid = $op->first; | ||
| 358 | if ($kid->name eq "const") { # constant list | ||
| 359 | my $av = $self->const_sv($kid); | ||
| 360 | return $self->list_const($kid, $cx, $av->ARRAY); | ||
| 361 | } else { | ||
| 362 | # FIXME? | ||
| 363 | return $self->maybe_local($op, $cx, $self->rv2x($op, $cx, "\@")); | ||
| 364 | } | ||
| 365 | } | ||
| 366 | |||
| 367 | sub elem_or_slice_array_name | ||
| 368 | { | ||
| 369 | my $self = shift; | ||
| 370 | my ($array, $left, $padname, $allow_arrow) = @_; | ||
| 371 | |||
| 372 | if ($array->name eq $padname) { | ||
| 373 | return $self->padany($array); | ||
| 374 | } elsif (B::Deparse::is_scope($array)) { # ${expr}[0] | ||
| 375 | return "{" . $self->deparse($array, 0) . "}"; | ||
| 376 | } elsif ($array->name eq "gv") { | ||
| 377 | ($array, my $quoted) = | ||
| 378 | $self->stash_variable_name( | ||
| 379 | $left eq '[' ? '@' : '%', $self->gv_or_padgv($array) | ||
| 380 | ); | ||
| 381 | if (!$allow_arrow && $quoted) { | ||
| 382 | # This cannot happen. | ||
| 383 | die "Invalid variable name $array for slice"; | ||
| 384 | } | ||
| 385 | return $quoted ? "$array->" : $array; | ||
| 386 | } elsif (!$allow_arrow || B::Deparse::is_scalar $array) { | ||
| 387 | # $x[0], $$x[0], ... | ||
| 388 | return $self->deparse($array, 24)->{text}; | ||
| 389 | } else { | ||
| 390 | return undef; | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | sub elem_or_slice_single_index($$) | ||
| 395 | { | ||
| 396 | my ($self, $idx, $parent) = @_; | ||
| 397 | |||
| 398 | my $idx_info = $self->deparse($idx, 1, $parent); | ||
| 399 | my $idx_str = $idx_info->{text}; | ||
| 400 | |||
| 401 | # Outer parens in an array index will confuse perl | ||
| 402 | # if we're interpolating in a regular expression, i.e. | ||
| 403 | # /$x$foo[(-1)]/ is *not* the same as /$x$foo[-1]/ | ||
| 404 | # | ||
| 405 | # If $self->{parens}, then an initial '(' will | ||
| 406 | # definitely be paired with a final ')'. If | ||
| 407 | # !$self->{parens}, the misleading parens won't | ||
| 408 | # have been added in the first place. | ||
| 409 | # | ||
| 410 | # [You might think that we could get "(...)...(...)" | ||
| 411 | # where the initial and final parens do not match | ||
| 412 | # each other. But we can't, because the above would | ||
| 413 | # only happen if there's an infix binop between the | ||
| 414 | # two pairs of parens, and *that* means that the whole | ||
| 415 | # expression would be parenthesized as well.] | ||
| 416 | # | ||
| 417 | $idx_str =~ s/^\((.*)\)$/$1/ if $self->{'parens'}; | ||
| 418 | |||
| 419 | # Hash-element braces will autoquote a bareword inside themselves. | ||
| 420 | # We need to make sure that C<$hash{warn()}> doesn't come out as | ||
| 421 | # C<$hash{warn}>, which has a quite different meaning. Currently | ||
| 422 | # B::Deparse will always quote strings, even if the string was a | ||
| 423 | # bareword in the original (i.e. the OPpCONST_BARE flag is ignored | ||
| 424 | # for constant strings.) So we can cheat slightly here - if we see | ||
| 425 | # a bareword, we know that it is supposed to be a function call. | ||
| 426 | # | ||
| 427 | $idx_str =~ s/^([A-Za-z_]\w*)$/$1()/; | ||
| 428 | |||
| 429 | return info_from_text($idx_info->{op}, $self, $idx_str, | ||
| 430 | 'elem_or_slice_single_index', | ||
| 431 | {body => [$idx_info]}); | ||
| 432 | } | ||
| 433 | |||
| 434 | sub pp_gelem | ||
| 435 | { | ||
| 436 | my($self, $op, $cx) = @_; | ||
| 437 | my($glob, $part) = ($op->first, $op->last); | ||
| 438 | $glob = $glob->first; # skip rv2gv | ||
| 439 | $glob = $glob->first if $glob->name eq "rv2gv"; # this one's a bug | ||
| 440 | my $scope = B::Deparse::is_scope($glob); | ||
| 441 | $glob = $self->deparse($glob, 0); | ||
| 442 | $part = $self->deparse($part, 1); | ||
| 443 | return "*" . ($scope ? "{$glob}" : $glob) . "{$part}"; | ||
| 444 | } | ||
| 445 | |||
| 446 | sub pp_lslice | ||
| 447 | { | ||
| 448 | my ($self, $op, $cs) = @_; | ||
| 449 | my $idx = $op->first; | ||
| 450 | my $list = $op->last; | ||
| 451 | my(@elems, $kid); | ||
| 452 | my $list_info = $self->deparse($list, 1, $op); | ||
| 453 | my $idx_info = $self->deparse($idx, 1, $op); | ||
| 454 | return info_from_list($op, $self, ['(', $list_info->{text}, ')', '[', $idx_info->{text}, ']'], | ||
| 455 | '', 'lslice', {body=>[$list_info, $idx_info]}); | ||
| 456 | } | ||
| 457 | |||
| 458 | sub _method | ||
| 459 | { | ||
| 460 | my($self, $op, $cx) = @_; | ||
| 461 | my @other_ops = ($op->first); | ||
| 462 | my $kid = $op->first->sibling; # skip pushmark | ||
| 463 | my($meth, $obj, @exprs); | ||
| 464 | if ($kid->name eq "list" and B::Deparse::want_list $kid) { | ||
| 465 | # When an indirect object isn't a bareword but the args are in | ||
| 466 | # parens, the parens aren't part of the method syntax (the LLAFR | ||
| 467 | # doesn't apply), but they make a list with OPf_PARENS set that | ||
| 468 | # doesn't get flattened by the append_elem that adds the method, | ||
| 469 | # making a (object, arg1, arg2, ...) list where the object | ||
| 470 | # usually is. This can be distinguished from | ||
| 471 | # '($obj, $arg1, $arg2)->meth()' (which is legal if $arg2 is an | ||
| 472 | # object) because in the later the list is in scalar context | ||
| 473 | # as the left side of -> always is, while in the former | ||
| 474 | # the list is in list context as method arguments always are. | ||
| 475 | # (Good thing there aren't method prototypes!) | ||
| 476 | $meth = $kid->sibling; | ||
| 477 | push @other_ops, $kid->first; | ||
| 478 | $kid = $kid->first->sibling; # skip pushmark | ||
| 479 | $obj = $kid; | ||
| 480 | $kid = $kid->sibling; | ||
| 481 | for (; not B::Deparse::null $kid; $kid = $kid->sibling) { | ||
| 482 | push @exprs, $kid; | ||
| 483 | } | ||
| 484 | } else { | ||
| 485 | $obj = $kid; | ||
| 486 | $kid = $kid->sibling; | ||
| 487 | for (; !B::Deparse::null ($kid->sibling) && $kid->name!~/^method(?:_named)?\z/; | ||
| 488 | $kid = $kid->sibling) { | ||
| 489 | push @exprs, $kid | ||
| 490 | } | ||
| 491 | $meth = $kid; | ||
| 492 | } | ||
| 493 | |||
| 494 | if ($meth->name eq "method_named") { | ||
| 495 | $meth = $self->const_sv($meth)->PV; | ||
| 496 | } else { | ||
| 497 | $meth = $meth->first; | ||
| 498 | if ($meth->name eq "const") { | ||
| 499 | # As of 5.005_58, this case is probably obsoleted by the | ||
| 500 | # method_named case above | ||
| 501 | $meth = $self->const_sv($meth)->PV; # needs to be bare | ||
| 502 | } | ||
| 503 | } | ||
| 504 | |||
| 505 | return { | ||
| 506 | method => $meth, | ||
| 507 | variable_method => ref($meth), | ||
| 508 | object => $obj, | ||
| 509 | args => \@exprs, | ||
| 510 | other_ops => \@other_ops | ||
| 511 | }, $cx; | ||
| 512 | } | ||
| 513 | |||
| 514 | sub e_method { | ||
| 515 | my ($self, $op, $minfo, $cx) = @_; | ||
| 516 | my $obj = $self->deparse($minfo->{object}, 24, $op); | ||
| 517 | my @body = ($obj); | ||
| 518 | my $other_ops = $minfo->{other_ops}; | ||
| 519 | |||
| 520 | my $meth_name = $minfo->{method}; | ||
| 521 | my $meth_info; | ||
| 522 | if ($minfo->{variable_method}) { | ||
| 523 | $meth_info = $self->deparse($meth_name, 1, $op); | ||
| 524 | push @body, $meth_info; | ||
| 525 | } | ||
| 526 | my @args = map { $self->deparse($_, 6, $op) } @{$minfo->{args}}; | ||
| 527 | push @body, @args; | ||
| 528 | my @args_texts = map $_->{text}, @args; | ||
| 529 | my $args = join(", ", @args_texts); | ||
| 530 | |||
| 531 | my $opts = {other_ops => $other_ops}; | ||
| 532 | my @texts = (); | ||
| 533 | my $type; | ||
| 534 | |||
| 535 | |||
| 536 | my $meth_object = $meth_info ? defined($meth_info) : $meth_name; | ||
| 537 | if ($minfo->{object}->name eq 'scope' && B::Deparse::want_list $minfo->{object}) { | ||
| 538 | # method { $object } | ||
| 539 | # This must be deparsed this way to preserve list context | ||
| 540 | # of $object. | ||
| 541 | my $need_paren = $cx >= 6; | ||
| 542 | if ($need_paren) { | ||
| 543 | @texts = ('(', $meth_object, substr($obj,2), | ||
| 544 | $args, ')'); | ||
| 545 | $type = 'e_method list ()'; | ||
| 546 | } else { | ||
| 547 | @texts = ($meth_object, substr($obj,2), $args); | ||
| 548 | $type = 'e_method list, no ()'; | ||
| 549 | } | ||
| 550 | return info_from_list($op, $self, \@texts, '', $type, $opts); | ||
| 551 | } | ||
| 552 | |||
| 553 | if (length $args) { | ||
| 554 | @texts = ($obj, '->', $meth_object, '(', $args, ')'); | ||
| 555 | $type = 'e_method -> ()'; | ||
| 556 | } else { | ||
| 557 | @texts = ($obj, '->', $meth_object); | ||
| 558 | $type = 'e_method -> no ()'; | ||
| 559 | } | ||
| 560 | return info_from_list($op, $self, \@texts, '', $type, $opts); | ||
| 561 | } | ||
| 562 | |||
| 563 | # returns "&" and the argument bodies if the prototype doesn't match the args, | ||
| 564 | # or ("", $args_after_prototype_demunging) if it does. | ||
| 565 | sub check_proto { | ||
| 566 | my $self = shift; | ||
| 567 | my $op = shift; | ||
| 568 | return ('&', []) if $self->{'noproto'}; | ||
| 569 | my($proto, @args) = @_; | ||
| 570 | my($arg, $real); | ||
| 571 | my $doneok = 0; | ||
| 572 | my @reals; | ||
| 573 | # An unbackslashed @ or % gobbles up the rest of the args | ||
| 574 | 1 while $proto =~ s/(?<!\\)([@%])[^\]]+$/$1/; | ||
| 575 | $proto =~ s/^\s*//; | ||
| 576 | while ($proto) { | ||
| 577 | $proto =~ s/^(\\?[\$\@&%*_]|\\\[[\$\@&%*]+\]|;)\s*//; | ||
| 578 | my $chr = $1; | ||
| 579 | if ($chr eq "") { | ||
| 580 | return ('&', []) if @args; | ||
| 581 | } elsif ($chr eq ";") { | ||
| 582 | $doneok = 1; | ||
| 583 | } elsif ($chr eq "@" or $chr eq "%") { | ||
| 584 | push @reals, map($self->deparse($_, 6), @args, $op); | ||
| 585 | @args = (); | ||
| 586 | } else { | ||
| 587 | $arg = shift @args; | ||
| 588 | last unless $arg; | ||
| 589 | if ($chr eq "\$" || $chr eq "_") { | ||
| 590 | if (B::Deparse::want_scalar $arg) { | ||
| 591 | push @reals, $self->deparse($arg, 6, $op); | ||
| 592 | } else { | ||
| 593 | return ('&', []); | ||
| 594 | } | ||
| 595 | } elsif ($chr eq "&") { | ||
| 596 | if ($arg->name =~ /^(s?refgen|undef)$/) { | ||
| 597 | push @reals, $self->deparse($arg, 6, $op); | ||
| 598 | } else { | ||
| 599 | return ('&', []); | ||
| 600 | } | ||
| 601 | } elsif ($chr eq "*") { | ||
| 602 | if ($arg->name =~ /^s?refgen$/ | ||
| 603 | and $arg->first->first->name eq "rv2gv") | ||
| 604 | { | ||
| 605 | $real = $arg->first->first; # skip refgen, null | ||
| 606 | if ($real->first->name eq "gv") { | ||
| 607 | push @reals, $self->deparse($real, 6, $op); | ||
| 608 | } else { | ||
| 609 | push @reals, $self->deparse($real->first, 6, $op); | ||
| 610 | } | ||
| 611 | } else { | ||
| 612 | return ('&', []); | ||
| 613 | } | ||
| 614 | } elsif (substr($chr, 0, 1) eq "\\") { | ||
| 615 | $chr =~ tr/\\[]//d; | ||
| 616 | if ($arg->name =~ /^s?refgen$/ and | ||
| 617 | !B::Deparse::null($real = $arg->first) and | ||
| 618 | ($chr =~ /\$/ && B::Deparse::is_scalar($real->first) | ||
| 619 | or ($chr =~ /@/ | ||
| 620 | && class($real->first->sibling) ne 'NULL' | ||
| 621 | && $real->first->sibling->name | ||
| 622 | =~ /^(rv2|pad)av$/) | ||
| 623 | or ($chr =~ /%/ | ||
| 624 | && class($real->first->sibling) ne 'NULL' | ||
| 625 | && $real->first->sibling->name | ||
| 626 | =~ /^(rv2|pad)hv$/) | ||
| 627 | #or ($chr =~ /&/ # This doesn't work | ||
| 628 | # && $real->first->name eq "rv2cv") | ||
| 629 | or ($chr =~ /\*/ | ||
| 630 | && $real->first->name eq "rv2gv"))) | ||
| 631 | { | ||
| 632 | push @reals, $self->deparse($real, 6, $op); | ||
| 633 | } else { | ||
| 634 | return ('&', []); | ||
| 635 | } | ||
| 636 | } | ||
| 637 | } | ||
| 638 | } | ||
| 639 | return ('&', []) if $proto and !$doneok; # too few args and no ';' | ||
| 640 | return ('&', []) if @args; # too many args | ||
| 641 | return ('', \@reals); | ||
| 642 | } | ||
| 643 | |||
| 644 | sub pp_enterwrite { unop(@_, "write") } | ||
| 645 | |||
| 646 | # Split a floating point number into an integer mantissa and a binary | ||
| 647 | # exponent. Assumes you've already made sure the number isn't zero or | ||
| 648 | # some weird infinity or NaN. | ||
| 649 | sub split_float { | ||
| 650 | my($f) = @_; | ||
| 651 | my $exponent = 0; | ||
| 652 | if ($f == int($f)) { | ||
| 653 | while ($f % 2 == 0) { | ||
| 654 | $f /= 2; | ||
| 655 | $exponent++; | ||
| 656 | } | ||
| 657 | } else { | ||
| 658 | while ($f != int($f)) { | ||
| 659 | $f *= 2; | ||
| 660 | $exponent--; | ||
| 661 | } | ||
| 662 | } | ||
| 663 | my $mantissa = sprintf("%.0f", $f); | ||
| 664 | return ($mantissa, $exponent); | ||
| 665 | } | ||
| 666 | |||
| 667 | # OP_STRINGIFY is a listop, but it only ever has one arg | ||
| 668 | sub pp_stringify { maybe_targmy(@_, \&dquote) } | ||
| 669 | |||
| 670 | # Like dq(), but different | ||
| 671 | sub re_dq { | ||
| 672 | my $self = shift; | ||
| 673 | my ($op, $extended) = @_; | ||
| 674 | my ($re_dq_info, $fmt); | ||
| 675 | |||
| 676 | my $type = $op->name; | ||
| 677 | my ($re, @texts); | ||
| 678 | my $opts = {}; | ||
| 679 | if ($type eq "const") { | ||
| 680 | return info_from_text($op, $self, '$[', 're_dq_const', {}) | ||
| 681 | if $op->private & OPpCONST_ARYBASE; | ||
| 682 | my $unbacked = B::Deparse::re_unback($self->const_sv($op)->as_string); | ||
| 683 | return B::Deparse::re_uninterp_extended(escape_extended_re($unbacked)) | ||
| 684 | if $extended; | ||
| 685 | return B::Deparse::re_uninterp(B::Deparse::escape_str($unbacked)); | ||
| 686 | } elsif ($type eq "concat") { | ||
| 687 | my $first = $self->re_dq($op->first, $extended); | ||
| 688 | my $last = $self->re_dq($op->last, $extended); | ||
| 689 | return B::Deparse::re_dq_disambiguate($first, $last); | ||
| 690 | } elsif ($type eq "uc") { | ||
| 691 | $re_dq_info = $self->re_dq($op->first->sibling, $extended); | ||
| 692 | $fmt = '\U%c\E'; | ||
| 693 | $type .= ' uc'; | ||
| 694 | } elsif ($type eq "lc") { | ||
| 695 | $re_dq_info = $self->re_dq($op->first->sibling, $extended); | ||
| 696 | $fmt = '\L%c\E'; | ||
| 697 | $type .= ' lc'; | ||
| 698 | } elsif ($type eq "ucfirst") { | ||
| 699 | $re_dq_info = $self->re_dq($op->first->sibling, $extended); | ||
| 700 | $fmt = '\u%c'; | ||
| 701 | $type .= ' ucfirst'; | ||
| 702 | } elsif ($type eq "lcfirst") { | ||
| 703 | $re_dq_info = $self->re_dq($op->first->sibling, $extended); | ||
| 704 | $fmt = '\u%c'; | ||
| 705 | $type .= ' lcfirst'; | ||
| 706 | } elsif ($type eq "quotemeta") { | ||
| 707 | $re = $self->re_dq($op->first->sibling, $extended); | ||
| 708 | @texts = ['\Q', $re->{text},'\E']; | ||
| 709 | $type .= ' quotemeta'; | ||
| 710 | } elsif ($type eq "fc") { | ||
| 711 | $re = $self->re_dq($op->first->sibling, $extended); | ||
| 712 | @texts = ['\F', $re->{text},'\E']; | ||
| 713 | $type .= ' fc'; | ||
| 714 | } elsif ($type eq "join") { | ||
| 715 | return $self->deparse($op->last, 26, $op); # was join($", @ary) | ||
| 716 | } else { | ||
| 717 | my $info = $self->deparse($op, 26, $op); | ||
| 718 | $info->{type} = 're_dq'; | ||
| 719 | $info->{text} =~ s/^\$([(|)])\z/\${$1}/; # $( $| $) need braces | ||
| 720 | return $info; | ||
| 721 | } | ||
| 722 | return info_from_list($op, $self, \@texts, '', $type, $opts); | ||
| 723 | } | ||
| 724 | |||
| 725 | sub pure_string { | ||
| 726 | my ($self, $op) = @_; | ||
| 727 | return 0 if B::Deparse::null $op; | ||
| 728 | my $type = $op->name; | ||
| 729 | |||
| 730 | if ($type eq 'const' || $type eq 'av2arylen') { | ||
| 731 | return 1; | ||
| 732 | } | ||
| 733 | elsif ($type =~ /^(?:[ul]c(first)?|fc)$/ || $type eq 'quotemeta') { | ||
| 734 | return $self->pure_string($op->first->sibling); | ||
| 735 | } | ||
| 736 | elsif ($type eq 'join') { | ||
| 737 | my $join_op = $op->first->sibling; # Skip pushmark | ||
| 738 | return 0 unless $join_op->name eq 'null' && $join_op->targ == OP_RV2SV; | ||
| 739 | |||
| 740 | my $gvop = $join_op->first; | ||
| 741 | return 0 unless $gvop->name eq 'gvsv'; | ||
| 742 | return 0 unless '"' eq $self->gv_name($self->gv_or_padgv($gvop)); | ||
| 743 | |||
| 744 | return 0 unless ${$join_op->sibling} eq ${$op->last}; | ||
| 745 | return 0 unless $op->last->name =~ /^(?:[ah]slice|(?:rv2|pad)av)$/; | ||
| 746 | } | ||
| 747 | elsif ($type eq 'concat') { | ||
| 748 | return $self->pure_string($op->first) | ||
| 749 | && $self->pure_string($op->last); | ||
| 750 | } | ||
| 751 | elsif (B::Deparse::is_scalar($op) || $type =~ /^[ah]elem$/) { | ||
| 752 | return 1; | ||
| 753 | } | ||
| 754 | elsif ($type eq "null" and $op->can('first') and not B::Deparse::null $op->first and | ||
| 755 | ($op->first->name eq "null" and $op->first->can('first') | ||
| 756 | and not B::Deparse::null $op->first->first and | ||
| 757 | $op->first->first->name eq "aelemfast" | ||
| 758 | or | ||
| 759 | $op->first->name =~ /^aelemfast(?:_lex)?\z/ | ||
| 760 | )) { | ||
| 761 | return 1; | ||
| 762 | } | ||
| 763 | else { | ||
| 764 | return 0; | ||
| 765 | } | ||
| 766 | |||
| 767 | return 1; | ||
| 768 | } | ||
| 769 | |||
| 770 | sub regcomp | ||
| 771 | { | ||
| 772 | my($self, $op, $cx, $extended) = @_; | ||
| 773 | my @other_ops = (); | ||
| 774 | my $kid = $op->first; | ||
| 775 | if ($kid->name eq "regcmaybe") { | ||
| 776 | push @other_ops, $kid; | ||
| 777 | $kid = $kid->first; | ||
| 778 | } | ||
| 779 | if ($kid->name eq "regcreset") { | ||
| 780 | push @other_ops, $kid; | ||
| 781 | $kid = $kid->first; | ||
| 782 | } | ||
| 783 | if ($kid->name eq "null" and !B::Deparse::null($kid->first) | ||
| 784 | and $kid->first->name eq 'pushmark') { | ||
| 785 | my $str = ''; | ||
| 786 | push(@other_ops, $kid); | ||
| 787 | $kid = $kid->first->sibling; | ||
| 788 | my @body = (); | ||
| 789 | while (!B::Deparse::null($kid)) { | ||
| 790 | my $first = $str; | ||
| 791 | my $last = $self->re_dq($kid, $extended); | ||
| 792 | push @body, $last; | ||
| 793 | push(@other_ops, $kid); | ||
| 794 | $str = B::Deparse::re_dq_disambiguate($first, | ||
| 795 | $self->info2str($last)); | ||
| 796 | $kid = $kid->sibling; | ||
| 797 | } | ||
| 798 | return (info_from_text($op, $self, $str, 'regcomp', | ||
| 799 | {other_ops => \@other_ops, | ||
| 800 | body => \@body}), 1); | ||
| 801 | } | ||
| 802 | |||
| 803 | if ($self->pure_string($kid)) { | ||
| 804 | my $info = $self->re_dq($kid, $extended); | ||
| 805 | my @kid_ops = $info->{other_ops} ? @{$info->{other_ops}} : (); | ||
| 806 | push @other_ops, @kid_ops; | ||
| 807 | $info->{other_ops} = \@other_ops; | ||
| 808 | return ($info, 1); | ||
| 809 | } | ||
| 810 | return ($self->deparse($kid, $cx, $op), 0, $op); | ||
| 811 | } | ||
| 812 | |||
| 813 | sub pp_match { matchop(@_, "m", "/") } | ||
| 814 | sub pp_pushre { matchop(@_, "m", "/") } | ||
| 815 | sub pp_qr { matchop(@_, "qr", "") } | ||
| 816 | |||
| 817 | sub pp_split | ||
| 818 | { | ||
| 819 | my($self, $op, $cx) = @_; | ||
| 820 | my($kid, @exprs, $ary_info, $expr); | ||
| 821 | my $ary = ''; | ||
| 822 | my @body = (); | ||
| 823 | my @other_ops = (); | ||
| 824 | $kid = $op->first; | ||
| 825 | |||
| 826 | # For our kid (an OP_PUSHRE), pmreplroot is never actually the | ||
| 827 | # root of a replacement; it's either empty, or abused to point to | ||
| 828 | # the GV for an array we split into (an optimization to save | ||
| 829 | # assignment overhead). Depending on whether we're using ithreads, | ||
| 830 | # this OP* holds either a GV* or a PADOFFSET. Luckily, B.xs | ||
| 831 | # figures out for us which it is. | ||
| 832 | my $replroot = $kid->pmreplroot; | ||
| 833 | my $gv = 0; | ||
| 834 | if (ref($replroot) eq "B::GV") { | ||
| 835 | $gv = $replroot; | ||
| 836 | } elsif (!ref($replroot) and $replroot > 0) { | ||
| 837 | $gv = $self->padval($replroot); | ||
| 838 | } | ||
| 839 | $ary = $self->stash_variable('@', $self->gv_name($gv), $cx) if $gv; | ||
| 840 | |||
| 841 | for (; !B::Deparse::null($kid); $kid = $kid->sibling) { | ||
| 842 | push @exprs, $self->deparse($kid, 6, $op); | ||
| 843 | } | ||
| 844 | |||
| 845 | my $opts = {body => \@exprs}; | ||
| 846 | |||
| 847 | my @args_texts = map $_->{text}, @exprs; | ||
| 848 | # handle special case of split(), and split(' ') that compiles to /\s+/ | ||
| 849 | # Under 5.10, the reflags may be undef if the split regexp isn't a constant | ||
| 850 | # Under 5.17.5-5.17.9, the special flag is on split itself. | ||
| 851 | $kid = $op->first; | ||
| 852 | if ( $op->flags & OPf_SPECIAL ) { | ||
| 853 | $exprs[0]->{text} = "' '"; | ||
| 854 | } | ||
| 855 | |||
| 856 | my $sep = ''; | ||
| 857 | my $type; | ||
| 858 | my @expr_texts; | ||
| 859 | if ($ary) { | ||
| 860 | @expr_texts = ("$ary", '=', join(', ', @args_texts)); | ||
| 861 | $sep = ' '; | ||
| 862 | $type = 'split_array'; | ||
| 863 | $opts->{maybe_parens} = [$self, $cx, 7]; | ||
| 864 | } else { | ||
| 865 | @expr_texts = ('split', '(', join(', ', @args_texts), ')'); | ||
| 866 | $type = 'split'; | ||
| 867 | |||
| 868 | } | ||
| 869 | return info_from_list($op, $self, \@expr_texts, $sep, $type, $opts); | ||
| 870 | } | ||
| 871 | |||
| 872 | # Kind of silly, but we prefer, subst regexp flags joined together to | ||
| 873 | # make words. For example: s/a/b/xo => s/a/b/ox | ||
| 874 | |||
| 875 | # oxime -- any of various compounds obtained chiefly by the action of | ||
| 876 | # hydroxylamine on aldehydes and ketones and characterized by the | ||
| 877 | # bivalent grouping C=NOH [Webster's Tenth] | ||
| 878 | |||
| 879 | my %substwords; | ||
| 880 | map($substwords{join "", sort split //, $_} = $_, 'ego', 'egoism', 'em', | ||
| 881 | 'es', 'ex', 'exes', 'gee', 'go', 'goes', 'ie', 'ism', 'iso', 'me', | ||
| 882 | 'meese', 'meso', 'mig', 'mix', 'os', 'ox', 'oxime', 'see', 'seem', | ||
| 883 | 'seg', 'sex', 'sig', 'six', 'smog', 'sog', 'some', 'xi', 'rogue', | ||
| 884 | 'sir', 'rise', 'smore', 'more', 'seer', 'rome', 'gore', 'grim', 'grime', | ||
| 885 | 'or', 'rose', 'rosie'); | ||
| 886 | |||
| 887 | unless (caller) { | ||
| 888 | eval "use Data::Printer;"; | ||
| 889 | |||
| 890 | eval { | ||
| 891 | our($Fileparse_fstype); | ||
| 892 | sub fib($) { | ||
| 893 | my $x = shift; | ||
| 894 | return 1 if $x <= 1; | ||
| 895 | return(fib($x-1) + fib($x-2)) | ||
| 896 | } | ||
| 897 | sub fileparse { | ||
| 898 | no strict; | ||
| 899 | # my($fullname,@suffices) = @_; | ||
| 900 | |||
| 901 | my $tail = ''; | ||
| 902 | $tail = $1 . $tail; | ||
| 903 | |||
| 904 | # Ensure taint is propagated from the path to its pieces. | ||
| 905 | $tail .= $taint; | ||
| 906 | wantarray ? ($basename .= $taint, $dirpath .= $taint, $tail) | ||
| 907 | : ($basename .= $taint); | ||
| 908 | } | ||
| 909 | sub baz { | ||
| 910 | no strict; | ||
| 911 | if ($basename =~ s/$pat//s) { | ||
| 912 | } | ||
| 913 | } | ||
| 914 | }; | ||
| 915 | |||
| 916 | my $deparse = __PACKAGE__->new("-l", "-c"); | ||
| 917 | my $info = $deparse->coderef2info(\&fileparse); | ||
| 918 | # my $info = $deparse->coderef2info(\&baz); | ||
| 919 | import Data::Printer colored => 0; | ||
| 920 | Data::Printer::p($info); | ||
| 921 | print "\n", '=' x 30, "\n"; | ||
| 922 | # print $deparse->($deparse->deparse_subname('fib')->{text}); | ||
| 923 | # print "\n", '=' x 30, "\n"; | ||
| 924 | # print "\n", '-' x 30, "\n"; | ||
| 925 | while (my($key, $value) = each %{$deparse->{optree}}) { | ||
| 926 | my $parent_op_name = 'undef'; | ||
| 927 | if ($value->{parent}) { | ||
| 928 | my $parent = $deparse->{optree}{$value->{parent}}; | ||
| 929 | $parent_op_name = $parent->{op}->name if $parent->{op}; | ||
| 930 | } | ||
| 931 | if (eval{$value->{op}->name}) { | ||
| 932 | printf("0x%x %s/%s of %s |\n%s", | ||
| 933 | $key, $value->{op}->name, $value->{type}, | ||
| 934 | $parent_op_name, $deparse->{text}); | ||
| 935 | } else { | ||
| 936 | printf("0x%x %s of %s |\n", | ||
| 937 | $key, $value->{type}, | ||
| 938 | $parent_op_name); | ||
| 939 | } | ||
| 940 | printf " ## line %s\n", $value->{cop} ? $value->{cop}->line : 'undef'; | ||
| 941 | print '-' x 30, "\n"; | ||
| 942 | } | ||
| 943 | # use B::Deparse; | ||
| 944 | # my $deparse_old = B::Deparse->new("-l", "-sC"); | ||
| 945 | # print $deparse_old->coderef2text(\&baz); | ||
| 946 | } | ||
| 947 | |||
| 948 | 1; |