5 * "A fair jaw-cracker dwarf-language must be." --Samwise Gamgee
8 /* NOTE: this is derived from Henry Spencer's regexp code, and should not
9 * confused with the original package (see point 3 below). Thanks, Henry!
12 /* Additional note: this code is very heavily munged from Henry's version
13 * in places. In some spots I've traded clarity for efficiency, so don't
14 * blame Henry for some of the lack of readability.
17 /* The names of the functions have been changed from regcomp and
18 * regexec to pregcomp and pregexec in order to avoid conflicts
19 * with the POSIX routines of the same names.
22 #ifdef PERL_EXT_RE_BUILD
23 /* need to replace pregcomp et al, so enable that */
24 # ifndef PERL_IN_XSUB_RE
25 # define PERL_IN_XSUB_RE
27 /* need access to debugger hooks */
28 # if defined(PERL_EXT_RE_DEBUG) && !defined(DEBUGGING)
33 #ifdef PERL_IN_XSUB_RE
34 /* We *really* need to overwrite these symbols: */
35 # define Perl_pregcomp my_regcomp
36 # define Perl_regdump my_regdump
37 # define Perl_regprop my_regprop
38 # define Perl_pregfree my_regfree
39 # define Perl_re_intuit_string my_re_intuit_string
40 /* *These* symbols are masked to allow static link. */
41 # define Perl_regnext my_regnext
42 # define Perl_save_re_context my_save_re_context
43 # define Perl_reginitcolors my_reginitcolors
45 # define PERL_NO_GET_CONTEXT
50 * pregcomp and pregexec -- regsub and regerror are not used in perl
52 * Copyright (c) 1986 by University of Toronto.
53 * Written by Henry Spencer. Not derived from licensed software.
55 * Permission is granted to anyone to use this software for any
56 * purpose on any computer system, and to redistribute it freely,
57 * subject to the following restrictions:
59 * 1. The author is not responsible for the consequences of use of
60 * this software, no matter how awful, even if they arise
63 * 2. The origin of this software must not be misrepresented, either
64 * by explicit claim or by omission.
66 * 3. Altered versions must be plainly marked as such, and must not
67 * be misrepresented as being the original software.
70 **** Alterations to Henry's code are...
72 **** Copyright (c) 1991-1999, Larry Wall
74 **** You may distribute under the terms of either the GNU General Public
75 **** License or the Artistic License, as specified in the README file.
78 * Beware that some of this code is subtly aware of the way operator
79 * precedence is structured in regular expressions. Serious changes in
80 * regular-expression syntax might require a total rethink.
83 #define PERL_IN_REGCOMP_C
86 #ifdef PERL_IN_XSUB_RE
87 # if defined(PERL_CAPI) || defined(PERL_OBJECT)
102 # if defined(BUGGY_MSC6)
103 /* MSC 6.00A breaks on op/regexp.t test 85 unless we turn this off */
104 # pragma optimize("a",off)
105 /* But MSC 6.00A is happy with 'w', for aliases only across function calls*/
106 # pragma optimize("w",on )
107 # endif /* BUGGY_MSC6 */
111 #define STATIC static
114 #define ISMULT1(c) ((c) == '*' || (c) == '+' || (c) == '?')
115 #define ISMULT2(s) ((*s) == '*' || (*s) == '+' || (*s) == '?' || \
116 ((*s) == '{' && regcurly(s)))
118 #define PERL_META "^$.[()|?+*\\"
120 #define META "^$.[()|?+*\\"
124 #undef SPSTART /* dratted cpp namespace... */
127 * Flags to be passed up and down.
129 #define WORST 0 /* Worst case. */
130 #define HASWIDTH 0x1 /* Known to match non-null strings. */
131 #define SIMPLE 0x2 /* Simple enough to be STAR/PLUS operand. */
132 #define SPSTART 0x4 /* Starts with * or +. */
133 #define TRYAGAIN 0x8 /* Weeded out a declaration. */
135 /* Length of a variant. */
137 typedef struct scan_data_t {
143 I32 last_end; /* min value, <0 unless valid. */
146 SV **longest; /* Either &l_fixed, or &l_float. */
150 I32 offset_float_min;
151 I32 offset_float_max;
157 * Forward declarations for pregcomp()'s friends.
160 static scan_data_t zero_scan_data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
163 #define SF_BEFORE_EOL (SF_BEFORE_SEOL|SF_BEFORE_MEOL)
164 #define SF_BEFORE_SEOL 0x1
165 #define SF_BEFORE_MEOL 0x2
166 #define SF_FIX_BEFORE_EOL (SF_FIX_BEFORE_SEOL|SF_FIX_BEFORE_MEOL)
167 #define SF_FL_BEFORE_EOL (SF_FL_BEFORE_SEOL|SF_FL_BEFORE_MEOL)
170 # define SF_FIX_SHIFT_EOL (0+2)
171 # define SF_FL_SHIFT_EOL (0+4)
173 # define SF_FIX_SHIFT_EOL (+2)
174 # define SF_FL_SHIFT_EOL (+4)
177 #define SF_FIX_BEFORE_SEOL (SF_BEFORE_SEOL << SF_FIX_SHIFT_EOL)
178 #define SF_FIX_BEFORE_MEOL (SF_BEFORE_MEOL << SF_FIX_SHIFT_EOL)
180 #define SF_FL_BEFORE_SEOL (SF_BEFORE_SEOL << SF_FL_SHIFT_EOL)
181 #define SF_FL_BEFORE_MEOL (SF_BEFORE_MEOL << SF_FL_SHIFT_EOL) /* 0x20 */
182 #define SF_IS_INF 0x40
183 #define SF_HAS_PAR 0x80
184 #define SF_IN_PAR 0x100
185 #define SF_HAS_EVAL 0x200
186 #define SCF_DO_SUBSTR 0x400
189 #define UTF (PL_reg_flags & RF_utf8)
190 #define LOC (PL_regflags & PMf_LOCALE)
191 #define FOLD (PL_regflags & PMf_FOLD)
193 #define OOB_CHAR8 1234
194 #define OOB_UTF8 123456
195 #define OOB_NAMEDCLASS -1
197 #define CHR_SVLEN(sv) (UTF ? sv_len_utf8(sv) : SvCUR(sv))
198 #define CHR_DIST(a,b) (UTF ? utf8_distance(a,b) : a - b)
200 /* Allow for side effects in s */
201 #define REGC(c,s) STMT_START { if (!SIZE_ONLY) *(s) = (c); else (s);} STMT_END
203 static void clear_re(pTHXo_ void *r);
206 S_scan_commit(pTHX_ scan_data_t *data)
209 STRLEN l = CHR_SVLEN(data->last_found);
210 STRLEN old_l = CHR_SVLEN(*data->longest);
212 if ((l >= old_l) && ((l > old_l) || (data->flags & SF_BEFORE_EOL))) {
213 sv_setsv(*data->longest, data->last_found);
214 if (*data->longest == data->longest_fixed) {
215 data->offset_fixed = l ? data->last_start_min : data->pos_min;
216 if (data->flags & SF_BEFORE_EOL)
218 |= ((data->flags & SF_BEFORE_EOL) << SF_FIX_SHIFT_EOL);
220 data->flags &= ~SF_FIX_BEFORE_EOL;
223 data->offset_float_min = l ? data->last_start_min : data->pos_min;
224 data->offset_float_max = (l
225 ? data->last_start_max
226 : data->pos_min + data->pos_delta);
227 if (data->flags & SF_BEFORE_EOL)
229 |= ((data->flags & SF_BEFORE_EOL) << SF_FL_SHIFT_EOL);
231 data->flags &= ~SF_FL_BEFORE_EOL;
234 SvCUR_set(data->last_found, 0);
236 data->flags &= ~SF_BEFORE_EOL;
239 /* Stops at toplevel WHILEM as well as at `last'. At end *scanp is set
240 to the position after last scanned or to NULL. */
243 S_study_chunk(pTHX_ regnode **scanp, I32 *deltap, regnode *last, scan_data_t *data, U32 flags)
244 /* scanp: Start here (read-write). */
245 /* deltap: Write maxlen-minlen here. */
246 /* last: Stop before this one. */
249 I32 min = 0, pars = 0, code;
250 regnode *scan = *scanp, *next;
252 int is_inf = (flags & SCF_DO_SUBSTR) && (data->flags & SF_IS_INF);
253 int is_inf_internal = 0; /* The studied chunk is infinite */
254 I32 is_par = OP(scan) == OPEN ? ARG(scan) : 0;
255 scan_data_t data_fake;
257 while (scan && OP(scan) != END && scan < last) {
258 /* Peephole optimizer: */
260 if (PL_regkind[(U8)OP(scan)] == EXACT) {
261 regnode *n = regnext(scan);
264 regnode *stop = scan;
267 next = scan + NODE_SZ_STR(scan);
268 /* Skip NOTHING, merge EXACT*. */
270 ( PL_regkind[(U8)OP(n)] == NOTHING ||
271 (stringok && (OP(n) == OP(scan))))
273 && NEXT_OFF(scan) + NEXT_OFF(n) < I16_MAX) {
274 if (OP(n) == TAIL || n > next)
276 if (PL_regkind[(U8)OP(n)] == NOTHING) {
277 NEXT_OFF(scan) += NEXT_OFF(n);
278 next = n + NODE_STEP_REGNODE;
286 int oldl = STR_LEN(scan);
287 regnode *nnext = regnext(n);
289 if (oldl + STR_LEN(n) > U8_MAX)
291 NEXT_OFF(scan) += NEXT_OFF(n);
292 STR_LEN(scan) += STR_LEN(n);
293 next = n + NODE_SZ_STR(n);
294 /* Now we can overwrite *n : */
295 Move(STRING(n), STRING(scan) + oldl,
306 n = scan + NODE_SZ_STR(scan);
308 /* Purify reports a benign UMR here sometimes, because we
309 * don't initialize the OP() slot of a node when that node
310 * is occupied by just the trailing null of the string in
312 if (PL_regkind[(U8)OP(n)] != NOTHING || OP(n) == NOTHING) {
321 if (OP(scan) != CURLYX) {
322 int max = (reg_off_by_arg[OP(scan)]
324 /* I32 may be smaller than U16 on CRAYs! */
325 : (I32_MAX < U16_MAX ? I32_MAX : U16_MAX));
326 int off = (reg_off_by_arg[OP(scan)] ? ARG(scan) : NEXT_OFF(scan));
330 /* Skip NOTHING and LONGJMP. */
331 while ((n = regnext(n))
332 && ((PL_regkind[(U8)OP(n)] == NOTHING && (noff = NEXT_OFF(n)))
333 || ((OP(n) == LONGJMP) && (noff = ARG(n))))
336 if (reg_off_by_arg[OP(scan)])
339 NEXT_OFF(scan) = off;
341 if (OP(scan) == BRANCH || OP(scan) == BRANCHJ
342 || OP(scan) == IFTHEN || OP(scan) == SUSPEND) {
343 next = regnext(scan);
346 if (OP(next) == code || code == IFTHEN || code == SUSPEND) {
347 I32 max1 = 0, min1 = I32_MAX, num = 0;
349 if (flags & SCF_DO_SUBSTR)
351 while (OP(scan) == code) {
352 I32 deltanext, minnext;
357 data_fake.whilem_c = data->whilem_c;
358 next = regnext(scan);
359 scan = NEXTOPER(scan);
361 scan = NEXTOPER(scan);
362 /* We suppose the run is continuous, last=next...*/
363 minnext = study_chunk(&scan, &deltanext, next,
367 if (max1 < minnext + deltanext)
368 max1 = minnext + deltanext;
369 if (deltanext == I32_MAX)
370 is_inf = is_inf_internal = 1;
372 if (data_fake.flags & (SF_HAS_PAR|SF_IN_PAR))
374 if (data && (data_fake.flags & SF_HAS_EVAL))
375 data->flags |= SF_HAS_EVAL;
377 data->whilem_c = data_fake.whilem_c;
381 if (code == IFTHEN && num < 2) /* Empty ELSE branch */
383 if (flags & SCF_DO_SUBSTR) {
384 data->pos_min += min1;
385 data->pos_delta += max1 - min1;
386 if (max1 != min1 || is_inf)
387 data->longest = &(data->longest_float);
390 delta += max1 - min1;
392 else if (code == BRANCHJ) /* single branch is optimized. */
393 scan = NEXTOPER(NEXTOPER(scan));
394 else /* single branch is optimized. */
395 scan = NEXTOPER(scan);
398 else if (OP(scan) == EXACT) {
399 I32 l = STR_LEN(scan);
401 unsigned char *s = (unsigned char *)STRING(scan);
402 unsigned char *e = s + l;
411 if (flags & SCF_DO_SUBSTR) { /* Update longest substr. */
412 /* The code below prefers earlier match for fixed
413 offset, later match for variable offset. */
414 if (data->last_end == -1) { /* Update the start info. */
415 data->last_start_min = data->pos_min;
416 data->last_start_max = is_inf
417 ? I32_MAX : data->pos_min + data->pos_delta;
419 sv_catpvn(data->last_found, STRING(scan), STR_LEN(scan));
420 data->last_end = data->pos_min + l;
421 data->pos_min += l; /* As in the first entry. */
422 data->flags &= ~SF_BEFORE_EOL;
425 else if (PL_regkind[(U8)OP(scan)] == EXACT) {
426 I32 l = STR_LEN(scan);
427 if (flags & SCF_DO_SUBSTR)
430 unsigned char *s = (unsigned char *)STRING(scan);
431 unsigned char *e = s + l;
440 if (data && (flags & SCF_DO_SUBSTR))
443 else if (strchr((char*)PL_varies,OP(scan))) {
444 I32 mincount, maxcount, minnext, deltanext, pos_before, fl;
445 regnode *oscan = scan;
447 switch (PL_regkind[(U8)OP(scan)]) {
449 scan = NEXTOPER(scan);
452 if (flags & SCF_DO_SUBSTR) {
453 next = NEXTOPER(scan);
454 if (OP(next) == EXACT) {
456 maxcount = REG_INFTY;
457 next = regnext(scan);
458 scan = NEXTOPER(scan);
462 if (flags & SCF_DO_SUBSTR)
467 is_inf = is_inf_internal = 1;
468 scan = regnext(scan);
469 if (flags & SCF_DO_SUBSTR) {
471 data->longest = &(data->longest_float);
473 goto optimize_curly_tail;
475 mincount = ARG1(scan);
476 maxcount = ARG2(scan);
477 next = regnext(scan);
478 scan = NEXTOPER(scan) + EXTRA_STEP_2ARGS;
480 if (flags & SCF_DO_SUBSTR) {
481 if (mincount == 0) scan_commit(data);
482 pos_before = data->pos_min;
486 data->flags &= ~(SF_HAS_PAR|SF_IN_PAR|SF_HAS_EVAL);
488 data->flags |= SF_IS_INF;
490 /* This will finish on WHILEM, setting scan, or on NULL: */
491 minnext = study_chunk(&scan, &deltanext, last, data,
493 ? (flags & ~SCF_DO_SUBSTR) : flags);
494 if (!scan) /* It was not CURLYX, but CURLY. */
496 if (ckWARN(WARN_UNSAFE) && (minnext + deltanext == 0)
497 && !(data->flags & (SF_HAS_PAR|SF_IN_PAR))
498 && maxcount <= REG_INFTY/3) /* Complement check for big count */
499 Perl_warner(aTHX_ WARN_UNSAFE,
500 "Strange *+?{} on zero-length expression");
501 min += minnext * mincount;
502 is_inf_internal |= (maxcount == REG_INFTY
503 && (minnext + deltanext) > 0
504 || deltanext == I32_MAX);
505 is_inf |= is_inf_internal;
506 delta += (minnext + deltanext) * maxcount - minnext * mincount;
508 /* Try powerful optimization CURLYX => CURLYN. */
509 if ( OP(oscan) == CURLYX && data
510 && data->flags & SF_IN_PAR
511 && !(data->flags & SF_HAS_EVAL)
512 && !deltanext && minnext == 1 ) {
513 /* Try to optimize to CURLYN. */
514 regnode *nxt = NEXTOPER(oscan) + EXTRA_STEP_2ARGS;
515 regnode *nxt1 = nxt, *nxt2;
519 if (!strchr((char*)PL_simple,OP(nxt))
520 && !(PL_regkind[(U8)OP(nxt)] == EXACT
521 && STR_LEN(nxt) == 1))
525 if (OP(nxt) != CLOSE)
527 /* Now we know that nxt2 is the only contents: */
528 oscan->flags = ARG(nxt);
530 OP(nxt1) = NOTHING; /* was OPEN. */
532 OP(nxt1 + 1) = OPTIMIZED; /* was count. */
533 NEXT_OFF(nxt1+ 1) = 0; /* just for consistancy. */
534 NEXT_OFF(nxt2) = 0; /* just for consistancy with CURLY. */
535 OP(nxt) = OPTIMIZED; /* was CLOSE. */
536 OP(nxt + 1) = OPTIMIZED; /* was count. */
537 NEXT_OFF(nxt+ 1) = 0; /* just for consistancy. */
542 /* Try optimization CURLYX => CURLYM. */
543 if ( OP(oscan) == CURLYX && data
544 && !(data->flags & SF_HAS_PAR)
545 && !(data->flags & SF_HAS_EVAL)
547 /* XXXX How to optimize if data == 0? */
548 /* Optimize to a simpler form. */
549 regnode *nxt = NEXTOPER(oscan) + EXTRA_STEP_2ARGS; /* OPEN */
553 while ( (nxt2 = regnext(nxt)) /* skip over embedded stuff*/
554 && (OP(nxt2) != WHILEM))
556 OP(nxt2) = SUCCEED; /* Whas WHILEM */
557 /* Need to optimize away parenths. */
558 if (data->flags & SF_IN_PAR) {
559 /* Set the parenth number. */
560 regnode *nxt1 = NEXTOPER(oscan) + EXTRA_STEP_2ARGS; /* OPEN*/
562 if (OP(nxt) != CLOSE)
563 FAIL("panic opt close");
564 oscan->flags = ARG(nxt);
565 OP(nxt1) = OPTIMIZED; /* was OPEN. */
566 OP(nxt) = OPTIMIZED; /* was CLOSE. */
568 OP(nxt1 + 1) = OPTIMIZED; /* was count. */
569 OP(nxt + 1) = OPTIMIZED; /* was count. */
570 NEXT_OFF(nxt1 + 1) = 0; /* just for consistancy. */
571 NEXT_OFF(nxt + 1) = 0; /* just for consistancy. */
574 while ( nxt1 && (OP(nxt1) != WHILEM)) {
575 regnode *nnxt = regnext(nxt1);
578 if (reg_off_by_arg[OP(nxt1)])
579 ARG_SET(nxt1, nxt2 - nxt1);
580 else if (nxt2 - nxt1 < U16_MAX)
581 NEXT_OFF(nxt1) = nxt2 - nxt1;
583 OP(nxt) = NOTHING; /* Cannot beautify */
588 /* Optimize again: */
589 study_chunk(&nxt1, &deltanext, nxt, NULL, 0);
594 else if (OP(oscan) == CURLYX && data && ++data->whilem_c < 16) {
595 /* This stays as CURLYX, and can put the count/of pair. */
596 /* Find WHILEM (as in regexec.c) */
597 regnode *nxt = oscan + NEXT_OFF(oscan);
599 if (OP(PREVOPER(nxt)) == NOTHING) /* LONGJMP */
601 PREVOPER(nxt)->flags = data->whilem_c
602 | (PL_reg_whilem_seen << 4); /* On WHILEM */
604 if (data && fl & (SF_HAS_PAR|SF_IN_PAR))
606 if (flags & SCF_DO_SUBSTR) {
607 SV *last_str = Nullsv;
608 int counted = mincount != 0;
610 if (data->last_end > 0 && mincount != 0) { /* Ends with a string. */
611 I32 b = pos_before >= data->last_start_min
612 ? pos_before : data->last_start_min;
614 char *s = SvPV(data->last_found, l);
615 I32 old = b - data->last_start_min;
618 old = utf8_hop((U8*)s, old) - (U8*)s;
621 /* Get the added string: */
622 last_str = newSVpvn(s + old, l);
623 if (deltanext == 0 && pos_before == b) {
624 /* What was added is a constant string */
626 SvGROW(last_str, (mincount * l) + 1);
627 repeatcpy(SvPVX(last_str) + l,
628 SvPVX(last_str), l, mincount - 1);
629 SvCUR(last_str) *= mincount;
630 /* Add additional parts. */
631 SvCUR_set(data->last_found,
632 SvCUR(data->last_found) - l);
633 sv_catsv(data->last_found, last_str);
634 data->last_end += l * (mincount - 1);
638 /* It is counted once already... */
639 data->pos_min += minnext * (mincount - counted);
640 data->pos_delta += - counted * deltanext +
641 (minnext + deltanext) * maxcount - minnext * mincount;
642 if (mincount != maxcount) {
644 if (mincount && last_str) {
645 sv_setsv(data->last_found, last_str);
646 data->last_end = data->pos_min;
647 data->last_start_min =
648 data->pos_min - CHR_SVLEN(last_str);
649 data->last_start_max = is_inf
651 : data->pos_min + data->pos_delta
652 - CHR_SVLEN(last_str);
654 data->longest = &(data->longest_float);
656 SvREFCNT_dec(last_str);
658 if (data && (fl & SF_HAS_EVAL))
659 data->flags |= SF_HAS_EVAL;
661 if (OP(oscan) != CURLYX) {
662 while (PL_regkind[(U8)OP(next = regnext(oscan))] == NOTHING
664 NEXT_OFF(oscan) += NEXT_OFF(next);
667 default: /* REF only? */
668 if (flags & SCF_DO_SUBSTR) {
670 data->longest = &(data->longest_float);
672 is_inf = is_inf_internal = 1;
676 else if (strchr((char*)PL_simple,OP(scan)) || PL_regkind[(U8)OP(scan)] == ANYUTF8) {
677 if (flags & SCF_DO_SUBSTR) {
683 else if (PL_regkind[(U8)OP(scan)] == EOL && flags & SCF_DO_SUBSTR) {
684 data->flags |= (OP(scan) == MEOL
688 else if (PL_regkind[(U8)OP(scan)] == BRANCHJ
689 && (scan->flags || data)
690 && (OP(scan) == IFMATCH || OP(scan) == UNLESSM)) {
691 I32 deltanext, minnext;
696 data_fake.whilem_c = data->whilem_c;
697 next = regnext(scan);
698 nscan = NEXTOPER(NEXTOPER(scan));
699 minnext = study_chunk(&nscan, &deltanext, last, &data_fake, 0);
702 FAIL("variable length lookbehind not implemented");
704 else if (minnext > U8_MAX) {
705 FAIL2("lookbehind longer than %"UVuf" not implemented", (UV)U8_MAX);
707 scan->flags = minnext;
709 if (data && data_fake.flags & (SF_HAS_PAR|SF_IN_PAR))
711 if (data && (data_fake.flags & SF_HAS_EVAL))
712 data->flags |= SF_HAS_EVAL;
714 data->whilem_c = data_fake.whilem_c;
716 else if (OP(scan) == OPEN) {
719 else if (OP(scan) == CLOSE && ARG(scan) == is_par) {
720 next = regnext(scan);
722 if ( next && (OP(next) != WHILEM) && next < last)
723 is_par = 0; /* Disable optimization */
725 else if (OP(scan) == EVAL) {
727 data->flags |= SF_HAS_EVAL;
729 else if (OP(scan) == LOGICAL && scan->flags == 2) { /* Embedded */
730 if (flags & SCF_DO_SUBSTR) {
732 data->longest = &(data->longest_float);
734 is_inf = is_inf_internal = 1;
736 /* Else: zero-length, ignore. */
737 scan = regnext(scan);
742 *deltap = is_inf_internal ? I32_MAX : delta;
743 if (flags & SCF_DO_SUBSTR && is_inf)
744 data->pos_delta = I32_MAX - data->pos_min;
747 if (is_par && pars==1 && data) {
748 data->flags |= SF_IN_PAR;
749 data->flags &= ~SF_HAS_PAR;
751 else if (pars && data) {
752 data->flags |= SF_HAS_PAR;
753 data->flags &= ~SF_IN_PAR;
759 S_add_data(pTHX_ I32 n, char *s)
762 if (PL_regcomp_rx->data) {
763 Renewc(PL_regcomp_rx->data,
764 sizeof(*PL_regcomp_rx->data) + sizeof(void*) * (PL_regcomp_rx->data->count + n - 1),
765 char, struct reg_data);
766 Renew(PL_regcomp_rx->data->what, PL_regcomp_rx->data->count + n, U8);
767 PL_regcomp_rx->data->count += n;
770 Newc(1207, PL_regcomp_rx->data, sizeof(*PL_regcomp_rx->data) + sizeof(void*) * (n - 1),
771 char, struct reg_data);
772 New(1208, PL_regcomp_rx->data->what, n, U8);
773 PL_regcomp_rx->data->count = n;
775 Copy(s, PL_regcomp_rx->data->what + PL_regcomp_rx->data->count - n, n, U8);
776 return PL_regcomp_rx->data->count - n;
780 Perl_reginitcolors(pTHX)
784 char *s = PerlEnv_getenv("PERL_RE_COLORS");
787 PL_colors[0] = s = savepv(s);
795 PL_colors[i] = s = "";
805 - pregcomp - compile a regular expression into internal code
807 * We can't allocate space until we know how big the compiled form will be,
808 * but we can't compile it (and thus know how big it is) until we've got a
809 * place to put the code. So we cheat: we compile it twice, once with code
810 * generation turned off and size counting turned on, and once "for real".
811 * This also means that we don't allocate space until we are sure that the
812 * thing really will compile successfully, and we never have to move the
813 * code and thus invalidate pointers into it. (Note that it has to be in
814 * one piece because free() must be able to free it all.) [NB: not true in perl]
816 * Beware that the optimization-preparation code in here knows about some
817 * of the structure of the compiled regexp. [I'll say.]
820 Perl_pregcomp(pTHX_ char *exp, char *xend, PMOP *pm)
836 FAIL("NULL regexp argument");
838 if (PL_curcop == &PL_compiling ? (PL_hints & HINT_UTF8) : IN_UTF8)
839 PL_reg_flags |= RF_utf8;
843 PL_regprecomp = savepvn(exp, xend - exp);
844 DEBUG_r(if (!PL_colorset) reginitcolors());
845 DEBUG_r(PerlIO_printf(Perl_debug_log, "%sCompiling REx%s `%s%*s%s'\n",
846 PL_colors[4],PL_colors[5],PL_colors[0],
847 (int)(xend - exp), PL_regprecomp, PL_colors[1]));
848 PL_regflags = pm->op_pmflags;
852 PL_seen_zerolen = *exp == '^' ? -1 : 0;
856 /* First pass: determine size, legality. */
857 PL_regcomp_parse = exp;
862 PL_regcode = &PL_regdummy;
863 PL_reg_whilem_seen = 0;
864 REGC((U8)REG_MAGIC, (char*)PL_regcode);
865 if (reg(0, &flags) == NULL) {
866 Safefree(PL_regprecomp);
867 PL_regprecomp = Nullch;
870 DEBUG_r(PerlIO_printf(Perl_debug_log, "size %"IVdf" ", (IV)PL_regsize));
872 /* Small enough for pointer-storage convention?
873 If extralen==0, this means that we will not need long jumps. */
874 if (PL_regsize >= 0x10000L && PL_extralen)
875 PL_regsize += PL_extralen;
878 if (PL_reg_whilem_seen > 15)
879 PL_reg_whilem_seen = 15;
881 /* Allocate space and initialize. */
882 Newc(1001, r, sizeof(regexp) + (unsigned)PL_regsize * sizeof(regnode),
885 FAIL("regexp out of space");
887 r->prelen = xend - exp;
888 r->precomp = PL_regprecomp;
890 r->reganch = pm->op_pmflags & PMf_COMPILETIME;
891 r->nparens = PL_regnpar - 1; /* set early to validate backrefs */
893 r->substrs = 0; /* Useful during FAIL. */
894 r->startp = 0; /* Useful during FAIL. */
895 r->endp = 0; /* Useful during FAIL. */
899 /* Second pass: emit code. */
900 PL_regcomp_parse = exp;
904 PL_regcode = r->program;
905 /* Store the count of eval-groups for security checks: */
906 PL_regcode->next_off = ((PL_seen_evals > U16_MAX) ? U16_MAX : PL_seen_evals);
907 REGC((U8)REG_MAGIC, (char*) PL_regcode++);
909 if (reg(0, &flags) == NULL)
912 /* Dig out information for optimizations. */
913 r->reganch = pm->op_pmflags & PMf_COMPILETIME; /* Again? */
914 pm->op_pmflags = PL_regflags;
916 r->reganch |= ROPT_UTF8;
917 r->regstclass = NULL;
918 if (PL_regnaughty >= 10) /* Probably an expensive pattern. */
919 r->reganch |= ROPT_NAUGHTY;
920 scan = r->program + 1; /* First BRANCH. */
922 /* XXXX To minimize changes to RE engine we always allocate
923 3-units-long substrs field. */
924 Newz(1004, r->substrs, 1, struct reg_substr_data);
926 StructCopy(&zero_scan_data, &data, scan_data_t);
927 if (OP(scan) != BRANCH) { /* Only one top-level choice. */
929 STRLEN longest_float_length, longest_fixed_length;
932 /* Skip introductions and multiplicators >= 1. */
933 while ((OP(first) == OPEN && (sawopen = 1)) ||
934 (OP(first) == BRANCH && OP(regnext(first)) != BRANCH) ||
935 (OP(first) == PLUS) ||
936 (OP(first) == MINMOD) ||
937 (PL_regkind[(U8)OP(first)] == CURLY && ARG1(first) > 0) ) {
938 if (OP(first) == PLUS)
941 first += regarglen[(U8)OP(first)];
942 first = NEXTOPER(first);
945 /* Starting-point info. */
947 if (PL_regkind[(U8)OP(first) == EXACT]) {
948 if (OP(first) == EXACT); /* Empty, get anchored substr later. */
949 else if ((OP(first) == EXACTF || OP(first) == EXACTFL)
951 r->regstclass = first;
953 else if (strchr((char*)PL_simple+4,OP(first)))
954 r->regstclass = first;
955 else if (PL_regkind[(U8)OP(first)] == BOUND ||
956 PL_regkind[(U8)OP(first)] == NBOUND)
957 r->regstclass = first;
958 else if (PL_regkind[(U8)OP(first)] == BOL) {
959 r->reganch |= (OP(first) == MBOL
964 first = NEXTOPER(first);
967 else if (OP(first) == GPOS) {
968 r->reganch |= ROPT_ANCH_GPOS;
969 first = NEXTOPER(first);
972 else if ((OP(first) == STAR &&
973 PL_regkind[(U8)OP(NEXTOPER(first))] == REG_ANY) &&
974 !(r->reganch & ROPT_ANCH) )
976 /* turn .* into ^.* with an implied $*=1 */
977 int type = OP(NEXTOPER(first));
979 if (type == REG_ANY || type == ANYUTF8)
980 type = ROPT_ANCH_MBOL;
982 type = ROPT_ANCH_SBOL;
984 r->reganch |= type | ROPT_IMPLICIT;
985 first = NEXTOPER(first);
988 if (sawplus && (!sawopen || !PL_regsawback)
989 && !(PL_regseen & REG_SEEN_EVAL)) /* May examine pos and $& */
990 /* x+ must match at the 1st pos of run of x's */
991 r->reganch |= ROPT_SKIP;
993 /* Scan is after the zeroth branch, first is atomic matcher. */
994 DEBUG_r(PerlIO_printf(Perl_debug_log, "first at %"IVdf"\n",
995 (IV)(first - scan + 1)));
997 * If there's something expensive in the r.e., find the
998 * longest literal string that must appear and make it the
999 * regmust. Resolve ties in favor of later strings, since
1000 * the regstart check works with the beginning of the r.e.
1001 * and avoiding duplication strengthens checking. Not a
1002 * strong reason, but sufficient in the absence of others.
1003 * [Now we resolve ties in favor of the earlier string if
1004 * it happens that c_offset_min has been invalidated, since the
1005 * earlier string may buy us something the later one won't.]
1009 data.longest_fixed = newSVpvn("",0);
1010 data.longest_float = newSVpvn("",0);
1011 data.last_found = newSVpvn("",0);
1012 data.longest = &(data.longest_fixed);
1015 minlen = study_chunk(&first, &fake, scan + PL_regsize, /* Up to end */
1016 &data, SCF_DO_SUBSTR);
1017 if ( PL_regnpar == 1 && data.longest == &(data.longest_fixed)
1018 && data.last_start_min == 0 && data.last_end > 0
1020 && (!(PL_regseen & REG_SEEN_GPOS) || (r->reganch & ROPT_ANCH_GPOS)))
1021 r->reganch |= ROPT_CHECK_ALL;
1023 SvREFCNT_dec(data.last_found);
1025 longest_float_length = CHR_SVLEN(data.longest_float);
1026 if (longest_float_length
1027 || (data.flags & SF_FL_BEFORE_EOL
1028 && (!(data.flags & SF_FL_BEFORE_MEOL)
1029 || (PL_regflags & PMf_MULTILINE)))) {
1032 if (SvCUR(data.longest_fixed) /* ok to leave SvCUR */
1033 && data.offset_fixed == data.offset_float_min
1034 && SvCUR(data.longest_fixed) == SvCUR(data.longest_float))
1035 goto remove_float; /* As in (a)+. */
1037 r->float_substr = data.longest_float;
1038 r->float_min_offset = data.offset_float_min;
1039 r->float_max_offset = data.offset_float_max;
1040 t = (data.flags & SF_FL_BEFORE_EOL /* Can't have SEOL and MULTI */
1041 && (!(data.flags & SF_FL_BEFORE_MEOL)
1042 || (PL_regflags & PMf_MULTILINE)));
1043 fbm_compile(r->float_substr, t ? FBMcf_TAIL : 0);
1047 r->float_substr = Nullsv;
1048 SvREFCNT_dec(data.longest_float);
1049 longest_float_length = 0;
1052 longest_fixed_length = CHR_SVLEN(data.longest_fixed);
1053 if (longest_fixed_length
1054 || (data.flags & SF_FIX_BEFORE_EOL /* Cannot have SEOL and MULTI */
1055 && (!(data.flags & SF_FIX_BEFORE_MEOL)
1056 || (PL_regflags & PMf_MULTILINE)))) {
1059 r->anchored_substr = data.longest_fixed;
1060 r->anchored_offset = data.offset_fixed;
1061 t = (data.flags & SF_FIX_BEFORE_EOL /* Can't have SEOL and MULTI */
1062 && (!(data.flags & SF_FIX_BEFORE_MEOL)
1063 || (PL_regflags & PMf_MULTILINE)));
1064 fbm_compile(r->anchored_substr, t ? FBMcf_TAIL : 0);
1067 r->anchored_substr = Nullsv;
1068 SvREFCNT_dec(data.longest_fixed);
1069 longest_fixed_length = 0;
1072 /* A temporary algorithm prefers floated substr to fixed one to dig more info. */
1073 if (longest_fixed_length > longest_float_length) {
1074 r->check_substr = r->anchored_substr;
1075 r->check_offset_min = r->check_offset_max = r->anchored_offset;
1076 if (r->reganch & ROPT_ANCH_SINGLE)
1077 r->reganch |= ROPT_NOSCAN;
1080 r->check_substr = r->float_substr;
1081 r->check_offset_min = data.offset_float_min;
1082 r->check_offset_max = data.offset_float_max;
1084 /* XXXX Currently intuiting is not compatible with ANCH_GPOS.
1085 This should be changed ASAP! */
1086 if (r->check_substr && !(r->reganch & ROPT_ANCH_GPOS)) {
1087 r->reganch |= RE_USE_INTUIT;
1088 if (SvTAIL(r->check_substr))
1089 r->reganch |= RE_INTUIT_TAIL;
1093 /* Several toplevels. Best we can is to set minlen. */
1096 DEBUG_r(PerlIO_printf(Perl_debug_log, "\n"));
1097 scan = r->program + 1;
1098 minlen = study_chunk(&scan, &fake, scan + PL_regsize, &data, 0);
1099 r->check_substr = r->anchored_substr = r->float_substr = Nullsv;
1103 if (PL_regseen & REG_SEEN_GPOS)
1104 r->reganch |= ROPT_GPOS_SEEN;
1105 if (PL_regseen & REG_SEEN_LOOKBEHIND)
1106 r->reganch |= ROPT_LOOKBEHIND_SEEN;
1107 if (PL_regseen & REG_SEEN_EVAL)
1108 r->reganch |= ROPT_EVAL_SEEN;
1109 Newz(1002, r->startp, PL_regnpar, I32);
1110 Newz(1002, r->endp, PL_regnpar, I32);
1111 DEBUG_r(regdump(r));
1116 - reg - regular expression, i.e. main body or parenthesized thing
1118 * Caller must absorb opening parenthesis.
1120 * Combining parenthesis handling with the base level of regular expression
1121 * is a trifle forced, but the need to tie the tails of the branches to what
1122 * follows makes it hard to avoid.
1125 S_reg(pTHX_ I32 paren, I32 *flagp)
1126 /* paren: Parenthesized? 0=top, 1=(, inside: changed to letter. */
1129 register regnode *ret; /* Will be the head of the group. */
1130 register regnode *br;
1131 register regnode *lastbr;
1132 register regnode *ender = 0;
1133 register I32 parno = 0;
1134 I32 flags, oregflags = PL_regflags, have_branch = 0, open = 0;
1137 *flagp = 0; /* Tentatively. */
1139 /* Make an OPEN node, if parenthesized. */
1141 if (*PL_regcomp_parse == '?') {
1142 U16 posflags = 0, negflags = 0;
1143 U16 *flagsp = &posflags;
1147 paren = *PL_regcomp_parse++;
1148 ret = NULL; /* For look-ahead/behind. */
1151 PL_regseen |= REG_SEEN_LOOKBEHIND;
1152 if (*PL_regcomp_parse == '!')
1154 if (*PL_regcomp_parse != '=' && *PL_regcomp_parse != '!')
1165 FAIL2("Sequence (?%c...) not implemented", (int)paren);
1168 while (*PL_regcomp_parse && *PL_regcomp_parse != ')')
1170 if (*PL_regcomp_parse != ')')
1171 FAIL("Sequence (?#... not terminated");
1177 paren = *PL_regcomp_parse++;
1182 I32 count = 1, n = 0;
1184 char *s = PL_regcomp_parse;
1186 OP_4tree *sop, *rop;
1189 PL_regseen |= REG_SEEN_EVAL;
1190 while (count && (c = *PL_regcomp_parse)) {
1191 if (c == '\\' && PL_regcomp_parse[1])
1199 if (*PL_regcomp_parse != ')')
1200 FAIL("Sequence (?{...}) not terminated or not {}-balanced");
1204 if (PL_regcomp_parse - 1 - s)
1205 sv = newSVpvn(s, PL_regcomp_parse - 1 - s);
1207 sv = newSVpvn("", 0);
1209 rop = sv_compile_2op(sv, &sop, "re", &av);
1211 n = add_data(3, "nop");
1212 PL_regcomp_rx->data->data[n] = (void*)rop;
1213 PL_regcomp_rx->data->data[n+1] = (void*)sop;
1214 PL_regcomp_rx->data->data[n+2] = (void*)av;
1217 else { /* First pass */
1218 if (PL_reginterp_cnt < ++PL_seen_evals
1219 && PL_curcop != &PL_compiling)
1220 /* No compiled RE interpolated, has runtime
1221 components ===> unsafe. */
1222 FAIL("Eval-group not allowed at runtime, use re 'eval'");
1224 FAIL("Eval-group in insecure regular expression");
1229 ret = reg_node(LOGICAL);
1232 regtail(ret, reganode(EVAL, n));
1235 return reganode(EVAL, n);
1239 if (PL_regcomp_parse[0] == '?') {
1240 if (PL_regcomp_parse[1] == '=' || PL_regcomp_parse[1] == '!'
1241 || PL_regcomp_parse[1] == '<'
1242 || PL_regcomp_parse[1] == '{') { /* Lookahead or eval. */
1245 ret = reg_node(LOGICAL);
1248 regtail(ret, reg(1, &flag));
1252 else if (PL_regcomp_parse[0] >= '1' && PL_regcomp_parse[0] <= '9' ) {
1253 parno = atoi(PL_regcomp_parse++);
1255 while (isDIGIT(*PL_regcomp_parse))
1257 ret = reganode(GROUPP, parno);
1258 if ((c = *nextchar()) != ')')
1259 FAIL2("Switch (?(number%c not recognized", c);
1261 regtail(ret, reganode(IFTHEN, 0));
1262 br = regbranch(&flags, 1);
1264 br = reganode(LONGJMP, 0);
1266 regtail(br, reganode(LONGJMP, 0));
1271 lastbr = reganode(IFTHEN, 0); /* Fake one for optimizer. */
1272 regbranch(&flags, 1);
1273 regtail(ret, lastbr);
1281 FAIL("Switch (?(condition)... contains too many branches");
1282 ender = reg_node(TAIL);
1285 regtail(lastbr, ender);
1286 regtail(NEXTOPER(NEXTOPER(lastbr)), ender);
1289 regtail(ret, ender);
1293 FAIL2("Unknown condition for (?(%.2s", PL_regcomp_parse);
1297 FAIL("Sequence (? incomplete");
1302 while (*PL_regcomp_parse && strchr("iogcmsx", *PL_regcomp_parse)) {
1303 if (*PL_regcomp_parse != 'o')
1304 pmflag(flagsp, *PL_regcomp_parse);
1307 if (*PL_regcomp_parse == '-') {
1312 PL_regflags |= posflags;
1313 PL_regflags &= ~negflags;
1314 if (*PL_regcomp_parse == ':') {
1320 if (*PL_regcomp_parse != ')')
1321 FAIL2("Sequence (?%c...) not recognized", *PL_regcomp_parse);
1330 ret = reganode(OPEN, parno);
1337 /* Pick up the branches, linking them together. */
1338 br = regbranch(&flags, 1);
1341 if (*PL_regcomp_parse == '|') {
1342 if (!SIZE_ONLY && PL_extralen) {
1343 reginsert(BRANCHJ, br);
1346 reginsert(BRANCH, br);
1349 PL_extralen += 1; /* For BRANCHJ-BRANCH. */
1351 else if (paren == ':') {
1352 *flagp |= flags&SIMPLE;
1354 if (open) { /* Starts with OPEN. */
1355 regtail(ret, br); /* OPEN -> first. */
1357 else if (paren != '?') /* Not Conditional */
1361 *flagp |= flags&SPSTART;
1363 while (*PL_regcomp_parse == '|') {
1364 if (!SIZE_ONLY && PL_extralen) {
1365 ender = reganode(LONGJMP,0);
1366 regtail(NEXTOPER(NEXTOPER(lastbr)), ender); /* Append to the previous. */
1369 PL_extralen += 2; /* Account for LONGJMP. */
1371 br = regbranch(&flags, 0);
1374 regtail(lastbr, br); /* BRANCH -> BRANCH. */
1378 *flagp |= flags&SPSTART;
1381 if (have_branch || paren != ':') {
1382 /* Make a closing node, and hook it on the end. */
1385 ender = reg_node(TAIL);
1388 ender = reganode(CLOSE, parno);
1394 *flagp &= ~HASWIDTH;
1397 ender = reg_node(SUCCEED);
1400 ender = reg_node(END);
1403 regtail(lastbr, ender);
1406 /* Hook the tails of the branches to the closing node. */
1407 for (br = ret; br != NULL; br = regnext(br)) {
1408 regoptail(br, ender);
1415 static char parens[] = "=!<,>";
1417 if (paren && (p = strchr(parens, paren))) {
1418 int node = ((p - parens) % 2) ? UNLESSM : IFMATCH;
1419 int flag = (p - parens) > 1;
1422 node = SUSPEND, flag = 0;
1423 reginsert(node,ret);
1425 regtail(ret, reg_node(TAIL));
1429 /* Check for proper termination. */
1431 PL_regflags = oregflags;
1432 if (PL_regcomp_parse >= PL_regxend || *nextchar() != ')') {
1433 FAIL("unmatched () in regexp");
1436 else if (!paren && PL_regcomp_parse < PL_regxend) {
1437 if (*PL_regcomp_parse == ')') {
1438 FAIL("unmatched () in regexp");
1441 FAIL("junk on end of regexp"); /* "Can't happen". */
1449 - regbranch - one alternative of an | operator
1451 * Implements the concatenation operator.
1454 S_regbranch(pTHX_ I32 *flagp, I32 first)
1457 register regnode *ret;
1458 register regnode *chain = NULL;
1459 register regnode *latest;
1460 I32 flags = 0, c = 0;
1465 if (!SIZE_ONLY && PL_extralen)
1466 ret = reganode(BRANCHJ,0);
1468 ret = reg_node(BRANCH);
1471 if (!first && SIZE_ONLY)
1472 PL_extralen += 1; /* BRANCHJ */
1474 *flagp = WORST; /* Tentatively. */
1478 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != '|' && *PL_regcomp_parse != ')') {
1480 latest = regpiece(&flags);
1481 if (latest == NULL) {
1482 if (flags & TRYAGAIN)
1486 else if (ret == NULL)
1488 *flagp |= flags&HASWIDTH;
1489 if (chain == NULL) /* First piece. */
1490 *flagp |= flags&SPSTART;
1493 regtail(chain, latest);
1498 if (chain == NULL) { /* Loop ran zero times. */
1499 chain = reg_node(NOTHING);
1504 *flagp |= flags&SIMPLE;
1511 - regpiece - something followed by possible [*+?]
1513 * Note that the branching code sequences used for ? and the general cases
1514 * of * and + are somewhat optimized: they use the same NOTHING node as
1515 * both the endmarker for their branch list and the body of the last branch.
1516 * It might seem that this node could be dispensed with entirely, but the
1517 * endmarker role is not redundant.
1520 S_regpiece(pTHX_ I32 *flagp)
1523 register regnode *ret;
1525 register char *next;
1527 char *origparse = PL_regcomp_parse;
1530 I32 max = REG_INFTY;
1532 ret = regatom(&flags);
1534 if (flags & TRYAGAIN)
1539 op = *PL_regcomp_parse;
1541 if (op == '{' && regcurly(PL_regcomp_parse)) {
1542 next = PL_regcomp_parse + 1;
1544 while (isDIGIT(*next) || *next == ',') {
1553 if (*next == '}') { /* got one */
1557 min = atoi(PL_regcomp_parse);
1561 maxpos = PL_regcomp_parse;
1563 if (!max && *maxpos != '0')
1564 max = REG_INFTY; /* meaning "infinity" */
1565 else if (max >= REG_INFTY)
1566 FAIL2("Quantifier in {,} bigger than %d", REG_INFTY - 1);
1567 PL_regcomp_parse = next;
1571 if ((flags&SIMPLE)) {
1572 PL_regnaughty += 2 + PL_regnaughty / 2;
1573 reginsert(CURLY, ret);
1576 regnode *w = reg_node(WHILEM);
1580 if (!SIZE_ONLY && PL_extralen) {
1581 reginsert(LONGJMP,ret);
1582 reginsert(NOTHING,ret);
1583 NEXT_OFF(ret) = 3; /* Go over LONGJMP. */
1585 reginsert(CURLYX,ret);
1586 if (!SIZE_ONLY && PL_extralen)
1587 NEXT_OFF(ret) = 3; /* Go over NOTHING to LONGJMP. */
1588 regtail(ret, reg_node(NOTHING));
1590 PL_reg_whilem_seen++, PL_extralen += 3;
1591 PL_regnaughty += 4 + PL_regnaughty; /* compound interest */
1599 if (max && max < min)
1600 FAIL("Can't do {n,m} with n > m");
1615 #if 0 /* Now runtime fix should be reliable. */
1616 if (!(flags&HASWIDTH) && op != '?')
1617 FAIL("regexp *+ operand could be empty");
1622 *flagp = (op != '+') ? (WORST|SPSTART|HASWIDTH) : (WORST|HASWIDTH);
1624 if (op == '*' && (flags&SIMPLE)) {
1625 reginsert(STAR, ret);
1629 else if (op == '*') {
1633 else if (op == '+' && (flags&SIMPLE)) {
1634 reginsert(PLUS, ret);
1638 else if (op == '+') {
1642 else if (op == '?') {
1647 if (ckWARN(WARN_UNSAFE) && !SIZE_ONLY && !(flags&HASWIDTH) && max > REG_INFTY/3) {
1648 Perl_warner(aTHX_ WARN_UNSAFE, "%.*s matches null string many times",
1649 PL_regcomp_parse - origparse, origparse);
1652 if (*PL_regcomp_parse == '?') {
1654 reginsert(MINMOD, ret);
1655 regtail(ret, ret + NODE_STEP_REGNODE);
1657 if (ISMULT2(PL_regcomp_parse))
1658 FAIL("nested *?+ in regexp");
1664 - regatom - the lowest level
1666 * Optimization: gobbles an entire sequence of ordinary characters so that
1667 * it can turn them into a single node, which is smaller to store and
1668 * faster to run. Backslashed characters are exceptions, each becoming a
1669 * separate node; the code is simpler that way and it's not worth fixing.
1671 * [Yes, it is worth fixing, some scripts can run twice the speed.]
1674 S_regatom(pTHX_ I32 *flagp)
1677 register regnode *ret = 0;
1680 *flagp = WORST; /* Tentatively. */
1683 switch (*PL_regcomp_parse) {
1687 if (PL_regflags & PMf_MULTILINE)
1688 ret = reg_node(MBOL);
1689 else if (PL_regflags & PMf_SINGLELINE)
1690 ret = reg_node(SBOL);
1692 ret = reg_node(BOL);
1695 if (PL_regcomp_parse[1])
1698 if (PL_regflags & PMf_MULTILINE)
1699 ret = reg_node(MEOL);
1700 else if (PL_regflags & PMf_SINGLELINE)
1701 ret = reg_node(SEOL);
1703 ret = reg_node(EOL);
1708 if (PL_regflags & PMf_SINGLELINE)
1709 ret = reg_node(SANYUTF8);
1711 ret = reg_node(ANYUTF8);
1715 if (PL_regflags & PMf_SINGLELINE)
1716 ret = reg_node(SANY);
1718 ret = reg_node(REG_ANY);
1719 *flagp |= HASWIDTH|SIMPLE;
1725 ret = (UTF ? regclassutf8() : regclass());
1726 if (*PL_regcomp_parse != ']')
1727 FAIL("unmatched [] in regexp");
1729 *flagp |= HASWIDTH|SIMPLE;
1733 ret = reg(1, &flags);
1735 if (flags & TRYAGAIN)
1739 *flagp |= flags&(HASWIDTH|SPSTART|SIMPLE);
1743 if (flags & TRYAGAIN) {
1747 FAIL2("internal urp in regexp at /%s/", PL_regcomp_parse);
1748 /* Supposed to be caught earlier. */
1751 if (!regcurly(PL_regcomp_parse)) {
1759 FAIL("?+*{} follows nothing in regexp");
1762 switch (*++PL_regcomp_parse) {
1765 ret = reg_node(SBOL);
1770 ret = reg_node(GPOS);
1771 PL_regseen |= REG_SEEN_GPOS;
1776 ret = reg_node(SEOL);
1781 ret = reg_node(EOS);
1783 PL_seen_zerolen++; /* Do not optimize RE away */
1787 ret = reg_node(SANY);
1788 *flagp |= HASWIDTH|SIMPLE;
1792 ret = reg_node(CLUMP);
1795 if (UTF && !PL_utf8_mark)
1796 is_utf8_mark((U8*)"~"); /* preload table */
1801 ? (LOC ? ALNUMLUTF8 : ALNUMUTF8)
1802 : (LOC ? ALNUML : ALNUM));
1803 *flagp |= HASWIDTH|SIMPLE;
1805 if (UTF && !PL_utf8_alnum)
1806 is_utf8_alnum((U8*)"a"); /* preload table */
1811 ? (LOC ? NALNUMLUTF8 : NALNUMUTF8)
1812 : (LOC ? NALNUML : NALNUM));
1813 *flagp |= HASWIDTH|SIMPLE;
1815 if (UTF && !PL_utf8_alnum)
1816 is_utf8_alnum((U8*)"a"); /* preload table */
1820 PL_regseen |= REG_SEEN_LOOKBEHIND;
1823 ? (LOC ? BOUNDLUTF8 : BOUNDUTF8)
1824 : (LOC ? BOUNDL : BOUND));
1827 if (UTF && !PL_utf8_alnum)
1828 is_utf8_alnum((U8*)"a"); /* preload table */
1832 PL_regseen |= REG_SEEN_LOOKBEHIND;
1835 ? (LOC ? NBOUNDLUTF8 : NBOUNDUTF8)
1836 : (LOC ? NBOUNDL : NBOUND));
1839 if (UTF && !PL_utf8_alnum)
1840 is_utf8_alnum((U8*)"a"); /* preload table */
1845 ? (LOC ? SPACELUTF8 : SPACEUTF8)
1846 : (LOC ? SPACEL : SPACE));
1847 *flagp |= HASWIDTH|SIMPLE;
1849 if (UTF && !PL_utf8_space)
1850 is_utf8_space((U8*)" "); /* preload table */
1855 ? (LOC ? NSPACELUTF8 : NSPACEUTF8)
1856 : (LOC ? NSPACEL : NSPACE));
1857 *flagp |= HASWIDTH|SIMPLE;
1859 if (UTF && !PL_utf8_space)
1860 is_utf8_space((U8*)" "); /* preload table */
1863 ret = reg_node(UTF ? DIGITUTF8 : DIGIT);
1864 *flagp |= HASWIDTH|SIMPLE;
1866 if (UTF && !PL_utf8_digit)
1867 is_utf8_digit((U8*)"1"); /* preload table */
1870 ret = reg_node(UTF ? NDIGITUTF8 : NDIGIT);
1871 *flagp |= HASWIDTH|SIMPLE;
1873 if (UTF && !PL_utf8_digit)
1874 is_utf8_digit((U8*)"1"); /* preload table */
1878 { /* a lovely hack--pretend we saw [\pX] instead */
1879 char* oldregxend = PL_regxend;
1881 if (PL_regcomp_parse[1] == '{') {
1882 PL_regxend = strchr(PL_regcomp_parse, '}');
1884 FAIL("Missing right brace on \\p{}");
1888 PL_regxend = PL_regcomp_parse + 2;
1891 ret = regclassutf8();
1893 PL_regxend = oldregxend;
1896 *flagp |= HASWIDTH|SIMPLE;
1909 case '1': case '2': case '3': case '4':
1910 case '5': case '6': case '7': case '8': case '9':
1912 I32 num = atoi(PL_regcomp_parse);
1914 if (num > 9 && num >= PL_regnpar)
1917 if (!SIZE_ONLY && num > PL_regcomp_rx->nparens)
1918 FAIL("reference to nonexistent group");
1921 ? (LOC ? REFFL : REFF)
1924 while (isDIGIT(*PL_regcomp_parse))
1932 if (PL_regcomp_parse >= PL_regxend)
1933 FAIL("trailing \\ in regexp");
1936 /* Do not generate `unrecognized' warnings here, we fall
1937 back into the quick-grab loop below */
1943 if (PL_regflags & PMf_EXTENDED) {
1944 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != '\n') PL_regcomp_parse++;
1945 if (PL_regcomp_parse < PL_regxend)
1961 ? (LOC ? EXACTFL : EXACTF)
1964 for (len = 0, p = PL_regcomp_parse - 1;
1965 len < 127 && p < PL_regxend;
1970 if (PL_regflags & PMf_EXTENDED)
1971 p = regwhite(p, PL_regxend);
2025 char* e = strchr(p, '}');
2028 FAIL("Missing right brace on \\x{}");
2030 ender = (UV)scan_hex(p + 1, e - p, &numlen);
2031 if (numlen + len >= 127) { /* numlen is generous */
2038 FAIL("Can't use \\x{} without 'use utf8' declaration");
2041 ender = (UV)scan_hex(p, 2, &numlen);
2047 ender = UCHARAT(p++);
2048 ender = toCTRL(ender);
2050 case '0': case '1': case '2': case '3':case '4':
2051 case '5': case '6': case '7': case '8':case '9':
2053 (isDIGIT(p[1]) && atoi(p) >= PL_regnpar) ) {
2054 ender = (UV)scan_oct(p, 3, &numlen);
2063 if (p >= PL_regxend)
2064 FAIL("trailing \\ in regexp");
2067 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) && isALPHA(*p))
2068 Perl_warner(aTHX_ WARN_UNSAFE,
2069 "/%.127s/: Unrecognized escape \\%c passed through",
2072 goto normal_default;
2077 if ((*p & 0xc0) == 0xc0 && UTF) {
2078 ender = utf8_to_uv((U8*)p, &numlen);
2085 if (PL_regflags & PMf_EXTENDED)
2086 p = regwhite(p, PL_regxend);
2089 ender = toLOWER_LC_uni(ender);
2091 ender = toLOWER_uni(ender);
2093 if (ISMULT2(p)) { /* Back off on ?+*. */
2096 else if (ender >= 0x80 && UTF) {
2097 reguni(ender, s, &numlen);
2107 if (ender >= 0x80 && UTF) {
2108 reguni(ender, s, &numlen);
2116 PL_regcomp_parse = p - 1;
2119 FAIL("internal disaster in regexp");
2127 PL_regsize += STR_SZ(len);
2129 PL_regcode += STR_SZ(len);
2138 S_regwhite(pTHX_ char *p, char *e)
2143 else if (*p == '#') {
2146 } while (p < e && *p != '\n');
2154 /* Parse POSIX character classes: [[:foo:]], [[=foo=]], [[.foo.]].
2155 Character classes ([:foo:]) can also be negated ([:^foo:]).
2156 Returns a named class id (ANYOF_XXX) if successful, -1 otherwise.
2157 Equivalence classes ([=foo=]) and composites ([.foo.]) are parsed,
2158 but trigger warnings because they are currently unimplemented. */
2160 S_regpposixcc(pTHX_ I32 value)
2164 I32 namedclass = OOB_NAMEDCLASS;
2166 if (value == '[' && PL_regcomp_parse + 1 < PL_regxend &&
2167 /* I smell either [: or [= or [. -- POSIX has been here, right? */
2168 (*PL_regcomp_parse == ':' ||
2169 *PL_regcomp_parse == '=' ||
2170 *PL_regcomp_parse == '.')) {
2171 char c = *PL_regcomp_parse;
2172 char* s = PL_regcomp_parse++;
2174 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != c)
2176 if (PL_regcomp_parse == PL_regxend)
2177 /* Grandfather lone [:, [=, [. */
2178 PL_regcomp_parse = s;
2180 char* t = PL_regcomp_parse++; /* skip over the c */
2182 if (*PL_regcomp_parse == ']') {
2183 PL_regcomp_parse++; /* skip over the ending ] */
2186 I32 complement = *posixcc == '^' ? *posixcc++ : 0;
2187 I32 skip = 5; /* the most common skip */
2191 if (strnEQ(posixcc, "alnum", 5))
2193 complement ? ANYOF_NALNUMC : ANYOF_ALNUMC;
2194 else if (strnEQ(posixcc, "alpha", 5))
2196 complement ? ANYOF_NALPHA : ANYOF_ALPHA;
2197 else if (strnEQ(posixcc, "ascii", 5))
2199 complement ? ANYOF_NASCII : ANYOF_ASCII;
2202 if (strnEQ(posixcc, "cntrl", 5))
2204 complement ? ANYOF_NCNTRL : ANYOF_CNTRL;
2207 if (strnEQ(posixcc, "digit", 5))
2209 complement ? ANYOF_NDIGIT : ANYOF_DIGIT;
2212 if (strnEQ(posixcc, "graph", 5))
2214 complement ? ANYOF_NGRAPH : ANYOF_GRAPH;
2217 if (strnEQ(posixcc, "lower", 5))
2219 complement ? ANYOF_NLOWER : ANYOF_LOWER;
2222 if (strnEQ(posixcc, "print", 5))
2224 complement ? ANYOF_NPRINT : ANYOF_PRINT;
2225 else if (strnEQ(posixcc, "punct", 5))
2227 complement ? ANYOF_NPUNCT : ANYOF_PUNCT;
2230 if (strnEQ(posixcc, "space", 5))
2232 complement ? ANYOF_NSPACE : ANYOF_SPACE;
2234 if (strnEQ(posixcc, "upper", 5))
2236 complement ? ANYOF_NUPPER : ANYOF_UPPER;
2238 case 'w': /* this is not POSIX, this is the Perl \w */
2239 if (strnEQ(posixcc, "word", 4)) {
2241 complement ? ANYOF_NALNUM : ANYOF_ALNUM;
2246 if (strnEQ(posixcc, "xdigit", 6)) {
2248 complement ? ANYOF_NXDIGIT : ANYOF_XDIGIT;
2253 if ((namedclass == OOB_NAMEDCLASS ||
2254 !(posixcc + skip + 2 < PL_regxend &&
2255 (posixcc[skip] == ':' &&
2256 posixcc[skip + 1] == ']'))))
2257 Perl_croak(aTHX_ "Character class [:%.*s:] unknown",
2259 } else if (ckWARN(WARN_UNSAFE) && !SIZE_ONLY)
2260 /* [[=foo=]] and [[.foo.]] are still future. */
2261 Perl_warner(aTHX_ WARN_UNSAFE,
2262 "Character class syntax [%c %c] is reserved for future extensions", c, c);
2264 /* Maternal grandfather:
2265 * "[:" ending in ":" but not in ":]" */
2266 PL_regcomp_parse = s;
2275 S_checkposixcc(pTHX)
2277 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) &&
2278 (*PL_regcomp_parse == ':' ||
2279 *PL_regcomp_parse == '=' ||
2280 *PL_regcomp_parse == '.')) {
2281 char *s = PL_regcomp_parse;
2284 while(*s && isALNUM(*s))
2286 if (*s && c == *s && s[1] == ']') {
2287 Perl_warner(aTHX_ WARN_UNSAFE,
2288 "Character class syntax [%c %c] belongs inside character classes", c, c);
2289 if (c == '=' || c == '.')
2290 Perl_warner(aTHX_ WARN_UNSAFE,
2291 "Character class syntax [%c %c] is reserved for future extensions", c, c);
2301 register I32 lastvalue = OOB_CHAR8;
2302 register I32 range = 0;
2303 register regnode *ret;
2308 bool need_class = 0;
2310 ret = reg_node(ANYOF);
2312 PL_regsize += ANYOF_SKIP;
2315 ANYOF_BITMAP_ZERO(ret);
2316 PL_regcode += ANYOF_SKIP;
2318 ANYOF_FLAGS(ret) |= ANYOF_FOLD;
2320 ANYOF_FLAGS(ret) |= ANYOF_LOCALE;
2322 if (*PL_regcomp_parse == '^') { /* Complement of range. */
2326 ANYOF_FLAGS(ret) |= ANYOF_INVERT;
2329 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE))
2332 if (*PL_regcomp_parse == ']' || *PL_regcomp_parse == '-')
2333 goto skipcond; /* allow 1st char to be ] or - */
2334 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != ']') {
2336 namedclass = OOB_NAMEDCLASS;
2338 rangebegin = PL_regcomp_parse;
2339 value = UCHARAT(PL_regcomp_parse++);
2341 namedclass = regpposixcc(value);
2342 else if (value == '\\') {
2343 value = UCHARAT(PL_regcomp_parse++);
2345 case 'w': namedclass = ANYOF_ALNUM; break;
2346 case 'W': namedclass = ANYOF_NALNUM; break;
2347 case 's': namedclass = ANYOF_SPACE; break;
2348 case 'S': namedclass = ANYOF_NSPACE; break;
2349 case 'd': namedclass = ANYOF_DIGIT; break;
2350 case 'D': namedclass = ANYOF_NDIGIT; break;
2351 case 'n': value = '\n'; break;
2352 case 'r': value = '\r'; break;
2353 case 't': value = '\t'; break;
2354 case 'f': value = '\f'; break;
2355 case 'b': value = '\b'; break;
2356 case 'e': value = '\033'; break;
2357 case 'a': value = '\007'; break;
2359 value = (UV)scan_hex(PL_regcomp_parse, 2, &numlen);
2360 PL_regcomp_parse += numlen;
2363 value = UCHARAT(PL_regcomp_parse++);
2364 value = toCTRL(value);
2366 case '0': case '1': case '2': case '3': case '4':
2367 case '5': case '6': case '7': case '8': case '9':
2368 value = (UV)scan_oct(--PL_regcomp_parse, 3, &numlen);
2369 PL_regcomp_parse += numlen;
2372 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) && isALPHA(value))
2373 Perl_warner(aTHX_ WARN_UNSAFE,
2374 "/%.127s/: Unrecognized escape \\%c in character class passed through",
2380 if (namedclass > OOB_NAMEDCLASS) {
2381 if (!need_class && !SIZE_ONLY)
2382 ANYOF_CLASS_ZERO(ret);
2384 if (range) { /* a-\d, a-[:digit:] */
2386 if (ckWARN(WARN_UNSAFE))
2387 Perl_warner(aTHX_ WARN_UNSAFE,
2388 "/%.127s/: false [] range \"%*.*s\" in regexp",
2390 PL_regcomp_parse - rangebegin,
2391 PL_regcomp_parse - rangebegin,
2393 ANYOF_BITMAP_SET(ret, lastvalue);
2394 ANYOF_BITMAP_SET(ret, '-');
2396 range = 0; /* this is not a true range */
2399 switch (namedclass) {
2402 ANYOF_CLASS_SET(ret, ANYOF_ALNUM);
2404 for (value = 0; value < 256; value++)
2406 ANYOF_BITMAP_SET(ret, value);
2411 ANYOF_CLASS_SET(ret, ANYOF_NALNUM);
2413 for (value = 0; value < 256; value++)
2414 if (!isALNUM(value))
2415 ANYOF_BITMAP_SET(ret, value);
2420 ANYOF_CLASS_SET(ret, ANYOF_SPACE);
2422 for (value = 0; value < 256; value++)
2424 ANYOF_BITMAP_SET(ret, value);
2429 ANYOF_CLASS_SET(ret, ANYOF_NSPACE);
2431 for (value = 0; value < 256; value++)
2432 if (!isSPACE(value))
2433 ANYOF_BITMAP_SET(ret, value);
2438 ANYOF_CLASS_SET(ret, ANYOF_DIGIT);
2440 for (value = '0'; value <= '9'; value++)
2441 ANYOF_BITMAP_SET(ret, value);
2446 ANYOF_CLASS_SET(ret, ANYOF_NDIGIT);
2448 for (value = 0; value < '0'; value++)
2449 ANYOF_BITMAP_SET(ret, value);
2450 for (value = '9' + 1; value < 256; value++)
2451 ANYOF_BITMAP_SET(ret, value);
2456 ANYOF_CLASS_SET(ret, ANYOF_NALNUMC);
2458 for (value = 0; value < 256; value++)
2459 if (!isALNUMC(value))
2460 ANYOF_BITMAP_SET(ret, value);
2465 ANYOF_CLASS_SET(ret, ANYOF_ALNUMC);
2467 for (value = 0; value < 256; value++)
2468 if (isALNUMC(value))
2469 ANYOF_BITMAP_SET(ret, value);
2474 ANYOF_CLASS_SET(ret, ANYOF_ALPHA);
2476 for (value = 0; value < 256; value++)
2478 ANYOF_BITMAP_SET(ret, value);
2483 ANYOF_CLASS_SET(ret, ANYOF_NALPHA);
2485 for (value = 0; value < 256; value++)
2486 if (!isALPHA(value))
2487 ANYOF_BITMAP_SET(ret, value);
2492 ANYOF_CLASS_SET(ret, ANYOF_ASCII);
2494 for (value = 0; value < 128; value++)
2495 ANYOF_BITMAP_SET(ret, value);
2500 ANYOF_CLASS_SET(ret, ANYOF_NASCII);
2502 for (value = 128; value < 256; value++)
2503 ANYOF_BITMAP_SET(ret, value);
2508 ANYOF_CLASS_SET(ret, ANYOF_CNTRL);
2510 for (value = 0; value < 256; value++)
2512 ANYOF_BITMAP_SET(ret, value);
2514 lastvalue = OOB_CHAR8;
2518 ANYOF_CLASS_SET(ret, ANYOF_NCNTRL);
2520 for (value = 0; value < 256; value++)
2521 if (!isCNTRL(value))
2522 ANYOF_BITMAP_SET(ret, value);
2527 ANYOF_CLASS_SET(ret, ANYOF_GRAPH);
2529 for (value = 0; value < 256; value++)
2531 ANYOF_BITMAP_SET(ret, value);
2536 ANYOF_CLASS_SET(ret, ANYOF_NGRAPH);
2538 for (value = 0; value < 256; value++)
2539 if (!isGRAPH(value))
2540 ANYOF_BITMAP_SET(ret, value);
2545 ANYOF_CLASS_SET(ret, ANYOF_LOWER);
2547 for (value = 0; value < 256; value++)
2549 ANYOF_BITMAP_SET(ret, value);
2554 ANYOF_CLASS_SET(ret, ANYOF_NLOWER);
2556 for (value = 0; value < 256; value++)
2557 if (!isLOWER(value))
2558 ANYOF_BITMAP_SET(ret, value);
2563 ANYOF_CLASS_SET(ret, ANYOF_PRINT);
2565 for (value = 0; value < 256; value++)
2567 ANYOF_BITMAP_SET(ret, value);
2572 ANYOF_CLASS_SET(ret, ANYOF_NPRINT);
2574 for (value = 0; value < 256; value++)
2575 if (!isPRINT(value))
2576 ANYOF_BITMAP_SET(ret, value);
2581 ANYOF_CLASS_SET(ret, ANYOF_PUNCT);
2583 for (value = 0; value < 256; value++)
2585 ANYOF_BITMAP_SET(ret, value);
2590 ANYOF_CLASS_SET(ret, ANYOF_NPUNCT);
2592 for (value = 0; value < 256; value++)
2593 if (!isPUNCT(value))
2594 ANYOF_BITMAP_SET(ret, value);
2599 ANYOF_CLASS_SET(ret, ANYOF_UPPER);
2601 for (value = 0; value < 256; value++)
2603 ANYOF_BITMAP_SET(ret, value);
2608 ANYOF_CLASS_SET(ret, ANYOF_NUPPER);
2610 for (value = 0; value < 256; value++)
2611 if (!isUPPER(value))
2612 ANYOF_BITMAP_SET(ret, value);
2617 ANYOF_CLASS_SET(ret, ANYOF_XDIGIT);
2619 for (value = 0; value < 256; value++)
2620 if (isXDIGIT(value))
2621 ANYOF_BITMAP_SET(ret, value);
2626 ANYOF_CLASS_SET(ret, ANYOF_NXDIGIT);
2628 for (value = 0; value < 256; value++)
2629 if (!isXDIGIT(value))
2630 ANYOF_BITMAP_SET(ret, value);
2634 FAIL("invalid [::] class in regexp");
2638 ANYOF_FLAGS(ret) |= ANYOF_CLASS;
2643 if (lastvalue > value) /* b-a */ {
2645 "/%.127s/: invalid [] range \"%*.*s\" in regexp",
2647 PL_regcomp_parse - rangebegin,
2648 PL_regcomp_parse - rangebegin,
2655 if (*PL_regcomp_parse == '-' && PL_regcomp_parse+1 < PL_regxend &&
2656 PL_regcomp_parse[1] != ']') {
2658 if (namedclass > OOB_NAMEDCLASS) { /* \w-, [:word:]- */
2659 if (ckWARN(WARN_UNSAFE))
2660 Perl_warner(aTHX_ WARN_UNSAFE,
2661 "/%.127s/: false [] range \"%*.*s\" in regexp",
2663 PL_regcomp_parse - rangebegin,
2664 PL_regcomp_parse - rangebegin,
2667 ANYOF_BITMAP_SET(ret, '-');
2670 continue; /* do it next time */
2673 /* now is the next time */
2675 #ifndef ASCIIish /* EBCDIC, for example. */
2676 if ((isLOWER(lastvalue) && isLOWER(value)) ||
2677 (isUPPER(lastvalue) && isUPPER(value)))
2680 if (isLOWER(lastvalue)) {
2681 for (i = lastvalue; i <= value; i++)
2683 ANYOF_BITMAP_SET(ret, i);
2685 for (i = lastvalue; i <= value; i++)
2687 ANYOF_BITMAP_SET(ret, i);
2692 for ( ; lastvalue <= value; lastvalue++)
2693 ANYOF_BITMAP_SET(ret, lastvalue);
2699 PL_regsize += ANYOF_CLASS_ADD_SKIP;
2701 PL_regcode += ANYOF_CLASS_ADD_SKIP;
2703 /* optimize case-insensitive simple patterns (e.g. /[a-z]/i) */
2705 (ANYOF_FLAGS(ret) & (ANYOF_FLAGS_ALL ^ ANYOF_INVERT)) == ANYOF_FOLD) {
2706 for (value = 0; value < 256; ++value) {
2707 if (ANYOF_BITMAP_TEST(ret, value)) {
2708 I32 cf = PL_fold[value];
2709 ANYOF_BITMAP_SET(ret, cf);
2712 ANYOF_FLAGS(ret) &= ~ANYOF_FOLD;
2714 /* optimize inverted simple patterns (e.g. [^a-z]) */
2715 if (!SIZE_ONLY && (ANYOF_FLAGS(ret) & ANYOF_FLAGS_ALL) == ANYOF_INVERT) {
2716 for (value = 0; value < ANYOF_BITMAP_SIZE; ++value)
2717 ANYOF_BITMAP(ret)[value] ^= ANYOF_FLAGS_ALL;
2718 ANYOF_FLAGS(ret) = 0;
2724 S_regclassutf8(pTHX)
2729 register U32 lastvalue = OOB_UTF8;
2730 register I32 range = 0;
2731 register regnode *ret;
2739 if (*PL_regcomp_parse == '^') { /* Complement of range. */
2743 flags |= ANYOF_INVERT;
2747 flags |= ANYOF_FOLD;
2749 flags |= ANYOF_LOCALE;
2750 listsv = newSVpvn("# comment\n",10);
2753 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE))
2756 if (*PL_regcomp_parse == ']' || *PL_regcomp_parse == '-')
2757 goto skipcond; /* allow 1st char to be ] or - */
2759 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != ']') {
2761 namedclass = OOB_NAMEDCLASS;
2763 rangebegin = PL_regcomp_parse;
2764 value = utf8_to_uv((U8*)PL_regcomp_parse, &numlen);
2765 PL_regcomp_parse += numlen;
2767 namedclass = regpposixcc(value);
2768 else if (value == '\\') {
2769 value = utf8_to_uv((U8*)PL_regcomp_parse, &numlen);
2770 PL_regcomp_parse += numlen;
2772 case 'w': namedclass = ANYOF_ALNUM; break;
2773 case 'W': namedclass = ANYOF_NALNUM; break;
2774 case 's': namedclass = ANYOF_SPACE; break;
2775 case 'S': namedclass = ANYOF_NSPACE; break;
2776 case 'd': namedclass = ANYOF_DIGIT; break;
2777 case 'D': namedclass = ANYOF_NDIGIT; break;
2780 if (*PL_regcomp_parse == '{') {
2781 e = strchr(PL_regcomp_parse++, '}');
2783 FAIL("Missing right brace on \\p{}");
2784 n = e - PL_regcomp_parse;
2787 e = PL_regcomp_parse;
2792 Perl_sv_catpvf(aTHX_ listsv,
2793 "+utf8::%.*s\n", n, PL_regcomp_parse);
2795 Perl_sv_catpvf(aTHX_ listsv,
2796 "!utf8::%.*s\n", n, PL_regcomp_parse);
2798 PL_regcomp_parse = e + 1;
2799 lastvalue = OOB_UTF8;
2801 case 'n': value = '\n'; break;
2802 case 'r': value = '\r'; break;
2803 case 't': value = '\t'; break;
2804 case 'f': value = '\f'; break;
2805 case 'b': value = '\b'; break;
2806 case 'e': value = '\033'; break;
2807 case 'a': value = '\007'; break;
2809 if (*PL_regcomp_parse == '{') {
2810 e = strchr(PL_regcomp_parse++, '}');
2812 FAIL("Missing right brace on \\x{}");
2813 value = (UV)scan_hex(PL_regcomp_parse,
2814 e - PL_regcomp_parse,
2816 PL_regcomp_parse = e + 1;
2819 value = (UV)scan_hex(PL_regcomp_parse, 2, &numlen);
2820 PL_regcomp_parse += numlen;
2824 value = UCHARAT(PL_regcomp_parse++);
2825 value = toCTRL(value);
2827 case '0': case '1': case '2': case '3': case '4':
2828 case '5': case '6': case '7': case '8': case '9':
2829 value = (UV)scan_oct(--PL_regcomp_parse, 3, &numlen);
2830 PL_regcomp_parse += numlen;
2833 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) && isALPHA(value))
2834 Perl_warner(aTHX_ WARN_UNSAFE,
2835 "/%.127s/: Unrecognized escape \\%c in character class passed through",
2841 if (namedclass > OOB_NAMEDCLASS) {
2842 if (range) { /* a-\d, a-[:digit:] */
2844 if (ckWARN(WARN_UNSAFE))
2845 Perl_warner(aTHX_ WARN_UNSAFE,
2846 "/%.127s/: false [] range \"%*.*s\" in regexp",
2848 PL_regcomp_parse - rangebegin,
2849 PL_regcomp_parse - rangebegin,
2851 Perl_sv_catpvf(aTHX_ listsv,
2852 /* 0x002D is Unicode for '-' */
2853 "%04"UVxf"\n002D\n", (UV)lastvalue);
2858 switch (namedclass) {
2860 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsWord\n"); break;
2862 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsWord\n"); break;
2864 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsAlnum\n"); break;
2866 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsAlnum\n"); break;
2868 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsAlpha\n"); break;
2870 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsAlpha\n"); break;
2872 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsASCII\n"); break;
2874 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsASCII\n"); break;
2876 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsCntrl\n"); break;
2878 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsCntrl\n"); break;
2880 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsGraph\n"); break;
2882 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsGraph\n"); break;
2884 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsDigit\n"); break;
2886 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsDigit\n"); break;
2888 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsLower\n"); break;
2890 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsLower\n"); break;
2892 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsPrint\n"); break;
2894 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsPrint\n"); break;
2896 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsPunct\n"); break;
2898 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsPunct\n"); break;
2900 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsSpace\n"); break;
2902 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsSpace\n"); break;
2904 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsUpper\n"); break;
2906 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsUpper\n"); break;
2908 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsXDigit\n"); break;
2910 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsXDigit\n"); break;
2916 if (lastvalue > value) { /* b-a */
2918 "/%.127s/: invalid [] range \"%*.*s\" in regexp",
2920 PL_regcomp_parse - rangebegin,
2921 PL_regcomp_parse - rangebegin,
2928 if (*PL_regcomp_parse == '-' && PL_regcomp_parse+1 < PL_regxend &&
2929 PL_regcomp_parse[1] != ']') {
2931 if (namedclass > OOB_NAMEDCLASS) { /* \w-, [:word:]- */
2932 if (ckWARN(WARN_UNSAFE))
2933 Perl_warner(aTHX_ WARN_UNSAFE,
2934 "/%.127s/: false [] range \"%*.*s\" in regexp",
2936 PL_regcomp_parse - rangebegin,
2937 PL_regcomp_parse - rangebegin,
2940 Perl_sv_catpvf(aTHX_ listsv,
2941 /* 0x002D is Unicode for '-' */
2945 continue; /* do it next time */
2948 /* now is the next time */
2950 Perl_sv_catpvf(aTHX_ listsv, "%04"UVxf"\t%04"UVxf"\n",
2951 (UV)lastvalue, (UV)value);
2955 ret = reganode(ANYOFUTF8, 0);
2958 SV *rv = swash_init("utf8", "", listsv, 1, 0);
2959 SvREFCNT_dec(listsv);
2960 n = add_data(1,"s");
2961 PL_regcomp_rx->data->data[n] = (void*)rv;
2962 ARG1_SET(ret, flags);
2973 char* retval = PL_regcomp_parse++;
2976 if (*PL_regcomp_parse == '(' && PL_regcomp_parse[1] == '?' &&
2977 PL_regcomp_parse[2] == '#') {
2978 while (*PL_regcomp_parse && *PL_regcomp_parse != ')')
2983 if (PL_regflags & PMf_EXTENDED) {
2984 if (isSPACE(*PL_regcomp_parse)) {
2988 else if (*PL_regcomp_parse == '#') {
2989 while (*PL_regcomp_parse && *PL_regcomp_parse != '\n')
3000 - reg_node - emit a node
3002 STATIC regnode * /* Location. */
3003 S_reg_node(pTHX_ U8 op)
3006 register regnode *ret;
3007 register regnode *ptr;
3011 SIZE_ALIGN(PL_regsize);
3016 NODE_ALIGN_FILL(ret);
3018 FILL_ADVANCE_NODE(ptr, op);
3025 - reganode - emit a node with an argument
3027 STATIC regnode * /* Location. */
3028 S_reganode(pTHX_ U8 op, U32 arg)
3031 register regnode *ret;
3032 register regnode *ptr;
3036 SIZE_ALIGN(PL_regsize);
3041 NODE_ALIGN_FILL(ret);
3043 FILL_ADVANCE_NODE_ARG(ptr, op, arg);
3050 - reguni - emit (if appropriate) a Unicode character
3053 S_reguni(pTHX_ UV uv, char* s, I32* lenp)
3058 *lenp = uv_to_utf8(tmpbuf, uv) - tmpbuf;
3061 *lenp = uv_to_utf8((U8*)s, uv) - (U8*)s;
3066 - reginsert - insert an operator in front of already-emitted operand
3068 * Means relocating the operand.
3071 S_reginsert(pTHX_ U8 op, regnode *opnd)
3074 register regnode *src;
3075 register regnode *dst;
3076 register regnode *place;
3077 register int offset = regarglen[(U8)op];
3079 /* (PL_regkind[(U8)op] == CURLY ? EXTRA_STEP_2ARGS : 0); */
3082 PL_regsize += NODE_STEP_REGNODE + offset;
3087 PL_regcode += NODE_STEP_REGNODE + offset;
3090 StructCopy(--src, --dst, regnode);
3092 place = opnd; /* Op node, where operand used to be. */
3093 src = NEXTOPER(place);
3094 FILL_ADVANCE_NODE(place, op);
3095 Zero(src, offset, regnode);
3099 - regtail - set the next-pointer at the end of a node chain of p to val.
3102 S_regtail(pTHX_ regnode *p, regnode *val)
3105 register regnode *scan;
3106 register regnode *temp;
3107 register I32 offset;
3112 /* Find last node. */
3115 temp = regnext(scan);
3121 if (reg_off_by_arg[OP(scan)]) {
3122 ARG_SET(scan, val - scan);
3125 NEXT_OFF(scan) = val - scan;
3130 - regoptail - regtail on operand of first argument; nop if operandless
3133 S_regoptail(pTHX_ regnode *p, regnode *val)
3136 /* "Operandless" and "op != BRANCH" are synonymous in practice. */
3137 if (p == NULL || SIZE_ONLY)
3139 if (PL_regkind[(U8)OP(p)] == BRANCH) {
3140 regtail(NEXTOPER(p), val);
3142 else if ( PL_regkind[(U8)OP(p)] == BRANCHJ) {
3143 regtail(NEXTOPER(NEXTOPER(p)), val);
3150 - regcurly - a little FSA that accepts {\d+,?\d*}
3153 S_regcurly(pTHX_ register char *s)
3172 S_dumpuntil(pTHX_ regnode *start, regnode *node, regnode *last, SV* sv, I32 l)
3175 register U8 op = EXACT; /* Arbitrary non-END op. */
3176 register regnode *next, *onode;
3178 while (op != END && (!last || node < last)) {
3179 /* While that wasn't END last time... */
3185 next = regnext(node);
3187 if (OP(node) == OPTIMIZED)
3190 PerlIO_printf(Perl_debug_log, "%4"IVdf":%*s%s", (IV)(node - start),
3191 (int)(2*l + 1), "", SvPVX(sv));
3192 if (next == NULL) /* Next ptr. */
3193 PerlIO_printf(Perl_debug_log, "(0)");
3195 PerlIO_printf(Perl_debug_log, "(%"IVdf")", (IV)(next - start));
3196 (void)PerlIO_putc(Perl_debug_log, '\n');
3198 if (PL_regkind[(U8)op] == BRANCHJ) {
3199 register regnode *nnode = (OP(next) == LONGJMP
3202 if (last && nnode > last)
3204 node = dumpuntil(start, NEXTOPER(NEXTOPER(node)), nnode, sv, l + 1);
3206 else if (PL_regkind[(U8)op] == BRANCH) {
3207 node = dumpuntil(start, NEXTOPER(node), next, sv, l + 1);
3209 else if ( op == CURLY) { /* `next' might be very big: optimizer */
3210 node = dumpuntil(start, NEXTOPER(node) + EXTRA_STEP_2ARGS,
3211 NEXTOPER(node) + EXTRA_STEP_2ARGS + 1, sv, l + 1);
3213 else if (PL_regkind[(U8)op] == CURLY && op != CURLYX) {
3214 node = dumpuntil(start, NEXTOPER(node) + EXTRA_STEP_2ARGS,
3217 else if ( op == PLUS || op == STAR) {
3218 node = dumpuntil(start, NEXTOPER(node), NEXTOPER(node) + 1, sv, l + 1);
3220 else if (op == ANYOF) {
3221 node = NEXTOPER(node);
3224 else if (PL_regkind[(U8)op] == EXACT) {
3225 /* Literal string, where present. */
3226 node += NODE_SZ_STR(node) - 1;
3227 node = NEXTOPER(node);
3230 node = NEXTOPER(node);
3231 node += regarglen[(U8)op];
3233 if (op == CURLYX || op == OPEN)
3235 else if (op == WHILEM)
3238 #endif /* DEBUGGING */
3243 - regdump - dump a regexp onto Perl_debug_log in vaguely comprehensible form
3246 Perl_regdump(pTHX_ regexp *r)
3250 SV *sv = sv_newmortal();
3252 (void)dumpuntil(r->program, r->program + 1, NULL, sv, 0);
3254 /* Header fields of interest. */
3255 if (r->anchored_substr)
3256 PerlIO_printf(Perl_debug_log,
3257 "anchored `%s%.*s%s'%s at %"IVdf" ",
3259 (int)(SvCUR(r->anchored_substr) - (SvTAIL(r->anchored_substr)!=0)),
3260 SvPVX(r->anchored_substr),
3262 SvTAIL(r->anchored_substr) ? "$" : "",
3263 (IV)r->anchored_offset);
3264 if (r->float_substr)
3265 PerlIO_printf(Perl_debug_log,
3266 "floating `%s%.*s%s'%s at %"IVdf"..%"UVuf" ",
3268 (int)(SvCUR(r->float_substr) - (SvTAIL(r->float_substr)!=0)),
3269 SvPVX(r->float_substr),
3271 SvTAIL(r->float_substr) ? "$" : "",
3272 (IV)r->float_min_offset, (UV)r->float_max_offset);
3273 if (r->check_substr)
3274 PerlIO_printf(Perl_debug_log,
3275 r->check_substr == r->float_substr
3276 ? "(checking floating" : "(checking anchored");
3277 if (r->reganch & ROPT_NOSCAN)
3278 PerlIO_printf(Perl_debug_log, " noscan");
3279 if (r->reganch & ROPT_CHECK_ALL)
3280 PerlIO_printf(Perl_debug_log, " isall");
3281 if (r->check_substr)
3282 PerlIO_printf(Perl_debug_log, ") ");
3284 if (r->regstclass) {
3285 regprop(sv, r->regstclass);
3286 PerlIO_printf(Perl_debug_log, "stclass `%s' ", SvPVX(sv));
3288 if (r->reganch & ROPT_ANCH) {
3289 PerlIO_printf(Perl_debug_log, "anchored");
3290 if (r->reganch & ROPT_ANCH_BOL)
3291 PerlIO_printf(Perl_debug_log, "(BOL)");
3292 if (r->reganch & ROPT_ANCH_MBOL)
3293 PerlIO_printf(Perl_debug_log, "(MBOL)");
3294 if (r->reganch & ROPT_ANCH_SBOL)
3295 PerlIO_printf(Perl_debug_log, "(SBOL)");
3296 if (r->reganch & ROPT_ANCH_GPOS)
3297 PerlIO_printf(Perl_debug_log, "(GPOS)");
3298 PerlIO_putc(Perl_debug_log, ' ');
3300 if (r->reganch & ROPT_GPOS_SEEN)
3301 PerlIO_printf(Perl_debug_log, "GPOS ");
3302 if (r->reganch & ROPT_SKIP)
3303 PerlIO_printf(Perl_debug_log, "plus ");
3304 if (r->reganch & ROPT_IMPLICIT)
3305 PerlIO_printf(Perl_debug_log, "implicit ");
3306 PerlIO_printf(Perl_debug_log, "minlen %ld ", (long) r->minlen);
3307 if (r->reganch & ROPT_EVAL_SEEN)
3308 PerlIO_printf(Perl_debug_log, "with eval ");
3309 PerlIO_printf(Perl_debug_log, "\n");
3310 #endif /* DEBUGGING */
3314 - regprop - printable representation of opcode
3317 Perl_regprop(pTHX_ SV *sv, regnode *o)
3323 sv_setpvn(sv, "", 0);
3324 if (OP(o) >= reg_num) /* regnode.type is unsigned */
3325 FAIL("corrupted regexp opcode");
3326 sv_catpv(sv, (char*)reg_name[OP(o)]); /* Take off const! */
3328 k = PL_regkind[(U8)OP(o)];
3331 Perl_sv_catpvf(aTHX_ sv, " <%s%.*s%s>", PL_colors[0],
3332 STR_LEN(o), STRING(o), PL_colors[1]);
3333 else if (k == CURLY) {
3334 if (OP(o) == CURLYM || OP(o) == CURLYN)
3335 Perl_sv_catpvf(aTHX_ sv, "[%d]", o->flags); /* Parenth number */
3336 Perl_sv_catpvf(aTHX_ sv, " {%d,%d}", ARG1(o), ARG2(o));
3338 else if (k == WHILEM && o->flags) /* Ordinal/of */
3339 Perl_sv_catpvf(aTHX_ sv, "[%d/%d]", o->flags & 0xf, o->flags>>4);
3340 else if (k == REF || k == OPEN || k == CLOSE || k == GROUPP )
3341 Perl_sv_catpvf(aTHX_ sv, "%d", ARG(o)); /* Parenth number */
3342 else if (k == LOGICAL)
3343 Perl_sv_catpvf(aTHX_ sv, "[%d]", o->flags); /* 2: embedded, otherwise 1 */
3344 else if (k == BRANCHJ && (OP(o) == UNLESSM || OP(o) == IFMATCH))
3345 Perl_sv_catpvf(aTHX_ sv, "[-%d]", o->flags);
3346 #endif /* DEBUGGING */
3350 Perl_re_intuit_string(pTHX_ regexp *prog)
3351 { /* Assume that RE_INTUIT is set */
3354 char *s = SvPV(prog->check_substr,n_a);
3356 if (!PL_colorset) reginitcolors();
3357 PerlIO_printf(Perl_debug_log,
3358 "%sUsing REx substr:%s `%s%.60s%s%s'\n",
3359 PL_colors[4],PL_colors[5],PL_colors[0],
3362 (strlen(s) > 60 ? "..." : ""));
3365 return prog->check_substr;
3369 Perl_pregfree(pTHX_ struct regexp *r)
3372 DEBUG_r(if (!PL_colorset) reginitcolors());
3374 if (!r || (--r->refcnt > 0))
3376 DEBUG_r(PerlIO_printf(Perl_debug_log,
3377 "%sFreeing REx:%s `%s%.60s%s%s'\n",
3378 PL_colors[4],PL_colors[5],PL_colors[0],
3381 (strlen(r->precomp) > 60 ? "..." : "")));
3384 Safefree(r->precomp);
3385 if (RX_MATCH_COPIED(r))
3386 Safefree(r->subbeg);
3388 if (r->anchored_substr)
3389 SvREFCNT_dec(r->anchored_substr);
3390 if (r->float_substr)
3391 SvREFCNT_dec(r->float_substr);
3392 Safefree(r->substrs);
3395 int n = r->data->count;
3396 AV* new_comppad = NULL;
3401 switch (r->data->what[n]) {
3403 SvREFCNT_dec((SV*)r->data->data[n]);
3406 new_comppad = (AV*)r->data->data[n];
3409 if (new_comppad == NULL)
3410 Perl_croak(aTHX_ "panic: pregfree comppad");
3411 old_comppad = PL_comppad;
3412 old_curpad = PL_curpad;
3413 PL_comppad = new_comppad;
3414 PL_curpad = AvARRAY(new_comppad);
3415 op_free((OP_4tree*)r->data->data[n]);
3416 PL_comppad = old_comppad;
3417 PL_curpad = old_curpad;
3418 SvREFCNT_dec((SV*)new_comppad);
3424 FAIL2("panic: regfree data code '%c'", r->data->what[n]);
3427 Safefree(r->data->what);
3430 Safefree(r->startp);
3436 - regnext - dig the "next" pointer out of a node
3438 * [Note, when REGALIGN is defined there are two places in regmatch()
3439 * that bypass this code for speed.]
3442 Perl_regnext(pTHX_ register regnode *p)
3445 register I32 offset;
3447 if (p == &PL_regdummy)
3450 offset = (reg_off_by_arg[OP(p)] ? ARG(p) : NEXT_OFF(p));
3458 S_re_croak2(pTHX_ const char* pat1,const char* pat2,...)
3461 STRLEN l1 = strlen(pat1);
3462 STRLEN l2 = strlen(pat2);
3471 Copy(pat1, buf, l1 , char);
3472 Copy(pat2, buf + l1, l2 , char);
3473 buf[l1 + l2] = '\n';
3474 buf[l1 + l2 + 1] = '\0';
3476 /* ANSI variant takes additional second argument */
3477 va_start(args, pat2);
3481 msv = vmess(buf, &args);
3483 message = SvPV(msv,l1);
3486 Copy(message, buf, l1 , char);
3487 buf[l1] = '\0'; /* Overwrite \n */
3488 Perl_croak(aTHX_ "%s", buf);
3491 /* XXX Here's a total kludge. But we need to re-enter for swash routines. */
3494 Perl_save_re_context(pTHX)
3498 SAVEPPTR(PL_regprecomp); /* uncompiled string. */
3499 SAVEI32(PL_regnpar); /* () count. */
3500 SAVEI32(PL_regsize); /* Code size. */
3501 SAVEI16(PL_regflags); /* are we folding, multilining? */
3502 SAVEPPTR(PL_reginput); /* String-input pointer. */
3503 SAVEPPTR(PL_regbol); /* Beginning of input, for ^ check. */
3504 SAVEPPTR(PL_regeol); /* End of input, for $ check. */
3505 SAVESPTR(PL_regstartp); /* Pointer to startp array. */
3506 SAVESPTR(PL_regendp); /* Ditto for endp. */
3507 SAVESPTR(PL_reglastparen); /* Similarly for lastparen. */
3508 SAVEPPTR(PL_regtill); /* How far we are required to go. */
3509 SAVEI32(PL_regprev); /* char before regbol, \n if none */
3510 SAVESPTR(PL_reg_start_tmp); /* from regexec.c */
3511 PL_reg_start_tmp = 0;
3512 SAVEFREEPV(PL_reg_start_tmp);
3513 SAVEI32(PL_reg_start_tmpl); /* from regexec.c */
3514 PL_reg_start_tmpl = 0;
3515 SAVESPTR(PL_regdata);
3516 SAVEI32(PL_reg_flags); /* from regexec.c */
3517 SAVEI32(PL_reg_eval_set); /* from regexec.c */
3518 SAVEI32(PL_regnarrate); /* from regexec.c */
3519 SAVESPTR(PL_regprogram); /* from regexec.c */
3520 SAVEINT(PL_regindent); /* from regexec.c */
3521 SAVESPTR(PL_regcc); /* from regexec.c */
3522 SAVESPTR(PL_curcop);
3523 SAVESPTR(PL_regcomp_rx); /* from regcomp.c */
3524 SAVEI32(PL_regseen); /* from regcomp.c */
3525 SAVEI32(PL_regsawback); /* Did we see \1, ...? */
3526 SAVEI32(PL_regnaughty); /* How bad is this pattern? */
3527 SAVESPTR(PL_regcode); /* Code-emit pointer; ®dummy = don't */
3528 SAVEPPTR(PL_regxend); /* End of input for compile */
3529 SAVEPPTR(PL_regcomp_parse); /* Input-scan pointer. */
3530 SAVESPTR(PL_reg_call_cc); /* from regexec.c */
3531 SAVESPTR(PL_reg_re); /* from regexec.c */
3532 SAVEPPTR(PL_reg_ganch); /* from regexec.c */
3533 SAVESPTR(PL_reg_sv); /* from regexec.c */
3534 SAVESPTR(PL_reg_magic); /* from regexec.c */
3535 SAVEI32(PL_reg_oldpos); /* from regexec.c */
3536 SAVESPTR(PL_reg_oldcurpm); /* from regexec.c */
3537 SAVESPTR(PL_reg_curpm); /* from regexec.c */
3539 SAVEPPTR(PL_reg_starttry); /* from regexec.c */
3550 clear_re(pTHXo_ void *r)
3552 ReREFCNT_dec((regexp *)r);