This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Math::Trig: POD correction
[perl5.git] / regexp.h
CommitLineData
a0d0e21e 1/* regexp.h
d6376244 2 *
4bb101f2 3 * Copyright (C) 1993, 1994, 1996, 1997, 1999, 2000, 2001, 2003,
1129b882 4 * 2005, 2006, 2007, 2008 by Larry Wall and others
d6376244
JH
5 *
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
8 *
a0d0e21e
LW
9 */
10
378cc40b
LW
11/*
12 * Definitions etc. for regexp(3) routines.
13 *
14 * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof],
15 * not the System V one.
16 */
be8e71aa 17#ifndef PLUGGABLE_RE_EXTENSION
785a26d5
YO
18/* we don't want to include this stuff if we are inside of
19 an external regex engine based on the core one - like re 'debug'*/
378cc40b 20
6c5474e8 21# include "utf8.h"
79a2a0e8 22
f55b7b26
KW
23typedef SSize_t regnode_offset;
24
12d173c9
YO
25struct regnode_meta {
26 U8 type;
27 U8 arg_len;
28 U8 arg_len_varies;
29 U8 off_by_arg;
30};
31
c277df42 32struct regnode {
85900e28 33 U8 flags;
c277df42
IZ
34 U8 type;
35 U16 next_off;
36};
37
38typedef struct regnode regnode;
39
cad2e5aa 40struct reg_substr_data;
2779dcf1 41
0ee3c8d0
JH
42struct reg_data;
43
f9f4320a 44struct regexp_engine;
28d8d7f4 45struct regexp;
bbe252da 46
785a26d5 47struct reg_substr_datum {
c4828ca0 48 SSize_t min_offset; /* min pos (in chars) that substr must appear */
6459affc 49 SSize_t max_offset; /* max pos (in chars) that substr must appear */
85900e28
YO
50 SV *substr; /* non-utf8 variant */
51 SV *utf8_substr; /* utf8 variant */
c4828ca0 52 SSize_t end_shift; /* how many fixed chars must end the string */
785a26d5
YO
53};
54struct reg_substr_data {
6480a6c4 55 U8 check_ix; /* index into data[] of check substr */
85900e28 56 struct reg_substr_datum data[3]; /* Actual array */
785a26d5 57};
f9f4320a 58
6c5474e8
KW
59# ifdef PERL_ANY_COW
60# define SV_SAVED_COPY SV *saved_copy; /* If non-NULL, SV which is COW from original */
61# else
62# define SV_SAVED_COPY
63# endif
28d8d7f4 64
b3fd53f3
DM
65/* offsets within a string of a particular /(.)/ capture */
66
f0ab9afb 67typedef struct regexp_paren_pair {
99a90e59
FC
68 SSize_t start;
69 SSize_t end;
b3fd53f3
DM
70 /* 'start_tmp' records a new opening position before the matching end
71 * has been found, so that the old start and end values are still
72 * valid, e.g.
85900e28 73 * "abc" =~ /(.(?{print "[$1]"}))+/
b3fd53f3
DM
74 *outputs [][a][b]
75 * This field is not part of the API. */
ea3daa5d 76 SSize_t start_tmp;
f0ab9afb 77} regexp_paren_pair;
28d8d7f4 78
85900e28 79# if defined(PERL_IN_REGCOMP_ANY) || defined(PERL_IN_UTF8_C)
6c5474e8
KW
80# define _invlist_union(a, b, output) _invlist_union_maybe_complement_2nd(a, b, FALSE, output)
81# define _invlist_intersection(a, b, output) _invlist_intersection_maybe_complement_2nd(a, b, FALSE, output)
3f80b571
KW
82
83/* Subtracting b from a leaves in a everything that was there that isn't in b,
84 * that is the intersection of a with b's complement */
6c5474e8
KW
85# define _invlist_subtract(a, b, output) _invlist_intersection_maybe_complement_2nd(a, b, TRUE, output)
86# endif
52ae8f7e 87
3d2bd50a
DM
88/* record the position of a (?{...}) within a pattern */
89
90struct reg_code_block {
91 STRLEN start;
92 STRLEN end;
93 OP *block;
b30fcab9 94 REGEXP *src_regex;
3d2bd50a
DM
95};
96
1acab4c5
DM
97/* array of reg_code_block's plus header info */
98
99struct reg_code_blocks {
f8def6c7 100 int refcnt; /* we may be pointed to from a regex and from the savestack */
1acab4c5
DM
101 int count; /* how many code blocks */
102 struct reg_code_block *cb; /* array of reg_code_block's */
103};
104
3d2bd50a 105
882227b7 106/*
1f6e74eb 107= for apidoc AyT||regexp
882227b7
AB
108 The regexp/REGEXP struct, see L<perlreapi> for further documentation
109 on the individual fields. The struct is ordered so that the most
110 commonly used fields are placed at the start.
111
112 Any patch that adds items to this struct will need to include
113 changes to F<sv.c> (C<Perl_re_dup()>) and F<regcomp.c>
114 (C<pregfree()>). This involves freeing or cloning items in the
115 regexp's data array based on the data item's type.
116*/
117
bbe252da 118typedef struct regexp {
e1168c11
DM
119 _XPV_HEAD;
120 const struct regexp_engine* engine; /* what engine created this regexp? */
121 REGEXP *mother_re; /* what re is this a lightweight copy of? */
122 HV *paren_names; /* Optional hash of paren names */
123
124 /*----------------------------------------------------------------------
125 * Information about the match that the perl core uses to manage things
126 */
127
128 U32 extflags; /* Flags used both externally and internally */
2bb68ff1 129 U32 nparens; /* number of capture buffers */
e1168c11 130 SSize_t minlen; /* minimum possible number of chars in string to match */
0c6362ad 131 SSize_t minlenret; /* minimum possible number of chars in $& */
e1168c11
DM
132 STRLEN gofs; /* chars left of pos that we search from */
133 /* substring data about strings that must appear in
134 * the final match, used for optimisations */
135 struct reg_substr_data *substrs;
e1168c11
DM
136
137 /* private engine specific data */
138
e1168c11
DM
139 void *pprivate; /* Data private to the regex engine which
140 * created this object. */
2bb68ff1 141 U32 intflags; /* Engine Specific Internal flags */
e1168c11
DM
142
143 /*----------------------------------------------------------------------
144 * Data about the last/current match. These are modified during matching
145 */
146
0b9dad94 147 U32 lastparen; /* highest close paren matched ($+) */
e1168c11
DM
148 regexp_paren_pair *offs; /* Array of offsets for (@-) and (@+) */
149 char **recurse_locinput; /* used to detect infinite recursion, XXX: move to internal */
2bb68ff1 150 U32 lastcloseparen; /* last close paren matched ($^N) */
e1168c11
DM
151
152 /*---------------------------------------------------------------------- */
153
154 /* offset from wrapped to the start of precomp */
155 PERL_BITFIELD32 pre_prefix:4;
156
157 /* original flags used to compile the pattern, may differ from
158 * extflags in various ways */
159 PERL_BITFIELD32 compflags:9;
160
161 /*---------------------------------------------------------------------- */
162
da35f4ca 163 char *subbeg; /* saved or original string so \digit works forever. */
2bb68ff1
RL
164 SV_SAVED_COPY /* If non-NULL, SV which is COW from original */
165 SSize_t sublen; /* Length of string pointed by subbeg */
166 SSize_t suboffset; /* byte offset of subbeg from logical start of str */
167 SSize_t subcoffset; /* suboffset equiv, but in chars (for @-/@+) */
168 SSize_t maxlen; /* minimum possible number of chars in string to match */
2bb68ff1
RL
169
170 /*---------------------------------------------------------------------- */
171
172
e1168c11 173 CV *qr_anoncv; /* the anon sub wrapped round qr/(?{..})/ */
f8fc2ecf
YO
174} regexp;
175
e1168c11 176
85900e28 177# define RXp_PAREN_NAMES(rx) ((rx)->paren_names)
5daac39c 178
785a26d5 179/* used for high speed searches */
f9f4320a
YO
180typedef struct re_scream_pos_data_s
181{
85900e28
YO
182 char **scream_olds; /* match pos */
183 SSize_t *scream_pos; /* Internal iterator of scream. */
f9f4320a
YO
184} re_scream_pos_data;
185
785a26d5
YO
186/* regexp_engine structure. This is the dispatch table for regexes.
187 * Any regex engine implementation must be able to build one of these.
188 */
f9f4320a 189typedef struct regexp_engine {
1593ad57 190 REGEXP* (*comp) (pTHX_ SV * const pattern, U32 flags);
49d7dfbc 191 I32 (*exec) (pTHX_ REGEXP * const rx, char* stringarg, char* strend,
ea3daa5d 192 char* strbeg, SSize_t minend, SV* sv,
49d7dfbc 193 void* data, U32 flags);
52a21eb3
DM
194 char* (*intuit) (pTHX_
195 REGEXP * const rx,
196 SV *sv,
197 const char * const strbeg,
198 char *strpos,
199 char *strend,
200 const U32 flags,
9f61653a 201 re_scream_pos_data *data);
49d7dfbc 202 SV* (*checkstr) (pTHX_ REGEXP * const rx);
fc6bde6f 203 void (*rxfree) (pTHX_ REGEXP * const rx);
2fdbfb4d 204 void (*numbered_buff_FETCH) (pTHX_ REGEXP * const rx, const I32 paren,
192b9cd1 205 SV * const sv);
2fdbfb4d
AB
206 void (*numbered_buff_STORE) (pTHX_ REGEXP * const rx, const I32 paren,
207 SV const * const value);
208 I32 (*numbered_buff_LENGTH) (pTHX_ REGEXP * const rx, const SV * const sv,
209 const I32 paren);
192b9cd1
AB
210 SV* (*named_buff) (pTHX_ REGEXP * const rx, SV * const key,
211 SV * const value, const U32 flags);
212 SV* (*named_buff_iter) (pTHX_ REGEXP * const rx, const SV * const lastkey,
213 const U32 flags);
49d7dfbc 214 SV* (*qr_package)(pTHX_ REGEXP * const rx);
6c5474e8 215# ifdef USE_ITHREADS
49d7dfbc 216 void* (*dupe) (pTHX_ REGEXP * const rx, CLONE_PARAMS *param);
6c5474e8 217# endif
3c13cae6 218 REGEXP* (*op_comp) (pTHX_ SV ** const patternp, int pat_count,
1f4fbd3b
MS
219 OP *expr, const struct regexp_engine* eng,
220 REGEXP *old_re,
221 bool *is_bare_re, U32 orig_rx_flags, U32 pm_flags);
f9f4320a
YO
222} regexp_engine;
223
192b9cd1
AB
224/*
225 These are passed to the numbered capture variable callbacks as the
226 paren name. >= 1 is reserved for actual numbered captures, i.e. $1,
227 $2 etc.
228*/
6c5474e8
KW
229# define RX_BUFF_IDX_CARET_PREMATCH -5 /* ${^PREMATCH} */
230# define RX_BUFF_IDX_CARET_POSTMATCH -4 /* ${^POSTMATCH} */
231# define RX_BUFF_IDX_CARET_FULLMATCH -3 /* ${^MATCH} */
232# define RX_BUFF_IDX_PREMATCH -2 /* $` */
233# define RX_BUFF_IDX_POSTMATCH -1 /* $' */
234# define RX_BUFF_IDX_FULLMATCH 0 /* $& */
192b9cd1
AB
235
236/*
237 Flags that are passed to the named_buff and named_buff_iter
238 callbacks above. Those routines are called from universal.c via the
239 Tie::Hash::NamedCapture interface for %+ and %- and the re::
240 functions in the same file.
241*/
242
243/* The Tie::Hash::NamedCapture operation this is part of, if any */
6c5474e8
KW
244# define RXapif_FETCH 0x0001
245# define RXapif_STORE 0x0002
246# define RXapif_DELETE 0x0004
247# define RXapif_CLEAR 0x0008
248# define RXapif_EXISTS 0x0010
249# define RXapif_SCALAR 0x0020
250# define RXapif_FIRSTKEY 0x0040
251# define RXapif_NEXTKEY 0x0080
192b9cd1
AB
252
253/* Whether %+ or %- is being operated on */
6c5474e8
KW
254# define RXapif_ONE 0x0100 /* %+ */
255# define RXapif_ALL 0x0200 /* %- */
192b9cd1
AB
256
257/* Whether this is being called from a re:: function */
6c5474e8
KW
258# define RXapif_REGNAME 0x0400
259# define RXapif_REGNAMES 0x0800
260# define RXapif_REGNAMES_COUNT 0x1000
192b9cd1 261
f7e71195 262/*
f7e71195
AB
263=for apidoc Am|REGEXP *|SvRX|SV *sv
264
72d33970 265Convenience macro to get the REGEXP from a SV. This is approximately
f7e71195
AB
266equivalent to the following snippet:
267
268 if (SvMAGICAL(sv))
269 mg_get(sv);
1af910ea
DL
270 if (SvROK(sv))
271 sv = MUTABLE_SV(SvRV(sv));
272 if (SvTYPE(sv) == SVt_REGEXP)
273 return (REGEXP*) sv;
f7e71195 274
796b6530 275C<NULL> will be returned if a REGEXP* is not found.
f7e71195
AB
276
277=for apidoc Am|bool|SvRXOK|SV* sv
278
1af910ea
DL
279Returns a boolean indicating whether the SV (or the one it references)
280is a REGEXP.
f7e71195
AB
281
282If you want to do something with the REGEXP* later use SvRX instead
283and check for NULL.
284
285=cut
286*/
287
6c5474e8
KW
288# define SvRX(sv) (Perl_get_re_arg(aTHX_ sv))
289# define SvRXOK(sv) cBOOL(Perl_get_re_arg(aTHX_ sv))
f7e71195
AB
290
291
7948fc08 292/* Flags stored in regexp->extflags
bbe252da 293 * These are used by code external to the regexp engine
e357fc67 294 *
5b126c84
KW
295 * Note that the flags whose names start with RXf_PMf_ are defined in
296 * op_reg_common.h, being copied from the parallel flags of op_pmflags
cb5027f2 297 *
eb2624c9
FC
298 * NOTE: if you modify any RXf flags you should run regen.pl or
299 * regen/regcomp.pl so that regnodes.h is updated with the changes.
cb5027f2 300 *
bbe252da
YO
301 */
302
6c5474e8 303# include "op_reg_common.h"
5b126c84 304
85900e28 305# define RXf_PMf_STD_PMMOD (RXf_PMf_MULTILINE|RXf_PMf_SINGLELINE|RXf_PMf_FOLD|RXf_PMf_EXTENDED|RXf_PMf_EXTENDED_MORE|RXf_PMf_NOCAPTURE)
cde0cee5 306
6c5474e8 307# define CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl, x_count) \
cc4d09e1
KW
308 case IGNORE_PAT_MOD: *(pmfl) |= RXf_PMf_FOLD; break; \
309 case MULTILINE_PAT_MOD: *(pmfl) |= RXf_PMf_MULTILINE; break; \
310 case SINGLE_PAT_MOD: *(pmfl) |= RXf_PMf_SINGLELINE; break; \
77c8f263
KW
311 case XTENDED_PAT_MOD: if (x_count == 0) { \
312 *(pmfl) |= RXf_PMf_EXTENDED; \
313 *(pmfl) &= ~RXf_PMf_EXTENDED_MORE; \
314 } \
315 else { \
316 *(pmfl) |= RXf_PMf_EXTENDED \
317 |RXf_PMf_EXTENDED_MORE; \
318 } \
319 (x_count)++; break; \
41d7c59e 320 case NOCAPTURE_PAT_MOD: *(pmfl) |= RXf_PMf_NOCAPTURE; break;
cc4d09e1 321
94b03d7d 322/* Note, includes charset ones, assumes 0 is the default for them */
6c5474e8 323# define STD_PMMOD_FLAGS_CLEAR(pmfl) \
77c8f263 324 *(pmfl) &= ~(RXf_PMf_FOLD|RXf_PMf_MULTILINE|RXf_PMf_SINGLELINE|RXf_PMf_EXTENDED|RXf_PMf_EXTENDED_MORE|RXf_PMf_CHARSET|RXf_PMf_NOCAPTURE)
fb85c044 325
bcdf7404 326/* chars and strings used as regex pattern modifiers
486ec47a 327 * Singular is a 'c'har, plural is a "string"
87e95b7f
YO
328 *
329 * NOTE, KEEPCOPY was originally 'k', but was changed to 'p' for preserve
330 * for compatibility reasons with Regexp::Common which highjacked (?k:...)
331 * for its own uses. So 'k' is out as well.
bcdf7404 332 */
6c5474e8
KW
333# define DEFAULT_PAT_MOD '^' /* Short for all the default modifiers */
334# define EXEC_PAT_MOD 'e'
335# define KEEPCOPY_PAT_MOD 'p'
336# define NOCAPTURE_PAT_MOD 'n'
337# define ONCE_PAT_MOD 'o'
338# define GLOBAL_PAT_MOD 'g'
339# define CONTINUE_PAT_MOD 'c'
340# define MULTILINE_PAT_MOD 'm'
341# define SINGLE_PAT_MOD 's'
342# define IGNORE_PAT_MOD 'i'
343# define XTENDED_PAT_MOD 'x'
344# define NONDESTRUCT_PAT_MOD 'r'
345# define LOCALE_PAT_MOD 'l'
346# define UNICODE_PAT_MOD 'u'
347# define DEPENDS_PAT_MOD 'd'
348# define ASCII_RESTRICT_PAT_MOD 'a'
349
350# define ONCE_PAT_MODS "o"
351# define KEEPCOPY_PAT_MODS "p"
352# define NOCAPTURE_PAT_MODS "n"
353# define EXEC_PAT_MODS "e"
354# define LOOP_PAT_MODS "gc"
355# define NONDESTRUCT_PAT_MODS "r"
356# define LOCALE_PAT_MODS "l"
357# define UNICODE_PAT_MODS "u"
358# define DEPENDS_PAT_MODS "d"
359# define ASCII_RESTRICT_PAT_MODS "a"
360# define ASCII_MORE_RESTRICT_PAT_MODS "aa"
bcdf7404 361
78fecfc8 362/* This string is expected by regcomp.c to be ordered so that the first
c18d5d15
KW
363 * character is the flag in bit RXf_PMf_STD_PMMOD_SHIFT of extflags; the next
364 * character is bit +1, etc. */
6c5474e8 365# define STD_PAT_MODS "msixxn"
bcdf7404 366
6c5474e8 367# define CHARSET_PAT_MODS ASCII_RESTRICT_PAT_MODS DEPENDS_PAT_MODS LOCALE_PAT_MODS UNICODE_PAT_MODS
94b03d7d 368
78fecfc8 369/* This string is expected by XS_re_regexp_pattern() in universal.c to be ordered
c18d5d15
KW
370 * so that the first character is the flag in bit RXf_PMf_STD_PMMOD_SHIFT of
371 * extflags; the next character is in bit +1, etc. */
6c5474e8 372# define INT_PAT_MODS STD_PAT_MODS KEEPCOPY_PAT_MODS
bcdf7404 373
6c5474e8 374# define EXT_PAT_MODS ONCE_PAT_MODS KEEPCOPY_PAT_MODS NOCAPTURE_PAT_MODS
85900e28 375# define QR_PAT_MODS STD_PAT_MODS EXT_PAT_MODS CHARSET_PAT_MODS
6c5474e8
KW
376# define M_PAT_MODS QR_PAT_MODS LOOP_PAT_MODS
377# define S_PAT_MODS M_PAT_MODS EXEC_PAT_MODS NONDESTRUCT_PAT_MODS
bcdf7404 378
cb5027f2 379/*
eb2624c9
FC
380 * NOTE: if you modify any RXf flags you should run regen.pl or
381 * regen/regcomp.pl so that regnodes.h is updated with the changes.
cb5027f2
YO
382 *
383 */
bcdf7404 384
dbc200c5 385/*
5012eebe
DM
386 Set in Perl_pmruntime for a split. Will be used by regex engines to
387 check whether they should set RXf_SKIPWHITE
dbc200c5 388*/
6c5474e8 389# define RXf_SPLIT RXf_PMf_SPLIT
32f62247 390
0bd51918
KW
391/* Currently the regex flags occupy a single 32-bit word. Not all bits are
392 * currently used. The lower bits are shared with their corresponding PMf flag
393 * bits, up to but not including _RXf_PMf_SHIFT_NEXT. The unused bits
394 * immediately follow; finally the used RXf-only (unshared) bits, so that the
395 * highest bit in the word is used. This gathers all the unused bits as a pool
396 * in the middle, like so: 11111111111111110000001111111111
397 * where the '1's represent used bits, and the '0's unused. This design allows
398 * us to allocate off one end of the pool if we need to add a shared bit, and
399 * off the other end if we need a non-shared bit, without disturbing the other
400 * bits. This maximizes the likelihood of being able to change things without
401 * breaking binary compatibility.
402 *
403 * To add shared bits, do so in op_reg_common.h. This should change
404 * _RXf_PMf_SHIFT_NEXT so that things won't compile. Then come to regexp.h and
405 * op.h and adjust the constant adders in the definitions of RXf_BASE_SHIFT and
406 * Pmf_BASE_SHIFT down by the number of shared bits you added. That's it.
407 * Things should be binary compatible. But if either of these gets to having
408 * to subtract rather than add, leave at 0 and instead adjust all the entries
409 * that are in terms of it. But if the first one of those is already
410 * RXf_BASE_SHIFT+0, there are no bits left, and a redesign is in order.
411 *
412 * To remove unshared bits, just delete its entry. If you're where breaking
413 * binary compatibility is ok to do, you might want to adjust things to move
414 * the newly opened space so that it gets absorbed into the common pool.
415 *
416 * To add unshared bits, first use up any gaps in the middle. Otherwise,
417 * allocate off the low end until you get to RXf_BASE_SHIFT+0. If that isn't
418 * enough, move RXf_BASE_SHIFT down (if possible) and add the new bit at the
419 * other end instead; this preserves binary compatibility.
420 *
421 * For the regexp bits, PL_reg_extflags_name[] in regnodes.h has a comment
422 * giving which bits are used/unused */
423
6c5474e8 424# define RXf_BASE_SHIFT (_RXf_PMf_SHIFT_NEXT + 2)
52d81aa8 425
bbe252da 426/* What we have seen */
6c5474e8 427# define RXf_NO_INPLACE_SUBST (1U<<(RXf_BASE_SHIFT+2))
85900e28 428# define RXf_EVAL_SEEN (1U<<(RXf_BASE_SHIFT+3))
bbe252da
YO
429
430/* Special */
6c5474e8 431# define RXf_UNBOUNDED_QUANTIFIER_SEEN (1U<<(RXf_BASE_SHIFT+4))
85900e28 432# define RXf_CHECK_ALL (1U<<(RXf_BASE_SHIFT+5))
bbe252da
YO
433
434/* UTF8 related */
85900e28 435# define RXf_MATCH_UTF8 (1U<<(RXf_BASE_SHIFT+6)) /* $1 etc are utf8 */
bbe252da
YO
436
437/* Intuit related */
85900e28
YO
438# define RXf_USE_INTUIT_NOML (1U<<(RXf_BASE_SHIFT+7))
439# define RXf_USE_INTUIT_ML (1U<<(RXf_BASE_SHIFT+8))
440# define RXf_INTUIT_TAIL (1U<<(RXf_BASE_SHIFT+9))
6c5474e8 441# define RXf_USE_INTUIT (RXf_USE_INTUIT_NOML|RXf_USE_INTUIT_ML)
bbe252da 442
a3b51d37 443/* Do we have some sort of anchor? */
6c5474e8 444# define RXf_IS_ANCHORED (1U<<(RXf_BASE_SHIFT+10))
a3b51d37 445
bbe252da 446/* Copy and tainted info */
85900e28 447# define RXf_COPY_DONE (1U<<(RXf_BASE_SHIFT+11))
ef07e810 448
1738e041 449/* post-execution: $1 et al are tainted */
85900e28 450# define RXf_TAINTED_SEEN (1U<<(RXf_BASE_SHIFT+12))
ef07e810 451/* this pattern was tainted during compilation */
85900e28 452# define RXf_TAINTED (1U<<(RXf_BASE_SHIFT+13))
52d81aa8
NC
453
454/* Flags indicating special patterns */
6c5474e8
KW
455# define RXf_START_ONLY (1U<<(RXf_BASE_SHIFT+14)) /* Pattern is /^/ */
456# define RXf_SKIPWHITE (1U<<(RXf_BASE_SHIFT+15)) /* Pattern is for a */
9cba692b 457 /* split " " */
85900e28
YO
458# define RXf_WHITE (1U<<(RXf_BASE_SHIFT+16)) /* Pattern is /\s+/ */
459# define RXf_NULL (1U<<(RXf_BASE_SHIFT+17)) /* Pattern is // */
0bd51918
KW
460
461/* See comments at the beginning of these defines about adding bits. The
462 * highest bit position should be used, so that if RXf_BASE_SHIFT gets
463 * increased, the #error below will be triggered so that you will be reminded
464 * to adjust things at the other end to keep the bit positions unchanged */
6c5474e8
KW
465# if RXf_BASE_SHIFT+17 > 31
466# error Too many RXf_PMf bits used. See comments at beginning of these for what to do
467# endif
c737faaf 468
cb5027f2 469/*
eb2624c9
FC
470 * NOTE: if you modify any RXf flags you should run regen.pl or
471 * regen/regcomp.pl so that regnodes.h is updated with the changes.
cb5027f2
YO
472 *
473 */
bbe252da 474
6c5474e8
KW
475# ifdef NO_TAINT_SUPPORT
476# define RX_ISTAINTED(rx_sv) 0
477# define RXp_ISTAINTED(prog) 0
478# define RX_TAINT_on(rx_sv) NOOP
479# define RXp_MATCH_TAINTED(prog) 0
480# define RX_MATCH_TAINTED(rx_sv) 0
481# define RXp_MATCH_TAINTED_on(prog) NOOP
482# define RX_MATCH_TAINTED_on(rx_sv) NOOP
483# define RXp_MATCH_TAINTED_off(prog) NOOP
484# define RX_MATCH_TAINTED_off(rx_sv) NOOP
485# else
486# define RX_ISTAINTED(rx_sv) (RX_EXTFLAGS(rx_sv) & RXf_TAINTED)
487# define RXp_ISTAINTED(prog) (RXp_EXTFLAGS(prog) & RXf_TAINTED)
488# define RX_TAINT_on(rx_sv) (RX_EXTFLAGS(rx_sv) |= RXf_TAINTED)
489# define RXp_MATCH_TAINTED(prog) (RXp_EXTFLAGS(prog) & RXf_TAINTED_SEEN)
490# define RX_MATCH_TAINTED(rx_sv) (RX_EXTFLAGS(rx_sv) & RXf_TAINTED_SEEN)
491# define RXp_MATCH_TAINTED_on(prog) (RXp_EXTFLAGS(prog) |= RXf_TAINTED_SEEN)
492# define RX_MATCH_TAINTED_on(rx_sv) (RX_EXTFLAGS(rx_sv) |= RXf_TAINTED_SEEN)
493# define RXp_MATCH_TAINTED_off(prog) (RXp_EXTFLAGS(prog) &= ~RXf_TAINTED_SEEN)
494# define RX_MATCH_TAINTED_off(rx_sv) (RX_EXTFLAGS(rx_sv) &= ~RXf_TAINTED_SEEN)
495# endif
496
497# define RXp_HAS_CUTGROUP(prog) ((prog)->intflags & PREGf_CUTGROUP_SEEN)
498
499# define RX_MATCH_TAINTED_set(rx_sv, t) ((t) \
a885a8e0
DM
500 ? RX_MATCH_TAINTED_on(rx_sv) \
501 : RX_MATCH_TAINTED_off(rx_sv))
502
6c5474e8
KW
503# define RXp_MATCH_COPIED(prog) (RXp_EXTFLAGS(prog) & RXf_COPY_DONE)
504# define RX_MATCH_COPIED(rx_sv) (RX_EXTFLAGS(rx_sv) & RXf_COPY_DONE)
505# define RXp_MATCH_COPIED_on(prog) (RXp_EXTFLAGS(prog) |= RXf_COPY_DONE)
506# define RX_MATCH_COPIED_on(rx_sv) (RX_EXTFLAGS(rx_sv) |= RXf_COPY_DONE)
507# define RXp_MATCH_COPIED_off(prog) (RXp_EXTFLAGS(prog) &= ~RXf_COPY_DONE)
508# define RX_MATCH_COPIED_off(rx_sv) (RX_EXTFLAGS(rx_sv) &= ~RXf_COPY_DONE)
509# define RX_MATCH_COPIED_set(rx_sv,t) ((t) \
a885a8e0
DM
510 ? RX_MATCH_COPIED_on(rx_sv) \
511 : RX_MATCH_COPIED_off(rx_sv))
512
6c5474e8
KW
513# define RXp_EXTFLAGS(rx) ((rx)->extflags)
514# define RXp_COMPFLAGS(rx) ((rx)->compflags)
866c78d1 515
07bc277f 516/* For source compatibility. We used to store these explicitly. */
6c5474e8 517# define RX_PRECOMP(rx_sv) (RX_WRAPPED(rx_sv) \
a885a8e0 518 + ReANY(rx_sv)->pre_prefix)
6c5474e8 519# define RX_PRECOMP_const(rx_sv) (RX_WRAPPED_const(rx_sv) \
a885a8e0 520 + ReANY(rx_sv)->pre_prefix)
5509d87a
NC
521/* FIXME? Are we hardcoding too much here and constraining plugin extension
522 writers? Specifically, the value 1 assumes that the wrapped version always
523 has exactly one character at the end, a ')'. Will that always be true? */
6c5474e8 524# define RX_PRELEN(rx_sv) (RX_WRAPLEN(rx_sv) \
a885a8e0
DM
525 - ReANY(rx_sv)->pre_prefix - 1)
526
6c5474e8
KW
527# define RX_WRAPPED(rx_sv) SvPVX(rx_sv)
528# define RX_WRAPPED_const(rx_sv) SvPVX_const(rx_sv)
529# define RX_WRAPLEN(rx_sv) SvCUR(rx_sv)
530# define RX_CHECK_SUBSTR(rx_sv) (ReANY(rx_sv)->check_substr)
531# define RX_REFCNT(rx_sv) SvREFCNT(rx_sv)
532# define RX_EXTFLAGS(rx_sv) RXp_EXTFLAGS(ReANY(rx_sv))
533# define RX_COMPFLAGS(rx_sv) RXp_COMPFLAGS(ReANY(rx_sv))
534# define RXp_ENGINE(prog) ((prog)->engine)
535# define RX_ENGINE(rx_sv) (RXp_ENGINE(ReANY(rx_sv)))
536# define RXp_SUBBEG(prog) (prog->subbeg)
537# define RX_SUBBEG(rx_sv) (RXp_SUBBEG(ReANY(rx_sv)))
538# define RXp_SUBOFFSET(prog) (prog->suboffset)
539# define RX_SUBOFFSET(rx_sv) (RXp_SUBOFFSET(ReANY(rx_sv)))
540# define RX_SUBCOFFSET(rx_sv) (ReANY(rx_sv)->subcoffset)
541# define RXp_OFFS(prog) (prog->offs)
542# define RX_OFFS(rx_sv) (RXp_OFFS(ReANY(rx_sv)))
543# define RXp_NPARENS(prog) (prog->nparens)
544# define RX_NPARENS(rx_sv) (RXp_NPARENS(ReANY(rx_sv)))
545# define RX_SUBLEN(rx_sv) (ReANY(rx_sv)->sublen)
546# define RXp_MINLEN(prog) (prog->minlen)
547# define RX_MINLEN(rx_sv) (RXp_MINLEN(ReANY(rx_sv)))
548# define RXp_MINLENRET(prog) (prog->minlenret)
549# define RX_MINLENRET(rx_sv) (RXp_MINLENRET(ReANY(rx_sv)))
550# define RXp_GOFS(prog) (prog->gofs)
551# define RX_GOFS(rx_sv) (RXp_GOFS(ReANY(rx_sv)))
552# define RX_LASTPAREN(rx_sv) (ReANY(rx_sv)->lastparen)
553# define RX_LASTCLOSEPAREN(rx_sv) (ReANY(rx_sv)->lastcloseparen)
554# define RXp_SAVED_COPY(prog) (prog->saved_copy)
555# define RX_SAVED_COPY(rx_sv) (RXp_SAVED_COPY(ReANY(rx_sv)))
03c83e26 556/* last match was zero-length */
6c5474e8 557# define RXp_ZERO_LEN(prog) \
196a02af
DM
558 (RXp_OFFS(prog)[0].start + (SSize_t)RXp_GOFS(prog) \
559 == RXp_OFFS(prog)[0].end)
6c5474e8 560# define RX_ZERO_LEN(rx_sv) (RXp_ZERO_LEN(ReANY(rx_sv)))
220fc49f 561
be8e71aa
YO
562#endif /* PLUGGABLE_RE_EXTENSION */
563
486ec47a 564/* Stuff that needs to be included in the pluggable extension goes below here */
be8e71aa 565
db2c6cb3 566#ifdef PERL_ANY_COW
ffd0ba0c
YO
567# define RXp_MATCH_COPY_FREE(prog) \
568 STMT_START { \
569 if (RXp_SAVED_COPY(prog)) { \
570 SV_CHECK_THINKFIRST_COW_DROP(RXp_SAVED_COPY(prog)); \
571 } \
572 if (RXp_MATCH_COPIED(prog)) { \
573 Safefree(RXp_SUBBEG(prog)); \
574 RXp_MATCH_COPIED_off(prog); \
575 } \
576 } STMT_END
ed252734 577#else
ffd0ba0c
YO
578# define RXp_MATCH_COPY_FREE(prog) \
579 STMT_START { \
580 if (RXp_MATCH_COPIED(prog)) { \
581 Safefree(RXp_SUBBEG(prog)); \
582 RXp_MATCH_COPIED_off(prog); \
583 } \
584 } STMT_END
ed252734 585#endif
a8cb1947 586#define RX_MATCH_COPY_FREE(rx_sv) RXp_MATCH_COPY_FREE(ReANY(rx_sv))
ed252734 587
a885a8e0
DM
588#define RXp_MATCH_UTF8(prog) (RXp_EXTFLAGS(prog) & RXf_MATCH_UTF8)
589#define RX_MATCH_UTF8(rx_sv) (RX_EXTFLAGS(rx_sv) & RXf_MATCH_UTF8)
196a02af 590#define RXp_MATCH_UTF8_on(prog) (RXp_EXTFLAGS(prog) |= RXf_MATCH_UTF8)
97f6857b 591#define RX_MATCH_UTF8_on(rx_sv) (RXp_MATCH_UTF8_on(ReANY(rx_sv)))
196a02af
DM
592#define RXp_MATCH_UTF8_off(prog) (RXp_EXTFLAGS(prog) &= ~RXf_MATCH_UTF8)
593#define RX_MATCH_UTF8_off(rx_sv) (RXp_MATCH_UTF8_off(ReANY(rx_sv))
594#define RXp_MATCH_UTF8_set(prog, t) ((t) \
595 ? RXp_MATCH_UTF8_on(prog) \
596 : RXp_MATCH_UTF8_off(prog))
597#define RX_MATCH_UTF8_set(rx_sv, t) (RXp_MATCH_UTF8_set(ReANY(rx_sv), t))
efd26800
NC
598
599/* Whether the pattern stored at RX_WRAPPED is in UTF-8 */
a885a8e0 600#define RX_UTF8(rx_sv) SvUTF8(rx_sv)
7948fc08 601
a340edde
DM
602
603/* bits in flags arg of Perl_regexec_flags() */
604
605#define REXEC_COPY_STR 0x01 /* Need to copy the string for captures. */
606#define REXEC_CHECKED 0x02 /* re_intuit_start() already called. */
607#define REXEC_SCREAM 0x04 /* currently unused. */
608#define REXEC_IGNOREPOS 0x08 /* use stringarg, not pos(), for \G match */
609#define REXEC_NOT_FIRST 0x10 /* This is another iteration of //g:
610 no need to copy string again */
611
612 /* under REXEC_COPY_STR, it's ok for the
613 engine (modulo PL_sawamperand etc)
614 to skip copying: ... */
615#define REXEC_COPY_SKIP_PRE 0x20 /* ...the $` part of the string, or */
616#define REXEC_COPY_SKIP_POST 0x40 /* ...the $' part of the string */
d5e7783a
DM
617#define REXEC_FAIL_ON_UNDERFLOW 0x80 /* fail the match if $& would start before
618 the start pos (so s/.\G// would fail
619 on second iteration */
c277df42 620
041c1a23 621#if defined(PERL_USE_GCC_BRACE_GROUPS)
85900e28
YO
622# define ReREFCNT_inc(re) \
623 ({ \
624 /* This is here to generate a casting warning if incorrect. */ \
625 REGEXP *const _rerefcnt_inc = (re); \
626 assert(SvTYPE(_rerefcnt_inc) == SVt_REGEXP); \
627 SvREFCNT_inc(_rerefcnt_inc); \
628 _rerefcnt_inc; \
288b8c02 629 })
85900e28
YO
630# define ReREFCNT_dec(re) \
631 ({ \
632 /* This is here to generate a casting warning if incorrect. */ \
633 REGEXP *const _rerefcnt_dec = (re); \
634 SvREFCNT_dec(_rerefcnt_dec); \
288b8c02
NC
635 })
636#else
85900e28
YO
637# define ReREFCNT_dec(re) SvREFCNT_dec(re)
638# define ReREFCNT_inc(re) ((REGEXP *) SvREFCNT_inc(re))
288b8c02 639#endif
85900e28 640#define ReANY(re) Perl_ReANY((const REGEXP *)(re))
288b8c02
NC
641
642/* FIXME for plugins. */
cf93c79d 643
85900e28
YO
644#define FBMcf_TAIL_DOLLAR 1
645#define FBMcf_TAIL_DOLLARM 2
646#define FBMcf_TAIL_Z 4
647#define FBMcf_TAIL_z 8
648#define FBMcf_TAIL (FBMcf_TAIL_DOLLAR|FBMcf_TAIL_DOLLARM|FBMcf_TAIL_Z|FBMcf_TAIL_z)
cf93c79d 649
85900e28 650#define FBMrf_MULTILINE 1
cad2e5aa 651
331b2dcc
DM
652struct regmatch_state;
653struct regmatch_slab;
8adc0f72 654
bf2039a9
DM
655/* like regmatch_info_aux, but contains extra fields only needed if the
656 * pattern contains (?{}). If used, is snuck into the second slot in the
657 * regmatch_state stack at the start of execution */
8adc0f72
DM
658
659typedef struct {
660 regexp *rex;
661 PMOP *curpm; /* saved PL_curpm */
662#ifdef PERL_ANY_COW
663 SV *saved_copy; /* saved saved_copy field from rex */
664#endif
665 char *subbeg; /* saved subbeg field from rex */
666 STRLEN sublen; /* saved sublen field from rex */
667 STRLEN suboffset; /* saved suboffset field from rex */
668 STRLEN subcoffset; /* saved subcoffset field from rex */
1d48e83d 669 SV *sv; /* $_ during (?{}) */
8adc0f72 670 MAGIC *pos_magic; /* pos() magic attached to $_ */
ea3daa5d 671 SSize_t pos; /* the original value of pos() in pos_magic */
25fdce4a 672 U8 pos_flags; /* flags to be restored; currently only MGf_BYTES*/
bf2039a9
DM
673} regmatch_info_aux_eval;
674
675
676/* fields that logically live in regmatch_info, but which need cleaning
677 * up on croak(), and so are instead are snuck into the first slot in
678 * the regmatch_state stack at the start of execution */
679
680typedef struct {
681 regmatch_info_aux_eval *info_aux_eval;
331b2dcc
DM
682 struct regmatch_state *old_regmatch_state; /* saved PL_regmatch_state */
683 struct regmatch_slab *old_regmatch_slab; /* saved PL_regmatch_slab */
85900e28 684 char *poscache; /* S-L cache of fail positions of WHILEMs */
bf2039a9
DM
685} regmatch_info_aux;
686
8adc0f72 687
1f6e74eb
KW
688/*
689=for apidoc Ay||regmatch_info
690Some basic information about the current match that is created by
691Perl_regexec_flags and then passed to regtry(), regmatch() etc.
692It is allocated as a local var on the stack, so nothing should be
693stored in it that needs preserving or clearing up on croak().
694For that, see the aux_info and aux_info_eval members of the
695regmatch_state union.
696
697=cut
698*/
3b0527fe
DM
699
700typedef struct {
28d03b21 701 REGEXP *prog; /* the regex being executed */
9d9163fb 702 const char * strbeg; /* real start of string */
28d03b21
DM
703 char *strend; /* one byte beyond last char of match string */
704 char *till; /* matches shorter than this fail (see minlen arg) */
705 SV *sv; /* the SV string currently being matched */
706 char *ganch; /* position of \G anchor */
707 char *cutpoint; /* (*COMMIT) position (if any) */
bf2039a9
DM
708 regmatch_info_aux *info_aux; /* extra fields that need cleanup */
709 regmatch_info_aux_eval *info_aux_eval; /* extra saved state for (?{}) */
1cb48e53
DM
710 I32 poscache_maxiter; /* how many whilems todo before S-L cache kicks in */
711 I32 poscache_iter; /* current countdown from _maxiter to zero */
2ac8ff4b 712 STRLEN poscache_size; /* size of regmatch_info_aux.poscache */
02d5137b 713 bool intuit; /* re_intuit_start() is the top-level caller */
ba44c216
DM
714 bool is_utf8_pat; /* regex is utf8 */
715 bool is_utf8_target; /* string being matched is utf8 */
39819bd9 716 bool warned; /* we have issued a recursion warning; no need for more */
3b0527fe 717} regmatch_info;
1f4fbd3b 718
5d9a96ca
DM
719
720/* structures for holding and saving the state maintained by regmatch() */
721
d56b3014 722#ifndef MAX_RECURSE_EVAL_NOCHANGE_DEPTH
6c5474e8 723# define MAX_RECURSE_EVAL_NOCHANGE_DEPTH 10
d56b3014 724#endif
6bda09f9 725
52c50ff1
KW
726/* The +1 is because everything matches itself, which isn't included in
727 * MAX_FOLD_FROMS; the +2 is based on the current Unicode standards needs, and
728 * is unlikely to change. An assertion should fail in regexec.c if it is too
729 * low. It is needed for certain edge cases involving multi-character folds
730 * when the first component also participates in a fold individually. */
731#define MAX_MATCHES (MAX_FOLD_FROMS + 1 + 2)
bb382562
KW
732
733struct next_matchable_info {
734 U8 first_byte_mask;
735 U8 first_byte_anded;
736 U32 mask32;
737 U32 anded32;
738 PERL_INT_FAST8_T count; /* Negative means not initialized */
739 PERL_UINT_FAST8_T min_length;
740 PERL_UINT_FAST8_T max_length;
741 PERL_UINT_FAST8_T initial_definitive;
742 PERL_UINT_FAST8_T initial_exact;
743 PERL_UINT_FAST8_T lengths[MAX_MATCHES];
744
745 /* The size is from trial and error, and could change with new Unicode
746 * standards, in which case there is an assertion that should start
747 * failing. This size could be calculated in one of the regen scripts
748 * dealing with Unicode, but khw thinks the likelihood of it changing is
749 * low enough that it isn't worth the effort. */
750 U8 matches[18];
751};
752
5d9a96ca
DM
753typedef I32 CHECKPOINT;
754
a0374537 755typedef struct regmatch_state {
85900e28
YO
756 int resume_state; /* where to jump to on return */
757 char *locinput; /* where to backtrack in string on failure */
fd1dd2eb 758 char *loceol;
8e9f3eef 759 U8 *sr0; /* position of start of script run, or NULL */
e822a8b4
DM
760
761 union {
77cb431f 762
bf2039a9
DM
763 /* the 'info_aux' and 'info_aux_eval' union members are cuckoos in
764 * the nest. They aren't saved backtrack state; rather they
765 * represent one or two extra chunks of data that need allocating
766 * at the start of a match. These fields would logically live in
767 * the regmatch_info struct, except that is allocated on the
768 * C stack, and these fields are all things that require cleanup
769 * after a croak(), when the stack is lost.
770 * As a convenience, we just use the first 1 or 2 regmatch_state
771 * slots to store this info, as we will be allocating a slab of
772 * these anyway. Otherwise we'd have to malloc and then free them,
773 * or allocate them on the save stack (where they will get
774 * realloced if the save stack grows).
775 * info_aux contains the extra fields that are always needed;
776 * info_aux_eval contains extra fields that only needed if
777 * the pattern contains code blocks
778 * We split them into two separate structs to avoid increasing
779 * the size of the union.
780 */
781
782 regmatch_info_aux info_aux;
783
784 regmatch_info_aux_eval info_aux_eval;
785
1f4fbd3b
MS
786 /* this is a fake union member that matches the first element
787 * of each member that needs to store positive backtrack
788 * information */
789 struct {
790 struct regmatch_state *prev_yes_state;
791 } yes;
77cb431f 792
fae667d5
YO
793 /* branchlike members */
794 /* this is a fake union member that matches the first elements
795 * of each member that needs to behave like a branch */
796 struct {
1f4fbd3b
MS
797 /* this first element must match u.yes */
798 struct regmatch_state *prev_yes_state;
799 U32 lastparen;
800 U32 lastcloseparen;
801 CHECKPOINT cp;
802
fae667d5 803 } branchlike;
1f4fbd3b
MS
804
805 struct {
806 /* the first elements must match u.branchlike */
807 struct regmatch_state *prev_yes_state;
808 U32 lastparen;
809 U32 lastcloseparen;
810 CHECKPOINT cp;
811
812 regnode *next_branch; /* next branch node */
813 } branch;
814
815 struct {
816 /* the first elements must match u.branchlike */
817 struct regmatch_state *prev_yes_state;
818 U32 lastparen;
819 U32 lastcloseparen;
820 CHECKPOINT cp;
821
85900e28
YO
822 U32 accepted; /* how many accepting states left */
823 bool longfold;/* saw a fold with a 1->n char mapping */
1f4fbd3b 824 U16 *jump; /* positive offsets from me */
85900e28
YO
825 regnode *me; /* Which node am I - needed for jump tries*/
826 U8 *firstpos;/* pos in string of first trie match */
827 U32 firstchars;/* len in chars of firstpos from start */
828 U16 nextword;/* next word to try */
829 U16 topword; /* longest accepted word */
1f4fbd3b 830 } trie;
e822a8b4 831
fae667d5
YO
832 /* special types - these members are used to store state for special
833 regops like eval, if/then, lookaround and the markpoint state */
1f4fbd3b
MS
834 struct {
835 /* this first element must match u.yes */
836 struct regmatch_state *prev_yes_state;
837 struct regmatch_state *prev_curlyx;
d1c49ad5 838 struct regmatch_state *prev_eval;
85900e28
YO
839 REGEXP *prev_rex;
840 CHECKPOINT cp; /* remember current savestack indexes */
841 CHECKPOINT lastcp;
24be3102 842 U32 close_paren; /* which close bracket is our end (+1) */
85900e28 843 regnode *B; /* the node following us */
ba6840fb 844 char *prev_recurse_locinput;
1f4fbd3b 845 } eval;
e822a8b4 846
1f4fbd3b
MS
847 struct {
848 /* this first element must match u.yes */
849 struct regmatch_state *prev_yes_state;
850 I32 wanted;
85900e28 851 I32 logical; /* saved copy of 'logical' var */
2abbd513
KW
852 U8 count; /* number of beginning positions */
853 char *start;
854 char *end;
1f4fbd3b 855 regnode *me; /* the IFMATCH/SUSPEND/UNLESSM node */
271c3af7 856 char *prev_match_end;
1f4fbd3b
MS
857 } ifmatch; /* and SUSPEND/UNLESSM */
858
859 struct {
860 /* this first element must match u.yes */
861 struct regmatch_state *prev_yes_state;
862 struct regmatch_state *prev_mark;
863 SV* mark_name;
864 char *mark_loc;
865 } mark;
866
867 struct {
868 int val;
869 } keeper;
fae667d5
YO
870
871 /* quantifiers - these members are used for storing state for
a3815e44 872 the regops used to implement quantifiers */
1f4fbd3b
MS
873 struct {
874 /* this first element must match u.yes */
875 struct regmatch_state *prev_yes_state;
876 struct regmatch_state *prev_curlyx; /* previous cur_curlyx */
85900e28
YO
877 regnode *me; /* the CURLYX node */
878 regnode *B; /* the B node in /A*B/ */
879 CHECKPOINT cp; /* remember current savestack index */
880 bool minmod;
881 int parenfloor;/* how far back to strip paren data */
1f4fbd3b
MS
882
883 /* these two are modified by WHILEM */
85900e28
YO
884 int count; /* how many instances of A we've matched */
885 char *lastloc;/* where previous A matched (0-len detect) */
1f4fbd3b
MS
886 } curlyx;
887
888 struct {
889 /* this first element must match u.yes */
890 struct regmatch_state *prev_yes_state;
891 struct regmatch_state *save_curlyx;
85900e28
YO
892 CHECKPOINT cp; /* remember current savestack indexes */
893 CHECKPOINT lastcp;
894 char *save_lastloc; /* previous curlyx.lastloc */
895 I32 cache_offset;
896 I32 cache_mask;
1f4fbd3b
MS
897 } whilem;
898
899 struct {
900 /* this first element must match u.yes */
901 struct regmatch_state *prev_yes_state;
902 CHECKPOINT cp;
903 U32 lastparen;
904 U32 lastcloseparen;
85900e28 905 I32 alen; /* length of first-matched A string */
1f4fbd3b
MS
906 I32 count;
907 bool minmod;
85900e28
YO
908 regnode *A, *B; /* the nodes corresponding to /A*B/ */
909 regnode *me; /* the curlym node */
bb382562 910 struct next_matchable_info Binfo;
1f4fbd3b
MS
911 } curlym;
912
913 struct {
914 U32 paren;
915 CHECKPOINT cp;
916 U32 lastparen;
917 U32 lastcloseparen;
85900e28
YO
918 char *maxpos; /* highest possible point in string to match */
919 char *oldloc; /* the previous locinput */
1f4fbd3b 920 int count;
85900e28
YO
921 int min, max; /* {m,n} */
922 regnode *A, *B; /* the nodes corresponding to /A*B/ */
bb382562 923 struct next_matchable_info Binfo;
1f4fbd3b 924 } curly; /* and CURLYN/PLUS/STAR */
dad79028 925
d8319b27 926 } u;
5d9a96ca
DM
927} regmatch_state;
928
ce12e254 929
d5a00e4a 930
5d9a96ca
DM
931/* how many regmatch_state structs to allocate as a single slab.
932 * We do it in 4K blocks for efficiency. The "3" is 2 for the next/prev
933 * pointers, plus 1 for any mythical malloc overhead. */
1f4fbd3b 934
5d9a96ca
DM
935#define PERL_REGMATCH_SLAB_SLOTS \
936 ((4096 - 3 * sizeof (void*)) / sizeof(regmatch_state))
937
938typedef struct regmatch_slab {
939 regmatch_state states[PERL_REGMATCH_SLAB_SLOTS];
940 struct regmatch_slab *prev, *next;
941} regmatch_slab;
1ade1aa1 942
46ab3289 943
cde0cee5 944
1ade1aa1 945/*
14d04a33 946 * ex: set ts=8 sts=4 sw=4 et:
1ade1aa1 947 */