Debian Codegraph @

regen/op_private

raw
1 #!perl
2
3 =head1 F<regen/op_private>
4
5 This file contains all the definitions of the meanings of the flags in the
6 op_private field of an OP.
7
8 After editing this file, run C<make regen>. This will generate/update data
9 in:
10
11 opcode.h
12 lib/B/Op_private.pm
13
14 C<B::Op_private> holds three global hashes, C<%bits>, C<%defines>,
15 C<%labels>, which hold roughly the same information as found in this file
16 (after processing).
17
18 F<opcode.h> gains a series of C<OPp*> defines, and a few static data
19 structures:
20
21 C<PL_op_private_valid> defines, per-op, which op_private bits are legally
22 allowed to be set. This is a good first place to look to see if an op has
23 any spare private bits.
24
25 C<PL_op_private_bitdef_ix>, C<PL_op_private_bitdefs>,
26 C<PL_op_private_labels>, C<PL_op_private_bitfields>,
27 C<PL_op_private_valid> contain (in a compact form) the data needed by
28 Perl_do_op_dump() to dump the op_private field of an op.
29
30 This file actually contains perl code which is run by F<regen/opcode.pl>.
31 The basic idea is that you keep calling addbits() to add definitions of
32 what a particular bit or range of bits in op_private means for a
33 particular op. This can be specified either as a 1-bit flag or a 1-or-more
34 bit bit field. Here's a general example:
35
36 addbits('aelem',
37 7 => qw(OPpLVAL_INTRO LVINTRO),
38 6 => qw(OPpLVAL_DEFER LVDEFER),
39 '4..5' => {
40 mask_def => 'OPpDEREF',
41 enum => [ qw(
42 1 OPpDEREF_AV DREFAV
43 2 OPpDEREF_HV DREFHV
44 3 OPpDEREF_SV DREFSV
45 )],
46 },
47 );
48
49 Here for the op C<aelem>, bits 6 and 7 (bits are numbered 0..7) are
50 defined as single-bit flags. The first string following the bit number is
51 the define name that gets emitted in F<opcode.h>, and the second string is
52 the label, which will be displayed by F<Concise.pm> and Perl_do_op_dump()
53 (as used by C<perl -Dx>).
54
55 If the bit number is actually two numbers connected with '..', then this
56 defines a bit field, which is 1 or more bits taken to hold a small
57 unsigned integer. Instead of two string arguments, it just has a single
58 hash ref argument. A bit field allows you to generate extra defines, such
59 as a mask, and optionally allows you to define an enumeration, where a
60 subset of the possible values of the bit field are given their own defines
61 and labels. The full syntax of this hash is explained further below.
62
63 Note that not all bits for a particular op need to be added in a single
64 addbits() call; they accumulate. In particular, this file is arranged in
65 two halves; first, generic flags shared by multiple ops are added, then
66 in the second half, specific per-op flags are added, e.g.
67
68 addbits($_, 7 => qw(OPpLVAL_INTRO LVINTRO)) for qw(pos substr vec ...);
69
70 ....
71
72 addbits('substr',
73 4 => qw(OPpSUBSTR_REPL_FIRST REPL1ST),
74 3 => ...
75 );
76
77 (although the dividing line between these two halves is somewhat
78 subjective, and is based on whether "OPp" is followed by the op name or
79 something generic).
80
81 There are some utility functions for generating a list of ops from
82 F<regen/opcodes> based on various criteria. These are:
83
84 ops_with_check('ck_foo')
85 ops_with_flag('X')
86 ops_with_arg(N, 'XYZ')
87
88 which respectively return a list of op names where:
89
90 field 3 of regen/opcodes specifies 'ck_foo' as the check function;
91 field 4 of regen/opcodes has flag or type 'X' set;
92 argument field N of regen/opcodes matches 'XYZ';
93
94 For example
95
96 addbits($_, 4 => qw(OPpTARGET_MY TARGMY)) for ops_with_flag('T');
97
98 If a label is specified as '-', then the flag or bit field is not
99 displayed symbolically by Concise/-Dx; instead the bits are treated as
100 unrecognised and are included in the final residual integer value after
101 all recognised bits have been processed (this doesn't apply to individual
102 enum labels).
103
104 Here is a full example of a bit field hash:
105
106 '5..6' => {
107 mask_def => 'OPpFOO_MASK',
108 baseshift_def => 'OPpFOO_SHIFT',
109 bitcount_def => 'OPpFOO_BITS',
110 label => 'FOO',
111 enum => [ qw(
112 1 OPpFOO_A A
113 2 OPpFOO_B B
114 3 OPpFOO_C C
115 )],
116 };
117
118 The optional C<*_def> keys cause defines to be emitted that specify
119 useful values based on the bit range (5 to 6 in this case):
120
121 mask_def: a mask that will extract the bit field
122 baseshift_def: how much to shift to make the bit field reach bit 0
123 bitcount_def: how many bits make up the bit field
124
125 The example above will generate
126
127 #define OPpFOO_MASK 0x60
128 #define OPpFOO_SHIFT 5
129 #define OPpFOO_BITS 2
130
131 The optional enum list specifies a set of defines and labels for (possibly
132 a subset of) the possible values of the bit field (which in this example
133 are 0,1,2,3). If a particular value matches an enum, then it will be
134 displayed symbolically (e.g. 'C'), otherwise as a small integer. The
135 defines are suitably shifted. The example above will generate
136
137 #define OPpFOO_A 0x20
138 #define OPpFOO_B 0x40
139 #define OPpFOO_C 0x60
140
141 So you can write code like
142
143 if ((o->op_private & OPpFOO_MASK) == OPpFOO_C) ...
144
145 The optional 'label' key causes Concise/-Dx output to prefix the value
146 with C<LABEL=>; so in this case it might display C<FOO=C>. If the field
147 value is zero, and if no label is present, and if no enum matches, then
148 the field isn't displayed.
149
150 =cut
151
152
153 use warnings;
154 use strict;
155
156
157
158
159 # ====================================================================
160 #
161 # GENERIC OPpFOO flags
162 #
163 # Flags where FOO is a generic term (like LVAL), and the flag is
164 # shared between multiple (possibly unrelated) ops.
165
166
167
168
169 {
170 # The lower few bits of op_private often indicate the number of
171 # arguments. This is usually set by newUNOP() and newLOGOP (to 1),
172 # by newBINOP() (to 1 or 2), and by ck_fun() (to 1..15).
173 #
174 # These values are sometimes used at runtime: in particular,
175 # the MAXARG macro extracts out the lower 4 bits.
176 #
177 # Some ops encroach upon these bits; for example, entersub is a unop,
178 # but uses bit 0 for something else. Bit 0 is initially set to 1 in
179 # newUNOP(), but is later cleared (in ck_rvconst()), when the code
180 # notices that this op is an entersub.
181 #
182 # The important thing below is that any ops which use MAXARG at
183 # runtime must have all 4 bits allocated; if bit 3 were used for a new
184 # flag say, then things could break. The information on the other
185 # types of op is for completeness (so we can account for every bit
186 # used in every op)
187
188 my (%maxarg, %args0, %args1, %args2, %args3, %args4);
189
190 # these are the functions which currently use MAXARG at runtime
191 # (i.e. in the pp() functions). Thus they must always have 4 bits
192 # allocated
193 $maxarg{$_} = 1 for qw(
194 binmode bless caller chdir close enterwrite eof exit fileno getc
195 getpgrp gmtime index mkdir rand reset setpgrp sleep srand sysopen
196 tell umask
197 );
198
199 # find which ops use 0,1,2,3 or 4 bits of op_private for arg count info
200
201 $args0{$_} = 1 for qw(entersub avhvswitch
202 rv2hv aelemfastlex_store); # UNOPs that usurp bit 0
203
204 # Historically, bit ops used bit 0 to indicate 'use integer' in scope;
205 # For now, ban use of bits 0..1 as an arg count, in order to detect
206 # any residual code which conflates use of the HINT_INTEGER and
207 # OPpUSEINT flags
208
209 $args0{$_} = 1 for ops_with_check('ck_bitop');
210
211 $args1{$_} = 1 for (
212 qw(reverse), # ck_fun(), but most bits stolen
213 qw(mapstart grepstart), # set in ck_fun, but
214 # cleared in ck_grep,
215 # unless there is an error
216 grep !$maxarg{$_} && !$args0{$_},
217 ops_with_flag('1'), # UNOP
218 ops_with_flag('+'), # UNOP_AUX
219 ops_with_flag('%'), # BASEOP/UNOP
220 ops_with_flag('|'), # LOGOP
221 ops_with_flag('-'), # FILESTATOP
222 ops_with_flag('}'), # LOOPEXOP
223 ops_with_flag('.'), # METHOP
224 );
225
226 $args2{$_} = 1 for (
227 qw(vec),
228 grep !$maxarg{$_} && !$args0{$_} && !$args1{$_},
229 ops_with_flag('2'), # BINOP
230 );
231
232 $args3{$_} = 1 for grep !$maxarg{$_} && !$args0{$_}
233 && !$args1{$_} && !$args2{$_},
234 # substr starts off with 4 bits set in
235 # ck_fun(), but since it never has more than 7
236 # args, bit 3 is later stolen
237 qw(substr);
238
239 $args4{$_} = 1 for keys %maxarg,
240 grep !$args0{$_} && !$args1{$_}
241 && !$args2{$_} && !$args3{$_},
242 ops_with_check('ck_fun'),
243 # these other ck_*() functions call ck_fun()
244 ops_with_check('ck_exec'),
245 ops_with_check('ck_glob'),
246 ops_with_check('ck_index'),
247 ops_with_check('ck_join'),
248 ops_with_check('ck_lfun'),
249 ops_with_check('ck_open'),
250 ops_with_check('ck_select'),
251 ops_with_check('ck_stringify'),
252 ops_with_check('ck_tell'),
253 ops_with_check('ck_trunc'),
254 ;
255
256
257 for (sort keys %args1) {
258 addbits($_, '0..0' => {
259 mask_def => 'OPpARG1_MASK',
260 label => '-',
261 }
262 );
263 }
264
265 for (sort keys %args2) {
266 addbits($_, '0..1' => {
267 mask_def => 'OPpARG2_MASK',
268 label => '-',
269 }
270 );
271 }
272
273 for (sort keys %args3) {
274 addbits($_, '0..2' => {
275 mask_def => 'OPpARG3_MASK',
276 label => '-',
277 }
278 );
279 }
280
281 for (sort keys %args4) {
282 addbits($_, '0..3' => {
283 mask_def => 'OPpARG4_MASK',
284 label => '-',
285 }
286 );
287 }
288 }
289
290
291 # Are these bit ops in the scope of 'use integer'?
292 #
293 # Note that historically they used to use bit 0, which corresponded to
294 # HINT_INTEGER (a bit flags within PL_hints). We deliberately choose
295 # a value (2) different than that flag, and different to the two bits used
296 # to store the argument count, to flush out any residual code which
297 # conflates the two.
298
299 addbits($_, 2 => qw(OPpUSEINT USEINT))
300 for ops_with_check('ck_bitop');
301
302 # if NATIVE_HINTS is defined, op_private on cops holds the top 8 bits
303 # of PL_hints, although only bits 6 & 7 are officially used for that
304 # purpose (the rest ought to be masked off). Bit 5 is set separately
305
306 for (qw(nextstate dbstate)) {
307 addbits($_,
308 5 => qw(OPpHUSH_VMSISH HUSH),
309 );
310 }
311
312
313 # op is in local context, or pad variable is being introduced, e.g.
314 # local $h{foo}
315 # my $x
316
317 addbits($_, 7 => qw(OPpLVAL_INTRO LVINTRO))
318 for qw(gvsv rv2sv rv2hv rv2gv rv2av aelem helem aslice split
319 hslice delete padsv padav padhv enteriter entersub padrange
320 pushmark cond_expr refassign lvref lvrefslice lvavref multideref
321 multiconcat padsv_store undef emptyavhv),
322 'list', # this gets set in my_attrs() for some reason
323 ;
324
325
326
327 # TARGLEX
328 #
329 # in constructs like my $x; ...; $x = $a + $b,
330 # the sassign is optimised away and OPpTARGET_MY is set on the add op
331 #
332 # Note that OPpTARGET_MY is mainly used at compile-time. At run time,
333 # the pp function just updates the SV pointed to by op_targ, and doesn't
334 # care whether that's a PADTMP or a lexical var.
335
336 # Some comments about when its safe to use T/OPpTARGET_MY.
337 #
338 # Safe to set if the ppcode uses:
339 # tryAMAGICbin, tryAMAGICun, SETn, SETi, SETu, PUSHn, PUSHTARG, SETTARG,
340 # SETs(TARG), XPUSHn, XPUSHu,
341 # but make sure set-magic is invoked separately for SETs(TARG) (or change
342 # it to SETTARG).
343 #
344 # Unsafe to set if the ppcode uses dTARG or [X]RETPUSH[YES|NO|UNDEF]
345 #
346 # Only the code paths that handle scalar rvalue context matter. If dTARG
347 # or RETPUSHNO occurs only in list or lvalue paths, T is safe.
348 #
349 # lt and friends do SETs (including ncmp, but not scmp or i_ncmp)
350 #
351 # Additional mode of failure: the opcode can modify TARG before it "used"
352 # all the arguments (or may call an external function which does the same).
353 # If the target coincides with one of the arguments ==> kaboom.
354 #
355 # pp.c pos substr each not OK (RETPUSHUNDEF)
356 # ref not OK (RETPUSHNO)
357 # trans not OK (target is used for lhs, not retval)
358 # ucfirst etc not OK: TMP arg processed inplace
359 # quotemeta not OK (unsafe when TARG == arg)
360 # pack - unknown whether it is safe
361 # sprintf: is calling do_sprintf(TARG,...) which can act on TARG
362 # before other args are processed.
363 #
364 # Suspicious wrt "additional mode of failure" (and only it):
365 # schop, chop, postinc/dec, bit_and etc, complement.
366 #
367 # Also suspicious: 4-arg substr, sprintf, uc/lc (POK_only), reverse, pack.
368 #
369 # substr/vec: doing TAINT_off()???
370 #
371 # pp_hot.c
372 # readline - unknown whether it is safe
373 # match subst not OK (dTARG)
374 # grepwhile not OK (not always setting)
375 # join not OK (unsafe when TARG == arg)
376 #
377 # concat - pp_concat special-cases TARG==arg to avoid
378 # "additional mode of failure"
379 #
380 # pp_ctl.c
381 # mapwhile flip caller not OK (not always setting)
382 #
383 # pp_sys.c
384 # backtick glob warn die not OK (not always setting)
385 # warn not OK (RETPUSHYES)
386 # open fileno getc sysread syswrite ioctl accept shutdown
387 # ftsize(etc) readlink telldir fork alarm getlogin not OK (RETPUSHUNDEF)
388 # umask select not OK (XPUSHs(&PL_sv_undef);)
389 # fileno getc sysread syswrite tell not OK (meth("FILENO" "GETC"))
390 # sselect shm* sem* msg* syscall - unknown whether they are safe
391 # gmtime not OK (list context)
392 #
393 # Suspicious wrt "additional mode of failure": warn, die, select.
394
395
396 addbits($_, 4 => qw(OPpTARGET_MY TARGMY))
397 for ops_with_flag('T'),
398 ;
399
400
401
402
403
404 # op_targ carries a refcount
405 addbits($_, 6 => qw(OPpREFCOUNTED REFC))
406 for qw(leave leavesub leavesublv leavewrite leaveeval);
407
408
409
410 # Do not copy return value
411 addbits($_, 7 => qw(OPpLVALUE LV)) for qw(leave leaveloop);
412
413
414
415 # autovivify: Want ref to something
416 for (qw(rv2gv rv2sv padsv aelem helem entersub)) {
417 addbits($_, '4..5' => {
418 mask_def => 'OPpDEREF',
419 enum => [ qw(
420 1 OPpDEREF_AV DREFAV
421 2 OPpDEREF_HV DREFHV
422 3 OPpDEREF_SV DREFSV
423 )],
424 }
425 );
426 }
427
428
429
430 # Defer creation of array/hash elem
431 addbits($_, 6 => qw(OPpLVAL_DEFER LVDEFER)) for qw(aelem helem multideref);
432
433
434
435 addbits($_, 2 => qw(OPpSLICEWARNING SLICEWARN)) # warn about @hash{$scalar}
436 for qw(rv2hv rv2av padav padhv hslice aslice);
437
438
439
440 # XXX Concise seemed to think that OPpOUR_INTRO is used in rv2gv too,
441 # but I can't see it - DAPM
442 addbits($_, 6 => qw(OPpOUR_INTRO OURINTR)) # Variable was in an our()
443 for qw(gvsv rv2sv rv2av rv2hv enteriter split);
444
445
446
447 # We might be an lvalue to return
448 # 'values' doesn't actually use this bit, but we reserve it here as
449 # pp_values may call Perl_do_kv() which is shared among several ops which
450 # do.
451
452 addbits($_, 3 => qw(OPpMAYBE_LVSUB LVSUB))
453 for qw(aassign rv2av rv2gv rv2hv padav padhv aelem helem aslice hslice
454 av2arylen keys akeys avhvswitch kvaslice kvhslice substr pos vec
455 multideref values);
456
457
458
459 for (qw(rv2hv padhv ref blessed)) {
460 addbits($_, # e.g. %hash in (%hash || $foo) ...
461 4 => qw(OPpMAYBE_TRUEBOOL BOOL?), # but cx not known till run time
462 5 => qw(OPpTRUEBOOL BOOL),
463 );
464 }
465 for (qw(grepwhile index length padav pos rindex rv2av subst)) {
466 addbits($_,
467 5 => qw(OPpTRUEBOOL BOOL), # if (@a) {...}
468 );
469 }
470
471
472 addbits($_, 1 => qw(OPpHINT_STRICT_REFS STRICT))
473 for qw(rv2sv rv2av rv2hv rv2gv multideref);
474
475
476
477 # Treat caller(1) as caller(2)
478 addbits($_, 7 => qw(OPpOFFBYONE +1)) for qw(caller wantarray runcv);
479
480
481
482 # label is in UTF8 */
483 addbits($_, 7 => qw(OPpPV_IS_UTF8 UTF)) for qw(last redo next goto dump);
484
485 # suppress looking up a class name as an IO handle in a method call
486 addbits($_, 1 => qw(OPpMETH_NO_BAREWORD_IO NO_BAREWORD_IO)) for ops_with_flag('.');
487
488 # ====================================================================
489 #
490 # OP-SPECIFIC OPpFOO_* flags:
491 #
492 # where FOO is typically the name of an op, and the flag is used by a
493 # single op (or maybe by a few closely related ops).
494
495
496
497 # note that for refassign, this bit can mean either OPpPAD_STATE or
498 # OPpOUR_INTRO depending on the type of the LH child, .e.g.
499 # \our $foo = ...
500 # \state $foo = ...
501
502 addbits($_, 6 => qw(OPpPAD_STATE STATE)) for qw(padav padhv padsv lvavref
503 lvref refassign pushmark
504 padsv_store undef emptyavhv);
505
506 # NB: both sassign and aassign use the 'OPpASSIGN' naming convention
507 # for their private flags
508
509 # there *may* be common scalar items on both sides of a list assign:
510 # run-time checking will be needed.
511 addbits('aassign', 6 => qw(OPpASSIGN_COMMON_SCALAR COM_SCALAR));
512 #
513 # as above, but it's possible to check for non-commonality with just
514 # a SvREFCNT(lhs) == 1 test for each lhs element
515 addbits('aassign', 5 => qw(OPpASSIGN_COMMON_RC1 COM_RC1));
516
517 # run-time checking is required for an aggregate on the LHS
518 addbits('aassign', 4 => qw(OPpASSIGN_COMMON_AGG COM_AGG));
519
520 addbits('aassign', 2 => qw(OPpASSIGN_TRUEBOOL BOOL)); # if (@a = (...)) {...}
521
522
523 # NB: both sassign and aassign use the 'OPpASSIGN' naming convention
524 # for their private flags
525
526 addbits('sassign',
527 6 => qw(OPpASSIGN_BACKWARDS BKWARD), # Left & right switched
528 7 => qw(OPpASSIGN_CV_TO_GV CV2GV), # Possible optimisation for constants
529 );
530
531
532
533 for (qw(trans transr)) {
534 addbits($_,
535 # There is a character in the lhs representable not using UTF-8 whose
536 # replacement requires UTF-8.
537 0 => qw(OPpTRANS_CAN_FORCE_UTF8 CAN_FORCE_UTF8), # 0-255 range
538 # character maps to 256-INF
539 1 => qw(OPpTRANS_USE_SVOP USE_SVOP),# This is implemented an an svop
540 # vs pvop
541 2 => qw(OPpTRANS_IDENTICAL IDENT), # right side is same as left
542 3 => qw(OPpTRANS_SQUASH SQUASH), # /s
543 # 4 is used for OPpTARGET_MY
544 5 => qw(OPpTRANS_COMPLEMENT COMPL), # /c
545 6 => qw(OPpTRANS_GROWS GROWS), # replacement chars longer than
546 # src chars
547 7 => qw(OPpTRANS_DELETE DEL), # /d
548 );
549 }
550
551
552
553 addbits('repeat', 6 => qw(OPpREPEAT_DOLIST DOLIST)); # List replication
554
555
556
557 # OP_ENTERSUB and OP_RV2CV flags
558 #
559 # Flags are set on entersub and rv2cv in three phases:
560 # parser - the parser passes the flag to the op constructor
561 # check - the check routine called by the op constructor sets the flag
562 # context - application of scalar/ref/lvalue context applies the flag
563 #
564 # In the third stage, an entersub op might turn into an rv2cv op (undef &foo,
565 # \&foo, lock &foo, exists &foo, defined &foo). The two places where that
566 # happens (op_lvalue_flags and doref in op.c) need to make sure the flags do
567 # not conflict, since some flags with different meanings overlap between
568 # the two ops. Flags applied in the context phase are only set when there
569 # is no conversion of op type.
570 #
571 # bit entersub flag phase rv2cv flag phase
572 # --- ------------- ----- ---------- -----
573 # 0 OPpENTERSUB_INARGS context
574 # 1 HINT_STRICT_REFS check HINT_STRICT_REFS check
575 # 2 OPpENTERSUB_HASTARG checki OPpENTERSUB_HASTARG
576 # 3 OPpENTERSUB_AMPER check OPpENTERSUB_AMPER parser
577 # 4 OPpDEREF_AV context
578 # 5 OPpDEREF_HV context OPpMAY_RETURN_CONSTANT parser/context
579 # 6 OPpENTERSUB_DB check OPpENTERSUB_DB
580 # 7 OPpLVAL_INTRO context OPpENTERSUB_NOPAREN parser
581
582 # NB: OPpHINT_STRICT_REFS must equal HINT_STRICT_REFS
583
584 addbits('entersub',
585 0 => qw(OPpENTERSUB_INARGS INARGS), # Lval used as arg to a sub
586 1 => qw(OPpHINT_STRICT_REFS STRICT), # 'use strict' in scope
587 2 => qw(OPpENTERSUB_HASTARG TARG ), # Called from OP tree
588 3 => qw(OPpENTERSUB_AMPER AMPER), # Used & form to call
589 # 4..5 => OPpDEREF, already defined above
590 6 => qw(OPpENTERSUB_DB DBG ), # Debug subroutine
591 # 7 => OPpLVAL_INTRO, already defined above
592 );
593
594 # OpENTERSUB_HASTARG is checked by dXSTARG, used by many XSUBs, to see if
595 # a TARG is available.
596 #
597 # A normal entersub, or these builtin:: ops allocate the TARG and sets this
598 # flag in their ck functions. entersub allocates it since it will be the active
599 # op during execution of the XSUB and this saves creating a new mortal.
600 #
601 # goto never allocates the targ and never sets the flag, but it can call
602 # XSUBs that check the flag (see github #22542)
603 #
604 # call_sv() can create an entersub that has neither the TARG nor the
605 # flag set (and it would be difficult to do so), so we do need the
606 # flag or an equivalent.
607 #
608 # The listed builtin:: pp_ functions need this flag (rather than
609 # assuming a TARG) because their XSUB implementations just call the
610 # pp_ func, which may be called from goto or call_sv() and not have a
611 # TARG allocated.
612
613 addbits($_,
614 2 => qw(OPpENTERSUB_HASTARG TARG ),
615 ) for qw(refaddr reftype ceil floor goto);
616
617 # note that some of these flags are just left-over from when an entersub
618 # is converted into an rv2cv, and could probably be cleared/re-assigned
619
620 addbits('rv2cv',
621 1 => qw(OPpHINT_STRICT_REFS STRICT), # 'use strict' in scope
622 2 => qw(OPpENTERSUB_HASTARG TARG ), # If const sub, return the const
623 3 => qw(OPpENTERSUB_AMPER AMPER ), # Used & form to call
624
625 5 => qw(OPpMAY_RETURN_CONSTANT CONST ),
626 6 => qw(OPpENTERSUB_DB DBG ), # Debug subroutine
627 7 => qw(OPpENTERSUB_NOPAREN NO() ), # bare sub call (without parens)
628 );
629
630
631
632 #foo() called before sub foo was parsed */
633 addbits('gv', 5 => qw(OPpEARLY_CV EARLYCV));
634
635
636
637 # 1st arg is replacement string */
638 addbits('substr', 4 => qw(OPpSUBSTR_REPL_FIRST REPL1ST));
639
640
641
642 addbits('padrange',
643 # bits 0..6 hold target range
644 '0..6' => {
645 label => 'range',
646 mask_def => 'OPpPADRANGE_COUNTMASK',
647 bitcount_def => 'OPpPADRANGE_COUNTSHIFT',
648 }
649 # 7 => OPpLVAL_INTRO, already defined above
650 );
651
652
653
654 for (qw(aelemfast aelemfast_lex aelemfastlex_store)) {
655 addbits($_,
656 '0..7' => {
657 label => 'key',
658 }
659 );
660 }
661
662
663
664 addbits('rv2gv',
665 2 => qw(OPpDONT_INIT_GV NOINIT), # Call gv_fetchpv with GV_NOINIT
666 # (Therefore will return whatever is currently in
667 # the symbol table, not guaranteed to be a PVGV)
668 6 => qw(OPpALLOW_FAKE FAKE), # OK to return fake glob
669 );
670
671
672 # NB OPpITER_REVERSED must always be bit 1: see pp_iter()
673
674 addbits('enteriter',
675 1 => qw(OPpITER_REVERSED REVERSED),# for (reverse ...)
676 3 => qw(OPpITER_DEF DEF), # 'for $_'
677 );
678 addbits('iter', 1 => qw(OPpITER_REVERSED REVERSED));
679
680
681
682 addbits('const',
683 1 => qw(OPpCONST_NOVER NOVER), # no 6;
684 2 => qw(OPpCONST_SHORTCIRCUIT SHORT), # e.g. the constant 5 in (5 || foo)
685 3 => qw(OPpCONST_STRICT STRICT), # bareword subject to strict 'subs'
686 4 => qw(OPpCONST_ENTERED ENTERED), # Has been entered as symbol
687 5 => qw(OPpCONST_BARE BARE), # Was a bare word (filehandle?)
688 '6..7' => { # value derived from __LINE__ etc
689 mask_def => 'OPpCONST_TOKEN_MASK',
690 baseshift_def => 'OPpCONST_TOKEN_SHIFT',
691 bitcount_def => 'OPpCONST_TOKEN_BITS',
692 label => 'TOKEN',
693 enum => [ qw(
694 1 OPpCONST_TOKEN_LINE LINE
695 2 OPpCONST_TOKEN_FILE FILE
696 3 OPpCONST_TOKEN_PACKAGE PACKAGE
697 )],
698 },
699 );
700
701
702
703 # Range arg potentially a line num. */
704 addbits($_, 6 => qw(OPpFLIP_LINENUM LINENUM)) for qw(flip flop);
705
706
707
708 # Guessed that pushmark was needed. */
709 addbits('list', 6 => qw(OPpLIST_GUESSED GUESSED));
710
711
712
713 addbits('delete',
714 5 => qw(OPpKVSLICE KVSLICE), # Operating on a list of key/value pairs
715 6 => qw(OPpSLICE SLICE ), # Operating on a list of keys
716 #7 => OPpLVAL_INTRO, already defined above
717 );
718
719
720
721 # Checking for &sub, not {} or [].
722 addbits('exists', 6 => qw(OPpEXISTS_SUB SUB));
723
724
725
726 addbits('sort',
727 0 => qw(OPpSORT_NUMERIC NUM ), # Optimized away { $a <=> $b }
728 1 => qw(OPpSORT_INTEGER INT ), # Ditto while under "use integer"
729 2 => qw(OPpSORT_REVERSE REV ), # Reversed sort
730 3 => qw(OPpSORT_INPLACE INPLACE), # sort in-place; eg @a = sort @a
731 4 => qw(OPpSORT_DESCEND DESC ), # Descending sort
732 );
733
734
735
736 # reverse in-place (@a = reverse @a) */
737 addbits('reverse', 3 => qw(OPpREVERSE_INPLACE INPLACE));
738
739
740
741 for (qw(open backtick)) {
742 addbits($_,
743 4 => qw(OPpOPEN_IN_RAW INBIN ), # binmode(F,":raw") on input fh
744 5 => qw(OPpOPEN_IN_CRLF INCR ), # binmode(F,":crlf") on input fh
745 6 => qw(OPpOPEN_OUT_RAW OUTBIN), # binmode(F,":raw") on output fh
746 7 => qw(OPpOPEN_OUT_CRLF OUTCR ), # binmode(F,":crlf") on output fh
747 );
748 }
749
750
751
752 # The various OPpFT* filetest ops
753
754 # "use filetest 'access'" is in scope:
755 # this flag is set only on a subset of the FT* ops
756 addbits($_, 1 => qw(OPpFT_ACCESS FTACCESS)) for ops_with_arg(0, 'F-+');
757
758 # all OPpFT* ops except stat and lstat
759 for (grep { $_ !~ /^l?stat$/ } ops_with_flag('-')) {
760 addbits($_,
761 2 => qw(OPpFT_STACKED FTSTACKED ), # stacked filetest,
762 # e.g. "-f" in "-f -x $foo"
763 3 => qw(OPpFT_STACKING FTSTACKING), # stacking filetest.
764 # e.g. "-x" in "-f -x $foo"
765 4 => qw(OPpFT_AFTER_t FTAFTERt ), # previous op was -t
766 );
767 }
768
769
770
771 addbits('entereval',
772 1 => qw(OPpEVAL_HAS_HH HAS_HH ), # Does it have a copy of %^H ?
773 2 => qw(OPpEVAL_UNICODE UNI ),
774 3 => qw(OPpEVAL_BYTES BYTES ),
775 4 => qw(OPpEVAL_COPHH COPHH ), # Construct %^H from COP hints
776 5 => qw(OPpEVAL_RE_REPARSING REPARSE), # eval_sv(..., G_RE_REPARSING)
777 6 => qw(OPpEVAL_EVALSV EVALSV ), # called from eval_sv()
778
779 );
780
781
782
783 # These must not conflict with OPpDONT_INIT_GV or OPpALLOW_FAKE.
784 # See pp.c:S_rv2gv. */
785 addbits('coreargs',
786 0 => qw(OPpCOREARGS_DEREF1 DEREF1), # Arg 1 is a handle constructor
787 1 => qw(OPpCOREARGS_DEREF2 DEREF2), # Arg 2 is a handle constructor
788 #2 reserved for OPpDONT_INIT_GV in rv2gv
789 #4 reserved for OPpALLOW_FAKE in rv2gv
790 6 => qw(OPpCOREARGS_SCALARMOD $MOD ), # \$ rather than \[$@%*]
791 7 => qw(OPpCOREARGS_PUSHMARK MARK ), # Call pp_pushmark
792 );
793
794
795
796 addbits('split',
797 # @a = split() has been replaced with split() where split itself
798 # does the array assign
799 4 => qw(OPpSPLIT_ASSIGN ASSIGN),
800 3 => qw(OPpSPLIT_LEX LEX), # the OPpSPLIT_ASSIGN is a lexical array
801 2 => qw(OPpSPLIT_IMPLIM IMPLIM), # implicit limit
802 );
803
804
805 addbits($_,
806 2 => qw(OPpLVREF_ELEM ELEM ),
807 3 => qw(OPpLVREF_ITER ITER ),
808 '4..5'=> {
809 mask_def => 'OPpLVREF_TYPE',
810 enum => [ qw(
811 0 OPpLVREF_SV SV
812 1 OPpLVREF_AV AV
813 2 OPpLVREF_HV HV
814 3 OPpLVREF_CV CV
815 )],
816 },
817 #6 => qw(OPpPAD_STATE STATE),
818 #7 => qw(OPpLVAL_INTRO LVINTRO),
819 ) for 'refassign', 'lvref';
820
821
822
823 addbits('multideref',
824 4 => qw(OPpMULTIDEREF_EXISTS EXISTS), # deref is actually exists
825 5 => qw(OPpMULTIDEREF_DELETE DELETE), # deref is actually delete
826 );
827
828
829
830 addbits('avhvswitch',
831 '0..1' => {
832 mask_def => 'OPpAVHVSWITCH_MASK',
833 label => 'offset',
834 }
835 );
836
837
838 addbits('argelem',
839 '1..2' => {
840 mask_def => 'OPpARGELEM_MASK',
841 enum => [ qw(
842 0 OPpARGELEM_SV SV
843 1 OPpARGELEM_AV AV
844 2 OPpARGELEM_HV HV
845 )],
846 },
847 );
848
849
850 # rv2hv and padhv in void/scalar context implementing 'keys %h'
851 # directly, without a following OP_KEYS
852
853 addbits('padhv',
854 0 => qw(OPpPADHV_ISKEYS KEYS),
855 );
856 addbits('rv2hv',
857 0 => qw(OPpRV2HV_ISKEYS KEYS),
858 );
859
860 # In conjunction with OPpTRUEBOOL, indicates that the test should be
861 # inverted. This allows both (index() == -1) and (index() != -1)
862 # to optimise away the const and eq/ne
863
864 for (qw(index rindex)) {
865 addbits($_, 6 => qw(OPpINDEX_BOOLNEG NEG));
866 }
867
868
869 addbits('concat',
870 # OPf_STACKED normally indicates .=; but it also gets set to optimise
871 # $a . $b . $c into ($a . $b) .= $c
872 # so that the first concat's PADTMP (which holds the result of $a.$b)
873 # can be reused. Set a flag in this case to help deparse and warn
874 # distinguish the cases.
875 6 => qw(OPpCONCAT_NESTED NESTED),
876 );
877
878
879 addbits('multiconcat',
880 # 7 OPpLVAL_INTRO
881 6 => qw(OPpMULTICONCAT_APPEND APPEND), # $x .= ....
882 5 => qw(OPpMULTICONCAT_FAKE FAKE), # sprintf() optimised to MC.
883 # 4 OPpTARGET_MY
884 3 => qw(OPpMULTICONCAT_STRINGIFY STRINGIFY), # "$a$b..."
885 );
886
887
888 addbits('pushdefer',
889 7 => qw(OPpDEFER_FINALLY FINALLY),
890 );
891
892 # undef does not have the T flag set in regen/opcodes (and therefore
893 # automatically get the TARGMY flag added), as this causes S_maybe_targlex
894 # to do an unwanted optimization prior to Perl_rpeep.
895 addbits('undef',
896 4 => qw(OPpTARGET_MY TARGMY),
897 5 => qw(OPpUNDEF_KEEP_PV KEEP_PV),
898 );
899
900 addbits('emptyavhv',
901 # 7 OPpLVAL_INTRO
902 # 6 OPpPAD_STATE
903 5 => qw(OPpEMPTYAVHV_IS_HV ANONHASH),
904 # 4 OPpTARGET_MY
905 );
906
907 addbits('argdefelem',
908 7 => qw(OPpARG_IF_UNDEF IF_UNDEF),
909 6 => qw(OPpARG_IF_FALSE IF_FALSE),
910 );
911
912 addbits('helemexistsor',
913 7 => qw(OPpHELEMEXISTSOR_DELETE DELETE),
914 );
915
916 addbits('methstart',
917 7 => qw(OPpINITFIELDS INITFIELDS),
918 );
919
920 addbits('initfield',
921 1 => qw(OPpINITFIELD_AV INITFIELD_AV),
922 2 => qw(OPpINITFIELD_HV INITFIELD_HV),
923 );
924
925 1;
926
927 # ex: set ts=8 sts=4 sw=4 et: