line |
stmt |
bran |
cond |
sub |
time |
code |
1
|
|
|
|
|
|
#line 2 "op.c" |
2
|
|
|
|
|
|
/* op.c |
3
|
|
|
|
|
|
* |
4
|
|
|
|
|
|
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
5
|
|
|
|
|
|
* 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others |
6
|
|
|
|
|
|
* |
7
|
|
|
|
|
|
* You may distribute under the terms of either the GNU General Public |
8
|
|
|
|
|
|
* License or the Artistic License, as specified in the README file. |
9
|
|
|
|
|
|
* |
10
|
|
|
|
|
|
*/ |
11
|
|
|
|
|
|
|
12
|
|
|
|
|
|
/* |
13
|
|
|
|
|
|
* 'You see: Mr. Drogo, he married poor Miss Primula Brandybuck. She was |
14
|
|
|
|
|
|
* our Mr. Bilbo's first cousin on the mother's side (her mother being the |
15
|
|
|
|
|
|
* youngest of the Old Took's daughters); and Mr. Drogo was his second |
16
|
|
|
|
|
|
* cousin. So Mr. Frodo is his first *and* second cousin, once removed |
17
|
|
|
|
|
|
* either way, as the saying is, if you follow me.' --the Gaffer |
18
|
|
|
|
|
|
* |
19
|
|
|
|
|
|
* [p.23 of _The Lord of the Rings_, I/i: "A Long-Expected Party"] |
20
|
|
|
|
|
|
*/ |
21
|
|
|
|
|
|
|
22
|
|
|
|
|
|
/* This file contains the functions that create, manipulate and optimize |
23
|
|
|
|
|
|
* the OP structures that hold a compiled perl program. |
24
|
|
|
|
|
|
* |
25
|
|
|
|
|
|
* A Perl program is compiled into a tree of OPs. Each op contains |
26
|
|
|
|
|
|
* structural pointers (eg to its siblings and the next op in the |
27
|
|
|
|
|
|
* execution sequence), a pointer to the function that would execute the |
28
|
|
|
|
|
|
* op, plus any data specific to that op. For example, an OP_CONST op |
29
|
|
|
|
|
|
* points to the pp_const() function and to an SV containing the constant |
30
|
|
|
|
|
|
* value. When pp_const() is executed, its job is to push that SV onto the |
31
|
|
|
|
|
|
* stack. |
32
|
|
|
|
|
|
* |
33
|
|
|
|
|
|
* OPs are mainly created by the newFOO() functions, which are mainly |
34
|
|
|
|
|
|
* called from the parser (in perly.y) as the code is parsed. For example |
35
|
|
|
|
|
|
* the Perl code $a + $b * $c would cause the equivalent of the following |
36
|
|
|
|
|
|
* to be called (oversimplifying a bit): |
37
|
|
|
|
|
|
* |
38
|
|
|
|
|
|
* newBINOP(OP_ADD, flags, |
39
|
|
|
|
|
|
* newSVREF($a), |
40
|
|
|
|
|
|
* newBINOP(OP_MULTIPLY, flags, newSVREF($b), newSVREF($c)) |
41
|
|
|
|
|
|
* ) |
42
|
|
|
|
|
|
* |
43
|
|
|
|
|
|
* Note that during the build of miniperl, a temporary copy of this file |
44
|
|
|
|
|
|
* is made, called opmini.c. |
45
|
|
|
|
|
|
*/ |
46
|
|
|
|
|
|
|
47
|
|
|
|
|
|
/* |
48
|
|
|
|
|
|
Perl's compiler is essentially a 3-pass compiler with interleaved phases: |
49
|
|
|
|
|
|
|
50
|
|
|
|
|
|
A bottom-up pass |
51
|
|
|
|
|
|
A top-down pass |
52
|
|
|
|
|
|
An execution-order pass |
53
|
|
|
|
|
|
|
54
|
|
|
|
|
|
The bottom-up pass is represented by all the "newOP" routines and |
55
|
|
|
|
|
|
the ck_ routines. The bottom-upness is actually driven by yacc. |
56
|
|
|
|
|
|
So at the point that a ck_ routine fires, we have no idea what the |
57
|
|
|
|
|
|
context is, either upward in the syntax tree, or either forward or |
58
|
|
|
|
|
|
backward in the execution order. (The bottom-up parser builds that |
59
|
|
|
|
|
|
part of the execution order it knows about, but if you follow the "next" |
60
|
|
|
|
|
|
links around, you'll find it's actually a closed loop through the |
61
|
|
|
|
|
|
top level node.) |
62
|
|
|
|
|
|
|
63
|
|
|
|
|
|
Whenever the bottom-up parser gets to a node that supplies context to |
64
|
|
|
|
|
|
its components, it invokes that portion of the top-down pass that applies |
65
|
|
|
|
|
|
to that part of the subtree (and marks the top node as processed, so |
66
|
|
|
|
|
|
if a node further up supplies context, it doesn't have to take the |
67
|
|
|
|
|
|
plunge again). As a particular subcase of this, as the new node is |
68
|
|
|
|
|
|
built, it takes all the closed execution loops of its subcomponents |
69
|
|
|
|
|
|
and links them into a new closed loop for the higher level node. But |
70
|
|
|
|
|
|
it's still not the real execution order. |
71
|
|
|
|
|
|
|
72
|
|
|
|
|
|
The actual execution order is not known till we get a grammar reduction |
73
|
|
|
|
|
|
to a top-level unit like a subroutine or file that will be called by |
74
|
|
|
|
|
|
"name" rather than via a "next" pointer. At that point, we can call |
75
|
|
|
|
|
|
into peep() to do that code's portion of the 3rd pass. It has to be |
76
|
|
|
|
|
|
recursive, but it's recursive on basic blocks, not on tree nodes. |
77
|
|
|
|
|
|
*/ |
78
|
|
|
|
|
|
|
79
|
|
|
|
|
|
/* To implement user lexical pragmas, there needs to be a way at run time to |
80
|
|
|
|
|
|
get the compile time state of %^H for that block. Storing %^H in every |
81
|
|
|
|
|
|
block (or even COP) would be very expensive, so a different approach is |
82
|
|
|
|
|
|
taken. The (running) state of %^H is serialised into a tree of HE-like |
83
|
|
|
|
|
|
structs. Stores into %^H are chained onto the current leaf as a struct |
84
|
|
|
|
|
|
refcounted_he * with the key and the value. Deletes from %^H are saved |
85
|
|
|
|
|
|
with a value of PL_sv_placeholder. The state of %^H at any point can be |
86
|
|
|
|
|
|
turned back into a regular HV by walking back up the tree from that point's |
87
|
|
|
|
|
|
leaf, ignoring any key you've already seen (placeholder or not), storing |
88
|
|
|
|
|
|
the rest into the HV structure, then removing the placeholders. Hence |
89
|
|
|
|
|
|
memory is only used to store the %^H deltas from the enclosing COP, rather |
90
|
|
|
|
|
|
than the entire %^H on each COP. |
91
|
|
|
|
|
|
|
92
|
|
|
|
|
|
To cause actions on %^H to write out the serialisation records, it has |
93
|
|
|
|
|
|
magic type 'H'. This magic (itself) does nothing, but its presence causes |
94
|
|
|
|
|
|
the values to gain magic type 'h', which has entries for set and clear. |
95
|
|
|
|
|
|
C updates C with a store |
96
|
|
|
|
|
|
record, with deletes written by C. C |
97
|
|
|
|
|
|
saves the current C on the save stack, so that |
98
|
|
|
|
|
|
it will be correctly restored when any inner compiling scope is exited. |
99
|
|
|
|
|
|
*/ |
100
|
|
|
|
|
|
|
101
|
|
|
|
|
|
#include "EXTERN.h" |
102
|
|
|
|
|
|
#define PERL_IN_OP_C |
103
|
|
|
|
|
|
#include "perl.h" |
104
|
|
|
|
|
|
#include "keywords.h" |
105
|
|
|
|
|
|
#include "feature.h" |
106
|
|
|
|
|
|
#include "regcomp.h" |
107
|
|
|
|
|
|
|
108
|
|
|
|
|
|
#define CALL_PEEP(o) PL_peepp(aTHX_ o) |
109
|
|
|
|
|
|
#define CALL_RPEEP(o) PL_rpeepp(aTHX_ o) |
110
|
|
|
|
|
|
#define CALL_OPFREEHOOK(o) if (PL_opfreehook) PL_opfreehook(aTHX_ o) |
111
|
|
|
|
|
|
|
112
|
|
|
|
|
|
/* See the explanatory comments above struct opslab in op.h. */ |
113
|
|
|
|
|
|
|
114
|
|
|
|
|
|
#ifdef PERL_DEBUG_READONLY_OPS |
115
|
|
|
|
|
|
# define PERL_SLAB_SIZE 128 |
116
|
|
|
|
|
|
# define PERL_MAX_SLAB_SIZE 4096 |
117
|
|
|
|
|
|
# include |
118
|
|
|
|
|
|
#endif |
119
|
|
|
|
|
|
|
120
|
|
|
|
|
|
#ifndef PERL_SLAB_SIZE |
121
|
|
|
|
|
|
# define PERL_SLAB_SIZE 64 |
122
|
|
|
|
|
|
#endif |
123
|
|
|
|
|
|
#ifndef PERL_MAX_SLAB_SIZE |
124
|
|
|
|
|
|
# define PERL_MAX_SLAB_SIZE 2048 |
125
|
|
|
|
|
|
#endif |
126
|
|
|
|
|
|
|
127
|
|
|
|
|
|
/* rounds up to nearest pointer */ |
128
|
|
|
|
|
|
#define SIZE_TO_PSIZE(x) (((x) + sizeof(I32 *) - 1)/sizeof(I32 *)) |
129
|
|
|
|
|
|
#define DIFF(o,p) ((size_t)((I32 **)(p) - (I32**)(o))) |
130
|
|
|
|
|
|
|
131
|
|
|
|
|
|
static OPSLAB * |
132
|
|
|
|
|
|
S_new_slab(pTHX_ size_t sz) |
133
|
|
|
|
|
|
{ |
134
|
|
|
|
|
|
#ifdef PERL_DEBUG_READONLY_OPS |
135
|
|
|
|
|
|
OPSLAB *slab = (OPSLAB *) mmap(0, sz * sizeof(I32 *), |
136
|
|
|
|
|
|
PROT_READ|PROT_WRITE, |
137
|
|
|
|
|
|
MAP_ANON|MAP_PRIVATE, -1, 0); |
138
|
|
|
|
|
|
DEBUG_m(PerlIO_printf(Perl_debug_log, "mapped %lu at %p\n", |
139
|
|
|
|
|
|
(unsigned long) sz, slab)); |
140
|
|
|
|
|
|
if (slab == MAP_FAILED) { |
141
|
|
|
|
|
|
perror("mmap failed"); |
142
|
|
|
|
|
|
abort(); |
143
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
slab->opslab_size = (U16)sz; |
145
|
|
|
|
|
|
#else |
146
|
40862606
|
|
|
|
|
OPSLAB *slab = (OPSLAB *)PerlMemShared_calloc(sz, sizeof(I32 *)); |
147
|
|
|
|
|
|
#endif |
148
|
40862606
|
|
|
|
|
slab->opslab_first = (OPSLOT *)((I32 **)slab + sz - 1); |
149
|
|
|
|
|
|
return slab; |
150
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
152
|
|
|
|
|
|
/* requires double parens and aTHX_ */ |
153
|
|
|
|
|
|
#define DEBUG_S_warn(args) \ |
154
|
|
|
|
|
|
DEBUG_S( \ |
155
|
|
|
|
|
|
PerlIO_printf(Perl_debug_log, "%s", SvPVx_nolen(Perl_mess args)) \ |
156
|
|
|
|
|
|
) |
157
|
|
|
|
|
|
|
158
|
|
|
|
|
|
void * |
159
|
881508931
|
|
|
|
|
Perl_Slab_Alloc(pTHX_ size_t sz) |
160
|
|
|
|
|
|
{ |
161
|
|
|
|
|
|
dVAR; |
162
|
|
|
|
|
|
OPSLAB *slab; |
163
|
|
|
|
|
|
OPSLAB *slab2; |
164
|
|
|
|
|
|
OPSLOT *slot; |
165
|
|
|
|
|
|
OP *o; |
166
|
|
|
|
|
|
size_t opsz, space; |
167
|
|
|
|
|
|
|
168
|
|
|
|
|
|
/* We only allocate ops from the slab during subroutine compilation. |
169
|
|
|
|
|
|
We find the slab via PL_compcv, hence that must be non-NULL. It could |
170
|
|
|
|
|
|
also be pointing to a subroutine which is now fully set up (CvROOT() |
171
|
|
|
|
|
|
pointing to the top of the optree for that sub), or a subroutine |
172
|
|
|
|
|
|
which isn't using the slab allocator. If our sanity checks aren't met, |
173
|
|
|
|
|
|
don't use a slab, but allocate the OP directly from the heap. */ |
174
|
881508931
|
100
|
|
|
|
if (!PL_compcv || CvROOT(PL_compcv) |
|
|
100
|
|
|
|
|
175
|
881496577
|
100
|
|
|
|
|| (CvSTART(PL_compcv) && !CvSLABBED(PL_compcv))) |
|
|
50
|
|
|
|
|
176
|
12354
|
|
|
|
|
return PerlMemShared_calloc(1, sz); |
177
|
|
|
|
|
|
|
178
|
|
|
|
|
|
/* While the subroutine is under construction, the slabs are accessed via |
179
|
|
|
|
|
|
CvSTART(), to avoid needing to expand PVCV by one pointer for something |
180
|
|
|
|
|
|
unneeded at runtime. Once a subroutine is constructed, the slabs are |
181
|
|
|
|
|
|
accessed via CvROOT(). So if CvSTART() is NULL, no slab has been |
182
|
|
|
|
|
|
allocated yet. See the commit message for 8be227ab5eaa23f2 for more |
183
|
|
|
|
|
|
details. */ |
184
|
881496577
|
100
|
|
|
|
if (!CvSTART(PL_compcv)) { |
185
|
33789004
|
|
|
|
|
CvSTART(PL_compcv) = |
186
|
|
|
|
|
|
(OP *)(slab = S_new_slab(aTHX_ PERL_SLAB_SIZE)); |
187
|
16894502
|
|
|
|
|
CvSLABBED_on(PL_compcv); |
188
|
16894502
|
|
|
|
|
slab->opslab_refcnt = 2; /* one for the CV; one for the new OP */ |
189
|
|
|
|
|
|
} |
190
|
864602075
|
|
|
|
|
else ++(slab = (OPSLAB *)CvSTART(PL_compcv))->opslab_refcnt; |
191
|
|
|
|
|
|
|
192
|
881496577
|
|
|
|
|
opsz = SIZE_TO_PSIZE(sz); |
193
|
881496577
|
|
|
|
|
sz = opsz + OPSLOT_HEADER_P; |
194
|
|
|
|
|
|
|
195
|
|
|
|
|
|
/* The slabs maintain a free list of OPs. In particular, constant folding |
196
|
|
|
|
|
|
will free up OPs, so it makes sense to re-use them where possible. A |
197
|
|
|
|
|
|
freed up slot is used in preference to a new allocation. */ |
198
|
881496577
|
100
|
|
|
|
if (slab->opslab_freed) { |
199
|
207884490
|
|
|
|
|
OP **too = &slab->opslab_freed; |
200
|
207884490
|
|
|
|
|
o = *too; |
201
|
|
|
|
|
|
DEBUG_S_warn((aTHX_ "found free op at %p, slab %p", o, slab)); |
202
|
431172708
|
100
|
|
|
|
while (o && DIFF(OpSLOT(o), OpSLOT(o)->opslot_next) < sz) { |
|
|
100
|
|
|
|
|
203
|
|
|
|
|
|
DEBUG_S_warn((aTHX_ "Alas! too small")); |
204
|
123620202
|
|
|
|
|
o = *(too = &o->op_next); |
205
|
|
|
|
|
|
if (o) { DEBUG_S_warn((aTHX_ "found another free op at %p", o)); } |
206
|
|
|
|
|
|
} |
207
|
207884490
|
100
|
|
|
|
if (o) { |
208
|
133642482
|
|
|
|
|
*too = o->op_next; |
209
|
133642482
|
50
|
|
|
|
Zero(o, opsz, I32 *); |
210
|
133642482
|
|
|
|
|
o->op_slabbed = 1; |
211
|
133642482
|
|
|
|
|
return (void *)o; |
212
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
215
|
|
|
|
|
|
#define INIT_OPSLOT \ |
216
|
|
|
|
|
|
slot->opslot_slab = slab; \ |
217
|
|
|
|
|
|
slot->opslot_next = slab2->opslab_first; \ |
218
|
|
|
|
|
|
slab2->opslab_first = slot; \ |
219
|
|
|
|
|
|
o = &slot->opslot_op; \ |
220
|
|
|
|
|
|
o->op_slabbed = 1 |
221
|
|
|
|
|
|
|
222
|
|
|
|
|
|
/* The partially-filled slab is next in the chain. */ |
223
|
747854095
|
100
|
|
|
|
slab2 = slab->opslab_next ? slab->opslab_next : slab; |
224
|
747854095
|
100
|
|
|
|
if ((space = DIFF(&slab2->opslab_slots, slab2->opslab_first)) < sz) { |
225
|
|
|
|
|
|
/* Remaining space is too small. */ |
226
|
|
|
|
|
|
|
227
|
|
|
|
|
|
/* If we can fit a BASEOP, add it to the free chain, so as not |
228
|
|
|
|
|
|
to waste it. */ |
229
|
23968104
|
100
|
|
|
|
if (space >= SIZE_TO_PSIZE(sizeof(OP)) + OPSLOT_HEADER_P) { |
230
|
4137633
|
|
|
|
|
slot = &slab2->opslab_slots; |
231
|
4137633
|
|
|
|
|
INIT_OPSLOT; |
232
|
4137633
|
|
|
|
|
o->op_type = OP_FREED; |
233
|
4137633
|
|
|
|
|
o->op_next = slab->opslab_freed; |
234
|
4137633
|
|
|
|
|
slab->opslab_freed = o; |
235
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
237
|
|
|
|
|
|
/* Create a new slab. Make this one twice as big. */ |
238
|
23968104
|
|
|
|
|
slot = slab2->opslab_first; |
239
|
292894261
|
100
|
|
|
|
while (slot->opslot_next) slot = slot->opslot_next; |
240
|
23968104
|
|
|
|
|
slab2 = S_new_slab(aTHX_ |
241
|
|
|
|
|
|
(DIFF(slab2, slot)+1)*2 > PERL_MAX_SLAB_SIZE |
242
|
|
|
|
|
|
? PERL_MAX_SLAB_SIZE |
243
|
23968104
|
|
|
|
|
: (DIFF(slab2, slot)+1)*2); |
244
|
23968104
|
|
|
|
|
slab2->opslab_next = slab->opslab_next; |
245
|
23968104
|
|
|
|
|
slab->opslab_next = slab2; |
246
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
assert(DIFF(&slab2->opslab_slots, slab2->opslab_first) >= sz); |
248
|
|
|
|
|
|
|
249
|
|
|
|
|
|
/* Create a new op slot */ |
250
|
747854095
|
|
|
|
|
slot = (OPSLOT *)((I32 **)slab2->opslab_first - sz); |
251
|
|
|
|
|
|
assert(slot >= &slab2->opslab_slots); |
252
|
747854095
|
100
|
|
|
|
if (DIFF(&slab2->opslab_slots, slot) |
253
|
|
|
|
|
|
< SIZE_TO_PSIZE(sizeof(OP)) + OPSLOT_HEADER_P) |
254
|
20039209
|
|
|
|
|
slot = &slab2->opslab_slots; |
255
|
747854095
|
|
|
|
|
INIT_OPSLOT; |
256
|
|
|
|
|
|
DEBUG_S_warn((aTHX_ "allocating op at %p, slab %p", o, slab)); |
257
|
817466935
|
|
|
|
|
return (void *)o; |
258
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
260
|
|
|
|
|
|
#undef INIT_OPSLOT |
261
|
|
|
|
|
|
|
262
|
|
|
|
|
|
#ifdef PERL_DEBUG_READONLY_OPS |
263
|
|
|
|
|
|
void |
264
|
|
|
|
|
|
Perl_Slab_to_ro(pTHX_ OPSLAB *slab) |
265
|
|
|
|
|
|
{ |
266
|
|
|
|
|
|
PERL_ARGS_ASSERT_SLAB_TO_RO; |
267
|
|
|
|
|
|
|
268
|
|
|
|
|
|
if (slab->opslab_readonly) return; |
269
|
|
|
|
|
|
slab->opslab_readonly = 1; |
270
|
|
|
|
|
|
for (; slab; slab = slab->opslab_next) { |
271
|
|
|
|
|
|
/*DEBUG_U(PerlIO_printf(Perl_debug_log,"mprotect ->ro %lu at %p\n", |
272
|
|
|
|
|
|
(unsigned long) slab->opslab_size, slab));*/ |
273
|
|
|
|
|
|
if (mprotect(slab, slab->opslab_size * sizeof(I32 *), PROT_READ)) |
274
|
|
|
|
|
|
Perl_warn(aTHX_ "mprotect for %p %lu failed with %d", slab, |
275
|
|
|
|
|
|
(unsigned long)slab->opslab_size, errno); |
276
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
279
|
|
|
|
|
|
void |
280
|
|
|
|
|
|
Perl_Slab_to_rw(pTHX_ OPSLAB *const slab) |
281
|
|
|
|
|
|
{ |
282
|
|
|
|
|
|
OPSLAB *slab2; |
283
|
|
|
|
|
|
|
284
|
|
|
|
|
|
PERL_ARGS_ASSERT_SLAB_TO_RW; |
285
|
|
|
|
|
|
|
286
|
|
|
|
|
|
if (!slab->opslab_readonly) return; |
287
|
|
|
|
|
|
slab2 = slab; |
288
|
|
|
|
|
|
for (; slab2; slab2 = slab2->opslab_next) { |
289
|
|
|
|
|
|
/*DEBUG_U(PerlIO_printf(Perl_debug_log,"mprotect ->rw %lu at %p\n", |
290
|
|
|
|
|
|
(unsigned long) size, slab2));*/ |
291
|
|
|
|
|
|
if (mprotect((void *)slab2, slab2->opslab_size * sizeof(I32 *), |
292
|
|
|
|
|
|
PROT_READ|PROT_WRITE)) { |
293
|
|
|
|
|
|
Perl_warn(aTHX_ "mprotect RW for %p %lu failed with %d", slab, |
294
|
|
|
|
|
|
(unsigned long)slab2->opslab_size, errno); |
295
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
slab->opslab_readonly = 0; |
298
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
300
|
|
|
|
|
|
#else |
301
|
|
|
|
|
|
# define Slab_to_rw(op) NOOP |
302
|
|
|
|
|
|
#endif |
303
|
|
|
|
|
|
|
304
|
|
|
|
|
|
/* This cannot possibly be right, but it was copied from the old slab |
305
|
|
|
|
|
|
allocator, to which it was originally added, without explanation, in |
306
|
|
|
|
|
|
commit 083fcd5. */ |
307
|
|
|
|
|
|
#ifdef NETWARE |
308
|
|
|
|
|
|
# define PerlMemShared PerlMem |
309
|
|
|
|
|
|
#endif |
310
|
|
|
|
|
|
|
311
|
|
|
|
|
|
void |
312
|
264816991
|
|
|
|
|
Perl_Slab_Free(pTHX_ void *op) |
313
|
|
|
|
|
|
{ |
314
|
|
|
|
|
|
dVAR; |
315
|
|
|
|
|
|
OP * const o = (OP *)op; |
316
|
|
|
|
|
|
OPSLAB *slab; |
317
|
|
|
|
|
|
|
318
|
|
|
|
|
|
PERL_ARGS_ASSERT_SLAB_FREE; |
319
|
|
|
|
|
|
|
320
|
264816991
|
100
|
|
|
|
if (!o->op_slabbed) { |
321
|
428
|
50
|
|
|
|
if (!o->op_static) |
322
|
428
|
|
|
|
|
PerlMemShared_free(op); |
323
|
264816991
|
|
|
|
|
return; |
324
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
326
|
264816563
|
|
|
|
|
slab = OpSLAB(o); |
327
|
|
|
|
|
|
/* If this op is already freed, our refcount will get screwy. */ |
328
|
|
|
|
|
|
assert(o->op_type != OP_FREED); |
329
|
264816563
|
|
|
|
|
o->op_type = OP_FREED; |
330
|
264816563
|
|
|
|
|
o->op_next = slab->opslab_freed; |
331
|
264816563
|
|
|
|
|
slab->opslab_freed = o; |
332
|
|
|
|
|
|
DEBUG_S_warn((aTHX_ "free op at %p, recorded in slab %p", o, slab)); |
333
|
264816563
|
100
|
|
|
|
OpslabREFCNT_dec_padok(slab); |
334
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
336
|
|
|
|
|
|
void |
337
|
0
|
|
|
|
|
Perl_opslab_free_nopad(pTHX_ OPSLAB *slab) |
338
|
|
|
|
|
|
{ |
339
|
|
|
|
|
|
dVAR; |
340
|
0
|
|
|
|
|
const bool havepad = !!PL_comppad; |
341
|
|
|
|
|
|
PERL_ARGS_ASSERT_OPSLAB_FREE_NOPAD; |
342
|
0
|
0
|
|
|
|
if (havepad) { |
343
|
0
|
|
|
|
|
ENTER; |
344
|
0
|
|
|
|
|
PAD_SAVE_SETNULLPAD(); |
345
|
|
|
|
|
|
} |
346
|
0
|
|
|
|
|
opslab_free(slab); |
347
|
0
|
0
|
|
|
|
if (havepad) LEAVE; |
348
|
0
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
350
|
|
|
|
|
|
void |
351
|
4050364
|
|
|
|
|
Perl_opslab_free(pTHX_ OPSLAB *slab) |
352
|
|
|
|
|
|
{ |
353
|
|
|
|
|
|
dVAR; |
354
|
|
|
|
|
|
OPSLAB *slab2; |
355
|
|
|
|
|
|
PERL_ARGS_ASSERT_OPSLAB_FREE; |
356
|
|
|
|
|
|
DEBUG_S_warn((aTHX_ "freeing slab %p", slab)); |
357
|
|
|
|
|
|
assert(slab->opslab_refcnt == 1); |
358
|
14218499
|
100
|
|
|
|
for (; slab; slab = slab2) { |
359
|
8223943
|
|
|
|
|
slab2 = slab->opslab_next; |
360
|
|
|
|
|
|
#ifdef DEBUGGING |
361
|
|
|
|
|
|
slab->opslab_refcnt = ~(size_t)0; |
362
|
|
|
|
|
|
#endif |
363
|
|
|
|
|
|
#ifdef PERL_DEBUG_READONLY_OPS |
364
|
|
|
|
|
|
DEBUG_m(PerlIO_printf(Perl_debug_log, "Deallocate slab at %p\n", |
365
|
|
|
|
|
|
slab)); |
366
|
|
|
|
|
|
if (munmap(slab, slab->opslab_size * sizeof(I32 *))) { |
367
|
|
|
|
|
|
perror("munmap failed"); |
368
|
|
|
|
|
|
abort(); |
369
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
#else |
371
|
8223943
|
|
|
|
|
PerlMemShared_free(slab); |
372
|
|
|
|
|
|
#endif |
373
|
|
|
|
|
|
} |
374
|
4050364
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
376
|
|
|
|
|
|
void |
377
|
215142
|
|
|
|
|
Perl_opslab_force_free(pTHX_ OPSLAB *slab) |
378
|
|
|
|
|
|
{ |
379
|
|
|
|
|
|
OPSLAB *slab2; |
380
|
|
|
|
|
|
OPSLOT *slot; |
381
|
|
|
|
|
|
#ifdef DEBUGGING |
382
|
|
|
|
|
|
size_t savestack_count = 0; |
383
|
|
|
|
|
|
#endif |
384
|
|
|
|
|
|
PERL_ARGS_ASSERT_OPSLAB_FORCE_FREE; |
385
|
|
|
|
|
|
slab2 = slab; |
386
|
|
|
|
|
|
do { |
387
|
992974
|
100
|
|
|
|
for (slot = slab2->opslab_first; |
388
|
888466
|
|
|
|
|
slot->opslot_next; |
389
|
671890
|
|
|
|
|
slot = slot->opslot_next) { |
390
|
673506
|
100
|
|
|
|
if (slot->opslot_op.op_type != OP_FREED |
391
|
3118
|
50
|
|
|
|
&& !(slot->opslot_op.op_savefree |
392
|
|
|
|
|
|
#ifdef DEBUGGING |
393
|
|
|
|
|
|
&& ++savestack_count |
394
|
|
|
|
|
|
#endif |
395
|
|
|
|
|
|
) |
396
|
|
|
|
|
|
) { |
397
|
|
|
|
|
|
assert(slot->opslot_op.op_slabbed); |
398
|
3118
|
|
|
|
|
op_free(&slot->opslot_op); |
399
|
3118
|
100
|
|
|
|
if (slab->opslab_refcnt == 1) goto free; |
400
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
} |
402
|
214960
|
100
|
|
|
|
} while ((slab2 = slab2->opslab_next)); |
403
|
|
|
|
|
|
/* > 1 because the CV still holds a reference count. */ |
404
|
213526
|
50
|
|
|
|
if (slab->opslab_refcnt > 1) { /* still referenced by the savestack */ |
405
|
|
|
|
|
|
#ifdef DEBUGGING |
406
|
|
|
|
|
|
assert(savestack_count == slab->opslab_refcnt-1); |
407
|
|
|
|
|
|
#endif |
408
|
|
|
|
|
|
/* Remove the CV’s reference count. */ |
409
|
0
|
|
|
|
|
slab->opslab_refcnt--; |
410
|
215142
|
|
|
|
|
return; |
411
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
free: |
413
|
215142
|
|
|
|
|
opslab_free(slab); |
414
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
|
416
|
|
|
|
|
|
#ifdef PERL_DEBUG_READONLY_OPS |
417
|
|
|
|
|
|
OP * |
418
|
|
|
|
|
|
Perl_op_refcnt_inc(pTHX_ OP *o) |
419
|
|
|
|
|
|
{ |
420
|
|
|
|
|
|
if(o) { |
421
|
|
|
|
|
|
OPSLAB *const slab = o->op_slabbed ? OpSLAB(o) : NULL; |
422
|
|
|
|
|
|
if (slab && slab->opslab_readonly) { |
423
|
|
|
|
|
|
Slab_to_rw(slab); |
424
|
|
|
|
|
|
++o->op_targ; |
425
|
|
|
|
|
|
Slab_to_ro(slab); |
426
|
|
|
|
|
|
} else { |
427
|
|
|
|
|
|
++o->op_targ; |
428
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
return o; |
431
|
|
|
|
|
|
|
432
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
434
|
|
|
|
|
|
PADOFFSET |
435
|
|
|
|
|
|
Perl_op_refcnt_dec(pTHX_ OP *o) |
436
|
|
|
|
|
|
{ |
437
|
|
|
|
|
|
PADOFFSET result; |
438
|
|
|
|
|
|
OPSLAB *const slab = o->op_slabbed ? OpSLAB(o) : NULL; |
439
|
|
|
|
|
|
|
440
|
|
|
|
|
|
PERL_ARGS_ASSERT_OP_REFCNT_DEC; |
441
|
|
|
|
|
|
|
442
|
|
|
|
|
|
if (slab && slab->opslab_readonly) { |
443
|
|
|
|
|
|
Slab_to_rw(slab); |
444
|
|
|
|
|
|
result = --o->op_targ; |
445
|
|
|
|
|
|
Slab_to_ro(slab); |
446
|
|
|
|
|
|
} else { |
447
|
|
|
|
|
|
result = --o->op_targ; |
448
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
return result; |
450
|
|
|
|
|
|
} |
451
|
|
|
|
|
|
#endif |
452
|
|
|
|
|
|
/* |
453
|
|
|
|
|
|
* In the following definition, the ", (OP*)0" is just to make the compiler |
454
|
|
|
|
|
|
* think the expression is of the right type: croak actually does a Siglongjmp. |
455
|
|
|
|
|
|
*/ |
456
|
|
|
|
|
|
#define CHECKOP(type,o) \ |
457
|
|
|
|
|
|
((PL_op_mask && PL_op_mask[type]) \ |
458
|
|
|
|
|
|
? ( op_free((OP*)o), \ |
459
|
|
|
|
|
|
Perl_croak(aTHX_ "'%s' trapped by operation mask", PL_op_desc[type]), \ |
460
|
|
|
|
|
|
(OP*)0 ) \ |
461
|
|
|
|
|
|
: PL_check[type](aTHX_ (OP*)o)) |
462
|
|
|
|
|
|
|
463
|
|
|
|
|
|
#define RETURN_UNLIMITED_NUMBER (PERL_INT_MAX / 2) |
464
|
|
|
|
|
|
|
465
|
|
|
|
|
|
#define CHANGE_TYPE(o,type) \ |
466
|
|
|
|
|
|
STMT_START { \ |
467
|
|
|
|
|
|
o->op_type = (OPCODE)type; \ |
468
|
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[type]; \ |
469
|
|
|
|
|
|
} STMT_END |
470
|
|
|
|
|
|
|
471
|
|
|
|
|
|
STATIC SV* |
472
|
68
|
|
|
|
|
S_gv_ename(pTHX_ GV *gv) |
473
|
|
|
|
|
|
{ |
474
|
68
|
|
|
|
|
SV* const tmpsv = sv_newmortal(); |
475
|
|
|
|
|
|
|
476
|
|
|
|
|
|
PERL_ARGS_ASSERT_GV_ENAME; |
477
|
|
|
|
|
|
|
478
|
68
|
|
|
|
|
gv_efullname3(tmpsv, gv, NULL); |
479
|
68
|
|
|
|
|
return tmpsv; |
480
|
|
|
|
|
|
} |
481
|
|
|
|
|
|
|
482
|
|
|
|
|
|
STATIC OP * |
483
|
2
|
|
|
|
|
S_no_fh_allowed(pTHX_ OP *o) |
484
|
|
|
|
|
|
{ |
485
|
|
|
|
|
|
PERL_ARGS_ASSERT_NO_FH_ALLOWED; |
486
|
|
|
|
|
|
|
487
|
2
|
50
|
|
|
|
yyerror(Perl_form(aTHX_ "Missing comma after first argument to %s function", |
|
|
0
|
|
|
|
|
488
|
|
|
|
|
|
OP_DESC(o))); |
489
|
2
|
|
|
|
|
return o; |
490
|
|
|
|
|
|
} |
491
|
|
|
|
|
|
|
492
|
|
|
|
|
|
STATIC OP * |
493
|
|
|
|
|
|
S_too_few_arguments_sv(pTHX_ OP *o, SV *namesv, U32 flags) |
494
|
|
|
|
|
|
{ |
495
|
|
|
|
|
|
PERL_ARGS_ASSERT_TOO_FEW_ARGUMENTS_SV; |
496
|
40
|
|
|
|
|
yyerror_pv(Perl_form(aTHX_ "Not enough arguments for %"SVf, namesv), |
497
|
|
|
|
|
|
SvUTF8(namesv) | flags); |
498
|
|
|
|
|
|
return o; |
499
|
|
|
|
|
|
} |
500
|
|
|
|
|
|
|
501
|
|
|
|
|
|
STATIC OP * |
502
|
|
|
|
|
|
S_too_few_arguments_pv(pTHX_ OP *o, const char* name, U32 flags) |
503
|
|
|
|
|
|
{ |
504
|
|
|
|
|
|
PERL_ARGS_ASSERT_TOO_FEW_ARGUMENTS_PV; |
505
|
12
|
|
|
|
|
yyerror_pv(Perl_form(aTHX_ "Not enough arguments for %s", name), flags); |
506
|
|
|
|
|
|
return o; |
507
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
509
|
|
|
|
|
|
STATIC OP * |
510
|
314
|
|
|
|
|
S_too_many_arguments_pv(pTHX_ OP *o, const char *name, U32 flags) |
511
|
|
|
|
|
|
{ |
512
|
|
|
|
|
|
PERL_ARGS_ASSERT_TOO_MANY_ARGUMENTS_PV; |
513
|
|
|
|
|
|
|
514
|
314
|
|
|
|
|
yyerror_pv(Perl_form(aTHX_ "Too many arguments for %s", name), flags); |
515
|
314
|
|
|
|
|
return o; |
516
|
|
|
|
|
|
} |
517
|
|
|
|
|
|
|
518
|
|
|
|
|
|
STATIC OP * |
519
|
|
|
|
|
|
S_too_many_arguments_sv(pTHX_ OP *o, SV *namesv, U32 flags) |
520
|
|
|
|
|
|
{ |
521
|
|
|
|
|
|
PERL_ARGS_ASSERT_TOO_MANY_ARGUMENTS_SV; |
522
|
|
|
|
|
|
|
523
|
10
|
|
|
|
|
yyerror_pv(Perl_form(aTHX_ "Too many arguments for %"SVf, SVfARG(namesv)), |
524
|
|
|
|
|
|
SvUTF8(namesv) | flags); |
525
|
|
|
|
|
|
return o; |
526
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
528
|
|
|
|
|
|
STATIC void |
529
|
12
|
|
|
|
|
S_bad_type_pv(pTHX_ I32 n, const char *t, const char *name, U32 flags, const OP *kid) |
530
|
|
|
|
|
|
{ |
531
|
|
|
|
|
|
PERL_ARGS_ASSERT_BAD_TYPE_PV; |
532
|
|
|
|
|
|
|
533
|
12
|
50
|
|
|
|
yyerror_pv(Perl_form(aTHX_ "Type of arg %d to %s must be %s (not %s)", |
|
|
0
|
|
|
|
|
534
|
|
|
|
|
|
(int)n, name, t, OP_DESC(kid)), flags); |
535
|
12
|
|
|
|
|
} |
536
|
|
|
|
|
|
|
537
|
|
|
|
|
|
STATIC void |
538
|
18
|
|
|
|
|
S_bad_type_gv(pTHX_ I32 n, const char *t, GV *gv, U32 flags, const OP *kid) |
539
|
|
|
|
|
|
{ |
540
|
18
|
|
|
|
|
SV * const namesv = gv_ename(gv); |
541
|
|
|
|
|
|
PERL_ARGS_ASSERT_BAD_TYPE_GV; |
542
|
|
|
|
|
|
|
543
|
18
|
50
|
|
|
|
yyerror_pv(Perl_form(aTHX_ "Type of arg %d to %"SVf" must be %s (not %s)", |
|
|
0
|
|
|
|
|
544
|
|
|
|
|
|
(int)n, SVfARG(namesv), t, OP_DESC(kid)), SvUTF8(namesv) | flags); |
545
|
18
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
547
|
|
|
|
|
|
STATIC void |
548
|
74
|
|
|
|
|
S_no_bareword_allowed(pTHX_ OP *o) |
549
|
|
|
|
|
|
{ |
550
|
|
|
|
|
|
PERL_ARGS_ASSERT_NO_BAREWORD_ALLOWED; |
551
|
|
|
|
|
|
|
552
|
|
|
|
|
|
if (PL_madskills) |
553
|
74
|
|
|
|
|
return; /* various ok barewords are hidden in extra OP_NULL */ |
554
|
74
|
|
|
|
|
qerror(Perl_mess(aTHX_ |
555
|
|
|
|
|
|
"Bareword \"%"SVf"\" not allowed while \"strict subs\" in use", |
556
|
|
|
|
|
|
SVfARG(cSVOPo_sv))); |
557
|
74
|
|
|
|
|
o->op_private &= ~OPpCONST_STRICT; /* prevent warning twice about the same OP */ |
558
|
|
|
|
|
|
} |
559
|
|
|
|
|
|
|
560
|
|
|
|
|
|
/* "register" allocation */ |
561
|
|
|
|
|
|
|
562
|
|
|
|
|
|
PADOFFSET |
563
|
20556280
|
|
|
|
|
Perl_allocmy(pTHX_ const char *const name, const STRLEN len, const U32 flags) |
564
|
|
|
|
|
|
{ |
565
|
|
|
|
|
|
dVAR; |
566
|
|
|
|
|
|
PADOFFSET off; |
567
|
20556280
|
|
|
|
|
const bool is_our = (PL_parser->in_my == KEY_our); |
568
|
|
|
|
|
|
|
569
|
|
|
|
|
|
PERL_ARGS_ASSERT_ALLOCMY; |
570
|
|
|
|
|
|
|
571
|
20556280
|
50
|
|
|
|
if (flags & ~SVf_UTF8) |
572
|
0
|
|
|
|
|
Perl_croak(aTHX_ "panic: allocmy illegal flag bits 0x%" UVxf, |
573
|
|
|
|
|
|
(UV)flags); |
574
|
|
|
|
|
|
|
575
|
|
|
|
|
|
/* Until we're using the length for real, cross check that we're being |
576
|
|
|
|
|
|
told the truth. */ |
577
|
|
|
|
|
|
assert(strlen(name) == len); |
578
|
|
|
|
|
|
|
579
|
|
|
|
|
|
/* complain about "my $" etc etc */ |
580
|
20701575
|
50
|
|
|
|
if (len && |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
581
|
19595415
|
100
|
|
|
|
!(is_our || |
|
|
100
|
|
|
|
|
582
|
9569265
|
100
|
|
|
|
isALPHA(name[1]) || |
583
|
149924
|
100
|
|
|
|
((flags & SVf_UTF8) && isIDFIRST_utf8((U8 *)name+1)) || |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
584
|
13760
|
50
|
|
|
|
(name[1] == '_' && (*name == '$' || len > 2)))) |
585
|
|
|
|
|
|
{ |
586
|
|
|
|
|
|
/* name[2] is true if strlen(name) > 2 */ |
587
|
10
|
100
|
|
|
|
if (!(flags & SVf_UTF8 && UTF8_IS_START(name[1])) |
|
|
50
|
|
|
|
|
588
|
10
|
100
|
|
|
|
&& (!isPRINT(name[1]) || strchr("\t\n\r\f", name[1]))) { |
|
|
50
|
|
|
|
|
589
|
4
|
50
|
|
|
|
yyerror(Perl_form(aTHX_ "Can't use global %c^%c%.*s in \"%s\"", |
|
|
50
|
|
|
|
|
590
|
|
|
|
|
|
name[0], toCTRL(name[1]), (int)(len - 2), name + 2, |
591
|
|
|
|
|
|
PL_parser->in_my == KEY_state ? "state" : "my")); |
592
|
|
|
|
|
|
} else { |
593
|
6
|
50
|
|
|
|
yyerror_pv(Perl_form(aTHX_ "Can't use global %.*s in \"%s\"", (int) len, name, |
594
|
|
|
|
|
|
PL_parser->in_my == KEY_state ? "state" : "my"), flags & SVf_UTF8); |
595
|
|
|
|
|
|
} |
596
|
|
|
|
|
|
} |
597
|
20556270
|
100
|
|
|
|
else if (len == 2 && name[1] == '_' && !is_our) |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
598
|
|
|
|
|
|
/* diag_listed_as: Use of my $_ is experimental */ |
599
|
112
|
100
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_EXPERIMENTAL__LEXICAL_TOPIC), |
600
|
|
|
|
|
|
"Use of %s $_ is experimental", |
601
|
112
|
|
|
|
|
PL_parser->in_my == KEY_state |
602
|
|
|
|
|
|
? "state" |
603
|
|
|
|
|
|
: "my"); |
604
|
|
|
|
|
|
|
605
|
|
|
|
|
|
/* allocate a spare slot and store the name in that slot */ |
606
|
|
|
|
|
|
|
607
|
20556280
|
100
|
|
|
|
off = pad_add_name_pvn(name, len, |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
608
|
|
|
|
|
|
(is_our ? padadd_OUR : |
609
|
|
|
|
|
|
PL_parser->in_my == KEY_state ? padadd_STATE : 0) |
610
|
|
|
|
|
|
| ( flags & SVf_UTF8 ? SVf_UTF8 : 0 ), |
611
|
|
|
|
|
|
PL_parser->in_my_stash, |
612
|
|
|
|
|
|
(is_our |
613
|
|
|
|
|
|
/* $_ is always in main::, even with our */ |
614
|
|
|
|
|
|
? (PL_curstash && !strEQ(name,"$_") ? PL_curstash : PL_defstash) |
615
|
|
|
|
|
|
: NULL |
616
|
|
|
|
|
|
) |
617
|
|
|
|
|
|
); |
618
|
|
|
|
|
|
/* anon sub prototypes contains state vars should always be cloned, |
619
|
|
|
|
|
|
* otherwise the state var would be shared between anon subs */ |
620
|
|
|
|
|
|
|
621
|
20556272
|
100
|
|
|
|
if (PL_parser->in_my == KEY_state && CvANON(PL_compcv)) |
|
|
100
|
|
|
|
|
622
|
16
|
|
|
|
|
CvCLONE_on(PL_compcv); |
623
|
|
|
|
|
|
|
624
|
20556272
|
|
|
|
|
return off; |
625
|
|
|
|
|
|
} |
626
|
|
|
|
|
|
|
627
|
|
|
|
|
|
/* |
628
|
|
|
|
|
|
=for apidoc alloccopstash |
629
|
|
|
|
|
|
|
630
|
|
|
|
|
|
Available only under threaded builds, this function allocates an entry in |
631
|
|
|
|
|
|
C for the stash passed to it. |
632
|
|
|
|
|
|
|
633
|
|
|
|
|
|
=cut |
634
|
|
|
|
|
|
*/ |
635
|
|
|
|
|
|
|
636
|
|
|
|
|
|
#ifdef USE_ITHREADS |
637
|
|
|
|
|
|
PADOFFSET |
638
|
|
|
|
|
|
Perl_alloccopstash(pTHX_ HV *hv) |
639
|
|
|
|
|
|
{ |
640
|
|
|
|
|
|
PADOFFSET off = 0, o = 1; |
641
|
|
|
|
|
|
bool found_slot = FALSE; |
642
|
|
|
|
|
|
|
643
|
|
|
|
|
|
PERL_ARGS_ASSERT_ALLOCCOPSTASH; |
644
|
|
|
|
|
|
|
645
|
|
|
|
|
|
if (PL_stashpad[PL_stashpadix] == hv) return PL_stashpadix; |
646
|
|
|
|
|
|
|
647
|
|
|
|
|
|
for (; o < PL_stashpadmax; ++o) { |
648
|
|
|
|
|
|
if (PL_stashpad[o] == hv) return PL_stashpadix = o; |
649
|
|
|
|
|
|
if (!PL_stashpad[o] || SvTYPE(PL_stashpad[o]) != SVt_PVHV) |
650
|
|
|
|
|
|
found_slot = TRUE, off = o; |
651
|
|
|
|
|
|
} |
652
|
|
|
|
|
|
if (!found_slot) { |
653
|
|
|
|
|
|
Renew(PL_stashpad, PL_stashpadmax + 10, HV *); |
654
|
|
|
|
|
|
Zero(PL_stashpad + PL_stashpadmax, 10, HV *); |
655
|
|
|
|
|
|
off = PL_stashpadmax; |
656
|
|
|
|
|
|
PL_stashpadmax += 10; |
657
|
|
|
|
|
|
} |
658
|
|
|
|
|
|
|
659
|
|
|
|
|
|
PL_stashpad[PL_stashpadix = off] = hv; |
660
|
|
|
|
|
|
return off; |
661
|
|
|
|
|
|
} |
662
|
|
|
|
|
|
#endif |
663
|
|
|
|
|
|
|
664
|
|
|
|
|
|
/* free the body of an op without examining its contents. |
665
|
|
|
|
|
|
* Always use this rather than FreeOp directly */ |
666
|
|
|
|
|
|
|
667
|
|
|
|
|
|
static void |
668
|
|
|
|
|
|
S_op_destroy(pTHX_ OP *o) |
669
|
|
|
|
|
|
{ |
670
|
40904021
|
|
|
|
|
FreeOp(o); |
671
|
|
|
|
|
|
} |
672
|
|
|
|
|
|
|
673
|
|
|
|
|
|
/* Destructor */ |
674
|
|
|
|
|
|
|
675
|
|
|
|
|
|
void |
676
|
227735937
|
|
|
|
|
Perl_op_free(pTHX_ OP *o) |
677
|
|
|
|
|
|
{ |
678
|
|
|
|
|
|
dVAR; |
679
|
|
|
|
|
|
OPCODE type; |
680
|
|
|
|
|
|
|
681
|
|
|
|
|
|
/* Though ops may be freed twice, freeing the op after its slab is a |
682
|
|
|
|
|
|
big no-no. */ |
683
|
|
|
|
|
|
assert(!o || !o->op_slabbed || OpSLAB(o)->opslab_refcnt != ~(size_t)0); |
684
|
|
|
|
|
|
/* During the forced freeing of ops after compilation failure, kidops |
685
|
|
|
|
|
|
may be freed before their parents. */ |
686
|
227735937
|
100
|
|
|
|
if (!o || o->op_type == OP_FREED) |
|
|
100
|
|
|
|
|
687
|
|
|
|
|
|
return; |
688
|
|
|
|
|
|
|
689
|
226823189
|
|
|
|
|
type = o->op_type; |
690
|
226823189
|
100
|
|
|
|
if (o->op_private & OPpREFCOUNTED) { |
691
|
29181162
|
100
|
|
|
|
switch (type) { |
692
|
|
|
|
|
|
case OP_LEAVESUB: |
693
|
|
|
|
|
|
case OP_LEAVESUBLV: |
694
|
|
|
|
|
|
case OP_LEAVEEVAL: |
695
|
|
|
|
|
|
case OP_LEAVE: |
696
|
|
|
|
|
|
case OP_SCOPE: |
697
|
|
|
|
|
|
case OP_LEAVEWRITE: |
698
|
|
|
|
|
|
{ |
699
|
|
|
|
|
|
PADOFFSET refcnt; |
700
|
|
|
|
|
|
OP_REFCNT_LOCK; |
701
|
9149031
|
|
|
|
|
refcnt = OpREFCNT_dec(o); |
702
|
|
|
|
|
|
OP_REFCNT_UNLOCK; |
703
|
9149031
|
100
|
|
|
|
if (refcnt) { |
704
|
|
|
|
|
|
/* Need to find and remove any pattern match ops from the list |
705
|
|
|
|
|
|
we maintain for reset(). */ |
706
|
2910239
|
|
|
|
|
find_and_forget_pmops(o); |
707
|
2910239
|
|
|
|
|
return; |
708
|
|
|
|
|
|
} |
709
|
|
|
|
|
|
} |
710
|
|
|
|
|
|
break; |
711
|
|
|
|
|
|
default: |
712
|
|
|
|
|
|
break; |
713
|
|
|
|
|
|
} |
714
|
|
|
|
|
|
} |
715
|
|
|
|
|
|
|
716
|
|
|
|
|
|
/* Call the op_free hook if it has been set. Do it now so that it's called |
717
|
|
|
|
|
|
* at the right time for refcounted ops, but still before all of the kids |
718
|
|
|
|
|
|
* are freed. */ |
719
|
223912950
|
100
|
|
|
|
CALL_OPFREEHOOK(o); |
720
|
|
|
|
|
|
|
721
|
223912950
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
722
|
|
|
|
|
|
OP *kid, *nextkid; |
723
|
286858385
|
100
|
|
|
|
for (kid = cUNOPo->op_first; kid; kid = nextkid) { |
724
|
165274623
|
|
|
|
|
nextkid = kid->op_sibling; /* Get before next freeing kid */ |
725
|
165274623
|
|
|
|
|
op_free(kid); |
726
|
|
|
|
|
|
} |
727
|
|
|
|
|
|
} |
728
|
223912950
|
100
|
|
|
|
if (type == OP_NULL) |
729
|
19619662
|
|
|
|
|
type = (OPCODE)o->op_targ; |
730
|
|
|
|
|
|
|
731
|
|
|
|
|
|
if (o->op_slabbed) |
732
|
|
|
|
|
|
Slab_to_rw(OpSLAB(o)); |
733
|
|
|
|
|
|
|
734
|
|
|
|
|
|
/* COP* is not cleared by op_clear() so that we may track line |
735
|
|
|
|
|
|
* numbers etc even after null() */ |
736
|
223912950
|
100
|
|
|
|
if (type == OP_NEXTSTATE || type == OP_DBSTATE) { |
737
|
15401836
|
|
|
|
|
cop_free((COP*)o); |
738
|
|
|
|
|
|
} |
739
|
|
|
|
|
|
|
740
|
223912950
|
|
|
|
|
op_clear(o); |
741
|
225828402
|
|
|
|
|
FreeOp(o); |
742
|
|
|
|
|
|
#ifdef DEBUG_LEAKING_SCALARS |
743
|
|
|
|
|
|
if (PL_op == o) |
744
|
|
|
|
|
|
PL_op = NULL; |
745
|
|
|
|
|
|
#endif |
746
|
|
|
|
|
|
} |
747
|
|
|
|
|
|
|
748
|
|
|
|
|
|
void |
749
|
307419884
|
|
|
|
|
Perl_op_clear(pTHX_ OP *o) |
750
|
|
|
|
|
|
{ |
751
|
|
|
|
|
|
|
752
|
|
|
|
|
|
dVAR; |
753
|
|
|
|
|
|
|
754
|
|
|
|
|
|
PERL_ARGS_ASSERT_OP_CLEAR; |
755
|
|
|
|
|
|
|
756
|
|
|
|
|
|
#ifdef PERL_MAD |
757
|
|
|
|
|
|
mad_free(o->op_madprop); |
758
|
|
|
|
|
|
o->op_madprop = 0; |
759
|
|
|
|
|
|
#endif |
760
|
|
|
|
|
|
|
761
|
|
|
|
|
|
retry: |
762
|
307419884
|
|
|
|
|
switch (o->op_type) { |
763
|
|
|
|
|
|
case OP_NULL: /* Was holding old type, if any. */ |
764
|
|
|
|
|
|
if (PL_madskills && o->op_targ != OP_NULL) { |
765
|
|
|
|
|
|
o->op_type = (Optype)o->op_targ; |
766
|
|
|
|
|
|
o->op_targ = 0; |
767
|
|
|
|
|
|
goto retry; |
768
|
|
|
|
|
|
} |
769
|
|
|
|
|
|
case OP_ENTERTRY: |
770
|
|
|
|
|
|
case OP_ENTEREVAL: /* Was holding hints. */ |
771
|
20232336
|
|
|
|
|
o->op_targ = 0; |
772
|
20232336
|
|
|
|
|
break; |
773
|
|
|
|
|
|
default: |
774
|
184776863
|
100
|
|
|
|
if (!(o->op_flags & OPf_REF) |
775
|
14497658
|
100
|
|
|
|
|| (PL_check[o->op_type] != Perl_ck_ftst)) |
776
|
|
|
|
|
|
break; |
777
|
|
|
|
|
|
/* FALL THROUGH */ |
778
|
|
|
|
|
|
case OP_GVSV: |
779
|
|
|
|
|
|
case OP_GV: |
780
|
|
|
|
|
|
case OP_AELEMFAST: |
781
|
|
|
|
|
|
{ |
782
|
18315876
|
|
|
|
|
GV *gv = (o->op_type == OP_GV || o->op_type == OP_GVSV) |
783
|
|
|
|
|
|
#ifdef USE_ITHREADS |
784
|
|
|
|
|
|
&& PL_curpad |
785
|
|
|
|
|
|
#endif |
786
|
18315876
|
100
|
|
|
|
? cGVOPo_gv : NULL; |
787
|
|
|
|
|
|
/* It's possible during global destruction that the GV is freed |
788
|
|
|
|
|
|
before the optree. Whilst the SvREFCNT_inc is happy to bump from |
789
|
|
|
|
|
|
0 to 1 on a freed SV, the corresponding SvREFCNT_dec from 1 to 0 |
790
|
|
|
|
|
|
will trigger an assertion failure, because the entry to sv_clear |
791
|
|
|
|
|
|
checks that the scalar is not already freed. A check of for |
792
|
|
|
|
|
|
!SvIS_FREED(gv) turns out to be invalid, because during global |
793
|
|
|
|
|
|
destruction the reference count can be forced down to zero |
794
|
|
|
|
|
|
(with SVf_BREAK set). In which case raising to 1 and then |
795
|
|
|
|
|
|
dropping to 0 triggers cleanup before it should happen. I |
796
|
|
|
|
|
|
*think* that this might actually be a general, systematic, |
797
|
|
|
|
|
|
weakness of the whole idea of SVf_BREAK, in that code *is* |
798
|
|
|
|
|
|
allowed to raise and lower references during global destruction, |
799
|
|
|
|
|
|
so any *valid* code that happens to do this during global |
800
|
|
|
|
|
|
destruction might well trigger premature cleanup. */ |
801
|
18315876
|
100
|
|
|
|
bool still_valid = gv && SvREFCNT(gv); |
|
|
50
|
|
|
|
|
802
|
|
|
|
|
|
|
803
|
18315876
|
100
|
|
|
|
if (still_valid) |
804
|
18231324
|
50
|
|
|
|
SvREFCNT_inc_simple_void(gv); |
805
|
|
|
|
|
|
#ifdef USE_ITHREADS |
806
|
|
|
|
|
|
if (cPADOPo->op_padix > 0) { |
807
|
|
|
|
|
|
/* No GvIN_PAD_off(cGVOPo_gv) here, because other references |
808
|
|
|
|
|
|
* may still exist on the pad */ |
809
|
|
|
|
|
|
pad_swipe(cPADOPo->op_padix, TRUE); |
810
|
|
|
|
|
|
cPADOPo->op_padix = 0; |
811
|
|
|
|
|
|
} |
812
|
|
|
|
|
|
#else |
813
|
18315876
|
|
|
|
|
SvREFCNT_dec(cSVOPo->op_sv); |
814
|
18315876
|
|
|
|
|
cSVOPo->op_sv = NULL; |
815
|
|
|
|
|
|
#endif |
816
|
18315876
|
100
|
|
|
|
if (still_valid) { |
817
|
18231324
|
|
|
|
|
int try_downgrade = SvREFCNT(gv) == 2; |
818
|
18231324
|
|
|
|
|
SvREFCNT_dec_NN(gv); |
819
|
18231324
|
100
|
|
|
|
if (try_downgrade) |
820
|
7474607
|
|
|
|
|
gv_try_downgrade(gv); |
821
|
|
|
|
|
|
} |
822
|
|
|
|
|
|
} |
823
|
|
|
|
|
|
break; |
824
|
|
|
|
|
|
case OP_METHOD_NAMED: |
825
|
|
|
|
|
|
case OP_CONST: |
826
|
|
|
|
|
|
case OP_HINTSEVAL: |
827
|
83131162
|
|
|
|
|
SvREFCNT_dec(cSVOPo->op_sv); |
828
|
83131162
|
|
|
|
|
cSVOPo->op_sv = NULL; |
829
|
|
|
|
|
|
#ifdef USE_ITHREADS |
830
|
|
|
|
|
|
/** Bug #15654 |
831
|
|
|
|
|
|
Even if op_clear does a pad_free for the target of the op, |
832
|
|
|
|
|
|
pad_free doesn't actually remove the sv that exists in the pad; |
833
|
|
|
|
|
|
instead it lives on. This results in that it could be reused as |
834
|
|
|
|
|
|
a target later on when the pad was reallocated. |
835
|
|
|
|
|
|
**/ |
836
|
|
|
|
|
|
if(o->op_targ) { |
837
|
|
|
|
|
|
pad_swipe(o->op_targ,1); |
838
|
|
|
|
|
|
o->op_targ = 0; |
839
|
|
|
|
|
|
} |
840
|
|
|
|
|
|
#endif |
841
|
83131162
|
|
|
|
|
break; |
842
|
|
|
|
|
|
case OP_DUMP: |
843
|
|
|
|
|
|
case OP_GOTO: |
844
|
|
|
|
|
|
case OP_NEXT: |
845
|
|
|
|
|
|
case OP_LAST: |
846
|
|
|
|
|
|
case OP_REDO: |
847
|
37263
|
100
|
|
|
|
if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS)) |
848
|
|
|
|
|
|
break; |
849
|
|
|
|
|
|
/* FALL THROUGH */ |
850
|
|
|
|
|
|
case OP_TRANS: |
851
|
|
|
|
|
|
case OP_TRANSR: |
852
|
23342
|
100
|
|
|
|
if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) { |
853
|
|
|
|
|
|
assert(o->op_type == OP_TRANS || o->op_type == OP_TRANSR); |
854
|
|
|
|
|
|
#ifdef USE_ITHREADS |
855
|
|
|
|
|
|
if (cPADOPo->op_padix > 0) { |
856
|
|
|
|
|
|
pad_swipe(cPADOPo->op_padix, TRUE); |
857
|
|
|
|
|
|
cPADOPo->op_padix = 0; |
858
|
|
|
|
|
|
} |
859
|
|
|
|
|
|
#else |
860
|
120
|
|
|
|
|
SvREFCNT_dec(cSVOPo->op_sv); |
861
|
120
|
|
|
|
|
cSVOPo->op_sv = NULL; |
862
|
|
|
|
|
|
#endif |
863
|
|
|
|
|
|
} |
864
|
|
|
|
|
|
else { |
865
|
23222
|
|
|
|
|
PerlMemShared_free(cPVOPo->op_pv); |
866
|
23222
|
|
|
|
|
cPVOPo->op_pv = NULL; |
867
|
|
|
|
|
|
} |
868
|
|
|
|
|
|
break; |
869
|
|
|
|
|
|
case OP_SUBST: |
870
|
31081
|
|
|
|
|
op_free(cPMOPo->op_pmreplrootu.op_pmreplroot); |
871
|
31081
|
|
|
|
|
goto clear_pmop; |
872
|
|
|
|
|
|
case OP_PUSHRE: |
873
|
|
|
|
|
|
#ifdef USE_ITHREADS |
874
|
|
|
|
|
|
if (cPMOPo->op_pmreplrootu.op_pmtargetoff) { |
875
|
|
|
|
|
|
/* No GvIN_PAD_off here, because other references may still |
876
|
|
|
|
|
|
* exist on the pad */ |
877
|
|
|
|
|
|
pad_swipe(cPMOPo->op_pmreplrootu.op_pmtargetoff, TRUE); |
878
|
|
|
|
|
|
} |
879
|
|
|
|
|
|
#else |
880
|
57050
|
|
|
|
|
SvREFCNT_dec(MUTABLE_SV(cPMOPo->op_pmreplrootu.op_pmtargetgv)); |
881
|
|
|
|
|
|
#endif |
882
|
|
|
|
|
|
/* FALL THROUGH */ |
883
|
|
|
|
|
|
case OP_MATCH: |
884
|
|
|
|
|
|
case OP_QR: |
885
|
|
|
|
|
|
clear_pmop: |
886
|
905442
|
100
|
|
|
|
if (!(cPMOPo->op_pmflags & PMf_CODELIST_PRIVATE)) |
887
|
905414
|
|
|
|
|
op_free(cPMOPo->op_code_list); |
888
|
905442
|
|
|
|
|
cPMOPo->op_code_list = NULL; |
889
|
905442
|
|
|
|
|
forget_pmop(cPMOPo); |
890
|
905442
|
|
|
|
|
cPMOPo->op_pmreplrootu.op_pmreplroot = NULL; |
891
|
|
|
|
|
|
/* we use the same protection as the "SAFE" version of the PM_ macros |
892
|
|
|
|
|
|
* here since sv_clean_all might release some PMOPs |
893
|
|
|
|
|
|
* after PL_regex_padav has been cleared |
894
|
|
|
|
|
|
* and the clearing of PL_regex_padav needs to |
895
|
|
|
|
|
|
* happen before sv_clean_all |
896
|
|
|
|
|
|
*/ |
897
|
|
|
|
|
|
#ifdef USE_ITHREADS |
898
|
|
|
|
|
|
if(PL_regex_pad) { /* We could be in destruction */ |
899
|
|
|
|
|
|
const IV offset = (cPMOPo)->op_pmoffset; |
900
|
|
|
|
|
|
ReREFCNT_dec(PM_GETRE(cPMOPo)); |
901
|
|
|
|
|
|
PL_regex_pad[offset] = &PL_sv_undef; |
902
|
|
|
|
|
|
sv_catpvn_nomg(PL_regex_pad[0], (const char *)&offset, |
903
|
|
|
|
|
|
sizeof(offset)); |
904
|
|
|
|
|
|
} |
905
|
|
|
|
|
|
#else |
906
|
905442
|
|
|
|
|
ReREFCNT_dec(PM_GETRE(cPMOPo)); |
907
|
905442
|
|
|
|
|
PM_SETRE(cPMOPo, NULL); |
908
|
|
|
|
|
|
#endif |
909
|
|
|
|
|
|
|
910
|
905442
|
|
|
|
|
break; |
911
|
|
|
|
|
|
} |
912
|
|
|
|
|
|
|
913
|
307419884
|
100
|
|
|
|
if (o->op_targ > 0) { |
914
|
24529676
|
|
|
|
|
pad_free(o->op_targ); |
915
|
24529676
|
|
|
|
|
o->op_targ = 0; |
916
|
|
|
|
|
|
} |
917
|
307419884
|
|
|
|
|
} |
918
|
|
|
|
|
|
|
919
|
|
|
|
|
|
STATIC void |
920
|
17148804
|
|
|
|
|
S_cop_free(pTHX_ COP* cop) |
921
|
|
|
|
|
|
{ |
922
|
|
|
|
|
|
PERL_ARGS_ASSERT_COP_FREE; |
923
|
|
|
|
|
|
|
924
|
17148804
|
|
|
|
|
CopFILE_free(cop); |
925
|
17148804
|
100
|
|
|
|
if (! specialWARN(cop->cop_warnings)) |
|
|
100
|
|
|
|
|
926
|
1624378
|
|
|
|
|
PerlMemShared_free(cop->cop_warnings); |
927
|
17148804
|
|
|
|
|
cophh_free(CopHINTHASH_get(cop)); |
928
|
17148804
|
100
|
|
|
|
if (PL_curcop == cop) |
929
|
1747000
|
|
|
|
|
PL_curcop = NULL; |
930
|
17148804
|
|
|
|
|
} |
931
|
|
|
|
|
|
|
932
|
|
|
|
|
|
STATIC void |
933
|
967037
|
|
|
|
|
S_forget_pmop(pTHX_ PMOP *const o |
934
|
|
|
|
|
|
) |
935
|
|
|
|
|
|
{ |
936
|
967037
|
100
|
|
|
|
HV * const pmstash = PmopSTASH(o); |
937
|
|
|
|
|
|
|
938
|
|
|
|
|
|
PERL_ARGS_ASSERT_FORGET_PMOP; |
939
|
|
|
|
|
|
|
940
|
967037
|
100
|
|
|
|
if (pmstash && !SvIS_FREED(pmstash) && SvMAGICAL(pmstash)) { |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
941
|
26
|
|
|
|
|
MAGIC * const mg = mg_find((const SV *)pmstash, PERL_MAGIC_symtab); |
942
|
26
|
50
|
|
|
|
if (mg) { |
943
|
26
|
|
|
|
|
PMOP **const array = (PMOP**) mg->mg_ptr; |
944
|
26
|
|
|
|
|
U32 count = mg->mg_len / sizeof(PMOP**); |
945
|
|
|
|
|
|
U32 i = count; |
946
|
|
|
|
|
|
|
947
|
45
|
50
|
|
|
|
while (i--) { |
948
|
32
|
100
|
|
|
|
if (array[i] == o) { |
949
|
|
|
|
|
|
/* Found it. Move the entry at the end to overwrite it. */ |
950
|
26
|
|
|
|
|
array[i] = array[--count]; |
951
|
26
|
|
|
|
|
mg->mg_len = count * sizeof(PMOP**); |
952
|
|
|
|
|
|
/* Could realloc smaller at this point always, but probably |
953
|
|
|
|
|
|
not worth it. Probably worth free()ing if we're the |
954
|
|
|
|
|
|
last. */ |
955
|
26
|
100
|
|
|
|
if(!count) { |
956
|
20
|
|
|
|
|
Safefree(mg->mg_ptr); |
957
|
20
|
|
|
|
|
mg->mg_ptr = NULL; |
958
|
|
|
|
|
|
} |
959
|
|
|
|
|
|
break; |
960
|
|
|
|
|
|
} |
961
|
|
|
|
|
|
} |
962
|
|
|
|
|
|
} |
963
|
|
|
|
|
|
} |
964
|
967037
|
100
|
|
|
|
if (PL_curpm == o) |
965
|
178
|
|
|
|
|
PL_curpm = NULL; |
966
|
967037
|
|
|
|
|
} |
967
|
|
|
|
|
|
|
968
|
|
|
|
|
|
STATIC void |
969
|
33938286
|
|
|
|
|
S_find_and_forget_pmops(pTHX_ OP *o) |
970
|
|
|
|
|
|
{ |
971
|
|
|
|
|
|
PERL_ARGS_ASSERT_FIND_AND_FORGET_PMOPS; |
972
|
|
|
|
|
|
|
973
|
33938286
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
974
|
17127202
|
|
|
|
|
OP *kid = cUNOPo->op_first; |
975
|
56709139
|
100
|
|
|
|
while (kid) { |
976
|
31028047
|
100
|
|
|
|
switch (kid->op_type) { |
977
|
|
|
|
|
|
case OP_SUBST: |
978
|
|
|
|
|
|
case OP_PUSHRE: |
979
|
|
|
|
|
|
case OP_MATCH: |
980
|
|
|
|
|
|
case OP_QR: |
981
|
61595
|
|
|
|
|
forget_pmop((PMOP*)kid); |
982
|
|
|
|
|
|
} |
983
|
31028047
|
|
|
|
|
find_and_forget_pmops(kid); |
984
|
31028047
|
|
|
|
|
kid = kid->op_sibling; |
985
|
|
|
|
|
|
} |
986
|
|
|
|
|
|
} |
987
|
33938286
|
|
|
|
|
} |
988
|
|
|
|
|
|
|
989
|
|
|
|
|
|
void |
990
|
83506934
|
|
|
|
|
Perl_op_null(pTHX_ OP *o) |
991
|
|
|
|
|
|
{ |
992
|
|
|
|
|
|
dVAR; |
993
|
|
|
|
|
|
|
994
|
|
|
|
|
|
PERL_ARGS_ASSERT_OP_NULL; |
995
|
|
|
|
|
|
|
996
|
83506934
|
50
|
|
|
|
if (o->op_type == OP_NULL) |
997
|
83506934
|
|
|
|
|
return; |
998
|
|
|
|
|
|
if (!PL_madskills) |
999
|
83506934
|
|
|
|
|
op_clear(o); |
1000
|
83506934
|
|
|
|
|
o->op_targ = o->op_type; |
1001
|
83506934
|
|
|
|
|
o->op_type = OP_NULL; |
1002
|
83506934
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_NULL]; |
1003
|
|
|
|
|
|
} |
1004
|
|
|
|
|
|
|
1005
|
|
|
|
|
|
void |
1006
|
0
|
|
|
|
|
Perl_op_refcnt_lock(pTHX) |
1007
|
|
|
|
|
|
{ |
1008
|
|
|
|
|
|
dVAR; |
1009
|
|
|
|
|
|
PERL_UNUSED_CONTEXT; |
1010
|
|
|
|
|
|
OP_REFCNT_LOCK; |
1011
|
0
|
|
|
|
|
} |
1012
|
|
|
|
|
|
|
1013
|
|
|
|
|
|
void |
1014
|
0
|
|
|
|
|
Perl_op_refcnt_unlock(pTHX) |
1015
|
|
|
|
|
|
{ |
1016
|
|
|
|
|
|
dVAR; |
1017
|
|
|
|
|
|
PERL_UNUSED_CONTEXT; |
1018
|
|
|
|
|
|
OP_REFCNT_UNLOCK; |
1019
|
0
|
|
|
|
|
} |
1020
|
|
|
|
|
|
|
1021
|
|
|
|
|
|
/* Contextualizers */ |
1022
|
|
|
|
|
|
|
1023
|
|
|
|
|
|
/* |
1024
|
|
|
|
|
|
=for apidoc Am|OP *|op_contextualize|OP *o|I32 context |
1025
|
|
|
|
|
|
|
1026
|
|
|
|
|
|
Applies a syntactic context to an op tree representing an expression. |
1027
|
|
|
|
|
|
I is the op tree, and I must be C, C, |
1028
|
|
|
|
|
|
or C to specify the context to apply. The modified op tree |
1029
|
|
|
|
|
|
is returned. |
1030
|
|
|
|
|
|
|
1031
|
|
|
|
|
|
=cut |
1032
|
|
|
|
|
|
*/ |
1033
|
|
|
|
|
|
|
1034
|
|
|
|
|
|
OP * |
1035
|
50
|
|
|
|
|
Perl_op_contextualize(pTHX_ OP *o, I32 context) |
1036
|
|
|
|
|
|
{ |
1037
|
|
|
|
|
|
PERL_ARGS_ASSERT_OP_CONTEXTUALIZE; |
1038
|
50
|
|
|
|
|
switch (context) { |
1039
|
46
|
|
|
|
|
case G_SCALAR: return scalar(o); |
1040
|
2
|
|
|
|
|
case G_ARRAY: return list(o); |
1041
|
2
|
|
|
|
|
case G_VOID: return scalarvoid(o); |
1042
|
|
|
|
|
|
default: |
1043
|
25
|
|
|
|
|
Perl_croak(aTHX_ "panic: op_contextualize bad context %ld", |
1044
|
|
|
|
|
|
(long) context); |
1045
|
|
|
|
|
|
return o; |
1046
|
|
|
|
|
|
} |
1047
|
|
|
|
|
|
} |
1048
|
|
|
|
|
|
|
1049
|
|
|
|
|
|
/* |
1050
|
|
|
|
|
|
=head1 Optree Manipulation Functions |
1051
|
|
|
|
|
|
|
1052
|
|
|
|
|
|
=for apidoc Am|OP*|op_linklist|OP *o |
1053
|
|
|
|
|
|
This function is the implementation of the L macro. It should |
1054
|
|
|
|
|
|
not be called directly. |
1055
|
|
|
|
|
|
|
1056
|
|
|
|
|
|
=cut |
1057
|
|
|
|
|
|
*/ |
1058
|
|
|
|
|
|
|
1059
|
|
|
|
|
|
OP * |
1060
|
309826465
|
|
|
|
|
Perl_op_linklist(pTHX_ OP *o) |
1061
|
|
|
|
|
|
{ |
1062
|
|
|
|
|
|
OP *first; |
1063
|
|
|
|
|
|
|
1064
|
|
|
|
|
|
PERL_ARGS_ASSERT_OP_LINKLIST; |
1065
|
|
|
|
|
|
|
1066
|
309826465
|
50
|
|
|
|
if (o->op_next) |
1067
|
0
|
|
|
|
|
return o->op_next; |
1068
|
|
|
|
|
|
|
1069
|
|
|
|
|
|
/* establish postfix order */ |
1070
|
309826465
|
|
|
|
|
first = cUNOPo->op_first; |
1071
|
309826465
|
100
|
|
|
|
if (first) { |
1072
|
|
|
|
|
|
OP *kid; |
1073
|
308821804
|
100
|
|
|
|
o->op_next = LINKLIST(first); |
1074
|
|
|
|
|
|
kid = first; |
1075
|
|
|
|
|
|
for (;;) { |
1076
|
677571657
|
100
|
|
|
|
if (kid->op_sibling) { |
1077
|
368749853
|
100
|
|
|
|
kid->op_next = LINKLIST(kid->op_sibling); |
1078
|
368749853
|
|
|
|
|
kid = kid->op_sibling; |
1079
|
|
|
|
|
|
} else { |
1080
|
308821804
|
|
|
|
|
kid->op_next = o; |
1081
|
|
|
|
|
|
break; |
1082
|
|
|
|
|
|
} |
1083
|
368749853
|
|
|
|
|
} |
1084
|
|
|
|
|
|
} |
1085
|
|
|
|
|
|
else |
1086
|
1004661
|
|
|
|
|
o->op_next = o; |
1087
|
|
|
|
|
|
|
1088
|
309826465
|
|
|
|
|
return o->op_next; |
1089
|
|
|
|
|
|
} |
1090
|
|
|
|
|
|
|
1091
|
|
|
|
|
|
static OP * |
1092
|
108046
|
|
|
|
|
S_scalarkids(pTHX_ OP *o) |
1093
|
|
|
|
|
|
{ |
1094
|
108046
|
50
|
|
|
|
if (o && o->op_flags & OPf_KIDS) { |
|
|
50
|
|
|
|
|
1095
|
|
|
|
|
|
OP *kid; |
1096
|
234986
|
100
|
|
|
|
for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) |
1097
|
126940
|
|
|
|
|
scalar(kid); |
1098
|
|
|
|
|
|
} |
1099
|
108046
|
|
|
|
|
return o; |
1100
|
|
|
|
|
|
} |
1101
|
|
|
|
|
|
|
1102
|
|
|
|
|
|
STATIC OP * |
1103
|
26219362
|
|
|
|
|
S_scalarboolean(pTHX_ OP *o) |
1104
|
|
|
|
|
|
{ |
1105
|
|
|
|
|
|
dVAR; |
1106
|
|
|
|
|
|
|
1107
|
|
|
|
|
|
PERL_ARGS_ASSERT_SCALARBOOLEAN; |
1108
|
|
|
|
|
|
|
1109
|
26219362
|
100
|
|
|
|
if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST |
|
|
100
|
|
|
|
|
1110
|
14
|
100
|
|
|
|
&& !(cBINOPo->op_first->op_flags & OPf_SPECIAL)) { |
1111
|
10
|
100
|
|
|
|
if (ckWARN(WARN_SYNTAX)) { |
1112
|
4
|
|
|
|
|
const line_t oldline = CopLINE(PL_curcop); |
1113
|
|
|
|
|
|
|
1114
|
4
|
50
|
|
|
|
if (PL_parser && PL_parser->copline != NOLINE) { |
|
|
50
|
|
|
|
|
1115
|
|
|
|
|
|
/* This ensures that warnings are reported at the first line |
1116
|
|
|
|
|
|
of the conditional, not the last. */ |
1117
|
4
|
|
|
|
|
CopLINE_set(PL_curcop, PL_parser->copline); |
1118
|
|
|
|
|
|
} |
1119
|
4
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Found = in conditional, should be =="); |
1120
|
4
|
|
|
|
|
CopLINE_set(PL_curcop, oldline); |
1121
|
|
|
|
|
|
} |
1122
|
|
|
|
|
|
} |
1123
|
26219362
|
|
|
|
|
return scalar(o); |
1124
|
|
|
|
|
|
} |
1125
|
|
|
|
|
|
|
1126
|
|
|
|
|
|
OP * |
1127
|
1066652324
|
|
|
|
|
Perl_scalar(pTHX_ OP *o) |
1128
|
|
|
|
|
|
{ |
1129
|
|
|
|
|
|
dVAR; |
1130
|
|
|
|
|
|
OP *kid; |
1131
|
|
|
|
|
|
|
1132
|
|
|
|
|
|
/* assumes no premature commitment */ |
1133
|
1066652324
|
100
|
|
|
|
if (!o || (PL_parser && PL_parser->error_count) |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
1134
|
1065783407
|
100
|
|
|
|
|| (o->op_flags & OPf_WANT) |
1135
|
530415953
|
100
|
|
|
|
|| o->op_type == OP_RETURN) |
1136
|
|
|
|
|
|
{ |
1137
|
|
|
|
|
|
return o; |
1138
|
|
|
|
|
|
} |
1139
|
|
|
|
|
|
|
1140
|
530380251
|
|
|
|
|
o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_SCALAR; |
1141
|
|
|
|
|
|
|
1142
|
530380251
|
|
|
|
|
switch (o->op_type) { |
1143
|
|
|
|
|
|
case OP_REPEAT: |
1144
|
147986
|
|
|
|
|
scalar(cBINOPo->op_first); |
1145
|
147986
|
|
|
|
|
break; |
1146
|
|
|
|
|
|
case OP_OR: |
1147
|
|
|
|
|
|
case OP_AND: |
1148
|
|
|
|
|
|
case OP_COND_EXPR: |
1149
|
15305037
|
100
|
|
|
|
for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling) |
1150
|
8435450
|
|
|
|
|
scalar(kid); |
1151
|
|
|
|
|
|
break; |
1152
|
|
|
|
|
|
/* FALL THROUGH */ |
1153
|
|
|
|
|
|
case OP_SPLIT: |
1154
|
|
|
|
|
|
case OP_MATCH: |
1155
|
|
|
|
|
|
case OP_QR: |
1156
|
|
|
|
|
|
case OP_SUBST: |
1157
|
|
|
|
|
|
case OP_NULL: |
1158
|
|
|
|
|
|
default: |
1159
|
513256187
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
1160
|
462176976
|
100
|
|
|
|
for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) |
1161
|
290640958
|
|
|
|
|
scalar(kid); |
1162
|
|
|
|
|
|
} |
1163
|
|
|
|
|
|
break; |
1164
|
|
|
|
|
|
case OP_LEAVE: |
1165
|
|
|
|
|
|
case OP_LEAVETRY: |
1166
|
719646
|
|
|
|
|
kid = cLISTOPo->op_first; |
1167
|
719646
|
|
|
|
|
scalar(kid); |
1168
|
5559754
|
|
|
|
|
kid = kid->op_sibling; |
1169
|
|
|
|
|
|
do_kids: |
1170
|
45849747
|
100
|
|
|
|
while (kid) { |
1171
|
35743270
|
|
|
|
|
OP *sib = kid->op_sibling; |
1172
|
35743270
|
100
|
|
|
|
if (sib && kid->op_type != OP_LEAVEWHEN) |
|
|
100
|
|
|
|
|
1173
|
25636749
|
|
|
|
|
scalarvoid(kid); |
1174
|
|
|
|
|
|
else |
1175
|
23377180
|
|
|
|
|
scalar(kid); |
1176
|
|
|
|
|
|
kid = sib; |
1177
|
|
|
|
|
|
} |
1178
|
10106477
|
|
|
|
|
PL_curcop = &PL_compiling; |
1179
|
10106477
|
|
|
|
|
break; |
1180
|
|
|
|
|
|
case OP_SCOPE: |
1181
|
|
|
|
|
|
case OP_LINESEQ: |
1182
|
|
|
|
|
|
case OP_LIST: |
1183
|
9386831
|
|
|
|
|
kid = cLISTOPo->op_first; |
1184
|
9386831
|
|
|
|
|
goto do_kids; |
1185
|
|
|
|
|
|
case OP_SORT: |
1186
|
14
|
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_VOID), "Useless use of sort in scalar context"); |
1187
|
554549055
|
|
|
|
|
break; |
1188
|
|
|
|
|
|
} |
1189
|
|
|
|
|
|
return o; |
1190
|
|
|
|
|
|
} |
1191
|
|
|
|
|
|
|
1192
|
|
|
|
|
|
OP * |
1193
|
295597498
|
|
|
|
|
Perl_scalarvoid(pTHX_ OP *o) |
1194
|
|
|
|
|
|
{ |
1195
|
|
|
|
|
|
dVAR; |
1196
|
|
|
|
|
|
OP *kid; |
1197
|
|
|
|
|
|
SV *useless_sv = NULL; |
1198
|
|
|
|
|
|
const char* useless = NULL; |
1199
|
|
|
|
|
|
SV* sv; |
1200
|
|
|
|
|
|
U8 want; |
1201
|
|
|
|
|
|
|
1202
|
|
|
|
|
|
PERL_ARGS_ASSERT_SCALARVOID; |
1203
|
|
|
|
|
|
|
1204
|
|
|
|
|
|
/* trailing mad null ops don't count as "there" for void processing */ |
1205
|
|
|
|
|
|
if (PL_madskills && |
1206
|
|
|
|
|
|
o->op_type != OP_NULL && |
1207
|
|
|
|
|
|
o->op_sibling && |
1208
|
|
|
|
|
|
o->op_sibling->op_type == OP_NULL) |
1209
|
|
|
|
|
|
{ |
1210
|
|
|
|
|
|
OP *sib; |
1211
|
|
|
|
|
|
for (sib = o->op_sibling; |
1212
|
|
|
|
|
|
sib && sib->op_type == OP_NULL; |
1213
|
|
|
|
|
|
sib = sib->op_sibling) ; |
1214
|
|
|
|
|
|
|
1215
|
|
|
|
|
|
if (!sib) |
1216
|
|
|
|
|
|
return o; |
1217
|
|
|
|
|
|
} |
1218
|
|
|
|
|
|
|
1219
|
437666929
|
100
|
|
|
|
if (o->op_type == OP_NEXTSTATE |
1220
|
295597498
|
|
|
|
|
|| o->op_type == OP_DBSTATE |
1221
|
171553284
|
100
|
|
|
|
|| (o->op_type == OP_NULL && (o->op_targ == OP_NEXTSTATE |
|
|
100
|
|
|
|
|
1222
|
32958965
|
|
|
|
|
|| o->op_targ == OP_DBSTATE))) |
1223
|
145559830
|
|
|
|
|
PL_curcop = (COP*)o; /* for warning below */ |
1224
|
|
|
|
|
|
|
1225
|
|
|
|
|
|
/* assumes no premature commitment */ |
1226
|
295597498
|
|
|
|
|
want = o->op_flags & OPf_WANT; |
1227
|
295597498
|
100
|
|
|
|
if ((want && want != OPf_WANT_SCALAR) |
1228
|
186141042
|
100
|
|
|
|
|| (PL_parser && PL_parser->error_count) |
|
|
100
|
|
|
|
|
1229
|
186138072
|
100
|
|
|
|
|| o->op_type == OP_RETURN || o->op_type == OP_REQUIRE || o->op_type == OP_LEAVEWHEN) |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
1230
|
|
|
|
|
|
{ |
1231
|
|
|
|
|
|
return o; |
1232
|
|
|
|
|
|
} |
1233
|
|
|
|
|
|
|
1234
|
176880750
|
100
|
|
|
|
if ((o->op_private & OPpTARGET_MY) |
1235
|
1040855
|
100
|
|
|
|
&& (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */ |
1236
|
|
|
|
|
|
{ |
1237
|
737126
|
|
|
|
|
return scalar(o); /* As if inside SASSIGN */ |
1238
|
|
|
|
|
|
} |
1239
|
|
|
|
|
|
|
1240
|
176143624
|
|
|
|
|
o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID; |
1241
|
|
|
|
|
|
|
1242
|
176143624
|
|
|
|
|
switch (o->op_type) { |
1243
|
|
|
|
|
|
default: |
1244
|
15281694
|
100
|
|
|
|
if (!(PL_opargs[o->op_type] & OA_FOLDCONST)) |
1245
|
|
|
|
|
|
break; |
1246
|
|
|
|
|
|
/* FALL THROUGH */ |
1247
|
|
|
|
|
|
case OP_REPEAT: |
1248
|
1449247
|
100
|
|
|
|
if (o->op_flags & OPf_STACKED) |
1249
|
|
|
|
|
|
break; |
1250
|
|
|
|
|
|
goto func_ops; |
1251
|
|
|
|
|
|
case OP_SUBSTR: |
1252
|
40772
|
100
|
|
|
|
if (o->op_private == 4) |
1253
|
|
|
|
|
|
break; |
1254
|
|
|
|
|
|
/* FALL THROUGH */ |
1255
|
|
|
|
|
|
case OP_GVSV: |
1256
|
|
|
|
|
|
case OP_WANTARRAY: |
1257
|
|
|
|
|
|
case OP_GV: |
1258
|
|
|
|
|
|
case OP_SMARTMATCH: |
1259
|
|
|
|
|
|
case OP_PADSV: |
1260
|
|
|
|
|
|
case OP_PADAV: |
1261
|
|
|
|
|
|
case OP_PADHV: |
1262
|
|
|
|
|
|
case OP_PADANY: |
1263
|
|
|
|
|
|
case OP_AV2ARYLEN: |
1264
|
|
|
|
|
|
case OP_REF: |
1265
|
|
|
|
|
|
case OP_REFGEN: |
1266
|
|
|
|
|
|
case OP_SREFGEN: |
1267
|
|
|
|
|
|
case OP_DEFINED: |
1268
|
|
|
|
|
|
case OP_HEX: |
1269
|
|
|
|
|
|
case OP_OCT: |
1270
|
|
|
|
|
|
case OP_LENGTH: |
1271
|
|
|
|
|
|
case OP_VEC: |
1272
|
|
|
|
|
|
case OP_INDEX: |
1273
|
|
|
|
|
|
case OP_RINDEX: |
1274
|
|
|
|
|
|
case OP_SPRINTF: |
1275
|
|
|
|
|
|
case OP_AELEM: |
1276
|
|
|
|
|
|
case OP_AELEMFAST: |
1277
|
|
|
|
|
|
case OP_AELEMFAST_LEX: |
1278
|
|
|
|
|
|
case OP_ASLICE: |
1279
|
|
|
|
|
|
case OP_HELEM: |
1280
|
|
|
|
|
|
case OP_HSLICE: |
1281
|
|
|
|
|
|
case OP_UNPACK: |
1282
|
|
|
|
|
|
case OP_PACK: |
1283
|
|
|
|
|
|
case OP_JOIN: |
1284
|
|
|
|
|
|
case OP_LSLICE: |
1285
|
|
|
|
|
|
case OP_ANONLIST: |
1286
|
|
|
|
|
|
case OP_ANONHASH: |
1287
|
|
|
|
|
|
case OP_SORT: |
1288
|
|
|
|
|
|
case OP_REVERSE: |
1289
|
|
|
|
|
|
case OP_RANGE: |
1290
|
|
|
|
|
|
case OP_FLIP: |
1291
|
|
|
|
|
|
case OP_FLOP: |
1292
|
|
|
|
|
|
case OP_CALLER: |
1293
|
|
|
|
|
|
case OP_FILENO: |
1294
|
|
|
|
|
|
case OP_EOF: |
1295
|
|
|
|
|
|
case OP_TELL: |
1296
|
|
|
|
|
|
case OP_GETSOCKNAME: |
1297
|
|
|
|
|
|
case OP_GETPEERNAME: |
1298
|
|
|
|
|
|
case OP_READLINK: |
1299
|
|
|
|
|
|
case OP_TELLDIR: |
1300
|
|
|
|
|
|
case OP_GETPPID: |
1301
|
|
|
|
|
|
case OP_GETPGRP: |
1302
|
|
|
|
|
|
case OP_GETPRIORITY: |
1303
|
|
|
|
|
|
case OP_TIME: |
1304
|
|
|
|
|
|
case OP_TMS: |
1305
|
|
|
|
|
|
case OP_LOCALTIME: |
1306
|
|
|
|
|
|
case OP_GMTIME: |
1307
|
|
|
|
|
|
case OP_GHBYNAME: |
1308
|
|
|
|
|
|
case OP_GHBYADDR: |
1309
|
|
|
|
|
|
case OP_GHOSTENT: |
1310
|
|
|
|
|
|
case OP_GNBYNAME: |
1311
|
|
|
|
|
|
case OP_GNBYADDR: |
1312
|
|
|
|
|
|
case OP_GNETENT: |
1313
|
|
|
|
|
|
case OP_GPBYNAME: |
1314
|
|
|
|
|
|
case OP_GPBYNUMBER: |
1315
|
|
|
|
|
|
case OP_GPROTOENT: |
1316
|
|
|
|
|
|
case OP_GSBYNAME: |
1317
|
|
|
|
|
|
case OP_GSBYPORT: |
1318
|
|
|
|
|
|
case OP_GSERVENT: |
1319
|
|
|
|
|
|
case OP_GPWNAM: |
1320
|
|
|
|
|
|
case OP_GPWUID: |
1321
|
|
|
|
|
|
case OP_GGRNAM: |
1322
|
|
|
|
|
|
case OP_GGRGID: |
1323
|
|
|
|
|
|
case OP_GETLOGIN: |
1324
|
|
|
|
|
|
case OP_PROTOTYPE: |
1325
|
|
|
|
|
|
case OP_RUNCV: |
1326
|
|
|
|
|
|
func_ops: |
1327
|
2883165
|
100
|
|
|
|
if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO))) |
1328
|
|
|
|
|
|
/* Otherwise it's "Useless use of grep iterator" */ |
1329
|
1146
|
50
|
|
|
|
useless = OP_DESC(o); |
|
|
0
|
|
|
|
|
1330
|
|
|
|
|
|
break; |
1331
|
|
|
|
|
|
|
1332
|
|
|
|
|
|
case OP_SPLIT: |
1333
|
82
|
|
|
|
|
kid = cLISTOPo->op_first; |
1334
|
82
|
50
|
|
|
|
if (kid && kid->op_type == OP_PUSHRE |
|
|
50
|
|
|
|
|
1335
|
|
|
|
|
|
#ifdef USE_ITHREADS |
1336
|
|
|
|
|
|
&& !((PMOP*)kid)->op_pmreplrootu.op_pmtargetoff) |
1337
|
|
|
|
|
|
#else |
1338
|
82
|
100
|
|
|
|
&& !((PMOP*)kid)->op_pmreplrootu.op_pmtargetgv) |
1339
|
|
|
|
|
|
#endif |
1340
|
8
|
50
|
|
|
|
useless = OP_DESC(o); |
|
|
0
|
|
|
|
|
1341
|
|
|
|
|
|
break; |
1342
|
|
|
|
|
|
|
1343
|
|
|
|
|
|
case OP_NOT: |
1344
|
2
|
|
|
|
|
kid = cUNOPo->op_first; |
1345
|
3
|
50
|
|
|
|
if (kid->op_type != OP_MATCH && kid->op_type != OP_SUBST && |
|
|
50
|
|
|
|
|
1346
|
3
|
50
|
|
|
|
kid->op_type != OP_TRANS && kid->op_type != OP_TRANSR) { |
1347
|
|
|
|
|
|
goto func_ops; |
1348
|
|
|
|
|
|
} |
1349
|
|
|
|
|
|
useless = "negative pattern binding (!~)"; |
1350
|
|
|
|
|
|
break; |
1351
|
|
|
|
|
|
|
1352
|
|
|
|
|
|
case OP_SUBST: |
1353
|
988645
|
100
|
|
|
|
if (cPMOPo->op_pmflags & PMf_NONDESTRUCT) |
1354
|
|
|
|
|
|
useless = "non-destructive substitution (s///r)"; |
1355
|
|
|
|
|
|
break; |
1356
|
|
|
|
|
|
|
1357
|
|
|
|
|
|
case OP_TRANSR: |
1358
|
|
|
|
|
|
useless = "non-destructive transliteration (tr///r)"; |
1359
|
|
|
|
|
|
break; |
1360
|
|
|
|
|
|
|
1361
|
|
|
|
|
|
case OP_RV2GV: |
1362
|
|
|
|
|
|
case OP_RV2SV: |
1363
|
|
|
|
|
|
case OP_RV2AV: |
1364
|
|
|
|
|
|
case OP_RV2HV: |
1365
|
661447
|
100
|
|
|
|
if (!(o->op_private & (OPpLVAL_INTRO|OPpOUR_INTRO)) && |
|
|
100
|
|
|
|
|
1366
|
443
|
50
|
|
|
|
(!o->op_sibling || o->op_sibling->op_type != OP_READLINE)) |
1367
|
|
|
|
|
|
useless = "a variable"; |
1368
|
|
|
|
|
|
break; |
1369
|
|
|
|
|
|
|
1370
|
|
|
|
|
|
case OP_CONST: |
1371
|
272356
|
|
|
|
|
sv = cSVOPo_sv; |
1372
|
272356
|
100
|
|
|
|
if (cSVOPo->op_private & OPpCONST_STRICT) |
1373
|
6
|
|
|
|
|
no_bareword_allowed(o); |
1374
|
|
|
|
|
|
else { |
1375
|
272350
|
100
|
|
|
|
if (ckWARN(WARN_VOID)) { |
1376
|
|
|
|
|
|
/* don't warn on optimised away booleans, eg |
1377
|
|
|
|
|
|
* use constant Foo, 5; Foo || print; */ |
1378
|
114912
|
100
|
|
|
|
if (cSVOPo->op_private & OPpCONST_SHORTCIRCUIT) |
1379
|
|
|
|
|
|
useless = NULL; |
1380
|
|
|
|
|
|
/* the constants 0 and 1 are permitted as they are |
1381
|
|
|
|
|
|
conventionally used as dummies in constructs like |
1382
|
|
|
|
|
|
1 while some_condition_with_side_effects; */ |
1383
|
6848
|
100
|
|
|
|
else if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0)) |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
0
|
|
|
|
|
1384
|
|
|
|
|
|
useless = NULL; |
1385
|
28
|
100
|
|
|
|
else if (SvPOK(sv)) { |
1386
|
20
|
|
|
|
|
SV * const dsv = newSVpvs(""); |
1387
|
|
|
|
|
|
useless_sv |
1388
|
30
|
|
|
|
|
= Perl_newSVpvf(aTHX_ |
1389
|
|
|
|
|
|
"a constant (%s)", |
1390
|
40
|
|
|
|
|
pv_pretty(dsv, SvPVX_const(sv), |
1391
|
|
|
|
|
|
SvCUR(sv), 32, NULL, NULL, |
1392
|
|
|
|
|
|
PERL_PV_PRETTY_DUMP |
1393
|
|
|
|
|
|
| PERL_PV_ESCAPE_NOCLEAR |
1394
|
|
|
|
|
|
| PERL_PV_ESCAPE_UNI_DETECT)); |
1395
|
20
|
|
|
|
|
SvREFCNT_dec_NN(dsv); |
1396
|
|
|
|
|
|
} |
1397
|
8
|
100
|
|
|
|
else if (SvOK(sv)) { |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
1398
|
4
|
|
|
|
|
useless_sv = Perl_newSVpvf(aTHX_ "a constant (%"SVf")", sv); |
1399
|
|
|
|
|
|
} |
1400
|
|
|
|
|
|
else |
1401
|
|
|
|
|
|
useless = "a constant (undef)"; |
1402
|
|
|
|
|
|
} |
1403
|
|
|
|
|
|
} |
1404
|
272356
|
|
|
|
|
op_null(o); /* don't execute or even remember it */ |
1405
|
272356
|
|
|
|
|
break; |
1406
|
|
|
|
|
|
|
1407
|
|
|
|
|
|
case OP_POSTINC: |
1408
|
319818
|
|
|
|
|
o->op_type = OP_PREINC; /* pre-increment is faster */ |
1409
|
319818
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_PREINC]; |
1410
|
319818
|
|
|
|
|
break; |
1411
|
|
|
|
|
|
|
1412
|
|
|
|
|
|
case OP_POSTDEC: |
1413
|
72728
|
|
|
|
|
o->op_type = OP_PREDEC; /* pre-decrement is faster */ |
1414
|
72728
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_PREDEC]; |
1415
|
72728
|
|
|
|
|
break; |
1416
|
|
|
|
|
|
|
1417
|
|
|
|
|
|
case OP_I_POSTINC: |
1418
|
8402
|
|
|
|
|
o->op_type = OP_I_PREINC; /* pre-increment is faster */ |
1419
|
8402
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_I_PREINC]; |
1420
|
8402
|
|
|
|
|
break; |
1421
|
|
|
|
|
|
|
1422
|
|
|
|
|
|
case OP_I_POSTDEC: |
1423
|
4540
|
|
|
|
|
o->op_type = OP_I_PREDEC; /* pre-decrement is faster */ |
1424
|
4540
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_I_PREDEC]; |
1425
|
4540
|
|
|
|
|
break; |
1426
|
|
|
|
|
|
|
1427
|
|
|
|
|
|
case OP_SASSIGN: { |
1428
|
|
|
|
|
|
OP *rv2gv; |
1429
|
|
|
|
|
|
UNOP *refgen, *rv2cv; |
1430
|
|
|
|
|
|
LISTOP *exlist; |
1431
|
|
|
|
|
|
|
1432
|
17842429
|
50
|
|
|
|
if ((o->op_private & ~OPpASSIGN_BACKWARDS) != 2) |
1433
|
|
|
|
|
|
break; |
1434
|
|
|
|
|
|
|
1435
|
17842429
|
|
|
|
|
rv2gv = ((BINOP *)o)->op_last; |
1436
|
17842429
|
50
|
|
|
|
if (!rv2gv || rv2gv->op_type != OP_RV2GV) |
|
|
100
|
|
|
|
|
1437
|
|
|
|
|
|
break; |
1438
|
|
|
|
|
|
|
1439
|
663677
|
|
|
|
|
refgen = (UNOP *)((BINOP *)o)->op_first; |
1440
|
|
|
|
|
|
|
1441
|
663677
|
50
|
|
|
|
if (!refgen || refgen->op_type != OP_REFGEN) |
|
|
100
|
|
|
|
|
1442
|
|
|
|
|
|
break; |
1443
|
|
|
|
|
|
|
1444
|
539861
|
|
|
|
|
exlist = (LISTOP *)refgen->op_first; |
1445
|
539861
|
50
|
|
|
|
if (!exlist || exlist->op_type != OP_NULL |
|
|
50
|
|
|
|
|
1446
|
539861
|
50
|
|
|
|
|| exlist->op_targ != OP_LIST) |
1447
|
|
|
|
|
|
break; |
1448
|
|
|
|
|
|
|
1449
|
539861
|
50
|
|
|
|
if (exlist->op_first->op_type != OP_PUSHMARK) |
1450
|
|
|
|
|
|
break; |
1451
|
|
|
|
|
|
|
1452
|
539861
|
|
|
|
|
rv2cv = (UNOP*)exlist->op_last; |
1453
|
|
|
|
|
|
|
1454
|
539861
|
100
|
|
|
|
if (rv2cv->op_type != OP_RV2CV) |
1455
|
|
|
|
|
|
break; |
1456
|
|
|
|
|
|
|
1457
|
|
|
|
|
|
assert ((rv2gv->op_private & OPpDONT_INIT_GV) == 0); |
1458
|
|
|
|
|
|
assert ((o->op_private & OPpASSIGN_CV_TO_GV) == 0); |
1459
|
|
|
|
|
|
assert ((rv2cv->op_private & OPpMAY_RETURN_CONSTANT) == 0); |
1460
|
|
|
|
|
|
|
1461
|
377892
|
|
|
|
|
o->op_private |= OPpASSIGN_CV_TO_GV; |
1462
|
377892
|
|
|
|
|
rv2gv->op_private |= OPpDONT_INIT_GV; |
1463
|
377892
|
|
|
|
|
rv2cv->op_private |= OPpMAY_RETURN_CONSTANT; |
1464
|
|
|
|
|
|
|
1465
|
377892
|
|
|
|
|
break; |
1466
|
|
|
|
|
|
} |
1467
|
|
|
|
|
|
|
1468
|
|
|
|
|
|
case OP_AASSIGN: { |
1469
|
5544596
|
|
|
|
|
inplace_aassign(o); |
1470
|
5544596
|
|
|
|
|
break; |
1471
|
|
|
|
|
|
} |
1472
|
|
|
|
|
|
|
1473
|
|
|
|
|
|
case OP_OR: |
1474
|
|
|
|
|
|
case OP_AND: |
1475
|
12255313
|
|
|
|
|
kid = cLOGOPo->op_first; |
1476
|
12255313
|
100
|
|
|
|
if (kid->op_type == OP_NOT |
1477
|
618569
|
|
|
|
|
&& (kid->op_flags & OPf_KIDS) |
1478
|
618569
|
50
|
|
|
|
&& !PL_madskills) { |
1479
|
618569
|
100
|
|
|
|
if (o->op_type == OP_AND) { |
1480
|
611231
|
|
|
|
|
o->op_type = OP_OR; |
1481
|
611231
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_OR]; |
1482
|
|
|
|
|
|
} else { |
1483
|
7338
|
|
|
|
|
o->op_type = OP_AND; |
1484
|
7338
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_AND]; |
1485
|
|
|
|
|
|
} |
1486
|
618569
|
|
|
|
|
op_null(kid); |
1487
|
|
|
|
|
|
} |
1488
|
|
|
|
|
|
|
1489
|
|
|
|
|
|
case OP_DOR: |
1490
|
|
|
|
|
|
case OP_COND_EXPR: |
1491
|
|
|
|
|
|
case OP_ENTERGIVEN: |
1492
|
|
|
|
|
|
case OP_ENTERWHEN: |
1493
|
34167569
|
100
|
|
|
|
for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling) |
1494
|
18693209
|
|
|
|
|
scalarvoid(kid); |
1495
|
|
|
|
|
|
break; |
1496
|
|
|
|
|
|
|
1497
|
|
|
|
|
|
case OP_NULL: |
1498
|
17631589
|
100
|
|
|
|
if (o->op_flags & OPf_STACKED) |
1499
|
|
|
|
|
|
break; |
1500
|
|
|
|
|
|
/* FALL THROUGH */ |
1501
|
|
|
|
|
|
case OP_NEXTSTATE: |
1502
|
|
|
|
|
|
case OP_DBSTATE: |
1503
|
|
|
|
|
|
case OP_ENTERTRY: |
1504
|
|
|
|
|
|
case OP_ENTER: |
1505
|
101911778
|
100
|
|
|
|
if (!(o->op_flags & OPf_KIDS)) |
1506
|
|
|
|
|
|
break; |
1507
|
|
|
|
|
|
/* FALL THROUGH */ |
1508
|
|
|
|
|
|
case OP_SCOPE: |
1509
|
|
|
|
|
|
case OP_LEAVE: |
1510
|
|
|
|
|
|
case OP_LEAVETRY: |
1511
|
|
|
|
|
|
case OP_LEAVELOOP: |
1512
|
|
|
|
|
|
case OP_LINESEQ: |
1513
|
|
|
|
|
|
case OP_LIST: |
1514
|
|
|
|
|
|
case OP_LEAVEGIVEN: |
1515
|
|
|
|
|
|
case OP_LEAVEWHEN: |
1516
|
109786061
|
100
|
|
|
|
for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) |
1517
|
79171829
|
|
|
|
|
scalarvoid(kid); |
1518
|
|
|
|
|
|
break; |
1519
|
|
|
|
|
|
case OP_ENTEREVAL: |
1520
|
99738
|
|
|
|
|
scalarkids(o); |
1521
|
99738
|
|
|
|
|
break; |
1522
|
|
|
|
|
|
case OP_SCALAR: |
1523
|
82
|
|
|
|
|
return scalar(o); |
1524
|
|
|
|
|
|
} |
1525
|
|
|
|
|
|
|
1526
|
176143534
|
100
|
|
|
|
if (useless_sv) { |
1527
|
|
|
|
|
|
/* mortalise it, in case warnings are fatal. */ |
1528
|
24
|
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_VOID), |
1529
|
|
|
|
|
|
"Useless use of %"SVf" in void context", |
1530
|
|
|
|
|
|
sv_2mortal(useless_sv)); |
1531
|
|
|
|
|
|
} |
1532
|
176143510
|
100
|
|
|
|
else if (useless) { |
1533
|
153528800
|
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_VOID), |
1534
|
|
|
|
|
|
"Useless use of %s in void context", |
1535
|
|
|
|
|
|
useless); |
1536
|
|
|
|
|
|
} |
1537
|
|
|
|
|
|
return o; |
1538
|
|
|
|
|
|
} |
1539
|
|
|
|
|
|
|
1540
|
|
|
|
|
|
static OP * |
1541
|
75216057
|
|
|
|
|
S_listkids(pTHX_ OP *o) |
1542
|
|
|
|
|
|
{ |
1543
|
75216057
|
50
|
|
|
|
if (o && o->op_flags & OPf_KIDS) { |
|
|
50
|
|
|
|
|
1544
|
|
|
|
|
|
OP *kid; |
1545
|
243933015
|
100
|
|
|
|
for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) |
1546
|
168716958
|
|
|
|
|
list(kid); |
1547
|
|
|
|
|
|
} |
1548
|
75216057
|
|
|
|
|
return o; |
1549
|
|
|
|
|
|
} |
1550
|
|
|
|
|
|
|
1551
|
|
|
|
|
|
OP * |
1552
|
229345363
|
|
|
|
|
Perl_list(pTHX_ OP *o) |
1553
|
|
|
|
|
|
{ |
1554
|
|
|
|
|
|
dVAR; |
1555
|
|
|
|
|
|
OP *kid; |
1556
|
|
|
|
|
|
|
1557
|
|
|
|
|
|
/* assumes no premature commitment */ |
1558
|
229345363
|
100
|
|
|
|
if (!o || (o->op_flags & OPf_WANT) |
|
|
100
|
|
|
|
|
1559
|
64526277
|
100
|
|
|
|
|| (PL_parser && PL_parser->error_count) |
|
|
100
|
|
|
|
|
1560
|
64524391
|
100
|
|
|
|
|| o->op_type == OP_RETURN) |
1561
|
|
|
|
|
|
{ |
1562
|
|
|
|
|
|
return o; |
1563
|
|
|
|
|
|
} |
1564
|
|
|
|
|
|
|
1565
|
64524185
|
100
|
|
|
|
if ((o->op_private & OPpTARGET_MY) |
1566
|
226094
|
50
|
|
|
|
&& (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */ |
1567
|
|
|
|
|
|
{ |
1568
|
|
|
|
|
|
return o; /* As if inside SASSIGN */ |
1569
|
|
|
|
|
|
} |
1570
|
|
|
|
|
|
|
1571
|
64524185
|
|
|
|
|
o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_LIST; |
1572
|
|
|
|
|
|
|
1573
|
64524185
|
|
|
|
|
switch (o->op_type) { |
1574
|
|
|
|
|
|
case OP_FLOP: |
1575
|
|
|
|
|
|
case OP_REPEAT: |
1576
|
107224
|
|
|
|
|
list(cBINOPo->op_first); |
1577
|
118642228
|
|
|
|
|
break; |
1578
|
|
|
|
|
|
case OP_OR: |
1579
|
|
|
|
|
|
case OP_AND: |
1580
|
|
|
|
|
|
case OP_COND_EXPR: |
1581
|
1775342
|
100
|
|
|
|
for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling) |
1582
|
1153478
|
|
|
|
|
list(kid); |
1583
|
|
|
|
|
|
break; |
1584
|
|
|
|
|
|
default: |
1585
|
|
|
|
|
|
case OP_MATCH: |
1586
|
|
|
|
|
|
case OP_QR: |
1587
|
|
|
|
|
|
case OP_SUBST: |
1588
|
|
|
|
|
|
case OP_NULL: |
1589
|
62648330
|
100
|
|
|
|
if (!(o->op_flags & OPf_KIDS)) |
1590
|
|
|
|
|
|
break; |
1591
|
38733541
|
100
|
|
|
|
if (!o->op_next && cUNOPo->op_first->op_type == OP_FLOP) { |
|
|
100
|
|
|
|
|
1592
|
19530
|
|
|
|
|
list(cBINOPo->op_first); |
1593
|
19530
|
|
|
|
|
return gen_constant_list(o); |
1594
|
|
|
|
|
|
} |
1595
|
|
|
|
|
|
case OP_LIST: |
1596
|
39577414
|
|
|
|
|
listkids(o); |
1597
|
39577414
|
|
|
|
|
break; |
1598
|
|
|
|
|
|
case OP_LEAVE: |
1599
|
|
|
|
|
|
case OP_LEAVETRY: |
1600
|
192604
|
|
|
|
|
kid = cLISTOPo->op_first; |
1601
|
192604
|
|
|
|
|
list(kid); |
1602
|
240503
|
|
|
|
|
kid = kid->op_sibling; |
1603
|
|
|
|
|
|
do_kids: |
1604
|
989280
|
100
|
|
|
|
while (kid) { |
1605
|
705916
|
|
|
|
|
OP *sib = kid->op_sibling; |
1606
|
705916
|
100
|
|
|
|
if (sib && kid->op_type != OP_LEAVEWHEN) |
|
|
100
|
|
|
|
|
1607
|
422534
|
|
|
|
|
scalarvoid(kid); |
1608
|
|
|
|
|
|
else |
1609
|
504905
|
|
|
|
|
list(kid); |
1610
|
|
|
|
|
|
kid = sib; |
1611
|
|
|
|
|
|
} |
1612
|
283364
|
|
|
|
|
PL_curcop = &PL_compiling; |
1613
|
283364
|
|
|
|
|
break; |
1614
|
|
|
|
|
|
case OP_SCOPE: |
1615
|
|
|
|
|
|
case OP_LINESEQ: |
1616
|
90760
|
|
|
|
|
kid = cLISTOPo->op_first; |
1617
|
90760
|
|
|
|
|
goto do_kids; |
1618
|
|
|
|
|
|
} |
1619
|
|
|
|
|
|
return o; |
1620
|
|
|
|
|
|
} |
1621
|
|
|
|
|
|
|
1622
|
|
|
|
|
|
static OP * |
1623
|
49811830
|
|
|
|
|
S_scalarseq(pTHX_ OP *o) |
1624
|
|
|
|
|
|
{ |
1625
|
|
|
|
|
|
dVAR; |
1626
|
49811830
|
100
|
|
|
|
if (o) { |
1627
|
49457828
|
|
|
|
|
const OPCODE type = o->op_type; |
1628
|
|
|
|
|
|
|
1629
|
49457828
|
100
|
|
|
|
if (type == OP_LINESEQ || type == OP_SCOPE || |
1630
|
8580113
|
50
|
|
|
|
type == OP_LEAVE || type == OP_LEAVETRY) |
1631
|
|
|
|
|
|
{ |
1632
|
|
|
|
|
|
OP *kid; |
1633
|
253003961
|
100
|
|
|
|
for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) { |
1634
|
212126252
|
100
|
|
|
|
if (kid->op_sibling) { |
1635
|
171248543
|
|
|
|
|
scalarvoid(kid); |
1636
|
|
|
|
|
|
} |
1637
|
|
|
|
|
|
} |
1638
|
40877709
|
|
|
|
|
PL_curcop = &PL_compiling; |
1639
|
|
|
|
|
|
} |
1640
|
49457822
|
|
|
|
|
o->op_flags &= ~OPf_PARENS; |
1641
|
49457822
|
100
|
|
|
|
if (PL_hints & HINT_BLOCK_SCOPE) |
1642
|
33461018
|
|
|
|
|
o->op_flags |= OPf_PARENS; |
1643
|
|
|
|
|
|
} |
1644
|
|
|
|
|
|
else |
1645
|
354002
|
|
|
|
|
o = newOP(OP_STUB, 0); |
1646
|
49811824
|
|
|
|
|
return o; |
1647
|
|
|
|
|
|
} |
1648
|
|
|
|
|
|
|
1649
|
|
|
|
|
|
STATIC OP * |
1650
|
4619499
|
|
|
|
|
S_modkids(pTHX_ OP *o, I32 type) |
1651
|
|
|
|
|
|
{ |
1652
|
4619499
|
50
|
|
|
|
if (o && o->op_flags & OPf_KIDS) { |
|
|
50
|
|
|
|
|
1653
|
|
|
|
|
|
OP *kid; |
1654
|
10914879
|
100
|
|
|
|
for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) |
1655
|
6295380
|
|
|
|
|
op_lvalue(kid, type); |
1656
|
|
|
|
|
|
} |
1657
|
4619499
|
|
|
|
|
return o; |
1658
|
|
|
|
|
|
} |
1659
|
|
|
|
|
|
|
1660
|
|
|
|
|
|
/* |
1661
|
|
|
|
|
|
=for apidoc finalize_optree |
1662
|
|
|
|
|
|
|
1663
|
|
|
|
|
|
This function finalizes the optree. Should be called directly after |
1664
|
|
|
|
|
|
the complete optree is built. It does some additional |
1665
|
|
|
|
|
|
checking which can't be done in the normal ck_xxx functions and makes |
1666
|
|
|
|
|
|
the tree thread-safe. |
1667
|
|
|
|
|
|
|
1668
|
|
|
|
|
|
=cut |
1669
|
|
|
|
|
|
*/ |
1670
|
|
|
|
|
|
void |
1671
|
16687178
|
|
|
|
|
Perl_finalize_optree(pTHX_ OP* o) |
1672
|
|
|
|
|
|
{ |
1673
|
|
|
|
|
|
PERL_ARGS_ASSERT_FINALIZE_OPTREE; |
1674
|
|
|
|
|
|
|
1675
|
16687178
|
|
|
|
|
ENTER; |
1676
|
16687178
|
|
|
|
|
SAVEVPTR(PL_curcop); |
1677
|
|
|
|
|
|
|
1678
|
16687178
|
|
|
|
|
finalize_op(o); |
1679
|
|
|
|
|
|
|
1680
|
16687164
|
|
|
|
|
LEAVE; |
1681
|
16687164
|
|
|
|
|
} |
1682
|
|
|
|
|
|
|
1683
|
|
|
|
|
|
STATIC void |
1684
|
745257967
|
|
|
|
|
S_finalize_op(pTHX_ OP* o) |
1685
|
|
|
|
|
|
{ |
1686
|
|
|
|
|
|
PERL_ARGS_ASSERT_FINALIZE_OP; |
1687
|
|
|
|
|
|
|
1688
|
|
|
|
|
|
#if defined(PERL_MAD) && defined(USE_ITHREADS) |
1689
|
|
|
|
|
|
{ |
1690
|
|
|
|
|
|
/* Make sure mad ops are also thread-safe */ |
1691
|
|
|
|
|
|
MADPROP *mp = o->op_madprop; |
1692
|
|
|
|
|
|
while (mp) { |
1693
|
|
|
|
|
|
if (mp->mad_type == MAD_OP && mp->mad_vlen) { |
1694
|
|
|
|
|
|
OP *prop_op = (OP *) mp->mad_val; |
1695
|
|
|
|
|
|
/* We only need "Relocate sv to the pad for thread safety.", but this |
1696
|
|
|
|
|
|
easiest way to make sure it traverses everything */ |
1697
|
|
|
|
|
|
if (prop_op->op_type == OP_CONST) |
1698
|
|
|
|
|
|
cSVOPx(prop_op)->op_private &= ~OPpCONST_STRICT; |
1699
|
|
|
|
|
|
finalize_op(prop_op); |
1700
|
|
|
|
|
|
} |
1701
|
|
|
|
|
|
mp = mp->mad_next; |
1702
|
|
|
|
|
|
} |
1703
|
|
|
|
|
|
} |
1704
|
|
|
|
|
|
#endif |
1705
|
|
|
|
|
|
|
1706
|
745257967
|
|
|
|
|
switch (o->op_type) { |
1707
|
|
|
|
|
|
case OP_NEXTSTATE: |
1708
|
|
|
|
|
|
case OP_DBSTATE: |
1709
|
74201719
|
|
|
|
|
PL_curcop = ((COP*)o); /* for warnings */ |
1710
|
74201719
|
|
|
|
|
break; |
1711
|
|
|
|
|
|
case OP_EXEC: |
1712
|
7750
|
100
|
|
|
|
if ( o->op_sibling |
1713
|
798
|
100
|
|
|
|
&& (o->op_sibling->op_type == OP_NEXTSTATE || o->op_sibling->op_type == OP_DBSTATE) |
1714
|
4
|
50
|
|
|
|
&& ckWARN(WARN_EXEC)) |
1715
|
|
|
|
|
|
{ |
1716
|
4
|
50
|
|
|
|
if (o->op_sibling->op_sibling) { |
1717
|
4
|
|
|
|
|
const OPCODE type = o->op_sibling->op_sibling->op_type; |
1718
|
4
|
50
|
|
|
|
if (type != OP_EXIT && type != OP_WARN && type != OP_DIE) { |
|
|
50
|
|
|
|
|
1719
|
4
|
|
|
|
|
const line_t oldline = CopLINE(PL_curcop); |
1720
|
4
|
|
|
|
|
CopLINE_set(PL_curcop, CopLINE((COP*)o->op_sibling)); |
1721
|
4
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_EXEC), |
1722
|
|
|
|
|
|
"Statement unlikely to be reached"); |
1723
|
4
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_EXEC), |
1724
|
|
|
|
|
|
"\t(Maybe you meant system() when you said exec()?)\n"); |
1725
|
4
|
|
|
|
|
CopLINE_set(PL_curcop, oldline); |
1726
|
|
|
|
|
|
} |
1727
|
|
|
|
|
|
} |
1728
|
|
|
|
|
|
} |
1729
|
|
|
|
|
|
break; |
1730
|
|
|
|
|
|
|
1731
|
|
|
|
|
|
case OP_GV: |
1732
|
23462091
|
100
|
|
|
|
if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_PROTOTYPE)) { |
|
|
100
|
|
|
|
|
1733
|
671698
|
|
|
|
|
GV * const gv = cGVOPo_gv; |
1734
|
671698
|
50
|
|
|
|
if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX_const(GvCV(gv))) { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
1735
|
|
|
|
|
|
/* XXX could check prototype here instead of just carping */ |
1736
|
2
|
|
|
|
|
SV * const sv = sv_newmortal(); |
1737
|
2
|
|
|
|
|
gv_efullname3(sv, gv, NULL); |
1738
|
2
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_PROTOTYPE), |
1739
|
|
|
|
|
|
"%"SVf"() called too early to check prototype", |
1740
|
|
|
|
|
|
SVfARG(sv)); |
1741
|
|
|
|
|
|
} |
1742
|
|
|
|
|
|
} |
1743
|
|
|
|
|
|
break; |
1744
|
|
|
|
|
|
|
1745
|
|
|
|
|
|
case OP_CONST: |
1746
|
97353418
|
100
|
|
|
|
if (cSVOPo->op_private & OPpCONST_STRICT) |
1747
|
48
|
|
|
|
|
no_bareword_allowed(o); |
1748
|
|
|
|
|
|
/* FALLTHROUGH */ |
1749
|
|
|
|
|
|
#ifdef USE_ITHREADS |
1750
|
|
|
|
|
|
case OP_HINTSEVAL: |
1751
|
|
|
|
|
|
case OP_METHOD_NAMED: |
1752
|
|
|
|
|
|
/* Relocate sv to the pad for thread safety. |
1753
|
|
|
|
|
|
* Despite being a "constant", the SV is written to, |
1754
|
|
|
|
|
|
* for reference counts, sv_upgrade() etc. */ |
1755
|
|
|
|
|
|
if (cSVOPo->op_sv) { |
1756
|
|
|
|
|
|
const PADOFFSET ix = pad_alloc(OP_CONST, SVf_READONLY); |
1757
|
|
|
|
|
|
if (o->op_type != OP_METHOD_NAMED |
1758
|
|
|
|
|
|
&& cSVOPo->op_sv == &PL_sv_undef) { |
1759
|
|
|
|
|
|
/* PL_sv_undef is hack - it's unsafe to store it in the |
1760
|
|
|
|
|
|
AV that is the pad, because av_fetch treats values of |
1761
|
|
|
|
|
|
PL_sv_undef as a "free" AV entry and will merrily |
1762
|
|
|
|
|
|
replace them with a new SV, causing pad_alloc to think |
1763
|
|
|
|
|
|
that this pad slot is free. (When, clearly, it is not) |
1764
|
|
|
|
|
|
*/ |
1765
|
|
|
|
|
|
SvOK_off(PAD_SVl(ix)); |
1766
|
|
|
|
|
|
SvPADTMP_on(PAD_SVl(ix)); |
1767
|
|
|
|
|
|
SvREADONLY_on(PAD_SVl(ix)); |
1768
|
|
|
|
|
|
} |
1769
|
|
|
|
|
|
else { |
1770
|
|
|
|
|
|
SvREFCNT_dec(PAD_SVl(ix)); |
1771
|
|
|
|
|
|
PAD_SETSV(ix, cSVOPo->op_sv); |
1772
|
|
|
|
|
|
/* XXX I don't know how this isn't readonly already. */ |
1773
|
|
|
|
|
|
if (!SvIsCOW(PAD_SVl(ix))) SvREADONLY_on(PAD_SVl(ix)); |
1774
|
|
|
|
|
|
} |
1775
|
|
|
|
|
|
cSVOPo->op_sv = NULL; |
1776
|
|
|
|
|
|
o->op_targ = ix; |
1777
|
|
|
|
|
|
} |
1778
|
|
|
|
|
|
#endif |
1779
|
|
|
|
|
|
break; |
1780
|
|
|
|
|
|
|
1781
|
|
|
|
|
|
case OP_HELEM: { |
1782
|
|
|
|
|
|
UNOP *rop; |
1783
|
|
|
|
|
|
SV *lexname; |
1784
|
|
|
|
|
|
GV **fields; |
1785
|
|
|
|
|
|
SV **svp, *sv; |
1786
|
|
|
|
|
|
const char *key = NULL; |
1787
|
|
|
|
|
|
STRLEN keylen; |
1788
|
|
|
|
|
|
|
1789
|
11411345
|
100
|
|
|
|
if (((BINOP*)o)->op_last->op_type != OP_CONST) |
1790
|
|
|
|
|
|
break; |
1791
|
|
|
|
|
|
|
1792
|
|
|
|
|
|
/* Make the CONST have a shared SV */ |
1793
|
8433099
|
|
|
|
|
svp = cSVOPx_svp(((BINOP*)o)->op_last); |
1794
|
8433099
|
100
|
|
|
|
if ((!SvIsCOW_shared_hash(sv = *svp)) |
|
|
100
|
|
|
|
|
1795
|
8432559
|
100
|
|
|
|
&& SvTYPE(sv) < SVt_PVMG && SvOK(sv) && !SvROK(sv)) { |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
1796
|
8432549
|
100
|
|
|
|
key = SvPV_const(sv, keylen); |
1797
|
8432549
|
100
|
|
|
|
lexname = newSVpvn_share(key, |
1798
|
|
|
|
|
|
SvUTF8(sv) ? -(I32)keylen : (I32)keylen, |
1799
|
|
|
|
|
|
0); |
1800
|
8432549
|
|
|
|
|
SvREFCNT_dec_NN(sv); |
1801
|
8432549
|
|
|
|
|
*svp = lexname; |
1802
|
|
|
|
|
|
} |
1803
|
|
|
|
|
|
|
1804
|
8433099
|
100
|
|
|
|
if ((o->op_private & (OPpLVAL_INTRO))) |
1805
|
|
|
|
|
|
break; |
1806
|
|
|
|
|
|
|
1807
|
8153282
|
|
|
|
|
rop = (UNOP*)((BINOP*)o)->op_first; |
1808
|
8153282
|
100
|
|
|
|
if (rop->op_type != OP_RV2HV || rop->op_first->op_type != OP_PADSV) |
|
|
100
|
|
|
|
|
1809
|
|
|
|
|
|
break; |
1810
|
4786714
|
|
|
|
|
lexname = *av_fetch(PL_comppad_name, rop->op_first->op_targ, TRUE); |
1811
|
4786714
|
100
|
|
|
|
if (!SvPAD_TYPED(lexname)) |
1812
|
|
|
|
|
|
break; |
1813
|
62
|
|
|
|
|
fields = (GV**)hv_fetchs(SvSTASH(lexname), "FIELDS", FALSE); |
1814
|
62
|
50
|
|
|
|
if (!fields || !GvHV(*fields)) |
|
|
50
|
|
|
|
|
1815
|
|
|
|
|
|
break; |
1816
|
62
|
50
|
|
|
|
key = SvPV_const(*svp, keylen); |
1817
|
62
|
100
|
|
|
|
if (!hv_fetch(GvHV(*fields), key, |
|
|
100
|
|
|
|
|
1818
|
|
|
|
|
|
SvUTF8(*svp) ? -(I32)keylen : (I32)keylen, FALSE)) { |
1819
|
25
|
50
|
|
|
|
Perl_croak(aTHX_ "No such class field \"%"SVf"\" " |
|
|
50
|
|
|
|
|
1820
|
|
|
|
|
|
"in variable %"SVf" of type %"HEKf, |
1821
|
|
|
|
|
|
SVfARG(*svp), SVfARG(lexname), |
1822
|
20
|
50
|
|
|
|
HEKfARG(HvNAME_HEK(SvSTASH(lexname)))); |
1823
|
|
|
|
|
|
} |
1824
|
|
|
|
|
|
break; |
1825
|
|
|
|
|
|
} |
1826
|
|
|
|
|
|
|
1827
|
|
|
|
|
|
case OP_HSLICE: { |
1828
|
|
|
|
|
|
UNOP *rop; |
1829
|
|
|
|
|
|
SV *lexname; |
1830
|
|
|
|
|
|
GV **fields; |
1831
|
|
|
|
|
|
SV **svp; |
1832
|
|
|
|
|
|
const char *key; |
1833
|
|
|
|
|
|
STRLEN keylen; |
1834
|
|
|
|
|
|
SVOP *first_key_op, *key_op; |
1835
|
|
|
|
|
|
|
1836
|
233429
|
100
|
|
|
|
if ((o->op_private & (OPpLVAL_INTRO)) |
1837
|
|
|
|
|
|
/* I bet there's always a pushmark... */ |
1838
|
193327
|
100
|
|
|
|
|| ((LISTOP*)o)->op_first->op_sibling->op_type != OP_LIST) |
1839
|
|
|
|
|
|
/* hmmm, no optimization if list contains only one key. */ |
1840
|
|
|
|
|
|
break; |
1841
|
108477
|
|
|
|
|
rop = (UNOP*)((LISTOP*)o)->op_last; |
1842
|
108477
|
100
|
|
|
|
if (rop->op_type != OP_RV2HV) |
1843
|
|
|
|
|
|
break; |
1844
|
75318
|
100
|
|
|
|
if (rop->op_first->op_type == OP_PADSV) |
1845
|
|
|
|
|
|
/* @$hash{qw(keys here)} */ |
1846
|
31588
|
|
|
|
|
rop = (UNOP*)rop->op_first; |
1847
|
|
|
|
|
|
else { |
1848
|
|
|
|
|
|
/* @{$hash}{qw(keys here)} */ |
1849
|
43730
|
100
|
|
|
|
if (rop->op_first->op_type == OP_SCOPE |
1850
|
29600
|
100
|
|
|
|
&& cLISTOPx(rop->op_first)->op_last->op_type == OP_PADSV) |
1851
|
|
|
|
|
|
{ |
1852
|
27972
|
|
|
|
|
rop = (UNOP*)cLISTOPx(rop->op_first)->op_last; |
1853
|
|
|
|
|
|
} |
1854
|
|
|
|
|
|
else |
1855
|
|
|
|
|
|
break; |
1856
|
|
|
|
|
|
} |
1857
|
|
|
|
|
|
|
1858
|
59560
|
|
|
|
|
lexname = *av_fetch(PL_comppad_name, rop->op_targ, TRUE); |
1859
|
59560
|
100
|
|
|
|
if (!SvPAD_TYPED(lexname)) |
1860
|
|
|
|
|
|
break; |
1861
|
12
|
|
|
|
|
fields = (GV**)hv_fetchs(SvSTASH(lexname), "FIELDS", FALSE); |
1862
|
12
|
50
|
|
|
|
if (!fields || !GvHV(*fields)) |
|
|
50
|
|
|
|
|
1863
|
|
|
|
|
|
break; |
1864
|
|
|
|
|
|
/* Again guessing that the pushmark can be jumped over.... */ |
1865
|
24
|
|
|
|
|
first_key_op = (SVOP*)((LISTOP*)((LISTOP*)o)->op_first->op_sibling) |
1866
|
12
|
|
|
|
|
->op_first->op_sibling; |
1867
|
42
|
100
|
|
|
|
for (key_op = first_key_op; key_op; |
1868
|
24
|
|
|
|
|
key_op = (SVOP*)key_op->op_sibling) { |
1869
|
28
|
100
|
|
|
|
if (key_op->op_type != OP_CONST) |
1870
|
2
|
|
|
|
|
continue; |
1871
|
|
|
|
|
|
svp = cSVOPx_svp(key_op); |
1872
|
26
|
50
|
|
|
|
key = SvPV_const(*svp, keylen); |
1873
|
26
|
50
|
|
|
|
if (!hv_fetch(GvHV(*fields), key, |
|
|
100
|
|
|
|
|
1874
|
|
|
|
|
|
SvUTF8(*svp) ? -(I32)keylen : (I32)keylen, FALSE)) { |
1875
|
10
|
50
|
|
|
|
Perl_croak(aTHX_ "No such class field \"%"SVf"\" " |
|
|
50
|
|
|
|
|
1876
|
|
|
|
|
|
"in variable %"SVf" of type %"HEKf, |
1877
|
|
|
|
|
|
SVfARG(*svp), SVfARG(lexname), |
1878
|
8
|
50
|
|
|
|
HEKfARG(HvNAME_HEK(SvSTASH(lexname)))); |
1879
|
|
|
|
|
|
} |
1880
|
|
|
|
|
|
} |
1881
|
|
|
|
|
|
break; |
1882
|
|
|
|
|
|
} |
1883
|
|
|
|
|
|
|
1884
|
|
|
|
|
|
case OP_SUBST: { |
1885
|
1215765
|
100
|
|
|
|
if (cPMOPo->op_pmreplrootu.op_pmreplroot) |
1886
|
298025
|
|
|
|
|
finalize_op(cPMOPo->op_pmreplrootu.op_pmreplroot); |
1887
|
|
|
|
|
|
break; |
1888
|
|
|
|
|
|
} |
1889
|
|
|
|
|
|
default: |
1890
|
|
|
|
|
|
break; |
1891
|
|
|
|
|
|
} |
1892
|
|
|
|
|
|
|
1893
|
745257953
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
1894
|
|
|
|
|
|
OP *kid; |
1895
|
1062750824
|
100
|
|
|
|
for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) |
1896
|
728272764
|
|
|
|
|
finalize_op(kid); |
1897
|
|
|
|
|
|
} |
1898
|
745257915
|
|
|
|
|
} |
1899
|
|
|
|
|
|
|
1900
|
|
|
|
|
|
/* |
1901
|
|
|
|
|
|
=for apidoc Amx|OP *|op_lvalue|OP *o|I32 type |
1902
|
|
|
|
|
|
|
1903
|
|
|
|
|
|
Propagate lvalue ("modifiable") context to an op and its children. |
1904
|
|
|
|
|
|
I represents the context type, roughly based on the type of op that |
1905
|
|
|
|
|
|
would do the modifying, although C is represented by OP_NULL, |
1906
|
|
|
|
|
|
because it has no op type of its own (it is signalled by a flag on |
1907
|
|
|
|
|
|
the lvalue op). |
1908
|
|
|
|
|
|
|
1909
|
|
|
|
|
|
This function detects things that can't be modified, such as C<$x+1>, and |
1910
|
|
|
|
|
|
generates errors for them. For example, C<$x+1 = 2> would cause it to be |
1911
|
|
|
|
|
|
called with an op of type OP_ADD and a C argument of OP_SASSIGN. |
1912
|
|
|
|
|
|
|
1913
|
|
|
|
|
|
It also flags things that need to behave specially in an lvalue context, |
1914
|
|
|
|
|
|
such as C<$$x = 5> which might have to vivify a reference in C<$x>. |
1915
|
|
|
|
|
|
|
1916
|
|
|
|
|
|
=cut |
1917
|
|
|
|
|
|
*/ |
1918
|
|
|
|
|
|
|
1919
|
|
|
|
|
|
OP * |
1920
|
105835903
|
|
|
|
|
Perl_op_lvalue_flags(pTHX_ OP *o, I32 type, U32 flags) |
1921
|
|
|
|
|
|
{ |
1922
|
|
|
|
|
|
dVAR; |
1923
|
|
|
|
|
|
OP *kid; |
1924
|
|
|
|
|
|
/* -1 = error on localize, 0 = ignore localize, 1 = ok to localize */ |
1925
|
|
|
|
|
|
int localize = -1; |
1926
|
|
|
|
|
|
|
1927
|
105835903
|
100
|
|
|
|
if (!o || (PL_parser && PL_parser->error_count)) |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
1928
|
|
|
|
|
|
return o; |
1929
|
|
|
|
|
|
|
1930
|
105817841
|
100
|
|
|
|
if ((o->op_private & OPpTARGET_MY) |
1931
|
704414
|
100
|
|
|
|
&& (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */ |
1932
|
|
|
|
|
|
{ |
1933
|
|
|
|
|
|
return o; |
1934
|
|
|
|
|
|
} |
1935
|
|
|
|
|
|
|
1936
|
|
|
|
|
|
assert( (o->op_flags & OPf_WANT) != OPf_WANT_VOID ); |
1937
|
|
|
|
|
|
|
1938
|
105817525
|
100
|
|
|
|
if (type == OP_PRTF || type == OP_SPRINTF) type = OP_ENTERSUB; |
1939
|
|
|
|
|
|
|
1940
|
105817525
|
|
|
|
|
switch (o->op_type) { |
1941
|
|
|
|
|
|
case OP_UNDEF: |
1942
|
177361
|
|
|
|
|
PL_modcount++; |
1943
|
177361
|
|
|
|
|
return o; |
1944
|
|
|
|
|
|
case OP_STUB: |
1945
|
48382
|
100
|
|
|
|
if ((o->op_flags & OPf_PARENS) || PL_madskills) |
1946
|
|
|
|
|
|
break; |
1947
|
|
|
|
|
|
goto nomod; |
1948
|
|
|
|
|
|
case OP_ENTERSUB: |
1949
|
5581257
|
100
|
|
|
|
if ((type == OP_UNDEF || type == OP_REFGEN || type == OP_LOCK) && |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
1950
|
1403324
|
|
|
|
|
!(o->op_flags & OPf_STACKED)) { |
1951
|
1403248
|
|
|
|
|
o->op_type = OP_RV2CV; /* entersub => rv2cv */ |
1952
|
|
|
|
|
|
/* Both ENTERSUB and RV2CV use this bit, but for different pur- |
1953
|
|
|
|
|
|
poses, so we need it clear. */ |
1954
|
1403248
|
|
|
|
|
o->op_private &= ~1; |
1955
|
1403248
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_RV2CV]; |
1956
|
|
|
|
|
|
assert(cUNOPo->op_first->op_type == OP_NULL); |
1957
|
1403248
|
|
|
|
|
op_null(((LISTOP*)cUNOPo->op_first)->op_first);/* disable pushmark */ |
1958
|
1403248
|
|
|
|
|
break; |
1959
|
|
|
|
|
|
} |
1960
|
|
|
|
|
|
else { /* lvalue subroutine call */ |
1961
|
3496142
|
100
|
|
|
|
o->op_private |= OPpLVAL_INTRO |
1962
|
|
|
|
|
|
|(OPpENTERSUB_INARGS * (type == OP_LEAVESUBLV)); |
1963
|
3496142
|
|
|
|
|
PL_modcount = RETURN_UNLIMITED_NUMBER; |
1964
|
3496142
|
100
|
|
|
|
if (type == OP_GREPSTART || type == OP_ENTERSUB || type == OP_REFGEN) { |
|
|
100
|
|
|
|
|
1965
|
|
|
|
|
|
/* Potential lvalue context: */ |
1966
|
3495630
|
|
|
|
|
o->op_private |= OPpENTERSUB_INARGS; |
1967
|
3495630
|
|
|
|
|
break; |
1968
|
|
|
|
|
|
} |
1969
|
|
|
|
|
|
else { /* Compile-time error message: */ |
1970
|
512
|
|
|
|
|
OP *kid = cUNOPo->op_first; |
1971
|
|
|
|
|
|
CV *cv; |
1972
|
|
|
|
|
|
|
1973
|
512
|
100
|
|
|
|
if (kid->op_type != OP_PUSHMARK) { |
1974
|
490
|
50
|
|
|
|
if (kid->op_type != OP_NULL || kid->op_targ != OP_LIST) |
|
|
50
|
|
|
|
|
1975
|
0
|
|
|
|
|
Perl_croak(aTHX_ |
1976
|
|
|
|
|
|
"panic: unexpected lvalue entersub " |
1977
|
|
|
|
|
|
"args: type/targ %ld:%"UVuf, |
1978
|
0
|
|
|
|
|
(long)kid->op_type, (UV)kid->op_targ); |
1979
|
501
|
|
|
|
|
kid = kLISTOP->op_first; |
1980
|
|
|
|
|
|
} |
1981
|
1156
|
100
|
|
|
|
while (kid->op_sibling) |
1982
|
644
|
|
|
|
|
kid = kid->op_sibling; |
1983
|
512
|
100
|
|
|
|
if (!(kid->op_type == OP_NULL && kid->op_targ == OP_RV2CV)) { |
|
|
50
|
|
|
|
|
1984
|
|
|
|
|
|
break; /* Postpone until runtime */ |
1985
|
|
|
|
|
|
} |
1986
|
|
|
|
|
|
|
1987
|
490
|
|
|
|
|
kid = kUNOP->op_first; |
1988
|
490
|
50
|
|
|
|
if (kid->op_type == OP_NULL && kid->op_targ == OP_RV2SV) |
|
|
0
|
|
|
|
|
1989
|
0
|
|
|
|
|
kid = kUNOP->op_first; |
1990
|
490
|
50
|
|
|
|
if (kid->op_type == OP_NULL) |
1991
|
0
|
|
|
|
|
Perl_croak(aTHX_ |
1992
|
|
|
|
|
|
"Unexpected constant lvalue entersub " |
1993
|
|
|
|
|
|
"entry via type/targ %ld:%"UVuf, |
1994
|
0
|
|
|
|
|
(long)kid->op_type, (UV)kid->op_targ); |
1995
|
490
|
100
|
|
|
|
if (kid->op_type != OP_GV) { |
1996
|
|
|
|
|
|
break; |
1997
|
|
|
|
|
|
} |
1998
|
|
|
|
|
|
|
1999
|
244
|
|
|
|
|
cv = GvCV(kGVOP_gv); |
2000
|
244
|
100
|
|
|
|
if (!cv) |
2001
|
|
|
|
|
|
break; |
2002
|
226
|
100
|
|
|
|
if (CvLVALUE(cv)) |
2003
|
|
|
|
|
|
break; |
2004
|
|
|
|
|
|
} |
2005
|
|
|
|
|
|
} |
2006
|
|
|
|
|
|
/* FALL THROUGH */ |
2007
|
|
|
|
|
|
default: |
2008
|
|
|
|
|
|
nomod: |
2009
|
22265383
|
100
|
|
|
|
if (flags & OP_LVALUE_NO_CROAK) return NULL; |
2010
|
|
|
|
|
|
/* grep, foreach, subcalls, refgen */ |
2011
|
22265375
|
100
|
|
|
|
if (type == OP_GREPSTART || type == OP_ENTERSUB |
2012
|
2093401
|
100
|
|
|
|
|| type == OP_REFGEN || type == OP_LEAVESUBLV) |
2013
|
|
|
|
|
|
break; |
2014
|
66
|
50
|
|
|
|
yyerror(Perl_form(aTHX_ "Can't modify %s in %s", |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
2015
|
|
|
|
|
|
(o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL) |
2016
|
|
|
|
|
|
? "do block" |
2017
|
|
|
|
|
|
: (o->op_type == OP_ENTERSUB |
2018
|
|
|
|
|
|
? "non-lvalue subroutine call" |
2019
|
|
|
|
|
|
: OP_DESC(o))), |
2020
|
|
|
|
|
|
type ? PL_op_desc[type] : "local")); |
2021
|
66
|
|
|
|
|
return o; |
2022
|
|
|
|
|
|
|
2023
|
|
|
|
|
|
case OP_PREINC: |
2024
|
|
|
|
|
|
case OP_PREDEC: |
2025
|
|
|
|
|
|
case OP_POW: |
2026
|
|
|
|
|
|
case OP_MULTIPLY: |
2027
|
|
|
|
|
|
case OP_DIVIDE: |
2028
|
|
|
|
|
|
case OP_MODULO: |
2029
|
|
|
|
|
|
case OP_REPEAT: |
2030
|
|
|
|
|
|
case OP_ADD: |
2031
|
|
|
|
|
|
case OP_SUBTRACT: |
2032
|
|
|
|
|
|
case OP_CONCAT: |
2033
|
|
|
|
|
|
case OP_LEFT_SHIFT: |
2034
|
|
|
|
|
|
case OP_RIGHT_SHIFT: |
2035
|
|
|
|
|
|
case OP_BIT_AND: |
2036
|
|
|
|
|
|
case OP_BIT_XOR: |
2037
|
|
|
|
|
|
case OP_BIT_OR: |
2038
|
|
|
|
|
|
case OP_I_MULTIPLY: |
2039
|
|
|
|
|
|
case OP_I_DIVIDE: |
2040
|
|
|
|
|
|
case OP_I_MODULO: |
2041
|
|
|
|
|
|
case OP_I_ADD: |
2042
|
|
|
|
|
|
case OP_I_SUBTRACT: |
2043
|
372560
|
100
|
|
|
|
if (!(o->op_flags & OPf_STACKED)) |
2044
|
|
|
|
|
|
goto nomod; |
2045
|
64760
|
|
|
|
|
PL_modcount++; |
2046
|
64760
|
|
|
|
|
break; |
2047
|
|
|
|
|
|
|
2048
|
|
|
|
|
|
case OP_COND_EXPR: |
2049
|
|
|
|
|
|
localize = 1; |
2050
|
614538
|
100
|
|
|
|
for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling) |
2051
|
409692
|
|
|
|
|
op_lvalue(kid, type); |
2052
|
|
|
|
|
|
break; |
2053
|
|
|
|
|
|
|
2054
|
|
|
|
|
|
case OP_RV2AV: |
2055
|
|
|
|
|
|
case OP_RV2HV: |
2056
|
5409725
|
100
|
|
|
|
if (type == OP_REFGEN && o->op_flags & OPf_PARENS) { |
|
|
100
|
|
|
|
|
2057
|
8
|
|
|
|
|
PL_modcount = RETURN_UNLIMITED_NUMBER; |
2058
|
8
|
|
|
|
|
return o; /* Treat \(@foo) like ordinary list. */ |
2059
|
|
|
|
|
|
} |
2060
|
|
|
|
|
|
/* FALL THROUGH */ |
2061
|
|
|
|
|
|
case OP_RV2GV: |
2062
|
6576689
|
100
|
|
|
|
if (scalar_mod_type(o, type)) |
2063
|
|
|
|
|
|
goto nomod; |
2064
|
6576671
|
|
|
|
|
ref(cUNOPo->op_first, o->op_type); |
2065
|
|
|
|
|
|
/* FALL THROUGH */ |
2066
|
|
|
|
|
|
case OP_ASLICE: |
2067
|
|
|
|
|
|
case OP_HSLICE: |
2068
|
|
|
|
|
|
localize = 1; |
2069
|
|
|
|
|
|
/* FALL THROUGH */ |
2070
|
|
|
|
|
|
case OP_AASSIGN: |
2071
|
6796198
|
100
|
|
|
|
if (type == OP_LEAVESUBLV) |
2072
|
32
|
|
|
|
|
o->op_private |= OPpMAYBE_LVSUB; |
2073
|
|
|
|
|
|
/* FALL THROUGH */ |
2074
|
|
|
|
|
|
case OP_NEXTSTATE: |
2075
|
|
|
|
|
|
case OP_DBSTATE: |
2076
|
6796202
|
|
|
|
|
PL_modcount = RETURN_UNLIMITED_NUMBER; |
2077
|
6796202
|
|
|
|
|
break; |
2078
|
|
|
|
|
|
case OP_AV2ARYLEN: |
2079
|
15546
|
|
|
|
|
PL_hints |= HINT_BLOCK_SCOPE; |
2080
|
15546
|
100
|
|
|
|
if (type == OP_LEAVESUBLV) |
2081
|
2
|
|
|
|
|
o->op_private |= OPpMAYBE_LVSUB; |
2082
|
15546
|
|
|
|
|
PL_modcount++; |
2083
|
15546
|
|
|
|
|
break; |
2084
|
|
|
|
|
|
case OP_RV2SV: |
2085
|
4228017
|
|
|
|
|
ref(cUNOPo->op_first, o->op_type); |
2086
|
|
|
|
|
|
localize = 1; |
2087
|
|
|
|
|
|
/* FALL THROUGH */ |
2088
|
|
|
|
|
|
case OP_GV: |
2089
|
4228021
|
|
|
|
|
PL_hints |= HINT_BLOCK_SCOPE; |
2090
|
|
|
|
|
|
case OP_SASSIGN: |
2091
|
|
|
|
|
|
case OP_ANDASSIGN: |
2092
|
|
|
|
|
|
case OP_ORASSIGN: |
2093
|
|
|
|
|
|
case OP_DORASSIGN: |
2094
|
4387864
|
|
|
|
|
PL_modcount++; |
2095
|
4387864
|
|
|
|
|
break; |
2096
|
|
|
|
|
|
|
2097
|
|
|
|
|
|
case OP_AELEMFAST: |
2098
|
|
|
|
|
|
case OP_AELEMFAST_LEX: |
2099
|
|
|
|
|
|
localize = -1; |
2100
|
0
|
|
|
|
|
PL_modcount++; |
2101
|
0
|
|
|
|
|
break; |
2102
|
|
|
|
|
|
|
2103
|
|
|
|
|
|
case OP_PADAV: |
2104
|
|
|
|
|
|
case OP_PADHV: |
2105
|
4048874
|
|
|
|
|
PL_modcount = RETURN_UNLIMITED_NUMBER; |
2106
|
4048874
|
100
|
|
|
|
if (type == OP_REFGEN && o->op_flags & OPf_PARENS) |
|
|
100
|
|
|
|
|
2107
|
|
|
|
|
|
return o; /* Treat \(@foo) like ordinary list. */ |
2108
|
4048858
|
100
|
|
|
|
if (scalar_mod_type(o, type)) |
2109
|
|
|
|
|
|
goto nomod; |
2110
|
4048852
|
100
|
|
|
|
if (type == OP_LEAVESUBLV) |
2111
|
16
|
|
|
|
|
o->op_private |= OPpMAYBE_LVSUB; |
2112
|
|
|
|
|
|
/* FALL THROUGH */ |
2113
|
|
|
|
|
|
case OP_PADSV: |
2114
|
46337798
|
|
|
|
|
PL_modcount++; |
2115
|
46337798
|
100
|
|
|
|
if (!type) /* local() */ |
2116
|
4
|
|
|
|
|
Perl_croak(aTHX_ "Can't localize lexical variable %"SVf, |
2117
|
4
|
|
|
|
|
PAD_COMPNAME_SV(o->op_targ)); |
2118
|
|
|
|
|
|
break; |
2119
|
|
|
|
|
|
|
2120
|
|
|
|
|
|
case OP_PUSHMARK: |
2121
|
|
|
|
|
|
localize = 0; |
2122
|
|
|
|
|
|
break; |
2123
|
|
|
|
|
|
|
2124
|
|
|
|
|
|
case OP_KEYS: |
2125
|
|
|
|
|
|
case OP_RKEYS: |
2126
|
228925
|
100
|
|
|
|
if (type != OP_SASSIGN && type != OP_LEAVESUBLV) |
2127
|
|
|
|
|
|
goto nomod; |
2128
|
|
|
|
|
|
goto lvalue_func; |
2129
|
|
|
|
|
|
case OP_SUBSTR: |
2130
|
80511
|
100
|
|
|
|
if (o->op_private == 4) /* don't allow 4 arg substr as lvalue */ |
2131
|
|
|
|
|
|
goto nomod; |
2132
|
|
|
|
|
|
/* FALL THROUGH */ |
2133
|
|
|
|
|
|
case OP_POS: |
2134
|
|
|
|
|
|
case OP_VEC: |
2135
|
|
|
|
|
|
lvalue_func: |
2136
|
231733
|
100
|
|
|
|
if (type == OP_LEAVESUBLV) |
2137
|
24
|
|
|
|
|
o->op_private |= OPpMAYBE_LVSUB; |
2138
|
231733
|
50
|
|
|
|
if (o->op_flags & OPf_KIDS) |
2139
|
231733
|
|
|
|
|
op_lvalue(cBINOPo->op_first->op_sibling, type); |
2140
|
|
|
|
|
|
break; |
2141
|
|
|
|
|
|
|
2142
|
|
|
|
|
|
case OP_AELEM: |
2143
|
|
|
|
|
|
case OP_HELEM: |
2144
|
5524151
|
|
|
|
|
ref(cBINOPo->op_first, o->op_type); |
2145
|
6068677
|
100
|
|
|
|
if (type == OP_ENTERSUB && |
|
|
50
|
|
|
|
|
2146
|
1154210
|
|
|
|
|
!(o->op_private & (OPpLVAL_INTRO | OPpDEREF))) |
2147
|
1154210
|
|
|
|
|
o->op_private |= OPpLVAL_DEFER; |
2148
|
5524151
|
100
|
|
|
|
if (type == OP_LEAVESUBLV) |
2149
|
5358
|
|
|
|
|
o->op_private |= OPpMAYBE_LVSUB; |
2150
|
|
|
|
|
|
localize = 1; |
2151
|
5524151
|
|
|
|
|
PL_modcount++; |
2152
|
5524151
|
|
|
|
|
break; |
2153
|
|
|
|
|
|
|
2154
|
|
|
|
|
|
case OP_SCOPE: |
2155
|
|
|
|
|
|
case OP_LEAVE: |
2156
|
|
|
|
|
|
case OP_ENTER: |
2157
|
|
|
|
|
|
case OP_LINESEQ: |
2158
|
|
|
|
|
|
localize = 0; |
2159
|
5882
|
50
|
|
|
|
if (o->op_flags & OPf_KIDS) |
2160
|
5882
|
|
|
|
|
op_lvalue(cLISTOPo->op_last, type); |
2161
|
|
|
|
|
|
break; |
2162
|
|
|
|
|
|
|
2163
|
|
|
|
|
|
case OP_NULL: |
2164
|
|
|
|
|
|
localize = 0; |
2165
|
4559285
|
100
|
|
|
|
if (o->op_flags & OPf_SPECIAL) /* do BLOCK */ |
2166
|
|
|
|
|
|
goto nomod; |
2167
|
4555479
|
100
|
|
|
|
else if (!(o->op_flags & OPf_KIDS)) |
2168
|
|
|
|
|
|
break; |
2169
|
4555475
|
100
|
|
|
|
if (o->op_targ != OP_LIST) { |
2170
|
286506
|
|
|
|
|
op_lvalue(cBINOPo->op_first, type); |
2171
|
286506
|
|
|
|
|
break; |
2172
|
|
|
|
|
|
} |
2173
|
|
|
|
|
|
/* FALL THROUGH */ |
2174
|
|
|
|
|
|
case OP_LIST: |
2175
|
|
|
|
|
|
localize = 0; |
2176
|
25720168
|
100
|
|
|
|
for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) |
2177
|
|
|
|
|
|
/* elements might be in void context because the list is |
2178
|
|
|
|
|
|
in scalar context or because they are attribute sub calls */ |
2179
|
18754912
|
100
|
|
|
|
if ( (kid->op_flags & OPf_WANT) != OPf_WANT_VOID ) |
2180
|
18754862
|
|
|
|
|
op_lvalue(kid, type); |
2181
|
|
|
|
|
|
break; |
2182
|
|
|
|
|
|
|
2183
|
|
|
|
|
|
case OP_RETURN: |
2184
|
40
|
50
|
|
|
|
if (type != OP_LEAVESUBLV) |
2185
|
|
|
|
|
|
goto nomod; |
2186
|
|
|
|
|
|
break; /* op_lvalue()ing was handled by ck_return() */ |
2187
|
|
|
|
|
|
|
2188
|
|
|
|
|
|
case OP_COREARGS: |
2189
|
|
|
|
|
|
return o; |
2190
|
|
|
|
|
|
} |
2191
|
|
|
|
|
|
|
2192
|
|
|
|
|
|
/* [20011101.069] File test operators interpret OPf_REF to mean that |
2193
|
|
|
|
|
|
their argument is a filehandle; thus \stat(".") should not set |
2194
|
|
|
|
|
|
it. AMS 20011102 */ |
2195
|
110927459
|
100
|
|
|
|
if (type == OP_REFGEN && |
|
|
100
|
|
|
|
|
2196
|
10941604
|
|
|
|
|
PL_check[o->op_type] == Perl_ck_ftst) |
2197
|
|
|
|
|
|
return o; |
2198
|
|
|
|
|
|
|
2199
|
105640042
|
100
|
|
|
|
if (type != OP_LEAVESUBLV) |
2200
|
105627600
|
|
|
|
|
o->op_flags |= OPf_MOD; |
2201
|
|
|
|
|
|
|
2202
|
105640042
|
100
|
|
|
|
if (type == OP_AASSIGN || type == OP_SASSIGN) |
2203
|
34739817
|
|
|
|
|
o->op_flags |= OPf_SPECIAL|OPf_REF; |
2204
|
70900225
|
100
|
|
|
|
else if (!type) { /* local() */ |
2205
|
1326589
|
|
|
|
|
switch (localize) { |
2206
|
|
|
|
|
|
case 1: |
2207
|
1150045
|
|
|
|
|
o->op_private |= OPpLVAL_INTRO; |
2208
|
1150045
|
|
|
|
|
o->op_flags &= ~OPf_SPECIAL; |
2209
|
1150045
|
|
|
|
|
PL_hints |= HINT_BLOCK_SCOPE; |
2210
|
1150045
|
|
|
|
|
break; |
2211
|
|
|
|
|
|
case 0: |
2212
|
|
|
|
|
|
break; |
2213
|
|
|
|
|
|
case -1: |
2214
|
84
|
50
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), |
2215
|
28
|
0
|
|
|
|
"Useless localization of %s", OP_DESC(o)); |
2216
|
|
|
|
|
|
} |
2217
|
|
|
|
|
|
} |
2218
|
69573636
|
100
|
|
|
|
else if (type != OP_GREPSTART && type != OP_ENTERSUB |
2219
|
18848660
|
100
|
|
|
|
&& type != OP_LEAVESUBLV) |
2220
|
63607081
|
|
|
|
|
o->op_flags |= OPf_REF; |
2221
|
|
|
|
|
|
return o; |
2222
|
|
|
|
|
|
} |
2223
|
|
|
|
|
|
|
2224
|
|
|
|
|
|
STATIC bool |
2225
|
10635877
|
|
|
|
|
S_scalar_mod_type(const OP *o, I32 type) |
2226
|
|
|
|
|
|
{ |
2227
|
10635877
|
|
|
|
|
switch (type) { |
2228
|
|
|
|
|
|
case OP_POS: |
2229
|
|
|
|
|
|
case OP_SASSIGN: |
2230
|
854835
|
100
|
|
|
|
if (o && o->op_type == OP_RV2GV) |
|
|
100
|
|
|
|
|
2231
|
|
|
|
|
|
return FALSE; |
2232
|
|
|
|
|
|
/* FALL THROUGH */ |
2233
|
|
|
|
|
|
case OP_PREINC: |
2234
|
|
|
|
|
|
case OP_PREDEC: |
2235
|
|
|
|
|
|
case OP_POSTINC: |
2236
|
|
|
|
|
|
case OP_POSTDEC: |
2237
|
|
|
|
|
|
case OP_I_PREINC: |
2238
|
|
|
|
|
|
case OP_I_PREDEC: |
2239
|
|
|
|
|
|
case OP_I_POSTINC: |
2240
|
|
|
|
|
|
case OP_I_POSTDEC: |
2241
|
|
|
|
|
|
case OP_POW: |
2242
|
|
|
|
|
|
case OP_MULTIPLY: |
2243
|
|
|
|
|
|
case OP_DIVIDE: |
2244
|
|
|
|
|
|
case OP_MODULO: |
2245
|
|
|
|
|
|
case OP_REPEAT: |
2246
|
|
|
|
|
|
case OP_ADD: |
2247
|
|
|
|
|
|
case OP_SUBTRACT: |
2248
|
|
|
|
|
|
case OP_I_MULTIPLY: |
2249
|
|
|
|
|
|
case OP_I_DIVIDE: |
2250
|
|
|
|
|
|
case OP_I_MODULO: |
2251
|
|
|
|
|
|
case OP_I_ADD: |
2252
|
|
|
|
|
|
case OP_I_SUBTRACT: |
2253
|
|
|
|
|
|
case OP_LEFT_SHIFT: |
2254
|
|
|
|
|
|
case OP_RIGHT_SHIFT: |
2255
|
|
|
|
|
|
case OP_BIT_AND: |
2256
|
|
|
|
|
|
case OP_BIT_XOR: |
2257
|
|
|
|
|
|
case OP_BIT_OR: |
2258
|
|
|
|
|
|
case OP_CONCAT: |
2259
|
|
|
|
|
|
case OP_SUBST: |
2260
|
|
|
|
|
|
case OP_TRANS: |
2261
|
|
|
|
|
|
case OP_TRANSR: |
2262
|
|
|
|
|
|
case OP_READ: |
2263
|
|
|
|
|
|
case OP_SYSREAD: |
2264
|
|
|
|
|
|
case OP_RECV: |
2265
|
|
|
|
|
|
case OP_ANDASSIGN: |
2266
|
|
|
|
|
|
case OP_ORASSIGN: |
2267
|
|
|
|
|
|
case OP_DORASSIGN: |
2268
|
5528744
|
|
|
|
|
return TRUE; |
2269
|
|
|
|
|
|
default: |
2270
|
|
|
|
|
|
return FALSE; |
2271
|
|
|
|
|
|
} |
2272
|
|
|
|
|
|
} |
2273
|
|
|
|
|
|
|
2274
|
|
|
|
|
|
STATIC bool |
2275
|
331388
|
|
|
|
|
S_is_handle_constructor(const OP *o, I32 numargs) |
2276
|
|
|
|
|
|
{ |
2277
|
|
|
|
|
|
PERL_ARGS_ASSERT_IS_HANDLE_CONSTRUCTOR; |
2278
|
|
|
|
|
|
|
2279
|
331388
|
|
|
|
|
switch (o->op_type) { |
2280
|
|
|
|
|
|
case OP_PIPE_OP: |
2281
|
|
|
|
|
|
case OP_SOCKPAIR: |
2282
|
8182
|
100
|
|
|
|
if (numargs == 2) |
2283
|
|
|
|
|
|
return TRUE; |
2284
|
|
|
|
|
|
/* FALL THROUGH */ |
2285
|
|
|
|
|
|
case OP_SYSOPEN: |
2286
|
|
|
|
|
|
case OP_OPEN: |
2287
|
|
|
|
|
|
case OP_SELECT: /* XXX c.f. SelectSaver.pm */ |
2288
|
|
|
|
|
|
case OP_SOCKET: |
2289
|
|
|
|
|
|
case OP_OPEN_DIR: |
2290
|
|
|
|
|
|
case OP_ACCEPT: |
2291
|
129935
|
100
|
|
|
|
if (numargs == 1) |
2292
|
|
|
|
|
|
return TRUE; |
2293
|
|
|
|
|
|
/* FALLTHROUGH */ |
2294
|
|
|
|
|
|
default: |
2295
|
267015
|
|
|
|
|
return FALSE; |
2296
|
|
|
|
|
|
} |
2297
|
|
|
|
|
|
} |
2298
|
|
|
|
|
|
|
2299
|
|
|
|
|
|
static OP * |
2300
|
|
|
|
|
|
S_refkids(pTHX_ OP *o, I32 type) |
2301
|
|
|
|
|
|
{ |
2302
|
2796604
|
50
|
|
|
|
if (o && o->op_flags & OPf_KIDS) { |
|
|
100
|
|
|
|
|
2303
|
|
|
|
|
|
OP *kid; |
2304
|
5593212
|
100
|
|
|
|
for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) |
2305
|
2796610
|
|
|
|
|
ref(kid, type); |
2306
|
|
|
|
|
|
} |
2307
|
|
|
|
|
|
return o; |
2308
|
|
|
|
|
|
} |
2309
|
|
|
|
|
|
|
2310
|
|
|
|
|
|
OP * |
2311
|
78747716
|
|
|
|
|
Perl_doref(pTHX_ OP *o, I32 type, bool set_op_ref) |
2312
|
|
|
|
|
|
{ |
2313
|
|
|
|
|
|
dVAR; |
2314
|
|
|
|
|
|
OP *kid; |
2315
|
|
|
|
|
|
|
2316
|
|
|
|
|
|
PERL_ARGS_ASSERT_DOREF; |
2317
|
|
|
|
|
|
|
2318
|
78747716
|
50
|
|
|
|
if (!o || (PL_parser && PL_parser->error_count)) |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
2319
|
|
|
|
|
|
return o; |
2320
|
|
|
|
|
|
|
2321
|
78747700
|
|
|
|
|
switch (o->op_type) { |
2322
|
|
|
|
|
|
case OP_ENTERSUB: |
2323
|
679792
|
100
|
|
|
|
if ((type == OP_EXISTS || type == OP_DEFINED) && |
|
|
100
|
|
|
|
|
2324
|
382036
|
|
|
|
|
!(o->op_flags & OPf_STACKED)) { |
2325
|
337478
|
|
|
|
|
o->op_type = OP_RV2CV; /* entersub => rv2cv */ |
2326
|
337478
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_RV2CV]; |
2327
|
|
|
|
|
|
assert(cUNOPo->op_first->op_type == OP_NULL); |
2328
|
337478
|
|
|
|
|
op_null(((LISTOP*)cUNOPo->op_first)->op_first); /* disable pushmark */ |
2329
|
337478
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; |
2330
|
337478
|
|
|
|
|
o->op_private &= ~1; |
2331
|
|
|
|
|
|
} |
2332
|
158496
|
100
|
|
|
|
else if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV){ |
|
|
100
|
|
|
|
|
2333
|
107102
|
100
|
|
|
|
o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV |
|
|
100
|
|
|
|
|
2334
|
|
|
|
|
|
: type == OP_RV2HV ? OPpDEREF_HV |
2335
|
|
|
|
|
|
: OPpDEREF_SV); |
2336
|
107102
|
|
|
|
|
o->op_flags |= OPf_MOD; |
2337
|
|
|
|
|
|
} |
2338
|
|
|
|
|
|
|
2339
|
|
|
|
|
|
break; |
2340
|
|
|
|
|
|
|
2341
|
|
|
|
|
|
case OP_COND_EXPR: |
2342
|
1842
|
100
|
|
|
|
for (kid = cUNOPo->op_first->op_sibling; kid; kid = kid->op_sibling) |
2343
|
1228
|
|
|
|
|
doref(kid, type, set_op_ref); |
2344
|
|
|
|
|
|
break; |
2345
|
|
|
|
|
|
case OP_RV2SV: |
2346
|
591736
|
100
|
|
|
|
if (type == OP_DEFINED) |
2347
|
295034
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; /* don't create GV */ |
2348
|
591736
|
|
|
|
|
doref(cUNOPo->op_first, o->op_type, set_op_ref); |
2349
|
|
|
|
|
|
/* FALL THROUGH */ |
2350
|
|
|
|
|
|
case OP_PADSV: |
2351
|
15882668
|
100
|
|
|
|
if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) { |
|
|
100
|
|
|
|
|
2352
|
13172768
|
100
|
|
|
|
o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV |
|
|
100
|
|
|
|
|
2353
|
|
|
|
|
|
: type == OP_RV2HV ? OPpDEREF_HV |
2354
|
|
|
|
|
|
: OPpDEREF_SV); |
2355
|
13172768
|
|
|
|
|
o->op_flags |= OPf_MOD; |
2356
|
|
|
|
|
|
} |
2357
|
|
|
|
|
|
break; |
2358
|
|
|
|
|
|
|
2359
|
|
|
|
|
|
case OP_RV2AV: |
2360
|
|
|
|
|
|
case OP_RV2HV: |
2361
|
27218251
|
100
|
|
|
|
if (set_op_ref) |
2362
|
26597853
|
|
|
|
|
o->op_flags |= OPf_REF; |
2363
|
|
|
|
|
|
/* FALL THROUGH */ |
2364
|
|
|
|
|
|
case OP_RV2GV: |
2365
|
29176098
|
100
|
|
|
|
if (type == OP_DEFINED) |
2366
|
200
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; /* don't create GV */ |
2367
|
29176098
|
|
|
|
|
doref(cUNOPo->op_first, o->op_type, set_op_ref); |
2368
|
29176098
|
|
|
|
|
break; |
2369
|
|
|
|
|
|
|
2370
|
|
|
|
|
|
case OP_PADAV: |
2371
|
|
|
|
|
|
case OP_PADHV: |
2372
|
4693066
|
100
|
|
|
|
if (set_op_ref) |
2373
|
4598440
|
|
|
|
|
o->op_flags |= OPf_REF; |
2374
|
|
|
|
|
|
break; |
2375
|
|
|
|
|
|
|
2376
|
|
|
|
|
|
case OP_SCALAR: |
2377
|
|
|
|
|
|
case OP_NULL: |
2378
|
72304
|
100
|
|
|
|
if (!(o->op_flags & OPf_KIDS) || type == OP_DEFINED) |
2379
|
|
|
|
|
|
break; |
2380
|
23084
|
|
|
|
|
doref(cBINOPo->op_first, type, set_op_ref); |
2381
|
23084
|
|
|
|
|
break; |
2382
|
|
|
|
|
|
case OP_AELEM: |
2383
|
|
|
|
|
|
case OP_HELEM: |
2384
|
7064833
|
|
|
|
|
doref(cBINOPo->op_first, o->op_type, set_op_ref); |
2385
|
7064833
|
100
|
|
|
|
if (type == OP_RV2SV || type == OP_RV2AV || type == OP_RV2HV) { |
|
|
100
|
|
|
|
|
2386
|
6516745
|
100
|
|
|
|
o->op_private |= (type == OP_RV2AV ? OPpDEREF_AV |
|
|
100
|
|
|
|
|
2387
|
|
|
|
|
|
: type == OP_RV2HV ? OPpDEREF_HV |
2388
|
|
|
|
|
|
: OPpDEREF_SV); |
2389
|
7417760
|
|
|
|
|
o->op_flags |= OPf_MOD; |
2390
|
|
|
|
|
|
} |
2391
|
|
|
|
|
|
break; |
2392
|
|
|
|
|
|
|
2393
|
|
|
|
|
|
case OP_SCOPE: |
2394
|
|
|
|
|
|
case OP_LEAVE: |
2395
|
|
|
|
|
|
set_op_ref = FALSE; |
2396
|
|
|
|
|
|
/* FALL THROUGH */ |
2397
|
|
|
|
|
|
case OP_ENTER: |
2398
|
|
|
|
|
|
case OP_LIST: |
2399
|
1719958
|
50
|
|
|
|
if (!(o->op_flags & OPf_KIDS)) |
2400
|
|
|
|
|
|
break; |
2401
|
1719958
|
|
|
|
|
doref(cLISTOPo->op_last, type, set_op_ref); |
2402
|
1719958
|
|
|
|
|
break; |
2403
|
|
|
|
|
|
default: |
2404
|
|
|
|
|
|
break; |
2405
|
|
|
|
|
|
} |
2406
|
78747708
|
|
|
|
|
return scalar(o); |
2407
|
|
|
|
|
|
|
2408
|
|
|
|
|
|
} |
2409
|
|
|
|
|
|
|
2410
|
|
|
|
|
|
STATIC OP * |
2411
|
216
|
|
|
|
|
S_dup_attrlist(pTHX_ OP *o) |
2412
|
|
|
|
|
|
{ |
2413
|
|
|
|
|
|
dVAR; |
2414
|
|
|
|
|
|
OP *rop; |
2415
|
|
|
|
|
|
|
2416
|
|
|
|
|
|
PERL_ARGS_ASSERT_DUP_ATTRLIST; |
2417
|
|
|
|
|
|
|
2418
|
|
|
|
|
|
/* An attrlist is either a simple OP_CONST or an OP_LIST with kids, |
2419
|
|
|
|
|
|
* where the first kid is OP_PUSHMARK and the remaining ones |
2420
|
|
|
|
|
|
* are OP_CONST. We need to push the OP_CONST values. |
2421
|
|
|
|
|
|
*/ |
2422
|
216
|
100
|
|
|
|
if (o->op_type == OP_CONST) |
2423
|
321
|
|
|
|
|
rop = newSVOP(OP_CONST, o->op_flags, SvREFCNT_inc_NN(cSVOPo->op_sv)); |
2424
|
|
|
|
|
|
#ifdef PERL_MAD |
2425
|
|
|
|
|
|
else if (o->op_type == OP_NULL) |
2426
|
|
|
|
|
|
rop = NULL; |
2427
|
|
|
|
|
|
#endif |
2428
|
|
|
|
|
|
else { |
2429
|
|
|
|
|
|
assert((o->op_type == OP_LIST) && (o->op_flags & OPf_KIDS)); |
2430
|
|
|
|
|
|
rop = NULL; |
2431
|
8
|
100
|
|
|
|
for (o = cLISTOPo->op_first; o; o=o->op_sibling) { |
2432
|
6
|
100
|
|
|
|
if (o->op_type == OP_CONST) |
2433
|
6
|
|
|
|
|
rop = op_append_elem(OP_LIST, rop, |
2434
|
|
|
|
|
|
newSVOP(OP_CONST, o->op_flags, |
2435
|
|
|
|
|
|
SvREFCNT_inc_NN(cSVOPo->op_sv))); |
2436
|
|
|
|
|
|
} |
2437
|
|
|
|
|
|
} |
2438
|
216
|
|
|
|
|
return rop; |
2439
|
|
|
|
|
|
} |
2440
|
|
|
|
|
|
|
2441
|
|
|
|
|
|
STATIC void |
2442
|
116
|
|
|
|
|
S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs) |
2443
|
|
|
|
|
|
{ |
2444
|
|
|
|
|
|
dVAR; |
2445
|
116
|
50
|
|
|
|
SV * const stashsv = stash ? newSVhek(HvNAME_HEK(stash)) : &PL_sv_no; |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
2446
|
|
|
|
|
|
|
2447
|
|
|
|
|
|
PERL_ARGS_ASSERT_APPLY_ATTRS; |
2448
|
|
|
|
|
|
|
2449
|
|
|
|
|
|
/* fake up C |
2450
|
116
|
|
|
|
|
ENTER; /* need to protect against side-effects of 'use' */ |
2451
|
|
|
|
|
|
|
2452
|
|
|
|
|
|
#define ATTRSMODULE "attributes" |
2453
|
|
|
|
|
|
#define ATTRSMODULE_PM "attributes.pm" |
2454
|
|
|
|
|
|
|
2455
|
116
|
|
|
|
|
Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS, |
2456
|
|
|
|
|
|
newSVpvs(ATTRSMODULE), |
2457
|
|
|
|
|
|
NULL, |
2458
|
|
|
|
|
|
op_prepend_elem(OP_LIST, |
2459
|
|
|
|
|
|
newSVOP(OP_CONST, 0, stashsv), |
2460
|
|
|
|
|
|
op_prepend_elem(OP_LIST, |
2461
|
|
|
|
|
|
newSVOP(OP_CONST, 0, |
2462
|
|
|
|
|
|
newRV(target)), |
2463
|
|
|
|
|
|
dup_attrlist(attrs)))); |
2464
|
108
|
|
|
|
|
LEAVE; |
2465
|
108
|
|
|
|
|
} |
2466
|
|
|
|
|
|
|
2467
|
|
|
|
|
|
STATIC void |
2468
|
100
|
|
|
|
|
S_apply_attrs_my(pTHX_ HV *stash, OP *target, OP *attrs, OP **imopsp) |
2469
|
|
|
|
|
|
{ |
2470
|
|
|
|
|
|
dVAR; |
2471
|
|
|
|
|
|
OP *pack, *imop, *arg; |
2472
|
|
|
|
|
|
SV *meth, *stashsv, **svp; |
2473
|
|
|
|
|
|
|
2474
|
|
|
|
|
|
PERL_ARGS_ASSERT_APPLY_ATTRS_MY; |
2475
|
|
|
|
|
|
|
2476
|
100
|
50
|
|
|
|
if (!attrs) |
2477
|
100
|
|
|
|
|
return; |
2478
|
|
|
|
|
|
|
2479
|
|
|
|
|
|
assert(target->op_type == OP_PADSV || |
2480
|
|
|
|
|
|
target->op_type == OP_PADHV || |
2481
|
|
|
|
|
|
target->op_type == OP_PADAV); |
2482
|
|
|
|
|
|
|
2483
|
|
|
|
|
|
/* Ensure that attributes.pm is loaded. */ |
2484
|
100
|
|
|
|
|
ENTER; /* need to protect against side-effects of 'use' */ |
2485
|
|
|
|
|
|
/* Don't force the C |
2486
|
100
|
50
|
|
|
|
svp = hv_fetchs(GvHVn(PL_incgv), ATTRSMODULE_PM, FALSE); |
2487
|
100
|
100
|
|
|
|
if (svp && *svp != &PL_sv_undef) |
|
|
50
|
|
|
|
|
2488
|
|
|
|
|
|
NOOP; /* already in %INC */ |
2489
|
|
|
|
|
|
else |
2490
|
14
|
|
|
|
|
Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, |
2491
|
|
|
|
|
|
newSVpvs(ATTRSMODULE), NULL); |
2492
|
100
|
|
|
|
|
LEAVE; |
2493
|
|
|
|
|
|
|
2494
|
|
|
|
|
|
/* Need package name for method call. */ |
2495
|
100
|
|
|
|
|
pack = newSVOP(OP_CONST, 0, newSVpvs(ATTRSMODULE)); |
2496
|
|
|
|
|
|
|
2497
|
|
|
|
|
|
/* Build up the real arg-list. */ |
2498
|
100
|
50
|
|
|
|
stashsv = stash ? newSVhek(HvNAME_HEK(stash)) : &PL_sv_no; |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
2499
|
|
|
|
|
|
|
2500
|
100
|
|
|
|
|
arg = newOP(OP_PADSV, 0); |
2501
|
100
|
|
|
|
|
arg->op_targ = target->op_targ; |
2502
|
100
|
|
|
|
|
arg = op_prepend_elem(OP_LIST, |
2503
|
|
|
|
|
|
newSVOP(OP_CONST, 0, stashsv), |
2504
|
|
|
|
|
|
op_prepend_elem(OP_LIST, |
2505
|
|
|
|
|
|
newUNOP(OP_REFGEN, 0, |
2506
|
|
|
|
|
|
op_lvalue(arg, OP_REFGEN)), |
2507
|
|
|
|
|
|
dup_attrlist(attrs))); |
2508
|
|
|
|
|
|
|
2509
|
|
|
|
|
|
/* Fake up a method call to import */ |
2510
|
100
|
|
|
|
|
meth = newSVpvs_share("import"); |
2511
|
100
|
|
|
|
|
imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL|OPf_WANT_VOID, |
2512
|
|
|
|
|
|
op_append_elem(OP_LIST, |
2513
|
|
|
|
|
|
op_prepend_elem(OP_LIST, pack, list(arg)), |
2514
|
|
|
|
|
|
newSVOP(OP_METHOD_NAMED, 0, meth))); |
2515
|
|
|
|
|
|
|
2516
|
|
|
|
|
|
/* Combine the ops. */ |
2517
|
100
|
|
|
|
|
*imopsp = op_append_elem(OP_LIST, *imopsp, imop); |
2518
|
|
|
|
|
|
} |
2519
|
|
|
|
|
|
|
2520
|
|
|
|
|
|
/* |
2521
|
|
|
|
|
|
=notfor apidoc apply_attrs_string |
2522
|
|
|
|
|
|
|
2523
|
|
|
|
|
|
Attempts to apply a list of attributes specified by the C and |
2524
|
|
|
|
|
|
C arguments to the subroutine identified by the C argument which |
2525
|
|
|
|
|
|
is expected to be associated with the package identified by the C |
2526
|
|
|
|
|
|
argument (see L). It gets this wrong, though, in that it |
2527
|
|
|
|
|
|
does not correctly identify the boundaries of the individual attribute |
2528
|
|
|
|
|
|
specifications within C. This is not really intended for the |
2529
|
|
|
|
|
|
public API, but has to be listed here for systems such as AIX which |
2530
|
|
|
|
|
|
need an explicit export list for symbols. (It's called from XS code |
2531
|
|
|
|
|
|
in support of the C keyword from F.) Patches to fix it |
2532
|
|
|
|
|
|
to respect attribute syntax properly would be welcome. |
2533
|
|
|
|
|
|
|
2534
|
|
|
|
|
|
=cut |
2535
|
|
|
|
|
|
*/ |
2536
|
|
|
|
|
|
|
2537
|
|
|
|
|
|
void |
2538
|
2
|
|
|
|
|
Perl_apply_attrs_string(pTHX_ const char *stashpv, CV *cv, |
2539
|
|
|
|
|
|
const char *attrstr, STRLEN len) |
2540
|
|
|
|
|
|
{ |
2541
|
|
|
|
|
|
OP *attrs = NULL; |
2542
|
|
|
|
|
|
|
2543
|
|
|
|
|
|
PERL_ARGS_ASSERT_APPLY_ATTRS_STRING; |
2544
|
|
|
|
|
|
|
2545
|
2
|
50
|
|
|
|
if (!len) { |
2546
|
2
|
|
|
|
|
len = strlen(attrstr); |
2547
|
|
|
|
|
|
} |
2548
|
|
|
|
|
|
|
2549
|
4
|
100
|
|
|
|
while (len) { |
2550
|
1
|
50
|
|
|
|
for (; isSPACE(*attrstr) && len; --len, ++attrstr) ; |
2551
|
2
|
50
|
|
|
|
if (len) { |
2552
|
|
|
|
|
|
const char * const sstr = attrstr; |
2553
|
13
|
100
|
|
|
|
for (; !isSPACE(*attrstr) && len; --len, ++attrstr) ; |
2554
|
3
|
|
|
|
|
attrs = op_append_elem(OP_LIST, attrs, |
2555
|
|
|
|
|
|
newSVOP(OP_CONST, 0, |
2556
|
|
|
|
|
|
newSVpvn(sstr, attrstr-sstr))); |
2557
|
|
|
|
|
|
} |
2558
|
|
|
|
|
|
} |
2559
|
|
|
|
|
|
|
2560
|
2
|
|
|
|
|
Perl_load_module(aTHX_ PERL_LOADMOD_IMPORT_OPS, |
2561
|
|
|
|
|
|
newSVpvs(ATTRSMODULE), |
2562
|
|
|
|
|
|
NULL, op_prepend_elem(OP_LIST, |
2563
|
|
|
|
|
|
newSVOP(OP_CONST, 0, newSVpv(stashpv,0)), |
2564
|
|
|
|
|
|
op_prepend_elem(OP_LIST, |
2565
|
|
|
|
|
|
newSVOP(OP_CONST, 0, |
2566
|
|
|
|
|
|
newRV(MUTABLE_SV(cv))), |
2567
|
|
|
|
|
|
attrs))); |
2568
|
2
|
|
|
|
|
} |
2569
|
|
|
|
|
|
|
2570
|
|
|
|
|
|
STATIC OP * |
2571
|
25785423
|
|
|
|
|
S_my_kid(pTHX_ OP *o, OP *attrs, OP **imopsp) |
2572
|
|
|
|
|
|
{ |
2573
|
|
|
|
|
|
dVAR; |
2574
|
|
|
|
|
|
I32 type; |
2575
|
25785423
|
50
|
|
|
|
const bool stately = PL_parser && PL_parser->in_my == KEY_state; |
|
|
100
|
|
|
|
|
2576
|
|
|
|
|
|
|
2577
|
|
|
|
|
|
PERL_ARGS_ASSERT_MY_KID; |
2578
|
|
|
|
|
|
|
2579
|
25785423
|
50
|
|
|
|
if (!o || (PL_parser && PL_parser->error_count)) |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
2580
|
|
|
|
|
|
return o; |
2581
|
|
|
|
|
|
|
2582
|
25785391
|
|
|
|
|
type = o->op_type; |
2583
|
|
|
|
|
|
if (PL_madskills && type == OP_NULL && o->op_flags & OPf_KIDS) { |
2584
|
|
|
|
|
|
(void)my_kid(cUNOPo->op_first, attrs, imopsp); |
2585
|
|
|
|
|
|
return o; |
2586
|
|
|
|
|
|
} |
2587
|
|
|
|
|
|
|
2588
|
25785391
|
100
|
|
|
|
if (type == OP_LIST) { |
2589
|
|
|
|
|
|
OP *kid; |
2590
|
11915214
|
100
|
|
|
|
for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling) |
2591
|
9346976
|
|
|
|
|
my_kid(kid, attrs, imopsp); |
2592
|
|
|
|
|
|
return o; |
2593
|
23217153
|
100
|
|
|
|
} else if (type == OP_UNDEF || type == OP_STUB) { |
2594
|
|
|
|
|
|
return o; |
2595
|
34296062
|
100
|
|
|
|
} else if (type == OP_RV2SV || /* "our" declaration */ |
2596
|
33461486
|
100
|
|
|
|
type == OP_RV2AV || |
2597
|
|
|
|
|
|
type == OP_RV2HV) { /* XXX does this let anything illegal in? */ |
2598
|
970029
|
100
|
|
|
|
if (cUNOPo->op_first->op_type != OP_GV) { /* MJD 20011224 */ |
2599
|
8
|
50
|
|
|
|
yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"", |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
2600
|
|
|
|
|
|
OP_DESC(o), |
2601
|
|
|
|
|
|
PL_parser->in_my == KEY_our |
2602
|
|
|
|
|
|
? "our" |
2603
|
|
|
|
|
|
: PL_parser->in_my == KEY_state ? "state" : "my")); |
2604
|
970021
|
100
|
|
|
|
} else if (attrs) { |
2605
|
4
|
|
|
|
|
GV * const gv = cGVOPx_gv(cUNOPo->op_first); |
2606
|
4
|
|
|
|
|
PL_parser->in_my = FALSE; |
2607
|
4
|
|
|
|
|
PL_parser->in_my_stash = NULL; |
2608
|
4
|
50
|
|
|
|
apply_attrs(GvSTASH(gv), |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
2609
|
|
|
|
|
|
(type == OP_RV2SV ? GvSV(gv) : |
2610
|
|
|
|
|
|
type == OP_RV2AV ? MUTABLE_SV(GvAV(gv)) : |
2611
|
|
|
|
|
|
type == OP_RV2HV ? MUTABLE_SV(GvHV(gv)) : MUTABLE_SV(gv)), |
2612
|
|
|
|
|
|
attrs); |
2613
|
|
|
|
|
|
} |
2614
|
970029
|
|
|
|
|
o->op_private |= OPpOUR_INTRO; |
2615
|
970029
|
|
|
|
|
return o; |
2616
|
|
|
|
|
|
} |
2617
|
22154261
|
50
|
|
|
|
else if (type != OP_PADSV && |
2618
|
22154261
|
|
|
|
|
type != OP_PADAV && |
2619
|
22154261
|
|
|
|
|
type != OP_PADHV && |
2620
|
22154261
|
|
|
|
|
type != OP_PUSHMARK) |
2621
|
|
|
|
|
|
{ |
2622
|
0
|
0
|
|
|
|
yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"", |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
2623
|
|
|
|
|
|
OP_DESC(o), |
2624
|
|
|
|
|
|
PL_parser->in_my == KEY_our |
2625
|
|
|
|
|
|
? "our" |
2626
|
|
|
|
|
|
: PL_parser->in_my == KEY_state ? "state" : "my")); |
2627
|
0
|
|
|
|
|
return o; |
2628
|
|
|
|
|
|
} |
2629
|
22154261
|
100
|
|
|
|
else if (attrs && type != OP_PUSHMARK) { |
2630
|
|
|
|
|
|
HV *stash; |
2631
|
|
|
|
|
|
|
2632
|
100
|
|
|
|
|
PL_parser->in_my = FALSE; |
2633
|
100
|
|
|
|
|
PL_parser->in_my_stash = NULL; |
2634
|
|
|
|
|
|
|
2635
|
|
|
|
|
|
/* check for C when deciding package */ |
2636
|
100
|
|
|
|
|
stash = PAD_COMPNAME_TYPE(o->op_targ); |
2637
|
100
|
100
|
|
|
|
if (!stash) |
2638
|
86
|
|
|
|
|
stash = PL_curstash; |
2639
|
100
|
|
|
|
|
apply_attrs_my(stash, o, attrs, imopsp); |
2640
|
|
|
|
|
|
} |
2641
|
22154261
|
|
|
|
|
o->op_flags |= OPf_MOD; |
2642
|
22154261
|
|
|
|
|
o->op_private |= OPpLVAL_INTRO; |
2643
|
22154261
|
100
|
|
|
|
if (stately) |
2644
|
13328515
|
|
|
|
|
o->op_private |= OPpPAD_STATE; |
2645
|
|
|
|
|
|
return o; |
2646
|
|
|
|
|
|
} |
2647
|
|
|
|
|
|
|
2648
|
|
|
|
|
|
OP * |
2649
|
16438447
|
|
|
|
|
Perl_my_attrs(pTHX_ OP *o, OP *attrs) |
2650
|
|
|
|
|
|
{ |
2651
|
|
|
|
|
|
dVAR; |
2652
|
|
|
|
|
|
OP *rops; |
2653
|
|
|
|
|
|
int maybe_scalar = 0; |
2654
|
|
|
|
|
|
|
2655
|
|
|
|
|
|
PERL_ARGS_ASSERT_MY_ATTRS; |
2656
|
|
|
|
|
|
|
2657
|
|
|
|
|
|
/* [perl #17376]: this appears to be premature, and results in code such as |
2658
|
|
|
|
|
|
C< our(%x); > executing in list mode rather than void mode */ |
2659
|
|
|
|
|
|
#if 0 |
2660
|
|
|
|
|
|
if (o->op_flags & OPf_PARENS) |
2661
|
|
|
|
|
|
list(o); |
2662
|
|
|
|
|
|
else |
2663
|
|
|
|
|
|
maybe_scalar = 1; |
2664
|
|
|
|
|
|
#else |
2665
|
|
|
|
|
|
maybe_scalar = 1; |
2666
|
|
|
|
|
|
#endif |
2667
|
16438447
|
100
|
|
|
|
if (attrs) |
2668
|
104
|
|
|
|
|
SAVEFREEOP(attrs); |
2669
|
16438447
|
|
|
|
|
rops = NULL; |
2670
|
16438447
|
|
|
|
|
o = my_kid(o, attrs, &rops); |
2671
|
16438447
|
100
|
|
|
|
if (rops) { |
2672
|
100
|
100
|
|
|
|
if (maybe_scalar && o->op_type == OP_PADSV) { |
2673
|
56
|
|
|
|
|
o = scalar(op_append_list(OP_LIST, rops, o)); |
2674
|
56
|
|
|
|
|
o->op_private |= OPpLVAL_INTRO; |
2675
|
|
|
|
|
|
} |
2676
|
|
|
|
|
|
else { |
2677
|
|
|
|
|
|
/* The listop in rops might have a pushmark at the beginning, |
2678
|
|
|
|
|
|
which will mess up list assignment. */ |
2679
|
44
|
|
|
|
|
LISTOP * const lrops = (LISTOP *)rops; /* for brevity */ |
2680
|
44
|
50
|
|
|
|
if (rops->op_type == OP_LIST && |
|
|
0
|
|
|
|
|
2681
|
0
|
0
|
|
|
|
lrops->op_first && lrops->op_first->op_type == OP_PUSHMARK) |
2682
|
|
|
|
|
|
{ |
2683
|
0
|
|
|
|
|
OP * const pushmark = lrops->op_first; |
2684
|
0
|
|
|
|
|
lrops->op_first = pushmark->op_sibling; |
2685
|
0
|
|
|
|
|
op_free(pushmark); |
2686
|
|
|
|
|
|
} |
2687
|
44
|
|
|
|
|
o = op_append_list(OP_LIST, o, rops); |
2688
|
|
|
|
|
|
} |
2689
|
|
|
|
|
|
} |
2690
|
16438447
|
|
|
|
|
PL_parser->in_my = FALSE; |
2691
|
16438447
|
|
|
|
|
PL_parser->in_my_stash = NULL; |
2692
|
16438447
|
|
|
|
|
return o; |
2693
|
|
|
|
|
|
} |
2694
|
|
|
|
|
|
|
2695
|
|
|
|
|
|
OP * |
2696
|
9534048
|
|
|
|
|
Perl_sawparens(pTHX_ OP *o) |
2697
|
|
|
|
|
|
{ |
2698
|
|
|
|
|
|
PERL_UNUSED_CONTEXT; |
2699
|
9566138
|
50
|
|
|
|
if (o) |
2700
|
9566138
|
|
|
|
|
o->op_flags |= OPf_PARENS; |
2701
|
9534048
|
|
|
|
|
return o; |
2702
|
|
|
|
|
|
} |
2703
|
|
|
|
|
|
|
2704
|
|
|
|
|
|
OP * |
2705
|
3316769
|
|
|
|
|
Perl_bind_match(pTHX_ I32 type, OP *left, OP *right) |
2706
|
|
|
|
|
|
{ |
2707
|
|
|
|
|
|
OP *o; |
2708
|
|
|
|
|
|
bool ismatchop = 0; |
2709
|
3689593
|
|
|
|
|
const OPCODE ltype = left->op_type; |
2710
|
3689593
|
|
|
|
|
const OPCODE rtype = right->op_type; |
2711
|
|
|
|
|
|
|
2712
|
|
|
|
|
|
PERL_ARGS_ASSERT_BIND_MATCH; |
2713
|
|
|
|
|
|
|
2714
|
3689593
|
100
|
|
|
|
if ( (ltype == OP_RV2AV || ltype == OP_RV2HV || ltype == OP_PADAV |
2715
|
3689578
|
100
|
|
|
|
|| ltype == OP_PADHV) && ckWARN(WARN_MISC)) |
|
|
100
|
|
|
|
|
2716
|
|
|
|
|
|
{ |
2717
|
24
|
|
|
|
|
const char * const desc |
2718
|
|
|
|
|
|
= PL_op_desc[( |
2719
|
24
|
|
|
|
|
rtype == OP_SUBST || rtype == OP_TRANS |
2720
|
8
|
50
|
|
|
|
|| rtype == OP_TRANSR |
2721
|
|
|
|
|
|
) |
2722
|
32
|
100
|
|
|
|
? (int)rtype : OP_MATCH]; |
2723
|
24
|
|
|
|
|
const bool isary = ltype == OP_RV2AV || ltype == OP_PADAV; |
2724
|
|
|
|
|
|
GV *gv; |
2725
|
|
|
|
|
|
SV * const name = |
2726
|
24
|
|
|
|
|
(ltype == OP_RV2AV || ltype == OP_RV2HV) |
2727
|
20
|
|
|
|
|
? cUNOPx(left)->op_first->op_type == OP_GV |
2728
|
8
|
50
|
|
|
|
&& (gv = cGVOPx_gv(cUNOPx(left)->op_first)) |
2729
|
8
|
100
|
|
|
|
? varname(gv, isary ? '@' : '%', 0, NULL, 0, 1) |
2730
|
28
|
100
|
|
|
|
: NULL |
2731
|
26
|
100
|
|
|
|
: varname( |
|
|
100
|
|
|
|
|
2732
|
|
|
|
|
|
(GV *)PL_compcv, isary ? '@' : '%', left->op_targ, NULL, 0, 1 |
2733
|
|
|
|
|
|
); |
2734
|
24
|
100
|
|
|
|
if (name) |
2735
|
12
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_MISC), |
2736
|
|
|
|
|
|
"Applying %s to %"SVf" will act on scalar(%"SVf")", |
2737
|
|
|
|
|
|
desc, name, name); |
2738
|
|
|
|
|
|
else { |
2739
|
|
|
|
|
|
const char * const sample = (isary |
2740
|
12
|
100
|
|
|
|
? "@array" : "%hash"); |
2741
|
12
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_MISC), |
2742
|
|
|
|
|
|
"Applying %s to %s will act on scalar(%s)", |
2743
|
|
|
|
|
|
desc, sample, sample); |
2744
|
|
|
|
|
|
} |
2745
|
|
|
|
|
|
} |
2746
|
|
|
|
|
|
|
2747
|
3689593
|
100
|
|
|
|
if (rtype == OP_CONST && |
2748
|
10692
|
100
|
|
|
|
cSVOPx(right)->op_private & OPpCONST_BARE && |
2749
|
|
|
|
|
|
cSVOPx(right)->op_private & OPpCONST_STRICT) |
2750
|
|
|
|
|
|
{ |
2751
|
2
|
|
|
|
|
no_bareword_allowed(right); |
2752
|
|
|
|
|
|
} |
2753
|
|
|
|
|
|
|
2754
|
|
|
|
|
|
/* !~ doesn't make sense with /r, so error on it for now */ |
2755
|
4200983
|
100
|
|
|
|
if (rtype == OP_SUBST && (cPMOPx(right)->op_pmflags & PMf_NONDESTRUCT) && |
|
|
100
|
|
|
|
|
2756
|
1063087
|
|
|
|
|
type == OP_NOT) |
2757
|
4
|
|
|
|
|
yyerror("Using !~ with s///r doesn't make sense"); |
2758
|
3689593
|
100
|
|
|
|
if (rtype == OP_TRANSR && type == OP_NOT) |
2759
|
2
|
|
|
|
|
yyerror("Using !~ with tr///r doesn't make sense"); |
2760
|
|
|
|
|
|
|
2761
|
11068779
|
|
|
|
|
ismatchop = (rtype == OP_MATCH || |
2762
|
3689593
|
|
|
|
|
rtype == OP_SUBST || |
2763
|
455954
|
100
|
|
|
|
rtype == OP_TRANS || rtype == OP_TRANSR) |
2764
|
5513508
|
100
|
|
|
|
&& !(right->op_flags & OPf_SPECIAL); |
|
|
100
|
|
|
|
|
2765
|
3689593
|
100
|
|
|
|
if (ismatchop && right->op_private & OPpTARGET_MY) { |
|
|
100
|
|
|
|
|
2766
|
44
|
|
|
|
|
right->op_targ = 0; |
2767
|
44
|
|
|
|
|
right->op_private &= ~OPpTARGET_MY; |
2768
|
|
|
|
|
|
} |
2769
|
3689593
|
50
|
|
|
|
if (!(right->op_flags & OPf_STACKED) && ismatchop) { |
|
|
100
|
|
|
|
|
2770
|
|
|
|
|
|
OP *newleft; |
2771
|
|
|
|
|
|
|
2772
|
3316769
|
|
|
|
|
right->op_flags |= OPf_STACKED; |
2773
|
3316769
|
100
|
|
|
|
if (rtype != OP_MATCH && rtype != OP_TRANSR && |
|
|
100
|
|
|
|
|
2774
|
83122
|
100
|
|
|
|
! (rtype == OP_TRANS && |
2775
|
1131178
|
100
|
|
|
|
right->op_private & OPpTRANS_IDENTICAL) && |
2776
|
1063083
|
100
|
|
|
|
! (rtype == OP_SUBST && |
2777
|
1063083
|
|
|
|
|
(cPMOPx(right)->op_pmflags & PMf_NONDESTRUCT))) |
2778
|
1087927
|
|
|
|
|
newleft = op_lvalue(left, rtype); |
2779
|
|
|
|
|
|
else |
2780
|
|
|
|
|
|
newleft = left; |
2781
|
3316769
|
100
|
|
|
|
if (right->op_type == OP_TRANS || right->op_type == OP_TRANSR) |
2782
|
83138
|
|
|
|
|
o = newBINOP(OP_NULL, OPf_STACKED, scalar(newleft), right); |
2783
|
|
|
|
|
|
else |
2784
|
3233631
|
|
|
|
|
o = op_prepend_elem(rtype, scalar(newleft), right); |
2785
|
3316769
|
100
|
|
|
|
if (type == OP_NOT) |
2786
|
265266
|
|
|
|
|
return newUNOP(OP_NOT, 0, scalar(o)); |
2787
|
|
|
|
|
|
return o; |
2788
|
|
|
|
|
|
} |
2789
|
|
|
|
|
|
else |
2790
|
2099421
|
|
|
|
|
return bind_match(type, left, |
2791
|
|
|
|
|
|
pmruntime(newPMOP(OP_MATCH, 0), right, 0, 0)); |
2792
|
|
|
|
|
|
} |
2793
|
|
|
|
|
|
|
2794
|
|
|
|
|
|
OP * |
2795
|
657547
|
|
|
|
|
Perl_invert(pTHX_ OP *o) |
2796
|
|
|
|
|
|
{ |
2797
|
657547
|
50
|
|
|
|
if (!o) |
2798
|
|
|
|
|
|
return NULL; |
2799
|
657547
|
|
|
|
|
return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o)); |
2800
|
|
|
|
|
|
} |
2801
|
|
|
|
|
|
|
2802
|
|
|
|
|
|
/* |
2803
|
|
|
|
|
|
=for apidoc Amx|OP *|op_scope|OP *o |
2804
|
|
|
|
|
|
|
2805
|
|
|
|
|
|
Wraps up an op tree with some additional ops so that at runtime a dynamic |
2806
|
|
|
|
|
|
scope will be created. The original ops run in the new dynamic scope, |
2807
|
|
|
|
|
|
and then, provided that they exit normally, the scope will be unwound. |
2808
|
|
|
|
|
|
The additional ops used to create and unwind the dynamic scope will |
2809
|
|
|
|
|
|
normally be an C/C pair, but a C op may be used |
2810
|
|
|
|
|
|
instead if the ops are simple enough to not need the full dynamic scope |
2811
|
|
|
|
|
|
structure. |
2812
|
|
|
|
|
|
|
2813
|
|
|
|
|
|
=cut |
2814
|
|
|
|
|
|
*/ |
2815
|
|
|
|
|
|
|
2816
|
|
|
|
|
|
OP * |
2817
|
14292462
|
|
|
|
|
Perl_op_scope(pTHX_ OP *o) |
2818
|
|
|
|
|
|
{ |
2819
|
|
|
|
|
|
dVAR; |
2820
|
14292462
|
50
|
|
|
|
if (o) { |
2821
|
14292462
|
100
|
|
|
|
if (o->op_flags & OPf_PARENS || PERLDB_NOOPT || TAINTING_get) { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
2822
|
9497413
|
|
|
|
|
o = op_prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o); |
2823
|
9497413
|
|
|
|
|
o->op_type = OP_LEAVE; |
2824
|
9497413
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_LEAVE]; |
2825
|
|
|
|
|
|
} |
2826
|
4795049
|
100
|
|
|
|
else if (o->op_type == OP_LINESEQ) { |
2827
|
|
|
|
|
|
OP *kid; |
2828
|
4747429
|
|
|
|
|
o->op_type = OP_SCOPE; |
2829
|
4747429
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_SCOPE]; |
2830
|
4747429
|
|
|
|
|
kid = ((LISTOP*)o)->op_first; |
2831
|
4747429
|
50
|
|
|
|
if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) { |
2832
|
4747429
|
|
|
|
|
op_null(kid); |
2833
|
|
|
|
|
|
|
2834
|
|
|
|
|
|
/* The following deals with things like 'do {1 for 1}' */ |
2835
|
4747429
|
|
|
|
|
kid = kid->op_sibling; |
2836
|
7011348
|
50
|
|
|
|
if (kid && |
|
|
50
|
|
|
|
|
2837
|
4747429
|
|
|
|
|
(kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE)) |
2838
|
0
|
|
|
|
|
op_null(kid); |
2839
|
|
|
|
|
|
} |
2840
|
|
|
|
|
|
} |
2841
|
|
|
|
|
|
else |
2842
|
47620
|
|
|
|
|
o = newLISTOP(OP_SCOPE, 0, o, NULL); |
2843
|
|
|
|
|
|
} |
2844
|
14292462
|
|
|
|
|
return o; |
2845
|
|
|
|
|
|
} |
2846
|
|
|
|
|
|
|
2847
|
|
|
|
|
|
OP * |
2848
|
316
|
|
|
|
|
Perl_op_unscope(pTHX_ OP *o) |
2849
|
|
|
|
|
|
{ |
2850
|
316
|
100
|
|
|
|
if (o && o->op_type == OP_LINESEQ) { |
|
|
50
|
|
|
|
|
2851
|
308
|
|
|
|
|
OP *kid = cLISTOPo->op_first; |
2852
|
932
|
100
|
|
|
|
for(; kid; kid = kid->op_sibling) |
2853
|
624
|
100
|
|
|
|
if (kid->op_type == OP_NEXTSTATE || kid->op_type == OP_DBSTATE) |
2854
|
312
|
|
|
|
|
op_null(kid); |
2855
|
|
|
|
|
|
} |
2856
|
316
|
|
|
|
|
return o; |
2857
|
|
|
|
|
|
} |
2858
|
|
|
|
|
|
|
2859
|
|
|
|
|
|
int |
2860
|
37407361
|
|
|
|
|
Perl_block_start(pTHX_ int full) |
2861
|
|
|
|
|
|
{ |
2862
|
|
|
|
|
|
dVAR; |
2863
|
37407361
|
|
|
|
|
const int retval = PL_savestack_ix; |
2864
|
|
|
|
|
|
|
2865
|
37407361
|
|
|
|
|
pad_block_start(full); |
2866
|
37407361
|
|
|
|
|
SAVEHINTS(); |
2867
|
37407355
|
|
|
|
|
PL_hints &= ~HINT_BLOCK_SCOPE; |
2868
|
37407355
|
|
|
|
|
SAVECOMPILEWARNINGS(); |
2869
|
55432314
|
100
|
|
|
|
PL_compiling.cop_warnings = DUP_WARNINGS(PL_compiling.cop_warnings); |
|
|
100
|
|
|
|
|
2870
|
|
|
|
|
|
|
2871
|
37705535
|
100
|
|
|
|
CALL_BLOCK_HOOKS(bhk_start, full); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
2872
|
|
|
|
|
|
|
2873
|
37407355
|
|
|
|
|
return retval; |
2874
|
|
|
|
|
|
} |
2875
|
|
|
|
|
|
|
2876
|
|
|
|
|
|
OP* |
2877
|
37345311
|
|
|
|
|
Perl_block_end(pTHX_ I32 floor, OP *seq) |
2878
|
|
|
|
|
|
{ |
2879
|
|
|
|
|
|
dVAR; |
2880
|
37345311
|
|
|
|
|
const int needblockscope = PL_hints & HINT_BLOCK_SCOPE; |
2881
|
37345311
|
|
|
|
|
OP* retval = scalarseq(seq); |
2882
|
|
|
|
|
|
OP *o; |
2883
|
|
|
|
|
|
|
2884
|
37643449
|
100
|
|
|
|
CALL_BLOCK_HOOKS(bhk_pre_end, &retval); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
2885
|
|
|
|
|
|
|
2886
|
37345305
|
100
|
|
|
|
LEAVE_SCOPE(floor); |
2887
|
37345305
|
100
|
|
|
|
if (needblockscope) |
2888
|
23872703
|
|
|
|
|
PL_hints |= HINT_BLOCK_SCOPE; /* propagate out */ |
2889
|
37345305
|
|
|
|
|
o = pad_leavemy(); |
2890
|
|
|
|
|
|
|
2891
|
37345305
|
100
|
|
|
|
if (o) { |
2892
|
|
|
|
|
|
/* pad_leavemy has created a sequence of introcv ops for all my |
2893
|
|
|
|
|
|
subs declared in the block. We have to replicate that list with |
2894
|
|
|
|
|
|
clonecv ops, to deal with this situation: |
2895
|
|
|
|
|
|
|
2896
|
|
|
|
|
|
sub { |
2897
|
|
|
|
|
|
my sub s1; |
2898
|
|
|
|
|
|
my sub s2; |
2899
|
|
|
|
|
|
sub s1 { state sub foo { \&s2 } } |
2900
|
|
|
|
|
|
}->() |
2901
|
|
|
|
|
|
|
2902
|
|
|
|
|
|
Originally, I was going to have introcv clone the CV and turn |
2903
|
|
|
|
|
|
off the stale flag. Since &s1 is declared before &s2, the |
2904
|
|
|
|
|
|
introcv op for &s1 is executed (on sub entry) before the one for |
2905
|
|
|
|
|
|
&s2. But the &foo sub inside &s1 (which is cloned when &s1 is |
2906
|
|
|
|
|
|
cloned, since it is a state sub) closes over &s2 and expects |
2907
|
|
|
|
|
|
to see it in its outer CV’s pad. If the introcv op clones &s1, |
2908
|
|
|
|
|
|
then &s2 is still marked stale. Since &s1 is not active, and |
2909
|
|
|
|
|
|
&foo closes over &s1’s implicit entry for &s2, we get a ‘Varia- |
2910
|
|
|
|
|
|
ble will not stay shared’ warning. Because it is the same stub |
2911
|
|
|
|
|
|
that will be used when the introcv op for &s2 is executed, clos- |
2912
|
|
|
|
|
|
ing over it is safe. Hence, we have to turn off the stale flag |
2913
|
|
|
|
|
|
on all lexical subs in the block before we clone any of them. |
2914
|
|
|
|
|
|
Hence, having introcv clone the sub cannot work. So we create a |
2915
|
|
|
|
|
|
list of ops like this: |
2916
|
|
|
|
|
|
|
2917
|
|
|
|
|
|
lineseq |
2918
|
|
|
|
|
|
| |
2919
|
|
|
|
|
|
+-- introcv |
2920
|
|
|
|
|
|
| |
2921
|
|
|
|
|
|
+-- introcv |
2922
|
|
|
|
|
|
| |
2923
|
|
|
|
|
|
+-- introcv |
2924
|
|
|
|
|
|
| |
2925
|
|
|
|
|
|
. |
2926
|
|
|
|
|
|
. |
2927
|
|
|
|
|
|
. |
2928
|
|
|
|
|
|
| |
2929
|
|
|
|
|
|
+-- clonecv |
2930
|
|
|
|
|
|
| |
2931
|
|
|
|
|
|
+-- clonecv |
2932
|
|
|
|
|
|
| |
2933
|
|
|
|
|
|
+-- clonecv |
2934
|
|
|
|
|
|
| |
2935
|
|
|
|
|
|
. |
2936
|
|
|
|
|
|
. |
2937
|
|
|
|
|
|
. |
2938
|
|
|
|
|
|
*/ |
2939
|
86
|
100
|
|
|
|
OP *kid = o->op_flags & OPf_KIDS ? cLISTOPo->op_first : o; |
2940
|
86
|
100
|
|
|
|
OP * const last = o->op_flags & OPf_KIDS ? cLISTOPo->op_last : o; |
2941
|
22
|
|
|
|
|
for (;; kid = kid->op_sibling) { |
2942
|
108
|
|
|
|
|
OP *newkid = newOP(OP_CLONECV, 0); |
2943
|
108
|
|
|
|
|
newkid->op_targ = kid->op_targ; |
2944
|
108
|
|
|
|
|
o = op_append_elem(OP_LINESEQ, o, newkid); |
2945
|
108
|
100
|
|
|
|
if (kid == last) break; |
2946
|
22
|
|
|
|
|
} |
2947
|
86
|
|
|
|
|
retval = op_prepend_elem(OP_LINESEQ, o, retval); |
2948
|
|
|
|
|
|
} |
2949
|
|
|
|
|
|
|
2950
|
37643449
|
100
|
|
|
|
CALL_BLOCK_HOOKS(bhk_post_end, &retval); |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
2951
|
|
|
|
|
|
|
2952
|
37345305
|
|
|
|
|
return retval; |
2953
|
|
|
|
|
|
} |
2954
|
|
|
|
|
|
|
2955
|
|
|
|
|
|
/* |
2956
|
|
|
|
|
|
=head1 Compile-time scope hooks |
2957
|
|
|
|
|
|
|
2958
|
|
|
|
|
|
=for apidoc Aox||blockhook_register |
2959
|
|
|
|
|
|
|
2960
|
|
|
|
|
|
Register a set of hooks to be called when the Perl lexical scope changes |
2961
|
|
|
|
|
|
at compile time. See L. |
2962
|
|
|
|
|
|
|
2963
|
|
|
|
|
|
=cut |
2964
|
|
|
|
|
|
*/ |
2965
|
|
|
|
|
|
|
2966
|
|
|
|
|
|
void |
2967
|
352
|
|
|
|
|
Perl_blockhook_register(pTHX_ BHK *hk) |
2968
|
|
|
|
|
|
{ |
2969
|
|
|
|
|
|
PERL_ARGS_ASSERT_BLOCKHOOK_REGISTER; |
2970
|
|
|
|
|
|
|
2971
|
352
|
|
|
|
|
Perl_av_create_and_push(aTHX_ &PL_blockhooks, newSViv(PTR2IV(hk))); |
2972
|
352
|
|
|
|
|
} |
2973
|
|
|
|
|
|
|
2974
|
|
|
|
|
|
STATIC OP * |
2975
|
161427
|
|
|
|
|
S_newDEFSVOP(pTHX) |
2976
|
|
|
|
|
|
{ |
2977
|
|
|
|
|
|
dVAR; |
2978
|
161427
|
|
|
|
|
const PADOFFSET offset = pad_findmy_pvs("$_", 0); |
2979
|
161427
|
100
|
|
|
|
if (offset == NOT_IN_PAD || PAD_COMPNAME_FLAGS_isOUR(offset)) { |
|
|
100
|
|
|
|
|
2980
|
161381
|
|
|
|
|
return newSVREF(newGVOP(OP_GV, 0, PL_defgv)); |
2981
|
|
|
|
|
|
} |
2982
|
|
|
|
|
|
else { |
2983
|
46
|
|
|
|
|
OP * const o = newOP(OP_PADSV, 0); |
2984
|
46
|
|
|
|
|
o->op_targ = offset; |
2985
|
83256
|
|
|
|
|
return o; |
2986
|
|
|
|
|
|
} |
2987
|
|
|
|
|
|
} |
2988
|
|
|
|
|
|
|
2989
|
|
|
|
|
|
void |
2990
|
4210875
|
|
|
|
|
Perl_newPROG(pTHX_ OP *o) |
2991
|
|
|
|
|
|
{ |
2992
|
|
|
|
|
|
dVAR; |
2993
|
|
|
|
|
|
|
2994
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWPROG; |
2995
|
|
|
|
|
|
|
2996
|
4210875
|
100
|
|
|
|
if (PL_in_eval) { |
2997
|
|
|
|
|
|
PERL_CONTEXT *cx; |
2998
|
|
|
|
|
|
I32 i; |
2999
|
4191275
|
50
|
|
|
|
if (PL_eval_root) |
3000
|
|
|
|
|
|
return; |
3001
|
4191275
|
100
|
|
|
|
PL_eval_root = newUNOP(OP_LEAVEEVAL, |
3002
|
|
|
|
|
|
((PL_in_eval & EVAL_KEEPERR) |
3003
|
|
|
|
|
|
? OPf_SPECIAL : 0), o); |
3004
|
|
|
|
|
|
|
3005
|
4191275
|
|
|
|
|
cx = &cxstack[cxstack_ix]; |
3006
|
|
|
|
|
|
assert(CxTYPE(cx) == CXt_EVAL); |
3007
|
|
|
|
|
|
|
3008
|
4191275
|
100
|
|
|
|
if ((cx->blk_gimme & G_WANT) == G_VOID) |
3009
|
405180
|
|
|
|
|
scalarvoid(PL_eval_root); |
3010
|
3786095
|
100
|
|
|
|
else if ((cx->blk_gimme & G_WANT) == G_ARRAY) |
3011
|
2114
|
|
|
|
|
list(PL_eval_root); |
3012
|
|
|
|
|
|
else |
3013
|
3783981
|
|
|
|
|
scalar(PL_eval_root); |
3014
|
|
|
|
|
|
|
3015
|
4191275
|
|
|
|
|
PL_eval_start = op_linklist(PL_eval_root); |
3016
|
4191275
|
|
|
|
|
PL_eval_root->op_private |= OPpREFCOUNTED; |
3017
|
4191275
|
|
|
|
|
OpREFCNT_set(PL_eval_root, 1); |
3018
|
4191275
|
|
|
|
|
PL_eval_root->op_next = 0; |
3019
|
4191275
|
|
|
|
|
i = PL_savestack_ix; |
3020
|
4191275
|
|
|
|
|
SAVEFREEOP(o); |
3021
|
4191275
|
|
|
|
|
ENTER; |
3022
|
4191275
|
|
|
|
|
CALL_PEEP(PL_eval_start); |
3023
|
4191275
|
|
|
|
|
finalize_optree(PL_eval_root); |
3024
|
4191265
|
|
|
|
|
LEAVE; |
3025
|
4191265
|
|
|
|
|
PL_savestack_ix = i; |
3026
|
|
|
|
|
|
} |
3027
|
|
|
|
|
|
else { |
3028
|
19600
|
100
|
|
|
|
if (o->op_type == OP_STUB) { |
3029
|
|
|
|
|
|
/* This block is entered if nothing is compiled for the main |
3030
|
|
|
|
|
|
program. This will be the case for an genuinely empty main |
3031
|
|
|
|
|
|
program, or one which only has BEGIN blocks etc, so already |
3032
|
|
|
|
|
|
run and freed. |
3033
|
|
|
|
|
|
|
3034
|
|
|
|
|
|
Historically (5.000) the guard above was !o. However, commit |
3035
|
|
|
|
|
|
f8a08f7b8bd67b28 (Jun 2001), integrated to blead as |
3036
|
|
|
|
|
|
c71fccf11fde0068, changed perly.y so that newPROG() is now |
3037
|
|
|
|
|
|
called with the output of block_end(), which returns a new |
3038
|
|
|
|
|
|
OP_STUB for the case of an empty optree. ByteLoader (and |
3039
|
|
|
|
|
|
maybe other things) also take this path, because they set up |
3040
|
|
|
|
|
|
PL_main_start and PL_main_root directly, without generating an |
3041
|
|
|
|
|
|
optree. |
3042
|
|
|
|
|
|
|
3043
|
|
|
|
|
|
If the parsing the main program aborts (due to parse errors, |
3044
|
|
|
|
|
|
or due to BEGIN or similar calling exit), then newPROG() |
3045
|
|
|
|
|
|
isn't even called, and hence this code path and its cleanups |
3046
|
|
|
|
|
|
are skipped. This shouldn't make a make a difference: |
3047
|
|
|
|
|
|
* a non-zero return from perl_parse is a failure, and |
3048
|
|
|
|
|
|
perl_destruct() should be called immediately. |
3049
|
|
|
|
|
|
* however, if exit(0) is called during the parse, then |
3050
|
|
|
|
|
|
perl_parse() returns 0, and perl_run() is called. As |
3051
|
|
|
|
|
|
PL_main_start will be NULL, perl_run() will return |
3052
|
|
|
|
|
|
promptly, and the exit code will remain 0. |
3053
|
|
|
|
|
|
*/ |
3054
|
|
|
|
|
|
|
3055
|
148
|
|
|
|
|
PL_comppad_name = 0; |
3056
|
148
|
|
|
|
|
PL_compcv = 0; |
3057
|
|
|
|
|
|
S_op_destroy(aTHX_ o); |
3058
|
|
|
|
|
|
return; |
3059
|
|
|
|
|
|
} |
3060
|
38904
|
|
|
|
|
PL_main_root = op_scope(sawparens(scalarvoid(o))); |
3061
|
19452
|
|
|
|
|
PL_curcop = &PL_compiling; |
3062
|
19452
|
50
|
|
|
|
PL_main_start = LINKLIST(PL_main_root); |
3063
|
19452
|
|
|
|
|
PL_main_root->op_private |= OPpREFCOUNTED; |
3064
|
19452
|
|
|
|
|
OpREFCNT_set(PL_main_root, 1); |
3065
|
19452
|
|
|
|
|
PL_main_root->op_next = 0; |
3066
|
19452
|
|
|
|
|
CALL_PEEP(PL_main_start); |
3067
|
19452
|
|
|
|
|
finalize_optree(PL_main_root); |
3068
|
19448
|
|
|
|
|
cv_forget_slab(PL_compcv); |
3069
|
19448
|
|
|
|
|
PL_compcv = 0; |
3070
|
|
|
|
|
|
|
3071
|
|
|
|
|
|
/* Register with debugger */ |
3072
|
19448
|
100
|
|
|
|
if (PERLDB_INTER) { |
|
|
100
|
|
|
|
|
3073
|
208
|
|
|
|
|
CV * const cv = get_cvs("DB::postponed", 0); |
3074
|
208
|
100
|
|
|
|
if (cv) { |
3075
|
190
|
|
|
|
|
dSP; |
3076
|
190
|
50
|
|
|
|
PUSHMARK(SP); |
3077
|
190
|
50
|
|
|
|
XPUSHs(MUTABLE_SV(CopFILEGV(&PL_compiling))); |
3078
|
190
|
|
|
|
|
PUTBACK; |
3079
|
2127302
|
|
|
|
|
call_sv(MUTABLE_SV(cv), G_DISCARD); |
3080
|
|
|
|
|
|
} |
3081
|
|
|
|
|
|
} |
3082
|
|
|
|
|
|
} |
3083
|
|
|
|
|
|
} |
3084
|
|
|
|
|
|
|
3085
|
|
|
|
|
|
OP * |
3086
|
16734877
|
|
|
|
|
Perl_localize(pTHX_ OP *o, I32 lex) |
3087
|
|
|
|
|
|
{ |
3088
|
|
|
|
|
|
dVAR; |
3089
|
|
|
|
|
|
|
3090
|
|
|
|
|
|
PERL_ARGS_ASSERT_LOCALIZE; |
3091
|
|
|
|
|
|
|
3092
|
16734877
|
100
|
|
|
|
if (o->op_flags & OPf_PARENS) |
3093
|
|
|
|
|
|
/* [perl #17376]: this appears to be premature, and results in code such as |
3094
|
|
|
|
|
|
C< our(%x); > executing in list mode rather than void mode */ |
3095
|
|
|
|
|
|
#if 0 |
3096
|
|
|
|
|
|
list(o); |
3097
|
|
|
|
|
|
#else |
3098
|
|
|
|
|
|
NOOP; |
3099
|
|
|
|
|
|
#endif |
3100
|
|
|
|
|
|
else { |
3101
|
13231357
|
50
|
|
|
|
if ( PL_parser->bufptr > PL_parser->oldbufptr |
3102
|
13231357
|
100
|
|
|
|
&& PL_parser->bufptr[-1] == ',' |
3103
|
75941
|
100
|
|
|
|
&& ckWARN(WARN_PARENTHESIS)) |
3104
|
|
|
|
|
|
{ |
3105
|
58372
|
|
|
|
|
char *s = PL_parser->bufptr; |
3106
|
|
|
|
|
|
bool sigil = FALSE; |
3107
|
|
|
|
|
|
|
3108
|
|
|
|
|
|
/* some heuristics to detect a potential error */ |
3109
|
147487
|
100
|
|
|
|
while (*s && (strchr(", \t\n", *s))) |
|
|
100
|
|
|
|
|
3110
|
58156
|
|
|
|
|
s++; |
3111
|
|
|
|
|
|
|
3112
|
|
|
|
|
|
while (1) { |
3113
|
64438
|
100
|
|
|
|
if (*s && strchr("@$%*", *s) && *++s |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
3114
|
6070
|
100
|
|
|
|
&& (isWORDCHAR(*s) || UTF8_IS_CONTINUED(*s))) { |
|
|
50
|
|
|
|
|
3115
|
6066
|
|
|
|
|
s++; |
3116
|
|
|
|
|
|
sigil = TRUE; |
3117
|
27187
|
50
|
|
|
|
while (*s && (isWORDCHAR(*s) || UTF8_IS_CONTINUED(*s))) |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
3118
|
18268
|
|
|
|
|
s++; |
3119
|
6324
|
100
|
|
|
|
while (*s && (strchr(", \t\n", *s))) |
|
|
100
|
|
|
|
|
3120
|
258
|
|
|
|
|
s++; |
3121
|
|
|
|
|
|
} |
3122
|
|
|
|
|
|
else |
3123
|
|
|
|
|
|
break; |
3124
|
|
|
|
|
|
} |
3125
|
58372
|
100
|
|
|
|
if (sigil && (*s == ';' || *s == '=')) { |
|
|
100
|
|
|
|
|
3126
|
18
|
100
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_PARENTHESIS), |
3127
|
|
|
|
|
|
"Parentheses missing around \"%s\" list", |
3128
|
|
|
|
|
|
lex |
3129
|
6
|
|
|
|
|
? (PL_parser->in_my == KEY_our |
3130
|
|
|
|
|
|
? "our" |
3131
|
6
|
100
|
|
|
|
: PL_parser->in_my == KEY_state |
3132
|
|
|
|
|
|
? "state" |
3133
|
5
|
50
|
|
|
|
: "my") |
3134
|
|
|
|
|
|
: "local"); |
3135
|
|
|
|
|
|
} |
3136
|
|
|
|
|
|
} |
3137
|
|
|
|
|
|
} |
3138
|
16734877
|
100
|
|
|
|
if (lex) |
3139
|
15722638
|
|
|
|
|
o = my(o); |
3140
|
|
|
|
|
|
else |
3141
|
1012239
|
|
|
|
|
o = op_lvalue(o, OP_NULL); /* a bit kludgey */ |
3142
|
16734873
|
|
|
|
|
PL_parser->in_my = FALSE; |
3143
|
16734873
|
|
|
|
|
PL_parser->in_my_stash = NULL; |
3144
|
16734873
|
|
|
|
|
return o; |
3145
|
|
|
|
|
|
} |
3146
|
|
|
|
|
|
|
3147
|
|
|
|
|
|
OP * |
3148
|
12492836
|
|
|
|
|
Perl_jmaybe(pTHX_ OP *o) |
3149
|
|
|
|
|
|
{ |
3150
|
|
|
|
|
|
PERL_ARGS_ASSERT_JMAYBE; |
3151
|
|
|
|
|
|
|
3152
|
12492836
|
100
|
|
|
|
if (o->op_type == OP_LIST) { |
3153
|
4202
|
|
|
|
|
OP * const o2 |
3154
|
4202
|
|
|
|
|
= newSVREF(newGVOP(OP_GV, 0, gv_fetchpvs(";", GV_ADD|GV_NOTQUAL, SVt_PV))); |
3155
|
4202
|
|
|
|
|
o = convert(OP_JOIN, 0, op_prepend_elem(OP_LIST, o2, o)); |
3156
|
|
|
|
|
|
} |
3157
|
12492836
|
|
|
|
|
return o; |
3158
|
|
|
|
|
|
} |
3159
|
|
|
|
|
|
|
3160
|
|
|
|
|
|
PERL_STATIC_INLINE OP * |
3161
|
253940731
|
|
|
|
|
S_op_std_init(pTHX_ OP *o) |
3162
|
|
|
|
|
|
{ |
3163
|
253940731
|
|
|
|
|
I32 type = o->op_type; |
3164
|
|
|
|
|
|
|
3165
|
|
|
|
|
|
PERL_ARGS_ASSERT_OP_STD_INIT; |
3166
|
|
|
|
|
|
|
3167
|
253940731
|
100
|
|
|
|
if (PL_opargs[type] & OA_RETSCALAR) |
3168
|
111154622
|
|
|
|
|
scalar(o); |
3169
|
253940731
|
100
|
|
|
|
if (PL_opargs[type] & OA_TARGET && !o->op_targ) |
|
|
100
|
|
|
|
|
3170
|
89105812
|
|
|
|
|
o->op_targ = pad_alloc(type, SVs_PADTMP); |
3171
|
|
|
|
|
|
|
3172
|
253940731
|
|
|
|
|
return o; |
3173
|
|
|
|
|
|
} |
3174
|
|
|
|
|
|
|
3175
|
|
|
|
|
|
PERL_STATIC_INLINE OP * |
3176
|
253940731
|
|
|
|
|
S_op_integerize(pTHX_ OP *o) |
3177
|
|
|
|
|
|
{ |
3178
|
253940731
|
|
|
|
|
I32 type = o->op_type; |
3179
|
|
|
|
|
|
|
3180
|
|
|
|
|
|
PERL_ARGS_ASSERT_OP_INTEGERIZE; |
3181
|
|
|
|
|
|
|
3182
|
|
|
|
|
|
/* integerize op. */ |
3183
|
253940731
|
100
|
|
|
|
if ((PL_opargs[type] & OA_OTHERINT) && (PL_hints & HINT_INTEGER)) |
|
|
100
|
|
|
|
|
3184
|
|
|
|
|
|
{ |
3185
|
|
|
|
|
|
dVAR; |
3186
|
311290
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[type = ++(o->op_type)]; |
3187
|
|
|
|
|
|
} |
3188
|
|
|
|
|
|
|
3189
|
253940731
|
100
|
|
|
|
if (type == OP_NEGATE) |
3190
|
|
|
|
|
|
/* XXX might want a ck_negate() for this */ |
3191
|
384770
|
|
|
|
|
cUNOPo->op_first->op_private &= ~OPpCONST_STRICT; |
3192
|
|
|
|
|
|
|
3193
|
253940731
|
|
|
|
|
return o; |
3194
|
|
|
|
|
|
} |
3195
|
|
|
|
|
|
|
3196
|
|
|
|
|
|
static OP * |
3197
|
253940731
|
|
|
|
|
S_fold_constants(pTHX_ OP *o) |
3198
|
|
|
|
|
|
{ |
3199
|
|
|
|
|
|
dVAR; |
3200
|
|
|
|
|
|
OP * VOL curop; |
3201
|
|
|
|
|
|
OP *newop; |
3202
|
253940731
|
|
|
|
|
VOL I32 type = o->op_type; |
3203
|
253940731
|
|
|
|
|
SV * VOL sv = NULL; |
3204
|
|
|
|
|
|
int ret = 0; |
3205
|
|
|
|
|
|
I32 oldscope; |
3206
|
|
|
|
|
|
OP *old_next; |
3207
|
253940731
|
|
|
|
|
SV * const oldwarnhook = PL_warnhook; |
3208
|
253940731
|
|
|
|
|
SV * const olddiehook = PL_diehook; |
3209
|
|
|
|
|
|
COP not_compiling; |
3210
|
|
|
|
|
|
dJMPENV; |
3211
|
|
|
|
|
|
|
3212
|
|
|
|
|
|
PERL_ARGS_ASSERT_FOLD_CONSTANTS; |
3213
|
|
|
|
|
|
|
3214
|
253940731
|
100
|
|
|
|
if (!(PL_opargs[type] & OA_FOLDCONST)) |
3215
|
|
|
|
|
|
goto nope; |
3216
|
|
|
|
|
|
|
3217
|
39682345
|
|
|
|
|
switch (type) { |
3218
|
|
|
|
|
|
case OP_UCFIRST: |
3219
|
|
|
|
|
|
case OP_LCFIRST: |
3220
|
|
|
|
|
|
case OP_UC: |
3221
|
|
|
|
|
|
case OP_LC: |
3222
|
|
|
|
|
|
case OP_FC: |
3223
|
|
|
|
|
|
case OP_SLT: |
3224
|
|
|
|
|
|
case OP_SGT: |
3225
|
|
|
|
|
|
case OP_SLE: |
3226
|
|
|
|
|
|
case OP_SGE: |
3227
|
|
|
|
|
|
case OP_SCMP: |
3228
|
|
|
|
|
|
case OP_SPRINTF: |
3229
|
|
|
|
|
|
/* XXX what about the numeric ops? */ |
3230
|
496893
|
100
|
|
|
|
if (IN_LOCALE_COMPILETIME) |
3231
|
|
|
|
|
|
goto nope; |
3232
|
|
|
|
|
|
break; |
3233
|
|
|
|
|
|
case OP_PACK: |
3234
|
80375
|
100
|
|
|
|
if (!cLISTOPo->op_first->op_sibling |
3235
|
80373
|
100
|
|
|
|
|| cLISTOPo->op_first->op_sibling->op_type != OP_CONST) |
3236
|
|
|
|
|
|
goto nope; |
3237
|
|
|
|
|
|
{ |
3238
|
80187
|
|
|
|
|
SV * const sv = cSVOPx_sv(cLISTOPo->op_first->op_sibling); |
3239
|
80187
|
50
|
|
|
|
if (!SvPOK(sv) || SvGMAGICAL(sv)) goto nope; |
3240
|
|
|
|
|
|
{ |
3241
|
80187
|
|
|
|
|
const char *s = SvPVX_const(sv); |
3242
|
231649
|
100
|
|
|
|
while (s < SvEND(sv)) { |
3243
|
112124
|
100
|
|
|
|
if (*s == 'p' || *s == 'P') goto nope; |
3244
|
112088
|
|
|
|
|
s++; |
3245
|
|
|
|
|
|
} |
3246
|
|
|
|
|
|
} |
3247
|
|
|
|
|
|
} |
3248
|
|
|
|
|
|
break; |
3249
|
|
|
|
|
|
case OP_REPEAT: |
3250
|
200138
|
100
|
|
|
|
if (o->op_private & OPpREPEAT_DOLIST) goto nope; |
3251
|
|
|
|
|
|
} |
3252
|
|
|
|
|
|
|
3253
|
39627831
|
50
|
|
|
|
if (PL_parser && PL_parser->error_count) |
|
|
100
|
|
|
|
|
3254
|
|
|
|
|
|
goto nope; /* Don't try to run w/ errors */ |
3255
|
|
|
|
|
|
|
3256
|
73226583
|
50
|
|
|
|
for (curop = LINKLIST(o); curop != o; curop = LINKLIST(curop)) { |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
3257
|
68007429
|
|
|
|
|
const OPCODE type = curop->op_type; |
3258
|
68007429
|
100
|
|
|
|
if ((type != OP_CONST || (curop->op_private & OPpCONST_BARE)) && |
|
|
100
|
|
|
|
|
3259
|
72454921
|
100
|
|
|
|
type != OP_LIST && |
3260
|
48948691
|
|
|
|
|
type != OP_SCALAR && |
3261
|
72447514
|
100
|
|
|
|
type != OP_NULL && |
3262
|
48943753
|
|
|
|
|
type != OP_PUSHMARK) |
3263
|
|
|
|
|
|
{ |
3264
|
|
|
|
|
|
goto nope; |
3265
|
|
|
|
|
|
} |
3266
|
|
|
|
|
|
} |
3267
|
|
|
|
|
|
|
3268
|
5219154
|
50
|
|
|
|
curop = LINKLIST(o); |
3269
|
5219154
|
|
|
|
|
old_next = o->op_next; |
3270
|
5219154
|
|
|
|
|
o->op_next = 0; |
3271
|
5219154
|
|
|
|
|
PL_op = curop; |
3272
|
|
|
|
|
|
|
3273
|
5219154
|
|
|
|
|
oldscope = PL_scopestack_ix; |
3274
|
5219154
|
|
|
|
|
create_eval_scope(G_FAKINGEVAL); |
3275
|
|
|
|
|
|
|
3276
|
|
|
|
|
|
/* Verify that we don't need to save it: */ |
3277
|
|
|
|
|
|
assert(PL_curcop == &PL_compiling); |
3278
|
5219154
|
|
|
|
|
StructCopy(&PL_compiling, ¬_compiling, COP); |
3279
|
5219154
|
|
|
|
|
PL_curcop = ¬_compiling; |
3280
|
|
|
|
|
|
/* The above ensures that we run with all the correct hints of the |
3281
|
|
|
|
|
|
currently compiling COP, but that IN_PERL_RUNTIME is not true. */ |
3282
|
|
|
|
|
|
assert(IN_PERL_RUNTIME); |
3283
|
5219154
|
|
|
|
|
PL_warnhook = PERL_WARNHOOK_FATAL; |
3284
|
5219154
|
|
|
|
|
PL_diehook = NULL; |
3285
|
5219154
|
|
|
|
|
JMPENV_PUSH(ret); |
3286
|
|
|
|
|
|
|
3287
|
5219300
|
|
|
|
|
switch (ret) { |
3288
|
|
|
|
|
|
case 0: |
3289
|
5219154
|
|
|
|
|
CALLRUNOPS(aTHX); |
3290
|
5219008
|
|
|
|
|
sv = *(PL_stack_sp--); |
3291
|
5219008
|
100
|
|
|
|
if (o->op_targ && sv == PAD_SV(o->op_targ)) { /* grab pad temp? */ |
|
|
100
|
|
|
|
|
3292
|
|
|
|
|
|
#ifdef PERL_MAD |
3293
|
|
|
|
|
|
/* Can't simply swipe the SV from the pad, because that relies on |
3294
|
|
|
|
|
|
the op being freed "real soon now". Under MAD, this doesn't |
3295
|
|
|
|
|
|
happen (see the #ifdef below). */ |
3296
|
|
|
|
|
|
sv = newSVsv(sv); |
3297
|
|
|
|
|
|
#else |
3298
|
5001520
|
|
|
|
|
pad_swipe(o->op_targ, FALSE); |
3299
|
|
|
|
|
|
#endif |
3300
|
|
|
|
|
|
} |
3301
|
217488
|
100
|
|
|
|
else if (SvTEMP(sv)) { /* grab mortal temp? */ |
3302
|
65664
|
50
|
|
|
|
SvREFCNT_inc_simple_void(sv); |
3303
|
65664
|
|
|
|
|
SvTEMP_off(sv); |
3304
|
|
|
|
|
|
} |
3305
|
|
|
|
|
|
else { assert(SvIMMORTAL(sv)); } |
3306
|
|
|
|
|
|
break; |
3307
|
|
|
|
|
|
case 3: |
3308
|
|
|
|
|
|
/* Something tried to die. Abandon constant folding. */ |
3309
|
|
|
|
|
|
/* Pretend the error never happened. */ |
3310
|
146
|
50
|
|
|
|
CLEAR_ERRSV(); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
3311
|
146
|
|
|
|
|
o->op_next = old_next; |
3312
|
146
|
|
|
|
|
break; |
3313
|
|
|
|
|
|
default: |
3314
|
0
|
|
|
|
|
JMPENV_POP; |
3315
|
|
|
|
|
|
/* Don't expect 1 (setjmp failed) or 2 (something called my_exit) */ |
3316
|
0
|
|
|
|
|
PL_warnhook = oldwarnhook; |
3317
|
0
|
|
|
|
|
PL_diehook = olddiehook; |
3318
|
|
|
|
|
|
/* XXX note that this croak may fail as we've already blown away |
3319
|
|
|
|
|
|
* the stack - eg any nested evals */ |
3320
|
0
|
|
|
|
|
Perl_croak(aTHX_ "panic: fold_constants JMPENV_PUSH returned %d", ret); |
3321
|
|
|
|
|
|
} |
3322
|
5219154
|
|
|
|
|
JMPENV_POP; |
3323
|
5219154
|
|
|
|
|
PL_warnhook = oldwarnhook; |
3324
|
5219154
|
|
|
|
|
PL_diehook = olddiehook; |
3325
|
5219154
|
|
|
|
|
PL_curcop = &PL_compiling; |
3326
|
|
|
|
|
|
|
3327
|
5219154
|
100
|
|
|
|
if (PL_scopestack_ix > oldscope) |
3328
|
5219008
|
|
|
|
|
delete_eval_scope(); |
3329
|
|
|
|
|
|
|
3330
|
5219154
|
100
|
|
|
|
if (ret) |
3331
|
|
|
|
|
|
goto nope; |
3332
|
|
|
|
|
|
|
3333
|
|
|
|
|
|
#ifndef PERL_MAD |
3334
|
5219008
|
|
|
|
|
op_free(o); |
3335
|
|
|
|
|
|
#endif |
3336
|
|
|
|
|
|
assert(sv); |
3337
|
5219008
|
100
|
|
|
|
if (type == OP_STRINGIFY) SvPADTMP_off(sv); |
3338
|
1148443
|
100
|
|
|
|
else if (!SvIMMORTAL(sv)) SvPADTMP_on(sv); |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
3339
|
5219008
|
50
|
|
|
|
if (type == OP_RV2GV) |
3340
|
0
|
|
|
|
|
newop = newGVOP(OP_GV, 0, MUTABLE_GV(sv)); |
3341
|
|
|
|
|
|
else |
3342
|
|
|
|
|
|
{ |
3343
|
5219008
|
|
|
|
|
newop = newSVOP(OP_CONST, OPpCONST_FOLDED<<8, MUTABLE_SV(sv)); |
3344
|
5219008
|
|
|
|
|
newop->op_folded = 1; |
3345
|
|
|
|
|
|
} |
3346
|
|
|
|
|
|
op_getmad(o,newop,'f'); |
3347
|
134368624
|
|
|
|
|
return newop; |
3348
|
|
|
|
|
|
|
3349
|
|
|
|
|
|
nope: |
3350
|
|
|
|
|
|
return o; |
3351
|
|
|
|
|
|
} |
3352
|
|
|
|
|
|
|
3353
|
|
|
|
|
|
static OP * |
3354
|
19530
|
|
|
|
|
S_gen_constant_list(pTHX_ OP *o) |
3355
|
|
|
|
|
|
{ |
3356
|
|
|
|
|
|
dVAR; |
3357
|
|
|
|
|
|
OP *curop; |
3358
|
19530
|
|
|
|
|
const SSize_t oldtmps_floor = PL_tmps_floor; |
3359
|
|
|
|
|
|
SV **svp; |
3360
|
|
|
|
|
|
AV *av; |
3361
|
|
|
|
|
|
|
3362
|
19530
|
|
|
|
|
list(o); |
3363
|
19530
|
50
|
|
|
|
if (PL_parser && PL_parser->error_count) |
|
|
50
|
|
|
|
|
3364
|
|
|
|
|
|
return o; /* Don't attempt to run with errors */ |
3365
|
|
|
|
|
|
|
3366
|
19530
|
50
|
|
|
|
PL_op = curop = LINKLIST(o); |
3367
|
19530
|
|
|
|
|
o->op_next = 0; |
3368
|
19530
|
|
|
|
|
CALL_PEEP(curop); |
3369
|
19530
|
|
|
|
|
Perl_pp_pushmark(aTHX); |
3370
|
19530
|
|
|
|
|
CALLRUNOPS(aTHX); |
3371
|
19530
|
|
|
|
|
PL_op = curop; |
3372
|
|
|
|
|
|
assert (!(curop->op_flags & OPf_SPECIAL)); |
3373
|
|
|
|
|
|
assert(curop->op_type == OP_RANGE); |
3374
|
19530
|
|
|
|
|
Perl_pp_anonlist(aTHX); |
3375
|
19530
|
|
|
|
|
PL_tmps_floor = oldtmps_floor; |
3376
|
|
|
|
|
|
|
3377
|
19530
|
|
|
|
|
o->op_type = OP_RV2AV; |
3378
|
19530
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_RV2AV]; |
3379
|
19530
|
|
|
|
|
o->op_flags &= ~OPf_REF; /* treat \(1..2) like an ordinary list */ |
3380
|
19530
|
|
|
|
|
o->op_flags |= OPf_PARENS; /* and flatten \(1..2,3) */ |
3381
|
19530
|
|
|
|
|
o->op_opt = 0; /* needs to be revisited in rpeep() */ |
3382
|
19530
|
|
|
|
|
curop = ((UNOP*)o)->op_first; |
3383
|
19530
|
|
|
|
|
av = (AV *)SvREFCNT_inc_NN(*PL_stack_sp--); |
3384
|
19530
|
|
|
|
|
((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, (SV *)av); |
3385
|
19530
|
100
|
|
|
|
if (AvFILLp(av) != -1) |
3386
|
415302
|
100
|
|
|
|
for (svp = AvARRAY(av) + AvFILLp(av); svp >= AvARRAY(av); --svp) |
3387
|
395780
|
|
|
|
|
SvPADTMP_on(*svp); |
3388
|
|
|
|
|
|
#ifdef PERL_MAD |
3389
|
|
|
|
|
|
op_getmad(curop,o,'O'); |
3390
|
|
|
|
|
|
#else |
3391
|
19530
|
|
|
|
|
op_free(curop); |
3392
|
|
|
|
|
|
#endif |
3393
|
19530
|
50
|
|
|
|
LINKLIST(o); |
3394
|
19530
|
|
|
|
|
return list(o); |
3395
|
|
|
|
|
|
} |
3396
|
|
|
|
|
|
|
3397
|
|
|
|
|
|
OP * |
3398
|
41883678
|
|
|
|
|
Perl_convert(pTHX_ I32 type, I32 flags, OP *o) |
3399
|
|
|
|
|
|
{ |
3400
|
|
|
|
|
|
dVAR; |
3401
|
41883678
|
100
|
|
|
|
if (type < 0) type = -type, flags |= OPf_SPECIAL; |
3402
|
41883678
|
100
|
|
|
|
if (!o || o->op_type != OP_LIST) |
|
|
100
|
|
|
|
|
3403
|
17913601
|
|
|
|
|
o = newLISTOP(OP_LIST, 0, o, NULL); |
3404
|
|
|
|
|
|
else |
3405
|
23970077
|
|
|
|
|
o->op_flags &= ~OPf_WANT; |
3406
|
|
|
|
|
|
|
3407
|
41883678
|
100
|
|
|
|
if (!(PL_opargs[type] & OA_MARK)) |
3408
|
11765191
|
|
|
|
|
op_null(cLISTOPo->op_first); |
3409
|
|
|
|
|
|
else { |
3410
|
30118487
|
|
|
|
|
OP * const kid2 = cLISTOPo->op_first->op_sibling; |
3411
|
30118487
|
100
|
|
|
|
if (kid2 && kid2->op_type == OP_COREARGS) { |
|
|
100
|
|
|
|
|
3412
|
164
|
|
|
|
|
op_null(cLISTOPo->op_first); |
3413
|
164
|
|
|
|
|
kid2->op_private |= OPpCOREARGS_PUSHMARK; |
3414
|
|
|
|
|
|
} |
3415
|
|
|
|
|
|
} |
3416
|
|
|
|
|
|
|
3417
|
41883678
|
|
|
|
|
o->op_type = (OPCODE)type; |
3418
|
41883678
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[type]; |
3419
|
41883678
|
|
|
|
|
o->op_flags |= flags; |
3420
|
|
|
|
|
|
|
3421
|
41883678
|
100
|
|
|
|
o = CHECKOP(type, o); |
|
|
100
|
|
|
|
|
3422
|
41883676
|
100
|
|
|
|
if (o->op_type != (unsigned)type) |
3423
|
|
|
|
|
|
return o; |
3424
|
|
|
|
|
|
|
3425
|
41502827
|
|
|
|
|
return fold_constants(op_integerize(op_std_init(o))); |
3426
|
|
|
|
|
|
} |
3427
|
|
|
|
|
|
|
3428
|
|
|
|
|
|
/* |
3429
|
|
|
|
|
|
=head1 Optree Manipulation Functions |
3430
|
|
|
|
|
|
*/ |
3431
|
|
|
|
|
|
|
3432
|
|
|
|
|
|
/* List constructors */ |
3433
|
|
|
|
|
|
|
3434
|
|
|
|
|
|
/* |
3435
|
|
|
|
|
|
=for apidoc Am|OP *|op_append_elem|I32 optype|OP *first|OP *last |
3436
|
|
|
|
|
|
|
3437
|
|
|
|
|
|
Append an item to the list of ops contained directly within a list-type |
3438
|
|
|
|
|
|
op, returning the lengthened list. I is the list-type op, |
3439
|
|
|
|
|
|
and I is the op to append to the list. I specifies the |
3440
|
|
|
|
|
|
intended opcode for the list. If I is not already a list of the |
3441
|
|
|
|
|
|
right type, it will be upgraded into one. If either I or I |
3442
|
|
|
|
|
|
is null, the other is returned unchanged. |
3443
|
|
|
|
|
|
|
3444
|
|
|
|
|
|
=cut |
3445
|
|
|
|
|
|
*/ |
3446
|
|
|
|
|
|
|
3447
|
|
|
|
|
|
OP * |
3448
|
96651768
|
|
|
|
|
Perl_op_append_elem(pTHX_ I32 type, OP *first, OP *last) |
3449
|
|
|
|
|
|
{ |
3450
|
96651768
|
100
|
|
|
|
if (!first) |
3451
|
|
|
|
|
|
return last; |
3452
|
|
|
|
|
|
|
3453
|
93397526
|
100
|
|
|
|
if (!last) |
3454
|
|
|
|
|
|
return first; |
3455
|
|
|
|
|
|
|
3456
|
92536373
|
100
|
|
|
|
if (first->op_type != (unsigned)type |
3457
|
57287128
|
100
|
|
|
|
|| (type == OP_LIST && (first->op_flags & OPf_PARENS))) |
|
|
100
|
|
|
|
|
3458
|
|
|
|
|
|
{ |
3459
|
35302786
|
|
|
|
|
return newLISTOP(type, 0, first, last); |
3460
|
|
|
|
|
|
} |
3461
|
|
|
|
|
|
|
3462
|
57233587
|
50
|
|
|
|
if (first->op_flags & OPf_KIDS) |
3463
|
57233587
|
|
|
|
|
((LISTOP*)first)->op_last->op_sibling = last; |
3464
|
|
|
|
|
|
else { |
3465
|
0
|
|
|
|
|
first->op_flags |= OPf_KIDS; |
3466
|
0
|
|
|
|
|
((LISTOP*)first)->op_first = last; |
3467
|
|
|
|
|
|
} |
3468
|
57233587
|
|
|
|
|
((LISTOP*)first)->op_last = last; |
3469
|
77512482
|
|
|
|
|
return first; |
3470
|
|
|
|
|
|
} |
3471
|
|
|
|
|
|
|
3472
|
|
|
|
|
|
/* |
3473
|
|
|
|
|
|
=for apidoc Am|OP *|op_append_list|I32 optype|OP *first|OP *last |
3474
|
|
|
|
|
|
|
3475
|
|
|
|
|
|
Concatenate the lists of ops contained directly within two list-type ops, |
3476
|
|
|
|
|
|
returning the combined list. I and I are the list-type ops |
3477
|
|
|
|
|
|
to concatenate. I specifies the intended opcode for the list. |
3478
|
|
|
|
|
|
If either I or I is not already a list of the right type, |
3479
|
|
|
|
|
|
it will be upgraded into one. If either I or I is null, |
3480
|
|
|
|
|
|
the other is returned unchanged. |
3481
|
|
|
|
|
|
|
3482
|
|
|
|
|
|
=cut |
3483
|
|
|
|
|
|
*/ |
3484
|
|
|
|
|
|
|
3485
|
|
|
|
|
|
OP * |
3486
|
103035334
|
|
|
|
|
Perl_op_append_list(pTHX_ I32 type, OP *first, OP *last) |
3487
|
|
|
|
|
|
{ |
3488
|
103035334
|
100
|
|
|
|
if (!first) |
3489
|
|
|
|
|
|
return last; |
3490
|
|
|
|
|
|
|
3491
|
69784380
|
100
|
|
|
|
if (!last) |
3492
|
|
|
|
|
|
return first; |
3493
|
|
|
|
|
|
|
3494
|
41618937
|
100
|
|
|
|
if (first->op_type != (unsigned)type) |
3495
|
596561
|
|
|
|
|
return op_prepend_elem(type, first, last); |
3496
|
|
|
|
|
|
|
3497
|
41022376
|
100
|
|
|
|
if (last->op_type != (unsigned)type) |
3498
|
1509706
|
|
|
|
|
return op_append_elem(type, first, last); |
3499
|
|
|
|
|
|
|
3500
|
39512670
|
|
|
|
|
((LISTOP*)first)->op_last->op_sibling = ((LISTOP*)last)->op_first; |
3501
|
39512670
|
|
|
|
|
((LISTOP*)first)->op_last = ((LISTOP*)last)->op_last; |
3502
|
39512670
|
|
|
|
|
first->op_flags |= (last->op_flags & OPf_KIDS); |
3503
|
|
|
|
|
|
|
3504
|
|
|
|
|
|
#ifdef PERL_MAD |
3505
|
|
|
|
|
|
if (((LISTOP*)last)->op_first && first->op_madprop) { |
3506
|
|
|
|
|
|
MADPROP *mp = ((LISTOP*)last)->op_first->op_madprop; |
3507
|
|
|
|
|
|
if (mp) { |
3508
|
|
|
|
|
|
while (mp->mad_next) |
3509
|
|
|
|
|
|
mp = mp->mad_next; |
3510
|
|
|
|
|
|
mp->mad_next = first->op_madprop; |
3511
|
|
|
|
|
|
} |
3512
|
|
|
|
|
|
else { |
3513
|
|
|
|
|
|
((LISTOP*)last)->op_first->op_madprop = first->op_madprop; |
3514
|
|
|
|
|
|
} |
3515
|
|
|
|
|
|
} |
3516
|
|
|
|
|
|
first->op_madprop = last->op_madprop; |
3517
|
|
|
|
|
|
last->op_madprop = 0; |
3518
|
|
|
|
|
|
#endif |
3519
|
|
|
|
|
|
|
3520
|
|
|
|
|
|
S_op_destroy(aTHX_ last); |
3521
|
|
|
|
|
|
|
3522
|
72387541
|
|
|
|
|
return first; |
3523
|
|
|
|
|
|
} |
3524
|
|
|
|
|
|
|
3525
|
|
|
|
|
|
/* |
3526
|
|
|
|
|
|
=for apidoc Am|OP *|op_prepend_elem|I32 optype|OP *first|OP *last |
3527
|
|
|
|
|
|
|
3528
|
|
|
|
|
|
Prepend an item to the list of ops contained directly within a list-type |
3529
|
|
|
|
|
|
op, returning the lengthened list. I is the op to prepend to the |
3530
|
|
|
|
|
|
list, and I is the list-type op. I specifies the intended |
3531
|
|
|
|
|
|
opcode for the list. If I is not already a list of the right type, |
3532
|
|
|
|
|
|
it will be upgraded into one. If either I or I is null, |
3533
|
|
|
|
|
|
the other is returned unchanged. |
3534
|
|
|
|
|
|
|
3535
|
|
|
|
|
|
=cut |
3536
|
|
|
|
|
|
*/ |
3537
|
|
|
|
|
|
|
3538
|
|
|
|
|
|
OP * |
3539
|
109356336
|
|
|
|
|
Perl_op_prepend_elem(pTHX_ I32 type, OP *first, OP *last) |
3540
|
|
|
|
|
|
{ |
3541
|
109356336
|
100
|
|
|
|
if (!first) |
3542
|
|
|
|
|
|
return last; |
3543
|
|
|
|
|
|
|
3544
|
109356330
|
100
|
|
|
|
if (!last) |
3545
|
|
|
|
|
|
return first; |
3546
|
|
|
|
|
|
|
3547
|
101060003
|
100
|
|
|
|
if (last->op_type == (unsigned)type) { |
3548
|
18414646
|
100
|
|
|
|
if (type == OP_LIST) { /* already a PUSHMARK there */ |
3549
|
3121921
|
|
|
|
|
first->op_sibling = ((LISTOP*)last)->op_first->op_sibling; |
3550
|
3121921
|
|
|
|
|
((LISTOP*)last)->op_first->op_sibling = first; |
3551
|
3121921
|
100
|
|
|
|
if (!(first->op_flags & OPf_PARENS)) |
3552
|
3121719
|
|
|
|
|
last->op_flags &= ~OPf_PARENS; |
3553
|
|
|
|
|
|
} |
3554
|
|
|
|
|
|
else { |
3555
|
15292725
|
100
|
|
|
|
if (!(last->op_flags & OPf_KIDS)) { |
3556
|
3440833
|
|
|
|
|
((LISTOP*)last)->op_last = first; |
3557
|
3440833
|
|
|
|
|
last->op_flags |= OPf_KIDS; |
3558
|
|
|
|
|
|
} |
3559
|
15292725
|
|
|
|
|
first->op_sibling = ((LISTOP*)last)->op_first; |
3560
|
15292725
|
|
|
|
|
((LISTOP*)last)->op_first = first; |
3561
|
|
|
|
|
|
} |
3562
|
18414646
|
|
|
|
|
last->op_flags |= OPf_KIDS; |
3563
|
18414646
|
|
|
|
|
return last; |
3564
|
|
|
|
|
|
} |
3565
|
|
|
|
|
|
|
3566
|
96443063
|
|
|
|
|
return newLISTOP(type, 0, first, last); |
3567
|
|
|
|
|
|
} |
3568
|
|
|
|
|
|
|
3569
|
|
|
|
|
|
/* Constructors */ |
3570
|
|
|
|
|
|
|
3571
|
|
|
|
|
|
#ifdef PERL_MAD |
3572
|
|
|
|
|
|
|
3573
|
|
|
|
|
|
TOKEN * |
3574
|
|
|
|
|
|
Perl_newTOKEN(pTHX_ I32 optype, YYSTYPE lval, MADPROP* madprop) |
3575
|
|
|
|
|
|
{ |
3576
|
|
|
|
|
|
TOKEN *tk; |
3577
|
|
|
|
|
|
Newxz(tk, 1, TOKEN); |
3578
|
|
|
|
|
|
tk->tk_type = (OPCODE)optype; |
3579
|
|
|
|
|
|
tk->tk_type = 12345; |
3580
|
|
|
|
|
|
tk->tk_lval = lval; |
3581
|
|
|
|
|
|
tk->tk_mad = madprop; |
3582
|
|
|
|
|
|
return tk; |
3583
|
|
|
|
|
|
} |
3584
|
|
|
|
|
|
|
3585
|
|
|
|
|
|
void |
3586
|
|
|
|
|
|
Perl_token_free(pTHX_ TOKEN* tk) |
3587
|
|
|
|
|
|
{ |
3588
|
|
|
|
|
|
PERL_ARGS_ASSERT_TOKEN_FREE; |
3589
|
|
|
|
|
|
|
3590
|
|
|
|
|
|
if (tk->tk_type != 12345) |
3591
|
|
|
|
|
|
return; |
3592
|
|
|
|
|
|
mad_free(tk->tk_mad); |
3593
|
|
|
|
|
|
Safefree(tk); |
3594
|
|
|
|
|
|
} |
3595
|
|
|
|
|
|
|
3596
|
|
|
|
|
|
void |
3597
|
|
|
|
|
|
Perl_token_getmad(pTHX_ TOKEN* tk, OP* o, char slot) |
3598
|
|
|
|
|
|
{ |
3599
|
|
|
|
|
|
MADPROP* mp; |
3600
|
|
|
|
|
|
MADPROP* tm; |
3601
|
|
|
|
|
|
|
3602
|
|
|
|
|
|
PERL_ARGS_ASSERT_TOKEN_GETMAD; |
3603
|
|
|
|
|
|
|
3604
|
|
|
|
|
|
if (tk->tk_type != 12345) { |
3605
|
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_MISC), |
3606
|
|
|
|
|
|
"Invalid TOKEN object ignored"); |
3607
|
|
|
|
|
|
return; |
3608
|
|
|
|
|
|
} |
3609
|
|
|
|
|
|
tm = tk->tk_mad; |
3610
|
|
|
|
|
|
if (!tm) |
3611
|
|
|
|
|
|
return; |
3612
|
|
|
|
|
|
|
3613
|
|
|
|
|
|
/* faked up qw list? */ |
3614
|
|
|
|
|
|
if (slot == '(' && |
3615
|
|
|
|
|
|
tm->mad_type == MAD_SV && |
3616
|
|
|
|
|
|
SvPVX((SV *)tm->mad_val)[0] == 'q') |
3617
|
|
|
|
|
|
slot = 'x'; |
3618
|
|
|
|
|
|
|
3619
|
|
|
|
|
|
if (o) { |
3620
|
|
|
|
|
|
mp = o->op_madprop; |
3621
|
|
|
|
|
|
if (mp) { |
3622
|
|
|
|
|
|
for (;;) { |
3623
|
|
|
|
|
|
/* pretend constant fold didn't happen? */ |
3624
|
|
|
|
|
|
if (mp->mad_key == 'f' && |
3625
|
|
|
|
|
|
(o->op_type == OP_CONST || |
3626
|
|
|
|
|
|
o->op_type == OP_GV) ) |
3627
|
|
|
|
|
|
{ |
3628
|
|
|
|
|
|
token_getmad(tk,(OP*)mp->mad_val,slot); |
3629
|
|
|
|
|
|
return; |
3630
|
|
|
|
|
|
} |
3631
|
|
|
|
|
|
if (!mp->mad_next) |
3632
|
|
|
|
|
|
break; |
3633
|
|
|
|
|
|
mp = mp->mad_next; |
3634
|
|
|
|
|
|
} |
3635
|
|
|
|
|
|
mp->mad_next = tm; |
3636
|
|
|
|
|
|
mp = mp->mad_next; |
3637
|
|
|
|
|
|
} |
3638
|
|
|
|
|
|
else { |
3639
|
|
|
|
|
|
o->op_madprop = tm; |
3640
|
|
|
|
|
|
mp = o->op_madprop; |
3641
|
|
|
|
|
|
} |
3642
|
|
|
|
|
|
if (mp->mad_key == 'X') |
3643
|
|
|
|
|
|
mp->mad_key = slot; /* just change the first one */ |
3644
|
|
|
|
|
|
|
3645
|
|
|
|
|
|
tk->tk_mad = 0; |
3646
|
|
|
|
|
|
} |
3647
|
|
|
|
|
|
else |
3648
|
|
|
|
|
|
mad_free(tm); |
3649
|
|
|
|
|
|
Safefree(tk); |
3650
|
|
|
|
|
|
} |
3651
|
|
|
|
|
|
|
3652
|
|
|
|
|
|
void |
3653
|
|
|
|
|
|
Perl_op_getmad_weak(pTHX_ OP* from, OP* o, char slot) |
3654
|
|
|
|
|
|
{ |
3655
|
|
|
|
|
|
MADPROP* mp; |
3656
|
|
|
|
|
|
if (!from) |
3657
|
|
|
|
|
|
return; |
3658
|
|
|
|
|
|
if (o) { |
3659
|
|
|
|
|
|
mp = o->op_madprop; |
3660
|
|
|
|
|
|
if (mp) { |
3661
|
|
|
|
|
|
for (;;) { |
3662
|
|
|
|
|
|
/* pretend constant fold didn't happen? */ |
3663
|
|
|
|
|
|
if (mp->mad_key == 'f' && |
3664
|
|
|
|
|
|
(o->op_type == OP_CONST || |
3665
|
|
|
|
|
|
o->op_type == OP_GV) ) |
3666
|
|
|
|
|
|
{ |
3667
|
|
|
|
|
|
op_getmad(from,(OP*)mp->mad_val,slot); |
3668
|
|
|
|
|
|
return; |
3669
|
|
|
|
|
|
} |
3670
|
|
|
|
|
|
if (!mp->mad_next) |
3671
|
|
|
|
|
|
break; |
3672
|
|
|
|
|
|
mp = mp->mad_next; |
3673
|
|
|
|
|
|
} |
3674
|
|
|
|
|
|
mp->mad_next = newMADPROP(slot,MAD_OP,from,0); |
3675
|
|
|
|
|
|
} |
3676
|
|
|
|
|
|
else { |
3677
|
|
|
|
|
|
o->op_madprop = newMADPROP(slot,MAD_OP,from,0); |
3678
|
|
|
|
|
|
} |
3679
|
|
|
|
|
|
} |
3680
|
|
|
|
|
|
} |
3681
|
|
|
|
|
|
|
3682
|
|
|
|
|
|
void |
3683
|
|
|
|
|
|
Perl_op_getmad(pTHX_ OP* from, OP* o, char slot) |
3684
|
|
|
|
|
|
{ |
3685
|
|
|
|
|
|
MADPROP* mp; |
3686
|
|
|
|
|
|
if (!from) |
3687
|
|
|
|
|
|
return; |
3688
|
|
|
|
|
|
if (o) { |
3689
|
|
|
|
|
|
mp = o->op_madprop; |
3690
|
|
|
|
|
|
if (mp) { |
3691
|
|
|
|
|
|
for (;;) { |
3692
|
|
|
|
|
|
/* pretend constant fold didn't happen? */ |
3693
|
|
|
|
|
|
if (mp->mad_key == 'f' && |
3694
|
|
|
|
|
|
(o->op_type == OP_CONST || |
3695
|
|
|
|
|
|
o->op_type == OP_GV) ) |
3696
|
|
|
|
|
|
{ |
3697
|
|
|
|
|
|
op_getmad(from,(OP*)mp->mad_val,slot); |
3698
|
|
|
|
|
|
return; |
3699
|
|
|
|
|
|
} |
3700
|
|
|
|
|
|
if (!mp->mad_next) |
3701
|
|
|
|
|
|
break; |
3702
|
|
|
|
|
|
mp = mp->mad_next; |
3703
|
|
|
|
|
|
} |
3704
|
|
|
|
|
|
mp->mad_next = newMADPROP(slot,MAD_OP,from,1); |
3705
|
|
|
|
|
|
} |
3706
|
|
|
|
|
|
else { |
3707
|
|
|
|
|
|
o->op_madprop = newMADPROP(slot,MAD_OP,from,1); |
3708
|
|
|
|
|
|
} |
3709
|
|
|
|
|
|
} |
3710
|
|
|
|
|
|
else { |
3711
|
|
|
|
|
|
PerlIO_printf(PerlIO_stderr(), |
3712
|
|
|
|
|
|
"DESTROYING op = %0"UVxf"\n", PTR2UV(from)); |
3713
|
|
|
|
|
|
op_free(from); |
3714
|
|
|
|
|
|
} |
3715
|
|
|
|
|
|
} |
3716
|
|
|
|
|
|
|
3717
|
|
|
|
|
|
void |
3718
|
|
|
|
|
|
Perl_prepend_madprops(pTHX_ MADPROP* mp, OP* o, char slot) |
3719
|
|
|
|
|
|
{ |
3720
|
|
|
|
|
|
MADPROP* tm; |
3721
|
|
|
|
|
|
if (!mp || !o) |
3722
|
|
|
|
|
|
return; |
3723
|
|
|
|
|
|
if (slot) |
3724
|
|
|
|
|
|
mp->mad_key = slot; |
3725
|
|
|
|
|
|
tm = o->op_madprop; |
3726
|
|
|
|
|
|
o->op_madprop = mp; |
3727
|
|
|
|
|
|
for (;;) { |
3728
|
|
|
|
|
|
if (!mp->mad_next) |
3729
|
|
|
|
|
|
break; |
3730
|
|
|
|
|
|
mp = mp->mad_next; |
3731
|
|
|
|
|
|
} |
3732
|
|
|
|
|
|
mp->mad_next = tm; |
3733
|
|
|
|
|
|
} |
3734
|
|
|
|
|
|
|
3735
|
|
|
|
|
|
void |
3736
|
|
|
|
|
|
Perl_append_madprops(pTHX_ MADPROP* tm, OP* o, char slot) |
3737
|
|
|
|
|
|
{ |
3738
|
|
|
|
|
|
if (!o) |
3739
|
|
|
|
|
|
return; |
3740
|
|
|
|
|
|
addmad(tm, &(o->op_madprop), slot); |
3741
|
|
|
|
|
|
} |
3742
|
|
|
|
|
|
|
3743
|
|
|
|
|
|
void |
3744
|
|
|
|
|
|
Perl_addmad(pTHX_ MADPROP* tm, MADPROP** root, char slot) |
3745
|
|
|
|
|
|
{ |
3746
|
|
|
|
|
|
MADPROP* mp; |
3747
|
|
|
|
|
|
if (!tm || !root) |
3748
|
|
|
|
|
|
return; |
3749
|
|
|
|
|
|
if (slot) |
3750
|
|
|
|
|
|
tm->mad_key = slot; |
3751
|
|
|
|
|
|
mp = *root; |
3752
|
|
|
|
|
|
if (!mp) { |
3753
|
|
|
|
|
|
*root = tm; |
3754
|
|
|
|
|
|
return; |
3755
|
|
|
|
|
|
} |
3756
|
|
|
|
|
|
for (;;) { |
3757
|
|
|
|
|
|
if (!mp->mad_next) |
3758
|
|
|
|
|
|
break; |
3759
|
|
|
|
|
|
mp = mp->mad_next; |
3760
|
|
|
|
|
|
} |
3761
|
|
|
|
|
|
mp->mad_next = tm; |
3762
|
|
|
|
|
|
} |
3763
|
|
|
|
|
|
|
3764
|
|
|
|
|
|
MADPROP * |
3765
|
|
|
|
|
|
Perl_newMADsv(pTHX_ char key, SV* sv) |
3766
|
|
|
|
|
|
{ |
3767
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWMADSV; |
3768
|
|
|
|
|
|
|
3769
|
|
|
|
|
|
return newMADPROP(key, MAD_SV, sv, 0); |
3770
|
|
|
|
|
|
} |
3771
|
|
|
|
|
|
|
3772
|
|
|
|
|
|
MADPROP * |
3773
|
|
|
|
|
|
Perl_newMADPROP(pTHX_ char key, char type, void* val, I32 vlen) |
3774
|
|
|
|
|
|
{ |
3775
|
|
|
|
|
|
MADPROP *const mp = (MADPROP *) PerlMemShared_malloc(sizeof(MADPROP)); |
3776
|
|
|
|
|
|
mp->mad_next = 0; |
3777
|
|
|
|
|
|
mp->mad_key = key; |
3778
|
|
|
|
|
|
mp->mad_vlen = vlen; |
3779
|
|
|
|
|
|
mp->mad_type = type; |
3780
|
|
|
|
|
|
mp->mad_val = val; |
3781
|
|
|
|
|
|
/* PerlIO_printf(PerlIO_stderr(), "NEW mp = %0x\n", mp); */ |
3782
|
|
|
|
|
|
return mp; |
3783
|
|
|
|
|
|
} |
3784
|
|
|
|
|
|
|
3785
|
|
|
|
|
|
void |
3786
|
|
|
|
|
|
Perl_mad_free(pTHX_ MADPROP* mp) |
3787
|
|
|
|
|
|
{ |
3788
|
|
|
|
|
|
/* PerlIO_printf(PerlIO_stderr(), "FREE mp = %0x\n", mp); */ |
3789
|
|
|
|
|
|
if (!mp) |
3790
|
|
|
|
|
|
return; |
3791
|
|
|
|
|
|
if (mp->mad_next) |
3792
|
|
|
|
|
|
mad_free(mp->mad_next); |
3793
|
|
|
|
|
|
/* if (PL_parser && PL_parser->lex_state != LEX_NOTPARSING && mp->mad_vlen) |
3794
|
|
|
|
|
|
PerlIO_printf(PerlIO_stderr(), "DESTROYING '%c'=<%s>\n", mp->mad_key & 255, mp->mad_val); */ |
3795
|
|
|
|
|
|
switch (mp->mad_type) { |
3796
|
|
|
|
|
|
case MAD_NULL: |
3797
|
|
|
|
|
|
break; |
3798
|
|
|
|
|
|
case MAD_PV: |
3799
|
|
|
|
|
|
Safefree(mp->mad_val); |
3800
|
|
|
|
|
|
break; |
3801
|
|
|
|
|
|
case MAD_OP: |
3802
|
|
|
|
|
|
if (mp->mad_vlen) /* vlen holds "strong/weak" boolean */ |
3803
|
|
|
|
|
|
op_free((OP*)mp->mad_val); |
3804
|
|
|
|
|
|
break; |
3805
|
|
|
|
|
|
case MAD_SV: |
3806
|
|
|
|
|
|
sv_free(MUTABLE_SV(mp->mad_val)); |
3807
|
|
|
|
|
|
break; |
3808
|
|
|
|
|
|
default: |
3809
|
|
|
|
|
|
PerlIO_printf(PerlIO_stderr(), "Unrecognized mad\n"); |
3810
|
|
|
|
|
|
break; |
3811
|
|
|
|
|
|
} |
3812
|
|
|
|
|
|
PerlMemShared_free(mp); |
3813
|
|
|
|
|
|
} |
3814
|
|
|
|
|
|
|
3815
|
|
|
|
|
|
#endif |
3816
|
|
|
|
|
|
|
3817
|
|
|
|
|
|
/* |
3818
|
|
|
|
|
|
=head1 Optree construction |
3819
|
|
|
|
|
|
|
3820
|
|
|
|
|
|
=for apidoc Am|OP *|newNULLLIST |
3821
|
|
|
|
|
|
|
3822
|
|
|
|
|
|
Constructs, checks, and returns a new C op, which represents an |
3823
|
|
|
|
|
|
empty list expression. |
3824
|
|
|
|
|
|
|
3825
|
|
|
|
|
|
=cut |
3826
|
|
|
|
|
|
*/ |
3827
|
|
|
|
|
|
|
3828
|
|
|
|
|
|
OP * |
3829
|
483602
|
|
|
|
|
Perl_newNULLLIST(pTHX) |
3830
|
|
|
|
|
|
{ |
3831
|
483602
|
|
|
|
|
return newOP(OP_STUB, 0); |
3832
|
|
|
|
|
|
} |
3833
|
|
|
|
|
|
|
3834
|
|
|
|
|
|
static OP * |
3835
|
28100116
|
|
|
|
|
S_force_list(pTHX_ OP *o) |
3836
|
|
|
|
|
|
{ |
3837
|
28100116
|
100
|
|
|
|
if (!o || o->op_type != OP_LIST) |
|
|
100
|
|
|
|
|
3838
|
16002679
|
|
|
|
|
o = newLISTOP(OP_LIST, 0, o, NULL); |
3839
|
28100116
|
|
|
|
|
op_null(o); |
3840
|
28100116
|
|
|
|
|
return o; |
3841
|
|
|
|
|
|
} |
3842
|
|
|
|
|
|
|
3843
|
|
|
|
|
|
/* |
3844
|
|
|
|
|
|
=for apidoc Am|OP *|newLISTOP|I32 type|I32 flags|OP *first|OP *last |
3845
|
|
|
|
|
|
|
3846
|
|
|
|
|
|
Constructs, checks, and returns an op of any list type. I is |
3847
|
|
|
|
|
|
the opcode. I gives the eight bits of C, except that |
3848
|
|
|
|
|
|
C will be set automatically if required. I and I |
3849
|
|
|
|
|
|
supply up to two ops to be direct children of the list op; they are |
3850
|
|
|
|
|
|
consumed by this function and become part of the constructed op tree. |
3851
|
|
|
|
|
|
|
3852
|
|
|
|
|
|
=cut |
3853
|
|
|
|
|
|
*/ |
3854
|
|
|
|
|
|
|
3855
|
|
|
|
|
|
OP * |
3856
|
152353570
|
|
|
|
|
Perl_newLISTOP(pTHX_ I32 type, I32 flags, OP *first, OP *last) |
3857
|
|
|
|
|
|
{ |
3858
|
|
|
|
|
|
dVAR; |
3859
|
|
|
|
|
|
LISTOP *listop; |
3860
|
|
|
|
|
|
|
3861
|
|
|
|
|
|
assert((PL_opargs[type] & OA_CLASS_MASK) == OA_LISTOP); |
3862
|
|
|
|
|
|
|
3863
|
152353570
|
|
|
|
|
NewOp(1101, listop, 1, LISTOP); |
3864
|
|
|
|
|
|
|
3865
|
152353570
|
|
|
|
|
listop->op_type = (OPCODE)type; |
3866
|
152353570
|
|
|
|
|
listop->op_ppaddr = PL_ppaddr[type]; |
3867
|
152353570
|
100
|
|
|
|
if (first || last) |
3868
|
151227728
|
|
|
|
|
flags |= OPf_KIDS; |
3869
|
152353570
|
|
|
|
|
listop->op_flags = (U8)flags; |
3870
|
|
|
|
|
|
|
3871
|
152353570
|
100
|
|
|
|
if (!last && first) |
3872
|
|
|
|
|
|
last = first; |
3873
|
119515466
|
50
|
|
|
|
else if (!first && last) |
3874
|
|
|
|
|
|
first = last; |
3875
|
119515466
|
100
|
|
|
|
else if (first) |
3876
|
118389624
|
|
|
|
|
first->op_sibling = last; |
3877
|
152353570
|
|
|
|
|
listop->op_first = first; |
3878
|
152353570
|
|
|
|
|
listop->op_last = last; |
3879
|
152353570
|
100
|
|
|
|
if (type == OP_LIST) { |
3880
|
72779894
|
|
|
|
|
OP* const pushop = newOP(OP_PUSHMARK, 0); |
3881
|
72779894
|
|
|
|
|
pushop->op_sibling = first; |
3882
|
72779894
|
|
|
|
|
listop->op_first = pushop; |
3883
|
72779894
|
|
|
|
|
listop->op_flags |= OPf_KIDS; |
3884
|
72779894
|
100
|
|
|
|
if (!last) |
3885
|
1125842
|
|
|
|
|
listop->op_last = pushop; |
3886
|
|
|
|
|
|
} |
3887
|
|
|
|
|
|
|
3888
|
152353570
|
100
|
|
|
|
return CHECKOP(type, listop); |
|
|
50
|
|
|
|
|
3889
|
|
|
|
|
|
} |
3890
|
|
|
|
|
|
|
3891
|
|
|
|
|
|
/* |
3892
|
|
|
|
|
|
=for apidoc Am|OP *|newOP|I32 type|I32 flags |
3893
|
|
|
|
|
|
|
3894
|
|
|
|
|
|
Constructs, checks, and returns an op of any base type (any type that |
3895
|
|
|
|
|
|
has no extra fields). I is the opcode. I gives the |
3896
|
|
|
|
|
|
eight bits of C, and, shifted up eight bits, the eight bits |
3897
|
|
|
|
|
|
of C. |
3898
|
|
|
|
|
|
|
3899
|
|
|
|
|
|
=cut |
3900
|
|
|
|
|
|
*/ |
3901
|
|
|
|
|
|
|
3902
|
|
|
|
|
|
OP * |
3903
|
183382813
|
|
|
|
|
Perl_newOP(pTHX_ I32 type, I32 flags) |
3904
|
|
|
|
|
|
{ |
3905
|
|
|
|
|
|
dVAR; |
3906
|
|
|
|
|
|
OP *o; |
3907
|
|
|
|
|
|
|
3908
|
183382813
|
50
|
|
|
|
if (type == -OP_ENTEREVAL) { |
3909
|
|
|
|
|
|
type = OP_ENTEREVAL; |
3910
|
0
|
|
|
|
|
flags |= OPpEVAL_BYTES<<8; |
3911
|
|
|
|
|
|
} |
3912
|
|
|
|
|
|
|
3913
|
|
|
|
|
|
assert((PL_opargs[type] & OA_CLASS_MASK) == OA_BASEOP |
3914
|
|
|
|
|
|
|| (PL_opargs[type] & OA_CLASS_MASK) == OA_BASEOP_OR_UNOP |
3915
|
|
|
|
|
|
|| (PL_opargs[type] & OA_CLASS_MASK) == OA_FILESTATOP |
3916
|
|
|
|
|
|
|| (PL_opargs[type] & OA_CLASS_MASK) == OA_LOOPEXOP); |
3917
|
|
|
|
|
|
|
3918
|
183382813
|
|
|
|
|
NewOp(1101, o, 1, OP); |
3919
|
183382813
|
|
|
|
|
o->op_type = (OPCODE)type; |
3920
|
183382813
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[type]; |
3921
|
183382813
|
|
|
|
|
o->op_flags = (U8)flags; |
3922
|
|
|
|
|
|
|
3923
|
183382813
|
|
|
|
|
o->op_next = o; |
3924
|
183382813
|
|
|
|
|
o->op_private = (U8)(0 | (flags >> 8)); |
3925
|
183382813
|
100
|
|
|
|
if (PL_opargs[type] & OA_RETSCALAR) |
3926
|
80409920
|
|
|
|
|
scalar(o); |
3927
|
183382813
|
100
|
|
|
|
if (PL_opargs[type] & OA_TARGET) |
3928
|
291899
|
|
|
|
|
o->op_targ = pad_alloc(type, SVs_PADTMP); |
3929
|
183382813
|
100
|
|
|
|
return CHECKOP(type, o); |
|
|
50
|
|
|
|
|
3930
|
|
|
|
|
|
} |
3931
|
|
|
|
|
|
|
3932
|
|
|
|
|
|
/* |
3933
|
|
|
|
|
|
=for apidoc Am|OP *|newUNOP|I32 type|I32 flags|OP *first |
3934
|
|
|
|
|
|
|
3935
|
|
|
|
|
|
Constructs, checks, and returns an op of any unary type. I is |
3936
|
|
|
|
|
|
the opcode. I gives the eight bits of C, except that |
3937
|
|
|
|
|
|
C will be set automatically if required, and, shifted up eight |
3938
|
|
|
|
|
|
bits, the eight bits of C, except that the bit with value 1 |
3939
|
|
|
|
|
|
is automatically set. I supplies an optional op to be the direct |
3940
|
|
|
|
|
|
child of the unary op; it is consumed by this function and become part |
3941
|
|
|
|
|
|
of the constructed op tree. |
3942
|
|
|
|
|
|
|
3943
|
|
|
|
|
|
=cut |
3944
|
|
|
|
|
|
*/ |
3945
|
|
|
|
|
|
|
3946
|
|
|
|
|
|
OP * |
3947
|
153962874
|
|
|
|
|
Perl_newUNOP(pTHX_ I32 type, I32 flags, OP *first) |
3948
|
|
|
|
|
|
{ |
3949
|
|
|
|
|
|
dVAR; |
3950
|
|
|
|
|
|
UNOP *unop; |
3951
|
|
|
|
|
|
|
3952
|
153962874
|
100
|
|
|
|
if (type == -OP_ENTEREVAL) { |
3953
|
|
|
|
|
|
type = OP_ENTEREVAL; |
3954
|
42
|
|
|
|
|
flags |= OPpEVAL_BYTES<<8; |
3955
|
|
|
|
|
|
} |
3956
|
|
|
|
|
|
|
3957
|
|
|
|
|
|
assert((PL_opargs[type] & OA_CLASS_MASK) == OA_UNOP |
3958
|
|
|
|
|
|
|| (PL_opargs[type] & OA_CLASS_MASK) == OA_BASEOP_OR_UNOP |
3959
|
|
|
|
|
|
|| (PL_opargs[type] & OA_CLASS_MASK) == OA_FILESTATOP |
3960
|
|
|
|
|
|
|| (PL_opargs[type] & OA_CLASS_MASK) == OA_LOOPEXOP |
3961
|
|
|
|
|
|
|| type == OP_SASSIGN |
3962
|
|
|
|
|
|
|| type == OP_ENTERTRY |
3963
|
|
|
|
|
|
|| type == OP_NULL ); |
3964
|
|
|
|
|
|
|
3965
|
153962874
|
50
|
|
|
|
if (!first) |
3966
|
0
|
|
|
|
|
first = newOP(OP_STUB, 0); |
3967
|
153962874
|
100
|
|
|
|
if (PL_opargs[type] & OA_MARK) |
3968
|
14614407
|
|
|
|
|
first = force_list(first); |
3969
|
|
|
|
|
|
|
3970
|
153962874
|
|
|
|
|
NewOp(1101, unop, 1, UNOP); |
3971
|
153962874
|
|
|
|
|
unop->op_type = (OPCODE)type; |
3972
|
153962874
|
|
|
|
|
unop->op_ppaddr = PL_ppaddr[type]; |
3973
|
153962874
|
|
|
|
|
unop->op_first = first; |
3974
|
153962874
|
|
|
|
|
unop->op_flags = (U8)(flags | OPf_KIDS); |
3975
|
153962874
|
|
|
|
|
unop->op_private = (U8)(1 | (flags >> 8)); |
3976
|
153962874
|
100
|
|
|
|
unop = (UNOP*) CHECKOP(type, unop); |
|
|
100
|
|
|
|
|
3977
|
153962820
|
100
|
|
|
|
if (unop->op_next) |
3978
|
|
|
|
|
|
return (OP*)unop; |
3979
|
|
|
|
|
|
|
3980
|
148097258
|
|
|
|
|
return fold_constants(op_integerize(op_std_init((OP *) unop))); |
3981
|
|
|
|
|
|
} |
3982
|
|
|
|
|
|
|
3983
|
|
|
|
|
|
/* |
3984
|
|
|
|
|
|
=for apidoc Am|OP *|newBINOP|I32 type|I32 flags|OP *first|OP *last |
3985
|
|
|
|
|
|
|
3986
|
|
|
|
|
|
Constructs, checks, and returns an op of any binary type. I |
3987
|
|
|
|
|
|
is the opcode. I gives the eight bits of C, except |
3988
|
|
|
|
|
|
that C will be set automatically, and, shifted up eight bits, |
3989
|
|
|
|
|
|
the eight bits of C, except that the bit with value 1 or |
3990
|
|
|
|
|
|
2 is automatically set as required. I and I supply up to |
3991
|
|
|
|
|
|
two ops to be the direct children of the binary op; they are consumed |
3992
|
|
|
|
|
|
by this function and become part of the constructed op tree. |
3993
|
|
|
|
|
|
|
3994
|
|
|
|
|
|
=cut |
3995
|
|
|
|
|
|
*/ |
3996
|
|
|
|
|
|
|
3997
|
|
|
|
|
|
OP * |
3998
|
71431726
|
|
|
|
|
Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last) |
3999
|
|
|
|
|
|
{ |
4000
|
|
|
|
|
|
dVAR; |
4001
|
|
|
|
|
|
BINOP *binop; |
4002
|
|
|
|
|
|
|
4003
|
|
|
|
|
|
assert((PL_opargs[type] & OA_CLASS_MASK) == OA_BINOP |
4004
|
|
|
|
|
|
|| type == OP_SASSIGN || type == OP_NULL ); |
4005
|
|
|
|
|
|
|
4006
|
71431726
|
|
|
|
|
NewOp(1101, binop, 1, BINOP); |
4007
|
|
|
|
|
|
|
4008
|
71431726
|
50
|
|
|
|
if (!first) |
4009
|
0
|
|
|
|
|
first = newOP(OP_NULL, 0); |
4010
|
|
|
|
|
|
|
4011
|
71431726
|
|
|
|
|
binop->op_type = (OPCODE)type; |
4012
|
71431726
|
|
|
|
|
binop->op_ppaddr = PL_ppaddr[type]; |
4013
|
71431726
|
|
|
|
|
binop->op_first = first; |
4014
|
71431726
|
|
|
|
|
binop->op_flags = (U8)(flags | OPf_KIDS); |
4015
|
71431726
|
50
|
|
|
|
if (!last) { |
4016
|
|
|
|
|
|
last = first; |
4017
|
0
|
|
|
|
|
binop->op_private = (U8)(1 | (flags >> 8)); |
4018
|
|
|
|
|
|
} |
4019
|
|
|
|
|
|
else { |
4020
|
71431726
|
|
|
|
|
binop->op_private = (U8)(2 | (flags >> 8)); |
4021
|
71431726
|
|
|
|
|
first->op_sibling = last; |
4022
|
|
|
|
|
|
} |
4023
|
|
|
|
|
|
|
4024
|
71431726
|
100
|
|
|
|
binop = (BINOP*)CHECKOP(type, binop); |
|
|
100
|
|
|
|
|
4025
|
71431722
|
100
|
|
|
|
if (binop->op_next || binop->op_type != (OPCODE)type) |
|
|
100
|
|
|
|
|
4026
|
|
|
|
|
|
return (OP*)binop; |
4027
|
|
|
|
|
|
|
4028
|
70836770
|
|
|
|
|
binop->op_last = binop->op_first->op_sibling; |
4029
|
|
|
|
|
|
|
4030
|
71140365
|
|
|
|
|
return fold_constants(op_integerize(op_std_init((OP *)binop))); |
4031
|
|
|
|
|
|
} |
4032
|
|
|
|
|
|
|
4033
|
|
|
|
|
|
static int uvcompare(const void *a, const void *b) |
4034
|
|
|
|
|
|
__attribute__nonnull__(1) |
4035
|
|
|
|
|
|
__attribute__nonnull__(2) |
4036
|
|
|
|
|
|
__attribute__pure__; |
4037
|
4102
|
|
|
|
|
static int uvcompare(const void *a, const void *b) |
4038
|
|
|
|
|
|
{ |
4039
|
4102
|
50
|
|
|
|
if (*((const UV *)a) < (*(const UV *)b)) |
4040
|
|
|
|
|
|
return -1; |
4041
|
0
|
0
|
|
|
|
if (*((const UV *)a) > (*(const UV *)b)) |
4042
|
|
|
|
|
|
return 1; |
4043
|
0
|
0
|
|
|
|
if (*((const UV *)a+1) < (*(const UV *)b+1)) |
4044
|
|
|
|
|
|
return -1; |
4045
|
0
|
0
|
|
|
|
if (*((const UV *)a+1) > (*(const UV *)b+1)) |
4046
|
|
|
|
|
|
return 1; |
4047
|
2051
|
|
|
|
|
return 0; |
4048
|
|
|
|
|
|
} |
4049
|
|
|
|
|
|
|
4050
|
|
|
|
|
|
static OP * |
4051
|
84040
|
|
|
|
|
S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl) |
4052
|
|
|
|
|
|
{ |
4053
|
|
|
|
|
|
dVAR; |
4054
|
84040
|
|
|
|
|
SV * const tstr = ((SVOP*)expr)->op_sv; |
4055
|
84040
|
|
|
|
|
SV * const rstr = |
4056
|
|
|
|
|
|
#ifdef PERL_MAD |
4057
|
|
|
|
|
|
(repl->op_type == OP_NULL) |
4058
|
|
|
|
|
|
? ((SVOP*)((LISTOP*)repl)->op_first)->op_sv : |
4059
|
|
|
|
|
|
#endif |
4060
|
|
|
|
|
|
((SVOP*)repl)->op_sv; |
4061
|
|
|
|
|
|
STRLEN tlen; |
4062
|
|
|
|
|
|
STRLEN rlen; |
4063
|
84040
|
100
|
|
|
|
const U8 *t = (U8*)SvPV_const(tstr, tlen); |
4064
|
84040
|
50
|
|
|
|
const U8 *r = (U8*)SvPV_const(rstr, rlen); |
4065
|
|
|
|
|
|
I32 i; |
4066
|
|
|
|
|
|
I32 j; |
4067
|
|
|
|
|
|
I32 grows = 0; |
4068
|
|
|
|
|
|
short *tbl; |
4069
|
|
|
|
|
|
|
4070
|
84040
|
|
|
|
|
const I32 complement = o->op_private & OPpTRANS_COMPLEMENT; |
4071
|
84040
|
|
|
|
|
const I32 squash = o->op_private & OPpTRANS_SQUASH; |
4072
|
84040
|
|
|
|
|
I32 del = o->op_private & OPpTRANS_DELETE; |
4073
|
|
|
|
|
|
SV* swash; |
4074
|
|
|
|
|
|
|
4075
|
|
|
|
|
|
PERL_ARGS_ASSERT_PMTRANS; |
4076
|
|
|
|
|
|
|
4077
|
84040
|
|
|
|
|
PL_hints |= HINT_BLOCK_SCOPE; |
4078
|
|
|
|
|
|
|
4079
|
84040
|
100
|
|
|
|
if (SvUTF8(tstr)) |
4080
|
106
|
|
|
|
|
o->op_private |= OPpTRANS_FROM_UTF; |
4081
|
|
|
|
|
|
|
4082
|
84040
|
100
|
|
|
|
if (SvUTF8(rstr)) |
4083
|
110
|
|
|
|
|
o->op_private |= OPpTRANS_TO_UTF; |
4084
|
|
|
|
|
|
|
4085
|
84040
|
100
|
|
|
|
if (o->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF)) { |
4086
|
124
|
|
|
|
|
SV* const listsv = newSVpvs("# comment\n"); |
4087
|
|
|
|
|
|
SV* transv = NULL; |
4088
|
124
|
|
|
|
|
const U8* tend = t + tlen; |
4089
|
124
|
|
|
|
|
const U8* rend = r + rlen; |
4090
|
|
|
|
|
|
STRLEN ulen; |
4091
|
|
|
|
|
|
UV tfirst = 1; |
4092
|
|
|
|
|
|
UV tlast = 0; |
4093
|
|
|
|
|
|
IV tdiff; |
4094
|
|
|
|
|
|
UV rfirst = 1; |
4095
|
|
|
|
|
|
UV rlast = 0; |
4096
|
|
|
|
|
|
IV rdiff; |
4097
|
|
|
|
|
|
IV diff; |
4098
|
|
|
|
|
|
I32 none = 0; |
4099
|
|
|
|
|
|
U32 max = 0; |
4100
|
|
|
|
|
|
I32 bits; |
4101
|
|
|
|
|
|
I32 havefinal = 0; |
4102
|
|
|
|
|
|
U32 final = 0; |
4103
|
124
|
|
|
|
|
const I32 from_utf = o->op_private & OPpTRANS_FROM_UTF; |
4104
|
124
|
|
|
|
|
const I32 to_utf = o->op_private & OPpTRANS_TO_UTF; |
4105
|
|
|
|
|
|
U8* tsave = NULL; |
4106
|
|
|
|
|
|
U8* rsave = NULL; |
4107
|
124
|
100
|
|
|
|
const U32 flags = UTF8_ALLOW_DEFAULT; |
4108
|
|
|
|
|
|
|
4109
|
124
|
100
|
|
|
|
if (!from_utf) { |
4110
|
18
|
|
|
|
|
STRLEN len = tlen; |
4111
|
18
|
|
|
|
|
t = tsave = bytes_to_utf8(t, &len); |
4112
|
18
|
|
|
|
|
tend = t + len; |
4113
|
|
|
|
|
|
} |
4114
|
124
|
100
|
|
|
|
if (!to_utf && rlen) { |
|
|
50
|
|
|
|
|
4115
|
0
|
|
|
|
|
STRLEN len = rlen; |
4116
|
0
|
|
|
|
|
r = rsave = bytes_to_utf8(r, &len); |
4117
|
0
|
|
|
|
|
rend = r + len; |
4118
|
|
|
|
|
|
} |
4119
|
|
|
|
|
|
|
4120
|
|
|
|
|
|
/* There is a snag with this code on EBCDIC: scan_const() in toke.c has |
4121
|
|
|
|
|
|
* encoded chars in native encoding which makes ranges in the EBCDIC 0..255 |
4122
|
|
|
|
|
|
* odd. */ |
4123
|
|
|
|
|
|
|
4124
|
124
|
100
|
|
|
|
if (complement) { |
4125
|
|
|
|
|
|
U8 tmpbuf[UTF8_MAXBYTES+1]; |
4126
|
|
|
|
|
|
UV *cp; |
4127
|
|
|
|
|
|
UV nextmin = 0; |
4128
|
20
|
50
|
|
|
|
Newx(cp, 2*tlen, UV); |
4129
|
|
|
|
|
|
i = 0; |
4130
|
20
|
|
|
|
|
transv = newSVpvs(""); |
4131
|
1076
|
100
|
|
|
|
while (t < tend) { |
4132
|
1046
|
|
|
|
|
cp[2*i] = utf8n_to_uvchr(t, tend-t, &ulen, flags); |
4133
|
1046
|
|
|
|
|
t += ulen; |
4134
|
1046
|
100
|
|
|
|
if (t < tend && *t == ILLEGAL_UTF8_BYTE) { |
|
|
100
|
|
|
|
|
4135
|
10
|
|
|
|
|
t++; |
4136
|
10
|
|
|
|
|
cp[2*i+1] = utf8n_to_uvchr(t, tend-t, &ulen, flags); |
4137
|
10
|
|
|
|
|
t += ulen; |
4138
|
|
|
|
|
|
} |
4139
|
|
|
|
|
|
else { |
4140
|
1036
|
|
|
|
|
cp[2*i+1] = cp[2*i]; |
4141
|
|
|
|
|
|
} |
4142
|
1046
|
|
|
|
|
i++; |
4143
|
|
|
|
|
|
} |
4144
|
20
|
|
|
|
|
qsort(cp, i, 2*sizeof(UV), uvcompare); |
4145
|
1066
|
100
|
|
|
|
for (j = 0; j < i; j++) { |
4146
|
1046
|
|
|
|
|
UV val = cp[2*j]; |
4147
|
1046
|
|
|
|
|
diff = val - nextmin; |
4148
|
1046
|
100
|
|
|
|
if (diff > 0) { |
4149
|
14
|
|
|
|
|
t = uvchr_to_utf8(tmpbuf,nextmin); |
4150
|
14
|
|
|
|
|
sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf); |
4151
|
14
|
100
|
|
|
|
if (diff > 1) { |
4152
|
10
|
|
|
|
|
U8 range_mark = ILLEGAL_UTF8_BYTE; |
4153
|
10
|
|
|
|
|
t = uvchr_to_utf8(tmpbuf, val - 1); |
4154
|
10
|
|
|
|
|
sv_catpvn(transv, (char *)&range_mark, 1); |
4155
|
10
|
|
|
|
|
sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf); |
4156
|
|
|
|
|
|
} |
4157
|
|
|
|
|
|
} |
4158
|
1046
|
|
|
|
|
val = cp[2*j+1]; |
4159
|
1046
|
50
|
|
|
|
if (val >= nextmin) |
4160
|
1046
|
|
|
|
|
nextmin = val + 1; |
4161
|
|
|
|
|
|
} |
4162
|
20
|
|
|
|
|
t = uvchr_to_utf8(tmpbuf,nextmin); |
4163
|
20
|
|
|
|
|
sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf); |
4164
|
|
|
|
|
|
{ |
4165
|
20
|
|
|
|
|
U8 range_mark = ILLEGAL_UTF8_BYTE; |
4166
|
20
|
|
|
|
|
sv_catpvn(transv, (char *)&range_mark, 1); |
4167
|
|
|
|
|
|
} |
4168
|
20
|
|
|
|
|
t = uvchr_to_utf8(tmpbuf, 0x7fffffff); |
4169
|
20
|
|
|
|
|
sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf); |
4170
|
20
|
|
|
|
|
t = (const U8*)SvPVX_const(transv); |
4171
|
20
|
|
|
|
|
tlen = SvCUR(transv); |
4172
|
20
|
|
|
|
|
tend = t + tlen; |
4173
|
20
|
|
|
|
|
Safefree(cp); |
4174
|
|
|
|
|
|
} |
4175
|
104
|
100
|
|
|
|
else if (!rlen && !del) { |
4176
|
6
|
|
|
|
|
r = t; rlen = tlen; rend = tend; |
4177
|
|
|
|
|
|
} |
4178
|
124
|
100
|
|
|
|
if (!squash) { |
4179
|
162
|
100
|
|
|
|
if ((!rlen && !del) || t == r || |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
4180
|
114
|
100
|
|
|
|
(tlen == rlen && memEQ((char *)t, (char *)r, tlen))) |
4181
|
|
|
|
|
|
{ |
4182
|
68
|
|
|
|
|
o->op_private |= OPpTRANS_IDENTICAL; |
4183
|
|
|
|
|
|
} |
4184
|
|
|
|
|
|
} |
4185
|
|
|
|
|
|
|
4186
|
370
|
100
|
|
|
|
while (t < tend || tfirst <= tlast) { |
4187
|
|
|
|
|
|
/* see if we need more "t" chars */ |
4188
|
246
|
100
|
|
|
|
if (tfirst > tlast) { |
4189
|
228
|
|
|
|
|
tfirst = (I32)utf8n_to_uvchr(t, tend - t, &ulen, flags); |
4190
|
228
|
|
|
|
|
t += ulen; |
4191
|
228
|
100
|
|
|
|
if (t < tend && *t == ILLEGAL_UTF8_BYTE) { /* illegal utf8 val indicates range */ |
|
|
100
|
|
|
|
|
4192
|
72
|
|
|
|
|
t++; |
4193
|
72
|
|
|
|
|
tlast = (I32)utf8n_to_uvchr(t, tend - t, &ulen, flags); |
4194
|
72
|
|
|
|
|
t += ulen; |
4195
|
|
|
|
|
|
} |
4196
|
|
|
|
|
|
else |
4197
|
|
|
|
|
|
tlast = tfirst; |
4198
|
|
|
|
|
|
} |
4199
|
|
|
|
|
|
|
4200
|
|
|
|
|
|
/* now see if we need more "r" chars */ |
4201
|
246
|
100
|
|
|
|
if (rfirst > rlast) { |
4202
|
222
|
100
|
|
|
|
if (r < rend) { |
4203
|
190
|
|
|
|
|
rfirst = (I32)utf8n_to_uvchr(r, rend - r, &ulen, flags); |
4204
|
190
|
|
|
|
|
r += ulen; |
4205
|
190
|
100
|
|
|
|
if (r < rend && *r == ILLEGAL_UTF8_BYTE) { /* illegal utf8 val indicates range */ |
|
|
100
|
|
|
|
|
4206
|
42
|
|
|
|
|
r++; |
4207
|
42
|
|
|
|
|
rlast = (I32)utf8n_to_uvchr(r, rend - r, &ulen, flags); |
4208
|
42
|
|
|
|
|
r += ulen; |
4209
|
|
|
|
|
|
} |
4210
|
|
|
|
|
|
else |
4211
|
|
|
|
|
|
rlast = rfirst; |
4212
|
|
|
|
|
|
} |
4213
|
|
|
|
|
|
else { |
4214
|
32
|
50
|
|
|
|
if (!havefinal++) |
4215
|
32
|
|
|
|
|
final = rlast; |
4216
|
|
|
|
|
|
rfirst = rlast = 0xffffffff; |
4217
|
|
|
|
|
|
} |
4218
|
|
|
|
|
|
} |
4219
|
|
|
|
|
|
|
4220
|
|
|
|
|
|
/* now see which range will peter our first, if either. */ |
4221
|
246
|
|
|
|
|
tdiff = tlast - tfirst; |
4222
|
246
|
|
|
|
|
rdiff = rlast - rfirst; |
4223
|
|
|
|
|
|
|
4224
|
246
|
100
|
|
|
|
if (tdiff <= rdiff) |
4225
|
|
|
|
|
|
diff = tdiff; |
4226
|
|
|
|
|
|
else |
4227
|
|
|
|
|
|
diff = rdiff; |
4228
|
|
|
|
|
|
|
4229
|
246
|
100
|
|
|
|
if (rfirst == 0xffffffff) { |
4230
|
|
|
|
|
|
diff = tdiff; /* oops, pretend rdiff is infinite */ |
4231
|
44
|
100
|
|
|
|
if (diff > 0) |
4232
|
32
|
|
|
|
|
Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\tXXXX\n", |
4233
|
|
|
|
|
|
(long)tfirst, (long)tlast); |
4234
|
|
|
|
|
|
else |
4235
|
12
|
|
|
|
|
Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\tXXXX\n", (long)tfirst); |
4236
|
|
|
|
|
|
} |
4237
|
|
|
|
|
|
else { |
4238
|
202
|
100
|
|
|
|
if (diff > 0) |
4239
|
57
|
|
|
|
|
Perl_sv_catpvf(aTHX_ listsv, "%04lx\t%04lx\t%04lx\n", |
4240
|
38
|
|
|
|
|
(long)tfirst, (long)(tfirst + diff), |
4241
|
|
|
|
|
|
(long)rfirst); |
4242
|
|
|
|
|
|
else |
4243
|
164
|
|
|
|
|
Perl_sv_catpvf(aTHX_ listsv, "%04lx\t\t%04lx\n", |
4244
|
|
|
|
|
|
(long)tfirst, (long)rfirst); |
4245
|
|
|
|
|
|
|
4246
|
202
|
100
|
|
|
|
if (rfirst + diff > max) |
4247
|
146
|
|
|
|
|
max = rfirst + diff; |
4248
|
202
|
100
|
|
|
|
if (!grows) |
4249
|
224
|
100
|
|
|
|
grows = (tfirst < rfirst && |
|
|
100
|
|
|
|
|
4250
|
80
|
100
|
|
|
|
UNISKIP(tfirst) < UNISKIP(rfirst + diff)); |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
4251
|
202
|
|
|
|
|
rfirst += diff + 1; |
4252
|
|
|
|
|
|
} |
4253
|
246
|
|
|
|
|
tfirst += diff + 1; |
4254
|
|
|
|
|
|
} |
4255
|
|
|
|
|
|
|
4256
|
124
|
|
|
|
|
none = ++max; |
4257
|
124
|
100
|
|
|
|
if (del) |
4258
|
6
|
|
|
|
|
del = ++max; |
4259
|
|
|
|
|
|
|
4260
|
124
|
100
|
|
|
|
if (max > 0xffff) |
4261
|
|
|
|
|
|
bits = 32; |
4262
|
110
|
100
|
|
|
|
else if (max > 0xff) |
4263
|
|
|
|
|
|
bits = 16; |
4264
|
|
|
|
|
|
else |
4265
|
|
|
|
|
|
bits = 8; |
4266
|
|
|
|
|
|
|
4267
|
124
|
|
|
|
|
swash = MUTABLE_SV(swash_init("utf8", "", listsv, bits, none)); |
4268
|
|
|
|
|
|
#ifdef USE_ITHREADS |
4269
|
|
|
|
|
|
cPADOPo->op_padix = pad_alloc(OP_TRANS, SVf_READONLY); |
4270
|
|
|
|
|
|
SvREFCNT_dec(PAD_SVl(cPADOPo->op_padix)); |
4271
|
|
|
|
|
|
PAD_SETSV(cPADOPo->op_padix, swash); |
4272
|
|
|
|
|
|
SvPADTMP_on(swash); |
4273
|
|
|
|
|
|
SvREADONLY_on(swash); |
4274
|
|
|
|
|
|
#else |
4275
|
124
|
|
|
|
|
cSVOPo->op_sv = swash; |
4276
|
|
|
|
|
|
#endif |
4277
|
124
|
|
|
|
|
SvREFCNT_dec(listsv); |
4278
|
124
|
|
|
|
|
SvREFCNT_dec(transv); |
4279
|
|
|
|
|
|
|
4280
|
124
|
100
|
|
|
|
if (!del && havefinal && rlen) |
|
|
100
|
|
|
|
|
4281
|
22
|
|
|
|
|
(void)hv_store(MUTABLE_HV(SvRV(swash)), "FINAL", 5, |
4282
|
|
|
|
|
|
newSVuv((UV)final), 0); |
4283
|
|
|
|
|
|
|
4284
|
124
|
100
|
|
|
|
if (grows) |
4285
|
20
|
|
|
|
|
o->op_private |= OPpTRANS_GROWS; |
4286
|
|
|
|
|
|
|
4287
|
124
|
|
|
|
|
Safefree(tsave); |
4288
|
124
|
|
|
|
|
Safefree(rsave); |
4289
|
|
|
|
|
|
|
4290
|
|
|
|
|
|
#ifdef PERL_MAD |
4291
|
|
|
|
|
|
op_getmad(expr,o,'e'); |
4292
|
|
|
|
|
|
op_getmad(repl,o,'r'); |
4293
|
|
|
|
|
|
#else |
4294
|
124
|
|
|
|
|
op_free(expr); |
4295
|
124
|
|
|
|
|
op_free(repl); |
4296
|
|
|
|
|
|
#endif |
4297
|
124
|
|
|
|
|
return o; |
4298
|
|
|
|
|
|
} |
4299
|
|
|
|
|
|
|
4300
|
83916
|
100
|
|
|
|
tbl = (short*)PerlMemShared_calloc( |
|
|
100
|
|
|
|
|
4301
|
|
|
|
|
|
(o->op_private & OPpTRANS_COMPLEMENT) && |
4302
|
|
|
|
|
|
!(o->op_private & OPpTRANS_DELETE) ? 258 : 256, |
4303
|
|
|
|
|
|
sizeof(short)); |
4304
|
83916
|
|
|
|
|
cPVOPo->op_pv = (char*)tbl; |
4305
|
83916
|
100
|
|
|
|
if (complement) { |
4306
|
1514986
|
100
|
|
|
|
for (i = 0; i < (I32)tlen; i++) |
4307
|
1510706
|
|
|
|
|
tbl[t[i]] = -1; |
4308
|
2103480
|
100
|
|
|
|
for (i = 0, j = 0; i < 256; i++) { |
4309
|
2099200
|
100
|
|
|
|
if (!tbl[i]) { |
4310
|
588494
|
100
|
|
|
|
if (j >= (I32)rlen) { |
4311
|
588490
|
100
|
|
|
|
if (del) |
4312
|
205198
|
|
|
|
|
tbl[i] = -2; |
4313
|
383292
|
100
|
|
|
|
else if (rlen) |
4314
|
1018
|
|
|
|
|
tbl[i] = r[j-1]; |
4315
|
|
|
|
|
|
else |
4316
|
382274
|
|
|
|
|
tbl[i] = (short)i; |
4317
|
|
|
|
|
|
} |
4318
|
|
|
|
|
|
else { |
4319
|
4
|
50
|
|
|
|
if (i < 128 && r[j] >= 128) |
|
|
50
|
|
|
|
|
4320
|
|
|
|
|
|
grows = 1; |
4321
|
4
|
|
|
|
|
tbl[i] = r[j++]; |
4322
|
|
|
|
|
|
} |
4323
|
|
|
|
|
|
} |
4324
|
|
|
|
|
|
} |
4325
|
8200
|
100
|
|
|
|
if (!del) { |
4326
|
7214
|
100
|
|
|
|
if (!rlen) { |
4327
|
7202
|
|
|
|
|
j = rlen; |
4328
|
7202
|
50
|
|
|
|
if (!squash) |
4329
|
7202
|
|
|
|
|
o->op_private |= OPpTRANS_IDENTICAL; |
4330
|
|
|
|
|
|
} |
4331
|
12
|
100
|
|
|
|
else if (j >= (I32)rlen) |
4332
|
4
|
|
|
|
|
j = rlen - 1; |
4333
|
|
|
|
|
|
else { |
4334
|
8
|
|
|
|
|
tbl = |
4335
|
|
|
|
|
|
(short *) |
4336
|
8
|
|
|
|
|
PerlMemShared_realloc(tbl, |
4337
|
|
|
|
|
|
(0x101+rlen-j) * sizeof(short)); |
4338
|
8
|
|
|
|
|
cPVOPo->op_pv = (char*)tbl; |
4339
|
|
|
|
|
|
} |
4340
|
7214
|
|
|
|
|
tbl[0x100] = (short)(rlen - j); |
4341
|
7230
|
100
|
|
|
|
for (i=0; i < (I32)rlen - j; i++) |
4342
|
16
|
|
|
|
|
tbl[0x101+i] = r[j+i]; |
4343
|
|
|
|
|
|
} |
4344
|
|
|
|
|
|
} |
4345
|
|
|
|
|
|
else { |
4346
|
75716
|
100
|
|
|
|
if (!rlen && !del) { |
4347
|
45972
|
|
|
|
|
r = t; rlen = tlen; |
4348
|
45972
|
50
|
|
|
|
if (!squash) |
4349
|
45972
|
|
|
|
|
o->op_private |= OPpTRANS_IDENTICAL; |
4350
|
|
|
|
|
|
} |
4351
|
29744
|
100
|
|
|
|
else if (!squash && rlen == tlen && memEQ((char*)t, (char*)r, tlen)) { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
4352
|
66
|
|
|
|
|
o->op_private |= OPpTRANS_IDENTICAL; |
4353
|
|
|
|
|
|
} |
4354
|
19459012
|
100
|
|
|
|
for (i = 0; i < 256; i++) |
4355
|
19383296
|
|
|
|
|
tbl[i] = -1; |
4356
|
976270
|
100
|
|
|
|
for (i = 0, j = 0; i < (I32)tlen; i++,j++) { |
4357
|
935172
|
100
|
|
|
|
if (j >= (I32)rlen) { |
4358
|
106356
|
100
|
|
|
|
if (del) { |
4359
|
51948
|
100
|
|
|
|
if (tbl[t[i]] == -1) |
4360
|
50776
|
|
|
|
|
tbl[t[i]] = -2; |
4361
|
51948
|
|
|
|
|
continue; |
4362
|
|
|
|
|
|
} |
4363
|
54408
|
|
|
|
|
--j; |
4364
|
|
|
|
|
|
} |
4365
|
883224
|
100
|
|
|
|
if (tbl[t[i]] == -1) { |
4366
|
883218
|
100
|
|
|
|
if (t[i] < 128 && r[j] >= 128) |
|
|
100
|
|
|
|
|
4367
|
|
|
|
|
|
grows = 1; |
4368
|
883218
|
|
|
|
|
tbl[t[i]] = r[j]; |
4369
|
|
|
|
|
|
} |
4370
|
|
|
|
|
|
} |
4371
|
|
|
|
|
|
} |
4372
|
|
|
|
|
|
|
4373
|
83916
|
100
|
|
|
|
if(del && rlen == tlen) { |
|
|
100
|
|
|
|
|
4374
|
2
|
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "Useless use of /d modifier in transliteration operator"); |
4375
|
83914
|
100
|
|
|
|
} else if(rlen > tlen && !complement) { |
4376
|
2
|
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_MISC), "Replacement list is longer than search list"); |
4377
|
|
|
|
|
|
} |
4378
|
|
|
|
|
|
|
4379
|
83916
|
100
|
|
|
|
if (grows) |
4380
|
80
|
|
|
|
|
o->op_private |= OPpTRANS_GROWS; |
4381
|
|
|
|
|
|
#ifdef PERL_MAD |
4382
|
|
|
|
|
|
op_getmad(expr,o,'e'); |
4383
|
|
|
|
|
|
op_getmad(repl,o,'r'); |
4384
|
|
|
|
|
|
#else |
4385
|
83916
|
|
|
|
|
op_free(expr); |
4386
|
83916
|
|
|
|
|
op_free(repl); |
4387
|
|
|
|
|
|
#endif |
4388
|
|
|
|
|
|
|
4389
|
83978
|
|
|
|
|
return o; |
4390
|
|
|
|
|
|
} |
4391
|
|
|
|
|
|
|
4392
|
|
|
|
|
|
/* |
4393
|
|
|
|
|
|
=for apidoc Am|OP *|newPMOP|I32 type|I32 flags |
4394
|
|
|
|
|
|
|
4395
|
|
|
|
|
|
Constructs, checks, and returns an op of any pattern matching type. |
4396
|
|
|
|
|
|
I is the opcode. I gives the eight bits of C |
4397
|
|
|
|
|
|
and, shifted up eight bits, the eight bits of C. |
4398
|
|
|
|
|
|
|
4399
|
|
|
|
|
|
=cut |
4400
|
|
|
|
|
|
*/ |
4401
|
|
|
|
|
|
|
4402
|
|
|
|
|
|
OP * |
4403
|
4458812
|
|
|
|
|
Perl_newPMOP(pTHX_ I32 type, I32 flags) |
4404
|
|
|
|
|
|
{ |
4405
|
|
|
|
|
|
dVAR; |
4406
|
|
|
|
|
|
PMOP *pmop; |
4407
|
|
|
|
|
|
|
4408
|
|
|
|
|
|
assert((PL_opargs[type] & OA_CLASS_MASK) == OA_PMOP); |
4409
|
|
|
|
|
|
|
4410
|
4458812
|
|
|
|
|
NewOp(1101, pmop, 1, PMOP); |
4411
|
4458812
|
|
|
|
|
pmop->op_type = (OPCODE)type; |
4412
|
4458812
|
|
|
|
|
pmop->op_ppaddr = PL_ppaddr[type]; |
4413
|
4458812
|
|
|
|
|
pmop->op_flags = (U8)flags; |
4414
|
4458812
|
|
|
|
|
pmop->op_private = (U8)(0 | (flags >> 8)); |
4415
|
|
|
|
|
|
|
4416
|
4458812
|
100
|
|
|
|
if (PL_hints & HINT_RE_TAINT) |
4417
|
3378
|
|
|
|
|
pmop->op_pmflags |= PMf_RETAINT; |
4418
|
4458812
|
100
|
|
|
|
if (IN_LOCALE_COMPILETIME) { |
4419
|
|
|
|
|
|
set_regex_charset(&(pmop->op_pmflags), REGEX_LOCALE_CHARSET); |
4420
|
|
|
|
|
|
} |
4421
|
4452686
|
100
|
|
|
|
else if ((! (PL_hints & HINT_BYTES)) |
4422
|
|
|
|
|
|
/* Both UNI_8_BIT and locale :not_characters imply Unicode */ |
4423
|
4446608
|
100
|
|
|
|
&& (PL_hints & (HINT_UNI_8_BIT|HINT_LOCALE_NOT_CHARS))) |
4424
|
|
|
|
|
|
{ |
4425
|
|
|
|
|
|
set_regex_charset(&(pmop->op_pmflags), REGEX_UNICODE_CHARSET); |
4426
|
|
|
|
|
|
} |
4427
|
4458812
|
100
|
|
|
|
if (PL_hints & HINT_RE_FLAGS) { |
4428
|
54686
|
|
|
|
|
SV *reflags = Perl_refcounted_he_fetch_pvn(aTHX_ |
4429
|
54686
|
|
|
|
|
PL_compiling.cop_hints_hash, STR_WITH_LEN("reflags"), 0, 0 |
4430
|
|
|
|
|
|
); |
4431
|
54686
|
50
|
|
|
|
if (reflags && SvOK(reflags)) pmop->op_pmflags |= SvIV(reflags); |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
4432
|
54686
|
|
|
|
|
reflags = Perl_refcounted_he_fetch_pvn(aTHX_ |
4433
|
54686
|
|
|
|
|
PL_compiling.cop_hints_hash, STR_WITH_LEN("reflags_charset"), 0, 0 |
4434
|
|
|
|
|
|
); |
4435
|
54686
|
50
|
|
|
|
if (reflags && SvOK(reflags)) { |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
4436
|
54630
|
50
|
|
|
|
set_regex_charset(&(pmop->op_pmflags), (regex_charset)SvIV(reflags)); |
4437
|
|
|
|
|
|
} |
4438
|
|
|
|
|
|
} |
4439
|
|
|
|
|
|
|
4440
|
|
|
|
|
|
|
4441
|
|
|
|
|
|
#ifdef USE_ITHREADS |
4442
|
|
|
|
|
|
assert(SvPOK(PL_regex_pad[0])); |
4443
|
|
|
|
|
|
if (SvCUR(PL_regex_pad[0])) { |
4444
|
|
|
|
|
|
/* Pop off the "packed" IV from the end. */ |
4445
|
|
|
|
|
|
SV *const repointer_list = PL_regex_pad[0]; |
4446
|
|
|
|
|
|
const char *p = SvEND(repointer_list) - sizeof(IV); |
4447
|
|
|
|
|
|
const IV offset = *((IV*)p); |
4448
|
|
|
|
|
|
|
4449
|
|
|
|
|
|
assert(SvCUR(repointer_list) % sizeof(IV) == 0); |
4450
|
|
|
|
|
|
|
4451
|
|
|
|
|
|
SvEND_set(repointer_list, p); |
4452
|
|
|
|
|
|
|
4453
|
|
|
|
|
|
pmop->op_pmoffset = offset; |
4454
|
|
|
|
|
|
/* This slot should be free, so assert this: */ |
4455
|
|
|
|
|
|
assert(PL_regex_pad[offset] == &PL_sv_undef); |
4456
|
|
|
|
|
|
} else { |
4457
|
|
|
|
|
|
SV * const repointer = &PL_sv_undef; |
4458
|
|
|
|
|
|
av_push(PL_regex_padav, repointer); |
4459
|
|
|
|
|
|
pmop->op_pmoffset = av_len(PL_regex_padav); |
4460
|
|
|
|
|
|
PL_regex_pad = AvARRAY(PL_regex_padav); |
4461
|
|
|
|
|
|
} |
4462
|
|
|
|
|
|
#endif |
4463
|
|
|
|
|
|
|
4464
|
4458812
|
100
|
|
|
|
return CHECKOP(type, pmop); |
|
|
50
|
|
|
|
|
4465
|
|
|
|
|
|
} |
4466
|
|
|
|
|
|
|
4467
|
|
|
|
|
|
/* Given some sort of match op o, and an expression expr containing a |
4468
|
|
|
|
|
|
* pattern, either compile expr into a regex and attach it to o (if it's |
4469
|
|
|
|
|
|
* constant), or convert expr into a runtime regcomp op sequence (if it's |
4470
|
|
|
|
|
|
* not) |
4471
|
|
|
|
|
|
* |
4472
|
|
|
|
|
|
* isreg indicates that the pattern is part of a regex construct, eg |
4473
|
|
|
|
|
|
* $x =~ /pattern/ or split /pattern/, as opposed to $x =~ $pattern or |
4474
|
|
|
|
|
|
* split "pattern", which aren't. In the former case, expr will be a list |
4475
|
|
|
|
|
|
* if the pattern contains more than one term (eg /a$b/) or if it contains |
4476
|
|
|
|
|
|
* a replacement, ie s/// or tr///. |
4477
|
|
|
|
|
|
* |
4478
|
|
|
|
|
|
* When the pattern has been compiled within a new anon CV (for |
4479
|
|
|
|
|
|
* qr/(?{...})/ ), then floor indicates the savestack level just before |
4480
|
|
|
|
|
|
* the new sub was created |
4481
|
|
|
|
|
|
*/ |
4482
|
|
|
|
|
|
|
4483
|
|
|
|
|
|
OP * |
4484
|
4534838
|
|
|
|
|
Perl_pmruntime(pTHX_ OP *o, OP *expr, bool isreg, I32 floor) |
4485
|
|
|
|
|
|
{ |
4486
|
|
|
|
|
|
dVAR; |
4487
|
|
|
|
|
|
PMOP *pm; |
4488
|
|
|
|
|
|
LOGOP *rcop; |
4489
|
|
|
|
|
|
I32 repl_has_vars = 0; |
4490
|
|
|
|
|
|
OP* repl = NULL; |
4491
|
4534838
|
|
|
|
|
bool is_trans = (o->op_type == OP_TRANS || o->op_type == OP_TRANSR); |
4492
|
|
|
|
|
|
bool is_compiletime; |
4493
|
|
|
|
|
|
bool has_code; |
4494
|
|
|
|
|
|
|
4495
|
|
|
|
|
|
PERL_ARGS_ASSERT_PMRUNTIME; |
4496
|
|
|
|
|
|
|
4497
|
|
|
|
|
|
/* for s/// and tr///, last element in list is the replacement; pop it */ |
4498
|
|
|
|
|
|
|
4499
|
4534838
|
100
|
|
|
|
if (is_trans || o->op_type == OP_SUBST) { |
|
|
100
|
|
|
|
|
4500
|
|
|
|
|
|
OP* kid; |
4501
|
1313529
|
|
|
|
|
repl = cLISTOPx(expr)->op_last; |
4502
|
1313529
|
|
|
|
|
kid = cLISTOPx(expr)->op_first; |
4503
|
3336712
|
100
|
|
|
|
while (kid->op_sibling != repl) |
4504
|
1394851
|
|
|
|
|
kid = kid->op_sibling; |
4505
|
1313529
|
|
|
|
|
kid->op_sibling = NULL; |
4506
|
1313529
|
|
|
|
|
cLISTOPx(expr)->op_last = kid; |
4507
|
|
|
|
|
|
} |
4508
|
|
|
|
|
|
|
4509
|
|
|
|
|
|
/* for TRANS, convert LIST/PUSH/CONST into CONST, and pass to pmtrans() */ |
4510
|
|
|
|
|
|
|
4511
|
4534838
|
100
|
|
|
|
if (is_trans) { |
4512
|
|
|
|
|
|
OP* const oe = expr; |
4513
|
|
|
|
|
|
assert(expr->op_type == OP_LIST); |
4514
|
|
|
|
|
|
assert(cLISTOPx(expr)->op_first->op_type == OP_PUSHMARK); |
4515
|
|
|
|
|
|
assert(cLISTOPx(expr)->op_first->op_sibling == cLISTOPx(expr)->op_last); |
4516
|
84040
|
|
|
|
|
expr = cLISTOPx(oe)->op_last; |
4517
|
84040
|
|
|
|
|
cLISTOPx(oe)->op_first->op_sibling = NULL; |
4518
|
84040
|
|
|
|
|
cLISTOPx(oe)->op_last = NULL; |
4519
|
84040
|
|
|
|
|
op_free(oe); |
4520
|
|
|
|
|
|
|
4521
|
84040
|
|
|
|
|
return pmtrans(o, expr, repl); |
4522
|
|
|
|
|
|
} |
4523
|
|
|
|
|
|
|
4524
|
|
|
|
|
|
/* find whether we have any runtime or code elements; |
4525
|
|
|
|
|
|
* at the same time, temporarily set the op_next of each DO block; |
4526
|
|
|
|
|
|
* then when we LINKLIST, this will cause the DO blocks to be excluded |
4527
|
|
|
|
|
|
* from the op_next chain (and from having LINKLIST recursively |
4528
|
|
|
|
|
|
* applied to them). We fix up the DOs specially later */ |
4529
|
|
|
|
|
|
|
4530
|
|
|
|
|
|
is_compiletime = 1; |
4531
|
|
|
|
|
|
has_code = 0; |
4532
|
4450798
|
100
|
|
|
|
if (expr->op_type == OP_LIST) { |
4533
|
|
|
|
|
|
OP *o; |
4534
|
4645327
|
100
|
|
|
|
for (o = cLISTOPx(expr)->op_first; o; o = o->op_sibling) { |
4535
|
3245004
|
100
|
|
|
|
if (o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL)) { |
|
|
50
|
|
|
|
|
4536
|
|
|
|
|
|
has_code = 1; |
4537
|
|
|
|
|
|
assert(!o->op_next && o->op_sibling); |
4538
|
9966
|
|
|
|
|
o->op_next = o->op_sibling; |
4539
|
|
|
|
|
|
} |
4540
|
3235038
|
100
|
|
|
|
else if (o->op_type != OP_CONST && o->op_type != OP_PUSHMARK) |
4541
|
|
|
|
|
|
is_compiletime = 0; |
4542
|
|
|
|
|
|
} |
4543
|
|
|
|
|
|
} |
4544
|
3050475
|
100
|
|
|
|
else if (expr->op_type != OP_CONST) |
4545
|
|
|
|
|
|
is_compiletime = 0; |
4546
|
|
|
|
|
|
|
4547
|
4450798
|
100
|
|
|
|
LINKLIST(expr); |
4548
|
|
|
|
|
|
|
4549
|
|
|
|
|
|
/* fix up DO blocks; treat each one as a separate little sub; |
4550
|
|
|
|
|
|
* also, mark any arrays as LIST/REF */ |
4551
|
|
|
|
|
|
|
4552
|
4450798
|
100
|
|
|
|
if (expr->op_type == OP_LIST) { |
4553
|
|
|
|
|
|
OP *o; |
4554
|
4645327
|
100
|
|
|
|
for (o = cLISTOPx(expr)->op_first; o; o = o->op_sibling) { |
4555
|
|
|
|
|
|
|
4556
|
3245004
|
100
|
|
|
|
if (o->op_type == OP_PADAV || o->op_type == OP_RV2AV) { |
4557
|
|
|
|
|
|
assert( !(o->op_flags & OPf_WANT)); |
4558
|
|
|
|
|
|
/* push the array rather than its contents. The regex |
4559
|
|
|
|
|
|
* engine will retrieve and join the elements later */ |
4560
|
32
|
|
|
|
|
o->op_flags |= (OPf_WANT_LIST | OPf_REF); |
4561
|
32
|
|
|
|
|
continue; |
4562
|
|
|
|
|
|
} |
4563
|
|
|
|
|
|
|
4564
|
3244972
|
100
|
|
|
|
if (!(o->op_type == OP_NULL && (o->op_flags & OPf_SPECIAL))) |
|
|
50
|
|
|
|
|
4565
|
3235006
|
|
|
|
|
continue; |
4566
|
9966
|
|
|
|
|
o->op_next = NULL; /* undo temporary hack from above */ |
4567
|
9966
|
|
|
|
|
scalar(o); |
4568
|
9966
|
50
|
|
|
|
LINKLIST(o); |
4569
|
9966
|
100
|
|
|
|
if (cLISTOPo->op_first->op_type == OP_LEAVE) { |
4570
|
5186
|
|
|
|
|
LISTOP *leaveop = cLISTOPx(cLISTOPo->op_first); |
4571
|
|
|
|
|
|
/* skip ENTER */ |
4572
|
|
|
|
|
|
assert(leaveop->op_first->op_type == OP_ENTER); |
4573
|
|
|
|
|
|
assert(leaveop->op_first->op_sibling); |
4574
|
5186
|
|
|
|
|
o->op_next = leaveop->op_first->op_sibling; |
4575
|
|
|
|
|
|
/* skip leave */ |
4576
|
|
|
|
|
|
assert(leaveop->op_flags & OPf_KIDS); |
4577
|
|
|
|
|
|
assert(leaveop->op_last->op_next == (OP*)leaveop); |
4578
|
5186
|
|
|
|
|
leaveop->op_next = NULL; /* stop on last op */ |
4579
|
5186
|
|
|
|
|
op_null((OP*)leaveop); |
4580
|
|
|
|
|
|
} |
4581
|
|
|
|
|
|
else { |
4582
|
|
|
|
|
|
/* skip SCOPE */ |
4583
|
4780
|
|
|
|
|
OP *scope = cLISTOPo->op_first; |
4584
|
|
|
|
|
|
assert(scope->op_type == OP_SCOPE); |
4585
|
|
|
|
|
|
assert(scope->op_flags & OPf_KIDS); |
4586
|
4780
|
|
|
|
|
scope->op_next = NULL; /* stop on last op */ |
4587
|
4780
|
|
|
|
|
op_null(scope); |
4588
|
|
|
|
|
|
} |
4589
|
|
|
|
|
|
/* have to peep the DOs individually as we've removed it from |
4590
|
|
|
|
|
|
* the op_next chain */ |
4591
|
9966
|
|
|
|
|
CALL_PEEP(o); |
4592
|
9966
|
100
|
|
|
|
if (is_compiletime) |
4593
|
|
|
|
|
|
/* runtime finalizes as part of finalizing whole tree */ |
4594
|
9932
|
|
|
|
|
finalize_optree(o); |
4595
|
|
|
|
|
|
} |
4596
|
|
|
|
|
|
} |
4597
|
3050475
|
100
|
|
|
|
else if (expr->op_type == OP_PADAV || expr->op_type == OP_RV2AV) { |
4598
|
|
|
|
|
|
assert( !(expr->op_flags & OPf_WANT)); |
4599
|
|
|
|
|
|
/* push the array rather than its contents. The regex |
4600
|
|
|
|
|
|
* engine will retrieve and join the elements later */ |
4601
|
2
|
|
|
|
|
expr->op_flags |= (OPf_WANT_LIST | OPf_REF); |
4602
|
|
|
|
|
|
} |
4603
|
|
|
|
|
|
|
4604
|
4450798
|
|
|
|
|
PL_hints |= HINT_BLOCK_SCOPE; |
4605
|
|
|
|
|
|
pm = (PMOP*)o; |
4606
|
|
|
|
|
|
assert(floor==0 || (pm->op_pmflags & PMf_HAS_CV)); |
4607
|
|
|
|
|
|
|
4608
|
4450798
|
100
|
|
|
|
if (is_compiletime) { |
4609
|
3788002
|
|
|
|
|
U32 rx_flags = pm->op_pmflags & RXf_PMf_COMPILETIME; |
4610
|
3788002
|
|
|
|
|
regexp_engine const *eng = current_re_engine(); |
4611
|
|
|
|
|
|
|
4612
|
3788002
|
100
|
|
|
|
if (o->op_flags & OPf_SPECIAL) |
4613
|
68767
|
|
|
|
|
rx_flags |= RXf_SPLIT; |
4614
|
|
|
|
|
|
|
4615
|
3788002
|
100
|
|
|
|
if (!has_code || !eng->op_comp) { |
|
|
50
|
|
|
|
|
4616
|
|
|
|
|
|
/* compile-time simple constant pattern */ |
4617
|
|
|
|
|
|
|
4618
|
3778564
|
100
|
|
|
|
if ((pm->op_pmflags & PMf_HAS_CV) && !has_code) { |
|
|
50
|
|
|
|
|
4619
|
|
|
|
|
|
/* whoops! we guessed that a qr// had a code block, but we |
4620
|
|
|
|
|
|
* were wrong (e.g. /[(?{}]/ ). Throw away the PL_compcv |
4621
|
|
|
|
|
|
* that isn't required now. Note that we have to be pretty |
4622
|
|
|
|
|
|
* confident that nothing used that CV's pad while the |
4623
|
|
|
|
|
|
* regex was parsed */ |
4624
|
|
|
|
|
|
assert(AvFILLp(PL_comppad) == 0); /* just @_ */ |
4625
|
|
|
|
|
|
/* But we know that one op is using this CV's slab. */ |
4626
|
232
|
|
|
|
|
cv_forget_slab(PL_compcv); |
4627
|
232
|
50
|
|
|
|
LEAVE_SCOPE(floor); |
4628
|
232
|
|
|
|
|
pm->op_pmflags &= ~PMf_HAS_CV; |
4629
|
|
|
|
|
|
} |
4630
|
|
|
|
|
|
|
4631
|
3778564
|
50
|
|
|
|
PM_SETRE(pm, |
4632
|
|
|
|
|
|
eng->op_comp |
4633
|
|
|
|
|
|
? eng->op_comp(aTHX_ NULL, 0, expr, eng, NULL, NULL, |
4634
|
|
|
|
|
|
rx_flags, pm->op_pmflags) |
4635
|
|
|
|
|
|
: Perl_re_op_compile(aTHX_ NULL, 0, expr, eng, NULL, NULL, |
4636
|
|
|
|
|
|
rx_flags, pm->op_pmflags) |
4637
|
|
|
|
|
|
); |
4638
|
|
|
|
|
|
#ifdef PERL_MAD |
4639
|
|
|
|
|
|
op_getmad(expr,(OP*)pm,'e'); |
4640
|
|
|
|
|
|
#else |
4641
|
3777104
|
|
|
|
|
op_free(expr); |
4642
|
|
|
|
|
|
#endif |
4643
|
|
|
|
|
|
} |
4644
|
|
|
|
|
|
else { |
4645
|
|
|
|
|
|
/* compile-time pattern that includes literal code blocks */ |
4646
|
14157
|
100
|
|
|
|
REGEXP* re = eng->op_comp(aTHX_ NULL, 0, expr, eng, NULL, NULL, |
4647
|
|
|
|
|
|
rx_flags, |
4648
|
9438
|
|
|
|
|
(pm->op_pmflags | |
4649
|
9438
|
|
|
|
|
((PL_hints & HINT_RE_EVAL) ? PMf_USE_RE_EVAL : 0)) |
4650
|
|
|
|
|
|
); |
4651
|
9426
|
|
|
|
|
PM_SETRE(pm, re); |
4652
|
9426
|
100
|
|
|
|
if (pm->op_pmflags & PMf_HAS_CV) { |
4653
|
|
|
|
|
|
CV *cv; |
4654
|
|
|
|
|
|
/* this QR op (and the anon sub we embed it in) is never |
4655
|
|
|
|
|
|
* actually executed. It's just a placeholder where we can |
4656
|
|
|
|
|
|
* squirrel away expr in op_code_list without the peephole |
4657
|
|
|
|
|
|
* optimiser etc processing it for a second time */ |
4658
|
7772
|
|
|
|
|
OP *qr = newPMOP(OP_QR, 0); |
4659
|
7772
|
|
|
|
|
((PMOP*)qr)->op_code_list = expr; |
4660
|
|
|
|
|
|
|
4661
|
|
|
|
|
|
/* handle the implicit sub{} wrapped round the qr/(?{..})/ */ |
4662
|
7772
|
50
|
|
|
|
SvREFCNT_inc_simple_void(PL_compcv); |
4663
|
7772
|
|
|
|
|
cv = newATTRSUB(floor, 0, NULL, NULL, qr); |
4664
|
7772
|
|
|
|
|
ReANY(re)->qr_anoncv = cv; |
4665
|
|
|
|
|
|
|
4666
|
|
|
|
|
|
/* attach the anon CV to the pad so that |
4667
|
|
|
|
|
|
* pad_fixup_inner_anons() can find it */ |
4668
|
7772
|
|
|
|
|
(void)pad_add_anon(cv, o->op_type); |
4669
|
7772
|
50
|
|
|
|
SvREFCNT_inc_simple_void(cv); |
4670
|
|
|
|
|
|
} |
4671
|
|
|
|
|
|
else { |
4672
|
1654
|
|
|
|
|
pm->op_code_list = expr; |
4673
|
|
|
|
|
|
} |
4674
|
|
|
|
|
|
} |
4675
|
|
|
|
|
|
} |
4676
|
|
|
|
|
|
else { |
4677
|
|
|
|
|
|
/* runtime pattern: build chain of regcomp etc ops */ |
4678
|
|
|
|
|
|
bool reglist; |
4679
|
|
|
|
|
|
PADOFFSET cv_targ = 0; |
4680
|
|
|
|
|
|
|
4681
|
662796
|
100
|
|
|
|
reglist = isreg && expr->op_type == OP_LIST; |
|
|
100
|
|
|
|
|
4682
|
662796
|
100
|
|
|
|
if (reglist) |
4683
|
215000
|
|
|
|
|
op_null(expr); |
4684
|
|
|
|
|
|
|
4685
|
662796
|
100
|
|
|
|
if (has_code) { |
4686
|
34
|
|
|
|
|
pm->op_code_list = expr; |
4687
|
|
|
|
|
|
/* don't free op_code_list; its ops are embedded elsewhere too */ |
4688
|
34
|
|
|
|
|
pm->op_pmflags |= PMf_CODELIST_PRIVATE; |
4689
|
|
|
|
|
|
} |
4690
|
|
|
|
|
|
|
4691
|
662796
|
100
|
|
|
|
if (o->op_flags & OPf_SPECIAL) |
4692
|
11902
|
|
|
|
|
pm->op_pmflags |= PMf_SPLIT; |
4693
|
|
|
|
|
|
|
4694
|
|
|
|
|
|
/* the OP_REGCMAYBE is a placeholder in the non-threaded case |
4695
|
|
|
|
|
|
* to allow its op_next to be pointed past the regcomp and |
4696
|
|
|
|
|
|
* preceding stacking ops; |
4697
|
|
|
|
|
|
* OP_REGCRESET is there to reset taint before executing the |
4698
|
|
|
|
|
|
* stacking ops */ |
4699
|
662796
|
100
|
|
|
|
if (pm->op_pmflags & PMf_KEEP || TAINTING_get) |
|
|
100
|
|
|
|
|
4700
|
21802
|
100
|
|
|
|
expr = newUNOP((TAINTING_get ? OP_REGCRESET : OP_REGCMAYBE),0,expr); |
4701
|
|
|
|
|
|
|
4702
|
662796
|
100
|
|
|
|
if (pm->op_pmflags & PMf_HAS_CV) { |
4703
|
|
|
|
|
|
/* we have a runtime qr with literal code. This means |
4704
|
|
|
|
|
|
* that the qr// has been wrapped in a new CV, which |
4705
|
|
|
|
|
|
* means that runtime consts, vars etc will have been compiled |
4706
|
|
|
|
|
|
* against a new pad. So... we need to execute those ops |
4707
|
|
|
|
|
|
* within the environment of the new CV. So wrap them in a call |
4708
|
|
|
|
|
|
* to a new anon sub. i.e. for |
4709
|
|
|
|
|
|
* |
4710
|
|
|
|
|
|
* qr/a$b(?{...})/, |
4711
|
|
|
|
|
|
* |
4712
|
|
|
|
|
|
* we build an anon sub that looks like |
4713
|
|
|
|
|
|
* |
4714
|
|
|
|
|
|
* sub { "a", $b, '(?{...})' } |
4715
|
|
|
|
|
|
* |
4716
|
|
|
|
|
|
* and call it, passing the returned list to regcomp. |
4717
|
|
|
|
|
|
* Or to put it another way, the list of ops that get executed |
4718
|
|
|
|
|
|
* are: |
4719
|
|
|
|
|
|
* |
4720
|
|
|
|
|
|
* normal PMf_HAS_CV |
4721
|
|
|
|
|
|
* ------ ------------------- |
4722
|
|
|
|
|
|
* pushmark (for regcomp) |
4723
|
|
|
|
|
|
* pushmark (for entersub) |
4724
|
|
|
|
|
|
* pushmark (for refgen) |
4725
|
|
|
|
|
|
* anoncode |
4726
|
|
|
|
|
|
* refgen |
4727
|
|
|
|
|
|
* entersub |
4728
|
|
|
|
|
|
* regcreset regcreset |
4729
|
|
|
|
|
|
* pushmark pushmark |
4730
|
|
|
|
|
|
* const("a") const("a") |
4731
|
|
|
|
|
|
* gvsv(b) gvsv(b) |
4732
|
|
|
|
|
|
* const("(?{...})") const("(?{...})") |
4733
|
|
|
|
|
|
* leavesub |
4734
|
|
|
|
|
|
* regcomp regcomp |
4735
|
|
|
|
|
|
*/ |
4736
|
|
|
|
|
|
|
4737
|
10
|
50
|
|
|
|
SvREFCNT_inc_simple_void(PL_compcv); |
4738
|
|
|
|
|
|
/* these lines are just an unrolled newANONATTRSUB */ |
4739
|
10
|
|
|
|
|
expr = newSVOP(OP_ANONCODE, 0, |
4740
|
|
|
|
|
|
MUTABLE_SV(newATTRSUB(floor, 0, NULL, NULL, expr))); |
4741
|
10
|
|
|
|
|
cv_targ = expr->op_targ; |
4742
|
10
|
|
|
|
|
expr = newUNOP(OP_REFGEN, 0, expr); |
4743
|
|
|
|
|
|
|
4744
|
10
|
|
|
|
|
expr = list(force_list(newUNOP(OP_ENTERSUB, 0, scalar(expr)))); |
4745
|
|
|
|
|
|
} |
4746
|
|
|
|
|
|
|
4747
|
662796
|
|
|
|
|
NewOp(1101, rcop, 1, LOGOP); |
4748
|
662796
|
|
|
|
|
rcop->op_type = OP_REGCOMP; |
4749
|
662796
|
|
|
|
|
rcop->op_ppaddr = PL_ppaddr[OP_REGCOMP]; |
4750
|
662796
|
|
|
|
|
rcop->op_first = scalar(expr); |
4751
|
985375
|
100
|
|
|
|
rcop->op_flags |= OPf_KIDS |
|
|
100
|
|
|
|
|
4752
|
662796
|
|
|
|
|
| ((PL_hints & HINT_RE_EVAL) ? OPf_SPECIAL : 0) |
4753
|
|
|
|
|
|
| (reglist ? OPf_STACKED : 0); |
4754
|
662796
|
|
|
|
|
rcop->op_private = 0; |
4755
|
662796
|
|
|
|
|
rcop->op_other = o; |
4756
|
662796
|
|
|
|
|
rcop->op_targ = cv_targ; |
4757
|
|
|
|
|
|
|
4758
|
|
|
|
|
|
/* /$x/ may cause an eval, since $x might be qr/(?{..})/ */ |
4759
|
662796
|
100
|
|
|
|
if (PL_hints & HINT_RE_EVAL) PL_cv_has_eval = 1; |
4760
|
|
|
|
|
|
|
4761
|
|
|
|
|
|
/* establish postfix order */ |
4762
|
662796
|
100
|
|
|
|
if (expr->op_type == OP_REGCRESET || expr->op_type == OP_REGCMAYBE) { |
4763
|
21802
|
50
|
|
|
|
LINKLIST(expr); |
4764
|
21802
|
|
|
|
|
rcop->op_next = expr; |
4765
|
21802
|
|
|
|
|
((UNOP*)expr)->op_first->op_next = (OP*)rcop; |
4766
|
|
|
|
|
|
} |
4767
|
|
|
|
|
|
else { |
4768
|
640994
|
100
|
|
|
|
rcop->op_next = LINKLIST(expr); |
4769
|
640994
|
|
|
|
|
expr->op_next = (OP*)rcop; |
4770
|
|
|
|
|
|
} |
4771
|
|
|
|
|
|
|
4772
|
662796
|
|
|
|
|
op_prepend_elem(o->op_type, scalar((OP*)rcop), o); |
4773
|
|
|
|
|
|
} |
4774
|
|
|
|
|
|
|
4775
|
4449326
|
100
|
|
|
|
if (repl) { |
4776
|
|
|
|
|
|
OP *curop = repl; |
4777
|
|
|
|
|
|
bool konst; |
4778
|
1229489
|
100
|
|
|
|
if (pm->op_pmflags & PMf_EVAL) { |
4779
|
162363
|
50
|
|
|
|
if (CopLINE(PL_curcop) < (line_t)PL_parser->multi_end) |
4780
|
0
|
|
|
|
|
CopLINE_set(PL_curcop, (line_t)PL_parser->multi_end); |
4781
|
|
|
|
|
|
} |
4782
|
|
|
|
|
|
/* If we are looking at s//.../e with a single statement, get past |
4783
|
|
|
|
|
|
the implicit do{}. */ |
4784
|
1229489
|
100
|
|
|
|
if (curop->op_type == OP_NULL && curop->op_flags & OPf_KIDS |
|
|
50
|
|
|
|
|
4785
|
160155
|
100
|
|
|
|
&& cUNOPx(curop)->op_first->op_type == OP_SCOPE |
4786
|
128770
|
50
|
|
|
|
&& cUNOPx(curop)->op_first->op_flags & OPf_KIDS) { |
4787
|
128770
|
|
|
|
|
OP *kid = cUNOPx(cUNOPx(curop)->op_first)->op_first; |
4788
|
128770
|
100
|
|
|
|
if (kid->op_type == OP_NULL && kid->op_sibling |
|
|
50
|
|
|
|
|
4789
|
128682
|
50
|
|
|
|
&& !kid->op_sibling->op_sibling) |
4790
|
128682
|
|
|
|
|
curop = kid->op_sibling; |
4791
|
|
|
|
|
|
} |
4792
|
1229489
|
100
|
|
|
|
if (curop->op_type == OP_CONST) |
4793
|
|
|
|
|
|
konst = TRUE; |
4794
|
371885
|
100
|
|
|
|
else if (( (curop->op_type == OP_RV2SV || |
4795
|
311199
|
50
|
|
|
|
curop->op_type == OP_RV2AV || |
4796
|
462840
|
50
|
|
|
|
curop->op_type == OP_RV2HV || |
4797
|
311199
|
|
|
|
|
curop->op_type == OP_RV2GV) |
4798
|
60686
|
50
|
|
|
|
&& cUNOPx(curop)->op_first |
4799
|
60686
|
100
|
|
|
|
&& cUNOPx(curop)->op_first->op_type == OP_GV ) |
4800
|
311217
|
100
|
|
|
|
|| curop->op_type == OP_PADSV |
4801
|
307671
|
50
|
|
|
|
|| curop->op_type == OP_PADAV |
4802
|
307671
|
50
|
|
|
|
|| curop->op_type == OP_PADHV |
4803
|
307671
|
50
|
|
|
|
|| curop->op_type == OP_PADANY) { |
4804
|
|
|
|
|
|
repl_has_vars = 1; |
4805
|
|
|
|
|
|
konst = TRUE; |
4806
|
|
|
|
|
|
} |
4807
|
|
|
|
|
|
else konst = FALSE; |
4808
|
1229489
|
100
|
|
|
|
if (konst |
4809
|
953385
|
100
|
|
|
|
&& !(repl_has_vars |
|
|
100
|
|
|
|
|
4810
|
64214
|
|
|
|
|
&& (!PM_GETRE(pm) |
4811
|
92703
|
100
|
|
|
|
|| !RX_PRELEN(PM_GETRE(pm)) |
4812
|
92685
|
100
|
|
|
|
|| RX_EXTFLAGS(PM_GETRE(pm)) & RXf_EVAL_SEEN))) |
4813
|
|
|
|
|
|
{ |
4814
|
919746
|
|
|
|
|
pm->op_pmflags |= PMf_CONST; /* const for long enough */ |
4815
|
919746
|
|
|
|
|
op_prepend_elem(o->op_type, scalar(repl), o); |
4816
|
|
|
|
|
|
} |
4817
|
|
|
|
|
|
else { |
4818
|
309743
|
|
|
|
|
NewOp(1101, rcop, 1, LOGOP); |
4819
|
309743
|
|
|
|
|
rcop->op_type = OP_SUBSTCONT; |
4820
|
309743
|
|
|
|
|
rcop->op_ppaddr = PL_ppaddr[OP_SUBSTCONT]; |
4821
|
309743
|
|
|
|
|
rcop->op_first = scalar(repl); |
4822
|
309743
|
|
|
|
|
rcop->op_flags |= OPf_KIDS; |
4823
|
309743
|
|
|
|
|
rcop->op_private = 1; |
4824
|
309743
|
|
|
|
|
rcop->op_other = o; |
4825
|
|
|
|
|
|
|
4826
|
|
|
|
|
|
/* establish postfix order */ |
4827
|
309743
|
100
|
|
|
|
rcop->op_next = LINKLIST(repl); |
4828
|
309743
|
|
|
|
|
repl->op_next = (OP*)rcop; |
4829
|
|
|
|
|
|
|
4830
|
309743
|
|
|
|
|
pm->op_pmreplrootu.op_pmreplroot = scalar((OP*)rcop); |
4831
|
|
|
|
|
|
assert(!(pm->op_pmflags & PMf_ONCE)); |
4832
|
309743
|
50
|
|
|
|
pm->op_pmstashstartu.op_pmreplstart = LINKLIST(rcop); |
4833
|
2509564
|
|
|
|
|
rcop->op_next = 0; |
4834
|
|
|
|
|
|
} |
4835
|
|
|
|
|
|
} |
4836
|
|
|
|
|
|
|
4837
|
|
|
|
|
|
return (OP*)pm; |
4838
|
|
|
|
|
|
} |
4839
|
|
|
|
|
|
|
4840
|
|
|
|
|
|
/* |
4841
|
|
|
|
|
|
=for apidoc Am|OP *|newSVOP|I32 type|I32 flags|SV *sv |
4842
|
|
|
|
|
|
|
4843
|
|
|
|
|
|
Constructs, checks, and returns an op of any type that involves an |
4844
|
|
|
|
|
|
embedded SV. I is the opcode. I gives the eight bits |
4845
|
|
|
|
|
|
of C. I gives the SV to embed in the op; this function |
4846
|
|
|
|
|
|
takes ownership of one reference to it. |
4847
|
|
|
|
|
|
|
4848
|
|
|
|
|
|
=cut |
4849
|
|
|
|
|
|
*/ |
4850
|
|
|
|
|
|
|
4851
|
|
|
|
|
|
OP * |
4852
|
202500201
|
|
|
|
|
Perl_newSVOP(pTHX_ I32 type, I32 flags, SV *sv) |
4853
|
|
|
|
|
|
{ |
4854
|
|
|
|
|
|
dVAR; |
4855
|
|
|
|
|
|
SVOP *svop; |
4856
|
|
|
|
|
|
|
4857
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWSVOP; |
4858
|
|
|
|
|
|
|
4859
|
|
|
|
|
|
assert((PL_opargs[type] & OA_CLASS_MASK) == OA_SVOP |
4860
|
|
|
|
|
|
|| (PL_opargs[type] & OA_CLASS_MASK) == OA_PVOP_OR_SVOP |
4861
|
|
|
|
|
|
|| (PL_opargs[type] & OA_CLASS_MASK) == OA_FILESTATOP); |
4862
|
|
|
|
|
|
|
4863
|
202500201
|
|
|
|
|
NewOp(1101, svop, 1, SVOP); |
4864
|
202500201
|
|
|
|
|
svop->op_type = (OPCODE)type; |
4865
|
202500201
|
|
|
|
|
svop->op_ppaddr = PL_ppaddr[type]; |
4866
|
202500201
|
|
|
|
|
svop->op_sv = sv; |
4867
|
202500201
|
|
|
|
|
svop->op_next = (OP*)svop; |
4868
|
202500201
|
|
|
|
|
svop->op_flags = (U8)flags; |
4869
|
202500201
|
|
|
|
|
svop->op_private = (U8)(0 | (flags >> 8)); |
4870
|
202500201
|
100
|
|
|
|
if (PL_opargs[type] & OA_RETSCALAR) |
4871
|
185816409
|
|
|
|
|
scalar((OP*)svop); |
4872
|
202500201
|
100
|
|
|
|
if (PL_opargs[type] & OA_TARGET) |
4873
|
4520
|
|
|
|
|
svop->op_targ = pad_alloc(type, SVs_PADTMP); |
4874
|
202500201
|
100
|
|
|
|
return CHECKOP(type, svop); |
|
|
50
|
|
|
|
|
4875
|
|
|
|
|
|
} |
4876
|
|
|
|
|
|
|
4877
|
|
|
|
|
|
#ifdef USE_ITHREADS |
4878
|
|
|
|
|
|
|
4879
|
|
|
|
|
|
/* |
4880
|
|
|
|
|
|
=for apidoc Am|OP *|newPADOP|I32 type|I32 flags|SV *sv |
4881
|
|
|
|
|
|
|
4882
|
|
|
|
|
|
Constructs, checks, and returns an op of any type that involves a |
4883
|
|
|
|
|
|
reference to a pad element. I is the opcode. I gives the |
4884
|
|
|
|
|
|
eight bits of C. A pad slot is automatically allocated, and |
4885
|
|
|
|
|
|
is populated with I; this function takes ownership of one reference |
4886
|
|
|
|
|
|
to it. |
4887
|
|
|
|
|
|
|
4888
|
|
|
|
|
|
This function only exists if Perl has been compiled to use ithreads. |
4889
|
|
|
|
|
|
|
4890
|
|
|
|
|
|
=cut |
4891
|
|
|
|
|
|
*/ |
4892
|
|
|
|
|
|
|
4893
|
|
|
|
|
|
OP * |
4894
|
|
|
|
|
|
Perl_newPADOP(pTHX_ I32 type, I32 flags, SV *sv) |
4895
|
|
|
|
|
|
{ |
4896
|
|
|
|
|
|
dVAR; |
4897
|
|
|
|
|
|
PADOP *padop; |
4898
|
|
|
|
|
|
|
4899
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWPADOP; |
4900
|
|
|
|
|
|
|
4901
|
|
|
|
|
|
assert((PL_opargs[type] & OA_CLASS_MASK) == OA_SVOP |
4902
|
|
|
|
|
|
|| (PL_opargs[type] & OA_CLASS_MASK) == OA_PVOP_OR_SVOP |
4903
|
|
|
|
|
|
|| (PL_opargs[type] & OA_CLASS_MASK) == OA_FILESTATOP); |
4904
|
|
|
|
|
|
|
4905
|
|
|
|
|
|
NewOp(1101, padop, 1, PADOP); |
4906
|
|
|
|
|
|
padop->op_type = (OPCODE)type; |
4907
|
|
|
|
|
|
padop->op_ppaddr = PL_ppaddr[type]; |
4908
|
|
|
|
|
|
padop->op_padix = pad_alloc(type, SVs_PADTMP); |
4909
|
|
|
|
|
|
SvREFCNT_dec(PAD_SVl(padop->op_padix)); |
4910
|
|
|
|
|
|
PAD_SETSV(padop->op_padix, sv); |
4911
|
|
|
|
|
|
assert(sv); |
4912
|
|
|
|
|
|
SvPADTMP_on(sv); |
4913
|
|
|
|
|
|
padop->op_next = (OP*)padop; |
4914
|
|
|
|
|
|
padop->op_flags = (U8)flags; |
4915
|
|
|
|
|
|
if (PL_opargs[type] & OA_RETSCALAR) |
4916
|
|
|
|
|
|
scalar((OP*)padop); |
4917
|
|
|
|
|
|
if (PL_opargs[type] & OA_TARGET) |
4918
|
|
|
|
|
|
padop->op_targ = pad_alloc(type, SVs_PADTMP); |
4919
|
|
|
|
|
|
return CHECKOP(type, padop); |
4920
|
|
|
|
|
|
} |
4921
|
|
|
|
|
|
|
4922
|
|
|
|
|
|
#endif /* USE_ITHREADS */ |
4923
|
|
|
|
|
|
|
4924
|
|
|
|
|
|
/* |
4925
|
|
|
|
|
|
=for apidoc Am|OP *|newGVOP|I32 type|I32 flags|GV *gv |
4926
|
|
|
|
|
|
|
4927
|
|
|
|
|
|
Constructs, checks, and returns an op of any type that involves an |
4928
|
|
|
|
|
|
embedded reference to a GV. I is the opcode. I gives the |
4929
|
|
|
|
|
|
eight bits of C. I identifies the GV that the op should |
4930
|
|
|
|
|
|
reference; calling this function does not transfer ownership of any |
4931
|
|
|
|
|
|
reference to it. |
4932
|
|
|
|
|
|
|
4933
|
|
|
|
|
|
=cut |
4934
|
|
|
|
|
|
*/ |
4935
|
|
|
|
|
|
|
4936
|
|
|
|
|
|
OP * |
4937
|
1014492
|
|
|
|
|
Perl_newGVOP(pTHX_ I32 type, I32 flags, GV *gv) |
4938
|
|
|
|
|
|
{ |
4939
|
|
|
|
|
|
dVAR; |
4940
|
|
|
|
|
|
|
4941
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWGVOP; |
4942
|
|
|
|
|
|
|
4943
|
|
|
|
|
|
#ifdef USE_ITHREADS |
4944
|
|
|
|
|
|
GvIN_PAD_on(gv); |
4945
|
|
|
|
|
|
return newPADOP(type, flags, SvREFCNT_inc_simple_NN(gv)); |
4946
|
|
|
|
|
|
#else |
4947
|
1014492
|
|
|
|
|
return newSVOP(type, flags, SvREFCNT_inc_simple_NN(gv)); |
4948
|
|
|
|
|
|
#endif |
4949
|
|
|
|
|
|
} |
4950
|
|
|
|
|
|
|
4951
|
|
|
|
|
|
/* |
4952
|
|
|
|
|
|
=for apidoc Am|OP *|newPVOP|I32 type|I32 flags|char *pv |
4953
|
|
|
|
|
|
|
4954
|
|
|
|
|
|
Constructs, checks, and returns an op of any type that involves an |
4955
|
|
|
|
|
|
embedded C-level pointer (PV). I is the opcode. I gives |
4956
|
|
|
|
|
|
the eight bits of C. I supplies the C-level pointer, which |
4957
|
|
|
|
|
|
must have been allocated using C; the memory will |
4958
|
|
|
|
|
|
be freed when the op is destroyed. |
4959
|
|
|
|
|
|
|
4960
|
|
|
|
|
|
=cut |
4961
|
|
|
|
|
|
*/ |
4962
|
|
|
|
|
|
|
4963
|
|
|
|
|
|
OP * |
4964
|
209254
|
|
|
|
|
Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv) |
4965
|
|
|
|
|
|
{ |
4966
|
|
|
|
|
|
dVAR; |
4967
|
209254
|
|
|
|
|
const bool utf8 = cBOOL(flags & SVf_UTF8); |
4968
|
|
|
|
|
|
PVOP *pvop; |
4969
|
|
|
|
|
|
|
4970
|
209254
|
|
|
|
|
flags &= ~SVf_UTF8; |
4971
|
|
|
|
|
|
|
4972
|
|
|
|
|
|
assert((PL_opargs[type] & OA_CLASS_MASK) == OA_PVOP_OR_SVOP |
4973
|
|
|
|
|
|
|| type == OP_RUNCV |
4974
|
|
|
|
|
|
|| (PL_opargs[type] & OA_CLASS_MASK) == OA_LOOPEXOP); |
4975
|
|
|
|
|
|
|
4976
|
209254
|
|
|
|
|
NewOp(1101, pvop, 1, PVOP); |
4977
|
209254
|
|
|
|
|
pvop->op_type = (OPCODE)type; |
4978
|
209254
|
|
|
|
|
pvop->op_ppaddr = PL_ppaddr[type]; |
4979
|
209254
|
|
|
|
|
pvop->op_pv = pv; |
4980
|
209254
|
|
|
|
|
pvop->op_next = (OP*)pvop; |
4981
|
209254
|
|
|
|
|
pvop->op_flags = (U8)flags; |
4982
|
209254
|
100
|
|
|
|
pvop->op_private = utf8 ? OPpPV_IS_UTF8 : 0; |
4983
|
209254
|
50
|
|
|
|
if (PL_opargs[type] & OA_RETSCALAR) |
4984
|
209254
|
|
|
|
|
scalar((OP*)pvop); |
4985
|
209254
|
50
|
|
|
|
if (PL_opargs[type] & OA_TARGET) |
4986
|
0
|
|
|
|
|
pvop->op_targ = pad_alloc(type, SVs_PADTMP); |
4987
|
209254
|
50
|
|
|
|
return CHECKOP(type, pvop); |
|
|
0
|
|
|
|
|
4988
|
|
|
|
|
|
} |
4989
|
|
|
|
|
|
|
4990
|
|
|
|
|
|
#ifdef PERL_MAD |
4991
|
|
|
|
|
|
OP* |
4992
|
|
|
|
|
|
#else |
4993
|
|
|
|
|
|
void |
4994
|
|
|
|
|
|
#endif |
4995
|
607902
|
|
|
|
|
Perl_package(pTHX_ OP *o) |
4996
|
|
|
|
|
|
{ |
4997
|
|
|
|
|
|
dVAR; |
4998
|
607902
|
|
|
|
|
SV *const sv = cSVOPo->op_sv; |
4999
|
|
|
|
|
|
#ifdef PERL_MAD |
5000
|
|
|
|
|
|
OP *pegop; |
5001
|
|
|
|
|
|
#endif |
5002
|
|
|
|
|
|
|
5003
|
|
|
|
|
|
PERL_ARGS_ASSERT_PACKAGE; |
5004
|
|
|
|
|
|
|
5005
|
607902
|
|
|
|
|
SAVEGENERICSV(PL_curstash); |
5006
|
607902
|
|
|
|
|
save_item(PL_curstname); |
5007
|
|
|
|
|
|
|
5008
|
898175
|
|
|
|
|
PL_curstash = (HV *)SvREFCNT_inc(gv_stashsv(sv, GV_ADD)); |
5009
|
|
|
|
|
|
|
5010
|
607902
|
|
|
|
|
sv_setsv(PL_curstname, sv); |
5011
|
|
|
|
|
|
|
5012
|
607902
|
|
|
|
|
PL_hints |= HINT_BLOCK_SCOPE; |
5013
|
607902
|
|
|
|
|
PL_parser->copline = NOLINE; |
5014
|
607902
|
|
|
|
|
PL_parser->expect = XSTATE; |
5015
|
|
|
|
|
|
|
5016
|
|
|
|
|
|
#ifndef PERL_MAD |
5017
|
607902
|
|
|
|
|
op_free(o); |
5018
|
|
|
|
|
|
#else |
5019
|
|
|
|
|
|
if (!PL_madskills) { |
5020
|
|
|
|
|
|
op_free(o); |
5021
|
|
|
|
|
|
return NULL; |
5022
|
|
|
|
|
|
} |
5023
|
|
|
|
|
|
|
5024
|
|
|
|
|
|
pegop = newOP(OP_NULL,0); |
5025
|
|
|
|
|
|
op_getmad(o,pegop,'P'); |
5026
|
|
|
|
|
|
return pegop; |
5027
|
|
|
|
|
|
#endif |
5028
|
607902
|
|
|
|
|
} |
5029
|
|
|
|
|
|
|
5030
|
|
|
|
|
|
void |
5031
|
100
|
|
|
|
|
Perl_package_version( pTHX_ OP *v ) |
5032
|
|
|
|
|
|
{ |
5033
|
|
|
|
|
|
dVAR; |
5034
|
100
|
|
|
|
|
U32 savehints = PL_hints; |
5035
|
|
|
|
|
|
PERL_ARGS_ASSERT_PACKAGE_VERSION; |
5036
|
100
|
|
|
|
|
PL_hints &= ~HINT_STRICT_VARS; |
5037
|
100
|
|
|
|
|
sv_setsv( GvSV(gv_fetchpvs("VERSION", GV_ADDMULTI, SVt_PV)), cSVOPx(v)->op_sv ); |
5038
|
100
|
|
|
|
|
PL_hints = savehints; |
5039
|
100
|
|
|
|
|
op_free(v); |
5040
|
100
|
|
|
|
|
} |
5041
|
|
|
|
|
|
|
5042
|
|
|
|
|
|
#ifdef PERL_MAD |
5043
|
|
|
|
|
|
OP* |
5044
|
|
|
|
|
|
#else |
5045
|
|
|
|
|
|
void |
5046
|
|
|
|
|
|
#endif |
5047
|
4381844
|
|
|
|
|
Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg) |
5048
|
|
|
|
|
|
{ |
5049
|
|
|
|
|
|
dVAR; |
5050
|
|
|
|
|
|
OP *pack; |
5051
|
|
|
|
|
|
OP *imop; |
5052
|
|
|
|
|
|
OP *veop; |
5053
|
|
|
|
|
|
#ifdef PERL_MAD |
5054
|
|
|
|
|
|
OP *pegop = PL_madskills ? newOP(OP_NULL,0) : NULL; |
5055
|
|
|
|
|
|
#endif |
5056
|
|
|
|
|
|
SV *use_version = NULL; |
5057
|
|
|
|
|
|
|
5058
|
|
|
|
|
|
PERL_ARGS_ASSERT_UTILIZE; |
5059
|
|
|
|
|
|
|
5060
|
4381844
|
50
|
|
|
|
if (idop->op_type != OP_CONST) |
5061
|
0
|
|
|
|
|
Perl_croak(aTHX_ "Module name must be constant"); |
5062
|
|
|
|
|
|
|
5063
|
|
|
|
|
|
if (PL_madskills) |
5064
|
|
|
|
|
|
op_getmad(idop,pegop,'U'); |
5065
|
|
|
|
|
|
|
5066
|
|
|
|
|
|
veop = NULL; |
5067
|
|
|
|
|
|
|
5068
|
4381844
|
100
|
|
|
|
if (version) { |
5069
|
29028
|
|
|
|
|
SV * const vesv = ((SVOP*)version)->op_sv; |
5070
|
|
|
|
|
|
|
5071
|
|
|
|
|
|
if (PL_madskills) |
5072
|
|
|
|
|
|
op_getmad(version,pegop,'V'); |
5073
|
29028
|
100
|
|
|
|
if (!arg && !SvNIOKp(vesv)) { |
|
|
100
|
|
|
|
|
5074
|
|
|
|
|
|
arg = version; |
5075
|
|
|
|
|
|
} |
5076
|
|
|
|
|
|
else { |
5077
|
|
|
|
|
|
OP *pack; |
5078
|
|
|
|
|
|
SV *meth; |
5079
|
|
|
|
|
|
|
5080
|
29026
|
50
|
|
|
|
if (version->op_type != OP_CONST || !SvNIOKp(vesv)) |
|
|
50
|
|
|
|
|
5081
|
0
|
|
|
|
|
Perl_croak(aTHX_ "Version number must be a constant number"); |
5082
|
|
|
|
|
|
|
5083
|
|
|
|
|
|
/* Make copy of idop so we don't free it twice */ |
5084
|
29026
|
|
|
|
|
pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)idop)->op_sv)); |
5085
|
|
|
|
|
|
|
5086
|
|
|
|
|
|
/* Fake up a method call to VERSION */ |
5087
|
29026
|
|
|
|
|
meth = newSVpvs_share("VERSION"); |
5088
|
29026
|
|
|
|
|
veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL, |
5089
|
|
|
|
|
|
op_append_elem(OP_LIST, |
5090
|
|
|
|
|
|
op_prepend_elem(OP_LIST, pack, list(version)), |
5091
|
|
|
|
|
|
newSVOP(OP_METHOD_NAMED, 0, meth))); |
5092
|
|
|
|
|
|
} |
5093
|
|
|
|
|
|
} |
5094
|
|
|
|
|
|
|
5095
|
|
|
|
|
|
/* Fake up an import/unimport */ |
5096
|
4381844
|
100
|
|
|
|
if (arg && arg->op_type == OP_STUB) { |
|
|
100
|
|
|
|
|
5097
|
|
|
|
|
|
if (PL_madskills) |
5098
|
|
|
|
|
|
op_getmad(arg,pegop,'S'); |
5099
|
|
|
|
|
|
imop = arg; /* no import on explicit () */ |
5100
|
|
|
|
|
|
} |
5101
|
4285602
|
100
|
|
|
|
else if (SvNIOKp(((SVOP*)idop)->op_sv)) { |
5102
|
|
|
|
|
|
imop = NULL; /* use 5.0; */ |
5103
|
81258
|
100
|
|
|
|
if (aver) |
5104
|
81224
|
|
|
|
|
use_version = ((SVOP*)idop)->op_sv; |
5105
|
|
|
|
|
|
else |
5106
|
34
|
|
|
|
|
idop->op_private |= OPpCONST_NOVER; |
5107
|
|
|
|
|
|
} |
5108
|
|
|
|
|
|
else { |
5109
|
|
|
|
|
|
SV *meth; |
5110
|
|
|
|
|
|
|
5111
|
|
|
|
|
|
if (PL_madskills) |
5112
|
|
|
|
|
|
op_getmad(arg,pegop,'A'); |
5113
|
|
|
|
|
|
|
5114
|
|
|
|
|
|
/* Make copy of idop so we don't free it twice */ |
5115
|
4204344
|
|
|
|
|
pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)idop)->op_sv)); |
5116
|
|
|
|
|
|
|
5117
|
|
|
|
|
|
/* Fake up a method call to import/unimport */ |
5118
|
|
|
|
|
|
meth = aver |
5119
|
4204344
|
100
|
|
|
|
? newSVpvs_share("import") : newSVpvs_share("unimport"); |
5120
|
4204344
|
|
|
|
|
imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL, |
5121
|
|
|
|
|
|
op_append_elem(OP_LIST, |
5122
|
|
|
|
|
|
op_prepend_elem(OP_LIST, pack, list(arg)), |
5123
|
|
|
|
|
|
newSVOP(OP_METHOD_NAMED, 0, meth))); |
5124
|
|
|
|
|
|
} |
5125
|
|
|
|
|
|
|
5126
|
|
|
|
|
|
/* Fake up the BEGIN {}, which does its thing immediately. */ |
5127
|
4381844
|
|
|
|
|
newATTRSUB(floor, |
5128
|
|
|
|
|
|
newSVOP(OP_CONST, 0, newSVpvs_share("BEGIN")), |
5129
|
|
|
|
|
|
NULL, |
5130
|
|
|
|
|
|
NULL, |
5131
|
|
|
|
|
|
op_append_elem(OP_LINESEQ, |
5132
|
|
|
|
|
|
op_append_elem(OP_LINESEQ, |
5133
|
|
|
|
|
|
newSTATEOP(0, NULL, newUNOP(OP_REQUIRE, 0, idop)), |
5134
|
|
|
|
|
|
newSTATEOP(0, NULL, veop)), |
5135
|
|
|
|
|
|
newSTATEOP(0, NULL, imop) )); |
5136
|
|
|
|
|
|
|
5137
|
4356480
|
100
|
|
|
|
if (use_version) { |
5138
|
|
|
|
|
|
/* Enable the |
5139
|
|
|
|
|
|
* feature bundle that corresponds to the required version. */ |
5140
|
81194
|
|
|
|
|
use_version = sv_2mortal(new_version(use_version)); |
5141
|
|
|
|
|
|
S_enable_feature_bundle(aTHX_ use_version); |
5142
|
|
|
|
|
|
|
5143
|
|
|
|
|
|
/* If a version >= 5.11.0 is requested, strictures are on by default! */ |
5144
|
81194
|
100
|
|
|
|
if (vcmp(use_version, |
5145
|
|
|
|
|
|
sv_2mortal(upg_version(newSVnv(5.011000), FALSE))) >= 0) { |
5146
|
250
|
100
|
|
|
|
if (!(PL_hints & HINT_EXPLICIT_STRICT_REFS)) |
5147
|
238
|
|
|
|
|
PL_hints |= HINT_STRICT_REFS; |
5148
|
250
|
100
|
|
|
|
if (!(PL_hints & HINT_EXPLICIT_STRICT_SUBS)) |
5149
|
236
|
|
|
|
|
PL_hints |= HINT_STRICT_SUBS; |
5150
|
250
|
100
|
|
|
|
if (!(PL_hints & HINT_EXPLICIT_STRICT_VARS)) |
5151
|
238
|
|
|
|
|
PL_hints |= HINT_STRICT_VARS; |
5152
|
|
|
|
|
|
} |
5153
|
|
|
|
|
|
/* otherwise they are off */ |
5154
|
|
|
|
|
|
else { |
5155
|
80944
|
100
|
|
|
|
if (!(PL_hints & HINT_EXPLICIT_STRICT_REFS)) |
5156
|
72446
|
|
|
|
|
PL_hints &= ~HINT_STRICT_REFS; |
5157
|
80944
|
100
|
|
|
|
if (!(PL_hints & HINT_EXPLICIT_STRICT_SUBS)) |
5158
|
72446
|
|
|
|
|
PL_hints &= ~HINT_STRICT_SUBS; |
5159
|
80944
|
100
|
|
|
|
if (!(PL_hints & HINT_EXPLICIT_STRICT_VARS)) |
5160
|
72446
|
|
|
|
|
PL_hints &= ~HINT_STRICT_VARS; |
5161
|
|
|
|
|
|
} |
5162
|
|
|
|
|
|
} |
5163
|
|
|
|
|
|
|
5164
|
|
|
|
|
|
/* The "did you use incorrect case?" warning used to be here. |
5165
|
|
|
|
|
|
* The problem is that on case-insensitive filesystems one |
5166
|
|
|
|
|
|
* might get false positives for "use" (and "require"): |
5167
|
|
|
|
|
|
* "use Strict" or "require CARP" will work. This causes |
5168
|
|
|
|
|
|
* portability problems for the script: in case-strict |
5169
|
|
|
|
|
|
* filesystems the script will stop working. |
5170
|
|
|
|
|
|
* |
5171
|
|
|
|
|
|
* The "incorrect case" warning checked whether "use Foo" |
5172
|
|
|
|
|
|
* imported "Foo" to your namespace, but that is wrong, too: |
5173
|
|
|
|
|
|
* there is no requirement nor promise in the language that |
5174
|
|
|
|
|
|
* a Foo.pm should or would contain anything in package "Foo". |
5175
|
|
|
|
|
|
* |
5176
|
|
|
|
|
|
* There is very little Configure-wise that can be done, either: |
5177
|
|
|
|
|
|
* the case-sensitivity of the build filesystem of Perl does not |
5178
|
|
|
|
|
|
* help in guessing the case-sensitivity of the runtime environment. |
5179
|
|
|
|
|
|
*/ |
5180
|
|
|
|
|
|
|
5181
|
4356480
|
|
|
|
|
PL_hints |= HINT_BLOCK_SCOPE; |
5182
|
4356480
|
|
|
|
|
PL_parser->copline = NOLINE; |
5183
|
4356480
|
|
|
|
|
PL_parser->expect = XSTATE; |
5184
|
4356480
|
|
|
|
|
PL_cop_seqmax++; /* Purely for B::*'s benefit */ |
5185
|
4356480
|
50
|
|
|
|
if (PL_cop_seqmax == PERL_PADSEQ_INTRO) /* not a legal value */ |
5186
|
0
|
|
|
|
|
PL_cop_seqmax++; |
5187
|
|
|
|
|
|
|
5188
|
|
|
|
|
|
#ifdef PERL_MAD |
5189
|
|
|
|
|
|
return pegop; |
5190
|
|
|
|
|
|
#endif |
5191
|
4356480
|
|
|
|
|
} |
5192
|
|
|
|
|
|
|
5193
|
|
|
|
|
|
/* |
5194
|
|
|
|
|
|
=head1 Embedding Functions |
5195
|
|
|
|
|
|
|
5196
|
|
|
|
|
|
=for apidoc load_module |
5197
|
|
|
|
|
|
|
5198
|
|
|
|
|
|
Loads the module whose name is pointed to by the string part of name. |
5199
|
|
|
|
|
|
Note that the actual module name, not its filename, should be given. |
5200
|
|
|
|
|
|
Eg, "Foo::Bar" instead of "Foo/Bar.pm". flags can be any of |
5201
|
|
|
|
|
|
PERL_LOADMOD_DENY, PERL_LOADMOD_NOIMPORT, or PERL_LOADMOD_IMPORT_OPS |
5202
|
|
|
|
|
|
(or 0 for no flags). ver, if specified and not NULL, provides version semantics |
5203
|
|
|
|
|
|
similar to C |
5204
|
|
|
|
|
|
arguments can be used to specify arguments to the module's import() |
5205
|
|
|
|
|
|
method, similar to C |
5206
|
|
|
|
|
|
terminated with a final NULL pointer. Note that this list can only |
5207
|
|
|
|
|
|
be omitted when the PERL_LOADMOD_NOIMPORT flag has been used. |
5208
|
|
|
|
|
|
Otherwise at least a single NULL pointer to designate the default |
5209
|
|
|
|
|
|
import list is required. |
5210
|
|
|
|
|
|
|
5211
|
|
|
|
|
|
The reference count for each specified C parameter is decremented. |
5212
|
|
|
|
|
|
|
5213
|
|
|
|
|
|
=cut */ |
5214
|
|
|
|
|
|
|
5215
|
|
|
|
|
|
void |
5216
|
13038
|
|
|
|
|
Perl_load_module(pTHX_ U32 flags, SV *name, SV *ver, ...) |
5217
|
|
|
|
|
|
{ |
5218
|
|
|
|
|
|
va_list args; |
5219
|
|
|
|
|
|
|
5220
|
|
|
|
|
|
PERL_ARGS_ASSERT_LOAD_MODULE; |
5221
|
|
|
|
|
|
|
5222
|
13038
|
|
|
|
|
va_start(args, ver); |
5223
|
13038
|
|
|
|
|
vload_module(flags, name, ver, &args); |
5224
|
12926
|
|
|
|
|
va_end(args); |
5225
|
12926
|
|
|
|
|
} |
5226
|
|
|
|
|
|
|
5227
|
|
|
|
|
|
#ifdef PERL_IMPLICIT_CONTEXT |
5228
|
|
|
|
|
|
void |
5229
|
|
|
|
|
|
Perl_load_module_nocontext(U32 flags, SV *name, SV *ver, ...) |
5230
|
|
|
|
|
|
{ |
5231
|
|
|
|
|
|
dTHX; |
5232
|
|
|
|
|
|
va_list args; |
5233
|
|
|
|
|
|
PERL_ARGS_ASSERT_LOAD_MODULE_NOCONTEXT; |
5234
|
|
|
|
|
|
va_start(args, ver); |
5235
|
|
|
|
|
|
vload_module(flags, name, ver, &args); |
5236
|
|
|
|
|
|
va_end(args); |
5237
|
|
|
|
|
|
} |
5238
|
|
|
|
|
|
#endif |
5239
|
|
|
|
|
|
|
5240
|
|
|
|
|
|
void |
5241
|
13038
|
|
|
|
|
Perl_vload_module(pTHX_ U32 flags, SV *name, SV *ver, va_list *args) |
5242
|
|
|
|
|
|
{ |
5243
|
|
|
|
|
|
dVAR; |
5244
|
|
|
|
|
|
OP *veop, *imop; |
5245
|
13038
|
|
|
|
|
OP * const modname = newSVOP(OP_CONST, 0, name); |
5246
|
|
|
|
|
|
|
5247
|
|
|
|
|
|
PERL_ARGS_ASSERT_VLOAD_MODULE; |
5248
|
|
|
|
|
|
|
5249
|
13038
|
|
|
|
|
modname->op_private |= OPpCONST_BARE; |
5250
|
13038
|
100
|
|
|
|
if (ver) { |
5251
|
18
|
|
|
|
|
veop = newSVOP(OP_CONST, 0, ver); |
5252
|
|
|
|
|
|
} |
5253
|
|
|
|
|
|
else |
5254
|
|
|
|
|
|
veop = NULL; |
5255
|
13038
|
100
|
|
|
|
if (flags & PERL_LOADMOD_NOIMPORT) { |
5256
|
12638
|
|
|
|
|
imop = sawparens(newNULLLIST()); |
5257
|
|
|
|
|
|
} |
5258
|
400
|
100
|
|
|
|
else if (flags & PERL_LOADMOD_IMPORT_OPS) { |
5259
|
118
|
50
|
|
|
|
imop = va_arg(*args, OP*); |
5260
|
|
|
|
|
|
} |
5261
|
|
|
|
|
|
else { |
5262
|
|
|
|
|
|
SV *sv; |
5263
|
|
|
|
|
|
imop = NULL; |
5264
|
282
|
50
|
|
|
|
sv = va_arg(*args, SV*); |
5265
|
807
|
100
|
|
|
|
while (sv) { |
5266
|
384
|
|
|
|
|
imop = op_append_elem(OP_LIST, imop, newSVOP(OP_CONST, 0, sv)); |
5267
|
384
|
50
|
|
|
|
sv = va_arg(*args, SV*); |
5268
|
|
|
|
|
|
} |
5269
|
|
|
|
|
|
} |
5270
|
|
|
|
|
|
|
5271
|
|
|
|
|
|
/* utilize() fakes up a BEGIN { require ..; import ... }, so make sure |
5272
|
|
|
|
|
|
* that it has a PL_parser to play with while doing that, and also |
5273
|
|
|
|
|
|
* that it doesn't mess with any existing parser, by creating a tmp |
5274
|
|
|
|
|
|
* new parser with lex_start(). This won't actually be used for much, |
5275
|
|
|
|
|
|
* since pp_require() will create another parser for the real work. */ |
5276
|
|
|
|
|
|
|
5277
|
13038
|
|
|
|
|
ENTER; |
5278
|
13038
|
|
|
|
|
SAVEVPTR(PL_curcop); |
5279
|
13038
|
|
|
|
|
lex_start(NULL, NULL, LEX_START_SAME_FILTER); |
5280
|
13038
|
|
|
|
|
utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0), |
5281
|
|
|
|
|
|
veop, modname, imop); |
5282
|
12926
|
|
|
|
|
LEAVE; |
5283
|
12926
|
|
|
|
|
} |
5284
|
|
|
|
|
|
|
5285
|
|
|
|
|
|
OP * |
5286
|
21380
|
|
|
|
|
Perl_dofile(pTHX_ OP *term, I32 force_builtin) |
5287
|
|
|
|
|
|
{ |
5288
|
|
|
|
|
|
dVAR; |
5289
|
|
|
|
|
|
OP *doop; |
5290
|
|
|
|
|
|
GV *gv = NULL; |
5291
|
|
|
|
|
|
|
5292
|
|
|
|
|
|
PERL_ARGS_ASSERT_DOFILE; |
5293
|
|
|
|
|
|
|
5294
|
21380
|
50
|
|
|
|
if (!force_builtin) { |
5295
|
21380
|
|
|
|
|
gv = gv_fetchpvs("do", GV_NOTQUAL, SVt_PVCV); |
5296
|
21380
|
50
|
|
|
|
if (!(gv && GvCVu(gv) && GvIMPORTED_CV(gv))) { |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
5297
|
21380
|
|
|
|
|
GV * const * const gvp = (GV**)hv_fetchs(PL_globalstash, "do", FALSE); |
5298
|
21380
|
50
|
|
|
|
gv = gvp ? *gvp : NULL; |
5299
|
|
|
|
|
|
} |
5300
|
|
|
|
|
|
} |
5301
|
|
|
|
|
|
|
5302
|
21380
|
50
|
|
|
|
if (gv && GvCVu(gv) && GvIMPORTED_CV(gv)) { |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
5303
|
0
|
|
|
|
|
doop = newUNOP(OP_ENTERSUB, OPf_STACKED, |
5304
|
|
|
|
|
|
op_append_elem(OP_LIST, term, |
5305
|
|
|
|
|
|
scalar(newUNOP(OP_RV2CV, 0, |
5306
|
|
|
|
|
|
newGVOP(OP_GV, 0, gv))))); |
5307
|
|
|
|
|
|
} |
5308
|
|
|
|
|
|
else { |
5309
|
21380
|
|
|
|
|
doop = newUNOP(OP_DOFILE, 0, scalar(term)); |
5310
|
|
|
|
|
|
} |
5311
|
21380
|
|
|
|
|
return doop; |
5312
|
|
|
|
|
|
} |
5313
|
|
|
|
|
|
|
5314
|
|
|
|
|
|
/* |
5315
|
|
|
|
|
|
=head1 Optree construction |
5316
|
|
|
|
|
|
|
5317
|
|
|
|
|
|
=for apidoc Am|OP *|newSLICEOP|I32 flags|OP *subscript|OP *listval |
5318
|
|
|
|
|
|
|
5319
|
|
|
|
|
|
Constructs, checks, and returns an C (list slice) op. I |
5320
|
|
|
|
|
|
gives the eight bits of C, except that C will |
5321
|
|
|
|
|
|
be set automatically, and, shifted up eight bits, the eight bits of |
5322
|
|
|
|
|
|
C, except that the bit with value 1 or 2 is automatically |
5323
|
|
|
|
|
|
set as required. I and I supply the parameters of |
5324
|
|
|
|
|
|
the slice; they are consumed by this function and become part of the |
5325
|
|
|
|
|
|
constructed op tree. |
5326
|
|
|
|
|
|
|
5327
|
|
|
|
|
|
=cut |
5328
|
|
|
|
|
|
*/ |
5329
|
|
|
|
|
|
|
5330
|
|
|
|
|
|
OP * |
5331
|
273503
|
|
|
|
|
Perl_newSLICEOP(pTHX_ I32 flags, OP *subscript, OP *listval) |
5332
|
|
|
|
|
|
{ |
5333
|
273503
|
|
|
|
|
return newBINOP(OP_LSLICE, flags, |
5334
|
|
|
|
|
|
list(force_list(subscript)), |
5335
|
|
|
|
|
|
list(force_list(listval)) ); |
5336
|
|
|
|
|
|
} |
5337
|
|
|
|
|
|
|
5338
|
|
|
|
|
|
STATIC I32 |
5339
|
25598199
|
|
|
|
|
S_is_list_assignment(pTHX_ const OP *o) |
5340
|
|
|
|
|
|
{ |
5341
|
|
|
|
|
|
unsigned type; |
5342
|
|
|
|
|
|
U8 flags; |
5343
|
|
|
|
|
|
|
5344
|
25598199
|
50
|
|
|
|
if (!o) |
5345
|
|
|
|
|
|
return TRUE; |
5346
|
|
|
|
|
|
|
5347
|
25598199
|
100
|
|
|
|
if ((o->op_type == OP_NULL) && (o->op_flags & OPf_KIDS)) |
|
|
50
|
|
|
|
|
5348
|
588
|
|
|
|
|
o = cUNOPo->op_first; |
5349
|
|
|
|
|
|
|
5350
|
25598199
|
|
|
|
|
flags = o->op_flags; |
5351
|
25598199
|
|
|
|
|
type = o->op_type; |
5352
|
25598199
|
100
|
|
|
|
if (type == OP_COND_EXPR) { |
5353
|
588
|
|
|
|
|
const I32 t = is_list_assignment(cLOGOPo->op_first->op_sibling); |
5354
|
588
|
|
|
|
|
const I32 f = is_list_assignment(cLOGOPo->op_first->op_sibling->op_sibling); |
5355
|
|
|
|
|
|
|
5356
|
588
|
50
|
|
|
|
if (t && f) |
5357
|
|
|
|
|
|
return TRUE; |
5358
|
588
|
100
|
|
|
|
if (t || f) |
5359
|
2
|
|
|
|
|
yyerror("Assignment to both a list and a scalar"); |
5360
|
|
|
|
|
|
return FALSE; |
5361
|
|
|
|
|
|
} |
5362
|
|
|
|
|
|
|
5363
|
26823837
|
100
|
|
|
|
if (type == OP_LIST && |
|
|
100
|
|
|
|
|
5364
|
1226236
|
50
|
|
|
|
(flags & OPf_WANT) == OPf_WANT_SCALAR && |
5365
|
10
|
|
|
|
|
o->op_private & OPpLVAL_INTRO) |
5366
|
|
|
|
|
|
return FALSE; |
5367
|
|
|
|
|
|
|
5368
|
36716455
|
100
|
|
|
|
if (type == OP_LIST || flags & OPf_PARENS || |
|
|
100
|
|
|
|
|
5369
|
42900945
|
100
|
|
|
|
type == OP_RV2AV || type == OP_RV2HV || |
5370
|
31610860
|
100
|
|
|
|
type == OP_ASLICE || type == OP_HSLICE) |
5371
|
|
|
|
|
|
return TRUE; |
5372
|
|
|
|
|
|
|
5373
|
23442950
|
100
|
|
|
|
if (type == OP_PADAV || type == OP_PADHV) |
5374
|
|
|
|
|
|
return TRUE; |
5375
|
|
|
|
|
|
|
5376
|
|
|
|
|
|
if (type == OP_RV2SV) |
5377
|
|
|
|
|
|
return FALSE; |
5378
|
|
|
|
|
|
|
5379
|
|
|
|
|
|
return FALSE; |
5380
|
|
|
|
|
|
} |
5381
|
|
|
|
|
|
|
5382
|
|
|
|
|
|
/* |
5383
|
|
|
|
|
|
Helper function for newASSIGNOP to detection commonality between the |
5384
|
|
|
|
|
|
lhs and the rhs. Marks all variables with PL_generation. If it |
5385
|
|
|
|
|
|
returns TRUE the assignment must be able to handle common variables. |
5386
|
|
|
|
|
|
*/ |
5387
|
|
|
|
|
|
PERL_STATIC_INLINE bool |
5388
|
10537289
|
|
|
|
|
S_aassign_common_vars(pTHX_ OP* o) |
5389
|
|
|
|
|
|
{ |
5390
|
|
|
|
|
|
OP *curop; |
5391
|
51088455
|
100
|
|
|
|
for (curop = cUNOPo->op_first; curop; curop=curop->op_sibling) { |
5392
|
42329831
|
100
|
|
|
|
if (PL_opargs[curop->op_type] & OA_DANGEROUS) { |
5393
|
5261450
|
100
|
|
|
|
if (curop->op_type == OP_GV) { |
5394
|
1311532
|
|
|
|
|
GV *gv = cGVOPx_gv(curop); |
5395
|
1311532
|
100
|
|
|
|
if (gv == PL_defgv |
5396
|
1131080
|
100
|
|
|
|
|| (int)GvASSIGN_GENERATION(gv) == PL_generation) |
5397
|
|
|
|
|
|
return TRUE; |
5398
|
1096408
|
|
|
|
|
GvASSIGN_GENERATION_set(gv, PL_generation); |
5399
|
|
|
|
|
|
} |
5400
|
5847664
|
100
|
|
|
|
else if (curop->op_type == OP_PADSV || |
5401
|
|
|
|
|
|
curop->op_type == OP_PADAV || |
5402
|
3949918
|
|
|
|
|
curop->op_type == OP_PADHV || |
5403
|
|
|
|
|
|
curop->op_type == OP_PADANY) |
5404
|
|
|
|
|
|
{ |
5405
|
1963822
|
100
|
|
|
|
if (PAD_COMPNAME_GEN(curop->op_targ) |
5406
|
1325773
|
|
|
|
|
== (STRLEN)PL_generation) |
5407
|
|
|
|
|
|
return TRUE; |
5408
|
1285893
|
|
|
|
|
PAD_COMPNAME_GEN_set(curop->op_targ, PL_generation); |
5409
|
|
|
|
|
|
|
5410
|
|
|
|
|
|
} |
5411
|
2624145
|
100
|
|
|
|
else if (curop->op_type == OP_RV2CV) |
5412
|
|
|
|
|
|
return TRUE; |
5413
|
2618655
|
100
|
|
|
|
else if (curop->op_type == OP_RV2SV || |
5414
|
1338702
|
100
|
|
|
|
curop->op_type == OP_RV2AV || |
5415
|
1603430
|
100
|
|
|
|
curop->op_type == OP_RV2HV || |
5416
|
958197
|
|
|
|
|
curop->op_type == OP_RV2GV) { |
5417
|
1672864
|
100
|
|
|
|
if (cUNOPx(curop)->op_first->op_type != OP_GV) /* funny deref? */ |
5418
|
|
|
|
|
|
return TRUE; |
5419
|
|
|
|
|
|
} |
5420
|
945791
|
100
|
|
|
|
else if (curop->op_type == OP_PUSHRE) { |
5421
|
89930
|
|
|
|
|
GV *const gv = |
5422
|
|
|
|
|
|
#ifdef USE_ITHREADS |
5423
|
|
|
|
|
|
((PMOP*)curop)->op_pmreplrootu.op_pmtargetoff |
5424
|
|
|
|
|
|
? MUTABLE_GV(PAD_SVl(((PMOP*)curop)->op_pmreplrootu.op_pmtargetoff)) |
5425
|
|
|
|
|
|
: NULL; |
5426
|
|
|
|
|
|
#else |
5427
|
|
|
|
|
|
((PMOP*)curop)->op_pmreplrootu.op_pmtargetgv; |
5428
|
|
|
|
|
|
#endif |
5429
|
89930
|
100
|
|
|
|
if (gv) { |
5430
|
2
|
50
|
|
|
|
if (gv == PL_defgv |
5431
|
2
|
50
|
|
|
|
|| (int)GvASSIGN_GENERATION(gv) == PL_generation) |
5432
|
|
|
|
|
|
return TRUE; |
5433
|
2
|
|
|
|
|
GvASSIGN_GENERATION_set(gv, PL_generation); |
5434
|
|
|
|
|
|
} |
5435
|
|
|
|
|
|
} |
5436
|
|
|
|
|
|
else |
5437
|
|
|
|
|
|
return TRUE; |
5438
|
|
|
|
|
|
} |
5439
|
|
|
|
|
|
|
5440
|
40849170
|
100
|
|
|
|
if (curop->op_flags & OPf_KIDS) { |
5441
|
7528564
|
100
|
|
|
|
if (aassign_common_vars(curop)) |
5442
|
|
|
|
|
|
return TRUE; |
5443
|
|
|
|
|
|
} |
5444
|
|
|
|
|
|
} |
5445
|
|
|
|
|
|
return FALSE; |
5446
|
|
|
|
|
|
} |
5447
|
|
|
|
|
|
|
5448
|
|
|
|
|
|
/* |
5449
|
|
|
|
|
|
=for apidoc Am|OP *|newASSIGNOP|I32 flags|OP *left|I32 optype|OP *right |
5450
|
|
|
|
|
|
|
5451
|
|
|
|
|
|
Constructs, checks, and returns an assignment op. I and I |
5452
|
|
|
|
|
|
supply the parameters of the assignment; they are consumed by this |
5453
|
|
|
|
|
|
function and become part of the constructed op tree. |
5454
|
|
|
|
|
|
|
5455
|
|
|
|
|
|
If I is C, C, or C, then |
5456
|
|
|
|
|
|
a suitable conditional optree is constructed. If I is the opcode |
5457
|
|
|
|
|
|
of a binary operator, such as C, then an op is constructed that |
5458
|
|
|
|
|
|
performs the binary operation and assigns the result to the left argument. |
5459
|
|
|
|
|
|
Either way, if I is non-zero then I has no effect. |
5460
|
|
|
|
|
|
|
5461
|
|
|
|
|
|
If I is zero, then a plain scalar or list assignment is |
5462
|
|
|
|
|
|
constructed. Which type of assignment it is is automatically determined. |
5463
|
|
|
|
|
|
I gives the eight bits of C, except that C |
5464
|
|
|
|
|
|
will be set automatically, and, shifted up eight bits, the eight bits |
5465
|
|
|
|
|
|
of C, except that the bit with value 1 or 2 is automatically |
5466
|
|
|
|
|
|
set as required. |
5467
|
|
|
|
|
|
|
5468
|
|
|
|
|
|
=cut |
5469
|
|
|
|
|
|
*/ |
5470
|
|
|
|
|
|
|
5471
|
|
|
|
|
|
OP * |
5472
|
27580533
|
|
|
|
|
Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right) |
5473
|
|
|
|
|
|
{ |
5474
|
|
|
|
|
|
dVAR; |
5475
|
|
|
|
|
|
OP *o; |
5476
|
|
|
|
|
|
|
5477
|
27580533
|
100
|
|
|
|
if (optype) { |
5478
|
1983510
|
100
|
|
|
|
if (optype == OP_ANDASSIGN || optype == OP_ORASSIGN || optype == OP_DORASSIGN) { |
5479
|
733462
|
|
|
|
|
return newLOGOP(optype, 0, |
5480
|
|
|
|
|
|
op_lvalue(scalar(left), optype), |
5481
|
|
|
|
|
|
newUNOP(OP_SASSIGN, 0, scalar(right))); |
5482
|
|
|
|
|
|
} |
5483
|
|
|
|
|
|
else { |
5484
|
1616779
|
|
|
|
|
return newBINOP(optype, OPf_STACKED, |
5485
|
|
|
|
|
|
op_lvalue(scalar(left), optype), scalar(right)); |
5486
|
|
|
|
|
|
} |
5487
|
|
|
|
|
|
} |
5488
|
|
|
|
|
|
|
5489
|
25597023
|
100
|
|
|
|
if (is_list_assignment(left)) { |
5490
|
|
|
|
|
|
static const char no_list_state[] = "Initialization of state variables" |
5491
|
|
|
|
|
|
" in list context currently forbidden"; |
5492
|
|
|
|
|
|
OP *curop; |
5493
|
|
|
|
|
|
bool maybe_common_vars = TRUE; |
5494
|
|
|
|
|
|
|
5495
|
5796374
|
|
|
|
|
PL_modcount = 0; |
5496
|
5796374
|
|
|
|
|
left = op_lvalue(left, OP_AASSIGN); |
5497
|
5796374
|
|
|
|
|
curop = list(force_list(left)); |
5498
|
5796374
|
|
|
|
|
o = newBINOP(OP_AASSIGN, flags, list(force_list(right)), curop); |
5499
|
5796374
|
|
|
|
|
o->op_private = (U8)(0 | (flags >> 8)); |
5500
|
|
|
|
|
|
|
5501
|
5796374
|
50
|
|
|
|
if ((left->op_type == OP_LIST |
5502
|
5796374
|
100
|
|
|
|
|| (left->op_type == OP_NULL && left->op_targ == OP_LIST))) |
|
|
50
|
|
|
|
|
5503
|
|
|
|
|
|
{ |
5504
|
2541713
|
|
|
|
|
OP* lop = ((LISTOP*)left)->op_first; |
5505
|
|
|
|
|
|
maybe_common_vars = FALSE; |
5506
|
12816518
|
100
|
|
|
|
while (lop) { |
5507
|
13409452
|
100
|
|
|
|
if (lop->op_type == OP_PADSV || |
5508
|
|
|
|
|
|
lop->op_type == OP_PADAV || |
5509
|
9048584
|
|
|
|
|
lop->op_type == OP_PADHV || |
5510
|
|
|
|
|
|
lop->op_type == OP_PADANY) { |
5511
|
6269646
|
100
|
|
|
|
if (!(lop->op_private & OPpLVAL_INTRO)) |
5512
|
|
|
|
|
|
maybe_common_vars = TRUE; |
5513
|
|
|
|
|
|
|
5514
|
6269646
|
100
|
|
|
|
if (lop->op_private & OPpPAD_STATE) { |
5515
|
|
|
|
|
|
if (left->op_private & OPpLVAL_INTRO) { |
5516
|
|
|
|
|
|
/* Each variable in state($a, $b, $c) = ... */ |
5517
|
|
|
|
|
|
} |
5518
|
|
|
|
|
|
else { |
5519
|
|
|
|
|
|
/* Each state variable in |
5520
|
|
|
|
|
|
(state $a, my $b, our $c, $d, undef) = ... */ |
5521
|
|
|
|
|
|
} |
5522
|
30
|
|
|
|
|
yyerror(no_list_state); |
5523
|
|
|
|
|
|
} else { |
5524
|
|
|
|
|
|
/* Each my variable in |
5525
|
|
|
|
|
|
(state $a, my $b, our $c, $d, undef) = ... */ |
5526
|
|
|
|
|
|
} |
5527
|
2778938
|
100
|
|
|
|
} else if (lop->op_type == OP_UNDEF || |
5528
|
|
|
|
|
|
lop->op_type == OP_PUSHMARK) { |
5529
|
|
|
|
|
|
/* undef may be interesting in |
5530
|
|
|
|
|
|
(state $a, undef, state $c) */ |
5531
|
|
|
|
|
|
} else { |
5532
|
|
|
|
|
|
/* Other ops in the list. */ |
5533
|
|
|
|
|
|
maybe_common_vars = TRUE; |
5534
|
|
|
|
|
|
} |
5535
|
9048584
|
|
|
|
|
lop = lop->op_sibling; |
5536
|
|
|
|
|
|
} |
5537
|
|
|
|
|
|
} |
5538
|
3254661
|
100
|
|
|
|
else if ((left->op_private & OPpLVAL_INTRO) |
5539
|
2544123
|
100
|
|
|
|
&& ( left->op_type == OP_PADSV |
5540
|
|
|
|
|
|
|| left->op_type == OP_PADAV |
5541
|
|
|
|
|
|
|| left->op_type == OP_PADHV |
5542
|
1713600
|
|
|
|
|
|| left->op_type == OP_PADANY)) |
5543
|
|
|
|
|
|
{ |
5544
|
1577234
|
100
|
|
|
|
if (left->op_type == OP_PADSV) maybe_common_vars = FALSE; |
5545
|
1577234
|
100
|
|
|
|
if (left->op_private & OPpPAD_STATE) { |
5546
|
|
|
|
|
|
/* All single variable list context state assignments, hence |
5547
|
|
|
|
|
|
state ($a) = ... |
5548
|
|
|
|
|
|
(state $a) = ... |
5549
|
|
|
|
|
|
state @a = ... |
5550
|
|
|
|
|
|
state (@a) = ... |
5551
|
|
|
|
|
|
(state @a) = ... |
5552
|
|
|
|
|
|
state %a = ... |
5553
|
|
|
|
|
|
state (%a) = ... |
5554
|
|
|
|
|
|
(state %a) = ... |
5555
|
|
|
|
|
|
*/ |
5556
|
16
|
|
|
|
|
yyerror(no_list_state); |
5557
|
|
|
|
|
|
} |
5558
|
|
|
|
|
|
} |
5559
|
|
|
|
|
|
|
5560
|
|
|
|
|
|
/* PL_generation sorcery: |
5561
|
|
|
|
|
|
* an assignment like ($a,$b) = ($c,$d) is easier than |
5562
|
|
|
|
|
|
* ($a,$b) = ($c,$a), since there is no need for temporary vars. |
5563
|
|
|
|
|
|
* To detect whether there are common vars, the global var |
5564
|
|
|
|
|
|
* PL_generation is incremented for each assign op we compile. |
5565
|
|
|
|
|
|
* Then, while compiling the assign op, we run through all the |
5566
|
|
|
|
|
|
* variables on both sides of the assignment, setting a spare slot |
5567
|
|
|
|
|
|
* in each of them to PL_generation. If any of them already have |
5568
|
|
|
|
|
|
* that value, we know we've got commonality. We could use a |
5569
|
|
|
|
|
|
* single bit marker, but then we'd have to make 2 passes, first |
5570
|
|
|
|
|
|
* to clear the flag, then to test and set it. To find somewhere |
5571
|
|
|
|
|
|
* to store these values, evil chicanery is done with SvUVX(). |
5572
|
|
|
|
|
|
*/ |
5573
|
|
|
|
|
|
|
5574
|
5796374
|
100
|
|
|
|
if (maybe_common_vars) { |
5575
|
3008725
|
|
|
|
|
PL_generation++; |
5576
|
3008725
|
100
|
|
|
|
if (aassign_common_vars(o)) |
5577
|
1480661
|
|
|
|
|
o->op_private |= OPpASSIGN_COMMON; |
5578
|
3008725
|
50
|
|
|
|
LINKLIST(o); |
5579
|
|
|
|
|
|
} |
5580
|
|
|
|
|
|
|
5581
|
5796374
|
50
|
|
|
|
if (right && right->op_type == OP_SPLIT && !PL_madskills) { |
|
|
100
|
|
|
|
|
5582
|
111654
|
|
|
|
|
OP* tmpop = ((LISTOP*)right)->op_first; |
5583
|
111654
|
50
|
|
|
|
if (tmpop && (tmpop->op_type == OP_PUSHRE)) { |
|
|
50
|
|
|
|
|
5584
|
|
|
|
|
|
PMOP * const pm = (PMOP*)tmpop; |
5585
|
111733
|
100
|
|
|
|
if (left->op_type == OP_RV2AV && |
|
|
50
|
|
|
|
|
5586
|
237
|
100
|
|
|
|
!(left->op_private & OPpLVAL_INTRO) && |
5587
|
158
|
|
|
|
|
!(o->op_private & OPpASSIGN_COMMON) ) |
5588
|
|
|
|
|
|
{ |
5589
|
82
|
|
|
|
|
tmpop = ((UNOP*)left)->op_first; |
5590
|
82
|
50
|
|
|
|
if (tmpop->op_type == OP_GV |
5591
|
|
|
|
|
|
#ifdef USE_ITHREADS |
5592
|
|
|
|
|
|
&& !pm->op_pmreplrootu.op_pmtargetoff |
5593
|
|
|
|
|
|
#else |
5594
|
82
|
100
|
|
|
|
&& !pm->op_pmreplrootu.op_pmtargetgv |
5595
|
|
|
|
|
|
#endif |
5596
|
|
|
|
|
|
) { |
5597
|
|
|
|
|
|
#ifdef USE_ITHREADS |
5598
|
|
|
|
|
|
pm->op_pmreplrootu.op_pmtargetoff |
5599
|
|
|
|
|
|
= cPADOPx(tmpop)->op_padix; |
5600
|
|
|
|
|
|
cPADOPx(tmpop)->op_padix = 0; /* steal it */ |
5601
|
|
|
|
|
|
#else |
5602
|
|
|
|
|
|
pm->op_pmreplrootu.op_pmtargetgv |
5603
|
80
|
|
|
|
|
= MUTABLE_GV(cSVOPx(tmpop)->op_sv); |
5604
|
80
|
|
|
|
|
cSVOPx(tmpop)->op_sv = NULL; /* steal it */ |
5605
|
|
|
|
|
|
#endif |
5606
|
80
|
|
|
|
|
tmpop = cUNOPo->op_first; /* to list (nulled) */ |
5607
|
80
|
|
|
|
|
tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */ |
5608
|
80
|
|
|
|
|
tmpop->op_sibling = NULL; /* don't free split */ |
5609
|
80
|
|
|
|
|
right->op_next = tmpop->op_next; /* fix starting loc */ |
5610
|
80
|
|
|
|
|
op_free(o); /* blow off assign */ |
5611
|
80
|
|
|
|
|
right->op_flags &= ~OPf_WANT; |
5612
|
|
|
|
|
|
/* "I don't know and I don't care." */ |
5613
|
80
|
|
|
|
|
return right; |
5614
|
|
|
|
|
|
} |
5615
|
|
|
|
|
|
} |
5616
|
|
|
|
|
|
else { |
5617
|
122327
|
100
|
|
|
|
if (PL_modcount < RETURN_UNLIMITED_NUMBER && |
|
|
100
|
|
|
|
|
5618
|
22230
|
|
|
|
|
((LISTOP*)right)->op_last->op_type == OP_CONST) |
5619
|
|
|
|
|
|
{ |
5620
|
|
|
|
|
|
SV ** const svp = |
5621
|
22226
|
|
|
|
|
&((SVOP*)((LISTOP*)right)->op_last)->op_sv; |
5622
|
22226
|
|
|
|
|
SV * const sv = *svp; |
5623
|
22226
|
100
|
|
|
|
if (SvIOK(sv) && SvIVX(sv) == 0) |
|
|
100
|
|
|
|
|
5624
|
|
|
|
|
|
{ |
5625
|
8024
|
100
|
|
|
|
if (right->op_private & OPpSPLIT_IMPLIM) { |
5626
|
|
|
|
|
|
/* our own SV, created in ck_split */ |
5627
|
8022
|
|
|
|
|
SvREADONLY_off(sv); |
5628
|
8022
|
|
|
|
|
sv_setiv(sv, PL_modcount+1); |
5629
|
|
|
|
|
|
} |
5630
|
|
|
|
|
|
else { |
5631
|
|
|
|
|
|
/* SV may belong to someone else */ |
5632
|
2
|
|
|
|
|
SvREFCNT_dec(sv); |
5633
|
2
|
|
|
|
|
*svp = newSViv(PL_modcount+1); |
5634
|
|
|
|
|
|
} |
5635
|
|
|
|
|
|
} |
5636
|
|
|
|
|
|
} |
5637
|
|
|
|
|
|
} |
5638
|
|
|
|
|
|
} |
5639
|
|
|
|
|
|
} |
5640
|
|
|
|
|
|
return o; |
5641
|
|
|
|
|
|
} |
5642
|
19800649
|
50
|
|
|
|
if (!right) |
5643
|
0
|
|
|
|
|
right = newOP(OP_UNDEF, 0); |
5644
|
19800649
|
100
|
|
|
|
if (right->op_type == OP_READLINE) { |
5645
|
54864
|
|
|
|
|
right->op_flags |= OPf_STACKED; |
5646
|
54864
|
|
|
|
|
return newBINOP(OP_NULL, flags, op_lvalue(scalar(left), OP_SASSIGN), |
5647
|
|
|
|
|
|
scalar(right)); |
5648
|
|
|
|
|
|
} |
5649
|
|
|
|
|
|
else { |
5650
|
19745785
|
|
|
|
|
o = newBINOP(OP_SASSIGN, flags, |
5651
|
|
|
|
|
|
scalar(right), op_lvalue(scalar(left), OP_SASSIGN) ); |
5652
|
|
|
|
|
|
} |
5653
|
23804625
|
|
|
|
|
return o; |
5654
|
|
|
|
|
|
} |
5655
|
|
|
|
|
|
|
5656
|
|
|
|
|
|
/* |
5657
|
|
|
|
|
|
=for apidoc Am|OP *|newSTATEOP|I32 flags|char *label|OP *o |
5658
|
|
|
|
|
|
|
5659
|
|
|
|
|
|
Constructs a state op (COP). The state op is normally a C op, |
5660
|
|
|
|
|
|
but will be a C op if debugging is enabled for currently-compiled |
5661
|
|
|
|
|
|
code. The state op is populated from C (or C). |
5662
|
|
|
|
|
|
If I |
5663
|
|
|
|
|
|
the state op; this function takes ownership of the memory pointed at by |
5664
|
|
|
|
|
|
I |
5665
|
|
|
|
|
|
for the state op. |
5666
|
|
|
|
|
|
|
5667
|
|
|
|
|
|
If I is null, the state op is returned. Otherwise the state op is |
5668
|
|
|
|
|
|
combined with I into a C list op, which is returned. I |
5669
|
|
|
|
|
|
is consumed by this function and becomes part of the returned op tree. |
5670
|
|
|
|
|
|
|
5671
|
|
|
|
|
|
=cut |
5672
|
|
|
|
|
|
*/ |
5673
|
|
|
|
|
|
|
5674
|
|
|
|
|
|
OP * |
5675
|
82793308
|
|
|
|
|
Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o) |
5676
|
|
|
|
|
|
{ |
5677
|
|
|
|
|
|
dVAR; |
5678
|
82793308
|
|
|
|
|
const U32 seq = intro_my(); |
5679
|
82793308
|
|
|
|
|
const U32 utf8 = flags & SVf_UTF8; |
5680
|
|
|
|
|
|
COP *cop; |
5681
|
|
|
|
|
|
|
5682
|
82793308
|
|
|
|
|
flags &= ~SVf_UTF8; |
5683
|
|
|
|
|
|
|
5684
|
82793308
|
|
|
|
|
NewOp(1101, cop, 1, COP); |
5685
|
82793308
|
100
|
|
|
|
if (PERLDB_LINE && CopLINE(PL_curcop) && PL_curstash != PL_debstash) { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
5686
|
331586
|
|
|
|
|
cop->op_type = OP_DBSTATE; |
5687
|
331586
|
|
|
|
|
cop->op_ppaddr = PL_ppaddr[ OP_DBSTATE ]; |
5688
|
|
|
|
|
|
} |
5689
|
|
|
|
|
|
else { |
5690
|
82461722
|
|
|
|
|
cop->op_type = OP_NEXTSTATE; |
5691
|
82461722
|
|
|
|
|
cop->op_ppaddr = PL_ppaddr[ OP_NEXTSTATE ]; |
5692
|
|
|
|
|
|
} |
5693
|
82793308
|
|
|
|
|
cop->op_flags = (U8)flags; |
5694
|
82793308
|
|
|
|
|
CopHINTS_set(cop, PL_hints); |
5695
|
|
|
|
|
|
#ifdef NATIVE_HINTS |
5696
|
|
|
|
|
|
cop->op_private |= NATIVE_HINTS; |
5697
|
|
|
|
|
|
#endif |
5698
|
82793308
|
|
|
|
|
cop->op_next = (OP*)cop; |
5699
|
|
|
|
|
|
|
5700
|
82793308
|
|
|
|
|
cop->cop_seq = seq; |
5701
|
122731588
|
100
|
|
|
|
cop->cop_warnings = DUP_WARNINGS(PL_curcop->cop_warnings); |
|
|
100
|
|
|
|
|
5702
|
82793308
|
|
|
|
|
CopHINTHASH_set(cop, cophh_copy(CopHINTHASH_get(PL_curcop))); |
5703
|
82793308
|
100
|
|
|
|
if (label) { |
5704
|
69488
|
|
|
|
|
Perl_cop_store_label(aTHX_ cop, label, strlen(label), utf8); |
5705
|
|
|
|
|
|
|
5706
|
69488
|
|
|
|
|
PL_hints |= HINT_BLOCK_SCOPE; |
5707
|
|
|
|
|
|
/* It seems that we need to defer freeing this pointer, as other parts |
5708
|
|
|
|
|
|
of the grammar end up wanting to copy it after this op has been |
5709
|
|
|
|
|
|
created. */ |
5710
|
69488
|
|
|
|
|
SAVEFREEPV(label); |
5711
|
|
|
|
|
|
} |
5712
|
|
|
|
|
|
|
5713
|
82793308
|
50
|
|
|
|
if (PL_parser && PL_parser->copline == NOLINE) |
|
|
100
|
|
|
|
|
5714
|
8947726
|
|
|
|
|
CopLINE_set(cop, CopLINE(PL_curcop)); |
5715
|
|
|
|
|
|
else { |
5716
|
73845582
|
|
|
|
|
CopLINE_set(cop, PL_parser->copline); |
5717
|
73845582
|
|
|
|
|
PL_parser->copline = NOLINE; |
5718
|
|
|
|
|
|
} |
5719
|
|
|
|
|
|
#ifdef USE_ITHREADS |
5720
|
|
|
|
|
|
CopFILE_set(cop, CopFILE(PL_curcop)); /* XXX share in a pvtable? */ |
5721
|
|
|
|
|
|
#else |
5722
|
165586616
|
|
|
|
|
CopFILEGV_set(cop, CopFILEGV(PL_curcop)); |
5723
|
|
|
|
|
|
#endif |
5724
|
82793308
|
|
|
|
|
CopSTASH_set(cop, PL_curstash); |
5725
|
|
|
|
|
|
|
5726
|
82793308
|
100
|
|
|
|
if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash) { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
5727
|
|
|
|
|
|
/* this line can have a breakpoint - store the cop in IV */ |
5728
|
331840
|
|
|
|
|
AV *av = CopFILEAVx(PL_curcop); |
5729
|
331840
|
100
|
|
|
|
if (av) { |
5730
|
331784
|
|
|
|
|
SV * const * const svp = av_fetch(av, CopLINE(cop), FALSE); |
5731
|
331784
|
100
|
|
|
|
if (svp && *svp != &PL_sv_undef ) { |
|
|
50
|
|
|
|
|
5732
|
328590
|
|
|
|
|
(void)SvIOK_on(*svp); |
5733
|
328590
|
|
|
|
|
SvIV_set(*svp, PTR2IV(cop)); |
5734
|
|
|
|
|
|
} |
5735
|
|
|
|
|
|
} |
5736
|
|
|
|
|
|
} |
5737
|
|
|
|
|
|
|
5738
|
82793308
|
100
|
|
|
|
if (flags & OPf_SPECIAL) |
5739
|
1631358
|
|
|
|
|
op_null((OP*)cop); |
5740
|
82793308
|
|
|
|
|
return op_prepend_elem(OP_LINESEQ, (OP*)cop, o); |
5741
|
|
|
|
|
|
} |
5742
|
|
|
|
|
|
|
5743
|
|
|
|
|
|
/* |
5744
|
|
|
|
|
|
=for apidoc Am|OP *|newLOGOP|I32 type|I32 flags|OP *first|OP *other |
5745
|
|
|
|
|
|
|
5746
|
|
|
|
|
|
Constructs, checks, and returns a logical (flow control) op. I |
5747
|
|
|
|
|
|
is the opcode. I gives the eight bits of C, except |
5748
|
|
|
|
|
|
that C will be set automatically, and, shifted up eight bits, |
5749
|
|
|
|
|
|
the eight bits of C, except that the bit with value 1 is |
5750
|
|
|
|
|
|
automatically set. I supplies the expression controlling the |
5751
|
|
|
|
|
|
flow, and I supplies the side (alternate) chain of ops; they are |
5752
|
|
|
|
|
|
consumed by this function and become part of the constructed op tree. |
5753
|
|
|
|
|
|
|
5754
|
|
|
|
|
|
=cut |
5755
|
|
|
|
|
|
*/ |
5756
|
|
|
|
|
|
|
5757
|
|
|
|
|
|
OP * |
5758
|
12533974
|
|
|
|
|
Perl_newLOGOP(pTHX_ I32 type, I32 flags, OP *first, OP *other) |
5759
|
|
|
|
|
|
{ |
5760
|
|
|
|
|
|
dVAR; |
5761
|
|
|
|
|
|
|
5762
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWLOGOP; |
5763
|
|
|
|
|
|
|
5764
|
17122668
|
|
|
|
|
return new_logop(type, flags, &first, &other); |
5765
|
|
|
|
|
|
} |
5766
|
|
|
|
|
|
|
5767
|
|
|
|
|
|
STATIC OP * |
5768
|
29707213
|
|
|
|
|
S_search_const(pTHX_ OP *o) |
5769
|
|
|
|
|
|
{ |
5770
|
|
|
|
|
|
PERL_ARGS_ASSERT_SEARCH_CONST; |
5771
|
|
|
|
|
|
|
5772
|
32897716
|
|
|
|
|
switch (o->op_type) { |
5773
|
|
|
|
|
|
case OP_CONST: |
5774
|
483620
|
|
|
|
|
return o; |
5775
|
|
|
|
|
|
case OP_NULL: |
5776
|
5032292
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) |
5777
|
5032228
|
|
|
|
|
return search_const(cUNOPo->op_first); |
5778
|
|
|
|
|
|
break; |
5779
|
|
|
|
|
|
case OP_LEAVE: |
5780
|
|
|
|
|
|
case OP_SCOPE: |
5781
|
|
|
|
|
|
case OP_LINESEQ: |
5782
|
|
|
|
|
|
{ |
5783
|
|
|
|
|
|
OP *kid; |
5784
|
1647072
|
50
|
|
|
|
if (!(o->op_flags & OPf_KIDS)) |
5785
|
|
|
|
|
|
return NULL; |
5786
|
1647072
|
|
|
|
|
kid = cLISTOPo->op_first; |
5787
|
|
|
|
|
|
do { |
5788
|
3311040
|
100
|
|
|
|
switch (kid->op_type) { |
5789
|
|
|
|
|
|
case OP_ENTER: |
5790
|
|
|
|
|
|
case OP_NULL: |
5791
|
|
|
|
|
|
case OP_NEXTSTATE: |
5792
|
1984306
|
|
|
|
|
kid = kid->op_sibling; |
5793
|
|
|
|
|
|
break; |
5794
|
|
|
|
|
|
default: |
5795
|
1326734
|
100
|
|
|
|
if (kid != cLISTOPo->op_last) |
5796
|
|
|
|
|
|
return NULL; |
5797
|
|
|
|
|
|
goto last; |
5798
|
|
|
|
|
|
} |
5799
|
1984306
|
100
|
|
|
|
} while (kid); |
5800
|
320338
|
50
|
|
|
|
if (!kid) |
5801
|
320338
|
|
|
|
|
kid = cLISTOPo->op_last; |
5802
|
|
|
|
|
|
last: |
5803
|
15320424
|
|
|
|
|
return search_const(kid); |
5804
|
|
|
|
|
|
} |
5805
|
|
|
|
|
|
} |
5806
|
|
|
|
|
|
|
5807
|
|
|
|
|
|
return NULL; |
5808
|
|
|
|
|
|
} |
5809
|
|
|
|
|
|
|
5810
|
|
|
|
|
|
STATIC OP * |
5811
|
19395911
|
|
|
|
|
S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp) |
5812
|
|
|
|
|
|
{ |
5813
|
|
|
|
|
|
dVAR; |
5814
|
|
|
|
|
|
LOGOP *logop; |
5815
|
|
|
|
|
|
OP *o; |
5816
|
|
|
|
|
|
OP *first; |
5817
|
|
|
|
|
|
OP *other; |
5818
|
|
|
|
|
|
OP *cstop = NULL; |
5819
|
|
|
|
|
|
int prepend_not = 0; |
5820
|
|
|
|
|
|
|
5821
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEW_LOGOP; |
5822
|
|
|
|
|
|
|
5823
|
19395911
|
|
|
|
|
first = *firstp; |
5824
|
19395911
|
|
|
|
|
other = *otherp; |
5825
|
|
|
|
|
|
|
5826
|
19395911
|
100
|
|
|
|
if (type == OP_XOR) /* Not short circuit, but here by precedence. */ |
5827
|
36924
|
|
|
|
|
return newBINOP(type, flags, scalar(first), scalar(other)); |
5828
|
|
|
|
|
|
|
5829
|
|
|
|
|
|
assert((PL_opargs[type] & OA_CLASS_MASK) == OA_LOGOP); |
5830
|
|
|
|
|
|
|
5831
|
19358987
|
|
|
|
|
scalarboolean(first); |
5832
|
|
|
|
|
|
/* optimize AND and OR ops that have NOTs as children */ |
5833
|
19358987
|
100
|
|
|
|
if (first->op_type == OP_NOT |
5834
|
1866961
|
50
|
|
|
|
&& (first->op_flags & OPf_KIDS) |
5835
|
1866961
|
|
|
|
|
&& ((first->op_flags & OPf_SPECIAL) /* unless ($x) { } */ |
5836
|
1227070
|
100
|
|
|
|
|| (other->op_type == OP_NOT)) /* if (!$x && !$y) { } */ |
5837
|
1866961
|
100
|
|
|
|
&& !PL_madskills) { |
5838
|
796041
|
50
|
|
|
|
if (type == OP_AND || type == OP_OR) { |
5839
|
796041
|
100
|
|
|
|
if (type == OP_AND) |
5840
|
|
|
|
|
|
type = OP_OR; |
5841
|
|
|
|
|
|
else |
5842
|
|
|
|
|
|
type = OP_AND; |
5843
|
796041
|
|
|
|
|
op_null(first); |
5844
|
796041
|
100
|
|
|
|
if (other->op_type == OP_NOT) { /* !a AND|OR !b => !(a OR|AND b) */ |
5845
|
156150
|
|
|
|
|
op_null(other); |
5846
|
|
|
|
|
|
prepend_not = 1; /* prepend a NOT op later */ |
5847
|
|
|
|
|
|
} |
5848
|
|
|
|
|
|
} |
5849
|
|
|
|
|
|
} |
5850
|
|
|
|
|
|
/* search for a constant op that could let us fold the test */ |
5851
|
19358987
|
100
|
|
|
|
if ((cstop = search_const(first))) { |
5852
|
405934
|
100
|
|
|
|
if (cstop->op_private & OPpCONST_STRICT) |
5853
|
4
|
|
|
|
|
no_bareword_allowed(cstop); |
5854
|
405930
|
100
|
|
|
|
else if ((cstop->op_private & OPpCONST_BARE)) |
5855
|
36
|
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_BAREWORD), "Bareword found in conditional"); |
5856
|
416993
|
100
|
|
|
|
if ((type == OP_AND && SvTRUE(((SVOP*)cstop)->op_sv)) || |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
5857
|
203136
|
50
|
|
|
|
(type == OP_OR && !SvTRUE(((SVOP*)cstop)->op_sv)) || |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
5858
|
4
|
50
|
|
|
|
(type == OP_DOR && !SvOK(((SVOP*)cstop)->op_sv))) { |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
5859
|
99716
|
|
|
|
|
*firstp = NULL; |
5860
|
99716
|
100
|
|
|
|
if (other->op_type == OP_CONST) |
5861
|
550
|
|
|
|
|
other->op_private |= OPpCONST_SHORTCIRCUIT; |
5862
|
|
|
|
|
|
if (PL_madskills) { |
5863
|
|
|
|
|
|
OP *newop = newUNOP(OP_NULL, 0, other); |
5864
|
|
|
|
|
|
op_getmad(first, newop, '1'); |
5865
|
|
|
|
|
|
newop->op_targ = type; /* set "was" field */ |
5866
|
|
|
|
|
|
return newop; |
5867
|
|
|
|
|
|
} |
5868
|
99716
|
|
|
|
|
op_free(first); |
5869
|
99716
|
100
|
|
|
|
if (other->op_type == OP_LEAVE) |
5870
|
13282
|
|
|
|
|
other = newUNOP(OP_NULL, OPf_SPECIAL, other); |
5871
|
127851
|
100
|
|
|
|
else if (other->op_type == OP_MATCH |
5872
|
86434
|
|
|
|
|
|| other->op_type == OP_SUBST |
5873
|
74946
|
50
|
|
|
|
|| other->op_type == OP_TRANSR |
5874
|
74946
|
100
|
|
|
|
|| other->op_type == OP_TRANS) |
5875
|
|
|
|
|
|
/* Mark the op as being unbindable with =~ */ |
5876
|
11490
|
|
|
|
|
other->op_flags |= OPf_SPECIAL; |
5877
|
74944
|
100
|
|
|
|
else if (other->op_type == OP_CONST) |
5878
|
550
|
|
|
|
|
other->op_private |= OPpCONST_FOLDED; |
5879
|
|
|
|
|
|
|
5880
|
99716
|
|
|
|
|
other->op_folded = 1; |
5881
|
99716
|
|
|
|
|
return other; |
5882
|
|
|
|
|
|
} |
5883
|
|
|
|
|
|
else { |
5884
|
|
|
|
|
|
/* check for C, or C */ |
5885
|
|
|
|
|
|
const OP *o2 = other; |
5886
|
306222
|
100
|
|
|
|
if ( ! (o2->op_type == OP_LIST |
|
|
50
|
|
|
|
|
5887
|
4
|
50
|
|
|
|
&& (( o2 = cUNOPx(o2)->op_first)) |
5888
|
4
|
50
|
|
|
|
&& o2->op_type == OP_PUSHMARK |
5889
|
4
|
|
|
|
|
&& (( o2 = o2->op_sibling)) ) |
5890
|
|
|
|
|
|
) |
5891
|
|
|
|
|
|
o2 = other; |
5892
|
417567
|
100
|
|
|
|
if ((o2->op_type == OP_PADSV || o2->op_type == OP_PADAV |
5893
|
306218
|
|
|
|
|
|| o2->op_type == OP_PADHV) |
5894
|
736
|
100
|
|
|
|
&& o2->op_private & OPpLVAL_INTRO |
5895
|
14
|
50
|
|
|
|
&& !(o2->op_private & OPpPAD_STATE)) |
5896
|
|
|
|
|
|
{ |
5897
|
14
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED), |
5898
|
|
|
|
|
|
"Deprecated use of my() in false conditional"); |
5899
|
|
|
|
|
|
} |
5900
|
|
|
|
|
|
|
5901
|
306218
|
|
|
|
|
*otherp = NULL; |
5902
|
306218
|
50
|
|
|
|
if (cstop->op_type == OP_CONST) |
5903
|
306218
|
|
|
|
|
cstop->op_private |= OPpCONST_SHORTCIRCUIT; |
5904
|
|
|
|
|
|
if (PL_madskills) { |
5905
|
|
|
|
|
|
first = newUNOP(OP_NULL, 0, first); |
5906
|
|
|
|
|
|
op_getmad(other, first, '2'); |
5907
|
|
|
|
|
|
first->op_targ = type; /* set "was" field */ |
5908
|
|
|
|
|
|
} |
5909
|
|
|
|
|
|
else |
5910
|
306218
|
|
|
|
|
op_free(other); |
5911
|
306218
|
|
|
|
|
return first; |
5912
|
|
|
|
|
|
} |
5913
|
|
|
|
|
|
} |
5914
|
18953053
|
100
|
|
|
|
else if ((first->op_flags & OPf_KIDS) && type != OP_DOR |
5915
|
15555606
|
100
|
|
|
|
&& ckWARN(WARN_MISC)) /* [#24076] Don't warn for err FOO. */ |
5916
|
|
|
|
|
|
{ |
5917
|
5919531
|
|
|
|
|
const OP * const k1 = ((UNOP*)first)->op_first; |
5918
|
5919531
|
|
|
|
|
const OP * const k2 = k1->op_sibling; |
5919
|
|
|
|
|
|
OPCODE warnop = 0; |
5920
|
5919531
|
|
|
|
|
switch (first->op_type) |
5921
|
|
|
|
|
|
{ |
5922
|
|
|
|
|
|
case OP_NULL: |
5923
|
1378550
|
100
|
|
|
|
if (k2 && k2->op_type == OP_READLINE |
|
|
100
|
|
|
|
|
5924
|
4
|
50
|
|
|
|
&& (k2->op_flags & OPf_STACKED) |
5925
|
4
|
50
|
|
|
|
&& ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR)) |
5926
|
|
|
|
|
|
{ |
5927
|
4
|
|
|
|
|
warnop = k2->op_type; |
5928
|
|
|
|
|
|
} |
5929
|
|
|
|
|
|
break; |
5930
|
|
|
|
|
|
|
5931
|
|
|
|
|
|
case OP_SASSIGN: |
5932
|
119895
|
100
|
|
|
|
if (k1->op_type == OP_READDIR |
5933
|
80410
|
|
|
|
|
|| k1->op_type == OP_GLOB |
5934
|
80398
|
100
|
|
|
|
|| (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB) |
|
|
50
|
|
|
|
|
5935
|
80398
|
100
|
|
|
|
|| k1->op_type == OP_EACH |
5936
|
80396
|
50
|
|
|
|
|| k1->op_type == OP_AEACH) |
5937
|
|
|
|
|
|
{ |
5938
|
21
|
50
|
|
|
|
warnop = ((k1->op_type == OP_NULL) |
5939
|
14
|
|
|
|
|
? (OPCODE)k1->op_targ : k1->op_type); |
5940
|
|
|
|
|
|
} |
5941
|
|
|
|
|
|
break; |
5942
|
|
|
|
|
|
} |
5943
|
5919531
|
100
|
|
|
|
if (warnop) { |
5944
|
18
|
|
|
|
|
const line_t oldline = CopLINE(PL_curcop); |
5945
|
|
|
|
|
|
/* This ensures that warnings are reported at the first line |
5946
|
|
|
|
|
|
of the construction, not the last. */ |
5947
|
18
|
|
|
|
|
CopLINE_set(PL_curcop, PL_parser->copline); |
5948
|
18
|
100
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_MISC), |
5949
|
|
|
|
|
|
"Value of %s%s can be \"0\"; test with defined()", |
5950
|
|
|
|
|
|
PL_op_desc[warnop], |
5951
|
18
|
|
|
|
|
((warnop == OP_READLINE || warnop == OP_GLOB) |
5952
|
|
|
|
|
|
? " construct" : "() operator")); |
5953
|
18
|
|
|
|
|
CopLINE_set(PL_curcop, oldline); |
5954
|
|
|
|
|
|
} |
5955
|
|
|
|
|
|
} |
5956
|
|
|
|
|
|
|
5957
|
18953053
|
50
|
|
|
|
if (!other) |
5958
|
|
|
|
|
|
return first; |
5959
|
|
|
|
|
|
|
5960
|
18953053
|
100
|
|
|
|
if (type == OP_ANDASSIGN || type == OP_ORASSIGN || type == OP_DORASSIGN) |
5961
|
366731
|
|
|
|
|
other->op_private |= OPpASSIGN_BACKWARDS; /* other is an OP_SASSIGN */ |
5962
|
|
|
|
|
|
|
5963
|
18953053
|
|
|
|
|
NewOp(1101, logop, 1, LOGOP); |
5964
|
|
|
|
|
|
|
5965
|
18953053
|
|
|
|
|
logop->op_type = (OPCODE)type; |
5966
|
18953053
|
|
|
|
|
logop->op_ppaddr = PL_ppaddr[type]; |
5967
|
18953053
|
|
|
|
|
logop->op_first = first; |
5968
|
18953053
|
|
|
|
|
logop->op_flags = (U8)(flags | OPf_KIDS); |
5969
|
18953053
|
100
|
|
|
|
logop->op_other = LINKLIST(other); |
5970
|
18953053
|
|
|
|
|
logop->op_private = (U8)(1 | (flags >> 8)); |
5971
|
|
|
|
|
|
|
5972
|
|
|
|
|
|
/* establish postfix order */ |
5973
|
18953053
|
100
|
|
|
|
logop->op_next = LINKLIST(first); |
5974
|
18953053
|
|
|
|
|
first->op_next = (OP*)logop; |
5975
|
18953053
|
|
|
|
|
first->op_sibling = other; |
5976
|
|
|
|
|
|
|
5977
|
18953053
|
100
|
|
|
|
CHECKOP(type,logop); |
|
|
50
|
|
|
|
|
5978
|
|
|
|
|
|
|
5979
|
18953053
|
100
|
|
|
|
o = newUNOP(prepend_not ? OP_NOT : OP_NULL, 0, (OP*)logop); |
5980
|
18953053
|
|
|
|
|
other->op_next = o; |
5981
|
|
|
|
|
|
|
5982
|
19219482
|
|
|
|
|
return o; |
5983
|
|
|
|
|
|
} |
5984
|
|
|
|
|
|
|
5985
|
|
|
|
|
|
/* |
5986
|
|
|
|
|
|
=for apidoc Am|OP *|newCONDOP|I32 flags|OP *first|OP *trueop|OP *falseop |
5987
|
|
|
|
|
|
|
5988
|
|
|
|
|
|
Constructs, checks, and returns a conditional-expression (C) |
5989
|
|
|
|
|
|
op. I gives the eight bits of C, except that C |
5990
|
|
|
|
|
|
will be set automatically, and, shifted up eight bits, the eight bits of |
5991
|
|
|
|
|
|
C, except that the bit with value 1 is automatically set. |
5992
|
|
|
|
|
|
I supplies the expression selecting between the two branches, |
5993
|
|
|
|
|
|
and I and I supply the branches; they are consumed by |
5994
|
|
|
|
|
|
this function and become part of the constructed op tree. |
5995
|
|
|
|
|
|
|
5996
|
|
|
|
|
|
=cut |
5997
|
|
|
|
|
|
*/ |
5998
|
|
|
|
|
|
|
5999
|
|
|
|
|
|
OP * |
6000
|
11082338
|
|
|
|
|
Perl_newCONDOP(pTHX_ I32 flags, OP *first, OP *trueop, OP *falseop) |
6001
|
|
|
|
|
|
{ |
6002
|
|
|
|
|
|
dVAR; |
6003
|
|
|
|
|
|
LOGOP *logop; |
6004
|
|
|
|
|
|
OP *start; |
6005
|
|
|
|
|
|
OP *o; |
6006
|
|
|
|
|
|
OP *cstop; |
6007
|
|
|
|
|
|
|
6008
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWCONDOP; |
6009
|
|
|
|
|
|
|
6010
|
11082338
|
100
|
|
|
|
if (!falseop) |
6011
|
4221963
|
|
|
|
|
return newLOGOP(OP_AND, 0, first, trueop); |
6012
|
6860375
|
50
|
|
|
|
if (!trueop) |
6013
|
0
|
|
|
|
|
return newLOGOP(OP_OR, 0, first, falseop); |
6014
|
|
|
|
|
|
|
6015
|
6860375
|
|
|
|
|
scalarboolean(first); |
6016
|
6860375
|
100
|
|
|
|
if ((cstop = search_const(first))) { |
6017
|
|
|
|
|
|
/* Left or right arm of the conditional? */ |
6018
|
77686
|
50
|
|
|
|
const bool left = SvTRUE(((SVOP*)cstop)->op_sv); |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
0
|
|
|
|
|
6019
|
77686
|
100
|
|
|
|
OP *live = left ? trueop : falseop; |
6020
|
77686
|
100
|
|
|
|
OP *const dead = left ? falseop : trueop; |
6021
|
77686
|
100
|
|
|
|
if (cstop->op_private & OPpCONST_BARE && |
6022
|
|
|
|
|
|
cstop->op_private & OPpCONST_STRICT) { |
6023
|
2
|
|
|
|
|
no_bareword_allowed(cstop); |
6024
|
|
|
|
|
|
} |
6025
|
|
|
|
|
|
if (PL_madskills) { |
6026
|
|
|
|
|
|
/* This is all dead code when PERL_MAD is not defined. */ |
6027
|
|
|
|
|
|
live = newUNOP(OP_NULL, 0, live); |
6028
|
|
|
|
|
|
op_getmad(first, live, 'C'); |
6029
|
|
|
|
|
|
op_getmad(dead, live, left ? 'e' : 't'); |
6030
|
|
|
|
|
|
} else { |
6031
|
77686
|
|
|
|
|
op_free(first); |
6032
|
77686
|
|
|
|
|
op_free(dead); |
6033
|
|
|
|
|
|
} |
6034
|
77686
|
100
|
|
|
|
if (live->op_type == OP_LEAVE) |
6035
|
59794
|
|
|
|
|
live = newUNOP(OP_NULL, OPf_SPECIAL, live); |
6036
|
17892
|
100
|
|
|
|
else if (live->op_type == OP_MATCH || live->op_type == OP_SUBST |
6037
|
17888
|
100
|
|
|
|
|| live->op_type == OP_TRANS || live->op_type == OP_TRANSR) |
|
|
50
|
|
|
|
|
6038
|
|
|
|
|
|
/* Mark the op as being unbindable with =~ */ |
6039
|
6
|
|
|
|
|
live->op_flags |= OPf_SPECIAL; |
6040
|
17886
|
100
|
|
|
|
else if (live->op_type == OP_CONST) |
6041
|
13598
|
|
|
|
|
live->op_private |= OPpCONST_FOLDED; |
6042
|
77686
|
|
|
|
|
live->op_folded = 1; |
6043
|
77686
|
|
|
|
|
return live; |
6044
|
|
|
|
|
|
} |
6045
|
6782689
|
|
|
|
|
NewOp(1101, logop, 1, LOGOP); |
6046
|
6782689
|
|
|
|
|
logop->op_type = OP_COND_EXPR; |
6047
|
6782689
|
|
|
|
|
logop->op_ppaddr = PL_ppaddr[OP_COND_EXPR]; |
6048
|
6782689
|
|
|
|
|
logop->op_first = first; |
6049
|
6782689
|
|
|
|
|
logop->op_flags = (U8)(flags | OPf_KIDS); |
6050
|
6782689
|
|
|
|
|
logop->op_private = (U8)(1 | (flags >> 8)); |
6051
|
6782689
|
100
|
|
|
|
logop->op_other = LINKLIST(trueop); |
6052
|
6782689
|
100
|
|
|
|
logop->op_next = LINKLIST(falseop); |
6053
|
|
|
|
|
|
|
6054
|
6782689
|
100
|
|
|
|
CHECKOP(OP_COND_EXPR, /* that's logop->op_type */ |
|
|
50
|
|
|
|
|
6055
|
|
|
|
|
|
logop); |
6056
|
|
|
|
|
|
|
6057
|
|
|
|
|
|
/* establish postfix order */ |
6058
|
6782689
|
100
|
|
|
|
start = LINKLIST(first); |
6059
|
6782689
|
|
|
|
|
first->op_next = (OP*)logop; |
6060
|
|
|
|
|
|
|
6061
|
6782689
|
|
|
|
|
first->op_sibling = trueop; |
6062
|
6782689
|
|
|
|
|
trueop->op_sibling = falseop; |
6063
|
6782689
|
|
|
|
|
o = newUNOP(OP_NULL, 0, (OP*)logop); |
6064
|
|
|
|
|
|
|
6065
|
6782689
|
|
|
|
|
trueop->op_next = falseop->op_next = o; |
6066
|
|
|
|
|
|
|
6067
|
6782689
|
|
|
|
|
o->op_next = start; |
6068
|
9022148
|
|
|
|
|
return o; |
6069
|
|
|
|
|
|
} |
6070
|
|
|
|
|
|
|
6071
|
|
|
|
|
|
/* |
6072
|
|
|
|
|
|
=for apidoc Am|OP *|newRANGE|I32 flags|OP *left|OP *right |
6073
|
|
|
|
|
|
|
6074
|
|
|
|
|
|
Constructs and returns a C op, with subordinate C and |
6075
|
|
|
|
|
|
C ops. I gives the eight bits of C for the |
6076
|
|
|
|
|
|
C op and, shifted up eight bits, the eight bits of C |
6077
|
|
|
|
|
|
for both the C and C ops, except that the bit with value |
6078
|
|
|
|
|
|
1 is automatically set. I and I supply the expressions |
6079
|
|
|
|
|
|
controlling the endpoints of the range; they are consumed by this function |
6080
|
|
|
|
|
|
and become part of the constructed op tree. |
6081
|
|
|
|
|
|
|
6082
|
|
|
|
|
|
=cut |
6083
|
|
|
|
|
|
*/ |
6084
|
|
|
|
|
|
|
6085
|
|
|
|
|
|
OP * |
6086
|
169528
|
|
|
|
|
Perl_newRANGE(pTHX_ I32 flags, OP *left, OP *right) |
6087
|
|
|
|
|
|
{ |
6088
|
|
|
|
|
|
dVAR; |
6089
|
|
|
|
|
|
LOGOP *range; |
6090
|
|
|
|
|
|
OP *flip; |
6091
|
|
|
|
|
|
OP *flop; |
6092
|
|
|
|
|
|
OP *leftstart; |
6093
|
|
|
|
|
|
OP *o; |
6094
|
|
|
|
|
|
|
6095
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWRANGE; |
6096
|
|
|
|
|
|
|
6097
|
169528
|
|
|
|
|
NewOp(1101, range, 1, LOGOP); |
6098
|
|
|
|
|
|
|
6099
|
169528
|
|
|
|
|
range->op_type = OP_RANGE; |
6100
|
169528
|
|
|
|
|
range->op_ppaddr = PL_ppaddr[OP_RANGE]; |
6101
|
169528
|
|
|
|
|
range->op_first = left; |
6102
|
169528
|
|
|
|
|
range->op_flags = OPf_KIDS; |
6103
|
169528
|
100
|
|
|
|
leftstart = LINKLIST(left); |
6104
|
169528
|
100
|
|
|
|
range->op_other = LINKLIST(right); |
6105
|
169528
|
|
|
|
|
range->op_private = (U8)(1 | (flags >> 8)); |
6106
|
|
|
|
|
|
|
6107
|
169528
|
|
|
|
|
left->op_sibling = right; |
6108
|
|
|
|
|
|
|
6109
|
169528
|
|
|
|
|
range->op_next = (OP*)range; |
6110
|
169528
|
|
|
|
|
flip = newUNOP(OP_FLIP, flags, (OP*)range); |
6111
|
169528
|
|
|
|
|
flop = newUNOP(OP_FLOP, 0, flip); |
6112
|
169528
|
|
|
|
|
o = newUNOP(OP_NULL, 0, flop); |
6113
|
169528
|
50
|
|
|
|
LINKLIST(flop); |
6114
|
169528
|
|
|
|
|
range->op_next = leftstart; |
6115
|
|
|
|
|
|
|
6116
|
169528
|
|
|
|
|
left->op_next = flip; |
6117
|
169528
|
|
|
|
|
right->op_next = flop; |
6118
|
|
|
|
|
|
|
6119
|
169528
|
|
|
|
|
range->op_targ = pad_alloc(OP_RANGE, SVs_PADMY); |
6120
|
169528
|
|
|
|
|
sv_upgrade(PAD_SV(range->op_targ), SVt_PVNV); |
6121
|
169528
|
|
|
|
|
flip->op_targ = pad_alloc(OP_RANGE, SVs_PADMY); |
6122
|
169528
|
|
|
|
|
sv_upgrade(PAD_SV(flip->op_targ), SVt_PVNV); |
6123
|
|
|
|
|
|
|
6124
|
169528
|
100
|
|
|
|
flip->op_private = left->op_type == OP_CONST ? OPpFLIP_LINENUM : 0; |
6125
|
169528
|
100
|
|
|
|
flop->op_private = right->op_type == OP_CONST ? OPpFLIP_LINENUM : 0; |
6126
|
|
|
|
|
|
|
6127
|
|
|
|
|
|
/* check barewords before they might be optimized aways */ |
6128
|
169528
|
100
|
|
|
|
if (flip->op_private && cSVOPx(left)->op_private & OPpCONST_STRICT) |
|
|
100
|
|
|
|
|
6129
|
4
|
|
|
|
|
no_bareword_allowed(left); |
6130
|
169528
|
100
|
|
|
|
if (flop->op_private && cSVOPx(right)->op_private & OPpCONST_STRICT) |
|
|
100
|
|
|
|
|
6131
|
4
|
|
|
|
|
no_bareword_allowed(right); |
6132
|
|
|
|
|
|
|
6133
|
169528
|
|
|
|
|
flip->op_next = o; |
6134
|
169528
|
100
|
|
|
|
if (!flip->op_private || !flop->op_private) |
|
|
100
|
|
|
|
|
6135
|
136898
|
50
|
|
|
|
LINKLIST(o); /* blow off optimizer unless constant */ |
6136
|
|
|
|
|
|
|
6137
|
169528
|
|
|
|
|
return o; |
6138
|
|
|
|
|
|
} |
6139
|
|
|
|
|
|
|
6140
|
|
|
|
|
|
/* |
6141
|
|
|
|
|
|
=for apidoc Am|OP *|newLOOPOP|I32 flags|I32 debuggable|OP *expr|OP *block |
6142
|
|
|
|
|
|
|
6143
|
|
|
|
|
|
Constructs, checks, and returns an op tree expressing a loop. This is |
6144
|
|
|
|
|
|
only a loop in the control flow through the op tree; it does not have |
6145
|
|
|
|
|
|
the heavyweight loop structure that allows exiting the loop by C |
6146
|
|
|
|
|
|
and suchlike. I gives the eight bits of C for the |
6147
|
|
|
|
|
|
top-level op, except that some bits will be set automatically as required. |
6148
|
|
|
|
|
|
I supplies the expression controlling loop iteration, and I |
6149
|
|
|
|
|
|
supplies the body of the loop; they are consumed by this function and |
6150
|
|
|
|
|
|
become part of the constructed op tree. I is currently |
6151
|
|
|
|
|
|
unused and should always be 1. |
6152
|
|
|
|
|
|
|
6153
|
|
|
|
|
|
=cut |
6154
|
|
|
|
|
|
*/ |
6155
|
|
|
|
|
|
|
6156
|
|
|
|
|
|
OP * |
6157
|
167344
|
|
|
|
|
Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block) |
6158
|
|
|
|
|
|
{ |
6159
|
|
|
|
|
|
dVAR; |
6160
|
|
|
|
|
|
OP* listop; |
6161
|
|
|
|
|
|
OP* o; |
6162
|
179154
|
50
|
|
|
|
const bool once = block && block->op_flags & OPf_SPECIAL && |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
6163
|
24700
|
|
|
|
|
(block->op_type == OP_ENTERSUB || block->op_type == OP_NULL); |
6164
|
|
|
|
|
|
|
6165
|
|
|
|
|
|
PERL_UNUSED_ARG(debuggable); |
6166
|
|
|
|
|
|
|
6167
|
167344
|
50
|
|
|
|
if (expr) { |
6168
|
167344
|
100
|
|
|
|
if (once && expr->op_type == OP_CONST && !SvTRUE(((SVOP*)expr)->op_sv)) |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
6169
|
|
|
|
|
|
return block; /* do {} while 0 does once */ |
6170
|
249936
|
100
|
|
|
|
if (expr->op_type == OP_READLINE |
6171
|
167344
|
|
|
|
|
|| expr->op_type == OP_READDIR |
6172
|
166438
|
50
|
|
|
|
|| expr->op_type == OP_GLOB |
6173
|
166438
|
100
|
|
|
|
|| expr->op_type == OP_EACH || expr->op_type == OP_AEACH |
|
|
100
|
|
|
|
|
6174
|
166432
|
100
|
|
|
|
|| (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) { |
|
|
50
|
|
|
|
|
6175
|
912
|
|
|
|
|
expr = newUNOP(OP_DEFINED, 0, |
6176
|
|
|
|
|
|
newASSIGNOP(0, newDEFSVOP(), 0, expr) ); |
6177
|
166432
|
100
|
|
|
|
} else if (expr->op_flags & OPf_KIDS) { |
6178
|
165798
|
|
|
|
|
const OP * const k1 = ((UNOP*)expr)->op_first; |
6179
|
165798
|
50
|
|
|
|
const OP * const k2 = k1 ? k1->op_sibling : NULL; |
6180
|
165798
|
|
|
|
|
switch (expr->op_type) { |
6181
|
|
|
|
|
|
case OP_NULL: |
6182
|
38990
|
100
|
|
|
|
if (k2 && (k2->op_type == OP_READLINE || k2->op_type == OP_READDIR) |
|
|
50
|
|
|
|
|
6183
|
2
|
50
|
|
|
|
&& (k2->op_flags & OPf_STACKED) |
6184
|
2
|
50
|
|
|
|
&& ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR)) |
6185
|
2
|
|
|
|
|
expr = newUNOP(OP_DEFINED, 0, expr); |
6186
|
|
|
|
|
|
break; |
6187
|
|
|
|
|
|
|
6188
|
|
|
|
|
|
case OP_SASSIGN: |
6189
|
39
|
50
|
|
|
|
if (k1 && (k1->op_type == OP_READDIR |
|
|
100
|
|
|
|
|
6190
|
26
|
|
|
|
|
|| k1->op_type == OP_GLOB |
6191
|
24
|
100
|
|
|
|
|| (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB) |
|
|
50
|
|
|
|
|
6192
|
24
|
100
|
|
|
|
|| k1->op_type == OP_EACH |
6193
|
16
|
50
|
|
|
|
|| k1->op_type == OP_AEACH)) |
6194
|
10
|
|
|
|
|
expr = newUNOP(OP_DEFINED, 0, expr); |
6195
|
|
|
|
|
|
break; |
6196
|
|
|
|
|
|
} |
6197
|
|
|
|
|
|
} |
6198
|
|
|
|
|
|
} |
6199
|
|
|
|
|
|
|
6200
|
|
|
|
|
|
/* if block is null, the next op_append_elem() would put UNSTACK, a scalar |
6201
|
|
|
|
|
|
* op, in listop. This is wrong. [perl #27024] */ |
6202
|
167344
|
50
|
|
|
|
if (!block) |
6203
|
0
|
|
|
|
|
block = newOP(OP_NULL, 0); |
6204
|
167344
|
|
|
|
|
listop = op_append_elem(OP_LINESEQ, block, newOP(OP_UNSTACK, 0)); |
6205
|
167344
|
|
|
|
|
o = new_logop(OP_AND, 0, &expr, &listop); |
6206
|
|
|
|
|
|
|
6207
|
167344
|
50
|
|
|
|
if (listop) |
6208
|
167344
|
50
|
|
|
|
((LISTOP*)listop)->op_last->op_next = LINKLIST(o); |
6209
|
|
|
|
|
|
|
6210
|
167344
|
100
|
|
|
|
if (once && o != listop) |
|
|
100
|
|
|
|
|
6211
|
24670
|
|
|
|
|
o->op_next = ((LOGOP*)cUNOPo->op_first)->op_other; |
6212
|
|
|
|
|
|
|
6213
|
167344
|
100
|
|
|
|
if (o == listop) |
6214
|
6
|
|
|
|
|
o = newUNOP(OP_NULL, 0, o); /* or do {} while 1 loses outer block */ |
6215
|
|
|
|
|
|
|
6216
|
167344
|
|
|
|
|
o->op_flags |= flags; |
6217
|
167344
|
|
|
|
|
o = op_scope(o); |
6218
|
167344
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; /* suppress POPBLOCK curpm restoration*/ |
6219
|
167344
|
|
|
|
|
return o; |
6220
|
|
|
|
|
|
} |
6221
|
|
|
|
|
|
|
6222
|
|
|
|
|
|
/* |
6223
|
|
|
|
|
|
=for apidoc Am|OP *|newWHILEOP|I32 flags|I32 debuggable|LOOP *loop|OP *expr|OP *block|OP *cont|I32 has_my |
6224
|
|
|
|
|
|
|
6225
|
|
|
|
|
|
Constructs, checks, and returns an op tree expressing a C loop. |
6226
|
|
|
|
|
|
This is a heavyweight loop, with structure that allows exiting the loop |
6227
|
|
|
|
|
|
by C and suchlike. |
6228
|
|
|
|
|
|
|
6229
|
|
|
|
|
|
I is an optional preconstructed C op to use in the |
6230
|
|
|
|
|
|
loop; if it is null then a suitable op will be constructed automatically. |
6231
|
|
|
|
|
|
I supplies the loop's controlling expression. I supplies the |
6232
|
|
|
|
|
|
main body of the loop, and I optionally supplies a C block |
6233
|
|
|
|
|
|
that operates as a second half of the body. All of these optree inputs |
6234
|
|
|
|
|
|
are consumed by this function and become part of the constructed op tree. |
6235
|
|
|
|
|
|
|
6236
|
|
|
|
|
|
I gives the eight bits of C for the C |
6237
|
|
|
|
|
|
op and, shifted up eight bits, the eight bits of C for |
6238
|
|
|
|
|
|
the C op, except that (in both cases) some bits will be set |
6239
|
|
|
|
|
|
automatically. I is currently unused and should always be 1. |
6240
|
|
|
|
|
|
I can be supplied as true to force the |
6241
|
|
|
|
|
|
loop body to be enclosed in its own scope. |
6242
|
|
|
|
|
|
|
6243
|
|
|
|
|
|
=cut |
6244
|
|
|
|
|
|
*/ |
6245
|
|
|
|
|
|
|
6246
|
|
|
|
|
|
OP * |
6247
|
2397563
|
|
|
|
|
Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, |
6248
|
|
|
|
|
|
OP *expr, OP *block, OP *cont, I32 has_my) |
6249
|
|
|
|
|
|
{ |
6250
|
|
|
|
|
|
dVAR; |
6251
|
|
|
|
|
|
OP *redo; |
6252
|
|
|
|
|
|
OP *next = NULL; |
6253
|
|
|
|
|
|
OP *listop; |
6254
|
|
|
|
|
|
OP *o; |
6255
|
|
|
|
|
|
U8 loopflags = 0; |
6256
|
|
|
|
|
|
|
6257
|
|
|
|
|
|
PERL_UNUSED_ARG(debuggable); |
6258
|
|
|
|
|
|
|
6259
|
2397563
|
100
|
|
|
|
if (expr) { |
6260
|
3116911
|
100
|
|
|
|
if (expr->op_type == OP_READLINE |
6261
|
2105899
|
|
|
|
|
|| expr->op_type == OP_READDIR |
6262
|
2071059
|
100
|
|
|
|
|| expr->op_type == OP_GLOB |
6263
|
2071057
|
100
|
|
|
|
|| expr->op_type == OP_EACH || expr->op_type == OP_AEACH |
|
|
100
|
|
|
|
|
6264
|
2071045
|
100
|
|
|
|
|| (expr->op_type == OP_NULL && expr->op_targ == OP_GLOB)) { |
|
|
100
|
|
|
|
|
6265
|
34878
|
|
|
|
|
expr = newUNOP(OP_DEFINED, 0, |
6266
|
|
|
|
|
|
newASSIGNOP(0, newDEFSVOP(), 0, expr) ); |
6267
|
2071021
|
100
|
|
|
|
} else if (expr->op_flags & OPf_KIDS) { |
6268
|
602200
|
|
|
|
|
const OP * const k1 = ((UNOP*)expr)->op_first; |
6269
|
602200
|
50
|
|
|
|
const OP * const k2 = (k1) ? k1->op_sibling : NULL; |
6270
|
602200
|
|
|
|
|
switch (expr->op_type) { |
6271
|
|
|
|
|
|
case OP_NULL: |
6272
|
86520
|
100
|
|
|
|
if (k2 && (k2->op_type == OP_READLINE || k2->op_type == OP_READDIR) |
|
|
50
|
|
|
|
|
6273
|
1782
|
50
|
|
|
|
&& (k2->op_flags & OPf_STACKED) |
6274
|
1782
|
50
|
|
|
|
&& ((k1->op_flags & OPf_WANT) == OPf_WANT_SCALAR)) |
6275
|
1782
|
|
|
|
|
expr = newUNOP(OP_DEFINED, 0, expr); |
6276
|
|
|
|
|
|
break; |
6277
|
|
|
|
|
|
|
6278
|
|
|
|
|
|
case OP_SASSIGN: |
6279
|
36591
|
50
|
|
|
|
if (k1 && (k1->op_type == OP_READDIR |
|
|
100
|
|
|
|
|
6280
|
25234
|
|
|
|
|
|| k1->op_type == OP_GLOB |
6281
|
25220
|
50
|
|
|
|
|| (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB) |
|
|
0
|
|
|
|
|
6282
|
25220
|
100
|
|
|
|
|| k1->op_type == OP_EACH |
6283
|
24700
|
100
|
|
|
|
|| k1->op_type == OP_AEACH)) |
6284
|
538
|
|
|
|
|
expr = newUNOP(OP_DEFINED, 0, expr); |
6285
|
|
|
|
|
|
break; |
6286
|
|
|
|
|
|
} |
6287
|
|
|
|
|
|
} |
6288
|
|
|
|
|
|
} |
6289
|
|
|
|
|
|
|
6290
|
2397563
|
100
|
|
|
|
if (!block) |
6291
|
2
|
|
|
|
|
block = newOP(OP_NULL, 0); |
6292
|
2397561
|
100
|
|
|
|
else if (cont || has_my) { |
6293
|
299930
|
|
|
|
|
block = op_scope(block); |
6294
|
|
|
|
|
|
} |
6295
|
|
|
|
|
|
|
6296
|
2397563
|
100
|
|
|
|
if (cont) { |
6297
|
196778
|
100
|
|
|
|
next = LINKLIST(cont); |
6298
|
|
|
|
|
|
} |
6299
|
2397563
|
100
|
|
|
|
if (expr) { |
6300
|
2105899
|
|
|
|
|
OP * const unstack = newOP(OP_UNSTACK, 0); |
6301
|
2105899
|
100
|
|
|
|
if (!next) |
6302
|
|
|
|
|
|
next = unstack; |
6303
|
2105899
|
|
|
|
|
cont = op_append_elem(OP_LINESEQ, cont, unstack); |
6304
|
|
|
|
|
|
} |
6305
|
|
|
|
|
|
|
6306
|
|
|
|
|
|
assert(block); |
6307
|
2397563
|
|
|
|
|
listop = op_append_list(OP_LINESEQ, block, cont); |
6308
|
|
|
|
|
|
assert(listop); |
6309
|
2397563
|
100
|
|
|
|
redo = LINKLIST(listop); |
6310
|
|
|
|
|
|
|
6311
|
2397563
|
100
|
|
|
|
if (expr) { |
6312
|
2105899
|
|
|
|
|
scalar(listop); |
6313
|
2105899
|
|
|
|
|
o = new_logop(OP_AND, 0, &expr, &listop); |
6314
|
2105899
|
100
|
|
|
|
if (o == expr && o->op_type == OP_CONST && !SvTRUE(cSVOPo->op_sv)) { |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
6315
|
16
|
|
|
|
|
op_free((OP*)loop); |
6316
|
16
|
|
|
|
|
return expr; /* listop already freed by new_logop */ |
6317
|
|
|
|
|
|
} |
6318
|
2105883
|
50
|
|
|
|
if (listop) |
6319
|
3116887
|
|
|
|
|
((LISTOP*)listop)->op_last->op_next = |
6320
|
2105883
|
100
|
|
|
|
(o == listop ? redo : LINKLIST(o)); |
|
|
50
|
|
|
|
|
6321
|
|
|
|
|
|
} |
6322
|
|
|
|
|
|
else |
6323
|
291664
|
|
|
|
|
o = listop; |
6324
|
|
|
|
|
|
|
6325
|
2397547
|
100
|
|
|
|
if (!loop) { |
6326
|
990212
|
|
|
|
|
NewOp(1101,loop,1,LOOP); |
6327
|
990212
|
|
|
|
|
loop->op_type = OP_ENTERLOOP; |
6328
|
990212
|
|
|
|
|
loop->op_ppaddr = PL_ppaddr[OP_ENTERLOOP]; |
6329
|
990212
|
|
|
|
|
loop->op_private = 0; |
6330
|
990212
|
|
|
|
|
loop->op_next = (OP*)loop; |
6331
|
|
|
|
|
|
} |
6332
|
|
|
|
|
|
|
6333
|
2397547
|
|
|
|
|
o = newBINOP(OP_LEAVELOOP, 0, (OP*)loop, o); |
6334
|
|
|
|
|
|
|
6335
|
2397547
|
|
|
|
|
loop->op_redoop = redo; |
6336
|
2397547
|
|
|
|
|
loop->op_lastop = o; |
6337
|
2397547
|
|
|
|
|
o->op_private |= loopflags; |
6338
|
|
|
|
|
|
|
6339
|
2397547
|
100
|
|
|
|
if (next) |
6340
|
2105905
|
|
|
|
|
loop->op_nextop = next; |
6341
|
|
|
|
|
|
else |
6342
|
291642
|
|
|
|
|
loop->op_nextop = o; |
6343
|
|
|
|
|
|
|
6344
|
2397547
|
|
|
|
|
o->op_flags |= flags; |
6345
|
2397547
|
|
|
|
|
o->op_private |= (flags >> 8); |
6346
|
2397555
|
|
|
|
|
return o; |
6347
|
|
|
|
|
|
} |
6348
|
|
|
|
|
|
|
6349
|
|
|
|
|
|
/* |
6350
|
|
|
|
|
|
=for apidoc Am|OP *|newFOROP|I32 flags|OP *sv|OP *expr|OP *block|OP *cont |
6351
|
|
|
|
|
|
|
6352
|
|
|
|
|
|
Constructs, checks, and returns an op tree expressing a C |
6353
|
|
|
|
|
|
loop (iteration through a list of values). This is a heavyweight loop, |
6354
|
|
|
|
|
|
with structure that allows exiting the loop by C and suchlike. |
6355
|
|
|
|
|
|
|
6356
|
|
|
|
|
|
I optionally supplies the variable that will be aliased to each |
6357
|
|
|
|
|
|
item in turn; if null, it defaults to C<$_> (either lexical or global). |
6358
|
|
|
|
|
|
I supplies the list of values to iterate over. I supplies |
6359
|
|
|
|
|
|
the main body of the loop, and I optionally supplies a C |
6360
|
|
|
|
|
|
block that operates as a second half of the body. All of these optree |
6361
|
|
|
|
|
|
inputs are consumed by this function and become part of the constructed |
6362
|
|
|
|
|
|
op tree. |
6363
|
|
|
|
|
|
|
6364
|
|
|
|
|
|
I gives the eight bits of C for the C |
6365
|
|
|
|
|
|
op and, shifted up eight bits, the eight bits of C for |
6366
|
|
|
|
|
|
the C op, except that (in both cases) some bits will be set |
6367
|
|
|
|
|
|
automatically. |
6368
|
|
|
|
|
|
|
6369
|
|
|
|
|
|
=cut |
6370
|
|
|
|
|
|
*/ |
6371
|
|
|
|
|
|
|
6372
|
|
|
|
|
|
OP * |
6373
|
1407335
|
|
|
|
|
Perl_newFOROP(pTHX_ I32 flags, OP *sv, OP *expr, OP *block, OP *cont) |
6374
|
|
|
|
|
|
{ |
6375
|
|
|
|
|
|
dVAR; |
6376
|
|
|
|
|
|
LOOP *loop; |
6377
|
|
|
|
|
|
OP *wop; |
6378
|
|
|
|
|
|
PADOFFSET padoff = 0; |
6379
|
|
|
|
|
|
I32 iterflags = 0; |
6380
|
|
|
|
|
|
I32 iterpflags = 0; |
6381
|
|
|
|
|
|
OP *madsv = NULL; |
6382
|
|
|
|
|
|
|
6383
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWFOROP; |
6384
|
|
|
|
|
|
|
6385
|
1407335
|
100
|
|
|
|
if (sv) { |
6386
|
873601
|
100
|
|
|
|
if (sv->op_type == OP_RV2SV) { /* symbol table variable */ |
6387
|
12458
|
|
|
|
|
iterpflags = sv->op_private & OPpOUR_INTRO; /* for our $x () */ |
6388
|
12458
|
|
|
|
|
sv->op_type = OP_RV2GV; |
6389
|
12458
|
|
|
|
|
sv->op_ppaddr = PL_ppaddr[OP_RV2GV]; |
6390
|
|
|
|
|
|
|
6391
|
|
|
|
|
|
/* The op_type check is needed to prevent a possible segfault |
6392
|
|
|
|
|
|
* if the loop variable is undeclared and 'strict vars' is in |
6393
|
|
|
|
|
|
* effect. This is illegal but is nonetheless parsed, so we |
6394
|
|
|
|
|
|
* may reach this point with an OP_CONST where we're expecting |
6395
|
|
|
|
|
|
* an OP_GV. |
6396
|
|
|
|
|
|
*/ |
6397
|
12458
|
50
|
|
|
|
if (cUNOPx(sv)->op_first->op_type == OP_GV |
6398
|
12458
|
100
|
|
|
|
&& cGVOPx_gv(cUNOPx(sv)->op_first) == PL_defgv) |
6399
|
342
|
|
|
|
|
iterpflags |= OPpITER_DEF; |
6400
|
|
|
|
|
|
} |
6401
|
861143
|
50
|
|
|
|
else if (sv->op_type == OP_PADSV) { /* private variable */ |
6402
|
861143
|
|
|
|
|
iterpflags = sv->op_private & OPpLVAL_INTRO; /* for my $x () */ |
6403
|
861143
|
|
|
|
|
padoff = sv->op_targ; |
6404
|
|
|
|
|
|
if (PL_madskills) |
6405
|
|
|
|
|
|
madsv = sv; |
6406
|
|
|
|
|
|
else { |
6407
|
861143
|
|
|
|
|
sv->op_targ = 0; |
6408
|
861143
|
|
|
|
|
op_free(sv); |
6409
|
|
|
|
|
|
} |
6410
|
|
|
|
|
|
sv = NULL; |
6411
|
|
|
|
|
|
} |
6412
|
|
|
|
|
|
else |
6413
|
0
|
|
|
|
|
Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]); |
6414
|
873601
|
100
|
|
|
|
if (padoff) { |
6415
|
861143
|
|
|
|
|
SV *const namesv = PAD_COMPNAME_SV(padoff); |
6416
|
|
|
|
|
|
STRLEN len; |
6417
|
861143
|
50
|
|
|
|
const char *const name = SvPV_const(namesv, len); |
6418
|
|
|
|
|
|
|
6419
|
861143
|
100
|
|
|
|
if (len == 2 && name[0] == '$' && name[1] == '_') |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
6420
|
12
|
|
|
|
|
iterpflags |= OPpITER_DEF; |
6421
|
|
|
|
|
|
} |
6422
|
|
|
|
|
|
} |
6423
|
|
|
|
|
|
else { |
6424
|
533734
|
|
|
|
|
const PADOFFSET offset = pad_findmy_pvs("$_", 0); |
6425
|
533734
|
100
|
|
|
|
if (offset == NOT_IN_PAD || PAD_COMPNAME_FLAGS_isOUR(offset)) { |
|
|
50
|
|
|
|
|
6426
|
533728
|
|
|
|
|
sv = newGVOP(OP_GV, 0, PL_defgv); |
6427
|
|
|
|
|
|
} |
6428
|
|
|
|
|
|
else { |
6429
|
|
|
|
|
|
padoff = offset; |
6430
|
|
|
|
|
|
} |
6431
|
|
|
|
|
|
iterpflags |= OPpITER_DEF; |
6432
|
|
|
|
|
|
} |
6433
|
1407335
|
100
|
|
|
|
if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) { |
6434
|
636532
|
|
|
|
|
expr = op_lvalue(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART); |
6435
|
|
|
|
|
|
iterflags |= OPf_STACKED; |
6436
|
|
|
|
|
|
} |
6437
|
833494
|
100
|
|
|
|
else if (expr->op_type == OP_NULL && |
|
|
50
|
|
|
|
|
6438
|
191673
|
100
|
|
|
|
(expr->op_flags & OPf_KIDS) && |
6439
|
128982
|
|
|
|
|
((BINOP*)expr)->op_first->op_type == OP_FLOP) |
6440
|
113550
|
|
|
|
|
{ |
6441
|
|
|
|
|
|
/* Basically turn for($x..$y) into the same as for($x,$y), but we |
6442
|
|
|
|
|
|
* set the STACKED flag to indicate that these values are to be |
6443
|
|
|
|
|
|
* treated as min/max values by 'pp_enteriter'. |
6444
|
|
|
|
|
|
*/ |
6445
|
113550
|
|
|
|
|
const UNOP* const flip = (UNOP*)((UNOP*)((BINOP*)expr)->op_first)->op_first; |
6446
|
113550
|
|
|
|
|
LOGOP* const range = (LOGOP*) flip->op_first; |
6447
|
113550
|
|
|
|
|
OP* const left = range->op_first; |
6448
|
113550
|
|
|
|
|
OP* const right = left->op_sibling; |
6449
|
|
|
|
|
|
LISTOP* listop; |
6450
|
|
|
|
|
|
|
6451
|
113550
|
|
|
|
|
range->op_flags &= ~OPf_KIDS; |
6452
|
113550
|
|
|
|
|
range->op_first = NULL; |
6453
|
|
|
|
|
|
|
6454
|
113550
|
|
|
|
|
listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right); |
6455
|
113550
|
|
|
|
|
listop->op_first->op_next = range->op_next; |
6456
|
113550
|
|
|
|
|
left->op_next = range->op_other; |
6457
|
113550
|
|
|
|
|
right->op_next = (OP*)listop; |
6458
|
113550
|
|
|
|
|
listop->op_next = listop->op_first; |
6459
|
|
|
|
|
|
|
6460
|
|
|
|
|
|
#ifdef PERL_MAD |
6461
|
|
|
|
|
|
op_getmad(expr,(OP*)listop,'O'); |
6462
|
|
|
|
|
|
#else |
6463
|
113550
|
|
|
|
|
op_free(expr); |
6464
|
|
|
|
|
|
#endif |
6465
|
|
|
|
|
|
expr = (OP*)(listop); |
6466
|
113550
|
|
|
|
|
op_null(expr); |
6467
|
|
|
|
|
|
iterflags |= OPf_STACKED; |
6468
|
|
|
|
|
|
} |
6469
|
|
|
|
|
|
else { |
6470
|
657253
|
|
|
|
|
expr = op_lvalue(force_list(expr), OP_GREPSTART); |
6471
|
|
|
|
|
|
} |
6472
|
|
|
|
|
|
|
6473
|
1407335
|
|
|
|
|
loop = (LOOP*)list(convert(OP_ENTERITER, iterflags, |
6474
|
|
|
|
|
|
op_append_elem(OP_LIST, expr, scalar(sv)))); |
6475
|
|
|
|
|
|
assert(!loop->op_next); |
6476
|
|
|
|
|
|
/* for my $x () sets OPpLVAL_INTRO; |
6477
|
|
|
|
|
|
* for our $x () sets OPpOUR_INTRO */ |
6478
|
1407335
|
|
|
|
|
loop->op_private = (U8)iterpflags; |
6479
|
1407335
|
100
|
|
|
|
if (loop->op_slabbed |
6480
|
1407333
|
100
|
|
|
|
&& DIFF(loop, OpSLOT(loop)->opslot_next) |
6481
|
|
|
|
|
|
< SIZE_TO_PSIZE(sizeof(LOOP))) |
6482
|
1391203
|
|
|
|
|
{ |
6483
|
|
|
|
|
|
LOOP *tmp; |
6484
|
1391203
|
|
|
|
|
NewOp(1234,tmp,1,LOOP); |
6485
|
1391203
|
|
|
|
|
Copy(loop,tmp,1,LISTOP); |
6486
|
|
|
|
|
|
S_op_destroy(aTHX_ (OP*)loop); |
6487
|
|
|
|
|
|
loop = tmp; |
6488
|
|
|
|
|
|
} |
6489
|
16132
|
100
|
|
|
|
else if (!loop->op_slabbed) |
6490
|
2
|
|
|
|
|
loop = (LOOP*)PerlMemShared_realloc(loop, sizeof(LOOP)); |
6491
|
1407335
|
|
|
|
|
loop->op_targ = padoff; |
6492
|
1407335
|
|
|
|
|
wop = newWHILEOP(flags, 1, loop, newOP(OP_ITER, 0), block, cont, 0); |
6493
|
|
|
|
|
|
if (madsv) |
6494
|
|
|
|
|
|
op_getmad(madsv, (OP*)loop, 'v'); |
6495
|
1407335
|
|
|
|
|
return wop; |
6496
|
|
|
|
|
|
} |
6497
|
|
|
|
|
|
|
6498
|
|
|
|
|
|
/* |
6499
|
|
|
|
|
|
=for apidoc Am|OP *|newLOOPEX|I32 type|OP *label |
6500
|
|
|
|
|
|
|
6501
|
|
|
|
|
|
Constructs, checks, and returns a loop-exiting op (such as C |
6502
|
|
|
|
|
|
or C). I is the opcode. I |
6503
|
|
|
|
|
|
determining the target of the op; it is consumed by this function and |
6504
|
|
|
|
|
|
becomes part of the constructed op tree. |
6505
|
|
|
|
|
|
|
6506
|
|
|
|
|
|
=cut |
6507
|
|
|
|
|
|
*/ |
6508
|
|
|
|
|
|
|
6509
|
|
|
|
|
|
OP* |
6510
|
360403
|
|
|
|
|
Perl_newLOOPEX(pTHX_ I32 type, OP *label) |
6511
|
|
|
|
|
|
{ |
6512
|
|
|
|
|
|
dVAR; |
6513
|
|
|
|
|
|
OP *o = NULL; |
6514
|
|
|
|
|
|
|
6515
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWLOOPEX; |
6516
|
|
|
|
|
|
|
6517
|
|
|
|
|
|
assert((PL_opargs[type] & OA_CLASS_MASK) == OA_LOOPEXOP); |
6518
|
|
|
|
|
|
|
6519
|
360403
|
100
|
|
|
|
if (type != OP_GOTO) { |
6520
|
|
|
|
|
|
/* "last()" means "last" */ |
6521
|
117024
|
100
|
|
|
|
if (label->op_type == OP_STUB && (label->op_flags & OPf_PARENS)) { |
|
|
50
|
|
|
|
|
6522
|
14004
|
|
|
|
|
o = newOP(type, OPf_SPECIAL); |
6523
|
|
|
|
|
|
} |
6524
|
|
|
|
|
|
} |
6525
|
|
|
|
|
|
else { |
6526
|
|
|
|
|
|
/* Check whether it's going to be a goto &function */ |
6527
|
243379
|
100
|
|
|
|
if (label->op_type == OP_ENTERSUB |
6528
|
170824
|
100
|
|
|
|
&& !(label->op_flags & OPf_STACKED)) |
6529
|
170822
|
|
|
|
|
label = newUNOP(OP_REFGEN, 0, op_lvalue(label, OP_REFGEN)); |
6530
|
|
|
|
|
|
} |
6531
|
|
|
|
|
|
|
6532
|
|
|
|
|
|
/* Check for a constant argument */ |
6533
|
360403
|
100
|
|
|
|
if (label->op_type == OP_CONST) { |
6534
|
125160
|
|
|
|
|
SV * const sv = ((SVOP *)label)->op_sv; |
6535
|
|
|
|
|
|
STRLEN l; |
6536
|
125160
|
50
|
|
|
|
const char *s = SvPV_const(sv,l); |
6537
|
125160
|
100
|
|
|
|
if (l == strlen(s)) { |
6538
|
125158
|
50
|
|
|
|
o = newPVOP(type, |
6539
|
|
|
|
|
|
SvUTF8(((SVOP*)label)->op_sv), |
6540
|
|
|
|
|
|
savesharedpv( |
6541
|
|
|
|
|
|
SvPV_nolen_const(((SVOP*)label)->op_sv))); |
6542
|
|
|
|
|
|
} |
6543
|
|
|
|
|
|
} |
6544
|
|
|
|
|
|
|
6545
|
|
|
|
|
|
/* If we have already created an op, we do not need the label. */ |
6546
|
360403
|
100
|
|
|
|
if (o) |
6547
|
|
|
|
|
|
#ifdef PERL_MAD |
6548
|
|
|
|
|
|
op_getmad(label,o,'L'); |
6549
|
|
|
|
|
|
#else |
6550
|
139162
|
|
|
|
|
op_free(label); |
6551
|
|
|
|
|
|
#endif |
6552
|
221241
|
|
|
|
|
else o = newUNOP(type, OPf_STACKED, label); |
6553
|
|
|
|
|
|
|
6554
|
360403
|
|
|
|
|
PL_hints |= HINT_BLOCK_SCOPE; |
6555
|
360403
|
|
|
|
|
return o; |
6556
|
|
|
|
|
|
} |
6557
|
|
|
|
|
|
|
6558
|
|
|
|
|
|
/* if the condition is a literal array or hash |
6559
|
|
|
|
|
|
(or @{ ... } etc), make a reference to it. |
6560
|
|
|
|
|
|
*/ |
6561
|
|
|
|
|
|
STATIC OP * |
6562
|
1906
|
|
|
|
|
S_ref_array_or_hash(pTHX_ OP *cond) |
6563
|
|
|
|
|
|
{ |
6564
|
1906
|
50
|
|
|
|
if (cond |
6565
|
2859
|
100
|
|
|
|
&& (cond->op_type == OP_RV2AV |
6566
|
1906
|
|
|
|
|
|| cond->op_type == OP_PADAV |
6567
|
1814
|
50
|
|
|
|
|| cond->op_type == OP_RV2HV |
6568
|
1814
|
100
|
|
|
|
|| cond->op_type == OP_PADHV)) |
6569
|
|
|
|
|
|
|
6570
|
194
|
|
|
|
|
return newUNOP(OP_REFGEN, 0, op_lvalue(cond, OP_REFGEN)); |
6571
|
|
|
|
|
|
|
6572
|
1712
|
50
|
|
|
|
else if(cond |
6573
|
2568
|
100
|
|
|
|
&& (cond->op_type == OP_ASLICE |
6574
|
1712
|
|
|
|
|
|| cond->op_type == OP_HSLICE)) { |
6575
|
|
|
|
|
|
|
6576
|
|
|
|
|
|
/* anonlist now needs a list from this op, was previously used in |
6577
|
|
|
|
|
|
* scalar context */ |
6578
|
42
|
|
|
|
|
cond->op_flags |= ~(OPf_WANT_SCALAR | OPf_REF); |
6579
|
42
|
|
|
|
|
cond->op_flags |= OPf_WANT_LIST; |
6580
|
|
|
|
|
|
|
6581
|
974
|
|
|
|
|
return newANONLIST(op_lvalue(cond, OP_ANONLIST)); |
6582
|
|
|
|
|
|
} |
6583
|
|
|
|
|
|
|
6584
|
|
|
|
|
|
else |
6585
|
|
|
|
|
|
return cond; |
6586
|
|
|
|
|
|
} |
6587
|
|
|
|
|
|
|
6588
|
|
|
|
|
|
/* These construct the optree fragments representing given() |
6589
|
|
|
|
|
|
and when() blocks. |
6590
|
|
|
|
|
|
|
6591
|
|
|
|
|
|
entergiven and enterwhen are LOGOPs; the op_other pointer |
6592
|
|
|
|
|
|
points up to the associated leave op. We need this so we |
6593
|
|
|
|
|
|
can put it in the context and make break/continue work. |
6594
|
|
|
|
|
|
(Also, of course, pp_enterwhen will jump straight to |
6595
|
|
|
|
|
|
op_other if the match fails.) |
6596
|
|
|
|
|
|
*/ |
6597
|
|
|
|
|
|
|
6598
|
|
|
|
|
|
STATIC OP * |
6599
|
718
|
|
|
|
|
S_newGIVWHENOP(pTHX_ OP *cond, OP *block, |
6600
|
|
|
|
|
|
I32 enter_opcode, I32 leave_opcode, |
6601
|
|
|
|
|
|
PADOFFSET entertarg) |
6602
|
|
|
|
|
|
{ |
6603
|
|
|
|
|
|
dVAR; |
6604
|
|
|
|
|
|
LOGOP *enterop; |
6605
|
|
|
|
|
|
OP *o; |
6606
|
|
|
|
|
|
|
6607
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWGIVWHENOP; |
6608
|
|
|
|
|
|
|
6609
|
718
|
|
|
|
|
NewOp(1101, enterop, 1, LOGOP); |
6610
|
718
|
|
|
|
|
enterop->op_type = (Optype)enter_opcode; |
6611
|
718
|
|
|
|
|
enterop->op_ppaddr = PL_ppaddr[enter_opcode]; |
6612
|
718
|
|
|
|
|
enterop->op_flags = (U8) OPf_KIDS; |
6613
|
718
|
50
|
|
|
|
enterop->op_targ = ((entertarg == NOT_IN_PAD) ? 0 : entertarg); |
6614
|
718
|
|
|
|
|
enterop->op_private = 0; |
6615
|
|
|
|
|
|
|
6616
|
718
|
|
|
|
|
o = newUNOP(leave_opcode, 0, (OP *) enterop); |
6617
|
|
|
|
|
|
|
6618
|
718
|
100
|
|
|
|
if (cond) { |
6619
|
648
|
|
|
|
|
enterop->op_first = scalar(cond); |
6620
|
648
|
|
|
|
|
cond->op_sibling = block; |
6621
|
|
|
|
|
|
|
6622
|
648
|
100
|
|
|
|
o->op_next = LINKLIST(cond); |
6623
|
648
|
|
|
|
|
cond->op_next = (OP *) enterop; |
6624
|
|
|
|
|
|
} |
6625
|
|
|
|
|
|
else { |
6626
|
|
|
|
|
|
/* This is a default {} block */ |
6627
|
70
|
|
|
|
|
enterop->op_first = block; |
6628
|
70
|
|
|
|
|
enterop->op_flags |= OPf_SPECIAL; |
6629
|
70
|
|
|
|
|
o ->op_flags |= OPf_SPECIAL; |
6630
|
|
|
|
|
|
|
6631
|
70
|
|
|
|
|
o->op_next = (OP *) enterop; |
6632
|
|
|
|
|
|
} |
6633
|
|
|
|
|
|
|
6634
|
718
|
50
|
|
|
|
CHECKOP(enter_opcode, enterop); /* Currently does nothing, since |
|
|
0
|
|
|
|
|
6635
|
|
|
|
|
|
entergiven and enterwhen both |
6636
|
|
|
|
|
|
use ck_null() */ |
6637
|
|
|
|
|
|
|
6638
|
718
|
50
|
|
|
|
enterop->op_next = LINKLIST(block); |
6639
|
718
|
|
|
|
|
block->op_next = enterop->op_other = o; |
6640
|
|
|
|
|
|
|
6641
|
718
|
|
|
|
|
return o; |
6642
|
|
|
|
|
|
} |
6643
|
|
|
|
|
|
|
6644
|
|
|
|
|
|
/* Does this look like a boolean operation? For these purposes |
6645
|
|
|
|
|
|
a boolean operation is: |
6646
|
|
|
|
|
|
- a subroutine call [*] |
6647
|
|
|
|
|
|
- a logical connective |
6648
|
|
|
|
|
|
- a comparison operator |
6649
|
|
|
|
|
|
- a filetest operator, with the exception of -s -M -A -C |
6650
|
|
|
|
|
|
- defined(), exists() or eof() |
6651
|
|
|
|
|
|
- /$re/ or $foo =~ /$re/ |
6652
|
|
|
|
|
|
|
6653
|
|
|
|
|
|
[*] possibly surprising |
6654
|
|
|
|
|
|
*/ |
6655
|
|
|
|
|
|
STATIC bool |
6656
|
456
|
|
|
|
|
S_looks_like_bool(pTHX_ const OP *o) |
6657
|
|
|
|
|
|
{ |
6658
|
|
|
|
|
|
dVAR; |
6659
|
|
|
|
|
|
|
6660
|
|
|
|
|
|
PERL_ARGS_ASSERT_LOOKS_LIKE_BOOL; |
6661
|
|
|
|
|
|
|
6662
|
462
|
|
|
|
|
switch(o->op_type) { |
6663
|
|
|
|
|
|
case OP_OR: |
6664
|
|
|
|
|
|
case OP_DOR: |
6665
|
6
|
|
|
|
|
return looks_like_bool(cLOGOPo->op_first); |
6666
|
|
|
|
|
|
|
6667
|
|
|
|
|
|
case OP_AND: |
6668
|
4
|
|
|
|
|
return ( |
6669
|
4
|
|
|
|
|
looks_like_bool(cLOGOPo->op_first) |
6670
|
4
|
50
|
|
|
|
&& looks_like_bool(cLOGOPo->op_first->op_sibling)); |
|
|
50
|
|
|
|
|
6671
|
|
|
|
|
|
|
6672
|
|
|
|
|
|
case OP_NULL: |
6673
|
|
|
|
|
|
case OP_SCALAR: |
6674
|
16
|
|
|
|
|
return ( |
6675
|
16
|
|
|
|
|
o->op_flags & OPf_KIDS |
6676
|
16
|
50
|
|
|
|
&& looks_like_bool(cUNOPo->op_first)); |
|
|
100
|
|
|
|
|
6677
|
|
|
|
|
|
|
6678
|
|
|
|
|
|
case OP_ENTERSUB: |
6679
|
|
|
|
|
|
|
6680
|
|
|
|
|
|
case OP_NOT: case OP_XOR: |
6681
|
|
|
|
|
|
|
6682
|
|
|
|
|
|
case OP_EQ: case OP_NE: case OP_LT: |
6683
|
|
|
|
|
|
case OP_GT: case OP_LE: case OP_GE: |
6684
|
|
|
|
|
|
|
6685
|
|
|
|
|
|
case OP_I_EQ: case OP_I_NE: case OP_I_LT: |
6686
|
|
|
|
|
|
case OP_I_GT: case OP_I_LE: case OP_I_GE: |
6687
|
|
|
|
|
|
|
6688
|
|
|
|
|
|
case OP_SEQ: case OP_SNE: case OP_SLT: |
6689
|
|
|
|
|
|
case OP_SGT: case OP_SLE: case OP_SGE: |
6690
|
|
|
|
|
|
|
6691
|
|
|
|
|
|
case OP_SMARTMATCH: |
6692
|
|
|
|
|
|
|
6693
|
|
|
|
|
|
case OP_FTRREAD: case OP_FTRWRITE: case OP_FTREXEC: |
6694
|
|
|
|
|
|
case OP_FTEREAD: case OP_FTEWRITE: case OP_FTEEXEC: |
6695
|
|
|
|
|
|
case OP_FTIS: case OP_FTEOWNED: case OP_FTROWNED: |
6696
|
|
|
|
|
|
case OP_FTZERO: case OP_FTSOCK: case OP_FTCHR: |
6697
|
|
|
|
|
|
case OP_FTBLK: case OP_FTFILE: case OP_FTDIR: |
6698
|
|
|
|
|
|
case OP_FTPIPE: case OP_FTLINK: case OP_FTSUID: |
6699
|
|
|
|
|
|
case OP_FTSGID: case OP_FTSVTX: case OP_FTTTY: |
6700
|
|
|
|
|
|
case OP_FTTEXT: case OP_FTBINARY: |
6701
|
|
|
|
|
|
|
6702
|
|
|
|
|
|
case OP_DEFINED: case OP_EXISTS: |
6703
|
|
|
|
|
|
case OP_MATCH: case OP_EOF: |
6704
|
|
|
|
|
|
|
6705
|
|
|
|
|
|
case OP_FLOP: |
6706
|
|
|
|
|
|
|
6707
|
|
|
|
|
|
return TRUE; |
6708
|
|
|
|
|
|
|
6709
|
|
|
|
|
|
case OP_CONST: |
6710
|
|
|
|
|
|
/* Detect comparisons that have been optimized away */ |
6711
|
182
|
100
|
|
|
|
if (cSVOPo->op_sv == &PL_sv_yes |
6712
|
180
|
100
|
|
|
|
|| cSVOPo->op_sv == &PL_sv_no) |
6713
|
|
|
|
|
|
|
6714
|
|
|
|
|
|
return TRUE; |
6715
|
|
|
|
|
|
else |
6716
|
178
|
|
|
|
|
return FALSE; |
6717
|
|
|
|
|
|
|
6718
|
|
|
|
|
|
/* FALL THROUGH */ |
6719
|
|
|
|
|
|
default: |
6720
|
260
|
|
|
|
|
return FALSE; |
6721
|
|
|
|
|
|
} |
6722
|
|
|
|
|
|
} |
6723
|
|
|
|
|
|
|
6724
|
|
|
|
|
|
/* |
6725
|
|
|
|
|
|
=for apidoc Am|OP *|newGIVENOP|OP *cond|OP *block|PADOFFSET defsv_off |
6726
|
|
|
|
|
|
|
6727
|
|
|
|
|
|
Constructs, checks, and returns an op tree expressing a C block. |
6728
|
|
|
|
|
|
I supplies the expression that will be locally assigned to a lexical |
6729
|
|
|
|
|
|
variable, and I supplies the body of the C construct; they |
6730
|
|
|
|
|
|
are consumed by this function and become part of the constructed op tree. |
6731
|
|
|
|
|
|
I is the pad offset of the scalar lexical variable that will |
6732
|
|
|
|
|
|
be affected. If it is 0, the global $_ will be used. |
6733
|
|
|
|
|
|
|
6734
|
|
|
|
|
|
=cut |
6735
|
|
|
|
|
|
*/ |
6736
|
|
|
|
|
|
|
6737
|
|
|
|
|
|
OP * |
6738
|
216
|
|
|
|
|
Perl_newGIVENOP(pTHX_ OP *cond, OP *block, PADOFFSET defsv_off) |
6739
|
|
|
|
|
|
{ |
6740
|
|
|
|
|
|
dVAR; |
6741
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWGIVENOP; |
6742
|
216
|
|
|
|
|
return newGIVWHENOP( |
6743
|
|
|
|
|
|
ref_array_or_hash(cond), |
6744
|
|
|
|
|
|
block, |
6745
|
|
|
|
|
|
OP_ENTERGIVEN, OP_LEAVEGIVEN, |
6746
|
|
|
|
|
|
defsv_off); |
6747
|
|
|
|
|
|
} |
6748
|
|
|
|
|
|
|
6749
|
|
|
|
|
|
/* |
6750
|
|
|
|
|
|
=for apidoc Am|OP *|newWHENOP|OP *cond|OP *block |
6751
|
|
|
|
|
|
|
6752
|
|
|
|
|
|
Constructs, checks, and returns an op tree expressing a C block. |
6753
|
|
|
|
|
|
I supplies the test expression, and I supplies the block |
6754
|
|
|
|
|
|
that will be executed if the test evaluates to true; they are consumed |
6755
|
|
|
|
|
|
by this function and become part of the constructed op tree. I |
6756
|
|
|
|
|
|
will be interpreted DWIMically, often as a comparison against C<$_>, |
6757
|
|
|
|
|
|
and may be null to generate a C block. |
6758
|
|
|
|
|
|
|
6759
|
|
|
|
|
|
=cut |
6760
|
|
|
|
|
|
*/ |
6761
|
|
|
|
|
|
|
6762
|
|
|
|
|
|
OP * |
6763
|
502
|
|
|
|
|
Perl_newWHENOP(pTHX_ OP *cond, OP *block) |
6764
|
|
|
|
|
|
{ |
6765
|
502
|
100
|
|
|
|
const bool cond_llb = (!cond || looks_like_bool(cond)); |
|
|
100
|
|
|
|
|
6766
|
|
|
|
|
|
OP *cond_op; |
6767
|
|
|
|
|
|
|
6768
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWWHENOP; |
6769
|
|
|
|
|
|
|
6770
|
502
|
100
|
|
|
|
if (cond_llb) |
6771
|
|
|
|
|
|
cond_op = cond; |
6772
|
|
|
|
|
|
else { |
6773
|
242
|
|
|
|
|
cond_op = newBINOP(OP_SMARTMATCH, OPf_SPECIAL, |
6774
|
|
|
|
|
|
newDEFSVOP(), |
6775
|
|
|
|
|
|
scalar(ref_array_or_hash(cond))); |
6776
|
|
|
|
|
|
} |
6777
|
|
|
|
|
|
|
6778
|
502
|
|
|
|
|
return newGIVWHENOP(cond_op, block, OP_ENTERWHEN, OP_LEAVEWHEN, 0); |
6779
|
|
|
|
|
|
} |
6780
|
|
|
|
|
|
|
6781
|
|
|
|
|
|
void |
6782
|
35074
|
|
|
|
|
Perl_cv_ckproto_len_flags(pTHX_ const CV *cv, const GV *gv, const char *p, |
6783
|
|
|
|
|
|
const STRLEN len, const U32 flags) |
6784
|
|
|
|
|
|
{ |
6785
|
|
|
|
|
|
SV *name = NULL, *msg; |
6786
|
35074
|
100
|
|
|
|
const char * cvp = SvROK(cv) ? "" : CvPROTO(cv); |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
6787
|
35074
|
100
|
|
|
|
STRLEN clen = CvPROTOLEN(cv), plen = len; |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
6788
|
|
|
|
|
|
|
6789
|
|
|
|
|
|
PERL_ARGS_ASSERT_CV_CKPROTO_LEN_FLAGS; |
6790
|
|
|
|
|
|
|
6791
|
35074
|
100
|
|
|
|
if (p == NULL && cvp == NULL) |
6792
|
|
|
|
|
|
return; |
6793
|
|
|
|
|
|
|
6794
|
30000
|
100
|
|
|
|
if (!ckWARN_d(WARN_PROTOTYPE)) |
6795
|
|
|
|
|
|
return; |
6796
|
|
|
|
|
|
|
6797
|
29918
|
100
|
|
|
|
if (p && cvp) { |
6798
|
29890
|
|
|
|
|
p = S_strip_spaces(aTHX_ p, &plen); |
6799
|
29890
|
|
|
|
|
cvp = S_strip_spaces(aTHX_ cvp, &clen); |
6800
|
29890
|
100
|
|
|
|
if ((flags & SVf_UTF8) == SvUTF8(cv)) { |
6801
|
29884
|
100
|
|
|
|
if (plen == clen && memEQ(cvp, p, plen)) |
|
|
50
|
|
|
|
|
6802
|
|
|
|
|
|
return; |
6803
|
|
|
|
|
|
} else { |
6804
|
6
|
100
|
|
|
|
if (flags & SVf_UTF8) { |
6805
|
4
|
100
|
|
|
|
if (bytes_cmp_utf8((const U8 *)cvp, clen, (const U8 *)p, plen) == 0) |
6806
|
|
|
|
|
|
return; |
6807
|
|
|
|
|
|
} |
6808
|
|
|
|
|
|
else { |
6809
|
2
|
50
|
|
|
|
if (bytes_cmp_utf8((const U8 *)p, plen, (const U8 *)cvp, clen) == 0) |
6810
|
|
|
|
|
|
return; |
6811
|
|
|
|
|
|
} |
6812
|
|
|
|
|
|
} |
6813
|
|
|
|
|
|
} |
6814
|
|
|
|
|
|
|
6815
|
50
|
|
|
|
|
msg = sv_newmortal(); |
6816
|
|
|
|
|
|
|
6817
|
50
|
50
|
|
|
|
if (gv) |
6818
|
|
|
|
|
|
{ |
6819
|
50
|
100
|
|
|
|
if (isGV(gv)) |
6820
|
38
|
|
|
|
|
gv_efullname3(name = sv_newmortal(), gv, NULL); |
6821
|
12
|
50
|
|
|
|
else if (SvPOK(gv) && *SvPVX((SV *)gv) == '&') |
|
|
100
|
|
|
|
|
6822
|
8
|
|
|
|
|
name = newSVpvn_flags(SvPVX((SV *)gv)+1, SvCUR(gv)-1, SvUTF8(gv)|SVs_TEMP); |
6823
|
|
|
|
|
|
else name = (SV *)gv; |
6824
|
|
|
|
|
|
} |
6825
|
50
|
|
|
|
|
sv_setpvs(msg, "Prototype mismatch:"); |
6826
|
50
|
50
|
|
|
|
if (name) |
6827
|
50
|
|
|
|
|
Perl_sv_catpvf(aTHX_ msg, " sub %"SVf, SVfARG(name)); |
6828
|
50
|
100
|
|
|
|
if (cvp) |
6829
|
60
|
|
|
|
|
Perl_sv_catpvf(aTHX_ msg, " (%"UTF8f")", |
6830
|
40
|
|
|
|
|
UTF8fARG(SvUTF8(cv),clen,cvp) |
6831
|
|
|
|
|
|
); |
6832
|
|
|
|
|
|
else |
6833
|
10
|
|
|
|
|
sv_catpvs(msg, ": none"); |
6834
|
50
|
|
|
|
|
sv_catpvs(msg, " vs "); |
6835
|
50
|
100
|
|
|
|
if (p) |
6836
|
32
|
|
|
|
|
Perl_sv_catpvf(aTHX_ msg, "(%"UTF8f")", UTF8fARG(flags & SVf_UTF8,len,p)); |
6837
|
|
|
|
|
|
else |
6838
|
18
|
|
|
|
|
sv_catpvs(msg, "none"); |
6839
|
19722
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_PROTOTYPE), "%"SVf, SVfARG(msg)); |
6840
|
|
|
|
|
|
} |
6841
|
|
|
|
|
|
|
6842
|
|
|
|
|
|
static void const_sv_xsub(pTHX_ CV* cv); |
6843
|
|
|
|
|
|
static void const_av_xsub(pTHX_ CV* cv); |
6844
|
|
|
|
|
|
|
6845
|
|
|
|
|
|
/* |
6846
|
|
|
|
|
|
|
6847
|
|
|
|
|
|
=head1 Optree Manipulation Functions |
6848
|
|
|
|
|
|
|
6849
|
|
|
|
|
|
=for apidoc cv_const_sv |
6850
|
|
|
|
|
|
|
6851
|
|
|
|
|
|
If C is a constant sub eligible for inlining. returns the constant |
6852
|
|
|
|
|
|
value returned by the sub. Otherwise, returns NULL. |
6853
|
|
|
|
|
|
|
6854
|
|
|
|
|
|
Constant subs can be created with C or as described in |
6855
|
|
|
|
|
|
L. |
6856
|
|
|
|
|
|
|
6857
|
|
|
|
|
|
=cut |
6858
|
|
|
|
|
|
*/ |
6859
|
|
|
|
|
|
SV * |
6860
|
44095
|
|
|
|
|
Perl_cv_const_sv(pTHX_ const CV *const cv) |
6861
|
|
|
|
|
|
{ |
6862
|
|
|
|
|
|
SV *sv; |
6863
|
|
|
|
|
|
PERL_UNUSED_CONTEXT; |
6864
|
44095
|
50
|
|
|
|
if (!cv) |
6865
|
|
|
|
|
|
return NULL; |
6866
|
44095
|
50
|
|
|
|
if (!(SvTYPE(cv) == SVt_PVCV || SvTYPE(cv) == SVt_PVFM)) |
6867
|
|
|
|
|
|
return NULL; |
6868
|
44095
|
100
|
|
|
|
sv = CvCONST(cv) ? MUTABLE_SV(CvXSUBANY(cv).any_ptr) : NULL; |
6869
|
44095
|
100
|
|
|
|
if (sv && SvTYPE(sv) == SVt_PVAV) return NULL; |
|
|
50
|
|
|
|
|
6870
|
44095
|
|
|
|
|
return sv; |
6871
|
|
|
|
|
|
} |
6872
|
|
|
|
|
|
|
6873
|
|
|
|
|
|
SV * |
6874
|
3891734
|
|
|
|
|
Perl_cv_const_sv_or_av(pTHX_ const CV * const cv) |
6875
|
|
|
|
|
|
{ |
6876
|
|
|
|
|
|
PERL_UNUSED_CONTEXT; |
6877
|
3891734
|
50
|
|
|
|
if (!cv) |
6878
|
|
|
|
|
|
return NULL; |
6879
|
|
|
|
|
|
assert (SvTYPE(cv) == SVt_PVCV || SvTYPE(cv) == SVt_PVFM); |
6880
|
3891734
|
100
|
|
|
|
return CvCONST(cv) ? MUTABLE_SV(CvXSUBANY(cv).any_ptr) : NULL; |
6881
|
|
|
|
|
|
} |
6882
|
|
|
|
|
|
|
6883
|
|
|
|
|
|
/* op_const_sv: examine an optree to determine whether it's in-lineable. |
6884
|
|
|
|
|
|
*/ |
6885
|
|
|
|
|
|
|
6886
|
|
|
|
|
|
SV * |
6887
|
270526
|
|
|
|
|
Perl_op_const_sv(pTHX_ const OP *o) |
6888
|
|
|
|
|
|
{ |
6889
|
|
|
|
|
|
dVAR; |
6890
|
|
|
|
|
|
SV *sv = NULL; |
6891
|
|
|
|
|
|
|
6892
|
|
|
|
|
|
if (PL_madskills) |
6893
|
|
|
|
|
|
return NULL; |
6894
|
|
|
|
|
|
|
6895
|
270526
|
50
|
|
|
|
if (!o) |
6896
|
|
|
|
|
|
return NULL; |
6897
|
|
|
|
|
|
|
6898
|
270526
|
100
|
|
|
|
if (o->op_type == OP_LINESEQ && cLISTOPo->op_first) |
|
|
50
|
|
|
|
|
6899
|
265043
|
|
|
|
|
o = cLISTOPo->op_first->op_sibling; |
6900
|
|
|
|
|
|
|
6901
|
468414
|
50
|
|
|
|
for (; o; o = o->op_next) { |
6902
|
459054
|
|
|
|
|
const OPCODE type = o->op_type; |
6903
|
|
|
|
|
|
|
6904
|
459054
|
100
|
|
|
|
if (sv && o->op_next == o) |
|
|
50
|
|
|
|
|
6905
|
|
|
|
|
|
return sv; |
6906
|
270526
|
100
|
|
|
|
if (o->op_next != o) { |
6907
|
13224
|
50
|
|
|
|
if (type == OP_NEXTSTATE |
6908
|
13224
|
100
|
|
|
|
|| (type == OP_NULL && !(o->op_flags & OPf_KIDS)) |
|
|
50
|
|
|
|
|
6909
|
13224
|
50
|
|
|
|
|| type == OP_PUSHMARK) |
6910
|
0
|
|
|
|
|
continue; |
6911
|
13224
|
50
|
|
|
|
if (type == OP_DBSTATE) |
6912
|
0
|
|
|
|
|
continue; |
6913
|
|
|
|
|
|
} |
6914
|
270526
|
100
|
|
|
|
if (type == OP_LEAVESUB || type == OP_RETURN) |
6915
|
|
|
|
|
|
break; |
6916
|
265528
|
50
|
|
|
|
if (sv) |
6917
|
|
|
|
|
|
return NULL; |
6918
|
265528
|
100
|
|
|
|
if (type == OP_CONST && cSVOPo->op_sv) |
|
|
50
|
|
|
|
|
6919
|
188528
|
|
|
|
|
sv = cSVOPo->op_sv; |
6920
|
|
|
|
|
|
else { |
6921
|
|
|
|
|
|
return NULL; |
6922
|
|
|
|
|
|
} |
6923
|
|
|
|
|
|
} |
6924
|
|
|
|
|
|
return sv; |
6925
|
|
|
|
|
|
} |
6926
|
|
|
|
|
|
|
6927
|
|
|
|
|
|
static bool |
6928
|
520
|
|
|
|
|
S_already_defined(pTHX_ CV *const cv, OP * const block, OP * const o, |
6929
|
|
|
|
|
|
PADNAME * const name, SV ** const const_svp) |
6930
|
|
|
|
|
|
{ |
6931
|
|
|
|
|
|
assert (cv); |
6932
|
|
|
|
|
|
assert (o || name); |
6933
|
|
|
|
|
|
assert (const_svp); |
6934
|
520
|
100
|
|
|
|
if ((!block |
6935
|
|
|
|
|
|
#ifdef PERL_MAD |
6936
|
|
|
|
|
|
|| block->op_type == OP_NULL |
6937
|
|
|
|
|
|
#endif |
6938
|
|
|
|
|
|
)) { |
6939
|
38
|
100
|
|
|
|
if (CvFLAGS(PL_compcv)) { |
6940
|
|
|
|
|
|
/* might have had built-in attrs applied */ |
6941
|
16
|
100
|
|
|
|
const bool pureperl = !CvISXSUB(cv) && CvROOT(cv); |
|
|
100
|
|
|
|
|
6942
|
16
|
50
|
|
|
|
if (CvLVALUE(PL_compcv) && ! CvLVALUE(cv) && pureperl |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
6943
|
12
|
50
|
|
|
|
&& ckWARN(WARN_MISC)) |
6944
|
|
|
|
|
|
{ |
6945
|
|
|
|
|
|
/* protect against fatal warnings leaking compcv */ |
6946
|
12
|
|
|
|
|
SAVEFREESV(PL_compcv); |
6947
|
12
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_MISC), "lvalue attribute ignored after the subroutine has been defined"); |
6948
|
4
|
|
|
|
|
SvREFCNT_inc_simple_void_NN(PL_compcv); |
6949
|
|
|
|
|
|
} |
6950
|
12
|
|
|
|
|
CvFLAGS(cv) |= |
6951
|
8
|
|
|
|
|
(CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS |
6952
|
8
|
|
|
|
|
& ~(CVf_LVALUE * pureperl)); |
6953
|
|
|
|
|
|
} |
6954
|
|
|
|
|
|
return FALSE; |
6955
|
|
|
|
|
|
} |
6956
|
|
|
|
|
|
|
6957
|
|
|
|
|
|
/* redundant check for speed: */ |
6958
|
482
|
100
|
|
|
|
if (CvCONST(cv) || ckWARN(WARN_REDEFINE)) { |
|
|
100
|
|
|
|
|
6959
|
102
|
|
|
|
|
const line_t oldline = CopLINE(PL_curcop); |
6960
|
|
|
|
|
|
SV *namesv = o |
6961
|
|
|
|
|
|
? cSVOPo->op_sv |
6962
|
102
|
100
|
|
|
|
: sv_2mortal(newSVpvn_utf8( |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
6963
|
|
|
|
|
|
PadnamePV(name)+1,PadnameLEN(name)-1, PadnameUTF8(name) |
6964
|
|
|
|
|
|
)); |
6965
|
102
|
50
|
|
|
|
if (PL_parser && PL_parser->copline != NOLINE) |
|
|
50
|
|
|
|
|
6966
|
|
|
|
|
|
/* This ensures that warnings are reported at the first |
6967
|
|
|
|
|
|
line of a redefinition, not the last. */ |
6968
|
102
|
|
|
|
|
CopLINE_set(PL_curcop, PL_parser->copline); |
6969
|
|
|
|
|
|
/* protect against fatal warnings leaking compcv */ |
6970
|
102
|
|
|
|
|
SAVEFREESV(PL_compcv); |
6971
|
102
|
|
|
|
|
report_redefined_cv(namesv, cv, const_svp); |
6972
|
98
|
|
|
|
|
SvREFCNT_inc_simple_void_NN(PL_compcv); |
6973
|
98
|
|
|
|
|
CopLINE_set(PL_curcop, oldline); |
6974
|
|
|
|
|
|
} |
6975
|
|
|
|
|
|
#ifdef PERL_MAD |
6976
|
|
|
|
|
|
if (!PL_minus_c) /* keep old one around for madskills */ |
6977
|
|
|
|
|
|
#endif |
6978
|
|
|
|
|
|
{ |
6979
|
|
|
|
|
|
/* (PL_madskills unset in used file.) */ |
6980
|
478
|
|
|
|
|
SvREFCNT_dec(cv); |
6981
|
|
|
|
|
|
} |
6982
|
493
|
|
|
|
|
return TRUE; |
6983
|
|
|
|
|
|
} |
6984
|
|
|
|
|
|
|
6985
|
|
|
|
|
|
CV * |
6986
|
236
|
|
|
|
|
Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block) |
6987
|
|
|
|
|
|
{ |
6988
|
|
|
|
|
|
dVAR; |
6989
|
|
|
|
|
|
CV **spot; |
6990
|
|
|
|
|
|
SV **svspot; |
6991
|
|
|
|
|
|
const char *ps; |
6992
|
236
|
|
|
|
|
STRLEN ps_len = 0; /* init it to avoid false uninit warning from icc */ |
6993
|
|
|
|
|
|
U32 ps_utf8 = 0; |
6994
|
|
|
|
|
|
CV *cv = NULL; |
6995
|
236
|
|
|
|
|
CV *compcv = PL_compcv; |
6996
|
|
|
|
|
|
SV *const_sv; |
6997
|
|
|
|
|
|
PADNAME *name; |
6998
|
236
|
|
|
|
|
PADOFFSET pax = o->op_targ; |
6999
|
236
|
|
|
|
|
CV *outcv = CvOUTSIDE(PL_compcv); |
7000
|
236
|
|
|
|
|
CV *clonee = NULL; |
7001
|
|
|
|
|
|
HEK *hek = NULL; |
7002
|
|
|
|
|
|
bool reusable = FALSE; |
7003
|
|
|
|
|
|
|
7004
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWMYSUB; |
7005
|
|
|
|
|
|
|
7006
|
|
|
|
|
|
/* Find the pad slot for storing the new sub. |
7007
|
|
|
|
|
|
We cannot use PL_comppad, as it is the pad owned by the new sub. We |
7008
|
|
|
|
|
|
need to look in CvOUTSIDE and find the pad belonging to the enclos- |
7009
|
|
|
|
|
|
ing sub. And then we need to dig deeper if this is a lexical from |
7010
|
|
|
|
|
|
outside, as in: |
7011
|
|
|
|
|
|
my sub foo; sub { sub foo { } } |
7012
|
|
|
|
|
|
*/ |
7013
|
|
|
|
|
|
redo: |
7014
|
266
|
|
|
|
|
name = PadlistNAMESARRAY(CvPADLIST(outcv))[pax]; |
7015
|
266
|
100
|
|
|
|
if (PadnameOUTER(name) && PARENT_PAD_INDEX(name)) { |
|
|
50
|
|
|
|
|
7016
|
30
|
|
|
|
|
pax = PARENT_PAD_INDEX(name); |
7017
|
30
|
|
|
|
|
outcv = CvOUTSIDE(outcv); |
7018
|
|
|
|
|
|
assert(outcv); |
7019
|
30
|
|
|
|
|
goto redo; |
7020
|
|
|
|
|
|
} |
7021
|
236
|
|
|
|
|
svspot = |
7022
|
359
|
100
|
|
|
|
&PadARRAY(PadlistARRAY(CvPADLIST(outcv)) |
7023
|
236
|
|
|
|
|
[CvDEPTH(outcv) ? CvDEPTH(outcv) : 1])[pax]; |
7024
|
|
|
|
|
|
spot = (CV **)svspot; |
7025
|
|
|
|
|
|
|
7026
|
236
|
100
|
|
|
|
if (proto) { |
7027
|
|
|
|
|
|
assert(proto->op_type == OP_CONST); |
7028
|
42
|
50
|
|
|
|
ps = SvPV_const(((SVOP*)proto)->op_sv, ps_len); |
7029
|
42
|
|
|
|
|
ps_utf8 = SvUTF8(((SVOP*)proto)->op_sv); |
7030
|
|
|
|
|
|
} |
7031
|
|
|
|
|
|
else |
7032
|
|
|
|
|
|
ps = NULL; |
7033
|
|
|
|
|
|
|
7034
|
|
|
|
|
|
if (!PL_madskills) { |
7035
|
236
|
100
|
|
|
|
if (proto) |
7036
|
42
|
|
|
|
|
SAVEFREEOP(proto); |
7037
|
236
|
50
|
|
|
|
if (attrs) |
7038
|
0
|
|
|
|
|
SAVEFREEOP(attrs); |
7039
|
|
|
|
|
|
} |
7040
|
|
|
|
|
|
|
7041
|
236
|
50
|
|
|
|
if (PL_parser && PL_parser->error_count) { |
|
|
100
|
|
|
|
|
7042
|
8
|
|
|
|
|
op_free(block); |
7043
|
8
|
|
|
|
|
SvREFCNT_dec(PL_compcv); |
7044
|
8
|
|
|
|
|
PL_compcv = 0; |
7045
|
8
|
|
|
|
|
goto done; |
7046
|
|
|
|
|
|
} |
7047
|
|
|
|
|
|
|
7048
|
228
|
100
|
|
|
|
if (CvDEPTH(outcv) && CvCLONE(compcv)) { |
|
|
100
|
|
|
|
|
7049
|
4
|
|
|
|
|
cv = *spot; |
7050
|
4
|
|
|
|
|
svspot = (SV **)(spot = &clonee); |
7051
|
|
|
|
|
|
} |
7052
|
295
|
100
|
|
|
|
else if (PadnameIsSTATE(name) || CvDEPTH(outcv)) |
|
|
50
|
|
|
|
|
7053
|
82
|
|
|
|
|
cv = *spot; |
7054
|
142
|
100
|
|
|
|
else { |
7055
|
|
|
|
|
|
MAGIC *mg; |
7056
|
177
|
|
|
|
|
SvUPGRADE(name, SVt_PVMG); |
7057
|
142
|
|
|
|
|
mg = mg_find(name, PERL_MAGIC_proto); |
7058
|
|
|
|
|
|
assert (SvTYPE(*spot) == SVt_PVCV); |
7059
|
142
|
100
|
|
|
|
if (CvNAMED(*spot)) |
7060
|
36
|
|
|
|
|
hek = CvNAME_HEK(*spot); |
7061
|
|
|
|
|
|
else { |
7062
|
159
|
50
|
|
|
|
CvNAME_HEK_set(*spot, hek = |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
7063
|
|
|
|
|
|
share_hek( |
7064
|
|
|
|
|
|
PadnamePV(name)+1, |
7065
|
|
|
|
|
|
PadnameLEN(name)-1 * (PadnameUTF8(name) ? -1 : 1), 0 |
7066
|
|
|
|
|
|
) |
7067
|
|
|
|
|
|
); |
7068
|
|
|
|
|
|
} |
7069
|
142
|
100
|
|
|
|
if (mg) { |
7070
|
|
|
|
|
|
assert(mg->mg_obj); |
7071
|
36
|
|
|
|
|
cv = (CV *)mg->mg_obj; |
7072
|
|
|
|
|
|
} |
7073
|
|
|
|
|
|
else { |
7074
|
106
|
|
|
|
|
sv_magic(name, &PL_sv_undef, PERL_MAGIC_proto, NULL, 0); |
7075
|
106
|
|
|
|
|
mg = mg_find(name, PERL_MAGIC_proto); |
7076
|
|
|
|
|
|
} |
7077
|
142
|
|
|
|
|
spot = (CV **)(svspot = &mg->mg_obj); |
7078
|
|
|
|
|
|
} |
7079
|
|
|
|
|
|
|
7080
|
228
|
100
|
|
|
|
if (!block || !ps || *ps || attrs |
|
|
100
|
|
|
|
|
7081
|
24
|
50
|
|
|
|
|| (CvFLAGS(compcv) & CVf_BUILTIN_ATTRS) |
7082
|
|
|
|
|
|
#ifdef PERL_MAD |
7083
|
|
|
|
|
|
|| block->op_type == OP_NULL |
7084
|
|
|
|
|
|
#endif |
7085
|
|
|
|
|
|
) |
7086
|
204
|
|
|
|
|
const_sv = NULL; |
7087
|
|
|
|
|
|
else |
7088
|
24
|
|
|
|
|
const_sv = op_const_sv(block); |
7089
|
|
|
|
|
|
|
7090
|
228
|
100
|
|
|
|
if (cv) { |
7091
|
122
|
100
|
|
|
|
const bool exists = CvROOT(cv) || CvXSUB(cv); |
|
|
50
|
|
|
|
|
7092
|
|
|
|
|
|
|
7093
|
|
|
|
|
|
/* if the subroutine doesn't exist and wasn't pre-declared |
7094
|
|
|
|
|
|
* with a prototype, assume it will be AUTOLOADed, |
7095
|
|
|
|
|
|
* skipping the prototype check |
7096
|
|
|
|
|
|
*/ |
7097
|
122
|
100
|
|
|
|
if (exists || SvPOK(cv)) |
|
|
100
|
|
|
|
|
7098
|
22
|
|
|
|
|
cv_ckproto_len_flags(cv, (GV *)name, ps, ps_len, ps_utf8); |
7099
|
|
|
|
|
|
/* already defined? */ |
7100
|
122
|
100
|
|
|
|
if (exists) { |
7101
|
18
|
50
|
|
|
|
if (S_already_defined(aTHX_ cv, block, NULL, name, &const_sv)) |
7102
|
|
|
|
|
|
cv = NULL; |
7103
|
|
|
|
|
|
else { |
7104
|
0
|
0
|
|
|
|
if (attrs) goto attrs; |
7105
|
|
|
|
|
|
/* just a "sub foo;" when &foo is already defined */ |
7106
|
0
|
|
|
|
|
SAVEFREESV(compcv); |
7107
|
0
|
|
|
|
|
goto done; |
7108
|
|
|
|
|
|
} |
7109
|
|
|
|
|
|
} |
7110
|
104
|
100
|
|
|
|
else if (CvDEPTH(outcv) && CvCLONE(compcv)) { |
|
|
100
|
|
|
|
|
7111
|
|
|
|
|
|
cv = NULL; |
7112
|
|
|
|
|
|
reusable = TRUE; |
7113
|
|
|
|
|
|
} |
7114
|
|
|
|
|
|
} |
7115
|
224
|
100
|
|
|
|
if (const_sv) { |
7116
|
22
|
|
|
|
|
SvREFCNT_inc_simple_void_NN(const_sv); |
7117
|
22
|
|
|
|
|
SvFLAGS(const_sv) = (SvFLAGS(const_sv) & ~SVs_PADMY) | SVs_PADTMP; |
7118
|
22
|
100
|
|
|
|
if (cv) { |
7119
|
|
|
|
|
|
assert(!CvROOT(cv) && !CvCONST(cv)); |
7120
|
6
|
|
|
|
|
cv_forget_slab(cv); |
7121
|
|
|
|
|
|
} |
7122
|
|
|
|
|
|
else { |
7123
|
16
|
|
|
|
|
cv = MUTABLE_CV(newSV_type(SVt_PVCV)); |
7124
|
16
|
50
|
|
|
|
CvFILE_set_from_cop(cv, PL_curcop); |
7125
|
16
|
|
|
|
|
CvSTASH_set(cv, PL_curstash); |
7126
|
16
|
|
|
|
|
*spot = cv; |
7127
|
|
|
|
|
|
} |
7128
|
22
|
|
|
|
|
sv_setpvs(MUTABLE_SV(cv), ""); /* prototype is "" */ |
7129
|
22
|
|
|
|
|
CvXSUBANY(cv).any_ptr = const_sv; |
7130
|
22
|
|
|
|
|
CvXSUB(cv) = const_sv_xsub; |
7131
|
22
|
|
|
|
|
CvCONST_on(cv); |
7132
|
22
|
|
|
|
|
CvISXSUB_on(cv); |
7133
|
|
|
|
|
|
if (PL_madskills) |
7134
|
|
|
|
|
|
goto install_block; |
7135
|
22
|
|
|
|
|
op_free(block); |
7136
|
22
|
|
|
|
|
SvREFCNT_dec(compcv); |
7137
|
22
|
|
|
|
|
PL_compcv = NULL; |
7138
|
22
|
|
|
|
|
goto setname; |
7139
|
|
|
|
|
|
} |
7140
|
|
|
|
|
|
/* Checking whether outcv is CvOUTSIDE(compcv) is not sufficient to |
7141
|
|
|
|
|
|
determine whether this sub definition is in the same scope as its |
7142
|
|
|
|
|
|
declaration. If this sub definition is inside an inner named pack- |
7143
|
|
|
|
|
|
age sub (my sub foo; sub bar { sub foo { ... } }), outcv points to |
7144
|
|
|
|
|
|
the package sub. So check PadnameOUTER(name) too. |
7145
|
|
|
|
|
|
*/ |
7146
|
202
|
100
|
|
|
|
if (outcv == CvOUTSIDE(compcv) && !PadnameOUTER(name)) { |
|
|
50
|
|
|
|
|
7147
|
|
|
|
|
|
assert(!CvWEAKOUTSIDE(compcv)); |
7148
|
174
|
|
|
|
|
SvREFCNT_dec(CvOUTSIDE(compcv)); |
7149
|
174
|
|
|
|
|
CvWEAKOUTSIDE_on(compcv); |
7150
|
|
|
|
|
|
} |
7151
|
|
|
|
|
|
/* XXX else do we have a circular reference? */ |
7152
|
202
|
100
|
|
|
|
if (cv) { /* must reuse cv in case stub is referenced elsewhere */ |
7153
|
|
|
|
|
|
/* transfer PL_compcv to cv */ |
7154
|
96
|
100
|
|
|
|
if (block |
7155
|
|
|
|
|
|
#ifdef PERL_MAD |
7156
|
|
|
|
|
|
&& block->op_type != OP_NULL |
7157
|
|
|
|
|
|
#endif |
7158
|
|
|
|
|
|
) { |
7159
|
72
|
|
|
|
|
cv_flags_t preserved_flags = |
7160
|
72
|
|
|
|
|
CvFLAGS(cv) & (CVf_BUILTIN_ATTRS|CVf_NAMED); |
7161
|
72
|
|
|
|
|
PADLIST *const temp_padl = CvPADLIST(cv); |
7162
|
72
|
|
|
|
|
CV *const temp_cv = CvOUTSIDE(cv); |
7163
|
72
|
|
|
|
|
const cv_flags_t other_flags = |
7164
|
72
|
|
|
|
|
CvFLAGS(cv) & (CVf_SLABBED|CVf_WEAKOUTSIDE); |
7165
|
72
|
|
|
|
|
OP * const cvstart = CvSTART(cv); |
7166
|
|
|
|
|
|
|
7167
|
72
|
|
|
|
|
SvPOK_off(cv); |
7168
|
144
|
|
|
|
|
CvFLAGS(cv) = |
7169
|
72
|
|
|
|
|
CvFLAGS(compcv) | preserved_flags; |
7170
|
72
|
|
|
|
|
CvOUTSIDE(cv) = CvOUTSIDE(compcv); |
7171
|
72
|
|
|
|
|
CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(compcv); |
7172
|
72
|
|
|
|
|
CvPADLIST(cv) = CvPADLIST(compcv); |
7173
|
72
|
|
|
|
|
CvOUTSIDE(compcv) = temp_cv; |
7174
|
72
|
|
|
|
|
CvPADLIST(compcv) = temp_padl; |
7175
|
72
|
|
|
|
|
CvSTART(cv) = CvSTART(compcv); |
7176
|
72
|
|
|
|
|
CvSTART(compcv) = cvstart; |
7177
|
72
|
|
|
|
|
CvFLAGS(compcv) &= ~(CVf_SLABBED|CVf_WEAKOUTSIDE); |
7178
|
72
|
|
|
|
|
CvFLAGS(compcv) |= other_flags; |
7179
|
|
|
|
|
|
|
7180
|
72
|
100
|
|
|
|
if (CvFILE(cv) && CvDYNFILE(cv)) { |
|
|
50
|
|
|
|
|
7181
|
0
|
|
|
|
|
Safefree(CvFILE(cv)); |
7182
|
|
|
|
|
|
} |
7183
|
|
|
|
|
|
|
7184
|
|
|
|
|
|
/* inner references to compcv must be fixed up ... */ |
7185
|
72
|
|
|
|
|
pad_fixup_inner_anons(CvPADLIST(cv), compcv, cv); |
7186
|
72
|
100
|
|
|
|
if (PERLDB_INTER)/* Advice debugger on the new sub. */ |
|
|
50
|
|
|
|
|
7187
|
0
|
|
|
|
|
++PL_sub_generation; |
7188
|
|
|
|
|
|
} |
7189
|
|
|
|
|
|
else { |
7190
|
|
|
|
|
|
/* Might have had built-in attributes applied -- propagate them. */ |
7191
|
24
|
|
|
|
|
CvFLAGS(cv) |= (CvFLAGS(compcv) & CVf_BUILTIN_ATTRS); |
7192
|
|
|
|
|
|
} |
7193
|
|
|
|
|
|
/* ... before we throw it away */ |
7194
|
96
|
|
|
|
|
SvREFCNT_dec(compcv); |
7195
|
96
|
|
|
|
|
PL_compcv = compcv = cv; |
7196
|
|
|
|
|
|
} |
7197
|
|
|
|
|
|
else { |
7198
|
|
|
|
|
|
cv = compcv; |
7199
|
106
|
|
|
|
|
*spot = cv; |
7200
|
|
|
|
|
|
} |
7201
|
|
|
|
|
|
setname: |
7202
|
224
|
100
|
|
|
|
if (!CvNAME_HEK(cv)) { |
7203
|
184
|
50
|
|
|
|
CvNAME_HEK_set(cv, |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
7204
|
|
|
|
|
|
hek |
7205
|
|
|
|
|
|
? share_hek_hek(hek) |
7206
|
|
|
|
|
|
: share_hek(PadnamePV(name)+1, |
7207
|
|
|
|
|
|
PadnameLEN(name)-1 * (PadnameUTF8(name) ? -1 : 1), |
7208
|
|
|
|
|
|
0) |
7209
|
|
|
|
|
|
); |
7210
|
|
|
|
|
|
} |
7211
|
224
|
100
|
|
|
|
if (const_sv) goto clone; |
7212
|
|
|
|
|
|
|
7213
|
202
|
50
|
|
|
|
CvFILE_set_from_cop(cv, PL_curcop); |
7214
|
202
|
|
|
|
|
CvSTASH_set(cv, PL_curstash); |
7215
|
|
|
|
|
|
|
7216
|
202
|
100
|
|
|
|
if (ps) { |
7217
|
20
|
|
|
|
|
sv_setpvn(MUTABLE_SV(cv), ps, ps_len); |
7218
|
20
|
100
|
|
|
|
if ( ps_utf8 ) SvUTF8_on(MUTABLE_SV(cv)); |
7219
|
|
|
|
|
|
} |
7220
|
|
|
|
|
|
|
7221
|
|
|
|
|
|
install_block: |
7222
|
202
|
100
|
|
|
|
if (!block) |
7223
|
|
|
|
|
|
goto attrs; |
7224
|
|
|
|
|
|
|
7225
|
|
|
|
|
|
/* If we assign an optree to a PVCV, then we've defined a subroutine that |
7226
|
|
|
|
|
|
the debugger could be able to set a breakpoint in, so signal to |
7227
|
|
|
|
|
|
pp_entereval that it should not throw away any saved lines at scope |
7228
|
|
|
|
|
|
exit. */ |
7229
|
|
|
|
|
|
|
7230
|
138
|
|
|
|
|
PL_breakable_sub_gen++; |
7231
|
|
|
|
|
|
/* This makes sub {}; work as expected. */ |
7232
|
138
|
100
|
|
|
|
if (block->op_type == OP_STUB) { |
7233
|
34
|
|
|
|
|
OP* const newblock = newSTATEOP(0, NULL, 0); |
7234
|
|
|
|
|
|
#ifdef PERL_MAD |
7235
|
|
|
|
|
|
op_getmad(block,newblock,'B'); |
7236
|
|
|
|
|
|
#else |
7237
|
34
|
|
|
|
|
op_free(block); |
7238
|
|
|
|
|
|
#endif |
7239
|
|
|
|
|
|
block = newblock; |
7240
|
|
|
|
|
|
} |
7241
|
276
|
|
|
|
|
CvROOT(cv) = CvLVALUE(cv) |
7242
|
0
|
|
|
|
|
? newUNOP(OP_LEAVESUBLV, 0, |
7243
|
|
|
|
|
|
op_lvalue(scalarseq(block), OP_LEAVESUBLV)) |
7244
|
138
|
50
|
|
|
|
: newUNOP(OP_LEAVESUB, 0, scalarseq(block)); |
7245
|
138
|
|
|
|
|
CvROOT(cv)->op_private |= OPpREFCOUNTED; |
7246
|
138
|
|
|
|
|
OpREFCNT_set(CvROOT(cv), 1); |
7247
|
|
|
|
|
|
/* The cv no longer needs to hold a refcount on the slab, as CvROOT |
7248
|
|
|
|
|
|
itself has a refcount. */ |
7249
|
138
|
|
|
|
|
CvSLABBED_off(cv); |
7250
|
138
|
50
|
|
|
|
OpslabREFCNT_dec_padok((OPSLAB *)CvSTART(cv)); |
7251
|
138
|
50
|
|
|
|
CvSTART(cv) = LINKLIST(CvROOT(cv)); |
7252
|
138
|
|
|
|
|
CvROOT(cv)->op_next = 0; |
7253
|
138
|
|
|
|
|
CALL_PEEP(CvSTART(cv)); |
7254
|
138
|
|
|
|
|
finalize_optree(CvROOT(cv)); |
7255
|
|
|
|
|
|
|
7256
|
|
|
|
|
|
/* now that optimizer has done its work, adjust pad values */ |
7257
|
|
|
|
|
|
|
7258
|
138
|
|
|
|
|
pad_tidy(CvCLONE(cv) ? padtidy_SUBCLONE : padtidy_SUB); |
7259
|
|
|
|
|
|
|
7260
|
|
|
|
|
|
attrs: |
7261
|
202
|
50
|
|
|
|
if (attrs) { |
7262
|
|
|
|
|
|
/* Need to do a C |
7263
|
0
|
|
|
|
|
apply_attrs(PL_curstash, MUTABLE_SV(cv), attrs); |
7264
|
|
|
|
|
|
} |
7265
|
|
|
|
|
|
|
7266
|
202
|
100
|
|
|
|
if (block) { |
7267
|
138
|
100
|
|
|
|
if (PERLDB_SUBLINE && PL_curstash != PL_debstash) { |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
7268
|
0
|
|
|
|
|
SV * const tmpstr = sv_newmortal(); |
7269
|
0
|
|
|
|
|
GV * const db_postponed = gv_fetchpvs("DB::postponed", |
7270
|
|
|
|
|
|
GV_ADDMULTI, SVt_PVHV); |
7271
|
|
|
|
|
|
HV *hv; |
7272
|
0
|
0
|
|
|
|
SV * const sv = Perl_newSVpvf(aTHX_ "%s:%ld-%ld", |
7273
|
0
|
|
|
|
|
CopFILE(PL_curcop), |
7274
|
|
|
|
|
|
(long)PL_subline, |
7275
|
0
|
|
|
|
|
(long)CopLINE(PL_curcop)); |
7276
|
0
|
0
|
|
|
|
if (HvNAME_HEK(PL_curstash)) { |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
7277
|
0
|
0
|
|
|
|
sv_sethek(tmpstr, HvNAME_HEK(PL_curstash)); |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
7278
|
0
|
|
|
|
|
sv_catpvs(tmpstr, "::"); |
7279
|
|
|
|
|
|
} |
7280
|
0
|
|
|
|
|
else sv_setpvs(tmpstr, "__ANON__::"); |
7281
|
0
|
0
|
|
|
|
sv_catpvn_flags(tmpstr, PadnamePV(name)+1, PadnameLEN(name)-1, |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
7282
|
|
|
|
|
|
PadnameUTF8(name) ? SV_CATUTF8 : SV_CATBYTES); |
7283
|
0
|
0
|
|
|
|
(void)hv_store(GvHV(PL_DBsub), SvPVX_const(tmpstr), |
7284
|
|
|
|
|
|
SvUTF8(tmpstr) ? -(I32)SvCUR(tmpstr) : (I32)SvCUR(tmpstr), sv, 0); |
7285
|
0
|
0
|
|
|
|
hv = GvHVn(db_postponed); |
7286
|
0
|
0
|
|
|
|
if (HvTOTALKEYS(hv) > 0 && hv_exists(hv, SvPVX_const(tmpstr), SvUTF8(tmpstr) ? -(I32)SvCUR(tmpstr) : (I32)SvCUR(tmpstr))) { |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
7287
|
0
|
|
|
|
|
CV * const pcv = GvCV(db_postponed); |
7288
|
0
|
0
|
|
|
|
if (pcv) { |
7289
|
0
|
|
|
|
|
dSP; |
7290
|
0
|
0
|
|
|
|
PUSHMARK(SP); |
7291
|
0
|
0
|
|
|
|
XPUSHs(tmpstr); |
7292
|
0
|
|
|
|
|
PUTBACK; |
7293
|
0
|
|
|
|
|
call_sv(MUTABLE_SV(pcv), G_DISCARD); |
7294
|
|
|
|
|
|
} |
7295
|
|
|
|
|
|
} |
7296
|
|
|
|
|
|
} |
7297
|
|
|
|
|
|
} |
7298
|
|
|
|
|
|
|
7299
|
|
|
|
|
|
clone: |
7300
|
224
|
100
|
|
|
|
if (clonee) { |
7301
|
|
|
|
|
|
assert(CvDEPTH(outcv)); |
7302
|
4
|
|
|
|
|
spot = (CV **) |
7303
|
8
|
|
|
|
|
&PadARRAY(PadlistARRAY(CvPADLIST(outcv))[CvDEPTH(outcv)])[pax]; |
7304
|
4
|
100
|
|
|
|
if (reusable) cv_clone_into(clonee, *spot); |
7305
|
2
|
|
|
|
|
else *spot = cv_clone(clonee); |
7306
|
4
|
|
|
|
|
SvREFCNT_dec_NN(clonee); |
7307
|
4
|
|
|
|
|
cv = *spot; |
7308
|
4
|
|
|
|
|
SvPADMY_on(cv); |
7309
|
|
|
|
|
|
} |
7310
|
224
|
100
|
|
|
|
if (CvDEPTH(outcv) && !reusable && PadnameIsSTATE(name)) { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
7311
|
6
|
|
|
|
|
PADOFFSET depth = CvDEPTH(outcv); |
7312
|
11
|
100
|
|
|
|
while (--depth) { |
7313
|
|
|
|
|
|
SV *oldcv; |
7314
|
2
|
|
|
|
|
svspot = &PadARRAY(PadlistARRAY(CvPADLIST(outcv))[depth])[pax]; |
7315
|
2
|
|
|
|
|
oldcv = *svspot; |
7316
|
2
|
|
|
|
|
*svspot = SvREFCNT_inc_simple_NN(cv); |
7317
|
2
|
|
|
|
|
SvREFCNT_dec(oldcv); |
7318
|
|
|
|
|
|
} |
7319
|
|
|
|
|
|
} |
7320
|
|
|
|
|
|
|
7321
|
|
|
|
|
|
done: |
7322
|
232
|
50
|
|
|
|
if (PL_parser) |
7323
|
232
|
|
|
|
|
PL_parser->copline = NOLINE; |
7324
|
232
|
50
|
|
|
|
LEAVE_SCOPE(floor); |
7325
|
232
|
50
|
|
|
|
if (o) op_free(o); |
7326
|
232
|
|
|
|
|
return cv; |
7327
|
|
|
|
|
|
} |
7328
|
|
|
|
|
|
|
7329
|
|
|
|
|
|
CV * |
7330
|
12998418
|
|
|
|
|
Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block) |
7331
|
|
|
|
|
|
{ |
7332
|
12998418
|
|
|
|
|
return newATTRSUB_flags(floor, o, proto, attrs, block, 0); |
7333
|
|
|
|
|
|
} |
7334
|
|
|
|
|
|
|
7335
|
|
|
|
|
|
CV * |
7336
|
12999146
|
|
|
|
|
Perl_newATTRSUB_flags(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, |
7337
|
|
|
|
|
|
OP *block, U32 flags) |
7338
|
|
|
|
|
|
{ |
7339
|
|
|
|
|
|
dVAR; |
7340
|
|
|
|
|
|
GV *gv; |
7341
|
|
|
|
|
|
const char *ps; |
7342
|
12999146
|
|
|
|
|
STRLEN ps_len = 0; /* init it to avoid false uninit warning from icc */ |
7343
|
|
|
|
|
|
U32 ps_utf8 = 0; |
7344
|
|
|
|
|
|
CV *cv = NULL; |
7345
|
|
|
|
|
|
SV *const_sv; |
7346
|
12999146
|
50
|
|
|
|
const bool ec = PL_parser && PL_parser->error_count; |
|
|
100
|
|
|
|
|
7347
|
|
|
|
|
|
/* If the subroutine has no body, no attributes, and no builtin attributes |
7348
|
|
|
|
|
|
then it's just a sub declaration, and we may be able to get away with |
7349
|
|
|
|
|
|
storing with a placeholder scalar in the symbol table, rather than a |
7350
|
|
|
|
|
|
full GV and CV. If anything is present then it will take a full CV to |
7351
|
|
|
|
|
|
store it. */ |
7352
|
|
|
|
|
|
const I32 gv_fetch_flags |
7353
|
12999146
|
100
|
|
|
|
= ec ? GV_NOADD_NOINIT : |
7354
|
6655202
|
100
|
|
|
|
(block || attrs || (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS) |
7355
|
12998716
|
100
|
|
|
|
|| PL_madskills) |
7356
|
12998716
|
100
|
|
|
|
? GV_ADDMULTI : GV_ADDMULTI | GV_NOINIT; |
7357
|
12999146
|
|
|
|
|
STRLEN namlen = 0; |
7358
|
12999146
|
|
|
|
|
const bool o_is_gv = flags & 1; |
7359
|
|
|
|
|
|
const char * const name = |
7360
|
12999146
|
100
|
|
|
|
o ? SvPV_const(o_is_gv ? (SV *)o : cSVOPo->op_sv, namlen) : NULL; |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
7361
|
|
|
|
|
|
bool has_name; |
7362
|
12999146
|
100
|
|
|
|
bool name_is_utf8 = o && !o_is_gv && SvUTF8(cSVOPo->op_sv); |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
7363
|
|
|
|
|
|
#ifdef PERL_DEBUG_READONLY_OPS |
7364
|
|
|
|
|
|
OPSLAB *slab = NULL; |
7365
|
|
|
|
|
|
#endif |
7366
|
|
|
|
|
|
|
7367
|
12999146
|
100
|
|
|
|
if (proto) { |
7368
|
|
|
|
|
|
assert(proto->op_type == OP_CONST); |
7369
|
455240
|
50
|
|
|
|
ps = SvPV_const(((SVOP*)proto)->op_sv, ps_len); |
7370
|
455240
|
|
|
|
|
ps_utf8 = SvUTF8(((SVOP*)proto)->op_sv); |
7371
|
|
|
|
|
|
} |
7372
|
|
|
|
|
|
else |
7373
|
|
|
|
|
|
ps = NULL; |
7374
|
|
|
|
|
|
|
7375
|
12999146
|
100
|
|
|
|
if (o_is_gv) { |
7376
|
|
|
|
|
|
gv = (GV*)o; |
7377
|
|
|
|
|
|
o = NULL; |
7378
|
|
|
|
|
|
has_name = TRUE; |
7379
|
12998418
|
100
|
|
|
|
} else if (name) { |
7380
|
12439522
|
|
|
|
|
gv = gv_fetchsv(cSVOPo->op_sv, gv_fetch_flags, SVt_PVCV); |
7381
|
|
|
|
|
|
has_name = TRUE; |
7382
|
562606
|
100
|
|
|
|
} else if (PERLDB_NAMEANON && CopLINE(PL_curcop)) { |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
7383
|
3710
|
|
|
|
|
SV * const sv = sv_newmortal(); |
7384
|
9275
|
50
|
|
|
|
Perl_sv_setpvf(aTHX_ sv, "%s[%s:%"IVdf"]", |
|
|
50
|
|
|
|
|
7385
|
3710
|
|
|
|
|
PL_curstash ? "__ANON__" : "__ANON__::__ANON__", |
7386
|
11130
|
|
|
|
|
CopFILE(PL_curcop), (IV)CopLINE(PL_curcop)); |
7387
|
3710
|
|
|
|
|
gv = gv_fetchsv(sv, gv_fetch_flags, SVt_PVCV); |
7388
|
|
|
|
|
|
has_name = TRUE; |
7389
|
555186
|
50
|
|
|
|
} else if (PL_curstash) { |
7390
|
555186
|
|
|
|
|
gv = gv_fetchpvs("__ANON__", gv_fetch_flags, SVt_PVCV); |
7391
|
|
|
|
|
|
has_name = FALSE; |
7392
|
|
|
|
|
|
} else { |
7393
|
0
|
|
|
|
|
gv = gv_fetchpvs("__ANON__::__ANON__", gv_fetch_flags, SVt_PVCV); |
7394
|
|
|
|
|
|
has_name = FALSE; |
7395
|
|
|
|
|
|
} |
7396
|
|
|
|
|
|
|
7397
|
|
|
|
|
|
if (!PL_madskills) { |
7398
|
12999146
|
100
|
|
|
|
if (o) |
7399
|
12439522
|
|
|
|
|
SAVEFREEOP(o); |
7400
|
12999146
|
100
|
|
|
|
if (proto) |
7401
|
455240
|
|
|
|
|
SAVEFREEOP(proto); |
7402
|
12999146
|
100
|
|
|
|
if (attrs) |
7403
|
112
|
|
|
|
|
SAVEFREEOP(attrs); |
7404
|
|
|
|
|
|
} |
7405
|
|
|
|
|
|
|
7406
|
12999146
|
100
|
|
|
|
if (ec) { |
7407
|
430
|
|
|
|
|
op_free(block); |
7408
|
430
|
100
|
|
|
|
if (name) SvREFCNT_dec(PL_compcv); |
7409
|
340
|
|
|
|
|
else cv = PL_compcv; |
7410
|
430
|
|
|
|
|
PL_compcv = 0; |
7411
|
430
|
100
|
|
|
|
if (name && block) { |
7412
|
80
|
|
|
|
|
const char *s = strrchr(name, ':'); |
7413
|
80
|
100
|
|
|
|
s = s ? s+1 : name; |
7414
|
80
|
100
|
|
|
|
if (strEQ(s, "BEGIN")) { |
7415
|
26
|
50
|
|
|
|
if (PL_in_eval & EVAL_KEEPERR) |
7416
|
0
|
|
|
|
|
Perl_croak_nocontext("BEGIN not safe after errors--compilation aborted"); |
7417
|
|
|
|
|
|
else { |
7418
|
26
|
50
|
|
|
|
SV * const errsv = ERRSV; |
7419
|
|
|
|
|
|
/* force display of errors found but not reported */ |
7420
|
26
|
|
|
|
|
sv_catpvs(errsv, "BEGIN not safe after errors--compilation aborted"); |
7421
|
26
|
|
|
|
|
Perl_croak_nocontext("%"SVf, SVfARG(errsv)); |
7422
|
|
|
|
|
|
} |
7423
|
|
|
|
|
|
} |
7424
|
|
|
|
|
|
} |
7425
|
|
|
|
|
|
goto done; |
7426
|
|
|
|
|
|
} |
7427
|
|
|
|
|
|
|
7428
|
12998716
|
100
|
|
|
|
if (SvTYPE(gv) != SVt_PVGV) { /* Maybe prototype now, and had at |
7429
|
|
|
|
|
|
maximum a prototype before. */ |
7430
|
343509
|
100
|
|
|
|
if (SvTYPE(gv) > SVt_NULL) { |
7431
|
8
|
50
|
|
|
|
cv_ckproto_len_flags((const CV *)gv, |
7432
|
|
|
|
|
|
o ? (const GV *)cSVOPo->op_sv : NULL, ps, |
7433
|
|
|
|
|
|
ps_len, ps_utf8); |
7434
|
|
|
|
|
|
} |
7435
|
343509
|
100
|
|
|
|
if (ps) { |
7436
|
74060
|
|
|
|
|
sv_setpvn(MUTABLE_SV(gv), ps, ps_len); |
7437
|
74060
|
50
|
|
|
|
if ( ps_utf8 ) SvUTF8_on(MUTABLE_SV(gv)); |
7438
|
|
|
|
|
|
} |
7439
|
|
|
|
|
|
else |
7440
|
269449
|
|
|
|
|
sv_setiv(MUTABLE_SV(gv), -1); |
7441
|
|
|
|
|
|
|
7442
|
343509
|
|
|
|
|
SvREFCNT_dec(PL_compcv); |
7443
|
343509
|
|
|
|
|
cv = PL_compcv = NULL; |
7444
|
343509
|
|
|
|
|
goto done; |
7445
|
|
|
|
|
|
} |
7446
|
|
|
|
|
|
|
7447
|
12655207
|
100
|
|
|
|
cv = (!name || GvCVGEN(gv)) ? NULL : GvCV(gv); |
|
|
100
|
|
|
|
|
7448
|
|
|
|
|
|
|
7449
|
12655207
|
100
|
|
|
|
if (!block || !ps || *ps || attrs |
|
|
100
|
|
|
|
|
7450
|
270514
|
100
|
|
|
|
|| (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS) |
7451
|
|
|
|
|
|
#ifdef PERL_MAD |
7452
|
|
|
|
|
|
|| block->op_type == OP_NULL |
7453
|
|
|
|
|
|
#endif |
7454
|
|
|
|
|
|
) |
7455
|
12384705
|
|
|
|
|
const_sv = NULL; |
7456
|
|
|
|
|
|
else |
7457
|
270502
|
|
|
|
|
const_sv = op_const_sv(block); |
7458
|
|
|
|
|
|
|
7459
|
12655207
|
100
|
|
|
|
if (cv) { |
7460
|
81318
|
100
|
|
|
|
const bool exists = CvROOT(cv) || CvXSUB(cv); |
|
|
50
|
|
|
|
|
7461
|
|
|
|
|
|
|
7462
|
|
|
|
|
|
/* if the subroutine doesn't exist and wasn't pre-declared |
7463
|
|
|
|
|
|
* with a prototype, assume it will be AUTOLOADed, |
7464
|
|
|
|
|
|
* skipping the prototype check |
7465
|
|
|
|
|
|
*/ |
7466
|
81318
|
100
|
|
|
|
if (exists || SvPOK(cv)) |
|
|
100
|
|
|
|
|
7467
|
11842
|
|
|
|
|
cv_ckproto_len_flags(cv, gv, ps, ps_len, ps_utf8); |
7468
|
|
|
|
|
|
/* already defined (or promised)? */ |
7469
|
81318
|
100
|
|
|
|
if (exists || GvASSUMECV(gv)) { |
|
|
100
|
|
|
|
|
7470
|
502
|
100
|
|
|
|
if (S_already_defined(aTHX_ cv, block, o, NULL, &const_sv)) |
7471
|
|
|
|
|
|
cv = NULL; |
7472
|
|
|
|
|
|
else { |
7473
|
30
|
100
|
|
|
|
if (attrs) goto attrs; |
7474
|
|
|
|
|
|
/* just a "sub foo;" when &foo is already defined */ |
7475
|
28
|
|
|
|
|
SAVEFREESV(PL_compcv); |
7476
|
28
|
|
|
|
|
goto done; |
7477
|
|
|
|
|
|
} |
7478
|
|
|
|
|
|
} |
7479
|
|
|
|
|
|
} |
7480
|
12655169
|
100
|
|
|
|
if (const_sv) { |
7481
|
188506
|
|
|
|
|
SvREFCNT_inc_simple_void_NN(const_sv); |
7482
|
188506
|
|
|
|
|
SvFLAGS(const_sv) = (SvFLAGS(const_sv) & ~SVs_PADMY) | SVs_PADTMP; |
7483
|
188506
|
100
|
|
|
|
if (cv) { |
7484
|
|
|
|
|
|
assert(!CvROOT(cv) && !CvCONST(cv)); |
7485
|
2
|
|
|
|
|
cv_forget_slab(cv); |
7486
|
2
|
|
|
|
|
sv_setpvs(MUTABLE_SV(cv), ""); /* prototype is "" */ |
7487
|
2
|
|
|
|
|
CvXSUBANY(cv).any_ptr = const_sv; |
7488
|
2
|
|
|
|
|
CvXSUB(cv) = const_sv_xsub; |
7489
|
2
|
|
|
|
|
CvCONST_on(cv); |
7490
|
2
|
|
|
|
|
CvISXSUB_on(cv); |
7491
|
|
|
|
|
|
} |
7492
|
|
|
|
|
|
else { |
7493
|
188504
|
|
|
|
|
GvCV_set(gv, NULL); |
7494
|
188504
|
100
|
|
|
|
cv = newCONSTSUB_flags( |
7495
|
|
|
|
|
|
NULL, name, namlen, name_is_utf8 ? SVf_UTF8 : 0, |
7496
|
|
|
|
|
|
const_sv |
7497
|
|
|
|
|
|
); |
7498
|
|
|
|
|
|
} |
7499
|
|
|
|
|
|
if (PL_madskills) |
7500
|
|
|
|
|
|
goto install_block; |
7501
|
188506
|
|
|
|
|
op_free(block); |
7502
|
188506
|
|
|
|
|
SvREFCNT_dec(PL_compcv); |
7503
|
188506
|
|
|
|
|
PL_compcv = NULL; |
7504
|
188506
|
|
|
|
|
goto done; |
7505
|
|
|
|
|
|
} |
7506
|
12466663
|
100
|
|
|
|
if (cv) { /* must reuse cv if autoloaded */ |
7507
|
|
|
|
|
|
/* transfer PL_compcv to cv */ |
7508
|
80814
|
100
|
|
|
|
if (block |
7509
|
|
|
|
|
|
#ifdef PERL_MAD |
7510
|
|
|
|
|
|
&& block->op_type != OP_NULL |
7511
|
|
|
|
|
|
#endif |
7512
|
|
|
|
|
|
) { |
7513
|
80798
|
|
|
|
|
cv_flags_t existing_builtin_attrs = CvFLAGS(cv) & CVf_BUILTIN_ATTRS; |
7514
|
80798
|
|
|
|
|
PADLIST *const temp_av = CvPADLIST(cv); |
7515
|
80798
|
|
|
|
|
CV *const temp_cv = CvOUTSIDE(cv); |
7516
|
80798
|
|
|
|
|
const cv_flags_t other_flags = |
7517
|
80798
|
|
|
|
|
CvFLAGS(cv) & (CVf_SLABBED|CVf_WEAKOUTSIDE); |
7518
|
80798
|
|
|
|
|
OP * const cvstart = CvSTART(cv); |
7519
|
|
|
|
|
|
|
7520
|
80798
|
|
|
|
|
CvGV_set(cv,gv); |
7521
|
|
|
|
|
|
assert(!CvCVGV_RC(cv)); |
7522
|
|
|
|
|
|
assert(CvGV(cv) == gv); |
7523
|
|
|
|
|
|
|
7524
|
80798
|
|
|
|
|
SvPOK_off(cv); |
7525
|
80798
|
|
|
|
|
CvFLAGS(cv) = CvFLAGS(PL_compcv) | existing_builtin_attrs; |
7526
|
80798
|
|
|
|
|
CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv); |
7527
|
80798
|
|
|
|
|
CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(PL_compcv); |
7528
|
80798
|
|
|
|
|
CvPADLIST(cv) = CvPADLIST(PL_compcv); |
7529
|
80798
|
|
|
|
|
CvOUTSIDE(PL_compcv) = temp_cv; |
7530
|
80798
|
|
|
|
|
CvPADLIST(PL_compcv) = temp_av; |
7531
|
80798
|
|
|
|
|
CvSTART(cv) = CvSTART(PL_compcv); |
7532
|
80798
|
|
|
|
|
CvSTART(PL_compcv) = cvstart; |
7533
|
80798
|
|
|
|
|
CvFLAGS(PL_compcv) &= ~(CVf_SLABBED|CVf_WEAKOUTSIDE); |
7534
|
80798
|
|
|
|
|
CvFLAGS(PL_compcv) |= other_flags; |
7535
|
|
|
|
|
|
|
7536
|
80798
|
100
|
|
|
|
if (CvFILE(cv) && CvDYNFILE(cv)) { |
|
|
50
|
|
|
|
|
7537
|
0
|
|
|
|
|
Safefree(CvFILE(cv)); |
7538
|
|
|
|
|
|
} |
7539
|
80798
|
50
|
|
|
|
CvFILE_set_from_cop(cv, PL_curcop); |
7540
|
80798
|
|
|
|
|
CvSTASH_set(cv, PL_curstash); |
7541
|
|
|
|
|
|
|
7542
|
|
|
|
|
|
/* inner references to PL_compcv must be fixed up ... */ |
7543
|
80798
|
|
|
|
|
pad_fixup_inner_anons(CvPADLIST(cv), PL_compcv, cv); |
7544
|
80798
|
100
|
|
|
|
if (PERLDB_INTER)/* Advice debugger on the new sub. */ |
|
|
100
|
|
|
|
|
7545
|
102
|
|
|
|
|
++PL_sub_generation; |
7546
|
|
|
|
|
|
} |
7547
|
|
|
|
|
|
else { |
7548
|
|
|
|
|
|
/* Might have had built-in attributes applied -- propagate them. */ |
7549
|
16
|
|
|
|
|
CvFLAGS(cv) |= (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS); |
7550
|
|
|
|
|
|
} |
7551
|
|
|
|
|
|
/* ... before we throw it away */ |
7552
|
80814
|
|
|
|
|
SvREFCNT_dec(PL_compcv); |
7553
|
80814
|
|
|
|
|
PL_compcv = cv; |
7554
|
|
|
|
|
|
} |
7555
|
|
|
|
|
|
else { |
7556
|
12385849
|
|
|
|
|
cv = PL_compcv; |
7557
|
12385849
|
100
|
|
|
|
if (name) { |
7558
|
11883081
|
|
|
|
|
GvCV_set(gv, cv); |
7559
|
11883081
|
|
|
|
|
GvCVGEN(gv) = 0; |
7560
|
11883081
|
50
|
|
|
|
if (HvENAME_HEK(GvSTASH(gv))) |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
7561
|
|
|
|
|
|
/* sub Foo::bar { (shift)+1 } */ |
7562
|
11883079
|
100
|
|
|
|
gv_method_changed(gv); |
7563
|
|
|
|
|
|
} |
7564
|
|
|
|
|
|
} |
7565
|
12466663
|
100
|
|
|
|
if (!CvGV(cv)) { |
7566
|
12385123
|
|
|
|
|
CvGV_set(cv, gv); |
7567
|
12385123
|
50
|
|
|
|
CvFILE_set_from_cop(cv, PL_curcop); |
7568
|
12385123
|
|
|
|
|
CvSTASH_set(cv, PL_curstash); |
7569
|
|
|
|
|
|
} |
7570
|
|
|
|
|
|
|
7571
|
12466663
|
100
|
|
|
|
if (ps) { |
7572
|
192642
|
|
|
|
|
sv_setpvn(MUTABLE_SV(cv), ps, ps_len); |
7573
|
192642
|
100
|
|
|
|
if ( ps_utf8 ) SvUTF8_on(MUTABLE_SV(cv)); |
7574
|
|
|
|
|
|
} |
7575
|
|
|
|
|
|
|
7576
|
|
|
|
|
|
install_block: |
7577
|
12466663
|
100
|
|
|
|
if (!block) |
7578
|
|
|
|
|
|
goto attrs; |
7579
|
|
|
|
|
|
|
7580
|
|
|
|
|
|
/* If we assign an optree to a PVCV, then we've defined a subroutine that |
7581
|
|
|
|
|
|
the debugger could be able to set a breakpoint in, so signal to |
7582
|
|
|
|
|
|
pp_entereval that it should not throw away any saved lines at scope |
7583
|
|
|
|
|
|
exit. */ |
7584
|
|
|
|
|
|
|
7585
|
12466107
|
|
|
|
|
PL_breakable_sub_gen++; |
7586
|
|
|
|
|
|
/* This makes sub {}; work as expected. */ |
7587
|
12466107
|
100
|
|
|
|
if (block->op_type == OP_STUB) { |
7588
|
112330
|
|
|
|
|
OP* const newblock = newSTATEOP(0, NULL, 0); |
7589
|
|
|
|
|
|
#ifdef PERL_MAD |
7590
|
|
|
|
|
|
op_getmad(block,newblock,'B'); |
7591
|
|
|
|
|
|
#else |
7592
|
112330
|
|
|
|
|
op_free(block); |
7593
|
|
|
|
|
|
#endif |
7594
|
|
|
|
|
|
block = newblock; |
7595
|
|
|
|
|
|
} |
7596
|
24932214
|
|
|
|
|
CvROOT(cv) = CvLVALUE(cv) |
7597
|
6490
|
|
|
|
|
? newUNOP(OP_LEAVESUBLV, 0, |
7598
|
|
|
|
|
|
op_lvalue(scalarseq(block), OP_LEAVESUBLV)) |
7599
|
12472597
|
100
|
|
|
|
: newUNOP(OP_LEAVESUB, 0, scalarseq(block)); |
7600
|
12466107
|
|
|
|
|
CvROOT(cv)->op_private |= OPpREFCOUNTED; |
7601
|
12466107
|
|
|
|
|
OpREFCNT_set(CvROOT(cv), 1); |
7602
|
|
|
|
|
|
/* The cv no longer needs to hold a refcount on the slab, as CvROOT |
7603
|
|
|
|
|
|
itself has a refcount. */ |
7604
|
12466107
|
|
|
|
|
CvSLABBED_off(cv); |
7605
|
12466107
|
50
|
|
|
|
OpslabREFCNT_dec_padok((OPSLAB *)CvSTART(cv)); |
7606
|
|
|
|
|
|
#ifdef PERL_DEBUG_READONLY_OPS |
7607
|
|
|
|
|
|
slab = (OPSLAB *)CvSTART(cv); |
7608
|
|
|
|
|
|
#endif |
7609
|
12466107
|
50
|
|
|
|
CvSTART(cv) = LINKLIST(CvROOT(cv)); |
7610
|
12466107
|
|
|
|
|
CvROOT(cv)->op_next = 0; |
7611
|
12466107
|
|
|
|
|
CALL_PEEP(CvSTART(cv)); |
7612
|
12466107
|
|
|
|
|
finalize_optree(CvROOT(cv)); |
7613
|
|
|
|
|
|
|
7614
|
|
|
|
|
|
/* now that optimizer has done its work, adjust pad values */ |
7615
|
|
|
|
|
|
|
7616
|
12466107
|
|
|
|
|
pad_tidy(CvCLONE(cv) ? padtidy_SUBCLONE : padtidy_SUB); |
7617
|
|
|
|
|
|
|
7618
|
|
|
|
|
|
attrs: |
7619
|
12466665
|
100
|
|
|
|
if (attrs) { |
7620
|
|
|
|
|
|
/* Need to do a C |
7621
|
324
|
100
|
|
|
|
HV *stash = name && GvSTASH(CvGV(cv)) ? GvSTASH(CvGV(cv)) : PL_curstash; |
|
|
50
|
|
|
|
|
7622
|
112
|
100
|
|
|
|
if (!name) SAVEFREESV(cv); |
7623
|
112
|
|
|
|
|
apply_attrs(stash, MUTABLE_SV(cv), attrs); |
7624
|
104
|
100
|
|
|
|
if (!name) SvREFCNT_inc_simple_void_NN(cv); |
7625
|
|
|
|
|
|
} |
7626
|
|
|
|
|
|
|
7627
|
12466657
|
100
|
|
|
|
if (block && has_name) { |
|
|
100
|
|
|
|
|
7628
|
11966261
|
100
|
|
|
|
if (PERLDB_SUBLINE && PL_curstash != PL_debstash) { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
7629
|
43104
|
|
|
|
|
SV * const tmpstr = sv_newmortal(); |
7630
|
43104
|
|
|
|
|
GV * const db_postponed = gv_fetchpvs("DB::postponed", |
7631
|
|
|
|
|
|
GV_ADDMULTI, SVt_PVHV); |
7632
|
|
|
|
|
|
HV *hv; |
7633
|
86208
|
50
|
|
|
|
SV * const sv = Perl_newSVpvf(aTHX_ "%s:%ld-%ld", |
7634
|
86208
|
|
|
|
|
CopFILE(PL_curcop), |
7635
|
|
|
|
|
|
(long)PL_subline, |
7636
|
43104
|
|
|
|
|
(long)CopLINE(PL_curcop)); |
7637
|
43104
|
|
|
|
|
gv_efullname3(tmpstr, gv, NULL); |
7638
|
43104
|
50
|
|
|
|
(void)hv_store(GvHV(PL_DBsub), SvPVX_const(tmpstr), |
7639
|
|
|
|
|
|
SvUTF8(tmpstr) ? -(I32)SvCUR(tmpstr) : (I32)SvCUR(tmpstr), sv, 0); |
7640
|
43104
|
50
|
|
|
|
hv = GvHVn(db_postponed); |
7641
|
43104
|
50
|
|
|
|
if (HvTOTALKEYS(hv) > 0 && hv_exists(hv, SvPVX_const(tmpstr), SvUTF8(tmpstr) ? -(I32)SvCUR(tmpstr) : (I32)SvCUR(tmpstr))) { |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
7642
|
0
|
|
|
|
|
CV * const pcv = GvCV(db_postponed); |
7643
|
0
|
0
|
|
|
|
if (pcv) { |
7644
|
0
|
|
|
|
|
dSP; |
7645
|
0
|
0
|
|
|
|
PUSHMARK(SP); |
7646
|
0
|
0
|
|
|
|
XPUSHs(tmpstr); |
7647
|
0
|
|
|
|
|
PUTBACK; |
7648
|
0
|
|
|
|
|
call_sv(MUTABLE_SV(pcv), G_DISCARD); |
7649
|
|
|
|
|
|
} |
7650
|
|
|
|
|
|
} |
7651
|
|
|
|
|
|
} |
7652
|
|
|
|
|
|
|
7653
|
11966261
|
100
|
|
|
|
if (name && ! (PL_parser && PL_parser->error_count)) |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
7654
|
11963331
|
|
|
|
|
process_special_blocks(floor, name, gv, cv); |
7655
|
|
|
|
|
|
} |
7656
|
|
|
|
|
|
|
7657
|
|
|
|
|
|
done: |
7658
|
12973500
|
50
|
|
|
|
if (PL_parser) |
7659
|
12973500
|
|
|
|
|
PL_parser->copline = NOLINE; |
7660
|
12973500
|
100
|
|
|
|
LEAVE_SCOPE(floor); |
7661
|
|
|
|
|
|
#ifdef PERL_DEBUG_READONLY_OPS |
7662
|
|
|
|
|
|
/* Watch out for BEGIN blocks */ |
7663
|
|
|
|
|
|
if (slab && gv && isGV(gv) && GvCV(gv)) Slab_to_ro(slab); |
7664
|
|
|
|
|
|
#endif |
7665
|
12973500
|
|
|
|
|
return cv; |
7666
|
|
|
|
|
|
} |
7667
|
|
|
|
|
|
|
7668
|
|
|
|
|
|
STATIC void |
7669
|
20107765
|
|
|
|
|
S_process_special_blocks(pTHX_ I32 floor, const char *const fullname, |
7670
|
|
|
|
|
|
GV *const gv, |
7671
|
|
|
|
|
|
CV *const cv) |
7672
|
|
|
|
|
|
{ |
7673
|
20107765
|
|
|
|
|
const char *const colon = strrchr(fullname,':'); |
7674
|
20107765
|
100
|
|
|
|
const char *const name = colon ? colon + 1 : fullname; |
7675
|
|
|
|
|
|
|
7676
|
|
|
|
|
|
PERL_ARGS_ASSERT_PROCESS_SPECIAL_BLOCKS; |
7677
|
|
|
|
|
|
|
7678
|
20107765
|
100
|
|
|
|
if (*name == 'B') { |
7679
|
4732925
|
100
|
|
|
|
if (strEQ(name, "BEGIN")) { |
7680
|
4652858
|
|
|
|
|
const I32 oldscope = PL_scopestack_ix; |
7681
|
4652858
|
100
|
|
|
|
if (floor) LEAVE_SCOPE(floor); |
|
|
50
|
|
|
|
|
7682
|
4652858
|
|
|
|
|
ENTER; |
7683
|
4652858
|
|
|
|
|
SAVECOPFILE(&PL_compiling); |
7684
|
4652858
|
|
|
|
|
SAVECOPLINE(&PL_compiling); |
7685
|
4652858
|
|
|
|
|
SAVEVPTR(PL_curcop); |
7686
|
|
|
|
|
|
|
7687
|
|
|
|
|
|
DEBUG_x( dump_sub(gv) ); |
7688
|
4652858
|
|
|
|
|
Perl_av_create_and_push(aTHX_ &PL_beginav, MUTABLE_SV(cv)); |
7689
|
4652858
|
|
|
|
|
GvCV_set(gv,0); /* cv has been hijacked */ |
7690
|
4652858
|
|
|
|
|
call_list(oldscope, PL_beginav); |
7691
|
|
|
|
|
|
|
7692
|
4627254
|
|
|
|
|
LEAVE; |
7693
|
|
|
|
|
|
} |
7694
|
|
|
|
|
|
else |
7695
|
|
|
|
|
|
return; |
7696
|
|
|
|
|
|
} else { |
7697
|
15374840
|
100
|
|
|
|
if (*name == 'E') { |
7698
|
743209
|
50
|
|
|
|
if strEQ(name, "END") { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
7699
|
|
|
|
|
|
DEBUG_x( dump_sub(gv) ); |
7700
|
13442
|
|
|
|
|
Perl_av_create_and_unshift_one(aTHX_ &PL_endav, MUTABLE_SV(cv)); |
7701
|
|
|
|
|
|
} else |
7702
|
|
|
|
|
|
return; |
7703
|
14631631
|
100
|
|
|
|
} else if (*name == 'U') { |
7704
|
26452
|
100
|
|
|
|
if (strEQ(name, "UNITCHECK")) { |
7705
|
|
|
|
|
|
/* It's never too late to run a unitcheck block */ |
7706
|
390
|
|
|
|
|
Perl_av_create_and_unshift_one(aTHX_ &PL_unitcheckav, MUTABLE_SV(cv)); |
7707
|
|
|
|
|
|
} |
7708
|
|
|
|
|
|
else |
7709
|
|
|
|
|
|
return; |
7710
|
14605179
|
100
|
|
|
|
} else if (*name == 'C') { |
7711
|
364054
|
100
|
|
|
|
if (strEQ(name, "CHECK")) { |
7712
|
9874
|
100
|
|
|
|
if (PL_main_start) |
7713
|
|
|
|
|
|
/* diag_listed_as: Too late to run %s block */ |
7714
|
120
|
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_VOID), |
7715
|
|
|
|
|
|
"Too late to run CHECK block"); |
7716
|
9874
|
|
|
|
|
Perl_av_create_and_unshift_one(aTHX_ &PL_checkav, MUTABLE_SV(cv)); |
7717
|
|
|
|
|
|
} |
7718
|
|
|
|
|
|
else |
7719
|
|
|
|
|
|
return; |
7720
|
14241125
|
100
|
|
|
|
} else if (*name == 'I') { |
7721
|
184890
|
100
|
|
|
|
if (strEQ(name, "INIT")) { |
7722
|
5088
|
100
|
|
|
|
if (PL_main_start) |
7723
|
|
|
|
|
|
/* diag_listed_as: Too late to run %s block */ |
7724
|
120
|
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_VOID), |
7725
|
|
|
|
|
|
"Too late to run INIT block"); |
7726
|
5088
|
|
|
|
|
Perl_av_create_and_push(aTHX_ &PL_initav, MUTABLE_SV(cv)); |
7727
|
|
|
|
|
|
} |
7728
|
|
|
|
|
|
else |
7729
|
|
|
|
|
|
return; |
7730
|
|
|
|
|
|
} else |
7731
|
|
|
|
|
|
return; |
7732
|
|
|
|
|
|
DEBUG_x( dump_sub(gv) ); |
7733
|
10331016
|
|
|
|
|
GvCV_set(gv,0); /* cv has been hijacked */ |
7734
|
|
|
|
|
|
} |
7735
|
|
|
|
|
|
} |
7736
|
|
|
|
|
|
|
7737
|
|
|
|
|
|
/* |
7738
|
|
|
|
|
|
=for apidoc newCONSTSUB |
7739
|
|
|
|
|
|
|
7740
|
|
|
|
|
|
See L. |
7741
|
|
|
|
|
|
|
7742
|
|
|
|
|
|
=cut |
7743
|
|
|
|
|
|
*/ |
7744
|
|
|
|
|
|
|
7745
|
|
|
|
|
|
CV * |
7746
|
108073
|
|
|
|
|
Perl_newCONSTSUB(pTHX_ HV *stash, const char *name, SV *sv) |
7747
|
|
|
|
|
|
{ |
7748
|
108073
|
100
|
|
|
|
return newCONSTSUB_flags(stash, name, name ? strlen(name) : 0, 0, sv); |
7749
|
|
|
|
|
|
} |
7750
|
|
|
|
|
|
|
7751
|
|
|
|
|
|
/* |
7752
|
|
|
|
|
|
=for apidoc newCONSTSUB_flags |
7753
|
|
|
|
|
|
|
7754
|
|
|
|
|
|
Creates a constant sub equivalent to Perl C which is |
7755
|
|
|
|
|
|
eligible for inlining at compile-time. |
7756
|
|
|
|
|
|
|
7757
|
|
|
|
|
|
Currently, the only useful value for C is SVf_UTF8. |
7758
|
|
|
|
|
|
|
7759
|
|
|
|
|
|
The newly created subroutine takes ownership of a reference to the passed in |
7760
|
|
|
|
|
|
SV. |
7761
|
|
|
|
|
|
|
7762
|
|
|
|
|
|
Passing NULL for SV creates a constant sub equivalent to C, |
7763
|
|
|
|
|
|
which won't be called if used as a destructor, but will suppress the overhead |
7764
|
|
|
|
|
|
of a call to C. (This form, however, isn't eligible for inlining at |
7765
|
|
|
|
|
|
compile time.) |
7766
|
|
|
|
|
|
|
7767
|
|
|
|
|
|
=cut |
7768
|
|
|
|
|
|
*/ |
7769
|
|
|
|
|
|
|
7770
|
|
|
|
|
|
CV * |
7771
|
5053757
|
|
|
|
|
Perl_newCONSTSUB_flags(pTHX_ HV *stash, const char *name, STRLEN len, |
7772
|
|
|
|
|
|
U32 flags, SV *sv) |
7773
|
|
|
|
|
|
{ |
7774
|
|
|
|
|
|
dVAR; |
7775
|
|
|
|
|
|
CV* cv; |
7776
|
5053757
|
50
|
|
|
|
const char *const file = CopFILE(PL_curcop); |
7777
|
|
|
|
|
|
|
7778
|
5053757
|
|
|
|
|
ENTER; |
7779
|
|
|
|
|
|
|
7780
|
5053757
|
100
|
|
|
|
if (IN_PERL_RUNTIME) { |
7781
|
|
|
|
|
|
/* at runtime, it's not safe to manipulate PL_curcop: it may be |
7782
|
|
|
|
|
|
* an op shared between threads. Use a non-shared COP for our |
7783
|
|
|
|
|
|
* dirty work */ |
7784
|
3478299
|
|
|
|
|
SAVEVPTR(PL_curcop); |
7785
|
3478299
|
|
|
|
|
SAVECOMPILEWARNINGS(); |
7786
|
5216550
|
100
|
|
|
|
PL_compiling.cop_warnings = DUP_WARNINGS(PL_curcop->cop_warnings); |
|
|
100
|
|
|
|
|
7787
|
3478299
|
|
|
|
|
PL_curcop = &PL_compiling; |
7788
|
|
|
|
|
|
} |
7789
|
5053757
|
|
|
|
|
SAVECOPLINE(PL_curcop); |
7790
|
5053757
|
100
|
|
|
|
CopLINE_set(PL_curcop, PL_parser ? PL_parser->copline : NOLINE); |
7791
|
|
|
|
|
|
|
7792
|
5053757
|
|
|
|
|
SAVEHINTS(); |
7793
|
5053757
|
|
|
|
|
PL_hints &= ~HINT_BLOCK_SCOPE; |
7794
|
|
|
|
|
|
|
7795
|
5053757
|
100
|
|
|
|
if (stash) { |
7796
|
4865253
|
|
|
|
|
SAVEGENERICSV(PL_curstash); |
7797
|
4865253
|
|
|
|
|
PL_curstash = (HV *)SvREFCNT_inc_simple_NN(stash); |
7798
|
|
|
|
|
|
} |
7799
|
|
|
|
|
|
|
7800
|
|
|
|
|
|
/* Protect sv against leakage caused by fatal warnings. */ |
7801
|
5053757
|
100
|
|
|
|
if (sv) SAVEFREESV(sv); |
7802
|
|
|
|
|
|
|
7803
|
|
|
|
|
|
/* file becomes the CvFILE. For an XS, it's usually static storage, |
7804
|
|
|
|
|
|
and so doesn't get free()d. (It's expected to be from the C pre- |
7805
|
|
|
|
|
|
processor __FILE__ directive). But we need a dynamically allocated one, |
7806
|
|
|
|
|
|
and we need it to get freed. */ |
7807
|
5053757
|
50
|
|
|
|
cv = newXS_len_flags(name, len, |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
7808
|
|
|
|
|
|
sv && SvTYPE(sv) == SVt_PVAV |
7809
|
|
|
|
|
|
? const_av_xsub |
7810
|
|
|
|
|
|
: const_sv_xsub, |
7811
|
|
|
|
|
|
file ? file : "", "", |
7812
|
|
|
|
|
|
&sv, XS_DYNAMIC_FILENAME | flags); |
7813
|
10107510
|
|
|
|
|
CvXSUBANY(cv).any_ptr = SvREFCNT_inc_simple(sv); |
7814
|
5053755
|
|
|
|
|
CvCONST_on(cv); |
7815
|
|
|
|
|
|
|
7816
|
5053755
|
|
|
|
|
LEAVE; |
7817
|
|
|
|
|
|
|
7818
|
5053755
|
|
|
|
|
return cv; |
7819
|
|
|
|
|
|
} |
7820
|
|
|
|
|
|
|
7821
|
|
|
|
|
|
CV * |
7822
|
1455047
|
|
|
|
|
Perl_newXS_flags(pTHX_ const char *name, XSUBADDR_t subaddr, |
7823
|
|
|
|
|
|
const char *const filename, const char *const proto, |
7824
|
|
|
|
|
|
U32 flags) |
7825
|
|
|
|
|
|
{ |
7826
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWXS_FLAGS; |
7827
|
1455047
|
50
|
|
|
|
return newXS_len_flags( |
7828
|
|
|
|
|
|
name, name ? strlen(name) : 0, subaddr, filename, proto, NULL, flags |
7829
|
|
|
|
|
|
); |
7830
|
|
|
|
|
|
} |
7831
|
|
|
|
|
|
|
7832
|
|
|
|
|
|
CV * |
7833
|
8217522
|
|
|
|
|
Perl_newXS_len_flags(pTHX_ const char *name, STRLEN len, |
7834
|
|
|
|
|
|
XSUBADDR_t subaddr, const char *const filename, |
7835
|
|
|
|
|
|
const char *const proto, SV **const_svp, |
7836
|
|
|
|
|
|
U32 flags) |
7837
|
|
|
|
|
|
{ |
7838
|
|
|
|
|
|
CV *cv; |
7839
|
|
|
|
|
|
|
7840
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWXS_LEN_FLAGS; |
7841
|
|
|
|
|
|
|
7842
|
|
|
|
|
|
{ |
7843
|
8217522
|
100
|
|
|
|
GV * const gv = gv_fetchpvn( |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
7844
|
|
|
|
|
|
name ? name : PL_curstash ? "__ANON__" : "__ANON__::__ANON__", |
7845
|
|
|
|
|
|
name ? len : PL_curstash ? sizeof("__ANON__") - 1: |
7846
|
|
|
|
|
|
sizeof("__ANON__::__ANON__") - 1, |
7847
|
|
|
|
|
|
GV_ADDMULTI | flags, SVt_PVCV); |
7848
|
|
|
|
|
|
|
7849
|
8217522
|
50
|
|
|
|
if (!subaddr) |
7850
|
0
|
|
|
|
|
Perl_croak(aTHX_ "panic: no address for '%s' in '%s'", name, filename); |
7851
|
|
|
|
|
|
|
7852
|
8217522
|
100
|
|
|
|
if ((cv = (name ? GvCV(gv) : NULL))) { |
|
|
100
|
|
|
|
|
7853
|
6698
|
100
|
|
|
|
if (GvCVGEN(gv)) { |
7854
|
|
|
|
|
|
/* just a cached method */ |
7855
|
6188
|
|
|
|
|
SvREFCNT_dec(cv); |
7856
|
|
|
|
|
|
cv = NULL; |
7857
|
|
|
|
|
|
} |
7858
|
510
|
100
|
|
|
|
else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) { |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
7859
|
|
|
|
|
|
/* already defined (or promised) */ |
7860
|
|
|
|
|
|
/* Redundant check that allows us to avoid creating an SV |
7861
|
|
|
|
|
|
most of the time: */ |
7862
|
84
|
100
|
|
|
|
if (CvCONST(cv) || ckWARN(WARN_REDEFINE)) { |
|
|
100
|
|
|
|
|
7863
|
34
|
|
|
|
|
report_redefined_cv(newSVpvn_flags( |
7864
|
|
|
|
|
|
name,len,(flags&SVf_UTF8)|SVs_TEMP |
7865
|
|
|
|
|
|
), |
7866
|
|
|
|
|
|
cv, const_svp); |
7867
|
|
|
|
|
|
} |
7868
|
82
|
|
|
|
|
SvREFCNT_dec_NN(cv); |
7869
|
|
|
|
|
|
cv = NULL; |
7870
|
|
|
|
|
|
} |
7871
|
|
|
|
|
|
} |
7872
|
|
|
|
|
|
|
7873
|
8217520
|
100
|
|
|
|
if (cv) /* must reuse cv if autoloaded */ |
7874
|
426
|
|
|
|
|
cv_undef(cv); |
7875
|
|
|
|
|
|
else { |
7876
|
8217094
|
|
|
|
|
cv = MUTABLE_CV(newSV_type(SVt_PVCV)); |
7877
|
8217094
|
100
|
|
|
|
if (name) { |
7878
|
8144008
|
|
|
|
|
GvCV_set(gv,cv); |
7879
|
8144008
|
|
|
|
|
GvCVGEN(gv) = 0; |
7880
|
8144008
|
50
|
|
|
|
if (HvENAME_HEK(GvSTASH(gv))) |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
7881
|
8144008
|
100
|
|
|
|
gv_method_changed(gv); /* newXS */ |
7882
|
|
|
|
|
|
} |
7883
|
|
|
|
|
|
} |
7884
|
8217520
|
100
|
|
|
|
if (!name) |
7885
|
73086
|
|
|
|
|
CvANON_on(cv); |
7886
|
8217520
|
|
|
|
|
CvGV_set(cv, gv); |
7887
|
8217520
|
|
|
|
|
(void)gv_fetchfile(filename); |
7888
|
8217520
|
|
|
|
|
CvFILE(cv) = (char *)filename; /* NOTE: not copied, as it is expected to be |
7889
|
|
|
|
|
|
an external constant string */ |
7890
|
|
|
|
|
|
assert(!CvDYNFILE(cv)); /* cv_undef should have turned it off */ |
7891
|
8217520
|
|
|
|
|
CvISXSUB_on(cv); |
7892
|
8217520
|
|
|
|
|
CvXSUB(cv) = subaddr; |
7893
|
|
|
|
|
|
|
7894
|
8217520
|
100
|
|
|
|
if (name) |
7895
|
8144434
|
|
|
|
|
process_special_blocks(0, name, gv, cv); |
7896
|
|
|
|
|
|
} |
7897
|
|
|
|
|
|
|
7898
|
8217520
|
100
|
|
|
|
if (flags & XS_DYNAMIC_FILENAME) { |
7899
|
5116809
|
|
|
|
|
CvFILE(cv) = savepv(filename); |
7900
|
5116809
|
|
|
|
|
CvDYNFILE_on(cv); |
7901
|
|
|
|
|
|
} |
7902
|
8217520
|
|
|
|
|
sv_setpv(MUTABLE_SV(cv), proto); |
7903
|
8217520
|
|
|
|
|
return cv; |
7904
|
|
|
|
|
|
} |
7905
|
|
|
|
|
|
|
7906
|
|
|
|
|
|
CV * |
7907
|
525108
|
|
|
|
|
Perl_newSTUB(pTHX_ GV *gv, bool fake) |
7908
|
|
|
|
|
|
{ |
7909
|
525108
|
|
|
|
|
CV *cv = MUTABLE_CV(newSV_type(SVt_PVCV)); |
7910
|
|
|
|
|
|
GV *cvgv; |
7911
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWSTUB; |
7912
|
|
|
|
|
|
assert(!GvCVu(gv)); |
7913
|
525108
|
|
|
|
|
GvCV_set(gv, cv); |
7914
|
525108
|
|
|
|
|
GvCVGEN(gv) = 0; |
7915
|
525108
|
100
|
|
|
|
if (!fake && HvENAME_HEK(GvSTASH(gv))) |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
7916
|
38068
|
100
|
|
|
|
gv_method_changed(gv); |
7917
|
525108
|
100
|
|
|
|
if (SvFAKE(gv)) { |
7918
|
4
|
|
|
|
|
cvgv = gv_fetchsv((SV *)gv, GV_ADDMULTI, SVt_PVCV); |
7919
|
4
|
|
|
|
|
SvFAKE_off(cvgv); |
7920
|
|
|
|
|
|
} |
7921
|
|
|
|
|
|
else cvgv = gv; |
7922
|
525108
|
|
|
|
|
CvGV_set(cv, cvgv); |
7923
|
525108
|
50
|
|
|
|
CvFILE_set_from_cop(cv, PL_curcop); |
7924
|
525108
|
|
|
|
|
CvSTASH_set(cv, PL_curstash); |
7925
|
525108
|
|
|
|
|
GvMULTI_on(gv); |
7926
|
525108
|
|
|
|
|
return cv; |
7927
|
|
|
|
|
|
} |
7928
|
|
|
|
|
|
|
7929
|
|
|
|
|
|
/* |
7930
|
|
|
|
|
|
=for apidoc U||newXS |
7931
|
|
|
|
|
|
|
7932
|
|
|
|
|
|
Used by C to hook up XSUBs as Perl subs. I needs to be |
7933
|
|
|
|
|
|
static storage, as it is used directly as CvFILE(), without a copy being made. |
7934
|
|
|
|
|
|
|
7935
|
|
|
|
|
|
=cut |
7936
|
|
|
|
|
|
*/ |
7937
|
|
|
|
|
|
|
7938
|
|
|
|
|
|
CV * |
7939
|
1708718
|
|
|
|
|
Perl_newXS(pTHX_ const char *name, XSUBADDR_t subaddr, const char *filename) |
7940
|
|
|
|
|
|
{ |
7941
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWXS; |
7942
|
1708718
|
50
|
|
|
|
return newXS_len_flags( |
7943
|
|
|
|
|
|
name, name ? strlen(name) : 0, subaddr, filename, NULL, NULL, 0 |
7944
|
|
|
|
|
|
); |
7945
|
|
|
|
|
|
} |
7946
|
|
|
|
|
|
|
7947
|
|
|
|
|
|
#ifdef PERL_MAD |
7948
|
|
|
|
|
|
OP * |
7949
|
|
|
|
|
|
#else |
7950
|
|
|
|
|
|
void |
7951
|
|
|
|
|
|
#endif |
7952
|
282
|
|
|
|
|
Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block) |
7953
|
|
|
|
|
|
{ |
7954
|
|
|
|
|
|
dVAR; |
7955
|
|
|
|
|
|
CV *cv; |
7956
|
|
|
|
|
|
#ifdef PERL_MAD |
7957
|
|
|
|
|
|
OP* pegop = newOP(OP_NULL, 0); |
7958
|
|
|
|
|
|
#endif |
7959
|
|
|
|
|
|
|
7960
|
|
|
|
|
|
GV *gv; |
7961
|
|
|
|
|
|
|
7962
|
282
|
50
|
|
|
|
if (PL_parser && PL_parser->error_count) { |
|
|
100
|
|
|
|
|
7963
|
8
|
|
|
|
|
op_free(block); |
7964
|
8
|
|
|
|
|
goto finish; |
7965
|
|
|
|
|
|
} |
7966
|
|
|
|
|
|
|
7967
|
|
|
|
|
|
gv = o |
7968
|
248
|
|
|
|
|
? gv_fetchsv(cSVOPo->op_sv, GV_ADD, SVt_PVFM) |
7969
|
398
|
100
|
|
|
|
: gv_fetchpvs("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVFM); |
7970
|
|
|
|
|
|
|
7971
|
274
|
|
|
|
|
GvMULTI_on(gv); |
7972
|
274
|
100
|
|
|
|
if ((cv = GvFORM(gv))) { |
7973
|
14
|
100
|
|
|
|
if (ckWARN(WARN_REDEFINE)) { |
7974
|
4
|
|
|
|
|
const line_t oldline = CopLINE(PL_curcop); |
7975
|
4
|
50
|
|
|
|
if (PL_parser && PL_parser->copline != NOLINE) |
|
|
50
|
|
|
|
|
7976
|
4
|
|
|
|
|
CopLINE_set(PL_curcop, PL_parser->copline); |
7977
|
4
|
100
|
|
|
|
if (o) { |
7978
|
2
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_REDEFINE), |
7979
|
2
|
|
|
|
|
"Format %"SVf" redefined", SVfARG(cSVOPo->op_sv)); |
7980
|
|
|
|
|
|
} else { |
7981
|
|
|
|
|
|
/* diag_listed_as: Format %s redefined */ |
7982
|
2
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_REDEFINE), |
7983
|
|
|
|
|
|
"Format STDOUT redefined"); |
7984
|
|
|
|
|
|
} |
7985
|
4
|
|
|
|
|
CopLINE_set(PL_curcop, oldline); |
7986
|
|
|
|
|
|
} |
7987
|
14
|
|
|
|
|
SvREFCNT_dec(cv); |
7988
|
|
|
|
|
|
} |
7989
|
274
|
|
|
|
|
cv = PL_compcv; |
7990
|
274
|
|
|
|
|
GvFORM(gv) = (CV *)SvREFCNT_inc_simple_NN(cv); |
7991
|
274
|
|
|
|
|
CvGV_set(cv, gv); |
7992
|
274
|
50
|
|
|
|
CvFILE_set_from_cop(cv, PL_curcop); |
7993
|
|
|
|
|
|
|
7994
|
|
|
|
|
|
|
7995
|
274
|
|
|
|
|
pad_tidy(padtidy_FORMAT); |
7996
|
274
|
|
|
|
|
CvROOT(cv) = newUNOP(OP_LEAVEWRITE, 0, scalarseq(block)); |
7997
|
274
|
|
|
|
|
CvROOT(cv)->op_private |= OPpREFCOUNTED; |
7998
|
274
|
|
|
|
|
OpREFCNT_set(CvROOT(cv), 1); |
7999
|
274
|
50
|
|
|
|
CvSTART(cv) = LINKLIST(CvROOT(cv)); |
8000
|
274
|
|
|
|
|
CvROOT(cv)->op_next = 0; |
8001
|
274
|
|
|
|
|
CALL_PEEP(CvSTART(cv)); |
8002
|
274
|
|
|
|
|
finalize_optree(CvROOT(cv)); |
8003
|
274
|
|
|
|
|
cv_forget_slab(cv); |
8004
|
|
|
|
|
|
|
8005
|
|
|
|
|
|
finish: |
8006
|
|
|
|
|
|
#ifdef PERL_MAD |
8007
|
|
|
|
|
|
op_getmad(o,pegop,'n'); |
8008
|
|
|
|
|
|
op_getmad_weak(block, pegop, 'b'); |
8009
|
|
|
|
|
|
#else |
8010
|
282
|
|
|
|
|
op_free(o); |
8011
|
|
|
|
|
|
#endif |
8012
|
282
|
50
|
|
|
|
if (PL_parser) |
8013
|
282
|
|
|
|
|
PL_parser->copline = NOLINE; |
8014
|
282
|
50
|
|
|
|
LEAVE_SCOPE(floor); |
8015
|
|
|
|
|
|
#ifdef PERL_MAD |
8016
|
|
|
|
|
|
return pegop; |
8017
|
|
|
|
|
|
#endif |
8018
|
282
|
|
|
|
|
} |
8019
|
|
|
|
|
|
|
8020
|
|
|
|
|
|
OP * |
8021
|
1144472
|
|
|
|
|
Perl_newANONLIST(pTHX_ OP *o) |
8022
|
|
|
|
|
|
{ |
8023
|
1144472
|
|
|
|
|
return convert(OP_ANONLIST, OPf_SPECIAL, o); |
8024
|
|
|
|
|
|
} |
8025
|
|
|
|
|
|
|
8026
|
|
|
|
|
|
OP * |
8027
|
833921
|
|
|
|
|
Perl_newANONHASH(pTHX_ OP *o) |
8028
|
|
|
|
|
|
{ |
8029
|
833921
|
|
|
|
|
return convert(OP_ANONHASH, OPf_SPECIAL, o); |
8030
|
|
|
|
|
|
} |
8031
|
|
|
|
|
|
|
8032
|
|
|
|
|
|
OP * |
8033
|
0
|
|
|
|
|
Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block) |
8034
|
|
|
|
|
|
{ |
8035
|
0
|
|
|
|
|
return newANONATTRSUB(floor, proto, NULL, block); |
8036
|
|
|
|
|
|
} |
8037
|
|
|
|
|
|
|
8038
|
|
|
|
|
|
OP * |
8039
|
551114
|
|
|
|
|
Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block) |
8040
|
|
|
|
|
|
{ |
8041
|
551114
|
|
|
|
|
return newUNOP(OP_REFGEN, 0, |
8042
|
|
|
|
|
|
newSVOP(OP_ANONCODE, 0, |
8043
|
|
|
|
|
|
MUTABLE_SV(newATTRSUB(floor, 0, proto, attrs, block)))); |
8044
|
|
|
|
|
|
} |
8045
|
|
|
|
|
|
|
8046
|
|
|
|
|
|
OP * |
8047
|
3520723
|
|
|
|
|
Perl_oopsAV(pTHX_ OP *o) |
8048
|
|
|
|
|
|
{ |
8049
|
|
|
|
|
|
dVAR; |
8050
|
|
|
|
|
|
|
8051
|
|
|
|
|
|
PERL_ARGS_ASSERT_OOPSAV; |
8052
|
|
|
|
|
|
|
8053
|
3520723
|
|
|
|
|
switch (o->op_type) { |
8054
|
|
|
|
|
|
case OP_PADSV: |
8055
|
850074
|
|
|
|
|
o->op_type = OP_PADAV; |
8056
|
850074
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_PADAV]; |
8057
|
850074
|
|
|
|
|
return ref(o, OP_RV2AV); |
8058
|
|
|
|
|
|
|
8059
|
|
|
|
|
|
case OP_RV2SV: |
8060
|
2670649
|
|
|
|
|
o->op_type = OP_RV2AV; |
8061
|
2670649
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_RV2AV]; |
8062
|
2670649
|
|
|
|
|
ref(o, OP_RV2AV); |
8063
|
2670649
|
|
|
|
|
break; |
8064
|
|
|
|
|
|
|
8065
|
|
|
|
|
|
default: |
8066
|
0
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_INTERNAL), "oops: oopsAV"); |
8067
|
1862059
|
|
|
|
|
break; |
8068
|
|
|
|
|
|
} |
8069
|
|
|
|
|
|
return o; |
8070
|
|
|
|
|
|
} |
8071
|
|
|
|
|
|
|
8072
|
|
|
|
|
|
OP * |
8073
|
4596823
|
|
|
|
|
Perl_oopsHV(pTHX_ OP *o) |
8074
|
|
|
|
|
|
{ |
8075
|
|
|
|
|
|
dVAR; |
8076
|
|
|
|
|
|
|
8077
|
|
|
|
|
|
PERL_ARGS_ASSERT_OOPSHV; |
8078
|
|
|
|
|
|
|
8079
|
4596823
|
|
|
|
|
switch (o->op_type) { |
8080
|
|
|
|
|
|
case OP_PADSV: |
8081
|
|
|
|
|
|
case OP_PADAV: |
8082
|
1935748
|
|
|
|
|
o->op_type = OP_PADHV; |
8083
|
1935748
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_PADHV]; |
8084
|
1935748
|
|
|
|
|
return ref(o, OP_RV2HV); |
8085
|
|
|
|
|
|
|
8086
|
|
|
|
|
|
case OP_RV2SV: |
8087
|
|
|
|
|
|
case OP_RV2AV: |
8088
|
2661075
|
|
|
|
|
o->op_type = OP_RV2HV; |
8089
|
2661075
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_RV2HV]; |
8090
|
2661075
|
|
|
|
|
ref(o, OP_RV2HV); |
8091
|
2661075
|
|
|
|
|
break; |
8092
|
|
|
|
|
|
|
8093
|
|
|
|
|
|
default: |
8094
|
0
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_INTERNAL), "oops: oopsHV"); |
8095
|
2402437
|
|
|
|
|
break; |
8096
|
|
|
|
|
|
} |
8097
|
|
|
|
|
|
return o; |
8098
|
|
|
|
|
|
} |
8099
|
|
|
|
|
|
|
8100
|
|
|
|
|
|
OP * |
8101
|
15576742
|
|
|
|
|
Perl_newAVREF(pTHX_ OP *o) |
8102
|
|
|
|
|
|
{ |
8103
|
|
|
|
|
|
dVAR; |
8104
|
|
|
|
|
|
|
8105
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWAVREF; |
8106
|
|
|
|
|
|
|
8107
|
15576742
|
100
|
|
|
|
if (o->op_type == OP_PADANY) { |
8108
|
5120224
|
|
|
|
|
o->op_type = OP_PADAV; |
8109
|
5120224
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_PADAV]; |
8110
|
5120224
|
|
|
|
|
return o; |
8111
|
|
|
|
|
|
} |
8112
|
10456518
|
100
|
|
|
|
else if ((o->op_type == OP_RV2AV || o->op_type == OP_PADAV)) { |
8113
|
16
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED), |
8114
|
|
|
|
|
|
"Using an array as a reference is deprecated"); |
8115
|
|
|
|
|
|
} |
8116
|
13109863
|
|
|
|
|
return newUNOP(OP_RV2AV, 0, scalar(o)); |
8117
|
|
|
|
|
|
} |
8118
|
|
|
|
|
|
|
8119
|
|
|
|
|
|
OP * |
8120
|
2128488
|
|
|
|
|
Perl_newGVREF(pTHX_ I32 type, OP *o) |
8121
|
|
|
|
|
|
{ |
8122
|
2128488
|
100
|
|
|
|
if (type == OP_MAPSTART || type == OP_GREPSTART || type == OP_SORT) |
|
|
100
|
|
|
|
|
8123
|
427389
|
|
|
|
|
return newUNOP(OP_NULL, 0, o); |
8124
|
1922891
|
|
|
|
|
return ref(newUNOP(OP_RV2GV, OPf_REF, o), type); |
8125
|
|
|
|
|
|
} |
8126
|
|
|
|
|
|
|
8127
|
|
|
|
|
|
OP * |
8128
|
10131534
|
|
|
|
|
Perl_newHVREF(pTHX_ OP *o) |
8129
|
|
|
|
|
|
{ |
8130
|
|
|
|
|
|
dVAR; |
8131
|
|
|
|
|
|
|
8132
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWHVREF; |
8133
|
|
|
|
|
|
|
8134
|
10131534
|
100
|
|
|
|
if (o->op_type == OP_PADANY) { |
8135
|
1024878
|
|
|
|
|
o->op_type = OP_PADHV; |
8136
|
1024878
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_PADHV]; |
8137
|
1024878
|
|
|
|
|
return o; |
8138
|
|
|
|
|
|
} |
8139
|
9106656
|
100
|
|
|
|
else if ((o->op_type == OP_RV2HV || o->op_type == OP_PADHV)) { |
8140
|
16
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED), |
8141
|
|
|
|
|
|
"Using a hash as a reference is deprecated"); |
8142
|
|
|
|
|
|
} |
8143
|
9635294
|
|
|
|
|
return newUNOP(OP_RV2HV, 0, scalar(o)); |
8144
|
|
|
|
|
|
} |
8145
|
|
|
|
|
|
|
8146
|
|
|
|
|
|
OP * |
8147
|
23403885
|
|
|
|
|
Perl_newCVREF(pTHX_ I32 flags, OP *o) |
8148
|
|
|
|
|
|
{ |
8149
|
23403885
|
100
|
|
|
|
if (o->op_type == OP_PADANY) { |
8150
|
|
|
|
|
|
dVAR; |
8151
|
194
|
|
|
|
|
o->op_type = OP_PADCV; |
8152
|
194
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_PADCV]; |
8153
|
|
|
|
|
|
} |
8154
|
23403885
|
|
|
|
|
return newUNOP(OP_RV2CV, flags, scalar(o)); |
8155
|
|
|
|
|
|
} |
8156
|
|
|
|
|
|
|
8157
|
|
|
|
|
|
OP * |
8158
|
102184799
|
|
|
|
|
Perl_newSVREF(pTHX_ OP *o) |
8159
|
|
|
|
|
|
{ |
8160
|
|
|
|
|
|
dVAR; |
8161
|
|
|
|
|
|
|
8162
|
|
|
|
|
|
PERL_ARGS_ASSERT_NEWSVREF; |
8163
|
|
|
|
|
|
|
8164
|
102184799
|
100
|
|
|
|
if (o->op_type == OP_PADANY) { |
8165
|
84888725
|
|
|
|
|
o->op_type = OP_PADSV; |
8166
|
84888725
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_PADSV]; |
8167
|
84888725
|
|
|
|
|
return o; |
8168
|
|
|
|
|
|
} |
8169
|
61319456
|
|
|
|
|
return newUNOP(OP_RV2SV, 0, scalar(o)); |
8170
|
|
|
|
|
|
} |
8171
|
|
|
|
|
|
|
8172
|
|
|
|
|
|
/* Check routines. See the comments at the top of this file for details |
8173
|
|
|
|
|
|
* on when these are called */ |
8174
|
|
|
|
|
|
|
8175
|
|
|
|
|
|
OP * |
8176
|
551120
|
|
|
|
|
Perl_ck_anoncode(pTHX_ OP *o) |
8177
|
|
|
|
|
|
{ |
8178
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_ANONCODE; |
8179
|
|
|
|
|
|
|
8180
|
551120
|
|
|
|
|
cSVOPo->op_targ = pad_add_anon((CV*)cSVOPo->op_sv, o->op_type); |
8181
|
|
|
|
|
|
if (!PL_madskills) |
8182
|
551120
|
|
|
|
|
cSVOPo->op_sv = NULL; |
8183
|
551120
|
|
|
|
|
return o; |
8184
|
|
|
|
|
|
} |
8185
|
|
|
|
|
|
|
8186
|
|
|
|
|
|
OP * |
8187
|
1844784
|
|
|
|
|
Perl_ck_bitop(pTHX_ OP *o) |
8188
|
|
|
|
|
|
{ |
8189
|
|
|
|
|
|
dVAR; |
8190
|
|
|
|
|
|
|
8191
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_BITOP; |
8192
|
|
|
|
|
|
|
8193
|
1844784
|
|
|
|
|
o->op_private = (U8)(PL_hints & HINT_INTEGER); |
8194
|
1844784
|
100
|
|
|
|
if (!(o->op_flags & OPf_STACKED) /* Not an assignment */ |
8195
|
2065924
|
100
|
|
|
|
&& (o->op_type == OP_BIT_OR |
8196
|
1382922
|
|
|
|
|
|| o->op_type == OP_BIT_AND |
8197
|
237149
|
100
|
|
|
|
|| o->op_type == OP_BIT_XOR)) |
8198
|
|
|
|
|
|
{ |
8199
|
1152807
|
|
|
|
|
const OP * const left = cBINOPo->op_first; |
8200
|
1152807
|
|
|
|
|
const OP * const right = left->op_sibling; |
8201
|
1152823
|
100
|
|
|
|
if ((OP_IS_NUMCOMPARE(left->op_type) && |
|
|
50
|
|
|
|
|
8202
|
1152791
|
100
|
|
|
|
(left->op_flags & OPf_PARENS) == 0) || |
8203
|
569932
|
50
|
|
|
|
(OP_IS_NUMCOMPARE(right->op_type) && |
8204
|
24
|
|
|
|
|
(right->op_flags & OPf_PARENS) == 0)) |
8205
|
104
|
100
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_PRECEDENCE), |
8206
|
|
|
|
|
|
"Possible precedence problem on bitwise %c operator", |
8207
|
56
|
|
|
|
|
o->op_type == OP_BIT_OR ? '|' |
8208
|
68
|
100
|
|
|
|
: o->op_type == OP_BIT_AND ? '&' : '^' |
8209
|
|
|
|
|
|
); |
8210
|
|
|
|
|
|
} |
8211
|
1844784
|
|
|
|
|
return o; |
8212
|
|
|
|
|
|
} |
8213
|
|
|
|
|
|
|
8214
|
|
|
|
|
|
PERL_STATIC_INLINE bool |
8215
|
761721
|
|
|
|
|
is_dollar_bracket(pTHX_ const OP * const o) |
8216
|
|
|
|
|
|
{ |
8217
|
|
|
|
|
|
const OP *kid; |
8218
|
1249708
|
50
|
|
|
|
return o->op_type == OP_RV2SV && o->op_flags & OPf_KIDS |
8219
|
114506
|
50
|
|
|
|
&& (kid = cUNOPx(o)->op_first) |
8220
|
114506
|
100
|
|
|
|
&& kid->op_type == OP_GV |
8221
|
876010
|
100
|
|
|
|
&& strEQ(GvNAME(cGVOPx_gv(kid)), "["); |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
8222
|
|
|
|
|
|
} |
8223
|
|
|
|
|
|
|
8224
|
|
|
|
|
|
OP * |
8225
|
1729754
|
|
|
|
|
Perl_ck_cmp(pTHX_ OP *o) |
8226
|
|
|
|
|
|
{ |
8227
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_CMP; |
8228
|
1729754
|
100
|
|
|
|
if (ckWARN(WARN_SYNTAX)) { |
8229
|
657465
|
|
|
|
|
const OP *kid = cUNOPo->op_first; |
8230
|
1314930
|
|
|
|
|
if (kid && ( |
8231
|
|
|
|
|
|
( |
8232
|
657465
|
|
|
|
|
is_dollar_bracket(aTHX_ kid) |
8233
|
32
|
50
|
|
|
|
&& kid->op_sibling && kid->op_sibling->op_type == OP_CONST |
|
|
100
|
|
|
|
|
8234
|
|
|
|
|
|
) |
8235
|
657449
|
100
|
|
|
|
|| ( kid->op_type == OP_CONST |
8236
|
104256
|
50
|
|
|
|
&& (kid = kid->op_sibling) && is_dollar_bracket(aTHX_ kid)) |
|
|
100
|
|
|
|
|
8237
|
|
|
|
|
|
)) |
8238
|
48
|
50
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
8239
|
16
|
0
|
|
|
|
"$[ used in %s (did you mean $] ?)", OP_DESC(o)); |
8240
|
|
|
|
|
|
} |
8241
|
1729754
|
|
|
|
|
return o; |
8242
|
|
|
|
|
|
} |
8243
|
|
|
|
|
|
|
8244
|
|
|
|
|
|
OP * |
8245
|
14325329
|
|
|
|
|
Perl_ck_concat(pTHX_ OP *o) |
8246
|
|
|
|
|
|
{ |
8247
|
14325329
|
|
|
|
|
const OP * const kid = cUNOPo->op_first; |
8248
|
|
|
|
|
|
|
8249
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_CONCAT; |
8250
|
|
|
|
|
|
PERL_UNUSED_CONTEXT; |
8251
|
|
|
|
|
|
|
8252
|
17655227
|
100
|
|
|
|
if (kid->op_type == OP_CONCAT && !(kid->op_private & OPpTARGET_MY) && |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
8253
|
6981242
|
|
|
|
|
!(kUNOP->op_first->op_flags & OPf_MOD)) |
8254
|
6981240
|
|
|
|
|
o->op_flags |= OPf_STACKED; |
8255
|
14325329
|
|
|
|
|
return o; |
8256
|
|
|
|
|
|
} |
8257
|
|
|
|
|
|
|
8258
|
|
|
|
|
|
OP * |
8259
|
3000309
|
|
|
|
|
Perl_ck_spair(pTHX_ OP *o) |
8260
|
|
|
|
|
|
{ |
8261
|
|
|
|
|
|
dVAR; |
8262
|
|
|
|
|
|
|
8263
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_SPAIR; |
8264
|
|
|
|
|
|
|
8265
|
3000309
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
8266
|
|
|
|
|
|
OP* newop; |
8267
|
|
|
|
|
|
OP* kid; |
8268
|
2975518
|
|
|
|
|
const OPCODE type = o->op_type; |
8269
|
2975518
|
|
|
|
|
o = modkids(ck_fun(o), type); |
8270
|
2975518
|
|
|
|
|
kid = cUNOPo->op_first; |
8271
|
2975518
|
|
|
|
|
newop = kUNOP->op_first->op_sibling; |
8272
|
2975518
|
50
|
|
|
|
if (newop) { |
8273
|
2975518
|
|
|
|
|
const OPCODE type = newop->op_type; |
8274
|
4412690
|
100
|
|
|
|
if (newop->op_sibling || !(PL_opargs[type] & OA_RETSCALAR) || |
|
|
100
|
|
|
|
|
8275
|
2291315
|
50
|
|
|
|
type == OP_PADAV || type == OP_PADHV || |
8276
|
854143
|
50
|
|
|
|
type == OP_RV2AV || type == OP_RV2HV) |
8277
|
|
|
|
|
|
return o; |
8278
|
|
|
|
|
|
} |
8279
|
|
|
|
|
|
#ifdef PERL_MAD |
8280
|
|
|
|
|
|
op_getmad(kUNOP->op_first,newop,'K'); |
8281
|
|
|
|
|
|
#else |
8282
|
576508
|
|
|
|
|
op_free(kUNOP->op_first); |
8283
|
|
|
|
|
|
#endif |
8284
|
576508
|
|
|
|
|
kUNOP->op_first = newop; |
8285
|
|
|
|
|
|
} |
8286
|
|
|
|
|
|
/* transforms OP_REFGEN into OP_SREFGEN, OP_CHOP into OP_SCHOP, |
8287
|
|
|
|
|
|
* and OP_CHOMP into OP_SCHOMP */ |
8288
|
601299
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[++o->op_type]; |
8289
|
1840758
|
|
|
|
|
return ck_fun(o); |
8290
|
|
|
|
|
|
} |
8291
|
|
|
|
|
|
|
8292
|
|
|
|
|
|
OP * |
8293
|
358438
|
|
|
|
|
Perl_ck_delete(pTHX_ OP *o) |
8294
|
|
|
|
|
|
{ |
8295
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_DELETE; |
8296
|
|
|
|
|
|
|
8297
|
358438
|
|
|
|
|
o = ck_fun(o); |
8298
|
358438
|
|
|
|
|
o->op_private = 0; |
8299
|
358438
|
50
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
8300
|
358438
|
|
|
|
|
OP * const kid = cUNOPo->op_first; |
8301
|
358438
|
|
|
|
|
switch (kid->op_type) { |
8302
|
|
|
|
|
|
case OP_ASLICE: |
8303
|
10
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; |
8304
|
|
|
|
|
|
/* FALL THROUGH */ |
8305
|
|
|
|
|
|
case OP_HSLICE: |
8306
|
21600
|
|
|
|
|
o->op_private |= OPpSLICE; |
8307
|
21600
|
|
|
|
|
break; |
8308
|
|
|
|
|
|
case OP_AELEM: |
8309
|
108
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; |
8310
|
|
|
|
|
|
/* FALL THROUGH */ |
8311
|
|
|
|
|
|
case OP_HELEM: |
8312
|
|
|
|
|
|
break; |
8313
|
|
|
|
|
|
default: |
8314
|
3
|
50
|
|
|
|
Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element or slice", |
8315
|
1
|
0
|
|
|
|
OP_DESC(o)); |
8316
|
|
|
|
|
|
} |
8317
|
358436
|
100
|
|
|
|
if (kid->op_private & OPpLVAL_INTRO) |
8318
|
48
|
|
|
|
|
o->op_private |= OPpLVAL_INTRO; |
8319
|
358436
|
|
|
|
|
op_null(kid); |
8320
|
|
|
|
|
|
} |
8321
|
358436
|
|
|
|
|
return o; |
8322
|
|
|
|
|
|
} |
8323
|
|
|
|
|
|
|
8324
|
|
|
|
|
|
OP * |
8325
|
568084
|
|
|
|
|
Perl_ck_die(pTHX_ OP *o) |
8326
|
|
|
|
|
|
{ |
8327
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_DIE; |
8328
|
|
|
|
|
|
|
8329
|
|
|
|
|
|
#ifdef VMS |
8330
|
|
|
|
|
|
if (VMSISH_HUSHED) o->op_private |= OPpHUSH_VMSISH; |
8331
|
|
|
|
|
|
#endif |
8332
|
568084
|
|
|
|
|
return ck_fun(o); |
8333
|
|
|
|
|
|
} |
8334
|
|
|
|
|
|
|
8335
|
|
|
|
|
|
OP * |
8336
|
4748
|
|
|
|
|
Perl_ck_eof(pTHX_ OP *o) |
8337
|
|
|
|
|
|
{ |
8338
|
|
|
|
|
|
dVAR; |
8339
|
|
|
|
|
|
|
8340
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_EOF; |
8341
|
|
|
|
|
|
|
8342
|
4748
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
8343
|
|
|
|
|
|
OP *kid; |
8344
|
4678
|
50
|
|
|
|
if (cLISTOPo->op_first->op_type == OP_STUB) { |
8345
|
0
|
|
|
|
|
OP * const newop |
8346
|
0
|
|
|
|
|
= newUNOP(o->op_type, OPf_SPECIAL, newGVOP(OP_GV, 0, PL_argvgv)); |
8347
|
|
|
|
|
|
#ifdef PERL_MAD |
8348
|
|
|
|
|
|
op_getmad(o,newop,'O'); |
8349
|
|
|
|
|
|
#else |
8350
|
0
|
|
|
|
|
op_free(o); |
8351
|
|
|
|
|
|
#endif |
8352
|
|
|
|
|
|
o = newop; |
8353
|
|
|
|
|
|
} |
8354
|
4678
|
|
|
|
|
o = ck_fun(o); |
8355
|
4678
|
|
|
|
|
kid = cLISTOPo->op_first; |
8356
|
4678
|
100
|
|
|
|
if (kid->op_type == OP_RV2GV) |
8357
|
3322
|
|
|
|
|
kid->op_private |= OPpALLOW_FAKE; |
8358
|
|
|
|
|
|
} |
8359
|
4748
|
|
|
|
|
return o; |
8360
|
|
|
|
|
|
} |
8361
|
|
|
|
|
|
|
8362
|
|
|
|
|
|
OP * |
8363
|
627747
|
|
|
|
|
Perl_ck_eval(pTHX_ OP *o) |
8364
|
|
|
|
|
|
{ |
8365
|
|
|
|
|
|
dVAR; |
8366
|
|
|
|
|
|
|
8367
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_EVAL; |
8368
|
|
|
|
|
|
|
8369
|
627747
|
|
|
|
|
PL_hints |= HINT_BLOCK_SCOPE; |
8370
|
627747
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
8371
|
627725
|
|
|
|
|
SVOP * const kid = (SVOP*)cUNOPo->op_first; |
8372
|
|
|
|
|
|
assert(kid); |
8373
|
|
|
|
|
|
|
8374
|
627725
|
100
|
|
|
|
if (kid->op_type == OP_LINESEQ || kid->op_type == OP_STUB) { |
8375
|
|
|
|
|
|
LOGOP *enter; |
8376
|
|
|
|
|
|
#ifdef PERL_MAD |
8377
|
|
|
|
|
|
OP* const oldo = o; |
8378
|
|
|
|
|
|
#endif |
8379
|
|
|
|
|
|
|
8380
|
360290
|
|
|
|
|
cUNOPo->op_first = 0; |
8381
|
|
|
|
|
|
#ifndef PERL_MAD |
8382
|
360290
|
|
|
|
|
op_free(o); |
8383
|
|
|
|
|
|
#endif |
8384
|
|
|
|
|
|
|
8385
|
360290
|
|
|
|
|
NewOp(1101, enter, 1, LOGOP); |
8386
|
360290
|
|
|
|
|
enter->op_type = OP_ENTERTRY; |
8387
|
360290
|
|
|
|
|
enter->op_ppaddr = PL_ppaddr[OP_ENTERTRY]; |
8388
|
360290
|
|
|
|
|
enter->op_private = 0; |
8389
|
|
|
|
|
|
|
8390
|
|
|
|
|
|
/* establish postfix order */ |
8391
|
360290
|
|
|
|
|
enter->op_next = (OP*)enter; |
8392
|
|
|
|
|
|
|
8393
|
360290
|
|
|
|
|
o = op_prepend_elem(OP_LINESEQ, (OP*)enter, (OP*)kid); |
8394
|
360290
|
|
|
|
|
o->op_type = OP_LEAVETRY; |
8395
|
360290
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_LEAVETRY]; |
8396
|
360290
|
|
|
|
|
enter->op_other = o; |
8397
|
|
|
|
|
|
op_getmad(oldo,o,'O'); |
8398
|
360290
|
|
|
|
|
return o; |
8399
|
|
|
|
|
|
} |
8400
|
|
|
|
|
|
else { |
8401
|
267435
|
|
|
|
|
scalar((OP*)kid); |
8402
|
267435
|
|
|
|
|
PL_cv_has_eval = 1; |
8403
|
|
|
|
|
|
} |
8404
|
|
|
|
|
|
} |
8405
|
|
|
|
|
|
else { |
8406
|
22
|
|
|
|
|
const U8 priv = o->op_private; |
8407
|
|
|
|
|
|
#ifdef PERL_MAD |
8408
|
|
|
|
|
|
OP* const oldo = o; |
8409
|
|
|
|
|
|
#else |
8410
|
22
|
|
|
|
|
op_free(o); |
8411
|
|
|
|
|
|
#endif |
8412
|
22
|
|
|
|
|
o = newUNOP(OP_ENTEREVAL, priv <<8, newDEFSVOP()); |
8413
|
|
|
|
|
|
op_getmad(oldo,o,'O'); |
8414
|
|
|
|
|
|
} |
8415
|
267457
|
|
|
|
|
o->op_targ = (PADOFFSET)PL_hints; |
8416
|
267457
|
100
|
|
|
|
if (o->op_private & OPpEVAL_BYTES) o->op_targ &= ~HINT_UTF8; |
8417
|
267457
|
100
|
|
|
|
if ((PL_hints & HINT_LOCALIZE_HH) != 0 |
8418
|
12922
|
50
|
|
|
|
&& !(o->op_private & OPpEVAL_COPHH) && GvHV(PL_hintgv)) { |
|
|
50
|
|
|
|
|
8419
|
|
|
|
|
|
/* Store a copy of %^H that pp_entereval can pick up. */ |
8420
|
12922
|
|
|
|
|
OP *hhop = newSVOP(OP_HINTSEVAL, 0, |
8421
|
|
|
|
|
|
MUTABLE_SV(hv_copy_hints_hv(GvHV(PL_hintgv)))); |
8422
|
12922
|
|
|
|
|
cUNOPo->op_first->op_sibling = hhop; |
8423
|
12922
|
|
|
|
|
o->op_private |= OPpEVAL_HAS_HH; |
8424
|
|
|
|
|
|
} |
8425
|
665195
|
100
|
|
|
|
if (!(o->op_private & OPpEVAL_BYTES) |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
8426
|
665143
|
100
|
|
|
|
&& FEATURE_UNIEVAL_IS_ENABLED) |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
8427
|
326488
|
|
|
|
|
o->op_private |= OPpEVAL_UNICODE; |
8428
|
|
|
|
|
|
return o; |
8429
|
|
|
|
|
|
} |
8430
|
|
|
|
|
|
|
8431
|
|
|
|
|
|
OP * |
8432
|
17172
|
|
|
|
|
Perl_ck_exit(pTHX_ OP *o) |
8433
|
|
|
|
|
|
{ |
8434
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_EXIT; |
8435
|
|
|
|
|
|
|
8436
|
|
|
|
|
|
#ifdef VMS |
8437
|
|
|
|
|
|
HV * const table = GvHV(PL_hintgv); |
8438
|
|
|
|
|
|
if (table) { |
8439
|
|
|
|
|
|
SV * const * const svp = hv_fetchs(table, "vmsish_exit", FALSE); |
8440
|
|
|
|
|
|
if (svp && *svp && SvTRUE(*svp)) |
8441
|
|
|
|
|
|
o->op_private |= OPpEXIT_VMSISH; |
8442
|
|
|
|
|
|
} |
8443
|
|
|
|
|
|
if (VMSISH_HUSHED) o->op_private |= OPpHUSH_VMSISH; |
8444
|
|
|
|
|
|
#endif |
8445
|
17172
|
|
|
|
|
return ck_fun(o); |
8446
|
|
|
|
|
|
} |
8447
|
|
|
|
|
|
|
8448
|
|
|
|
|
|
OP * |
8449
|
14652
|
|
|
|
|
Perl_ck_exec(pTHX_ OP *o) |
8450
|
|
|
|
|
|
{ |
8451
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_EXEC; |
8452
|
|
|
|
|
|
|
8453
|
14652
|
100
|
|
|
|
if (o->op_flags & OPf_STACKED) { |
8454
|
|
|
|
|
|
OP *kid; |
8455
|
512
|
|
|
|
|
o = ck_fun(o); |
8456
|
512
|
|
|
|
|
kid = cUNOPo->op_first->op_sibling; |
8457
|
512
|
50
|
|
|
|
if (kid->op_type == OP_RV2GV) |
8458
|
512
|
|
|
|
|
op_null(kid); |
8459
|
|
|
|
|
|
} |
8460
|
|
|
|
|
|
else |
8461
|
14140
|
|
|
|
|
o = listkids(o); |
8462
|
14652
|
|
|
|
|
return o; |
8463
|
|
|
|
|
|
} |
8464
|
|
|
|
|
|
|
8465
|
|
|
|
|
|
OP * |
8466
|
709101
|
|
|
|
|
Perl_ck_exists(pTHX_ OP *o) |
8467
|
|
|
|
|
|
{ |
8468
|
|
|
|
|
|
dVAR; |
8469
|
|
|
|
|
|
|
8470
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_EXISTS; |
8471
|
|
|
|
|
|
|
8472
|
709101
|
|
|
|
|
o = ck_fun(o); |
8473
|
709101
|
50
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
8474
|
709101
|
|
|
|
|
OP * const kid = cUNOPo->op_first; |
8475
|
709101
|
100
|
|
|
|
if (kid->op_type == OP_ENTERSUB) { |
8476
|
22062
|
|
|
|
|
(void) ref(kid, o->op_type); |
8477
|
22062
|
100
|
|
|
|
if (kid->op_type != OP_RV2CV |
8478
|
4
|
50
|
|
|
|
&& !(PL_parser && PL_parser->error_count)) |
|
|
50
|
|
|
|
|
8479
|
6
|
50
|
|
|
|
Perl_croak(aTHX_ "%s argument is not a subroutine name", |
8480
|
2
|
0
|
|
|
|
OP_DESC(o)); |
8481
|
22058
|
|
|
|
|
o->op_private |= OPpEXISTS_SUB; |
8482
|
|
|
|
|
|
} |
8483
|
687039
|
100
|
|
|
|
else if (kid->op_type == OP_AELEM) |
8484
|
29352
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; |
8485
|
657687
|
100
|
|
|
|
else if (kid->op_type != OP_HELEM) |
8486
|
3
|
50
|
|
|
|
Perl_croak(aTHX_ "%s argument is not a HASH or ARRAY element or a subroutine", |
8487
|
1
|
0
|
|
|
|
OP_DESC(o)); |
8488
|
709095
|
|
|
|
|
op_null(kid); |
8489
|
|
|
|
|
|
} |
8490
|
709095
|
|
|
|
|
return o; |
8491
|
|
|
|
|
|
} |
8492
|
|
|
|
|
|
|
8493
|
|
|
|
|
|
OP * |
8494
|
62297694
|
|
|
|
|
Perl_ck_rvconst(pTHX_ OP *o) |
8495
|
|
|
|
|
|
{ |
8496
|
|
|
|
|
|
dVAR; |
8497
|
62297694
|
|
|
|
|
SVOP * const kid = (SVOP*)cUNOPo->op_first; |
8498
|
|
|
|
|
|
|
8499
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_RVCONST; |
8500
|
|
|
|
|
|
|
8501
|
62297694
|
|
|
|
|
o->op_private |= (PL_hints & HINT_STRICT_REFS); |
8502
|
62297694
|
100
|
|
|
|
if (o->op_type == OP_RV2CV) |
8503
|
23404443
|
|
|
|
|
o->op_private &= ~1; |
8504
|
|
|
|
|
|
|
8505
|
62297694
|
100
|
|
|
|
if (kid->op_type == OP_CONST) { |
8506
|
|
|
|
|
|
int iscv; |
8507
|
|
|
|
|
|
GV *gv; |
8508
|
47095543
|
|
|
|
|
SV * const kidsv = kid->op_sv; |
8509
|
|
|
|
|
|
|
8510
|
|
|
|
|
|
/* Is it a constant from cv_const_sv()? */ |
8511
|
47095543
|
100
|
|
|
|
if (SvROK(kidsv) && SvREADONLY(kidsv)) { |
8512
|
272
|
|
|
|
|
SV * const rsv = SvRV(kidsv); |
8513
|
272
|
|
|
|
|
const svtype type = SvTYPE(rsv); |
8514
|
|
|
|
|
|
const char *badtype = NULL; |
8515
|
|
|
|
|
|
|
8516
|
272
|
|
|
|
|
switch (o->op_type) { |
8517
|
|
|
|
|
|
case OP_RV2SV: |
8518
|
0
|
0
|
|
|
|
if (type > SVt_PVMG) |
8519
|
|
|
|
|
|
badtype = "a SCALAR"; |
8520
|
|
|
|
|
|
break; |
8521
|
|
|
|
|
|
case OP_RV2AV: |
8522
|
0
|
0
|
|
|
|
if (type != SVt_PVAV) |
8523
|
|
|
|
|
|
badtype = "an ARRAY"; |
8524
|
|
|
|
|
|
break; |
8525
|
|
|
|
|
|
case OP_RV2HV: |
8526
|
8
|
50
|
|
|
|
if (type != SVt_PVHV) |
8527
|
|
|
|
|
|
badtype = "a HASH"; |
8528
|
|
|
|
|
|
break; |
8529
|
|
|
|
|
|
case OP_RV2CV: |
8530
|
264
|
50
|
|
|
|
if (type != SVt_PVCV) |
8531
|
|
|
|
|
|
badtype = "a CODE"; |
8532
|
|
|
|
|
|
break; |
8533
|
|
|
|
|
|
} |
8534
|
272
|
50
|
|
|
|
if (badtype) |
8535
|
0
|
|
|
|
|
Perl_croak(aTHX_ "Constant is not %s reference", badtype); |
8536
|
|
|
|
|
|
return o; |
8537
|
|
|
|
|
|
} |
8538
|
47095271
|
100
|
|
|
|
if (SvTYPE(kidsv) == SVt_PVAV) return o; |
8539
|
47094261
|
100
|
|
|
|
if ((o->op_private & HINT_STRICT_REFS) && (kid->op_private & OPpCONST_BARE)) { |
|
|
100
|
|
|
|
|
8540
|
|
|
|
|
|
const char *badthing; |
8541
|
17416822
|
|
|
|
|
switch (o->op_type) { |
8542
|
|
|
|
|
|
case OP_RV2SV: |
8543
|
|
|
|
|
|
badthing = "a SCALAR"; |
8544
|
|
|
|
|
|
break; |
8545
|
|
|
|
|
|
case OP_RV2AV: |
8546
|
|
|
|
|
|
badthing = "an ARRAY"; |
8547
|
2
|
|
|
|
|
break; |
8548
|
|
|
|
|
|
case OP_RV2HV: |
8549
|
|
|
|
|
|
badthing = "a HASH"; |
8550
|
2
|
|
|
|
|
break; |
8551
|
|
|
|
|
|
default: |
8552
|
|
|
|
|
|
badthing = NULL; |
8553
|
17416818
|
|
|
|
|
break; |
8554
|
|
|
|
|
|
} |
8555
|
17416822
|
100
|
|
|
|
if (badthing) |
8556
|
4
|
|
|
|
|
Perl_croak(aTHX_ |
8557
|
|
|
|
|
|
"Can't use bareword (\"%"SVf"\") as %s ref while \"strict refs\" in use", |
8558
|
|
|
|
|
|
SVfARG(kidsv), badthing); |
8559
|
|
|
|
|
|
} |
8560
|
|
|
|
|
|
/* |
8561
|
|
|
|
|
|
* This is a little tricky. We only want to add the symbol if we |
8562
|
|
|
|
|
|
* didn't add it in the lexer. Otherwise we get duplicate strict |
8563
|
|
|
|
|
|
* warnings. But if we didn't add it in the lexer, we must at |
8564
|
|
|
|
|
|
* least pretend like we wanted to add it even if it existed before, |
8565
|
|
|
|
|
|
* or we get possible typo warnings. OPpCONST_ENTERED says |
8566
|
|
|
|
|
|
* whether the lexer already added THIS instance of this symbol. |
8567
|
|
|
|
|
|
*/ |
8568
|
47094257
|
100
|
|
|
|
iscv = (o->op_type == OP_RV2CV) * 2; |
8569
|
|
|
|
|
|
do { |
8570
|
47094257
|
100
|
|
|
|
gv = gv_fetchsv(kidsv, |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
8571
|
|
|
|
|
|
iscv | !(kid->op_private & OPpCONST_ENTERED), |
8572
|
|
|
|
|
|
iscv |
8573
|
|
|
|
|
|
? SVt_PVCV |
8574
|
|
|
|
|
|
: o->op_type == OP_RV2SV |
8575
|
|
|
|
|
|
? SVt_PV |
8576
|
|
|
|
|
|
: o->op_type == OP_RV2AV |
8577
|
|
|
|
|
|
? SVt_PVAV |
8578
|
|
|
|
|
|
: o->op_type == OP_RV2HV |
8579
|
|
|
|
|
|
? SVt_PVHV |
8580
|
|
|
|
|
|
: SVt_PVGV); |
8581
|
47094241
|
100
|
|
|
|
} while (!gv && !(kid->op_private & OPpCONST_ENTERED) && !iscv++); |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
8582
|
47094241
|
100
|
|
|
|
if (gv) { |
8583
|
47094163
|
|
|
|
|
kid->op_type = OP_GV; |
8584
|
47094163
|
|
|
|
|
SvREFCNT_dec(kid->op_sv); |
8585
|
|
|
|
|
|
#ifdef USE_ITHREADS |
8586
|
|
|
|
|
|
/* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */ |
8587
|
|
|
|
|
|
assert (sizeof(PADOP) <= sizeof(SVOP)); |
8588
|
|
|
|
|
|
kPADOP->op_padix = pad_alloc(OP_GV, SVs_PADTMP); |
8589
|
|
|
|
|
|
SvREFCNT_dec(PAD_SVl(kPADOP->op_padix)); |
8590
|
|
|
|
|
|
GvIN_PAD_on(gv); |
8591
|
|
|
|
|
|
PAD_SETSV(kPADOP->op_padix, MUTABLE_SV(SvREFCNT_inc_simple_NN(gv))); |
8592
|
|
|
|
|
|
#else |
8593
|
47094163
|
|
|
|
|
kid->op_sv = SvREFCNT_inc_simple_NN(gv); |
8594
|
|
|
|
|
|
#endif |
8595
|
47094163
|
|
|
|
|
kid->op_private = 0; |
8596
|
47094163
|
|
|
|
|
kid->op_ppaddr = PL_ppaddr[OP_GV]; |
8597
|
|
|
|
|
|
/* FAKE globs in the symbol table cause weird bugs (#77810) */ |
8598
|
55152750
|
|
|
|
|
SvFAKE_off(gv); |
8599
|
|
|
|
|
|
} |
8600
|
|
|
|
|
|
} |
8601
|
|
|
|
|
|
return o; |
8602
|
|
|
|
|
|
} |
8603
|
|
|
|
|
|
|
8604
|
|
|
|
|
|
OP * |
8605
|
702986
|
|
|
|
|
Perl_ck_ftst(pTHX_ OP *o) |
8606
|
|
|
|
|
|
{ |
8607
|
|
|
|
|
|
dVAR; |
8608
|
702986
|
|
|
|
|
const I32 type = o->op_type; |
8609
|
|
|
|
|
|
|
8610
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_FTST; |
8611
|
|
|
|
|
|
|
8612
|
702986
|
100
|
|
|
|
if (o->op_flags & OPf_REF) { |
8613
|
|
|
|
|
|
NOOP; |
8614
|
|
|
|
|
|
} |
8615
|
654026
|
100
|
|
|
|
else if (o->op_flags & OPf_KIDS && cUNOPo->op_first->op_type != OP_STUB) { |
|
|
100
|
|
|
|
|
8616
|
640748
|
|
|
|
|
SVOP * const kid = (SVOP*)cUNOPo->op_first; |
8617
|
640748
|
|
|
|
|
const OPCODE kidtype = kid->op_type; |
8618
|
|
|
|
|
|
|
8619
|
640748
|
100
|
|
|
|
if (kidtype == OP_CONST && (kid->op_private & OPpCONST_BARE) |
|
|
100
|
|
|
|
|
8620
|
48960
|
100
|
|
|
|
&& !kid->op_folded) { |
8621
|
48956
|
|
|
|
|
OP * const newop = newGVOP(type, OPf_REF, |
8622
|
|
|
|
|
|
gv_fetchsv(kid->op_sv, GV_ADD, SVt_PVIO)); |
8623
|
|
|
|
|
|
#ifdef PERL_MAD |
8624
|
|
|
|
|
|
op_getmad(o,newop,'O'); |
8625
|
|
|
|
|
|
#else |
8626
|
48956
|
|
|
|
|
op_free(o); |
8627
|
|
|
|
|
|
#endif |
8628
|
48956
|
|
|
|
|
return newop; |
8629
|
|
|
|
|
|
} |
8630
|
591792
|
100
|
|
|
|
if ((PL_hints & HINT_FILETEST_ACCESS) && OP_IS_FILETEST_ACCESS(o->op_type)) |
|
|
100
|
|
|
|
|
8631
|
280
|
|
|
|
|
o->op_private |= OPpFT_ACCESS; |
8632
|
878868
|
100
|
|
|
|
if (PL_check[kidtype] == Perl_ck_ftst |
8633
|
287290
|
50
|
|
|
|
&& kidtype != OP_STAT && kidtype != OP_LSTAT) { |
8634
|
214
|
|
|
|
|
o->op_private |= OPpFT_STACKED; |
8635
|
214
|
|
|
|
|
kid->op_private |= OPpFT_STACKING; |
8636
|
219
|
100
|
|
|
|
if (kidtype == OP_FTTTY && ( |
|
|
50
|
|
|
|
|
8637
|
10
|
|
|
|
|
!(kid->op_private & OPpFT_STACKED) |
8638
|
10
|
|
|
|
|
|| kid->op_private & OPpFT_AFTER_t |
8639
|
|
|
|
|
|
)) |
8640
|
10
|
|
|
|
|
o->op_private |= OPpFT_AFTER_t; |
8641
|
|
|
|
|
|
} |
8642
|
|
|
|
|
|
} |
8643
|
|
|
|
|
|
else { |
8644
|
|
|
|
|
|
#ifdef PERL_MAD |
8645
|
|
|
|
|
|
OP* const oldo = o; |
8646
|
|
|
|
|
|
#else |
8647
|
13278
|
|
|
|
|
op_free(o); |
8648
|
|
|
|
|
|
#endif |
8649
|
13278
|
100
|
|
|
|
if (type == OP_FTTTY) |
8650
|
4
|
|
|
|
|
o = newGVOP(type, OPf_REF, PL_stdingv); |
8651
|
|
|
|
|
|
else |
8652
|
13274
|
|
|
|
|
o = newUNOP(type, 0, newDEFSVOP()); |
8653
|
|
|
|
|
|
op_getmad(oldo,o,'O'); |
8654
|
|
|
|
|
|
} |
8655
|
679228
|
|
|
|
|
return o; |
8656
|
|
|
|
|
|
} |
8657
|
|
|
|
|
|
|
8658
|
|
|
|
|
|
OP * |
8659
|
35518990
|
|
|
|
|
Perl_ck_fun(pTHX_ OP *o) |
8660
|
|
|
|
|
|
{ |
8661
|
|
|
|
|
|
dVAR; |
8662
|
35518990
|
|
|
|
|
const int type = o->op_type; |
8663
|
35518990
|
|
|
|
|
I32 oa = PL_opargs[type] >> OASHIFT; |
8664
|
|
|
|
|
|
|
8665
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_FUN; |
8666
|
|
|
|
|
|
|
8667
|
35518990
|
100
|
|
|
|
if (o->op_flags & OPf_STACKED) { |
8668
|
512
|
50
|
|
|
|
if ((oa & OA_OPTIONAL) && (oa >> 4) && !((oa >> 4) & OA_OPTIONAL)) |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
8669
|
512
|
|
|
|
|
oa &= ~OA_OPTIONAL; |
8670
|
|
|
|
|
|
else |
8671
|
0
|
|
|
|
|
return no_fh_allowed(o); |
8672
|
|
|
|
|
|
} |
8673
|
|
|
|
|
|
|
8674
|
35518990
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
8675
|
34466773
|
|
|
|
|
OP **tokid = &cLISTOPo->op_first; |
8676
|
34466773
|
|
|
|
|
OP *kid = cLISTOPo->op_first; |
8677
|
|
|
|
|
|
OP *sibl; |
8678
|
|
|
|
|
|
I32 numargs = 0; |
8679
|
|
|
|
|
|
bool seen_optional = FALSE; |
8680
|
|
|
|
|
|
|
8681
|
47977778
|
100
|
|
|
|
if (kid->op_type == OP_PUSHMARK || |
|
|
100
|
|
|
|
|
8682
|
27185439
|
100
|
|
|
|
(kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK)) |
8683
|
|
|
|
|
|
{ |
8684
|
16376406
|
|
|
|
|
tokid = &kid->op_sibling; |
8685
|
16376406
|
|
|
|
|
kid = kid->op_sibling; |
8686
|
|
|
|
|
|
} |
8687
|
34466773
|
100
|
|
|
|
if (kid && kid->op_type == OP_COREARGS) { |
|
|
100
|
|
|
|
|
8688
|
|
|
|
|
|
bool optional = FALSE; |
8689
|
1788
|
100
|
|
|
|
while (oa) { |
8690
|
1186
|
|
|
|
|
numargs++; |
8691
|
1186
|
100
|
|
|
|
if (oa & OA_OPTIONAL) optional = TRUE; |
8692
|
1186
|
|
|
|
|
oa = oa >> 4; |
8693
|
|
|
|
|
|
} |
8694
|
602
|
100
|
|
|
|
if (optional) o->op_private |= numargs; |
8695
|
|
|
|
|
|
return o; |
8696
|
|
|
|
|
|
} |
8697
|
|
|
|
|
|
|
8698
|
73855121
|
100
|
|
|
|
while (oa) { |
8699
|
49256040
|
100
|
|
|
|
if (oa & OA_OPTIONAL || (oa & 7) == OA_LIST) { |
|
|
100
|
|
|
|
|
8700
|
31316493
|
100
|
|
|
|
if (!kid && !seen_optional && PL_opargs[type] & OA_DEFGV) |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
8701
|
500
|
|
|
|
|
*tokid = kid = newDEFSVOP(); |
8702
|
|
|
|
|
|
seen_optional = TRUE; |
8703
|
|
|
|
|
|
} |
8704
|
49256040
|
100
|
|
|
|
if (!kid) break; |
8705
|
|
|
|
|
|
|
8706
|
39388958
|
|
|
|
|
numargs++; |
8707
|
39388958
|
|
|
|
|
sibl = kid->op_sibling; |
8708
|
|
|
|
|
|
#ifdef PERL_MAD |
8709
|
|
|
|
|
|
if (!sibl && kid->op_type == OP_STUB) { |
8710
|
|
|
|
|
|
numargs--; |
8711
|
|
|
|
|
|
break; |
8712
|
|
|
|
|
|
} |
8713
|
|
|
|
|
|
#endif |
8714
|
39388958
|
|
|
|
|
switch (oa & 7) { |
8715
|
|
|
|
|
|
case OA_SCALAR: |
8716
|
|
|
|
|
|
/* list seen where single (scalar) arg expected? */ |
8717
|
26924884
|
100
|
|
|
|
if (numargs == 1 && !(oa >> 4) |
|
|
100
|
|
|
|
|
8718
|
22591440
|
100
|
|
|
|
&& kid->op_type == OP_LIST && type != OP_SCALAR) |
8719
|
|
|
|
|
|
{ |
8720
|
4
|
|
|
|
|
return too_many_arguments_pv(o,PL_op_desc[type], 0); |
8721
|
|
|
|
|
|
} |
8722
|
26924880
|
|
|
|
|
scalar(kid); |
8723
|
26924880
|
|
|
|
|
break; |
8724
|
|
|
|
|
|
case OA_LIST: |
8725
|
8716127
|
50
|
|
|
|
if (oa < 16) { |
8726
|
|
|
|
|
|
kid = 0; |
8727
|
8716127
|
|
|
|
|
continue; |
8728
|
|
|
|
|
|
} |
8729
|
|
|
|
|
|
else |
8730
|
0
|
|
|
|
|
list(kid); |
8731
|
0
|
|
|
|
|
break; |
8732
|
|
|
|
|
|
case OA_AVREF: |
8733
|
1656004
|
100
|
|
|
|
if ((type == OP_PUSH || type == OP_UNSHIFT) |
8734
|
1212726
|
100
|
|
|
|
&& !kid->op_sibling) |
8735
|
28
|
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), |
8736
|
|
|
|
|
|
"Useless use of %s with no values", |
8737
|
|
|
|
|
|
PL_op_desc[type]); |
8738
|
|
|
|
|
|
|
8739
|
1656020
|
100
|
|
|
|
if (kid->op_type == OP_CONST && |
|
|
100
|
|
|
|
|
8740
|
32
|
|
|
|
|
(kid->op_private & OPpCONST_BARE)) |
8741
|
20
|
|
|
|
|
{ |
8742
|
20
|
|
|
|
|
OP * const newop = newAVREF(newGVOP(OP_GV, 0, |
8743
|
|
|
|
|
|
gv_fetchsv(((SVOP*)kid)->op_sv, GV_ADD, SVt_PVAV) )); |
8744
|
30
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED), |
8745
|
|
|
|
|
|
"Array @%"SVf" missing the @ in argument %"IVdf" of %s()", |
8746
|
20
|
|
|
|
|
SVfARG(((SVOP*)kid)->op_sv), (IV)numargs, PL_op_desc[type]); |
8747
|
|
|
|
|
|
#ifdef PERL_MAD |
8748
|
|
|
|
|
|
op_getmad(kid,newop,'K'); |
8749
|
|
|
|
|
|
#else |
8750
|
20
|
|
|
|
|
op_free(kid); |
8751
|
|
|
|
|
|
#endif |
8752
|
|
|
|
|
|
kid = newop; |
8753
|
20
|
|
|
|
|
kid->op_sibling = sibl; |
8754
|
20
|
|
|
|
|
*tokid = kid; |
8755
|
|
|
|
|
|
} |
8756
|
1655984
|
100
|
|
|
|
else if (kid->op_type == OP_CONST |
8757
|
12
|
100
|
|
|
|
&& ( !SvROK(cSVOPx_sv(kid)) |
8758
|
6
|
50
|
|
|
|
|| SvTYPE(SvRV(cSVOPx_sv(kid))) != SVt_PVAV ) |
8759
|
|
|
|
|
|
) |
8760
|
6
|
|
|
|
|
bad_type_pv(numargs, "array", PL_op_desc[type], 0, kid); |
8761
|
|
|
|
|
|
/* Defer checks to run-time if we have a scalar arg */ |
8762
|
1656004
|
100
|
|
|
|
if (kid->op_type == OP_RV2AV || kid->op_type == OP_PADAV) |
8763
|
1655880
|
|
|
|
|
op_lvalue(kid, type); |
8764
|
124
|
|
|
|
|
else scalar(kid); |
8765
|
|
|
|
|
|
break; |
8766
|
|
|
|
|
|
case OA_HVREF: |
8767
|
616697
|
100
|
|
|
|
if (kid->op_type == OP_CONST && |
|
|
100
|
|
|
|
|
8768
|
18
|
|
|
|
|
(kid->op_private & OPpCONST_BARE)) |
8769
|
12
|
|
|
|
|
{ |
8770
|
12
|
|
|
|
|
OP * const newop = newHVREF(newGVOP(OP_GV, 0, |
8771
|
|
|
|
|
|
gv_fetchsv(((SVOP*)kid)->op_sv, GV_ADD, SVt_PVHV) )); |
8772
|
18
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED), |
8773
|
|
|
|
|
|
"Hash %%%"SVf" missing the %% in argument %"IVdf" of %s()", |
8774
|
12
|
|
|
|
|
SVfARG(((SVOP*)kid)->op_sv), (IV)numargs, PL_op_desc[type]); |
8775
|
|
|
|
|
|
#ifdef PERL_MAD |
8776
|
|
|
|
|
|
op_getmad(kid,newop,'K'); |
8777
|
|
|
|
|
|
#else |
8778
|
12
|
|
|
|
|
op_free(kid); |
8779
|
|
|
|
|
|
#endif |
8780
|
|
|
|
|
|
kid = newop; |
8781
|
12
|
|
|
|
|
kid->op_sibling = sibl; |
8782
|
12
|
|
|
|
|
*tokid = kid; |
8783
|
|
|
|
|
|
} |
8784
|
616676
|
100
|
|
|
|
else if (kid->op_type != OP_RV2HV && kid->op_type != OP_PADHV) |
8785
|
6
|
|
|
|
|
bad_type_pv(numargs, "hash", PL_op_desc[type], 0, kid); |
8786
|
616688
|
|
|
|
|
op_lvalue(kid, type); |
8787
|
616688
|
|
|
|
|
break; |
8788
|
|
|
|
|
|
case OA_CVREF: |
8789
|
|
|
|
|
|
{ |
8790
|
796089
|
|
|
|
|
OP * const newop = newUNOP(OP_NULL, 0, kid); |
8791
|
796089
|
|
|
|
|
kid->op_sibling = 0; |
8792
|
796089
|
|
|
|
|
newop->op_next = newop; |
8793
|
|
|
|
|
|
kid = newop; |
8794
|
796089
|
|
|
|
|
kid->op_sibling = sibl; |
8795
|
796089
|
|
|
|
|
*tokid = kid; |
8796
|
|
|
|
|
|
} |
8797
|
796089
|
|
|
|
|
break; |
8798
|
|
|
|
|
|
case OA_FILEREF: |
8799
|
566219
|
100
|
|
|
|
if (kid->op_type != OP_GV && kid->op_type != OP_RV2GV) { |
8800
|
676521
|
100
|
|
|
|
if (kid->op_type == OP_CONST && |
|
|
100
|
|
|
|
|
8801
|
234843
|
|
|
|
|
(kid->op_private & OPpCONST_BARE)) |
8802
|
234785
|
|
|
|
|
{ |
8803
|
234785
|
|
|
|
|
OP * const newop = newGVOP(OP_GV, 0, |
8804
|
|
|
|
|
|
gv_fetchsv(((SVOP*)kid)->op_sv, GV_ADD, SVt_PVIO)); |
8805
|
291148
|
100
|
|
|
|
if (!(o->op_private & 1) && /* if not unop */ |
|
|
100
|
|
|
|
|
8806
|
118839
|
|
|
|
|
kid == cLISTOPo->op_last) |
8807
|
20896
|
|
|
|
|
cLISTOPo->op_last = newop; |
8808
|
|
|
|
|
|
#ifdef PERL_MAD |
8809
|
|
|
|
|
|
op_getmad(kid,newop,'K'); |
8810
|
|
|
|
|
|
#else |
8811
|
234785
|
|
|
|
|
op_free(kid); |
8812
|
|
|
|
|
|
#endif |
8813
|
|
|
|
|
|
kid = newop; |
8814
|
|
|
|
|
|
} |
8815
|
330430
|
50
|
|
|
|
else if (kid->op_type == OP_READLINE) { |
8816
|
|
|
|
|
|
/* neophyte patrol: open(), close() etc. */ |
8817
|
0
|
0
|
|
|
|
bad_type_pv(numargs, "HANDLE", OP_DESC(o), 0, kid); |
|
|
0
|
|
|
|
|
8818
|
|
|
|
|
|
} |
8819
|
|
|
|
|
|
else { |
8820
|
|
|
|
|
|
I32 flags = OPf_SPECIAL; |
8821
|
|
|
|
|
|
I32 priv = 0; |
8822
|
|
|
|
|
|
PADOFFSET targ = 0; |
8823
|
|
|
|
|
|
|
8824
|
|
|
|
|
|
/* is this op a FH constructor? */ |
8825
|
330430
|
100
|
|
|
|
if (is_handle_constructor(o,numargs)) { |
8826
|
|
|
|
|
|
const char *name = NULL; |
8827
|
133745
|
|
|
|
|
STRLEN len = 0; |
8828
|
|
|
|
|
|
U32 name_utf8 = 0; |
8829
|
|
|
|
|
|
bool want_dollar = TRUE; |
8830
|
|
|
|
|
|
|
8831
|
|
|
|
|
|
flags = 0; |
8832
|
|
|
|
|
|
/* Set a flag to tell rv2gv to vivify |
8833
|
|
|
|
|
|
* need to "prove" flag does not mean something |
8834
|
|
|
|
|
|
* else already - NI-S 1999/05/07 |
8835
|
|
|
|
|
|
*/ |
8836
|
|
|
|
|
|
priv = OPpDEREF; |
8837
|
133745
|
100
|
|
|
|
if (kid->op_type == OP_PADSV) { |
8838
|
121123
|
|
|
|
|
SV *const namesv |
8839
|
121123
|
|
|
|
|
= PAD_COMPNAME_SV(kid->op_targ); |
8840
|
121123
|
50
|
|
|
|
name = SvPV_const(namesv, len); |
8841
|
121123
|
|
|
|
|
name_utf8 = SvUTF8(namesv); |
8842
|
|
|
|
|
|
} |
8843
|
12622
|
100
|
|
|
|
else if (kid->op_type == OP_RV2SV |
8844
|
2054
|
100
|
|
|
|
&& kUNOP->op_first->op_type == OP_GV) |
8845
|
582
|
|
|
|
|
{ |
8846
|
582
|
|
|
|
|
GV * const gv = cGVOPx_gv(kUNOP->op_first); |
8847
|
582
|
|
|
|
|
name = GvNAME(gv); |
8848
|
582
|
|
|
|
|
len = GvNAMELEN(gv); |
8849
|
582
|
100
|
|
|
|
name_utf8 = GvNAMEUTF8(gv) ? SVf_UTF8 : 0; |
8850
|
|
|
|
|
|
} |
8851
|
18060
|
100
|
|
|
|
else if (kid->op_type == OP_AELEM |
8852
|
12040
|
|
|
|
|
|| kid->op_type == OP_HELEM) |
8853
|
|
|
|
|
|
{ |
8854
|
|
|
|
|
|
OP *firstop; |
8855
|
5662
|
|
|
|
|
OP *op = ((BINOP*)kid)->op_first; |
8856
|
|
|
|
|
|
name = NULL; |
8857
|
5662
|
50
|
|
|
|
if (op) { |
8858
|
|
|
|
|
|
SV *tmpstr = NULL; |
8859
|
|
|
|
|
|
const char * const a = |
8860
|
5662
|
|
|
|
|
kid->op_type == OP_AELEM ? |
8861
|
5662
|
100
|
|
|
|
"[]" : "{}"; |
8862
|
5662
|
100
|
|
|
|
if (((op->op_type == OP_RV2AV) || |
8863
|
5606
|
50
|
|
|
|
(op->op_type == OP_RV2HV)) && |
8864
|
8409
|
100
|
|
|
|
(firstop = ((UNOP*)op)->op_first) && |
8865
|
5606
|
|
|
|
|
(firstop->op_type == OP_GV)) { |
8866
|
|
|
|
|
|
/* packagevar $a[] or $h{} */ |
8867
|
4446
|
|
|
|
|
GV * const gv = cGVOPx_gv(firstop); |
8868
|
4446
|
50
|
|
|
|
if (gv) |
8869
|
4446
|
|
|
|
|
tmpstr = |
8870
|
8892
|
|
|
|
|
Perl_newSVpvf(aTHX_ |
8871
|
|
|
|
|
|
"%s%c...%c", |
8872
|
4446
|
|
|
|
|
GvNAME(gv), |
8873
|
8892
|
|
|
|
|
a[0], a[1]); |
8874
|
|
|
|
|
|
} |
8875
|
1824
|
100
|
|
|
|
else if (op->op_type == OP_PADAV |
8876
|
1216
|
|
|
|
|
|| op->op_type == OP_PADHV) { |
8877
|
|
|
|
|
|
/* lexicalvar $a[] or $h{} */ |
8878
|
112
|
50
|
|
|
|
const char * const padname = |
8879
|
112
|
|
|
|
|
PAD_COMPNAME_PV(op->op_targ); |
8880
|
56
|
50
|
|
|
|
if (padname) |
8881
|
56
|
|
|
|
|
tmpstr = |
8882
|
112
|
|
|
|
|
Perl_newSVpvf(aTHX_ |
8883
|
|
|
|
|
|
"%s%c...%c", |
8884
|
|
|
|
|
|
padname + 1, |
8885
|
112
|
|
|
|
|
a[0], a[1]); |
8886
|
|
|
|
|
|
} |
8887
|
5662
|
100
|
|
|
|
if (tmpstr) { |
8888
|
4502
|
50
|
|
|
|
name = SvPV_const(tmpstr, len); |
8889
|
4502
|
|
|
|
|
name_utf8 = SvUTF8(tmpstr); |
8890
|
4502
|
|
|
|
|
sv_2mortal(tmpstr); |
8891
|
|
|
|
|
|
} |
8892
|
|
|
|
|
|
} |
8893
|
5662
|
100
|
|
|
|
if (!name) { |
8894
|
|
|
|
|
|
name = "__ANONIO__"; |
8895
|
1160
|
|
|
|
|
len = 10; |
8896
|
|
|
|
|
|
want_dollar = FALSE; |
8897
|
|
|
|
|
|
} |
8898
|
5662
|
|
|
|
|
op_lvalue(kid, type); |
8899
|
|
|
|
|
|
} |
8900
|
133745
|
100
|
|
|
|
if (name) { |
8901
|
|
|
|
|
|
SV *namesv; |
8902
|
127367
|
|
|
|
|
targ = pad_alloc(OP_RV2GV, SVf_READONLY); |
8903
|
127367
|
|
|
|
|
namesv = PAD_SVl(targ); |
8904
|
127367
|
100
|
|
|
|
if (want_dollar && *name != '$') |
|
|
100
|
|
|
|
|
8905
|
5084
|
|
|
|
|
sv_setpvs(namesv, "$"); |
8906
|
|
|
|
|
|
else |
8907
|
122283
|
|
|
|
|
sv_setpvs(namesv, ""); |
8908
|
127367
|
|
|
|
|
sv_catpvn(namesv, name, len); |
8909
|
127367
|
100
|
|
|
|
if ( name_utf8 ) SvUTF8_on(namesv); |
8910
|
|
|
|
|
|
} |
8911
|
|
|
|
|
|
} |
8912
|
330430
|
|
|
|
|
kid->op_sibling = 0; |
8913
|
330430
|
|
|
|
|
kid = newUNOP(OP_RV2GV, flags, scalar(kid)); |
8914
|
330430
|
|
|
|
|
kid->op_targ = targ; |
8915
|
330430
|
|
|
|
|
kid->op_private |= priv; |
8916
|
|
|
|
|
|
} |
8917
|
565215
|
|
|
|
|
kid->op_sibling = sibl; |
8918
|
565215
|
|
|
|
|
*tokid = kid; |
8919
|
|
|
|
|
|
} |
8920
|
566219
|
|
|
|
|
scalar(kid); |
8921
|
566219
|
|
|
|
|
break; |
8922
|
|
|
|
|
|
case OA_SCALARREF: |
8923
|
112947
|
100
|
|
|
|
if ((type == OP_UNDEF || type == OP_POS) |
8924
|
66112
|
50
|
|
|
|
&& numargs == 1 && !(oa >> 4) |
|
|
50
|
|
|
|
|
8925
|
66112
|
100
|
|
|
|
&& kid->op_type == OP_LIST) |
8926
|
4
|
|
|
|
|
return too_many_arguments_pv(o,PL_op_desc[type], 0); |
8927
|
112943
|
|
|
|
|
op_lvalue(scalar(kid), type); |
8928
|
112943
|
|
|
|
|
break; |
8929
|
|
|
|
|
|
} |
8930
|
30672823
|
|
|
|
|
oa >>= 4; |
8931
|
30672823
|
|
|
|
|
tokid = &kid->op_sibling; |
8932
|
35203847
|
|
|
|
|
kid = kid->op_sibling; |
8933
|
|
|
|
|
|
} |
8934
|
|
|
|
|
|
#ifdef PERL_MAD |
8935
|
|
|
|
|
|
if (kid && kid->op_type != OP_STUB) |
8936
|
|
|
|
|
|
return too_many_arguments_pv(o,OP_DESC(o), 0); |
8937
|
|
|
|
|
|
o->op_private |= numargs; |
8938
|
|
|
|
|
|
#else |
8939
|
|
|
|
|
|
/* FIXME - should the numargs move as for the PERL_MAD case? */ |
8940
|
34466163
|
|
|
|
|
o->op_private |= numargs; |
8941
|
34466163
|
100
|
|
|
|
if (kid) |
8942
|
250
|
50
|
|
|
|
return too_many_arguments_pv(o,OP_DESC(o), 0); |
|
|
0
|
|
|
|
|
8943
|
|
|
|
|
|
#endif |
8944
|
34465913
|
|
|
|
|
listkids(o); |
8945
|
|
|
|
|
|
} |
8946
|
1052217
|
100
|
|
|
|
else if (PL_opargs[type] & OA_DEFGV) { |
8947
|
|
|
|
|
|
#ifdef PERL_MAD |
8948
|
|
|
|
|
|
OP *newop = newUNOP(type, 0, newDEFSVOP()); |
8949
|
|
|
|
|
|
op_getmad(o,newop,'O'); |
8950
|
|
|
|
|
|
return newop; |
8951
|
|
|
|
|
|
#else |
8952
|
|
|
|
|
|
/* Ordering of these two is important to keep f_map.t passing. */ |
8953
|
107545
|
|
|
|
|
op_free(o); |
8954
|
107545
|
|
|
|
|
return newUNOP(type, 0, newDEFSVOP()); |
8955
|
|
|
|
|
|
#endif |
8956
|
|
|
|
|
|
} |
8957
|
|
|
|
|
|
|
8958
|
35410585
|
100
|
|
|
|
if (oa) { |
8959
|
12545797
|
100
|
|
|
|
while (oa & OA_OPTIONAL) |
8960
|
1734043
|
|
|
|
|
oa >>= 4; |
8961
|
10811754
|
100
|
|
|
|
if (oa && oa != OA_LIST) |
8962
|
18479782
|
50
|
|
|
|
return too_few_arguments_pv(o,OP_DESC(o), 0); |
|
|
0
|
|
|
|
|
8963
|
|
|
|
|
|
} |
8964
|
|
|
|
|
|
return o; |
8965
|
|
|
|
|
|
} |
8966
|
|
|
|
|
|
|
8967
|
|
|
|
|
|
OP * |
8968
|
8354
|
|
|
|
|
Perl_ck_glob(pTHX_ OP *o) |
8969
|
|
|
|
|
|
{ |
8970
|
|
|
|
|
|
dVAR; |
8971
|
|
|
|
|
|
GV *gv; |
8972
|
8354
|
|
|
|
|
const bool core = o->op_flags & OPf_SPECIAL; |
8973
|
|
|
|
|
|
|
8974
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_GLOB; |
8975
|
|
|
|
|
|
|
8976
|
8354
|
|
|
|
|
o = ck_fun(o); |
8977
|
8354
|
50
|
|
|
|
if ((o->op_flags & OPf_KIDS) && !cLISTOPo->op_first->op_sibling) |
|
|
100
|
|
|
|
|
8978
|
520
|
|
|
|
|
op_append_elem(OP_GLOB, o, newDEFSVOP()); /* glob() => glob($_) */ |
8979
|
|
|
|
|
|
|
8980
|
8354
|
100
|
|
|
|
if (core) gv = NULL; |
8981
|
8366
|
100
|
|
|
|
else if (!((gv = gv_fetchpvs("glob", GV_NOTQUAL, SVt_PVCV)) |
|
|
50
|
|
|
|
|
8982
|
22
|
50
|
|
|
|
&& GvCVu(gv) && GvIMPORTED_CV(gv))) |
|
|
50
|
|
|
|
|
8983
|
|
|
|
|
|
{ |
8984
|
8322
|
|
|
|
|
GV * const * const gvp = |
8985
|
8322
|
|
|
|
|
(GV **)hv_fetchs(PL_globalstash, "glob", FALSE); |
8986
|
8322
|
100
|
|
|
|
gv = gvp ? *gvp : NULL; |
8987
|
|
|
|
|
|
} |
8988
|
|
|
|
|
|
|
8989
|
8354
|
100
|
|
|
|
if (gv && GvCVu(gv) && GvIMPORTED_CV(gv)) { |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
8990
|
|
|
|
|
|
/* convert |
8991
|
|
|
|
|
|
* glob |
8992
|
|
|
|
|
|
* \ null - const(wildcard) |
8993
|
|
|
|
|
|
* into |
8994
|
|
|
|
|
|
* null |
8995
|
|
|
|
|
|
* \ enter |
8996
|
|
|
|
|
|
* \ list |
8997
|
|
|
|
|
|
* \ mark - glob - rv2cv |
8998
|
|
|
|
|
|
* | \ gv(CORE::GLOBAL::glob) |
8999
|
|
|
|
|
|
* | |
9000
|
|
|
|
|
|
* \ null - const(wildcard) |
9001
|
|
|
|
|
|
*/ |
9002
|
46
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; |
9003
|
46
|
|
|
|
|
o->op_targ = pad_alloc(OP_GLOB, SVs_PADTMP); |
9004
|
46
|
|
|
|
|
o = newLISTOP(OP_LIST, 0, o, NULL); |
9005
|
46
|
|
|
|
|
o = newUNOP(OP_ENTERSUB, OPf_STACKED, |
9006
|
|
|
|
|
|
op_append_elem(OP_LIST, o, |
9007
|
|
|
|
|
|
scalar(newUNOP(OP_RV2CV, 0, |
9008
|
|
|
|
|
|
newGVOP(OP_GV, 0, gv))))); |
9009
|
46
|
|
|
|
|
o = newUNOP(OP_NULL, 0, o); |
9010
|
46
|
|
|
|
|
o->op_targ = OP_GLOB; /* hint at what it used to be: eg in newWHILEOP */ |
9011
|
46
|
|
|
|
|
return o; |
9012
|
|
|
|
|
|
} |
9013
|
8308
|
|
|
|
|
else o->op_flags &= ~OPf_SPECIAL; |
9014
|
|
|
|
|
|
#if !defined(PERL_EXTERNAL_GLOB) |
9015
|
8308
|
100
|
|
|
|
if (!PL_globhook) { |
9016
|
5966
|
|
|
|
|
ENTER; |
9017
|
5966
|
|
|
|
|
Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, |
9018
|
|
|
|
|
|
newSVpvs("File::Glob"), NULL, NULL, NULL); |
9019
|
5966
|
|
|
|
|
LEAVE; |
9020
|
|
|
|
|
|
} |
9021
|
|
|
|
|
|
#endif /* !PERL_EXTERNAL_GLOB */ |
9022
|
8308
|
|
|
|
|
gv = (GV *)newSV(0); |
9023
|
8308
|
|
|
|
|
gv_init(gv, 0, "", 0, 0); |
9024
|
8308
|
|
|
|
|
gv_IOadd(gv); |
9025
|
8308
|
|
|
|
|
op_append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv)); |
9026
|
8308
|
|
|
|
|
SvREFCNT_dec_NN(gv); /* newGVOP increased it */ |
9027
|
8308
|
|
|
|
|
scalarkids(o); |
9028
|
8331
|
|
|
|
|
return o; |
9029
|
|
|
|
|
|
} |
9030
|
|
|
|
|
|
|
9031
|
|
|
|
|
|
OP * |
9032
|
796091
|
|
|
|
|
Perl_ck_grep(pTHX_ OP *o) |
9033
|
|
|
|
|
|
{ |
9034
|
|
|
|
|
|
dVAR; |
9035
|
|
|
|
|
|
LOGOP *gwop; |
9036
|
|
|
|
|
|
OP *kid; |
9037
|
796091
|
100
|
|
|
|
const OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE; |
9038
|
|
|
|
|
|
PADOFFSET offset; |
9039
|
|
|
|
|
|
|
9040
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_GREP; |
9041
|
|
|
|
|
|
|
9042
|
796091
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_GREPSTART]; |
9043
|
|
|
|
|
|
/* don't allocate gwop here, as we may leak it if PL_parser->error_count > 0 */ |
9044
|
|
|
|
|
|
|
9045
|
796091
|
100
|
|
|
|
if (o->op_flags & OPf_STACKED) { |
9046
|
391739
|
|
|
|
|
kid = cUNOPx(cLISTOPo->op_first->op_sibling)->op_first; |
9047
|
391739
|
100
|
|
|
|
if (kid->op_type != OP_SCOPE && kid->op_type != OP_LEAVE) |
9048
|
2
|
|
|
|
|
return no_fh_allowed(o); |
9049
|
391737
|
|
|
|
|
o->op_flags &= ~OPf_STACKED; |
9050
|
|
|
|
|
|
} |
9051
|
796089
|
|
|
|
|
kid = cLISTOPo->op_first->op_sibling; |
9052
|
796089
|
100
|
|
|
|
if (type == OP_MAPWHILE) |
9053
|
450205
|
|
|
|
|
list(kid); |
9054
|
|
|
|
|
|
else |
9055
|
345884
|
|
|
|
|
scalar(kid); |
9056
|
796089
|
|
|
|
|
o = ck_fun(o); |
9057
|
796089
|
50
|
|
|
|
if (PL_parser && PL_parser->error_count) |
|
|
50
|
|
|
|
|
9058
|
|
|
|
|
|
return o; |
9059
|
796089
|
|
|
|
|
kid = cLISTOPo->op_first->op_sibling; |
9060
|
796089
|
50
|
|
|
|
if (kid->op_type != OP_NULL) |
9061
|
0
|
|
|
|
|
Perl_croak(aTHX_ "panic: ck_grep, type=%u", (unsigned) kid->op_type); |
9062
|
796089
|
|
|
|
|
kid = kUNOP->op_first; |
9063
|
|
|
|
|
|
|
9064
|
796089
|
|
|
|
|
NewOp(1101, gwop, 1, LOGOP); |
9065
|
796089
|
|
|
|
|
gwop->op_type = type; |
9066
|
796089
|
|
|
|
|
gwop->op_ppaddr = PL_ppaddr[type]; |
9067
|
796089
|
|
|
|
|
gwop->op_first = o; |
9068
|
796089
|
|
|
|
|
gwop->op_flags |= OPf_KIDS; |
9069
|
796089
|
100
|
|
|
|
gwop->op_other = LINKLIST(kid); |
9070
|
796089
|
|
|
|
|
kid->op_next = (OP*)gwop; |
9071
|
796089
|
|
|
|
|
offset = pad_findmy_pvs("$_", 0); |
9072
|
796089
|
100
|
|
|
|
if (offset == NOT_IN_PAD || PAD_COMPNAME_FLAGS_isOUR(offset)) { |
|
|
100
|
|
|
|
|
9073
|
796071
|
|
|
|
|
o->op_private = gwop->op_private = 0; |
9074
|
796071
|
|
|
|
|
gwop->op_targ = pad_alloc(type, SVs_PADTMP); |
9075
|
|
|
|
|
|
} |
9076
|
|
|
|
|
|
else { |
9077
|
18
|
|
|
|
|
o->op_private = gwop->op_private = OPpGREP_LEX; |
9078
|
18
|
|
|
|
|
gwop->op_targ = o->op_targ = offset; |
9079
|
|
|
|
|
|
} |
9080
|
|
|
|
|
|
|
9081
|
796089
|
|
|
|
|
kid = cLISTOPo->op_first->op_sibling; |
9082
|
2510327
|
100
|
|
|
|
for (kid = kid->op_sibling; kid; kid = kid->op_sibling) |
9083
|
1714237
|
|
|
|
|
op_lvalue(kid, OP_GREPSTART); |
9084
|
|
|
|
|
|
|
9085
|
|
|
|
|
|
return (OP*)gwop; |
9086
|
|
|
|
|
|
} |
9087
|
|
|
|
|
|
|
9088
|
|
|
|
|
|
OP * |
9089
|
61086
|
|
|
|
|
Perl_ck_index(pTHX_ OP *o) |
9090
|
|
|
|
|
|
{ |
9091
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_INDEX; |
9092
|
|
|
|
|
|
|
9093
|
61086
|
50
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
9094
|
61086
|
|
|
|
|
OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ |
9095
|
61086
|
50
|
|
|
|
if (kid) |
9096
|
61086
|
|
|
|
|
kid = kid->op_sibling; /* get past "big" */ |
9097
|
61086
|
100
|
|
|
|
if (kid && kid->op_type == OP_CONST) { |
|
|
100
|
|
|
|
|
9098
|
33027
|
|
|
|
|
const bool save_taint = TAINT_get; |
9099
|
33027
|
|
|
|
|
SV *sv = kSVOP->op_sv; |
9100
|
33027
|
100
|
|
|
|
if ((!SvPOK(sv) || SvNIOKp(sv)) && SvOK(sv) && !SvROK(sv)) { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
9101
|
24
|
|
|
|
|
sv = newSV(0); |
9102
|
24
|
|
|
|
|
sv_copypv(sv, kSVOP->op_sv); |
9103
|
24
|
|
|
|
|
SvREFCNT_dec_NN(kSVOP->op_sv); |
9104
|
24
|
|
|
|
|
kSVOP->op_sv = sv; |
9105
|
|
|
|
|
|
} |
9106
|
33027
|
100
|
|
|
|
if (SvOK(sv)) fbm_compile(sv, 0); |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
9107
|
33027
|
|
|
|
|
TAINT_set(save_taint); |
9108
|
|
|
|
|
|
#ifdef NO_TAINT_SUPPORT |
9109
|
|
|
|
|
|
PERL_UNUSED_VAR(save_taint); |
9110
|
|
|
|
|
|
#endif |
9111
|
|
|
|
|
|
} |
9112
|
|
|
|
|
|
} |
9113
|
61086
|
|
|
|
|
return ck_fun(o); |
9114
|
|
|
|
|
|
} |
9115
|
|
|
|
|
|
|
9116
|
|
|
|
|
|
OP * |
9117
|
1345913
|
|
|
|
|
Perl_ck_lfun(pTHX_ OP *o) |
9118
|
|
|
|
|
|
{ |
9119
|
1345913
|
|
|
|
|
const OPCODE type = o->op_type; |
9120
|
|
|
|
|
|
|
9121
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_LFUN; |
9122
|
|
|
|
|
|
|
9123
|
1345913
|
|
|
|
|
return modkids(ck_fun(o), type); |
9124
|
|
|
|
|
|
} |
9125
|
|
|
|
|
|
|
9126
|
|
|
|
|
|
OP * |
9127
|
2795712
|
|
|
|
|
Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */ |
9128
|
|
|
|
|
|
{ |
9129
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_DEFINED; |
9130
|
|
|
|
|
|
|
9131
|
2795712
|
100
|
|
|
|
if ((o->op_flags & OPf_KIDS)) { |
9132
|
2770842
|
|
|
|
|
switch (cUNOPo->op_first->op_type) { |
9133
|
|
|
|
|
|
case OP_RV2AV: |
9134
|
|
|
|
|
|
case OP_PADAV: |
9135
|
|
|
|
|
|
case OP_AASSIGN: /* Is this a good idea? */ |
9136
|
24
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED), |
9137
|
|
|
|
|
|
"defined(@array) is deprecated"); |
9138
|
24
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED), |
9139
|
|
|
|
|
|
"\t(Maybe you should just omit the defined()?)\n"); |
9140
|
24
|
|
|
|
|
break; |
9141
|
|
|
|
|
|
case OP_RV2HV: |
9142
|
|
|
|
|
|
case OP_PADHV: |
9143
|
56
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED), |
9144
|
|
|
|
|
|
"defined(%%hash) is deprecated"); |
9145
|
56
|
|
|
|
|
Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED), |
9146
|
|
|
|
|
|
"\t(Maybe you should just omit the defined()?)\n"); |
9147
|
56
|
|
|
|
|
break; |
9148
|
|
|
|
|
|
default: |
9149
|
|
|
|
|
|
/* no warning */ |
9150
|
|
|
|
|
|
break; |
9151
|
|
|
|
|
|
} |
9152
|
|
|
|
|
|
} |
9153
|
2795712
|
|
|
|
|
return ck_rfun(o); |
9154
|
|
|
|
|
|
} |
9155
|
|
|
|
|
|
|
9156
|
|
|
|
|
|
OP * |
9157
|
72242
|
|
|
|
|
Perl_ck_readline(pTHX_ OP *o) |
9158
|
|
|
|
|
|
{ |
9159
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_READLINE; |
9160
|
|
|
|
|
|
|
9161
|
72242
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
9162
|
72230
|
|
|
|
|
OP *kid = cLISTOPo->op_first; |
9163
|
72230
|
100
|
|
|
|
if (kid->op_type == OP_RV2GV) kid->op_private |= OPpALLOW_FAKE; |
9164
|
|
|
|
|
|
} |
9165
|
|
|
|
|
|
else { |
9166
|
12
|
|
|
|
|
OP * const newop |
9167
|
12
|
|
|
|
|
= newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, PL_argvgv)); |
9168
|
|
|
|
|
|
#ifdef PERL_MAD |
9169
|
|
|
|
|
|
op_getmad(o,newop,'O'); |
9170
|
|
|
|
|
|
#else |
9171
|
12
|
|
|
|
|
op_free(o); |
9172
|
|
|
|
|
|
#endif |
9173
|
37747
|
|
|
|
|
return newop; |
9174
|
|
|
|
|
|
} |
9175
|
|
|
|
|
|
return o; |
9176
|
|
|
|
|
|
} |
9177
|
|
|
|
|
|
|
9178
|
|
|
|
|
|
OP * |
9179
|
2796604
|
|
|
|
|
Perl_ck_rfun(pTHX_ OP *o) |
9180
|
|
|
|
|
|
{ |
9181
|
2796604
|
|
|
|
|
const OPCODE type = o->op_type; |
9182
|
|
|
|
|
|
|
9183
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_RFUN; |
9184
|
|
|
|
|
|
|
9185
|
5593208
|
|
|
|
|
return refkids(ck_fun(o), type); |
9186
|
|
|
|
|
|
} |
9187
|
|
|
|
|
|
|
9188
|
|
|
|
|
|
OP * |
9189
|
1158590
|
|
|
|
|
Perl_ck_listiob(pTHX_ OP *o) |
9190
|
|
|
|
|
|
{ |
9191
|
|
|
|
|
|
OP *kid; |
9192
|
|
|
|
|
|
|
9193
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_LISTIOB; |
9194
|
|
|
|
|
|
|
9195
|
1158590
|
|
|
|
|
kid = cLISTOPo->op_first; |
9196
|
1158590
|
50
|
|
|
|
if (!kid) { |
9197
|
0
|
|
|
|
|
o = force_list(o); |
9198
|
0
|
|
|
|
|
kid = cLISTOPo->op_first; |
9199
|
|
|
|
|
|
} |
9200
|
1158590
|
50
|
|
|
|
if (kid->op_type == OP_PUSHMARK) |
9201
|
1158590
|
|
|
|
|
kid = kid->op_sibling; |
9202
|
1158590
|
100
|
|
|
|
if (kid && o->op_flags & OPf_STACKED) |
|
|
100
|
|
|
|
|
9203
|
353853
|
|
|
|
|
kid = kid->op_sibling; |
9204
|
804737
|
100
|
|
|
|
else if (kid && !kid->op_sibling) { /* print HANDLE; */ |
|
|
100
|
|
|
|
|
9205
|
366481
|
100
|
|
|
|
if (kid->op_type == OP_CONST && kid->op_private & OPpCONST_BARE |
|
|
100
|
|
|
|
|
9206
|
24
|
100
|
|
|
|
&& !kid->op_folded) { |
9207
|
16
|
|
|
|
|
o->op_flags |= OPf_STACKED; /* make it a filehandle */ |
9208
|
16
|
|
|
|
|
kid = newUNOP(OP_RV2GV, OPf_REF, scalar(kid)); |
9209
|
16
|
|
|
|
|
cLISTOPo->op_first->op_sibling = kid; |
9210
|
16
|
|
|
|
|
cLISTOPo->op_last = kid; |
9211
|
16
|
|
|
|
|
kid = kid->op_sibling; |
9212
|
|
|
|
|
|
} |
9213
|
|
|
|
|
|
} |
9214
|
|
|
|
|
|
|
9215
|
1158590
|
100
|
|
|
|
if (!kid) |
9216
|
1830
|
|
|
|
|
op_append_elem(o->op_type, o, newDEFSVOP()); |
9217
|
|
|
|
|
|
|
9218
|
1158590
|
100
|
|
|
|
if (o->op_type == OP_PRTF) return modkids(listkids(o), OP_PRTF); |
9219
|
1011716
|
|
|
|
|
return listkids(o); |
9220
|
|
|
|
|
|
} |
9221
|
|
|
|
|
|
|
9222
|
|
|
|
|
|
OP * |
9223
|
966
|
|
|
|
|
Perl_ck_smartmatch(pTHX_ OP *o) |
9224
|
|
|
|
|
|
{ |
9225
|
|
|
|
|
|
dVAR; |
9226
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_SMARTMATCH; |
9227
|
966
|
100
|
|
|
|
if (0 == (o->op_flags & OPf_SPECIAL)) { |
9228
|
724
|
|
|
|
|
OP *first = cBINOPo->op_first; |
9229
|
724
|
|
|
|
|
OP *second = first->op_sibling; |
9230
|
|
|
|
|
|
|
9231
|
|
|
|
|
|
/* Implicitly take a reference to an array or hash */ |
9232
|
724
|
|
|
|
|
first->op_sibling = NULL; |
9233
|
724
|
|
|
|
|
first = cBINOPo->op_first = ref_array_or_hash(first); |
9234
|
724
|
|
|
|
|
second = first->op_sibling = ref_array_or_hash(second); |
9235
|
|
|
|
|
|
|
9236
|
|
|
|
|
|
/* Implicitly take a reference to a regular expression */ |
9237
|
724
|
100
|
|
|
|
if (first->op_type == OP_MATCH) { |
9238
|
22
|
|
|
|
|
first->op_type = OP_QR; |
9239
|
22
|
|
|
|
|
first->op_ppaddr = PL_ppaddr[OP_QR]; |
9240
|
|
|
|
|
|
} |
9241
|
724
|
100
|
|
|
|
if (second->op_type == OP_MATCH) { |
9242
|
12
|
|
|
|
|
second->op_type = OP_QR; |
9243
|
12
|
|
|
|
|
second->op_ppaddr = PL_ppaddr[OP_QR]; |
9244
|
|
|
|
|
|
} |
9245
|
|
|
|
|
|
} |
9246
|
|
|
|
|
|
|
9247
|
966
|
|
|
|
|
return o; |
9248
|
|
|
|
|
|
} |
9249
|
|
|
|
|
|
|
9250
|
|
|
|
|
|
|
9251
|
|
|
|
|
|
OP * |
9252
|
20112516
|
|
|
|
|
Perl_ck_sassign(pTHX_ OP *o) |
9253
|
|
|
|
|
|
{ |
9254
|
|
|
|
|
|
dVAR; |
9255
|
20112516
|
|
|
|
|
OP * const kid = cLISTOPo->op_first; |
9256
|
|
|
|
|
|
|
9257
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_SASSIGN; |
9258
|
|
|
|
|
|
|
9259
|
|
|
|
|
|
/* has a disposable target? */ |
9260
|
20112516
|
100
|
|
|
|
if ((PL_opargs[kid->op_type] & OA_TARGLEX) |
9261
|
1493797
|
100
|
|
|
|
&& !(kid->op_flags & OPf_STACKED) |
9262
|
|
|
|
|
|
/* Cannot steal the second time! */ |
9263
|
1328691
|
|
|
|
|
&& !(kid->op_private & OPpTARGET_MY) |
9264
|
|
|
|
|
|
/* Keep the full thing for madskills */ |
9265
|
1328691
|
100
|
|
|
|
&& !PL_madskills |
9266
|
|
|
|
|
|
) |
9267
|
|
|
|
|
|
{ |
9268
|
1328279
|
|
|
|
|
OP * const kkid = kid->op_sibling; |
9269
|
|
|
|
|
|
|
9270
|
|
|
|
|
|
/* Can just relocate the target. */ |
9271
|
1328279
|
100
|
|
|
|
if (kkid && kkid->op_type == OP_PADSV |
|
|
100
|
|
|
|
|
9272
|
1071181
|
100
|
|
|
|
&& !(kkid->op_private & OPpLVAL_INTRO)) |
9273
|
|
|
|
|
|
{ |
9274
|
594884
|
|
|
|
|
kid->op_targ = kkid->op_targ; |
9275
|
594884
|
|
|
|
|
kkid->op_targ = 0; |
9276
|
|
|
|
|
|
/* Now we do not need PADSV and SASSIGN. */ |
9277
|
594884
|
|
|
|
|
kid->op_sibling = o->op_sibling; /* NULL */ |
9278
|
594884
|
|
|
|
|
cLISTOPo->op_first = NULL; |
9279
|
594884
|
|
|
|
|
op_free(o); |
9280
|
594884
|
|
|
|
|
op_free(kkid); |
9281
|
594884
|
|
|
|
|
kid->op_private |= OPpTARGET_MY; /* Used for context settings */ |
9282
|
594884
|
|
|
|
|
return kid; |
9283
|
|
|
|
|
|
} |
9284
|
|
|
|
|
|
} |
9285
|
19517632
|
100
|
|
|
|
if (kid->op_sibling) { |
9286
|
19150901
|
|
|
|
|
OP *kkid = kid->op_sibling; |
9287
|
|
|
|
|
|
/* For state variable assignment, kkid is a list op whose op_last |
9288
|
|
|
|
|
|
is a padsv. */ |
9289
|
21887053
|
100
|
|
|
|
if ((kkid->op_type == OP_PADSV || |
|
|
100
|
|
|
|
|
9290
|
2736162
|
50
|
|
|
|
(kkid->op_type == OP_LIST && |
9291
|
10
|
|
|
|
|
(kkid = cLISTOPx(kkid)->op_last)->op_type == OP_PADSV |
9292
|
|
|
|
|
|
) |
9293
|
|
|
|
|
|
) |
9294
|
13406839
|
100
|
|
|
|
&& (kkid->op_private & OPpLVAL_INTRO) |
9295
|
8915672
|
100
|
|
|
|
&& SvPAD_STATE(*av_fetch(PL_comppad_name, kkid->op_targ, FALSE))) { |
9296
|
64
|
|
|
|
|
const PADOFFSET target = kkid->op_targ; |
9297
|
64
|
|
|
|
|
OP *const other = newOP(OP_PADSV, |
9298
|
|
|
|
|
|
kkid->op_flags |
9299
|
|
|
|
|
|
| ((kkid->op_private & ~OPpLVAL_INTRO) << 8)); |
9300
|
64
|
|
|
|
|
OP *const first = newOP(OP_NULL, 0); |
9301
|
64
|
|
|
|
|
OP *const nullop = newCONDOP(0, first, o, other); |
9302
|
64
|
|
|
|
|
OP *const condop = first->op_next; |
9303
|
|
|
|
|
|
/* hijacking PADSTALE for uninitialized state variables */ |
9304
|
64
|
|
|
|
|
SvPADSTALE_on(PAD_SVl(target)); |
9305
|
|
|
|
|
|
|
9306
|
64
|
|
|
|
|
condop->op_type = OP_ONCE; |
9307
|
64
|
|
|
|
|
condop->op_ppaddr = PL_ppaddr[OP_ONCE]; |
9308
|
64
|
|
|
|
|
condop->op_targ = target; |
9309
|
64
|
|
|
|
|
other->op_targ = target; |
9310
|
|
|
|
|
|
|
9311
|
|
|
|
|
|
/* Because we change the type of the op here, we will skip the |
9312
|
|
|
|
|
|
assignment binop->op_last = binop->op_first->op_sibling; at the |
9313
|
|
|
|
|
|
end of Perl_newBINOP(). So need to do it here. */ |
9314
|
64
|
|
|
|
|
cBINOPo->op_last = cBINOPo->op_first->op_sibling; |
9315
|
|
|
|
|
|
|
9316
|
10414267
|
|
|
|
|
return nullop; |
9317
|
|
|
|
|
|
} |
9318
|
|
|
|
|
|
} |
9319
|
|
|
|
|
|
return o; |
9320
|
|
|
|
|
|
} |
9321
|
|
|
|
|
|
|
9322
|
|
|
|
|
|
OP * |
9323
|
4542868
|
|
|
|
|
Perl_ck_match(pTHX_ OP *o) |
9324
|
|
|
|
|
|
{ |
9325
|
|
|
|
|
|
dVAR; |
9326
|
|
|
|
|
|
|
9327
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_MATCH; |
9328
|
|
|
|
|
|
|
9329
|
4542868
|
100
|
|
|
|
if (o->op_type != OP_QR && PL_compcv) { |
|
|
100
|
|
|
|
|
9330
|
4088622
|
|
|
|
|
const PADOFFSET offset = pad_findmy_pvs("$_", 0); |
9331
|
4088622
|
100
|
|
|
|
if (offset != NOT_IN_PAD && !(PAD_COMPNAME_FLAGS_isOUR(offset))) { |
|
|
100
|
|
|
|
|
9332
|
100
|
|
|
|
|
o->op_targ = offset; |
9333
|
100
|
|
|
|
|
o->op_private |= OPpTARGET_MY; |
9334
|
|
|
|
|
|
} |
9335
|
|
|
|
|
|
} |
9336
|
4542868
|
100
|
|
|
|
if (o->op_type == OP_MATCH || o->op_type == OP_QR) |
9337
|
3229301
|
|
|
|
|
o->op_private |= OPpRUNTIME; |
9338
|
4542868
|
|
|
|
|
return o; |
9339
|
|
|
|
|
|
} |
9340
|
|
|
|
|
|
|
9341
|
|
|
|
|
|
OP * |
9342
|
12082680
|
|
|
|
|
Perl_ck_method(pTHX_ OP *o) |
9343
|
|
|
|
|
|
{ |
9344
|
12082680
|
|
|
|
|
OP * const kid = cUNOPo->op_first; |
9345
|
|
|
|
|
|
|
9346
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_METHOD; |
9347
|
|
|
|
|
|
|
9348
|
12082680
|
100
|
|
|
|
if (kid->op_type == OP_CONST) { |
9349
|
12013932
|
|
|
|
|
SV* sv = kSVOP->op_sv; |
9350
|
12013932
|
|
|
|
|
const char * const method = SvPVX_const(sv); |
9351
|
12013932
|
100
|
|
|
|
if (!(strchr(method, ':') || strchr(method, '\''))) { |
|
|
50
|
|
|
|
|
9352
|
|
|
|
|
|
OP *cmop; |
9353
|
11896902
|
50
|
|
|
|
if (!SvIsCOW_shared_hash(sv)) { |
|
|
50
|
|
|
|
|
9354
|
11896902
|
100
|
|
|
|
sv = newSVpvn_share(method, SvUTF8(sv) ? -(I32)SvCUR(sv) : (I32)SvCUR(sv), 0); |
9355
|
|
|
|
|
|
} |
9356
|
|
|
|
|
|
else { |
9357
|
0
|
|
|
|
|
kSVOP->op_sv = NULL; |
9358
|
|
|
|
|
|
} |
9359
|
11896902
|
|
|
|
|
cmop = newSVOP(OP_METHOD_NAMED, 0, sv); |
9360
|
|
|
|
|
|
#ifdef PERL_MAD |
9361
|
|
|
|
|
|
op_getmad(o,cmop,'O'); |
9362
|
|
|
|
|
|
#else |
9363
|
11896902
|
|
|
|
|
op_free(o); |
9364
|
|
|
|
|
|
#endif |
9365
|
11993571
|
|
|
|
|
return cmop; |
9366
|
|
|
|
|
|
} |
9367
|
|
|
|
|
|
} |
9368
|
|
|
|
|
|
return o; |
9369
|
|
|
|
|
|
} |
9370
|
|
|
|
|
|
|
9371
|
|
|
|
|
|
OP * |
9372
|
458599954
|
|
|
|
|
Perl_ck_null(pTHX_ OP *o) |
9373
|
|
|
|
|
|
{ |
9374
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_NULL; |
9375
|
|
|
|
|
|
PERL_UNUSED_CONTEXT; |
9376
|
458599954
|
|
|
|
|
return o; |
9377
|
|
|
|
|
|
} |
9378
|
|
|
|
|
|
|
9379
|
|
|
|
|
|
OP * |
9380
|
189134
|
|
|
|
|
Perl_ck_open(pTHX_ OP *o) |
9381
|
|
|
|
|
|
{ |
9382
|
|
|
|
|
|
dVAR; |
9383
|
189134
|
|
|
|
|
HV * const table = GvHV(PL_hintgv); |
9384
|
|
|
|
|
|
|
9385
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_OPEN; |
9386
|
|
|
|
|
|
|
9387
|
189134
|
50
|
|
|
|
if (table) { |
9388
|
189134
|
|
|
|
|
SV **svp = hv_fetchs(table, "open_IN", FALSE); |
9389
|
189134
|
100
|
|
|
|
if (svp && *svp) { |
|
|
50
|
|
|
|
|
9390
|
12
|
|
|
|
|
STRLEN len = 0; |
9391
|
12
|
50
|
|
|
|
const char *d = SvPV_const(*svp, len); |
9392
|
12
|
|
|
|
|
const I32 mode = mode_from_discipline(d, len); |
9393
|
|
|
|
|
|
if (mode & O_BINARY) |
9394
|
|
|
|
|
|
o->op_private |= OPpOPEN_IN_RAW; |
9395
|
|
|
|
|
|
else if (mode & O_TEXT) |
9396
|
|
|
|
|
|
o->op_private |= OPpOPEN_IN_CRLF; |
9397
|
|
|
|
|
|
} |
9398
|
|
|
|
|
|
|
9399
|
189134
|
|
|
|
|
svp = hv_fetchs(table, "open_OUT", FALSE); |
9400
|
189134
|
50
|
|
|
|
if (svp && *svp) { |
|
|
0
|
|
|
|
|
9401
|
0
|
|
|
|
|
STRLEN len = 0; |
9402
|
0
|
0
|
|
|
|
const char *d = SvPV_const(*svp, len); |
9403
|
0
|
|
|
|
|
const I32 mode = mode_from_discipline(d, len); |
9404
|
|
|
|
|
|
if (mode & O_BINARY) |
9405
|
|
|
|
|
|
o->op_private |= OPpOPEN_OUT_RAW; |
9406
|
|
|
|
|
|
else if (mode & O_TEXT) |
9407
|
|
|
|
|
|
o->op_private |= OPpOPEN_OUT_CRLF; |
9408
|
|
|
|
|
|
} |
9409
|
|
|
|
|
|
} |
9410
|
189134
|
100
|
|
|
|
if (o->op_type == OP_BACKTICK) { |
9411
|
52086
|
50
|
|
|
|
if (!(o->op_flags & OPf_KIDS)) { |
9412
|
0
|
|
|
|
|
OP * const newop = newUNOP(OP_BACKTICK, 0, newDEFSVOP()); |
9413
|
|
|
|
|
|
#ifdef PERL_MAD |
9414
|
|
|
|
|
|
op_getmad(o,newop,'O'); |
9415
|
|
|
|
|
|
#else |
9416
|
0
|
|
|
|
|
op_free(o); |
9417
|
|
|
|
|
|
#endif |
9418
|
0
|
|
|
|
|
return newop; |
9419
|
|
|
|
|
|
} |
9420
|
|
|
|
|
|
return o; |
9421
|
|
|
|
|
|
} |
9422
|
|
|
|
|
|
{ |
9423
|
|
|
|
|
|
/* In case of three-arg dup open remove strictness |
9424
|
|
|
|
|
|
* from the last arg if it is a bareword. */ |
9425
|
137048
|
|
|
|
|
OP * const first = cLISTOPx(o)->op_first; /* The pushmark. */ |
9426
|
137048
|
|
|
|
|
OP * const last = cLISTOPx(o)->op_last; /* The bareword. */ |
9427
|
|
|
|
|
|
OP *oa; |
9428
|
|
|
|
|
|
const char *mode; |
9429
|
|
|
|
|
|
|
9430
|
137048
|
100
|
|
|
|
if ((last->op_type == OP_CONST) && /* The bareword. */ |
9431
|
22430
|
100
|
|
|
|
(last->op_private & OPpCONST_BARE) && |
9432
|
2
|
50
|
|
|
|
(last->op_private & OPpCONST_STRICT) && |
9433
|
3
|
50
|
|
|
|
(oa = first->op_sibling) && /* The fh. */ |
9434
|
3
|
50
|
|
|
|
(oa = oa->op_sibling) && /* The mode. */ |
9435
|
3
|
50
|
|
|
|
(oa->op_type == OP_CONST) && |
9436
|
3
|
50
|
|
|
|
SvPOK(((SVOP*)oa)->op_sv) && |
9437
|
3
|
50
|
|
|
|
(mode = SvPVX_const(((SVOP*)oa)->op_sv)) && |
9438
|
4
|
50
|
|
|
|
mode[0] == '>' && mode[1] == '&' && /* A dup open. */ |
|
|
50
|
|
|
|
|
9439
|
2
|
|
|
|
|
(last == oa->op_sibling)) /* The bareword. */ |
9440
|
2
|
|
|
|
|
last->op_private &= ~OPpCONST_STRICT; |
9441
|
|
|
|
|
|
} |
9442
|
164171
|
|
|
|
|
return ck_fun(o); |
9443
|
|
|
|
|
|
} |
9444
|
|
|
|
|
|
|
9445
|
|
|
|
|
|
OP * |
9446
|
200138
|
|
|
|
|
Perl_ck_repeat(pTHX_ OP *o) |
9447
|
|
|
|
|
|
{ |
9448
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_REPEAT; |
9449
|
|
|
|
|
|
|
9450
|
200138
|
100
|
|
|
|
if (cBINOPo->op_first->op_flags & OPf_PARENS) { |
9451
|
52160
|
|
|
|
|
o->op_private |= OPpREPEAT_DOLIST; |
9452
|
52160
|
|
|
|
|
cBINOPo->op_first = force_list(cBINOPo->op_first); |
9453
|
|
|
|
|
|
} |
9454
|
|
|
|
|
|
else |
9455
|
147978
|
|
|
|
|
scalar(o); |
9456
|
200138
|
|
|
|
|
return o; |
9457
|
|
|
|
|
|
} |
9458
|
|
|
|
|
|
|
9459
|
|
|
|
|
|
OP * |
9460
|
5586131
|
|
|
|
|
Perl_ck_require(pTHX_ OP *o) |
9461
|
|
|
|
|
|
{ |
9462
|
|
|
|
|
|
dVAR; |
9463
|
|
|
|
|
|
GV* gv = NULL; |
9464
|
|
|
|
|
|
|
9465
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_REQUIRE; |
9466
|
|
|
|
|
|
|
9467
|
5586131
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { /* Shall we supply missing .pm? */ |
9468
|
5586127
|
|
|
|
|
SVOP * const kid = (SVOP*)cUNOPo->op_first; |
9469
|
|
|
|
|
|
|
9470
|
5586127
|
100
|
|
|
|
if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) { |
|
|
100
|
|
|
|
|
9471
|
5412696
|
|
|
|
|
SV * const sv = kid->op_sv; |
9472
|
5412696
|
|
|
|
|
U32 was_readonly = SvREADONLY(sv); |
9473
|
|
|
|
|
|
char *s; |
9474
|
|
|
|
|
|
STRLEN len; |
9475
|
|
|
|
|
|
const char *end; |
9476
|
|
|
|
|
|
|
9477
|
5412696
|
50
|
|
|
|
if (was_readonly) { |
9478
|
5412696
|
|
|
|
|
SvREADONLY_off(sv); |
9479
|
|
|
|
|
|
} |
9480
|
5412696
|
50
|
|
|
|
if (SvIsCOW(sv)) sv_force_normal_flags(sv, 0); |
9481
|
|
|
|
|
|
|
9482
|
5412696
|
|
|
|
|
s = SvPVX(sv); |
9483
|
5412696
|
|
|
|
|
len = SvCUR(sv); |
9484
|
5412696
|
|
|
|
|
end = s + len; |
9485
|
90357863
|
100
|
|
|
|
for (; s < end; s++) { |
9486
|
84945167
|
100
|
|
|
|
if (*s == ':' && s[1] == ':') { |
|
|
50
|
|
|
|
|
9487
|
10270796
|
|
|
|
|
*s = '/'; |
9488
|
10270796
|
|
|
|
|
Move(s+2, s+1, end - s - 1, char); |
9489
|
10270796
|
|
|
|
|
--end; |
9490
|
|
|
|
|
|
} |
9491
|
|
|
|
|
|
} |
9492
|
5412696
|
|
|
|
|
SvEND_set(sv, end); |
9493
|
5412696
|
|
|
|
|
sv_catpvs(sv, ".pm"); |
9494
|
5412696
|
|
|
|
|
SvFLAGS(sv) |= was_readonly; |
9495
|
|
|
|
|
|
} |
9496
|
|
|
|
|
|
} |
9497
|
|
|
|
|
|
|
9498
|
5586131
|
100
|
|
|
|
if (!(o->op_flags & OPf_SPECIAL)) { /* Wasn't written as CORE::require */ |
9499
|
|
|
|
|
|
/* handle override, if any */ |
9500
|
5586121
|
|
|
|
|
gv = gv_fetchpvs("require", GV_NOTQUAL, SVt_PVCV); |
9501
|
5586121
|
50
|
|
|
|
if (!(gv && GvCVu(gv) && GvIMPORTED_CV(gv))) { |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
9502
|
5586121
|
|
|
|
|
GV * const * const gvp = (GV**)hv_fetchs(PL_globalstash, "require", FALSE); |
9503
|
5586121
|
100
|
|
|
|
gv = gvp ? *gvp : NULL; |
9504
|
|
|
|
|
|
} |
9505
|
|
|
|
|
|
} |
9506
|
|
|
|
|
|
|
9507
|
5586131
|
100
|
|
|
|
if (gv && GvCVu(gv) && GvIMPORTED_CV(gv)) { |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
9508
|
|
|
|
|
|
OP *kid, *newop; |
9509
|
512
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
9510
|
508
|
|
|
|
|
kid = cUNOPo->op_first; |
9511
|
508
|
|
|
|
|
cUNOPo->op_first = NULL; |
9512
|
|
|
|
|
|
} |
9513
|
|
|
|
|
|
else { |
9514
|
4
|
|
|
|
|
kid = newDEFSVOP(); |
9515
|
|
|
|
|
|
} |
9516
|
|
|
|
|
|
#ifndef PERL_MAD |
9517
|
512
|
|
|
|
|
op_free(o); |
9518
|
|
|
|
|
|
#endif |
9519
|
512
|
|
|
|
|
newop = newUNOP(OP_ENTERSUB, OPf_STACKED, |
9520
|
|
|
|
|
|
op_append_elem(OP_LIST, kid, |
9521
|
|
|
|
|
|
scalar(newUNOP(OP_RV2CV, 0, |
9522
|
|
|
|
|
|
newGVOP(OP_GV, 0, |
9523
|
|
|
|
|
|
gv))))); |
9524
|
|
|
|
|
|
op_getmad(o,newop,'O'); |
9525
|
512
|
|
|
|
|
return newop; |
9526
|
|
|
|
|
|
} |
9527
|
|
|
|
|
|
|
9528
|
5585875
|
|
|
|
|
return scalar(ck_fun(o)); |
9529
|
|
|
|
|
|
} |
9530
|
|
|
|
|
|
|
9531
|
|
|
|
|
|
OP * |
9532
|
6095549
|
|
|
|
|
Perl_ck_return(pTHX_ OP *o) |
9533
|
|
|
|
|
|
{ |
9534
|
|
|
|
|
|
dVAR; |
9535
|
|
|
|
|
|
OP *kid; |
9536
|
|
|
|
|
|
|
9537
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_RETURN; |
9538
|
|
|
|
|
|
|
9539
|
6095549
|
|
|
|
|
kid = cLISTOPo->op_first->op_sibling; |
9540
|
6095549
|
100
|
|
|
|
if (CvLVALUE(PL_compcv)) { |
9541
|
67
|
100
|
|
|
|
for (; kid; kid = kid->op_sibling) |
9542
|
44
|
|
|
|
|
op_lvalue(kid, OP_LEAVESUBLV); |
9543
|
|
|
|
|
|
} |
9544
|
|
|
|
|
|
|
9545
|
6095549
|
|
|
|
|
return o; |
9546
|
|
|
|
|
|
} |
9547
|
|
|
|
|
|
|
9548
|
|
|
|
|
|
OP * |
9549
|
35388
|
|
|
|
|
Perl_ck_select(pTHX_ OP *o) |
9550
|
|
|
|
|
|
{ |
9551
|
|
|
|
|
|
dVAR; |
9552
|
|
|
|
|
|
OP* kid; |
9553
|
|
|
|
|
|
|
9554
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_SELECT; |
9555
|
|
|
|
|
|
|
9556
|
35388
|
50
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
9557
|
35388
|
|
|
|
|
kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ |
9558
|
35388
|
100
|
|
|
|
if (kid && kid->op_sibling) { |
|
|
100
|
|
|
|
|
9559
|
2636
|
|
|
|
|
o->op_type = OP_SSELECT; |
9560
|
2636
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_SSELECT]; |
9561
|
2636
|
|
|
|
|
o = ck_fun(o); |
9562
|
2636
|
|
|
|
|
return fold_constants(op_integerize(op_std_init(o))); |
9563
|
|
|
|
|
|
} |
9564
|
|
|
|
|
|
} |
9565
|
32752
|
|
|
|
|
o = ck_fun(o); |
9566
|
32752
|
|
|
|
|
kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ |
9567
|
32752
|
100
|
|
|
|
if (kid && kid->op_type == OP_RV2GV) |
|
|
100
|
|
|
|
|
9568
|
29623
|
|
|
|
|
kid->op_private &= ~HINT_STRICT_REFS; |
9569
|
|
|
|
|
|
return o; |
9570
|
|
|
|
|
|
} |
9571
|
|
|
|
|
|
|
9572
|
|
|
|
|
|
OP * |
9573
|
3093759
|
|
|
|
|
Perl_ck_shift(pTHX_ OP *o) |
9574
|
|
|
|
|
|
{ |
9575
|
|
|
|
|
|
dVAR; |
9576
|
3093759
|
|
|
|
|
const I32 type = o->op_type; |
9577
|
|
|
|
|
|
|
9578
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_SHIFT; |
9579
|
|
|
|
|
|
|
9580
|
3093759
|
100
|
|
|
|
if (!(o->op_flags & OPf_KIDS)) { |
9581
|
|
|
|
|
|
OP *argop; |
9582
|
|
|
|
|
|
|
9583
|
2731145
|
100
|
|
|
|
if (!CvUNIQUE(PL_compcv)) { |
9584
|
2729821
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; |
9585
|
2729821
|
|
|
|
|
return o; |
9586
|
|
|
|
|
|
} |
9587
|
|
|
|
|
|
|
9588
|
1324
|
|
|
|
|
argop = newUNOP(OP_RV2AV, 0, scalar(newGVOP(OP_GV, 0, PL_argvgv))); |
9589
|
|
|
|
|
|
#ifdef PERL_MAD |
9590
|
|
|
|
|
|
{ |
9591
|
|
|
|
|
|
OP * const oldo = o; |
9592
|
|
|
|
|
|
o = newUNOP(type, 0, scalar(argop)); |
9593
|
|
|
|
|
|
op_getmad(oldo,o,'O'); |
9594
|
|
|
|
|
|
return o; |
9595
|
|
|
|
|
|
} |
9596
|
|
|
|
|
|
#else |
9597
|
1324
|
|
|
|
|
op_free(o); |
9598
|
1324
|
|
|
|
|
return newUNOP(type, 0, scalar(argop)); |
9599
|
|
|
|
|
|
#endif |
9600
|
|
|
|
|
|
} |
9601
|
1772101
|
|
|
|
|
return scalar(ck_fun(o)); |
9602
|
|
|
|
|
|
} |
9603
|
|
|
|
|
|
|
9604
|
|
|
|
|
|
OP * |
9605
|
203916
|
|
|
|
|
Perl_ck_sort(pTHX_ OP *o) |
9606
|
|
|
|
|
|
{ |
9607
|
|
|
|
|
|
dVAR; |
9608
|
|
|
|
|
|
OP *firstkid; |
9609
|
|
|
|
|
|
OP *kid; |
9610
|
|
|
|
|
|
HV * const hinthv = |
9611
|
203916
|
100
|
|
|
|
PL_hints & HINT_LOCALIZE_HH ? GvHV(PL_hintgv) : NULL; |
9612
|
|
|
|
|
|
U8 stacked; |
9613
|
|
|
|
|
|
|
9614
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_SORT; |
9615
|
|
|
|
|
|
|
9616
|
203916
|
100
|
|
|
|
if (hinthv) { |
9617
|
4954
|
|
|
|
|
SV ** const svp = hv_fetchs(hinthv, "sort", FALSE); |
9618
|
4954
|
100
|
|
|
|
if (svp) { |
9619
|
14
|
50
|
|
|
|
const I32 sorthints = (I32)SvIV(*svp); |
9620
|
14
|
100
|
|
|
|
if ((sorthints & HINT_SORT_QUICKSORT) != 0) |
9621
|
4
|
|
|
|
|
o->op_private |= OPpSORT_QSORT; |
9622
|
14
|
100
|
|
|
|
if ((sorthints & HINT_SORT_STABLE) != 0) |
9623
|
8
|
|
|
|
|
o->op_private |= OPpSORT_STABLE; |
9624
|
|
|
|
|
|
} |
9625
|
|
|
|
|
|
} |
9626
|
|
|
|
|
|
|
9627
|
203916
|
100
|
|
|
|
if (o->op_flags & OPf_STACKED) |
9628
|
35650
|
|
|
|
|
simplify_sort(o); |
9629
|
203916
|
|
|
|
|
firstkid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ |
9630
|
203916
|
100
|
|
|
|
if ((stacked = o->op_flags & OPf_STACKED)) { /* may have been cleared */ |
9631
|
33042
|
|
|
|
|
OP *kid = cUNOPx(firstkid)->op_first; /* get past null */ |
9632
|
|
|
|
|
|
|
9633
|
33042
|
100
|
|
|
|
if (kid->op_type == OP_SCOPE || kid->op_type == OP_LEAVE) { |
9634
|
27330
|
50
|
|
|
|
LINKLIST(kid); |
9635
|
27330
|
100
|
|
|
|
if (kid->op_type == OP_LEAVE) |
9636
|
9850
|
|
|
|
|
op_null(kid); /* wipe out leave */ |
9637
|
|
|
|
|
|
/* Prevent execution from escaping out of the sort block. */ |
9638
|
27330
|
|
|
|
|
kid->op_next = 0; |
9639
|
|
|
|
|
|
|
9640
|
|
|
|
|
|
/* provide scalar context for comparison function/block */ |
9641
|
27330
|
|
|
|
|
kid = scalar(firstkid); |
9642
|
27330
|
|
|
|
|
kid->op_next = kid; |
9643
|
27330
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; |
9644
|
|
|
|
|
|
} |
9645
|
|
|
|
|
|
|
9646
|
33042
|
|
|
|
|
firstkid = firstkid->op_sibling; |
9647
|
|
|
|
|
|
} |
9648
|
|
|
|
|
|
|
9649
|
409832
|
100
|
|
|
|
for (kid = firstkid; kid; kid = kid->op_sibling) { |
9650
|
|
|
|
|
|
/* provide list context for arguments */ |
9651
|
205916
|
|
|
|
|
list(kid); |
9652
|
205916
|
100
|
|
|
|
if (stacked) |
9653
|
33470
|
|
|
|
|
op_lvalue(kid, OP_GREPSTART); |
9654
|
|
|
|
|
|
} |
9655
|
|
|
|
|
|
|
9656
|
203916
|
|
|
|
|
return o; |
9657
|
|
|
|
|
|
} |
9658
|
|
|
|
|
|
|
9659
|
|
|
|
|
|
STATIC void |
9660
|
35650
|
|
|
|
|
S_simplify_sort(pTHX_ OP *o) |
9661
|
|
|
|
|
|
{ |
9662
|
|
|
|
|
|
dVAR; |
9663
|
35650
|
|
|
|
|
OP *kid = cLISTOPo->op_first->op_sibling; /* get past pushmark */ |
9664
|
|
|
|
|
|
OP *k; |
9665
|
|
|
|
|
|
int descending; |
9666
|
|
|
|
|
|
GV *gv; |
9667
|
|
|
|
|
|
const char *gvname; |
9668
|
|
|
|
|
|
bool have_scopeop; |
9669
|
|
|
|
|
|
|
9670
|
|
|
|
|
|
PERL_ARGS_ASSERT_SIMPLIFY_SORT; |
9671
|
|
|
|
|
|
|
9672
|
35650
|
|
|
|
|
GvMULTI_on(gv_fetchpvs("a", GV_ADD|GV_NOTQUAL, SVt_PV)); |
9673
|
35650
|
|
|
|
|
GvMULTI_on(gv_fetchpvs("b", GV_ADD|GV_NOTQUAL, SVt_PV)); |
9674
|
35650
|
|
|
|
|
kid = kUNOP->op_first; /* get past null */ |
9675
|
35650
|
100
|
|
|
|
if (!(have_scopeop = kid->op_type == OP_SCOPE) |
9676
|
15562
|
100
|
|
|
|
&& kid->op_type != OP_LEAVE) |
9677
|
|
|
|
|
|
return; |
9678
|
29938
|
|
|
|
|
kid = kLISTOP->op_last; /* get past scope */ |
9679
|
29938
|
100
|
|
|
|
switch(kid->op_type) { |
9680
|
|
|
|
|
|
case OP_NCMP: |
9681
|
|
|
|
|
|
case OP_I_NCMP: |
9682
|
|
|
|
|
|
case OP_SCMP: |
9683
|
25040
|
100
|
|
|
|
if (!have_scopeop) goto padkids; |
9684
|
|
|
|
|
|
break; |
9685
|
|
|
|
|
|
default: |
9686
|
|
|
|
|
|
return; |
9687
|
|
|
|
|
|
} |
9688
|
|
|
|
|
|
k = kid; /* remember this node*/ |
9689
|
20060
|
100
|
|
|
|
if (kBINOP->op_first->op_type != OP_RV2SV |
9690
|
2684
|
100
|
|
|
|
|| kBINOP->op_last ->op_type != OP_RV2SV) |
9691
|
|
|
|
|
|
{ |
9692
|
|
|
|
|
|
/* |
9693
|
|
|
|
|
|
Warn about my($a) or my($b) in a sort block, *if* $a or $b is |
9694
|
|
|
|
|
|
then used in a comparison. This catches most, but not |
9695
|
|
|
|
|
|
all cases. For instance, it catches |
9696
|
|
|
|
|
|
sort { my($a); $a <=> $b } |
9697
|
|
|
|
|
|
but not |
9698
|
|
|
|
|
|
sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; } |
9699
|
|
|
|
|
|
(although why you'd do that is anyone's guess). |
9700
|
|
|
|
|
|
*/ |
9701
|
|
|
|
|
|
|
9702
|
|
|
|
|
|
padkids: |
9703
|
22380
|
100
|
|
|
|
if (!ckWARN(WARN_SYNTAX)) return; |
9704
|
14202
|
|
|
|
|
kid = kBINOP->op_first; |
9705
|
|
|
|
|
|
do { |
9706
|
28404
|
100
|
|
|
|
if (kid->op_type == OP_PADSV) { |
9707
|
586
|
|
|
|
|
SV * const name = AvARRAY(PL_comppad_name)[kid->op_targ]; |
9708
|
586
|
100
|
|
|
|
if (SvCUR(name) == 2 && *SvPVX(name) == '$' |
|
|
50
|
|
|
|
|
9709
|
146
|
50
|
|
|
|
&& (SvPVX(name)[1] == 'a' || SvPVX(name)[1] == 'b')) |
9710
|
|
|
|
|
|
/* diag_listed_as: "my %s" used in sort comparison */ |
9711
|
219
|
100
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
9712
|
|
|
|
|
|
"\"%s %s\" used in sort comparison", |
9713
|
146
|
|
|
|
|
SvPAD_STATE(name) ? "state" : "my", |
9714
|
|
|
|
|
|
SvPVX(name)); |
9715
|
|
|
|
|
|
} |
9716
|
28404
|
100
|
|
|
|
} while ((kid = kid->op_sibling)); |
9717
|
|
|
|
|
|
return; |
9718
|
|
|
|
|
|
} |
9719
|
2660
|
|
|
|
|
kid = kBINOP->op_first; /* get past cmp */ |
9720
|
2660
|
100
|
|
|
|
if (kUNOP->op_first->op_type != OP_GV) |
9721
|
|
|
|
|
|
return; |
9722
|
2608
|
|
|
|
|
kid = kUNOP->op_first; /* get past rv2sv */ |
9723
|
2608
|
|
|
|
|
gv = kGVOP_gv; |
9724
|
2608
|
50
|
|
|
|
if (GvSTASH(gv) != PL_curstash) |
9725
|
|
|
|
|
|
return; |
9726
|
2608
|
|
|
|
|
gvname = GvNAME(gv); |
9727
|
2608
|
100
|
|
|
|
if (*gvname == 'a' && gvname[1] == '\0') |
|
|
50
|
|
|
|
|
9728
|
|
|
|
|
|
descending = 0; |
9729
|
828
|
50
|
|
|
|
else if (*gvname == 'b' && gvname[1] == '\0') |
|
|
50
|
|
|
|
|
9730
|
|
|
|
|
|
descending = 1; |
9731
|
|
|
|
|
|
else |
9732
|
|
|
|
|
|
return; |
9733
|
|
|
|
|
|
|
9734
|
|
|
|
|
|
kid = k; /* back to cmp */ |
9735
|
|
|
|
|
|
/* already checked above that it is rv2sv */ |
9736
|
2608
|
|
|
|
|
kid = kBINOP->op_last; /* down to 2nd arg */ |
9737
|
2608
|
50
|
|
|
|
if (kUNOP->op_first->op_type != OP_GV) |
9738
|
|
|
|
|
|
return; |
9739
|
2608
|
|
|
|
|
kid = kUNOP->op_first; /* get past rv2sv */ |
9740
|
2608
|
|
|
|
|
gv = kGVOP_gv; |
9741
|
2608
|
50
|
|
|
|
if (GvSTASH(gv) != PL_curstash) |
9742
|
|
|
|
|
|
return; |
9743
|
2608
|
|
|
|
|
gvname = GvNAME(gv); |
9744
|
6340
|
100
|
|
|
|
if ( descending |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
9745
|
1242
|
50
|
|
|
|
? !(*gvname == 'a' && gvname[1] == '\0') |
9746
|
2490
|
50
|
|
|
|
: !(*gvname == 'b' && gvname[1] == '\0')) |
9747
|
|
|
|
|
|
return; |
9748
|
2608
|
|
|
|
|
o->op_flags &= ~(OPf_STACKED | OPf_SPECIAL); |
9749
|
2608
|
100
|
|
|
|
if (descending) |
9750
|
828
|
|
|
|
|
o->op_private |= OPpSORT_DESCEND; |
9751
|
2608
|
100
|
|
|
|
if (k->op_type == OP_NCMP) |
9752
|
1376
|
|
|
|
|
o->op_private |= OPpSORT_NUMERIC; |
9753
|
2608
|
100
|
|
|
|
if (k->op_type == OP_I_NCMP) |
9754
|
496
|
|
|
|
|
o->op_private |= OPpSORT_NUMERIC | OPpSORT_INTEGER; |
9755
|
2608
|
|
|
|
|
kid = cLISTOPo->op_first->op_sibling; |
9756
|
2608
|
|
|
|
|
cLISTOPo->op_first->op_sibling = kid->op_sibling; /* bypass old block */ |
9757
|
|
|
|
|
|
#ifdef PERL_MAD |
9758
|
|
|
|
|
|
op_getmad(kid,o,'S'); /* then delete it */ |
9759
|
|
|
|
|
|
#else |
9760
|
19849
|
|
|
|
|
op_free(kid); /* then delete it */ |
9761
|
|
|
|
|
|
#endif |
9762
|
|
|
|
|
|
} |
9763
|
|
|
|
|
|
|
9764
|
|
|
|
|
|
OP * |
9765
|
259516
|
|
|
|
|
Perl_ck_split(pTHX_ OP *o) |
9766
|
|
|
|
|
|
{ |
9767
|
|
|
|
|
|
dVAR; |
9768
|
|
|
|
|
|
OP *kid; |
9769
|
|
|
|
|
|
|
9770
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_SPLIT; |
9771
|
|
|
|
|
|
|
9772
|
259516
|
50
|
|
|
|
if (o->op_flags & OPf_STACKED) |
9773
|
0
|
|
|
|
|
return no_fh_allowed(o); |
9774
|
|
|
|
|
|
|
9775
|
259516
|
|
|
|
|
kid = cLISTOPo->op_first; |
9776
|
259516
|
50
|
|
|
|
if (kid->op_type != OP_NULL) |
9777
|
0
|
|
|
|
|
Perl_croak(aTHX_ "panic: ck_split, type=%u", (unsigned) kid->op_type); |
9778
|
259516
|
|
|
|
|
kid = kid->op_sibling; |
9779
|
259516
|
|
|
|
|
op_free(cLISTOPo->op_first); |
9780
|
259516
|
100
|
|
|
|
if (kid) |
9781
|
259386
|
|
|
|
|
cLISTOPo->op_first = kid; |
9782
|
|
|
|
|
|
else { |
9783
|
130
|
|
|
|
|
cLISTOPo->op_first = kid = newSVOP(OP_CONST, 0, newSVpvs(" ")); |
9784
|
130
|
|
|
|
|
cLISTOPo->op_last = kid; /* There was only one element previously */ |
9785
|
|
|
|
|
|
} |
9786
|
|
|
|
|
|
|
9787
|
259516
|
100
|
|
|
|
if (kid->op_type != OP_MATCH || kid->op_flags & OPf_STACKED) { |
|
|
100
|
|
|
|
|
9788
|
80669
|
|
|
|
|
OP * const sibl = kid->op_sibling; |
9789
|
80669
|
|
|
|
|
kid->op_sibling = 0; |
9790
|
80669
|
|
|
|
|
kid = pmruntime( newPMOP(OP_MATCH, OPf_SPECIAL), kid, 0, 0); /* OPf_SPECIAL is used to trigger split " " behavior */ |
9791
|
80669
|
100
|
|
|
|
if (cLISTOPo->op_first == cLISTOPo->op_last) |
9792
|
282
|
|
|
|
|
cLISTOPo->op_last = kid; |
9793
|
80669
|
|
|
|
|
cLISTOPo->op_first = kid; |
9794
|
80669
|
|
|
|
|
kid->op_sibling = sibl; |
9795
|
|
|
|
|
|
} |
9796
|
|
|
|
|
|
|
9797
|
259516
|
|
|
|
|
kid->op_type = OP_PUSHRE; |
9798
|
259516
|
|
|
|
|
kid->op_ppaddr = PL_ppaddr[OP_PUSHRE]; |
9799
|
259516
|
|
|
|
|
scalar(kid); |
9800
|
259516
|
100
|
|
|
|
if (((PMOP *)kid)->op_pmflags & PMf_GLOBAL) { |
9801
|
4
|
|
|
|
|
Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), |
9802
|
|
|
|
|
|
"Use of /g modifier is meaningless in split"); |
9803
|
|
|
|
|
|
} |
9804
|
|
|
|
|
|
|
9805
|
259516
|
100
|
|
|
|
if (!kid->op_sibling) |
9806
|
1632
|
|
|
|
|
op_append_elem(OP_SPLIT, o, newDEFSVOP()); |
9807
|
|
|
|
|
|
|
9808
|
259516
|
|
|
|
|
kid = kid->op_sibling; |
9809
|
259516
|
|
|
|
|
scalar(kid); |
9810
|
|
|
|
|
|
|
9811
|
259516
|
100
|
|
|
|
if (!kid->op_sibling) |
9812
|
|
|
|
|
|
{ |
9813
|
231404
|
|
|
|
|
op_append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0))); |
9814
|
231404
|
|
|
|
|
o->op_private |= OPpSPLIT_IMPLIM; |
9815
|
|
|
|
|
|
} |
9816
|
|
|
|
|
|
assert(kid->op_sibling); |
9817
|
|
|
|
|
|
|
9818
|
259516
|
|
|
|
|
kid = kid->op_sibling; |
9819
|
259516
|
|
|
|
|
scalar(kid); |
9820
|
|
|
|
|
|
|
9821
|
259516
|
100
|
|
|
|
if (kid->op_sibling) |
9822
|
133717
|
50
|
|
|
|
return too_many_arguments_pv(o,OP_DESC(o), 0); |
|
|
0
|
|
|
|
|
9823
|
|
|
|
|
|
|
9824
|
|
|
|
|
|
return o; |
9825
|
|
|
|
|
|
} |
9826
|
|
|
|
|
|
|
9827
|
|
|
|
|
|
OP * |
9828
|
639786
|
|
|
|
|
Perl_ck_join(pTHX_ OP *o) |
9829
|
|
|
|
|
|
{ |
9830
|
639786
|
|
|
|
|
const OP * const kid = cLISTOPo->op_first->op_sibling; |
9831
|
|
|
|
|
|
|
9832
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_JOIN; |
9833
|
|
|
|
|
|
|
9834
|
639786
|
50
|
|
|
|
if (kid && kid->op_type == OP_MATCH) { |
|
|
100
|
|
|
|
|
9835
|
4
|
50
|
|
|
|
if (ckWARN(WARN_SYNTAX)) { |
9836
|
4
|
|
|
|
|
const REGEXP *re = PM_GETRE(kPMOP); |
9837
|
6
|
50
|
|
|
|
const SV *msg = re |
9838
|
16
|
|
|
|
|
? newSVpvn_flags( RX_PRECOMP_const(re), RX_PRELEN(re), |
9839
|
|
|
|
|
|
SVs_TEMP | ( RX_UTF8(re) ? SVf_UTF8 : 0 ) ) |
9840
|
|
|
|
|
|
: newSVpvs_flags( "STRING", SVs_TEMP ); |
9841
|
4
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
9842
|
|
|
|
|
|
"/%"SVf"/ should probably be written as \"%"SVf"\"", |
9843
|
|
|
|
|
|
SVfARG(msg), SVfARG(msg)); |
9844
|
|
|
|
|
|
} |
9845
|
|
|
|
|
|
} |
9846
|
639786
|
|
|
|
|
return ck_fun(o); |
9847
|
|
|
|
|
|
} |
9848
|
|
|
|
|
|
|
9849
|
|
|
|
|
|
/* |
9850
|
|
|
|
|
|
=for apidoc Am|CV *|rv2cv_op_cv|OP *cvop|U32 flags |
9851
|
|
|
|
|
|
|
9852
|
|
|
|
|
|
Examines an op, which is expected to identify a subroutine at runtime, |
9853
|
|
|
|
|
|
and attempts to determine at compile time which subroutine it identifies. |
9854
|
|
|
|
|
|
This is normally used during Perl compilation to determine whether |
9855
|
|
|
|
|
|
a prototype can be applied to a function call. I is the op |
9856
|
|
|
|
|
|
being considered, normally an C op. A pointer to the identified |
9857
|
|
|
|
|
|
subroutine is returned, if it could be determined statically, and a null |
9858
|
|
|
|
|
|
pointer is returned if it was not possible to determine statically. |
9859
|
|
|
|
|
|
|
9860
|
|
|
|
|
|
Currently, the subroutine can be identified statically if the RV that the |
9861
|
|
|
|
|
|
C is to operate on is provided by a suitable C or C op. |
9862
|
|
|
|
|
|
A C op is suitable if the GV's CV slot is populated. A C op is |
9863
|
|
|
|
|
|
suitable if the constant value must be an RV pointing to a CV. Details of |
9864
|
|
|
|
|
|
this process may change in future versions of Perl. If the C op |
9865
|
|
|
|
|
|
has the C flag set then no attempt is made to identify |
9866
|
|
|
|
|
|
the subroutine statically: this flag is used to suppress compile-time |
9867
|
|
|
|
|
|
magic on a subroutine call, forcing it to use default runtime behaviour. |
9868
|
|
|
|
|
|
|
9869
|
|
|
|
|
|
If I has the bit C set, then the handling |
9870
|
|
|
|
|
|
of a GV reference is modified. If a GV was examined and its CV slot was |
9871
|
|
|
|
|
|
found to be empty, then the C op has the C flag set. |
9872
|
|
|
|
|
|
If the op is not optimised away, and the CV slot is later populated with |
9873
|
|
|
|
|
|
a subroutine having a prototype, that flag eventually triggers the warning |
9874
|
|
|
|
|
|
"called too early to check prototype". |
9875
|
|
|
|
|
|
|
9876
|
|
|
|
|
|
If I has the bit C set, then instead |
9877
|
|
|
|
|
|
of returning a pointer to the subroutine it returns a pointer to the |
9878
|
|
|
|
|
|
GV giving the most appropriate name for the subroutine in this context. |
9879
|
|
|
|
|
|
Normally this is just the C of the subroutine, but for an anonymous |
9880
|
|
|
|
|
|
(C) subroutine that is referenced through a GV it will be the |
9881
|
|
|
|
|
|
referencing GV. The resulting C is cast to C to be returned. |
9882
|
|
|
|
|
|
A null pointer is returned as usual if there is no statically-determinable |
9883
|
|
|
|
|
|
subroutine. |
9884
|
|
|
|
|
|
|
9885
|
|
|
|
|
|
=cut |
9886
|
|
|
|
|
|
*/ |
9887
|
|
|
|
|
|
|
9888
|
|
|
|
|
|
/* shared by toke.c:yylex */ |
9889
|
|
|
|
|
|
CV * |
9890
|
352
|
|
|
|
|
Perl_find_lexical_cv(pTHX_ PADOFFSET off) |
9891
|
|
|
|
|
|
{ |
9892
|
352
|
|
|
|
|
PADNAME *name = PAD_COMPNAME(off); |
9893
|
352
|
|
|
|
|
CV *compcv = PL_compcv; |
9894
|
558
|
100
|
|
|
|
while (PadnameOUTER(name)) { |
9895
|
|
|
|
|
|
assert(PARENT_PAD_INDEX(name)); |
9896
|
30
|
|
|
|
|
compcv = CvOUTSIDE(PL_compcv); |
9897
|
45
|
|
|
|
|
name = PadlistNAMESARRAY(CvPADLIST(compcv)) |
9898
|
30
|
|
|
|
|
[off = PARENT_PAD_INDEX(name)]; |
9899
|
|
|
|
|
|
} |
9900
|
|
|
|
|
|
assert(!PadnameIsOUR(name)); |
9901
|
352
|
100
|
|
|
|
if (!PadnameIsSTATE(name) && SvMAGICAL(name)) { |
|
|
100
|
|
|
|
|
9902
|
192
|
|
|
|
|
MAGIC * mg = mg_find(name, PERL_MAGIC_proto); |
9903
|
|
|
|
|
|
assert(mg); |
9904
|
|
|
|
|
|
assert(mg->mg_obj); |
9905
|
192
|
|
|
|
|
return (CV *)mg->mg_obj; |
9906
|
|
|
|
|
|
} |
9907
|
256
|
|
|
|
|
return (CV *)AvARRAY(PadlistARRAY(CvPADLIST(compcv))[1])[off]; |
9908
|
|
|
|
|
|
} |
9909
|
|
|
|
|
|
|
9910
|
|
|
|
|
|
CV * |
9911
|
48165444
|
|
|
|
|
Perl_rv2cv_op_cv(pTHX_ OP *cvop, U32 flags) |
9912
|
|
|
|
|
|
{ |
9913
|
|
|
|
|
|
OP *rvop; |
9914
|
|
|
|
|
|
CV *cv; |
9915
|
|
|
|
|
|
GV *gv; |
9916
|
|
|
|
|
|
PERL_ARGS_ASSERT_RV2CV_OP_CV; |
9917
|
48165444
|
50
|
|
|
|
if (flags & ~(RV2CVOPCV_MARK_EARLY|RV2CVOPCV_RETURN_NAME_GV)) |
9918
|
0
|
|
|
|
|
Perl_croak(aTHX_ "panic: rv2cv_op_cv bad flags %x", (unsigned)flags); |
9919
|
48165444
|
100
|
|
|
|
if (cvop->op_type != OP_RV2CV) |
9920
|
|
|
|
|
|
return NULL; |
9921
|
31849280
|
100
|
|
|
|
if (cvop->op_private & OPpENTERSUB_AMPER) |
9922
|
|
|
|
|
|
return NULL; |
9923
|
30301103
|
50
|
|
|
|
if (!(cvop->op_flags & OPf_KIDS)) |
9924
|
|
|
|
|
|
return NULL; |
9925
|
30301103
|
|
|
|
|
rvop = cUNOPx(cvop)->op_first; |
9926
|
30301103
|
|
|
|
|
switch (rvop->op_type) { |
9927
|
|
|
|
|
|
case OP_GV: { |
9928
|
29628218
|
|
|
|
|
gv = cGVOPx_gv(rvop); |
9929
|
29628218
|
100
|
|
|
|
cv = GvCVu(gv); |
9930
|
29628218
|
100
|
|
|
|
if (!cv) { |
9931
|
5628944
|
100
|
|
|
|
if (flags & RV2CVOPCV_MARK_EARLY) |
9932
|
2133919
|
|
|
|
|
rvop->op_private |= OPpEARLY_CV; |
9933
|
|
|
|
|
|
return NULL; |
9934
|
|
|
|
|
|
} |
9935
|
|
|
|
|
|
} break; |
9936
|
|
|
|
|
|
case OP_CONST: { |
9937
|
530
|
|
|
|
|
SV *rv = cSVOPx_sv(rvop); |
9938
|
530
|
50
|
|
|
|
if (!SvROK(rv)) |
9939
|
|
|
|
|
|
return NULL; |
9940
|
530
|
|
|
|
|
cv = (CV*)SvRV(rv); |
9941
|
|
|
|
|
|
gv = NULL; |
9942
|
530
|
|
|
|
|
} break; |
9943
|
|
|
|
|
|
case OP_PADCV: { |
9944
|
220
|
|
|
|
|
cv = find_lexical_cv(rvop->op_targ); |
9945
|
|
|
|
|
|
gv = NULL; |
9946
|
220
|
|
|
|
|
} break; |
9947
|
|
|
|
|
|
default: { |
9948
|
|
|
|
|
|
return NULL; |
9949
|
|
|
|
|
|
} break; |
9950
|
|
|
|
|
|
} |
9951
|
24000024
|
50
|
|
|
|
if (SvTYPE((SV*)cv) != SVt_PVCV) |
9952
|
|
|
|
|
|
return NULL; |
9953
|
24000024
|
100
|
|
|
|
if (flags & RV2CVOPCV_RETURN_NAME_GV) { |
9954
|
7284676
|
100
|
|
|
|
if (!CvANON(cv) || !gv) |
|
|
100
|
|
|
|
|
9955
|
|
|
|
|
|
gv = CvGV(cv); |
9956
|
28272904
|
|
|
|
|
return (CV*)gv; |
9957
|
|
|
|
|
|
} else { |
9958
|
|
|
|
|
|
return cv; |
9959
|
|
|
|
|
|
} |
9960
|
|
|
|
|
|
} |
9961
|
|
|
|
|
|
|
9962
|
|
|
|
|
|
/* |
9963
|
|
|
|
|
|
=for apidoc Am|OP *|ck_entersub_args_list|OP *entersubop |
9964
|
|
|
|
|
|
|
9965
|
|
|
|
|
|
Performs the default fixup of the arguments part of an C |
9966
|
|
|
|
|
|
op tree. This consists of applying list context to each of the |
9967
|
|
|
|
|
|
argument ops. This is the standard treatment used on a call marked |
9968
|
|
|
|
|
|
with C<&>, or a method call, or a call through a subroutine reference, |
9969
|
|
|
|
|
|
or any other call where the callee can't be identified at compile time, |
9970
|
|
|
|
|
|
or a call where the callee has no prototype. |
9971
|
|
|
|
|
|
|
9972
|
|
|
|
|
|
=cut |
9973
|
|
|
|
|
|
*/ |
9974
|
|
|
|
|
|
|
9975
|
|
|
|
|
|
OP * |
9976
|
27387405
|
|
|
|
|
Perl_ck_entersub_args_list(pTHX_ OP *entersubop) |
9977
|
|
|
|
|
|
{ |
9978
|
|
|
|
|
|
OP *aop; |
9979
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_ENTERSUB_ARGS_LIST; |
9980
|
27387405
|
|
|
|
|
aop = cUNOPx(entersubop)->op_first; |
9981
|
27387405
|
100
|
|
|
|
if (!aop->op_sibling) |
9982
|
11071255
|
|
|
|
|
aop = cUNOPx(aop)->op_first; |
9983
|
67390495
|
100
|
|
|
|
for (aop = aop->op_sibling; aop->op_sibling; aop = aop->op_sibling) { |
9984
|
|
|
|
|
|
if (!(PL_madskills && aop->op_type == OP_STUB)) { |
9985
|
40003090
|
|
|
|
|
list(aop); |
9986
|
40003090
|
|
|
|
|
op_lvalue(aop, OP_ENTERSUB); |
9987
|
|
|
|
|
|
} |
9988
|
|
|
|
|
|
} |
9989
|
27387405
|
|
|
|
|
return entersubop; |
9990
|
|
|
|
|
|
} |
9991
|
|
|
|
|
|
|
9992
|
|
|
|
|
|
/* |
9993
|
|
|
|
|
|
=for apidoc Am|OP *|ck_entersub_args_proto|OP *entersubop|GV *namegv|SV *protosv |
9994
|
|
|
|
|
|
|
9995
|
|
|
|
|
|
Performs the fixup of the arguments part of an C op tree |
9996
|
|
|
|
|
|
based on a subroutine prototype. This makes various modifications to |
9997
|
|
|
|
|
|
the argument ops, from applying context up to inserting C ops, |
9998
|
|
|
|
|
|
and checking the number and syntactic types of arguments, as directed by |
9999
|
|
|
|
|
|
the prototype. This is the standard treatment used on a subroutine call, |
10000
|
|
|
|
|
|
not marked with C<&>, where the callee can be identified at compile time |
10001
|
|
|
|
|
|
and has a prototype. |
10002
|
|
|
|
|
|
|
10003
|
|
|
|
|
|
I supplies the subroutine prototype to be applied to the call. |
10004
|
|
|
|
|
|
It may be a normal defined scalar, of which the string value will be used. |
10005
|
|
|
|
|
|
Alternatively, for convenience, it may be a subroutine object (a C |
10006
|
|
|
|
|
|
that has been cast to C) which has a prototype. The prototype |
10007
|
|
|
|
|
|
supplied, in whichever form, does not need to match the actual callee |
10008
|
|
|
|
|
|
referenced by the op tree. |
10009
|
|
|
|
|
|
|
10010
|
|
|
|
|
|
If the argument ops disagree with the prototype, for example by having |
10011
|
|
|
|
|
|
an unacceptable number of arguments, a valid op tree is returned anyway. |
10012
|
|
|
|
|
|
The error is reflected in the parser state, normally resulting in a single |
10013
|
|
|
|
|
|
exception at the top level of parsing which covers all the compilation |
10014
|
|
|
|
|
|
errors that occurred. In the error message, the callee is referred to |
10015
|
|
|
|
|
|
by the name defined by the I parameter. |
10016
|
|
|
|
|
|
|
10017
|
|
|
|
|
|
=cut |
10018
|
|
|
|
|
|
*/ |
10019
|
|
|
|
|
|
|
10020
|
|
|
|
|
|
OP * |
10021
|
566324
|
|
|
|
|
Perl_ck_entersub_args_proto(pTHX_ OP *entersubop, GV *namegv, SV *protosv) |
10022
|
|
|
|
|
|
{ |
10023
|
|
|
|
|
|
STRLEN proto_len; |
10024
|
|
|
|
|
|
const char *proto, *proto_end; |
10025
|
|
|
|
|
|
OP *aop, *prev, *cvop; |
10026
|
|
|
|
|
|
int optional = 0; |
10027
|
|
|
|
|
|
I32 arg = 0; |
10028
|
|
|
|
|
|
I32 contextclass = 0; |
10029
|
|
|
|
|
|
const char *e = NULL; |
10030
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_ENTERSUB_ARGS_PROTO; |
10031
|
566324
|
100
|
|
|
|
if (SvTYPE(protosv) == SVt_PVCV ? !SvPOK(protosv) : !SvOK(protosv)) |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
10032
|
4
|
|
|
|
|
Perl_croak(aTHX_ "panic: ck_entersub_args_proto CV with no proto, " |
10033
|
4
|
|
|
|
|
"flags=%lx", (unsigned long) SvFLAGS(protosv)); |
10034
|
566320
|
100
|
|
|
|
if (SvTYPE(protosv) == SVt_PVCV) |
10035
|
566310
|
50
|
|
|
|
proto = CvPROTO(protosv), proto_len = CvPROTOLEN(protosv); |
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
10036
|
10
|
50
|
|
|
|
else proto = SvPV(protosv, proto_len); |
10037
|
566320
|
|
|
|
|
proto = S_strip_spaces(aTHX_ proto, &proto_len); |
10038
|
566320
|
|
|
|
|
proto_end = proto + proto_len; |
10039
|
566320
|
|
|
|
|
aop = cUNOPx(entersubop)->op_first; |
10040
|
566320
|
50
|
|
|
|
if (!aop->op_sibling) |
10041
|
566320
|
|
|
|
|
aop = cUNOPx(aop)->op_first; |
10042
|
|
|
|
|
|
prev = aop; |
10043
|
566320
|
|
|
|
|
aop = aop->op_sibling; |
10044
|
1218237
|
100
|
|
|
|
for (cvop = aop; cvop->op_sibling; cvop = cvop->op_sibling) ; |
10045
|
1959526
|
100
|
|
|
|
while (aop != cvop) { |
10046
|
|
|
|
|
|
OP* o3; |
10047
|
|
|
|
|
|
if (PL_madskills && aop->op_type == OP_STUB) { |
10048
|
|
|
|
|
|
aop = aop->op_sibling; |
10049
|
|
|
|
|
|
continue; |
10050
|
|
|
|
|
|
} |
10051
|
|
|
|
|
|
if (PL_madskills && aop->op_type == OP_NULL) |
10052
|
|
|
|
|
|
o3 = ((UNOP*)aop)->op_first; |
10053
|
|
|
|
|
|
else |
10054
|
|
|
|
|
|
o3 = aop; |
10055
|
|
|
|
|
|
|
10056
|
1393224
|
100
|
|
|
|
if (proto >= proto_end) |
10057
|
20
|
|
|
|
|
return too_many_arguments_sv(entersubop, gv_ename(namegv), 0); |
10058
|
|
|
|
|
|
|
10059
|
1393214
|
|
|
|
|
switch (*proto) { |
10060
|
|
|
|
|
|
case ';': |
10061
|
|
|
|
|
|
optional = 1; |
10062
|
109914
|
|
|
|
|
proto++; |
10063
|
109914
|
|
|
|
|
continue; |
10064
|
|
|
|
|
|
case '_': |
10065
|
|
|
|
|
|
/* _ must be at the end */ |
10066
|
1242
|
100
|
|
|
|
if (proto[1] && !strchr(";@%", proto[1])) |
|
|
100
|
|
|
|
|
10067
|
|
|
|
|
|
goto oops; |
10068
|
|
|
|
|
|
case '$': |
10069
|
1162350
|
|
|
|
|
proto++; |
10070
|
1162350
|
|
|
|
|
arg++; |
10071
|
1162350
|
|
|
|
|
scalar(aop); |
10072
|
1162350
|
|
|
|
|
break; |
10073
|
|
|
|
|
|
case '%': |
10074
|
|
|
|
|
|
case '@': |
10075
|
63302
|
|
|
|
|
list(aop); |
10076
|
63302
|
|
|
|
|
arg++; |
10077
|
63302
|
|
|
|
|
break; |
10078
|
|
|
|
|
|
case '&': |
10079
|
2676
|
|
|
|
|
proto++; |
10080
|
2676
|
|
|
|
|
arg++; |
10081
|
2676
|
100
|
|
|
|
if (o3->op_type != OP_REFGEN && o3->op_type != OP_UNDEF) |
10082
|
2
|
50
|
|
|
|
bad_type_gv(arg, |
10083
|
|
|
|
|
|
arg == 1 ? "block or sub {}" : "sub {}", |
10084
|
|
|
|
|
|
namegv, 0, o3); |
10085
|
|
|
|
|
|
break; |
10086
|
|
|
|
|
|
case '*': |
10087
|
|
|
|
|
|
/* '*' allows any scalar type, including bareword */ |
10088
|
4438
|
|
|
|
|
proto++; |
10089
|
4438
|
|
|
|
|
arg++; |
10090
|
4438
|
100
|
|
|
|
if (o3->op_type == OP_RV2GV) |
10091
|
|
|
|
|
|
goto wrapref; /* autoconvert GLOB -> GLOBref */ |
10092
|
4424
|
100
|
|
|
|
else if (o3->op_type == OP_CONST) |
10093
|
108
|
|
|
|
|
o3->op_private &= ~OPpCONST_STRICT; |
10094
|
4316
|
100
|
|
|
|
else if (o3->op_type == OP_ENTERSUB) { |
10095
|
|
|
|
|
|
/* accidental subroutine, revert to bareword */ |
10096
|
8
|
|
|
|
|
OP *gvop = ((UNOP*)o3)->op_first; |
10097
|
8
|
50
|
|
|
|
if (gvop && gvop->op_type == OP_NULL) { |
|
|
50
|
|
|
|
|
10098
|
8
|
|
|
|
|
gvop = ((UNOP*)gvop)->op_first; |
10099
|
8
|
50
|
|
|
|
if (gvop) { |
10100
|
12
|
100
|
|
|
|
for (; gvop->op_sibling; gvop = gvop->op_sibling) |
10101
|
|
|
|
|
|
; |
10102
|
12
|
50
|
|
|
|
if (gvop && |
|
|
100
|
|
|
|
|
10103
|
8
|
50
|
|
|
|
(gvop->op_private & OPpENTERSUB_NOPAREN) && |
10104
|
6
|
50
|
|
|
|
(gvop = ((UNOP*)gvop)->op_first) && |
10105
|
4
|
|
|
|
|
gvop->op_type == OP_GV) |
10106
|
|
|
|
|
|
{ |
10107
|
4
|
|
|
|
|
GV * const gv = cGVOPx_gv(gvop); |
10108
|
4
|
|
|
|
|
OP * const sibling = aop->op_sibling; |
10109
|
4
|
|
|
|
|
SV * const n = newSVpvs(""); |
10110
|
|
|
|
|
|
#ifdef PERL_MAD |
10111
|
|
|
|
|
|
OP * const oldaop = aop; |
10112
|
|
|
|
|
|
#else |
10113
|
4
|
|
|
|
|
op_free(aop); |
10114
|
|
|
|
|
|
#endif |
10115
|
4
|
|
|
|
|
gv_fullname4(n, gv, "", FALSE); |
10116
|
4
|
|
|
|
|
aop = newSVOP(OP_CONST, 0, n); |
10117
|
|
|
|
|
|
op_getmad(oldaop,aop,'O'); |
10118
|
4
|
|
|
|
|
prev->op_sibling = aop; |
10119
|
4
|
|
|
|
|
aop->op_sibling = sibling; |
10120
|
|
|
|
|
|
} |
10121
|
|
|
|
|
|
} |
10122
|
|
|
|
|
|
} |
10123
|
|
|
|
|
|
} |
10124
|
4424
|
|
|
|
|
scalar(aop); |
10125
|
4424
|
|
|
|
|
break; |
10126
|
|
|
|
|
|
case '+': |
10127
|
20
|
|
|
|
|
proto++; |
10128
|
20
|
|
|
|
|
arg++; |
10129
|
20
|
50
|
|
|
|
if (o3->op_type == OP_RV2AV || |
10130
|
20
|
50
|
|
|
|
o3->op_type == OP_PADAV || |
10131
|
30
|
50
|
|
|
|
o3->op_type == OP_RV2HV || |
10132
|
20
|
|
|
|
|
o3->op_type == OP_PADHV |
10133
|
|
|
|
|
|
) { |
10134
|
|
|
|
|
|
goto wrapref; |
10135
|
|
|
|
|
|
} |
10136
|
20
|
|
|
|
|
scalar(aop); |
10137
|
20
|
|
|
|
|
break; |
10138
|
|
|
|
|
|
case '[': case ']': |
10139
|
|
|
|
|
|
goto oops; |
10140
|
|
|
|
|
|
break; |
10141
|
|
|
|
|
|
case '\\': |
10142
|
50506
|
|
|
|
|
proto++; |
10143
|
63132
|
|
|
|
|
arg++; |
10144
|
|
|
|
|
|
again: |
10145
|
124786
|
|
|
|
|
switch (*proto++) { |
10146
|
|
|
|
|
|
case '[': |
10147
|
49748
|
50
|
|
|
|
if (contextclass++ == 0) { |
10148
|
49748
|
|
|
|
|
e = strchr(proto, ']'); |
10149
|
49748
|
50
|
|
|
|
if (!e || e == proto) |
10150
|
|
|
|
|
|
goto oops; |
10151
|
|
|
|
|
|
} |
10152
|
|
|
|
|
|
else |
10153
|
|
|
|
|
|
goto oops; |
10154
|
|
|
|
|
|
goto again; |
10155
|
|
|
|
|
|
break; |
10156
|
|
|
|
|
|
case ']': |
10157
|
12
|
50
|
|
|
|
if (contextclass) { |
10158
|
|
|
|
|
|
const char *p = proto; |
10159
|
|
|
|
|
|
const char *const end = proto; |
10160
|
|
|
|
|
|
contextclass = 0; |
10161
|
52
|
100
|
|
|
|
while (*--p != '[') |
10162
|
|
|
|
|
|
/* \[$] accepts any scalar lvalue */ |
10163
|
42
|
100
|
|
|
|
if (*p == '$' |
10164
|
25
|
100
|
|
|
|
&& Perl_op_lvalue_flags(aTHX_ |
10165
|
|
|
|
|
|
scalar(o3), |
10166
|
|
|
|
|
|
OP_READ, /* not entersub */ |
10167
|
|
|
|
|
|
OP_LVALUE_NO_CROAK |
10168
|
|
|
|
|
|
)) goto wrapref; |
10169
|
10
|
|
|
|
|
bad_type_gv(arg, Perl_form(aTHX_ "one of %.*s", |
10170
|
|
|
|
|
|
(int)(end - p), p), |
10171
|
|
|
|
|
|
namegv, 0, o3); |
10172
|
|
|
|
|
|
} else |
10173
|
|
|
|
|
|
goto oops; |
10174
|
10
|
|
|
|
|
break; |
10175
|
|
|
|
|
|
case '*': |
10176
|
6
|
100
|
|
|
|
if (o3->op_type == OP_RV2GV) |
10177
|
|
|
|
|
|
goto wrapref; |
10178
|
4
|
50
|
|
|
|
if (!contextclass) |
10179
|
0
|
|
|
|
|
bad_type_gv(arg, "symbol", namegv, 0, o3); |
10180
|
|
|
|
|
|
break; |
10181
|
|
|
|
|
|
case '&': |
10182
|
12
|
100
|
|
|
|
if (o3->op_type == OP_ENTERSUB) |
10183
|
|
|
|
|
|
goto wrapref; |
10184
|
8
|
100
|
|
|
|
if (!contextclass) |
10185
|
2
|
|
|
|
|
bad_type_gv(arg, "subroutine entry", namegv, 0, |
10186
|
|
|
|
|
|
o3); |
10187
|
|
|
|
|
|
break; |
10188
|
|
|
|
|
|
case '$': |
10189
|
50388
|
100
|
|
|
|
if (o3->op_type == OP_RV2SV || |
10190
|
12986
|
100
|
|
|
|
o3->op_type == OP_PADSV || |
10191
|
19047
|
100
|
|
|
|
o3->op_type == OP_HELEM || |
10192
|
12734
|
|
|
|
|
o3->op_type == OP_AELEM) |
10193
|
|
|
|
|
|
goto wrapref; |
10194
|
12730
|
100
|
|
|
|
if (!contextclass) { |
10195
|
|
|
|
|
|
/* \$ accepts any scalar lvalue */ |
10196
|
4
|
100
|
|
|
|
if (Perl_op_lvalue_flags(aTHX_ |
10197
|
|
|
|
|
|
scalar(o3), |
10198
|
|
|
|
|
|
OP_READ, /* not entersub */ |
10199
|
|
|
|
|
|
OP_LVALUE_NO_CROAK |
10200
|
|
|
|
|
|
)) goto wrapref; |
10201
|
2
|
|
|
|
|
bad_type_gv(arg, "scalar", namegv, 0, o3); |
10202
|
|
|
|
|
|
} |
10203
|
|
|
|
|
|
break; |
10204
|
|
|
|
|
|
case '@': |
10205
|
12626
|
100
|
|
|
|
if (o3->op_type == OP_RV2AV || |
10206
|
|
|
|
|
|
o3->op_type == OP_PADAV) |
10207
|
|
|
|
|
|
goto wrapref; |
10208
|
454
|
50
|
|
|
|
if (!contextclass) |
10209
|
0
|
|
|
|
|
bad_type_gv(arg, "array", namegv, 0, o3); |
10210
|
|
|
|
|
|
break; |
10211
|
|
|
|
|
|
case '%': |
10212
|
11994
|
100
|
|
|
|
if (o3->op_type == OP_RV2HV || |
10213
|
|
|
|
|
|
o3->op_type == OP_PADHV) |
10214
|
|
|
|
|
|
goto wrapref; |
10215
|
11344
|
100
|
|
|
|
if (!contextclass) |
10216
|
2
|
|
|
|
|
bad_type_gv(arg, "hash", namegv, 0, o3); |
10217
|
|
|
|
|
|
break; |
10218
|
|
|
|
|
|
wrapref: |
10219
|
|
|
|
|
|
{ |
10220
|
|
|
|
|
|
OP* const kid = aop; |
10221
|
50504
|
|
|
|
|
OP* const sib = kid->op_sibling; |
10222
|
50504
|
|
|
|
|
kid->op_sibling = 0; |
10223
|
50504
|
|
|
|
|
aop = newUNOP(OP_REFGEN, 0, kid); |
10224
|
50504
|
|
|
|
|
aop->op_sibling = sib; |
10225
|
50504
|
|
|
|
|
prev->op_sibling = aop; |
10226
|
|
|
|
|
|
} |
10227
|
50504
|
100
|
|
|
|
if (contextclass && e) { |
10228
|
49736
|
|
|
|
|
proto = e + 1; |
10229
|
|
|
|
|
|
contextclass = 0; |
10230
|
|
|
|
|
|
} |
10231
|
|
|
|
|
|
break; |
10232
|
|
|
|
|
|
default: goto oops; |
10233
|
|
|
|
|
|
} |
10234
|
75052
|
100
|
|
|
|
if (contextclass) |
10235
|
|
|
|
|
|
goto again; |
10236
|
|
|
|
|
|
break; |
10237
|
|
|
|
|
|
case ' ': |
10238
|
0
|
|
|
|
|
proto++; |
10239
|
0
|
|
|
|
|
continue; |
10240
|
|
|
|
|
|
default: |
10241
|
|
|
|
|
|
oops: { |
10242
|
8
|
|
|
|
|
SV* const tmpsv = sv_newmortal(); |
10243
|
8
|
|
|
|
|
gv_efullname3(tmpsv, namegv, NULL); |
10244
|
8
|
|
|
|
|
Perl_croak(aTHX_ "Malformed prototype for %"SVf": %"SVf, |
10245
|
|
|
|
|
|
SVfARG(tmpsv), SVfARG(protosv)); |
10246
|
|
|
|
|
|
} |
10247
|
|
|
|
|
|
} |
10248
|
|
|
|
|
|
|
10249
|
1283292
|
|
|
|
|
op_lvalue(aop, OP_ENTERSUB); |
10250
|
|
|
|
|
|
prev = aop; |
10251
|
1339149
|
|
|
|
|
aop = aop->op_sibling; |
10252
|
|
|
|
|
|
} |
10253
|
566302
|
50
|
|
|
|
if (aop == cvop && *proto == '_') { |
|
|
100
|
|
|
|
|
10254
|
|
|
|
|
|
/* generate an access to $_ */ |
10255
|
68
|
|
|
|
|
aop = newDEFSVOP(); |
10256
|
68
|
|
|
|
|
aop->op_sibling = prev->op_sibling; |
10257
|
68
|
|
|
|
|
prev->op_sibling = aop; /* instead of cvop */ |
10258
|
|
|
|
|
|
} |
10259
|
622876
|
100
|
|
|
|
if (!optional && proto_end > proto && |
|
|
100
|
|
|
|
|
10260
|
118690
|
100
|
|
|
|
(*proto != '@' && *proto != '%' && *proto != ';' && *proto != '_')) |
|
|
100
|
|
|
|
|
10261
|
290056
|
|
|
|
|
return too_few_arguments_sv(entersubop, gv_ename(namegv), 0); |
10262
|
|
|
|
|
|
return entersubop; |
10263
|
|
|
|
|
|
} |
10264
|
|
|
|
|
|
|
10265
|
|
|
|
|
|
/* |
10266
|
|
|
|
|
|
=for apidoc Am|OP *|ck_entersub_args_proto_or_list|OP *entersubop|GV *namegv|SV *protosv |
10267
|
|
|
|
|
|
|
10268
|
|
|
|
|
|
Performs the fixup of the arguments part of an C op tree either |
10269
|
|
|
|
|
|
based on a subroutine prototype or using default list-context processing. |
10270
|
|
|
|
|
|
This is the standard treatment used on a subroutine call, not marked |
10271
|
|
|
|
|
|
with C<&>, where the callee can be identified at compile time. |
10272
|
|
|
|
|
|
|
10273
|
|
|
|
|
|
I supplies the subroutine prototype to be applied to the call, |
10274
|
|
|
|
|
|
or indicates that there is no prototype. It may be a normal scalar, |
10275
|
|
|
|
|
|
in which case if it is defined then the string value will be used |
10276
|
|
|
|
|
|
as a prototype, and if it is undefined then there is no prototype. |
10277
|
|
|
|
|
|
Alternatively, for convenience, it may be a subroutine object (a C |
10278
|
|
|
|
|
|
that has been cast to C), of which the prototype will be used if it |
10279
|
|
|
|
|
|
has one. The prototype (or lack thereof) supplied, in whichever form, |
10280
|
|
|
|
|
|
does not need to match the actual callee referenced by the op tree. |
10281
|
|
|
|
|
|
|
10282
|
|
|
|
|
|
If the argument ops disagree with the prototype, for example by having |
10283
|
|
|
|
|
|
an unacceptable number of arguments, a valid op tree is returned anyway. |
10284
|
|
|
|
|
|
The error is reflected in the parser state, normally resulting in a single |
10285
|
|
|
|
|
|
exception at the top level of parsing which covers all the compilation |
10286
|
|
|
|
|
|
errors that occurred. In the error message, the callee is referred to |
10287
|
|
|
|
|
|
by the name defined by the I parameter. |
10288
|
|
|
|
|
|
|
10289
|
|
|
|
|
|
=cut |
10290
|
|
|
|
|
|
*/ |
10291
|
|
|
|
|
|
|
10292
|
|
|
|
|
|
OP * |
10293
|
7283206
|
|
|
|
|
Perl_ck_entersub_args_proto_or_list(pTHX_ OP *entersubop, |
10294
|
|
|
|
|
|
GV *namegv, SV *protosv) |
10295
|
|
|
|
|
|
{ |
10296
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_ENTERSUB_ARGS_PROTO_OR_LIST; |
10297
|
7283206
|
100
|
|
|
|
if (SvTYPE(protosv) == SVt_PVCV ? SvPOK(protosv) : SvOK(protosv)) |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
10298
|
566178
|
|
|
|
|
return ck_entersub_args_proto(entersubop, namegv, protosv); |
10299
|
|
|
|
|
|
else |
10300
|
7006953
|
|
|
|
|
return ck_entersub_args_list(entersubop); |
10301
|
|
|
|
|
|
} |
10302
|
|
|
|
|
|
|
10303
|
|
|
|
|
|
OP * |
10304
|
1290
|
|
|
|
|
Perl_ck_entersub_args_core(pTHX_ OP *entersubop, GV *namegv, SV *protosv) |
10305
|
|
|
|
|
|
{ |
10306
|
1290
|
100
|
|
|
|
int opnum = SvTYPE(protosv) == SVt_PVCV ? 0 : (int)SvUV(protosv); |
|
|
50
|
|
|
|
|
10307
|
1290
|
|
|
|
|
OP *aop = cUNOPx(entersubop)->op_first; |
10308
|
|
|
|
|
|
|
10309
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_ENTERSUB_ARGS_CORE; |
10310
|
|
|
|
|
|
|
10311
|
1290
|
100
|
|
|
|
if (!opnum) { |
10312
|
|
|
|
|
|
OP *cvop; |
10313
|
24
|
50
|
|
|
|
if (!aop->op_sibling) |
10314
|
24
|
|
|
|
|
aop = cUNOPx(aop)->op_first; |
10315
|
24
|
|
|
|
|
aop = aop->op_sibling; |
10316
|
39
|
100
|
|
|
|
for (cvop = aop; cvop->op_sibling; cvop = cvop->op_sibling) ; |
10317
|
|
|
|
|
|
if (PL_madskills) while (aop != cvop && aop->op_type == OP_STUB) { |
10318
|
|
|
|
|
|
aop = aop->op_sibling; |
10319
|
|
|
|
|
|
} |
10320
|
24
|
100
|
|
|
|
if (aop != cvop) |
10321
|
6
|
|
|
|
|
(void)too_many_arguments_pv(entersubop, GvNAME(namegv), 0); |
10322
|
|
|
|
|
|
|
10323
|
24
|
|
|
|
|
op_free(entersubop); |
10324
|
24
|
|
|
|
|
switch(GvNAME(namegv)[2]) { |
10325
|
8
|
50
|
|
|
|
case 'F': return newSVOP(OP_CONST, 0, |
10326
|
|
|
|
|
|
newSVpv(CopFILE(PL_curcop),0)); |
10327
|
8
|
|
|
|
|
case 'L': return newSVOP( |
10328
|
|
|
|
|
|
OP_CONST, 0, |
10329
|
|
|
|
|
|
Perl_newSVpvf(aTHX_ |
10330
|
|
|
|
|
|
"%"IVdf, (IV)CopLINE(PL_curcop) |
10331
|
|
|
|
|
|
) |
10332
|
|
|
|
|
|
); |
10333
|
8
|
50
|
|
|
|
case 'P': return newSVOP(OP_CONST, 0, |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
10334
|
|
|
|
|
|
(PL_curstash |
10335
|
|
|
|
|
|
? newSVhek(HvNAME_HEK(PL_curstash)) |
10336
|
|
|
|
|
|
: &PL_sv_undef |
10337
|
|
|
|
|
|
) |
10338
|
|
|
|
|
|
); |
10339
|
|
|
|
|
|
} |
10340
|
|
|
|
|
|
assert(0); |
10341
|
|
|
|
|
|
} |
10342
|
|
|
|
|
|
else { |
10343
|
|
|
|
|
|
OP *prev, *cvop; |
10344
|
|
|
|
|
|
U32 flags; |
10345
|
|
|
|
|
|
#ifdef PERL_MAD |
10346
|
|
|
|
|
|
bool seenarg = FALSE; |
10347
|
|
|
|
|
|
#endif |
10348
|
1266
|
50
|
|
|
|
if (!aop->op_sibling) |
10349
|
1266
|
|
|
|
|
aop = cUNOPx(aop)->op_first; |
10350
|
|
|
|
|
|
|
10351
|
|
|
|
|
|
prev = aop; |
10352
|
1266
|
|
|
|
|
aop = aop->op_sibling; |
10353
|
1266
|
|
|
|
|
prev->op_sibling = NULL; |
10354
|
4905
|
100
|
|
|
|
for (cvop = aop; |
10355
|
4272
|
|
|
|
|
cvop->op_sibling; |
10356
|
3006
|
|
|
|
|
prev=cvop, cvop = cvop->op_sibling) |
10357
|
|
|
|
|
|
#ifdef PERL_MAD |
10358
|
|
|
|
|
|
if (PL_madskills && cvop->op_sibling |
10359
|
|
|
|
|
|
&& cvop->op_type != OP_STUB) seenarg = TRUE |
10360
|
|
|
|
|
|
#endif |
10361
|
|
|
|
|
|
; |
10362
|
1266
|
|
|
|
|
prev->op_sibling = NULL; |
10363
|
1266
|
100
|
|
|
|
flags = OPf_SPECIAL * !(cvop->op_private & OPpENTERSUB_NOPAREN); |
10364
|
1266
|
|
|
|
|
op_free(cvop); |
10365
|
1266
|
100
|
|
|
|
if (aop == cvop) aop = NULL; |
10366
|
1266
|
|
|
|
|
op_free(entersubop); |
10367
|
|
|
|
|
|
|
10368
|
1266
|
100
|
|
|
|
if (opnum == OP_ENTEREVAL |
10369
|
6
|
50
|
|
|
|
&& GvNAMELEN(namegv)==9 && strnEQ(GvNAME(namegv), "evalbytes", 9)) |
|
|
50
|
|
|
|
|
10370
|
6
|
|
|
|
|
flags |= OPpEVAL_BYTES <<8; |
10371
|
|
|
|
|
|
|
10372
|
1266
|
|
|
|
|
switch (PL_opargs[opnum] & OA_CLASS_MASK) { |
10373
|
|
|
|
|
|
case OA_UNOP: |
10374
|
|
|
|
|
|
case OA_BASEOP_OR_UNOP: |
10375
|
|
|
|
|
|
case OA_FILESTATOP: |
10376
|
610
|
100
|
|
|
|
return aop ? newUNOP(opnum,flags,aop) : newOP(opnum,flags); |
10377
|
|
|
|
|
|
case OA_BASEOP: |
10378
|
192
|
100
|
|
|
|
if (aop) { |
10379
|
|
|
|
|
|
#ifdef PERL_MAD |
10380
|
|
|
|
|
|
if (!PL_madskills || seenarg) |
10381
|
|
|
|
|
|
#endif |
10382
|
48
|
|
|
|
|
(void)too_many_arguments_pv(aop, GvNAME(namegv), 0); |
10383
|
48
|
|
|
|
|
op_free(aop); |
10384
|
|
|
|
|
|
} |
10385
|
192
|
|
|
|
|
return opnum == OP_RUNCV |
10386
|
|
|
|
|
|
? newPVOP(OP_RUNCV,0,NULL) |
10387
|
192
|
100
|
|
|
|
: newOP(opnum,0); |
10388
|
|
|
|
|
|
default: |
10389
|
877
|
|
|
|
|
return convert(opnum,0,aop); |
10390
|
|
|
|
|
|
} |
10391
|
|
|
|
|
|
} |
10392
|
|
|
|
|
|
assert(0); |
10393
|
|
|
|
|
|
return entersubop; |
10394
|
|
|
|
|
|
} |
10395
|
|
|
|
|
|
|
10396
|
|
|
|
|
|
/* |
10397
|
|
|
|
|
|
=for apidoc Am|void|cv_get_call_checker|CV *cv|Perl_call_checker *ckfun_p|SV **ckobj_p |
10398
|
|
|
|
|
|
|
10399
|
|
|
|
|
|
Retrieves the function that will be used to fix up a call to I. |
10400
|
|
|
|
|
|
Specifically, the function is applied to an C op tree for a |
10401
|
|
|
|
|
|
subroutine call, not marked with C<&>, where the callee can be identified |
10402
|
|
|
|
|
|
at compile time as I. |
10403
|
|
|
|
|
|
|
10404
|
|
|
|
|
|
The C-level function pointer is returned in I<*ckfun_p>, and an SV |
10405
|
|
|
|
|
|
argument for it is returned in I<*ckobj_p>. The function is intended |
10406
|
|
|
|
|
|
to be called in this manner: |
10407
|
|
|
|
|
|
|
10408
|
|
|
|
|
|
entersubop = (*ckfun_p)(aTHX_ entersubop, namegv, (*ckobj_p)); |
10409
|
|
|
|
|
|
|
10410
|
|
|
|
|
|
In this call, I is a pointer to the C op, |
10411
|
|
|
|
|
|
which may be replaced by the check function, and I is a GV |
10412
|
|
|
|
|
|
supplying the name that should be used by the check function to refer |
10413
|
|
|
|
|
|
to the callee of the C op if it needs to emit any diagnostics. |
10414
|
|
|
|
|
|
It is permitted to apply the check function in non-standard situations, |
10415
|
|
|
|
|
|
such as to a call to a different subroutine or to a method call. |
10416
|
|
|
|
|
|
|
10417
|
|
|
|
|
|
By default, the function is |
10418
|
|
|
|
|
|
L, |
10419
|
|
|
|
|
|
and the SV parameter is I itself. This implements standard |
10420
|
|
|
|
|
|
prototype processing. It can be changed, for a particular subroutine, |
10421
|
|
|
|
|
|
by L. |
10422
|
|
|
|
|
|
|
10423
|
|
|
|
|
|
=cut |
10424
|
|
|
|
|
|
*/ |
10425
|
|
|
|
|
|
|
10426
|
|
|
|
|
|
void |
10427
|
7284690
|
|
|
|
|
Perl_cv_get_call_checker(pTHX_ CV *cv, Perl_call_checker *ckfun_p, SV **ckobj_p) |
10428
|
|
|
|
|
|
{ |
10429
|
|
|
|
|
|
MAGIC *callmg; |
10430
|
|
|
|
|
|
PERL_ARGS_ASSERT_CV_GET_CALL_CHECKER; |
10431
|
7284690
|
100
|
|
|
|
callmg = SvMAGICAL((SV*)cv) ? mg_find((SV*)cv, PERL_MAGIC_checkcall) : NULL; |
10432
|
7284690
|
100
|
|
|
|
if (callmg) { |
10433
|
1476
|
|
|
|
|
*ckfun_p = DPTR2FPTR(Perl_call_checker, callmg->mg_ptr); |
10434
|
1476
|
|
|
|
|
*ckobj_p = callmg->mg_obj; |
10435
|
|
|
|
|
|
} else { |
10436
|
7283214
|
|
|
|
|
*ckfun_p = Perl_ck_entersub_args_proto_or_list; |
10437
|
7283214
|
|
|
|
|
*ckobj_p = (SV*)cv; |
10438
|
|
|
|
|
|
} |
10439
|
7284690
|
|
|
|
|
} |
10440
|
|
|
|
|
|
|
10441
|
|
|
|
|
|
/* |
10442
|
|
|
|
|
|
=for apidoc Am|void|cv_set_call_checker|CV *cv|Perl_call_checker ckfun|SV *ckobj |
10443
|
|
|
|
|
|
|
10444
|
|
|
|
|
|
Sets the function that will be used to fix up a call to I. |
10445
|
|
|
|
|
|
Specifically, the function is applied to an C op tree for a |
10446
|
|
|
|
|
|
subroutine call, not marked with C<&>, where the callee can be identified |
10447
|
|
|
|
|
|
at compile time as I. |
10448
|
|
|
|
|
|
|
10449
|
|
|
|
|
|
The C-level function pointer is supplied in I, and an SV argument |
10450
|
|
|
|
|
|
for it is supplied in I. The function is intended to be called |
10451
|
|
|
|
|
|
in this manner: |
10452
|
|
|
|
|
|
|
10453
|
|
|
|
|
|
entersubop = ckfun(aTHX_ entersubop, namegv, ckobj); |
10454
|
|
|
|
|
|
|
10455
|
|
|
|
|
|
In this call, I is a pointer to the C op, |
10456
|
|
|
|
|
|
which may be replaced by the check function, and I is a GV |
10457
|
|
|
|
|
|
supplying the name that should be used by the check function to refer |
10458
|
|
|
|
|
|
to the callee of the C op if it needs to emit any diagnostics. |
10459
|
|
|
|
|
|
It is permitted to apply the check function in non-standard situations, |
10460
|
|
|
|
|
|
such as to a call to a different subroutine or to a method call. |
10461
|
|
|
|
|
|
|
10462
|
|
|
|
|
|
The current setting for a particular CV can be retrieved by |
10463
|
|
|
|
|
|
L. |
10464
|
|
|
|
|
|
|
10465
|
|
|
|
|
|
=cut |
10466
|
|
|
|
|
|
*/ |
10467
|
|
|
|
|
|
|
10468
|
|
|
|
|
|
void |
10469
|
1388
|
|
|
|
|
Perl_cv_set_call_checker(pTHX_ CV *cv, Perl_call_checker ckfun, SV *ckobj) |
10470
|
|
|
|
|
|
{ |
10471
|
|
|
|
|
|
PERL_ARGS_ASSERT_CV_SET_CALL_CHECKER; |
10472
|
1388
|
100
|
|
|
|
if (ckfun == Perl_ck_entersub_args_proto_or_list && ckobj == (SV*)cv) { |
10473
|
4
|
50
|
|
|
|
if (SvMAGICAL((SV*)cv)) |
10474
|
4
|
|
|
|
|
mg_free_type((SV*)cv, PERL_MAGIC_checkcall); |
10475
|
|
|
|
|
|
} else { |
10476
|
|
|
|
|
|
MAGIC *callmg; |
10477
|
1384
|
|
|
|
|
sv_magic((SV*)cv, &PL_sv_undef, PERL_MAGIC_checkcall, NULL, 0); |
10478
|
1384
|
|
|
|
|
callmg = mg_find((SV*)cv, PERL_MAGIC_checkcall); |
10479
|
1384
|
50
|
|
|
|
if (callmg->mg_flags & MGf_REFCOUNTED) { |
10480
|
1384
|
|
|
|
|
SvREFCNT_dec(callmg->mg_obj); |
10481
|
1384
|
|
|
|
|
callmg->mg_flags &= ~MGf_REFCOUNTED; |
10482
|
|
|
|
|
|
} |
10483
|
1384
|
|
|
|
|
callmg->mg_ptr = FPTR2DPTR(char *, ckfun); |
10484
|
1384
|
|
|
|
|
callmg->mg_obj = ckobj; |
10485
|
1384
|
100
|
|
|
|
if (ckobj != (SV*)cv) { |
10486
|
836
|
|
|
|
|
SvREFCNT_inc_simple_void_NN(ckobj); |
10487
|
836
|
|
|
|
|
callmg->mg_flags |= MGf_REFCOUNTED; |
10488
|
|
|
|
|
|
} |
10489
|
1384
|
|
|
|
|
callmg->mg_flags |= MGf_COPY; |
10490
|
|
|
|
|
|
} |
10491
|
1388
|
|
|
|
|
} |
10492
|
|
|
|
|
|
|
10493
|
|
|
|
|
|
OP * |
10494
|
27955039
|
|
|
|
|
Perl_ck_subr(pTHX_ OP *o) |
10495
|
|
|
|
|
|
{ |
10496
|
|
|
|
|
|
OP *aop, *cvop; |
10497
|
|
|
|
|
|
CV *cv; |
10498
|
|
|
|
|
|
GV *namegv; |
10499
|
|
|
|
|
|
|
10500
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_SUBR; |
10501
|
|
|
|
|
|
|
10502
|
27955039
|
|
|
|
|
aop = cUNOPx(o)->op_first; |
10503
|
27955039
|
100
|
|
|
|
if (!aop->op_sibling) |
10504
|
11638889
|
|
|
|
|
aop = cUNOPx(aop)->op_first; |
10505
|
27955039
|
|
|
|
|
aop = aop->op_sibling; |
10506
|
49081060
|
100
|
|
|
|
for (cvop = aop; cvop->op_sibling; cvop = cvop->op_sibling) ; |
10507
|
27955039
|
|
|
|
|
cv = rv2cv_op_cv(cvop, RV2CVOPCV_MARK_EARLY); |
10508
|
27955039
|
100
|
|
|
|
namegv = cv ? (GV*)rv2cv_op_cv(cvop, RV2CVOPCV_RETURN_NAME_GV) : NULL; |
10509
|
|
|
|
|
|
|
10510
|
27955039
|
|
|
|
|
o->op_private &= ~1; |
10511
|
27955039
|
|
|
|
|
o->op_private |= OPpENTERSUB_HASTARG; |
10512
|
27955039
|
|
|
|
|
o->op_private |= (PL_hints & HINT_STRICT_REFS); |
10513
|
27955039
|
100
|
|
|
|
if (PERLDB_SUB && PL_curstash != PL_debstash) |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
10514
|
72038
|
|
|
|
|
o->op_private |= OPpENTERSUB_DB; |
10515
|
27955039
|
100
|
|
|
|
if (cvop->op_type == OP_RV2CV) { |
10516
|
11638879
|
|
|
|
|
o->op_private |= (cvop->op_private & OPpENTERSUB_AMPER); |
10517
|
11638879
|
|
|
|
|
op_null(cvop); |
10518
|
16316160
|
100
|
|
|
|
} else if (cvop->op_type == OP_METHOD || cvop->op_type == OP_METHOD_NAMED) { |
10519
|
16316150
|
100
|
|
|
|
if (aop->op_type == OP_CONST) |
10520
|
5133464
|
|
|
|
|
aop->op_private &= ~OPpCONST_STRICT; |
10521
|
11182686
|
50
|
|
|
|
else if (aop->op_type == OP_LIST) { |
10522
|
0
|
|
|
|
|
OP * const sib = ((UNOP*)aop)->op_first->op_sibling; |
10523
|
0
|
0
|
|
|
|
if (sib && sib->op_type == OP_CONST) |
|
|
0
|
|
|
|
|
10524
|
0
|
|
|
|
|
sib->op_private &= ~OPpCONST_STRICT; |
10525
|
|
|
|
|
|
} |
10526
|
|
|
|
|
|
} |
10527
|
|
|
|
|
|
|
10528
|
27955039
|
100
|
|
|
|
if (!cv) { |
10529
|
20670369
|
|
|
|
|
return ck_entersub_args_list(o); |
10530
|
|
|
|
|
|
} else { |
10531
|
|
|
|
|
|
Perl_call_checker ckfun; |
10532
|
|
|
|
|
|
SV *ckobj; |
10533
|
7284670
|
|
|
|
|
cv_get_call_checker(cv, &ckfun, &ckobj); |
10534
|
7284670
|
100
|
|
|
|
if (!namegv) { /* expletive! */ |
10535
|
|
|
|
|
|
/* XXX The call checker API is public. And it guarantees that |
10536
|
|
|
|
|
|
a GV will be provided with the right name. So we have |
10537
|
|
|
|
|
|
to create a GV. But it is still not correct, as its |
10538
|
|
|
|
|
|
stringification will include the package. What we |
10539
|
|
|
|
|
|
really need is a new call checker API that accepts a |
10540
|
|
|
|
|
|
GV or string (or GV or CV). */ |
10541
|
|
|
|
|
|
HEK * const hek = CvNAME_HEK(cv); |
10542
|
|
|
|
|
|
/* After a syntax error in a lexical sub, the cv that |
10543
|
|
|
|
|
|
rv2cv_op_cv returns may be a nameless stub. */ |
10544
|
106
|
100
|
|
|
|
if (!hek) return ck_entersub_args_list(o);; |
10545
|
102
|
|
|
|
|
namegv = (GV *)sv_newmortal(); |
10546
|
102
|
|
|
|
|
gv_init_pvn(namegv, PL_curstash, HEK_KEY(hek), HEK_LEN(hek), |
10547
|
|
|
|
|
|
SVf_UTF8 * !!HEK_UTF8(hek)); |
10548
|
|
|
|
|
|
} |
10549
|
17852568
|
|
|
|
|
return ckfun(aTHX_ o, namegv, ckobj); |
10550
|
|
|
|
|
|
} |
10551
|
|
|
|
|
|
} |
10552
|
|
|
|
|
|
|
10553
|
|
|
|
|
|
OP * |
10554
|
184803481
|
|
|
|
|
Perl_ck_svconst(pTHX_ OP *o) |
10555
|
|
|
|
|
|
{ |
10556
|
184803481
|
|
|
|
|
SV * const sv = cSVOPo->op_sv; |
10557
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_SVCONST; |
10558
|
|
|
|
|
|
PERL_UNUSED_CONTEXT; |
10559
|
|
|
|
|
|
#ifdef PERL_OLD_COPY_ON_WRITE |
10560
|
|
|
|
|
|
if (SvIsCOW(sv)) sv_force_normal(sv); |
10561
|
|
|
|
|
|
#elif defined(PERL_NEW_COPY_ON_WRITE) |
10562
|
|
|
|
|
|
/* Since the read-only flag may be used to protect a string buffer, we |
10563
|
|
|
|
|
|
cannot do copy-on-write with existing read-only scalars that are not |
10564
|
|
|
|
|
|
already copy-on-write scalars. To allow $_ = "hello" to do COW with |
10565
|
|
|
|
|
|
that constant, mark the constant as COWable here, if it is not |
10566
|
|
|
|
|
|
already read-only. */ |
10567
|
184803481
|
100
|
|
|
|
if (!SvREADONLY(sv) && !SvIsCOW(sv) && SvCANCOW(sv)) { |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
10568
|
127434890
|
|
|
|
|
SvIsCOW_on(sv); |
10569
|
127434890
|
|
|
|
|
CowREFCNT(sv) = 0; |
10570
|
|
|
|
|
|
} |
10571
|
|
|
|
|
|
#endif |
10572
|
184803481
|
|
|
|
|
SvREADONLY_on(sv); |
10573
|
184803481
|
|
|
|
|
return o; |
10574
|
|
|
|
|
|
} |
10575
|
|
|
|
|
|
|
10576
|
|
|
|
|
|
OP * |
10577
|
90725
|
|
|
|
|
Perl_ck_trunc(pTHX_ OP *o) |
10578
|
|
|
|
|
|
{ |
10579
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_TRUNC; |
10580
|
|
|
|
|
|
|
10581
|
90725
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
10582
|
90611
|
|
|
|
|
SVOP *kid = (SVOP*)cUNOPo->op_first; |
10583
|
|
|
|
|
|
|
10584
|
90611
|
100
|
|
|
|
if (kid->op_type == OP_NULL) |
10585
|
8365
|
|
|
|
|
kid = (SVOP*)kid->op_sibling; |
10586
|
97081
|
100
|
|
|
|
if (kid && kid->op_type == OP_CONST && |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
10587
|
11407
|
100
|
|
|
|
(kid->op_private & OPpCONST_BARE) && |
10588
|
4937
|
|
|
|
|
!kid->op_folded) |
10589
|
|
|
|
|
|
{ |
10590
|
4935
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; |
10591
|
4935
|
|
|
|
|
kid->op_private &= ~OPpCONST_STRICT; |
10592
|
|
|
|
|
|
} |
10593
|
|
|
|
|
|
} |
10594
|
90725
|
|
|
|
|
return ck_fun(o); |
10595
|
|
|
|
|
|
} |
10596
|
|
|
|
|
|
|
10597
|
|
|
|
|
|
OP * |
10598
|
500993
|
|
|
|
|
Perl_ck_substr(pTHX_ OP *o) |
10599
|
|
|
|
|
|
{ |
10600
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_SUBSTR; |
10601
|
|
|
|
|
|
|
10602
|
500993
|
|
|
|
|
o = ck_fun(o); |
10603
|
500993
|
50
|
|
|
|
if ((o->op_flags & OPf_KIDS) && (o->op_private == 4)) { |
|
|
100
|
|
|
|
|
10604
|
41202
|
|
|
|
|
OP *kid = cLISTOPo->op_first; |
10605
|
|
|
|
|
|
|
10606
|
41202
|
50
|
|
|
|
if (kid->op_type == OP_NULL) |
10607
|
41202
|
|
|
|
|
kid = kid->op_sibling; |
10608
|
41202
|
50
|
|
|
|
if (kid) |
10609
|
41202
|
|
|
|
|
kid->op_flags |= OPf_MOD; |
10610
|
|
|
|
|
|
|
10611
|
|
|
|
|
|
} |
10612
|
500993
|
|
|
|
|
return o; |
10613
|
|
|
|
|
|
} |
10614
|
|
|
|
|
|
|
10615
|
|
|
|
|
|
OP * |
10616
|
13018
|
|
|
|
|
Perl_ck_tell(pTHX_ OP *o) |
10617
|
|
|
|
|
|
{ |
10618
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_TELL; |
10619
|
13018
|
|
|
|
|
o = ck_fun(o); |
10620
|
13018
|
100
|
|
|
|
if (o->op_flags & OPf_KIDS) { |
10621
|
12974
|
|
|
|
|
OP *kid = cLISTOPo->op_first; |
10622
|
12974
|
100
|
|
|
|
if (kid->op_type == OP_NULL && kid->op_sibling) kid = kid->op_sibling; |
|
|
50
|
|
|
|
|
10623
|
12974
|
100
|
|
|
|
if (kid->op_type == OP_RV2GV) kid->op_private |= OPpALLOW_FAKE; |
10624
|
|
|
|
|
|
} |
10625
|
13018
|
|
|
|
|
return o; |
10626
|
|
|
|
|
|
} |
10627
|
|
|
|
|
|
|
10628
|
|
|
|
|
|
OP * |
10629
|
617068
|
|
|
|
|
Perl_ck_each(pTHX_ OP *o) |
10630
|
|
|
|
|
|
{ |
10631
|
|
|
|
|
|
dVAR; |
10632
|
617068
|
100
|
|
|
|
OP *kid = o->op_flags & OPf_KIDS ? cUNOPo->op_first : NULL; |
10633
|
617068
|
|
|
|
|
const unsigned orig_type = o->op_type; |
10634
|
617068
|
100
|
|
|
|
const unsigned array_type = orig_type == OP_EACH ? OP_AEACH |
|
|
100
|
|
|
|
|
10635
|
|
|
|
|
|
: orig_type == OP_KEYS ? OP_AKEYS : OP_AVALUES; |
10636
|
617068
|
100
|
|
|
|
const unsigned ref_type = orig_type == OP_EACH ? OP_REACH |
|
|
100
|
|
|
|
|
10637
|
|
|
|
|
|
: orig_type == OP_KEYS ? OP_RKEYS : OP_RVALUES; |
10638
|
|
|
|
|
|
|
10639
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_EACH; |
10640
|
|
|
|
|
|
|
10641
|
617068
|
100
|
|
|
|
if (kid) { |
10642
|
617062
|
|
|
|
|
switch (kid->op_type) { |
10643
|
|
|
|
|
|
case OP_PADHV: |
10644
|
|
|
|
|
|
case OP_RV2HV: |
10645
|
|
|
|
|
|
break; |
10646
|
|
|
|
|
|
case OP_PADAV: |
10647
|
|
|
|
|
|
case OP_RV2AV: |
10648
|
108
|
|
|
|
|
CHANGE_TYPE(o, array_type); |
10649
|
108
|
|
|
|
|
break; |
10650
|
|
|
|
|
|
case OP_CONST: |
10651
|
138
|
100
|
|
|
|
if (kid->op_private == OPpCONST_BARE |
10652
|
126
|
100
|
|
|
|
|| !SvROK(cSVOPx_sv(kid)) |
10653
|
180
|
50
|
|
|
|
|| ( SvTYPE(SvRV(cSVOPx_sv(kid))) != SVt_PVAV |
10654
|
120
|
|
|
|
|
&& SvTYPE(SvRV(cSVOPx_sv(kid))) != SVt_PVHV ) |
10655
|
|
|
|
|
|
) |
10656
|
|
|
|
|
|
/* we let ck_fun handle it */ |
10657
|
|
|
|
|
|
break; |
10658
|
|
|
|
|
|
default: |
10659
|
506
|
|
|
|
|
CHANGE_TYPE(o, ref_type); |
10660
|
506
|
|
|
|
|
scalar(kid); |
10661
|
|
|
|
|
|
} |
10662
|
|
|
|
|
|
} |
10663
|
|
|
|
|
|
/* if treating as a reference, defer additional checks to runtime */ |
10664
|
617068
|
100
|
|
|
|
return o->op_type == ref_type ? o : ck_fun(o); |
10665
|
|
|
|
|
|
} |
10666
|
|
|
|
|
|
|
10667
|
|
|
|
|
|
OP * |
10668
|
624797
|
|
|
|
|
Perl_ck_length(pTHX_ OP *o) |
10669
|
|
|
|
|
|
{ |
10670
|
|
|
|
|
|
PERL_ARGS_ASSERT_CK_LENGTH; |
10671
|
|
|
|
|
|
|
10672
|
624797
|
|
|
|
|
o = ck_fun(o); |
10673
|
|
|
|
|
|
|
10674
|
624797
|
100
|
|
|
|
if (ckWARN(WARN_SYNTAX)) { |
10675
|
263315
|
50
|
|
|
|
const OP *kid = o->op_flags & OPf_KIDS ? cLISTOPo->op_first : NULL; |
10676
|
|
|
|
|
|
|
10677
|
263315
|
50
|
|
|
|
if (kid) { |
10678
|
|
|
|
|
|
SV *name = NULL; |
10679
|
526630
|
|
|
|
|
const bool hash = kid->op_type == OP_PADHV |
10680
|
263315
|
|
|
|
|
|| kid->op_type == OP_RV2HV; |
10681
|
263315
|
|
|
|
|
switch (kid->op_type) { |
10682
|
|
|
|
|
|
case OP_PADHV: |
10683
|
|
|
|
|
|
case OP_PADAV: |
10684
|
6
|
100
|
|
|
|
name = varname( |
10685
|
|
|
|
|
|
(GV *)PL_compcv, hash ? '%' : '@', kid->op_targ, |
10686
|
|
|
|
|
|
NULL, 0, 1 |
10687
|
|
|
|
|
|
); |
10688
|
6
|
|
|
|
|
break; |
10689
|
|
|
|
|
|
case OP_RV2HV: |
10690
|
|
|
|
|
|
case OP_RV2AV: |
10691
|
8
|
100
|
|
|
|
if (cUNOPx(kid)->op_first->op_type != OP_GV) break; |
10692
|
|
|
|
|
|
{ |
10693
|
4
|
|
|
|
|
GV *gv = cGVOPx_gv(cUNOPx(kid)->op_first); |
10694
|
4
|
50
|
|
|
|
if (!gv) break; |
10695
|
4
|
100
|
|
|
|
name = varname(gv, hash?'%':'@', 0, NULL, 0, 1); |
10696
|
|
|
|
|
|
} |
10697
|
4
|
|
|
|
|
break; |
10698
|
|
|
|
|
|
default: |
10699
|
|
|
|
|
|
return o; |
10700
|
|
|
|
|
|
} |
10701
|
14
|
100
|
|
|
|
if (name) |
10702
|
10
|
100
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
10703
|
|
|
|
|
|
"length() used on %"SVf" (did you mean \"scalar(%s%"SVf |
10704
|
|
|
|
|
|
")\"?)", |
10705
|
|
|
|
|
|
name, hash ? "keys " : "", name |
10706
|
|
|
|
|
|
); |
10707
|
4
|
100
|
|
|
|
else if (hash) |
10708
|
|
|
|
|
|
/* diag_listed_as: length() used on %s (did you mean "scalar(%s)"?) */ |
10709
|
2
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
10710
|
|
|
|
|
|
"length() used on %%hash (did you mean \"scalar(keys %%hash)\"?)"); |
10711
|
|
|
|
|
|
else |
10712
|
|
|
|
|
|
/* diag_listed_as: length() used on %s (did you mean "scalar(%s)"?) */ |
10713
|
331657
|
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_SYNTAX), |
10714
|
|
|
|
|
|
"length() used on @array (did you mean \"scalar(@array)\"?)"); |
10715
|
|
|
|
|
|
} |
10716
|
|
|
|
|
|
} |
10717
|
|
|
|
|
|
|
10718
|
|
|
|
|
|
return o; |
10719
|
|
|
|
|
|
} |
10720
|
|
|
|
|
|
|
10721
|
|
|
|
|
|
/* Check for in place reverse and sort assignments like "@a = reverse @a" |
10722
|
|
|
|
|
|
and modify the optree to make them work inplace */ |
10723
|
|
|
|
|
|
|
10724
|
|
|
|
|
|
STATIC void |
10725
|
5544596
|
|
|
|
|
S_inplace_aassign(pTHX_ OP *o) { |
10726
|
|
|
|
|
|
|
10727
|
|
|
|
|
|
OP *modop, *modop_pushmark; |
10728
|
|
|
|
|
|
OP *oright; |
10729
|
|
|
|
|
|
OP *oleft, *oleft_pushmark; |
10730
|
|
|
|
|
|
|
10731
|
|
|
|
|
|
PERL_ARGS_ASSERT_INPLACE_AASSIGN; |
10732
|
|
|
|
|
|
|
10733
|
|
|
|
|
|
assert((o->op_flags & OPf_WANT) == OPf_WANT_VOID); |
10734
|
|
|
|
|
|
|
10735
|
|
|
|
|
|
assert(cUNOPo->op_first->op_type == OP_NULL); |
10736
|
5544596
|
|
|
|
|
modop_pushmark = cUNOPx(cUNOPo->op_first)->op_first; |
10737
|
|
|
|
|
|
assert(modop_pushmark->op_type == OP_PUSHMARK); |
10738
|
5544596
|
|
|
|
|
modop = modop_pushmark->op_sibling; |
10739
|
|
|
|
|
|
|
10740
|
5544596
|
100
|
|
|
|
if (modop->op_type != OP_SORT && modop->op_type != OP_REVERSE) |
10741
|
|
|
|
|
|
return; |
10742
|
|
|
|
|
|
|
10743
|
|
|
|
|
|
/* no other operation except sort/reverse */ |
10744
|
28114
|
100
|
|
|
|
if (modop->op_sibling) |
10745
|
|
|
|
|
|
return; |
10746
|
|
|
|
|
|
|
10747
|
|
|
|
|
|
assert(cUNOPx(modop)->op_first->op_type == OP_PUSHMARK); |
10748
|
28102
|
100
|
|
|
|
if (!(oright = cUNOPx(modop)->op_first->op_sibling)) return; |
10749
|
|
|
|
|
|
|
10750
|
28096
|
100
|
|
|
|
if (modop->op_flags & OPf_STACKED) { |
10751
|
|
|
|
|
|
/* skip sort subroutine/block */ |
10752
|
|
|
|
|
|
assert(oright->op_type == OP_NULL); |
10753
|
11196
|
|
|
|
|
oright = oright->op_sibling; |
10754
|
|
|
|
|
|
} |
10755
|
|
|
|
|
|
|
10756
|
|
|
|
|
|
assert(cUNOPo->op_first->op_sibling->op_type == OP_NULL); |
10757
|
28096
|
|
|
|
|
oleft_pushmark = cUNOPx(cUNOPo->op_first->op_sibling)->op_first; |
10758
|
|
|
|
|
|
assert(oleft_pushmark->op_type == OP_PUSHMARK); |
10759
|
28096
|
|
|
|
|
oleft = oleft_pushmark->op_sibling; |
10760
|
|
|
|
|
|
|
10761
|
|
|
|
|
|
/* Check the lhs is an array */ |
10762
|
41784
|
50
|
|
|
|
if (!oleft || |
|
|
100
|
|
|
|
|
10763
|
28096
|
|
|
|
|
(oleft->op_type != OP_RV2AV && oleft->op_type != OP_PADAV) |
10764
|
23192
|
50
|
|
|
|
|| oleft->op_sibling |
10765
|
23192
|
100
|
|
|
|
|| (oleft->op_private & OPpLVAL_INTRO) |
10766
|
|
|
|
|
|
) |
10767
|
|
|
|
|
|
return; |
10768
|
|
|
|
|
|
|
10769
|
|
|
|
|
|
/* Only one thing on the rhs */ |
10770
|
10384
|
100
|
|
|
|
if (oright->op_sibling) |
10771
|
|
|
|
|
|
return; |
10772
|
|
|
|
|
|
|
10773
|
|
|
|
|
|
/* check the array is the same on both sides */ |
10774
|
10284
|
100
|
|
|
|
if (oleft->op_type == OP_RV2AV) { |
10775
|
9442
|
100
|
|
|
|
if (oright->op_type != OP_RV2AV |
10776
|
4752
|
50
|
|
|
|
|| !cUNOPx(oright)->op_first |
10777
|
4752
|
100
|
|
|
|
|| cUNOPx(oright)->op_first->op_type != OP_GV |
10778
|
74
|
50
|
|
|
|
|| cUNOPx(oleft )->op_first->op_type != OP_GV |
10779
|
111
|
100
|
|
|
|
|| cGVOPx_gv(cUNOPx(oleft)->op_first) != |
10780
|
74
|
|
|
|
|
cGVOPx_gv(cUNOPx(oright)->op_first) |
10781
|
|
|
|
|
|
) |
10782
|
|
|
|
|
|
return; |
10783
|
|
|
|
|
|
} |
10784
|
842
|
100
|
|
|
|
else if (oright->op_type != OP_PADAV |
10785
|
480
|
100
|
|
|
|
|| oright->op_targ != oleft->op_targ |
10786
|
|
|
|
|
|
) |
10787
|
|
|
|
|
|
return; |
10788
|
|
|
|
|
|
|
10789
|
|
|
|
|
|
/* This actually is an inplace assignment */ |
10790
|
|
|
|
|
|
|
10791
|
498
|
|
|
|
|
modop->op_private |= OPpSORT_INPLACE; |
10792
|
|
|
|
|
|
|
10793
|
|
|
|
|
|
/* transfer MODishness etc from LHS arg to RHS arg */ |
10794
|
498
|
|
|
|
|
oright->op_flags = oleft->op_flags; |
10795
|
|
|
|
|
|
|
10796
|
|
|
|
|
|
/* remove the aassign op and the lhs */ |
10797
|
498
|
|
|
|
|
op_null(o); |
10798
|
498
|
|
|
|
|
op_null(oleft_pushmark); |
10799
|
498
|
100
|
|
|
|
if (oleft->op_type == OP_RV2AV && cUNOPx(oleft)->op_first) |
|
|
50
|
|
|
|
|
10800
|
38
|
|
|
|
|
op_null(cUNOPx(oleft)->op_first); |
10801
|
2870815
|
|
|
|
|
op_null(oleft); |
10802
|
|
|
|
|
|
} |
10803
|
|
|
|
|
|
|
10804
|
|
|
|
|
|
#define MAX_DEFERRED 4 |
10805
|
|
|
|
|
|
|
10806
|
|
|
|
|
|
#define DEFER(o) \ |
10807
|
|
|
|
|
|
STMT_START { \ |
10808
|
|
|
|
|
|
if (defer_ix == (MAX_DEFERRED-1)) { \ |
10809
|
|
|
|
|
|
CALL_RPEEP(defer_queue[defer_base]); \ |
10810
|
|
|
|
|
|
defer_base = (defer_base + 1) % MAX_DEFERRED; \ |
10811
|
|
|
|
|
|
defer_ix--; \ |
10812
|
|
|
|
|
|
} \ |
10813
|
|
|
|
|
|
defer_queue[(defer_base + ++defer_ix) % MAX_DEFERRED] = o; \ |
10814
|
|
|
|
|
|
} STMT_END |
10815
|
|
|
|
|
|
|
10816
|
|
|
|
|
|
/* A peephole optimizer. We visit the ops in the order they're to execute. |
10817
|
|
|
|
|
|
* See the comments at the top of this file for more details about when |
10818
|
|
|
|
|
|
* peep() is called */ |
10819
|
|
|
|
|
|
|
10820
|
|
|
|
|
|
void |
10821
|
46734451
|
|
|
|
|
Perl_rpeep(pTHX_ OP *o) |
10822
|
|
|
|
|
|
{ |
10823
|
|
|
|
|
|
dVAR; |
10824
|
|
|
|
|
|
OP* oldop = NULL; |
10825
|
|
|
|
|
|
OP* oldoldop = NULL; |
10826
|
|
|
|
|
|
OP* defer_queue[MAX_DEFERRED]; /* small queue of deferred branches */ |
10827
|
|
|
|
|
|
int defer_base = 0; |
10828
|
|
|
|
|
|
int defer_ix = -1; |
10829
|
|
|
|
|
|
|
10830
|
46734451
|
100
|
|
|
|
if (!o || o->op_opt) |
|
|
100
|
|
|
|
|
10831
|
46734451
|
|
|
|
|
return; |
10832
|
43494996
|
|
|
|
|
ENTER; |
10833
|
43494996
|
|
|
|
|
SAVEOP(); |
10834
|
43494996
|
|
|
|
|
SAVEVPTR(PL_curcop); |
10835
|
699142156
|
|
|
|
|
for (;; o = o->op_next) { |
10836
|
742637152
|
100
|
|
|
|
if (o && o->op_opt) |
|
|
100
|
|
|
|
|
10837
|
|
|
|
|
|
o = NULL; |
10838
|
742637152
|
100
|
|
|
|
if (!o) { |
10839
|
67657025
|
100
|
|
|
|
while (defer_ix >= 0) |
10840
|
24162029
|
|
|
|
|
CALL_RPEEP(defer_queue[(defer_base + defer_ix--) % MAX_DEFERRED]); |
10841
|
|
|
|
|
|
break; |
10842
|
|
|
|
|
|
} |
10843
|
|
|
|
|
|
|
10844
|
|
|
|
|
|
/* By default, this op has now been optimised. A couple of cases below |
10845
|
|
|
|
|
|
clear this again. */ |
10846
|
699142156
|
|
|
|
|
o->op_opt = 1; |
10847
|
699142156
|
|
|
|
|
PL_op = o; |
10848
|
699142156
|
|
|
|
|
switch (o->op_type) { |
10849
|
|
|
|
|
|
case OP_DBSTATE: |
10850
|
317896
|
|
|
|
|
PL_curcop = ((COP*)o); /* for warnings */ |
10851
|
317896
|
|
|
|
|
break; |
10852
|
|
|
|
|
|
case OP_NEXTSTATE: |
10853
|
73859583
|
|
|
|
|
PL_curcop = ((COP*)o); /* for warnings */ |
10854
|
|
|
|
|
|
|
10855
|
|
|
|
|
|
/* Two NEXTSTATEs in a row serve no purpose. Except if they happen |
10856
|
|
|
|
|
|
to carry two labels. For now, take the easier option, and skip |
10857
|
|
|
|
|
|
this optimisation if the first NEXTSTATE has a label. */ |
10858
|
73859583
|
100
|
|
|
|
if (!CopLABEL((COP*)o) && !PERLDB_NOOPT) { |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
10859
|
47884221
|
|
|
|
|
OP *nextop = o->op_next; |
10860
|
73183594
|
50
|
|
|
|
while (nextop && nextop->op_type == OP_NULL) |
|
|
100
|
|
|
|
|
10861
|
2578226
|
|
|
|
|
nextop = nextop->op_next; |
10862
|
|
|
|
|
|
|
10863
|
47884221
|
50
|
|
|
|
if (nextop && (nextop->op_type == OP_NEXTSTATE)) { |
|
|
100
|
|
|
|
|
10864
|
|
|
|
|
|
COP *firstcop = (COP *)o; |
10865
|
|
|
|
|
|
COP *secondcop = (COP *)nextop; |
10866
|
|
|
|
|
|
/* We want the COP pointed to by o (and anything else) to |
10867
|
|
|
|
|
|
become the next COP down the line. */ |
10868
|
1746968
|
|
|
|
|
cop_free(firstcop); |
10869
|
|
|
|
|
|
|
10870
|
1746968
|
|
|
|
|
firstcop->op_next = secondcop->op_next; |
10871
|
|
|
|
|
|
|
10872
|
|
|
|
|
|
/* Now steal all its pointers, and duplicate the other |
10873
|
|
|
|
|
|
data. */ |
10874
|
1746968
|
|
|
|
|
firstcop->cop_line = secondcop->cop_line; |
10875
|
|
|
|
|
|
#ifdef USE_ITHREADS |
10876
|
|
|
|
|
|
firstcop->cop_stashoff = secondcop->cop_stashoff; |
10877
|
|
|
|
|
|
firstcop->cop_file = secondcop->cop_file; |
10878
|
|
|
|
|
|
#else |
10879
|
1746968
|
|
|
|
|
firstcop->cop_stash = secondcop->cop_stash; |
10880
|
1746968
|
|
|
|
|
firstcop->cop_filegv = secondcop->cop_filegv; |
10881
|
|
|
|
|
|
#endif |
10882
|
1746968
|
|
|
|
|
firstcop->cop_hints = secondcop->cop_hints; |
10883
|
1746968
|
|
|
|
|
firstcop->cop_seq = secondcop->cop_seq; |
10884
|
1746968
|
|
|
|
|
firstcop->cop_warnings = secondcop->cop_warnings; |
10885
|
1746968
|
|
|
|
|
firstcop->cop_hints_hash = secondcop->cop_hints_hash; |
10886
|
|
|
|
|
|
|
10887
|
|
|
|
|
|
#ifdef USE_ITHREADS |
10888
|
|
|
|
|
|
secondcop->cop_stashoff = 0; |
10889
|
|
|
|
|
|
secondcop->cop_file = NULL; |
10890
|
|
|
|
|
|
#else |
10891
|
1746968
|
|
|
|
|
secondcop->cop_stash = NULL; |
10892
|
1746968
|
|
|
|
|
secondcop->cop_filegv = NULL; |
10893
|
|
|
|
|
|
#endif |
10894
|
1746968
|
|
|
|
|
secondcop->cop_warnings = NULL; |
10895
|
1746968
|
|
|
|
|
secondcop->cop_hints_hash = NULL; |
10896
|
|
|
|
|
|
|
10897
|
|
|
|
|
|
/* If we use op_null(), and hence leave an ex-COP, some |
10898
|
|
|
|
|
|
warnings are misreported. For example, the compile-time |
10899
|
|
|
|
|
|
error in 'use strict; no strict refs;' */ |
10900
|
1746968
|
|
|
|
|
secondcop->op_type = OP_NULL; |
10901
|
1746968
|
|
|
|
|
secondcop->op_ppaddr = PL_ppaddr[OP_NULL]; |
10902
|
|
|
|
|
|
} |
10903
|
|
|
|
|
|
} |
10904
|
|
|
|
|
|
break; |
10905
|
|
|
|
|
|
|
10906
|
|
|
|
|
|
case OP_CONCAT: |
10907
|
13705201
|
50
|
|
|
|
if (o->op_next && o->op_next->op_type == OP_STRINGIFY) { |
|
|
100
|
|
|
|
|
10908
|
4050732
|
100
|
|
|
|
if (o->op_next->op_private & OPpTARGET_MY) { |
10909
|
246850
|
100
|
|
|
|
if (o->op_flags & OPf_STACKED) /* chained concats */ |
10910
|
|
|
|
|
|
break; /* ignore_optimization */ |
10911
|
|
|
|
|
|
else { |
10912
|
|
|
|
|
|
/* assert(PL_opargs[o->op_type] & OA_TARGLEX); */ |
10913
|
104256
|
|
|
|
|
o->op_targ = o->op_next->op_targ; |
10914
|
104256
|
|
|
|
|
o->op_next->op_targ = 0; |
10915
|
104256
|
|
|
|
|
o->op_private |= OPpTARGET_MY; |
10916
|
|
|
|
|
|
} |
10917
|
|
|
|
|
|
} |
10918
|
3908138
|
|
|
|
|
op_null(o->op_next); |
10919
|
|
|
|
|
|
} |
10920
|
|
|
|
|
|
break; |
10921
|
|
|
|
|
|
case OP_STUB: |
10922
|
709110
|
100
|
|
|
|
if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) { |
10923
|
|
|
|
|
|
break; /* Scalar stub must produce undef. List stub is noop */ |
10924
|
|
|
|
|
|
} |
10925
|
|
|
|
|
|
goto nothin; |
10926
|
|
|
|
|
|
case OP_NULL: |
10927
|
136640229
|
100
|
|
|
|
if (o->op_targ == OP_NEXTSTATE |
10928
|
92233827
|
|
|
|
|
|| o->op_targ == OP_DBSTATE) |
10929
|
|
|
|
|
|
{ |
10930
|
3192970
|
|
|
|
|
PL_curcop = ((COP*)o); |
10931
|
|
|
|
|
|
} |
10932
|
|
|
|
|
|
/* XXX: We avoid setting op_seq here to prevent later calls |
10933
|
|
|
|
|
|
to rpeep() from mistakenly concluding that optimisation |
10934
|
|
|
|
|
|
has already occurred. This doesn't fix the real problem, |
10935
|
|
|
|
|
|
though (See 20010220.007). AMS 20010719 */ |
10936
|
|
|
|
|
|
/* op_seq functionality is now replaced by op_opt */ |
10937
|
92233827
|
|
|
|
|
o->op_opt = 0; |
10938
|
|
|
|
|
|
/* FALL THROUGH */ |
10939
|
|
|
|
|
|
case OP_SCALAR: |
10940
|
|
|
|
|
|
case OP_LINESEQ: |
10941
|
|
|
|
|
|
case OP_SCOPE: |
10942
|
|
|
|
|
|
nothin: |
10943
|
122775011
|
100
|
|
|
|
if (oldop && o->op_next) { |
|
|
100
|
|
|
|
|
10944
|
122657047
|
|
|
|
|
oldop->op_next = o->op_next; |
10945
|
122657047
|
|
|
|
|
o->op_opt = 0; |
10946
|
122657047
|
|
|
|
|
continue; |
10947
|
|
|
|
|
|
} |
10948
|
|
|
|
|
|
break; |
10949
|
|
|
|
|
|
|
10950
|
|
|
|
|
|
case OP_PUSHMARK: |
10951
|
|
|
|
|
|
|
10952
|
|
|
|
|
|
/* Convert a series of PAD ops for my vars plus support into a |
10953
|
|
|
|
|
|
* single padrange op. Basically |
10954
|
|
|
|
|
|
* |
10955
|
|
|
|
|
|
* pushmark -> pad[ahs]v -> pad[ahs]?v -> ... -> (list) -> rest |
10956
|
|
|
|
|
|
* |
10957
|
|
|
|
|
|
* becomes, depending on circumstances, one of |
10958
|
|
|
|
|
|
* |
10959
|
|
|
|
|
|
* padrange ----------------------------------> (list) -> rest |
10960
|
|
|
|
|
|
* padrange --------------------------------------------> rest |
10961
|
|
|
|
|
|
* |
10962
|
|
|
|
|
|
* where all the pad indexes are sequential and of the same type |
10963
|
|
|
|
|
|
* (INTRO or not). |
10964
|
|
|
|
|
|
* We convert the pushmark into a padrange op, then skip |
10965
|
|
|
|
|
|
* any other pad ops, and possibly some trailing ops. |
10966
|
|
|
|
|
|
* Note that we don't null() the skipped ops, to make it |
10967
|
|
|
|
|
|
* easier for Deparse to undo this optimisation (and none of |
10968
|
|
|
|
|
|
* the skipped ops are holding any resourses). It also makes |
10969
|
|
|
|
|
|
* it easier for find_uninit_var(), as it can just ignore |
10970
|
|
|
|
|
|
* padrange, and examine the original pad ops. |
10971
|
|
|
|
|
|
*/ |
10972
|
|
|
|
|
|
{ |
10973
|
|
|
|
|
|
OP *p; |
10974
|
|
|
|
|
|
OP *followop = NULL; /* the op that will follow the padrange op */ |
10975
|
|
|
|
|
|
U8 count = 0; |
10976
|
|
|
|
|
|
U8 intro = 0; |
10977
|
|
|
|
|
|
PADOFFSET base = 0; /* init only to stop compiler whining */ |
10978
|
|
|
|
|
|
U8 gimme = 0; /* init only to stop compiler whining */ |
10979
|
|
|
|
|
|
bool defav = 0; /* seen (...) = @_ */ |
10980
|
|
|
|
|
|
bool reuse = 0; /* reuse an existing padrange op */ |
10981
|
|
|
|
|
|
|
10982
|
|
|
|
|
|
/* look for a pushmark -> gv[_] -> rv2av */ |
10983
|
|
|
|
|
|
|
10984
|
|
|
|
|
|
{ |
10985
|
|
|
|
|
|
GV *gv; |
10986
|
|
|
|
|
|
OP *rv2av, *q; |
10987
|
55191813
|
|
|
|
|
p = o->op_next; |
10988
|
55191813
|
100
|
|
|
|
if ( p->op_type == OP_GV |
10989
|
8605766
|
50
|
|
|
|
&& (gv = cGVOPx_gv(p)) |
10990
|
8605766
|
100
|
|
|
|
&& GvNAMELEN_get(gv) == 1 |
10991
|
5300647
|
100
|
|
|
|
&& *GvNAME_get(gv) == '_' |
10992
|
4818318
|
100
|
|
|
|
&& GvSTASH(gv) == PL_defstash |
10993
|
4818308
|
50
|
|
|
|
&& (rv2av = p->op_next) |
10994
|
4818308
|
100
|
|
|
|
&& rv2av->op_type == OP_RV2AV |
10995
|
4523656
|
100
|
|
|
|
&& !(rv2av->op_flags & OPf_REF) |
10996
|
3965357
|
50
|
|
|
|
&& !(rv2av->op_private & (OPpLVAL_INTRO|OPpMAYBE_LVSUB)) |
10997
|
3965357
|
100
|
|
|
|
&& ((rv2av->op_flags & OPf_WANT) == OPf_WANT_LIST) |
10998
|
3910633
|
50
|
|
|
|
&& o->op_sibling == rv2av /* these two for Deparse */ |
10999
|
3910633
|
50
|
|
|
|
&& cUNOPx(rv2av)->op_first == p |
11000
|
|
|
|
|
|
) { |
11001
|
3910633
|
|
|
|
|
q = rv2av->op_next; |
11002
|
3910633
|
100
|
|
|
|
if (q->op_type == OP_NULL) |
11003
|
2144370
|
|
|
|
|
q = q->op_next; |
11004
|
3910633
|
100
|
|
|
|
if (q->op_type == OP_PUSHMARK) { |
11005
|
|
|
|
|
|
defav = 1; |
11006
|
|
|
|
|
|
p = q; |
11007
|
|
|
|
|
|
} |
11008
|
|
|
|
|
|
} |
11009
|
|
|
|
|
|
} |
11010
|
55191813
|
100
|
|
|
|
if (!defav) { |
11011
|
|
|
|
|
|
/* To allow Deparse to pessimise this, it needs to be able |
11012
|
|
|
|
|
|
* to restore the pushmark's original op_next, which it |
11013
|
|
|
|
|
|
* will assume to be the same as op_sibling. */ |
11014
|
52646925
|
100
|
|
|
|
if (o->op_next != o->op_sibling) |
11015
|
|
|
|
|
|
break; |
11016
|
|
|
|
|
|
p = o; |
11017
|
|
|
|
|
|
} |
11018
|
|
|
|
|
|
|
11019
|
|
|
|
|
|
/* scan for PAD ops */ |
11020
|
|
|
|
|
|
|
11021
|
66002108
|
50
|
|
|
|
for (p = p->op_next; p; p = p->op_next) { |
11022
|
66002108
|
100
|
|
|
|
if (p->op_type == OP_NULL) |
11023
|
6633552
|
|
|
|
|
continue; |
11024
|
|
|
|
|
|
|
11025
|
88235175
|
100
|
|
|
|
if (( p->op_type != OP_PADSV |
11026
|
|
|
|
|
|
&& p->op_type != OP_PADAV |
11027
|
59368556
|
|
|
|
|
&& p->op_type != OP_PADHV |
11028
|
|
|
|
|
|
) |
11029
|
|
|
|
|
|
/* any private flag other than INTRO? e.g. STATE */ |
11030
|
28686843
|
100
|
|
|
|
|| (p->op_private & ~OPpLVAL_INTRO) |
11031
|
|
|
|
|
|
) |
11032
|
|
|
|
|
|
break; |
11033
|
|
|
|
|
|
|
11034
|
|
|
|
|
|
/* let $a[N] potentially be optimised into ALEMFAST_LEX |
11035
|
|
|
|
|
|
* instead */ |
11036
|
28331397
|
100
|
|
|
|
if ( p->op_type == OP_PADAV |
11037
|
3184926
|
50
|
|
|
|
&& p->op_next |
11038
|
3184926
|
100
|
|
|
|
&& p->op_next->op_type == OP_CONST |
11039
|
162030
|
50
|
|
|
|
&& p->op_next->op_next |
11040
|
162030
|
100
|
|
|
|
&& p->op_next->op_next->op_type == OP_AELEM |
11041
|
|
|
|
|
|
) |
11042
|
|
|
|
|
|
break; |
11043
|
|
|
|
|
|
|
11044
|
|
|
|
|
|
/* for 1st padop, note what type it is and the range |
11045
|
|
|
|
|
|
* start; for the others, check that it's the same type |
11046
|
|
|
|
|
|
* and that the targs are contiguous */ |
11047
|
28318515
|
100
|
|
|
|
if (count == 0) { |
11048
|
20390394
|
|
|
|
|
intro = (p->op_private & OPpLVAL_INTRO); |
11049
|
20390394
|
|
|
|
|
base = p->op_targ; |
11050
|
20390394
|
|
|
|
|
gimme = (p->op_flags & OPf_WANT); |
11051
|
|
|
|
|
|
} |
11052
|
|
|
|
|
|
else { |
11053
|
7928121
|
100
|
|
|
|
if ((p->op_private & OPpLVAL_INTRO) != intro) |
11054
|
|
|
|
|
|
break; |
11055
|
|
|
|
|
|
/* Note that you'd normally expect targs to be |
11056
|
|
|
|
|
|
* contiguous in my($a,$b,$c), but that's not the case |
11057
|
|
|
|
|
|
* when external modules start doing things, e.g. |
11058
|
|
|
|
|
|
i* Function::Parameters */ |
11059
|
7913149
|
100
|
|
|
|
if (p->op_targ != base + count) |
11060
|
|
|
|
|
|
break; |
11061
|
|
|
|
|
|
assert(p->op_targ == base + count); |
11062
|
|
|
|
|
|
/* all the padops should be in the same context */ |
11063
|
5292352
|
100
|
|
|
|
if (gimme != (p->op_flags & OPf_WANT)) |
11064
|
|
|
|
|
|
break; |
11065
|
|
|
|
|
|
} |
11066
|
|
|
|
|
|
|
11067
|
|
|
|
|
|
/* for AV, HV, only when we're not flattening */ |
11068
|
37271628
|
100
|
|
|
|
if ( p->op_type != OP_PADSV |
11069
|
25073456
|
|
|
|
|
&& gimme != OPf_WANT_VOID |
11070
|
3387635
|
100
|
|
|
|
&& !(p->op_flags & OPf_REF) |
11071
|
|
|
|
|
|
) |
11072
|
|
|
|
|
|
break; |
11073
|
|
|
|
|
|
|
11074
|
24587673
|
50
|
|
|
|
if (count >= OPpPADRANGE_COUNTMASK) |
11075
|
|
|
|
|
|
break; |
11076
|
|
|
|
|
|
|
11077
|
|
|
|
|
|
/* there's a biggest base we can fit into a |
11078
|
|
|
|
|
|
* SAVEt_CLEARPADRANGE in pp_padrange */ |
11079
|
24587673
|
50
|
|
|
|
if (intro && base > |
11080
|
|
|
|
|
|
(UV_MAX >> (OPpPADRANGE_COUNTSHIFT+SAVE_TIGHT_SHIFT))) |
11081
|
|
|
|
|
|
break; |
11082
|
|
|
|
|
|
|
11083
|
|
|
|
|
|
/* Success! We've got another valid pad op to optimise away */ |
11084
|
24587673
|
|
|
|
|
count++; |
11085
|
24587673
|
|
|
|
|
followop = p->op_next; |
11086
|
|
|
|
|
|
} |
11087
|
|
|
|
|
|
|
11088
|
34780883
|
100
|
|
|
|
if (count < 1) |
11089
|
|
|
|
|
|
break; |
11090
|
|
|
|
|
|
|
11091
|
|
|
|
|
|
/* pp_padrange in specifically compile-time void context |
11092
|
|
|
|
|
|
* skips pushing a mark and lexicals; in all other contexts |
11093
|
|
|
|
|
|
* (including unknown till runtime) it pushes a mark and the |
11094
|
|
|
|
|
|
* lexicals. We must be very careful then, that the ops we |
11095
|
|
|
|
|
|
* optimise away would have exactly the same effect as the |
11096
|
|
|
|
|
|
* padrange. |
11097
|
|
|
|
|
|
* In particular in void context, we can only optimise to |
11098
|
|
|
|
|
|
* a padrange if see see the complete sequence |
11099
|
|
|
|
|
|
* pushmark, pad*v, ...., list, nextstate |
11100
|
|
|
|
|
|
* which has the net effect of of leaving the stack empty |
11101
|
|
|
|
|
|
* (for now we leave the nextstate in the execution chain, for |
11102
|
|
|
|
|
|
* its other side-effects). |
11103
|
|
|
|
|
|
*/ |
11104
|
|
|
|
|
|
assert(followop); |
11105
|
19911517
|
100
|
|
|
|
if (gimme == OPf_WANT_VOID) { |
11106
|
362454
|
100
|
|
|
|
if (followop->op_type == OP_LIST |
11107
|
362404
|
50
|
|
|
|
&& gimme == (followop->op_flags & OPf_WANT) |
11108
|
538386
|
100
|
|
|
|
&& ( followop->op_next->op_type == OP_NEXTSTATE |
11109
|
362404
|
|
|
|
|
|| followop->op_next->op_type == OP_DBSTATE)) |
11110
|
|
|
|
|
|
{ |
11111
|
361550
|
|
|
|
|
followop = followop->op_next; /* skip OP_LIST */ |
11112
|
|
|
|
|
|
|
11113
|
|
|
|
|
|
/* consolidate two successive my(...);'s */ |
11114
|
|
|
|
|
|
|
11115
|
361550
|
100
|
|
|
|
if ( oldoldop |
11116
|
340874
|
100
|
|
|
|
&& oldoldop->op_type == OP_PADRANGE |
11117
|
8640
|
50
|
|
|
|
&& (oldoldop->op_flags & OPf_WANT) == OPf_WANT_VOID |
11118
|
8640
|
50
|
|
|
|
&& (oldoldop->op_private & OPpLVAL_INTRO) == intro |
11119
|
8640
|
50
|
|
|
|
&& !(oldoldop->op_flags & OPf_SPECIAL) |
11120
|
|
|
|
|
|
) { |
11121
|
|
|
|
|
|
U8 old_count; |
11122
|
|
|
|
|
|
assert(oldoldop->op_next == oldop); |
11123
|
|
|
|
|
|
assert( oldop->op_type == OP_NEXTSTATE |
11124
|
|
|
|
|
|
|| oldop->op_type == OP_DBSTATE); |
11125
|
|
|
|
|
|
assert(oldop->op_next == o); |
11126
|
|
|
|
|
|
|
11127
|
|
|
|
|
|
old_count |
11128
|
8640
|
|
|
|
|
= (oldoldop->op_private & OPpPADRANGE_COUNTMASK); |
11129
|
|
|
|
|
|
assert(oldoldop->op_targ + old_count == base); |
11130
|
|
|
|
|
|
|
11131
|
8640
|
50
|
|
|
|
if (old_count < OPpPADRANGE_COUNTMASK - count) { |
11132
|
8640
|
|
|
|
|
base = oldoldop->op_targ; |
11133
|
190135
|
|
|
|
|
count += old_count; |
11134
|
|
|
|
|
|
reuse = 1; |
11135
|
|
|
|
|
|
} |
11136
|
|
|
|
|
|
} |
11137
|
|
|
|
|
|
|
11138
|
|
|
|
|
|
/* if there's any immediately following singleton |
11139
|
|
|
|
|
|
* my var's; then swallow them and the associated |
11140
|
|
|
|
|
|
* nextstates; i.e. |
11141
|
|
|
|
|
|
* my ($a,$b); my $c; my $d; |
11142
|
|
|
|
|
|
* is treated as |
11143
|
|
|
|
|
|
* my ($a,$b,$c,$d); |
11144
|
|
|
|
|
|
*/ |
11145
|
|
|
|
|
|
|
11146
|
385614
|
50
|
|
|
|
while ( ((p = followop->op_next)) |
11147
|
572841
|
100
|
|
|
|
&& ( p->op_type == OP_PADSV |
11148
|
|
|
|
|
|
|| p->op_type == OP_PADAV |
11149
|
385614
|
|
|
|
|
|| p->op_type == OP_PADHV) |
11150
|
88674
|
100
|
|
|
|
&& (p->op_flags & OPf_WANT) == OPf_WANT_VOID |
11151
|
24064
|
50
|
|
|
|
&& (p->op_private & OPpLVAL_INTRO) == intro |
11152
|
24064
|
50
|
|
|
|
&& p->op_next |
11153
|
24064
|
|
|
|
|
&& ( p->op_next->op_type == OP_NEXTSTATE |
11154
|
24064
|
|
|
|
|
|| p->op_next->op_type == OP_DBSTATE) |
11155
|
24064
|
50
|
|
|
|
&& count < OPpPADRANGE_COUNTMASK |
11156
|
|
|
|
|
|
) { |
11157
|
|
|
|
|
|
assert(base + count == p->op_targ); |
11158
|
24064
|
|
|
|
|
count++; |
11159
|
24064
|
|
|
|
|
followop = p->op_next; |
11160
|
|
|
|
|
|
} |
11161
|
|
|
|
|
|
} |
11162
|
|
|
|
|
|
else |
11163
|
|
|
|
|
|
break; |
11164
|
|
|
|
|
|
} |
11165
|
|
|
|
|
|
|
11166
|
19910613
|
100
|
|
|
|
if (reuse) { |
11167
|
|
|
|
|
|
assert(oldoldop->op_type == OP_PADRANGE); |
11168
|
8640
|
|
|
|
|
oldoldop->op_next = followop; |
11169
|
8640
|
|
|
|
|
oldoldop->op_private = (intro | count); |
11170
|
|
|
|
|
|
o = oldoldop; |
11171
|
|
|
|
|
|
oldop = NULL; |
11172
|
|
|
|
|
|
oldoldop = NULL; |
11173
|
|
|
|
|
|
} |
11174
|
|
|
|
|
|
else { |
11175
|
|
|
|
|
|
/* Convert the pushmark into a padrange. |
11176
|
|
|
|
|
|
* To make Deparse easier, we guarantee that a padrange was |
11177
|
|
|
|
|
|
* *always* formerly a pushmark */ |
11178
|
|
|
|
|
|
assert(o->op_type == OP_PUSHMARK); |
11179
|
19901973
|
|
|
|
|
o->op_next = followop; |
11180
|
19901973
|
|
|
|
|
o->op_type = OP_PADRANGE; |
11181
|
19901973
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_PADRANGE]; |
11182
|
19901973
|
|
|
|
|
o->op_targ = base; |
11183
|
|
|
|
|
|
/* bit 7: INTRO; bit 6..0: count */ |
11184
|
19901973
|
|
|
|
|
o->op_private = (intro | count); |
11185
|
19901973
|
100
|
|
|
|
o->op_flags = ((o->op_flags & ~(OPf_WANT|OPf_SPECIAL)) |
11186
|
|
|
|
|
|
| gimme | (defav ? OPf_SPECIAL : 0)); |
11187
|
|
|
|
|
|
} |
11188
|
|
|
|
|
|
break; |
11189
|
|
|
|
|
|
} |
11190
|
|
|
|
|
|
|
11191
|
|
|
|
|
|
case OP_PADAV: |
11192
|
|
|
|
|
|
case OP_GV: |
11193
|
37252535
|
100
|
|
|
|
if (o->op_type == OP_PADAV || o->op_next->op_type == OP_RV2AV) { |
|
|
100
|
|
|
|
|
11194
|
10766036
|
|
|
|
|
OP* const pop = (o->op_type == OP_PADAV) ? |
11195
|
10766036
|
100
|
|
|
|
o->op_next : o->op_next->op_next; |
11196
|
|
|
|
|
|
IV i; |
11197
|
13035108
|
50
|
|
|
|
if (pop && pop->op_type == OP_CONST && |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
11198
|
7022844
|
100
|
|
|
|
((PL_op = pop->op_next)) && |
11199
|
5481709
|
100
|
|
|
|
pop->op_next->op_type == OP_AELEM && |
11200
|
3212637
|
|
|
|
|
!(pop->op_next->op_private & |
11201
|
2101242
|
100
|
|
|
|
(OPpLVAL_INTRO|OPpLVAL_DEFER|OPpDEREF|OPpMAYBE_LVSUB)) && |
11202
|
4202450
|
100
|
|
|
|
(i = SvIV(((SVOP*)pop)->op_sv)) <= 255 && i >= 0) |
|
|
100
|
|
|
|
|
11203
|
|
|
|
|
|
{ |
11204
|
|
|
|
|
|
GV *gv; |
11205
|
2029386
|
100
|
|
|
|
if (cSVOPx(pop)->op_private & OPpCONST_STRICT) |
11206
|
4
|
|
|
|
|
no_bareword_allowed(pop); |
11207
|
2029386
|
100
|
|
|
|
if (o->op_type == OP_GV) |
11208
|
1542630
|
|
|
|
|
op_null(o->op_next); |
11209
|
2029386
|
|
|
|
|
op_null(pop->op_next); |
11210
|
2029386
|
|
|
|
|
op_null(pop); |
11211
|
2029386
|
|
|
|
|
o->op_flags |= pop->op_next->op_flags & OPf_MOD; |
11212
|
2029386
|
|
|
|
|
o->op_next = pop->op_next->op_next; |
11213
|
2029386
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_AELEMFAST]; |
11214
|
2029386
|
|
|
|
|
o->op_private = (U8)i; |
11215
|
2029386
|
100
|
|
|
|
if (o->op_type == OP_GV) { |
11216
|
1542630
|
|
|
|
|
gv = cGVOPo_gv; |
11217
|
1542630
|
50
|
|
|
|
GvAVn(gv); |
11218
|
1542630
|
|
|
|
|
o->op_type = OP_AELEMFAST; |
11219
|
|
|
|
|
|
} |
11220
|
|
|
|
|
|
else |
11221
|
486756
|
|
|
|
|
o->op_type = OP_AELEMFAST_LEX; |
11222
|
|
|
|
|
|
} |
11223
|
|
|
|
|
|
break; |
11224
|
|
|
|
|
|
} |
11225
|
|
|
|
|
|
|
11226
|
26486499
|
100
|
|
|
|
if (o->op_next->op_type == OP_RV2SV) { |
11227
|
11194684
|
100
|
|
|
|
if (!(o->op_next->op_private & OPpDEREF)) { |
11228
|
11056224
|
|
|
|
|
op_null(o->op_next); |
11229
|
11056224
|
|
|
|
|
o->op_private |= o->op_next->op_private & (OPpLVAL_INTRO |
11230
|
|
|
|
|
|
| OPpOUR_INTRO); |
11231
|
11056224
|
|
|
|
|
o->op_next = o->op_next->op_next; |
11232
|
11056224
|
|
|
|
|
o->op_type = OP_GVSV; |
11233
|
11056224
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_GVSV]; |
11234
|
|
|
|
|
|
} |
11235
|
|
|
|
|
|
} |
11236
|
15291815
|
100
|
|
|
|
else if (o->op_next->op_type == OP_READLINE |
11237
|
20964
|
100
|
|
|
|
&& o->op_next->op_next->op_type == OP_CONCAT |
11238
|
50
|
50
|
|
|
|
&& (o->op_next->op_next->op_flags & OPf_STACKED)) |
11239
|
|
|
|
|
|
{ |
11240
|
|
|
|
|
|
/* Turn "$a .= " into an OP_RCATLINE. AMS 20010917 */ |
11241
|
50
|
|
|
|
|
o->op_type = OP_RCATLINE; |
11242
|
50
|
|
|
|
|
o->op_flags |= OPf_STACKED; |
11243
|
50
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_RCATLINE]; |
11244
|
50
|
|
|
|
|
op_null(o->op_next->op_next); |
11245
|
50
|
|
|
|
|
op_null(o->op_next); |
11246
|
|
|
|
|
|
} |
11247
|
|
|
|
|
|
|
11248
|
|
|
|
|
|
break; |
11249
|
|
|
|
|
|
|
11250
|
|
|
|
|
|
{ |
11251
|
|
|
|
|
|
OP *fop; |
11252
|
|
|
|
|
|
OP *sop; |
11253
|
|
|
|
|
|
|
11254
|
|
|
|
|
|
#define HV_OR_SCALARHV(op) \ |
11255
|
|
|
|
|
|
( (op)->op_type == OP_PADHV || (op)->op_type == OP_RV2HV \ |
11256
|
|
|
|
|
|
? (op) \ |
11257
|
|
|
|
|
|
: (op)->op_type == OP_SCALAR && (op)->op_flags & OPf_KIDS \ |
11258
|
|
|
|
|
|
&& ( cUNOPx(op)->op_first->op_type == OP_PADHV \ |
11259
|
|
|
|
|
|
|| cUNOPx(op)->op_first->op_type == OP_RV2HV) \ |
11260
|
|
|
|
|
|
? cUNOPx(op)->op_first \ |
11261
|
|
|
|
|
|
: NULL) |
11262
|
|
|
|
|
|
|
11263
|
|
|
|
|
|
case OP_NOT: |
11264
|
1536471
|
100
|
|
|
|
if ((fop = HV_OR_SCALARHV(cUNOP->op_first))) |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
11265
|
12542
|
|
|
|
|
fop->op_private |= OPpTRUEBOOL; |
11266
|
|
|
|
|
|
break; |
11267
|
|
|
|
|
|
|
11268
|
|
|
|
|
|
case OP_AND: |
11269
|
|
|
|
|
|
case OP_OR: |
11270
|
|
|
|
|
|
case OP_DOR: |
11271
|
18440318
|
|
|
|
|
fop = cLOGOP->op_first; |
11272
|
18440318
|
|
|
|
|
sop = fop->op_sibling; |
11273
|
28870514
|
100
|
|
|
|
while (cLOGOP->op_other->op_type == OP_NULL) |
11274
|
1573783
|
|
|
|
|
cLOGOP->op_other = cLOGOP->op_other->op_next; |
11275
|
44475664
|
100
|
|
|
|
while (o->op_next && ( o->op_type == o->op_next->op_type |
|
|
100
|
|
|
|
|
11276
|
41209518
|
100
|
|
|
|
|| o->op_next->op_type == OP_NULL)) |
11277
|
26035346
|
|
|
|
|
o->op_next = o->op_next->op_next; |
11278
|
18440318
|
100
|
|
|
|
DEFER(cLOGOP->op_other); |
11279
|
|
|
|
|
|
|
11280
|
18440318
|
|
|
|
|
o->op_opt = 1; |
11281
|
18440318
|
100
|
|
|
|
fop = HV_OR_SCALARHV(fop); |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
11282
|
18440318
|
50
|
|
|
|
if (sop) sop = HV_OR_SCALARHV(sop); |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
11283
|
18440318
|
100
|
|
|
|
if (fop || sop |
11284
|
|
|
|
|
|
){ |
11285
|
|
|
|
|
|
OP * nop = o; |
11286
|
|
|
|
|
|
OP * lop = o; |
11287
|
8194
|
100
|
|
|
|
if (!((nop->op_flags & OPf_WANT) == OPf_WANT_VOID)) { |
11288
|
7466
|
100
|
|
|
|
while (nop && nop->op_next) { |
|
|
50
|
|
|
|
|
11289
|
4420
|
|
|
|
|
switch (nop->op_next->op_type) { |
11290
|
|
|
|
|
|
case OP_NOT: |
11291
|
|
|
|
|
|
case OP_AND: |
11292
|
|
|
|
|
|
case OP_OR: |
11293
|
|
|
|
|
|
case OP_DOR: |
11294
|
688
|
|
|
|
|
lop = nop = nop->op_next; |
11295
|
688
|
|
|
|
|
break; |
11296
|
|
|
|
|
|
case OP_NULL: |
11297
|
686
|
|
|
|
|
nop = nop->op_next; |
11298
|
2553
|
|
|
|
|
break; |
11299
|
|
|
|
|
|
default: |
11300
|
|
|
|
|
|
nop = NULL; |
11301
|
|
|
|
|
|
break; |
11302
|
|
|
|
|
|
} |
11303
|
|
|
|
|
|
} |
11304
|
|
|
|
|
|
} |
11305
|
8194
|
100
|
|
|
|
if (fop) { |
11306
|
6798
|
100
|
|
|
|
if ( (lop->op_flags & OPf_WANT) == OPf_WANT_VOID |
11307
|
1560
|
100
|
|
|
|
|| o->op_type == OP_AND ) |
11308
|
6596
|
|
|
|
|
fop->op_private |= OPpTRUEBOOL; |
11309
|
202
|
50
|
|
|
|
else if (!(lop->op_flags & OPf_WANT)) |
11310
|
0
|
|
|
|
|
fop->op_private |= OPpMAYBE_TRUEBOOL; |
11311
|
|
|
|
|
|
} |
11312
|
12111
|
100
|
|
|
|
if ( (lop->op_flags & OPf_WANT) == OPf_WANT_VOID |
11313
|
8194
|
|
|
|
|
&& sop) |
11314
|
526
|
|
|
|
|
sop->op_private |= OPpTRUEBOOL; |
11315
|
|
|
|
|
|
} |
11316
|
|
|
|
|
|
|
11317
|
|
|
|
|
|
|
11318
|
|
|
|
|
|
break; |
11319
|
|
|
|
|
|
|
11320
|
|
|
|
|
|
case OP_COND_EXPR: |
11321
|
6764345
|
100
|
|
|
|
if ((fop = HV_OR_SCALARHV(cLOGOP->op_first))) |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
11322
|
4163850
|
|
|
|
|
fop->op_private |= OPpTRUEBOOL; |
11323
|
|
|
|
|
|
#undef HV_OR_SCALARHV |
11324
|
|
|
|
|
|
/* GERONIMO! */ |
11325
|
|
|
|
|
|
} |
11326
|
|
|
|
|
|
|
11327
|
|
|
|
|
|
case OP_MAPWHILE: |
11328
|
|
|
|
|
|
case OP_GREPWHILE: |
11329
|
|
|
|
|
|
case OP_ANDASSIGN: |
11330
|
|
|
|
|
|
case OP_ORASSIGN: |
11331
|
|
|
|
|
|
case OP_DORASSIGN: |
11332
|
|
|
|
|
|
case OP_RANGE: |
11333
|
|
|
|
|
|
case OP_ONCE: |
11334
|
10122097
|
100
|
|
|
|
while (cLOGOP->op_other->op_type == OP_NULL) |
11335
|
2144234
|
|
|
|
|
cLOGOP->op_other = cLOGOP->op_other->op_next; |
11336
|
7977863
|
100
|
|
|
|
DEFER(cLOGOP->op_other); |
11337
|
7977863
|
|
|
|
|
break; |
11338
|
|
|
|
|
|
|
11339
|
|
|
|
|
|
case OP_ENTERLOOP: |
11340
|
|
|
|
|
|
case OP_ENTERITER: |
11341
|
2460623
|
100
|
|
|
|
while (cLOOP->op_redoop->op_type == OP_NULL) |
11342
|
93174
|
|
|
|
|
cLOOP->op_redoop = cLOOP->op_redoop->op_next; |
11343
|
2368041
|
100
|
|
|
|
while (cLOOP->op_nextop->op_type == OP_NULL) |
11344
|
592
|
|
|
|
|
cLOOP->op_nextop = cLOOP->op_nextop->op_next; |
11345
|
2367449
|
50
|
|
|
|
while (cLOOP->op_lastop->op_type == OP_NULL) |
11346
|
0
|
|
|
|
|
cLOOP->op_lastop = cLOOP->op_lastop->op_next; |
11347
|
|
|
|
|
|
/* a while(1) loop doesn't have an op_next that escapes the |
11348
|
|
|
|
|
|
* loop, so we have to explicitly follow the op_lastop to |
11349
|
|
|
|
|
|
* process the rest of the code */ |
11350
|
2367449
|
100
|
|
|
|
DEFER(cLOOP->op_lastop); |
11351
|
2367449
|
|
|
|
|
break; |
11352
|
|
|
|
|
|
|
11353
|
|
|
|
|
|
case OP_SUBST: |
11354
|
|
|
|
|
|
assert(!(cPMOP->op_pmflags & PMf_ONCE)); |
11355
|
1538398
|
100
|
|
|
|
while (cPMOP->op_pmstashstartu.op_pmreplstart && |
|
|
100
|
|
|
|
|
11356
|
417491
|
|
|
|
|
cPMOP->op_pmstashstartu.op_pmreplstart->op_type == OP_NULL) |
11357
|
|
|
|
|
|
cPMOP->op_pmstashstartu.op_pmreplstart |
11358
|
119466
|
|
|
|
|
= cPMOP->op_pmstashstartu.op_pmreplstart->op_next; |
11359
|
1215765
|
100
|
|
|
|
DEFER(cPMOP->op_pmstashstartu.op_pmreplstart); |
11360
|
1215765
|
|
|
|
|
break; |
11361
|
|
|
|
|
|
|
11362
|
|
|
|
|
|
case OP_SORT: { |
11363
|
|
|
|
|
|
OP *oright; |
11364
|
|
|
|
|
|
|
11365
|
201788
|
100
|
|
|
|
if (o->op_flags & OPf_STACKED) { |
11366
|
33038
|
|
|
|
|
OP * const kid = |
11367
|
33038
|
|
|
|
|
cUNOPx(cLISTOP->op_first->op_sibling)->op_first; |
11368
|
33038
|
100
|
|
|
|
if (kid->op_type == OP_SCOPE |
11369
|
15558
|
100
|
|
|
|
|| (kid->op_type == OP_NULL && kid->op_targ == OP_LEAVE)) |
|
|
100
|
|
|
|
|
11370
|
27326
|
100
|
|
|
|
DEFER(kLISTOP->op_first); |
11371
|
|
|
|
|
|
} |
11372
|
|
|
|
|
|
|
11373
|
|
|
|
|
|
/* check that RHS of sort is a single plain array */ |
11374
|
201788
|
|
|
|
|
oright = cUNOPo->op_first; |
11375
|
201788
|
50
|
|
|
|
if (!oright || oright->op_type != OP_PUSHMARK) |
|
|
100
|
|
|
|
|
11376
|
|
|
|
|
|
break; |
11377
|
|
|
|
|
|
|
11378
|
199472
|
100
|
|
|
|
if (o->op_private & OPpSORT_INPLACE) |
11379
|
|
|
|
|
|
break; |
11380
|
|
|
|
|
|
|
11381
|
|
|
|
|
|
/* reverse sort ... can be optimised. */ |
11382
|
199430
|
100
|
|
|
|
if (!cUNOPo->op_sibling) { |
11383
|
|
|
|
|
|
/* Nothing follows us on the list. */ |
11384
|
192240
|
|
|
|
|
OP * const reverse = o->op_next; |
11385
|
|
|
|
|
|
|
11386
|
192403
|
100
|
|
|
|
if (reverse->op_type == OP_REVERSE && |
|
|
100
|
|
|
|
|
11387
|
326
|
|
|
|
|
(reverse->op_flags & OPf_WANT) == OPf_WANT_LIST) { |
11388
|
296
|
|
|
|
|
OP * const pushmark = cUNOPx(reverse)->op_first; |
11389
|
296
|
50
|
|
|
|
if (pushmark && (pushmark->op_type == OP_PUSHMARK) |
|
|
50
|
|
|
|
|
11390
|
296
|
100
|
|
|
|
&& (cUNOPx(pushmark)->op_sibling == o)) { |
11391
|
|
|
|
|
|
/* reverse -> pushmark -> sort */ |
11392
|
294
|
|
|
|
|
o->op_private |= OPpSORT_REVERSE; |
11393
|
294
|
|
|
|
|
op_null(reverse); |
11394
|
294
|
|
|
|
|
pushmark->op_next = oright->op_next; |
11395
|
294
|
|
|
|
|
op_null(oright); |
11396
|
|
|
|
|
|
} |
11397
|
|
|
|
|
|
} |
11398
|
|
|
|
|
|
} |
11399
|
|
|
|
|
|
|
11400
|
|
|
|
|
|
break; |
11401
|
|
|
|
|
|
} |
11402
|
|
|
|
|
|
|
11403
|
|
|
|
|
|
case OP_REVERSE: { |
11404
|
|
|
|
|
|
OP *ourmark, *theirmark, *ourlast, *iter, *expushmark, *rv2av; |
11405
|
|
|
|
|
|
OP *gvop = NULL; |
11406
|
|
|
|
|
|
LISTOP *enter, *exlist; |
11407
|
|
|
|
|
|
|
11408
|
18034
|
100
|
|
|
|
if (o->op_private & OPpSORT_INPLACE) |
11409
|
|
|
|
|
|
break; |
11410
|
|
|
|
|
|
|
11411
|
17976
|
|
|
|
|
enter = (LISTOP *) o->op_next; |
11412
|
17976
|
50
|
|
|
|
if (!enter) |
11413
|
|
|
|
|
|
break; |
11414
|
17976
|
100
|
|
|
|
if (enter->op_type == OP_NULL) { |
11415
|
9382
|
|
|
|
|
enter = (LISTOP *) enter->op_next; |
11416
|
9382
|
50
|
|
|
|
if (!enter) |
11417
|
|
|
|
|
|
break; |
11418
|
|
|
|
|
|
} |
11419
|
|
|
|
|
|
/* for $a (...) will have OP_GV then OP_RV2GV here. |
11420
|
|
|
|
|
|
for (...) just has an OP_GV. */ |
11421
|
17976
|
100
|
|
|
|
if (enter->op_type == OP_GV) { |
11422
|
|
|
|
|
|
gvop = (OP *) enter; |
11423
|
1012
|
|
|
|
|
enter = (LISTOP *) enter->op_next; |
11424
|
1012
|
50
|
|
|
|
if (!enter) |
11425
|
|
|
|
|
|
break; |
11426
|
1012
|
100
|
|
|
|
if (enter->op_type == OP_RV2GV) { |
11427
|
52
|
|
|
|
|
enter = (LISTOP *) enter->op_next; |
11428
|
52
|
50
|
|
|
|
if (!enter) |
11429
|
|
|
|
|
|
break; |
11430
|
|
|
|
|
|
} |
11431
|
|
|
|
|
|
} |
11432
|
|
|
|
|
|
|
11433
|
17976
|
100
|
|
|
|
if (enter->op_type != OP_ENTERITER) |
11434
|
|
|
|
|
|
break; |
11435
|
|
|
|
|
|
|
11436
|
3120
|
|
|
|
|
iter = enter->op_next; |
11437
|
3120
|
50
|
|
|
|
if (!iter || iter->op_type != OP_ITER) |
|
|
50
|
|
|
|
|
11438
|
|
|
|
|
|
break; |
11439
|
|
|
|
|
|
|
11440
|
3120
|
|
|
|
|
expushmark = enter->op_first; |
11441
|
3120
|
50
|
|
|
|
if (!expushmark || expushmark->op_type != OP_NULL |
|
|
50
|
|
|
|
|
11442
|
3120
|
50
|
|
|
|
|| expushmark->op_targ != OP_PUSHMARK) |
11443
|
|
|
|
|
|
break; |
11444
|
|
|
|
|
|
|
11445
|
3120
|
|
|
|
|
exlist = (LISTOP *) expushmark->op_sibling; |
11446
|
3120
|
50
|
|
|
|
if (!exlist || exlist->op_type != OP_NULL |
|
|
50
|
|
|
|
|
11447
|
3120
|
50
|
|
|
|
|| exlist->op_targ != OP_LIST) |
11448
|
|
|
|
|
|
break; |
11449
|
|
|
|
|
|
|
11450
|
3120
|
50
|
|
|
|
if (exlist->op_last != o) { |
11451
|
|
|
|
|
|
/* Mmm. Was expecting to point back to this op. */ |
11452
|
|
|
|
|
|
break; |
11453
|
|
|
|
|
|
} |
11454
|
3120
|
|
|
|
|
theirmark = exlist->op_first; |
11455
|
3120
|
50
|
|
|
|
if (!theirmark || theirmark->op_type != OP_PUSHMARK) |
|
|
50
|
|
|
|
|
11456
|
|
|
|
|
|
break; |
11457
|
|
|
|
|
|
|
11458
|
3120
|
100
|
|
|
|
if (theirmark->op_sibling != o) { |
11459
|
|
|
|
|
|
/* There's something between the mark and the reverse, eg |
11460
|
|
|
|
|
|
for (1, reverse (...)) |
11461
|
|
|
|
|
|
so no go. */ |
11462
|
|
|
|
|
|
break; |
11463
|
|
|
|
|
|
} |
11464
|
|
|
|
|
|
|
11465
|
3084
|
|
|
|
|
ourmark = ((LISTOP *)o)->op_first; |
11466
|
3084
|
50
|
|
|
|
if (!ourmark || ourmark->op_type != OP_PUSHMARK) |
|
|
50
|
|
|
|
|
11467
|
|
|
|
|
|
break; |
11468
|
|
|
|
|
|
|
11469
|
3084
|
|
|
|
|
ourlast = ((LISTOP *)o)->op_last; |
11470
|
3084
|
50
|
|
|
|
if (!ourlast || ourlast->op_next != o) |
|
|
50
|
|
|
|
|
11471
|
|
|
|
|
|
break; |
11472
|
|
|
|
|
|
|
11473
|
3084
|
|
|
|
|
rv2av = ourmark->op_sibling; |
11474
|
3084
|
50
|
|
|
|
if (rv2av && rv2av->op_type == OP_RV2AV && rv2av->op_sibling == 0 |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
11475
|
2222
|
100
|
|
|
|
&& rv2av->op_flags == (OPf_WANT_LIST | OPf_KIDS) |
11476
|
2206
|
50
|
|
|
|
&& enter->op_flags == (OPf_WANT_LIST | OPf_KIDS)) { |
11477
|
|
|
|
|
|
/* We're just reversing a single array. */ |
11478
|
2206
|
|
|
|
|
rv2av->op_flags = OPf_WANT_SCALAR | OPf_KIDS | OPf_REF; |
11479
|
2206
|
|
|
|
|
enter->op_flags |= OPf_STACKED; |
11480
|
|
|
|
|
|
} |
11481
|
|
|
|
|
|
|
11482
|
|
|
|
|
|
/* We don't have control over who points to theirmark, so sacrifice |
11483
|
|
|
|
|
|
ours. */ |
11484
|
3084
|
|
|
|
|
theirmark->op_next = ourmark->op_next; |
11485
|
3084
|
|
|
|
|
theirmark->op_flags = ourmark->op_flags; |
11486
|
3084
|
100
|
|
|
|
ourlast->op_next = gvop ? gvop : (OP *) enter; |
11487
|
3084
|
|
|
|
|
op_null(ourmark); |
11488
|
3084
|
|
|
|
|
op_null(o); |
11489
|
3084
|
|
|
|
|
enter->op_private |= OPpITER_REVERSED; |
11490
|
3084
|
|
|
|
|
iter->op_private |= OPpITER_REVERSED; |
11491
|
|
|
|
|
|
|
11492
|
3084
|
|
|
|
|
break; |
11493
|
|
|
|
|
|
} |
11494
|
|
|
|
|
|
|
11495
|
|
|
|
|
|
case OP_QR: |
11496
|
|
|
|
|
|
case OP_MATCH: |
11497
|
|
|
|
|
|
if (!(cPMOP->op_pmflags & PMf_ONCE)) { |
11498
|
|
|
|
|
|
assert (!cPMOP->op_pmstashstartu.op_pmreplstart); |
11499
|
|
|
|
|
|
} |
11500
|
|
|
|
|
|
break; |
11501
|
|
|
|
|
|
|
11502
|
|
|
|
|
|
case OP_RUNCV: |
11503
|
44
|
100
|
|
|
|
if (!(o->op_private & OPpOFFBYONE) && !CvCLONE(PL_compcv)) { |
|
|
100
|
|
|
|
|
11504
|
|
|
|
|
|
SV *sv; |
11505
|
32
|
100
|
|
|
|
if (CvEVAL(PL_compcv)) sv = &PL_sv_undef; |
|
|
100
|
|
|
|
|
11506
|
|
|
|
|
|
else { |
11507
|
24
|
|
|
|
|
sv = newRV((SV *)PL_compcv); |
11508
|
24
|
|
|
|
|
sv_rvweaken(sv); |
11509
|
24
|
|
|
|
|
SvREADONLY_on(sv); |
11510
|
|
|
|
|
|
} |
11511
|
32
|
|
|
|
|
o->op_type = OP_CONST; |
11512
|
32
|
|
|
|
|
o->op_ppaddr = PL_ppaddr[OP_CONST]; |
11513
|
32
|
|
|
|
|
o->op_flags |= OPf_SPECIAL; |
11514
|
32
|
|
|
|
|
cSVOPo->op_sv = sv; |
11515
|
|
|
|
|
|
} |
11516
|
|
|
|
|
|
break; |
11517
|
|
|
|
|
|
|
11518
|
|
|
|
|
|
case OP_SASSIGN: |
11519
|
19362936
|
100
|
|
|
|
if (OP_GIMME(o,0) == G_VOID) { |
11520
|
17733397
|
|
|
|
|
OP *right = cBINOP->op_first; |
11521
|
17733397
|
50
|
|
|
|
if (right) { |
11522
|
17733397
|
|
|
|
|
OP *left = right->op_sibling; |
11523
|
17733397
|
100
|
|
|
|
if (left->op_type == OP_SUBSTR |
11524
|
49082
|
50
|
|
|
|
&& (left->op_private & 7) < 4) { |
11525
|
49082
|
|
|
|
|
op_null(o); |
11526
|
49082
|
|
|
|
|
cBINOP->op_first = left; |
11527
|
49082
|
|
|
|
|
right->op_sibling = |
11528
|
49082
|
|
|
|
|
cBINOPx(left)->op_first->op_sibling; |
11529
|
49082
|
|
|
|
|
cBINOPx(left)->op_first->op_sibling = right; |
11530
|
49082
|
|
|
|
|
left->op_private |= OPpSUBSTR_REPL_FIRST; |
11531
|
49082
|
|
|
|
|
left->op_flags = |
11532
|
49082
|
|
|
|
|
(o->op_flags & ~OPf_WANT) | OPf_WANT_VOID; |
11533
|
|
|
|
|
|
} |
11534
|
|
|
|
|
|
} |
11535
|
|
|
|
|
|
} |
11536
|
|
|
|
|
|
break; |
11537
|
|
|
|
|
|
|
11538
|
|
|
|
|
|
case OP_CUSTOM: { |
11539
|
|
|
|
|
|
Perl_cpeep_t cpeep = |
11540
|
16
|
100
|
|
|
|
XopENTRY(Perl_custom_op_xop(aTHX_ o), xop_peep); |
11541
|
16
|
100
|
|
|
|
if (cpeep) |
11542
|
298411204
|
|
|
|
|
cpeep(aTHX_ o, oldop); |
11543
|
|
|
|
|
|
break; |
11544
|
|
|
|
|
|
} |
11545
|
|
|
|
|
|
|
11546
|
|
|
|
|
|
} |
11547
|
|
|
|
|
|
oldoldop = oldop; |
11548
|
|
|
|
|
|
oldop = o; |
11549
|
699142156
|
|
|
|
|
} |
11550
|
43494996
|
|
|
|
|
LEAVE; |
11551
|
|
|
|
|
|
} |
11552
|
|
|
|
|
|
|
11553
|
|
|
|
|
|
void |
11554
|
16706742
|
|
|
|
|
Perl_peep(pTHX_ OP *o) |
11555
|
|
|
|
|
|
{ |
11556
|
16706742
|
|
|
|
|
CALL_RPEEP(o); |
11557
|
16706742
|
|
|
|
|
} |
11558
|
|
|
|
|
|
|
11559
|
|
|
|
|
|
/* |
11560
|
|
|
|
|
|
=head1 Custom Operators |
11561
|
|
|
|
|
|
|
11562
|
|
|
|
|
|
=for apidoc Ao||custom_op_xop |
11563
|
|
|
|
|
|
Return the XOP structure for a given custom op. This function should be |
11564
|
|
|
|
|
|
considered internal to OP_NAME and the other access macros: use them instead. |
11565
|
|
|
|
|
|
|
11566
|
|
|
|
|
|
=cut |
11567
|
|
|
|
|
|
*/ |
11568
|
|
|
|
|
|
|
11569
|
|
|
|
|
|
const XOP * |
11570
|
104
|
|
|
|
|
Perl_custom_op_xop(pTHX_ const OP *o) |
11571
|
|
|
|
|
|
{ |
11572
|
|
|
|
|
|
SV *keysv; |
11573
|
|
|
|
|
|
HE *he = NULL; |
11574
|
|
|
|
|
|
XOP *xop; |
11575
|
|
|
|
|
|
|
11576
|
|
|
|
|
|
static const XOP xop_null = { 0, 0, 0, 0, 0 }; |
11577
|
|
|
|
|
|
|
11578
|
|
|
|
|
|
PERL_ARGS_ASSERT_CUSTOM_OP_XOP; |
11579
|
|
|
|
|
|
assert(o->op_type == OP_CUSTOM); |
11580
|
|
|
|
|
|
|
11581
|
|
|
|
|
|
/* This is wrong. It assumes a function pointer can be cast to IV, |
11582
|
|
|
|
|
|
* which isn't guaranteed, but this is what the old custom OP code |
11583
|
|
|
|
|
|
* did. In principle it should be safer to Copy the bytes of the |
11584
|
|
|
|
|
|
* pointer into a PV: since the new interface is hidden behind |
11585
|
|
|
|
|
|
* functions, this can be changed later if necessary. */ |
11586
|
|
|
|
|
|
/* Change custom_op_xop if this ever happens */ |
11587
|
104
|
|
|
|
|
keysv = sv_2mortal(newSViv(PTR2IV(o->op_ppaddr))); |
11588
|
|
|
|
|
|
|
11589
|
104
|
100
|
|
|
|
if (PL_custom_ops) |
11590
|
94
|
|
|
|
|
he = hv_fetch_ent(PL_custom_ops, keysv, 0, 0); |
11591
|
|
|
|
|
|
|
11592
|
|
|
|
|
|
/* assume noone will have just registered a desc */ |
11593
|
106
|
100
|
|
|
|
if (!he && PL_custom_op_names && |
|
|
100
|
|
|
|
|
|
|
50
|
|
|
|
|
11594
|
4
|
|
|
|
|
(he = hv_fetch_ent(PL_custom_op_names, keysv, 0, 0)) |
11595
|
|
|
|
|
|
) { |
11596
|
|
|
|
|
|
const char *pv; |
11597
|
|
|
|
|
|
STRLEN l; |
11598
|
|
|
|
|
|
|
11599
|
|
|
|
|
|
/* XXX does all this need to be shared mem? */ |
11600
|
4
|
|
|
|
|
Newxz(xop, 1, XOP); |
11601
|
4
|
50
|
|
|
|
pv = SvPV(HeVAL(he), l); |
11602
|
4
|
|
|
|
|
XopENTRY_set(xop, xop_name, savepvn(pv, l)); |
11603
|
5
|
100
|
|
|
|
if (PL_custom_op_descs && |
|
|
50
|
|
|
|
|
11604
|
2
|
|
|
|
|
(he = hv_fetch_ent(PL_custom_op_descs, keysv, 0, 0)) |
11605
|
|
|
|
|
|
) { |
11606
|
2
|
50
|
|
|
|
pv = SvPV(HeVAL(he), l); |
11607
|
2
|
|
|
|
|
XopENTRY_set(xop, xop_desc, savepvn(pv, l)); |
11608
|
|
|
|
|
|
} |
11609
|
4
|
|
|
|
|
Perl_custom_op_register(aTHX_ o->op_ppaddr, xop); |
11610
|
4
|
|
|
|
|
return xop; |
11611
|
|
|
|
|
|
} |
11612
|
|
|
|
|
|
|
11613
|
100
|
100
|
|
|
|
if (!he) return &xop_null; |
11614
|
|
|
|
|
|
|
11615
|
92
|
50
|
|
|
|
xop = INT2PTR(XOP *, SvIV(HeVAL(he))); |
11616
|
98
|
|
|
|
|
return xop; |
11617
|
|
|
|
|
|
} |
11618
|
|
|
|
|
|
|
11619
|
|
|
|
|
|
/* |
11620
|
|
|
|
|
|
=for apidoc Ao||custom_op_register |
11621
|
|
|
|
|
|
Register a custom op. See L. |
11622
|
|
|
|
|
|
|
11623
|
|
|
|
|
|
=cut |
11624
|
|
|
|
|
|
*/ |
11625
|
|
|
|
|
|
|
11626
|
|
|
|
|
|
void |
11627
|
14
|
|
|
|
|
Perl_custom_op_register(pTHX_ Perl_ppaddr_t ppaddr, const XOP *xop) |
11628
|
|
|
|
|
|
{ |
11629
|
|
|
|
|
|
SV *keysv; |
11630
|
|
|
|
|
|
|
11631
|
|
|
|
|
|
PERL_ARGS_ASSERT_CUSTOM_OP_REGISTER; |
11632
|
|
|
|
|
|
|
11633
|
|
|
|
|
|
/* see the comment in custom_op_xop */ |
11634
|
14
|
|
|
|
|
keysv = sv_2mortal(newSViv(PTR2IV(ppaddr))); |
11635
|
|
|
|
|
|
|
11636
|
14
|
100
|
|
|
|
if (!PL_custom_ops) |
11637
|
10
|
|
|
|
|
PL_custom_ops = newHV(); |
11638
|
|
|
|
|
|
|
11639
|
14
|
50
|
|
|
|
if (!hv_store_ent(PL_custom_ops, keysv, newSViv(PTR2IV(xop)), 0)) |
11640
|
0
|
|
|
|
|
Perl_croak(aTHX_ "panic: can't register custom OP %s", xop->xop_name); |
11641
|
14
|
|
|
|
|
} |
11642
|
|
|
|
|
|
|
11643
|
|
|
|
|
|
/* |
11644
|
|
|
|
|
|
=head1 Functions in file op.c |
11645
|
|
|
|
|
|
|
11646
|
|
|
|
|
|
=for apidoc core_prototype |
11647
|
|
|
|
|
|
This function assigns the prototype of the named core function to C, or |
11648
|
|
|
|
|
|
to a new mortal SV if C is NULL. It returns the modified C, or |
11649
|
|
|
|
|
|
NULL if the core function has no prototype. C is a code as returned |
11650
|
|
|
|
|
|
by C. It must not be equal to 0 or -KEY_CORE. |
11651
|
|
|
|
|
|
|
11652
|
|
|
|
|
|
=cut |
11653
|
|
|
|
|
|
*/ |
11654
|
|
|
|
|
|
|
11655
|
|
|
|
|
|
SV * |
11656
|
798622
|
|
|
|
|
Perl_core_prototype(pTHX_ SV *sv, const char *name, const int code, |
11657
|
|
|
|
|
|
int * const opnum) |
11658
|
|
|
|
|
|
{ |
11659
|
|
|
|
|
|
int i = 0, n = 0, seen_question = 0, defgv = 0; |
11660
|
|
|
|
|
|
I32 oa; |
11661
|
|
|
|
|
|
#define MAX_ARGS_OP ((sizeof(I32) - 1) * 2) |
11662
|
|
|
|
|
|
char str[ MAX_ARGS_OP * 2 + 2 ]; /* One ';', one '\0' */ |
11663
|
|
|
|
|
|
bool nullret = FALSE; |
11664
|
|
|
|
|
|
|
11665
|
|
|
|
|
|
PERL_ARGS_ASSERT_CORE_PROTOTYPE; |
11666
|
|
|
|
|
|
|
11667
|
|
|
|
|
|
assert (code && code != -KEY_CORE); |
11668
|
|
|
|
|
|
|
11669
|
798622
|
100
|
|
|
|
if (!sv) sv = sv_newmortal(); |
11670
|
|
|
|
|
|
|
11671
|
|
|
|
|
|
#define retsetpvs(x,y) sv_setpvs(sv, x); if(opnum) *opnum=(y); return sv |
11672
|
|
|
|
|
|
|
11673
|
798622
|
|
|
|
|
switch (code < 0 ? -code : code) { |
11674
|
|
|
|
|
|
case KEY_and : case KEY_chop: case KEY_chomp: |
11675
|
|
|
|
|
|
case KEY_cmp : case KEY_defined: case KEY_delete: case KEY_exec : |
11676
|
|
|
|
|
|
case KEY_exists: case KEY_eq : case KEY_ge : case KEY_goto : |
11677
|
|
|
|
|
|
case KEY_grep : case KEY_gt : case KEY_last : case KEY_le : |
11678
|
|
|
|
|
|
case KEY_lt : case KEY_map : case KEY_ne : case KEY_next : |
11679
|
|
|
|
|
|
case KEY_or : case KEY_print : case KEY_printf: case KEY_qr : |
11680
|
|
|
|
|
|
case KEY_redo : case KEY_require: case KEY_return: case KEY_say : |
11681
|
|
|
|
|
|
case KEY_select: case KEY_sort : case KEY_split : case KEY_system: |
11682
|
|
|
|
|
|
case KEY_x : case KEY_xor : |
11683
|
255656
|
100
|
|
|
|
if (!opnum) return NULL; nullret = TRUE; goto findopnum; |
11684
|
10
|
100
|
|
|
|
case KEY_glob: retsetpvs("_;", OP_GLOB); |
11685
|
9626
|
100
|
|
|
|
case KEY_keys: retsetpvs("+", OP_KEYS); |
11686
|
1058
|
100
|
|
|
|
case KEY_values: retsetpvs("+", OP_VALUES); |
11687
|
3902
|
100
|
|
|
|
case KEY_each: retsetpvs("+", OP_EACH); |
11688
|
26552
|
100
|
|
|
|
case KEY_push: retsetpvs("+@", OP_PUSH); |
11689
|
15968
|
100
|
|
|
|
case KEY_unshift: retsetpvs("+@", OP_UNSHIFT); |
11690
|
886
|
100
|
|
|
|
case KEY_pop: retsetpvs(";+", OP_POP); |
11691
|
48558
|
100
|
|
|
|
case KEY_shift: retsetpvs(";+", OP_SHIFT); |
11692
|
770
|
100
|
|
|
|
case KEY_pos: retsetpvs(";\\[$*]", OP_POS); |
11693
|
|
|
|
|
|
case KEY_splice: |
11694
|
1852
|
100
|
|
|
|
retsetpvs("+;$$@", OP_SPLICE); |
11695
|
|
|
|
|
|
case KEY___FILE__: case KEY___LINE__: case KEY___PACKAGE__: |
11696
|
30
|
100
|
|
|
|
retsetpvs("", 0); |
11697
|
|
|
|
|
|
case KEY_evalbytes: |
11698
|
216974
|
|
|
|
|
name = "entereval"; break; |
11699
|
|
|
|
|
|
case KEY_readpipe: |
11700
|
|
|
|
|
|
name = "backtick"; |
11701
|
|
|
|
|
|
} |
11702
|
|
|
|
|
|
|
11703
|
|
|
|
|
|
#undef retsetpvs |
11704
|
|
|
|
|
|
|
11705
|
|
|
|
|
|
findopnum: |
11706
|
67652906
|
100
|
|
|
|
while (i < MAXO) { /* The slow way. */ |
11707
|
67633320
|
100
|
|
|
|
if (strEQ(name, PL_op_name[i]) |
11708
|
67221864
|
100
|
|
|
|
|| strEQ(name, PL_op_desc[i])) |
11709
|
|
|
|
|
|
{ |
11710
|
414204
|
100
|
|
|
|
if (nullret) { assert(opnum); *opnum = i; return NULL; } |
11711
|
|
|
|
|
|
goto found; |
11712
|
|
|
|
|
|
} |
11713
|
67219116
|
|
|
|
|
i++; |
11714
|
|
|
|
|
|
} |
11715
|
|
|
|
|
|
return NULL; |
11716
|
|
|
|
|
|
found: |
11717
|
414168
|
|
|
|
|
defgv = PL_opargs[i] & OA_DEFGV; |
11718
|
414168
|
|
|
|
|
oa = PL_opargs[i] >> OASHIFT; |
11719
|
1154814
|
100
|
|
|
|
while (oa) { |
11720
|
533562
|
100
|
|
|
|
if (oa & OA_OPTIONAL && !seen_question && ( |
|
|
100
|
|
|
|
|
11721
|
109748
|
100
|
|
|
|
!defgv || (oa & (OA_OPTIONAL - 1)) == OA_FILEREF |
11722
|
|
|
|
|
|
)) { |
11723
|
|
|
|
|
|
seen_question = 1; |
11724
|
101712
|
|
|
|
|
str[n++] = ';'; |
11725
|
|
|
|
|
|
} |
11726
|
533562
|
100
|
|
|
|
if ((oa & (OA_OPTIONAL - 1)) >= OA_AVREF |
11727
|
533562
|
|
|
|
|
&& (oa & (OA_OPTIONAL - 1)) <= OA_SCALARREF |
11728
|
|
|
|
|
|
/* But globs are already references (kinda) */ |
11729
|
47638
|
100
|
|
|
|
&& (oa & (OA_OPTIONAL - 1)) != OA_FILEREF |
11730
|
|
|
|
|
|
) { |
11731
|
9960
|
|
|
|
|
str[n++] = '\\'; |
11732
|
|
|
|
|
|
} |
11733
|
533562
|
100
|
|
|
|
if ((oa & (OA_OPTIONAL - 1)) == OA_SCALARREF |
11734
|
9716
|
100
|
|
|
|
&& !scalar_mod_type(NULL, i)) { |
11735
|
8986
|
|
|
|
|
str[n++] = '['; |
11736
|
8986
|
|
|
|
|
str[n++] = '$'; |
11737
|
8986
|
|
|
|
|
str[n++] = '@'; |
11738
|
8986
|
|
|
|
|
str[n++] = '%'; |
11739
|
8986
|
100
|
|
|
|
if (i == OP_LOCK || i == OP_UNDEF) str[n++] = '&'; |
11740
|
8986
|
|
|
|
|
str[n++] = '*'; |
11741
|
8986
|
|
|
|
|
str[n++] = ']'; |
11742
|
|
|
|
|
|
} |
11743
|
524576
|
|
|
|
|
else str[n++] = ("?$@@%&*$")[oa & (OA_OPTIONAL - 1)]; |
11744
|
533562
|
100
|
|
|
|
if (oa & OA_OPTIONAL && defgv && str[n-1] == '$') { |
|
|
100
|
|
|
|
|
11745
|
108608
|
|
|
|
|
str[n-1] = '_'; defgv = 0; |
11746
|
|
|
|
|
|
} |
11747
|
533562
|
|
|
|
|
oa = oa >> 4; |
11748
|
|
|
|
|
|
} |
11749
|
414168
|
100
|
|
|
|
if (code == -KEY_not || code == -KEY_getprotobynumber) str[n++] = ';'; |
11750
|
414168
|
|
|
|
|
str[n++] = '\0'; |
11751
|
414168
|
|
|
|
|
sv_setpvn(sv, str, n - 1); |
11752
|
606395
|
100
|
|
|
|
if (opnum) *opnum = i; |
11753
|
|
|
|
|
|
return sv; |
11754
|
|
|
|
|
|
} |
11755
|
|
|
|
|
|
|
11756
|
|
|
|
|
|
OP * |
11757
|
736
|
|
|
|
|
Perl_coresub_op(pTHX_ SV * const coreargssv, const int code, |
11758
|
|
|
|
|
|
const int opnum) |
11759
|
|
|
|
|
|
{ |
11760
|
736
|
|
|
|
|
OP * const argop = newSVOP(OP_COREARGS,0,coreargssv); |
11761
|
|
|
|
|
|
OP *o; |
11762
|
|
|
|
|
|
|
11763
|
|
|
|
|
|
PERL_ARGS_ASSERT_CORESUB_OP; |
11764
|
|
|
|
|
|
|
11765
|
736
|
|
|
|
|
switch(opnum) { |
11766
|
|
|
|
|
|
case 0: |
11767
|
12
|
|
|
|
|
return op_append_elem(OP_LINESEQ, |
11768
|
|
|
|
|
|
argop, |
11769
|
|
|
|
|
|
newSLICEOP(0, |
11770
|
|
|
|
|
|
newSVOP(OP_CONST, 0, newSViv(-code % 3)), |
11771
|
|
|
|
|
|
newOP(OP_CALLER,0) |
11772
|
|
|
|
|
|
) |
11773
|
|
|
|
|
|
); |
11774
|
|
|
|
|
|
case OP_SELECT: /* which represents OP_SSELECT as well */ |
11775
|
8
|
100
|
|
|
|
if (code) |
11776
|
4
|
|
|
|
|
return newCONDOP( |
11777
|
|
|
|
|
|
0, |
11778
|
|
|
|
|
|
newBINOP(OP_GT, 0, |
11779
|
|
|
|
|
|
newAVREF(newGVOP(OP_GV, 0, PL_defgv)), |
11780
|
|
|
|
|
|
newSVOP(OP_CONST, 0, newSVuv(1)) |
11781
|
|
|
|
|
|
), |
11782
|
|
|
|
|
|
coresub_op(newSVuv((UV)OP_SSELECT), 0, |
11783
|
|
|
|
|
|
OP_SSELECT), |
11784
|
|
|
|
|
|
coresub_op(coreargssv, 0, OP_SELECT) |
11785
|
|
|
|
|
|
); |
11786
|
|
|
|
|
|
/* FALL THROUGH */ |
11787
|
|
|
|
|
|
default: |
11788
|
720
|
|
|
|
|
switch (PL_opargs[opnum] & OA_CLASS_MASK) { |
11789
|
|
|
|
|
|
case OA_BASEOP: |
11790
|
98
|
100
|
|
|
|
return op_append_elem( |
11791
|
|
|
|
|
|
OP_LINESEQ, argop, |
11792
|
|
|
|
|
|
newOP(opnum, |
11793
|
|
|
|
|
|
opnum == OP_WANTARRAY || opnum == OP_RUNCV |
11794
|
|
|
|
|
|
? OPpOFFBYONE << 8 : 0) |
11795
|
|
|
|
|
|
); |
11796
|
|
|
|
|
|
case OA_BASEOP_OR_UNOP: |
11797
|
278
|
100
|
|
|
|
if (opnum == OP_ENTEREVAL) { |
11798
|
4
|
|
|
|
|
o = newUNOP(OP_ENTEREVAL,OPpEVAL_COPHH<<8,argop); |
11799
|
4
|
50
|
|
|
|
if (code == -KEY_evalbytes) o->op_private |= OPpEVAL_BYTES; |
11800
|
|
|
|
|
|
} |
11801
|
274
|
|
|
|
|
else o = newUNOP(opnum,0,argop); |
11802
|
278
|
100
|
|
|
|
if (opnum == OP_CALLER) o->op_private |= OPpOFFBYONE; |
11803
|
|
|
|
|
|
else { |
11804
|
|
|
|
|
|
onearg: |
11805
|
614
|
100
|
|
|
|
if (is_handle_constructor(o, 1)) |
11806
|
32
|
|
|
|
|
argop->op_private |= OPpCOREARGS_DEREF1; |
11807
|
614
|
100
|
|
|
|
if (scalar_mod_type(NULL, opnum)) |
11808
|
60
|
|
|
|
|
argop->op_private |= OPpCOREARGS_SCALARMOD; |
11809
|
|
|
|
|
|
} |
11810
|
618
|
|
|
|
|
return o; |
11811
|
|
|
|
|
|
default: |
11812
|
344
|
100
|
|
|
|
o = convert(opnum,OPf_SPECIAL*(opnum == OP_GLOB),argop); |
11813
|
344
|
100
|
|
|
|
if (is_handle_constructor(o, 2)) |
11814
|
8
|
|
|
|
|
argop->op_private |= OPpCOREARGS_DEREF2; |
11815
|
344
|
100
|
|
|
|
if (opnum == OP_SUBSTR) { |
11816
|
4
|
|
|
|
|
o->op_private |= OPpMAYBE_LVSUB; |
11817
|
370
|
|
|
|
|
return o; |
11818
|
|
|
|
|
|
} |
11819
|
|
|
|
|
|
else goto onearg; |
11820
|
|
|
|
|
|
} |
11821
|
|
|
|
|
|
} |
11822
|
|
|
|
|
|
} |
11823
|
|
|
|
|
|
|
11824
|
|
|
|
|
|
void |
11825
|
18696
|
|
|
|
|
Perl_report_redefined_cv(pTHX_ const SV *name, const CV *old_cv, |
11826
|
|
|
|
|
|
SV * const *new_const_svp) |
11827
|
|
|
|
|
|
{ |
11828
|
|
|
|
|
|
const char *hvname; |
11829
|
18696
|
|
|
|
|
bool is_const = !!CvCONST(old_cv); |
11830
|
18696
|
100
|
|
|
|
SV *old_const_sv = is_const ? cv_const_sv(old_cv) : NULL; |
11831
|
|
|
|
|
|
|
11832
|
|
|
|
|
|
PERL_ARGS_ASSERT_REPORT_REDEFINED_CV; |
11833
|
|
|
|
|
|
|
11834
|
18696
|
100
|
|
|
|
if (is_const && new_const_svp && old_const_sv == *new_const_svp) |
|
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
11835
|
18684
|
|
|
|
|
return; |
11836
|
|
|
|
|
|
/* They are 2 constant subroutines generated from |
11837
|
|
|
|
|
|
the same constant. This probably means that |
11838
|
|
|
|
|
|
they are really the "same" proxy subroutine |
11839
|
|
|
|
|
|
instantiated in 2 places. Most likely this is |
11840
|
|
|
|
|
|
when a constant is exported twice. Don't warn. |
11841
|
|
|
|
|
|
*/ |
11842
|
298
|
100
|
|
|
|
if ( |
|
|
100
|
|
|
|
|
11843
|
178
|
|
|
|
|
(ckWARN(WARN_REDEFINE) |
11844
|
124
|
100
|
|
|
|
&& !( |
|
|
0
|
|
|
|
|
11845
|
120
|
50
|
|
|
|
CvGV(old_cv) && GvSTASH(CvGV(old_cv)) |
11846
|
954
|
50
|
|
|
|
&& HvNAMELEN(GvSTASH(CvGV(old_cv))) == 7 |
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
50
|
|
|
|
|
11847
|
0
|
0
|
|
|
|
&& (hvname = HvNAME(GvSTASH(CvGV(old_cv))), |
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
11848
|
0
|
|
|
|
|
strEQ(hvname, "autouse")) |
11849
|
|
|
|
|
|
) |
11850
|
|
|
|
|
|
) |
11851
|
54
|
50
|
|
|
|
|| (is_const |
11852
|
54
|
100
|
|
|
|
&& ckWARN_d(WARN_REDEFINE) |
11853
|
36
|
50
|
|
|
|
&& (!new_const_svp || sv_cmp(old_const_sv, *new_const_svp)) |
|
|
100
|
|
|
|
|
11854
|
|
|
|
|
|
) |
11855
|
|
|
|
|
|
) |
11856
|
146
|
100
|
|
|
|
Perl_warner(aTHX_ packWARN(WARN_REDEFINE), |
11857
|
|
|
|
|
|
is_const |
11858
|
|
|
|
|
|
? "Constant subroutine %"SVf" redefined" |
11859
|
|
|
|
|
|
: "Subroutine %"SVf" redefined", |
11860
|
|
|
|
|
|
name); |
11861
|
|
|
|
|
|
} |
11862
|
|
|
|
|
|
|
11863
|
|
|
|
|
|
/* |
11864
|
|
|
|
|
|
=head1 Hook manipulation |
11865
|
|
|
|
|
|
|
11866
|
|
|
|
|
|
These functions provide convenient and thread-safe means of manipulating |
11867
|
|
|
|
|
|
hook variables. |
11868
|
|
|
|
|
|
|
11869
|
|
|
|
|
|
=cut |
11870
|
|
|
|
|
|
*/ |
11871
|
|
|
|
|
|
|
11872
|
|
|
|
|
|
/* |
11873
|
|
|
|
|
|
=for apidoc Am|void|wrap_op_checker|Optype opcode|Perl_check_t new_checker|Perl_check_t *old_checker_p |
11874
|
|
|
|
|
|
|
11875
|
|
|
|
|
|
Puts a C function into the chain of check functions for a specified op |
11876
|
|
|
|
|
|
type. This is the preferred way to manipulate the L array. |
11877
|
|
|
|
|
|
I specifies which type of op is to be affected. I |
11878
|
|
|
|
|
|
is a pointer to the C function that is to be added to that opcode's |
11879
|
|
|
|
|
|
check chain, and I points to the storage location where a |
11880
|
|
|
|
|
|
pointer to the next function in the chain will be stored. The value of |
11881
|
|
|
|
|
|
I is written into the L array, while the value |
11882
|
|
|
|
|
|
previously stored there is written to I<*old_checker_p>. |
11883
|
|
|
|
|
|
|
11884
|
|
|
|
|
|
L is global to an entire process, and a module wishing to |
11885
|
|
|
|
|
|
hook op checking may find itself invoked more than once per process, |
11886
|
|
|
|
|
|
typically in different threads. To handle that situation, this function |
11887
|
|
|
|
|
|
is idempotent. The location I<*old_checker_p> must initially (once |
11888
|
|
|
|
|
|
per process) contain a null pointer. A C variable of static duration |
11889
|
|
|
|
|
|
(declared at file scope, typically also marked C to give |
11890
|
|
|
|
|
|
it internal linkage) will be implicitly initialised appropriately, |
11891
|
|
|
|
|
|
if it does not have an explicit initialiser. This function will only |
11892
|
|
|
|
|
|
actually modify the check chain if it finds I<*old_checker_p> to be null. |
11893
|
|
|
|
|
|
This function is also thread safe on the small scale. It uses appropriate |
11894
|
|
|
|
|
|
locking to avoid race conditions in accessing L. |
11895
|
|
|
|
|
|
|
11896
|
|
|
|
|
|
When this function is called, the function referenced by I |
11897
|
|
|
|
|
|
must be ready to be called, except for I<*old_checker_p> being unfilled. |
11898
|
|
|
|
|
|
In a threading situation, I may be called immediately, |
11899
|
|
|
|
|
|
even before this function has returned. I<*old_checker_p> will always |
11900
|
|
|
|
|
|
be appropriately set before I is called. If I |
11901
|
|
|
|
|
|
decides not to do anything special with an op that it is given (which |
11902
|
|
|
|
|
|
is the usual case for most uses of op check hooking), it must chain the |
11903
|
|
|
|
|
|
check function referenced by I<*old_checker_p>. |
11904
|
|
|
|
|
|
|
11905
|
|
|
|
|
|
If you want to influence compilation of calls to a specific subroutine, |
11906
|
|
|
|
|
|
then use L rather than hooking checking of all |
11907
|
|
|
|
|
|
C ops. |
11908
|
|
|
|
|
|
|
11909
|
|
|
|
|
|
=cut |
11910
|
|
|
|
|
|
*/ |
11911
|
|
|
|
|
|
|
11912
|
|
|
|
|
|
void |
11913
|
3074
|
|
|
|
|
Perl_wrap_op_checker(pTHX_ Optype opcode, |
11914
|
|
|
|
|
|
Perl_check_t new_checker, Perl_check_t *old_checker_p) |
11915
|
|
|
|
|
|
{ |
11916
|
|
|
|
|
|
dVAR; |
11917
|
|
|
|
|
|
|
11918
|
|
|
|
|
|
PERL_ARGS_ASSERT_WRAP_OP_CHECKER; |
11919
|
6147
|
100
|
|
|
|
if (*old_checker_p) return; |
11920
|
|
|
|
|
|
OP_CHECK_MUTEX_LOCK; |
11921
|
3072
|
50
|
|
|
|
if (!*old_checker_p) { |
11922
|
3072
|
|
|
|
|
*old_checker_p = PL_check[opcode]; |
11923
|
3072
|
|
|
|
|
PL_check[opcode] = new_checker; |
11924
|
|
|
|
|
|
} |
11925
|
|
|
|
|
|
OP_CHECK_MUTEX_UNLOCK; |
11926
|
|
|
|
|
|
} |
11927
|
|
|
|
|
|
|
11928
|
|
|
|
|
|
#include "XSUB.h" |
11929
|
|
|
|
|
|
|
11930
|
|
|
|
|
|
/* Efficient sub that returns a constant scalar value. */ |
11931
|
|
|
|
|
|
static void |
11932
|
208426
|
|
|
|
|
const_sv_xsub(pTHX_ CV* cv) |
11933
|
208426
|
50
|
|
|
|
{ |
11934
|
|
|
|
|
|
dVAR; |
11935
|
208426
|
|
|
|
|
dXSARGS; |
11936
|
208426
|
|
|
|
|
SV *const sv = MUTABLE_SV(XSANY.any_ptr); |
11937
|
|
|
|
|
|
PERL_UNUSED_ARG(items); |
11938
|
208426
|
50
|
|
|
|
if (!sv) { |
11939
|
0
|
|
|
|
|
XSRETURN(0); |
11940
|
|
|
|
|
|
} |
11941
|
103853
|
|
|
|
|
EXTEND(sp, 1); |
11942
|
208426
|
|
|
|
|
ST(0) = sv; |
11943
|
208426
|
|
|
|
|
XSRETURN(1); |
11944
|
|
|
|
|
|
} |
11945
|
|
|
|
|
|
|
11946
|
|
|
|
|
|
static void |
11947
|
6
|
|
|
|
|
const_av_xsub(pTHX_ CV* cv) |
11948
|
6
|
50
|
|
|
|
{ |
11949
|
|
|
|
|
|
dVAR; |
11950
|
6
|
|
|
|
|
dXSARGS; |
11951
|
6
|
|
|
|
|
AV * const av = MUTABLE_AV(XSANY.any_ptr); |
11952
|
6
|
|
|
|
|
SP -= items; |
11953
|
|
|
|
|
|
assert(av); |
11954
|
|
|
|
|
|
#ifndef DEBUGGING |
11955
|
6
|
50
|
|
|
|
if (!av) { |
11956
|
0
|
|
|
|
|
XSRETURN(0); |
11957
|
|
|
|
|
|
} |
11958
|
|
|
|
|
|
#endif |
11959
|
6
|
50
|
|
|
|
if (SvRMAGICAL(av)) |
11960
|
0
|
|
|
|
|
Perl_croak(aTHX_ "Magical list constants are not supported"); |
11961
|
6
|
50
|
|
|
|
if (GIMME_V != G_ARRAY) { |
|
|
50
|
|
|
|
|
|
|
0
|
|
|
|
|
11962
|
0
|
|
|
|
|
EXTEND(SP, 1); |
11963
|
0
|
|
|
|
|
ST(0) = newSViv((IV)AvFILLp(av)+1); |
11964
|
0
|
|
|
|
|
XSRETURN(1); |
11965
|
|
|
|
|
|
} |
11966
|
3
|
|
|
|
|
EXTEND(SP, AvFILLp(av)+1); |
11967
|
6
|
50
|
|
|
|
Copy(AvARRAY(av), &ST(0), AvFILLp(av)+1, SV *); |
11968
|
6
|
|
|
|
|
XSRETURN(AvFILLp(av)+1); |
11969
|
19759256
|
|
|
|
|
} |
11970
|
|
|
|
|
|
|
11971
|
|
|
|
|
|
/* |
11972
|
|
|
|
|
|
* Local variables: |
11973
|
|
|
|
|
|
* c-indentation-style: bsd |
11974
|
|
|
|
|
|
* c-basic-offset: 4 |
11975
|
|
|
|
|
|
* indent-tabs-mode: nil |
11976
|
|
|
|
|
|
* End: |
11977
|
|
|
|
|
|
* |
11978
|
|
|
|
|
|
* ex: set ts=8 sts=4 sw=4 et: |
11979
|
|
|
|
|
|
*/ |