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