| 1 | # Copyright (c) 2015, 2018 Rocky Bernstein | ||
| 2 | |||
| 3 | # Common PP (push-pull) opcodes methods. Most of these are called | ||
| 4 | # from the method dispatch in Common. | ||
| 5 | # | ||
| 6 | # Specifc Perl versions can override these. Note some PP opcodes are | ||
| 7 | # handled via table lookup to their underlying base-handling function, | ||
| 8 | # e.g. binop, listop, unop, .... | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use warnings (); | ||
| 12 | require feature; | ||
| 13 | |||
| 14 | my %feature_keywords = ( | ||
| 15 | # keyword => 'feature', | ||
| 16 | state => 'state', | ||
| 17 | say => 'say', | ||
| 18 | given => 'switch', | ||
| 19 | when => 'switch', | ||
| 20 | default => 'switch', | ||
| 21 | break => 'switch', | ||
| 22 | evalbytes=>'evalbytes', | ||
| 23 | __SUB__ => '__SUB__', | ||
| 24 | fc => 'fc', | ||
| 25 | ); | ||
| 26 | |||
| 27 | use rlib '../..'; | ||
| 28 | |||
| 29 | package B::DeparseTree::PP; | ||
| 30 | |||
| 31 | use B::DeparseTree::SyntaxTree; | ||
| 32 | use B::DeparseTree::PPfns; | ||
| 33 | use B::DeparseTree::Node; | ||
| 34 | use B::Deparse; | ||
| 35 | our($VERSION, @EXPORT, @ISA); | ||
| 36 | $VERSION = '3.2.0'; | ||
| 37 | |||
| 38 | @ISA = qw(Exporter B::Deparse ); | ||
| 39 | |||
| 40 | # Copy unchanged functions from B::Deparse | ||
| 41 | *lex_in_scope = *B::Deparse::lex_in_scope; | ||
| 42 | *padany = *B::Deparse::padany; | ||
| 43 | *padname = *B::Deparse::padname; | ||
| 44 | *pp_anonhash = *B::Deparse::pp_anonhash; | ||
| 45 | *pp_anonlist = *B::Deparse::pp_anonlist; | ||
| 46 | *pp_i_negate = *B::Deparse::pp_i_negate; | ||
| 47 | *pp_negate = *B::Deparse::pp_negate; | ||
| 48 | *real_negate = *B::Deparse::real_negate; | ||
| 49 | |||
| 50 | use B qw( | ||
| 51 | OPf_MOD OPpENTERSUB_AMPER | ||
| 52 | OPf_SPECIAL | ||
| 53 | OPf_STACKED | ||
| 54 | OPpEXISTS_SUB | ||
| 55 | OPpTRANS_COMPLEMENT | ||
| 56 | OPpTRANS_DELETE | ||
| 57 | OPpTRANS_SQUASH | ||
| 58 | SVf_POK | ||
| 59 | SVf_ROK | ||
| 60 | class | ||
| 61 | opnumber | ||
| 62 | ); | ||
| 63 | |||
| 64 | @EXPORT = qw( | ||
| 65 | feature_enabled | ||
| 66 | pp_aassign | ||
| 67 | pp_abs | ||
| 68 | pp_aelem | ||
| 69 | pp_and | ||
| 70 | pp_anonhash | ||
| 71 | pp_anonlist | ||
| 72 | pp_aslice | ||
| 73 | pp_atan2 | ||
| 74 | pp_avalues | ||
| 75 | pp_backtick | ||
| 76 | pp_boolkeys | ||
| 77 | pp_chmod | ||
| 78 | pp_chomp | ||
| 79 | pp_chop | ||
| 80 | pp_chown | ||
| 81 | pp_clonecv | ||
| 82 | pp_cmp | ||
| 83 | pp_complement | ||
| 84 | pp_cond_expr | ||
| 85 | pp_connect | ||
| 86 | pp_const | ||
| 87 | pp_cos | ||
| 88 | pp_crypt | ||
| 89 | pp_dbmopen | ||
| 90 | pp_delete | ||
| 91 | pp_dofile | ||
| 92 | pp_dor | ||
| 93 | pp_entereval | ||
| 94 | pp_entersub | ||
| 95 | pp_eq | ||
| 96 | pp_exec | ||
| 97 | pp_exists | ||
| 98 | pp_exp | ||
| 99 | pp_flock | ||
| 100 | pp_flop | ||
| 101 | pp_formline | ||
| 102 | pp_ge | ||
| 103 | pp_getppid | ||
| 104 | pp_getpriority | ||
| 105 | pp_glob | ||
| 106 | pp_gnbyaddr | ||
| 107 | pp_gpbynumber | ||
| 108 | pp_grepwhile | ||
| 109 | pp_gt | ||
| 110 | pp_gv | ||
| 111 | pp_gvsv | ||
| 112 | pp_helem | ||
| 113 | pp_hex | ||
| 114 | pp_hslice | ||
| 115 | pp_i_cmp | ||
| 116 | pp_i_eq | ||
| 117 | pp_i_ge | ||
| 118 | pp_i_gt | ||
| 119 | pp_i_le | ||
| 120 | pp_i_lt | ||
| 121 | pp_i_ne | ||
| 122 | pp_i_negate | ||
| 123 | pp_i_predec | ||
| 124 | pp_i_preinc | ||
| 125 | pp_index | ||
| 126 | pp_int | ||
| 127 | pp_introcv | ||
| 128 | pp_ioctl | ||
| 129 | pp_join | ||
| 130 | pp_kill | ||
| 131 | pp_kvaslice | ||
| 132 | pp_kvhslice | ||
| 133 | pp_le | ||
| 134 | pp_leave | ||
| 135 | pp_leavegiven | ||
| 136 | pp_leaveloop | ||
| 137 | pp_leavetry | ||
| 138 | pp_leavewhen | ||
| 139 | pp_lineseq | ||
| 140 | pp_link | ||
| 141 | pp_list | ||
| 142 | pp_log | ||
| 143 | pp_lt | ||
| 144 | pp_mapstart | ||
| 145 | pp_mapwhile | ||
| 146 | pp_mkdir | ||
| 147 | pp_msgsnd | ||
| 148 | pp_ne | ||
| 149 | pp_negate | ||
| 150 | pp_not | ||
| 151 | pp_null | ||
| 152 | pp_oct | ||
| 153 | pp_once | ||
| 154 | pp_open_dir | ||
| 155 | pp_or | ||
| 156 | pp_padcv | ||
| 157 | pp_pos | ||
| 158 | pp_pos | ||
| 159 | pp_postdec | ||
| 160 | pp_postinc | ||
| 161 | pp_predec | ||
| 162 | pp_preinc | ||
| 163 | pp_print | ||
| 164 | pp_prtf | ||
| 165 | pp_push | ||
| 166 | pp_rand | ||
| 167 | pp_ref | ||
| 168 | pp_refgen | ||
| 169 | pp_rename | ||
| 170 | pp_repeat | ||
| 171 | pp_require | ||
| 172 | pp_return | ||
| 173 | pp_rindex | ||
| 174 | pp_rv2cv | ||
| 175 | pp_sassign | ||
| 176 | pp_scalar | ||
| 177 | pp_schomp | ||
| 178 | pp_schop | ||
| 179 | pp_scmp | ||
| 180 | pp_scope | ||
| 181 | pp_seekdir | ||
| 182 | pp_seq | ||
| 183 | pp_setpgrp | ||
| 184 | pp_setpriority | ||
| 185 | pp_sge | ||
| 186 | pp_sgt | ||
| 187 | pp_sin | ||
| 188 | pp_sle | ||
| 189 | pp_slt | ||
| 190 | pp_sne | ||
| 191 | pp_sockpair | ||
| 192 | pp_slice | ||
| 193 | pp_sprintf | ||
| 194 | pp_sqrt | ||
| 195 | pp_sselect | ||
| 196 | pp_ssockopt | ||
| 197 | pp_stub | ||
| 198 | pp_subst | ||
| 199 | pp_substr | ||
| 200 | pp_symlink | ||
| 201 | pp_sysread | ||
| 202 | pp_sysseek | ||
| 203 | pp_system | ||
| 204 | pp_time | ||
| 205 | pp_trans | ||
| 206 | pp_transr | ||
| 207 | pp_truncate | ||
| 208 | pp_unlink | ||
| 209 | pp_unpack | ||
| 210 | pp_unshift | ||
| 211 | pp_unstack | ||
| 212 | pp_utime | ||
| 213 | pp_values | ||
| 214 | pp_vec | ||
| 215 | pp_wait | ||
| 216 | pp_waitpid | ||
| 217 | pp_wantarray | ||
| 218 | pp_xor | ||
| 219 | ); | ||
| 220 | |||
| 221 | BEGIN { | ||
| 222 | # List version-specific constants here. | ||
| 223 | # Easiest way to keep this code portable between version looks to | ||
| 224 | # be to fake up a dummy constant that will never actually be true. | ||
| 225 | foreach (qw(OPpCONST_ARYBASE OPpEVAL_BYTES)) { | ||
| 226 | eval { import B $_ }; | ||
| 227 | no strict 'refs'; | ||
| 228 | *{$_} = sub () {0} unless *{$_}{CODE}; | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | BEGIN { for (qw[ const stringify rv2sv list glob pushmark null aelem | ||
| 233 | nextstate dbstate rv2av rv2hv helem custom ]) { | ||
| 234 | eval "sub OP_\U$_ () { " . opnumber($_) . "}" | ||
| 235 | }} | ||
| 236 | |||
| 237 | sub feature_enabled { | ||
| 238 | my($self,$name) = @_; | ||
| 239 | my $hh; | ||
| 240 | my $hints = $self->{hints} & $feature::hint_mask; | ||
| 241 | if ($hints && $hints != $feature::hint_mask) { | ||
| 242 | $hh = B::Deparse::_features_from_bundle($hints); | ||
| 243 | } | ||
| 244 | elsif ($hints) { $hh = $self->{'hinthash'} } | ||
| 245 | return $hh && $hh->{"feature_$feature_keywords{$name}"} | ||
| 246 | } | ||
| 247 | |||
| 248 | # Convert these to table entries... | ||
| 249 | sub pp_aelem { maybe_local(@_, elem(@_, "[", "]", "padav")) } | ||
| 250 | sub pp_aslice { maybe_local(@_, slice(@_, "[", "]", "rv2av", "padav")) } | ||
| 251 | sub pp_cmp { binop(@_, "<=>", 14) } | ||
| 252 | sub pp_eq { binop(@_, "==", 14) } | ||
| 253 | sub pp_ge { binop(@_, ">=", 15) } | ||
| 254 | sub pp_gt { binop(@_, ">", 15) } | ||
| 255 | sub pp_helem { maybe_local(@_, elem(@_, "{", "}", "padhv")) } | ||
| 256 | sub pp_hslice { maybe_local(@_, slice(@_, "{", "}", "rv2hv", "padhv")) } | ||
| 257 | sub pp_i_cmp { maybe_targmy(@_, \&binop, "<=>", 14) } | ||
| 258 | sub pp_i_eq { binop(@_, "==", 14) } | ||
| 259 | sub pp_i_ge { binop(@_, ">=", 15) } | ||
| 260 | sub pp_i_gt { binop(@_, ">", 15) } | ||
| 261 | sub pp_i_le { binop(@_, "<=", 15) } | ||
| 262 | sub pp_i_lt { binop(@_, "<", 15) } | ||
| 263 | sub pp_i_ne { binop(@_, "!=", 14) } | ||
| 264 | sub pp_kvaslice { slice(@_, "[", "]", "rv2av", "padav") } | ||
| 265 | sub pp_kvhslice { slice(@_, "{", "}", "rv2hv", "padhv") } | ||
| 266 | sub pp_le { binop(@_, "<=", 15) } | ||
| 267 | sub pp_lt { binop(@_, "<", 15) } | ||
| 268 | sub pp_ne { binop(@_, "!=", 14) } | ||
| 269 | |||
| 270 | # Note that we need to add undef and 1 (nollr) | ||
| 271 | sub pp_return { listop(@_, "return", undef, 1) } # llafr does not apply | ||
| 272 | |||
| 273 | sub pp_sassign { binop(@_, "=", 7, SWAP_CHILDREN) } | ||
| 274 | sub pp_scmp { binop(@_, "cmp", 14) } | ||
| 275 | sub pp_seekdir { listop(@_, "seekdir") } | ||
| 276 | sub pp_seq { binop(@_, "eq", 14) } | ||
| 277 | sub pp_sge { binop(@_, "ge", 15) } | ||
| 278 | sub pp_sgt { binop(@_, "gt", 15) } | ||
| 279 | sub pp_sle { binop(@_, "le", 15) } | ||
| 280 | sub pp_slt { binop(@_, "lt", 15) } | ||
| 281 | sub pp_sne { binop(@_, "ne", 14) } | ||
| 282 | |||
| 283 | # FIXME: These don't seem to be able to go into the table. | ||
| 284 | # PPfns calls pp_sockpair for example? | ||
| 285 | sub pp_sockpair { listop(@_, "socketpair") } | ||
| 286 | sub pp_values { unop(@_, "values") } | ||
| 287 | sub pp_avalues { unop(@_, "values") } | ||
| 288 | |||
| 289 | |||
| 290 | |||
| 291 | sub pp_aassign { binop(@_, "=", 7, SWAP_CHILDREN | LIST_CONTEXT, 'array assign') } | ||
| 292 | sub pp_abs { maybe_targmy(@_, \&unop, "abs") } | ||
| 293 | |||
| 294 | sub pp_backtick | ||
| 295 | { | ||
| 296 | my($self, $op, $cx) = @_; | ||
| 297 | # skip pushmark if it exists (readpipe() vs ``) | ||
| 298 | my $child = $op->first->sibling->isa('B::NULL') | ||
| 299 | ? $op->first : $op->first->sibling; | ||
| 300 | if ($self->pure_string($child)) { | ||
| 301 | return $self->single_delim($op, "qx", '`', $self->dq($child, 1)->{text}); | ||
| 302 | } | ||
| 303 | unop($self, $op, $cx, "readpipe"); | ||
| 304 | } | ||
| 305 | |||
| 306 | sub pp_boolkeys | ||
| 307 | { | ||
| 308 | # no name because its an optimisation op that has no keyword | ||
| 309 | unop(@_,""); | ||
| 310 | } | ||
| 311 | |||
| 312 | sub pp_chmod { maybe_targmy(@_, \&listop, "chmod") } | ||
| 313 | sub pp_chown { maybe_targmy(@_, \&listop, "chown") } | ||
| 314 | sub pp_cos { maybe_targmy(@_, \&unop, "cos") } | ||
| 315 | sub pp_crypt { maybe_targmy(@_, \&listop, "crypt") } | ||
| 316 | |||
| 317 | sub pp_dofile | ||
| 318 | { | ||
| 319 | my $code = unop(@_, "do", 1); # llafr does not apply | ||
| 320 | if ($code =~ s/^((?:CORE::)?do) \{/$1({/) { $code .= ')' } | ||
| 321 | $code; | ||
| 322 | } | ||
| 323 | |||
| 324 | sub pp_exec { maybe_targmy(@_, \&listop, "exec") } | ||
| 325 | sub pp_exp { maybe_targmy(@_, \&unop, "exp") } | ||
| 326 | sub pp_flock { maybe_targmy(@_, \&listop, "flock") } | ||
| 327 | sub pp_getpriority { maybe_targmy(@_, \&listop, "getpriority") } | ||
| 328 | sub pp_hex { maybe_targmy(@_, \&unop, "hex") } | ||
| 329 | sub pp_index { maybe_targmy(@_, \&listop, "index") } | ||
| 330 | sub pp_int { maybe_targmy(@_, \&unop, "int") } | ||
| 331 | sub pp_join { maybe_targmy(@_, \&listop, "join") } | ||
| 332 | sub pp_kill { maybe_targmy(@_, \&listop, "kill") } | ||
| 333 | sub pp_link { maybe_targmy(@_, \&listop, "link") } | ||
| 334 | |||
| 335 | sub pp_leavegiven { givwhen(@_, $_[0]->keyword("given")); } | ||
| 336 | sub pp_leavewhen { givwhen(@_, $_[0]->keyword("when")); } | ||
| 337 | |||
| 338 | sub pp_log { maybe_targmy(@_, \&unop, "log") } | ||
| 339 | sub pp_mkdir { maybe_targmy(@_, \&listop, "mkdir") } | ||
| 340 | |||
| 341 | sub pp_not | ||
| 342 | { | ||
| 343 | my($self, $op, $cx) = @_; | ||
| 344 | if ($cx <= 4) { | ||
| 345 | $self->listop($op, $cx, "not", $op->first); | ||
| 346 | } else { | ||
| 347 | $self->pfixop($op, $cx, "!", 21); | ||
| 348 | } | ||
| 349 | } | ||
| 350 | |||
| 351 | |||
| 352 | sub pp_oct { maybe_targmy(@_, \&unop, "oct") } | ||
| 353 | sub pp_open_dir { listop(@_, "opendir") } | ||
| 354 | sub pp_pos { maybe_local(@_, unop(@_, "pos")) } | ||
| 355 | sub pp_push { maybe_targmy(@_, \&listop, "push") } | ||
| 356 | sub pp_rename { maybe_targmy(@_, \&listop, "rename") } | ||
| 357 | sub pp_rindex { maybe_targmy(@_, \&listop, "rindex") } | ||
| 358 | |||
| 359 | # skip down to the old, ex-rv2cv | ||
| 360 | sub pp_rv2cv { | ||
| 361 | my ($self, $op, $cx) = @_; | ||
| 362 | if (!B::Deparse::null($op->first) && $op->first->name eq 'null' && | ||
| 363 | $op->first->targ == OP_LIST) | ||
| 364 | { | ||
| 365 | return $self->rv2x($op->first->first->sibling, $cx, "&") | ||
| 366 | } | ||
| 367 | else { | ||
| 368 | return $self->rv2x($op, $cx, "") | ||
| 369 | } | ||
| 370 | } | ||
| 371 | |||
| 372 | |||
| 373 | sub pp_scalar | ||
| 374 | { | ||
| 375 | my($self, $op, $cx) = @_; | ||
| 376 | my $kid = $op->first; | ||
| 377 | if (not B::Deparse::null $kid->sibling) { | ||
| 378 | # XXX Was a here-doc | ||
| 379 | return $self->dquote($op); | ||
| 380 | } | ||
| 381 | $self->unop($op, $cx, "scalar"); | ||
| 382 | } | ||
| 383 | |||
| 384 | sub pp_setpgrp { maybe_targmy(@_, \&listop, "setpgrp") } | ||
| 385 | sub pp_setpriority { maybe_targmy(@_, \&listop, "setpriority") } | ||
| 386 | sub pp_sin { maybe_targmy(@_, \&unop, "sin") } | ||
| 387 | sub pp_sprintf { maybe_targmy(@_, \&listop, "sprintf") } | ||
| 388 | sub pp_sqrt { maybe_targmy(@_, \&unop, "sqrt") } | ||
| 389 | sub pp_symlink { maybe_targmy(@_, \&listop, "symlink") } | ||
| 390 | sub pp_system { maybe_targmy(@_, \&listop, "system") } | ||
| 391 | |||
| 392 | sub pp_truncate | ||
| 393 | { | ||
| 394 | my($self, $op, $cx) = @_; | ||
| 395 | my(@exprs); | ||
| 396 | my $parens = ($cx >= 5) || $self->{'parens'}; | ||
| 397 | my $opts = {'other_ops' => [$op->first]}; | ||
| 398 | my $kid = $op->first->sibling; | ||
| 399 | my $fh; | ||
| 400 | if ($op->flags & B::OPf_SPECIAL) { | ||
| 401 | # $kid is an OP_CONST | ||
| 402 | $fh = $self->const_sv($kid)->PV; | ||
| 403 | } else { | ||
| 404 | $fh = $self->deparse($kid, 6, $op); | ||
| 405 | $fh = "+$fh" if not $parens and substr($fh, 0, 1) eq "("; | ||
| 406 | } | ||
| 407 | my $len = $self->deparse($kid->sibling, 6, $op); | ||
| 408 | my $name = $self->keyword('truncate'); | ||
| 409 | my $args = "$fh->{text}, $len->{text}"; | ||
| 410 | if ($parens) { | ||
| 411 | return info_from_list($op, $self, [$name, '(', $args, ')'], '', | ||
| 412 | 'truncate_parens', $opts); | ||
| 413 | } else { | ||
| 414 | return info_from_list($op, $self, [$name, $args], '', 'truncate', $opts); | ||
| 415 | } | ||
| 416 | } | ||
| 417 | |||
| 418 | sub pp_unlink { maybe_targmy(@_, \&listop, "unlink") } | ||
| 419 | sub pp_unshift { maybe_targmy(@_, \&listop, "unshift") } | ||
| 420 | sub pp_utime { maybe_targmy(@_, \&listop, "utime") } | ||
| 421 | |||
| 422 | sub pp_vec { maybe_local(@_, listop(@_, "vec")) } | ||
| 423 | sub pp_waitpid { maybe_targmy(@_, \&listop, "waitpid") } | ||
| 424 | |||
| 425 | sub pp_glob | ||
| 426 | { | ||
| 427 | my($self, $op, $cx) = @_; | ||
| 428 | |||
| 429 | my $opts = {other_ops => [$op->first]}; | ||
| 430 | my $kid = $op->first->sibling; # skip pushmark | ||
| 431 | my $keyword = | ||
| 432 | $op->flags & OPf_SPECIAL ? 'glob' : $self->keyword('glob'); | ||
| 433 | |||
| 434 | if ($keyword =~ /^CORE::/ or $kid->name ne 'const') { | ||
| 435 | my $kid_info = $self->dq($kid, $op); | ||
| 436 | my $body = [$kid_info]; | ||
| 437 | my $text = $kid_info->{text}; | ||
| 438 | if ($text =~ /^\$?(\w|::|\`)+$/ # could look like a readline | ||
| 439 | or $text =~ /[<>]/) { | ||
| 440 | $kid_info = $self->deparse($kid, 0, $op); | ||
| 441 | $body = [$kid_info]; | ||
| 442 | $text = $kid_info->{text}; | ||
| 443 | $opts->{body} = $body; | ||
| 444 | if ($cx >= 5 || $self->{'parens'}) { | ||
| 445 | return info_from_list($op, $self, [$keyword, '(', $text, ')'], '', | ||
| 446 | 'glob_paren', $opts); | ||
| 447 | } else { | ||
| 448 | return info_from_list($op, $self, [$keyword, $text], ' ', | ||
| 449 | 'glob_space', $opts); | ||
| 450 | } | ||
| 451 | } else { | ||
| 452 | return info_from_list($op, $self, ['<', $text, '>'], '', 'glob_angle', $opts); | ||
| 453 | } | ||
| 454 | } | ||
| 455 | return info_from_list($op, $self, ['<', '>'], '', 'glob_angle', $opts); | ||
| 456 | } | ||
| 457 | |||
| 458 | sub pp_chomp { maybe_targmy(@_, \&unop, "chomp") } | ||
| 459 | sub pp_chop { maybe_targmy(@_, \&unop, "chop") } | ||
| 460 | |||
| 461 | sub pp_clonecv { | ||
| 462 | my $self = shift; | ||
| 463 | my($op, $cx) = @_; | ||
| 464 | my $sv = $self->padname_sv($op->targ); | ||
| 465 | my $name = substr $sv->PVX, 1; # skip &/$/@/%, like $self->padany | ||
| 466 | return info_from_list($op, $self, ['my', 'sub', $name], ' ', 'clonev', {}); | ||
| 467 | } | ||
| 468 | |||
| 469 | sub pp_delete($$$) | ||
| 470 | { | ||
| 471 | my($self, $op, $cx) = @_; | ||
| 472 | my $arg; | ||
| 473 | my ($info, $body, $type); | ||
| 474 | if ($op->private & B::OPpSLICE) { | ||
| 475 | if ($op->flags & B::OPf_SPECIAL) { | ||
| 476 | # Deleting from an array, not a hash | ||
| 477 | $info = $self->pp_aslice($op->first, 16); | ||
| 478 | $type = 'delete slice'; | ||
| 479 | } | ||
| 480 | } else { | ||
| 481 | if ($op->flags & B::OPf_SPECIAL) { | ||
| 482 | # Deleting from an array, not a hash | ||
| 483 | $info = $self->pp_aelem($op->first, 16); | ||
| 484 | $type = 'delete array' | ||
| 485 | } else { | ||
| 486 | $info = $self->pp_helem($op->first, 16); | ||
| 487 | $type = 'delete hash'; | ||
| 488 | } | ||
| 489 | } | ||
| 490 | my @texts = $self->maybe_parens_func("delete", | ||
| 491 | $info->{text}, $cx, 16); | ||
| 492 | return info_from_list($op, $self, \@texts, '', $type, {body => [$info]}); | ||
| 493 | } | ||
| 494 | |||
| 495 | sub pp_exists | ||
| 496 | { | ||
| 497 | my($self, $op, $cx) = @_; | ||
| 498 | my ($info, $type); | ||
| 499 | my $name = $self->keyword("exists"); | ||
| 500 | if ($op->private & OPpEXISTS_SUB) { | ||
| 501 | # Checking for the existence of a subroutine | ||
| 502 | $info = $self->pp_rv2cv($op->first, 16); | ||
| 503 | $type = 'exists sub'; | ||
| 504 | } elsif ($op->flags & OPf_SPECIAL) { | ||
| 505 | # Array element, not hash helement | ||
| 506 | $info = $self->pp_aelem($op->first, 16); | ||
| 507 | $type = 'exists array'; | ||
| 508 | } else { | ||
| 509 | $info = $self->pp_helem($op->first, 16); | ||
| 510 | $type = 'exists hash'; | ||
| 511 | } | ||
| 512 | my @texts = $self->maybe_parens_func($name, $info->{text}, $cx, 16); | ||
| 513 | return info_from_list($op, $self, \@texts, '', $type, {}); | ||
| 514 | } | ||
| 515 | |||
| 516 | sub pp_introcv | ||
| 517 | { | ||
| 518 | my($self, $op, $cx) = @_; | ||
| 519 | # For now, deparsing doesn't worry about the distinction between introcv | ||
| 520 | # and clonecv, so pretend this op doesn't exist: | ||
| 521 | return info_from_text($op, $self, '', 'introcv', {}); | ||
| 522 | } | ||
| 523 | |||
| 524 | sub pp_leave { scopeop(1, @_); } | ||
| 525 | sub pp_leaveloop { shift->loop_common(@_, undef); } | ||
| 526 | |||
| 527 | sub pp_leavetry { | ||
| 528 | my ($self, $op, $cx) = @_; | ||
| 529 | my $leave_info = $self->pp_leave($op, $cx); | ||
| 530 | return $self->info_from_template('eval {}', $op, "eval {\n%+%c\n%-}", | ||
| 531 | undef, [$leave_info]); | ||
| 532 | } | ||
| 533 | |||
| 534 | sub pp_lineseq { scopeop(0, @_); } | ||
| 535 | |||
| 536 | sub pp_list | ||
| 537 | { | ||
| 538 | my($self, $op, $cx) = @_; | ||
| 539 | my($expr, @exprs); | ||
| 540 | |||
| 541 | my $pushmark_op = $op->first; | ||
| 542 | my $kid = $pushmark_op->sibling; # skip a pushmark | ||
| 543 | |||
| 544 | if (class($kid) eq 'NULL') { | ||
| 545 | return info_from_text($op, $self, '', 'list_null', | ||
| 546 | {other_ops => [$pushmark_op]}); | ||
| 547 | } | ||
| 548 | my $lop; | ||
| 549 | my $local = "either"; # could be local(...), my(...), state(...) or our(...) | ||
| 550 | for ($lop = $kid; !B::Deparse::null($lop); $lop = $lop->sibling) { | ||
| 551 | # This assumes that no other private flags equal 128, and that | ||
| 552 | # OPs that store things other than flags in their op_private, | ||
| 553 | # like OP_AELEMFAST, won't be immediate children of a list. | ||
| 554 | # | ||
| 555 | # OP_ENTERSUB and OP_SPLIT can break this logic, so check for them. | ||
| 556 | # I suspect that open and exit can too. | ||
| 557 | # XXX This really needs to be rewritten to accept only those ops | ||
| 558 | # known to take the OPpLVAL_INTRO flag. | ||
| 559 | |||
| 560 | if (!($lop->private & (B::Deparse::OPpLVAL_INTRO|B::Deparse::OPpOUR_INTRO) | ||
| 561 | or $lop->name eq "undef") | ||
| 562 | or $lop->name =~ /^(?:entersub|exit|open|split)\z/) | ||
| 563 | { | ||
| 564 | $local = ""; # or not | ||
| 565 | last; | ||
| 566 | } | ||
| 567 | if ($lop->name =~ /^pad[ash]v$/) { | ||
| 568 | if ($lop->private & B::Deparse::OPpPAD_STATE) { # state() | ||
| 569 | ($local = "", last) if $local =~ /^(?:local|our|my)$/; | ||
| 570 | $local = "state"; | ||
| 571 | } else { # my() | ||
| 572 | ($local = "", last) if $local =~ /^(?:local|our|state)$/; | ||
| 573 | $local = "my"; | ||
| 574 | } | ||
| 575 | } elsif ($lop->name =~ /^(gv|rv2)[ash]v$/ | ||
| 576 | && $lop->private & B::Deparse::OPpOUR_INTRO | ||
| 577 | or $lop->name eq "null" && $lop->first->name eq "gvsv" | ||
| 578 | && $lop->first->private & B::Deparse::OPpOUR_INTRO) { # our() | ||
| 579 | ($local = "", last) if $local =~ /^(?:my|local|state)$/; | ||
| 580 | $local = "our"; | ||
| 581 | } elsif ($lop->name ne "undef" | ||
| 582 | # specifically avoid the "reverse sort" optimisation, | ||
| 583 | # where "reverse" is nullified | ||
| 584 | && !($lop->name eq 'sort' && ($lop->flags & B::Deparse::OPpSORT_REVERSE))) | ||
| 585 | { | ||
| 586 | # local() | ||
| 587 | ($local = "", last) if $local =~ /^(?:my|our|state)$/; | ||
| 588 | $local = "local"; | ||
| 589 | } | ||
| 590 | } | ||
| 591 | $local = "" if $local eq "either"; # no point if it's all undefs | ||
| 592 | if (B::Deparse::null $kid->sibling and not $local) { | ||
| 593 | my $info = $self->deparse($kid, $cx, $op); | ||
| 594 | $info->update_other_ops($pushmark_op); | ||
| 595 | return $info; | ||
| 596 | } | ||
| 597 | |||
| 598 | for (; !B::Deparse::null($kid); $kid = $kid->sibling) { | ||
| 599 | if ($local) { | ||
| 600 | if (class($kid) eq "UNOP" and $kid->first->name eq "gvsv") { | ||
| 601 | $lop = $kid->first; | ||
| 602 | } else { | ||
| 603 | $lop = $kid; | ||
| 604 | } | ||
| 605 | $self->{'avoid_local'}{$$lop}++; | ||
| 606 | $expr = $self->deparse($kid, 6, $op); | ||
| 607 | delete $self->{'avoid_local'}{$$lop}; | ||
| 608 | } else { | ||
| 609 | $expr = $self->deparse($kid, 6, $op); | ||
| 610 | } | ||
| 611 | push @exprs, $expr; | ||
| 612 | } | ||
| 613 | |||
| 614 | if ($local) { | ||
| 615 | return $self->info_from_template("$local ()", $op, | ||
| 616 | "$local(%C)", [[0, $#exprs, ', ']], | ||
| 617 | \@exprs, | ||
| 618 | {other_ops => [$pushmark_op]}); | ||
| 619 | |||
| 620 | } else { | ||
| 621 | return $self->info_from_template("list", $op, | ||
| 622 | "%C", [[0, $#exprs, ', ']], | ||
| 623 | \@exprs, | ||
| 624 | {maybe_parens => [$self, $cx, 6], | ||
| 625 | other_ops => [$pushmark_op]}); | ||
| 626 | } | ||
| 627 | } | ||
| 628 | |||
| 629 | sub pp_padcv { | ||
| 630 | my($self, $op, $cx) = @_; | ||
| 631 | return info_from_text($op, $self, $self->padany($op), 'padcv', {}); | ||
| 632 | } | ||
| 633 | |||
| 634 | sub pp_refgen | ||
| 635 | { | ||
| 636 | my($self, $op, $cx) = @_; | ||
| 637 | my $kid = $op->first; | ||
| 638 | if ($kid->name eq "null") { | ||
| 639 | my $other_ops = [$kid]; | ||
| 640 | my $anoncode = $kid = $kid->first; | ||
| 641 | if ($anoncode->name eq "anonconst") { | ||
| 642 | $anoncode = $anoncode->first->first->sibling; | ||
| 643 | } | ||
| 644 | if ($anoncode->name eq "anoncode" | ||
| 645 | or !B::Deparse::null($anoncode = $kid->sibling) and | ||
| 646 | $anoncode->name eq "anoncode") { | ||
| 647 | return $self->e_anoncode({ code => $self->padval($anoncode->targ) }); | ||
| 648 | } elsif ($kid->name eq "pushmark") { | ||
| 649 | my $sib_name = $kid->sibling->name; | ||
| 650 | if ($sib_name =~ /^enter(xs)?sub/) { | ||
| 651 | my $kid_info = $self->deparse($kid->sibling, 1, $op); | ||
| 652 | # Always show parens for \(&func()), but only with -p otherwise | ||
| 653 | my @texts = ('\\', $kid_info->{text}); | ||
| 654 | if ($self->{'parens'} or $kid->sibling->private & OPpENTERSUB_AMPER) { | ||
| 655 | @texts = ('(', "\\", $kid_info->{text}, ')'); | ||
| 656 | } | ||
| 657 | return info_from_list($op, $self, \@texts, '', 'refgen_entersub', | ||
| 658 | {body => [$kid_info], | ||
| 659 | other_ops => $other_ops}); | ||
| 660 | } | ||
| 661 | } | ||
| 662 | } | ||
| 663 | local $self->{'in_refgen'} = 1; | ||
| 664 | $self->pfixop($op, $cx, "\\", 20); | ||
| 665 | } | ||
| 666 | |||
| 667 | sub pp_require | ||
| 668 | { | ||
| 669 | my($self, $op, $cx) = @_; | ||
| 670 | my $opname = $op->flags & OPf_SPECIAL ? 'CORE::require' : 'require'; | ||
| 671 | if (class($op) eq "UNOP" and $op->first->name eq "const" | ||
| 672 | and $op->first->private & B::OPpCONST_BARE) { | ||
| 673 | my $name = $self->const_sv($op->first)->PV; | ||
| 674 | $name =~ s[/][::]g; | ||
| 675 | $name =~ s/\.pm//g; | ||
| 676 | return info_from_list($op, $self, [$opname, $name], ' ', | ||
| 677 | 'require', | ||
| 678 | {maybe_parens => [$self, $cx, 16]}); | ||
| 679 | } else { | ||
| 680 | return $self->unop( | ||
| 681 | $op, $cx, | ||
| 682 | $op->first->name eq 'const' | ||
| 683 | && $op->first->private & B::OPpCONST_NOVER | ||
| 684 | ? "no" | ||
| 685 | : $opname, | ||
| 686 | 1, # llafr does not apply | ||
| 687 | ); | ||
| 688 | } | ||
| 689 | Carp::confess("unhandled condition in pp_require"); | ||
| 690 | } | ||
| 691 | |||
| 692 | |||
| 693 | sub pp_schomp { maybe_targmy(@_, \&unop, "chomp") } | ||
| 694 | sub pp_schop { maybe_targmy(@_, \&unop, "chop") } | ||
| 695 | sub pp_scope { scopeop(0, @_); } | ||
| 696 | |||
| 697 | sub pp_and { logop(@_, "and", 3, "&&", 11, "if") } | ||
| 698 | |||
| 699 | sub pp_cond_expr | ||
| 700 | { | ||
| 701 | my $self = shift; | ||
| 702 | my($op, $cx) = @_; | ||
| 703 | my $cond = $op->first; | ||
| 704 | my $true = $cond->sibling; | ||
| 705 | my $false = $true->sibling; | ||
| 706 | my $cuddle = $self->{'cuddle'}; | ||
| 707 | my $type = 'if'; | ||
| 708 | unless ($cx < 1 and (B::Deparse::is_scope($true) and $true->name ne "null") and | ||
| 709 | (B::Deparse::is_scope($false) || B::Deparse::is_ifelse_cont($false)) | ||
| 710 | and $self->{'expand'} < 7) { | ||
| 711 | # FIXME: turn into template | ||
| 712 | my $cond_info = $self->deparse($cond, 8, $op); | ||
| 713 | my $true_info = $self->deparse($true, 6, $op); | ||
| 714 | my $false_info = $self->deparse($false, 8, $op); | ||
| 715 | return $self->info_from_template('ternary ?', $op, "%c ? %c : %c", | ||
| 716 | [0, 1, 2], | ||
| 717 | [$cond_info, $true_info, $false_info], | ||
| 718 | {maybe_parens => [$self, $cx, 8]}); | ||
| 719 | } | ||
| 720 | |||
| 721 | my $cond_info = $self->deparse($cond, 1, $op); | ||
| 722 | my $true_info = $self->deparse($true, 0, $op); | ||
| 723 | my $fmt = "%|if (%c) {\n%+%c\n%-}"; | ||
| 724 | my @exprs = ($cond_info, $true_info); | ||
| 725 | my @args_spec = (0, 1); | ||
| 726 | |||
| 727 | my $i; | ||
| 728 | for ($i=0; !B::Deparse::null($false) and B::Deparse::is_ifelse_cont($false); $i++) { | ||
| 729 | my $newop = $false->first; | ||
| 730 | my $newcond = $newop->first; | ||
| 731 | my $newtrue = $newcond->sibling; | ||
| 732 | $false = $newtrue->sibling; # last in chain is OP_AND => no else | ||
| 733 | if ($newcond->name eq "lineseq") | ||
| 734 | { | ||
| 735 | # lineseq to ensure correct line numbers in elsif() | ||
| 736 | # Bug #37302 fixed by change #33710. | ||
| 737 | $newcond = $newcond->first->sibling; | ||
| 738 | } | ||
| 739 | my $newcond_info = $self->deparse($newcond, 1, $op); | ||
| 740 | my $newtrue_info = $self->deparse($newtrue, 0, $op); | ||
| 741 | push @args_spec, scalar(@args_spec), scalar(@args_spec)+1; | ||
| 742 | push @exprs, $newcond_info, $newtrue_info; | ||
| 743 | $fmt .= " elsif ( %c ) {\n%+%c\n\%-}"; | ||
| 744 | } | ||
| 745 | $type .= " elsif($i)" if $i; | ||
| 746 | my $false_info; | ||
| 747 | if (!B::Deparse::null($false)) { | ||
| 748 | $false_info = $self->deparse($false, 0, $op); | ||
| 749 | $fmt .= "${cuddle}else {\n%+%c\n%-}"; | ||
| 750 | push @args_spec, scalar(@args_spec); | ||
| 751 | push @exprs, $false_info; | ||
| 752 | $type .= ' else'; | ||
| 753 | } | ||
| 754 | return $self->info_from_template($type, $op, $fmt, \@args_spec, \@exprs); | ||
| 755 | } | ||
| 756 | |||
| 757 | sub pp_const { | ||
| 758 | my $self = shift; | ||
| 759 | my($op, $cx) = @_; | ||
| 760 | if ($op->private & OPpCONST_ARYBASE) { | ||
| 761 | return info_from_text($op, $self, '$[', 'const_ary', {}); | ||
| 762 | } | ||
| 763 | # if ($op->private & OPpCONST_BARE) { # trouble with '=>' autoquoting | ||
| 764 | # return $self->const_sv($op)->PV; | ||
| 765 | # } | ||
| 766 | my $sv = $self->const_sv($op); | ||
| 767 | return $self->const($sv, $cx);; | ||
| 768 | } | ||
| 769 | |||
| 770 | # Handle subroutien calls. These are a bit complicated. | ||
| 771 | # NOTE: this is not right for CPerl, so it needs to be split out. | ||
| 772 | sub pp_entersub | ||
| 773 | { | ||
| 774 | my($self, $op, $cx) = @_; | ||
| 775 | return $self->e_method($op, $self->_method($op, $cx)) | ||
| 776 | unless B::Deparse::null $op->first->sibling; | ||
| 777 | my $prefix = ""; | ||
| 778 | my $amper = ""; | ||
| 779 | my($kid, @exprs); | ||
| 780 | if ($op->flags & OPf_SPECIAL && !($op->flags & OPf_MOD)) { | ||
| 781 | $prefix = "do "; | ||
| 782 | } elsif ($op->private & OPpENTERSUB_AMPER) { | ||
| 783 | $amper = "&"; | ||
| 784 | } | ||
| 785 | $kid = $op->first; | ||
| 786 | |||
| 787 | my $other_ops = [$kid, $kid->first]; | ||
| 788 | $kid = $kid->first->sibling; # skip ex-list, pushmark | ||
| 789 | |||
| 790 | for (; not B::Deparse::null $kid->sibling; $kid = $kid->sibling) { | ||
| 791 | push @exprs, $kid; | ||
| 792 | } | ||
| 793 | my ($simple, $proto, $subname_info) = (0, undef, undef); | ||
| 794 | if (B::Deparse::is_scope($kid)) { | ||
| 795 | $amper = "&"; | ||
| 796 | $subname_info = $self->deparse($kid, 0, $op); | ||
| 797 | $subname_info->{texts} = ['{', $subname_info->texts, '}']; | ||
| 798 | $subname_info->{text} = join('', @$subname_info->{texts}); | ||
| 799 | } elsif ($kid->first->name eq "gv") { | ||
| 800 | my $gv = $self->gv_or_padgv($kid->first); | ||
| 801 | my $cv; | ||
| 802 | if (class($gv) eq 'GV' && class($cv = $gv->CV) ne "SPECIAL" | ||
| 803 | || $gv->FLAGS & SVf_ROK && class($cv = $gv->RV) eq 'CV') { | ||
| 804 | $proto = $cv->PV if $cv->FLAGS & SVf_POK; | ||
| 805 | } | ||
| 806 | $simple = 1; # only calls of named functions can be prototyped | ||
| 807 | $subname_info = $self->deparse($kid, 24, $op); | ||
| 808 | my $fq; | ||
| 809 | # Fully qualify any sub name that conflicts with a lexical. | ||
| 810 | if ($self->lex_in_scope("&$kid") | ||
| 811 | || $self->lex_in_scope("&$kid", 1)) | ||
| 812 | { | ||
| 813 | $fq++; | ||
| 814 | } elsif (!$amper) { | ||
| 815 | if ($subname_info->{text} eq 'main::') { | ||
| 816 | $subname_info->{text} = '::'; | ||
| 817 | } else { | ||
| 818 | if ($kid !~ /::/ && $kid ne 'x') { | ||
| 819 | # Fully qualify any sub name that is also a keyword. While | ||
| 820 | # we could check the import flag, we cannot guarantee that | ||
| 821 | # the code deparsed so far would set that flag, so we qual- | ||
| 822 | # ify the names regardless of importation. | ||
| 823 | if (exists $feature_keywords{$kid}) { | ||
| 824 | $fq++ if $self->feature_enabled($kid); | ||
| 825 | } elsif (do { local $@; local $SIG{__DIE__}; | ||
| 826 | eval { () = prototype "CORE::$kid"; 1 } }) { | ||
| 827 | $fq++ | ||
| 828 | } | ||
| 829 | } | ||
| 830 | } | ||
| 831 | if ($subname_info->{text} !~ /^(?:\w|::)(?:[\w\d]|::(?!\z))*\z/) { | ||
| 832 | $subname_info->{text} = $self->single_delim($$kid, "q", "'", $kid) . '->'; | ||
| 833 | } | ||
| 834 | } | ||
| 835 | } elsif (B::Deparse::is_scalar ($kid->first) && $kid->first->name ne 'rv2cv') { | ||
| 836 | $amper = "&"; | ||
| 837 | $subname_info = $self->deparse($kid, 24, $op); | ||
| 838 | } else { | ||
| 839 | $prefix = ""; | ||
| 840 | my $arrow = is_subscriptable($kid->first) || $kid->first->name eq "padcv" ? "" : "->"; | ||
| 841 | $subname_info = $self->deparse($kid, 24, $op); | ||
| 842 | $subname_info->{text} .= $arrow; | ||
| 843 | } | ||
| 844 | |||
| 845 | # Doesn't matter how many prototypes there are, if | ||
| 846 | # they haven't happened yet! | ||
| 847 | my $declared; | ||
| 848 | my $sub_name = $subname_info->{text}; | ||
| 849 | { | ||
| 850 | no strict 'refs'; | ||
| 851 | no warnings 'uninitialized'; | ||
| 852 | $declared = exists $self->{'subs_declared'}{$sub_name} | ||
| 853 | || ( | ||
| 854 | defined &{ ${$self->{'curstash'}."::"}{$sub_name} } | ||
| 855 | && !exists | ||
| 856 | $self->{'subs_deparsed'}{$self->{'curstash'}."::" . $sub_name} | ||
| 857 | && defined prototype $self->{'curstash'}."::" . $sub_name | ||
| 858 | ); | ||
| 859 | if (!$declared && defined($proto)) { | ||
| 860 | # Avoid "too early to check prototype" warning | ||
| 861 | ($amper, $proto) = ('&'); | ||
| 862 | } | ||
| 863 | } | ||
| 864 | |||
| 865 | my (@texts, @body, $type); | ||
| 866 | @body = (); | ||
| 867 | if ($declared and defined $proto and not $amper) { | ||
| 868 | my $args; | ||
| 869 | ($amper, $args) = $self->check_proto($op, $proto, @exprs); | ||
| 870 | if ($amper eq "&") { | ||
| 871 | @body = map($self->deparse($_, 6, $op), @exprs); | ||
| 872 | } else { | ||
| 873 | @body = @$args if @$args; | ||
| 874 | } | ||
| 875 | } else { | ||
| 876 | @body = map($self->deparse($_, 6, $op), @exprs); | ||
| 877 | } | ||
| 878 | |||
| 879 | if ($prefix or $amper) { | ||
| 880 | if ($sub_name eq '&') { | ||
| 881 | # &{&} cannot be written as && | ||
| 882 | $subname_info->{texts} = ["{", @{$subname_info->{texts}}, "}"]; | ||
| 883 | $subname_info->{text} = join('', $subname_info->{texts}); | ||
| 884 | } | ||
| 885 | if ($op->flags & OPf_STACKED) { | ||
| 886 | $type = 'prefix- or &-stacked call()'; | ||
| 887 | @texts = ($prefix, $amper, $subname_info, "(", $self->combine2str(', ', \@body), ")"); | ||
| 888 | } else { | ||
| 889 | $type = 'prefix or &- call'; | ||
| 890 | @texts = ($prefix, $amper, $subname_info); | ||
| 891 | } | ||
| 892 | } else { | ||
| 893 | # It's a syntax error to call CORE::GLOBAL::foo with a prefix, | ||
| 894 | # so it must have been translated from a keyword call. Translate | ||
| 895 | # it back. | ||
| 896 | $subname_info->{text} =~ s/^CORE::GLOBAL:://; | ||
| 897 | my $dproto = defined($proto) ? $proto : "undefined"; | ||
| 898 | if (!$declared) { | ||
| 899 | $type = 'call (no prior declaration)'; | ||
| 900 | @texts = dedup_parens_func($self, $subname_info, \@body); | ||
| 901 | my $node = B::DeparseTree::Node->new($op, $self, \@texts, | ||
| 902 | '', $type, | ||
| 903 | {other_ops => $other_ops}); | ||
| 904 | |||
| 905 | # Take the subname_info portion of $node and use that as the | ||
| 906 | # part of the parent, null, pushmark ops. | ||
| 907 | if ($subname_info && $other_ops) { | ||
| 908 | my $str = $node->{text}; | ||
| 909 | my $position = [0, length($subname_info->{text})]; | ||
| 910 | my @new_ops = (); | ||
| 911 | foreach my $skipped_op (@$other_ops) { | ||
| 912 | my $new_op = $self->info_from_string($op->name, $skipped_op, $str, | ||
| 913 | {position => $position}); | ||
| 914 | push @new_ops, $new_op; | ||
| 915 | } | ||
| 916 | $node->{other_ops} = \@new_ops; | ||
| 917 | } | ||
| 918 | return $node; | ||
| 919 | |||
| 920 | } elsif ($dproto =~ /^\s*\z/) { | ||
| 921 | $type = 'call no protype'; | ||
| 922 | @texts = ($subname_info); | ||
| 923 | } elsif ($dproto eq "\$" and B::Deparse::is_scalar($exprs[0])) { | ||
| 924 | $type = 'call - $ prototype'; | ||
| 925 | # is_scalar is an excessively conservative test here: | ||
| 926 | # really, we should be comparing to the precedence of the | ||
| 927 | # top operator of $exprs[0] (ala unop()), but that would | ||
| 928 | # take some major code restructuring to do right. | ||
| 929 | @texts = $self->maybe_parens_func($sub_name, $self->combine2str(', ', \@body), $cx, 16); | ||
| 930 | } elsif ($dproto ne '$' and defined($proto) || $simple) { #' | ||
| 931 | $type = "call $sub_name having prototype"; | ||
| 932 | @texts = $self->maybe_parens_func($sub_name, $self->combine2str(', ', \@body), $cx, 5); | ||
| 933 | return B::DeparseTree::Node->new($op, $self, \@texts, | ||
| 934 | '', $type, | ||
| 935 | {other_ops => $other_ops}); | ||
| 936 | } else { | ||
| 937 | $type = 'call'; | ||
| 938 | @texts = dedup_parens_func($self, $subname_info, \@body); | ||
| 939 | return B::DeparseTree::Node->new($op, $self, \@texts, | ||
| 940 | '', $type, | ||
| 941 | {other_ops => $other_ops}); | ||
| 942 | } | ||
| 943 | } | ||
| 944 | my $node = $self->info_from_template($type, $op, | ||
| 945 | '%C', [[0, $#texts, '']], \@texts, | ||
| 946 | {other_ops => $other_ops}); | ||
| 947 | |||
| 948 | # Take the subname_info portion of $node and use that as the | ||
| 949 | # part of the parent, null, pushmark ops. | ||
| 950 | if ($subname_info && $other_ops) { | ||
| 951 | my $str = $node->{text}; | ||
| 952 | my $position = [0, length($subname_info->{text})]; | ||
| 953 | my @new_ops = (); | ||
| 954 | foreach my $skipped_op (@$other_ops) { | ||
| 955 | my $new_op = $self->info_from_string($op->name, $skipped_op, $str, | ||
| 956 | {position => $position}); | ||
| 957 | push @new_ops, $new_op; | ||
| 958 | } | ||
| 959 | $node->{other_ops} = \@new_ops; | ||
| 960 | } | ||
| 961 | return $node; | ||
| 962 | } | ||
| 963 | |||
| 964 | sub pp_entereval { | ||
| 965 | unop( | ||
| 966 | @_, | ||
| 967 | $_[1]->private & OPpEVAL_BYTES ? 'evalbytes' : "eval" | ||
| 968 | ) | ||
| 969 | } | ||
| 970 | |||
| 971 | sub pp_flop | ||
| 972 | { | ||
| 973 | my $self = shift; | ||
| 974 | my($op, $cx) = @_; | ||
| 975 | my $flip = $op->first; | ||
| 976 | my $type = ($flip->flags & OPf_SPECIAL) ? "..." : ".."; | ||
| 977 | my $node =$self->range($flip->first, $cx, $type); | ||
| 978 | return $self->info_from_template("pp_flop $type", $op, "%c", undef, [$node], {}); | ||
| 979 | } | ||
| 980 | |||
| 981 | sub pp_gv | ||
| 982 | { | ||
| 983 | my($self, $op, $cx) = @_; | ||
| 984 | my $gv = $self->gv_or_padgv($op); | ||
| 985 | my $name = $self->gv_name($gv); | ||
| 986 | return $self->info_from_string("global variable $name", $op, $name); | ||
| 987 | } | ||
| 988 | |||
| 989 | # FIXME: adjust use of maybe_local_str | ||
| 990 | sub pp_gvsv | ||
| 991 | { | ||
| 992 | my($self, $op, $cx) = @_; | ||
| 993 | my $gv = $self->gv_or_padgv($op); | ||
| 994 | return $self->maybe_local_str($op, $cx, | ||
| 995 | $self->stash_variable("\$", | ||
| 996 | $self->gv_name($gv), $cx)); | ||
| 997 | } | ||
| 998 | |||
| 999 | sub pp_null | ||
| 1000 | { | ||
| 1001 | $] < 5.022 ? null_older(@_) : null_newer(@_); | ||
| 1002 | } | ||
| 1003 | |||
| 1004 | sub pp_once | ||
| 1005 | { | ||
| 1006 | my ($self, $op, $cx) = @_; | ||
| 1007 | my $cond = $op->first; | ||
| 1008 | my $true = $cond->sibling; | ||
| 1009 | |||
| 1010 | return $self->deparse($true, $cx); | ||
| 1011 | } | ||
| 1012 | |||
| 1013 | sub pp_print { indirop(@_, "print") } | ||
| 1014 | sub pp_prtf { indirop(@_, "printf") } | ||
| 1015 | |||
| 1016 | sub pp_rand { maybe_targmy(@_, \&unop, "rand") } | ||
| 1017 | |||
| 1018 | sub pp_or { logop(@_, "or", 2, "||", 10, "unless") } | ||
| 1019 | sub pp_dor { logop(@_, "//", 10) } | ||
| 1020 | |||
| 1021 | sub pp_mapwhile { mapop(@_, "map") } | ||
| 1022 | sub pp_grepwhile { mapop(@_, "grep") } | ||
| 1023 | |||
| 1024 | sub pp_complement { maybe_targmy(@_, \&pfixop, "~", 21) } | ||
| 1025 | sub pp_getppid { maybe_targmy(@_, \&baseop, "getppid") } | ||
| 1026 | sub pp_postdec { maybe_targmy(@_, \&pfixop, "--", 23, POSTFIX) } | ||
| 1027 | sub pp_postinc { maybe_targmy(@_, \&pfixop, "++", 23, POSTFIX) } | ||
| 1028 | sub pp_time { maybe_targmy(@_, \&baseop, "time") } | ||
| 1029 | |||
| 1030 | sub pp_preinc { pfixop(@_, "++", 23) } | ||
| 1031 | sub pp_predec { pfixop(@_, "--", 23) } | ||
| 1032 | sub pp_i_preinc { pfixop(@_, "++", 23) } | ||
| 1033 | sub pp_i_predec { pfixop(@_, "--", 23) } | ||
| 1034 | |||
| 1035 | sub pp_subst { | ||
| 1036 | { | ||
| 1037 | $] < 5.022 ? subst_older(@_) : subst_newer(@_); | ||
| 1038 | } | ||
| 1039 | } | ||
| 1040 | |||
| 1041 | sub pp_substr { | ||
| 1042 | my ($self,$op,$cx) = @_; | ||
| 1043 | if ($op->private & B::Deparse::OPpSUBSTR_REPL_FIRST) { | ||
| 1044 | my $left = listop($self, $op, 7, "substr", $op->first->sibling->sibling); | ||
| 1045 | my $right = $self->deparse($op->first->sibling, 7, $op); | ||
| 1046 | return info_from_list($op, $self,[$left, '=', $right], ' ', | ||
| 1047 | 'substr_repl_first', {}); | ||
| 1048 | } | ||
| 1049 | return maybe_local(@_, listop(@_, "substr")) | ||
| 1050 | } | ||
| 1051 | # FIXME: | ||
| 1052 | # Different between 5.20 and 5.22. We've used 5.22 though. | ||
| 1053 | # Go over and make sure this is okay. | ||
| 1054 | sub pp_stub { | ||
| 1055 | my ($self, $op) = @_; | ||
| 1056 | $self->info_from_string('stub ()', $op, '()') | ||
| 1057 | }; | ||
| 1058 | |||
| 1059 | sub pp_symlink { maybe_targmy(@_, \&listop, "symlink") } | ||
| 1060 | |||
| 1061 | sub pp_trans { | ||
| 1062 | my $self = shift; | ||
| 1063 | my($op, $cx) = @_; | ||
| 1064 | my($from, $to); | ||
| 1065 | my $class = class($op); | ||
| 1066 | my $priv_flags = $op->private; | ||
| 1067 | if ($class eq "PVOP") { | ||
| 1068 | ($from, $to) = B::Deparse::tr_decode_byte($op->pv, $priv_flags); | ||
| 1069 | } elsif ($class eq "PADOP") { | ||
| 1070 | ($from, $to) | ||
| 1071 | = tr_decode_utf8($self->padval($op->padix)->RV, $priv_flags); | ||
| 1072 | } else { # class($op) eq "SVOP" | ||
| 1073 | ($from, $to) = B::Deparse::tr_decode_utf8($op->sv->RV, $priv_flags); | ||
| 1074 | } | ||
| 1075 | my $flags = ""; | ||
| 1076 | $flags .= "c" if $priv_flags & OPpTRANS_COMPLEMENT; | ||
| 1077 | $flags .= "d" if $priv_flags & OPpTRANS_DELETE; | ||
| 1078 | $to = "" if $from eq $to and $flags eq ""; | ||
| 1079 | $flags .= "s" if $priv_flags & OPpTRANS_SQUASH; | ||
| 1080 | return info_from_list($op, $self, ['tr', double_delim($from, $to), $flags], | ||
| 1081 | '', 'pp_trans', {}); | ||
| 1082 | } | ||
| 1083 | |||
| 1084 | sub pp_transr { | ||
| 1085 | my $self = $_[0]; | ||
| 1086 | my $op = $_[1]; | ||
| 1087 | my $info = pp_trans(@_); | ||
| 1088 | return info_from_text($op, $self, $info->{text} . 'r', 'pp_transr', | ||
| 1089 | {body => [$info]}); | ||
| 1090 | } | ||
| 1091 | |||
| 1092 | sub pp_unstack { | ||
| 1093 | my ($self, $op) = @_; | ||
| 1094 | # see also leaveloop | ||
| 1095 | return info_from_text($op, $self, '', 'unstack', {}); | ||
| 1096 | } | ||
| 1097 | |||
| 1098 | sub pp_wait { maybe_targmy(@_, \&baseop, "wait") } | ||
| 1099 | sub pp_wantarray { baseop(@_, "wantarray") } | ||
| 1100 | |||
| 1101 | # xor is syntactically a logop, but it's really a binop (contrary to | ||
| 1102 | # old versions of opcode.pl). Syntax is what matters here. | ||
| 1103 | sub pp_xor { logop(@_, "xor", 2, "", 0, "") } | ||
| 1104 | |||
| 1105 | 1; |