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;
154 struct regnode_charclass_class *start_class;
158 * Forward declarations for pregcomp()'s friends.
161 static scan_data_t zero_scan_data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
164 #define SF_BEFORE_EOL (SF_BEFORE_SEOL|SF_BEFORE_MEOL)
165 #define SF_BEFORE_SEOL 0x1
166 #define SF_BEFORE_MEOL 0x2
167 #define SF_FIX_BEFORE_EOL (SF_FIX_BEFORE_SEOL|SF_FIX_BEFORE_MEOL)
168 #define SF_FL_BEFORE_EOL (SF_FL_BEFORE_SEOL|SF_FL_BEFORE_MEOL)
171 # define SF_FIX_SHIFT_EOL (0+2)
172 # define SF_FL_SHIFT_EOL (0+4)
174 # define SF_FIX_SHIFT_EOL (+2)
175 # define SF_FL_SHIFT_EOL (+4)
178 #define SF_FIX_BEFORE_SEOL (SF_BEFORE_SEOL << SF_FIX_SHIFT_EOL)
179 #define SF_FIX_BEFORE_MEOL (SF_BEFORE_MEOL << SF_FIX_SHIFT_EOL)
181 #define SF_FL_BEFORE_SEOL (SF_BEFORE_SEOL << SF_FL_SHIFT_EOL)
182 #define SF_FL_BEFORE_MEOL (SF_BEFORE_MEOL << SF_FL_SHIFT_EOL) /* 0x20 */
183 #define SF_IS_INF 0x40
184 #define SF_HAS_PAR 0x80
185 #define SF_IN_PAR 0x100
186 #define SF_HAS_EVAL 0x200
187 #define SCF_DO_SUBSTR 0x400
188 #define SCF_DO_STCLASS_AND 0x0800
189 #define SCF_DO_STCLASS_OR 0x1000
190 #define SCF_DO_STCLASS (SCF_DO_STCLASS_AND|SCF_DO_STCLASS_OR)
193 #define UTF (PL_reg_flags & RF_utf8)
194 #define LOC (PL_regflags & PMf_LOCALE)
195 #define FOLD (PL_regflags & PMf_FOLD)
197 #define OOB_CHAR8 1234
198 #define OOB_UTF8 123456
199 #define OOB_NAMEDCLASS -1
201 #define CHR_SVLEN(sv) (UTF ? sv_len_utf8(sv) : SvCUR(sv))
202 #define CHR_DIST(a,b) (UTF ? utf8_distance(a,b) : a - b)
204 /* Allow for side effects in s */
205 #define REGC(c,s) STMT_START { if (!SIZE_ONLY) *(s) = (c); else (s);} STMT_END
207 static void clear_re(pTHXo_ void *r);
209 /* Mark that we cannot extend a found fixed substring at this point.
210 Updata the longest found anchored substring and the longest found
211 floating substrings if needed. */
214 S_scan_commit(pTHX_ scan_data_t *data)
217 STRLEN l = CHR_SVLEN(data->last_found);
218 STRLEN old_l = CHR_SVLEN(*data->longest);
220 if ((l >= old_l) && ((l > old_l) || (data->flags & SF_BEFORE_EOL))) {
221 sv_setsv(*data->longest, data->last_found);
222 if (*data->longest == data->longest_fixed) {
223 data->offset_fixed = l ? data->last_start_min : data->pos_min;
224 if (data->flags & SF_BEFORE_EOL)
226 |= ((data->flags & SF_BEFORE_EOL) << SF_FIX_SHIFT_EOL);
228 data->flags &= ~SF_FIX_BEFORE_EOL;
231 data->offset_float_min = l ? data->last_start_min : data->pos_min;
232 data->offset_float_max = (l
233 ? data->last_start_max
234 : data->pos_min + data->pos_delta);
235 if (data->flags & SF_BEFORE_EOL)
237 |= ((data->flags & SF_BEFORE_EOL) << SF_FL_SHIFT_EOL);
239 data->flags &= ~SF_FL_BEFORE_EOL;
242 SvCUR_set(data->last_found, 0);
244 data->flags &= ~SF_BEFORE_EOL;
247 /* Can match anything (initialization) */
249 S_cl_anything(pTHX_ struct regnode_charclass_class *cl)
253 ANYOF_CLASS_ZERO(cl);
254 for (value = 0; value < 256; ++value)
255 ANYOF_BITMAP_SET(cl, value);
256 cl->flags = ANYOF_EOS;
258 cl->flags |= ANYOF_LOCALE;
261 /* Can match anything (initialization) */
263 S_cl_is_anything(pTHX_ struct regnode_charclass_class *cl)
267 for (value = 0; value < ANYOF_MAX; value += 2)
268 if (ANYOF_CLASS_TEST(cl, value) && ANYOF_CLASS_TEST(cl, value + 1))
270 for (value = 0; value < 256; ++value)
271 if (!ANYOF_BITMAP_TEST(cl, value))
276 /* Can match anything (initialization) */
278 S_cl_init(pTHX_ struct regnode_charclass_class *cl)
285 S_cl_init_zero(pTHX_ struct regnode_charclass_class *cl)
289 ANYOF_CLASS_ZERO(cl);
290 ANYOF_BITMAP_ZERO(cl);
292 cl->flags |= ANYOF_LOCALE;
295 /* 'And' a given class with another one. Can create false positives */
296 /* We assume that cl is not inverted */
298 S_cl_and(pTHX_ struct regnode_charclass_class *cl,
299 struct regnode_charclass_class *and_with)
303 if (!(and_with->flags & ANYOF_CLASS)
304 && !(cl->flags & ANYOF_CLASS)
305 && (and_with->flags & ANYOF_LOCALE) == (cl->flags & ANYOF_LOCALE)
306 && !(and_with->flags & ANYOF_FOLD)
307 && !(cl->flags & ANYOF_FOLD)) {
310 if (and_with->flags & ANYOF_INVERT)
311 for (i = 0; i < ANYOF_BITMAP_SIZE; i++)
312 cl->bitmap[i] &= ~and_with->bitmap[i];
314 for (i = 0; i < ANYOF_BITMAP_SIZE; i++)
315 cl->bitmap[i] &= and_with->bitmap[i];
316 } /* XXXX: logic is complicated otherwise, leave it along for a moment. */
317 if (!(and_with->flags & ANYOF_EOS))
318 cl->flags &= ~ANYOF_EOS;
321 /* 'OR' a given class with another one. Can create false positives */
322 /* We assume that cl is not inverted */
324 S_cl_or(pTHX_ struct regnode_charclass_class *cl, struct regnode_charclass_class *or_with)
328 if (or_with->flags & ANYOF_INVERT) {
330 * (B1 | CL1) | (!B2 & !CL2) = (B1 | !B2 & !CL2) | (CL1 | (!B2 & !CL2))
331 * <= (B1 | !B2) | (CL1 | !CL2)
332 * which is wasteful if CL2 is small, but we ignore CL2:
333 * (B1 | CL1) | (!B2 & !CL2) <= (B1 | CL1) | !B2 = (B1 | !B2) | CL1
334 * XXXX Can we handle case-fold? Unclear:
335 * (OK1(i) | OK1(i')) | !(OK1(i) | OK1(i')) =
336 * (OK1(i) | OK1(i')) | (!OK1(i) & !OK1(i'))
338 if ( (or_with->flags & ANYOF_LOCALE) == (cl->flags & ANYOF_LOCALE)
339 && !(or_with->flags & ANYOF_FOLD)
340 && !(cl->flags & ANYOF_FOLD) ) {
343 for (i = 0; i < ANYOF_BITMAP_SIZE; i++)
344 cl->bitmap[i] |= ~or_with->bitmap[i];
345 } /* XXXX: logic is complicated otherwise */
350 /* (B1 | CL1) | (B2 | CL2) = (B1 | B2) | (CL1 | CL2)) */
351 if ( (or_with->flags & ANYOF_LOCALE) == (cl->flags & ANYOF_LOCALE)
352 && (!(or_with->flags & ANYOF_FOLD)
353 || (cl->flags & ANYOF_FOLD)) ) {
356 /* OR char bitmap and class bitmap separately */
357 for (i = 0; i < ANYOF_BITMAP_SIZE; i++)
358 cl->bitmap[i] |= or_with->bitmap[i];
359 if (or_with->flags & ANYOF_CLASS) {
360 for (i = 0; i < ANYOF_CLASSBITMAP_SIZE; i++)
361 cl->classflags[i] |= or_with->classflags[i];
362 cl->flags |= ANYOF_CLASS;
365 else { /* XXXX: logic is complicated, leave it along for a moment. */
369 if (or_with->flags & ANYOF_EOS)
370 cl->flags |= ANYOF_EOS;
373 /* REx optimizer. Converts nodes into quickier variants "in place".
374 Finds fixed substrings. */
376 /* Stops at toplevel WHILEM as well as at `last'. At end *scanp is set
377 to the position after last scanned or to NULL. */
380 S_study_chunk(pTHX_ regnode **scanp, I32 *deltap, regnode *last, scan_data_t *data, U32 flags)
381 /* scanp: Start here (read-write). */
382 /* deltap: Write maxlen-minlen here. */
383 /* last: Stop before this one. */
386 I32 min = 0, pars = 0, code;
387 regnode *scan = *scanp, *next;
389 int is_inf = (flags & SCF_DO_SUBSTR) && (data->flags & SF_IS_INF);
390 int is_inf_internal = 0; /* The studied chunk is infinite */
391 I32 is_par = OP(scan) == OPEN ? ARG(scan) : 0;
392 scan_data_t data_fake;
393 struct regnode_charclass_class and_with; /* Valid if flags & SCF_DO_STCLASS_OR */
395 while (scan && OP(scan) != END && scan < last) {
396 /* Peephole optimizer: */
398 if (PL_regkind[(U8)OP(scan)] == EXACT) {
399 /* Merge several consecutive EXACTish nodes into one. */
400 regnode *n = regnext(scan);
403 regnode *stop = scan;
406 next = scan + NODE_SZ_STR(scan);
407 /* Skip NOTHING, merge EXACT*. */
409 ( PL_regkind[(U8)OP(n)] == NOTHING ||
410 (stringok && (OP(n) == OP(scan))))
412 && NEXT_OFF(scan) + NEXT_OFF(n) < I16_MAX) {
413 if (OP(n) == TAIL || n > next)
415 if (PL_regkind[(U8)OP(n)] == NOTHING) {
416 NEXT_OFF(scan) += NEXT_OFF(n);
417 next = n + NODE_STEP_REGNODE;
425 int oldl = STR_LEN(scan);
426 regnode *nnext = regnext(n);
428 if (oldl + STR_LEN(n) > U8_MAX)
430 NEXT_OFF(scan) += NEXT_OFF(n);
431 STR_LEN(scan) += STR_LEN(n);
432 next = n + NODE_SZ_STR(n);
433 /* Now we can overwrite *n : */
434 Move(STRING(n), STRING(scan) + oldl,
445 n = scan + NODE_SZ_STR(scan);
447 if (PL_regkind[(U8)OP(n)] != NOTHING || OP(n) == NOTHING) {
455 /* Follow the next-chain of the current node and optimize
456 away all the NOTHINGs from it. */
457 if (OP(scan) != CURLYX) {
458 int max = (reg_off_by_arg[OP(scan)]
460 /* I32 may be smaller than U16 on CRAYs! */
461 : (I32_MAX < U16_MAX ? I32_MAX : U16_MAX));
462 int off = (reg_off_by_arg[OP(scan)] ? ARG(scan) : NEXT_OFF(scan));
466 /* Skip NOTHING and LONGJMP. */
467 while ((n = regnext(n))
468 && ((PL_regkind[(U8)OP(n)] == NOTHING && (noff = NEXT_OFF(n)))
469 || ((OP(n) == LONGJMP) && (noff = ARG(n))))
472 if (reg_off_by_arg[OP(scan)])
475 NEXT_OFF(scan) = off;
477 /* The principal pseudo-switch. Cannot be a switch, since we
478 look into several different things. */
479 if (OP(scan) == BRANCH || OP(scan) == BRANCHJ
480 || OP(scan) == IFTHEN || OP(scan) == SUSPEND) {
481 next = regnext(scan);
484 if (OP(next) == code || code == IFTHEN || code == SUSPEND) {
485 I32 max1 = 0, min1 = I32_MAX, num = 0;
486 struct regnode_charclass_class accum;
488 if (flags & SCF_DO_SUBSTR) /* XXXX Add !SUSPEND? */
489 scan_commit(data); /* Cannot merge strings after this. */
490 if (flags & SCF_DO_STCLASS)
491 cl_init_zero(&accum);
492 while (OP(scan) == code) {
493 I32 deltanext, minnext, f = 0;
494 struct regnode_charclass_class this_class;
499 data_fake.whilem_c = data->whilem_c;
500 next = regnext(scan);
501 scan = NEXTOPER(scan);
503 scan = NEXTOPER(scan);
504 if (flags & SCF_DO_STCLASS) {
505 cl_init(&this_class);
506 data_fake.start_class = &this_class;
507 f = SCF_DO_STCLASS_AND;
509 /* we suppose the run is continuous, last=next...*/
510 minnext = study_chunk(&scan, &deltanext, next,
514 if (max1 < minnext + deltanext)
515 max1 = minnext + deltanext;
516 if (deltanext == I32_MAX)
517 is_inf = is_inf_internal = 1;
519 if (data_fake.flags & (SF_HAS_PAR|SF_IN_PAR))
521 if (data && (data_fake.flags & SF_HAS_EVAL))
522 data->flags |= SF_HAS_EVAL;
524 data->whilem_c = data_fake.whilem_c;
525 if (flags & SCF_DO_STCLASS)
526 cl_or(&accum, &this_class);
530 if (code == IFTHEN && num < 2) /* Empty ELSE branch */
532 if (flags & SCF_DO_SUBSTR) {
533 data->pos_min += min1;
534 data->pos_delta += max1 - min1;
535 if (max1 != min1 || is_inf)
536 data->longest = &(data->longest_float);
539 delta += max1 - min1;
540 if (flags & SCF_DO_STCLASS_OR) {
541 cl_or(data->start_class, &accum);
543 cl_and(data->start_class, &and_with);
544 flags &= ~SCF_DO_STCLASS;
547 else if (flags & SCF_DO_STCLASS_AND) {
549 cl_and(data->start_class, &accum);
550 flags &= ~SCF_DO_STCLASS;
553 /* Switch to OR mode: cache the old value of
554 * data->start_class */
555 StructCopy(data->start_class, &and_with,
556 struct regnode_charclass_class);
557 flags &= ~SCF_DO_STCLASS_AND;
558 StructCopy(&accum, data->start_class,
559 struct regnode_charclass_class);
560 flags |= SCF_DO_STCLASS_OR;
561 data->start_class->flags |= ANYOF_EOS;
565 else if (code == BRANCHJ) /* single branch is optimized. */
566 scan = NEXTOPER(NEXTOPER(scan));
567 else /* single branch is optimized. */
568 scan = NEXTOPER(scan);
571 else if (OP(scan) == EXACT) {
572 I32 l = STR_LEN(scan);
574 unsigned char *s = (unsigned char *)STRING(scan);
575 unsigned char *e = s + l;
584 if (flags & SCF_DO_SUBSTR) { /* Update longest substr. */
585 /* The code below prefers earlier match for fixed
586 offset, later match for variable offset. */
587 if (data->last_end == -1) { /* Update the start info. */
588 data->last_start_min = data->pos_min;
589 data->last_start_max = is_inf
590 ? I32_MAX : data->pos_min + data->pos_delta;
592 sv_catpvn(data->last_found, STRING(scan), STR_LEN(scan));
593 data->last_end = data->pos_min + l;
594 data->pos_min += l; /* As in the first entry. */
595 data->flags &= ~SF_BEFORE_EOL;
597 if (flags & SCF_DO_STCLASS_AND) {
598 /* Check whether it is compatible with what we know already! */
601 if (!(data->start_class->flags & (ANYOF_CLASS | ANYOF_LOCALE))
602 && !ANYOF_BITMAP_TEST(data->start_class, *STRING(scan))
603 && (!(data->start_class->flags & ANYOF_FOLD)
604 || !ANYOF_BITMAP_TEST(data->start_class,
605 PL_fold[*STRING(scan)])))
607 ANYOF_CLASS_ZERO(data->start_class);
608 ANYOF_BITMAP_ZERO(data->start_class);
610 ANYOF_BITMAP_SET(data->start_class, *STRING(scan));
611 data->start_class->flags &= ~ANYOF_EOS;
613 else if (flags & SCF_DO_STCLASS_OR) {
614 /* false positive possible if the class is case-folded */
615 ANYOF_BITMAP_SET(data->start_class, *STRING(scan));
616 data->start_class->flags &= ~ANYOF_EOS;
617 cl_and(data->start_class, &and_with);
619 flags &= ~SCF_DO_STCLASS;
621 else if (PL_regkind[(U8)OP(scan)] == EXACT) { /* But OP != EXACT! */
622 I32 l = STR_LEN(scan);
624 /* Search for fixed substrings supports EXACT only. */
625 if (flags & SCF_DO_SUBSTR)
628 unsigned char *s = (unsigned char *)STRING(scan);
629 unsigned char *e = s + l;
638 if (data && (flags & SCF_DO_SUBSTR))
640 if (flags & SCF_DO_STCLASS_AND) {
641 /* Check whether it is compatible with what we know already! */
644 if (!(data->start_class->flags & (ANYOF_CLASS | ANYOF_LOCALE))
645 && !ANYOF_BITMAP_TEST(data->start_class, *STRING(scan))
646 && !ANYOF_BITMAP_TEST(data->start_class,
647 PL_fold[*STRING(scan)]))
649 ANYOF_CLASS_ZERO(data->start_class);
650 ANYOF_BITMAP_ZERO(data->start_class);
652 ANYOF_BITMAP_SET(data->start_class, *STRING(scan));
653 data->start_class->flags &= ~ANYOF_EOS;
654 data->start_class->flags |= ANYOF_FOLD;
655 if (OP(scan) == EXACTFL)
656 data->start_class->flags |= ANYOF_LOCALE;
659 else if (flags & SCF_DO_STCLASS_OR) {
660 if (data->start_class->flags & ANYOF_FOLD) {
661 /* false positive possible if the class is case-folded.
662 Assume that the locale settings are the same... */
663 ANYOF_BITMAP_SET(data->start_class, *STRING(scan));
664 data->start_class->flags &= ~ANYOF_EOS;
666 cl_and(data->start_class, &and_with);
668 flags &= ~SCF_DO_STCLASS;
670 else if (strchr((char*)PL_varies,OP(scan))) {
671 I32 mincount, maxcount, minnext, deltanext, pos_before, fl;
673 regnode *oscan = scan;
674 struct regnode_charclass_class this_class;
675 struct regnode_charclass_class *oclass = NULL;
677 switch (PL_regkind[(U8)OP(scan)]) {
678 case WHILEM: /* End of (?:...)* . */
679 scan = NEXTOPER(scan);
682 if (flags & (SCF_DO_SUBSTR | SCF_DO_STCLASS)) {
683 next = NEXTOPER(scan);
684 if (OP(next) == EXACT || (flags & SCF_DO_STCLASS)) {
686 maxcount = REG_INFTY;
687 next = regnext(scan);
688 scan = NEXTOPER(scan);
692 if (flags & SCF_DO_SUBSTR)
697 if (flags & SCF_DO_STCLASS) {
699 maxcount = REG_INFTY;
700 next = regnext(scan);
701 scan = NEXTOPER(scan);
704 is_inf = is_inf_internal = 1;
705 scan = regnext(scan);
706 if (flags & SCF_DO_SUBSTR) {
707 scan_commit(data); /* Cannot extend fixed substrings */
708 data->longest = &(data->longest_float);
710 goto optimize_curly_tail;
712 mincount = ARG1(scan);
713 maxcount = ARG2(scan);
714 next = regnext(scan);
715 scan = NEXTOPER(scan) + EXTRA_STEP_2ARGS;
717 if (flags & SCF_DO_SUBSTR) {
718 if (mincount == 0) scan_commit(data); /* Cannot extend fixed substrings */
719 pos_before = data->pos_min;
723 data->flags &= ~(SF_HAS_PAR|SF_IN_PAR|SF_HAS_EVAL);
725 data->flags |= SF_IS_INF;
727 if (flags & SCF_DO_STCLASS) {
728 cl_init(&this_class);
729 oclass = data->start_class;
730 data->start_class = &this_class;
731 f |= SCF_DO_STCLASS_AND;
732 f &= ~SCF_DO_STCLASS_OR;
735 /* This will finish on WHILEM, setting scan, or on NULL: */
736 minnext = study_chunk(&scan, &deltanext, last, data,
738 ? (f & ~SCF_DO_SUBSTR) : f);
740 if (flags & SCF_DO_STCLASS)
741 data->start_class = oclass;
742 if (mincount == 0 || minnext == 0) {
743 if (flags & SCF_DO_STCLASS_OR) {
744 cl_or(data->start_class, &this_class);
746 else if (flags & SCF_DO_STCLASS_AND) {
747 /* Switch to OR mode: cache the old value of
748 * data->start_class */
749 StructCopy(data->start_class, &and_with,
750 struct regnode_charclass_class);
751 flags &= ~SCF_DO_STCLASS_AND;
752 StructCopy(&this_class, data->start_class,
753 struct regnode_charclass_class);
754 flags |= SCF_DO_STCLASS_OR;
755 data->start_class->flags |= ANYOF_EOS;
757 } else { /* Non-zero len */
758 if (flags & SCF_DO_STCLASS_OR) {
759 cl_or(data->start_class, &this_class);
760 cl_and(data->start_class, &and_with);
762 else if (flags & SCF_DO_STCLASS_AND)
763 cl_and(data->start_class, &this_class);
764 flags &= ~SCF_DO_STCLASS;
766 if (!scan) /* It was not CURLYX, but CURLY. */
768 if (ckWARN(WARN_UNSAFE) && (minnext + deltanext == 0)
769 && !(data->flags & (SF_HAS_PAR|SF_IN_PAR))
770 && maxcount <= REG_INFTY/3) /* Complement check for big count */
771 Perl_warner(aTHX_ WARN_UNSAFE,
772 "Strange *+?{} on zero-length expression");
773 min += minnext * mincount;
774 is_inf_internal |= (maxcount == REG_INFTY
775 && (minnext + deltanext) > 0
776 || deltanext == I32_MAX);
777 is_inf |= is_inf_internal;
778 delta += (minnext + deltanext) * maxcount - minnext * mincount;
780 /* Try powerful optimization CURLYX => CURLYN. */
781 if ( OP(oscan) == CURLYX && data
782 && data->flags & SF_IN_PAR
783 && !(data->flags & SF_HAS_EVAL)
784 && !deltanext && minnext == 1 ) {
785 /* Try to optimize to CURLYN. */
786 regnode *nxt = NEXTOPER(oscan) + EXTRA_STEP_2ARGS;
787 regnode *nxt1 = nxt, *nxt2;
791 if (!strchr((char*)PL_simple,OP(nxt))
792 && !(PL_regkind[(U8)OP(nxt)] == EXACT
793 && STR_LEN(nxt) == 1))
797 if (OP(nxt) != CLOSE)
799 /* Now we know that nxt2 is the only contents: */
800 oscan->flags = ARG(nxt);
802 OP(nxt1) = NOTHING; /* was OPEN. */
804 OP(nxt1 + 1) = OPTIMIZED; /* was count. */
805 NEXT_OFF(nxt1+ 1) = 0; /* just for consistancy. */
806 NEXT_OFF(nxt2) = 0; /* just for consistancy with CURLY. */
807 OP(nxt) = OPTIMIZED; /* was CLOSE. */
808 OP(nxt + 1) = OPTIMIZED; /* was count. */
809 NEXT_OFF(nxt+ 1) = 0; /* just for consistancy. */
814 /* Try optimization CURLYX => CURLYM. */
815 if ( OP(oscan) == CURLYX && data
816 && !(data->flags & SF_HAS_PAR)
817 && !(data->flags & SF_HAS_EVAL)
819 /* XXXX How to optimize if data == 0? */
820 /* Optimize to a simpler form. */
821 regnode *nxt = NEXTOPER(oscan) + EXTRA_STEP_2ARGS; /* OPEN */
825 while ( (nxt2 = regnext(nxt)) /* skip over embedded stuff*/
826 && (OP(nxt2) != WHILEM))
828 OP(nxt2) = SUCCEED; /* Whas WHILEM */
829 /* Need to optimize away parenths. */
830 if (data->flags & SF_IN_PAR) {
831 /* Set the parenth number. */
832 regnode *nxt1 = NEXTOPER(oscan) + EXTRA_STEP_2ARGS; /* OPEN*/
834 if (OP(nxt) != CLOSE)
835 FAIL("panic opt close");
836 oscan->flags = ARG(nxt);
837 OP(nxt1) = OPTIMIZED; /* was OPEN. */
838 OP(nxt) = OPTIMIZED; /* was CLOSE. */
840 OP(nxt1 + 1) = OPTIMIZED; /* was count. */
841 OP(nxt + 1) = OPTIMIZED; /* was count. */
842 NEXT_OFF(nxt1 + 1) = 0; /* just for consistancy. */
843 NEXT_OFF(nxt + 1) = 0; /* just for consistancy. */
846 while ( nxt1 && (OP(nxt1) != WHILEM)) {
847 regnode *nnxt = regnext(nxt1);
850 if (reg_off_by_arg[OP(nxt1)])
851 ARG_SET(nxt1, nxt2 - nxt1);
852 else if (nxt2 - nxt1 < U16_MAX)
853 NEXT_OFF(nxt1) = nxt2 - nxt1;
855 OP(nxt) = NOTHING; /* Cannot beautify */
860 /* Optimize again: */
861 study_chunk(&nxt1, &deltanext, nxt, NULL, 0);
866 else if (OP(oscan) == CURLYX && data && ++data->whilem_c < 16) {
867 /* This stays as CURLYX, and can put the count/of pair. */
868 /* Find WHILEM (as in regexec.c) */
869 regnode *nxt = oscan + NEXT_OFF(oscan);
871 if (OP(PREVOPER(nxt)) == NOTHING) /* LONGJMP */
873 PREVOPER(nxt)->flags = data->whilem_c
874 | (PL_reg_whilem_seen << 4); /* On WHILEM */
876 if (data && fl & (SF_HAS_PAR|SF_IN_PAR))
878 if (flags & SCF_DO_SUBSTR) {
879 SV *last_str = Nullsv;
880 int counted = mincount != 0;
882 if (data->last_end > 0 && mincount != 0) { /* Ends with a string. */
883 I32 b = pos_before >= data->last_start_min
884 ? pos_before : data->last_start_min;
886 char *s = SvPV(data->last_found, l);
887 I32 old = b - data->last_start_min;
890 old = utf8_hop((U8*)s, old) - (U8*)s;
893 /* Get the added string: */
894 last_str = newSVpvn(s + old, l);
895 if (deltanext == 0 && pos_before == b) {
896 /* What was added is a constant string */
898 SvGROW(last_str, (mincount * l) + 1);
899 repeatcpy(SvPVX(last_str) + l,
900 SvPVX(last_str), l, mincount - 1);
901 SvCUR(last_str) *= mincount;
902 /* Add additional parts. */
903 SvCUR_set(data->last_found,
904 SvCUR(data->last_found) - l);
905 sv_catsv(data->last_found, last_str);
906 data->last_end += l * (mincount - 1);
910 /* It is counted once already... */
911 data->pos_min += minnext * (mincount - counted);
912 data->pos_delta += - counted * deltanext +
913 (minnext + deltanext) * maxcount - minnext * mincount;
914 if (mincount != maxcount) {
915 /* Cannot extend fixed substrings found inside
918 if (mincount && last_str) {
919 sv_setsv(data->last_found, last_str);
920 data->last_end = data->pos_min;
921 data->last_start_min =
922 data->pos_min - CHR_SVLEN(last_str);
923 data->last_start_max = is_inf
925 : data->pos_min + data->pos_delta
926 - CHR_SVLEN(last_str);
928 data->longest = &(data->longest_float);
930 SvREFCNT_dec(last_str);
932 if (data && (fl & SF_HAS_EVAL))
933 data->flags |= SF_HAS_EVAL;
935 if (OP(oscan) != CURLYX) {
936 while (PL_regkind[(U8)OP(next = regnext(oscan))] == NOTHING
938 NEXT_OFF(oscan) += NEXT_OFF(next);
941 default: /* REF and CLUMP only? */
942 if (flags & SCF_DO_SUBSTR) {
943 scan_commit(data); /* Cannot expect anything... */
944 data->longest = &(data->longest_float);
946 is_inf = is_inf_internal = 1;
947 if (flags & SCF_DO_STCLASS_OR)
948 cl_anything(data->start_class);
949 flags &= ~SCF_DO_STCLASS;
953 else if (strchr((char*)PL_simple,OP(scan)) || PL_regkind[(U8)OP(scan)] == ANYUTF8) {
956 if (flags & SCF_DO_SUBSTR) {
961 if (flags & SCF_DO_STCLASS) {
962 data->start_class->flags &= ~ANYOF_EOS; /* No match on empty */
964 /* Some of the logic below assumes that switching
965 locale on will only add false positives. */
966 switch (PL_regkind[(U8)OP(scan)]) {
983 /* Perl_croak(aTHX_ "panic: unexpected simple REx opcode %d", OP(scan)); */
984 if (flags & SCF_DO_STCLASS_OR) /* Allow everything */
985 cl_anything(data->start_class);
988 if (OP(scan) == SANY)
990 if (flags & SCF_DO_STCLASS_OR) { /* Everything but \n */
991 value = (ANYOF_BITMAP_TEST(data->start_class,'\n')
992 || (data->start_class->flags & ANYOF_CLASS));
993 cl_anything(data->start_class);
995 if (flags & SCF_DO_STCLASS_AND || !value)
996 ANYOF_BITMAP_CLEAR(data->start_class,'\n');
999 if (flags & SCF_DO_STCLASS_AND)
1000 cl_and(data->start_class,
1001 (struct regnode_charclass_class*)scan);
1003 cl_or(data->start_class,
1004 (struct regnode_charclass_class*)scan);
1007 if (flags & SCF_DO_STCLASS_AND) {
1008 if (!(data->start_class->flags & ANYOF_LOCALE)) {
1009 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_NALNUM);
1010 for (value = 0; value < 256; value++)
1011 if (!isALNUM(value))
1012 ANYOF_BITMAP_CLEAR(data->start_class, value);
1016 if (data->start_class->flags & ANYOF_LOCALE)
1017 ANYOF_CLASS_SET(data->start_class,ANYOF_ALNUM);
1019 for (value = 0; value < 256; value++)
1021 ANYOF_BITMAP_SET(data->start_class, value);
1026 if (flags & SCF_DO_STCLASS_AND) {
1027 if (data->start_class->flags & ANYOF_LOCALE)
1028 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_NALNUM);
1031 ANYOF_CLASS_SET(data->start_class,ANYOF_ALNUM);
1032 data->start_class->flags |= ANYOF_LOCALE;
1036 if (flags & SCF_DO_STCLASS_AND) {
1037 if (!(data->start_class->flags & ANYOF_LOCALE)) {
1038 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_ALNUM);
1039 for (value = 0; value < 256; value++)
1041 ANYOF_BITMAP_CLEAR(data->start_class, value);
1045 if (data->start_class->flags & ANYOF_LOCALE)
1046 ANYOF_CLASS_SET(data->start_class,ANYOF_NALNUM);
1048 for (value = 0; value < 256; value++)
1049 if (!isALNUM(value))
1050 ANYOF_BITMAP_SET(data->start_class, value);
1055 if (flags & SCF_DO_STCLASS_AND) {
1056 if (data->start_class->flags & ANYOF_LOCALE)
1057 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_ALNUM);
1060 data->start_class->flags |= ANYOF_LOCALE;
1061 ANYOF_CLASS_SET(data->start_class,ANYOF_NALNUM);
1065 if (flags & SCF_DO_STCLASS_AND) {
1066 if (!(data->start_class->flags & ANYOF_LOCALE)) {
1067 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_NSPACE);
1068 for (value = 0; value < 256; value++)
1069 if (!isSPACE(value))
1070 ANYOF_BITMAP_CLEAR(data->start_class, value);
1074 if (data->start_class->flags & ANYOF_LOCALE)
1075 ANYOF_CLASS_SET(data->start_class,ANYOF_SPACE);
1077 for (value = 0; value < 256; value++)
1079 ANYOF_BITMAP_SET(data->start_class, value);
1084 if (flags & SCF_DO_STCLASS_AND) {
1085 if (data->start_class->flags & ANYOF_LOCALE)
1086 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_NSPACE);
1089 data->start_class->flags |= ANYOF_LOCALE;
1090 ANYOF_CLASS_SET(data->start_class,ANYOF_SPACE);
1094 if (flags & SCF_DO_STCLASS_AND) {
1095 if (!(data->start_class->flags & ANYOF_LOCALE)) {
1096 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_SPACE);
1097 for (value = 0; value < 256; value++)
1099 ANYOF_BITMAP_CLEAR(data->start_class, value);
1103 if (data->start_class->flags & ANYOF_LOCALE)
1104 ANYOF_CLASS_SET(data->start_class,ANYOF_NSPACE);
1106 for (value = 0; value < 256; value++)
1107 if (!isSPACE(value))
1108 ANYOF_BITMAP_SET(data->start_class, value);
1113 if (flags & SCF_DO_STCLASS_AND) {
1114 if (data->start_class->flags & ANYOF_LOCALE) {
1115 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_SPACE);
1116 for (value = 0; value < 256; value++)
1117 if (!isSPACE(value))
1118 ANYOF_BITMAP_CLEAR(data->start_class, value);
1122 data->start_class->flags |= ANYOF_LOCALE;
1123 ANYOF_CLASS_SET(data->start_class,ANYOF_NSPACE);
1127 if (flags & SCF_DO_STCLASS_AND) {
1128 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_NDIGIT);
1129 for (value = 0; value < 256; value++)
1130 if (!isDIGIT(value))
1131 ANYOF_BITMAP_CLEAR(data->start_class, value);
1134 if (data->start_class->flags & ANYOF_LOCALE)
1135 ANYOF_CLASS_SET(data->start_class,ANYOF_DIGIT);
1137 for (value = 0; value < 256; value++)
1139 ANYOF_BITMAP_SET(data->start_class, value);
1144 if (flags & SCF_DO_STCLASS_AND) {
1145 ANYOF_CLASS_CLEAR(data->start_class,ANYOF_DIGIT);
1146 for (value = 0; value < 256; value++)
1148 ANYOF_BITMAP_CLEAR(data->start_class, value);
1151 if (data->start_class->flags & ANYOF_LOCALE)
1152 ANYOF_CLASS_SET(data->start_class,ANYOF_NDIGIT);
1154 for (value = 0; value < 256; value++)
1155 if (!isDIGIT(value))
1156 ANYOF_BITMAP_SET(data->start_class, value);
1161 if (flags & SCF_DO_STCLASS_OR)
1162 cl_and(data->start_class, &and_with);
1163 flags &= ~SCF_DO_STCLASS;
1166 else if (PL_regkind[(U8)OP(scan)] == EOL && flags & SCF_DO_SUBSTR) {
1167 data->flags |= (OP(scan) == MEOL
1171 else if ( PL_regkind[(U8)OP(scan)] == BRANCHJ
1172 /* Lookbehind, or need to calculate parens/evals/stclass: */
1173 && (scan->flags || data || (flags & SCF_DO_STCLASS))
1174 && (OP(scan) == IFMATCH || OP(scan) == UNLESSM)) {
1175 /* Lookahead/lookbehind */
1176 I32 deltanext, minnext;
1178 struct regnode_charclass_class intrnl;
1181 data_fake.flags = 0;
1183 data_fake.whilem_c = data->whilem_c;
1184 if ( flags & SCF_DO_STCLASS && !scan->flags
1185 && OP(scan) == IFMATCH ) { /* Lookahead */
1187 data_fake.start_class = &intrnl;
1188 f = SCF_DO_STCLASS_AND;
1190 next = regnext(scan);
1191 nscan = NEXTOPER(NEXTOPER(scan));
1192 minnext = study_chunk(&nscan, &deltanext, last, &data_fake, f);
1195 FAIL("variable length lookbehind not implemented");
1197 else if (minnext > U8_MAX) {
1198 FAIL2("lookbehind longer than %"UVuf" not implemented", (UV)U8_MAX);
1200 scan->flags = minnext;
1202 if (data && data_fake.flags & (SF_HAS_PAR|SF_IN_PAR))
1204 if (data && (data_fake.flags & SF_HAS_EVAL))
1205 data->flags |= SF_HAS_EVAL;
1207 data->whilem_c = data_fake.whilem_c;
1209 int was = (data->start_class->flags & ANYOF_EOS);
1211 cl_and(data->start_class, &intrnl);
1213 data->start_class->flags |= ANYOF_EOS;
1216 else if (OP(scan) == OPEN) {
1219 else if (OP(scan) == CLOSE && ARG(scan) == is_par) {
1220 next = regnext(scan);
1222 if ( next && (OP(next) != WHILEM) && next < last)
1223 is_par = 0; /* Disable optimization */
1225 else if (OP(scan) == EVAL) {
1227 data->flags |= SF_HAS_EVAL;
1229 else if (OP(scan) == LOGICAL && scan->flags == 2) { /* Embedded */
1230 if (flags & SCF_DO_SUBSTR) {
1232 data->longest = &(data->longest_float);
1234 is_inf = is_inf_internal = 1;
1235 if (flags & SCF_DO_STCLASS_OR) /* Allow everything */
1236 cl_anything(data->start_class);
1238 /* Else: zero-length, ignore. */
1239 scan = regnext(scan);
1244 *deltap = is_inf_internal ? I32_MAX : delta;
1245 if (flags & SCF_DO_SUBSTR && is_inf)
1246 data->pos_delta = I32_MAX - data->pos_min;
1247 if (is_par > U8_MAX)
1249 if (is_par && pars==1 && data) {
1250 data->flags |= SF_IN_PAR;
1251 data->flags &= ~SF_HAS_PAR;
1253 else if (pars && data) {
1254 data->flags |= SF_HAS_PAR;
1255 data->flags &= ~SF_IN_PAR;
1257 if (flags & SCF_DO_STCLASS_OR)
1258 cl_and(data->start_class, &and_with);
1263 S_add_data(pTHX_ I32 n, char *s)
1266 if (PL_regcomp_rx->data) {
1267 Renewc(PL_regcomp_rx->data,
1268 sizeof(*PL_regcomp_rx->data) + sizeof(void*) * (PL_regcomp_rx->data->count + n - 1),
1269 char, struct reg_data);
1270 Renew(PL_regcomp_rx->data->what, PL_regcomp_rx->data->count + n, U8);
1271 PL_regcomp_rx->data->count += n;
1274 Newc(1207, PL_regcomp_rx->data, sizeof(*PL_regcomp_rx->data) + sizeof(void*) * (n - 1),
1275 char, struct reg_data);
1276 New(1208, PL_regcomp_rx->data->what, n, U8);
1277 PL_regcomp_rx->data->count = n;
1279 Copy(s, PL_regcomp_rx->data->what + PL_regcomp_rx->data->count - n, n, U8);
1280 return PL_regcomp_rx->data->count - n;
1284 Perl_reginitcolors(pTHX)
1288 char *s = PerlEnv_getenv("PERL_RE_COLORS");
1291 PL_colors[0] = s = savepv(s);
1293 s = strchr(s, '\t');
1299 PL_colors[i] = s = "";
1303 PL_colors[i++] = "";
1309 - pregcomp - compile a regular expression into internal code
1311 * We can't allocate space until we know how big the compiled form will be,
1312 * but we can't compile it (and thus know how big it is) until we've got a
1313 * place to put the code. So we cheat: we compile it twice, once with code
1314 * generation turned off and size counting turned on, and once "for real".
1315 * This also means that we don't allocate space until we are sure that the
1316 * thing really will compile successfully, and we never have to move the
1317 * code and thus invalidate pointers into it. (Note that it has to be in
1318 * one piece because free() must be able to free it all.) [NB: not true in perl]
1320 * Beware that the optimization-preparation code in here knows about some
1321 * of the structure of the compiled regexp. [I'll say.]
1324 Perl_pregcomp(pTHX_ char *exp, char *xend, PMOP *pm)
1340 FAIL("NULL regexp argument");
1342 if (PL_curcop == &PL_compiling ? (PL_hints & HINT_UTF8) : IN_UTF8)
1343 PL_reg_flags |= RF_utf8;
1347 PL_regprecomp = savepvn(exp, xend - exp);
1348 DEBUG_r(if (!PL_colorset) reginitcolors());
1349 DEBUG_r(PerlIO_printf(Perl_debug_log, "%sCompiling REx%s `%s%*s%s'\n",
1350 PL_colors[4],PL_colors[5],PL_colors[0],
1351 (int)(xend - exp), PL_regprecomp, PL_colors[1]));
1352 PL_regflags = pm->op_pmflags;
1356 PL_seen_zerolen = *exp == '^' ? -1 : 0;
1360 /* First pass: determine size, legality. */
1361 PL_regcomp_parse = exp;
1366 PL_regcode = &PL_regdummy;
1367 PL_reg_whilem_seen = 0;
1368 REGC((U8)REG_MAGIC, (char*)PL_regcode);
1369 if (reg(0, &flags) == NULL) {
1370 Safefree(PL_regprecomp);
1371 PL_regprecomp = Nullch;
1374 DEBUG_r(PerlIO_printf(Perl_debug_log, "size %"IVdf" ", (IV)PL_regsize));
1376 /* Small enough for pointer-storage convention?
1377 If extralen==0, this means that we will not need long jumps. */
1378 if (PL_regsize >= 0x10000L && PL_extralen)
1379 PL_regsize += PL_extralen;
1382 if (PL_reg_whilem_seen > 15)
1383 PL_reg_whilem_seen = 15;
1385 /* Allocate space and initialize. */
1386 Newc(1001, r, sizeof(regexp) + (unsigned)PL_regsize * sizeof(regnode),
1389 FAIL("regexp out of space");
1391 r->prelen = xend - exp;
1392 r->precomp = PL_regprecomp;
1394 r->reganch = pm->op_pmflags & PMf_COMPILETIME;
1395 r->nparens = PL_regnpar - 1; /* set early to validate backrefs */
1397 r->substrs = 0; /* Useful during FAIL. */
1398 r->startp = 0; /* Useful during FAIL. */
1399 r->endp = 0; /* Useful during FAIL. */
1403 /* Second pass: emit code. */
1404 PL_regcomp_parse = exp;
1408 PL_regcode = r->program;
1409 /* Store the count of eval-groups for security checks: */
1410 PL_regcode->next_off = ((PL_seen_evals > U16_MAX) ? U16_MAX : PL_seen_evals);
1411 REGC((U8)REG_MAGIC, (char*) PL_regcode++);
1413 if (reg(0, &flags) == NULL)
1416 /* Dig out information for optimizations. */
1417 r->reganch = pm->op_pmflags & PMf_COMPILETIME; /* Again? */
1418 pm->op_pmflags = PL_regflags;
1420 r->reganch |= ROPT_UTF8;
1421 r->regstclass = NULL;
1422 if (PL_regnaughty >= 10) /* Probably an expensive pattern. */
1423 r->reganch |= ROPT_NAUGHTY;
1424 scan = r->program + 1; /* First BRANCH. */
1426 /* XXXX To minimize changes to RE engine we always allocate
1427 3-units-long substrs field. */
1428 Newz(1004, r->substrs, 1, struct reg_substr_data);
1430 StructCopy(&zero_scan_data, &data, scan_data_t);
1431 /* XXXX Should not we check for something else? Usually it is OPEN1... */
1432 if (OP(scan) != BRANCH) { /* Only one top-level choice. */
1434 STRLEN longest_float_length, longest_fixed_length;
1435 struct regnode_charclass_class ch_class;
1439 /* Skip introductions and multiplicators >= 1. */
1440 while ((OP(first) == OPEN && (sawopen = 1)) ||
1441 /* An OR of *one* alternative - should not happen now. */
1442 (OP(first) == BRANCH && OP(regnext(first)) != BRANCH) ||
1443 (OP(first) == PLUS) ||
1444 (OP(first) == MINMOD) ||
1445 /* An {n,m} with n>0 */
1446 (PL_regkind[(U8)OP(first)] == CURLY && ARG1(first) > 0) ) {
1447 if (OP(first) == PLUS)
1450 first += regarglen[(U8)OP(first)];
1451 first = NEXTOPER(first);
1454 /* Starting-point info. */
1456 if (PL_regkind[(U8)OP(first)] == EXACT) {
1457 if (OP(first) == EXACT); /* Empty, get anchored substr later. */
1458 else if ((OP(first) == EXACTF || OP(first) == EXACTFL)
1460 r->regstclass = first;
1462 else if (strchr((char*)PL_simple,OP(first)))
1463 r->regstclass = first;
1464 else if (PL_regkind[(U8)OP(first)] == BOUND ||
1465 PL_regkind[(U8)OP(first)] == NBOUND)
1466 r->regstclass = first;
1467 else if (PL_regkind[(U8)OP(first)] == BOL) {
1468 r->reganch |= (OP(first) == MBOL
1470 : (OP(first) == SBOL
1473 first = NEXTOPER(first);
1476 else if (OP(first) == GPOS) {
1477 r->reganch |= ROPT_ANCH_GPOS;
1478 first = NEXTOPER(first);
1481 else if ((OP(first) == STAR &&
1482 PL_regkind[(U8)OP(NEXTOPER(first))] == REG_ANY) &&
1483 !(r->reganch & ROPT_ANCH) )
1485 /* turn .* into ^.* with an implied $*=1 */
1486 int type = OP(NEXTOPER(first));
1488 if (type == REG_ANY || type == ANYUTF8)
1489 type = ROPT_ANCH_MBOL;
1491 type = ROPT_ANCH_SBOL;
1493 r->reganch |= type | ROPT_IMPLICIT;
1494 first = NEXTOPER(first);
1497 if (sawplus && (!sawopen || !PL_regsawback)
1498 && !(PL_regseen & REG_SEEN_EVAL)) /* May examine pos and $& */
1499 /* x+ must match at the 1st pos of run of x's */
1500 r->reganch |= ROPT_SKIP;
1502 /* Scan is after the zeroth branch, first is atomic matcher. */
1503 DEBUG_r(PerlIO_printf(Perl_debug_log, "first at %"IVdf"\n",
1504 (IV)(first - scan + 1)));
1506 * If there's something expensive in the r.e., find the
1507 * longest literal string that must appear and make it the
1508 * regmust. Resolve ties in favor of later strings, since
1509 * the regstart check works with the beginning of the r.e.
1510 * and avoiding duplication strengthens checking. Not a
1511 * strong reason, but sufficient in the absence of others.
1512 * [Now we resolve ties in favor of the earlier string if
1513 * it happens that c_offset_min has been invalidated, since the
1514 * earlier string may buy us something the later one won't.]
1518 data.longest_fixed = newSVpvn("",0);
1519 data.longest_float = newSVpvn("",0);
1520 data.last_found = newSVpvn("",0);
1521 data.longest = &(data.longest_fixed);
1523 if (!r->regstclass) {
1525 data.start_class = &ch_class;
1526 stclass_flag = SCF_DO_STCLASS_AND;
1527 } else /* XXXX Check for BOUND? */
1530 minlen = study_chunk(&first, &fake, scan + PL_regsize, /* Up to end */
1531 &data, SCF_DO_SUBSTR | stclass_flag);
1532 if ( PL_regnpar == 1 && data.longest == &(data.longest_fixed)
1533 && data.last_start_min == 0 && data.last_end > 0
1535 && (!(PL_regseen & REG_SEEN_GPOS) || (r->reganch & ROPT_ANCH_GPOS)))
1536 r->reganch |= ROPT_CHECK_ALL;
1538 SvREFCNT_dec(data.last_found);
1540 longest_float_length = CHR_SVLEN(data.longest_float);
1541 if (longest_float_length
1542 || (data.flags & SF_FL_BEFORE_EOL
1543 && (!(data.flags & SF_FL_BEFORE_MEOL)
1544 || (PL_regflags & PMf_MULTILINE)))) {
1547 if (SvCUR(data.longest_fixed) /* ok to leave SvCUR */
1548 && data.offset_fixed == data.offset_float_min
1549 && SvCUR(data.longest_fixed) == SvCUR(data.longest_float))
1550 goto remove_float; /* As in (a)+. */
1552 r->float_substr = data.longest_float;
1553 r->float_min_offset = data.offset_float_min;
1554 r->float_max_offset = data.offset_float_max;
1555 t = (data.flags & SF_FL_BEFORE_EOL /* Can't have SEOL and MULTI */
1556 && (!(data.flags & SF_FL_BEFORE_MEOL)
1557 || (PL_regflags & PMf_MULTILINE)));
1558 fbm_compile(r->float_substr, t ? FBMcf_TAIL : 0);
1562 r->float_substr = Nullsv;
1563 SvREFCNT_dec(data.longest_float);
1564 longest_float_length = 0;
1567 longest_fixed_length = CHR_SVLEN(data.longest_fixed);
1568 if (longest_fixed_length
1569 || (data.flags & SF_FIX_BEFORE_EOL /* Cannot have SEOL and MULTI */
1570 && (!(data.flags & SF_FIX_BEFORE_MEOL)
1571 || (PL_regflags & PMf_MULTILINE)))) {
1574 r->anchored_substr = data.longest_fixed;
1575 r->anchored_offset = data.offset_fixed;
1576 t = (data.flags & SF_FIX_BEFORE_EOL /* Can't have SEOL and MULTI */
1577 && (!(data.flags & SF_FIX_BEFORE_MEOL)
1578 || (PL_regflags & PMf_MULTILINE)));
1579 fbm_compile(r->anchored_substr, t ? FBMcf_TAIL : 0);
1582 r->anchored_substr = Nullsv;
1583 SvREFCNT_dec(data.longest_fixed);
1584 longest_fixed_length = 0;
1587 && (OP(r->regstclass) == REG_ANY || OP(r->regstclass) == ANYUTF8
1588 || OP(r->regstclass) == SANYUTF8 || OP(r->regstclass) == SANY))
1589 r->regstclass = NULL;
1590 if ((!r->anchored_substr || r->anchored_offset) && stclass_flag
1591 && !(data.start_class->flags & ANYOF_EOS)
1592 && !cl_is_anything(data.start_class)) {
1594 I32 n = add_data(1, "f");
1596 New(1006, PL_regcomp_rx->data->data[n], 1,
1597 struct regnode_charclass_class);
1598 StructCopy(data.start_class,
1599 (struct regnode_charclass_class*)PL_regcomp_rx->data->data[n],
1600 struct regnode_charclass_class);
1601 r->regstclass = (regnode*)PL_regcomp_rx->data->data[n];
1602 r->reganch &= ~ROPT_SKIP; /* Used in find_byclass(). */
1603 DEBUG_r((sv = sv_newmortal(),
1604 regprop(sv, (regnode*)data.start_class),
1605 PerlIO_printf(Perl_debug_log, "synthetic stclass.\n",
1609 /* A temporary algorithm prefers floated substr to fixed one to dig more info. */
1610 if (longest_fixed_length > longest_float_length) {
1611 r->check_substr = r->anchored_substr;
1612 r->check_offset_min = r->check_offset_max = r->anchored_offset;
1613 if (r->reganch & ROPT_ANCH_SINGLE)
1614 r->reganch |= ROPT_NOSCAN;
1617 r->check_substr = r->float_substr;
1618 r->check_offset_min = data.offset_float_min;
1619 r->check_offset_max = data.offset_float_max;
1621 /* XXXX Currently intuiting is not compatible with ANCH_GPOS.
1622 This should be changed ASAP! */
1623 if (r->check_substr && !(r->reganch & ROPT_ANCH_GPOS)) {
1624 r->reganch |= RE_USE_INTUIT;
1625 if (SvTAIL(r->check_substr))
1626 r->reganch |= RE_INTUIT_TAIL;
1630 /* Several toplevels. Best we can is to set minlen. */
1632 struct regnode_charclass_class ch_class;
1634 DEBUG_r(PerlIO_printf(Perl_debug_log, "\n"));
1635 scan = r->program + 1;
1637 data.start_class = &ch_class;
1638 minlen = study_chunk(&scan, &fake, scan + PL_regsize, &data, SCF_DO_STCLASS_AND);
1639 r->check_substr = r->anchored_substr = r->float_substr = Nullsv;
1640 if (!(data.start_class->flags & ANYOF_EOS)
1641 && !cl_is_anything(data.start_class)) {
1643 I32 n = add_data(1, "f");
1645 New(1006, PL_regcomp_rx->data->data[n], 1,
1646 struct regnode_charclass_class);
1647 StructCopy(data.start_class,
1648 (struct regnode_charclass_class*)PL_regcomp_rx->data->data[n],
1649 struct regnode_charclass_class);
1650 r->regstclass = (regnode*)PL_regcomp_rx->data->data[n];
1651 r->reganch &= ~ROPT_SKIP; /* Used in find_byclass(). */
1652 DEBUG_r((sv = sv_newmortal(),
1653 regprop(sv, (regnode*)data.start_class),
1654 PerlIO_printf(Perl_debug_log, "synthetic stclass.\n",
1660 if (PL_regseen & REG_SEEN_GPOS)
1661 r->reganch |= ROPT_GPOS_SEEN;
1662 if (PL_regseen & REG_SEEN_LOOKBEHIND)
1663 r->reganch |= ROPT_LOOKBEHIND_SEEN;
1664 if (PL_regseen & REG_SEEN_EVAL)
1665 r->reganch |= ROPT_EVAL_SEEN;
1666 Newz(1002, r->startp, PL_regnpar, I32);
1667 Newz(1002, r->endp, PL_regnpar, I32);
1668 DEBUG_r(regdump(r));
1673 - reg - regular expression, i.e. main body or parenthesized thing
1675 * Caller must absorb opening parenthesis.
1677 * Combining parenthesis handling with the base level of regular expression
1678 * is a trifle forced, but the need to tie the tails of the branches to what
1679 * follows makes it hard to avoid.
1682 S_reg(pTHX_ I32 paren, I32 *flagp)
1683 /* paren: Parenthesized? 0=top, 1=(, inside: changed to letter. */
1686 register regnode *ret; /* Will be the head of the group. */
1687 register regnode *br;
1688 register regnode *lastbr;
1689 register regnode *ender = 0;
1690 register I32 parno = 0;
1691 I32 flags, oregflags = PL_regflags, have_branch = 0, open = 0;
1694 *flagp = 0; /* Tentatively. */
1696 /* Make an OPEN node, if parenthesized. */
1698 if (*PL_regcomp_parse == '?') {
1699 U16 posflags = 0, negflags = 0;
1700 U16 *flagsp = &posflags;
1704 paren = *PL_regcomp_parse++;
1705 ret = NULL; /* For look-ahead/behind. */
1708 PL_regseen |= REG_SEEN_LOOKBEHIND;
1709 if (*PL_regcomp_parse == '!')
1711 if (*PL_regcomp_parse != '=' && *PL_regcomp_parse != '!')
1722 FAIL2("Sequence (?%c...) not implemented", (int)paren);
1725 while (*PL_regcomp_parse && *PL_regcomp_parse != ')')
1727 if (*PL_regcomp_parse != ')')
1728 FAIL("Sequence (?#... not terminated");
1734 paren = *PL_regcomp_parse++;
1739 I32 count = 1, n = 0;
1741 char *s = PL_regcomp_parse;
1743 OP_4tree *sop, *rop;
1746 PL_regseen |= REG_SEEN_EVAL;
1747 while (count && (c = *PL_regcomp_parse)) {
1748 if (c == '\\' && PL_regcomp_parse[1])
1756 if (*PL_regcomp_parse != ')')
1757 FAIL("Sequence (?{...}) not terminated or not {}-balanced");
1761 if (PL_regcomp_parse - 1 - s)
1762 sv = newSVpvn(s, PL_regcomp_parse - 1 - s);
1764 sv = newSVpvn("", 0);
1766 rop = sv_compile_2op(sv, &sop, "re", &av);
1768 n = add_data(3, "nop");
1769 PL_regcomp_rx->data->data[n] = (void*)rop;
1770 PL_regcomp_rx->data->data[n+1] = (void*)sop;
1771 PL_regcomp_rx->data->data[n+2] = (void*)av;
1774 else { /* First pass */
1775 if (PL_reginterp_cnt < ++PL_seen_evals
1776 && PL_curcop != &PL_compiling)
1777 /* No compiled RE interpolated, has runtime
1778 components ===> unsafe. */
1779 FAIL("Eval-group not allowed at runtime, use re 'eval'");
1781 FAIL("Eval-group in insecure regular expression");
1786 ret = reg_node(LOGICAL);
1789 regtail(ret, reganode(EVAL, n));
1792 return reganode(EVAL, n);
1796 if (PL_regcomp_parse[0] == '?') {
1797 if (PL_regcomp_parse[1] == '=' || PL_regcomp_parse[1] == '!'
1798 || PL_regcomp_parse[1] == '<'
1799 || PL_regcomp_parse[1] == '{') { /* Lookahead or eval. */
1802 ret = reg_node(LOGICAL);
1805 regtail(ret, reg(1, &flag));
1809 else if (PL_regcomp_parse[0] >= '1' && PL_regcomp_parse[0] <= '9' ) {
1810 parno = atoi(PL_regcomp_parse++);
1812 while (isDIGIT(*PL_regcomp_parse))
1814 ret = reganode(GROUPP, parno);
1815 if ((c = *nextchar()) != ')')
1816 FAIL2("Switch (?(number%c not recognized", c);
1818 regtail(ret, reganode(IFTHEN, 0));
1819 br = regbranch(&flags, 1);
1821 br = reganode(LONGJMP, 0);
1823 regtail(br, reganode(LONGJMP, 0));
1828 lastbr = reganode(IFTHEN, 0); /* Fake one for optimizer. */
1829 regbranch(&flags, 1);
1830 regtail(ret, lastbr);
1838 FAIL("Switch (?(condition)... contains too many branches");
1839 ender = reg_node(TAIL);
1842 regtail(lastbr, ender);
1843 regtail(NEXTOPER(NEXTOPER(lastbr)), ender);
1846 regtail(ret, ender);
1850 FAIL2("Unknown condition for (?(%.2s", PL_regcomp_parse);
1854 FAIL("Sequence (? incomplete");
1859 while (*PL_regcomp_parse && strchr("iogcmsx", *PL_regcomp_parse)) {
1860 if (*PL_regcomp_parse != 'o')
1861 pmflag(flagsp, *PL_regcomp_parse);
1864 if (*PL_regcomp_parse == '-') {
1869 PL_regflags |= posflags;
1870 PL_regflags &= ~negflags;
1871 if (*PL_regcomp_parse == ':') {
1877 if (*PL_regcomp_parse != ')')
1878 FAIL2("Sequence (?%c...) not recognized", *PL_regcomp_parse);
1887 ret = reganode(OPEN, parno);
1894 /* Pick up the branches, linking them together. */
1895 br = regbranch(&flags, 1);
1898 if (*PL_regcomp_parse == '|') {
1899 if (!SIZE_ONLY && PL_extralen) {
1900 reginsert(BRANCHJ, br);
1903 reginsert(BRANCH, br);
1906 PL_extralen += 1; /* For BRANCHJ-BRANCH. */
1908 else if (paren == ':') {
1909 *flagp |= flags&SIMPLE;
1911 if (open) { /* Starts with OPEN. */
1912 regtail(ret, br); /* OPEN -> first. */
1914 else if (paren != '?') /* Not Conditional */
1918 *flagp |= flags&SPSTART;
1920 while (*PL_regcomp_parse == '|') {
1921 if (!SIZE_ONLY && PL_extralen) {
1922 ender = reganode(LONGJMP,0);
1923 regtail(NEXTOPER(NEXTOPER(lastbr)), ender); /* Append to the previous. */
1926 PL_extralen += 2; /* Account for LONGJMP. */
1928 br = regbranch(&flags, 0);
1931 regtail(lastbr, br); /* BRANCH -> BRANCH. */
1935 *flagp |= flags&SPSTART;
1938 if (have_branch || paren != ':') {
1939 /* Make a closing node, and hook it on the end. */
1942 ender = reg_node(TAIL);
1945 ender = reganode(CLOSE, parno);
1951 *flagp &= ~HASWIDTH;
1954 ender = reg_node(SUCCEED);
1957 ender = reg_node(END);
1960 regtail(lastbr, ender);
1963 /* Hook the tails of the branches to the closing node. */
1964 for (br = ret; br != NULL; br = regnext(br)) {
1965 regoptail(br, ender);
1972 static char parens[] = "=!<,>";
1974 if (paren && (p = strchr(parens, paren))) {
1975 int node = ((p - parens) % 2) ? UNLESSM : IFMATCH;
1976 int flag = (p - parens) > 1;
1979 node = SUSPEND, flag = 0;
1980 reginsert(node,ret);
1982 regtail(ret, reg_node(TAIL));
1986 /* Check for proper termination. */
1988 PL_regflags = oregflags;
1989 if (PL_regcomp_parse >= PL_regxend || *nextchar() != ')') {
1990 FAIL("unmatched () in regexp");
1993 else if (!paren && PL_regcomp_parse < PL_regxend) {
1994 if (*PL_regcomp_parse == ')') {
1995 FAIL("unmatched () in regexp");
1998 FAIL("junk on end of regexp"); /* "Can't happen". */
2006 - regbranch - one alternative of an | operator
2008 * Implements the concatenation operator.
2011 S_regbranch(pTHX_ I32 *flagp, I32 first)
2014 register regnode *ret;
2015 register regnode *chain = NULL;
2016 register regnode *latest;
2017 I32 flags = 0, c = 0;
2022 if (!SIZE_ONLY && PL_extralen)
2023 ret = reganode(BRANCHJ,0);
2025 ret = reg_node(BRANCH);
2028 if (!first && SIZE_ONLY)
2029 PL_extralen += 1; /* BRANCHJ */
2031 *flagp = WORST; /* Tentatively. */
2035 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != '|' && *PL_regcomp_parse != ')') {
2037 latest = regpiece(&flags);
2038 if (latest == NULL) {
2039 if (flags & TRYAGAIN)
2043 else if (ret == NULL)
2045 *flagp |= flags&HASWIDTH;
2046 if (chain == NULL) /* First piece. */
2047 *flagp |= flags&SPSTART;
2050 regtail(chain, latest);
2055 if (chain == NULL) { /* Loop ran zero times. */
2056 chain = reg_node(NOTHING);
2061 *flagp |= flags&SIMPLE;
2068 - regpiece - something followed by possible [*+?]
2070 * Note that the branching code sequences used for ? and the general cases
2071 * of * and + are somewhat optimized: they use the same NOTHING node as
2072 * both the endmarker for their branch list and the body of the last branch.
2073 * It might seem that this node could be dispensed with entirely, but the
2074 * endmarker role is not redundant.
2077 S_regpiece(pTHX_ I32 *flagp)
2080 register regnode *ret;
2082 register char *next;
2084 char *origparse = PL_regcomp_parse;
2087 I32 max = REG_INFTY;
2089 ret = regatom(&flags);
2091 if (flags & TRYAGAIN)
2096 op = *PL_regcomp_parse;
2098 if (op == '{' && regcurly(PL_regcomp_parse)) {
2099 next = PL_regcomp_parse + 1;
2101 while (isDIGIT(*next) || *next == ',') {
2110 if (*next == '}') { /* got one */
2114 min = atoi(PL_regcomp_parse);
2118 maxpos = PL_regcomp_parse;
2120 if (!max && *maxpos != '0')
2121 max = REG_INFTY; /* meaning "infinity" */
2122 else if (max >= REG_INFTY)
2123 FAIL2("Quantifier in {,} bigger than %d", REG_INFTY - 1);
2124 PL_regcomp_parse = next;
2128 if ((flags&SIMPLE)) {
2129 PL_regnaughty += 2 + PL_regnaughty / 2;
2130 reginsert(CURLY, ret);
2133 regnode *w = reg_node(WHILEM);
2137 if (!SIZE_ONLY && PL_extralen) {
2138 reginsert(LONGJMP,ret);
2139 reginsert(NOTHING,ret);
2140 NEXT_OFF(ret) = 3; /* Go over LONGJMP. */
2142 reginsert(CURLYX,ret);
2143 if (!SIZE_ONLY && PL_extralen)
2144 NEXT_OFF(ret) = 3; /* Go over NOTHING to LONGJMP. */
2145 regtail(ret, reg_node(NOTHING));
2147 PL_reg_whilem_seen++, PL_extralen += 3;
2148 PL_regnaughty += 4 + PL_regnaughty; /* compound interest */
2156 if (max && max < min)
2157 FAIL("Can't do {n,m} with n > m");
2172 #if 0 /* Now runtime fix should be reliable. */
2173 if (!(flags&HASWIDTH) && op != '?')
2174 FAIL("regexp *+ operand could be empty");
2179 *flagp = (op != '+') ? (WORST|SPSTART|HASWIDTH) : (WORST|HASWIDTH);
2181 if (op == '*' && (flags&SIMPLE)) {
2182 reginsert(STAR, ret);
2186 else if (op == '*') {
2190 else if (op == '+' && (flags&SIMPLE)) {
2191 reginsert(PLUS, ret);
2195 else if (op == '+') {
2199 else if (op == '?') {
2204 if (ckWARN(WARN_UNSAFE) && !SIZE_ONLY && !(flags&HASWIDTH) && max > REG_INFTY/3) {
2205 Perl_warner(aTHX_ WARN_UNSAFE, "%.*s matches null string many times",
2206 PL_regcomp_parse - origparse, origparse);
2209 if (*PL_regcomp_parse == '?') {
2211 reginsert(MINMOD, ret);
2212 regtail(ret, ret + NODE_STEP_REGNODE);
2214 if (ISMULT2(PL_regcomp_parse))
2215 FAIL("nested *?+ in regexp");
2221 - regatom - the lowest level
2223 * Optimization: gobbles an entire sequence of ordinary characters so that
2224 * it can turn them into a single node, which is smaller to store and
2225 * faster to run. Backslashed characters are exceptions, each becoming a
2226 * separate node; the code is simpler that way and it's not worth fixing.
2228 * [Yes, it is worth fixing, some scripts can run twice the speed.]
2231 S_regatom(pTHX_ I32 *flagp)
2234 register regnode *ret = 0;
2237 *flagp = WORST; /* Tentatively. */
2240 switch (*PL_regcomp_parse) {
2244 if (PL_regflags & PMf_MULTILINE)
2245 ret = reg_node(MBOL);
2246 else if (PL_regflags & PMf_SINGLELINE)
2247 ret = reg_node(SBOL);
2249 ret = reg_node(BOL);
2252 if (PL_regcomp_parse[1])
2255 if (PL_regflags & PMf_MULTILINE)
2256 ret = reg_node(MEOL);
2257 else if (PL_regflags & PMf_SINGLELINE)
2258 ret = reg_node(SEOL);
2260 ret = reg_node(EOL);
2265 if (PL_regflags & PMf_SINGLELINE)
2266 ret = reg_node(SANYUTF8);
2268 ret = reg_node(ANYUTF8);
2272 if (PL_regflags & PMf_SINGLELINE)
2273 ret = reg_node(SANY);
2275 ret = reg_node(REG_ANY);
2276 *flagp |= HASWIDTH|SIMPLE;
2282 ret = (UTF ? regclassutf8() : regclass());
2283 if (*PL_regcomp_parse != ']')
2284 FAIL("unmatched [] in regexp");
2286 *flagp |= HASWIDTH|SIMPLE;
2290 ret = reg(1, &flags);
2292 if (flags & TRYAGAIN)
2296 *flagp |= flags&(HASWIDTH|SPSTART|SIMPLE);
2300 if (flags & TRYAGAIN) {
2304 FAIL2("internal urp in regexp at /%s/", PL_regcomp_parse);
2305 /* Supposed to be caught earlier. */
2308 if (!regcurly(PL_regcomp_parse)) {
2316 FAIL("?+*{} follows nothing in regexp");
2319 switch (*++PL_regcomp_parse) {
2322 ret = reg_node(SBOL);
2327 ret = reg_node(GPOS);
2328 PL_regseen |= REG_SEEN_GPOS;
2333 ret = reg_node(SEOL);
2338 ret = reg_node(EOS);
2340 PL_seen_zerolen++; /* Do not optimize RE away */
2344 ret = reg_node(SANY);
2345 *flagp |= HASWIDTH|SIMPLE;
2349 ret = reg_node(CLUMP);
2352 if (UTF && !PL_utf8_mark)
2353 is_utf8_mark((U8*)"~"); /* preload table */
2358 ? (LOC ? ALNUMLUTF8 : ALNUMUTF8)
2359 : (LOC ? ALNUML : ALNUM));
2360 *flagp |= HASWIDTH|SIMPLE;
2362 if (UTF && !PL_utf8_alnum)
2363 is_utf8_alnum((U8*)"a"); /* preload table */
2368 ? (LOC ? NALNUMLUTF8 : NALNUMUTF8)
2369 : (LOC ? NALNUML : NALNUM));
2370 *flagp |= HASWIDTH|SIMPLE;
2372 if (UTF && !PL_utf8_alnum)
2373 is_utf8_alnum((U8*)"a"); /* preload table */
2377 PL_regseen |= REG_SEEN_LOOKBEHIND;
2380 ? (LOC ? BOUNDLUTF8 : BOUNDUTF8)
2381 : (LOC ? BOUNDL : BOUND));
2384 if (UTF && !PL_utf8_alnum)
2385 is_utf8_alnum((U8*)"a"); /* preload table */
2389 PL_regseen |= REG_SEEN_LOOKBEHIND;
2392 ? (LOC ? NBOUNDLUTF8 : NBOUNDUTF8)
2393 : (LOC ? NBOUNDL : NBOUND));
2396 if (UTF && !PL_utf8_alnum)
2397 is_utf8_alnum((U8*)"a"); /* preload table */
2402 ? (LOC ? SPACELUTF8 : SPACEUTF8)
2403 : (LOC ? SPACEL : SPACE));
2404 *flagp |= HASWIDTH|SIMPLE;
2406 if (UTF && !PL_utf8_space)
2407 is_utf8_space((U8*)" "); /* preload table */
2412 ? (LOC ? NSPACELUTF8 : NSPACEUTF8)
2413 : (LOC ? NSPACEL : NSPACE));
2414 *flagp |= HASWIDTH|SIMPLE;
2416 if (UTF && !PL_utf8_space)
2417 is_utf8_space((U8*)" "); /* preload table */
2420 ret = reg_node(UTF ? DIGITUTF8 : DIGIT);
2421 *flagp |= HASWIDTH|SIMPLE;
2423 if (UTF && !PL_utf8_digit)
2424 is_utf8_digit((U8*)"1"); /* preload table */
2427 ret = reg_node(UTF ? NDIGITUTF8 : NDIGIT);
2428 *flagp |= HASWIDTH|SIMPLE;
2430 if (UTF && !PL_utf8_digit)
2431 is_utf8_digit((U8*)"1"); /* preload table */
2435 { /* a lovely hack--pretend we saw [\pX] instead */
2436 char* oldregxend = PL_regxend;
2438 if (PL_regcomp_parse[1] == '{') {
2439 PL_regxend = strchr(PL_regcomp_parse, '}');
2441 FAIL("Missing right brace on \\p{}");
2445 PL_regxend = PL_regcomp_parse + 2;
2448 ret = regclassutf8();
2450 PL_regxend = oldregxend;
2453 *flagp |= HASWIDTH|SIMPLE;
2466 case '1': case '2': case '3': case '4':
2467 case '5': case '6': case '7': case '8': case '9':
2469 I32 num = atoi(PL_regcomp_parse);
2471 if (num > 9 && num >= PL_regnpar)
2474 if (!SIZE_ONLY && num > PL_regcomp_rx->nparens)
2475 FAIL("reference to nonexistent group");
2478 ? (LOC ? REFFL : REFF)
2481 while (isDIGIT(*PL_regcomp_parse))
2489 if (PL_regcomp_parse >= PL_regxend)
2490 FAIL("trailing \\ in regexp");
2493 /* Do not generate `unrecognized' warnings here, we fall
2494 back into the quick-grab loop below */
2500 if (PL_regflags & PMf_EXTENDED) {
2501 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != '\n') PL_regcomp_parse++;
2502 if (PL_regcomp_parse < PL_regxend)
2518 ? (LOC ? EXACTFL : EXACTF)
2521 for (len = 0, p = PL_regcomp_parse - 1;
2522 len < 127 && p < PL_regxend;
2527 if (PL_regflags & PMf_EXTENDED)
2528 p = regwhite(p, PL_regxend);
2582 char* e = strchr(p, '}');
2585 FAIL("Missing right brace on \\x{}");
2587 ender = (UV)scan_hex(p + 1, e - p, &numlen);
2588 if (numlen + len >= 127) { /* numlen is generous */
2595 FAIL("Can't use \\x{} without 'use utf8' declaration");
2598 ender = (UV)scan_hex(p, 2, &numlen);
2604 ender = UCHARAT(p++);
2605 ender = toCTRL(ender);
2607 case '0': case '1': case '2': case '3':case '4':
2608 case '5': case '6': case '7': case '8':case '9':
2610 (isDIGIT(p[1]) && atoi(p) >= PL_regnpar) ) {
2611 ender = (UV)scan_oct(p, 3, &numlen);
2620 if (p >= PL_regxend)
2621 FAIL("trailing \\ in regexp");
2624 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) && isALPHA(*p))
2625 Perl_warner(aTHX_ WARN_UNSAFE,
2626 "/%.127s/: Unrecognized escape \\%c passed through",
2629 goto normal_default;
2634 if ((*p & 0xc0) == 0xc0 && UTF) {
2635 ender = utf8_to_uv((U8*)p, &numlen);
2642 if (PL_regflags & PMf_EXTENDED)
2643 p = regwhite(p, PL_regxend);
2646 ender = toLOWER_LC_uni(ender);
2648 ender = toLOWER_uni(ender);
2650 if (ISMULT2(p)) { /* Back off on ?+*. */
2653 else if (ender >= 0x80 && UTF) {
2654 reguni(ender, s, &numlen);
2664 if (ender >= 0x80 && UTF) {
2665 reguni(ender, s, &numlen);
2673 PL_regcomp_parse = p - 1;
2676 FAIL("internal disaster in regexp");
2684 PL_regsize += STR_SZ(len);
2686 PL_regcode += STR_SZ(len);
2695 S_regwhite(pTHX_ char *p, char *e)
2700 else if (*p == '#') {
2703 } while (p < e && *p != '\n');
2711 /* Parse POSIX character classes: [[:foo:]], [[=foo=]], [[.foo.]].
2712 Character classes ([:foo:]) can also be negated ([:^foo:]).
2713 Returns a named class id (ANYOF_XXX) if successful, -1 otherwise.
2714 Equivalence classes ([=foo=]) and composites ([.foo.]) are parsed,
2715 but trigger warnings because they are currently unimplemented. */
2717 S_regpposixcc(pTHX_ I32 value)
2721 I32 namedclass = OOB_NAMEDCLASS;
2723 if (value == '[' && PL_regcomp_parse + 1 < PL_regxend &&
2724 /* I smell either [: or [= or [. -- POSIX has been here, right? */
2725 (*PL_regcomp_parse == ':' ||
2726 *PL_regcomp_parse == '=' ||
2727 *PL_regcomp_parse == '.')) {
2728 char c = *PL_regcomp_parse;
2729 char* s = PL_regcomp_parse++;
2731 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != c)
2733 if (PL_regcomp_parse == PL_regxend)
2734 /* Grandfather lone [:, [=, [. */
2735 PL_regcomp_parse = s;
2737 char* t = PL_regcomp_parse++; /* skip over the c */
2739 if (*PL_regcomp_parse == ']') {
2740 PL_regcomp_parse++; /* skip over the ending ] */
2743 I32 complement = *posixcc == '^' ? *posixcc++ : 0;
2744 I32 skip = 5; /* the most common skip */
2748 if (strnEQ(posixcc, "alnum", 5))
2750 complement ? ANYOF_NALNUMC : ANYOF_ALNUMC;
2751 else if (strnEQ(posixcc, "alpha", 5))
2753 complement ? ANYOF_NALPHA : ANYOF_ALPHA;
2754 else if (strnEQ(posixcc, "ascii", 5))
2756 complement ? ANYOF_NASCII : ANYOF_ASCII;
2759 if (strnEQ(posixcc, "cntrl", 5))
2761 complement ? ANYOF_NCNTRL : ANYOF_CNTRL;
2764 if (strnEQ(posixcc, "digit", 5))
2766 complement ? ANYOF_NDIGIT : ANYOF_DIGIT;
2769 if (strnEQ(posixcc, "graph", 5))
2771 complement ? ANYOF_NGRAPH : ANYOF_GRAPH;
2774 if (strnEQ(posixcc, "lower", 5))
2776 complement ? ANYOF_NLOWER : ANYOF_LOWER;
2779 if (strnEQ(posixcc, "print", 5))
2781 complement ? ANYOF_NPRINT : ANYOF_PRINT;
2782 else if (strnEQ(posixcc, "punct", 5))
2784 complement ? ANYOF_NPUNCT : ANYOF_PUNCT;
2787 if (strnEQ(posixcc, "space", 5))
2789 complement ? ANYOF_NSPACE : ANYOF_SPACE;
2791 if (strnEQ(posixcc, "upper", 5))
2793 complement ? ANYOF_NUPPER : ANYOF_UPPER;
2795 case 'w': /* this is not POSIX, this is the Perl \w */
2796 if (strnEQ(posixcc, "word", 4)) {
2798 complement ? ANYOF_NALNUM : ANYOF_ALNUM;
2803 if (strnEQ(posixcc, "xdigit", 6)) {
2805 complement ? ANYOF_NXDIGIT : ANYOF_XDIGIT;
2810 if ((namedclass == OOB_NAMEDCLASS ||
2811 !(posixcc + skip + 2 < PL_regxend &&
2812 (posixcc[skip] == ':' &&
2813 posixcc[skip + 1] == ']'))))
2814 Perl_croak(aTHX_ "Character class [:%.*s:] unknown",
2816 } else if (ckWARN(WARN_UNSAFE) && !SIZE_ONLY)
2817 /* [[=foo=]] and [[.foo.]] are still future. */
2818 Perl_warner(aTHX_ WARN_UNSAFE,
2819 "Character class syntax [%c %c] is reserved for future extensions", c, c);
2821 /* Maternal grandfather:
2822 * "[:" ending in ":" but not in ":]" */
2823 PL_regcomp_parse = s;
2832 S_checkposixcc(pTHX)
2834 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) &&
2835 (*PL_regcomp_parse == ':' ||
2836 *PL_regcomp_parse == '=' ||
2837 *PL_regcomp_parse == '.')) {
2838 char *s = PL_regcomp_parse;
2841 while(*s && isALNUM(*s))
2843 if (*s && c == *s && s[1] == ']') {
2844 Perl_warner(aTHX_ WARN_UNSAFE,
2845 "Character class syntax [%c %c] belongs inside character classes", c, c);
2846 if (c == '=' || c == '.')
2847 Perl_warner(aTHX_ WARN_UNSAFE,
2848 "Character class syntax [%c %c] is reserved for future extensions", c, c);
2858 register I32 lastvalue = OOB_CHAR8;
2859 register I32 range = 0;
2860 register regnode *ret;
2865 bool need_class = 0;
2867 ret = reg_node(ANYOF);
2869 PL_regsize += ANYOF_SKIP;
2872 ANYOF_BITMAP_ZERO(ret);
2873 PL_regcode += ANYOF_SKIP;
2875 ANYOF_FLAGS(ret) |= ANYOF_FOLD;
2877 ANYOF_FLAGS(ret) |= ANYOF_LOCALE;
2879 if (*PL_regcomp_parse == '^') { /* Complement of range. */
2883 ANYOF_FLAGS(ret) |= ANYOF_INVERT;
2886 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE))
2889 if (*PL_regcomp_parse == ']' || *PL_regcomp_parse == '-')
2890 goto skipcond; /* allow 1st char to be ] or - */
2891 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != ']') {
2893 namedclass = OOB_NAMEDCLASS;
2895 rangebegin = PL_regcomp_parse;
2896 value = UCHARAT(PL_regcomp_parse++);
2898 namedclass = regpposixcc(value);
2899 else if (value == '\\') {
2900 value = UCHARAT(PL_regcomp_parse++);
2902 case 'w': namedclass = ANYOF_ALNUM; break;
2903 case 'W': namedclass = ANYOF_NALNUM; break;
2904 case 's': namedclass = ANYOF_SPACE; break;
2905 case 'S': namedclass = ANYOF_NSPACE; break;
2906 case 'd': namedclass = ANYOF_DIGIT; break;
2907 case 'D': namedclass = ANYOF_NDIGIT; break;
2908 case 'n': value = '\n'; break;
2909 case 'r': value = '\r'; break;
2910 case 't': value = '\t'; break;
2911 case 'f': value = '\f'; break;
2912 case 'b': value = '\b'; break;
2913 case 'e': value = '\033'; break;
2914 case 'a': value = '\007'; break;
2916 value = (UV)scan_hex(PL_regcomp_parse, 2, &numlen);
2917 PL_regcomp_parse += numlen;
2920 value = UCHARAT(PL_regcomp_parse++);
2921 value = toCTRL(value);
2923 case '0': case '1': case '2': case '3': case '4':
2924 case '5': case '6': case '7': case '8': case '9':
2925 value = (UV)scan_oct(--PL_regcomp_parse, 3, &numlen);
2926 PL_regcomp_parse += numlen;
2929 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) && isALPHA(value))
2930 Perl_warner(aTHX_ WARN_UNSAFE,
2931 "/%.127s/: Unrecognized escape \\%c in character class passed through",
2937 if (namedclass > OOB_NAMEDCLASS) {
2938 if (!need_class && !SIZE_ONLY)
2939 ANYOF_CLASS_ZERO(ret);
2941 if (range) { /* a-\d, a-[:digit:] */
2943 if (ckWARN(WARN_UNSAFE))
2944 Perl_warner(aTHX_ WARN_UNSAFE,
2945 "/%.127s/: false [] range \"%*.*s\" in regexp",
2947 PL_regcomp_parse - rangebegin,
2948 PL_regcomp_parse - rangebegin,
2950 ANYOF_BITMAP_SET(ret, lastvalue);
2951 ANYOF_BITMAP_SET(ret, '-');
2953 range = 0; /* this is not a true range */
2956 switch (namedclass) {
2959 ANYOF_CLASS_SET(ret, ANYOF_ALNUM);
2961 for (value = 0; value < 256; value++)
2963 ANYOF_BITMAP_SET(ret, value);
2968 ANYOF_CLASS_SET(ret, ANYOF_NALNUM);
2970 for (value = 0; value < 256; value++)
2971 if (!isALNUM(value))
2972 ANYOF_BITMAP_SET(ret, value);
2977 ANYOF_CLASS_SET(ret, ANYOF_SPACE);
2979 for (value = 0; value < 256; value++)
2981 ANYOF_BITMAP_SET(ret, value);
2986 ANYOF_CLASS_SET(ret, ANYOF_NSPACE);
2988 for (value = 0; value < 256; value++)
2989 if (!isSPACE(value))
2990 ANYOF_BITMAP_SET(ret, value);
2995 ANYOF_CLASS_SET(ret, ANYOF_DIGIT);
2997 for (value = '0'; value <= '9'; value++)
2998 ANYOF_BITMAP_SET(ret, value);
3003 ANYOF_CLASS_SET(ret, ANYOF_NDIGIT);
3005 for (value = 0; value < '0'; value++)
3006 ANYOF_BITMAP_SET(ret, value);
3007 for (value = '9' + 1; value < 256; value++)
3008 ANYOF_BITMAP_SET(ret, value);
3013 ANYOF_CLASS_SET(ret, ANYOF_NALNUMC);
3015 for (value = 0; value < 256; value++)
3016 if (!isALNUMC(value))
3017 ANYOF_BITMAP_SET(ret, value);
3022 ANYOF_CLASS_SET(ret, ANYOF_ALNUMC);
3024 for (value = 0; value < 256; value++)
3025 if (isALNUMC(value))
3026 ANYOF_BITMAP_SET(ret, value);
3031 ANYOF_CLASS_SET(ret, ANYOF_ALPHA);
3033 for (value = 0; value < 256; value++)
3035 ANYOF_BITMAP_SET(ret, value);
3040 ANYOF_CLASS_SET(ret, ANYOF_NALPHA);
3042 for (value = 0; value < 256; value++)
3043 if (!isALPHA(value))
3044 ANYOF_BITMAP_SET(ret, value);
3049 ANYOF_CLASS_SET(ret, ANYOF_ASCII);
3052 for (value = 0; value < 128; value++)
3053 ANYOF_BITMAP_SET(ret, value);
3055 for (value = 0; value < 256; value++)
3057 ANYOF_BITMAP_SET(ret, value);
3063 ANYOF_CLASS_SET(ret, ANYOF_NASCII);
3066 for (value = 128; value < 256; value++)
3067 ANYOF_BITMAP_SET(ret, value);
3069 for (value = 0; value < 256; value++)
3070 if (!isASCII(value))
3071 ANYOF_BITMAP_SET(ret, value);
3077 ANYOF_CLASS_SET(ret, ANYOF_CNTRL);
3079 for (value = 0; value < 256; value++)
3081 ANYOF_BITMAP_SET(ret, value);
3083 lastvalue = OOB_CHAR8;
3087 ANYOF_CLASS_SET(ret, ANYOF_NCNTRL);
3089 for (value = 0; value < 256; value++)
3090 if (!isCNTRL(value))
3091 ANYOF_BITMAP_SET(ret, value);
3096 ANYOF_CLASS_SET(ret, ANYOF_GRAPH);
3098 for (value = 0; value < 256; value++)
3100 ANYOF_BITMAP_SET(ret, value);
3105 ANYOF_CLASS_SET(ret, ANYOF_NGRAPH);
3107 for (value = 0; value < 256; value++)
3108 if (!isGRAPH(value))
3109 ANYOF_BITMAP_SET(ret, value);
3114 ANYOF_CLASS_SET(ret, ANYOF_LOWER);
3116 for (value = 0; value < 256; value++)
3118 ANYOF_BITMAP_SET(ret, value);
3123 ANYOF_CLASS_SET(ret, ANYOF_NLOWER);
3125 for (value = 0; value < 256; value++)
3126 if (!isLOWER(value))
3127 ANYOF_BITMAP_SET(ret, value);
3132 ANYOF_CLASS_SET(ret, ANYOF_PRINT);
3134 for (value = 0; value < 256; value++)
3136 ANYOF_BITMAP_SET(ret, value);
3141 ANYOF_CLASS_SET(ret, ANYOF_NPRINT);
3143 for (value = 0; value < 256; value++)
3144 if (!isPRINT(value))
3145 ANYOF_BITMAP_SET(ret, value);
3150 ANYOF_CLASS_SET(ret, ANYOF_PUNCT);
3152 for (value = 0; value < 256; value++)
3154 ANYOF_BITMAP_SET(ret, value);
3159 ANYOF_CLASS_SET(ret, ANYOF_NPUNCT);
3161 for (value = 0; value < 256; value++)
3162 if (!isPUNCT(value))
3163 ANYOF_BITMAP_SET(ret, value);
3168 ANYOF_CLASS_SET(ret, ANYOF_UPPER);
3170 for (value = 0; value < 256; value++)
3172 ANYOF_BITMAP_SET(ret, value);
3177 ANYOF_CLASS_SET(ret, ANYOF_NUPPER);
3179 for (value = 0; value < 256; value++)
3180 if (!isUPPER(value))
3181 ANYOF_BITMAP_SET(ret, value);
3186 ANYOF_CLASS_SET(ret, ANYOF_XDIGIT);
3188 for (value = 0; value < 256; value++)
3189 if (isXDIGIT(value))
3190 ANYOF_BITMAP_SET(ret, value);
3195 ANYOF_CLASS_SET(ret, ANYOF_NXDIGIT);
3197 for (value = 0; value < 256; value++)
3198 if (!isXDIGIT(value))
3199 ANYOF_BITMAP_SET(ret, value);
3203 FAIL("invalid [::] class in regexp");
3207 ANYOF_FLAGS(ret) |= ANYOF_CLASS;
3212 if (lastvalue > value) /* b-a */ {
3214 "/%.127s/: invalid [] range \"%*.*s\" in regexp",
3216 PL_regcomp_parse - rangebegin,
3217 PL_regcomp_parse - rangebegin,
3224 if (*PL_regcomp_parse == '-' && PL_regcomp_parse+1 < PL_regxend &&
3225 PL_regcomp_parse[1] != ']') {
3227 if (namedclass > OOB_NAMEDCLASS) { /* \w-, [:word:]- */
3228 if (ckWARN(WARN_UNSAFE))
3229 Perl_warner(aTHX_ WARN_UNSAFE,
3230 "/%.127s/: false [] range \"%*.*s\" in regexp",
3232 PL_regcomp_parse - rangebegin,
3233 PL_regcomp_parse - rangebegin,
3236 ANYOF_BITMAP_SET(ret, '-');
3239 continue; /* do it next time */
3242 /* now is the next time */
3244 #ifndef ASCIIish /* EBCDIC, for example. */
3245 if ((isLOWER(lastvalue) && isLOWER(value)) ||
3246 (isUPPER(lastvalue) && isUPPER(value)))
3249 if (isLOWER(lastvalue)) {
3250 for (i = lastvalue; i <= value; i++)
3252 ANYOF_BITMAP_SET(ret, i);
3254 for (i = lastvalue; i <= value; i++)
3256 ANYOF_BITMAP_SET(ret, i);
3261 for ( ; lastvalue <= value; lastvalue++)
3262 ANYOF_BITMAP_SET(ret, lastvalue);
3268 PL_regsize += ANYOF_CLASS_ADD_SKIP;
3270 PL_regcode += ANYOF_CLASS_ADD_SKIP;
3272 /* optimize case-insensitive simple patterns (e.g. /[a-z]/i) */
3274 (ANYOF_FLAGS(ret) & (ANYOF_FLAGS_ALL ^ ANYOF_INVERT)) == ANYOF_FOLD) {
3275 for (value = 0; value < 256; ++value) {
3276 if (ANYOF_BITMAP_TEST(ret, value)) {
3277 I32 cf = PL_fold[value];
3278 ANYOF_BITMAP_SET(ret, cf);
3281 ANYOF_FLAGS(ret) &= ~ANYOF_FOLD;
3283 /* optimize inverted simple patterns (e.g. [^a-z]) */
3284 if (!SIZE_ONLY && (ANYOF_FLAGS(ret) & ANYOF_FLAGS_ALL) == ANYOF_INVERT) {
3285 for (value = 0; value < ANYOF_BITMAP_SIZE; ++value)
3286 ANYOF_BITMAP(ret)[value] ^= ANYOF_FLAGS_ALL;
3287 ANYOF_FLAGS(ret) = 0;
3293 S_regclassutf8(pTHX)
3298 register U32 lastvalue = OOB_UTF8;
3299 register I32 range = 0;
3300 register regnode *ret;
3308 if (*PL_regcomp_parse == '^') { /* Complement of range. */
3312 flags |= ANYOF_INVERT;
3316 flags |= ANYOF_FOLD;
3318 flags |= ANYOF_LOCALE;
3319 listsv = newSVpvn("# comment\n",10);
3322 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE))
3325 if (*PL_regcomp_parse == ']' || *PL_regcomp_parse == '-')
3326 goto skipcond; /* allow 1st char to be ] or - */
3328 while (PL_regcomp_parse < PL_regxend && *PL_regcomp_parse != ']') {
3330 namedclass = OOB_NAMEDCLASS;
3332 rangebegin = PL_regcomp_parse;
3333 value = utf8_to_uv((U8*)PL_regcomp_parse, &numlen);
3334 PL_regcomp_parse += numlen;
3336 namedclass = regpposixcc(value);
3337 else if (value == '\\') {
3338 value = utf8_to_uv((U8*)PL_regcomp_parse, &numlen);
3339 PL_regcomp_parse += numlen;
3341 case 'w': namedclass = ANYOF_ALNUM; break;
3342 case 'W': namedclass = ANYOF_NALNUM; break;
3343 case 's': namedclass = ANYOF_SPACE; break;
3344 case 'S': namedclass = ANYOF_NSPACE; break;
3345 case 'd': namedclass = ANYOF_DIGIT; break;
3346 case 'D': namedclass = ANYOF_NDIGIT; break;
3349 if (*PL_regcomp_parse == '{') {
3350 e = strchr(PL_regcomp_parse++, '}');
3352 FAIL("Missing right brace on \\p{}");
3353 n = e - PL_regcomp_parse;
3356 e = PL_regcomp_parse;
3361 Perl_sv_catpvf(aTHX_ listsv,
3362 "+utf8::%.*s\n", n, PL_regcomp_parse);
3364 Perl_sv_catpvf(aTHX_ listsv,
3365 "!utf8::%.*s\n", n, PL_regcomp_parse);
3367 PL_regcomp_parse = e + 1;
3368 lastvalue = OOB_UTF8;
3370 case 'n': value = '\n'; break;
3371 case 'r': value = '\r'; break;
3372 case 't': value = '\t'; break;
3373 case 'f': value = '\f'; break;
3374 case 'b': value = '\b'; break;
3375 case 'e': value = '\033'; break;
3376 case 'a': value = '\007'; break;
3378 if (*PL_regcomp_parse == '{') {
3379 e = strchr(PL_regcomp_parse++, '}');
3381 FAIL("Missing right brace on \\x{}");
3382 value = (UV)scan_hex(PL_regcomp_parse,
3383 e - PL_regcomp_parse,
3385 PL_regcomp_parse = e + 1;
3388 value = (UV)scan_hex(PL_regcomp_parse, 2, &numlen);
3389 PL_regcomp_parse += numlen;
3393 value = UCHARAT(PL_regcomp_parse++);
3394 value = toCTRL(value);
3396 case '0': case '1': case '2': case '3': case '4':
3397 case '5': case '6': case '7': case '8': case '9':
3398 value = (UV)scan_oct(--PL_regcomp_parse, 3, &numlen);
3399 PL_regcomp_parse += numlen;
3402 if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) && isALPHA(value))
3403 Perl_warner(aTHX_ WARN_UNSAFE,
3404 "/%.127s/: Unrecognized escape \\%c in character class passed through",
3410 if (namedclass > OOB_NAMEDCLASS) {
3411 if (range) { /* a-\d, a-[:digit:] */
3413 if (ckWARN(WARN_UNSAFE))
3414 Perl_warner(aTHX_ WARN_UNSAFE,
3415 "/%.127s/: false [] range \"%*.*s\" in regexp",
3417 PL_regcomp_parse - rangebegin,
3418 PL_regcomp_parse - rangebegin,
3420 Perl_sv_catpvf(aTHX_ listsv,
3421 /* 0x002D is Unicode for '-' */
3422 "%04"UVxf"\n002D\n", (UV)lastvalue);
3427 switch (namedclass) {
3429 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsWord\n"); break;
3431 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsWord\n"); break;
3433 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsAlnum\n"); break;
3435 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsAlnum\n"); break;
3437 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsAlpha\n"); break;
3439 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsAlpha\n"); break;
3441 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsASCII\n"); break;
3443 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsASCII\n"); break;
3445 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsCntrl\n"); break;
3447 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsCntrl\n"); break;
3449 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsGraph\n"); break;
3451 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsGraph\n"); break;
3453 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsDigit\n"); break;
3455 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsDigit\n"); break;
3457 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsLower\n"); break;
3459 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsLower\n"); break;
3461 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsPrint\n"); break;
3463 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsPrint\n"); break;
3465 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsPunct\n"); break;
3467 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsPunct\n"); break;
3469 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsSpace\n"); break;
3471 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsSpace\n"); break;
3473 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsUpper\n"); break;
3475 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsUpper\n"); break;
3477 Perl_sv_catpvf(aTHX_ listsv, "+utf8::IsXDigit\n"); break;
3479 Perl_sv_catpvf(aTHX_ listsv, "!utf8::IsXDigit\n"); break;
3485 if (lastvalue > value) { /* b-a */
3487 "/%.127s/: invalid [] range \"%*.*s\" in regexp",
3489 PL_regcomp_parse - rangebegin,
3490 PL_regcomp_parse - rangebegin,
3497 if (*PL_regcomp_parse == '-' && PL_regcomp_parse+1 < PL_regxend &&
3498 PL_regcomp_parse[1] != ']') {
3500 if (namedclass > OOB_NAMEDCLASS) { /* \w-, [:word:]- */
3501 if (ckWARN(WARN_UNSAFE))
3502 Perl_warner(aTHX_ WARN_UNSAFE,
3503 "/%.127s/: false [] range \"%*.*s\" in regexp",
3505 PL_regcomp_parse - rangebegin,
3506 PL_regcomp_parse - rangebegin,
3509 Perl_sv_catpvf(aTHX_ listsv,
3510 /* 0x002D is Unicode for '-' */
3514 continue; /* do it next time */
3517 /* now is the next time */
3519 Perl_sv_catpvf(aTHX_ listsv, "%04"UVxf"\t%04"UVxf"\n",
3520 (UV)lastvalue, (UV)value);
3524 ret = reganode(ANYOFUTF8, 0);
3527 SV *rv = swash_init("utf8", "", listsv, 1, 0);
3528 SvREFCNT_dec(listsv);
3529 n = add_data(1,"s");
3530 PL_regcomp_rx->data->data[n] = (void*)rv;
3531 ARG1_SET(ret, flags);
3542 char* retval = PL_regcomp_parse++;
3545 if (*PL_regcomp_parse == '(' && PL_regcomp_parse[1] == '?' &&
3546 PL_regcomp_parse[2] == '#') {
3547 while (*PL_regcomp_parse && *PL_regcomp_parse != ')')
3552 if (PL_regflags & PMf_EXTENDED) {
3553 if (isSPACE(*PL_regcomp_parse)) {
3557 else if (*PL_regcomp_parse == '#') {
3558 while (*PL_regcomp_parse && *PL_regcomp_parse != '\n')
3569 - reg_node - emit a node
3571 STATIC regnode * /* Location. */
3572 S_reg_node(pTHX_ U8 op)
3575 register regnode *ret;
3576 register regnode *ptr;
3580 SIZE_ALIGN(PL_regsize);
3585 NODE_ALIGN_FILL(ret);
3587 FILL_ADVANCE_NODE(ptr, op);
3594 - reganode - emit a node with an argument
3596 STATIC regnode * /* Location. */
3597 S_reganode(pTHX_ U8 op, U32 arg)
3600 register regnode *ret;
3601 register regnode *ptr;
3605 SIZE_ALIGN(PL_regsize);
3610 NODE_ALIGN_FILL(ret);
3612 FILL_ADVANCE_NODE_ARG(ptr, op, arg);
3619 - reguni - emit (if appropriate) a Unicode character
3622 S_reguni(pTHX_ UV uv, char* s, I32* lenp)
3627 *lenp = uv_to_utf8(tmpbuf, uv) - tmpbuf;
3630 *lenp = uv_to_utf8((U8*)s, uv) - (U8*)s;
3635 - reginsert - insert an operator in front of already-emitted operand
3637 * Means relocating the operand.
3640 S_reginsert(pTHX_ U8 op, regnode *opnd)
3643 register regnode *src;
3644 register regnode *dst;
3645 register regnode *place;
3646 register int offset = regarglen[(U8)op];
3648 /* (PL_regkind[(U8)op] == CURLY ? EXTRA_STEP_2ARGS : 0); */
3651 PL_regsize += NODE_STEP_REGNODE + offset;
3656 PL_regcode += NODE_STEP_REGNODE + offset;
3659 StructCopy(--src, --dst, regnode);
3661 place = opnd; /* Op node, where operand used to be. */
3662 src = NEXTOPER(place);
3663 FILL_ADVANCE_NODE(place, op);
3664 Zero(src, offset, regnode);
3668 - regtail - set the next-pointer at the end of a node chain of p to val.
3671 S_regtail(pTHX_ regnode *p, regnode *val)
3674 register regnode *scan;
3675 register regnode *temp;
3676 register I32 offset;
3681 /* Find last node. */
3684 temp = regnext(scan);
3690 if (reg_off_by_arg[OP(scan)]) {
3691 ARG_SET(scan, val - scan);
3694 NEXT_OFF(scan) = val - scan;
3699 - regoptail - regtail on operand of first argument; nop if operandless
3702 S_regoptail(pTHX_ regnode *p, regnode *val)
3705 /* "Operandless" and "op != BRANCH" are synonymous in practice. */
3706 if (p == NULL || SIZE_ONLY)
3708 if (PL_regkind[(U8)OP(p)] == BRANCH) {
3709 regtail(NEXTOPER(p), val);
3711 else if ( PL_regkind[(U8)OP(p)] == BRANCHJ) {
3712 regtail(NEXTOPER(NEXTOPER(p)), val);
3719 - regcurly - a little FSA that accepts {\d+,?\d*}
3722 S_regcurly(pTHX_ register char *s)
3741 S_dumpuntil(pTHX_ regnode *start, regnode *node, regnode *last, SV* sv, I32 l)
3744 register U8 op = EXACT; /* Arbitrary non-END op. */
3745 register regnode *next, *onode;
3747 while (op != END && (!last || node < last)) {
3748 /* While that wasn't END last time... */
3754 next = regnext(node);
3756 if (OP(node) == OPTIMIZED)
3759 PerlIO_printf(Perl_debug_log, "%4"IVdf":%*s%s", (IV)(node - start),
3760 (int)(2*l + 1), "", SvPVX(sv));
3761 if (next == NULL) /* Next ptr. */
3762 PerlIO_printf(Perl_debug_log, "(0)");
3764 PerlIO_printf(Perl_debug_log, "(%"IVdf")", (IV)(next - start));
3765 (void)PerlIO_putc(Perl_debug_log, '\n');
3767 if (PL_regkind[(U8)op] == BRANCHJ) {
3768 register regnode *nnode = (OP(next) == LONGJMP
3771 if (last && nnode > last)
3773 node = dumpuntil(start, NEXTOPER(NEXTOPER(node)), nnode, sv, l + 1);
3775 else if (PL_regkind[(U8)op] == BRANCH) {
3776 node = dumpuntil(start, NEXTOPER(node), next, sv, l + 1);
3778 else if ( op == CURLY) { /* `next' might be very big: optimizer */
3779 node = dumpuntil(start, NEXTOPER(node) + EXTRA_STEP_2ARGS,
3780 NEXTOPER(node) + EXTRA_STEP_2ARGS + 1, sv, l + 1);
3782 else if (PL_regkind[(U8)op] == CURLY && op != CURLYX) {
3783 node = dumpuntil(start, NEXTOPER(node) + EXTRA_STEP_2ARGS,
3786 else if ( op == PLUS || op == STAR) {
3787 node = dumpuntil(start, NEXTOPER(node), NEXTOPER(node) + 1, sv, l + 1);
3789 else if (op == ANYOF) {
3790 node = NEXTOPER(node);
3793 else if (PL_regkind[(U8)op] == EXACT) {
3794 /* Literal string, where present. */
3795 node += NODE_SZ_STR(node) - 1;
3796 node = NEXTOPER(node);
3799 node = NEXTOPER(node);
3800 node += regarglen[(U8)op];
3802 if (op == CURLYX || op == OPEN)
3804 else if (op == WHILEM)
3807 #endif /* DEBUGGING */
3812 - regdump - dump a regexp onto Perl_debug_log in vaguely comprehensible form
3815 Perl_regdump(pTHX_ regexp *r)
3819 SV *sv = sv_newmortal();
3821 (void)dumpuntil(r->program, r->program + 1, NULL, sv, 0);
3823 /* Header fields of interest. */
3824 if (r->anchored_substr)
3825 PerlIO_printf(Perl_debug_log,
3826 "anchored `%s%.*s%s'%s at %"IVdf" ",
3828 (int)(SvCUR(r->anchored_substr) - (SvTAIL(r->anchored_substr)!=0)),
3829 SvPVX(r->anchored_substr),
3831 SvTAIL(r->anchored_substr) ? "$" : "",
3832 (IV)r->anchored_offset);
3833 if (r->float_substr)
3834 PerlIO_printf(Perl_debug_log,
3835 "floating `%s%.*s%s'%s at %"IVdf"..%"UVuf" ",
3837 (int)(SvCUR(r->float_substr) - (SvTAIL(r->float_substr)!=0)),
3838 SvPVX(r->float_substr),
3840 SvTAIL(r->float_substr) ? "$" : "",
3841 (IV)r->float_min_offset, (UV)r->float_max_offset);
3842 if (r->check_substr)
3843 PerlIO_printf(Perl_debug_log,
3844 r->check_substr == r->float_substr
3845 ? "(checking floating" : "(checking anchored");
3846 if (r->reganch & ROPT_NOSCAN)
3847 PerlIO_printf(Perl_debug_log, " noscan");
3848 if (r->reganch & ROPT_CHECK_ALL)
3849 PerlIO_printf(Perl_debug_log, " isall");
3850 if (r->check_substr)
3851 PerlIO_printf(Perl_debug_log, ") ");
3853 if (r->regstclass) {
3854 regprop(sv, r->regstclass);
3855 PerlIO_printf(Perl_debug_log, "stclass `%s' ", SvPVX(sv));
3857 if (r->reganch & ROPT_ANCH) {
3858 PerlIO_printf(Perl_debug_log, "anchored");
3859 if (r->reganch & ROPT_ANCH_BOL)
3860 PerlIO_printf(Perl_debug_log, "(BOL)");
3861 if (r->reganch & ROPT_ANCH_MBOL)
3862 PerlIO_printf(Perl_debug_log, "(MBOL)");
3863 if (r->reganch & ROPT_ANCH_SBOL)
3864 PerlIO_printf(Perl_debug_log, "(SBOL)");
3865 if (r->reganch & ROPT_ANCH_GPOS)
3866 PerlIO_printf(Perl_debug_log, "(GPOS)");
3867 PerlIO_putc(Perl_debug_log, ' ');
3869 if (r->reganch & ROPT_GPOS_SEEN)
3870 PerlIO_printf(Perl_debug_log, "GPOS ");
3871 if (r->reganch & ROPT_SKIP)
3872 PerlIO_printf(Perl_debug_log, "plus ");
3873 if (r->reganch & ROPT_IMPLICIT)
3874 PerlIO_printf(Perl_debug_log, "implicit ");
3875 PerlIO_printf(Perl_debug_log, "minlen %ld ", (long) r->minlen);
3876 if (r->reganch & ROPT_EVAL_SEEN)
3877 PerlIO_printf(Perl_debug_log, "with eval ");
3878 PerlIO_printf(Perl_debug_log, "\n");
3879 #endif /* DEBUGGING */
3883 S_put_byte(pTHX_ SV *sv, int c)
3885 if (c <= ' ' || c == 127 || c == 255)
3886 Perl_sv_catpvf(aTHX_ sv, "\\%o", c);
3887 else if (c == '-' || c == ']' || c == '\\' || c == '^')
3888 Perl_sv_catpvf(aTHX_ sv, "\\%c", c);
3890 Perl_sv_catpvf(aTHX_ sv, "%c", c);
3894 - regprop - printable representation of opcode
3897 Perl_regprop(pTHX_ SV *sv, regnode *o)
3903 sv_setpvn(sv, "", 0);
3904 if (OP(o) >= reg_num) /* regnode.type is unsigned */
3905 FAIL("corrupted regexp opcode");
3906 sv_catpv(sv, (char*)reg_name[OP(o)]); /* Take off const! */
3908 k = PL_regkind[(U8)OP(o)];
3911 Perl_sv_catpvf(aTHX_ sv, " <%s%.*s%s>", PL_colors[0],
3912 STR_LEN(o), STRING(o), PL_colors[1]);
3913 else if (k == CURLY) {
3914 if (OP(o) == CURLYM || OP(o) == CURLYN)
3915 Perl_sv_catpvf(aTHX_ sv, "[%d]", o->flags); /* Parenth number */
3916 Perl_sv_catpvf(aTHX_ sv, " {%d,%d}", ARG1(o), ARG2(o));
3918 else if (k == WHILEM && o->flags) /* Ordinal/of */
3919 Perl_sv_catpvf(aTHX_ sv, "[%d/%d]", o->flags & 0xf, o->flags>>4);
3920 else if (k == REF || k == OPEN || k == CLOSE || k == GROUPP )
3921 Perl_sv_catpvf(aTHX_ sv, "%d", ARG(o)); /* Parenth number */
3922 else if (k == LOGICAL)
3923 Perl_sv_catpvf(aTHX_ sv, "[%d]", o->flags); /* 2: embedded, otherwise 1 */
3924 else if (k == ANYOF) {
3925 int i, rangestart = -1;
3926 const char * const out[] = { /* Should be syncronized with
3927 a table in regcomp.h */
3956 if (o->flags & ANYOF_LOCALE)
3957 sv_catpv(sv, "{loc}");
3958 if (o->flags & ANYOF_FOLD)
3959 sv_catpv(sv, "{i}");
3960 Perl_sv_catpvf(aTHX_ sv, "[%s", PL_colors[0]);
3961 if (o->flags & ANYOF_INVERT)
3963 for (i = 0; i <= 256; i++) {
3964 if (i < 256 && ANYOF_BITMAP_TEST(o,i)) {
3965 if (rangestart == -1)
3967 } else if (rangestart != -1) {
3968 if (i <= rangestart + 3)
3969 for (; rangestart < i; rangestart++)
3970 put_byte(sv, rangestart);
3972 put_byte(sv, rangestart);
3974 put_byte(sv, i - 1);
3979 if (o->flags & ANYOF_CLASS)
3980 for (i = 0; i < sizeof(out)/sizeof(char*); i++)
3981 if (ANYOF_CLASS_TEST(o,i))
3982 sv_catpv(sv, out[i]);
3983 Perl_sv_catpvf(aTHX_ sv, "%s]", PL_colors[1]);
3985 else if (k == BRANCHJ && (OP(o) == UNLESSM || OP(o) == IFMATCH))
3986 Perl_sv_catpvf(aTHX_ sv, "[-%d]", o->flags);
3987 #endif /* DEBUGGING */
3991 Perl_re_intuit_string(pTHX_ regexp *prog)
3992 { /* Assume that RE_INTUIT is set */
3995 char *s = SvPV(prog->check_substr,n_a);
3997 if (!PL_colorset) reginitcolors();
3998 PerlIO_printf(Perl_debug_log,
3999 "%sUsing REx substr:%s `%s%.60s%s%s'\n",
4000 PL_colors[4],PL_colors[5],PL_colors[0],
4003 (strlen(s) > 60 ? "..." : ""));
4006 return prog->check_substr;
4010 Perl_pregfree(pTHX_ struct regexp *r)
4013 DEBUG_r(if (!PL_colorset) reginitcolors());
4015 if (!r || (--r->refcnt > 0))
4017 DEBUG_r(PerlIO_printf(Perl_debug_log,
4018 "%sFreeing REx:%s `%s%.60s%s%s'\n",
4019 PL_colors[4],PL_colors[5],PL_colors[0],
4022 (strlen(r->precomp) > 60 ? "..." : "")));
4025 Safefree(r->precomp);
4026 if (RX_MATCH_COPIED(r))
4027 Safefree(r->subbeg);
4029 if (r->anchored_substr)
4030 SvREFCNT_dec(r->anchored_substr);
4031 if (r->float_substr)
4032 SvREFCNT_dec(r->float_substr);
4033 Safefree(r->substrs);
4036 int n = r->data->count;
4037 AV* new_comppad = NULL;
4042 switch (r->data->what[n]) {
4044 SvREFCNT_dec((SV*)r->data->data[n]);
4047 Safefree(r->data->data[n]);
4050 new_comppad = (AV*)r->data->data[n];
4053 if (new_comppad == NULL)
4054 Perl_croak(aTHX_ "panic: pregfree comppad");
4055 old_comppad = PL_comppad;
4056 old_curpad = PL_curpad;
4057 PL_comppad = new_comppad;
4058 PL_curpad = AvARRAY(new_comppad);
4059 op_free((OP_4tree*)r->data->data[n]);
4060 PL_comppad = old_comppad;
4061 PL_curpad = old_curpad;
4062 SvREFCNT_dec((SV*)new_comppad);
4068 FAIL2("panic: regfree data code '%c'", r->data->what[n]);
4071 Safefree(r->data->what);
4074 Safefree(r->startp);
4080 - regnext - dig the "next" pointer out of a node
4082 * [Note, when REGALIGN is defined there are two places in regmatch()
4083 * that bypass this code for speed.]
4086 Perl_regnext(pTHX_ register regnode *p)
4089 register I32 offset;
4091 if (p == &PL_regdummy)
4094 offset = (reg_off_by_arg[OP(p)] ? ARG(p) : NEXT_OFF(p));
4102 S_re_croak2(pTHX_ const char* pat1,const char* pat2,...)
4105 STRLEN l1 = strlen(pat1);
4106 STRLEN l2 = strlen(pat2);
4115 Copy(pat1, buf, l1 , char);
4116 Copy(pat2, buf + l1, l2 , char);
4117 buf[l1 + l2] = '\n';
4118 buf[l1 + l2 + 1] = '\0';
4120 /* ANSI variant takes additional second argument */
4121 va_start(args, pat2);
4125 msv = vmess(buf, &args);
4127 message = SvPV(msv,l1);
4130 Copy(message, buf, l1 , char);
4131 buf[l1] = '\0'; /* Overwrite \n */
4132 Perl_croak(aTHX_ "%s", buf);
4135 /* XXX Here's a total kludge. But we need to re-enter for swash routines. */
4138 Perl_save_re_context(pTHX)
4142 SAVEPPTR(PL_regprecomp); /* uncompiled string. */
4143 SAVEI32(PL_regnpar); /* () count. */
4144 SAVEI32(PL_regsize); /* Code size. */
4145 SAVEI16(PL_regflags); /* are we folding, multilining? */
4146 SAVEPPTR(PL_reginput); /* String-input pointer. */
4147 SAVEPPTR(PL_regbol); /* Beginning of input, for ^ check. */
4148 SAVEPPTR(PL_regeol); /* End of input, for $ check. */
4149 SAVEVPTR(PL_regstartp); /* Pointer to startp array. */
4150 SAVEVPTR(PL_regendp); /* Ditto for endp. */
4151 SAVEVPTR(PL_reglastparen); /* Similarly for lastparen. */
4152 SAVEPPTR(PL_regtill); /* How far we are required to go. */
4153 SAVEI8(PL_regprev); /* char before regbol, \n if none */
4154 SAVEVPTR(PL_reg_start_tmp); /* from regexec.c */
4155 PL_reg_start_tmp = 0;
4156 SAVEFREEPV(PL_reg_start_tmp);
4157 SAVEI32(PL_reg_start_tmpl); /* from regexec.c */
4158 PL_reg_start_tmpl = 0;
4159 SAVEVPTR(PL_regdata);
4160 SAVEI32(PL_reg_flags); /* from regexec.c */
4161 SAVEI32(PL_reg_eval_set); /* from regexec.c */
4162 SAVEI32(PL_regnarrate); /* from regexec.c */
4163 SAVEVPTR(PL_regprogram); /* from regexec.c */
4164 SAVEINT(PL_regindent); /* from regexec.c */
4165 SAVEVPTR(PL_regcc); /* from regexec.c */
4166 SAVEVPTR(PL_curcop);
4167 SAVEVPTR(PL_regcomp_rx); /* from regcomp.c */
4168 SAVEI32(PL_regseen); /* from regcomp.c */
4169 SAVEI32(PL_regsawback); /* Did we see \1, ...? */
4170 SAVEI32(PL_regnaughty); /* How bad is this pattern? */
4171 SAVEVPTR(PL_regcode); /* Code-emit pointer; ®dummy = don't */
4172 SAVEPPTR(PL_regxend); /* End of input for compile */
4173 SAVEPPTR(PL_regcomp_parse); /* Input-scan pointer. */
4174 SAVEVPTR(PL_reg_call_cc); /* from regexec.c */
4175 SAVEVPTR(PL_reg_re); /* from regexec.c */
4176 SAVEPPTR(PL_reg_ganch); /* from regexec.c */
4177 SAVESPTR(PL_reg_sv); /* from regexec.c */
4178 SAVEVPTR(PL_reg_magic); /* from regexec.c */
4179 SAVEI32(PL_reg_oldpos); /* from regexec.c */
4180 SAVEVPTR(PL_reg_oldcurpm); /* from regexec.c */
4181 SAVEVPTR(PL_reg_curpm); /* from regexec.c */
4183 SAVEPPTR(PL_reg_starttry); /* from regexec.c */
4194 clear_re(pTHXo_ void *r)
4196 ReREFCNT_dec((regexp *)r);